Fix the silly values in the db by working around negative values.
[UnsignedByte.git] / src / DB / Savables / Exit.cpp
blob739bfa6fe40dcee81c59ab52a3da11242617779a
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 "Exit.h"
22 #include "Global.h"
23 #include "FieldImpls.h"
24 #include "TableImpls.h"
26 using mud::Exit;
28 Exit::Exit(SavableManagerPtr exit) :
29 m_exit(exit)
31 Assert(m_exit);
34 Exit::~Exit(void)
36 Unlock();
39 value_type Exit::getFromChunk() const
41 return m_exit->getValue(db::TableImpls::Get()->EXITS->FKCHUNKSFROM)->getIntegerValue();
44 value_type Exit::getToChunk() const
46 return m_exit->getValue(db::TableImpls::Get()->EXITS->FKCHUNKSTO)->getIntegerValue();
49 Coordinate Exit::getDirection() const
52 * The -1 is to correct from the +1 from below
54 int x = m_exit->getValue(db::TableImpls::Get()->EXITS->X)->getIntegerValue()-1;
55 int y = m_exit->getValue(db::TableImpls::Get()->EXITS->Y)->getIntegerValue()-1;
56 int z = m_exit->getValue(db::TableImpls::Get()->EXITS->Z)->getIntegerValue()-1;
58 Coordinate result(x, y, z);
59 return result;
62 void Exit::setFromChunk(value_type room)
64 Lock();
65 ValuePtr value(new FieldValue(db::TableImpls::Get()->EXITS->FKCHUNKSFROM, room));
66 m_exit->setValue(value);
69 void Exit::setToChunk(value_type room)
71 Lock();
72 ValuePtr value(new FieldValue(db::TableImpls::Get()->EXITS->FKCHUNKSTO, room));
73 m_exit->setValue(value);
76 void Exit::setDirection(const Coordinate& direction)
78 Assert(direction.isDirection());
80 Lock();
81 ValuePtr value;
84 * The +1 is to keep negative values from going into the database.
86 value = FieldValuePtr(new FieldValue(db::TableImpls::Get()->EXITS->X, direction.getXCoordinate()+1));
87 m_exit->setValue(value);
89 value = FieldValuePtr(new FieldValue(db::TableImpls::Get()->EXITS->Y, direction.getYCoordinate()+1));
90 m_exit->setValue(value);
92 value = FieldValuePtr(new FieldValue(db::TableImpls::Get()->EXITS->Z, direction.getZCoordinate()+1));
93 m_exit->setValue(value);
96 void Exit::Delete()
98 Lock();
99 m_exit->erase();
102 void Exit::Save()
104 Lock();
105 m_exit->save();
108 void Exit::Discard()
110 Lock();
111 m_exit->discard();
114 bool Exit::Exists()
116 return m_exit->exists();
119 SavableManagerPtr Exit::getManager() const
121 return m_exit;
124 TableImplPtr Exit::getTable() const
126 return m_exit->getTable();