summaryrefslogtreecommitdiffstats
path: root/pokemod/Ability.cpp
blob: 0d05af7c96a55549690168016078380ec133de52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/////////////////////////////////////////////////////////////////////////////
// Name:        pokemod/Ability.cpp
// Purpose:     Define an ability that Pokémon can possess to add extra
//              dynamics to the battle system
// Author:      Ben Boeckel
// Modified by: Ben Boeckel
// Created:     Wed Feb 28 21:41:10 2007
// Copyright:   ©2007 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 2 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, write to the Free Software Foundation, Inc.,
//    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
/////////////////////////////////////////////////////////////////////////////

#include "Ability.h"

PokeGen::PokeMod::Ability::Ability(unsigned _id)
{
   LogCtor("Ability", id);
   name = "";
   effects.clear();
   id = _id;
}

PokeGen::PokeMod::Ability::Ability(Ini &ini, unsigned _id)
{
   LogCtorIni("Ability", id);
   ImportIni(ini, _id);
   if (id == UINT_MAX)
      LogIdError("Ability");
}

PokeGen::PokeMod::Ability::~Ability()
{
   LogDtor("Ability", id, name);
}

void PokeGen::PokeMod::Ability::Validate()
{
   isValid = true;
   LogValidateStart("Ability", id, name);
   // Make sure the name is set to something
   if (name == "")
   {
      LogVarNotSet("Ability", id, "Name", name);
      isValid = false;
   }
   // Check if there are any effects defined
   if (GetAbilityEffectCount())
   {
      // Validate each effect
      for (std::vector<AbilityEffect>::iterator i = effects.begin(); i != effects.end(); ++i)
      {
         LogSubmoduleIterate("Ability", id, "effect", i->GetId(), name);
         // If an effect isn't valid, neither is the ability
         if (!i->IsValid())
            isValid = false;
      }
   }
   else
   {
      LogSubmoduleEmpty("Ability", id, "effect", name);
      isValid = false;
   }
   LogValidateOver("Ability", id, isValid, name);
}

#ifdef PG_DEBUG_WINDOW
void PokeGen::PokeMod::Ability::Validate(const wxListBox &output)
{
   isValid = true;
   LogValidateStart("Ability", id, name);
   // Make sure the name is set to something
   if (name == "")
   {
      LogVarNotSet("Ability", id, "Name", name);
      output.Append(ConsoleLogVarNotSet("Ability", id, "Name", name));
      isValid = false;
   }
   // Check if there are any effects defined
   if (GetAbilityEffectCount())
   {
      // Validate each effect
      for (std::vector<AbilityEffect>::iterator i = effects.begin(); i != effects.end(); ++i)
      {
         LogSubmoduleIterate("Ability", id, "effect", i->GetId(), name);
         // If an effect isn't valid, neither is the ability
         if (!i->IsValid())
            isValid = false;
      }
   }
   else
   {
      LogSubmoduleEmpty("Ability", id, "effect", id, name);
      output.Append(ConsoleLogSubmoduleEmpty("Ability", id, "effect", name));
      isValid = false;
   }
   LogValidateOver("Ability", id, isValid, name);
}
#endif

void PokeGen::PokeMod::Ability::ImportIni(Ini &ini, unsigned _id)
{
   LogImportStart("Ability");
   if (_id == UINT_MAX)
   {
      ini.GetValue("id", id, UINT_MAX);
      // Was there an id associated with the element?
      if (id == UINT_MAX)
         LogIdNotFound("Ability");
   }
   else
      id = _id;
   ini.GetValue("name", name, "");
   LogImportOver("Ability", id, name);
}

void PokeGen::PokeMod::Ability::ExportIni(std::ofstream &fout) const
{
   LogExportStart("Ability", id, name);
   // Make elements
   Ini exAbility("ability");
   exAbility.AddField("id", id);
   exAbility.AddField("name", name);
   exAbility.Export(fout);
   for (std::vector<AbilityEffect>::iterator i = effects.begin(); i != effects.end(); ++i)
      i->ExportIni(fout, name);
   LogExportOver("Ability", id, name);
}

void PokeGen::PokeMod::Ability::SetName(const String &n)
{
   LogSetVar("Ability", id, "name", id, n);
   name = n;
}

PokeGen::PokeMod::String PokeGen::PokeMod::Ability::GetName() const
{
   LogFetchVar("Ability", id, "name", name);
   return name;
}

PokeGen::PokeMod::AbilityEffect *PokeGen::PokeMod::Ability::GetAbilityEffect(unsigned _id)
{
   LogSubmoduleFetch("Ability", id, "effect", _id, name);
   for (unsigned i = 0; i < GetAbilityEffectCount(); ++i)
   {
      if (effects[i].GetId() == _id)
         return &effects[i];
   }
   LogSubmoduleFetch("Ability", id, "effect", _id, name);
   return NULL;
}

unsigned PokeGen::PokeMod::Ability::GetAbilityEffectCount() const
{
   LogSubmoduleCount("Ability", id, "effects", name);
   return effects.size();
}

void PokeGen::PokeMod::Ability::NewAbilityEffect(Ini *const ini)
{
   unsigned i = 0;
   // Find the first unused ID in the vector
   for (; i < GetAbilityEffectCount(); ++i)
   {
      if (!GetAbilityEffect(i))
         break;
   }
   AbilityEffect newAbilityEffect(i);
   if (ini)
      newAbilityEffect.ImportIni(*ini);
   LogSubmoduleNew("Ability", id, "effect", i, name);
   effects.push_back(newAbilityEffect);
}

void PokeGen::PokeMod::Ability::DeleteAbilityEffect(unsigned _id)
{
   LogSubmoduleRemoveStart("Ability", id, "effect", _id, name);
   for (std::vector<AbilityEffect>::iterator i = effects.begin(); i != effects.end(); ++i)
   {
      if (i->GetId() == _id)
      {
         LogSubmoduleRemoved("Ability", id, "effect", _id, name);
         effects.erase(i);
      }
   }
   LogSubmoduleRemoveFail("Ability", id, "effect", _id, name);
}