1 /***************************************************************************
2 * Copyright (C) 2008 by Sverre Rabbelier *
3 * sverre@rabbelier.nl *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 3 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include <boost/spirit/core.hpp>
22 #include <boost/spirit/symbols/symbols.hpp>
24 #include "EditorAccount.h"
25 #include "EditorMovement.h"
29 #include "StringUtilities.h"
31 #include "Character.h"
32 #include "PCharacter.h"
33 #include "PCharacterManager.h"
35 #include "ChunkManager.h"
37 #include "Coordinate.h"
39 using namespace boost::spirit
;
40 using mud::PCharacter
;
42 struct dirs
: symbols
<Coordinate
>
47 ("n", Coordinate(1, 0, 0))
48 ("s", Coordinate(-1, 0, 0))
49 ("e", Coordinate(0, 1, 0))
50 ("w", Coordinate(0, -1, 0))
51 ("u", Coordinate(0, 0, 1))
52 ("d", Coordinate(0, 0, -1))
60 add_dir(Coordinate
& coordinate
) : m_coordinate(coordinate
) {}
61 void operator()(Coordinate
& rhs
) const { m_coordinate
+= rhs
; }
62 Coordinate
& m_coordinate
;
67 add_and_reset(std::vector
<Coordinate
>& c
) : m_coordinates(c
) { }
68 void operator()(Coordinate
& rhs
) const {
69 m_coordinates
.push_back(rhs
);
72 std::vector
<Coordinate
>& m_coordinates
;
76 struct direction
: public grammar
<direction
>
78 template <typename ScannerT
>
81 definition(direction
const& self
)
84 +dirs_p
[add_dir(self
.m_coordinate
)]; // >> ch_p(';')
85 //)[add_and_reset(self.m_coordinates)];
90 rule
<ScannerT
> const& start() const { return first
; }
93 direction(std::vector
<Coordinate
>& coordinates
, Coordinate
& coordinate
) :
94 m_coordinate(coordinate
),
95 m_coordinates(coordinates
)
99 Coordinate
& m_coordinate
;
100 std::vector
<Coordinate
>& m_coordinates
;
103 EditorMovement::EditorMovement(UBSocket
* sock
, mud::PCharacterPtr character
) :
110 EditorMovement::~EditorMovement(void)
115 std::string
EditorMovement::lookup(const std::string
& str
)
118 return Global::Get()->EmptyString
;
120 std::vector
<Coordinate
> coordinates
;
121 Coordinate
coordinate(0,0,0);
123 direction
direction_p(coordinates
, coordinate
);
125 bool match
= parse(str
.c_str(), direction_p
).full
;
130 return Global::Get()->EmptyString
;
133 void EditorMovement::dispatch(const std::string
& action
, const std::string
& argument
)
138 void EditorMovement::listCommands(const std::string
& argument
)
145 void EditorMovement::quitEditor(const std::string
& argument
)
147 m_sock
->Send("Ok.\n");
153 void EditorRoom::North::Run(EditorRoom
* editor
, const std::string
&)
155 if(editor
->m_ypos
<= 1)
157 editor
->m_m_sock
->Send("You can't go further north!\n");
161 editor
->getRoom(Global::Get()->EmptyString
);
162 editor
->m_m_sock
->Send(Room::CreateMap(editor
->m_cluster
, editor
->m_xpos
, editor
-> m_ypos
));
165 void EditorRoom::NorthEast::Run(EditorRoom
* editor
, const std::string
& argument
)
167 long count
= DatabaseMgr::Get()->CountSavable(Tables::Get()->AREAS
, editor
->m_cluster
);
169 Global::Get()->bug("EditorMap::NorthEast::Run() with clustercount <= 0!\n");
170 editor
->m_m_sock
->Send("For some reason the cluster number of the room you are belongs to, does not correspond with anything in the database?!\n");
174 Global::Get()->bugf("EditorMap::NorthEast::Run() with clustercount '%d'!\n", count
);
175 editor
->m_m_sock
->Sendf("For some reason the cluster the room you are in exists multiple times in the database?!n");
178 Cluster
* cluster
= Cache::Get()->GetCluster(editor
->m_cluster
);
179 if(editor
->m_ypos
<= 1 || editor
->m_xpos
+1 > cluster
->getWidth())
181 editor
->m_m_sock
->Send("You can't go further northeast!\n");
186 editor
->getRoom(Global::Get()->EmptyString
);
187 editor
->m_m_sock
->Send(Room::CreateMap(editor
->m_cluster
, editor
->m_xpos
, editor
->m_ypos
));
190 void EditorRoom::East::Run(EditorRoom
* editor
, const std::string
& argument
)
192 long count
= DatabaseMgr::Get()->CountSavable(Tables::Get()->AREAS
, editor
->m_cluster
);
194 Global::Get()->bug("EditorMap::East::Run() with clustercount <= 0!\n");
195 editor
->m_m_sock
->Send("For some reason the cluster number of the room you are belongs to, does not correspond with anything in the database?!\n");
199 Global::Get()->bugf("EditorMap::East::Run() with clustercount '%d'!\n", count
);
200 editor
->m_m_sock
->Sendf("For some reason the cluster the room you are in exists multiple times in the database?!n");
203 Cluster
* cluster
= Cache::Get()->GetCluster(editor
->m_cluster
);
204 if(editor
->m_xpos
+1 > cluster
->getWidth())
206 editor
->m_m_sock
->Send("You can't go further east!\n");
210 editor
->getRoom(Global::Get()->EmptyString
);
211 editor
->m_m_sock
->Send(Room::CreateMap(editor
->m_cluster
, editor
->m_xpos
, editor
->m_ypos
));
214 void EditorRoom::SouthEast::Run(EditorRoom
* editor
, const std::string
& argument
)
216 long count
= DatabaseMgr::Get()->CountSavable(Tables::Get()->AREAS
, editor
->m_cluster
);
218 Global::Get()->bug("EditorMap::SouthEast::Run() with clustercount <= 0!\n");
219 editor
->m_m_sock
->Send("For some reason the cluster number of the room you are belongs to, does not correspond with anything in the database?!\n");
223 Global::Get()->bugf("EditorMap::SouthEast::Run() with clustercount '%d'!\n", count
);
224 editor
->m_m_sock
->Sendf("For some reason the cluster the room you are in exists multiple times in the database?!n");
227 Cluster
* cluster
= Cache::Get()->GetCluster(editor
->m_cluster
);
228 if(editor
->m_ypos
+1 > cluster
->getHeight() || editor
->m_xpos
+1 > cluster
->getWidth())
230 editor
->m_m_sock
->Send("You can't go further southeast!\n");
235 editor
->getRoom(Global::Get()->EmptyString
);
236 editor
->m_m_sock
->Send(Room::CreateMap(editor
->m_cluster
, editor
->m_xpos
, editor
->m_ypos
));
239 void EditorRoom::South::Run(EditorRoom
* editor
, const std::string
& argument
)
241 long count
= DatabaseMgr::Get()->CountSavable(Tables::Get()->AREAS
, editor
->m_cluster
);
243 Global::Get()->bug("EditorMap::South::Run() with clustercount <= 0!\n");
244 editor
->m_m_sock
->Send("For some reason the cluster number of the room you are belongs to, does not correspond with anything in the database?!\n");
248 Global::Get()->bugf("EditorMap::South::Run() with clustercount '%d'!\n", count
);
249 editor
->m_m_sock
->Sendf("For some reason the cluster the room you are in exists multiple times in the database?!n");
252 Cluster
* cluster
= Cache::Get()->GetCluster(editor
->m_cluster
);
253 if(editor
->m_ypos
+1 > cluster
->getHeight())
255 editor
->m_m_sock
->Send("You can't go further south!\n");
259 editor
->getRoom(Global::Get()->EmptyString
);
260 editor
->m_m_sock
->Send(Room::CreateMap(editor
->m_cluster
, editor
->m_xpos
, editor
->m_ypos
));
263 void EditorRoom::SouthWest::Run(EditorRoom
* editor
, const std::string
& argument
)
265 long count
= DatabaseMgr::Get()->CountSavable(Tables::Get()->AREAS
, editor
->m_cluster
);
267 Global::Get()->bug("EditorMap::SouthWest::Run() with clustercount <= 0!\n");
268 editor
->m_m_sock
->Send("For some reason the cluster number of the room you are belongs to, does not correspond with anything in the database?!\n");
272 Global::Get()->bugf("EditorMap::SouthWest::Run() with clustercount '%d'!\n", count
);
273 editor
->m_m_sock
->Sendf("For some reason the cluster the room you are in exists multiple times in the database?!n");
276 Cluster
* cluster
= Cache::Get()->GetCluster(editor
->m_cluster
);
277 if(editor
->m_xpos
<= 1 || editor
->m_ypos
+1 > cluster
->getHeight())
279 editor
->m_m_sock
->Send("You can't go further southwest!\n");
284 editor
->getRoom(Global::Get()->EmptyString
);
285 editor
->m_m_sock
->Send(Room::CreateMap(editor
->m_cluster
, editor
->m_xpos
, editor
->m_ypos
));
288 void EditorRoom::West::Run(EditorRoom
* editor
, const std::string
& argument
)
290 if(editor
->m_xpos
<= 1)
292 editor
->m_m_sock
->Send("You can't go further west!\n");
296 editor
->getRoom(Global::Get()->EmptyString
);
297 editor
->m_m_sock
->Send(Room::CreateMap(editor
->m_cluster
, editor
->m_xpos
, editor
->m_ypos
));
300 void EditorRoom::NorthWest::Run(EditorRoom
* editor
, const std::string
& argument
)
302 if(editor
->m_ypos
<= 1 || editor
->m_xpos
<= 1)
304 editor
->m_m_sock
->Send("You can't go further northwest!\n");
309 editor
->getRoom(Global::Get()->EmptyString
);
310 editor
->m_m_sock
->Send(Room::CreateMap(editor
->m_cluster
, editor
->m_xpos
, editor
->m_ypos
));