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
)
62 if(!str
.compare("quit"))
64 m_sock
->Send("Ok.\n");
69 DirectionParser
p(str
);
70 Coordinates result
= p
.getResult();
74 m_sock
->Sendf("'%s' is not a valid direction.\n", str
.c_str());
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());
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
);
102 value_type exitid
= chunk
->getExitAt(coordinate
);
105 m_sock
->Sendf("There is no exit to the %s.\n", coordinate
.toDirectionString().c_str());
109 mud::ExitPtr exit
= mud::Managers::Get()->Exit
->GetByKey(exitid
);
110 Assert(exit
->getFromChunk() == chunkid
);
112 value_type tochunkid
= exit
->getToChunk();
115 m_char
->MoveToChunk(tochunkid
);
119 void EditorMovement::OnFocus()
123 if(m_line
.compare("quit"))
130 void EditorMovement::OnEmptyLine()
132 m_sock
->Send("Ok.\n");