When a user does 'go quit', just ignore and pop the editor.
[UnsignedByte.git] / src / Core / Editors / EditorMovement.cpp
blobd0a4a90b455868081218fa24084789e46c8d15eb
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 if(!str.compare("quit"))
64 m_sock->Send("Ok.\n");
65 m_sock->PopEditor();
66 return;
69 DirectionParser p(str);
70 Coordinates result = p.getResult();
72 if(!result.size())
74 m_sock->Sendf("'%s' is not a valid direction.\n", str.c_str());
75 return;
78 if(result.size() > 1)
80 m_sock->Send("Let's get movin':\n");
82 for(Coordinates::const_iterator it = result.begin(); it != result.end(); it++)
84 Coordinate coordinate = *it;
85 Assert(coordinate.isDirection());
87 m_sock->Send(coordinate.toDirectionString());
88 m_sock->Send("\n");
91 m_sock->Send("\n");
94 for(Coordinates::const_iterator it = result.begin(); it != result.end(); it++)
96 Coordinate coordinate = *it;
98 value_type chunkid = m_char->getChunk();
99 mud::ChunkPtr chunk = mud::Managers::Get()->Chunk->GetByKey(chunkid);
100 Assert(chunk);
102 value_type exitid = chunk->getExitAt(coordinate);
103 if(!exitid)
105 m_sock->Sendf("There is no exit to the %s.\n", coordinate.toDirectionString().c_str());
106 return;
109 mud::ExitPtr exit = mud::Managers::Get()->Exit->GetByKey(exitid);
110 Assert(exit->getFromChunk() == chunkid);
112 value_type tochunkid = exit->getToChunk();
113 Assert(tochunkid);
115 m_char->MoveToChunk(tochunkid);
119 void EditorMovement::OnFocus()
121 if(m_line.size())
123 if(m_line.compare("quit"))
124 OnLine(m_line);
126 m_sock->PopEditor();
130 void EditorMovement::OnEmptyLine()
132 m_sock->Send("Ok.\n");
133 m_sock->PopEditor();
134 return;