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

Go to the source code of this file.

Functions

void default_trigger_on_activate (Trigger *self)
 
void clear_trigger_data (void)
 
void init_trigger_list (void)
 
Triggercreate_trigger (TriggerBlueprint *bp)
 
void update_triggers (void)
 
void delete_trigger (Trigger *toDelete)
 
s32 is_another_trigger_bound (Trigger *trigger, EvtScript *script)
 
Triggerget_trigger_by_id (s32 triggerID)
 
s32 should_collider_allow_interact (s32 colliderID)
 

Variables

s16 gTriggerCount
 
BSS TriggerList wTriggerList
 
BSS TriggerList bTriggerList
 
BSS TriggerListgCurrentTriggerListPtr
 

Function Documentation

◆ default_trigger_on_activate()

void default_trigger_on_activate ( Trigger * self)

Definition at line 9 of file trigger.c.

9 {
10 self->flags |= TRIGGER_ACTIVATED;
11}
@ TRIGGER_ACTIVATED
Definition enums.h:2674

Referenced by create_trigger().

◆ clear_trigger_data()

void clear_trigger_data ( void )

Definition at line 13 of file trigger.c.

13 {
14 CollisionStatus* collisionStatus = &gCollisionStatus;
15 s32 i;
16
19 } else {
21 }
22
23 for (i = 0; i < ARRAY_COUNT(*gCurrentTriggerListPtr); i++) {
24 (*gCurrentTriggerListPtr)[i] = NULL;
25 }
26
27 gTriggerCount = 0;
28 collisionStatus->pushingAgainstWall = NO_COLLIDER;
29 collisionStatus->curFloor = NO_COLLIDER;
30 collisionStatus->lastTouchedFloor = NO_COLLIDER;
31 collisionStatus->curCeiling = NO_COLLIDER;
32 collisionStatus->curInspect = NO_COLLIDER;
33 collisionStatus->unk_0C = -1;
34 collisionStatus->unk_0E = -1;
35 collisionStatus->unk_10 = -1;
36 collisionStatus->curWall = NO_COLLIDER;
37 collisionStatus->lastWallHammered = NO_COLLIDER;
38 collisionStatus->touchingWallTrigger = 0;
39 collisionStatus->bombetteExploded = -1;
40 collisionStatus->bombetteExplosionPos.x = 0.0f;
41 collisionStatus->bombetteExplosionPos.y = 0.0f;
42 collisionStatus->bombetteExplosionPos.z = 0.0f;
43}
@ CONTEXT_WORLD
Definition enums.h:3529
#define ARRAY_COUNT(arr)
Definition macros.h:40
#define NO_COLLIDER
Definition macros.h:156
BSS TriggerList * gCurrentTriggerListPtr
Definition trigger.c:7
BSS TriggerList bTriggerList
Definition trigger.c:6
BSS TriggerList wTriggerList
Definition trigger.c:5
s16 gTriggerCount
Definition trigger.c:4
CollisionStatus gCollisionStatus
Definition 7BB60.c:6
GameStatus * gGameStatusPtr
Definition main_loop.c:32

Referenced by load_demo_battle(), load_engine_data(), load_map_by_IDs(), state_step_battle(), state_step_demo(), state_step_intro(), state_step_pause(), and state_step_startup().

◆ init_trigger_list()

void init_trigger_list ( void )

Definition at line 45 of file trigger.c.

Referenced by state_step_end_battle(), and state_step_unpause().

◆ create_trigger()

Trigger * create_trigger ( TriggerBlueprint * bp)

Definition at line 55 of file trigger.c.

55 {
56 Trigger* trigger;
57 s32 i;
58
59 for (i = 0; i < ARRAY_COUNT(*gCurrentTriggerListPtr); i++) {
60 Trigger* listTrigger = (*gCurrentTriggerListPtr)[i];
61
62 if (listTrigger == NULL) {
63 break;
64 }
65 }
66
68
69 (*gCurrentTriggerListPtr)[i] = trigger = heap_malloc(sizeof(*trigger));
71
72 ASSERT(trigger != NULL);
73
74 trigger->flags = bp->flags | TRIGGER_ACTIVE;
75 trigger->varIndex = bp->varIndex;
76 trigger->location.colliderID = bp->colliderID;
77 trigger->itemList = bp->itemList;
78 trigger->tattleMsg = bp->tattleMsg;
80
81 trigger->onActivateFunc = bp->onActivateFunc;
82 if (trigger->onActivateFunc == NULL) {
84 }
85
86 return trigger;
87}
#define ASSERT(condition)
@ TRIGGER_ACTIVE
Definition enums.h:2673
void * heap_malloc(s32 size)
Definition heap.c:34
s32(* onActivateFunc)(struct Trigger *)
union Trigger::@1 location
s32(* onActivateFunc)(struct Trigger *)
s32 * itemList
u8 hasPlayerInteractPrompt
void default_trigger_on_activate(Trigger *self)
Definition trigger.c:9

Referenced by bind_trigger(), evt_handle_bind(), and evt_handle_bind_lock().

◆ update_triggers()

void update_triggers ( void )

Definition at line 89 of file trigger.c.

