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 ***************************************************************************/
30 #include "SectorManager.h"
31 #include "Character.h"
32 #include "CharacterManager.h"
34 #include "TraceManager.h"
35 #include "TableImpls.h"
37 #include "StringUtilities.h"
39 #include "FieldImpls.h"
41 #include "DetailManager.h"
42 #include "RoomManager.h"
46 Room::Room(SavableManagerPtr room
) :
57 value_type
Room::getID() const
59 return m_room
->getValue(db::TableImpls::Get()->ROOMS
->ROOMID
)->getIntegerValue();
62 const std::string
& Room::getName() const
64 return m_room
->getValue(db::TableImpls::Get()->ROOMS
->NAME
)->getStringValue();
67 const std::string
& Room::getDescription() const
69 return m_room
->getValue(db::TableImpls::Get()->ROOMS
->DESCRIPTION
)->getStringValue();
72 value_type
Room::getSector() const
74 return m_room
->getValue(db::TableImpls::Get()->ROOMS
->FKSECTORS
)->getIntegerValue();
77 value_type
Room::getCluster() const
79 return m_room
->getValue(db::TableImpls::Get()->ROOMS
->FKCLUSTERS
)->getIntegerValue();
82 value_type
Room::getHeight() const
84 return m_room
->getValue(db::TableImpls::Get()->ROOMS
->HEIGHT
)->getIntegerValue();
87 value_type
Room::getWidth() const
89 return m_room
->getValue(db::TableImpls::Get()->ROOMS
->WIDTH
)->getIntegerValue();
92 value_type
Room::getLength() const
94 return m_room
->getValue(db::TableImpls::Get()->ROOMS
->LENGTH
)->getIntegerValue();
98 void Room::setName(const std::string name
)
101 ValuePtr
value(new FieldValue(db::TableImpls::Get()->ROOMS
->NAME
, name
));
102 m_room
->setValue(value
);
105 void Room::setDescription(const std::string description
)
108 ValuePtr
value(new FieldValue(db::TableImpls::Get()->ROOMS
->DESCRIPTION
, description
));
109 m_room
->setValue(value
);
112 void Room::setSector(value_type sector
)
115 ValuePtr
value(new FieldValue(db::TableImpls::Get()->ROOMS
->FKSECTORS
, sector
));
116 m_room
->setValue(value
);
119 void Room::setCluster(value_type cluster
)
122 ValuePtr
value(new FieldValue(db::TableImpls::Get()->ROOMS
->FKCLUSTERS
, cluster
));
123 m_room
->setValue(value
);
126 void Room::setHeight(value_type height
)
129 ValuePtr
value(new FieldValue(db::TableImpls::Get()->ROOMS
->HEIGHT
, height
));
130 m_room
->setValue(value
);
133 void Room::setWidth(value_type width
)
136 ValuePtr
value(new FieldValue(db::TableImpls::Get()->ROOMS
->WIDTH
, width
));
137 m_room
->setValue(value
);
140 void Room::setLength(value_type length
)
143 ValuePtr
value(new FieldValue(db::TableImpls::Get()->ROOMS
->LENGTH
, length
));
144 m_room
->setValue(value
);
159 void mud::Room::Delete(value_type accountid
, const std::string
& description
)
162 Assert(!"Not yet implemented");
165 void mud::Room::Save(value_type accountid
, const std::string
& description
)
167 if(!m_room
->isDirty())
172 KeysPtr keys
= mud::Managers::Get()->Trace
->Add();
173 mud::TracePtr trace
= mud::Managers::Get()->Trace
->GetByKey(keys
->first()->getIntegerValue());
177 trace
->setAccount(accountid
);
179 if(description
!= Global::Get()->EmptyString
)
180 trace
->setDescription(description
);
183 trace
->setDiff(m_room
->getDiff());
184 trace
->setTime(time(NULL
));
185 trace
->Save(); // create the Trace
187 RelationPtr
relation(new Relation(db::TableImpls::Get()->TRACEROOM
));
188 relation
->addKey(db::TableImpls::Get()->TRACEROOM
->FKROOMS
, getID());
189 relation
->addKey(db::TableImpls::Get()->TRACEROOM
->FKTRACES
, keys
->first()->getIntegerValue());
190 relation
->save(); // create the relation
192 m_room
->save(); // save the room
204 return m_room
->exists();
208 std::string
Room::CreateMap(value_type id
, long origx
, long origy
)
212 long count
= DatabaseMgr::Get()->CountSavable(Tables::Get()->AREAS
, id
);
216 Global::Get()->bug("EditorMap::Map::Run() with areacount <= 0!\n");
217 return std::string("For some reason the area the room you are in does not belong to an area?!\n");
222 Area
* p
= Cache::Get()->GetArea(id
);
224 for(value_type y
= 1; y
<= p
->getHeight(); y
++)
228 std::string bottomrow
;
230 for(value_type x
= 1; x
<= p
->getWidth(); x
++)
232 long rid
= Cache::Get()->GetRoomID(id
, x
, y
);
233 long count
= DatabaseMgr::Get()->CountSavable(Tables::Get()->ROOMS
, rid
);
236 if(x
== origx
&& y
== origy
)
239 thisrow
.append (" o "); // Empty, current
240 bottomrow
.append(" ");
245 thisrow
.append (" . "); // Empty, not current
246 bottomrow
.append(" ");
252 Room
* room
= Cache::Get()->GetRoom(rid
);
254 if(!room
->isClosed(Exit::NORTHWEST
))
259 if(!room
->isClosed(Exit::NORTH
))
264 if(!room
->isClosed(Exit::NORTHEAST
))
269 if(!room
->isClosed(Exit::WEST
))
274 if(x
== origx
&& y
== origy
)
280 Sector
* sector
= Cache::Get()->GetSector(room
->getSector());
281 thisrow
.append(sector
->getSymbol());
284 if(!room
->isClosed(Exit::EAST
))
289 if(!room
->isClosed(Exit::SOUTHWEST
))
290 bottomrow
.append("/");
292 bottomrow
.append(" ");
294 if(!room
->isClosed(Exit::SOUTH
))
295 bottomrow
.append("|");
297 bottomrow
.append(" ");
299 if(!room
->isClosed(Exit::SOUTHEAST
))
300 bottomrow
.append("\\");
302 bottomrow
.append(" ");
306 result
.append(toprow
);
308 result
.append(thisrow
);
310 result
.append(bottomrow
);
318 SavableManagerPtr
Room::getManager() const
323 TableImplPtr
Room::getTable() const
325 return m_room
->getTable();
328 std::string
Room::toString() const
333 value_type roomid
= getID();
334 RoomPtr room
= mud::Managers::Get()->Room
->GetByKey(roomid
);
337 line
= room
->getDescription();
338 result
.push_back(line
);
340 Strings details
= mud::Managers::Get()->Detail
->ReadableList(room
);
343 for(Strings::const_iterator it
= details
.begin(); it
!= details
.end(); it
++) {
344 result
.push_back(*it
);
347 return String::Get()->unlines(result
, " ", 0);
350 std::string
Room::toFullString() const
352 return Savable::toString();