Skip to content

Commit 22ee217

Browse files
committed
Review trap eye candy ids
Closes #55
1 parent b652043 commit 22ee217

File tree

1 file changed

+45
-17
lines changed

1 file changed

+45
-17
lines changed

src/game/trap.c

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@
2424
#define TRAP_START_SENTINEL 0x81726354
2525
#define TRAP_END_SENTINEL 0x81726354
2626

27+
typedef enum TrapEyeCandyType {
28+
TRAP_EYE_CANDY_TYPE_TRIGGER_EFFECT,
29+
TRAP_EYE_CANDY_TYPE_VICTIM_EFFECT,
30+
TRAP_EYE_CANDY_TYPE_SPOTTED,
31+
TRAP_EYE_CANDY_TYPE_COUNT,
32+
} TrapEyeCandyType;
33+
2734
typedef enum TrapScript {
2835
TRAP_SCRIPT_MAGICAL = 30000,
2936
TRAP_SCRIPT_MECHANICAL = 30001,
@@ -303,7 +310,11 @@ void trap_mark_known(int64_t pc_obj, int64_t trap_obj, int reason)
303310
} else {
304311
obj_arrayfield_script_get(trap_obj, OBJ_F_SCRIPTS_IDX, SAP_USE, &scr);
305312
if (scr.num >= TRAP_SCRIPT_FIRST && scr.num < TRAP_SCRIPT_COUNT) {
306-
sub_4CCD20(&trap_eye_candies, &animfx, trap_obj, -1, 3 * scr.num - 90000 - 2);
313+
sub_4CCD20(&trap_eye_candies,
314+
&animfx,
315+
trap_obj,
316+
-1,
317+
TRAP_EYE_CANDY_TYPE_COUNT * (scr.num - TRAP_SCRIPT_FIRST) + TRAP_EYE_CANDY_TYPE_SPOTTED);
307318
animfx.animate = true;
308319
animfx_add(&animfx);
309320
}
@@ -334,7 +345,10 @@ void trap_remove_internal(int64_t trap_obj)
334345
} else {
335346
obj_arrayfield_script_get(trap_obj, OBJ_F_SCRIPTS_IDX, SAP_USE, &scr);
336347
if (scr.num >= TRAP_SCRIPT_FIRST && scr.num < TRAP_SCRIPT_COUNT) {
337-
animfx_remove(&trap_eye_candies, trap_obj, 3 * scr.num - 90000 - 2, -1);
348+
animfx_remove(&trap_eye_candies,
349+
trap_obj,
350+
TRAP_EYE_CANDY_TYPE_COUNT * (scr.num - TRAP_SCRIPT_FIRST) + TRAP_EYE_CANDY_TYPE_SPOTTED,
351+
-1);
338352
}
339353
scr.num = 0;
340354
obj_arrayfield_script_set(trap_obj, OBJ_F_SCRIPTS_IDX, 1, &scr);
@@ -630,7 +644,7 @@ bool trap_script_execute(ScriptInvocation* invocation)
630644
ObjectList critters;
631645
ObjectNode* node;
632646
AnimFxNode animfx;
633-
int v1;
647+
int base;
634648

635649
if (trap_type_from_scr(invocation->script) == TRAP_TYPE_INVALID) {
636650
return false;
@@ -664,25 +678,35 @@ bool trap_script_execute(ScriptInvocation* invocation)
664678
}
665679

666680
if (invocation->script->num >= TRAP_SCRIPT_FIRST && invocation->script->num < TRAP_SCRIPT_COUNT) {
667-
v1 = 3 * invocation->script->num - 90000;
668-
669-
// TODO: Looks unreachable, check.
670-
if (3 * invocation->script->num != 89999) {
671-
sub_4CCD20(&trap_eye_candies, &animfx, invocation->triggerer_obj, -1, v1);
672-
animfx.animate = true;
673-
animfx_add(&animfx);
674-
animfx_remove(&trap_eye_candies, invocation->attachee_obj, v1 + 2, -1);
675-
}
681+
base = TRAP_EYE_CANDY_TYPE_COUNT * (invocation->script->num - TRAP_SCRIPT_FIRST);
676682
} else {
677-
v1 = -1;
683+
base = -1;
684+
}
685+
686+
if (base != -1) {
687+
sub_4CCD20(&trap_eye_candies,
688+
&animfx,
689+
invocation->triggerer_obj,
690+
-1,
691+
base + TRAP_EYE_CANDY_TYPE_TRIGGER_EFFECT);
692+
animfx.animate = true;
693+
animfx_add(&animfx);
694+
animfx_remove(&trap_eye_candies,
695+
invocation->attachee_obj,
696+
base + TRAP_EYE_CANDY_TYPE_SPOTTED,
697+
-1);
678698
}
679699

680700
if (radius > 0) {
681701
node = critters.head;
682702
while (node != NULL) {
683703
trigger_trap(node->obj, invocation);
684-
if (v1 != -1) {
685-
sub_4CCD20(&trap_eye_candies, &animfx, node->obj, -1, v1 + 1);
704+
if (base != -1) {
705+
sub_4CCD20(&trap_eye_candies,
706+
&animfx,
707+
node->obj,
708+
-1,
709+
base + TRAP_EYE_CANDY_TYPE_VICTIM_EFFECT);
686710
animfx.animate = true;
687711
animfx_add(&animfx);
688712
}
@@ -698,8 +722,12 @@ bool trap_script_execute(ScriptInvocation* invocation)
698722
} else {
699723
if (invocation->triggerer_obj != OBJ_HANDLE_NULL) {
700724
trigger_trap(invocation->triggerer_obj, invocation);
701-
if (v1 != -1) {
702-
sub_4CCD20(&trap_eye_candies, &animfx, invocation->triggerer_obj, -1, v1 + 1);
725+
if (base != -1) {
726+
sub_4CCD20(&trap_eye_candies,
727+
&animfx,
728+
invocation->triggerer_obj,
729+
-1,
730+
base + TRAP_EYE_CANDY_TYPE_VICTIM_EFFECT);
703731
animfx.animate = true;
704732
animfx_add(&animfx);
705733
}

0 commit comments

Comments
 (0)