Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
run_away.c File Reference

Go to the source code of this file.

Enumerations

enum  {
  BTL_SUBSTATE_EXEC_SCRIPT = BTL_SUBSTATE_INIT , BTL_SUBSTATE_AWAIT_SCRIPT = 2 , BTL_SUBSTATE_EXEC_POST_FAILURE = 3 , BTL_SUBSTATE_AWAIT_POST_FAILURE = 4 ,
  BTL_SUBSTATE_GIVE_STAR_POINTS = 10 , BTL_SUBSTATE_DONE = 11
}
 

Functions

void btl_state_update_run_away (void)
 
void btl_state_draw_run_away (void)
 

Variables

BSS s32 RunAwayRewardStep
 
BSS s32 RunAwayRewardTotal
 
BSS s32 RunAwayRewardIncrement
 

Enumeration Type Documentation

◆ anonymous enum

Enumerator
BTL_SUBSTATE_EXEC_SCRIPT 
BTL_SUBSTATE_AWAIT_SCRIPT 
BTL_SUBSTATE_EXEC_POST_FAILURE 
BTL_SUBSTATE_AWAIT_POST_FAILURE 
BTL_SUBSTATE_GIVE_STAR_POINTS 
BTL_SUBSTATE_DONE 

Definition at line 4 of file run_away.c.

4 {
11};
@ BTL_SUBSTATE_EXEC_POST_FAILURE
Definition run_away.c:7
@ BTL_SUBSTATE_GIVE_STAR_POINTS
Definition run_away.c:9
@ BTL_SUBSTATE_AWAIT_SCRIPT
Definition run_away.c:6
@ BTL_SUBSTATE_AWAIT_POST_FAILURE
Definition run_away.c:8
@ BTL_SUBSTATE_EXEC_SCRIPT
Definition run_away.c:5
@ BTL_SUBSTATE_DONE
Definition run_away.c:10
@ BTL_SUBSTATE_INIT
Definition states.h:8

Function Documentation

◆ btl_state_update_run_away()

void btl_state_update_run_away ( void )

Definition at line 17 of file run_away.c.

