48fed810863592a6526c488bc9c8b07e16952f2a
[zzz-pokedex.git] / pokedex / db / tables.py
1 # encoding: utf8
2
3 u"""The Pokédex schema
4
5 Columns have a info dictionary with these keys:
6 - description: The description of the column
7 - official: True if the values appear in games or official material; False if
8 they are fan-created or fan-written. This flag is currently only set for
9 official text columns.
10 - markup: The format of a text column. Can be one of:
11 - plaintext: Normal Unicode text (widely used in names)
12 - markdown: Veekun's Markdown flavor (generally used in effect descriptions)
13 - gametext: Transcription of in-game text that strives to be both
14 human-readable and represent the original text exactly.
15 - identifier: A fan-made identifier in the [-_a-z0-9]* format. Not intended
16 for translation.
17 - latex: A formula in LaTeX syntax.
18
19 A localizable text column is visible as two properties:
20 The plural-name property (e.g. Pokemon.names) is a language-to-name dictionary:
21 bulbasaur.names['en'] == "Bulbasaur" and bulbasaur.names['de'] == "Bisasam".
22 You can use Pokemon.names['en'] to filter a query.
23 The singular-name property returns the name in the default language, English.
24 For example bulbasaur.name == "Bulbasaur"
25 Setting pokedex.db.tables.default_lang changes the default language.
26 """
27 # XXX: Check if "gametext" is set correctly everywhere
28
29 import collections
30 from functools import partial
31
32 from sqlalchemy import Column, ForeignKey, MetaData, PrimaryKeyConstraint, Table, UniqueConstraint
33 from sqlalchemy.ext.declarative import (
34 declarative_base, declared_attr, DeclarativeMeta,
35 )
36 from sqlalchemy.ext.associationproxy import association_proxy
37 from sqlalchemy.orm import (
38 backref, compile_mappers, eagerload_all, relation, class_mapper, synonym, mapper,
39 )
40 from sqlalchemy.orm.session import Session, object_session
41 from sqlalchemy.orm.interfaces import AttributeExtension
42 from sqlalchemy.orm.collections import attribute_mapped_collection, MappedCollection, collection, collection_adapter
43 from sqlalchemy.ext.associationproxy import _AssociationDict, association_proxy
44 from sqlalchemy.sql import and_
45 from sqlalchemy.sql.expression import ColumnOperators, bindparam
46 from sqlalchemy.schema import ColumnDefault
47 from sqlalchemy.types import *
48 from inspect import isclass
49
50 from pokedex.db import markdown, multilang
51
52 class TableSuperclass(object):
53 """Superclass for declarative tables, to give them some generic niceties
54 like stringification.
55 """
56 def __unicode__(self):
57 """Be as useful as possible. Show the primary key, and an identifier
58 if we've got one.
59 """
60 typename = u'.'.join((__name__, type(self).__name__))
61
62 pk_constraint = self.__table__.primary_key
63 if not pk_constraint:
64 return u"<%s object at %x>" % (typename, id(self))
65
66 pk = u', '.join(unicode(getattr(self, column.name))
67 for column in pk_constraint.columns)
68 try:
69 return u"<%s object (%s): %s>" % (typename, pk, self.identifier)
70 except AttributeError:
71 return u"<%s object (%s)>" % (typename, pk)
72
73 def __str__(self):
74 return unicode(self).encode('utf8')
75
76 metadata = MetaData()
77 TableBase = declarative_base(metadata=metadata, cls=TableSuperclass)
78
79
80 ### Need Language first, to create the partial() below
81
82 class Language(TableBase):
83 u"""A language the Pokémon games have been transleted into
84 """
85 __tablename__ = 'languages'
86 __singlename__ = 'language'
87 id = Column(Integer, primary_key=True, nullable=False,
88 info=dict(description="A numeric ID"))
89 iso639 = Column(Unicode(2), nullable=False,
90 info=dict(description="The two-letter code of the country where this language is spoken. Note that it is not unique.", format='identifier'))
91 iso3166 = Column(Unicode(2), nullable=False,
92 info=dict(description="The two-letter code of the language. Note that it is not unique.", format='identifier'))
93 identifier = Column(Unicode(16), nullable=False,
94 info=dict(description="An identifier", format='identifier'))
95 official = Column(Boolean, nullable=False, index=True,
96 info=dict(description=u"True iff games are produced in the language."))
97 order = Column(Integer, nullable=True,
98 info=dict(description=u"Order for sorting in foreign name lists."))
99
100 create_translation_table = partial(multilang.create_translation_table, language_class=Language)
101
102 create_translation_table('language_names', Language, 'names',
103 name = Column(Unicode(16), nullable=False, index=True,
104 info=dict(description="The name", format='plaintext', official=True)),
105 )
106
107 ### The actual tables
108
109 class Ability(TableBase):
110 u"""An ability a Pokémon can have, such as Static or Pressure.
111 """
112 __tablename__ = 'abilities'
113 __singlename__ = 'ability'
114 id = Column(Integer, primary_key=True, nullable=False,
115 info=dict(description="This ability's unique ID; matches the games' internal ID"))
116 identifier = Column(Unicode(24), nullable=False,
117 info=dict(description="An identifier", format='identifier'))
118 generation_id = Column(Integer, ForeignKey('generations.id'), nullable=False,
119 info=dict(description="The ID of the generation this ability was introduced in", detail=True))
120
121 create_translation_table('ability_names', Ability, 'names',
122 name = Column(Unicode(24), nullable=False, index=True,
123 info=dict(description="The name", format='plaintext', official=True)),
124 )
125 create_translation_table('ability_prose', Ability, 'prose',
126 effect = Column(markdown.MarkdownColumn(5120), nullable=False,
127 info=dict(description="A detailed description of this ability's effect", format='markdown')),
128 short_effect = Column(markdown.MarkdownColumn(255), nullable=False,
129 info=dict(description="A short summary of this ability's effect", format='markdown')),
130 )
131
132 class AbilityChangelog(TableBase):
133 """History of changes to abilities across main game versions."""
134 __tablename__ = 'ability_changelog'
135 __singlename__ = 'ability_changelog'
136 id = Column(Integer, primary_key=True, nullable=False,
137 info=dict(description="This change's unique ID"))
138 ability_id = Column(Integer, ForeignKey('abilities.id'), nullable=False,
139 info=dict(description="The ID of the ability that changed"))
140 changed_in_version_group_id = Column(Integer, ForeignKey('version_groups.id'), nullable=False,
141 info=dict(description="The ID of the version group in which the ability changed"))
142
143 create_translation_table('ability_changelog_prose', AbilityChangelog, 'prose',
144 effect = Column(markdown.MarkdownColumn(255), nullable=False,
145 info=dict(description="A description of the old behavior", format='markdown'))
146 )
147
148 class AbilityFlavorText(TableBase):
149 u"""In-game flavor text of an ability
150 """
151 __tablename__ = 'ability_flavor_text'
152 ability_id = Column(Integer, ForeignKey('abilities.id'), primary_key=True, nullable=False, autoincrement=False,
153 info=dict(description="The ID of the ability"))
154 version_group_id = Column(Integer, ForeignKey('version_groups.id'), primary_key=True, nullable=False, autoincrement=False,
155 info=dict(description="The ID of the version group this flavor text is taken from"))
156 language_id = Column(Integer, ForeignKey('languages.id'), primary_key=True, nullable=False,
157 info=dict(description="The language"))
158 flavor_text = Column(Unicode(64), nullable=False,
159 info=dict(description="The actual flavor text", official=True, format='gametext'))
160
161 class Berry(TableBase):
162 u"""A Berry, consumable item that grows on trees
163
164 For data common to all items, such as the name, see the corresponding item entry.
165 """
166 __tablename__ = 'berries'
167 id = Column(Integer, primary_key=True, nullable=False,
168 info=dict(description="This Berry's in-game number"))
169 item_id = Column(Integer, ForeignKey('items.id'), nullable=False,
170 info=dict(description="The ID of the item that represents this Berry"))
171 firmness_id = Column(Integer, ForeignKey('berry_firmness.id'), nullable=False,
172 info=dict(description="The ID of this Berry's firmness category"))
173 natural_gift_power = Column(Integer, nullable=True,
174 info=dict(description="Natural Gift's power when used with this Berry"))
175 natural_gift_type_id = Column(Integer, ForeignKey('types.id'), nullable=True,
176 info=dict(description="The ID of the Type that Natural Gift has when used with this Berry"))
177 size = Column(Integer, nullable=False,
178 info=dict(description=u"The size of this Berry, in millimeters"))
179 max_harvest = Column(Integer, nullable=False,
180 info=dict(description="The maximum number of these berries that can grow on one tree in Generation IV"))
181 growth_time = Column(Integer, nullable=False,
182 info=dict(description="Time it takes the tree to grow one stage, in hours. Berry trees go through four of these growth stages before they can be picked."))
183 soil_dryness = Column(Integer, nullable=False,
184 info=dict(description="The speed at which this Berry dries out the soil as it grows. A higher rate means the soil dries more quickly."))
185 smoothness = Column(Integer, nullable=False,
186 info=dict(description="The smoothness of this Berry, used in making Pokéblocks or Poffins"))
187
188 class BerryFirmness(TableBase):
189 u"""A Berry firmness, such as "hard" or "very soft".
190 """
191 __tablename__ = 'berry_firmness'
192 __singlename__ = 'berry_firmness'
193 id = Column(Integer, primary_key=True, nullable=False,
194 info=dict(description="A unique ID for this firmness"))
195 identifier = Column(Unicode(10), nullable=False,
196 info=dict(description="An identifier", format='identifier'))
197
198 create_translation_table('berry_firmness_names', BerryFirmness, 'names',
199 name = Column(Unicode(10), nullable=False, index=True,
200 info=dict(description="The name", format='plaintext', official=True)),
201 )
202
203 class BerryFlavor(TableBase):
204 u"""A Berry flavor level.
205 """
206 __tablename__ = 'berry_flavors'
207 berry_id = Column(Integer, ForeignKey('berries.id'), primary_key=True, nullable=False, autoincrement=False,
208 info=dict(description="The ID of the berry"))
209 contest_type_id = Column(Integer, ForeignKey('contest_types.id'), primary_key=True, nullable=False, autoincrement=False,
210 info=dict(description="The ID of the flavor"))
211 flavor = Column(Integer, nullable=False,
212 info=dict(description="The level of the flavor in the berry"))
213
214 class ContestCombo(TableBase):
215 u"""Combo of two moves in a Contest.
216 """
217 __tablename__ = 'contest_combos'
218 first_move_id = Column(Integer, ForeignKey('moves.id'), primary_key=True, nullable=False, autoincrement=False,
219 info=dict(description="The ID of the first move in the combo"))
220 second_move_id = Column(Integer, ForeignKey('moves.id'), primary_key=True, nullable=False, autoincrement=False,
221 info=dict(description="The ID of the second and final move in the combo"))
222
223 class ContestEffect(TableBase):
224 u"""Effect of a move when used in a Contest.
225 """
226 __tablename__ = 'contest_effects'
227 __singlename__ = 'contest_effect'
228 id = Column(Integer, primary_key=True, nullable=False,
229 info=dict(description="A unique ID for this effect"))
230 appeal = Column(SmallInteger, nullable=False,
231 info=dict(description="The base number of hearts the user of this move gets"))
232 jam = Column(SmallInteger, nullable=False,
233 info=dict(description="The base number of hearts the user's opponent loses"))
234
235 create_translation_table('contest_effect_prose', ContestEffect, 'prose',
236 flavor_text = Column(Unicode(64), nullable=False,
237 info=dict(description="The in-game description of this effect", official=True, format='gametext')),
238 effect = Column(Unicode(255), nullable=False,
239 info=dict(description="A detailed description of the effect", format='plaintext')),
240 )
241
242 class ContestType(TableBase):
243 u"""A Contest type, such as "cool" or "smart", and their associated Berry flavors and Pokéblock colors.
244 """
245 __tablename__ = 'contest_types'
246 __singlename__ = 'contest_type'
247 id = Column(Integer, primary_key=True, nullable=False,
248 info=dict(description="A unique ID for this Contest type"))
249 identifier = Column(Unicode(6), nullable=False,
250 info=dict(description="An identifier", format='identifier'))
251
252 create_translation_table('contest_type_names', ContestType, 'names',
253 name = Column(Unicode(6), nullable=False, index=True,
254 info=dict(description="The name", format='plaintext', official=True)),
255 flavor = Column(Unicode(6), nullable=False,
256 info=dict(description="The name of the corresponding Berry flavor", official=True, format='plaintext')),
257 color = Column(Unicode(6), nullable=False,
258 info=dict(description=u"The name of the corresponding Pokéblock color", official=True, format='plaintext')),
259 )
260
261 class EggGroup(TableBase):
262 u"""An Egg group. Usually, two Pokémon can breed if they share an Egg Group.
263
264 (exceptions are the Ditto and No Eggs groups)
265 """
266 __tablename__ = 'egg_groups'
267 __singlename__ = 'egg_group'
268 id = Column(Integer, primary_key=True, nullable=False,
269 info=dict(description="A unique ID for this group"))
270 identifier = Column(Unicode(16), nullable=False,
271 info=dict(description=u"An identifier.", format='identifier'))
272
273 create_translation_table('egg_group_prose', EggGroup, 'names',
274 name = Column(Unicode(16), nullable=False, index=True,
275 info=dict(description="The name", format='plaintext', official=False)),
276 )
277
278 class Encounter(TableBase):
279 u"""Encounters with wild Pokémon.
280
281 Bear with me, here.
282
283 Within a given area in a given game, encounters are differentiated by the
284 "slot" they are in and the state of the game world.
285
286 What the player is doing to get an encounter, such as surfing or walking
287 through tall grass, is called terrain. Each terrain has its own set of
288 encounter slots.
289
290 Within a terrain, slots are defined primarily by rarity. Each slot can
291 also be affected by world conditions; for example, the 20% slot for walking
292 in tall grass is affected by whether a swarm is in effect in that area.
293 "Is there a swarm?" is a condition; "there is a swarm" and "there is not a
294 swarm" are the possible values of this condition.
295
296 A slot (20% walking in grass) and any appropriate world conditions (no
297 swarm) are thus enough to define a specific encounter.
298
299 Well, okay, almost: each slot actually appears twice.
300 """
301
302 __tablename__ = 'encounters'
303 id = Column(Integer, primary_key=True, nullable=False,
304 info=dict(description="A unique ID for this encounter"))
305 version_id = Column(Integer, ForeignKey('versions.id'), nullable=False, autoincrement=False,
306 info=dict(description="The ID of the version this applies to"))
307 location_area_id = Column(Integer, ForeignKey('location_areas.id'), nullable=False, autoincrement=False,
308 info=dict(description="The ID of the location of this encounter"))
309 encounter_slot_id = Column(Integer, ForeignKey('encounter_slots.id'), nullable=False, autoincrement=False,
310 info=dict(description="The ID of the encounter slot, which determines terrain and rarity"))
311 pokemon_id = Column(Integer, ForeignKey('pokemon.id'), nullable=False, autoincrement=False,
312 info=dict(description=u"The ID of the encountered Pokémon"))
313 min_level = Column(Integer, nullable=False, autoincrement=False,
314 info=dict(description=u"The minimum level of the encountered Pokémon"))
315 max_level = Column(Integer, nullable=False, autoincrement=False,
316 info=dict(description=u"The maxmum level of the encountered Pokémon"))
317
318 class EncounterCondition(TableBase):
319 u"""A conditions in the game world that affects Pokémon encounters, such as time of day.
320 """
321
322 __tablename__ = 'encounter_conditions'
323 __singlename__ = 'encounter_condition'
324 id = Column(Integer, primary_key=True, nullable=False,
325 info=dict(description="A unique ID for this condition"))
326 identifier = Column(Unicode(64), nullable=False,
327 info=dict(description="An identifier", format='identifier'))
328
329 create_translation_table('encounter_condition_prose', EncounterCondition, 'prose',
330 name = Column(Unicode(64), nullable=False, index=True,
331 info=dict(description="The name", format='plaintext', official=False)),
332 )
333
334 class EncounterConditionValue(TableBase):
335 u"""A possible state for a condition; for example, the state of 'swarm' could be 'swarm' or 'no swarm'.
336 """
337
338 __tablename__ = 'encounter_condition_values'
339 __singlename__ = 'encounter_condition_value'
340 id = Column(Integer, primary_key=True, nullable=False,
341 info=dict(description="A numeric ID"))
342 encounter_condition_id = Column(Integer, ForeignKey('encounter_conditions.id'), primary_key=False, nullable=False, autoincrement=False,
343 info=dict(description="The ID of the encounter condition this is a value of"))
344 identifier = Column(Unicode(64), nullable=False,
345 info=dict(description="An identifier", format='identifier'))
346 is_default = Column(Boolean, nullable=False,
347 info=dict(description='Set if this value is the default state for the condition'))
348
349 create_translation_table('encounter_condition_value_prose', EncounterConditionValue, 'prose',
350 name = Column(Unicode(64), nullable=False, index=True,
351 info=dict(description="The name", format='plaintext', official=False)),
352 )
353
354 class EncounterConditionValueMap(TableBase):
355 u"""Maps encounters to the specific conditions under which they occur.
356 """
357 __tablename__ = 'encounter_condition_value_map'
358 encounter_id = Column(Integer, ForeignKey('encounters.id'), primary_key=True, nullable=False, autoincrement=False,
359 info=dict(description="The ID of the encounter"))
360 encounter_condition_value_id = Column(Integer, ForeignKey('encounter_condition_values.id'), primary_key=True, nullable=False, autoincrement=False,
361 info=dict(description="The ID of the encounter condition value"))
362
363 class EncounterTerrain(TableBase):
364 u"""A way the player can enter a wild encounter, e.g., surfing, fishing, or walking through tall grass.
365 """
366
367 __tablename__ = 'encounter_terrain'
368 __singlename__ = __tablename__
369 id = Column(Integer, primary_key=True, nullable=False,
370 info=dict(description="A unique ID for the terrain"))
371 identifier = Column(Unicode(64), nullable=False,
372 info=dict(description="An identifier", format='identifier'))
373
374 create_translation_table('encounter_terrain_prose', EncounterTerrain, 'prose',
375 name = Column(Unicode(64), nullable=False, index=True,
376 info=dict(description="The name", format='plaintext', official=False)),
377 )
378
379 class EncounterSlot(TableBase):
380 u"""An abstract "slot" within a terrain, associated with both some set of conditions and a rarity.
381
382 Note that there are two encounters per slot, so the rarities will only add
383 up to 50.
384 """
385
386 __tablename__ = 'encounter_slots'
387 id = Column(Integer, primary_key=True, nullable=False,
388 info=dict(description="A unique ID for this slot"))
389 version_group_id = Column(Integer, ForeignKey('version_groups.id'), nullable=False, autoincrement=False,
390 info=dict(description="The ID of the version group this slot is in"))
391 encounter_terrain_id = Column(Integer, ForeignKey('encounter_terrain.id'), primary_key=False, nullable=False, autoincrement=False,
392 info=dict(description="The ID of the terrain"))
393 slot = Column(Integer, nullable=True,
394 info=dict(description="This slot's order for the location and terrain"))
395 rarity = Column(Integer, nullable=False,
396 info=dict(description="The chance of the encounter as a percentage"))
397
398 class EvolutionChain(TableBase):
399 u"""A family of Pokémon that are linked by evolution
400 """
401 __tablename__ = 'evolution_chains'
402 id = Column(Integer, primary_key=True, nullable=False,
403 info=dict(description="A numeric ID"))
404 growth_rate_id = Column(Integer, ForeignKey('growth_rates.id'), nullable=False,
405 info=dict(description="ID of the growth rate for this family"))
406 baby_trigger_item_id = Column(Integer, ForeignKey('items.id'), nullable=True,
407 info=dict(description="Item that a parent must hold while breeding to produce a baby"))
408
409 class EvolutionTrigger(TableBase):
410 u"""An evolution type, such as "level" or "trade".
411 """
412 __tablename__ = 'evolution_triggers'
413 __singlename__ = 'evolution_trigger'
414 id = Column(Integer, primary_key=True, nullable=False,
415 info=dict(description="A numeric ID"))
416 identifier = Column(Unicode(16), nullable=False,
417 info=dict(description="An identifier", format='identifier'))
418
419 create_translation_table('evolution_trigger_prose', EvolutionTrigger, 'prose',
420 name = Column(Unicode(16), nullable=False, index=True,
421 info=dict(description="The name", format='plaintext', official=False)),
422 )
423
424 class Experience(TableBase):
425 u"""EXP needed for a certain level with a certain growth rate
426 """
427 __tablename__ = 'experience'
428 growth_rate_id = Column(Integer, ForeignKey('growth_rates.id'), primary_key=True, nullable=False,
429 info=dict(description="ID of the growth rate"))
430 level = Column(Integer, primary_key=True, nullable=False, autoincrement=False,
431 info=dict(description="The level"))
432 experience = Column(Integer, nullable=False,
433 info=dict(description="The number of EXP points needed to get to that level"))
434
435 class Generation(TableBase):
436 u"""A Generation of the Pokémon franchise
437 """
438 __tablename__ = 'generations'
439 __singlename__ = 'generation'
440 id = Column(Integer, primary_key=True, nullable=False,
441 info=dict(description="A numeric ID"))
442 main_region_id = Column(Integer, ForeignKey('regions.id'),
443 info=dict(description="ID of the region this generation's main games take place in"))
444 canonical_pokedex_id = Column(Integer, ForeignKey('pokedexes.id'),
445 info=dict(description=u"ID of the Pokédex this generation's main games use by default"))
446 identifier = Column(Unicode(16), nullable=False,
447 info=dict(description=u'An identifier', format='identifier'))
448
449 create_translation_table('generation_names', Generation, 'names',
450 name = Column(Unicode(16), nullable=False, index=True,
451 info=dict(description="The name", format='plaintext', official=True)),
452 )
453
454 class GrowthRate(TableBase):
455 u"""Growth rate of a Pokémon, i.e. the EXP → level function.
456 """
457 __tablename__ = 'growth_rates'
458 __singlename__ = 'growth_rate'
459 id = Column(Integer, primary_key=True, nullable=False,
460 info=dict(description="A numeric ID"))
461 identifier = Column(Unicode(20), nullable=False,
462 info=dict(description="An identifier", format='identifier'))
463 formula = Column(Unicode(500), nullable=False,
464 info=dict(description="The formula", format='latex'))
465
466 create_translation_table('growth_rate_prose', GrowthRate, 'prose',
467 name = Column(Unicode(20), nullable=False, index=True,
468 info=dict(description="The name", format='plaintext', official=False)),
469 )
470
471 class Item(TableBase):
472 u"""An Item from the games, like "Poké Ball" or "Bicycle".
473 """
474 __tablename__ = 'items'
475 __singlename__ = 'item'
476 id = Column(Integer, primary_key=True, nullable=False,
477 info=dict(description="A numeric ID"))
478 identifier = Column(Unicode(20), nullable=False,
479 info=dict(description="An identifier", format='identifier'))
480 category_id = Column(Integer, ForeignKey('item_categories.id'), nullable=False,
481 info=dict(description="ID of a category this item belongs to"))
482 cost = Column(Integer, nullable=False,
483 info=dict(description=u"Cost of the item when bought. Items sell for half this price."))
484 fling_power = Column(Integer, nullable=True,
485 info=dict(description=u"Power of the move Fling when used with this item."))
486 fling_effect_id = Column(Integer, ForeignKey('item_fling_effects.id'), nullable=True,
487 info=dict(description=u"ID of the fling-effect of the move Fling when used with this item. Note that these are different from move effects."))
488
489 @property
490 def appears_underground(self):
491 u"""True if the item appears underground, as specified by the appropriate flag
492 """
493 return any(flag.identifier == u'underground' for flag in self.flags)
494
495 create_translation_table('item_names', Item, 'names',
496 name = Column(Unicode(20), nullable=False, index=True,
497 info=dict(description="The name", format='plaintext', official=True)),
498 )
499 create_translation_table('item_prose', Item, 'prose',
500 short_effect = Column(Unicode(256), nullable=False,
501 info=dict(description="A short summary of the effect", format='plaintext')),
502 effect = Column(markdown.MarkdownColumn(5120), nullable=False,
503 info=dict(description=u"Detailed description of the item's effect.", format='markdown')),
504 )
505
506 class ItemCategory(TableBase):
507 u"""An item category
508 """
509 # XXX: This is fanon, right?
510 __tablename__ = 'item_categories'
511 __singlename__ = 'item_category'
512 id = Column(Integer, primary_key=True, nullable=False,
513 info=dict(description="A numeric ID"))
514 pocket_id = Column(Integer, ForeignKey('item_pockets.id'), nullable=False,
515 info=dict(description="ID of the pocket these items go to"))
516 identifier = Column(Unicode(16), nullable=False,
517 info=dict(description="An identifier", format='identifier'))
518
519 create_translation_table('item_category_prose', ItemCategory, 'prose',
520 name = Column(Unicode(16), nullable=False, index=True,
521 info=dict(description="The name", format='plaintext', official=False)),
522 )
523
524 class ItemFlag(TableBase):
525 u"""An item attribute such as "consumable" or "holdable".
526 """
527 __tablename__ = 'item_flags'
528 __singlename__ = 'item_flag'
529 id = Column(Integer, primary_key=True, nullable=False,
530 info=dict(description="A numeric ID"))
531 identifier = Column(Unicode(24), nullable=False,
532 info=dict(description="Identifier of the flag", format='identifier'))
533
534 create_translation_table('item_flag_prose', ItemFlag, 'prose',
535 name = Column(Unicode(24), nullable=False, index=True,
536 info=dict(description="The name", format='plaintext', official=False)),
537 description = Column(Unicode(64), nullable=False,
538 info=dict(description="Short description of the flag", format='plaintext')),
539 )
540
541 class ItemFlagMap(TableBase):
542 u"""Maps an item flag to its item.
543 """
544 __tablename__ = 'item_flag_map'
545 item_id = Column(Integer, ForeignKey('items.id'), primary_key=True, autoincrement=False, nullable=False,
546 info=dict(description="The ID of the item"))
547 item_flag_id = Column(Integer, ForeignKey('item_flags.id'), primary_key=True, autoincrement=False, nullable=False,
548 info=dict(description="The ID of the item flag"))
549
550 class ItemFlavorText(TableBase):
551 u"""An in-game description of an item
552 """
553 __tablename__ = 'item_flavor_text'
554 __singlename__ = 'item_flavor_text'
555 item_id = Column(Integer, ForeignKey('items.id'), primary_key=True, autoincrement=False, nullable=False,
556 info=dict(description="The ID of the item"))
557 version_group_id = Column(Integer, ForeignKey('version_groups.id'), primary_key=True, autoincrement=False, nullable=False,
558 info=dict(description="ID of the version group that sports this text"))
559 language_id = Column(Integer, ForeignKey('languages.id'), primary_key=True, nullable=False,
560 info=dict(description="The language"))
561 flavor_text = Column(Unicode(255), nullable=False,
562 info=dict(description="The flavor text itself", official=True, format='gametext'))
563
564 class ItemFlingEffect(TableBase):
565 u"""An effect of the move Fling when used with a specific item
566 """
567 __tablename__ = 'item_fling_effects'
568 __singlename__ = 'item_fling_effect'
569 id = Column(Integer, primary_key=True, nullable=False,
570 info=dict(description="A numeric ID"))
571
572 create_translation_table('item_fling_effect_prose', ItemFlingEffect, 'prose',
573 effect = Column(Unicode(255), nullable=False,
574 info=dict(description="Description of the effect", format='plaintext')),
575 )
576
577 class ItemInternalID(TableBase):
578 u"""The internal ID number a game uses for an item
579 """
580 __tablename__ = 'item_internal_ids'
581 item_id = Column(Integer, ForeignKey('items.id'), primary_key=True, autoincrement=False, nullable=False,
582 info=dict(description="The database ID of the item"))
583 generation_id = Column(Integer, ForeignKey('generations.id'), primary_key=True, autoincrement=False, nullable=False,
584 info=dict(description="ID of the generation of games"))
585 internal_id = Column(Integer, nullable=False,
586 info=dict(description="Internal ID of the item in the generation"))
587
588 class ItemPocket(TableBase):
589 u"""A pocket that categorizes items
590 """
591 __tablename__ = 'item_pockets'
592 __singlename__ = 'item_pocket'
593 id = Column(Integer, primary_key=True, nullable=False,
594 info=dict(description="A numeric ID"))
595 identifier = Column(Unicode(16), nullable=False,
596 info=dict(description="An identifier of this pocket", format='identifier'))
597
598 create_translation_table('item_pocket_names', ItemPocket, 'names',
599 name = Column(Unicode(16), nullable=False, index=True,
600 info=dict(description="The name", format='plaintext', official=True)),
601 )
602
603 class Location(TableBase):
604 u"""A place in the Pokémon world
605 """
606 __tablename__ = 'locations'
607 __singlename__ = 'location'
608 id = Column(Integer, primary_key=True, nullable=False,
609 info=dict(description="A numeric ID"))
610 region_id = Column(Integer, ForeignKey('regions.id'),
611 info=dict(description="ID of the region this location is in"))
612 identifier = Column(Unicode(64), nullable=False,
613 info=dict(description="An identifier", format='identifier'))
614
615 create_translation_table('location_names', Location, 'names',
616 name = Column(Unicode(64), nullable=False, index=True,
617 info=dict(description="The name", format='plaintext', official=True)),
618 )
619
620 class LocationArea(TableBase):
621 u"""A sub-area of a location
622 """
623 __tablename__ = 'location_areas'
624 __singlename__ = 'location_area'
625 id = Column(Integer, primary_key=True, nullable=False,
626 info=dict(description="A numeric ID"))
627 location_id = Column(Integer, ForeignKey('locations.id'), nullable=False,
628 info=dict(description="ID of the location this area is part of"))
629 internal_id = Column(Integer, nullable=False,
630 info=dict(description="ID the games ude for this area"))
631 identifier = Column(Unicode(64), nullable=True,
632 info=dict(description="An identifier", format='identifier'))
633
634 create_translation_table('location_area_prose', LocationArea, 'prose',
635 name = Column(Unicode(64), nullable=False, index=True,
636 info=dict(description="The name", format='plaintext', official=False)),
637 )
638
639 class LocationAreaEncounterRate(TableBase):
640 # XXX: What's this exactly? Someone add the docstring & revise the descriptions
641 __tablename__ = 'location_area_encounter_rates'
642 location_area_id = Column(Integer, ForeignKey('location_areas.id'), primary_key=True, nullable=False, autoincrement=False,
643 info=dict(description="ID of the area"))
644 encounter_terrain_id = Column(Integer, ForeignKey('encounter_terrain.id'), primary_key=True, nullable=False, autoincrement=False,
645 info=dict(description="ID of the terrain"))
646 version_id = Column(Integer, ForeignKey('versions.id'), primary_key=True, autoincrement=False,
647 info=dict(description="ID of the version"))
648 rate = Column(Integer, nullable=True,
649 info=dict(description="The encounter rate")) # units?
650
651 class LocationInternalID(TableBase):
652 u"""IDs the games use internally for locations
653 """
654 __tablename__ = 'location_internal_ids'
655 location_id = Column(Integer, ForeignKey('locations.id'), nullable=False, primary_key=True,
656 info=dict(description="Database ID of the locaion"))
657 generation_id = Column(Integer, ForeignKey('generations.id'), nullable=False, primary_key=True,
658 info=dict(description="ID of the generation this entry to"))
659 internal_id = Column(Integer, nullable=False,
660 info=dict(description="Internal game ID of the location"))
661
662 class Machine(TableBase):
663 u"""A TM or HM; numbered item that can teach a move to a Pokémon
664 """
665 __tablename__ = 'machines'
666 machine_number = Column(Integer, primary_key=True, nullable=False, autoincrement=False,
667 info=dict(description="Number of the machine for TMs, or 100 + the munber for HMs"))
668 version_group_id = Column(Integer, ForeignKey('version_groups.id'), primary_key=True, nullable=False, autoincrement=False,
669 info=dict(description="Versions this entry applies to"))
670 item_id = Column(Integer, ForeignKey('items.id'), nullable=False,
671 info=dict(description="ID of the corresponding Item"))
672 move_id = Column(Integer, ForeignKey('moves.id'), nullable=False,
673 info=dict(description="ID of the taught move"))
674
675 @property
676 def is_hm(self):
677 u"""True if this machine is a HM, False if it's a TM
678 """
679 return self.machine_number >= 100
680
681 class MoveBattleStyle(TableBase):
682 u"""A battle style of a move""" # XXX: Explain better
683 __tablename__ = 'move_battle_styles'
684 __singlename__ = 'move_battle_style'
685 id = Column(Integer, primary_key=True, nullable=False,
686 info=dict(description="A numeric ID"))
687 identifier = Column(Unicode(8), nullable=False,
688 info=dict(description="An identifier", format='identifier'))
689
690 create_translation_table('move_battle_style_prose', MoveBattleStyle, 'prose',
691 name = Column(Unicode(8), nullable=False, index=True,
692 info=dict(description="The name", format='plaintext', official=False)),
693 )
694
695 class MoveEffectCategory(TableBase):
696 u"""Category of a move effect
697 """
698 __tablename__ = 'move_effect_categories'
699 __singlename__ = 'move_effect_category'
700 id = Column(Integer, primary_key=True, nullable=False,
701 info=dict(description="A numeric ID"))
702 identifier = Column(Unicode(64), nullable=False,
703 info=dict(description="An identifier", format='identifier'))
704 can_affect_user = Column(Boolean, nullable=False,
705 info=dict(description="Set if the user can be affected"))
706
707 create_translation_table('move_effect_category_prose', MoveEffectCategory, 'prose',
708 name = Column(Unicode(64), nullable=False, index=True,
709 info=dict(description="The name", format='plaintext', official=False)),
710 )
711
712 class MoveEffectCategoryMap(TableBase):
713 u"""Maps a move effect category to a move effect
714 """
715 __tablename__ = 'move_effect_category_map'
716 move_effect_id = Column(Integer, ForeignKey('move_effects.id'), primary_key=True, nullable=False,
717 info=dict(description="ID of the move effect"))
718 move_effect_category_id = Column(Integer, ForeignKey('move_effect_categories.id'), primary_key=True, nullable=False,
719 info=dict(description="ID of the category"))
720 affects_user = Column(Boolean, primary_key=True, nullable=False,
721 info=dict(description="Set if the user is affected"))
722
723 class MoveDamageClass(TableBase):
724 u"""Any of the damage classes moves can have, i.e. physical, special, or non-damaging.
725 """
726 __tablename__ = 'move_damage_classes'
727 __singlename__ = 'move_damage_class'
728 id = Column(Integer, primary_key=True, nullable=False,
729 info=dict(description="A numeric ID"))
730 identifier = Column(Unicode(16), nullable=False,
731 info=dict(description="An identifier", format='identifier'))
732
733 create_translation_table('move_damage_class_prose', MoveDamageClass, 'prose',
734 name = Column(Unicode(16), nullable=False, index=True,
735 info=dict(description="The name", format='plaintext', official=False)),
736 description = Column(Unicode(64), nullable=False,
737 info=dict(description="A description of the class", format='plaintext')),
738 )
739
740 class MoveEffect(TableBase):
741 u"""An effect of a move
742 """
743 __tablename__ = 'move_effects'
744 __singlename__ = 'move_effect'
745 id = Column(Integer, primary_key=True, nullable=False,
746 info=dict(description="A numeric ID"))
747
748 create_translation_table('move_effect_prose', MoveEffect, 'prose',
749 short_effect = Column(Unicode(256), nullable=False,
750 info=dict(description="A short summary of the effect", format='plaintext')),
751 effect = Column(Unicode(5120), nullable=False,
752 info=dict(description="A detailed description of the effect", format='plaintext')),
753 )
754
755 class MoveEffectChangelog(TableBase):
756 """History of changes to move effects across main game versions."""
757 __tablename__ = 'move_effect_changelog'
758 __singlename__ = 'move_effect_changelog'
759 id = Column(Integer, primary_key=True, nullable=False,
760 info=dict(description="A numeric ID"))
761 effect_id = Column(Integer, ForeignKey('move_effects.id'), nullable=False,
762 info=dict(description="The ID of the effect that changed"))
763 changed_in_version_group_id = Column(Integer, ForeignKey('version_groups.id'), nullable=False,
764 info=dict(description="The ID of the version group in which the effect changed"))
765
766 __table_args__ = (
767 UniqueConstraint(effect_id, changed_in_version_group_id),
768 {},
769 )
770
771 create_translation_table('move_effect_changelog_prose', MoveEffectChangelog, 'prose',
772 effect = Column(markdown.MarkdownColumn(512), nullable=False,
773 info=dict(description="A description of the old behavior", format='markdown')),
774 )
775
776 class MoveFlag(TableBase):
777 u"""Maps a move flag to a move
778 """
779 # XXX: Other flags have a ___Flag class for the actual flag and ___FlagMap for the map,
780 # these, somewhat confusingly, have MoveFlagType and MoveFlag
781 __tablename__ = 'move_flags'
782 move_id = Column(Integer, ForeignKey('moves.id'), primary_key=True, nullable=False, autoincrement=False,
783 info=dict(description="ID of the move"))
784 move_flag_type_id = Column(Integer, ForeignKey('move_flag_types.id'), primary_key=True, nullable=False, autoincrement=False,
785 info=dict(description="ID of the flag"))
786
787 class MoveFlagType(TableBase):
788 u"""A Move attribute such as "snatchable" or "contact".
789 """
790 __tablename__ = 'move_flag_types'
791 __singlename__ = 'move_flag_type'
792 id = Column(Integer, primary_key=True, nullable=False,
793 info=dict(description="A numeric ID"))
794 identifier = Column(Unicode(32), nullable=False,
795 info=dict(description="A short identifier for the flag", format='identifier'))
796
797 create_translation_table('move_flag_type_prose', MoveFlagType, 'prose',
798 name = Column(Unicode(32), nullable=False, index=True,
799 info=dict(description="The name", format='plaintext', official=False)),
800 description = Column(markdown.MarkdownColumn(128), nullable=False,
801 info=dict(description="A short description of the flag", format='markdown')),
802 )
803
804 class MoveFlavorText(TableBase):
805 u"""In-game description of a move
806 """
807 __tablename__ = 'move_flavor_text'
808 move_id = Column(Integer, ForeignKey('moves.id'), primary_key=True, nullable=False, autoincrement=False,
809 info=dict(description="ID of the move"))
810 version_group_id = Column(Integer, ForeignKey('version_groups.id'), primary_key=True, nullable=False, autoincrement=False,
811 info=dict(description="ID of the version group this text appears in"))
812 language_id = Column(Integer, ForeignKey('languages.id'), primary_key=True, nullable=False,
813 info=dict(description="The language"))
814 flavor_text = Column(Unicode(255), nullable=False,
815 info=dict(description="The flavor text", official=True, format='gametext'))
816
817 class MoveMeta(TableBase):
818 u"""Metadata for move effects, sorta-kinda ripped straight from the game"""
819 __tablename__ = 'move_meta'
820 move_id = Column(Integer, ForeignKey('moves.id'), primary_key=True, nullable=False, autoincrement=False,
821 info=dict(description="A numeric ID"))
822 meta_category_id = Column(Integer, ForeignKey('move_meta_categories.id'), nullable=False,
823 info=dict(description="ID of the move category"))
824 meta_ailment_id = Column(Integer, ForeignKey('move_meta_ailments.id'), nullable=False,
825 info=dict(description="ID of the caused ailment"))
826 min_hits = Column(Integer, nullable=True, index=True,
827 info=dict(description="Minimum number of hits per use"))
828 max_hits = Column(Integer, nullable=True, index=True,
829 info=dict(description="Maximum number of hits per use"))
830 min_turns = Column(Integer, nullable=True, index=True,
831 info=dict(description="Minimum number of turns the user is forced to use the move"))
832 max_turns = Column(Integer, nullable=True, index=True,
833 info=dict(description="Maximum number of turns the user is forced to use the move"))
834 recoil = Column(Integer, nullable=False, index=True,
835 info=dict(description="Recoil damage, in percent of damage done"))
836 healing = Column(Integer, nullable=False, index=True,
837 info=dict(description="Healing, in percent of user's max HP"))
838 crit_rate = Column(Integer, nullable=False, index=True,
839 info=dict(description="Critical hit rate bonus"))
840 ailment_chance = Column(Integer, nullable=False, index=True,
841 info=dict(description="Chance to cause an ailment, in percent"))
842 flinch_chance = Column(Integer, nullable=False, index=True,
843 info=dict(description="Chance to cause flinching, in percent"))
844 stat_chance = Column(Integer, nullable=False, index=True,
845 info=dict(description="Chance to cause a stat change, in percent"))
846
847 class MoveMetaAilment(TableBase):
848 u"""Common status ailments moves can inflict on a single Pokémon, including
849 major ailments like paralysis and minor ailments like trapping.
850 """
851 __tablename__ = 'move_meta_ailments'
852 __singlename__ = 'move_meta_ailment'
853 id = Column(Integer, primary_key=True, nullable=False,
854 info=dict(description="A numeric ID"))
855 identifier = Column(Unicode(24), nullable=False,
856 info=dict(description="An identifier", format='identifier'))
857
858 create_translation_table('move_meta_ailment_names', MoveMetaAilment, 'names',
859 name = Column(Unicode(24), nullable=False, index=True,
860 info=dict(description="The name", format='plaintext', official=True)),
861 )
862
863 class MoveMetaCategory(TableBase):
864 u"""Very general categories that loosely group move effects."""
865 __tablename__ = 'move_meta_categories'
866 __singlename__ = 'move_meta_category'
867 id = Column(Integer, primary_key=True, nullable=False,
868 info=dict(description="A numeric ID"))
869
870 create_translation_table('move_meta_category_prose', MoveMetaCategory, 'prose',
871 description = Column(Unicode(64), nullable=False,
872 info=dict(description="A description of the category")),
873 )
874
875 class MoveMetaStatChange(TableBase):
876 u"""Stat changes moves (may) make."""
877 __tablename__ = 'move_meta_stat_changes'
878 move_id = Column(Integer, ForeignKey('moves.id'), primary_key=True, nullable=False, autoincrement=False,
879 info=dict(description="ID of the move"))
880 stat_id = Column(Integer, ForeignKey('stats.id'), primary_key=True, nullable=False, autoincrement=False,
881 info=dict(description="ID of the stat"))
882 change = Column(Integer, nullable=False, index=True,
883 info=dict(description="Amount of increase/decrease, in stages"))
884
885 class MoveTarget(TableBase):
886 u"""Targetting or "range" of a move, e.g. "Affects all opponents" or "Affects user".
887 """
888 __tablename__ = 'move_targets'
889 __singlename__ = 'move_target'
890 id = Column(Integer, primary_key=True, nullable=False,
891 info=dict(description="A numeric ID"))
892 identifier = Column(Unicode(32), nullable=False,
893 info=dict(description="An identifier", format='identifier'))
894
895 create_translation_table('move_target_prose', MoveTarget, 'prose',
896 name = Column(Unicode(32), nullable=False, index=True,
897 info=dict(description="The name", format='plaintext', official=False)),
898 description = Column(Unicode(128), nullable=False,
899 info=dict(description="A description", format='plaintext')),
900 )
901
902 class Move(TableBase):
903 u"""A Move: technique or attack a Pokémon can learn to use
904 """
905 __tablename__ = 'moves'
906 __singlename__ = 'move'
907 id = Column(Integer, primary_key=True, nullable=False,
908 info=dict(description="A numeric ID"))
909 identifier = Column(Unicode(24), nullable=False,
910 info=dict(description="An identifier", format='identifier'))
911 generation_id = Column(Integer, ForeignKey('generations.id'), nullable=False,
912 info=dict(description="ID of the generation this move first appeared in"))
913 type_id = Column(Integer, ForeignKey('types.id'), nullable=False,
914 info=dict(description="ID of the move's elemental type"))
915 power = Column(SmallInteger, nullable=False,
916 info=dict(description="Base power of the move"))
917 pp = Column(SmallInteger, nullable=True,
918 info=dict(description="Base PP (Power Points) of the move, nullable if not applicable (e.g. Struggle and Shadow moves)."))
919 accuracy = Column(SmallInteger, nullable=True,
920 info=dict(description="Accuracy of the move; NULL means it never misses"))
921 priority = Column(SmallInteger, nullable=False,
922 info=dict(description="The move's priority bracket"))
923 target_id = Column(Integer, ForeignKey('move_targets.id'), nullable=False,
924 info=dict(description="ID of the target (range) of the move"))
925 damage_class_id = Column(Integer, ForeignKey('move_damage_classes.id'), nullable=False,
926 info=dict(description="ID of the damage class (physical/special) of the move"))
927 effect_id = Column(Integer, ForeignKey('move_effects.id'), nullable=False,
928 info=dict(description="ID of the move's effect"))
929 effect_chance = Column(Integer, nullable=True,
930 info=dict(description="The chance for a secondary effect. What this is a chance of is specified by the move's effect."))
931 contest_type_id = Column(Integer, ForeignKey('contest_types.id'), nullable=True,
932 info=dict(description="ID of the move's Contest type (e.g. cool or smart)"))
933 contest_effect_id = Column(Integer, ForeignKey('contest_effects.id'), nullable=True,
934 info=dict(description="ID of the move's Contest effect"))
935 super_contest_effect_id = Column(Integer, ForeignKey('super_contest_effects.id'), nullable=True,
936 info=dict(description="ID of the move's Super Contest effect"))
937
938 create_translation_table('move_names', Move, 'names',
939 name = Column(Unicode(24), nullable=False, index=True,
940 info=dict(description="The name", format='plaintext', official=True))
941 )
942
943
944 class MoveChangelog(TableBase):
945 """History of changes to moves across main game versions."""
946 __tablename__ = 'move_changelog'
947 __singlename__ = 'move_changelog'
948 move_id = Column(Integer, ForeignKey('moves.id'), primary_key=True, nullable=False,
949 info=dict(description="ID of the move that changed"))
950 changed_in_version_group_id = Column(Integer, ForeignKey('version_groups.id'), primary_key=True, nullable=False,
951 info=dict(description="ID of the version group in which the move changed"))
952 type_id = Column(Integer, ForeignKey('types.id'), nullable=True,
953 info=dict(description="Prior type of the move, or NULL if unchanged"))
954 power = Column(SmallInteger, nullable=True,
955 info=dict(description="Prior base power of the move, or NULL if unchanged"))
956 pp = Column(SmallInteger, nullable=True,
957 info=dict(description="Prior base PP of the move, or NULL if unchanged"))
958 accuracy = Column(SmallInteger, nullable=True,
959 info=dict(description="Prior accuracy of the move, or NULL if unchanged"))
960 effect_id = Column(Integer, ForeignKey('move_effects.id'), nullable=True,
961 info=dict(description="Prior ID of the effect, or NULL if unchanged"))
962 effect_chance = Column(Integer, nullable=True,
963 info=dict(description="Prior effect chance, or NULL if unchanged"))
964
965 class Nature(TableBase):
966 u"""A nature a Pokémon can have, such as Calm or Brave
967 """
968 __tablename__ = 'natures'
969 __singlename__ = 'nature'
970 id = Column(Integer, primary_key=True, nullable=False,
971 info=dict(description="A numeric ID"))
972 identifier = Column(Unicode(8), nullable=False,
973 info=dict(description="An identifier", format='identifier'))
974 decreased_stat_id = Column(Integer, ForeignKey('stats.id'), nullable=False,
975 info=dict(description="ID of the stat that this nature decreases by 10% (if decreased_stat_id is the same, the effects cancel out)"))
976 increased_stat_id = Column(Integer, ForeignKey('stats.id'), nullable=False,
977 info=dict(description="ID of the stat that this nature increases by 10% (if decreased_stat_id is the same, the effects cancel out)"))
978 hates_flavor_id = Column(Integer, ForeignKey('contest_types.id'), nullable=False,
979 info=dict(description=u"ID of the Berry flavor the Pokémon hates (if likes_flavor_id is the same, the effects cancel out)"))
980 likes_flavor_id = Column(Integer, ForeignKey('contest_types.id'), nullable=False,
981 info=dict(description=u"ID of the Berry flavor the Pokémon likes (if hates_flavor_id is the same, the effects cancel out)"))
982
983 @property
984 def is_neutral(self):
985 u"""Returns True iff this nature doesn't alter a Pokémon's stats,
986 bestow taste preferences, etc.
987 """
988 return self.increased_stat_id == self.decreased_stat_id
989
990 create_translation_table('nature_names', Nature, 'names',
991 name = Column(Unicode(8), nullable=False, index=True,
992 info=dict(description="The name", format='plaintext', official=True)),
993 )
994
995 class NatureBattleStylePreference(TableBase):
996 u"""Battle Palace move preference
997
998 Specifies how likely a Pokémon with a specific Nature is to use a move of
999 a particular battl style in Battle Palace or Battle Tent
1000 """
1001 __tablename__ = 'nature_battle_style_preferences'
1002 nature_id = Column(Integer, ForeignKey('natures.id'), primary_key=True, nullable=False,
1003 info=dict(description=u"ID of the Pokémon's nature"))
1004 move_battle_style_id = Column(Integer, ForeignKey('move_battle_styles.id'), primary_key=True, nullable=False,
1005 info=dict(description="ID of the battle style"))
1006 low_hp_preference = Column(Integer, nullable=False,
1007 info=dict(description=u"Chance of using the move, in percent, if HP is under ½"))
1008 high_hp_preference = Column(Integer, nullable=False,
1009 info=dict(description=u"Chance of using the move, in percent, if HP is over ½"))
1010
1011 class NaturePokeathlonStat(TableBase):
1012 u"""Specifies how a Nature affects a Pokéathlon stat
1013 """
1014 __tablename__ = 'nature_pokeathlon_stats'
1015 nature_id = Column(Integer, ForeignKey('natures.id'), primary_key=True, nullable=False,
1016 info=dict(description="ID of the nature"))
1017 pokeathlon_stat_id = Column(Integer, ForeignKey('pokeathlon_stats.id'), primary_key=True, nullable=False,
1018 info=dict(description="ID of the stat"))
1019 max_change = Column(Integer, nullable=False,
1020 info=dict(description="Maximum change"))
1021
1022 class PokeathlonStat(TableBase):
1023 u"""A Pokéathlon stat, such as "Stamina" or "Jump".
1024 """
1025 __tablename__ = 'pokeathlon_stats'
1026 __singlename__ = 'pokeathlon_stat'
1027 id = Column(Integer, primary_key=True, nullable=False,
1028 info=dict(description="A numeric ID"))
1029 identifier = Column(Unicode(8), nullable=False,
1030 info=dict(description="An identifier", format='identifier'))
1031
1032 create_translation_table('pokeathlon_stat_names', PokeathlonStat, 'names',
1033 name = Column(Unicode(8), nullable=False, index=True,
1034 info=dict(description="The name", format='plaintext', official=True)),
1035 )
1036
1037 class Pokedex(TableBase):
1038 u"""A collection of Pokémon species ordered in a particular way
1039 """
1040 __tablename__ = 'pokedexes'
1041 __singlename__ = 'pokedex'
1042 id = Column(Integer, primary_key=True, nullable=False,
1043 info=dict(description="A numeric ID"))
1044 region_id = Column(Integer, ForeignKey('regions.id'), nullable=True,
1045 info=dict(description=u"ID of the region this Pokédex is used in, or None if it's global"))
1046 identifier = Column(Unicode(16), nullable=False,
1047 info=dict(description=u"An identifier", format='identifier'))
1048
1049 create_translation_table('pokedex_prose', Pokedex, 'prose',
1050 name = Column(Unicode(16), nullable=False, index=True,
1051 info=dict(description="The name", format='plaintext', official=False)),
1052 description = Column(Unicode(512), nullable=False,
1053 info=dict(description=u"A longer description of the Pokédex", format='plaintext')),
1054 )
1055
1056 class Pokemon(TableBase):
1057 u"""A species of Pokémon. The core to this whole mess.
1058 """
1059 __tablename__ = 'pokemon'
1060 __singlename__ = 'pokemon'
1061 id = Column(Integer, primary_key=True, nullable=False,
1062 info=dict(description=u"A numeric ID"))
1063 identifier = Column(Unicode(20), nullable=False,
1064 info=dict(description=u"An identifier", format='identifier'))
1065 generation_id = Column(Integer, ForeignKey('generations.id'),
1066 info=dict(description=u"ID of the generation this species first appeared in"))
1067 evolution_chain_id = Column(Integer, ForeignKey('evolution_chains.id'),
1068 info=dict(description=u"ID of the species' evolution chain (a.k.a. family)"))
1069 height = Column(Integer, nullable=False,
1070 info=dict(description=u"The height of the Pokémon, in decimeters (tenths of a meter)"))
1071 weight = Column(Integer, nullable=False,
1072 info=dict(description=u"The weight of the Pokémon, in tenths of a kilogram (decigrams)"))
1073 color_id = Column(Integer, ForeignKey('pokemon_colors.id'), nullable=False,
1074 info=dict(description=u"ID of this Pokémon's Pokédex color, as used for a gimmick search function in the games."))
1075 pokemon_shape_id = Column(Integer, ForeignKey('pokemon_shapes.id'), nullable=True,
1076 info=dict(description=u"ID of this Pokémon's body shape, as used for a gimmick search function in the games."))
1077 habitat_id = Column(Integer, ForeignKey('pokemon_habitats.id'), nullable=True,
1078 info=dict(description=u"ID of this Pokémon's habitat, as used for a gimmick search function in the games."))
1079 gender_rate = Column(Integer, nullable=False,
1080 info=dict(description=u"The chance of this Pokémon being female, in eighths; or -1 for genderless"))
1081 capture_rate = Column(Integer, nullable=False,
1082 info=dict(description=u"The base capture rate; up to 255"))
1083 base_experience = Column(Integer, nullable=False,
1084 info=dict(description=u"The base EXP gained when defeating this Pokémon")) # XXX: Is this correct?
1085 base_happiness = Column(Integer, nullable=False,
1086 info=dict(description=u"The tameness when caught by a normal ball"))
1087 is_baby = Column(Boolean, nullable=False,
1088 info=dict(description=u"True iff the Pokémon is a baby, i.e. a lowest-stage Pokémon that cannot breed but whose evolved form can."))
1089 hatch_counter = Column(Integer, nullable=False,
1090 info=dict(description=u"Initial hatch counter: one must walk 255 × (hatch_counter + 1) steps before this Pokémon's egg hatches, unless utilizing bonuses like Flame Body's"))
1091 has_gender_differences = Column(Boolean, nullable=False,
1092 info=dict(description=u"Set iff the species exhibits enough sexual dimorphism to have separate sets of sprites in Gen IV and beyond."))
1093 order = Column(Integer, nullable=False, index=True,
1094 info=dict(description=u"Order for sorting. Almost national order, except families and forms are grouped together."))
1095
1096 ### Stuff to handle alternate Pokémon forms
1097
1098 @property
1099 def form(self):
1100 u"""Returns the Pokémon's form, using its default form as fallback."""
1101
1102 return self.unique_form or self.default_form
1103
1104 @property
1105 def is_base_form(self):
1106 u"""Returns True iff the Pokémon is the base form for its species,
1107 e.g. Land Shaymin.
1108 """
1109
1110 return self.unique_form is None or self.unique_form.is_default
1111
1112 @property
1113 def form_name(self):
1114 u"""Returns the Pokémon's form name if it represents a particular form
1115 and that form has a name, or None otherwise.
1116 """
1117
1118 # If self.unique_form is None, the short-circuit "and" will go ahead
1119 # and return that. Otherwise, it'll return the form's name, which may
1120 # also be None.
1121 return self.unique_form and self.unique_form.name
1122
1123 @property
1124 def full_name(self):
1125 u"""Returns the Pokémon's name, including its form if applicable."""
1126
1127 if self.form_name:
1128 return u'{0} {1}'.format(self.form_name, self.name)
1129 else:
1130 return self.name
1131
1132 @property
1133 def normal_form(self):
1134 u"""Returns the normal form for this Pokémon; i.e., this will return
1135 regular Deoxys when called on any Deoxys form.
1136 """
1137
1138 if self.unique_form:
1139 return self.unique_form.form_base_pokemon
1140 return self
1141
1142 ### Not forms!
1143
1144 def stat(self, stat_name):
1145 u"""Returns a PokemonStat record for the given stat name (or Stat row
1146 object). Uses the normal has-many machinery, so all the stats are
1147 effectively cached.
1148 """
1149 if isinstance(stat_name, Stat):
1150 stat_name = stat_name.name
1151
1152 for pokemon_stat in self.stats:
1153 if pokemon_stat.stat.name == stat_name:
1154 return pokemon_stat
1155
1156 raise KeyError(u'No stat named %s' % stat_name)
1157
1158 @property
1159 def better_damage_class(self):
1160 u"""Returns the MoveDamageClass that this Pokémon is best suited for,
1161 based on its attack stats.
1162
1163 If the attack stats are about equal (within 5), returns None. The
1164 value None, not the damage class called 'None'.
1165 """
1166 phys = self.stat(u'Attack')
1167 spec = self.stat(u'Special Attack')
1168
1169 diff = phys.base_stat - spec.base_stat
1170
1171 if diff > 5:
1172 return phys.stat.damage_class
1173 elif diff < -5:
1174 return spec.stat.damage_class
1175 else:
1176 return None
1177
1178 create_translation_table('pokemon_names', Pokemon, 'names',
1179 name = Column(Unicode(20), nullable=False, index=True,
1180 info=dict(description="The name", format='plaintext', official=True)),
1181 species = Column(Unicode(16), nullable=False,
1182 info=dict(description=u'The short flavor text, such as "Seed" or "Lizard"; usually affixed with the word "Pokémon"',
1183 official=True, format='plaintext')),
1184 )
1185
1186 class PokemonAbility(TableBase):
1187 u"""Maps an ability to a Pokémon that can have it
1188 """
1189 __tablename__ = 'pokemon_abilities'
1190 pokemon_id = Column(Integer, ForeignKey('pokemon.id'), primary_key=True, nullable=False, autoincrement=False,
1191 info=dict(description=u"ID of the Pokémon"))
1192 ability_id = Column(Integer, ForeignKey('abilities.id'), nullable=False,
1193 info=dict(description=u"ID of the ability"))
1194 # XXX having both a method and a slot is kind of gross. "slot" is a
1195 # misnomer, anyway: duplicate abilities don't appear in slot 2.
1196 # Probably should replace that with "order".
1197 is_dream = Column(Boolean, nullable=False, index=True,
1198 info=dict(description=u"Whether this is a Dream World ability"))
1199 slot = Column(Integer, primary_key=True, nullable=False, autoincrement=False,
1200 info=dict(description=u"The ability slot, i.e. 1 or 2 for gen. IV"))
1201
1202 class PokemonColor(TableBase):
1203 u"""The "Pokédex color" of a Pokémon species. Usually based on the Pokémon's color.
1204 """
1205 __tablename__ = 'pokemon_colors'
1206 __singlename__ = 'pokemon_color'
1207 id = Column(Integer, primary_key=True, nullable=False, autoincrement=False,
1208 info=dict(description=u"ID of the Pokémon"))
1209 identifier = Column(Unicode(6), nullable=False,
1210 info=dict(description=u"An identifier", format='identifier'))
1211
1212 create_translation_table('pokemon_color_names', PokemonColor, 'names',
1213 name = Column(Unicode(6), nullable=False, index=True,
1214 info=dict(description="The name", format='plaintext', official=True)),
1215 )
1216
1217 class PokemonDexNumber(TableBase):
1218 u"""The number of a Pokémon in a particular Pokédex (e.g. Jigglypuff is #138 in Hoenn's 'dex)
1219 """
1220 __tablename__ = 'pokemon_dex_numbers'
1221 pokemon_id = Column(Integer, ForeignKey('pokemon.id'), primary_key=True, nullable=False, autoincrement=False,
1222 info=dict(description=u"ID of the Pokémon"))
1223 pokedex_id = Column(Integer, ForeignKey('pokedexes.id'), primary_key=True, nullable=False, autoincrement=False,
1224 info=dict(description=u"ID of the Pokédex"))
1225 pokedex_number = Column(Integer, nullable=False,
1226 info=dict(description=u"Number of the Pokémon in that the Pokédex"))
1227
1228 class PokemonEggGroup(TableBase):
1229 u"""Maps an Egg group to a Pokémon; each Pokémon belongs to one or two egg groups
1230 """
1231 __tablename__ = 'pokemon_egg_groups'
1232 pokemon_id = Column(Integer, ForeignKey('pokemon.id'), primary_key=True, nullable=False, autoincrement=False,
1233 info=dict(description=u"ID of the Pokémon"))
1234 egg_group_id = Column(Integer, ForeignKey('egg_groups.id'), primary_key=True, nullable=False, autoincrement=False,
1235 info=dict(description=u"ID of the egg group"))
1236
1237 class PokemonEvolution(TableBase):
1238 u"""A required action ("trigger") and the conditions under which the trigger
1239 must occur to cause a Pokémon to evolve.
1240
1241 Any condition may be null if it does not apply for a particular Pokémon.
1242 """
1243 __tablename__ = 'pokemon_evolution'
1244 from_pokemon_id = Column(Integer, ForeignKey('pokemon.id'), nullable=False,
1245 info=dict(description=u"The ID of the pre-evolution Pokémon."))
1246 to_pokemon_id = Column(Integer, ForeignKey('pokemon.id'), primary_key=True, nullable=False, autoincrement=False,
1247 info=dict(description=u"The ID of the post-evolution Pokémon."))
1248 evolution_trigger_id = Column(Integer, ForeignKey('evolution_triggers.id'), nullable=False,
1249 info=dict(description=u"The ID of the evolution trigger."))
1250 trigger_item_id = Column(Integer, ForeignKey('items.id'), nullable=True,
1251 info=dict(description=u"The ID of the item that must be used on the Pokémon."))
1252 minimum_level = Column(Integer, nullable=True,
1253 info=dict(description=u"The minimum level for the Pokémon."))
1254 gender = Column(Enum('male', 'female', name='pokemon_evolution_gender'), nullable=True,
1255 info=dict(description=u"The Pokémon's required gender, or None if gender doesn't matter"))
1256 location_id = Column(Integer, ForeignKey('locations.id'), nullable=True,
1257 info=dict(description=u"The ID of the location the evolution must be triggered at."))
1258 held_item_id = Column(Integer, ForeignKey('items.id'), nullable=True,
1259 info=dict(description=u"The ID of the item the Pokémon must hold."))
1260 time_of_day = Column(Enum('day', 'night', name='pokemon_evolution_time_of_day'), nullable=True,
1261 info=dict(description=u"The required time of day."))
1262 known_move_id = Column(Integer, ForeignKey('moves.id'), nullable=True,
1263 info=dict(description=u"The ID of the move the Pokémon must know."))
1264 minimum_happiness = Column(Integer, nullable=True,
1265 info=dict(description=u"The minimum happiness value the Pokémon must have."))
1266 minimum_beauty = Column(Integer, nullable=True,
1267 info=dict(description=u"The minimum Beauty value the Pokémon must have."))
1268 relative_physical_stats = Column(Integer, nullable=True,
1269 info=dict(description=u"The required relation between the Pokémon's Attack and Defense stats, as sgn(atk-def)."))
1270 party_pokemon_id = Column(Integer, ForeignKey('pokemon.id'), nullable=True,
1271 info=dict(description=u"The ID of the Pokémon that must be present in the party."))
1272 trade_pokemon_id = Column(Integer, ForeignKey('pokemon.id'), nullable=True,
1273 info=dict(description=u"The ID of the Pokémon for which this Pokémon must be traded."))
1274
1275 class PokemonFlavorText(TableBase):
1276 u"""In-game Pokédex descrption of a Pokémon.
1277 """
1278 __tablename__ = 'pokemon_flavor_text'
1279 pokemon_id = Column(Integer, ForeignKey('pokemon.id'), primary_key=True, nullable=False, autoincrement=False,
1280 info=dict(description=u"ID of the Pokémon"))
1281 version_id = Column(Integer, ForeignKey('versions.id'), primary_key=True, nullable=False, autoincrement=False,
1282 info=dict(description=u"ID of the version that has this flavor text"))
1283 language_id = Column(Integer, ForeignKey('languages.id'), primary_key=True, nullable=False,
1284 info=dict(description="The language"))
1285 flavor_text = Column(Unicode(255), nullable=False,
1286 info=dict(description=u"ID of the version that has this flavor text", official=True, format='gametext'))
1287
1288 class PokemonForm(TableBase):
1289 u"""An individual form of a Pokémon.
1290
1291 Pokémon that do not have separate forms are still given a single row to
1292 represent their single form.
1293 """
1294 __tablename__ = 'pokemon_forms'
1295 __singlename__ = 'pokemon_form'
1296 id = Column(Integer, primary_key=True, nullable=False,
1297 info=dict(description=u'A unique ID for this form.'))
1298 identifier = Column(Unicode(16), nullable=True,
1299 info=dict(description=u"An identifier", format='identifier'))
1300 form_base_pokemon_id = Column(Integer, ForeignKey('pokemon.id'), nullable=False, autoincrement=False,
1301 info=dict(description=u'The ID of the base Pokémon for this form.'))
1302 unique_pokemon_id = Column(Integer, ForeignKey('pokemon.id'), autoincrement=False,
1303 info=dict(description=u'The ID of a Pokémon that represents specifically this form, for Pokémon with functionally-different forms like Wormadam.'))
1304 introduced_in_version_group_id = Column(Integer, ForeignKey('version_groups.id'), autoincrement=False,
1305 info=dict(description=u'The ID of the version group in which this form first appeared.'))
1306 is_default = Column(Boolean, nullable=False,
1307 info=dict(description=u'Set for exactly one form used as the default for each species.'))
1308 order = Column(Integer, nullable=False, autoincrement=False,
1309 info=dict(description=u'The order in which forms should be sorted. Multiple forms may have equal order, in which case they should fall back on sorting by name.'))
1310
1311 @property
1312 def pokemon(self):
1313 u"""Returns the Pokémon for this form, using the form base as fallback.
1314 """
1315
1316 return self.unique_pokemon or self.form_base_pokemon
1317
1318 @property
1319 def full_name(self):
1320 u"""Returns the full name of this form, e.g. "Plant Cloak"."""
1321
1322 if not self.name:
1323 return None
1324 elif self.form_group and self.form_group.term:
1325 return u'{0} {1}'.format(self.name, self.form_group.term)
1326 else:
1327 return self.name
1328
1329 @property
1330 def pokemon_name(self):
1331 u"""Returns the name of this Pokémon with this form, e.g. "Plant
1332 Burmy".
1333 """
1334
1335 if self.name:
1336 return u'{0} {1}'.format(self.name, self.form_base_pokemon.name)
1337 else:
1338 return self.form_base_pokemon.name
1339
1340 create_translation_table('pokemon_form_names', PokemonForm, 'names',
1341 name = Column(Unicode(16), nullable=False, index=True,
1342 info=dict(description="The name", format='plaintext', official=True)),
1343 )
1344
1345 class PokemonFormGroup(TableBase):
1346 u"""Information about a Pokémon's forms as a group."""
1347 __tablename__ = 'pokemon_form_groups'
1348 __singlename__ = 'pokemon_form_group'
1349 pokemon_id = Column(Integer, ForeignKey('pokemon.id'), primary_key=True, nullable=False, autoincrement=False,
1350 info=dict(description=u"ID of the base form Pokémon"))
1351 is_battle_only = Column(Boolean, nullable=False,
1352 info=dict(description=u"Set iff the forms only change in battle"))
1353 # FIXME remooove
1354 PokemonFormGroup.id = PokemonFormGroup.pokemon_id
1355
1356 create_translation_table('pokemon_form_group_prose', PokemonFormGroup, 'prose',
1357 term = Column(Unicode(16), nullable=True,
1358 info=dict(description=u"The term for this Pokémon's forms, e.g. \"Cloak\" for Burmy or \"Forme\" for Deoxys.", official=True, format='plaintext')),
1359 description = Column(markdown.MarkdownColumn(1024), nullable=False,
1360 info=dict(description=u"Description of how the forms work", format='markdown')),
1361 )
1362
1363 class PokemonFormPokeathlonStat(TableBase):
1364 u"""A Pokémon form's performance in one Pokéathlon stat."""
1365 __tablename__ = 'pokemon_form_pokeathlon_stats'
1366 pokemon_form_id = Column(Integer, ForeignKey('pokemon_forms.id'), primary_key=True, nullable=False, autoincrement=False,
1367 info=dict(description=u'The ID of the Pokémon form.'))
1368 pokeathlon_stat_id = Column(Integer, ForeignKey('pokeathlon_stats.id'), primary_key=True, nullable=False, autoincrement=False,
1369 info=dict(description=u'The ID of the Pokéathlon stat.'))
1370 minimum_stat = Column(Integer, nullable=False, autoincrement=False,
1371 info=dict(description=u'The minimum value for this stat for this Pokémon form.'))
1372 base_stat = Column(Integer, nullable=False, autoincrement=False,
1373 info=dict(description=u'The default value for this stat for this Pokémon form.'))
1374 maximum_stat = Column(Integer, nullable=False, autoincrement=False,
1375 info=dict(description=u'The maximum value for this stat for this Pokémon form.'))
1376
1377 class PokemonHabitat(TableBase):
1378 u"""The habitat of a Pokémon, as given in the FireRed/LeafGreen version Pokédex
1379 """
1380 __tablename__ = 'pokemon_habitats'
1381 __singlename__ = 'pokemon_habitat'
1382 id = Column(Integer, primary_key=True, nullable=False, autoincrement=False,
1383 info=dict(description=u"A numeric ID"))
1384 identifier = Column(Unicode(16), nullable=False,
1385 info=dict(description=u"An identifier", format='identifier'))
1386
1387 create_translation_table('pokemon_habitat_names', PokemonHabitat, 'names',
1388 name = Column(Unicode(16), nullable=False, index=True,
1389 info=dict(description="The name", format='plaintext', official=True)),
1390 )
1391
1392 class PokemonInternalID(TableBase):
1393 u"""The number of a Pokémon a game uses internally
1394 """
1395 __tablename__ = 'pokemon_internal_ids'
1396 pokemon_id = Column(Integer, ForeignKey('pokemon.id'), primary_key=True, autoincrement=False, nullable=False,
1397 info=dict(description=u"Database ID of the Pokémon"))
1398 generation_id = Column(Integer, ForeignKey('generations.id'), primary_key=True, autoincrement=False, nullable=False,
1399 info=dict(description=u"Database ID of the generation"))
1400 internal_id = Column(Integer, nullable=False,
1401 info=dict(description=u"Internal ID the generation's games use for the Pokémon"))
1402
1403 class PokemonItem(TableBase):
1404 u"""Record of an item a Pokémon can hold in the wild
1405 """
1406 __tablename__ = 'pokemon_items'
1407 pokemon_id = Column(Integer, ForeignKey('pokemon.id'), primary_key=True, nullable=False, autoincrement=False,
1408 info=dict(description=u"ID of the Pokémon"))
1409 version_id = Column(Integer, ForeignKey('versions.id'), primary_key=True, nullable=False, autoincrement=False,
1410 info=dict(description=u"ID of the version this applies to"))
1411 item_id = Column(Integer, ForeignKey('items.id'), primary_key=True, nullable=False, autoincrement=False,
1412 info=dict(description=u"ID of the item"))
1413 rarity = Column(Integer, nullable=False,
1414 info=dict(description=u"Chance of the Pokémon holding the item, in percent"))
1415
1416 class PokemonMove(TableBase):
1417 u"""Record of a move a Pokémon can learn
1418 """
1419 __tablename__ = 'pokemon_moves'
1420 pokemon_id = Column(Integer, ForeignKey('pokemon.id'), nullable=False, index=True,
1421 info=dict(description=u"ID of the Pokémon"))
1422 version_group_id = Column(Integer, ForeignKey('version_groups.id'), nullable=False, index=True,
1423 info=dict(description=u"ID of the version group this applies to"))
1424 move_id = Column(Integer, ForeignKey('moves.id'), nullable=False, index=True,
1425 info=dict(description=u"ID of the move"))
1426 pokemon_move_method_id = Column(Integer, ForeignKey('pokemon_move_methods.id'), nullable=False, index=True,
1427 info=dict(description=u"ID of the method this move is learned by"))
1428 level = Column(Integer, nullable=True, index=True,
1429 info=dict(description=u"Level the move is learned at, if applicable"))
1430 order = Column(Integer, nullable=True,
1431 info=dict(description=u"A sort key to produce the correct ordering when all else is equal")) # XXX: This needs a better description
1432
1433 __table_args__ = (
1434 PrimaryKeyConstraint('pokemon_id', 'version_group_id', 'move_id', 'pokemon_move_method_id', 'level'),
1435 {},
1436 )
1437
1438 class PokemonMoveMethod(TableBase):
1439 u"""A method a move can be learned by, such as "Level up" or "Tutor".
1440 """
1441 __tablename__ = 'pokemon_move_methods'
1442 __singlename__ = 'pokemon_move_method'
1443 id = Column(Integer, primary_key=True, nullable=False, autoincrement=False,
1444 info=dict(description=u"A numeric ID"))
1445 identifier = Column(Unicode(64), nullable=False,
1446 info=dict(description=u"An identifier", format='identifier'))
1447
1448 create_translation_table('pokemon_move_method_prose', PokemonMoveMethod, 'prose',
1449 name = Column(Unicode(64), nullable=False, index=True,
1450 info=dict(description="The name", format='plaintext', official=False)),
1451 description = Column(Unicode(255), nullable=False,
1452 info=dict(description=u"A detailed description of how the method works", format='plaintext')),
1453 )
1454
1455
1456 class PokemonShape(TableBase):
1457 u"""The shape of a Pokémon's body, as used in generation IV Pokédexes.
1458 """
1459 __tablename__ = 'pokemon_shapes'
1460 __singlename__ = 'pokemon_shape'
1461 id = Column(Integer, primary_key=True, nullable=False,
1462 info=dict(description=u"A numeric ID"))
1463 identifier = Column(Unicode(24), nullable=False,
1464 info=dict(description=u"An identifier", format='identifier'))
1465
1466 create_translation_table('pokemon_shape_prose', PokemonShape, 'prose',
1467 name = Column(Unicode(24), nullable=False, index=True,
1468 info=dict(description="The name", format='plaintext', official=False)),
1469 awesome_name = Column(Unicode(16), nullable=False,
1470 info=dict(description=u"A splendiferous name of the body shape", format='plaintext')),
1471 )
1472
1473 class PokemonStat(TableBase):
1474 u"""A stat value of a Pokémon
1475 """
1476 __tablename__ = 'pokemon_stats'
1477 pokemon_id = Column(Integer, ForeignKey('pokemon.id'), primary_key=True, nullable=False, autoincrement=False,
1478 info=dict(description=u"ID of the Pokémon"))
1479 stat_id = Column(Integer, ForeignKey('stats.id'), primary_key=True, nullable=False, autoincrement=False,
1480 info=dict(description=u"ID of the stat"))
1481 base_stat = Column(Integer, nullable=False,
1482 info=dict(description=u"The base stat"))
1483 effort = Column(Integer, nullable=False,
1484 info=dict(description=u"The effort increase in this stat gained when this Pokémon is defeated"))
1485
1486 class PokemonType(TableBase):
1487 u"""Maps a type to a Pokémon. Each Pokémon has 1 or 2 types.
1488 """
1489 __tablename__ = 'pokemon_types'
1490 pokemon_id = Column(Integer, ForeignKey('pokemon.id'), primary_key=True, nullable=False, autoincrement=False,
1491 info=dict(description=u"ID of the Pokémon"))
1492 type_id = Column(Integer, ForeignKey('types.id'), nullable=False,
1493 info=dict(description=u"ID of the type"))
1494 slot = Column(Integer, primary_key=True, nullable=False, autoincrement=False,
1495 info=dict(description=u"The type's slot, 1 or 2, used to sort types if there are two of them"))
1496
1497 class Region(TableBase):
1498 u"""Major areas of the world: Kanto, Johto, etc.
1499 """
1500 __tablename__ = 'regions'
1501 __singlename__ = 'region'
1502 id = Column(Integer, primary_key=True, nullable=False,
1503 info=dict(description=u"A numeric ID"))
1504 identifier = Column(Unicode(16), nullable=False,
1505 info=dict(description=u"An identifier", format='identifier'))
1506
1507 create_translation_table('region_names', Region, 'names',
1508 name = Column(Unicode(16), nullable=False, index=True,
1509 info=dict(description="The name", format='plaintext', official=True)),
1510 )
1511
1512 class Stat(TableBase):
1513 u"""A Stat, such as Attack or Speed
1514 """
1515 __tablename__ = 'stats'
1516 __singlename__ = 'stat'
1517 id = Column(Integer, primary_key=True, nullable=False,
1518 info=dict(description=u"A numeric ID"))
1519 damage_class_id = Column(Integer, ForeignKey('move_damage_classes.id'), nullable=True,
1520 info=dict(description=u"For offensive and defensive stats, the damage this stat relates to; otherwise None (the NULL value)"))
1521 identifier = Column(Unicode(16), nullable=False,
1522 info=dict(description=u"An identifier", format='identifier'))
1523
1524 create_translation_table('stat_names', Stat, 'names',
1525 name = Column(Unicode(16), nullable=False, index=True,
1526 info=dict(description="The name", format='plaintext', official=True)),
1527 )
1528
1529 class StatHint(TableBase):
1530 u"""Flavor text for genes that appears in a Pokémon's summary. Sometimes
1531 called "characteristics".
1532 """
1533 __tablename__ = 'stat_hints'
1534 __singlename__ = 'stat_hint'
1535 id = Column(Integer, primary_key=True, nullable=False,
1536 info=dict(description=u"A numeric ID"))
1537 stat_id = Column(Integer, ForeignKey('stats.id'), nullable=False,
1538 info=dict(description=u"ID of the highest stat"))
1539 gene_mod_5 = Column(Integer, nullable=False, index=True,
1540 info=dict(description=u"Value of the highest stat modulo 5"))
1541
1542 create_translation_table('stat_hint_names', StatHint, 'names',
1543 message = Column(Unicode(24), nullable=False, index=True,
1544 info=dict(description=u"The text displayed", official=True, format='plaintext')),
1545 )
1546
1547 class SuperContestCombo(TableBase):
1548 u"""Combo of two moves in a Super Contest.
1549 """
1550 __tablename__ = 'super_contest_combos'
1551 first_move_id = Column(Integer, ForeignKey('moves.id'), primary_key=True, nullable=False, autoincrement=False,
1552 info=dict(description=u"The ID of the first move in the combo."))
1553 second_move_id = Column(Integer, ForeignKey('moves.id'), primary_key=True, nullable=False, autoincrement=False,
1554 info=dict(description=u"The ID of the second and last move."))
1555
1556 class SuperContestEffect(TableBase):
1557 u"""An effect a move can have when used in the Super Contest
1558 """
1559 __tablename__ = 'super_contest_effects'
1560 __singlename__ = 'super_contest_effect'
1561 id = Column(Integer, primary_key=True, nullable=False,
1562 info=dict(description=u"This effect's unique ID."))
1563 appeal = Column(SmallInteger, nullable=False,
1564 info=dict(description=u"The number of hearts the user gains."))
1565
1566 create_translation_table('super_contest_effect_prose', SuperContestEffect, 'prose',
1567 flavor_text = Column(Unicode(64), nullable=False,
1568 info=dict(description=u"A description of the effect.", format='plaintext')),
1569 )
1570
1571
1572 class TypeEfficacy(TableBase):
1573 u"""The damage multiplier used when a move of a particular type damages a
1574 Pokémon of a particular other type.
1575 """
1576 __tablename__ = 'type_efficacy'
1577 damage_type_id = Column(Integer, ForeignKey('types.id'), primary_key=True, nullable=False, autoincrement=False,
1578 info=dict(description=u"The ID of the damaging type."))
1579 target_type_id = Column(Integer, ForeignKey('types.id'), primary_key=True, nullable=False, autoincrement=False,
1580 info=dict(description=u"The ID of the defending Pokémon's type."))
1581 damage_factor = Column(Integer, nullable=False,
1582 info=dict(description=u"The multiplier, as a percentage of damage inflicted."))
1583
1584 class Type(TableBase):
1585 u"""Any of the elemental types Pokémon and moves can have."""
1586 __tablename__ = 'types'
1587 __singlename__ = 'type'
1588 id = Column(Integer, primary_key=True, nullable=False,
1589 info=dict(description=u"A unique ID for this type."))
1590 identifier = Column(Unicode(12), nullable=False,
1591 info=dict(description=u"An identifier", format='identifier'))
1592 generation_id = Column(Integer, ForeignKey('generations.id'), nullable=False,
1593 info=dict(description=u"The ID of the generation this type first appeared in."))
1594 damage_class_id = Column(Integer, ForeignKey('move_damage_classes.id'), nullable=True,
1595 info=dict(description=u"The ID of the damage class this type's moves had before Generation IV, null if not applicable (e.g. ???)."))
1596
1597 create_translation_table('type_names', Type, 'names',
1598 name = Column(Unicode(12), nullable=False, index=True,
1599 info=dict(description="The name", format='plaintext', official=True)),
1600 )
1601
1602 class VersionGroup(TableBase):
1603 u"""A group of versions, containing either two paired versions (such as Red
1604 and Blue) or a single game (such as Yellow.)
1605 """
1606 __tablename__ = 'version_groups'
1607 id = Column(Integer, primary_key=True, nullable=False,
1608 info=dict(description=u"This version group's unique ID."))
1609 generation_id = Column(Integer, ForeignKey('generations.id'), nullable=False,
1610 info=dict(description=u"The ID of the generation the games in this group belong to."))
1611 pokedex_id = Column(Integer, ForeignKey('pokedexes.id'), nullable=False,
1612 info=dict(description=u"The ID of the regional Pokédex used in this version group."))
1613
1614 class VersionGroupRegion(TableBase):
1615 u"""Maps a version group to a region that appears in it."""
1616 __tablename__ = 'version_group_regions'
1617 version_group_id = Column(Integer, ForeignKey('version_groups.id'), primary_key=True, nullable=False,
1618 info=dict(description=u"The ID of the version group."))
1619 region_id = Column(Integer, ForeignKey('regions.id'), primary_key=True, nullable=False,
1620 info=dict(description=u"The ID of the region."))
1621
1622 class Version(TableBase):
1623 u"""An individual main-series Pokémon game."""
1624 __tablename__ = 'versions'
1625 __singlename__ = 'version'
1626 id = Column(Integer, primary_key=True, nullable=False,
1627 info=dict(description=u"A unique ID for this version."))
1628 version_group_id = Column(Integer, ForeignKey('version_groups.id'), nullable=False,
1629 info=dict(description=u"The ID of the version group this game belongs to."))
1630 identifier = Column(Unicode(32), nullable=False,
1631 info=dict(description=u'And identifier', format='identifier'))
1632
1633 create_translation_table('version_names', Version, 'names',
1634 name = Column(Unicode(32), nullable=False, index=True,
1635 info=dict(description="The name", format='plaintext', official=True)),
1636 )
1637
1638
1639 ### Relations down here, to avoid ordering problems
1640 Ability.changelog = relation(AbilityChangelog,
1641 order_by=AbilityChangelog.changed_in_version_group_id.desc(),
1642 backref='ability',
1643 )
1644 Ability.flavor_text = relation(AbilityFlavorText, order_by=AbilityFlavorText.version_group_id, backref='ability')
1645 Ability.generation = relation(Generation, backref='abilities')
1646 Ability.all_pokemon = relation(Pokemon,
1647 secondary=PokemonAbility.__table__,
1648 order_by=Pokemon.order,
1649 #back_populates='all_abilities',
1650 )
1651 Ability.pokemon = relation(Pokemon,
1652 secondary=PokemonAbility.__table__,
1653 primaryjoin=and_(
1654 PokemonAbility.ability_id == Ability.id,
1655 PokemonAbility.is_dream == False
1656 ),
1657 order_by=Pokemon.order,
1658 #back_populates='abilities',
1659 )
1660 Ability.dream_pokemon = relation(Pokemon,
1661 secondary=PokemonAbility.__table__,
1662 primaryjoin=and_(
1663 PokemonAbility.ability_id == Ability.id,
1664 PokemonAbility.is_dream == True
1665 ),
1666 order_by=Pokemon.order,
1667 #back_populates='dream_ability',
1668 )
1669
1670 AbilityChangelog.changed_in = relation(VersionGroup, backref='ability_changelog')
1671
1672 AbilityFlavorText.version_group = relation(VersionGroup)
1673 AbilityFlavorText.language = relation(Language)
1674
1675 Berry.berry_firmness = relation(BerryFirmness, backref='berries')
1676 Berry.firmness = association_proxy('berry_firmness', 'name')
1677 Berry.flavors = relation(BerryFlavor, order_by=BerryFlavor.contest_type_id, backref='berry')
1678 Berry.natural_gift_type = relation(Type)
1679
1680 BerryFlavor.contest_type = relation(ContestType)
1681
1682 ContestCombo.first = relation(Move, primaryjoin=ContestCombo.first_move_id==Move.id,
1683 backref='contest_combo_first')
1684 ContestCombo.second = relation(Move, primaryjoin=ContestCombo.second_move_id==Move.id,
1685 backref='contest_combo_second')
1686
1687 Encounter.location_area = relation(LocationArea, backref='encounters')
1688 Encounter.pokemon = relation(Pokemon, backref='encounters')
1689 Encounter.version = relation(Version, backref='encounters')
1690 Encounter.slot = relation(EncounterSlot, backref='encounters')
1691
1692 EncounterConditionValue.condition = relation(EncounterCondition, backref='values')
1693
1694 Encounter.condition_value_map = relation(EncounterConditionValueMap, backref='encounter')
1695 Encounter.condition_values = association_proxy('condition_value_map', 'condition_value')
1696 EncounterConditionValueMap.condition_value = relation(EncounterConditionValue,
1697 backref='encounter_map')
1698
1699 EncounterSlot.terrain = relation(EncounterTerrain, backref='slots')
1700 EncounterSlot.version_group = relation(VersionGroup)
1701
1702 EvolutionChain.growth_rate = relation(GrowthRate, backref='evolution_chains')
1703 EvolutionChain.baby_trigger_item = relation(Item, backref='evolution_chains')
1704 EvolutionChain.pokemon = relation(Pokemon, order_by=Pokemon.order)#, back_populates='evolution_chain')
1705
1706 Experience.growth_rate = relation(GrowthRate, backref='experience_table')
1707
1708 Generation.canonical_pokedex = relation(Pokedex, backref='canonical_for_generation')
1709 Generation.versions = relation(Version, secondary=VersionGroup.__table__)
1710 Generation.main_region = relation(Region)
1711
1712 GrowthRate.max_experience_obj = relation(Experience, primaryjoin=and_(Experience.growth_rate_id == GrowthRate.id, Experience.level == 100), uselist=False)
1713 GrowthRate.max_experience = association_proxy('max_experience_obj', 'experience')
1714
1715 Item.berry = relation(Berry, uselist=False, backref='item')
1716 Item.flags = relation(ItemFlag, secondary=ItemFlagMap.__table__)
1717 Item.flavor_text = relation(ItemFlavorText, order_by=ItemFlavorText.version_group_id.asc(), backref='item')
1718 Item.fling_effect = relation(ItemFlingEffect, backref='items')
1719 Item.machines = relation(Machine, order_by=Machine.version_group_id.asc())
1720 Item.category = relation(ItemCategory)
1721 Item.pocket = association_proxy('category', 'pocket')
1722
1723 ItemCategory.items = relation(Item, order_by=Item.identifier)
1724 ItemCategory.pocket = relation(ItemPocket)
1725
1726 ItemFlavorText.version_group = relation(VersionGroup)
1727 ItemFlavorText.language = relation(Language)
1728
1729 ItemInternalID.item = relation(Item, backref='internal_ids')
1730 ItemInternalID.generation = relation(Generation)
1731
1732 ItemPocket.categories = relation(ItemCategory, order_by=ItemCategory.identifier)
1733
1734 Location.region = relation(Region, backref='locations')
1735
1736 LocationArea.location = relation(Location, backref='areas')
1737
1738 LocationInternalID.location = relation(Location, backref='internal_ids')
1739 LocationInternalID.generation = relation(Generation)
1740
1741 Machine.item = relation(Item)
1742 Machine.version_group = relation(VersionGroup)
1743
1744 Move.changelog = relation(MoveChangelog,
1745 order_by=MoveChangelog.changed_in_version_group_id.desc(),
1746 backref='move',
1747 )
1748 Move.contest_effect = relation(ContestEffect, backref='moves')
1749 Move.contest_combo_next = association_proxy('contest_combo_first', 'second')
1750 Move.contest_combo_prev = association_proxy('contest_combo_second', 'first')
1751 Move.contest_type = relation(ContestType, backref='moves')
1752 Move.damage_class = relation(MoveDamageClass, backref='moves')
1753 Move.flags = association_proxy('move_flags', 'flag')
1754 Move.flavor_text = relation(MoveFlavorText, order_by=MoveFlavorText.version_group_id, backref='move')
1755 Move.generation = relation(Generation, backref='moves')
1756 Move.machines = relation(Machine, backref='move')
1757 Move.meta = relation(MoveMeta, uselist=False, backref='move')
1758 Move.meta_stat_changes = relation(MoveMetaStatChange)
1759 Move.move_effect = relation(MoveEffect, backref='moves')
1760 Move.move_flags = relation(MoveFlag, backref='move')
1761 Move.super_contest_effect = relation(SuperContestEffect, backref='moves')
1762 Move.super_contest_combo_next = association_proxy('super_contest_combo_first', 'second')
1763 Move.super_contest_combo_prev = association_proxy('super_contest_combo_second', 'first')
1764 Move.target = relation(MoveTarget, backref='moves')
1765 Move.type = relation(Type)#, back_populates='moves')
1766
1767 MoveChangelog.changed_in = relation(VersionGroup, backref='move_changelog')
1768 MoveChangelog.move_effect = relation(MoveEffect, backref='move_changelog')
1769 MoveChangelog.type = relation(Type, backref='move_changelog')
1770
1771 MoveEffect.category_map = relation(MoveEffectCategoryMap)
1772 MoveEffect.categories = association_proxy('category_map', 'category')
1773 MoveEffect.changelog = relation(MoveEffectChangelog,
1774 order_by=MoveEffectChangelog.changed_in_version_group_id.desc(),
1775 backref='move_effect',
1776 )
1777 MoveEffectCategoryMap.category = relation(MoveEffectCategory)
1778
1779 MoveEffectChangelog.changed_in = relation(VersionGroup, backref='move_effect_changelog')
1780
1781 MoveFlag.flag = relation(MoveFlagType)
1782
1783 MoveFlavorText.version_group = relation(VersionGroup)
1784 MoveFlavorText.language = relation(Language)
1785
1786 MoveMeta.category = relation(MoveMetaCategory, backref='move_meta')
1787 MoveMeta.ailment = relation(MoveMetaAilment, backref='move_meta')
1788
1789 MoveMetaStatChange.stat = relation(Stat, backref='move_meta_stat_changes')
1790
1791 Nature.decreased_stat = relation(Stat, primaryjoin=Nature.decreased_stat_id==Stat.id,
1792 backref='decreasing_natures')
1793 Nature.increased_stat = relation(Stat, primaryjoin=Nature.increased_stat_id==Stat.id,
1794 backref='increasing_natures')
1795 Nature.hates_flavor = relation(ContestType, primaryjoin=Nature.hates_flavor_id==ContestType.id,
1796 backref='hating_natures')
1797 Nature.likes_flavor = relation(ContestType, primaryjoin=Nature.likes_flavor_id==ContestType.id,
1798 backref='liking_natures')
1799 Nature.battle_style_preferences = relation(NatureBattleStylePreference,
1800 order_by=NatureBattleStylePreference.move_battle_style_id,
1801 backref='nature')
1802 Nature.pokeathlon_effects = relation(NaturePokeathlonStat, order_by=NaturePokeathlonStat.pokeathlon_stat_id)
1803
1804 NatureBattleStylePreference.battle_style = relation(MoveBattleStyle, backref='nature_preferences')
1805
1806 NaturePokeathlonStat.pokeathlon_stat = relation(PokeathlonStat, backref='nature_effects')
1807
1808 Pokedex.region = relation(Region, backref='pokedexes')
1809 Pokedex.version_groups = relation(VersionGroup, order_by=VersionGroup.id)#, back_populates='pokedex')
1810
1811 Pokemon.all_abilities = relation(Ability,
1812 secondary=PokemonAbility.__table__,
1813 order_by=PokemonAbility.slot,
1814 )
1815 Pokemon.abilities = relation(Ability,
1816 secondary=PokemonAbility.__table__,
1817 primaryjoin=and_(
1818 Pokemon.id == PokemonAbility.pokemon_id,
1819 PokemonAbility.is_dream == False,
1820 ),
1821 order_by=PokemonAbility.slot,
1822 )
1823 Pokemon.dream_ability = relation(Ability,
1824 secondary=PokemonAbility.__table__,
1825 primaryjoin=and_(
1826 Pokemon.id == PokemonAbility.pokemon_id,
1827 PokemonAbility.is_dream == True,
1828 ),
1829 uselist=False,
1830 )
1831 Pokemon.pokemon_color = relation(PokemonColor, backref='pokemon')
1832 Pokemon.color = association_proxy('pokemon_color', 'name')
1833 Pokemon.dex_numbers = relation(PokemonDexNumber, order_by=PokemonDexNumber.pokedex_id.asc(), backref='pokemon')
1834 Pokemon.egg_groups = relation(EggGroup, secondary=PokemonEggGroup.__table__,
1835 order_by=PokemonEggGroup.egg_group_id,
1836 backref=backref('pokemon', order_by=Pokemon.order))
1837 Pokemon.evolution_chain = relation(EvolutionChain)#, back_populates='pokemon')
1838 Pokemon.child_pokemon = relation(Pokemon,
1839 primaryjoin=Pokemon.id==PokemonEvolution.from_pokemon_id,
1840 secondary=PokemonEvolution.__table__,
1841 secondaryjoin=PokemonEvolution.to_pokemon_id==Pokemon.id,
1842 backref=backref('parent_pokemon', uselist=False),
1843 )
1844 Pokemon.flavor_text = relation(PokemonFlavorText, order_by=PokemonFlavorText.version_id.asc(), backref='pokemon')
1845 Pokemon.forms = relation(PokemonForm, primaryjoin=Pokemon.id==PokemonForm.form_base_pokemon_id,
1846 order_by=(PokemonForm.order.asc(), PokemonForm.identifier.asc()))
1847 Pokemon.default_form = relation(PokemonForm,
1848 primaryjoin=and_(Pokemon.id==PokemonForm.form_base_pokemon_id, PokemonForm.is_default==True),
1849 uselist=False,
1850 )
1851 Pokemon.pokemon_habitat = relation(PokemonHabitat, backref='pokemon')
1852 Pokemon.habitat = association_proxy('pokemon_habitat', 'name')
1853 Pokemon.items = relation(PokemonItem, backref='pokemon')
1854 Pokemon.generation = relation(Generation, backref='pokemon')
1855 Pokemon.shape = relation(PokemonShape, backref='pokemon')
1856 Pokemon.stats = relation(PokemonStat, backref='pokemon', order_by=PokemonStat.stat_id.asc())
1857 Pokemon.types = relation(Type, secondary=PokemonType.__table__,
1858 order_by=PokemonType.slot.asc(),
1859 )#back_populates='pokemon')
1860
1861 PokemonDexNumber.pokedex = relation(Pokedex)
1862
1863 PokemonEvolution.from_pokemon = relation(Pokemon,
1864 primaryjoin=PokemonEvolution.from_pokemon_id==Pokemon.id,
1865 backref='child_evolutions',
1866 )
1867 PokemonEvolution.to_pokemon = relation(Pokemon,
1868 primaryjoin=PokemonEvolution.to_pokemon_id==Pokemon.id,
1869 backref=backref('parent_evolution', uselist=False),
1870 )
1871 PokemonEvolution.child_evolutions = relation(PokemonEvolution,
1872 primaryjoin=PokemonEvolution.from_pokemon_id==PokemonEvolution.to_pokemon_id,
1873 foreign_keys=[PokemonEvolution.to_pokemon_id],
1874 backref=backref('parent_evolution',
1875 remote_side=[PokemonEvolution.from_pokemon_id],
1876 uselist=False,
1877 ),
1878 )
1879 PokemonEvolution.trigger = relation(EvolutionTrigger, backref='evolutions')
1880 PokemonEvolution.trigger_item = relation(Item,
1881 primaryjoin=PokemonEvolution.trigger_item_id==Item.id,
1882 backref='triggered_evolutions',
1883 )
1884 PokemonEvolution.held_item = relation(Item,
1885 primaryjoin=PokemonEvolution.held_item_id==Item.id,
1886 backref='required_for_evolutions',
1887 )
1888 PokemonEvolution.location = relation(Location, backref='triggered_evolutions')
1889 PokemonEvolution.known_move = relation(Move, backref='triggered_evolutions')
1890 PokemonEvolution.party_pokemon = relation(Pokemon,
1891 primaryjoin=PokemonEvolution.party_pokemon_id==Pokemon.id,
1892 backref='triggered_evolutions',
1893 )
1894 PokemonEvolution.trade_pokemon = relation(Pokemon,
1895 primaryjoin=PokemonEvolution.trade_pokemon_id==Pokemon.id,
1896 )
1897
1898 PokemonFlavorText.version = relation(Version)
1899 PokemonFlavorText.language = relation(Language)
1900
1901 PokemonForm.form_base_pokemon = relation(Pokemon, primaryjoin=PokemonForm.form_base_pokemon_id==Pokemon.id)
1902 PokemonForm.unique_pokemon = relation(Pokemon, backref=backref('unique_form', uselist=False),
1903 primaryjoin=PokemonForm.unique_pokemon_id==Pokemon.id)
1904 PokemonForm.version_group = relation(VersionGroup)
1905 PokemonForm.form_group = association_proxy('form_base_pokemon', 'form_group')
1906 PokemonForm.pokeathlon_stats = relation(PokemonFormPokeathlonStat,
1907 order_by=PokemonFormPokeathlonStat.pokeathlon_stat_id,
1908 backref='pokemon_form')
1909
1910 PokemonFormGroup.pokemon = relation(Pokemon, backref=backref('form_group',
1911 uselist=False))
1912
1913 PokemonFormPokeathlonStat.pokeathlon_stat = relation(PokeathlonStat)
1914
1915 PokemonItem.item = relation(Item, backref='pokemon')
1916 PokemonItem.version = relation(Version)
1917
1918 PokemonMove.pokemon = relation(Pokemon, backref='pokemon_moves')
1919 PokemonMove.version_group = relation(VersionGroup)
1920 PokemonMove.machine = relation(Machine, backref='pokemon_moves',
1921 primaryjoin=and_(Machine.version_group_id==PokemonMove.version_group_id,
1922 Machine.move_id==PokemonMove.move_id),
1923 foreign_keys=[Machine.version_group_id, Machine.move_id],
1924 uselist=False)
1925 PokemonMove.move = relation(Move, backref='pokemon_moves')
1926 PokemonMove.method = relation(PokemonMoveMethod)
1927
1928 PokemonStat.stat = relation(Stat)
1929
1930 # This is technically a has-many; Generation.main_region_id -> Region.id
1931 Region.generation = relation(Generation, uselist=False)
1932 Region.version_group_regions = relation(VersionGroupRegion, backref='region',
1933 order_by='VersionGroupRegion.version_group_id')
1934 Region.version_groups = association_proxy('version_group_regions', 'version_group')
1935
1936 Stat.damage_class = relation(MoveDamageClass, backref='stats')
1937
1938 StatHint.stat = relation(Stat, backref='hints')
1939
1940 SuperContestCombo.first = relation(Move, primaryjoin=SuperContestCombo.first_move_id==Move.id,
1941 backref='super_contest_combo_first')
1942 SuperContestCombo.second = relation(Move, primaryjoin=SuperContestCombo.second_move_id==Move.id,
1943 backref='super_contest_combo_second')
1944
1945 Type.damage_efficacies = relation(TypeEfficacy,
1946 primaryjoin=Type.id
1947 ==TypeEfficacy.damage_type_id,
1948 backref='damage_type')
1949 Type.target_efficacies = relation(TypeEfficacy,
1950 primaryjoin=Type.id
1951 ==TypeEfficacy.target_type_id,
1952 backref='target_type')
1953
1954 Type.generation = relation(Generation, backref='types')
1955 Type.damage_class = relation(MoveDamageClass, backref='types')
1956 Type.pokemon = relation(Pokemon, secondary=PokemonType.__table__,
1957 order_by=Pokemon.order,
1958 )#back_populates='types')
1959 Type.moves = relation(Move, back_populates='type', order_by=Move.id)
1960
1961 Version.version_group = relation(VersionGroup)#, back_populates='versions')
1962 Version.generation = association_proxy('version_group', 'generation')
1963
1964 VersionGroup.versions = relation(Version, order_by=Version.id, back_populates='version_group')
1965 VersionGroup.generation = relation(Generation, backref='version_groups')
1966 VersionGroup.version_group_regions = relation(VersionGroupRegion, backref='version_group')
1967 VersionGroup.regions = association_proxy('version_group_regions', 'region')
1968 VersionGroup.pokedex = relation(Pokedex, back_populates='version_groups')
1969
1970 Move.effect = markdown.MoveEffectProperty('effect')
1971 Move.effect_map = markdown.MoveEffectProperty('effect_map')
1972 Move.short_effect = markdown.MoveEffectProperty('short_effect')
1973 Move.short_effect_map = markdown.MoveEffectProperty('short_effect_map')
1974
1975 MoveChangelog.effect = markdown.MoveEffectProperty('effect')
1976 MoveChangelog.effect_map = markdown.MoveEffectProperty('effect_map')
1977 MoveChangelog.short_effect = markdown.MoveEffectProperty('short_effect')
1978 MoveChangelog.short_effect_map = markdown.MoveEffectProperty('short_effect_map')