mirror of
https://github.com/pret/pokefirered.git
synced 2026-05-20 11:58:04 -05:00
7.3 KiB
7.3 KiB
pokefirered — Codebase Navigation Index
Fork of pret/pokefirered (Pokémon FireRed/LeafGreen decompilation). This fork adds a Trainer Type Level system — see design docs below.
Build
make # Build with agbcc (default, matching decomp)
make modern # Build with arm-none-eabi-gcc (MODERN=1)
make generated # Regenerate auto-generated headers from JSON
Toolchain: agbcc (C89 compiler) or arm-none-eabi-gcc with -std=gnu99.
Build output: pokefirered.gba / pokefirered_modern.gba.
Fork-Specific Changes
Design docs:
- TRAINER_TYPE_LEVEL_SPEC.md — Full system spec
- TRAINER_OBEDIENCE_SYSTEM.md — Obedience rework details
- docs/new_player_guide.md — Player-facing gameplay guide
- docs/pokemon_locations.md — Where to find every Pokémon
Changed files (vs upstream pokefirered):
include/global.h— AddedtrainerTypeExp[18],trainerTypeLevels[18]to SaveBlock2include/strings.h/src/strings.c— Added trainer type name strings, UI textinclude/constants/flags.h— Added trade flags (FLAG_DID_DUSKULL_TRADE, etc.)include/constants/trade.h— Added trade constants for new NPCsinclude/constants/battle_string_ids.h— Added trainer level feedback string IDssrc/new_game.c— CallsInitializeTrainerTypeLevels()on new gamesrc/start_menu.c— Added "TYPE LEVELS" entry to start menusrc/battle_script_commands.c— Awards type XP on moves/catches/defeats; accuracy and crit bonuses; in-battle trainer level feedback messagessrc/battle_message.c— Trainer level feedback battle stringssrc/battle_setup.c— Non-ghost Pokémon Tower encounters work without Silph Scopesrc/battle_util.c— Obedience now uses trainer type levels instead of badges alonesrc/trainer_card.c— Displays top 3 trainer type levels on Trainer Cardsrc/data/wild_encounters.json— Added Swinub, Sableye, rearranged Dark-type encounterssrc/data/ingame_trades.h— Added Duskull, Murkrow, and Bagon trade NPCs
New files:
include/trainer_xp_system.h/src/trainer_xp_system.c— XP tracking, level thresholds, catch rate bonusinclude/trainer_type_levels.h/src/trainer_type_levels.c— Type levels UI screensrc/trainer_type_npc_levels.c— Precomputed NPC trainer type level data
Directory Structure
src/ — C source (284 files)
The game logic. Key subsystems by file prefix:
| Prefix / File | Purpose |
|---|---|
battle_main.c |
Battle flow: turn order, switching, fleeing |
battle_script_commands.c |
Implements battle script opcodes (damage calc, status, items, catching) |
battle_util.c |
Battle helpers: type effectiveness, stat stages, obedience checks |
battle_ai_*.c |
AI decision-making for opponent trainers |
battle_anim_*.c |
Move animation rendering (~25 files, one per type + effects) |
battle_controller_*.c |
Input/output dispatch per battler type (player, opponent, link, safari) |
pokemon.c |
Core Pokémon data: GetMonData, SetMonData, stat calc, evolution |
pokemon_storage_system.c |
PC box system |
wild_encounter.c |
Wild encounter tables and generation |
event_data.c |
Save flags/vars: FlagGet, FlagSet, VarGet, VarSet |
field_control_avatar.c |
Overworld player movement and tile interactions |
event_object_movement.c |
NPC movement patterns |
script.c / scrcmd.c |
Event script interpreter and commands |
new_game.c |
New-game initialization (save block zeroing, defaults) |
start_menu.c |
Start menu: Pokédex, Pokémon, Bag, Save, Option, Type Levels |
strings.c |
All in-game text string definitions |
item.c / item_use.c |
Item data and use-item effects |
overworld.c |
Main overworld state machine and map loading |
trainer_type_levels.c |
[FORK] Type levels UI screen |
trainer_xp_system.c |
[FORK] XP/level tracking, catch rate bonus |
include/ — Headers (216 files)
Key headers:
global.h— Fundamental types,SaveBlock1/SaveBlock2structs (game save state)pokemon.h—struct Pokemon,struct BoxPokemon, species info,GetMonData/SetMonDatabattle.h—struct BattleStruct, battle state, move dataconstants/pokemon.h— Type IDs (TYPE_NORMAL=0 ..TYPE_DARK=17),NUMBER_OF_MON_TYPESconstants/species.h— Species IDs,NUM_SPECIESconstants/items.h— Item IDsconstants/flags.h— Story/event flags includingFLAG_BADGE01_GET..FLAG_BADGE08_GETevent_data.h—FlagGet(),FlagSet(),VarGet(),VarSet()strings.h—externdeclarations for all text stringstrainer_xp_system.h— [FORK]AwardTrainerTypeExp,GetCatchRateBonus, etc.
data/ — Game data assets
maps/— Per-map JSON: connections, events, headers, groupslayouts/— Map tile layouts (binary.binfiles, plus generated.inc)scripts/— Per-map event scripts (.incassembly)text/— Per-map dialogue text (.incassembly)tilesets/— Tileset graphics and palettes organized by primary/secondary- Top-level
.sfiles — Battle scripts, AI scripts, animation scripts, event scripts
graphics/ — Sprite/tile/UI art
Organized by feature: pokemon/, trainers/, battle_anims/, items/, interface/, etc.
All PNGs are converted to GBA formats (.4bpp, .gbapal, .bin) by the build system via gbagfx.
sound/ — Music and sound effects
songs/midi/— MIDI source filesdirect_sound_samples/— Instrument samples and cry datacry_tables.inc— Maps species to cry sound data
tools/ — Build tools
| Tool | Purpose |
|---|---|
agbcc/ |
Legacy GBA C compiler (C89, used for matching decomp builds) |
gbagfx |
PNG ↔ GBA tile format converter |
mapjson |
JSON ↔ assembly map data converter |
jsonproc |
JSON template processor (generates items.h, wild_encounters.h, etc.) |
preproc |
C preprocessor wrapper for assembly files |
scaninc |
Scans source files for #include/.include to generate Make dependencies |
ramscrgen |
Generates linker script fragments from symbol files |
mid2agb |
MIDI → GBA music format converter |
Other top-level files
Makefile— Main build orchestrationld_script.ld/ld_script_modern.ld— Linker scriptscharmap.txt— Character encoding table (game uses custom character set, not ASCII)sym_bss.txt,sym_common.txt,sym_ewram.txt— Symbol address maps for RAM sections
Conventions
- agbcc compatibility: All
.cfiles must be valid C89 — no mid-block declarations, nofor(int i=...), no//comments in some contexts. Declare all variables at the top of each block. - String encoding: Game text uses
_("...")macro which maps throughcharmap.txt, not standard C strings. - Generated headers:
src/data/items.h,src/data/wild_encounters.h,src/data/region_map/region_map_entries.h,include/constants/map_groups.h,include/constants/layouts.hare generated from JSON viajsonproc/mapjson. Don't edit them directly — edit the.jsonsource and runmake generated. - SaveBlock2 layout: Struct must remain exactly
0xF24bytes. New fields replace filler bytes at fixed offsets.