Skip to content

Commit 6827d56

Browse files
committed
Code review for potsanity 3.0
1 parent 665c702 commit 6827d56

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+492
-566
lines changed

ASM/build.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@
132132
else:
133133
continue
134134
data_symbols[name] = {
135-
"address": '{0:08X}'.format(addr),
136-
"length": sym['length'] if 'length' in sym.keys() else 0
137-
}
135+
'address': f'{addr:08X}',
136+
'length': sym.get('length', 0),
137+
}
138138
with open('../data/generated/symbols.json', 'w') as f:
139139
json.dump(data_symbols, f, indent=4, sort_keys=True)
140140

ASM/c/actor.c

+25-39
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,12 @@ ActorAdditionalData* Actor_GetAdditionalData(z64_actor_t* actor) {
3939
// Store the flag using the pointer
4040
void Actor_BuildFlag(z64_actor_t* actor, xflag_t* flag, uint16_t actor_index, uint8_t subflag) {
4141
flag->scene = z64_game.scene_index;
42-
if(z64_game.scene_index == 0x3E) {
42+
if (z64_game.scene_index == 0x3E) {
4343
flag->grotto.room = actor->room_index;
4444
flag->grotto.grotto_id = z64_file.grotto_id & 0x1F;
4545
flag->grotto.flag = actor_index;
4646
flag->grotto.subflag = subflag;
47-
}
48-
else {
47+
} else {
4948
flag->room = actor->room_index;
5049
flag->setup = curr_scene_setup;
5150
flag->flag = actor_index;
@@ -70,11 +69,11 @@ void Actor_After_UpdateAll_Hack(z64_actor_t* actor, z64_game_t* game) {
7069
void Actor_StoreFlag(z64_actor_t* actor, z64_game_t* game, xflag_t flag) {
7170
ActorAdditionalData* extra = Actor_GetAdditionalData(actor);
7271
flag = resolve_alternative_flag(&flag);
73-
if(CURR_ACTOR_SPAWN_INDEX)
72+
if (CURR_ACTOR_SPAWN_INDEX) {
7473
extra->actor_id = CURR_ACTOR_SPAWN_INDEX;
74+
}
7575
override_t override = lookup_override_by_newflag(&flag);
76-
switch(actor->actor_id)
77-
{
76+
switch (actor->actor_id) {
7877
// For the following actors we store the flag in the new space added to the actor.
7978
case OBJ_TSUBO:
8079
case EN_TUBO_TRAP:
@@ -85,8 +84,7 @@ void Actor_StoreFlag(z64_actor_t* actor, z64_game_t* game, xflag_t flag) {
8584
case EN_WONDER_ITEM:
8685
{
8786
// For these actors, only store the flag if there is a valid override
88-
if(override.key.all)
89-
{
87+
if (override.key.all) {
9088
extra->flag = flag;
9189
}
9290
break;
@@ -99,8 +97,7 @@ void Actor_StoreFlag(z64_actor_t* actor, z64_game_t* game, xflag_t flag) {
9997
// Don't really need to do this since we will recalculate the flag and check the override when spawning the subflags.
10098
extra->flag = flag;
10199
}
102-
default:
103-
{
100+
default: {
104101
break;
105102
}
106103
}
@@ -119,8 +116,8 @@ void Actor_StoreFlagByIndex(z64_actor_t* actor, z64_game_t* game, uint16_t actor
119116
// Get an override for new flag. If the override doesn't exist, or flag has already been set, return 0.
120117
override_t get_newflag_override(xflag_t* flag) {
121118
override_t override = lookup_override_by_newflag(flag);
122-
if(override.key.all != 0) {
123-
if(!Get_NewFlag(flag)) {
119+
if (override.key.all != 0) {
120+
if (!Get_NewFlag(flag)) {
124121
return override;
125122
}
126123
}
@@ -133,30 +130,21 @@ void Actor_StoreChestType(z64_actor_t* actor, z64_game_t* game) {
133130
uint8_t* pChestType = NULL;
134131
override_t override = { 0 };
135132
xflag_t* flag = &(Actor_GetAdditionalData(actor)->flag);
136-
if(actor->actor_id == OBJ_TSUBO) //Pots
137-
{
133+
if (actor->actor_id == OBJ_TSUBO) { // Pots
138134
override = get_newflag_override(flag);
139135
pChestType = &(((ObjTsubo*)actor)->chest_type);
140-
}
141-
else if(actor->actor_id == EN_TUBO_TRAP) // Flying Pots
142-
{
136+
} else if (actor->actor_id == EN_TUBO_TRAP) { // Flying Pots
143137
override = get_newflag_override(flag);
144138
pChestType = &(((EnTuboTrap*)actor)->chest_type);
145-
}
146-
else if(actor->actor_id == OBJ_KIBAKO2) // Large Crates
147-
{
139+
} else if (actor->actor_id == OBJ_KIBAKO2) { // Large Crates
148140
override = get_newflag_override(flag);
149141
pChestType = &(((ObjKibako2*)actor)->chest_type);
150-
}
151-
else if(actor->actor_id == OBJ_KIBAKO) // Small wooden crates
152-
{
142+
} else if (actor->actor_id == OBJ_KIBAKO) { // Small wooden crates
153143
override = get_newflag_override(flag);
154144
pChestType = &(((ObjKibako*)actor)->chest_type);
155-
}
156-
else if(actor->actor_id == OBJ_COMB)
157-
{
145+
} else if (actor->actor_id == OBJ_COMB) {
158146
override = get_newflag_override(flag);
159-
pChestType = &(((ObjComb *)actor)->chest_type);
147+
pChestType = &(((ObjComb*)actor)->chest_type);
160148
}
161149
if (override.key.all != 0 && pChestType != NULL) { // If we don't have an override key, then either this item doesn't have an override entry, or it has already been collected.
162150
if (POTCRATE_TEXTURES_MATCH_CONTENTS == PTMC_UNCHECKED && override.key.all > 0) { // For "unchecked" PTMC setting: Check if we have an override which means it wasn't collected.
@@ -206,11 +194,11 @@ bool spawn_override_silver_rupee(ActorEntry* actorEntry, z64_game_t* globalCtx,
206194
*overridden = false;
207195
if (SHUFFLE_SILVER_RUPEES) { // Check if silver rupee shuffle is enabled.
208196
xflag_t flag = {
209-
.scene = globalCtx->scene_index,
210-
.setup = curr_scene_setup,
211-
.room = globalCtx->room_index,
212-
.flag = CURR_ACTOR_SPAWN_INDEX,
213-
.subflag = 0
197+
.scene = globalCtx->scene_index,
198+
.setup = curr_scene_setup,
199+
.room = globalCtx->room_index,
200+
.flag = CURR_ACTOR_SPAWN_INDEX,
201+
.subflag = 0,
214202
};
215203

216204
flag = resolve_alternative_flag(&flag);
@@ -253,10 +241,9 @@ z64_actor_t* Player_SpawnEntry_Hack(void* actorCtx, ActorEntry* playerEntry, z64
253241
}
254242

255243
// This is our entrypoint back into Actor_Spawn. Call/return this to spawn the actor
256-
extern z64_actor_t *Actor_Spawn_Continue(void* actorCtx, z64_game_t* globalCtx, int16_t actorId, float posX, float posY, float posZ, int16_t rotX, int16_t rotY, int16_t rotZ, int16_t params);
244+
extern z64_actor_t* Actor_Spawn_Continue(void* actorCtx, z64_game_t* globalCtx, int16_t actorId, float posX, float posY, float posZ, int16_t rotX, int16_t rotY, int16_t rotZ, int16_t params);
257245

258-
z64_actor_t * Actor_Spawn_Hook(void* actorCtx, z64_game_t* globalCtx, int16_t actorId,
259-
float posX, float posY, float posZ, int16_t rotX, int16_t rotY, int16_t rotZ, int16_t params) {
246+
z64_actor_t* Actor_Spawn_Hook(void* actorCtx, z64_game_t* globalCtx, int16_t actorId, float posX, float posY, float posZ, int16_t rotX, int16_t rotY, int16_t rotZ, int16_t params) {
260247
bool continue_spawn = true;
261248

262249
ActorEntry entry;
@@ -269,11 +256,10 @@ z64_actor_t * Actor_Spawn_Hook(void* actorCtx, z64_game_t* globalCtx, int16_t ac
269256
entry.rot.y = rotY;
270257
entry.rot.z = rotZ;
271258

272-
if(continue_spawn) {
259+
if (continue_spawn) {
273260
z64_actor_t* spawned = Actor_Spawn_Continue(actorCtx, globalCtx, actorId, posX, posY, posZ, rotX, rotY, rotZ, params);
274-
if(spawned) {
275-
if(spawn_actor_with_flag)
276-
{
261+
if (spawned) {
262+
if (spawn_actor_with_flag) {
277263
Actor_StoreFlag(spawned, globalCtx, *spawn_actor_with_flag);
278264
Actor_StoreChestType(spawned, globalCtx);
279265
}

ASM/c/actor.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ typedef struct {
1212
/* 0x02 */ xflag_t flag;
1313
} ActorAdditionalData;
1414

15-
void Actor_After_UpdateAll_Hack(z64_actor_t *actor, z64_game_t *game);
16-
void Actor_StoreFlagByIndex(z64_actor_t *actor, z64_game_t* game, uint16_t actor_index);
17-
void Actor_StoreFlag(z64_actor_t *actor, z64_game_t* game, xflag_t flag);
18-
void Actor_StoreChestType(z64_actor_t *actor, z64_game_t *game);
19-
z64_actor_t *Actor_SpawnEntry_Hack(void *actorCtx, ActorEntry *actorEntry, z64_game_t *globalCtx);
20-
bool spawn_override_silver_rupee(ActorEntry *actorEntry, z64_game_t *globalCtx, bool* overridden);
15+
void Actor_After_UpdateAll_Hack(z64_actor_t* actor, z64_game_t* game);
16+
void Actor_StoreFlagByIndex(z64_actor_t* actor, z64_game_t* game, uint16_t actor_index);
17+
void Actor_StoreFlag(z64_actor_t* actor, z64_game_t* game, xflag_t flag);
18+
void Actor_StoreChestType(z64_actor_t* actor, z64_game_t *game);
19+
z64_actor_t *Actor_SpawnEntry_Hack(void* actorCtx, ActorEntry* actorEntry, z64_game_t* globalCtx);
20+
bool spawn_override_silver_rupee(ActorEntry* actorEntry, z64_game_t* globalCtx, bool* overridden);
2121
void after_spawn_override_silver_rupee(z64_actor_t* actor, bool overridden);
2222
void Actor_BuildFlag(z64_actor_t* actor, xflag_t* flag, uint16_t actor_index, uint8_t subflag);
2323
ActorAdditionalData* Actor_GetAdditionalData(z64_actor_t* actor);

ASM/c/en_item00.c

+9-15
Original file line numberDiff line numberDiff line change
@@ -47,45 +47,39 @@ bool EnItem00_ProximityCheck_Hack(EnItem00* this, z64_game_t* GlobalCtx) {
4747
extern void EnItem00_Init(EnItem00* this, z64_game_t* globalCtx);
4848
extern void en_item00_update(EnItem00* this, z64_game_t* globalCtx);
4949

50-
5150
void EnItem00_Init_Hook(EnItem00* this, z64_game_t* globalCtx) {
5251
EnItem00_Init(this, globalCtx);
5352
// Reset the scale for overridden collectibles
54-
if(this->override.key.all) {
53+
if (this->override.key.all) {
5554
this->scale = this->actor.scale.x = this->actor.scale.y = this->actor.scale.z = 0.015f;
5655
this->actor.yOffset = 750.0f;
5756
}
5857
}
5958

60-
61-
void en_item00_update_hook(EnItem00* this, z64_game_t* globalCtx)
62-
{
59+
void en_item00_update_hook(EnItem00* this, z64_game_t* globalCtx) {
6360
xflag_t* flag = &(Actor_GetAdditionalData(&this->actor)->flag);
64-
if (this->override.key.type != OVR_DELAYED && Get_NewFlag(flag) && !((collectible_mutex == this) || this->actor.dropFlag == 1))
65-
{
61+
if (this->override.key.type != OVR_DELAYED && Get_NewFlag(flag) && !((collectible_mutex == this) || this->actor.dropFlag == 1)) {
6662
this->override = (override_t) { 0 };
6763
}
68-
if(this->override.key.all && this->actionFunc != Collectible_WaitForMessageBox)
69-
{
64+
if (this->override.key.all && this->actionFunc != Collectible_WaitForMessageBox) {
7065
lookup_model_by_override(&this->model, this->override);
7166
}
7267
en_item00_update(this, globalCtx);
7368
}
7469

7570
void EnItem00_Draw_Hook(z64_actor_t* actor, z64_game_t* globalCtx) {
76-
EnItem00 *this = (EnItem00 *)actor;
71+
EnItem00* this = (EnItem00*)actor;
7772
model_t model = {
7873
.object_id = 0x0000,
7974
.graphic_id = 0x00,
8075
};
8176

82-
if(this->override.key.all) {
77+
if (this->override.key.all) {
8378
model = this->model;
84-
if(model.object_id != 0x0000) {
79+
if (model.object_id != 0x0000) {
8580
draw_model(model, actor, globalCtx, 25.0);
8681
}
87-
}
88-
else {
89-
EnItem00_Draw(&(this->actor),globalCtx);
82+
} else {
83+
EnItem00_Draw(&(this->actor), globalCtx);
9084
}
9185
}

ASM/c/en_item00.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
struct EnItem00;
99

10-
typedef void (*EnItem00ActionFunc)(struct EnItem00 *, z64_game_t *);
10+
typedef void (*EnItem00ActionFunc)(struct EnItem00*, z64_game_t*);
1111
typedef struct EnItem00 {
1212
z64_actor_t actor; // 0x0000
1313
EnItem00ActionFunc actionFunc; // 0x013C
@@ -20,15 +20,15 @@ typedef struct EnItem00 {
2020
float scale; // 0x014C
2121
ColliderCylinder collider; // 0x0150 size = 4C
2222
override_t override; // 0x019C
23-
bool is_silver_rupee; // 0x????
23+
bool is_silver_rupee; // 0x????
2424
bool dropped;
2525
model_t model;
2626
} EnItem00;
2727

2828
void EnItem00_OutgoingAction(EnItem00* this, z64_game_t* globalCtx);
2929

30-
typedef void (*z64_EnItem00ActionFunc)(struct EnItem00 *, z64_game_t *);
31-
typedef EnItem00 *(*z64_Item_DropCollectible_proc)(z64_game_t *globalCtx, z64_xyzf_t *spawnPos, int16_t params);
32-
typedef EnItem00 *(*z64_Item_DropCollectibleRandom_proc)(z64_game_t *globalCtx, z64_actor_t *fromActor, z64_xyzf_t *spawnPos, int16_t params);
30+
typedef void (*z64_EnItem00ActionFunc)(struct EnItem00*, z64_game_t*);
31+
typedef EnItem00*(*z64_Item_DropCollectible_proc)(z64_game_t* globalCtx, z64_xyzf_t* spawnPos, int16_t params);
32+
typedef EnItem00*(*z64_Item_DropCollectibleRandom_proc)(z64_game_t* globalCtx, z64_actor_t* fromActor, z64_xyzf_t* spawnPos, int16_t params);
3333

3434
#endif

ASM/c/en_wonderitem.c

+29-37
Original file line numberDiff line numberDiff line change
@@ -19,42 +19,33 @@ static z64_xyzf_t sEffectAccel = { 0.0f, 0.5f, 0.0f };
1919

2020
extern uint16_t CURR_ACTOR_SPAWN_INDEX;
2121

22-
void EnWonderitem_AfterInitHack(z64_actor_t* this, z64_game_t* globalCtx)
23-
{
24-
if(this->main_proc == NULL)
25-
return;
26-
if(this->actor_id != 0x112)
27-
return;
22+
void EnWonderitem_AfterInitHack(z64_actor_t* this, z64_game_t* globalCtx) {
23+
if (this->main_proc == NULL) return;
24+
if (this->actor_id != 0x112) return;
2825

2926
EnWonderItem* wonderitem = (EnWonderItem*)this;
3027
wonderitem->overridden = 0;
3128

3229
xflag_t flag = Actor_GetAdditionalData(this)->flag;
3330

3431
// Check if the Wonderitem should be overridden
35-
if(flag.all && !Get_NewFlag(&flag))
36-
{
32+
if (flag.all && !Get_NewFlag(&flag)) {
3733
wonderitem->overridden = 1;
3834
}
3935
}
4036

41-
void EnWonderItem_Multitag_DrawHack(z64_xyzf_t* tags, uint32_t index, EnWonderItem* this)
42-
{
43-
if(this->overridden)
44-
{
37+
void EnWonderItem_Multitag_DrawHack(z64_xyzf_t* tags, uint32_t index, EnWonderItem* this) {
38+
if (this->overridden) {
4539
colorRGBA8_t* color = &sEffectPrimColorBlue;
46-
if(this->wonderMode == WONDERITEM_MULTITAG_ORDERED)
40+
if (this->wonderMode == WONDERITEM_MULTITAG_ORDERED) {
4741
color = &sEffectPrimColorCyan;
42+
}
4843
z64_xyzf_t pos = tags[index];
49-
// if(this->wonderMode != WONDERITEM_INTERACT_SWITCH)
50-
// pos.y += 20.0;
51-
z64_EffectSsKiraKira_SpawnSmall(&z64_game, &pos, &sEffectVelocity, &sEffectAccel, color, &sEffectEnvColor );
44+
z64_EffectSsKiraKira_SpawnSmall(&z64_game, &pos, &sEffectVelocity, &sEffectAccel, color, &sEffectEnvColor);
5245
}
53-
5446
}
5547

56-
void EnWonderItem_DropCollectible_Hack(EnWonderItem* this, z64_game_t* globalCtx, int32_t autoCollect)
57-
{
48+
void EnWonderItem_DropCollectible_Hack(EnWonderItem* this, z64_game_t* globalCtx, int32_t autoCollect) {
5849
static int16_t dropTable[] = {
5950
ITEM00_NUTS, ITEM00_HEART_PIECE, ITEM00_MAGIC_LARGE, ITEM00_MAGIC_SMALL,
6051
ITEM00_HEART, ITEM00_ARROWS_SMALL, ITEM00_ARROWS_MEDIUM, ITEM00_ARROWS_LARGE,
@@ -67,17 +58,18 @@ void EnWonderItem_DropCollectible_Hack(EnWonderItem* this, z64_game_t* globalCtx
6758
z64_PlaySFXID(NA_SE_SY_GET_ITEM);
6859

6960
// Override behavior. Spawn an overridden collectible on link
70-
if(this->overridden)
71-
{
61+
if (this->overridden) {
7262
xflag_t* flag = &(Actor_GetAdditionalData(&this->actor)->flag);
7363
drop_collectible_override_flag = *flag;
74-
if(autoCollect)
64+
if(autoCollect) {
7565
z64_Item_DropCollectible2(globalCtx, &(z64_link.common.pos_world), 0);
76-
else
66+
} else {
7767
z64_Item_DropCollectible(globalCtx, &this->actor.pos_world, 0);
68+
}
7869
z64_bzero(&drop_collectible_override_flag, sizeof(drop_collectible_override_flag));
79-
if (this->switchFlag >= 0)
70+
if (this->switchFlag >= 0) {
8071
z64_Flags_SetSwitch(globalCtx, this->switchFlag);
72+
}
8173
z64_ActorKill(&this->actor);
8274
return;
8375
}
@@ -110,29 +102,31 @@ void EnWonderItem_DropCollectible_Hack(EnWonderItem* this, z64_game_t* globalCtx
110102

111103
void EnWonderItem_Update_Hack(EnWonderItem* this) {
112104
colorRGBA8_t* color = NULL;
113-
if(this->overridden) {
114-
switch(this->wonderMode){
115-
case(WONDERITEM_PROXIMITY_DROP): {
105+
if (this->overridden) {
106+
switch (this->wonderMode) {
107+
case WONDERITEM_PROXIMITY_DROP:
108+
{
116109
color = &sEffectPrimColorYellow;
117110
break;
118111
}
119-
case(WONDERITEM_INTERACT_SWITCH):
120-
case(WONDERITEM_BOMB_SOLDIER): {
112+
case WONDERITEM_INTERACT_SWITCH:
113+
case WONDERITEM_BOMB_SOLDIER:
114+
{
121115
color = &sEffectPrimColorRed;
122116
break;
123117
}
124-
default:
118+
default: {
125119
break;
120+
}
126121
}
127-
if(color) {
128-
z64_EffectSsKiraKira_SpawnSmall(&z64_game, &(this->actor.pos_world), &sEffectVelocity, &sEffectAccel, color, &sEffectEnvColor );
122+
if (color) {
123+
z64_EffectSsKiraKira_SpawnSmall(&z64_game, &(this->actor.pos_world), &sEffectVelocity, &sEffectAccel, color, &sEffectEnvColor);
129124
}
130125
}
131126
}
132127

133128
// Hack to not kill wonderitem when switch flag is set if we need to override still
134129
uint32_t EnWonderItem_Kill_Hack(EnWonderItem* this) {
135-
136130
xflag_t flag = { 0 };
137131
flag.flag = CURR_ACTOR_SPAWN_INDEX;
138132
flag.scene = z64_game.scene_index;
@@ -142,9 +136,7 @@ uint32_t EnWonderItem_Kill_Hack(EnWonderItem* this) {
142136
// Check if the Wonderitem should be overridden
143137
override_t override = lookup_override_by_newflag(&flag);
144138

145-
if(override.key.all != 0 && !Get_NewFlag(&flag))
146-
return 0;
147-
if ((this->switchFlag >= 0) && z64_Flags_GetSwitch(&z64_game, this->switchFlag))
148-
return 1;
139+
if (override.key.all != 0 && !Get_NewFlag(&flag)) return 0;
140+
if ((this->switchFlag >= 0) && z64_Flags_GetSwitch(&z64_game, this->switchFlag)) return 1;
149141
return 0;
150142
}

0 commit comments

Comments
 (0)