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 Global::Get()->bugf("EditorMap::Map::Run() with areacount '%d'!\n", count
);
223 return std::string(Global::Get()->sprintf("For some reason the area the room you are in exists multiple times in the database?!n"));
226 Area
* p
= Cache::Get()->GetArea(id
);
228 for(value_type y
= 1; y
<= p
->getHeight(); y
++)
232 std::string bottomrow
;
234 for(value_type x
= 1; x
<= p
->getWidth(); x
++)
236 long rid
= Cache::Get()->GetRoomID(id
, x
, y
);
237 long count
= DatabaseMgr::Get()->CountSavable(Tables::Get()->ROOMS
, rid
);
240 if(x
== origx
&& y
== origy
)
243 thisrow
.append (" o "); // Empty, current
244 bottomrow
.append(" ");
249 thisrow
.append (" . "); // Empty, not current
250 bottomrow
.append(" ");
256 Room
* room
= Cache::Get()->GetRoom(rid
);
258 if(!room
->isClosed(Exit::NORTHWEST
))
263 if(!room
->isClosed(Exit::NORTH
))
268 if(!room
->isClosed(Exit::NORTHEAST
))
273 if(!room
->isClosed(Exit::WEST
))
278 if(x
== origx
&& y
== origy
)
284 Sector
* sector
= Cache::Get()->GetSector(room
->getSector());
285 thisrow
.append(sector
->getSymbol());
288 if(!room
->isClosed(Exit::EAST
))
293 if(!room
->isClosed(Exit::SOUTHWEST
))
294 bottomrow
.append("/");
296 bottomrow
.append(" ");
298 if(!room
->isClosed(Exit::SOUTH
))
299 bottomrow
.append("|");
301 bottomrow
.append(" ");
303 if(!room
->isClosed(Exit::SOUTHEAST
))
304 bottomrow
.append("\\");
306 bottomrow
.append(" ");
310 result
.append(toprow
);
312 result
.append(thisrow
);
314 result
.append(bottomrow
);
322 SavableManagerPtr
Room::getManager() const
327 TableImplPtr
Room::getTable() const
329 return m_room
->getTable();
332 std::string
Room::toString()
337 value_type roomid
= getID();
338 RoomPtr room
= mud::Managers::Get()->Room
->GetByKey(roomid
);
341 line
= room
->getDescription();
342 result
.push_back(line
);
344 Strings details
= mud::Managers::Get()->Detail
->ReadableList(room
);
347 for(Strings::const_iterator it
= details
.begin(); it
!= details
.end(); it
++) {
348 result
.push_back(*it
);
351 return String::Get()->unlines(result
, " ", 0);