Cosmetic improvements with EditorMovement (and removed the #if 0 ... #endif-ed stuff).
[UnsignedByte.git] / src / Core / Editors / EditorMovement.cpp
blobeaad812b40b5fd5fb6d37e4542b0a1b388360457
1 /***************************************************************************
2 * Copyright (C) 2008 by Sverre Rabbelier *
3 * sverre@rabbelier.nl *
4 * *
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. *
9 * *
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. *
14 * *
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"
23 #include "UBSocket.h"
24 #include "Array.h"
25 #include "Assert.h"
26 #include "StringUtilities.h"
27 #include "Account.h"
28 #include "Character.h"
29 #include "PCharacter.h"
30 #include "PCharacterManager.h"
31 #include "Chunk.h"
32 #include "ChunkManager.h"
33 #include "Managers.h"
34 #include "DirectionParser.h"
35 #include "Exit.h"
36 #include "ExitManager.h"
38 using mud::PCharacter;
40 EditorMovement::EditorMovement(UBSocket* sock, mud::PCharacterPtr character) :
41 Editor(sock),
42 m_char(character)
44 Assert(character);
47 EditorMovement::EditorMovement(UBSocket* sock, mud::PCharacterPtr character, cstring line) :
48 Editor(sock),
49 m_char(character),
50 m_line(line)
52 Assert(character);
55 EditorMovement::~EditorMovement(void)
60 void EditorMovement::OnLine(const std::string& str)
62 DirectionParser p(str);
63 Coordinates result = p.getResult();
65 if(!result.size())
67 m_sock->Sendf("'%s' is not a valid direction.\n", str.c_str());
68 return;
71 if(result.size() > 1)
73 m_sock->Send("Let's get movin':\n");
75 for(Coordinates::const_iterator it = result.begin(); it != result.end(); it++)
77 Coordinate coordinate = *it;
78 Assert(coordinate.isDirection());
80 m_sock->Send(coordinate.toDirectionString());
81 m_sock->Send("\n");
84 m_sock->Send("\n");
87 for(Coordinates::const_iterator it = result.begin(); it != result.end(); it++)
89 Coordinate coordinate = *it;
91 value_type chunkid = m_char->getChunk();
92 mud::ChunkPtr chunk = mud::Managers::Get()->Chunk->GetByKey(chunkid);
93 Assert(chunk);
95 value_type exitid = chunk->getExitAt(coordinate);
96 if(!exitid)
98 m_sock->Sendf("There is no exit to the %s.\n", coordinate.toDirectionString().c_str());
99 return;
102 mud::ExitPtr exit = mud::Managers::Get()->Exit->GetByKey(exitid);
103 Assert(exit->getFromChunk() == chunkid);
105 value_type tochunkid = exit->getToChunk();
106 Assert(tochunkid);
108 m_char->MoveToChunk(tochunkid);
112 void EditorMovement::OnFocus()
114 if(m_line.size())
116 OnLine(m_line);
117 m_sock->PopEditor();
121 void EditorMovement::OnEmptyLine()
123 m_sock->Send("Ok.\n");
124 m_sock->PopEditor();
125 return;