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 "EditorAccount.h"
22 #include "EditorMovement.h"
26 #include "StringUtilities.h"
28 #include "Character.h"
29 #include "PCharacter.h"
30 #include "PCharacterManager.h"
32 #include "ChunkManager.h"
34 #include "DirectionParser.h"
36 #include "ExitManager.h"
38 using mud::PCharacter
;
40 EditorMovement::EditorMovement(UBSocket
* sock
, mud::PCharacterPtr character
) :
47 EditorMovement::EditorMovement(UBSocket
* sock
, mud::PCharacterPtr character
, cstring line
) :
55 EditorMovement::~EditorMovement(void)
60 void EditorMovement::OnLine(const std::string
& str
)
64 m_sock
->Send("Please specify where you want to move to.\n");
68 DirectionParser
p(str
);
69 Coordinates result
= p
.getResult();
73 OnLine(Global::Get()->EmptyString
);
74 m_sock
->Sendf("'%s' is not a valid direction.\n");
79 for(Coordinates::const_iterator it
= result
.begin(); it
!= result
.end(); it
++)
81 Coordinate coordinate
= *it
;
82 if(!coordinate
.isDirection())
84 m_sock
->Sendf("Your %dth direction is not a direction.\n", i
);
85 m_sock
->Send("Please consult the helpfile on directions.\n");
92 for(Coordinates::const_iterator it
= result
.begin(); it
!= result
.end(); it
++)
94 Coordinate coordinate
= *it
;
96 value_type chunkid
= m_char
->getChunk();
97 mud::ChunkPtr chunk
= mud::Managers::Get()->Chunk
->GetByKey(chunkid
);
100 value_type exitid
= chunk
->getExitAt(coordinate
);
103 m_sock
->Sendf("There is no exit to the %s.\n", coordinate
.toDirectionString().c_str());
107 mud::ExitPtr exit
= mud::Managers::Get()->Exit
->GetByKey(exitid
);
108 Assert(exit
->getFromChunk() == chunkid
);
110 value_type tochunkid
= exit
->getToChunk();
113 m_char
->MoveToChunk(tochunkid
);
117 void EditorMovement::OnFocus()
123 void EditorMovement::listCommands(const std::string
& argument
)
130 void EditorMovement::quitEditor(const std::string
& argument
)
132 m_sock
->Send("Ok.\n");
138 void EditorRoom::North::Run(EditorRoom
* editor
, const std::string
&)
140 if(editor
->m_ypos
<= 1)
142 editor
->m_m_sock
->Send("You can't go further north!\n");
146 editor
->getRoom(Global::Get()->EmptyString
);
147 editor
->m_m_sock
->Send(Room::CreateMap(editor
->m_cluster
, editor
->m_xpos
, editor
-> m_ypos
));
150 void EditorRoom::NorthEast::Run(EditorRoom
* editor
, const std::string
& argument
)
152 long count
= DatabaseMgr::Get()->CountSavable(Tables::Get()->AREAS
, editor
->m_cluster
);
154 Global::Get()->bug("EditorMap::NorthEast::Run() with clustercount <= 0!\n");
155 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");
159 Global::Get()->bugf("EditorMap::NorthEast::Run() with clustercount '%d'!\n", count
);
160 editor
->m_m_sock
->Sendf("For some reason the cluster the room you are in exists multiple times in the database?!n");
163 Cluster
* cluster
= Cache::Get()->GetCluster(editor
->m_cluster
);
164 if(editor
->m_ypos
<= 1 || editor
->m_xpos
+1 > cluster
->getWidth())
166 editor
->m_m_sock
->Send("You can't go further northeast!\n");
171 editor
->getRoom(Global::Get()->EmptyString
);
172 editor
->m_m_sock
->Send(Room::CreateMap(editor
->m_cluster
, editor
->m_xpos
, editor
->m_ypos
));
175 void EditorRoom::East::Run(EditorRoom
* editor
, const std::string
& argument
)
177 long count
= DatabaseMgr::Get()->CountSavable(Tables::Get()->AREAS
, editor
->m_cluster
);
179 Global::Get()->bug("EditorMap::East::Run() with clustercount <= 0!\n");
180 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");
184 Global::Get()->bugf("EditorMap::East::Run() with clustercount '%d'!\n", count
);
185 editor
->m_m_sock
->Sendf("For some reason the cluster the room you are in exists multiple times in the database?!n");
188 Cluster
* cluster
= Cache::Get()->GetCluster(editor
->m_cluster
);
189 if(editor
->m_xpos
+1 > cluster
->getWidth())
191 editor
->m_m_sock
->Send("You can't go further east!\n");
195 editor
->getRoom(Global::Get()->EmptyString
);
196 editor
->m_m_sock
->Send(Room::CreateMap(editor
->m_cluster
, editor
->m_xpos
, editor
->m_ypos
));
199 void EditorRoom::SouthEast::Run(EditorRoom
* editor
, const std::string
& argument
)
201 long count
= DatabaseMgr::Get()->CountSavable(Tables::Get()->AREAS
, editor
->m_cluster
);
203 Global::Get()->bug("EditorMap::SouthEast::Run() with clustercount <= 0!\n");
204 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");
208 Global::Get()->bugf("EditorMap::SouthEast::Run() with clustercount '%d'!\n", count
);
209 editor
->m_m_sock
->Sendf("For some reason the cluster the room you are in exists multiple times in the database?!n");
212 Cluster
* cluster
= Cache::Get()->GetCluster(editor
->m_cluster
);
213 if(editor
->m_ypos
+1 > cluster
->getHeight() || editor
->m_xpos
+1 > cluster
->getWidth())
215 editor
->m_m_sock
->Send("You can't go further southeast!\n");
220 editor
->getRoom(Global::Get()->EmptyString
);
221 editor
->m_m_sock
->Send(Room::CreateMap(editor
->m_cluster
, editor
->m_xpos
, editor
->m_ypos
));
224 void EditorRoom::South::Run(EditorRoom
* editor
, const std::string
& argument
)
226 long count
= DatabaseMgr::Get()->CountSavable(Tables::Get()->AREAS
, editor
->m_cluster
);
228 Global::Get()->bug("EditorMap::South::Run() with clustercount <= 0!\n");
229 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");
233 Global::Get()->bugf("EditorMap::South::Run() with clustercount '%d'!\n", count
);
234 editor
->m_m_sock
->Sendf("For some reason the cluster the room you are in exists multiple times in the database?!n");
237 Cluster
* cluster
= Cache::Get()->GetCluster(editor
->m_cluster
);
238 if(editor
->m_ypos
+1 > cluster
->getHeight())
240 editor
->m_m_sock
->Send("You can't go further south!\n");
244 editor
->getRoom(Global::Get()->EmptyString
);
245 editor
->m_m_sock
->Send(Room::CreateMap(editor
->m_cluster
, editor
->m_xpos
, editor
->m_ypos
));
248 void EditorRoom::SouthWest::Run(EditorRoom
* editor
, const std::string
& argument
)
250 long count
= DatabaseMgr::Get()->CountSavable(Tables::Get()->AREAS
, editor
->m_cluster
);
252 Global::Get()->bug("EditorMap::SouthWest::Run() with clustercount <= 0!\n");
253 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");
257 Global::Get()->bugf("EditorMap::SouthWest::Run() with clustercount '%d'!\n", count
);
258 editor
->m_m_sock
->Sendf("For some reason the cluster the room you are in exists multiple times in the database?!n");
261 Cluster
* cluster
= Cache::Get()->GetCluster(editor
->m_cluster
);
262 if(editor
->m_xpos
<= 1 || editor
->m_ypos
+1 > cluster
->getHeight())
264 editor
->m_m_sock
->Send("You can't go further southwest!\n");
269 editor
->getRoom(Global::Get()->EmptyString
);
270 editor
->m_m_sock
->Send(Room::CreateMap(editor
->m_cluster
, editor
->m_xpos
, editor
->m_ypos
));
273 void EditorRoom::West::Run(EditorRoom
* editor
, const std::string
& argument
)
275 if(editor
->m_xpos
<= 1)
277 editor
->m_m_sock
->Send("You can't go further west!\n");
281 editor
->getRoom(Global::Get()->EmptyString
);
282 editor
->m_m_sock
->Send(Room::CreateMap(editor
->m_cluster
, editor
->m_xpos
, editor
->m_ypos
));
285 void EditorRoom::NorthWest::Run(EditorRoom
* editor
, const std::string
& argument
)
287 if(editor
->m_ypos
<= 1 || editor
->m_xpos
<= 1)
289 editor
->m_m_sock
->Send("You can't go further northwest!\n");
294 editor
->getRoom(Global::Get()->EmptyString
);
295 editor
->m_m_sock
->Send(Room::CreateMap(editor
->m_cluster
, editor
->m_xpos
, editor
->m_ypos
));