Skip to content

Commit acedee0

Browse files
authored
zNPCSpawner WIP (#407)
* Add template function xUtil_select to xutil.h. * Filled in zNPCCommon struct with information from m2c decompiler. * Edited pendlist and actvlist types to pointers. * Modified existing functions to smooth additions. * Added partial matches for FillPending, ReFillPending, NextPendingNPC, and StatforNPC. Also have outline for ClearActive in comments. * zNPCCommon definition removed, now included from zNPCTypeCommon. Moved en_SM_NOTICES to zNPCTypeCommon to avoid recursive include. * zNPCTypeDuplotron now pulls zNPCSpawner definition directly from zNPCSpawner instead of transitively via zNPCTypeCommon. * Quick patches to data types after using more detailed definition of zNPCCommon. * Revert pendlist and actvllist to not being pointers. * Implemented suggested fixes to NextPendingNPC. * Used Clang to format.
1 parent 1f89e8f commit acedee0

File tree

5 files changed

+116
-18
lines changed

5 files changed

+116
-18
lines changed

src/SB/Core/x/xutil.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@ U32 xUtil_crc_update(U32 crc_accum, char* data, S32 datasize);
1111
S32 xUtil_yesno(F32 wt_yes);
1212
void xUtil_wtadjust(F32* wts, S32 cnt, F32 arbref);
1313

14+
template <typename T>
15+
T* xUtil_select(T** arg0, S32 arg1, const F32* arg3);
16+
1417
#endif

src/SB/Game/zNPCSpawner.cpp

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,95 @@ U8 zMovePoint::IsOn()
177177
{
178178
return this->on;
179179
}
180+
181+
st_XORDEREDARRAY* zNPCSpawner::FillPending()
182+
{
183+
ClearPending();
184+
ReFillPending();
185+
return &this->actvlist;
186+
}
187+
188+
st_XORDEREDARRAY* zNPCSpawner::ReFillPending()
189+
{
190+
s32 var_r28;
191+
zNPCCommon* temp_r29;
192+
zNPCSpawner* var_r30;
193+
194+
var_r28 = 0;
195+
var_r30 = this;
196+
do
197+
{
198+
temp_r29 = var_r30->npc_owner;
199+
if (((zNPCCommon*)var_r30->npc_owner != NULL) && ((s32)temp_r29->flg_vuln == 1))
200+
{
201+
XOrdAppend(&this->pendlist, (void*)temp_r29);
202+
temp_r29->flg_vuln = 2;
203+
}
204+
var_r28 += 1;
205+
var_r30 += 0xC;
206+
} while (var_r28 < 0x10);
207+
return &this->actvlist;
208+
}
209+
210+
// void zNPCSpawner::ClearActive()
211+
// {
212+
// s32 var_r6;
213+
// s32 var_r7;
214+
// void *temp_r5;
215+
216+
// var_r7 = 0;
217+
// var_r6 = 0;
218+
// loop_4:
219+
// if (var_r7 < (s32) this->cnt_cleanup) {
220+
// temp_r5 = *(this->pendlist->list + var_r6);
221+
// if (temp_r5 != NULL) {
222+
// (u32) temp_r5[1] = 1;
223+
// }
224+
// var_r6 += 4;
225+
// var_r7 += 1;
226+
// goto loop_4;
227+
// }
228+
// XOrdReset__FP16st_XORDEREDARRAY(&this->unk1B0);
229+
// }
230+
231+
SMNPCStatus* zNPCSpawner::NextPendingNPC(S32 arg0)
232+
{
233+
S32 temp_r4;
234+
const F32* temp_ptr = NULL;
235+
236+
temp_r4 = this->pendlist.cnt;
237+
if (temp_r4 < 1)
238+
{
239+
return NULL;
240+
}
241+
return xUtil_select<SMNPCStatus>((SMNPCStatus**)this->pendlist.list, temp_r4, temp_ptr);
242+
}
243+
244+
/* zNPCSpawner::StatForNPC (zNPCCommon *) */
245+
SMNPCStatus* zNPCSpawner::StatForNPC(zNPCCommon* npc)
246+
{
247+
s32 var_ctr;
248+
SMNPCStatus* var_r6;
249+
zNPCCommon* temp_r0;
250+
zNPCCommon* temp_r0_2;
251+
zNPCCommon* temp_r0_3;
252+
zNPCCommon* temp_r0_4;
253+
zNPCCommon* temp_r0_5;
254+
zNPCCommon* temp_r0_6;
255+
zNPCCommon* temp_r0_7;
256+
zNPCCommon* temp_r0_8;
257+
258+
var_r6 = NULL;
259+
var_ctr = 2;
260+
261+
for (var_ctr = 0; var_ctr < 16; var_ctr++)
262+
{
263+
temp_r0 = this->npcpool[var_ctr].npc;
264+
if ((temp_r0 != NULL) && (temp_r0 == npc))
265+
{
266+
var_r6 = &this->npcpool[var_ctr];
267+
}
268+
}
269+
270+
return var_r6;
271+
}

src/SB/Game/zNPCSpawner.h

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,9 @@
55

66
#include "xRMemData.h"
77
#include "xordarray.h"
8+
#include "xutil.h"
89

9-
enum en_SM_NOTICES
10-
{
11-
SM_NOTE_NPCDIED,
12-
SM_NOTE_NPCSTANDBY,
13-
SM_NOTE_NPCALIVE,
14-
SM_NOTE_DUPPAUSE,
15-
SM_NOTE_DUPRESUME,
16-
SM_NOTE_DUPSETDELAY,
17-
SM_NOTE_DUPDEAD,
18-
SM_NOTE_KILLKIDS,
19-
SM_NOTE_NOMORE,
20-
SM_NOTE_FORCE = 0x7fffffff
21-
};
10+
#include "zNPCTypeCommon.h"
2211

2312
enum en_SM_WAVE_MODE
2413
{
@@ -50,8 +39,6 @@ enum en_SM_NPC_STATUS
5039
SM_NPC_FORCE = 0x7fffffff
5140
};
5241

53-
struct zNPCCommon;
54-
5542
struct SMDepot
5643
{
5744
st_XORDEREDARRAY spawners;
@@ -84,7 +71,7 @@ struct zNPCSpawner : RyzMemData
8471
SMSPStatus sppool[16];
8572
SMNPCStatus npcpool[16];
8673
st_XORDEREDARRAY pendlist;
87-
st_XORDEREDARRAY actvlist;
74+
st_XORDEREDARRAY actvlist; //0x1A4
8875
S32 cnt_cleanup;
8976

9077
void Subscribe(zNPCCommon* owner);
@@ -103,6 +90,9 @@ struct zNPCSpawner : RyzMemData
10390
// NextPendingNPC.
10491
void ClearActive();
10592
void ClearPending();
93+
SMNPCStatus* NextPendingNPC( S32 arg0 );
94+
st_XORDEREDARRAY* FillPending();
95+
st_XORDEREDARRAY* ReFillPending();
10696

10797
void SetNPCStatus(zNPCCommon* npc, en_SM_NPC_STATUS status);
10898

src/SB/Game/zNPCTypeCommon.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "xSFX.h"
1111

1212
#include "zNPCSndTable.h"
13-
#include "zNPCSpawner.h"
1413
#include "zMovePoint.h"
1514
#include "zShrapnel.h"
1615

@@ -340,6 +339,20 @@ enum en_NPC_MSG_DATA
340339
NPC_MDAT_FORCE = 0x7fffffff
341340
};
342341

342+
enum en_SM_NOTICES
343+
{
344+
SM_NOTE_NPCDIED,
345+
SM_NOTE_NPCSTANDBY,
346+
SM_NOTE_NPCALIVE,
347+
SM_NOTE_DUPPAUSE,
348+
SM_NOTE_DUPRESUME,
349+
SM_NOTE_DUPSETDELAY,
350+
SM_NOTE_DUPDEAD,
351+
SM_NOTE_KILLKIDS,
352+
SM_NOTE_NOMORE,
353+
SM_NOTE_FORCE = 0x7fffffff
354+
};
355+
343356
struct zNPCLassoInfo
344357
{
345358
en_LASSO_STATUS stage;

src/SB/Game/zNPCTypeDuplotron.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef ZNPCTYPEDUPLOTRON_H
22
#define ZNPCTYPEDUPLOTRON_H
33

4-
#include "zNPCTypeCommon.h"
4+
#include "zNPCSpawner.h"
55

66
struct zNPCDuplotron : zNPCCommon
77
{

0 commit comments

Comments
 (0)