summaryrefslogtreecommitdiffstats
path: root/pokemod/Pokemod.cpp
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2008-05-28 00:59:52 +0000
committerBen Boeckel <MathStuf@gmail.com>2008-05-28 00:59:52 +0000
commit4d705de01059eb04b19db68a11cea1c57084c57a (patch)
treefa6deaba07d19041c21deca010b006931dc6abe0 /pokemod/Pokemod.cpp
parent8cbe19a3e1845657ccdfddbd3c4fffcaadb9ff55 (diff)
downloadsigen-4d705de01059eb04b19db68a11cea1c57084c57a.tar.gz
sigen-4d705de01059eb04b19db68a11cea1c57084c57a.tar.xz
sigen-4d705de01059eb04b19db68a11cea1c57084c57a.zip
[FIX] Typechart now works
[FIX] Matrix fixed up [FIX] Pokemod map widget fixed up [FIX] FractionWidget sets stuff on ctor [FIX] Assertion used in pokemod rather than returning NULL [FIX] Fixed a bad compare in Type git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@180 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokemod/Pokemod.cpp')
-rw-r--r--pokemod/Pokemod.cpp236
1 files changed, 81 insertions, 155 deletions
diff --git a/pokemod/Pokemod.cpp b/pokemod/Pokemod.cpp
index 414cb578..dd342ce7 100644
--- a/pokemod/Pokemod.cpp
+++ b/pokemod/Pokemod.cpp
@@ -64,7 +64,7 @@ Pokemod::Pokemod() :
m_flySkin(192, 128),
m_fishSkin(192, 128),
m_surfFishSkin(192, 128),
- m_typeChart(0, 0),
+ m_typechart(0, 0),
m_rules(new Rules(this))
{
}
@@ -104,7 +104,7 @@ void Pokemod::validate()
if (mapById(m_startMap)->warpIndex(m_startWarp) == INT_MAX)
emit(error("Invalid starting warp"));
}
- if ((m_typeChart.width() != typeCount()) || (m_typeChart.height() != typeCount()))
+ if ((m_typechart.width() != typeCount()) || (m_typechart.height() != typeCount()))
emit(error("Type chart is invalid"));
m_rules->validate();
QSet<int> idChecker;
@@ -438,7 +438,7 @@ void Pokemod::load(const QDomElement& xml, const int)
LOAD_SUB(newTrainer, Trainer);
LOAD_SUB(newType, Type);
LOAD_SUB(newWeather, Weather);
- LOAD_MATRIX(setTypeChart, Fraction, typeChart);
+ LOAD_Typechart(setTypechart, Fraction, typechart);
}
QDomElement Pokemod::save() const
@@ -456,7 +456,7 @@ QDomElement Pokemod::save() const
SAVE(QPixmap, fishSkin);
SAVE(QPixmap, surfFishSkin);
SAVE_Rules(rules);
- SAVE_MATRIX(Fraction, typeChart);
+ SAVE_MATRIX(Fraction, typechart);
SAVE_SUB(Ability, abilities);
SAVE_SUB(Author, authors);
SAVE_SUB(Badge, badges);
@@ -592,9 +592,9 @@ void Pokemod::setSurfFishSkin(const QPixmap& surfFishSkin)
emit(changed());
}
-void Pokemod::setTypeChart(const int attack, const int defense, const Fraction& multiplier)
+void Pokemod::setTypechart(const int attack, const int defense, const Fraction& multiplier)
{
- CHECK_ARRAY(typeChart(attack, defense), multiplier);
+ CHECK_ARRAY(typechart(attack, defense), multiplier);
}
void Pokemod::setRules(const Rules& rules)
@@ -662,19 +662,19 @@ QPixmap Pokemod::surfFishSkin() const
return m_surfFishSkin;
}
-const Matrix<Fraction>* Pokemod::typeChart() const
+const Matrix<Fraction>& Pokemod::typechart() const
{
- return &m_typeChart;
+ return m_typechart;
}
-Matrix<Fraction>* Pokemod::typeChart()
+Matrix<Fraction>& Pokemod::typechart()
{
- return &m_typeChart;
+ return m_typechart;
}
-Fraction Pokemod::typeChart(const int attack, const int defense) const
+Fraction Pokemod::typechart(const int attack, const int defense) const
{
- return m_typeChart(attack, defense);
+ return m_typechart(attack, defense);
}
const Rules* Pokemod::rules() const
@@ -689,15 +689,13 @@ Rules* Pokemod::rules()
const Ability* Pokemod::ability(const int index) const
{
- if (abilityCount() <= index)
- return NULL;
+ Q_ASSERT(index < abilityCount());
return m_abilities.at(index);
}
Ability* Pokemod::ability(const int index)
{
- if (abilityCount() <= index)
- return NULL;
+ Q_ASSERT(index < abilityCount());
return m_abilities[index];
}
@@ -749,8 +747,7 @@ Ability* Pokemod::newAbility(Ability* ability)
void Pokemod::deleteAbility(const int index)
{
- if (abilityCount() <= index)
- return;
+ Q_ASSERT(index < abilityCount());
delete m_abilities[index];
m_abilities.removeAt(index);
}
@@ -770,15 +767,13 @@ int Pokemod::newAbilityId() const
const Author* Pokemod::author(const int index) const
{
- if (authorCount() <= index)
- return NULL;
+ Q_ASSERT(index < authorCount());
return m_authors.at(index);
}
Author* Pokemod::author(const int index)
{
- if (authorCount() <= index)
- return NULL;
+ Q_ASSERT(index < authorCount());
return m_authors[index];
}
@@ -830,8 +825,7 @@ Author* Pokemod::newAuthor(Author* author)
void Pokemod::deleteAuthor(const int index)
{
- if (authorCount() <= index)
- return;
+ Q_ASSERT(index < authorCount());
delete m_authors[index];
m_authors.removeAt(index);
}
@@ -851,15 +845,13 @@ int Pokemod::newAuthorId() const
const Badge* Pokemod::badge(const int index) const
{
- if (badgeCount() <= index)
- return NULL;
+ Q_ASSERT(index < badgeCount());
return m_badges.at(index);
}
Badge* Pokemod::badge(const int index)
{
- if (badgeCount() <= index)
- return NULL;
+ Q_ASSERT(index < badgeCount());
return m_badges[index];
}
@@ -911,8 +903,7 @@ Badge* Pokemod::newBadge(Badge* badge)
void Pokemod::deleteBadge(const int index)
{
- if (badgeCount() <= index)
- return;
+ Q_ASSERT(index < badgeCount());
delete m_badges[index];
m_badges.removeAt(index);
}
@@ -932,15 +923,13 @@ int Pokemod::newBadgeId() const
const CoinList* Pokemod::coinList(const int index) const
{
- if (coinListCount() <= index)
- return NULL;
+ Q_ASSERT(index < coinListCount());
return m_coinLists.at(index);
}
CoinList* Pokemod::coinList(const int index)
{
- if (coinListCount() <= index)
- return NULL;
+ Q_ASSERT(index < coinListCount());
return m_coinLists[index];
}
@@ -992,8 +981,7 @@ CoinList* Pokemod::newCoinList(CoinList* coinList)
void Pokemod::deleteCoinList(const int index)
{
- if (coinListCount() <= index)
- return;
+ Q_ASSERT(index < coinListCount());
delete m_coinLists[index];
m_coinLists.removeAt(index);
}
@@ -1013,15 +1001,13 @@ int Pokemod::newCoinListId() const
const EggGroup* Pokemod::eggGroup(const int index) const
{
- if (eggGroupCount() <= index)
- return NULL;
+ Q_ASSERT(index < eggGroupCount());
return m_eggGroups.at(index);
}
EggGroup* Pokemod::eggGroup(const int index)
{
- if (eggGroupCount() <= index)
- return NULL;
+ Q_ASSERT(index < eggGroupCount());
return m_eggGroups[index];
}
@@ -1073,8 +1059,7 @@ EggGroup* Pokemod::newEggGroup(EggGroup* eggGroup)
void Pokemod::deleteEggGroup(const int index)
{
- if (eggGroupCount() <= index)
- return;
+ Q_ASSERT(index < eggGroupCount());
delete m_eggGroups[index];
m_eggGroups.removeAt(index);
}
@@ -1094,15 +1079,13 @@ int Pokemod::newEggGroupId() const
const GlobalScript* Pokemod::globalScript(const int index) const
{
- if (globalScriptCount() <= index)
- return NULL;
+ Q_ASSERT(index < globalScriptCount());
return m_globalScripts.at(index);
}
GlobalScript* Pokemod::globalScript(const int index)
{
- if (globalScriptCount() <= index)
- return NULL;
+ Q_ASSERT(index < globalScriptCount());
return m_globalScripts[index];
}
@@ -1154,8 +1137,7 @@ GlobalScript* Pokemod::newGlobalScript(GlobalScript* globalScript)
void Pokemod::deleteGlobalScript(const int index)
{
- if (globalScriptCount() <= index)
- return;
+ Q_ASSERT(index < globalScriptCount());
delete m_globalScripts[index];
m_globalScripts.removeAt(index);
}
@@ -1175,15 +1157,13 @@ int Pokemod::newGlobalScriptId() const
const Item* Pokemod::item(const int index) const
{
- if (itemCount() <= index)
- return NULL;
+ Q_ASSERT(index < itemCount());
return m_items.at(index);
}
Item* Pokemod::item(const int index)
{
- if (itemCount() <= index)
- return NULL;
+ Q_ASSERT(index < itemCount());
return m_items[index];
}
@@ -1235,8 +1215,7 @@ Item* Pokemod::newItem(Item* item)
void Pokemod::deleteItem(const int index)
{
- if (itemCount() <= index)
- return;
+ Q_ASSERT(index < itemCount());
delete m_items[index];
m_items.removeAt(index);
}
@@ -1256,15 +1235,13 @@ int Pokemod::newItemId() const
const ItemType* Pokemod::itemType(const int index) const
{
- if (itemTypeCount() <= index)
- return NULL;
+ Q_ASSERT(index < itemTypeCount());
return m_itemTypes.at(index);
}
ItemType* Pokemod::itemType(const int index)
{
- if (itemTypeCount() <= index)
- return NULL;
+ Q_ASSERT(index < itemTypeCount());
return m_itemTypes[index];
}
@@ -1316,8 +1293,7 @@ ItemType* Pokemod::newItemType(ItemType* itemType)
void Pokemod::deleteItemType(const int index)
{
- if (itemTypeCount() <= index)
- return;
+ Q_ASSERT(index < itemTypeCount());
delete m_itemTypes[index];
m_itemTypes.removeAt(index);
}
@@ -1337,15 +1313,13 @@ int Pokemod::newItemTypeId() const
const Map* Pokemod::map(const int index) const
{
- if (mapCount() <= index)
- return NULL;
+ Q_ASSERT(index < mapCount());
return m_maps.at(index);
}
Map* Pokemod::map(const int index)
{
- if (mapCount() <= index)
- return NULL;
+ Q_ASSERT(index < mapCount());
return m_maps[index];
}
@@ -1397,8 +1371,7 @@ Map* Pokemod::newMap(Map* map)
void Pokemod::deleteMap(const int index)
{
- if (mapCount() <= index)
- return;
+ Q_ASSERT(index < mapCount());
delete m_maps[index];
m_maps.removeAt(index);
}
@@ -1418,15 +1391,13 @@ int Pokemod::newMapId() const
const Move* Pokemod::move(const int index) const
{
- if (moveCount() <= index)
- return NULL;
+ Q_ASSERT(index < moveCount());
return m_moves.at(index);
}
Move* Pokemod::move(const int index)
{
- if (moveCount() <= index)
- return NULL;
+ Q_ASSERT(index < moveCount());
return m_moves[index];
}
@@ -1478,8 +1449,7 @@ Move* Pokemod::newMove(Move* move)
void Pokemod::deleteMove(const int index)
{
- if (moveCount() <= index)
- return;
+ Q_ASSERT(index < moveCount());
delete m_moves[index];
m_moves.removeAt(index);
}
@@ -1499,15 +1469,13 @@ int Pokemod::newMoveId() const
const Nature* Pokemod::nature(const int index) const
{
- if (natureCount() <= index)
- return NULL;
+ Q_ASSERT(index < natureCount());
return m_natures.at(index);
}
Nature* Pokemod::nature(const int index)
{
- if (natureCount() <= index)
- return NULL;
+ Q_ASSERT(index < natureCount());
return m_natures[index];
}
@@ -1559,8 +1527,7 @@ Nature* Pokemod::newNature(Nature* nature)
void Pokemod::deleteNature(const int index)
{
- if (natureCount() <= index)
- return;
+ Q_ASSERT(index < natureCount());
delete m_natures[index];
m_natures.removeAt(index);
}
@@ -1580,15 +1547,13 @@ int Pokemod::newNatureId() const
const Sound* Pokemod::sound(const int index) const
{
- if (soundCount() <= index)
- return NULL;
+ Q_ASSERT(index < soundCount());
return m_sounds.at(index);
}
Sound* Pokemod::sound(const int index)
{
- if (soundCount() <= index)
- return NULL;
+ Q_ASSERT(index < soundCount());
return m_sounds[index];
}
@@ -1640,8 +1605,7 @@ Sound* Pokemod::newSound(Sound* sound)
void Pokemod::deleteSound(const int index)
{
- if (soundCount() <= index)
- return;
+ Q_ASSERT(index < soundCount());
delete m_sounds[index];
m_sounds.removeAt(index);
}
@@ -1661,15 +1625,13 @@ int Pokemod::newSoundId() const
const Species* Pokemod::species(const int index) const
{
- if (speciesCount() <= index)
- return NULL;
+ Q_ASSERT(index < speciesCount());
return m_species.at(index);
}
Species* Pokemod::species(const int index)
{
- if (speciesCount() <= index)
- return NULL;
+ Q_ASSERT(index < speciesCount());
return m_species[index];
}
@@ -1721,8 +1683,7 @@ Species* Pokemod::newSpecies(Species* species)
void Pokemod::deleteSpecies(const int index)
{
- if (speciesCount() <= index)
- return;
+ Q_ASSERT(index < speciesCount());
delete m_species[index];
m_species.removeAt(index);
}
@@ -1742,15 +1703,13 @@ int Pokemod::newSpeciesId() const
const Sprite* Pokemod::sprite(const int index) const
{
- if (spriteCount() <= index)
- return NULL;
+ Q_ASSERT(index < spriteCount());
return m_sprites.at(index);
}
Sprite* Pokemod::sprite(const int index)
{
- if (spriteCount() <= index)
- return NULL;
+ Q_ASSERT(index < spriteCount());
return m_sprites[index];
}
@@ -1802,8 +1761,7 @@ Sprite* Pokemod::newSprite(Sprite* sprite)
void Pokemod::deleteSprite(const int index)
{
- if (spriteCount() <= index)
- return;
+ Q_ASSERT(index < spriteCount());
delete m_sprites[index];
m_sprites.removeAt(index);
}
@@ -1823,15 +1781,13 @@ int Pokemod::newSpriteId() const
const Status* Pokemod::status(const int index) const
{
- if (statusCount() <= index)
- return NULL;
+ Q_ASSERT(index < statusCount());
return m_status.at(index);
}
Status* Pokemod::status(const int index)
{
- if (statusCount() <= index)
- return NULL;
+ Q_ASSERT(index < statusCount());
return m_status[index];
}
@@ -1883,8 +1839,7 @@ Status* Pokemod::newStatus(Status* status)
void Pokemod::deleteStatus(const int index)
{
- if (statusCount() <= index)
- return;
+ Q_ASSERT(index < statusCount());
delete m_status[index];
m_status.removeAt(index);
}
@@ -1904,15 +1859,13 @@ int Pokemod::newStatusId() const
const Store* Pokemod::store(const int index) const
{
- if (storeCount() <= index)
- return NULL;
+ Q_ASSERT(index < storeCount());
return m_stores.at(index);
}
Store* Pokemod::store(const int index)
{
- if (storeCount() <= index)
- return NULL;
+ Q_ASSERT(index < storeCount());
return m_stores[index];
}
@@ -1964,8 +1917,7 @@ Store* Pokemod::newStore(Store* store)
void Pokemod::deleteStore(const int index)
{
- if (storeCount() <= index)
- return;
+ Q_ASSERT(index < storeCount());
delete m_stores[index];
m_stores.removeAt(index);
}
@@ -1985,15 +1937,13 @@ int Pokemod::newStoreId() const
const Tile* Pokemod::tile(const int index) const
{
- if (tileCount() <= index)
- return NULL;
+ Q_ASSERT(index < tileCount());
return m_tiles.at(index);
}
Tile* Pokemod::tile(const int index)
{
- if (tileCount() <= index)
- return NULL;
+ Q_ASSERT(index < tileCount());
return m_tiles[index];
}
@@ -2045,8 +1995,7 @@ Tile* Pokemod::newTile(Tile* tile)
void Pokemod::deleteTile(const int index)
{
- if (tileCount() <= index)
- return;
+ Q_ASSERT(index < tileCount());
delete m_tiles[index];
m_tiles.removeAt(index);
}
@@ -2066,16 +2015,14 @@ int Pokemod::newTileId() const
const Time* Pokemod::time(const int index) const
{
- if (timeCount() <= index)
- return NULL;
+ Q_ASSERT(index < timeCount());
return m_times.at(index);
}
-Time* Pokemod::time(const int i)
+Time* Pokemod::time(const int index)
{
- if (timeCount() <= i)
- return NULL;
- return m_times[i];
+ Q_ASSERT(index < timeCount());
+ return m_times[index];
}
const Time* Pokemod::timeById(const int id) const
@@ -2126,8 +2073,7 @@ Time* Pokemod::newTime(Time* time)
void Pokemod::deleteTime(const int index)
{
- if (timeCount() <= index)
- return;
+ Q_ASSERT(index < timeCount());
delete m_times[index];
m_times.removeAt(index);
}
@@ -2147,15 +2093,13 @@ int Pokemod::newTimeId() const
const Trainer* Pokemod::trainer(const int index) const
{
- if (trainerCount() <= index)
- return NULL;
+ Q_ASSERT(index < trainerCount());
return m_trainers.at(index);
}
Trainer* Pokemod::trainer(const int index)
{
- if (trainerCount() <= index)
- return NULL;
+ Q_ASSERT(index < trainerCount());
return m_trainers[index];
}
@@ -2207,8 +2151,7 @@ Trainer* Pokemod::newTrainer(Trainer* trainer)
void Pokemod::deleteTrainer(const int index)
{
- if (trainerCount() <= index)
- return;
+ Q_ASSERT(index < trainerCount());
delete m_trainers[index];
m_trainers.removeAt(index);
}
@@ -2228,15 +2171,13 @@ int Pokemod::newTrainerId() const
const Type* Pokemod::type(const int index) const
{
- if (typeCount() <= index)
- return NULL;
+ Q_ASSERT(index < typeCount());
return m_types.at(index);
}
Type* Pokemod::type(const int index)
{
- if (typeCount() <= index)
- return NULL;
+ Q_ASSERT(index < typeCount());
return m_types[index];
}
@@ -2282,30 +2223,17 @@ Type* Pokemod::newType(const Type& type)
Type* Pokemod::newType(Type* type)
{
- if (typeCount())
- {
- m_typeChart.addColumn(Fraction(1, 1));
- m_typeChart.addRow(Fraction(1, 1));
- }
- else
- m_typeChart.addColumn(Fraction(1, 1));
m_types.append(type);
+ m_typechart.resize(typeCount(), typeCount(), Fraction(1, 1));
return type;
}
void Pokemod::deleteType(const int index)
{
- if (typeCount() <= index)
- return;
+ Q_ASSERT(index < typeCount());
delete m_types[index];
- if (typeCount() == 1)
- m_typeChart.deleteColumn(index);
- else
- {
- m_typeChart.deleteColumn(index);
- m_typeChart.deleteRow(index);
- }
m_types.removeAt(index);
+ m_typechart.resize(typeCount(), typeCount(), Fraction(1, 1));
}
void Pokemod::deleteTypeById(const int id)
@@ -2323,15 +2251,13 @@ int Pokemod::newTypeId() const
const Weather* Pokemod::weather(const int index) const
{
- if (weatherCount() <= index)
- return NULL;
+ Q_ASSERT(index < weatherCount());
return m_weathers.at(index);
}
Weather* Pokemod::weather(const int index)
{
- if (weatherCount() <= index)
- return NULL;
+ Q_ASSERT(index < weatherCount());
return m_weathers[index];
}
@@ -2383,8 +2309,7 @@ Weather* Pokemod::newWeather(Weather* weather)
void Pokemod::deleteWeather(const int index)
{
- if (weatherCount() <= index)
- return;
+ Q_ASSERT(index < weatherCount());
delete m_weathers[index];
m_weathers.removeAt(index);
}
@@ -2412,7 +2337,7 @@ Pokemod& Pokemod::operator=(const Pokemod& rhs)
COPY(description);
COPY(startMap);
COPY(startWarp);
- COPY(typeChart);
+ COPY(typechart);
COPY_Rules(rules);
COPY_SUB(Ability, abilities);
COPY_SUB(Author, authors);
@@ -2435,6 +2360,7 @@ Pokemod& Pokemod::operator=(const Pokemod& rhs)
COPY_SUB(Trainer, trainers);
COPY_SUB(Type, types);
COPY_SUB(Weather, weathers);
+ m_typechart.resize(typeCount(), typeCount());
return *this;
}