Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
battle.c
Go to the documentation of this file.
1#include "common.h"
2#include "ld_addrs.h"
3#include "battle.h"
4#include "battle_tables.h"
5#include "hud_element.h"
6#include "sprite.h"
7#include "game_modes.h"
8
20
21// standard battle area table entry
22#define BTL_AREA(id, jpName) { \
23 .dmaStart = battle_area_##id##_ROM_START, \
24 .dmaEnd = battle_area_##id##_ROM_END, \
25 .dmaDest = battle_area_##id##_VRAM, \
26 .battles = &b_area_##id##_Formations, \
27 .stages = &b_area_##id##_Stages, \
28 .name = jpName, \
29} \
30
31// extended battle area with a dmaTable, used by kzn2 for lava piranha animations
32#define BTL_AREA_DMA(id, jpName) { \
33 .dmaStart = battle_area_##id##_ROM_START, \
34 .dmaEnd = battle_area_##id##_ROM_END, \
35 .dmaDest = battle_area_##id##_VRAM, \
36 .battles = &b_area_##id##_Formations, \
37 .stages = &b_area_##id##_Stages, \
38 .dmaTable = b_area_##id##_dmaTable, \
39 .name = jpName, \
40} \
41
42// auxiliary battle area for omo which contains only additional enemy data
43#define BTL_AREA_AUX(id, jpName) { \
44 .dmaStart = battle_area_##id##_ROM_START, \
45 .dmaEnd = battle_area_##id##_ROM_END, \
46 .dmaDest = battle_area_##id##_VRAM, \
47 .name = jpName, \
48} \
49
51 [BTL_AREA_KMR_1] BTL_AREA(kmr_part_1, "エリア KMR その1"),
52 [BTL_AREA_KMR_2] BTL_AREA(kmr_part_2, "エリア KMR その2"),
53 [BTL_AREA_KMR_3] BTL_AREA(kmr_part_3, "エリア KMR その3"),
54 [BTL_AREA_MAC] BTL_AREA(mac, "エリア MAC"),
55 [BTL_AREA_HOS] BTL_AREA(hos, "エリア HOS"),
56 [BTL_AREA_NOK] BTL_AREA(nok, "エリア NOK"),
57 [BTL_AREA_TRD_1] BTL_AREA(trd_part_1, "エリア TRD その1"),
58 [BTL_AREA_TRD_2] BTL_AREA(trd_part_2, "エリア TRD その2"),
59 [BTL_AREA_TRD_3] BTL_AREA(trd_part_3, "エリア TRD その3"),
60 [BTL_AREA_IWA] BTL_AREA(iwa, "エリア IWA"),
61 [BTL_AREA_SBK] BTL_AREA(sbk, "エリア SBK"),
62 [BTL_AREA_ISK_1] BTL_AREA(isk_part_1, "エリア ISK その1"),
63 [BTL_AREA_ISK_2] BTL_AREA(isk_part_2, "エリア ISK その2"),
64 [BTL_AREA_MIM] BTL_AREA(mim, "エリア MIM"),
65 [BTL_AREA_ARN] BTL_AREA(arn, "エリア ARN"),
66 [BTL_AREA_DGB] BTL_AREA(dgb, "エリア DGB"),
67 [BTL_AREA_OMO] BTL_AREA(omo, "エリア OMO"),
68 [BTL_AREA_OMO2] BTL_AREA(omo2, "エリア OMO2"),
69 [BTL_AREA_OMO3] BTL_AREA(omo3, "エリア OMO3"),
70 [BTL_AREA_KGR] BTL_AREA(kgr, "エリア KGR"),
71 [BTL_AREA_JAN] BTL_AREA(jan, "エリア JAN"),
72 [BTL_AREA_JAN2] BTL_AREA(jan2, "エリア JAN2"),
73 [BTL_AREA_KZN] BTL_AREA(kzn, "エリア KZN"),
74 [BTL_AREA_KZN2] BTL_AREA_DMA(kzn2, "エリア KZN2"),
75 [BTL_AREA_FLO] BTL_AREA(flo, "エリア FLO"),
76 [BTL_AREA_FLO2] BTL_AREA(flo2, "エリア FLO2"),
77 [BTL_AREA_TIK] BTL_AREA(tik, "エリア TIK"),
78 [BTL_AREA_TIK2] BTL_AREA(tik2, "エリア TIK2"),
79 [BTL_AREA_TIK3] BTL_AREA(tik3, "エリア TIK3"),
80 [BTL_AREA_SAM] BTL_AREA(sam, "エリア SAM"),
81 [BTL_AREA_SAM2] BTL_AREA(sam2, "エリア SAM2"),
82 [BTL_AREA_PRA] BTL_AREA(pra, "エリア PRA"),
83 [BTL_AREA_PRA2] BTL_AREA(pra2, "エリア PRA2"),
84 [BTL_AREA_PRA3] BTL_AREA(pra3, "エリア PRA3"),
85 [BTL_AREA_KPA] BTL_AREA(kpa, "エリア KPA"),
86 [BTL_AREA_KPA2] BTL_AREA(kpa2, "エリア KPA2"),
87 [BTL_AREA_KPA3] BTL_AREA(kpa3, "エリア KPA3"),
88 [BTL_AREA_KPA4] BTL_AREA(kpa4, "エリア KPA4"),
89 [BTL_AREA_KKJ] BTL_AREA(kkj, "エリア KKJ"),
90 [BTL_AREA_DIG] BTL_AREA(dig, "エリア DIG"),
91 [BTL_AREA_OMO2_1] BTL_AREA_AUX(omo2_1, "エリア OMO2_1"),
92 [BTL_AREA_OMO2_2] BTL_AREA_AUX(omo2_2, "エリア OMO2_2"),
93 [BTL_AREA_OMO2_3] BTL_AREA_AUX(omo2_3, "エリア OMO2_3"),
94 [BTL_AREA_OMO2_4] BTL_AREA_AUX(omo2_4, "エリア OMO2_4"),
95 [BTL_AREA_OMO2_5] BTL_AREA_AUX(omo2_5, "エリア OMO2_5"),
96 [BTL_AREA_OMO2_6] BTL_AREA_AUX(omo2_6, "エリア OMO2_6"),
97};
98
110
113 s32 battleIdx = UNPACK_BTL_INDEX(gCurrentBattleID);
114
115 dma_copy(battleArea->dmaStart, battleArea->dmaEnd, battleArea->dmaDest);
116
117 gCurrentBattlePtr = &(*battleArea->battles)[battleIdx];
118
119 if (gCurrentStageID < 0) {
120 gCurrentStagePtr = NULL;
121 } else {
122 gCurrentStagePtr = &(*battleArea->stages)[gCurrentStageID];
123 }
124
127}
128
136
137void set_battle_stage(s32 stageID) {
138 gCurrentStageID = stageID;
139}
140
142 gOverrideBattlePtr = battle;
143}
144
146 PlayerData* playerData = &gPlayerData;
147 s32 i;
148
149 playerData->curHP = 15;
150 playerData->curMaxHP = 15;
151 playerData->hardMaxHP = 15;
152 playerData->curFP = 10;
153 playerData->curMaxFP = 10;
154 playerData->hardMaxFP = 10;
155 playerData->level = 3;
156 playerData->hasActionCommands = TRUE;
157 playerData->starPoints = 55;
158 playerData->bootsLevel = 0;
159 playerData->hammerLevel = 0;
160 playerData->coins = 34;
161
162 for (i = 1; i < ARRAY_COUNT(playerData->partners); i++) {
163 playerData->partners[i].enabled = TRUE;
164 playerData->partners[i].level = 2;
165 }
166
167 playerData->curPartner = PARTNER_GOOMBARIO;
168
169 for (i = 0; i < ARRAY_COUNT(playerData->badges); i++) {
170 playerData->badges[i] = ITEM_NONE;
171 }
172
173 for (i = 0; i < ARRAY_COUNT(playerData->equippedBadges); i++) {
174 playerData->equippedBadges[i] = ITEM_NONE;
175 }
176
177 for (i = 0; i < ARRAY_COUNT(playerData->invItems); i++) {
178 playerData->invItems[i] = ITEM_NONE;
179 }
180
181 playerData->unused_288 = 0;
183 playerData->merleeCastsLeft = 0;
184 playerData->merleeTurnCount = 0;
185 playerData->maxStarPower = 0;
186 playerData->starPower = 0;
187 playerData->starBeamLevel = 0;
188}
189
190void load_demo_battle(u32 index) {
191 PlayerData* playerData = &gPlayerData;
192 u32 mode;
193 s32 battleID;
194
199
207 clear_npcs();
216 clear_entity_data(TRUE);
225
226 switch (index) {
227 case 0: // hammer first strike on Fuzzies
229 mode = 0;
230 playerData->hasActionCommands = FALSE;
231 battleID = BTL_DIG_FORMATION_00;
232 break;
233 case 1: // jump on Monty Mole
235 mode = 0;
236 playerData->curPartner = PARTNER_BOW;
237 battleID = BTL_DIG_FORMATION_01;
238 break;
239 case 2: // Parakarry shell shot against Pokey
241 mode = 0;
242 playerData->curPartner = PARTNER_PARAKARRY;
244 battleID = BTL_DIG_FORMATION_02;
245 break;
246 case 3: // Thunder Rage on Shy Guys at the slot machine
248 mode = 0;
249 playerData->curPartner = PARTNER_WATT;
250 battleID = BTL_DIG_FORMATION_03;
251 break;
252 case 4: // stomped by Tubba Blubba
254 mode = 0;
255 playerData->curPartner = PARTNER_KOOPER;
257 battleID = BTL_DIG_FORMATION_04;
258 break;
259 default:
261 mode = 2;
262 battleID = BTL_DIG_FORMATION_00;
263 }
264
267
268 switch (mode) {
269 case 0:
276 break;
277 case 1:
282 break;
283 case 2:
288 break;
289 case 3:
293 break;
294 case 4:
299 break;
300 }
301
307 gOverrideFlags &= ~GLOBAL_OVERRIDES_DISABLE_DRAW_FRAME;
308 load_battle(battleID);
309}
BSS s32 gBattleSubState
Definition battle.c:14
BSS s32 gDefeatedBattleSubstate
Definition battle.c:13
BSS Battle * gOverrideBattlePtr
Definition battle.c:18
void set_battle_formation(Battle *battle)
Definition battle.c:141
void set_battle_stage(s32 stageID)
Definition battle.c:137
BSS s32 gLastDrawBattleState
Definition battle.c:12
void load_battle_section(void)
Definition battle.c:111
BSS StageListRow * gCurrentStagePtr
Definition battle.c:9
BSS s32 gCurrentBattleID
Definition battle.c:16
BSS s32 gCurrentStageID
Definition battle.c:17
#define BTL_AREA_DMA(id, jpName)
Definition battle.c:32
void setup_demo_player(void)
Definition battle.c:145
BSS BattleStatus gBattleStatus
Definition battle.c:11
BSS s32 gBattleState
Definition battle.c:10
void reset_battle_status(void)
Definition battle.c:99
void load_demo_battle(u32 index)
Definition battle.c:190
BSS Battle * gCurrentBattlePtr
Definition battle.c:19
BattleArea gBattleAreas[]
Definition battle.c:50
void load_battle(s32 battleID)
Definition battle.c:129
#define BTL_AREA_AUX(id, jpName)
Definition battle.c:43
#define BTL_AREA(id, jpName)
Definition battle.c:22
BSS s32 gDefeatedBattleState
Definition battle.c:15
@ BTL_DIG_FORMATION_02
@ BTL_DIG_FORMATION_01
@ BTL_DIG_FORMATION_03
@ BTL_DIG_FORMATION_00
@ BTL_DIG_FORMATION_04
s16 equippedBadges[64]
s16 badges[128]
PartnerData partners[12]
s16 invItems[10]
@ MERLEE_SPELL_NONE
Definition enums.h:1910
@ OVERLAY_TYPE_9
Definition enums.h:2397
@ DEBUG_CONTACT_NONE
Definition enums.h:4267
@ DEMO_BTL_FLAG_10
Definition enums.h:3546
@ DEMO_BTL_FLAG_20
Definition enums.h:3547
@ DEMO_BTL_FLAG_ENEMY_ACTING
Definition enums.h:3545
@ DEMO_BTL_FLAG_ENABLED
Definition enums.h:3543
@ DEMO_BTL_FLAG_40
Definition enums.h:3548
@ DEMO_BTL_FLAG_PARTNER_ACTING
Definition enums.h:3544
@ ENCOUNTER_TRIGGER_JUMP
Definition enums.h:269
@ ENCOUNTER_TRIGGER_HAMMER
Definition enums.h:271
@ ENCOUNTER_TRIGGER_NONE
Definition enums.h:268
@ ENCOUNTER_TRIGGER_PARTNER
Definition enums.h:273
@ BTL_SUBSTATE_INIT
Definition enums.h:3671
@ BATTLE_STATE_0
Definition enums.h:3631
@ BATTLE_STATE_NORMAL_START
Definition enums.h:3632
@ CONTEXT_WORLD
Definition enums.h:3529
@ PARTNER_WATT
Definition enums.h:2891
@ PARTNER_BOW
Definition enums.h:2894
@ PARTNER_PARAKARRY
Definition enums.h:2889
@ PARTNER_KOOPER
Definition enums.h:2887
@ PARTNER_GOOMBARIO
Definition enums.h:2886
@ PLAYER_SPRITES_MARIO_WORLD
Definition enums.h:6346
@ FIRST_STRIKE_NONE
Definition enums.h:3458
@ FIRST_STRIKE_ENEMY
Definition enums.h:3460
@ FIRST_STRIKE_PLAYER
Definition enums.h:3459
void clear_script_list(void)
void clear_item_entity_data(void)
void create_cameras(void)
Definition cam_main.c:255
void clear_animator_list(void)
Definition animator.c:222
void clear_model_data(void)
Definition model.c:2364
void clear_trigger_data(void)
Definition trigger.c:13
void clear_sprite_shading_data(void)
void clear_entity_data(b32)
Definition entity.c:787
u32 dma_copy(Addr romStart, Addr romEnd, void *vramDest)
Definition 43F0.c:444
s32 evt_set_variable(Evt *script, Bytecode var, s32 value)
Definition evt.c:1847
void set_screen_overlay_params_front(u8, f32)
void clear_printers(void)
Definition msg.c:196
void clear_player_status(void)
Definition 77480.c:807
void clear_effect_data(void)
Definition effects.c:37
HeapNode * general_heap_create(void)
Definition heap.c:6
void clear_worker_list(void)
Definition worker.c:10
void clear_player_data(void)
Definition inventory.c:49
void func_80138188(void)
void btl_set_state(s32 battleState)
void clear_entity_models(void)
void reset_background_settings(void)
Definition background.c:33
void initialize_status_bar(void)
Definition inventory.c:477
void set_game_mode(s32 modeID)
Definition game_modes.c:127
@ GAME_MODE_BATTLE
Definition game_modes.h:15
void hud_element_clear_cache(void)
char unk_07
Definition npc.h:370
void clear_npcs(void)
Definition npc.c:60
void clear_encounter_status(void)
Definition npc.c:2224
EncounterStatus gCurrentEncounter
Definition encounter.c:176
s8 instigatorValue
Definition npc.h:378
s8 firstStrikeType
Definition npc.h:367
@ GF_Tutorial_SwapTurnOrder
#define UNPACK_BTL_AREA(battleID)
Definition macros.h:148
#define BSS
Definition macros.h:7
#define ARRAY_COUNT(arr)
Definition macros.h:40
#define UNPACK_BTL_INDEX(battleID)
Definition macros.h:149
void spr_init_sprites(s32 playerSpriteSet)
Definition sprite.c:764
@ BTL_AREA_KGR
Definition battle.h:30
@ BTL_AREA_ISK_1
Definition battle.h:22
@ BTL_AREA_TRD_2
Definition battle.h:18
@ BTL_AREA_OMO
Definition battle.h:27
@ BTL_AREA_HOS
Definition battle.h:15
@ BTL_AREA_ISK_2
Definition battle.h:23
@ BTL_AREA_TRD_3
Definition battle.h:19
@ BTL_AREA_KMR_3
Definition battle.h:13
@ BTL_AREA_KZN2
Definition battle.h:34
@ BTL_AREA_TIK2
Definition battle.h:38
@ BTL_AREA_OMO2_5
Definition battle.h:56
@ BTL_AREA_KPA4
Definition battle.h:48
@ BTL_AREA_IWA
Definition battle.h:20
@ BTL_AREA_KPA2
Definition battle.h:46
@ BTL_AREA_NOK
Definition battle.h:16
@ BTL_AREA_KZN
Definition battle.h:33
@ BTL_AREA_MIM
Definition battle.h:24
@ BTL_AREA_KPA3
Definition battle.h:47
@ BTL_AREA_JAN2
Definition battle.h:32
@ BTL_AREA_OMO2_2
Definition battle.h:53
@ BTL_AREA_TIK
Definition battle.h:37
@ BTL_AREA_KKJ
Definition battle.h:49
@ BTL_AREA_SBK
Definition battle.h:21
@ BTL_AREA_KMR_1
Definition battle.h:11
@ BTL_AREA_OMO2_4
Definition battle.h:55
@ BTL_AREA_OMO2_3
Definition battle.h:54
@ BTL_AREA_DIG
Definition battle.h:50
@ BTL_AREA_TRD_1
Definition battle.h:17
@ BTL_AREA_OMO2_6
Definition battle.h:57
@ BTL_AREA_PRA
Definition battle.h:42
@ BTL_AREA_MAC
Definition battle.h:14
@ BTL_AREA_JAN
Definition battle.h:31
@ BTL_AREA_KMR_2
Definition battle.h:12
@ BTL_AREA_TIK3
Definition battle.h:39
@ BTL_AREA_ARN
Definition battle.h:25
@ BTL_AREA_SAM2
Definition battle.h:41
@ BTL_AREA_SAM
Definition battle.h:40
@ BTL_AREA_KPA
Definition battle.h:45
@ BTL_AREA_PRA2
Definition battle.h:43
@ BTL_AREA_FLO
Definition battle.h:35
@ BTL_AREA_OMO2_1
Definition battle.h:52
@ BTL_AREA_OMO2
Definition battle.h:28
@ BTL_AREA_FLO2
Definition battle.h:36
@ BTL_AREA_PRA3
Definition battle.h:44
@ BTL_AREA_OMO3
Definition battle.h:29
@ BTL_AREA_DGB
Definition battle.h:26
void * dmaDest
Definition battle.h:217
BattleList * battles
Definition battle.h:218
StageList * stages
Definition battle.h:219
void * dmaEnd
Definition battle.h:216
void * dmaStart
Definition battle.h:215
Zero-terminated.
Definition battle.h:195
Zero-terminated.
Definition battle.h:206
#define BTL_STAGE_DEFAULT
Definition stage_names.h:3
s32 gOverrideFlags
Definition main_loop.c:11
GameStatus * gGameStatusPtr
Definition main_loop.c:32
PlayerData gPlayerData
Definition 77480.c:40