Skip to content

Commit 55a4de9

Browse files
committed
d_a_nzg ok
1 parent 2e2b706 commit 55a4de9

File tree

2 files changed

+110
-71
lines changed

2 files changed

+110
-71
lines changed

include/d/actor/d_a_nzg.h

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
11
#ifndef D_A_NZG_H
22
#define D_A_NZG_H
33

4-
#include "d/d_path.h"
54
#include "f_op/f_op_actor.h"
65
#include "d/d_cc_d.h"
76

8-
class nzg_class : public fopAc_ac_c {
7+
struct dPath;
8+
9+
class nzg_class : public fopEn_enemy_c {
910
public:
10-
/* Place member variables here */
11-
/* 0x290 */ u8 pad1[28];
12-
/* 0x2AC */ request_of_phase_process_class m2AC;
13-
/* 0x2B4 */ J3DModel* m2B4;
14-
u8 m2B8;
15-
u8 m2B9;
16-
u8 m2BA;
17-
u8 m2BB;
18-
u8 mPad2[2];
19-
s16 m2BE;
20-
s16 m2C0;
21-
s16 m2C2[5];
22-
f32 m2CC;
23-
f32 m2D0;
24-
u32 m2D4;
25-
dPath *m2D8;
26-
u8 mPad4[13];
27-
u8 m2E9;
28-
dCcD_Stts mStts;
29-
dCcD_Cyl m328;
11+
/* 0x2AC */ request_of_phase_process_class mPhs;
12+
/* 0x2B4 */ J3DModel* mpModel;
13+
/* 0x2B8 */ u8 m2B8;
14+
/* 0x2B9 */ u8 m2B9;
15+
/* 0x2BA */ u8 m2BA;
16+
/* 0x2BB */ u8 m2BB;
17+
/* 0x2BC */ u8 m2BC[0x2BE - 0x2BC];
18+
/* 0x2BE */ s16 m2BE;
19+
/* 0x2C0 */ s16 m2C0;
20+
/* 0x2C2 */ s16 m2C2[5];
21+
/* 0x2CC */ f32 m2CC;
22+
/* 0x2D0 */ f32 m2D0;
23+
/* 0x2D4 */ fpc_ProcID m2D4;
24+
/* 0x2D8 */ dPath* mpPath;
25+
/* 0x2DC */ u8 m2DC[0x2E9 - 0x2DC];
26+
/* 0x2E9 */ u8 m2E9;
27+
/* 0x2EC */ dCcD_Stts mStts;
28+
/* 0x328 */ dCcD_Cyl mCyl;
3029
};
3130

3231
#endif /* D_A_NZG_H */

src/d/actor/d_a_nzg.cpp

Lines changed: 89 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
//
2-
// Generated by dtk
3-
// Translation Unit: d_a_nzg.cpp
4-
//
1+
/**
2+
* d_a_nzg.cpp
3+
* Enemy - Rat Group
4+
*/
55

66
#include "d/dolzel_rel.h" // IWYU pragma: keep
77
#include "d/actor/d_a_nzg.h"
88
#include "d/d_path.h"
99
#include "d/d_procname.h"
1010
#include "d/d_priority.h"
11-
#include "d/d_cc_d.h"
1211
#include "d/d_s_play.h"
12+
#include "d/res/res_nzg.h"
1313

1414
/* 00000078-000000E4 .text daNZG_Draw__FP9nzg_class */
1515
static BOOL daNZG_Draw(nzg_class* i_this) {
16-
J3DModel* model = i_this->m2B4;
16+
J3DModel* model = i_this->mpModel;
1717
g_env_light.settingTevStruct(TEV_TYPE_ACTOR, &i_this->current.pos, &i_this->tevStr);
1818
g_env_light.setLightTevColorType(model, &i_this->tevStr);
1919
mDoExt_modelUpdateDL(model);
@@ -22,49 +22,82 @@ static BOOL daNZG_Draw(nzg_class* i_this) {
2222

2323
/* 000000E4-00000348 .text nzg_00_move__FP9nzg_class */
2424
void nzg_00_move(nzg_class* i_this) {
25-
/* Nonmatching */
26-
if (i_this->m2C2[0] != 0) {
25+
/* Nonmatching for Demo */
26+
//fixes regswap issue in demo for the most part but introduces a misplaced instruction error
27+
nzg_class* actor = i_this;
28+
29+
if (i_this->m2C2[0] != 0 || i_this->m2BE >= i_this->m2C0) {
2730
return;
2831
}
29-
if (i_this->m2BE < i_this->m2C0) {
30-
return;
32+
33+
actor->mCyl.SetC(actor->current.pos);
34+
actor->mCyl.SetH(REG8_F(11) + 40.0f);
35+
actor->mCyl.SetR(REG8_F(12) + 40.0f);
36+
dComIfG_Ccsp()->Set(&actor->mCyl);
37+
38+
if (actor->mCyl.ChkCoHit()) {
39+
fopAc_ac_c* hit_actor = actor->mCyl.GetCoHitAc();
40+
if (hit_actor != NULL) {
41+
s16 hitAC_name = fopAcM_GetName(hit_actor);
42+
if (hitAC_name != PROC_NZ && hitAC_name != PROC_BOMB && hitAC_name != PROC_Bomb2 && hitAC_name != PROC_ITEM && hitAC_name != PROC_ESA) {
43+
actor->m2D4 = fopAcM_GetID(hit_actor);
44+
actor->m2BB = 1;
45+
return;
46+
}
47+
}
48+
}
49+
50+
u32 parameters = fopAcM_GetParam(actor) & 0xFF000000;
51+
52+
if (actor->m2BA == 1) {
53+
parameters |= 0x100;
54+
} else if (actor->m2BA == 2 && cM_rnd() < 0.5f) {
55+
parameters |= 0x100;
3156
}
3257

33-
i_this->m328.SetC(i_this->current.pos);
34-
i_this->m328.SetH(REG8_F(11) + 40.0f);
35-
i_this->m328.SetR(REG8_F(12) + 40.0f);
36-
dComIfG_Ccsp()->Set(&i_this->m328);
37-
i_this->m328.ChkCoHit();
58+
if (parameters & 0x100 || fopAcM_searchActorDistance(actor, dComIfGp_getPlayer(0)) < actor->m2CC * 0.5f) {
59+
if (fopAcM_searchActorDistance(actor, dComIfGp_getPlayer(0)) > actor->m2D0 * 0.5f) {
60+
parameters |= 1;
61+
csXyz child_angle = actor->current.angle;
62+
63+
child_angle.y += cM_rndFX(8192.0f);
64+
fpc_ProcID childProcID = fopAcM_createChild(PROC_NZ, fopAcM_GetID(actor), parameters, &actor->current.pos, fopAcM_GetRoomNo(actor), &child_angle, &actor->scale, NULL);
65+
66+
if (childProcID != fpcM_ERROR_PROCESS_ID_e) {
67+
actor->m2C2[0] = (childProcID & 3) * 10 + 20;
68+
actor->m2BE++;
69+
}
70+
}
71+
}
3872
}
3973

4074
/* 00000348-00000450 .text nzg_01_move__FP9nzg_class */
4175
void nzg_01_move(nzg_class* i_this) {
42-
if (i_this->m2D4 != 0xffffffff) {
43-
u32 spC = i_this->m2D4;
44-
nzg_class* judgeVal = (nzg_class*)fopAcIt_Judge(fpcSch_JudgeByID, &spC);
45-
if (judgeVal != NULL) {
46-
f32 fVar1 = i_this->current.pos.x - judgeVal->current.pos.x;
47-
f32 fVar2 = i_this->current.pos.z - judgeVal->current.pos.z;
48-
fVar1 = (fVar1 * fVar1) + (fVar2 * fVar2);
49-
50-
if (std::sqrtf(fVar1) < 80.0f) {
76+
if (i_this->m2D4 != fpcM_ERROR_PROCESS_ID_e) {
77+
fopAc_ac_c* ac_id = fopAcM_SearchByID(i_this->m2D4);
78+
if (ac_id != NULL) {
79+
f32 pos_x_diff = i_this->current.pos.x - ac_id->current.pos.x;
80+
f32 pos_z_diff = i_this->current.pos.z - ac_id->current.pos.z;
81+
pos_x_diff = (pos_x_diff * pos_x_diff) + (pos_z_diff * pos_z_diff);
82+
83+
if (std::sqrtf(pos_x_diff) < 80.0f) {
5184
return;
5285
}
5386
}
5487
}
55-
i_this->m2D4 = 0xffffffff;
88+
i_this->m2D4 = fpcM_ERROR_PROCESS_ID_e;
5689
i_this->m2BB = 0;
5790
}
5891

5992
/* 00000450-000004D0 .text daNZG_Execute__FP9nzg_class */
6093
static BOOL daNZG_Execute(nzg_class* i_this) {
6194
i_this->m2D0 = 400.0f;
62-
int i = 0;
63-
for (int j = 4; j != 0; j--) {
64-
if (i_this->m2C2[i] != 0) {
65-
i_this->m2C2[i]--;
95+
s32 j = 0;
96+
for (s32 i = 4; i != 0; i--) {
97+
if (i_this->m2C2[j] != 0) {
98+
i_this->m2C2[j]--;
6699
}
67-
i += 1;
100+
j += 1;
68101
}
69102
switch (i_this->m2BB) {
70103
case 0:
@@ -84,36 +117,38 @@ static BOOL daNZG_IsDelete(nzg_class*) {
84117

85118
/* 000004D8-00000508 .text daNZG_Delete__FP9nzg_class */
86119
static BOOL daNZG_Delete(nzg_class* i_this) {
87-
dComIfG_resDelete(&i_this->m2AC, "NZG");
120+
#if VERSION == VERSION_DEMO
121+
g_dComIfG_gameInfo.mResControl.deleteObjectRes("NZG");
122+
#else
123+
dComIfG_resDelete(&i_this->mPhs, "NZG");
124+
#endif
88125
return TRUE;
89126
}
90127

91128
/* 00000508-00000620 .text useHeapInit__FP10fopAc_ac_c */
92129
static BOOL useHeapInit(fopAc_ac_c* i_this) {
93-
/* Nonmatching */
94130
nzg_class* nzg_this = (nzg_class*)i_this;
95131

96-
mDoMtx_trans(mDoMtx_stack_c::get(), nzg_this->current.pos.x, nzg_this->current.pos.y, nzg_this->current.pos.z);
97-
mDoMtx_YrotM(mDoMtx_stack_c::get(), nzg_this->shape_angle.y);
132+
mDoMtx_stack_c::transS(nzg_this->current.pos.x, nzg_this->current.pos.y, nzg_this->current.pos.z);
133+
mDoMtx_stack_c::YrotM(nzg_this->shape_angle.y);
98134

99-
J3DModelData* modelData = (J3DModelData*)dRes_control_c::getRes("NZG", 3, g_dComIfG_gameInfo.mResControl.mObjectInfo, 0x40);
100-
JUT_ASSERT(DEMO_SELECT(630, 630), modelData != NULL);
135+
J3DModelData* modelData = (J3DModelData*)dComIfG_getObjectRes("NZG", NZG_BDL_KANA_00);
136+
JUT_ASSERT(630, modelData != NULL);
101137
J3DModel* model = mDoExt_J3DModel__create(modelData, 0,0x11020203);
102138

103139
if (model == NULL) {
104140
return FALSE;
105141
}
106142

107-
nzg_this->m2B4 = model;
143+
nzg_this->mpModel = model;
108144
model->setBaseScale(nzg_this->scale);
109-
mDoMtx_copy(mDoMtx_stack_c::get(), model->getBaseTRMtx());
110-
nzg_this->cullMtx = model->getBaseTRMtx();
145+
model->setBaseTRMtx(mDoMtx_stack_c::get());
146+
fopAcM_SetMtx(nzg_this, model->getBaseTRMtx());
111147
return TRUE;
112148
}
113149

114150
/* 00000620-00000864 .text daNZG_Create__FP10fopAc_ac_c */
115151
static cPhs_State daNZG_Create(fopAc_ac_c* i_this) {
116-
/* Nonmatching */
117152
static dCcD_SrcCyl body_cyl_src = {
118153
// dCcD_SrcGObjInf
119154
{
@@ -143,11 +178,17 @@ static cPhs_State daNZG_Create(fopAc_ac_c* i_this) {
143178
/* Height */ 20.0f,
144179
}},
145180
};
146-
147-
fopAcM_SetupActor(i_this, nzg_class);
181+
#if VERSION == VERSION_DEMO
182+
nzg_class* nzg_this = (nzg_class*)i_this;
183+
cPhs_State phase_state = dComIfG_resLoad(&nzg_this->mPhs, "NZG");
184+
if (phase_state == cPhs_COMPLEATE_e) {
185+
fopAcM_SetupActor(nzg_this, nzg_class);
186+
#else
148187
nzg_class* nzg_this = (nzg_class*)i_this;
149-
cPhs_State phase_state = dComIfG_resLoad(&nzg_this->m2AC, "NZG");
188+
fopAcM_SetupActor(nzg_this, nzg_class);
189+
cPhs_State phase_state = dComIfG_resLoad(&nzg_this->mPhs, "NZG");
150190
if (phase_state == cPhs_COMPLEATE_e) {
191+
#endif
151192
if (!fopAcM_entrySolidHeap(nzg_this, useHeapInit, 0x680)) {
152193
return cPhs_ERROR_e;
153194
}
@@ -156,7 +197,7 @@ static cPhs_State daNZG_Create(fopAc_ac_c* i_this) {
156197
nzg_this->m2BA = fopAcM_GetParam(nzg_this) >> 16;
157198
nzg_this->m2E9 = fopAcM_GetParam(nzg_this) >> 24;
158199
if (nzg_this->m2E9 != 0xFF) {
159-
nzg_this->m2D8 = dPath_GetRoomPath(nzg_this->m2E9, fopAcM_GetRoomNo(nzg_this));
200+
nzg_this->mpPath = dPath_GetRoomPath(nzg_this->m2E9, fopAcM_GetRoomNo(nzg_this));
160201
}
161202
nzg_this->shape_angle.y = nzg_this->current.angle.y;
162203
nzg_this->m2CC = nzg_this->m2B8 * 10.0f;
@@ -168,12 +209,11 @@ static cPhs_State daNZG_Create(fopAc_ac_c* i_this) {
168209
if (nzg_this->m2BA > 2) {
169210
nzg_this->m2BA = 0;
170211
}
171-
nzg_this->m328.Set(body_cyl_src);
172-
nzg_this->m328.SetStts(&nzg_this->mStts);
212+
nzg_this->mCyl.Set(body_cyl_src);
213+
nzg_this->mCyl.SetStts(&nzg_this->mStts);
173214
if (nzg_this->m2BA == 0) {
174-
csXyz local_18;
175-
local_18.set(nzg_this->current.angle.x, 0, nzg_this->current.angle.z);
176-
fopAcM_createChild("NpcNz",fpcM_GetID(nzg_this), 0xffffffff, &nzg_this->current.pos, fopAcM_GetRoomNo(nzg_this), &local_18, &nzg_this->scale, NULL);
215+
csXyz child_angle = nzg_this->current.angle;
216+
fopAcM_createChild("NpcNz",fpcM_GetID(nzg_this), 0xffffffff, &nzg_this->current.pos, fopAcM_GetRoomNo(nzg_this), &child_angle, &nzg_this->scale, NULL);
177217
}
178218
}
179219
return phase_state;

0 commit comments

Comments
 (0)