summaryrefslogtreecommitdiffstats
path: root/pokemod/Tile.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'pokemod/Tile.cpp')
-rw-r--r--pokemod/Tile.cpp291
1 files changed, 139 insertions, 152 deletions
diff --git a/pokemod/Tile.cpp b/pokemod/Tile.cpp
index 2ef974b8..0c7a8195 100644
--- a/pokemod/Tile.cpp
+++ b/pokemod/Tile.cpp
@@ -1,274 +1,261 @@
-/////////////////////////////////////////////////////////////////////////////
-// Name: pokemod/Tile.cpp
-// Purpose: Define a tile for the map
-// Author: Ben Boeckel
-// Modified by: Ben Boeckel
-// Created: Thu May 31 2007 13:52:39
-// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions
-// Licence:
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License along
-// with this program. If not, see <http://www.gnu.org/licenses/>.
-/////////////////////////////////////////////////////////////////////////////
+/*
+ * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+// Pokemod includes
#include "Pokemod.h"
+
+// Header include
#include "Tile.h"
const QStringList Tile::ForceStr = QStringList() << "Slip" << "Stop" << "Force" << "Push";
-Tile::Tile(const Pokemod* par, const int _id) :
- Object("Tile", par, _id),
- name(""),
- wildChance(1, 1),
- hmType(-1),
- under(-1),
- forceType(-1),
- forceDirection(-1)
+Tile::Tile(const Pokemod* pokemod, const int id) :
+ Object("Tile", pokemod, id),
+ m_name(""),
+ m_wildChance(1, 1),
+ m_hmType(INT_MAX),
+ m_under(INT_MAX),
+ m_forceType(INT_MAX),
+ m_forceDirection(INT_MAX)
{
for (int i = 0; i < Pokemod::D_End; ++i)
- from[i] = false;
+ m_from[i] = false;
}
-Tile::Tile(const Pokemod* par, const Tile& t, const int _id) :
- Object("Tile", par, _id)
+Tile::Tile(const Pokemod* pokemod, const Tile& tile, const int id) :
+ Object("Tile", pokemod, id)
{
- *this = t;
+ *this = tile;
}
-Tile::Tile(const Pokemod* par, const QString& fname, const int _id) :
- Object("Tile", par, _id)
+Tile::Tile(const Pokemod* pokemod, const QString& fileName, const int id) :
+ Object("Tile", pokemod, id)
{
- load(fname, _id);
+ load(fileName, id);
}
bool Tile::validate() const
{
bool valid = true;
- pokemod->validationMsg(QString("---Tile \"%1\" with id %2---").arg(name).arg(id), Pokemod::V_Msg);
- if (name == "")
+ pokemod()->validationMsg(QString("---Tile \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg);
+ if (m_name == "")
{
- pokemod->validationMsg("Name is not defined");
+ pokemod()->validationMsg("Name is not defined");
valid = false;
}
- if (!QFile::exists(getPic()))
+ if (!QFile::exists(pic()))
{
- pokemod->validationMsg("Cannot find tile image");
+ pokemod()->validationMsg("Cannot find tile image");
valid = false;
}
- if ((hmType == Pokemod::HM_Waterfall) && (!from[Pokemod::D_Up] || !from[Pokemod::D_Down]))
+ if ((m_hmType == Pokemod::HM_Waterfall) && (!m_from[Pokemod::D_Up] || !m_from[Pokemod::D_Down]))
{
- pokemod->validationMsg("A waterfall tile must be accessible from above and below");
+ pokemod()->validationMsg("A waterfall tile must be accessible from above and below");
valid = false;
}
- else if ((hmType == Pokemod::HM_Whirlpool) && ((under == id) || (pokemod->getTileIndex(under) == -1) || (pokemod->getTileByID(under)->getHMType() != Pokemod::HM_Surf) || (pokemod->getTileByID(under)->getHMType() != Pokemod::HM_Dive)))
+ else if ((m_hmType == Pokemod::HM_Whirlpool) && ((m_under == id()) || (pokemod()->tileIndex(m_under) == INT_MAX) || (pokemod()->tileById(m_under)->hmType() != Pokemod::HM_Surf) || (pokemod()->tileById(m_under)->hmType() != Pokemod::HM_Dive)))
{
- pokemod->validationMsg("Invalid under tile");
+ pokemod()->validationMsg("Invalid under tile");
valid = false;
}
- else if ((hmType == Pokemod::HM_Whirlpool) && ((under == id) || (pokemod->getTileIndex(under) == -1) || (pokemod->getTileByID(under)->getHMType() != Pokemod::HM_End)))
+ else if ((m_hmType == Pokemod::HM_Whirlpool) && ((m_under == id()) || (pokemod()->tileIndex(m_under) == INT_MAX) || (pokemod()->tileById(m_under)->hmType() != Pokemod::HM_End)))
{
- pokemod->validationMsg("Invalid under tile");
+ pokemod()->validationMsg("Invalid under tile");
valid = false;
}
- else if ((hmType == Pokemod::HM_RockClimb) && (!from[Pokemod::D_Up] || !from[Pokemod::D_Down]))
+ else if ((m_hmType == Pokemod::HM_RockClimb) && (!m_from[Pokemod::D_Up] || !m_from[Pokemod::D_Down]))
{
- pokemod->validationMsg("A rock climb tile must be accessible from above and below");
+ pokemod()->validationMsg("A rock climb tile must be accessible from above and below");
valid = false;
}
- if (forceType < End)
+ if (m_forceType < End)
{
- if (((forceType == Slip) || (forceType == Force) || (forceType == Push)) && (Pokemod::D_End <= forceDirection))
+ if (((m_forceType == Slip) || (m_forceType == Force) || (m_forceType == Push)) && (Pokemod::D_End <= m_forceDirection))
{
- pokemod->validationMsg("Invalid force direction");
+ pokemod()->validationMsg("Invalid force direction");
valid = false;
}
}
else
{
- pokemod->validationMsg("Invalid force type");
+ pokemod()->validationMsg("Invalid force type");
valid = false;
}
return valid;
}
-void Tile::load(const QString& fname, const int _id) throw(Exception)
+void Tile::load(const QString& fileName, int id) throw(Exception)
{
- Ini ini(fname);
- if (_id == -1)
+ Ini ini(fileName);
+ if (id == INT_MAX)
ini.getValue("id", id);
- else
- id = _id;
+ setId(id);
int i;
int j;
- ini.getValue("name", name);
- ini.getValue("from-up", from[Pokemod::D_Up], false);
- ini.getValue("from-down", from[Pokemod::D_Down], false);
- ini.getValue("from-left", from[Pokemod::D_Left], false);
- ini.getValue("from-right", from[Pokemod::D_Right], false);
+ ini.getValue("name", m_name);
+ ini.getValue("from-up", m_from[Pokemod::D_Up], false);
+ ini.getValue("from-down", m_from[Pokemod::D_Down], false);
+ ini.getValue("from-left", m_from[Pokemod::D_Left], false);
+ ini.getValue("from-right", m_from[Pokemod::D_Right], false);
ini.getValue("wildChance-n", i, 1);
ini.getValue("wildChance-d", j, 1);
- wildChance.set(i, j);
- ini.getValue("hmType", hmType);
- ini.getValue("under", under);
- ini.getValue("forceType", forceType);
- ini.getValue("forceDirection", forceDirection);
+ m_wildChance.set(i, j);
+ ini.getValue("hmType", m_hmType);
+ ini.getValue("under", m_under);
+ ini.getValue("forceType", m_forceType);
+ ini.getValue("forceDirection", m_forceDirection);
}
void Tile::save() const throw(Exception)
{
Ini ini;
- ini.addField("id", id);
- ini.addField("name", name);
- ini.addField("from-up", from[Pokemod::D_Up]);
- ini.addField("from-down", from[Pokemod::D_Down]);
- ini.addField("from-left", from[Pokemod::D_Left]);
- ini.addField("from-right", from[Pokemod::D_Right]);
- ini.addField("wildChance-n", wildChance.getNum());
- ini.addField("wildChance-d", wildChance.getDenom());
- ini.addField("hmType", hmType);
- ini.addField("under", under);
- ini.addField("forceType", forceType);
- ini.addField("forceDirection", forceDirection);
- ini.save(QString("%1/tile/%2.pini").arg(pokemod->getPath()).arg(name));
+ ini.addField("id", id());
+ ini.addField("name", m_name);
+ ini.addField("from-up", m_from[Pokemod::D_Up]);
+ ini.addField("from-down", m_from[Pokemod::D_Down]);
+ ini.addField("from-left", m_from[Pokemod::D_Left]);
+ ini.addField("from-right", m_from[Pokemod::D_Right]);
+ ini.addField("wildChance-n", m_wildChance.numerator());
+ ini.addField("wildChance-d", m_wildChance.denominator());
+ ini.addField("hmType", m_hmType);
+ ini.addField("under", m_under);
+ ini.addField("forceType", m_forceType);
+ ini.addField("forceDirection", m_forceDirection);
+ ini.save(QString("%1/tile/%2.pini").arg(pokemod()->path()).arg(m_name));
}
-void Tile::setName(const QString& n)
+void Tile::setName(const QString& name)
{
- name = n;
+ m_name = name;
}
-void Tile::setPic(const QString& fname) throw(Exception)
+void Tile::setPic(const QString& fileName) throw(Exception)
{
- QFile file(getPic());
+ QFile file(pic());
if (file.exists() && !file.remove())
- throw(RemoveException(className, file.fileName()));
- if (!QFile::copy(fname, getPic()))
- throw(SaveException(className, file.fileName()));
-}
-
-void Tile::setFrom(const int d, const bool f) throw(BoundsException)
-{
- if (Pokemod::D_End <= d)
- throw(BoundsException(className, "direction"));
- from[d] = f;
-}
-
-void Tile::setWildChance(const int n, const int d) throw(Exception)
-{
- wildChance.set(n, d);
+ throw(RemoveException(className(), file.fileName()));
+ if (!QFile::copy(fileName, pic()))
+ throw(SaveException(className(), file.fileName()));
}
-void Tile::setWildChanceNum(const int n) throw(Exception)
+void Tile::setFrom(const int direction, const bool state) throw(BoundsException)
{
- wildChance.setNum(n);
+ if (Pokemod::D_End <= direction)
+ throw(BoundsException(className(), "direction"));
+ m_from[direction] = state;
}
-void Tile::setWildChanceDenom(const int d) throw(Exception)
+void Tile::setWildChance(const int numerator, const int denominator) throw(Exception)
{
- wildChance.setDenom(d);
+ m_wildChance.set(numerator, denominator);
}
-void Tile::setHMType(const int h) throw(BoundsException)
+void Tile::setHMType(const int hmType) throw(BoundsException)
{
- if (Pokemod::HM_End <= h)
- throw(BoundsException(className, "hmType"));
- hmType = h;
- under = -1;
+ if (Pokemod::HM_End <= hmType)
+ throw(BoundsException(className(), "hmType"));
+ m_hmType = hmType;
+ m_under = INT_MAX;
}
-void Tile::setUnder(const int u) throw(Exception)
+void Tile::setUnder(const int under) throw(Exception)
{
- if (hmType != -1)
+ if (m_hmType != INT_MAX)
{
- if ((hmType != Pokemod::HM_Whirlpool) || (hmType != Pokemod::HM_Cut) || (hmType != Pokemod::HM_RockSmash))
- throw(UnusedException(className, "under"));
- if ((u == id) || (pokemod->getTileIndex(u) == -1))
- throw(BoundsException(className, "under"));
+ if ((m_hmType != Pokemod::HM_Whirlpool) || (m_hmType != Pokemod::HM_Cut) || (m_hmType != Pokemod::HM_RockSmash))
+ throw(UnusedException(className(), "under"));
+ if ((under == id()) || (pokemod()->tileIndex(under) == INT_MAX))
+ throw(BoundsException(className(), "under"));
}
- under = u;
+ m_under = under;
}
-void Tile::setForceType(const int f) throw(BoundsException)
+void Tile::setForceType(const int forceType) throw(BoundsException)
{
- if (End <= f)
- throw(BoundsException(className, "forceType"));
- forceType = f;
+ if (End <= forceType)
+ throw(BoundsException(className(), "forceType"));
+ m_forceType = forceType;
}
-void Tile::setForceDirection(const int f) throw(Exception)
+void Tile::setForceDirection(const int forceDirection) throw(Exception)
{
- if (forceType != -1)
+ if (m_forceType != INT_MAX)
{
- if (forceType == Stop)
- throw(UnusedException(className, "forceDirection"));
- if (Pokemod::D_End <= f)
- throw(BoundsException(className, "forceDirection"));
+ if (m_forceType == Stop)
+ throw(UnusedException(className(), "forceDirection"));
+ if (Pokemod::D_End <= forceDirection)
+ throw(BoundsException(className(), "forceDirection"));
}
- forceDirection = f;
+ m_forceDirection = forceDirection;
}
-QString Tile::getName() const
+QString Tile::name() const
{
- return name;
+ return m_name;
}
-QString Tile::getPic() const
+QString Tile::pic() const
{
- return QString("%1/tile/%2.png").arg(pokemod->getPath()).arg(name);
+ return QString("%1/tile/%2.png").arg(pokemod()->path()).arg(m_name);
}
-bool Tile::getFrom(const int d) const throw(BoundsException)
+bool Tile::from(const int direction) const throw(BoundsException)
{
- if (Pokemod::D_End <= d)
- throw(BoundsException(className, "direction"));
- return from[d];
+ if (Pokemod::D_End <= direction)
+ throw(BoundsException(className(), "direction"));
+ return m_from[direction];
}
-Frac Tile::getWildChance() const
+Frac Tile::wildChance() const
{
- return wildChance;
+ return m_wildChance;
}
-int Tile::getHMType() const
+int Tile::hmType() const
{
- return hmType;
+ return m_hmType;
}
-int Tile::getUnder() const
+int Tile::under() const
{
- return under;
+ return m_under;
}
-int Tile::getForceType() const
+int Tile::forceType() const
{
- return forceType;
+ return m_forceType;
}
-int Tile::getForceDirection() const
+int Tile::forceDirection() const
{
- return forceDirection;
+ return m_forceDirection;
}
Tile& Tile::operator=(const Tile& rhs)
{
if (this == &rhs)
return *this;
- name = rhs.name;
+ m_name = rhs.m_name;
for (int i = 0; i < Pokemod::D_End; ++i)
- from[i] = rhs.from[i];
- wildChance = rhs.wildChance;
- hmType = rhs.hmType;
- under = rhs.under;
- forceType = rhs.forceType;
- forceDirection = rhs.forceDirection;
+ m_from[i] = rhs.m_from[i];
+ m_wildChance = rhs.m_wildChance;
+ m_hmType = rhs.m_hmType;
+ m_under = rhs.m_under;
+ m_forceType = rhs.m_forceType;
+ m_forceDirection = rhs.m_forceDirection;
return *this;
}