3 from sqlalchemy
import Column
, ForeignKey
, MetaData
, Table
4 from sqlalchemy
.ext
.declarative
import declarative_base
5 from sqlalchemy
.ext
.associationproxy
import association_proxy
6 from sqlalchemy
.orm
import backref
, relation
7 from sqlalchemy
.sql
import and_
8 from sqlalchemy
.types
import *
10 from pokedex
.db
import rst
13 TableBase
= declarative_base(metadata
=metadata
)
15 class Ability(TableBase
):
16 __tablename__
= 'abilities'
17 __singlename__
= 'ability'
18 id = Column(Integer
, primary_key
=True, nullable
=False)
19 name
= Column(Unicode(24), nullable
=False)
20 flavor_text
= Column(Unicode(64), nullable
=False)
21 effect
= Column(Unicode(255), nullable
=False)
23 class ContestCombo(TableBase
):
24 __tablename__
= 'contest_combos'
25 first_move_id
= Column(Integer
, ForeignKey('moves.id'), primary_key
=True, nullable
=False, autoincrement
=False)
26 second_move_id
= Column(Integer
, ForeignKey('moves.id'), primary_key
=True, nullable
=False, autoincrement
=False)
28 class ContestEffect(TableBase
):
29 __tablename__
= 'contest_effects'
30 id = Column(Integer
, primary_key
=True, nullable
=False)
31 appeal
= Column(SmallInteger
, nullable
=False)
32 jam
= Column(SmallInteger
, nullable
=False)
33 flavor_text
= Column(Unicode(64), nullable
=False)
34 effect
= Column(Unicode(255), nullable
=False)
36 class EggGroup(TableBase
):
37 __tablename__
= 'egg_groups'
38 id = Column(Integer
, primary_key
=True, nullable
=False)
39 name
= Column(Unicode(16), nullable
=False)
41 class Encounter(TableBase
):
42 """Rows in this table represent encounters with wild Pokémon. Bear with
45 Within a given area in a given game, encounters are differentiated by the
46 "slot" they are in and the state of the game world.
48 What the player is doing to get an encounter, such as surfing or walking
49 through tall grass, is called terrain. Each terrain has its own set of
52 Within a terrain, slots are defined primarily by rarity. Each slot can
53 also be affected by world conditions; for example, the 20% slot for walking
54 in tall grass is affected by whether a swarm is in effect in that area.
55 "Is there a swarm?" is a condition; "there is a swarm" and "there is not a
56 swarm" are the possible values of this condition.
58 A slot (20% walking in grass) and any appropriate world conditions (no
59 swarm) are thus enough to define a specific encounter.
61 Well, okay, almost: each slot actually appears twice.
64 __tablename__
= 'encounters'
65 id = Column(Integer
, primary_key
=True, nullable
=False)
66 version_id
= Column(Integer
, ForeignKey('versions.id'), nullable
=False, autoincrement
=False)
67 location_area_id
= Column(Integer
, ForeignKey('location_areas.id'), nullable
=False, autoincrement
=False)
68 encounter_slot_id
= Column(Integer
, ForeignKey('encounter_slots.id'), nullable
=False, autoincrement
=False)
69 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), nullable
=False, autoincrement
=False)
70 min_level
= Column(Integer
, nullable
=False, autoincrement
=False)
71 max_level
= Column(Integer
, nullable
=False, autoincrement
=False)
73 class EncounterCondition(TableBase
):
74 """Rows in this table represent varying conditions in the game world, such
78 __tablename__
= 'encounter_conditions'
79 id = Column(Integer
, primary_key
=True, nullable
=False)
80 name
= Column(Unicode(64), nullable
=False)
82 class EncounterConditionValue(TableBase
):
83 """Rows in this table represent possible states for a condition; for
84 example, the state of 'swarm' could be 'swarm' or 'no swarm'.
87 __tablename__
= 'encounter_condition_values'
88 id = Column(Integer
, primary_key
=True, nullable
=False)
89 encounter_condition_id
= Column(Integer
, ForeignKey('encounter_conditions.id'), primary_key
=False, nullable
=False, autoincrement
=False)
90 name
= Column(Unicode(64), nullable
=False)
91 is_default
= Column(Boolean
, nullable
=False)
93 class EncounterConditionValueMap(TableBase
):
94 """Maps encounters to the specific conditions under which they occur."""
96 __tablename__
= 'encounter_condition_value_map'
97 encounter_id
= Column(Integer
, ForeignKey('encounters.id'), primary_key
=True, nullable
=False, autoincrement
=False)
98 encounter_condition_value_id
= Column(Integer
, ForeignKey('encounter_condition_values.id'), primary_key
=True, nullable
=False, autoincrement
=False)
100 class EncounterTerrain(TableBase
):
101 """Rows in this table represent ways the player can enter a wild encounter,
102 e.g., surfing, fishing, or walking through tall grass.
105 __tablename__
= 'encounter_terrain'
106 id = Column(Integer
, primary_key
=True, nullable
=False)
107 name
= Column(Unicode(64), nullable
=False)
109 class EncounterSlot(TableBase
):
110 """Rows in this table represent an abstract "slot" within a terrain,
111 associated with both some set of conditions and a rarity.
113 Note that there are two encounters per slot, so the rarities will only add
117 __tablename__
= 'encounter_slots'
118 id = Column(Integer
, primary_key
=True, nullable
=False)
119 version_group_id
= Column(Integer
, ForeignKey('version_groups.id'), nullable
=False, autoincrement
=False)
120 encounter_terrain_id
= Column(Integer
, ForeignKey('encounter_terrain.id'), primary_key
=False, nullable
=False, autoincrement
=False)
121 slot
= Column(Integer
, nullable
=True)
122 rarity
= Column(Integer
, nullable
=False)
124 class EncounterSlotCondition(TableBase
):
125 """Lists all conditions that affect each slot."""
127 __tablename__
= 'encounter_slot_conditions'
128 encounter_slot_id
= Column(Integer
, ForeignKey('encounter_slots.id'), primary_key
=True, nullable
=False, autoincrement
=False)
129 encounter_condition_id
= Column(Integer
, ForeignKey('encounter_conditions.id'), primary_key
=True, nullable
=False, autoincrement
=False)
131 class EvolutionChain(TableBase
):
132 __tablename__
= 'evolution_chains'
133 id = Column(Integer
, primary_key
=True, nullable
=False)
134 growth_rate_id
= Column(Integer
, ForeignKey('growth_rates.id'), nullable
=False)
135 steps_to_hatch
= Column(Integer
, nullable
=False)
136 baby_trigger_item
= Column(Unicode(12))
138 class EvolutionMethod(TableBase
):
139 __tablename__
= 'evolution_methods'
140 id = Column(Integer
, primary_key
=True, nullable
=False)
141 name
= Column(Unicode(64), nullable
=False)
142 description
= Column(Unicode(255), nullable
=False)
144 class Generation(TableBase
):
145 __tablename__
= 'generations'
146 id = Column(Integer
, primary_key
=True, nullable
=False)
147 main_region_id
= Column(Integer
, ForeignKey('regions.id'))
148 canonical_pokedex_id
= Column(Integer
, ForeignKey('pokedexes.id'))
149 name
= Column(Unicode(16), nullable
=False)
151 class GrowthRate(TableBase
):
152 """`formula` is written in LaTeX math notation."""
153 __tablename__
= 'growth_rates'
154 id = Column(Integer
, primary_key
=True, nullable
=False)
155 name
= Column(Unicode(20), nullable
=False)
156 formula
= Column(Unicode(500), nullable
=False)
158 class Item(TableBase
):
159 __tablename__
= 'items'
160 __singlename__
= 'item'
161 id = Column(Integer
, primary_key
=True, nullable
=False)
162 name
= Column(Unicode(16), nullable
=False)
164 class Language(TableBase
):
165 __tablename__
= 'languages'
166 id = Column(Integer
, primary_key
=True, nullable
=False)
167 iso639
= Column(Unicode(2), nullable
=False)
168 iso3166
= Column(Unicode(2), nullable
=False)
169 name
= Column(Unicode(16), nullable
=False)
171 class Location(TableBase
):
172 __tablename__
= 'locations'
173 __singlename__
= 'location'
174 id = Column(Integer
, primary_key
=True, nullable
=False)
175 region_id
= Column(Integer
, ForeignKey('regions.id'))
176 name
= Column(Unicode(64), nullable
=False)
178 class LocationArea(TableBase
):
179 __tablename__
= 'location_areas'
180 id = Column(Integer
, primary_key
=True, nullable
=False)
181 location_id
= Column(Integer
, ForeignKey('locations.id'), nullable
=False)
182 internal_id
= Column(Integer
, nullable
=False)
183 name
= Column(Unicode(64), nullable
=True)
185 class LocationAreaEncounterRate(TableBase
):
186 __tablename__
= 'location_area_encounter_rates'
187 location_area_id
= Column(Integer
, ForeignKey('location_areas.id'), primary_key
=True, nullable
=False, autoincrement
=False)
188 encounter_type_id
= Column(Integer
, ForeignKey('encounter_terrain.id'), primary_key
=True, nullable
=False, autoincrement
=False)
189 rate
= Column(Integer
, nullable
=True)
191 class Machine(TableBase
):
192 __tablename__
= 'machines'
193 machine_number
= Column(Integer
, primary_key
=True, nullable
=False, autoincrement
=False)
194 version_group_id
= Column(Integer
, ForeignKey('version_groups.id'), primary_key
=True, nullable
=False, autoincrement
=False)
195 move_id
= Column(Integer
, ForeignKey('moves.id'), nullable
=False)
197 class MoveEffectCategory(TableBase
):
198 __tablename__
= 'move_effect_categories'
199 id = Column(Integer
, primary_key
=True, nullable
=False)
200 name
= Column(Unicode(64), nullable
=False)
201 can_affect_user
= Column(Boolean
, nullable
=False)
203 class MoveEffectCategoryMap(TableBase
):
204 __tablename__
= 'move_effect_category_map'
205 move_effect_id
= Column(Integer
, ForeignKey('move_effects.id'), primary_key
=True, nullable
=False)
206 move_effect_category_id
= Column(Integer
, ForeignKey('move_effect_categories.id'), primary_key
=True, nullable
=False)
207 affects_user
= Column(Boolean
, primary_key
=True, nullable
=False)
209 class MoveDamageClass(TableBase
):
210 __tablename__
= 'move_damage_classes'
211 id = Column(Integer
, primary_key
=True, nullable
=False)
212 name
= Column(Unicode(8), nullable
=False)
213 description
= Column(Unicode(64), nullable
=False)
215 class MoveEffect(TableBase
):
216 __tablename__
= 'move_effects'
217 id = Column(Integer
, primary_key
=True, nullable
=False)
218 priority
= Column(SmallInteger
, nullable
=False)
219 short_effect
= Column(Unicode(256), nullable
=False)
220 effect
= Column(Unicode(5120), nullable
=False)
222 class MoveFlag(TableBase
):
223 __tablename__
= 'move_flags'
224 move_id
= Column(Integer
, ForeignKey('moves.id'), primary_key
=True, nullable
=False, autoincrement
=False)
225 move_flag_type_id
= Column(Integer
, ForeignKey('move_flag_types.id'), primary_key
=True, nullable
=False, autoincrement
=False)
227 class MoveFlagType(TableBase
):
228 __tablename__
= 'move_flag_types'
229 id = Column(Integer
, primary_key
=True, nullable
=False)
230 name
= Column(Unicode(32), nullable
=False)
231 description
= Column(rst
.RstTextColumn(128), nullable
=False)
233 class MoveFlavorText(TableBase
):
234 __tablename__
= 'move_flavor_text'
235 move_id
= Column(Integer
, ForeignKey('moves.id'), primary_key
=True, nullable
=False, autoincrement
=False)
236 generation_id
= Column(Integer
, ForeignKey('generations.id'), primary_key
=True, nullable
=False, autoincrement
=False)
237 flavor_text
= Column(Unicode(255), nullable
=False)
239 class MoveName(TableBase
):
240 __tablename__
= 'move_names'
241 move_id
= Column(Integer
, ForeignKey('moves.id'), primary_key
=True, nullable
=False, autoincrement
=False)
242 language_id
= Column(Integer
, ForeignKey('languages.id'), primary_key
=True, nullable
=False, autoincrement
=False)
243 name
= Column(Unicode(16), nullable
=False)
245 class MoveTarget(TableBase
):
246 __tablename__
= 'move_targets'
247 id = Column(Integer
, primary_key
=True, nullable
=False)
248 name
= Column(Unicode(32), nullable
=False)
249 description
= Column(Unicode(128), nullable
=False)
251 class Move(TableBase
):
252 __tablename__
= 'moves'
253 __singlename__
= 'move'
254 id = Column(Integer
, primary_key
=True, nullable
=False)
255 name
= Column(Unicode(12), nullable
=False)
256 generation_id
= Column(Integer
, ForeignKey('generations.id'), nullable
=False)
257 type_id
= Column(Integer
, ForeignKey('types.id'), nullable
=False)
258 power
= Column(SmallInteger
)
259 pp
= Column(SmallInteger
, nullable
=False)
260 accuracy
= Column(SmallInteger
)
261 target_id
= Column(Integer
, ForeignKey('move_targets.id'), nullable
=False)
262 damage_class_id
= Column(Integer
, ForeignKey('move_damage_classes.id'), nullable
=False)
263 effect_id
= Column(Integer
, ForeignKey('move_effects.id'), nullable
=False)
264 effect_chance
= Column(Integer
)
265 contest_type
= Column(Unicode(8), nullable
=False)
266 contest_effect_id
= Column(Integer
, ForeignKey('contest_effects.id'), nullable
=True)
267 super_contest_effect_id
= Column(Integer
, ForeignKey('super_contest_effects.id'), nullable
=False)
269 class Nature(TableBase
):
270 __tablename__
= 'natures'
271 id = Column(Integer
, primary_key
=True, nullable
=False)
272 name
= Column(Unicode(8), nullable
=False)
273 decreased_stat_id
= Column(Integer
, ForeignKey('stats.id'), nullable
=False)
274 increased_stat_id
= Column(Integer
, ForeignKey('stats.id'), nullable
=False)
276 class Pokedex(TableBase
):
277 __tablename__
= 'pokedexes'
278 id = Column(Integer
, primary_key
=True, nullable
=False)
279 region_id
= Column(Integer
, ForeignKey('regions.id'), nullable
=True)
280 name
= Column(Unicode(16), nullable
=False)
281 description
= Column(Unicode(512))
283 class PokedexVersionGroup(TableBase
):
284 __tablename__
= 'pokedex_version_groups'
285 pokedex_id
= Column(Integer
, ForeignKey('pokedexes.id'), primary_key
=True, nullable
=False, autoincrement
=False)
286 version_group_id
= Column(Integer
, ForeignKey('version_groups.id'), primary_key
=True, nullable
=False, autoincrement
=False)
288 class Pokemon(TableBase
):
289 """The core to this whole mess.
291 Note that I use both 'forme' and 'form' in both code and the database. I
292 only use 'forme' when specifically referring to Pokémon that have multiple
293 distinct species as forms—i.e., different stats or movesets. 'Form' is a
294 more general term referring to any variation within a species, including
295 purely cosmetic forms like Unown.
297 __tablename__
= 'pokemon'
298 __singlename__
= 'pokemon'
299 id = Column(Integer
, primary_key
=True, nullable
=False)
300 name
= Column(Unicode(20), nullable
=False)
301 forme_name
= Column(Unicode(16))
302 forme_base_pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'))
303 generation_id
= Column(Integer
, ForeignKey('generations.id'))
304 evolution_chain_id
= Column(Integer
, ForeignKey('evolution_chains.id'))
305 evolution_parent_pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'))
306 evolution_method_id
= Column(Integer
, ForeignKey('evolution_methods.id'))
307 evolution_parameter
= Column(Unicode(32))
308 height
= Column(Integer
, nullable
=False)
309 weight
= Column(Integer
, nullable
=False)
310 species
= Column(Unicode(16), nullable
=False)
311 color_id
= Column(Integer
, ForeignKey('pokemon_colors.id'), nullable
=False)
312 pokemon_shape_id
= Column(Integer
, ForeignKey('pokemon_shapes.id'), nullable
=False)
313 habitat_id
= Column(Integer
, ForeignKey('pokemon_habitats.id'), nullable
=True)
314 gender_rate
= Column(Integer
, nullable
=False)
315 capture_rate
= Column(Integer
, nullable
=False)
316 base_experience
= Column(Integer
, nullable
=False)
317 base_happiness
= Column(Integer
, nullable
=False)
318 is_baby
= Column(Boolean
, nullable
=False)
319 has_gen4_fem_sprite
= Column(Boolean
, nullable
=False)
320 has_gen4_fem_back_sprite
= Column(Boolean
, nullable
=False)
322 ### Stuff to handle alternate Pokémon forms
325 def national_id(self
):
326 """Returns the National Pokédex number for this Pokémon. Use this
327 instead of the id directly; alternate formes may make the id incorrect.
330 if self
.forme_base_pokemon_id
:
331 return self
.forme_base_pokemon_id
336 """Returns the name of this Pokémon, including its Forme, if any."""
339 return "%s %s" %
(self
.forme_name
.title(), self
.name
)
343 def normal_form(self
):
344 """Returns the normal form for this Pokémon; i.e., this will return
345 regular Deoxys when called on any Deoxys form.
348 if self
.forme_base_pokemon
:
349 return self
.forme_base_pokemon
355 def stat(self
, stat_name
):
356 """Returns a PokemonStat record for the given stat name (or Stat row
357 object). Uses the normal has-many machinery, so all the stats are
360 if isinstance(stat_name
, Stat
):
361 stat_name
= stat_name
.name
363 for pokemon_stat
in self
.stats
:
364 if pokemon_stat
.stat
.name
== stat_name
:
369 class PokemonAbility(TableBase
):
370 __tablename__
= 'pokemon_abilities'
371 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
372 ability_id
= Column(Integer
, ForeignKey('abilities.id'), nullable
=False)
373 slot
= Column(Integer
, primary_key
=True, nullable
=False, autoincrement
=False)
375 class PokemonColor(TableBase
):
376 __tablename__
= 'pokemon_colors'
377 id = Column(Integer
, primary_key
=True, nullable
=False, autoincrement
=False)
378 name
= Column(Unicode(6), nullable
=False)
380 class PokemonDexNumber(TableBase
):
381 __tablename__
= 'pokemon_dex_numbers'
382 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
383 pokedex_id
= Column(Integer
, ForeignKey('pokedexes.id'), primary_key
=True, nullable
=False, autoincrement
=False)
384 pokedex_number
= Column(Integer
, nullable
=False)
386 class PokemonEggGroup(TableBase
):
387 __tablename__
= 'pokemon_egg_groups'
388 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
389 egg_group_id
= Column(Integer
, ForeignKey('egg_groups.id'), primary_key
=True, nullable
=False, autoincrement
=False)
391 class PokemonFlavorText(TableBase
):
392 __tablename__
= 'pokemon_flavor_text'
393 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
394 version_id
= Column(Integer
, ForeignKey('versions.id'), primary_key
=True, nullable
=False, autoincrement
=False)
395 flavor_text
= Column(Unicode(255), nullable
=False)
397 class PokemonFormGroup(TableBase
):
398 __tablename__
= 'pokemon_form_groups'
399 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
400 is_battle_only
= Column(Boolean
, nullable
=False)
401 description
= Column(Unicode(512), nullable
=False)
403 class PokemonFormSprite(TableBase
):
404 __tablename__
= 'pokemon_form_sprites'
405 id = Column(Integer
, primary_key
=True, nullable
=False)
406 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
407 introduced_in_version_group_id
= Column(Integer
, ForeignKey('version_groups.id'), primary_key
=True, nullable
=False, autoincrement
=False)
408 name
= Column(Unicode(16), nullable
=True)
409 is_default
= Column(Boolean
, nullable
=True)
411 class PokemonHabitat(TableBase
):
412 __tablename__
= 'pokemon_habitats'
413 id = Column(Integer
, primary_key
=True, nullable
=False, autoincrement
=False)
414 name
= Column(Unicode(16), nullable
=False)
416 class PokemonItem(TableBase
):
417 __tablename__
= 'pokemon_items'
418 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
419 version_id
= Column(Integer
, ForeignKey('versions.id'), primary_key
=True, nullable
=False, autoincrement
=False)
420 item_id
= Column(Integer
, ForeignKey('items.id'), primary_key
=True, nullable
=False, autoincrement
=False)
421 rarity
= Column(Integer
, nullable
=False)
423 class PokemonMove(TableBase
):
424 __tablename__
= 'pokemon_moves'
425 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
426 version_group_id
= Column(Integer
, ForeignKey('version_groups.id'), primary_key
=True, nullable
=False, autoincrement
=False)
427 move_id
= Column(Integer
, ForeignKey('moves.id'), primary_key
=True, nullable
=False, autoincrement
=False, index
=True)
428 pokemon_move_method_id
= Column(Integer
, ForeignKey('pokemon_move_methods.id'), primary_key
=True, nullable
=False, autoincrement
=False)
429 level
= Column(Integer
, primary_key
=True, nullable
=True, autoincrement
=False)
430 order
= Column(Integer
, nullable
=True)
432 class PokemonMoveMethod(TableBase
):
433 __tablename__
= 'pokemon_move_methods'
434 id = Column(Integer
, primary_key
=True, nullable
=False, autoincrement
=False)
435 name
= Column(Unicode(64), nullable
=False)
436 description
= Column(Unicode(255), nullable
=False)
438 class PokemonName(TableBase
):
439 __tablename__
= 'pokemon_names'
440 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
441 language_id
= Column(Integer
, ForeignKey('languages.id'), primary_key
=True, nullable
=False, autoincrement
=False)
442 name
= Column(Unicode(16), nullable
=False)
444 class PokemonShape(TableBase
):
445 __tablename__
= 'pokemon_shapes'
446 id = Column(Integer
, primary_key
=True, nullable
=False)
447 name
= Column(Unicode(24), nullable
=False)
448 awesome_name
= Column(Unicode(16), nullable
=False)
450 class PokemonStat(TableBase
):
451 __tablename__
= 'pokemon_stats'
452 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
453 stat_id
= Column(Integer
, ForeignKey('stats.id'), primary_key
=True, nullable
=False, autoincrement
=False)
454 base_stat
= Column(Integer
, nullable
=False)
455 effort
= Column(Integer
, nullable
=False)
457 class PokemonType(TableBase
):
458 __tablename__
= 'pokemon_types'
459 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
460 type_id
= Column(Integer
, ForeignKey('types.id'), nullable
=False)
461 slot
= Column(Integer
, primary_key
=True, nullable
=False, autoincrement
=False)
463 class Region(TableBase
):
464 """Major areas of the world: Kanto, Johto, etc."""
465 __tablename__
= 'regions'
466 id = Column(Integer
, primary_key
=True, nullable
=False)
467 name
= Column(Unicode(16), nullable
=False)
469 class Stat(TableBase
):
470 __tablename__
= 'stats'
471 id = Column(Integer
, primary_key
=True, nullable
=False)
472 name
= Column(Unicode(16), nullable
=False)
474 class SuperContestCombo(TableBase
):
475 __tablename__
= 'super_contest_combos'
476 first_move_id
= Column(Integer
, ForeignKey('moves.id'), primary_key
=True, nullable
=False, autoincrement
=False)
477 second_move_id
= Column(Integer
, ForeignKey('moves.id'), primary_key
=True, nullable
=False, autoincrement
=False)
479 class SuperContestEffect(TableBase
):
480 __tablename__
= 'super_contest_effects'
481 id = Column(Integer
, primary_key
=True, nullable
=False)
482 appeal
= Column(SmallInteger
, nullable
=False)
483 flavor_text
= Column(Unicode(64), nullable
=False)
485 class TypeEfficacy(TableBase
):
486 __tablename__
= 'type_efficacy'
487 damage_type_id
= Column(Integer
, ForeignKey('types.id'), primary_key
=True, nullable
=False, autoincrement
=False)
488 target_type_id
= Column(Integer
, ForeignKey('types.id'), primary_key
=True, nullable
=False, autoincrement
=False)
489 damage_factor
= Column(Integer
, nullable
=False)
491 class Type(TableBase
):
492 __tablename__
= 'types'
493 __singlename__
= 'type'
494 id = Column(Integer
, primary_key
=True, nullable
=False)
495 name
= Column(Unicode(8), nullable
=False)
496 abbreviation
= Column(Unicode(3), nullable
=False)
497 generation_id
= Column(Integer
, ForeignKey('generations.id'), nullable
=False)
498 damage_class_id
= Column(Integer
, ForeignKey('move_damage_classes.id'), nullable
=False) ## ??? is none; everything else is physical or special
500 class VersionGroup(TableBase
):
501 __tablename__
= 'version_groups'
502 id = Column(Integer
, primary_key
=True, nullable
=False)
503 generation_id
= Column(Integer
, ForeignKey('generations.id'), nullable
=False)
505 class VersionGroupRegion(TableBase
):
506 __tablename__
= 'version_group_regions'
507 version_group_id
= Column(Integer
, ForeignKey('version_groups.id'), primary_key
=True, nullable
=False)
508 region_id
= Column(Integer
, ForeignKey('regions.id'), primary_key
=True, nullable
=False)
510 class Version(TableBase
):
511 __tablename__
= 'versions'
512 id = Column(Integer
, primary_key
=True, nullable
=False)
513 version_group_id
= Column(Integer
, ForeignKey('version_groups.id'), nullable
=False)
514 name
= Column(Unicode(32), nullable
=False)
517 ### Relations down here, to avoid ordering problems
518 ContestCombo
.first
= relation(Move
, primaryjoin
=ContestCombo
.first_move_id
==Move
.id,
519 backref
='contest_combo_first')
520 ContestCombo
.second
= relation(Move
, primaryjoin
=ContestCombo
.second_move_id
==Move
.id,
521 backref
='contest_combo_second')
523 Encounter
.location_area
= relation(LocationArea
, backref
='encounters')
524 Encounter
.pokemon
= relation(Pokemon
, backref
='encounters')
525 Encounter
.version
= relation(Version
, backref
='encounters')
526 Encounter
.slot
= relation(EncounterSlot
, backref
='encounters')
528 EncounterConditionValue
.condition
= relation(EncounterCondition
, backref
='values')
530 Encounter
.condition_value_map
= relation(EncounterConditionValueMap
, backref
='encounter')
531 Encounter
.condition_values
= association_proxy('condition_value_map', 'condition_value')
532 EncounterConditionValueMap
.condition_value
= relation(EncounterConditionValue
,
533 backref
='encounter_map')
535 EncounterSlot
.terrain
= relation(EncounterTerrain
, backref
='slots')
537 EncounterSlot
.condition_map
= relation(EncounterSlotCondition
, backref
='slot')
538 EncounterSlot
.conditions
= association_proxy('condition_map', 'condition')
539 EncounterSlotCondition
.condition
= relation(EncounterCondition
,
542 EvolutionChain
.growth_rate
= relation(GrowthRate
, backref
='evolution_chains')
544 Generation
.canonical_pokedex
= relation(Pokedex
, backref
='canonical_for_generation')
545 Generation
.versions
= relation(Version
, secondary
=VersionGroup
.__table__
)
546 Generation
.main_region
= relation(Region
)
548 Location
.region
= relation(Region
, backref
='locations')
550 LocationArea
.location
= relation(Location
, backref
='areas')
552 Machine
.version_group
= relation(VersionGroup
)
554 Move
.contest_effect
= relation(ContestEffect
, backref
='moves')
555 Move
.contest_combo_next
= association_proxy('contest_combo_first', 'second')
556 Move
.contest_combo_prev
= association_proxy('contest_combo_second', 'first')
557 Move
.damage_class
= relation(MoveDamageClass
, backref
='moves')
558 Move
.flags
= association_proxy('move_flags', 'flag')
559 Move
.flavor_text
= relation(MoveFlavorText
, order_by
=MoveFlavorText
.generation_id
, backref
='move')
560 Move
.foreign_names
= relation(MoveName
, backref
='pokemon')
561 Move
.generation
= relation(Generation
, backref
='moves')
562 Move
.machines
= relation(Machine
, backref
='move')
563 Move
.move_effect
= relation(MoveEffect
, backref
='moves')
564 Move
.move_flags
= relation(MoveFlag
, backref
='move')
565 Move
.super_contest_effect
= relation(SuperContestEffect
, backref
='moves')
566 Move
.super_contest_combo_next
= association_proxy('super_contest_combo_first', 'second')
567 Move
.super_contest_combo_prev
= association_proxy('super_contest_combo_second', 'first')
568 Move
.target
= relation(MoveTarget
, backref
='moves')
569 Move
.type = relation(Type
, backref
='moves')
571 Move
.effect
= rst
.MoveEffectProperty('effect')
572 Move
.priority
= association_proxy('move_effect', 'priority')
573 Move
.short_effect
= rst
.MoveEffectProperty('short_effect')
575 MoveEffect
.category_map
= relation(MoveEffectCategoryMap
)
576 MoveEffect
.categories
= association_proxy('category_map', 'category')
577 MoveEffectCategoryMap
.category
= relation(MoveEffectCategory
)
579 MoveFlag
.flag
= relation(MoveFlagType
)
581 MoveFlavorText
.generation
= relation(Generation
)
583 MoveName
.language
= relation(Language
)
585 Nature
.decreased_stat
= relation(Stat
, primaryjoin
=Nature
.decreased_stat_id
==Stat
.id,
586 backref
='decreasing_natures')
587 Nature
.increased_stat
= relation(Stat
, primaryjoin
=Nature
.increased_stat_id
==Stat
.id,
588 backref
='increasing_natures')
590 Pokedex
.region
= relation(Region
, backref
='pokedexes')
591 Pokedex
.version_groups
= relation(VersionGroup
, secondary
=PokedexVersionGroup
.__table__
, backref
='pokedexes')
593 Pokemon
.abilities
= relation(Ability
, secondary
=PokemonAbility
.__table__
,
594 order_by
=PokemonAbility
.slot
,
596 Pokemon
.formes
= relation(Pokemon
, primaryjoin
=Pokemon
.id==Pokemon
.forme_base_pokemon_id
,
597 backref
=backref('forme_base_pokemon',
598 remote_side
=[Pokemon
.id]))
599 Pokemon
.pokemon_color
= relation(PokemonColor
, backref
='pokemon')
600 Pokemon
.color
= association_proxy('pokemon_color', 'name')
601 Pokemon
.dex_numbers
= relation(PokemonDexNumber
, backref
='pokemon')
602 Pokemon
.default_form_sprite
= relation(PokemonFormSprite
,
604 Pokemon
.id==PokemonFormSprite
.pokemon_id
,
605 PokemonFormSprite
.is_default
==True,
608 Pokemon
.egg_groups
= relation(EggGroup
, secondary
=PokemonEggGroup
.__table__
,
609 order_by
=PokemonEggGroup
.egg_group_id
,
611 Pokemon
.evolution_chain
= relation(EvolutionChain
, backref
='pokemon')
612 Pokemon
.evolution_method
= relation(EvolutionMethod
)
613 Pokemon
.evolution_children
= relation(Pokemon
, primaryjoin
=Pokemon
.id==Pokemon
.evolution_parent_pokemon_id
,
614 backref
=backref('evolution_parent',
615 remote_side
=[Pokemon
.id]))
616 Pokemon
.flavor_text
= relation(PokemonFlavorText
, order_by
=PokemonFlavorText
.pokemon_id
, backref
='pokemon')
617 Pokemon
.foreign_names
= relation(PokemonName
, backref
='pokemon')
618 Pokemon
.pokemon_habitat
= relation(PokemonHabitat
, backref
='pokemon')
619 Pokemon
.habitat
= association_proxy('pokemon_habitat', 'name')
620 Pokemon
.items
= relation(PokemonItem
)
621 Pokemon
.generation
= relation(Generation
, backref
='pokemon')
622 Pokemon
.shape
= relation(PokemonShape
, backref
='pokemon')
623 Pokemon
.stats
= relation(PokemonStat
, backref
='pokemon')
624 Pokemon
.types
= relation(Type
, secondary
=PokemonType
.__table__
)
626 PokemonDexNumber
.pokedex
= relation(Pokedex
)
628 PokemonFlavorText
.version
= relation(Version
)
630 PokemonItem
.item
= relation(Item
, backref
='pokemon')
631 PokemonItem
.version
= relation(Version
)
633 PokemonFormGroup
.pokemon
= relation(Pokemon
, backref
=backref('form_group',
635 PokemonFormSprite
.pokemon
= relation(Pokemon
, backref
='form_sprites')
636 PokemonFormSprite
.introduced_in
= relation(VersionGroup
)
638 PokemonMove
.pokemon
= relation(Pokemon
, backref
='pokemon_moves')
639 PokemonMove
.version_group
= relation(VersionGroup
)
640 PokemonMove
.machine
= relation(Machine
, backref
='pokemon_moves',
641 primaryjoin
=and_(Machine
.version_group_id
==PokemonMove
.version_group_id
,
642 Machine
.move_id
==PokemonMove
.move_id
),
643 foreign_keys
=[Machine
.version_group_id
, Machine
.move_id
],
645 PokemonMove
.move
= relation(Move
, backref
='pokemon_moves')
646 PokemonMove
.method
= relation(PokemonMoveMethod
)
648 PokemonName
.language
= relation(Language
)
650 PokemonStat
.stat
= relation(Stat
)
652 # This is technically a has-many; Generation.main_region_id -> Region.id
653 Region
.generation
= relation(Generation
, uselist
=False)
654 Region
.version_group_regions
= relation(VersionGroupRegion
, backref
='region',
655 order_by
='VersionGroupRegion.version_group_id')
656 Region
.version_groups
= association_proxy('version_group_regions', 'version_group')
658 SuperContestCombo
.first
= relation(Move
, primaryjoin
=SuperContestCombo
.first_move_id
==Move
.id,
659 backref
='super_contest_combo_first')
660 SuperContestCombo
.second
= relation(Move
, primaryjoin
=SuperContestCombo
.second_move_id
==Move
.id,
661 backref
='super_contest_combo_second')
663 Type
.damage_efficacies
= relation(TypeEfficacy
,
665 ==TypeEfficacy
.damage_type_id
,
666 backref
='damage_type')
667 Type
.target_efficacies
= relation(TypeEfficacy
,
669 ==TypeEfficacy
.target_type_id
,
670 backref
='target_type')
672 Type
.generation
= relation(Generation
, backref
='types')
673 Type
.damage_class
= relation(MoveDamageClass
, backref
='types')
675 Version
.version_group
= relation(VersionGroup
, backref
='versions')
676 Version
.generation
= association_proxy('version_group', 'generation')
678 VersionGroup
.generation
= relation(Generation
, backref
='version_groups')
679 VersionGroup
.version_group_regions
= relation(VersionGroupRegion
, backref
='version_group')
680 VersionGroup
.regions
= association_proxy('version_group_regions', 'region')