17 {
21 Actor* player = battleStatus->playerActor;
22 Actor* partner = battleStatus->partnerActor;
23 Actor* enemy;
26 Evt* script;
27 s32 i;
28
29 switch (gBattleSubState) {
31 battleStatus->stateFreezeCount = 0;
37
38 playerData->fleeAttempts++;
41
42 // calculate average escape chance
43 enemyCount = 0;
44 totalEscapeChance = 0.0f;
45
46 for (i = 0; i < ARRAY_COUNT(battleStatus->enemyActors); i++) {
47 enemy = battleStatus->enemyActors[i];
48 if (enemy != NULL) {
49 if (!(enemy->flags & ACTOR_FLAG_TARGET_ONLY)) {
50 if (!(enemy->flags & ACTOR_FLAG_NO_DMG_APPLY)) {
51 f32 escapeChance = enemy->actorBlueprint->escapeChance;
52
53 if (enemy->debuff == STATUS_KEY_UNUSED ||
54 enemy->debuff == STATUS_KEY_DIZZY ||
55 enemy->debuff == STATUS_KEY_PARALYZE ||
56 enemy->debuff == STATUS_KEY_SLEEP ||
57 enemy->debuff == STATUS_KEY_FROZEN ||
58 enemy->debuff == STATUS_KEY_STOP)
59 {
60 escapeChance = 100.0f;
61 }
62 totalEscapeChance += escapeChance;
63 enemyCount++;
64 }
65 }
66 }
67 }
68 player->state.varTable[0] = totalEscapeChance / enemyCount;
69
71 player->state.varTable[0] = 100;
72 }
73
76 player->takeTurnScript = script;
77 player->takeTurnScriptID = script->id;
78 script->owner1.actorID = ACTOR_PLAYER;
79 if (partner != NULL && partner->koStatus == 0) {
80 script = start_script(partner->takeTurnSource, EVT_PRIORITY_A, 0);
81 partner->takeTurnScript = script;
82 partner->takeTurnScriptID = script->id;
83 script->owner1.actorID = ACTOR_PARTNER;
84 }
86 break;
88 if (does_script_exist(player->takeTurnScriptID) || battleStatus->stateFreezeCount != 0) {
89 break;
90 }
93 } else {
97 } else {
101 // divide reward into 20 increments
102 RunAwayRewardTotal = battleStatus->totalStarPoints * 100;
106 }
107 }
108 break;
109 }
110
112 if (battleStatus->totalStarPoints != 0) {
113 s32 deltaSP;
114 s32 prevSP;
115
117 prevSP = battleStatus->totalStarPoints;
118 battleStatus->totalStarPoints = RunAwayRewardTotal / 100;
119 deltaSP = prevSP - battleStatus->totalStarPoints;
120
121 if (deltaSP > 0) {
123 }
124 playerData->starPoints += deltaSP;
126 if (RunAwayRewardStep == 0 && battleStatus->totalStarPoints != 0) {
127 playerData->starPoints++;
128 }
129 }
130 if (playerData->starPoints >= 99) {
131 playerData->starPoints = 99;
132 }
133 if (battleStatus->totalStarPoints == 0) {
134 if (RunAwayRewardStep != 0) {
136 } else {
140 }
141 }
142 }
143
145 playerData->battlesFled++;
147 bgm_set_song(0, -1, 0, 1500, 8);
148 }
150 }
151
152 switch (gBattleSubState) {
154 battleStatus->battlePhase = PHASE_RUN_AWAY_FAIL;
156 player->takeTurnScript = script;
157 player->takeTurnScriptID = script->id;
158 script->owner1.actorID = ACTOR_PLAYER;
159 if (partner != NULL && partner->koStatus == 0) {
160 script = start_script(partner->takeTurnSource, EVT_PRIORITY_A, 0);
161 partner->takeTurnScript = script;
162 partner->takeTurnScriptID = script->id;
163 script->owner1.actorID = ACTOR_PARTNER;
164 }
166 break;
168 if (BattleSubstateDelay != 0) {
170 return;
171 }
173 && (partner == NULL || !does_script_exist(partner->takeTurnScriptID))
174 && battleStatus->stateFreezeCount == 0
175 ) {
177 }
178 break;
179 }
180}
s32 BattleScreenFadeAmt
Definition 16C8E0.c:50
BSS s32 PopupMenu_SelectedIndex
s32 bgm_set_song(s32 playerIndex, s32 songID, s32 variation, s32 fadeOutTime, s16 volume)
BSS s32 BattleSubstateDelay
struct Evt * takeTurnScript
struct ActorBlueprint * actorBlueprint
ActorState state
s32 takeTurnScriptID
@ BS_FLAGS1_BATTLE_FLED
Definition enums.h:3620
@ DEBUG_CONTACT_AUTO_FLEE
Definition enums.h:3870
@ PHASE_RUN_AWAY_START
Definition enums.h:2093
@ PHASE_RUN_AWAY_FAIL
Definition enums.h:2097
@ BS_FLAGS2_OVERRIDE_INACTIVE_PARTNER
Definition enums.h:3641
@ BS_FLAGS2_PLAYER_TURN_USED
Definition enums.h:3638
@ BS_FLAGS2_OVERRIDE_INACTIVE_PLAYER
Definition enums.h:3640
@ BS_FLAGS2_PARTNER_TURN_USED
Definition enums.h:3639
@ BS_FLAGS2_DONT_STOP_MUSIC
Definition enums.h:3652
@ STATUS_KEY_PARALYZE
Definition enums.h:2806
@ STATUS_KEY_FROZEN
Definition enums.h:2808
@ STATUS_KEY_SLEEP
Definition enums.h:2807
@ STATUS_KEY_UNUSED
Definition enums.h:2804
@ STATUS_KEY_STOP
Definition enums.h:2809
@ STATUS_KEY_DIZZY
Definition enums.h:2805
@ BTL_CAM_PLAYER_FLEE
Definition enums.h:4432
@ BATTLE_STATE_TRANSFER_TURN
Definition enums.h:3673
@ BATTLE_STATE_END_BATTLE
Definition enums.h:3694
@ ABILITY_RUNAWAY_PAY
Definition enums.h:459
@ SOUND_COIN_PICKUP
Definition enums.h:925
@ ACTOR_PLAYER
Definition enums.h:2118
@ ACTOR_PARTNER
Definition enums.h:2119
@ ACTOR_FLAG_TARGET_ONLY
Battle ends even if undefeated. No turn.
Definition enums.h:3368
@ ACTOR_FLAG_NO_DMG_APPLY
Damage is not applied to actor HP.
Definition enums.h:3374
@ OUTCOME_PLAYER_FLED
Definition enums.h:1930
@ EVT_PRIORITY_A
Definition evt.h:154
s32 is_ability_active(s32 arg0)
Definition inventory.c:1735
void btl_start_blinking_starpoints(void)
Definition 16C8E0.c:97
void btl_stop_blinking_starpoints(void)
Definition 16C8E0.c:102
void status_bar_stop_blinking_starpoints(void)
Definition inventory.c:1647
void btl_cam_use_preset(s32)
Definition camera.c:1919
void btl_cam_target_actor(s32)
Definition camera.c:1926
Evt * start_script(EvtScript *source, s32 priority, s32 initialState)
void status_bar_start_blinking_starpoints(void)
Definition inventory.c:1638
s32 does_script_exist(s32 id)
void btl_set_state(s32 battleState)
EvtScript EVS_Mario_HandlePhase
EncounterStatus gCurrentEncounter
Definition encounter.c:175
void sfx_play_sound(s32 soundID)
BSS s32 RunAwayRewardStep
Definition run_away.c:13
BSS s32 RunAwayRewardIncrement
Definition run_away.c:15
BSS s32 RunAwayRewardTotal
Definition run_away.c:14
#define ARRAY_COUNT(arr)
Definition macros.h:40
GameStatus * gGameStatusPtr
Definition main_loop.c:31
PlayerData gPlayerData
Definition 77480.c:39
BattleStatus gBattleStatus
Definition battle.cpp:14
s32 gBattleSubState
Definition battle.cpp:17

Referenced by btl_update().

◆ btl_state_draw_run_away()

void btl_state_draw_run_away ( void )

Definition at line 182 of file run_away.c.

182 {
183}

Referenced by btl_draw_ui().

Variable Documentation

◆ RunAwayRewardStep

BSS s32 RunAwayRewardStep

Definition at line 13 of file run_away.c.

Referenced by btl_state_update_run_away().

◆ RunAwayRewardTotal

BSS s32 RunAwayRewardTotal

Definition at line 14 of file run_away.c.

Referenced by btl_state_update_run_away().

◆ RunAwayRewardIncrement

BSS s32 RunAwayRewardIncrement

Definition at line 15 of file run_away.c.

Referenced by btl_state_update_run_away().