Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
trigger.c
Go to the documentation of this file.
1#include "common.h"
2#include "vars_access.h"
3
8
12
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}
44
54
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}
88
89void update_triggers(void) {
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}
238
239void delete_trigger(Trigger* toDelete) {
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}
253
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}
275
276Trigger* get_trigger_by_id(s32 triggerID) {
277 return (*gCurrentTriggerListPtr)[triggerID];
278}
279
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}
u32 pressedButtons[4]
Trigger * TriggerList[64]
Bytecode EvtScript[]
#define ASSERT(condition)
@ BUTTON_A
Definition enums.h:2790
@ PS_FLAG_INPUT_DISABLED
Definition enums.h:3052
@ CONTEXT_WORLD
Definition enums.h:3529
@ TRIGGER_FLAG_8000
Definition enums.h:2685
@ TRIGGER_AREA_FLAG_SET
Definition enums.h:2687
@ TRIGGER_ACTIVE
Definition enums.h:2673
@ 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_ACTIVATED
Definition enums.h:2674
@ 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
s32 heap_free(void *ptr)
Definition heap.c:42
void * heap_malloc(s32 size)
Definition heap.c:34
#define BSS
Definition macros.h:7
#define ARRAY_COUNT(arr)
Definition macros.h:40
#define NO_COLLIDER
Definition macros.h:156
s32(* onActivateFunc)(struct Trigger *)
union Trigger::@1 location
s32(* onActivateFunc)(struct Trigger *)
s32 * itemList
u8 hasPlayerInteractPrompt
EvtScript * onTriggerEvt
s32 should_collider_allow_interact(s32 colliderID)
Definition trigger.c:281
void default_trigger_on_activate(Trigger *self)
Definition trigger.c:9
Trigger * get_trigger_by_id(s32 triggerID)
Definition trigger.c:276
BSS TriggerList * gCurrentTriggerListPtr
Definition trigger.c:7
void clear_trigger_data(void)
Definition trigger.c:13
void init_trigger_list(void)
Definition trigger.c:45
BSS TriggerList bTriggerList
Definition trigger.c:6
void update_triggers(void)
Definition trigger.c:89
s32 is_another_trigger_bound(Trigger *trigger, EvtScript *script)
Definition trigger.c:254
BSS TriggerList wTriggerList
Definition trigger.c:5
s16 gTriggerCount
Definition trigger.c:4
void delete_trigger(Trigger *toDelete)
Definition trigger.c:239
Trigger * create_trigger(TriggerBlueprint *bp)
Definition trigger.c:55
CollisionStatus gCollisionStatus
Definition 7BB60.c:6
GameStatus * gGameStatusPtr
Definition main_loop.c:32
PlayerStatus gPlayerStatus
Definition 77480.c:39
s32 get_global_flag(s32 index)
Definition vars_access.c:89
s32 get_area_flag(s32 index)