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 rarity
= Column(Integer
, nullable
=False, autoincrement
=False)
123 class EncounterSlotCondition(TableBase
):
124 """Lists all conditions that affect each slot."""
126 __tablename__
= 'encounter_slot_conditions'
127 encounter_slot_id
= Column(Integer
, ForeignKey('encounter_slots.id'), primary_key
=True, nullable
=False, autoincrement
=False)
128 encounter_condition_id
= Column(Integer
, ForeignKey('encounter_conditions.id'), primary_key
=True, nullable
=False, autoincrement
=False)
130 class EvolutionChain(TableBase
):
131 __tablename__
= 'evolution_chains'
132 id = Column(Integer
, primary_key
=True, nullable
=False)
133 growth_rate_id
= Column(Integer
, ForeignKey('growth_rates.id'), nullable
=False)
134 steps_to_hatch
= Column(Integer
, nullable
=False)
135 baby_trigger_item
= Column(Unicode(12))
137 class EvolutionMethod(TableBase
):
138 __tablename__
= 'evolution_methods'
139 id = Column(Integer
, primary_key
=True, nullable
=False)
140 name
= Column(Unicode(64), nullable
=False)
141 description
= Column(Unicode(255), nullable
=False)
143 class Generation(TableBase
):
144 __tablename__
= 'generations'
145 id = Column(Integer
, primary_key
=True, nullable
=False)
146 main_region_id
= Column(Integer
, ForeignKey('regions.id'))
147 name
= Column(Unicode(16), nullable
=False)
149 class GrowthRate(TableBase
):
150 """`formula` is written in LaTeX math notation."""
151 __tablename__
= 'growth_rates'
152 id = Column(Integer
, primary_key
=True, nullable
=False)
153 name
= Column(Unicode(20), nullable
=False)
154 formula
= Column(Unicode(500), nullable
=False)
156 class Item(TableBase
):
157 __tablename__
= 'items'
158 __singlename__
= 'item'
159 id = Column(Integer
, primary_key
=True, nullable
=False)
160 name
= Column(Unicode(16), nullable
=False)
162 class Language(TableBase
):
163 __tablename__
= 'languages'
164 id = Column(Integer
, primary_key
=True, nullable
=False)
165 iso639
= Column(Unicode(2), nullable
=False)
166 iso3166
= Column(Unicode(2), nullable
=False)
167 name
= Column(Unicode(16), nullable
=False)
169 class Location(TableBase
):
170 __tablename__
= 'locations'
171 __singlename__
= 'location'
172 id = Column(Integer
, primary_key
=True, nullable
=False)
173 region_id
= Column(Integer
, ForeignKey('regions.id'))
174 name
= Column(Unicode(64), nullable
=False)
176 class LocationArea(TableBase
):
177 __tablename__
= 'location_areas'
178 id = Column(Integer
, primary_key
=True, nullable
=False)
179 location_id
= Column(Integer
, ForeignKey('locations.id'), nullable
=False)
180 internal_id
= Column(Integer
, nullable
=False)
181 name
= Column(Unicode(64), nullable
=True)
183 class LocationAreaEncounterRate(TableBase
):
184 __tablename__
= 'location_area_encounter_rates'
185 location_area_id
= Column(Integer
, ForeignKey('location_areas.id'), primary_key
=True, nullable
=False, autoincrement
=False)
186 encounter_type_id
= Column(Integer
, ForeignKey('encounter_terrain.id'), primary_key
=True, nullable
=False, autoincrement
=False)
187 rate
= Column(Integer
, nullable
=True)
189 class Machine(TableBase
):
190 __tablename__
= 'machines'
191 machine_number
= Column(Integer
, primary_key
=True, nullable
=False, autoincrement
=False)
192 version_group_id
= Column(Integer
, ForeignKey('version_groups.id'), primary_key
=True, nullable
=False, autoincrement
=False)
193 move_id
= Column(Integer
, ForeignKey('moves.id'), nullable
=False)
195 class MoveEffectCategory(TableBase
):
196 __tablename__
= 'move_effect_categories'
197 id = Column(Integer
, primary_key
=True, nullable
=False)
198 name
= Column(Unicode(64), nullable
=False)
199 can_affect_user
= Column(Boolean
, nullable
=False)
201 class MoveEffectCategoryMap(TableBase
):
202 __tablename__
= 'move_effect_category_map'
203 move_effect_id
= Column(Integer
, ForeignKey('move_effects.id'), primary_key
=True, nullable
=False)
204 move_effect_category_id
= Column(Integer
, ForeignKey('move_effect_categories.id'), primary_key
=True, nullable
=False)
205 affects_user
= Column(Boolean
, primary_key
=True, nullable
=False)
207 class MoveDamageClass(TableBase
):
208 __tablename__
= 'move_damage_classes'
209 id = Column(Integer
, primary_key
=True, nullable
=False)
210 name
= Column(Unicode(8), nullable
=False)
211 description
= Column(Unicode(64), nullable
=False)
213 class MoveEffect(TableBase
):
214 __tablename__
= 'move_effects'
215 id = Column(Integer
, primary_key
=True, nullable
=False)
216 priority
= Column(SmallInteger
, nullable
=False)
217 short_effect
= Column(Unicode(256), nullable
=False)
218 effect
= Column(Unicode(5120), nullable
=False)
220 class MoveFlag(TableBase
):
221 __tablename__
= 'move_flags'
222 move_id
= Column(Integer
, ForeignKey('moves.id'), primary_key
=True, nullable
=False, autoincrement
=False)
223 move_flag_type_id
= Column(Integer
, ForeignKey('move_flag_types.id'), primary_key
=True, nullable
=False, autoincrement
=False)
225 class MoveFlagType(TableBase
):
226 __tablename__
= 'move_flag_types'
227 id = Column(Integer
, primary_key
=True, nullable
=False)
228 name
= Column(Unicode(32), nullable
=False)
229 description
= Column(rst
.RstTextColumn(128), nullable
=False)
231 class MoveFlavorText(TableBase
):
232 __tablename__
= 'move_flavor_text'
233 move_id
= Column(Integer
, ForeignKey('moves.id'), primary_key
=True, nullable
=False, autoincrement
=False)
234 generation_id
= Column(Integer
, ForeignKey('generations.id'), primary_key
=True, nullable
=False, autoincrement
=False)
235 flavor_text
= Column(Unicode(255), nullable
=False)
237 class MoveName(TableBase
):
238 __tablename__
= 'move_names'
239 move_id
= Column(Integer
, ForeignKey('moves.id'), primary_key
=True, nullable
=False, autoincrement
=False)
240 language_id
= Column(Integer
, ForeignKey('languages.id'), primary_key
=True, nullable
=False, autoincrement
=False)
241 name
= Column(Unicode(16), nullable
=False)
243 class MoveTarget(TableBase
):
244 __tablename__
= 'move_targets'
245 id = Column(Integer
, primary_key
=True, nullable
=False)
246 name
= Column(Unicode(32), nullable
=False)
247 description
= Column(Unicode(128), nullable
=False)
249 class Move(TableBase
):
250 __tablename__
= 'moves'
251 __singlename__
= 'move'
252 id = Column(Integer
, primary_key
=True, nullable
=False)
253 name
= Column(Unicode(12), nullable
=False)
254 generation_id
= Column(Integer
, ForeignKey('generations.id'), nullable
=False)
255 type_id
= Column(Integer
, ForeignKey('types.id'), nullable
=False)
256 power
= Column(SmallInteger
)
257 pp
= Column(SmallInteger
, nullable
=False)
258 accuracy
= Column(SmallInteger
)
259 target_id
= Column(Integer
, ForeignKey('move_targets.id'), nullable
=False)
260 damage_class_id
= Column(Integer
, ForeignKey('move_damage_classes.id'), nullable
=False)
261 effect_id
= Column(Integer
, ForeignKey('move_effects.id'), nullable
=False)
262 effect_chance
= Column(Integer
)
263 contest_type
= Column(Unicode(8), nullable
=False)
264 contest_effect_id
= Column(Integer
, ForeignKey('contest_effects.id'), nullable
=True)
265 super_contest_effect_id
= Column(Integer
, ForeignKey('super_contest_effects.id'), nullable
=False)
267 class Nature(TableBase
):
268 __tablename__
= 'natures'
269 id = Column(Integer
, primary_key
=True, nullable
=False)
270 name
= Column(Unicode(8), nullable
=False)
271 decreased_stat_id
= Column(Integer
, ForeignKey('stats.id'), nullable
=False)
272 increased_stat_id
= Column(Integer
, ForeignKey('stats.id'), nullable
=False)
274 class Pokedex(TableBase
):
275 __tablename__
= 'pokedexes'
276 id = Column(Integer
, primary_key
=True, nullable
=False)
277 name
= Column(Unicode(16), nullable
=False)
278 description
= Column(Unicode(512))
280 class PokedexVersionGroup(TableBase
):
281 __tablename__
= 'pokedex_version_groups'
282 pokedex_id
= Column(Integer
, ForeignKey('pokedexes.id'), primary_key
=True, nullable
=False, autoincrement
=False)
283 version_group_id
= Column(Integer
, ForeignKey('version_groups.id'), primary_key
=True, nullable
=False, autoincrement
=False)
285 class Pokemon(TableBase
):
286 """The core to this whole mess.
288 Note that I use both 'forme' and 'form' in both code and the database. I
289 only use 'forme' when specifically referring to Pokémon that have multiple
290 distinct species as forms—i.e., different stats or movesets. 'Form' is a
291 more general term referring to any variation within a species, including
292 purely cosmetic forms like Unown.
294 __tablename__
= 'pokemon'
295 __singlename__
= 'pokemon'
296 id = Column(Integer
, primary_key
=True, nullable
=False)
297 name
= Column(Unicode(20), nullable
=False)
298 forme_name
= Column(Unicode(16))
299 forme_base_pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'))
300 generation_id
= Column(Integer
, ForeignKey('generations.id'))
301 evolution_chain_id
= Column(Integer
, ForeignKey('evolution_chains.id'))
302 evolution_parent_pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'))
303 evolution_method_id
= Column(Integer
, ForeignKey('evolution_methods.id'))
304 evolution_parameter
= Column(Unicode(32))
305 height
= Column(Integer
, nullable
=False)
306 weight
= Column(Integer
, nullable
=False)
307 species
= Column(Unicode(16), nullable
=False)
308 color_id
= Column(Integer
, ForeignKey('pokemon_colors.id'), nullable
=False)
309 pokemon_shape_id
= Column(Integer
, ForeignKey('pokemon_shapes.id'), nullable
=False)
310 habitat_id
= Column(Integer
, ForeignKey('pokemon_habitats.id'), nullable
=True)
311 gender_rate
= Column(Integer
, nullable
=False)
312 capture_rate
= Column(Integer
, nullable
=False)
313 base_experience
= Column(Integer
, nullable
=False)
314 base_happiness
= Column(Integer
, nullable
=False)
315 is_baby
= Column(Boolean
, nullable
=False)
316 has_gen4_fem_sprite
= Column(Boolean
, nullable
=False)
317 has_gen4_fem_back_sprite
= Column(Boolean
, nullable
=False)
319 ### Stuff to handle alternate Pokémon forms
322 def national_id(self
):
323 """Returns the National Pokédex number for this Pokémon. Use this
324 instead of the id directly; alternate formes may make the id incorrect.
327 if self
.forme_base_pokemon_id
:
328 return self
.forme_base_pokemon_id
333 """Returns the name of this Pokémon, including its Forme, if any."""
336 return "%s %s" %
(self
.forme_name
.title(), self
.name
)
340 def normal_form(self
):
341 """Returns the normal form for this Pokémon; i.e., this will return
342 regular Deoxys when called on any Deoxys form.
345 if self
.forme_base_pokemon
:
346 return self
.forme_base_pokemon
350 class PokemonAbility(TableBase
):
351 __tablename__
= 'pokemon_abilities'
352 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
353 ability_id
= Column(Integer
, ForeignKey('abilities.id'), nullable
=False)
354 slot
= Column(Integer
, primary_key
=True, nullable
=False, autoincrement
=False)
356 class PokemonColor(TableBase
):
357 __tablename__
= 'pokemon_colors'
358 id = Column(Integer
, primary_key
=True, nullable
=False, autoincrement
=False)
359 name
= Column(Unicode(6), nullable
=False)
361 class PokemonDexNumber(TableBase
):
362 __tablename__
= 'pokemon_dex_numbers'
363 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
364 pokedex_id
= Column(Integer
, ForeignKey('pokedexes.id'), primary_key
=True, nullable
=False, autoincrement
=False)
365 pokedex_number
= Column(Integer
, nullable
=False)
367 class PokemonEggGroup(TableBase
):
368 __tablename__
= 'pokemon_egg_groups'
369 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
370 egg_group_id
= Column(Integer
, ForeignKey('egg_groups.id'), primary_key
=True, nullable
=False, autoincrement
=False)
372 class PokemonFlavorText(TableBase
):
373 __tablename__
= 'pokemon_flavor_text'
374 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
375 version_id
= Column(Integer
, ForeignKey('versions.id'), primary_key
=True, nullable
=False, autoincrement
=False)
376 flavor_text
= Column(Unicode(255), nullable
=False)
378 class PokemonFormGroup(TableBase
):
379 __tablename__
= 'pokemon_form_groups'
380 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
381 is_battle_only
= Column(Boolean
, nullable
=False)
382 description
= Column(Unicode(512), nullable
=False)
384 class PokemonFormSprite(TableBase
):
385 __tablename__
= 'pokemon_form_sprites'
386 id = Column(Integer
, primary_key
=True, nullable
=False)
387 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
388 introduced_in_version_group_id
= Column(Integer
, ForeignKey('version_groups.id'), primary_key
=True, nullable
=False, autoincrement
=False)
389 name
= Column(Unicode(16), nullable
=True)
390 is_default
= Column(Boolean
, nullable
=True)
392 class PokemonHabitat(TableBase
):
393 __tablename__
= 'pokemon_habitats'
394 id = Column(Integer
, primary_key
=True, nullable
=False, autoincrement
=False)
395 name
= Column(Unicode(16), nullable
=False)
397 class PokemonItem(TableBase
):
398 __tablename__
= 'pokemon_items'
399 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
400 version_id
= Column(Integer
, ForeignKey('versions.id'), primary_key
=True, nullable
=False, autoincrement
=False)
401 item_id
= Column(Integer
, ForeignKey('items.id'), primary_key
=True, nullable
=False, autoincrement
=False)
402 rarity
= Column(Integer
, nullable
=False)
404 class PokemonMove(TableBase
):
405 __tablename__
= 'pokemon_moves'
406 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
407 version_group_id
= Column(Integer
, ForeignKey('version_groups.id'), primary_key
=True, nullable
=False, autoincrement
=False)
408 move_id
= Column(Integer
, ForeignKey('moves.id'), primary_key
=True, nullable
=False, autoincrement
=False, index
=True)
409 pokemon_move_method_id
= Column(Integer
, ForeignKey('pokemon_move_methods.id'), primary_key
=True, nullable
=False, autoincrement
=False)
410 level
= Column(Integer
, primary_key
=True, nullable
=True, autoincrement
=False)
411 order
= Column(Integer
, nullable
=True)
413 class PokemonMoveMethod(TableBase
):
414 __tablename__
= 'pokemon_move_methods'
415 id = Column(Integer
, primary_key
=True, nullable
=False, autoincrement
=False)
416 name
= Column(Unicode(64), nullable
=False)
417 description
= Column(Unicode(255), nullable
=False)
419 class PokemonName(TableBase
):
420 __tablename__
= 'pokemon_names'
421 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
422 language_id
= Column(Integer
, ForeignKey('languages.id'), primary_key
=True, nullable
=False, autoincrement
=False)
423 name
= Column(Unicode(16), nullable
=False)
425 class PokemonShape(TableBase
):
426 __tablename__
= 'pokemon_shapes'
427 id = Column(Integer
, primary_key
=True, nullable
=False)
428 name
= Column(Unicode(24), nullable
=False)
429 awesome_name
= Column(Unicode(16), nullable
=False)
431 class PokemonStat(TableBase
):
432 __tablename__
= 'pokemon_stats'
433 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
434 stat_id
= Column(Integer
, ForeignKey('stats.id'), primary_key
=True, nullable
=False, autoincrement
=False)
435 base_stat
= Column(Integer
, nullable
=False)
436 effort
= Column(Integer
, nullable
=False)
438 class PokemonType(TableBase
):
439 __tablename__
= 'pokemon_types'
440 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
441 type_id
= Column(Integer
, ForeignKey('types.id'), nullable
=False)
442 slot
= Column(Integer
, primary_key
=True, nullable
=False, autoincrement
=False)
444 class Region(TableBase
):
445 """Major areas of the world: Kanto, Johto, etc."""
446 __tablename__
= 'regions'
447 id = Column(Integer
, primary_key
=True, nullable
=False)
448 name
= Column(Unicode(16), nullable
=False)
450 class Stat(TableBase
):
451 __tablename__
= 'stats'
452 id = Column(Integer
, primary_key
=True, nullable
=False)
453 name
= Column(Unicode(16), nullable
=False)
455 class SuperContestCombo(TableBase
):
456 __tablename__
= 'super_contest_combos'
457 first_move_id
= Column(Integer
, ForeignKey('moves.id'), primary_key
=True, nullable
=False, autoincrement
=False)
458 second_move_id
= Column(Integer
, ForeignKey('moves.id'), primary_key
=True, nullable
=False, autoincrement
=False)
460 class SuperContestEffect(TableBase
):
461 __tablename__
= 'super_contest_effects'
462 id = Column(Integer
, primary_key
=True, nullable
=False)
463 appeal
= Column(SmallInteger
, nullable
=False)
464 flavor_text
= Column(Unicode(64), nullable
=False)
466 class TypeEfficacy(TableBase
):
467 __tablename__
= 'type_efficacy'
468 damage_type_id
= Column(Integer
, ForeignKey('types.id'), primary_key
=True, nullable
=False, autoincrement
=False)
469 target_type_id
= Column(Integer
, ForeignKey('types.id'), primary_key
=True, nullable
=False, autoincrement
=False)
470 damage_factor
= Column(Integer
, nullable
=False)
472 class Type(TableBase
):
473 __tablename__
= 'types'
474 __singlename__
= 'type'
475 id = Column(Integer
, primary_key
=True, nullable
=False)
476 name
= Column(Unicode(8), nullable
=False)
477 abbreviation
= Column(Unicode(3), nullable
=False)
478 generation_id
= Column(Integer
, ForeignKey('generations.id'), nullable
=False)
479 damage_class_id
= Column(Integer
, ForeignKey('move_damage_classes.id'), nullable
=False) ## ??? is none; everything else is physical or special
481 class VersionGroup(TableBase
):
482 __tablename__
= 'version_groups'
483 id = Column(Integer
, primary_key
=True, nullable
=False)
484 generation_id
= Column(Integer
, ForeignKey('generations.id'), nullable
=False)
486 class VersionGroupRegion(TableBase
):
487 __tablename__
= 'version_group_regions'
488 version_group_id
= Column(Integer
, ForeignKey('version_groups.id'), primary_key
=True, nullable
=False)
489 region_id
= Column(Integer
, ForeignKey('regions.id'), primary_key
=True, nullable
=False)
491 class Version(TableBase
):
492 __tablename__
= 'versions'
493 id = Column(Integer
, primary_key
=True, nullable
=False)
494 version_group_id
= Column(Integer
, ForeignKey('version_groups.id'), nullable
=False)
495 name
= Column(Unicode(32), nullable
=False)
498 ### Relations down here, to avoid ordering problems
499 ContestCombo
.first
= relation(Move
, primaryjoin
=ContestCombo
.first_move_id
==Move
.id,
500 backref
='contest_combo_first')
501 ContestCombo
.second
= relation(Move
, primaryjoin
=ContestCombo
.second_move_id
==Move
.id,
502 backref
='contest_combo_second')
504 Encounter
.location_area
= relation(LocationArea
, backref
='encounters')
505 Encounter
.pokemon
= relation(Pokemon
, backref
='encounters')
506 Encounter
.version
= relation(Version
, backref
='encounters')
507 Encounter
.slot
= relation(EncounterSlot
, backref
='encounters')
509 EncounterConditionValue
.condition
= relation(EncounterCondition
, backref
='values')
511 Encounter
.condition_value_map
= relation(EncounterConditionValueMap
, backref
='encounter')
512 Encounter
.condition_values
= association_proxy('condition_value_map', 'condition_value')
513 EncounterConditionValueMap
.condition_value
= relation(EncounterConditionValue
,
514 backref
='encounter_map')
516 EncounterSlot
.terrain
= relation(EncounterTerrain
, backref
='slots')
518 EncounterSlot
.condition_map
= relation(EncounterSlotCondition
, backref
='slot')
519 EncounterSlot
.conditions
= association_proxy('condition_map', 'condition')
520 EncounterSlotCondition
.condition
= relation(EncounterCondition
,
523 EvolutionChain
.growth_rate
= relation(GrowthRate
, backref
='evolution_chains')
525 Generation
.versions
= relation(Version
, secondary
=VersionGroup
.__table__
)
526 Generation
.main_region
= relation(Region
)
528 Location
.region
= relation(Region
, backref
='locations')
530 LocationArea
.location
= relation(Location
, backref
='areas')
532 Machine
.version_group
= relation(VersionGroup
)
534 Move
.contest_effect
= relation(ContestEffect
, backref
='moves')
535 Move
.contest_combo_next
= association_proxy('contest_combo_first', 'second')
536 Move
.contest_combo_prev
= association_proxy('contest_combo_second', 'first')
537 Move
.damage_class
= relation(MoveDamageClass
, backref
='moves')
538 Move
.flags
= association_proxy('move_flags', 'flag')
539 Move
.flavor_text
= relation(MoveFlavorText
, order_by
=MoveFlavorText
.generation_id
, backref
='move')
540 Move
.foreign_names
= relation(MoveName
, backref
='pokemon')
541 Move
.generation
= relation(Generation
, backref
='moves')
542 Move
.machines
= relation(Machine
, backref
='move')
543 Move
.move_effect
= relation(MoveEffect
, backref
='moves')
544 Move
.move_flags
= relation(MoveFlag
, backref
='move')
545 Move
.super_contest_effect
= relation(SuperContestEffect
, backref
='moves')
546 Move
.super_contest_combo_next
= association_proxy('super_contest_combo_first', 'second')
547 Move
.super_contest_combo_prev
= association_proxy('super_contest_combo_second', 'first')
548 Move
.target
= relation(MoveTarget
, backref
='moves')
549 Move
.type = relation(Type
, backref
='moves')
551 Move
.effect
= rst
.MoveEffectProperty('effect')
552 Move
.priority
= association_proxy('move_effect', 'priority')
553 Move
.short_effect
= rst
.MoveEffectProperty('short_effect')
555 MoveEffect
.category_map
= relation(MoveEffectCategoryMap
)
556 MoveEffect
.categories
= association_proxy('category_map', 'category')
557 MoveEffectCategoryMap
.category
= relation(MoveEffectCategory
)
559 MoveFlag
.flag
= relation(MoveFlagType
)
561 MoveFlavorText
.generation
= relation(Generation
)
563 MoveName
.language
= relation(Language
)
565 Nature
.decreased_stat
= relation(Stat
, primaryjoin
=Nature
.decreased_stat_id
==Stat
.id,
566 backref
='decreasing_natures')
567 Nature
.increased_stat
= relation(Stat
, primaryjoin
=Nature
.increased_stat_id
==Stat
.id,
568 backref
='increasing_natures')
570 Pokedex
.version_groups
= relation(VersionGroup
, secondary
=PokedexVersionGroup
.__table__
)
572 Pokemon
.abilities
= relation(Ability
, secondary
=PokemonAbility
.__table__
,
573 order_by
=PokemonAbility
.slot
,
575 Pokemon
.formes
= relation(Pokemon
, primaryjoin
=Pokemon
.id==Pokemon
.forme_base_pokemon_id
,
576 backref
=backref('forme_base_pokemon',
577 remote_side
=[Pokemon
.id]))
578 Pokemon
.pokemon_color
= relation(PokemonColor
, backref
='pokemon')
579 Pokemon
.color
= association_proxy('pokemon_color', 'name')
580 Pokemon
.dex_numbers
= relation(PokemonDexNumber
, backref
='pokemon')
581 Pokemon
.default_form_sprite
= relation(PokemonFormSprite
,
583 Pokemon
.id==PokemonFormSprite
.pokemon_id
,
584 PokemonFormSprite
.is_default
==True,
587 Pokemon
.egg_groups
= relation(EggGroup
, secondary
=PokemonEggGroup
.__table__
,
588 order_by
=PokemonEggGroup
.egg_group_id
,
590 Pokemon
.evolution_chain
= relation(EvolutionChain
, backref
='pokemon')
591 Pokemon
.evolution_method
= relation(EvolutionMethod
)
592 Pokemon
.evolution_children
= relation(Pokemon
, primaryjoin
=Pokemon
.id==Pokemon
.evolution_parent_pokemon_id
,
593 backref
=backref('evolution_parent',
594 remote_side
=[Pokemon
.id]))
595 Pokemon
.flavor_text
= relation(PokemonFlavorText
, order_by
=PokemonFlavorText
.pokemon_id
, backref
='pokemon')
596 Pokemon
.foreign_names
= relation(PokemonName
, backref
='pokemon')
597 Pokemon
.pokemon_habitat
= relation(PokemonHabitat
, backref
='pokemon')
598 Pokemon
.habitat
= association_proxy('pokemon_habitat', 'name')
599 Pokemon
.items
= relation(PokemonItem
)
600 Pokemon
.generation
= relation(Generation
, backref
='pokemon')
601 Pokemon
.shape
= relation(PokemonShape
, backref
='pokemon')
602 Pokemon
.stats
= relation(PokemonStat
, backref
='pokemon')
603 Pokemon
.types
= relation(Type
, secondary
=PokemonType
.__table__
)
605 PokemonDexNumber
.pokedex
= relation(Pokedex
)
607 PokemonFlavorText
.version
= relation(Version
)
609 PokemonItem
.item
= relation(Item
, backref
='pokemon')
610 PokemonItem
.version
= relation(Version
)
612 PokemonFormGroup
.pokemon
= relation(Pokemon
, backref
=backref('form_group',
614 PokemonFormSprite
.pokemon
= relation(Pokemon
, backref
='form_sprites')
615 PokemonFormSprite
.introduced_in
= relation(VersionGroup
)
617 PokemonMove
.pokemon
= relation(Pokemon
, backref
='pokemon_moves')
618 PokemonMove
.version_group
= relation(VersionGroup
)
619 PokemonMove
.machine
= relation(Machine
, backref
='pokemon_moves',
620 primaryjoin
=and_(Machine
.version_group_id
==PokemonMove
.version_group_id
,
621 Machine
.move_id
==PokemonMove
.move_id
),
622 foreign_keys
=[Machine
.version_group_id
, Machine
.move_id
],
624 PokemonMove
.move
= relation(Move
, backref
='pokemon_moves')
625 PokemonMove
.method
= relation(PokemonMoveMethod
)
627 PokemonName
.language
= relation(Language
)
629 PokemonStat
.stat
= relation(Stat
)
631 # This is technically a has-many; Generation.main_region_id -> Region.id
632 Region
.generation
= relation(Generation
, uselist
=False)
633 Region
.version_group_regions
= relation(VersionGroupRegion
, backref
='region',
634 order_by
='VersionGroupRegion.version_group_id')
635 Region
.version_groups
= association_proxy('version_group_regions', 'version_group')
637 SuperContestCombo
.first
= relation(Move
, primaryjoin
=SuperContestCombo
.first_move_id
==Move
.id,
638 backref
='super_contest_combo_first')
639 SuperContestCombo
.second
= relation(Move
, primaryjoin
=SuperContestCombo
.second_move_id
==Move
.id,
640 backref
='super_contest_combo_second')
642 Type
.damage_efficacies
= relation(TypeEfficacy
,
644 ==TypeEfficacy
.damage_type_id
,
645 backref
='damage_type')
646 Type
.target_efficacies
= relation(TypeEfficacy
,
648 ==TypeEfficacy
.target_type_id
,
649 backref
='target_type')
651 Type
.generation
= relation(Generation
, backref
='types')
652 Type
.damage_class
= relation(MoveDamageClass
, backref
='types')
654 Version
.version_group
= relation(VersionGroup
, backref
='versions')
655 Version
.generation
= association_proxy('version_group', 'generation')
657 VersionGroup
.generation
= relation(Generation
, backref
='version_groups')
658 VersionGroup
.version_group_regions
= relation(VersionGroupRegion
, backref
='version_group')
659 VersionGroup
.regions
= association_proxy('version_group_regions', 'region')