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 Berry(TableBase
):
24 __tablename__
= 'berries'
25 id = Column(Integer
, primary_key
=True, nullable
=False)
26 item_id
= Column(Integer
, ForeignKey('items.id'), nullable
=False)
27 firmness_id
= Column(Integer
, ForeignKey('berry_firmness.id'), nullable
=False)
28 natural_gift_power
= Column(Integer
, nullable
=True)
29 natural_gift_type_id
= Column(Integer
, ForeignKey('types.id'), nullable
=True)
30 size
= Column(Integer
, nullable
=False)
31 max_harvest
= Column(Integer
, nullable
=False)
32 growth_time
= Column(Integer
, nullable
=False)
33 soil_dryness
= Column(Integer
, nullable
=False)
34 smoothness
= Column(Integer
, nullable
=False)
36 class BerryFirmness(TableBase
):
37 __tablename__
= 'berry_firmness'
38 id = Column(Integer
, primary_key
=True, nullable
=False)
39 name
= Column(Unicode(10), nullable
=False)
41 class BerryFlavor(TableBase
):
42 __tablename__
= 'berry_flavors'
43 berry_id
= Column(Integer
, ForeignKey('berries.id'), primary_key
=True, nullable
=False, autoincrement
=False)
44 contest_type_id
= Column(Integer
, ForeignKey('contest_types.id'), primary_key
=True, nullable
=False, autoincrement
=False)
45 flavor
= Column(Integer
, nullable
=False)
47 class ContestCombo(TableBase
):
48 __tablename__
= 'contest_combos'
49 first_move_id
= Column(Integer
, ForeignKey('moves.id'), primary_key
=True, nullable
=False, autoincrement
=False)
50 second_move_id
= Column(Integer
, ForeignKey('moves.id'), primary_key
=True, nullable
=False, autoincrement
=False)
52 class ContestEffect(TableBase
):
53 __tablename__
= 'contest_effects'
54 id = Column(Integer
, primary_key
=True, nullable
=False)
55 appeal
= Column(SmallInteger
, nullable
=False)
56 jam
= Column(SmallInteger
, nullable
=False)
57 flavor_text
= Column(Unicode(64), nullable
=False)
58 effect
= Column(Unicode(255), nullable
=False)
60 class ContestType(TableBase
):
61 __tablename__
= 'contest_types'
62 id = Column(Integer
, primary_key
=True, nullable
=False)
63 name
= Column(Unicode(6), nullable
=False)
64 flavor
= Column(Unicode(6), nullable
=False)
65 color
= Column(Unicode(6), nullable
=False)
67 class EggGroup(TableBase
):
68 __tablename__
= 'egg_groups'
69 id = Column(Integer
, primary_key
=True, nullable
=False)
70 name
= Column(Unicode(16), nullable
=False)
72 class Encounter(TableBase
):
73 """Rows in this table represent encounters with wild Pokémon. Bear with
76 Within a given area in a given game, encounters are differentiated by the
77 "slot" they are in and the state of the game world.
79 What the player is doing to get an encounter, such as surfing or walking
80 through tall grass, is called terrain. Each terrain has its own set of
83 Within a terrain, slots are defined primarily by rarity. Each slot can
84 also be affected by world conditions; for example, the 20% slot for walking
85 in tall grass is affected by whether a swarm is in effect in that area.
86 "Is there a swarm?" is a condition; "there is a swarm" and "there is not a
87 swarm" are the possible values of this condition.
89 A slot (20% walking in grass) and any appropriate world conditions (no
90 swarm) are thus enough to define a specific encounter.
92 Well, okay, almost: each slot actually appears twice.
95 __tablename__
= 'encounters'
96 id = Column(Integer
, primary_key
=True, nullable
=False)
97 version_id
= Column(Integer
, ForeignKey('versions.id'), nullable
=False, autoincrement
=False)
98 location_area_id
= Column(Integer
, ForeignKey('location_areas.id'), nullable
=False, autoincrement
=False)
99 encounter_slot_id
= Column(Integer
, ForeignKey('encounter_slots.id'), nullable
=False, autoincrement
=False)
100 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), nullable
=False, autoincrement
=False)
101 min_level
= Column(Integer
, nullable
=False, autoincrement
=False)
102 max_level
= Column(Integer
, nullable
=False, autoincrement
=False)
104 class EncounterCondition(TableBase
):
105 """Rows in this table represent varying conditions in the game world, such
109 __tablename__
= 'encounter_conditions'
110 id = Column(Integer
, primary_key
=True, nullable
=False)
111 name
= Column(Unicode(64), nullable
=False)
113 class EncounterConditionValue(TableBase
):
114 """Rows in this table represent possible states for a condition; for
115 example, the state of 'swarm' could be 'swarm' or 'no swarm'.
118 __tablename__
= 'encounter_condition_values'
119 id = Column(Integer
, primary_key
=True, nullable
=False)
120 encounter_condition_id
= Column(Integer
, ForeignKey('encounter_conditions.id'), primary_key
=False, nullable
=False, autoincrement
=False)
121 name
= Column(Unicode(64), nullable
=False)
122 is_default
= Column(Boolean
, nullable
=False)
124 class EncounterConditionValueMap(TableBase
):
125 """Maps encounters to the specific conditions under which they occur."""
127 __tablename__
= 'encounter_condition_value_map'
128 encounter_id
= Column(Integer
, ForeignKey('encounters.id'), primary_key
=True, nullable
=False, autoincrement
=False)
129 encounter_condition_value_id
= Column(Integer
, ForeignKey('encounter_condition_values.id'), primary_key
=True, nullable
=False, autoincrement
=False)
131 class EncounterTerrain(TableBase
):
132 """Rows in this table represent ways the player can enter a wild encounter,
133 e.g., surfing, fishing, or walking through tall grass.
136 __tablename__
= 'encounter_terrain'
137 id = Column(Integer
, primary_key
=True, nullable
=False)
138 name
= Column(Unicode(64), nullable
=False)
140 class EncounterSlot(TableBase
):
141 """Rows in this table represent an abstract "slot" within a terrain,
142 associated with both some set of conditions and a rarity.
144 Note that there are two encounters per slot, so the rarities will only add
148 __tablename__
= 'encounter_slots'
149 id = Column(Integer
, primary_key
=True, nullable
=False)
150 version_group_id
= Column(Integer
, ForeignKey('version_groups.id'), nullable
=False, autoincrement
=False)
151 encounter_terrain_id
= Column(Integer
, ForeignKey('encounter_terrain.id'), primary_key
=False, nullable
=False, autoincrement
=False)
152 slot
= Column(Integer
, nullable
=True)
153 rarity
= Column(Integer
, nullable
=False)
155 class EncounterSlotCondition(TableBase
):
156 """Lists all conditions that affect each slot."""
158 __tablename__
= 'encounter_slot_conditions'
159 encounter_slot_id
= Column(Integer
, ForeignKey('encounter_slots.id'), primary_key
=True, nullable
=False, autoincrement
=False)
160 encounter_condition_id
= Column(Integer
, ForeignKey('encounter_conditions.id'), primary_key
=True, nullable
=False, autoincrement
=False)
162 class EvolutionChain(TableBase
):
163 __tablename__
= 'evolution_chains'
164 id = Column(Integer
, primary_key
=True, nullable
=False)
165 growth_rate_id
= Column(Integer
, ForeignKey('growth_rates.id'), nullable
=False)
166 steps_to_hatch
= Column(Integer
, nullable
=False)
167 baby_trigger_item
= Column(Unicode(12))
169 class EvolutionMethod(TableBase
):
170 __tablename__
= 'evolution_methods'
171 id = Column(Integer
, primary_key
=True, nullable
=False)
172 name
= Column(Unicode(64), nullable
=False)
173 description
= Column(Unicode(255), nullable
=False)
175 class Generation(TableBase
):
176 __tablename__
= 'generations'
177 id = Column(Integer
, primary_key
=True, nullable
=False)
178 main_region_id
= Column(Integer
, ForeignKey('regions.id'))
179 canonical_pokedex_id
= Column(Integer
, ForeignKey('pokedexes.id'))
180 name
= Column(Unicode(16), nullable
=False)
182 class GrowthRate(TableBase
):
183 """`formula` is written in LaTeX math notation."""
184 __tablename__
= 'growth_rates'
185 id = Column(Integer
, primary_key
=True, nullable
=False)
186 name
= Column(Unicode(20), nullable
=False)
187 formula
= Column(Unicode(500), nullable
=False)
189 class Item(TableBase
):
190 __tablename__
= 'items'
191 __singlename__
= 'item'
192 id = Column(Integer
, primary_key
=True, nullable
=False)
193 name
= Column(Unicode(16), nullable
=False)
194 category_id
= Column(Integer
, ForeignKey('item_categories.id'), nullable
=False)
195 cost
= Column(Integer
, nullable
=False)
196 fling_power
= Column(Integer
, nullable
=True)
197 fling_effect_id
= Column(Integer
, ForeignKey('item_fling_effects.id'), nullable
=True)
198 flavor_text
= Column(Unicode(255), nullable
=False)
199 effect
= Column(Unicode(5120), nullable
=False)
200 is_underground
= Column(Boolean
, nullable
=False)
201 can_hold
= Column(Boolean
, nullable
=False)
202 is_battle_item
= Column(Boolean
, nullable
=False)
203 can_use_automatically
= Column(Boolean
, nullable
=False)
204 can_reuse
= Column(Boolean
, nullable
=False)
206 class ItemCategory(TableBase
):
207 __tablename__
= 'item_categories'
208 id = Column(Integer
, primary_key
=True, nullable
=False)
209 pocket_id
= Column(Integer
, ForeignKey('item_pockets.id'), nullable
=False)
210 name
= Column(Unicode(16), nullable
=False)
212 class ItemFlingEffect(TableBase
):
213 __tablename__
= 'item_fling_effects'
214 id = Column(Integer
, primary_key
=True, nullable
=False)
215 effect
= Column(Unicode(255), nullable
=False)
217 class ItemPocket(TableBase
):
218 __tablename__
= 'item_pockets'
219 id = Column(Integer
, primary_key
=True, nullable
=False)
220 name
= Column(Unicode(16), nullable
=False)
222 class Language(TableBase
):
223 __tablename__
= 'languages'
224 id = Column(Integer
, primary_key
=True, nullable
=False)
225 iso639
= Column(Unicode(2), nullable
=False)
226 iso3166
= Column(Unicode(2), nullable
=False)
227 name
= Column(Unicode(16), nullable
=False)
229 class Location(TableBase
):
230 __tablename__
= 'locations'
231 __singlename__
= 'location'
232 id = Column(Integer
, primary_key
=True, nullable
=False)
233 region_id
= Column(Integer
, ForeignKey('regions.id'))
234 name
= Column(Unicode(64), nullable
=False)
236 class LocationArea(TableBase
):
237 __tablename__
= 'location_areas'
238 id = Column(Integer
, primary_key
=True, nullable
=False)
239 location_id
= Column(Integer
, ForeignKey('locations.id'), nullable
=False)
240 internal_id
= Column(Integer
, nullable
=False)
241 name
= Column(Unicode(64), nullable
=True)
243 class LocationAreaEncounterRate(TableBase
):
244 __tablename__
= 'location_area_encounter_rates'
245 location_area_id
= Column(Integer
, ForeignKey('location_areas.id'), primary_key
=True, nullable
=False, autoincrement
=False)
246 encounter_terrain_id
= Column(Integer
, ForeignKey('encounter_terrain.id'), primary_key
=True, nullable
=False, autoincrement
=False)
247 version_id
= Column(Integer
, ForeignKey('versions.id'), primary_key
=True, autoincrement
=False)
248 rate
= Column(Integer
, nullable
=True)
250 class Machine(TableBase
):
251 __tablename__
= 'machines'
252 machine_number
= Column(Integer
, primary_key
=True, nullable
=False, autoincrement
=False)
253 version_group_id
= Column(Integer
, ForeignKey('version_groups.id'), primary_key
=True, nullable
=False, autoincrement
=False)
254 move_id
= Column(Integer
, ForeignKey('moves.id'), nullable
=False)
256 class MoveEffectCategory(TableBase
):
257 __tablename__
= 'move_effect_categories'
258 id = Column(Integer
, primary_key
=True, nullable
=False)
259 name
= Column(Unicode(64), nullable
=False)
260 can_affect_user
= Column(Boolean
, nullable
=False)
262 class MoveEffectCategoryMap(TableBase
):
263 __tablename__
= 'move_effect_category_map'
264 move_effect_id
= Column(Integer
, ForeignKey('move_effects.id'), primary_key
=True, nullable
=False)
265 move_effect_category_id
= Column(Integer
, ForeignKey('move_effect_categories.id'), primary_key
=True, nullable
=False)
266 affects_user
= Column(Boolean
, primary_key
=True, nullable
=False)
268 class MoveDamageClass(TableBase
):
269 __tablename__
= 'move_damage_classes'
270 id = Column(Integer
, primary_key
=True, nullable
=False)
271 name
= Column(Unicode(8), nullable
=False)
272 description
= Column(Unicode(64), nullable
=False)
274 class MoveEffect(TableBase
):
275 __tablename__
= 'move_effects'
276 id = Column(Integer
, primary_key
=True, nullable
=False)
277 priority
= Column(SmallInteger
, nullable
=False)
278 short_effect
= Column(Unicode(256), nullable
=False)
279 effect
= Column(Unicode(5120), nullable
=False)
281 class MoveFlag(TableBase
):
282 __tablename__
= 'move_flags'
283 move_id
= Column(Integer
, ForeignKey('moves.id'), primary_key
=True, nullable
=False, autoincrement
=False)
284 move_flag_type_id
= Column(Integer
, ForeignKey('move_flag_types.id'), primary_key
=True, nullable
=False, autoincrement
=False)
286 class MoveFlagType(TableBase
):
287 __tablename__
= 'move_flag_types'
288 id = Column(Integer
, primary_key
=True, nullable
=False)
289 name
= Column(Unicode(32), nullable
=False)
290 description
= Column(rst
.RstTextColumn(128), nullable
=False)
292 class MoveFlavorText(TableBase
):
293 __tablename__
= 'move_flavor_text'
294 move_id
= Column(Integer
, ForeignKey('moves.id'), primary_key
=True, nullable
=False, autoincrement
=False)
295 generation_id
= Column(Integer
, ForeignKey('generations.id'), primary_key
=True, nullable
=False, autoincrement
=False)
296 flavor_text
= Column(Unicode(255), nullable
=False)
298 class MoveName(TableBase
):
299 __tablename__
= 'move_names'
300 move_id
= Column(Integer
, ForeignKey('moves.id'), primary_key
=True, nullable
=False, autoincrement
=False)
301 language_id
= Column(Integer
, ForeignKey('languages.id'), primary_key
=True, nullable
=False, autoincrement
=False)
302 name
= Column(Unicode(16), nullable
=False)
304 class MoveTarget(TableBase
):
305 __tablename__
= 'move_targets'
306 id = Column(Integer
, primary_key
=True, nullable
=False)
307 name
= Column(Unicode(32), nullable
=False)
308 description
= Column(Unicode(128), nullable
=False)
310 class Move(TableBase
):
311 __tablename__
= 'moves'
312 __singlename__
= 'move'
313 id = Column(Integer
, primary_key
=True, nullable
=False)
314 name
= Column(Unicode(12), nullable
=False)
315 generation_id
= Column(Integer
, ForeignKey('generations.id'), nullable
=False)
316 type_id
= Column(Integer
, ForeignKey('types.id'), nullable
=False)
317 power
= Column(SmallInteger
)
318 pp
= Column(SmallInteger
, nullable
=False)
319 accuracy
= Column(SmallInteger
)
320 target_id
= Column(Integer
, ForeignKey('move_targets.id'), nullable
=False)
321 damage_class_id
= Column(Integer
, ForeignKey('move_damage_classes.id'), nullable
=False)
322 effect_id
= Column(Integer
, ForeignKey('move_effects.id'), nullable
=False)
323 effect_chance
= Column(Integer
)
324 contest_type
= Column(Unicode(8), nullable
=False)
325 contest_effect_id
= Column(Integer
, ForeignKey('contest_effects.id'), nullable
=True)
326 super_contest_effect_id
= Column(Integer
, ForeignKey('super_contest_effects.id'), nullable
=False)
328 class Nature(TableBase
):
329 __tablename__
= 'natures'
330 __singlename__
= 'nature'
331 id = Column(Integer
, primary_key
=True, nullable
=False)
332 name
= Column(Unicode(8), nullable
=False)
333 decreased_stat_id
= Column(Integer
, ForeignKey('stats.id'), nullable
=False)
334 increased_stat_id
= Column(Integer
, ForeignKey('stats.id'), nullable
=False)
336 class Pokedex(TableBase
):
337 __tablename__
= 'pokedexes'
338 id = Column(Integer
, primary_key
=True, nullable
=False)
339 region_id
= Column(Integer
, ForeignKey('regions.id'), nullable
=True)
340 name
= Column(Unicode(16), nullable
=False)
341 description
= Column(Unicode(512))
343 class PokedexVersionGroup(TableBase
):
344 __tablename__
= 'pokedex_version_groups'
345 pokedex_id
= Column(Integer
, ForeignKey('pokedexes.id'), primary_key
=True, nullable
=False, autoincrement
=False)
346 version_group_id
= Column(Integer
, ForeignKey('version_groups.id'), primary_key
=True, nullable
=False, autoincrement
=False)
348 class Pokemon(TableBase
):
349 """The core to this whole mess.
351 Note that I use both 'forme' and 'form' in both code and the database. I
352 only use 'forme' when specifically referring to Pokémon that have multiple
353 distinct species as forms—i.e., different stats or movesets. 'Form' is a
354 more general term referring to any variation within a species, including
355 purely cosmetic forms like Unown.
357 __tablename__
= 'pokemon'
358 __singlename__
= 'pokemon'
359 id = Column(Integer
, primary_key
=True, nullable
=False)
360 name
= Column(Unicode(20), nullable
=False)
361 forme_name
= Column(Unicode(16))
362 forme_base_pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'))
363 generation_id
= Column(Integer
, ForeignKey('generations.id'))
364 evolution_chain_id
= Column(Integer
, ForeignKey('evolution_chains.id'))
365 evolution_parent_pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'))
366 evolution_method_id
= Column(Integer
, ForeignKey('evolution_methods.id'))
367 evolution_parameter
= Column(Unicode(32))
368 height
= Column(Integer
, nullable
=False)
369 weight
= Column(Integer
, nullable
=False)
370 species
= Column(Unicode(16), nullable
=False)
371 color_id
= Column(Integer
, ForeignKey('pokemon_colors.id'), nullable
=False)
372 pokemon_shape_id
= Column(Integer
, ForeignKey('pokemon_shapes.id'), nullable
=False)
373 habitat_id
= Column(Integer
, ForeignKey('pokemon_habitats.id'), nullable
=True)
374 gender_rate
= Column(Integer
, nullable
=False)
375 capture_rate
= Column(Integer
, nullable
=False)
376 base_experience
= Column(Integer
, nullable
=False)
377 base_happiness
= Column(Integer
, nullable
=False)
378 is_baby
= Column(Boolean
, nullable
=False)
379 has_gen4_fem_sprite
= Column(Boolean
, nullable
=False)
380 has_gen4_fem_back_sprite
= Column(Boolean
, nullable
=False)
382 ### Stuff to handle alternate Pokémon forms
385 def national_id(self
):
386 """Returns the National Pokédex number for this Pokémon. Use this
387 instead of the id directly; alternate formes may make the id incorrect.
390 if self
.forme_base_pokemon_id
:
391 return self
.forme_base_pokemon_id
396 """Returns the name of this Pokémon, including its Forme, if any."""
399 return "%s %s" %
(self
.forme_name
.title(), self
.name
)
403 def normal_form(self
):
404 """Returns the normal form for this Pokémon; i.e., this will return
405 regular Deoxys when called on any Deoxys form.
408 if self
.forme_base_pokemon
:
409 return self
.forme_base_pokemon
415 def stat(self
, stat_name
):
416 """Returns a PokemonStat record for the given stat name (or Stat row
417 object). Uses the normal has-many machinery, so all the stats are
420 if isinstance(stat_name
, Stat
):
421 stat_name
= stat_name
.name
423 for pokemon_stat
in self
.stats
:
424 if pokemon_stat
.stat
.name
== stat_name
:
429 class PokemonAbility(TableBase
):
430 __tablename__
= 'pokemon_abilities'
431 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
432 ability_id
= Column(Integer
, ForeignKey('abilities.id'), nullable
=False)
433 slot
= Column(Integer
, primary_key
=True, nullable
=False, autoincrement
=False)
435 class PokemonColor(TableBase
):
436 __tablename__
= 'pokemon_colors'
437 id = Column(Integer
, primary_key
=True, nullable
=False, autoincrement
=False)
438 name
= Column(Unicode(6), nullable
=False)
440 class PokemonDexNumber(TableBase
):
441 __tablename__
= 'pokemon_dex_numbers'
442 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
443 pokedex_id
= Column(Integer
, ForeignKey('pokedexes.id'), primary_key
=True, nullable
=False, autoincrement
=False)
444 pokedex_number
= Column(Integer
, nullable
=False)
446 class PokemonEggGroup(TableBase
):
447 __tablename__
= 'pokemon_egg_groups'
448 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
449 egg_group_id
= Column(Integer
, ForeignKey('egg_groups.id'), primary_key
=True, nullable
=False, autoincrement
=False)
451 class PokemonFlavorText(TableBase
):
452 __tablename__
= 'pokemon_flavor_text'
453 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
454 version_id
= Column(Integer
, ForeignKey('versions.id'), primary_key
=True, nullable
=False, autoincrement
=False)
455 flavor_text
= Column(Unicode(255), nullable
=False)
457 class PokemonFormGroup(TableBase
):
458 __tablename__
= 'pokemon_form_groups'
459 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
460 is_battle_only
= Column(Boolean
, nullable
=False)
461 description
= Column(Unicode(512), nullable
=False)
463 class PokemonFormSprite(TableBase
):
464 __tablename__
= 'pokemon_form_sprites'
465 id = Column(Integer
, primary_key
=True, nullable
=False)
466 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
467 introduced_in_version_group_id
= Column(Integer
, ForeignKey('version_groups.id'), primary_key
=True, nullable
=False, autoincrement
=False)
468 name
= Column(Unicode(16), nullable
=True)
469 is_default
= Column(Boolean
, nullable
=True)
471 class PokemonHabitat(TableBase
):
472 __tablename__
= 'pokemon_habitats'
473 id = Column(Integer
, primary_key
=True, nullable
=False, autoincrement
=False)
474 name
= Column(Unicode(16), nullable
=False)
476 class PokemonItem(TableBase
):
477 __tablename__
= 'pokemon_items'
478 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
479 version_id
= Column(Integer
, ForeignKey('versions.id'), primary_key
=True, nullable
=False, autoincrement
=False)
480 item_id
= Column(Integer
, ForeignKey('items.id'), primary_key
=True, nullable
=False, autoincrement
=False)
481 rarity
= Column(Integer
, nullable
=False)
483 class PokemonMove(TableBase
):
484 __tablename__
= 'pokemon_moves'
485 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
486 version_group_id
= Column(Integer
, ForeignKey('version_groups.id'), primary_key
=True, nullable
=False, autoincrement
=False)
487 move_id
= Column(Integer
, ForeignKey('moves.id'), primary_key
=True, nullable
=False, autoincrement
=False, index
=True)
488 pokemon_move_method_id
= Column(Integer
, ForeignKey('pokemon_move_methods.id'), primary_key
=True, nullable
=False, autoincrement
=False)
489 level
= Column(Integer
, primary_key
=True, nullable
=True, autoincrement
=False)
490 order
= Column(Integer
, nullable
=True)
492 class PokemonMoveMethod(TableBase
):
493 __tablename__
= 'pokemon_move_methods'
494 id = Column(Integer
, primary_key
=True, nullable
=False, autoincrement
=False)
495 name
= Column(Unicode(64), nullable
=False)
496 description
= Column(Unicode(255), nullable
=False)
498 class PokemonName(TableBase
):
499 __tablename__
= 'pokemon_names'
500 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
501 language_id
= Column(Integer
, ForeignKey('languages.id'), primary_key
=True, nullable
=False, autoincrement
=False)
502 name
= Column(Unicode(16), nullable
=False)
504 class PokemonShape(TableBase
):
505 __tablename__
= 'pokemon_shapes'
506 id = Column(Integer
, primary_key
=True, nullable
=False)
507 name
= Column(Unicode(24), nullable
=False)
508 awesome_name
= Column(Unicode(16), nullable
=False)
510 class PokemonStat(TableBase
):
511 __tablename__
= 'pokemon_stats'
512 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
513 stat_id
= Column(Integer
, ForeignKey('stats.id'), primary_key
=True, nullable
=False, autoincrement
=False)
514 base_stat
= Column(Integer
, nullable
=False)
515 effort
= Column(Integer
, nullable
=False)
517 class PokemonType(TableBase
):
518 __tablename__
= 'pokemon_types'
519 pokemon_id
= Column(Integer
, ForeignKey('pokemon.id'), primary_key
=True, nullable
=False, autoincrement
=False)
520 type_id
= Column(Integer
, ForeignKey('types.id'), nullable
=False)
521 slot
= Column(Integer
, primary_key
=True, nullable
=False, autoincrement
=False)
523 class Region(TableBase
):
524 """Major areas of the world: Kanto, Johto, etc."""
525 __tablename__
= 'regions'
526 id = Column(Integer
, primary_key
=True, nullable
=False)
527 name
= Column(Unicode(16), nullable
=False)
529 class Stat(TableBase
):
530 __tablename__
= 'stats'
531 id = Column(Integer
, primary_key
=True, nullable
=False)
532 name
= Column(Unicode(16), nullable
=False)
534 class SuperContestCombo(TableBase
):
535 __tablename__
= 'super_contest_combos'
536 first_move_id
= Column(Integer
, ForeignKey('moves.id'), primary_key
=True, nullable
=False, autoincrement
=False)
537 second_move_id
= Column(Integer
, ForeignKey('moves.id'), primary_key
=True, nullable
=False, autoincrement
=False)
539 class SuperContestEffect(TableBase
):
540 __tablename__
= 'super_contest_effects'
541 id = Column(Integer
, primary_key
=True, nullable
=False)
542 appeal
= Column(SmallInteger
, nullable
=False)
543 flavor_text
= Column(Unicode(64), nullable
=False)
545 class TypeEfficacy(TableBase
):
546 __tablename__
= 'type_efficacy'
547 damage_type_id
= Column(Integer
, ForeignKey('types.id'), primary_key
=True, nullable
=False, autoincrement
=False)
548 target_type_id
= Column(Integer
, ForeignKey('types.id'), primary_key
=True, nullable
=False, autoincrement
=False)
549 damage_factor
= Column(Integer
, nullable
=False)
551 class Type(TableBase
):
552 __tablename__
= 'types'
553 __singlename__
= 'type'
554 id = Column(Integer
, primary_key
=True, nullable
=False)
555 name
= Column(Unicode(8), nullable
=False)
556 abbreviation
= Column(Unicode(3), nullable
=False)
557 generation_id
= Column(Integer
, ForeignKey('generations.id'), nullable
=False)
558 damage_class_id
= Column(Integer
, ForeignKey('move_damage_classes.id'), nullable
=False) ## ??? is none; everything else is physical or special
560 class VersionGroup(TableBase
):
561 __tablename__
= 'version_groups'
562 id = Column(Integer
, primary_key
=True, nullable
=False)
563 generation_id
= Column(Integer
, ForeignKey('generations.id'), nullable
=False)
565 class VersionGroupRegion(TableBase
):
566 __tablename__
= 'version_group_regions'
567 version_group_id
= Column(Integer
, ForeignKey('version_groups.id'), primary_key
=True, nullable
=False)
568 region_id
= Column(Integer
, ForeignKey('regions.id'), primary_key
=True, nullable
=False)
570 class Version(TableBase
):
571 __tablename__
= 'versions'
572 id = Column(Integer
, primary_key
=True, nullable
=False)
573 version_group_id
= Column(Integer
, ForeignKey('version_groups.id'), nullable
=False)
574 name
= Column(Unicode(32), nullable
=False)
577 ### Relations down here, to avoid ordering problems
578 Berry
.berry_firmness
= relation(BerryFirmness
, backref
='berries')
579 Berry
.firmness
= association_proxy('berry_firmness', 'name')
580 Berry
.flavors
= relation(BerryFlavor
, order_by
=BerryFlavor
.contest_type_id
, backref
='berry')
581 Berry
.natural_gift_type
= relation(Type
)
583 BerryFlavor
.contest_type
= relation(ContestType
)
585 ContestCombo
.first
= relation(Move
, primaryjoin
=ContestCombo
.first_move_id
==Move
.id,
586 backref
='contest_combo_first')
587 ContestCombo
.second
= relation(Move
, primaryjoin
=ContestCombo
.second_move_id
==Move
.id,
588 backref
='contest_combo_second')
590 Encounter
.location_area
= relation(LocationArea
, backref
='encounters')
591 Encounter
.pokemon
= relation(Pokemon
, backref
='encounters')
592 Encounter
.version
= relation(Version
, backref
='encounters')
593 Encounter
.slot
= relation(EncounterSlot
, backref
='encounters')
595 EncounterConditionValue
.condition
= relation(EncounterCondition
, backref
='values')
597 Encounter
.condition_value_map
= relation(EncounterConditionValueMap
, backref
='encounter')
598 Encounter
.condition_values
= association_proxy('condition_value_map', 'condition_value')
599 EncounterConditionValueMap
.condition_value
= relation(EncounterConditionValue
,
600 backref
='encounter_map')
602 EncounterSlot
.terrain
= relation(EncounterTerrain
, backref
='slots')
604 EncounterSlot
.condition_map
= relation(EncounterSlotCondition
, backref
='slot')
605 EncounterSlot
.conditions
= association_proxy('condition_map', 'condition')
606 EncounterSlotCondition
.condition
= relation(EncounterCondition
,
609 EvolutionChain
.growth_rate
= relation(GrowthRate
, backref
='evolution_chains')
611 Generation
.canonical_pokedex
= relation(Pokedex
, backref
='canonical_for_generation')
612 Generation
.versions
= relation(Version
, secondary
=VersionGroup
.__table__
)
613 Generation
.main_region
= relation(Region
)
615 Item
.berry
= relation(Berry
, uselist
=False, backref
='item')
616 Item
.fling_effect
= relation(ItemFlingEffect
, backref
='items')
617 Item
.category
= relation(ItemCategory
, backref
='items')
619 ItemCategory
.pocket
= relation(ItemPocket
, backref
='categories')
621 Location
.region
= relation(Region
, backref
='locations')
623 LocationArea
.location
= relation(Location
, backref
='areas')
625 Machine
.version_group
= relation(VersionGroup
)
627 Move
.contest_effect
= relation(ContestEffect
, backref
='moves')
628 Move
.contest_combo_next
= association_proxy('contest_combo_first', 'second')
629 Move
.contest_combo_prev
= association_proxy('contest_combo_second', 'first')
630 Move
.damage_class
= relation(MoveDamageClass
, backref
='moves')
631 Move
.flags
= association_proxy('move_flags', 'flag')
632 Move
.flavor_text
= relation(MoveFlavorText
, order_by
=MoveFlavorText
.generation_id
, backref
='move')
633 Move
.foreign_names
= relation(MoveName
, backref
='pokemon')
634 Move
.generation
= relation(Generation
, backref
='moves')
635 Move
.machines
= relation(Machine
, backref
='move')
636 Move
.move_effect
= relation(MoveEffect
, backref
='moves')
637 Move
.move_flags
= relation(MoveFlag
, backref
='move')
638 Move
.super_contest_effect
= relation(SuperContestEffect
, backref
='moves')
639 Move
.super_contest_combo_next
= association_proxy('super_contest_combo_first', 'second')
640 Move
.super_contest_combo_prev
= association_proxy('super_contest_combo_second', 'first')
641 Move
.target
= relation(MoveTarget
, backref
='moves')
642 Move
.type = relation(Type
, backref
='moves')
644 Move
.effect
= rst
.MoveEffectProperty('effect')
645 Move
.priority
= association_proxy('move_effect', 'priority')
646 Move
.short_effect
= rst
.MoveEffectProperty('short_effect')
648 MoveEffect
.category_map
= relation(MoveEffectCategoryMap
)
649 MoveEffect
.categories
= association_proxy('category_map', 'category')
650 MoveEffectCategoryMap
.category
= relation(MoveEffectCategory
)
652 MoveFlag
.flag
= relation(MoveFlagType
)
654 MoveFlavorText
.generation
= relation(Generation
)
656 MoveName
.language
= relation(Language
)
658 Nature
.decreased_stat
= relation(Stat
, primaryjoin
=Nature
.decreased_stat_id
==Stat
.id,
659 backref
='decreasing_natures')
660 Nature
.increased_stat
= relation(Stat
, primaryjoin
=Nature
.increased_stat_id
==Stat
.id,
661 backref
='increasing_natures')
663 Pokedex
.region
= relation(Region
, backref
='pokedexes')
664 Pokedex
.version_groups
= relation(VersionGroup
, secondary
=PokedexVersionGroup
.__table__
, backref
='pokedexes')
666 Pokemon
.abilities
= relation(Ability
, secondary
=PokemonAbility
.__table__
,
667 order_by
=PokemonAbility
.slot
,
669 Pokemon
.formes
= relation(Pokemon
, primaryjoin
=Pokemon
.id==Pokemon
.forme_base_pokemon_id
,
670 backref
=backref('forme_base_pokemon',
671 remote_side
=[Pokemon
.id]))
672 Pokemon
.pokemon_color
= relation(PokemonColor
, backref
='pokemon')
673 Pokemon
.color
= association_proxy('pokemon_color', 'name')
674 Pokemon
.dex_numbers
= relation(PokemonDexNumber
, backref
='pokemon')
675 Pokemon
.default_form_sprite
= relation(PokemonFormSprite
,
677 Pokemon
.id==PokemonFormSprite
.pokemon_id
,
678 PokemonFormSprite
.is_default
==True,
681 Pokemon
.egg_groups
= relation(EggGroup
, secondary
=PokemonEggGroup
.__table__
,
682 order_by
=PokemonEggGroup
.egg_group_id
,
684 Pokemon
.evolution_chain
= relation(EvolutionChain
, backref
='pokemon')
685 Pokemon
.evolution_method
= relation(EvolutionMethod
)
686 Pokemon
.evolution_children
= relation(Pokemon
, primaryjoin
=Pokemon
.id==Pokemon
.evolution_parent_pokemon_id
,
687 backref
=backref('evolution_parent',
688 remote_side
=[Pokemon
.id]))
689 Pokemon
.flavor_text
= relation(PokemonFlavorText
, order_by
=PokemonFlavorText
.pokemon_id
, backref
='pokemon')
690 Pokemon
.foreign_names
= relation(PokemonName
, backref
='pokemon')
691 Pokemon
.pokemon_habitat
= relation(PokemonHabitat
, backref
='pokemon')
692 Pokemon
.habitat
= association_proxy('pokemon_habitat', 'name')
693 Pokemon
.items
= relation(PokemonItem
, backref
='pokemon')
694 Pokemon
.generation
= relation(Generation
, backref
='pokemon')
695 Pokemon
.shape
= relation(PokemonShape
, backref
='pokemon')
696 Pokemon
.stats
= relation(PokemonStat
, backref
='pokemon')
697 Pokemon
.types
= relation(Type
, secondary
=PokemonType
.__table__
)
699 PokemonDexNumber
.pokedex
= relation(Pokedex
)
701 PokemonFlavorText
.version
= relation(Version
)
703 PokemonItem
.item
= relation(Item
, backref
='pokemon')
704 PokemonItem
.version
= relation(Version
)
706 PokemonFormGroup
.pokemon
= relation(Pokemon
, backref
=backref('form_group',
708 PokemonFormSprite
.pokemon
= relation(Pokemon
, backref
='form_sprites')
709 PokemonFormSprite
.introduced_in
= relation(VersionGroup
)
711 PokemonMove
.pokemon
= relation(Pokemon
, backref
='pokemon_moves')
712 PokemonMove
.version_group
= relation(VersionGroup
)
713 PokemonMove
.machine
= relation(Machine
, backref
='pokemon_moves',
714 primaryjoin
=and_(Machine
.version_group_id
==PokemonMove
.version_group_id
,
715 Machine
.move_id
==PokemonMove
.move_id
),
716 foreign_keys
=[Machine
.version_group_id
, Machine
.move_id
],
718 PokemonMove
.move
= relation(Move
, backref
='pokemon_moves')
719 PokemonMove
.method
= relation(PokemonMoveMethod
)
721 PokemonName
.language
= relation(Language
)
723 PokemonStat
.stat
= relation(Stat
)
725 # This is technically a has-many; Generation.main_region_id -> Region.id
726 Region
.generation
= relation(Generation
, uselist
=False)
727 Region
.version_group_regions
= relation(VersionGroupRegion
, backref
='region',
728 order_by
='VersionGroupRegion.version_group_id')
729 Region
.version_groups
= association_proxy('version_group_regions', 'version_group')
731 SuperContestCombo
.first
= relation(Move
, primaryjoin
=SuperContestCombo
.first_move_id
==Move
.id,
732 backref
='super_contest_combo_first')
733 SuperContestCombo
.second
= relation(Move
, primaryjoin
=SuperContestCombo
.second_move_id
==Move
.id,
734 backref
='super_contest_combo_second')
736 Type
.damage_efficacies
= relation(TypeEfficacy
,
738 ==TypeEfficacy
.damage_type_id
,
739 backref
='damage_type')
740 Type
.target_efficacies
= relation(TypeEfficacy
,
742 ==TypeEfficacy
.target_type_id
,
743 backref
='target_type')
745 Type
.generation
= relation(Generation
, backref
='types')
746 Type
.damage_class
= relation(MoveDamageClass
, backref
='types')
748 Version
.version_group
= relation(VersionGroup
, backref
='versions')
749 Version
.generation
= association_proxy('version_group', 'generation')
751 VersionGroup
.generation
= relation(Generation
, backref
='version_groups')
752 VersionGroup
.version_group_regions
= relation(VersionGroupRegion
, backref
='version_group')
753 VersionGroup
.regions
= association_proxy('version_group_regions', 'region')