89 {
90 CollisionStatus* collisionStatus = &gCollisionStatus;
91 Trigger* listTrigger;
92 s32 i;
93
94 collisionStatus->touchingWallTrigger = 0;
95
96 for (i = 0; i < ARRAY_COUNT(*gCurrentTriggerListPtr); i++) {
97 listTrigger = (*gCurrentTriggerListPtr)[i];
98
99 if (listTrigger == NULL) {
100 continue;
101 }
102
103 if (!(listTrigger->flags & TRIGGER_ACTIVE)) {
104 continue;
105 }
106
107 if (listTrigger->flags & TRIGGER_FORCE_ACTIVATE) {
108 listTrigger->flags |= TRIGGER_ACTIVATED;
109 continue;
110 }
111
112 if (listTrigger->flags & TRIGGER_WALL_PUSH) {
113 if (listTrigger->location.colliderID == collisionStatus->curWall) {
114 func_800E06C0(1);
115 }
116 if (listTrigger->location.colliderID == collisionStatus->pushingAgainstWall) {
117 func_800E06C0(0);
118 } else {
119 continue;
120 }
121 }
122
123 if (listTrigger->flags & TRIGGER_FLOOR_TOUCH) {
124 if (listTrigger->location.colliderID != collisionStatus->curFloor) {
125 continue;
126 }
127 }
128
129 if (listTrigger->flags & TRIGGER_FLOOR_ABOVE) {
130 if (listTrigger->location.colliderID != collisionStatus->floorBelow) {
131 continue;
132 }
133 }
134
135 if (listTrigger->flags & TRIGGER_WALL_PRESS_A) {
136 if (listTrigger->location.colliderID == collisionStatus->curWall) {
137 collisionStatus->touchingWallTrigger = 1;
138 }
139 if ((listTrigger->location.colliderID != collisionStatus->curInspect) || !phys_can_player_interact()) {
140 continue;
141 }
142 }
143
144 if (listTrigger->flags & TRIGGER_WALL_TOUCH) {
145 if (listTrigger->location.colliderID != collisionStatus->curWall) {
146 continue;
147 }
148 }
149
150 if (listTrigger->flags & TRIGGER_FLOOR_JUMP) {
151 if (listTrigger->location.colliderID != collisionStatus->lastTouchedFloor) {
152 continue;
153 }
154 }
155
156 if (listTrigger->flags & TRIGGER_FLOOR_PRESS_A) {
157 if ((listTrigger->location.colliderID != collisionStatus->curFloor) ||
159 continue;
160 }
161 }
162
163 if (listTrigger->flags & TRIGGER_WALL_HAMMER) {
164 if (listTrigger->location.colliderID != collisionStatus->lastWallHammered) {
165 continue;
166 }
167 }
168
169 if (listTrigger->flags & TRIGGER_CEILING_TOUCH) {
170 if (listTrigger->location.colliderID != collisionStatus->curCeiling) {
171 continue;
172 }
173 }
174
175 if (listTrigger->flags & TRIGGER_FLAG_2000) {
176 if (listTrigger->location.colliderID != collisionStatus->unk_0C) {
177 continue;
178 }
179 }
180
181 if (listTrigger->flags & TRIGGER_FLAG_4000) {
182 if (listTrigger->location.colliderID != collisionStatus->unk_0E) {
183 continue;
184 }
185 }
186
187 if (listTrigger->flags & TRIGGER_FLAG_8000) {
188 if (listTrigger->location.colliderID != collisionStatus->unk_10) {
189 continue;
190 }
191 }
192
193 if (listTrigger->flags & TRIGGER_POINT_BOMB) {
194 BombTrigger* bombPos;
195 f32 dist;
196
197 if (collisionStatus->bombetteExploded < 0) {
198 continue;
199 }
200
201 bombPos = listTrigger->location.blast;
202 dist = dist3D(bombPos->pos.x, bombPos->pos.y, bombPos->pos.z,
203 collisionStatus->bombetteExplosionPos.x, collisionStatus->bombetteExplosionPos.y,
204 collisionStatus->bombetteExplosionPos.z);
205
206 if ((bombPos->diameter * 0.5f) + 50.0f < dist) {
207 continue;
208 }
209 }
210
211 if (listTrigger->flags & TRIGGER_GAME_FLAG_SET && get_global_flag(listTrigger->varIndex) == 0) {
212 continue;
213 }
214
215 if (listTrigger->flags & TRIGGER_AREA_FLAG_SET && get_area_flag(listTrigger->varIndex) == 0) {
216 continue;
217 }
218
219 listTrigger->flags |= TRIGGER_ACTIVATED;
220 }
221
222 for (i = 0; i < ARRAY_COUNT(*gCurrentTriggerListPtr); i++) {
223 listTrigger = (*gCurrentTriggerListPtr)[i];
224
225 if (listTrigger == NULL) {
226 continue;
227 }
228
229 if (listTrigger->flags & TRIGGER_ACTIVE) {
230 if (listTrigger->flags & TRIGGER_ACTIVATED) {
231 if (listTrigger->onActivateFunc(listTrigger) == 0) {
232 listTrigger->flags &= ~TRIGGER_ACTIVATED;
233 }
234 }
235 }
236 }
237}
u32 pressedButtons[4]
@ BUTTON_A
Definition enums.h:2790
@ PS_FLAG_INPUT_DISABLED
Definition enums.h:3052
@ TRIGGER_FLAG_8000
Definition enums.h:2685
@ TRIGGER_AREA_FLAG_SET
Definition enums.h:2687
@ TRIGGER_FORCE_ACTIVATE
Definition enums.h:2675
@ TRIGGER_FLOOR_JUMP
Definition enums.h:2679
@ TRIGGER_FLAG_4000
Definition enums.h:2684
@ TRIGGER_FLOOR_ABOVE
Definition enums.h:2689
@ TRIGGER_GAME_FLAG_SET
Definition enums.h:2686
@ TRIGGER_WALL_HAMMER
Definition enums.h:2682
@ TRIGGER_WALL_PRESS_A
Definition enums.h:2678
@ TRIGGER_CEILING_TOUCH
Definition enums.h:2688
@ TRIGGER_WALL_PUSH
Definition enums.h:2676
@ TRIGGER_FLOOR_PRESS_A
Definition enums.h:2681
@ TRIGGER_FLOOR_TOUCH
Definition enums.h:2677
@ TRIGGER_POINT_BOMB
Definition enums.h:2690
@ TRIGGER_FLAG_2000
Definition enums.h:2683
@ TRIGGER_WALL_TOUCH
Definition enums.h:2680
s32 phys_can_player_interact(void)
Definition 7BB60.c:1159
f32 dist3D(f32 ax, f32 ay, f32 az, f32 bx, f32 by, f32 bz)
Definition 43F0.c:677
void func_800E06C0(s32)
Definition 77480.c:1160
PlayerStatus gPlayerStatus
Definition 77480.c:39
s32 get_global_flag(s32 index)
Definition vars_access.c:89
s32 get_area_flag(s32 index)

