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 DirectionParser
p(str
);
63 Coordinates result
= p
.getResult();
67 m_sock
->Sendf("'%s' is not a valid direction.\n", str
.c_str());
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());
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
);
95 value_type exitid
= chunk
->getExitAt(coordinate
);
98 m_sock
->Sendf("There is no exit to the %s.\n", coordinate
.toDirectionString().c_str());
102 mud::ExitPtr exit
= mud::Managers::Get()->Exit
->GetByKey(exitid
);
103 Assert(exit
->getFromChunk() == chunkid
);
105 value_type tochunkid
= exit
->getToChunk();
108 m_char
->MoveToChunk(tochunkid
);
112 void EditorMovement::OnFocus()
121 void EditorMovement::OnEmptyLine()
123 m_sock
->Send("Ok.\n");