Skip to content

Commit 48a8b56

Browse files
committed
Continue TyHealth.cpp
Work on Ty.cpp and TyHealth.cpp
1 parent 8edee0d commit 48a8b56

6 files changed

Lines changed: 236 additions & 12 deletions

File tree

include/ty/StructList.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define STRUCTLIST_H
33

44
#include "types.h"
5+
#include "common/Heap.h"
56

67
/// @brief A fixed-capacity, reverse-fill list structure
78
/// @tparam T Type of elements stored in the list

include/ty/Ty.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ struct HeadTurningInfo {
4545

4646
enum KnockBackType {
4747
KB_TYPE_0 = 0,
48-
};
49-
50-
enum TyHeads {
51-
48+
KB_TYPE_2 = 2,
5249
};
5350

5451
// Ty movement state: Air, Water, Land, UnderWater
@@ -463,6 +460,11 @@ struct DustTrail {
463460
char padding[0x18];
464461
};
465462

463+
enum TyHeads {
464+
TY_HEAD_0 = 0,
465+
TY_HEAD_1 = 1
466+
};
467+
466468
struct Ty : Hero {
467469

468470
int unk320;
@@ -794,6 +796,8 @@ struct Ty : Hero {
794796
void AddShadowLight(Vector*, float);
795797
void SetAbsolutePosition(Vector*, int, float, bool);
796798
void SetBounceOffFromPos(Vector*, float, bool);
799+
800+
void SetKnockBackFromPos(Vector*, float, KnockBackType);
797801
void SetKnockBackFromDir(Vector*, float, KnockBackType);
798802

799803
bool TryChangeState(bool, HeroActorState);
@@ -834,6 +838,8 @@ struct Ty : Hero {
834838
void LandMediumDeinit(void);
835839
//
836840

841+
void ResetDrownTimer(void);
842+
837843
// Rang Management
838844
void InitRangChange(void);
839845
void DeinitRangChange(void);
@@ -849,6 +855,8 @@ struct Ty : Hero {
849855
bool IsAbleToGlide(void);
850856
//
851857

858+
void EnableHead(TyHeads);
859+
852860
void SetFakeFloor(void);
853861
};
854862

include/ty/TyHealth.h

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,47 @@
11
#ifndef TYHEALTH_H
22
#define TYHEALTH_H
33

4+
#include "ty/StructList.h"
5+
#include "common/Blitter.h"
6+
#include "common/Material.h"
47
#include "common/Vector.h"
58

69
enum TyHealthType {
710
HEALTH_TYPE_0 = 0,
811
HEALTH_TYPE_1 = 1,
12+
HEALTH_TYPE_2 = 2,
913
};
1014

1115
enum HurtType {
12-
HURT_TYPE_5 = 5
16+
HURT_TYPE_0 = 0,
17+
HURT_TYPE_1 = 1,
18+
HURT_TYPE_2 = 2,
19+
HURT_TYPE_3 = 3,
20+
HURT_TYPE_4 = 4,
21+
HURT_TYPE_5 = 5,
22+
HURT_TYPE_6 = 6
1323
};
1424

1525
struct HealthInfo {
16-
char padding[0x24];
26+
int unk0;
27+
int unk4;
28+
int unk8;
29+
int unkC;
30+
int unk10;
31+
int unk14;
32+
int unk18;
33+
char* unk1C;
34+
Material* unk20;
1735
};
1836

1937
struct TyHealth {
20-
char padding[0x24];
38+
TyHealthType mType;
39+
int unk4;
40+
StructList<Blitter_Image> bubbleList;
41+
Material* pMaterial;
42+
int unk18;
43+
char unk1C;
44+
float unk20;
2145

2246
void Init(TyHealthType);
2347
void Deinit(void);
@@ -29,7 +53,11 @@ struct TyHealth {
2953
void DrawHudElement(Vector);
3054
void DoLoseFX(void);
3155

32-
static HealthInfo heathInfo[3];
56+
float GetHealthFieldUnk4(void) {
57+
return heathInfo[mType].unk4;
58+
}
59+
60+
static HealthInfo heathInfo[];
3361
};
3462

3563
#endif // TYHEALTH_H

include/ty/soundbank.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ enum SoundID {
163163
SFX_TyLand = 0x4,
164164
SFX_TyLongfallLand = 0x5,
165165

166+
SFX_Ty_0x9 = 0x9,
167+
166168
SFX_TyBiteRelease = 0x13,
167169

168170
SFX_TyRangStdThrow = 0x14,

src/ty/source/Ty.cpp

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ void Ty::Draw(void) {
287287
mFsm.Draw(this);
288288
}
289289

290-
void Ty::StartDeath(HurtType, bool) {
290+
void Ty::StartDeath(HurtType hurtType, bool r5) {
291291
gb.unk7AC = true;
292292
particleManager->StopExclamation(true);
293293

@@ -300,8 +300,61 @@ void Ty::StartDeath(HurtType, bool) {
300300
}
301301
}
302302

303-
void Ty::Hurt(HurtType, DDADamageCause, bool, Vector*, float) {
303+
void VibrateJoystick(float, float, float, char, float);
304304

305+
void Ty::Hurt(HurtType hurtType, DDADamageCause damageCause, bool, Vector* pVec, float f1) {
306+
static int flinch = 0;
307+
308+
if (gb.disableTriggers || gb.infinitePie) {
309+
return;
310+
}
311+
312+
if (invicibilityFrames > 0 || mFsm.GetStateEx() == TY_AS_28 || mFsm.GetStateEx() == TY_AS_29) {
313+
return;
314+
}
315+
316+
EnableHead(TY_HEAD_0);
317+
318+
if (hurtType == HURT_TYPE_1 || hurtType == HURT_TYPE_5) {
319+
VibrateJoystick(0.5f, 1.0f, (f1 / 45.0f) + 0.2f, 0, 4.0f);
320+
}
321+
322+
dda.StoreDamageInfo(damageCause);
323+
324+
if (ty.mMediumMachine.GetUnk0() == TY_MEDIUM_3 && mFsm.GetStateEx() != TY_AS_25) {
325+
for (int i = 0; i < 31; i++) {
326+
327+
}
328+
329+
SoundBank_Play(0x9, NULL, ID_NONE);
330+
}
331+
332+
if (tyHealth.Hurt(hurtType)) {
333+
switch (hurtType) {
334+
case HURT_TYPE_0:
335+
case HURT_TYPE_3:
336+
case HURT_TYPE_6:
337+
flinch = (flinch + 1) % 3;
338+
if (unk4EC.Condition()) {
339+
unk4EC.SetAnim(NULL);
340+
}
341+
break;
342+
case HURT_TYPE_2:
343+
SetKnockBackFromPos(&pos, f1, KB_TYPE_2);
344+
break;
345+
case HURT_TYPE_1:
346+
case HURT_TYPE_4:
347+
SetKnockBackFromPos(pVec, f1, KB_TYPE_0);
348+
break;
349+
case HURT_TYPE_5:
350+
SetKnockBackFromDir(pVec, f1, KB_TYPE_0);
351+
break;
352+
}
353+
354+
invicibilityFrames = 240; // 240 frames
355+
} else {
356+
StartDeath(hurtType, false);
357+
}
305358
}
306359

307360
// void Ty::SetToIdle(bool, TyMedium) {
@@ -328,9 +381,13 @@ void AutoTargetStruct::Reset(void) {
328381

329382
}
330383

384+
void Ty::ResetDrownTimer(void) {
385+
unk828 = gb.logicGameCount + (int)((gDisplay.fps * 180.0f) / tyHealth.GetHealthFieldUnk4());
386+
}
387+
331388
void Ty::WaterMediumInit(void) {
332389
BoomerangManagerAnims swimAnims = {
333-
true,
390+
false,
334391
unk6C8,
335392
{unk6C8, unk6DC},
336393
{unk6D4, unk6E8}
@@ -351,6 +408,8 @@ void Ty::WaterMediumDeinit(void) {
351408

352409
}
353410

411+
void Hud_ShowHealthMeter(bool);
412+
354413
void Ty::UnderWaterMediumInit(void) {
355414
BoomerangManagerAnims underWaterAnims = {
356415
true,
@@ -363,13 +422,22 @@ void Ty::UnderWaterMediumInit(void) {
363422

364423
tyHealth.SetType(HEALTH_TYPE_1);
365424

425+
SoundBank_PlayExclusiveAmbientSound(false);
426+
427+
Hud_ShowHealthMeter(true);
428+
429+
ResetDrownTimer();
430+
366431
if (pBunyip) {
367432
pBunyip->SetState(BUNYIP_DISAPPEAR);
368433
}
369434
}
370435

371436
void Ty::UnderWaterMediumUpdate(void) {
372-
437+
if (gb.logicGameCount >= unk828) {
438+
ty.Hurt(HURT_TYPE_6, DDA_DAMAGE_3, false, NULL, 15.0f);
439+
ResetDrownTimer();
440+
}
373441
}
374442

375443
void Ty::UnderWaterMediumDeinit(void) {

src/ty/source/TyHealth.cpp

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#include "ty/TyHealth.h"
2+
#include "ty/soundbank.h"
3+
4+
#include "ty/Ty.h"
5+
6+
void Hud_ShowLives(void);
7+
8+
void VibrateJoystick(float, float, float, char, float);
9+
10+
extern "C" int Sound_IsVoicePlaying(int);
11+
12+
HealthInfo TyHealth::heathInfo[] = {
13+
{2, 4, 1, 4, 0x10F, -1, -1, "paw_health"},
14+
{2, 8, 1, 8, 0x21, 0x22, 0x23, "paw_air"},
15+
{2, 4, 1, 8, -1, -1, -1, "paw_health"}
16+
};
17+
18+
void TyHealth::Init(TyHealthType type) {
19+
pMaterial = Material::Create("fx_002a");
20+
21+
bubbleList.Init(20);
22+
23+
SetType(type);
24+
25+
unk4 = 0;
26+
27+
for (int i = 0; i < ARRAY_SIZE(heathInfo); i++) {
28+
heathInfo[i].unk20 = Material::Create(heathInfo[i].unk1C);
29+
}
30+
31+
unk18 = -1;
32+
unk1C = 0;
33+
unk20 = 1.0f;
34+
}
35+
36+
void TyHealth::Deinit(void) {
37+
bubbleList.Deinit();
38+
39+
pMaterial->Destroy();
40+
41+
for (int i = 0; i < ARRAY_SIZE(heathInfo); i++) {
42+
heathInfo[i].unk20->Destroy();
43+
}
44+
}
45+
46+
bool TyHealth::Hurt(HurtType type) {
47+
unk4 = 15;
48+
49+
if (ty.mFsm.GetState() == TY_AS_28 || ty.mFsm.GetState() == TY_AS_29) {
50+
SoundBank_Stop(&unk18);
51+
}
52+
53+
if (type != HURT_TYPE_6 && mType == HEALTH_TYPE_1) {
54+
heathInfo[mType].unkC = Max<int>(heathInfo[mType].unkC - 2, 0);
55+
} else {
56+
heathInfo[mType].unkC = Max<int>(heathInfo[mType].unkC - 1, 0);
57+
}
58+
59+
DoLoseFX();
60+
61+
Hud_ShowLives();
62+
63+
VibrateJoystick(0.0f, 0.6f, 0.27f, 0, 4.0f);
64+
65+
return heathInfo[mType].unkC > 0;
66+
}
67+
68+
void TyHealth::Gain(int r4) {
69+
if (unk18 > -1 && Sound_IsVoicePlaying(unk18)) {
70+
SoundBank_Stop(&unk18);
71+
}
72+
73+
unk4 = 0;
74+
75+
heathInfo[mType].unkC = Min<int>(heathInfo[mType].unkC + r4, heathInfo[mType].unk4 * heathInfo[mType].unk8);
76+
77+
Hud_ShowLives();
78+
}
79+
80+
void TyHealth::SetType(TyHealthType type) {
81+
mType = type;
82+
unk4 = 0;
83+
84+
if (ty.mFsm.GetState() == TY_AS_28 || ty.mFsm.GetState() == TY_AS_29) {
85+
heathInfo[mType].unkC = 0;
86+
} else {
87+
heathInfo[mType].unkC = heathInfo[mType].unk8 * heathInfo[mType].unk4;
88+
}
89+
90+
Hud_ShowLives();
91+
}
92+
93+
void TyHealth::SetNumSymbols(int r4) {
94+
for (int i = 0; i < ARRAY_SIZE(heathInfo); i++) {
95+
heathInfo[i].unk8 = r4;
96+
}
97+
98+
SetType(mType);
99+
}
100+
101+
void TyHealth::DrawLooseFX(Vector vec) {
102+
103+
}
104+
105+
void TyHealth::DrawHudElement(Vector vec) {
106+
107+
}
108+
109+
void TyHealth::DoLoseFX(void) {
110+
if (heathInfo[mType].unk18 >= 0 && heathInfo[mType].unkC == 1) {
111+
if (unk18 == -1) {
112+
unk18 = SoundBank_Play(heathInfo[mType].unk18, NULL, 0);
113+
}
114+
} else if (heathInfo[mType].unk14 >= 0 && heathInfo[mType].unkC > 0) {
115+
SoundBank_Play(heathInfo[mType].unk14, NULL, 0);
116+
}
117+
}

0 commit comments

Comments
 (0)