Referenced by step_game_loop().

◆ delete_trigger()

void delete_trigger ( Trigger * toDelete)

Definition at line 239 of file trigger.c.

239 {
240 s32 i;
241
242 for (i = 0; i < ARRAY_COUNT(*gCurrentTriggerListPtr); i++) {
243 if ((*gCurrentTriggerListPtr)[i] == toDelete) {
244 break;
245 }
246 }
247
250 (*gCurrentTriggerListPtr)[i] = NULL;
251 }
252}
s32 heap_free(void *ptr)
Definition heap.c:42

Referenced by evt_handle_unbind().

◆ is_another_trigger_bound()

s32 is_another_trigger_bound ( Trigger * trigger,
EvtScript * script )

Definition at line 254 of file trigger.c.

254 {
255 s32 i;
256
257 for (i = 0; i < ARRAY_COUNT(*gCurrentTriggerListPtr); i++) {
258 Trigger* listTrigger = (*gCurrentTriggerListPtr)[i];
259
260 if (listTrigger == NULL || listTrigger == trigger) {
261 continue;
262 }
263
264 if (listTrigger->flags & TRIGGER_ACTIVE) {
265 if (listTrigger->flags & TRIGGER_ACTIVATED) {
266 if (listTrigger->onTriggerEvt == script) {
267 return TRUE;
268 }
269 }
270 }
271 }
272
273 return FALSE;
274}
EvtScript * onTriggerEvt

Referenced by evt_trigger_on_activate_exec_script().

◆ get_trigger_by_id()

Trigger * get_trigger_by_id ( s32 triggerID)

Definition at line 276 of file trigger.c.

276 {
277 return (*gCurrentTriggerListPtr)[triggerID];
278}

Referenced by get_trigger_tattle().

◆ should_collider_allow_interact()

s32 should_collider_allow_interact ( s32 colliderID)
Returns
TRUE if colliderID is bound to an interaction trigger (press A) and the player can use it.

Definition at line 281 of file trigger.c.

281 {
282 s32 i;
283
285 return FALSE;
286 }
287
288 for (i = 0; i < ARRAY_COUNT(*gCurrentTriggerListPtr); i++) {
289 Trigger* trigger = (*gCurrentTriggerListPtr)[i];
290
291 if (trigger != NULL
292 && trigger->hasPlayerInteractPrompt != 0
293 && trigger->location.colliderID == colliderID
294 && trigger->flags & TRIGGER_WALL_PRESS_A
295 ) {
296 return TRUE;
297 }
298 }
299 return FALSE;
300}

Referenced by check_for_interactables(), func_800E06D8(), and should_continue_inspect().

Variable Documentation

◆ gTriggerCount

s16 gTriggerCount

Definition at line 4 of file trigger.c.

Referenced by clear_trigger_data(), create_trigger(), and init_trigger_list().

◆ wTriggerList

BSS TriggerList wTriggerList

Definition at line 5 of file trigger.c.

Referenced by clear_trigger_data(), and init_trigger_list().

◆ bTriggerList

BSS TriggerList bTriggerList

Definition at line 6 of file trigger.c.

Referenced by clear_trigger_data(), and init_trigger_list().

◆ gCurrentTriggerListPtr