Skip to content

Commit 211ec2b

Browse files
committed
Link shears.cpp
1 parent ea15177 commit 211ec2b

File tree

6 files changed

+304
-3
lines changed

6 files changed

+304
-3
lines changed

configure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ def MatchingFor(*versions):
570570
Object(Matching, "ty/source/setup.cpp"),
571571
Object(Matching, "ty/source/Shadow.cpp"),
572572
Object(NonMatching, "ty/source/Shatter.cpp"),
573-
Object(NonMatching, "ty/source/shears.cpp"),
573+
Object(Matching, "ty/source/shears.cpp"),
574574
Object(Matching, "ty/source/SignPost.cpp"),
575575
Object(Matching, "ty/source/soundbank.cpp"),
576576
Object(NonMatching, "ty/source/SpecialPickup.cpp"),

include/common/MKAnimScript.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ struct MKAnimScript {
8888
bool HasLooped(void);
8989
int UpdatesUntilFinished(void);
9090
int GetLength(void);
91-
void GetStartAndEnd(MKAnim*, short*, short*);
91+
void GetStartAndEnd(MKAnim* pAnim, short* pStart, short* pEnd);
9292
void SetAnimKeepingPosition(MKAnim*);
9393
float GetNormalPosition(void);
9494
float GetFrameOfNormalPosition(float, MKAnim*);

include/ty/Shears.h

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#ifndef SHEARS_H
2+
#define SHEARS_H
3+
4+
#include "common/Model.h"
5+
#include "common/Collision.h"
6+
7+
struct ShearsLoadInfo {
8+
Vector unk0;
9+
Vector unk10;
10+
11+
int unk20;
12+
int unk24;
13+
int unk28;
14+
};
15+
16+
struct ShearBlade {
17+
bool bRefPointExists : 1;
18+
bool b1 : 1;
19+
20+
int unk4;
21+
Vector unk8;
22+
};
23+
24+
struct ShearsStruct {
25+
ShearBlade blades[5];
26+
Vector unk78;
27+
Vector unk88;
28+
Vector unk98;
29+
Vector unkA8;
30+
Model* unkB8;
31+
Model* unkBC;
32+
int unkC0;
33+
int unkC4;
34+
int unkC8;
35+
int unkCC;
36+
int unkD0;
37+
int unkD4;
38+
int unkD8;
39+
int unkDC;
40+
int unkE0;
41+
int unkE4;
42+
float unkE8;
43+
int unkEC;
44+
CollisionInfo mCollisionInfo;
45+
46+
void Logic(void);
47+
void CheckForTy(void);
48+
void Load(ShearsLoadInfo* pLoadInfo);
49+
void Reset(void);
50+
};
51+
52+
void Shears_LoadResources(void);
53+
54+
void Shears_Init(void);
55+
void Shears_Deinit(void);
56+
57+
ShearsStruct* Shears_Add(ShearsLoadInfo* pLoadInfo);
58+
59+
void Shears_Update(void);
60+
61+
void Shears_Draw(void);
62+
63+
#endif // SHEARS_H

src/ty/source/main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "ty/SignPost.h"
2323
#include "ty/FinishLine.h"
2424
#include "ty/effects/Weather.h"
25+
#include "ty/Lasso.h"
2526

2627
#include "common/FileSys.h"
2728
#include "common/ParticleSystemManager.h"
@@ -87,6 +88,8 @@ void Main_LoadStaticResources(void) {
8788
RainbowEffect_LoadResources();
8889
ChronorangEffects_LoadResources();
8990

91+
Lasso_LoadResources();
92+
9093
Boomerang_LoadResources(&ini);
9194

9295
Bunyip_LoadResources(&ini);

src/ty/source/setup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "ty/main.h"
2424
#include "ty/frontend/FrontEnd.h"
2525
#include "ty/effects/Weather.h"
26+
#include "ty/Shears.h"
2627

2728
MKSceneManager gSceneManager;
2829

@@ -204,7 +205,6 @@ void BonusPickup_Deinit(void);
204205
void PauseScreen_DeinitLevel(void);
205206
void Fly_DeinitTyFlies(void);
206207
void Critters_DeInit(void);
207-
void Shears_Deinit(void);
208208
void StaticSpikes_Deinit(void);
209209
void SpikeyIce_Deinit(void);
210210
void BarbedWire_Deinit(void);

src/ty/source/shears.cpp

Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
#include "ty/Shears.h"
2+
#include "ty/RangeCheck.h"
3+
#include "ty/Ty.h"
4+
#include "ty/tools.h"
5+
#include "ty/soundbank.h"
6+
#include "common/MKAnimScript.h"
7+
#include "common/PtrListDL.h"
8+
9+
static MKAnimScript shearsBad;
10+
11+
static bool bShearsLoaded = false;
12+
13+
static PtrListDL<ShearsStruct> Shears;
14+
15+
int shearsMax = 0;
16+
17+
static short startFrame = -1;
18+
static short midFrame = -1;
19+
static short endFrame = -1;
20+
21+
void Shears_LoadResources(void) {
22+
shearsBad.Init("prop_0081_shears");
23+
24+
shearsBad.GetStartAndEnd(shearsBad.GetAnim("close"), &startFrame, &midFrame);
25+
shearsBad.GetStartAndEnd(shearsBad.GetAnim("open"), NULL, &endFrame);
26+
}
27+
28+
void Shears_Init(void) {
29+
if (!bShearsLoaded) {
30+
bShearsLoaded = true;
31+
Shears.Init(shearsMax, sizeof(ShearsStruct));
32+
}
33+
}
34+
35+
void Shears_Deinit(void) {
36+
if (bShearsLoaded) {
37+
ShearsStruct** ppShears = Shears.GetMem();
38+
while (*ppShears) {
39+
if ((*ppShears)->unkB8->collisionTracking == true) {
40+
Collision_DeleteDynamicModel((*ppShears)->unkB8);
41+
}
42+
43+
(*ppShears)->unkB8->Destroy();
44+
(*ppShears)->unkBC->Destroy();
45+
46+
ppShears++;
47+
}
48+
49+
Shears.Deinit();
50+
51+
bShearsLoaded = false;
52+
}
53+
}
54+
55+
extern "C" char* sprintf(char*, ...);
56+
57+
ShearsStruct* Shears_Add(ShearsLoadInfo* pLoadInfo) {
58+
ShearsStruct* pShear = Shears.GetNextEntry();
59+
60+
if (pShear) {
61+
pShear->Load(pLoadInfo);
62+
63+
pShear->unkB8 = Model::Create(shearsBad.GetMeshName(), shearsBad.GetAnimName());
64+
pShear->unkB8->renderType = 3;
65+
66+
pShear->unkBC = Model::Create("Prop_0081_ShearsColide", NULL);
67+
68+
for (int i = 0; i < ARRAY_SIZE(pShear->blades); i++) {
69+
char buf[256];
70+
71+
sprintf(buf, "R_Shears%02d", i + 1);
72+
73+
pShear->blades[i].bRefPointExists = pShear->unkBC->RefPointExists(
74+
buf,
75+
&pShear->blades[i].unk4
76+
);
77+
78+
pShear->blades[i].b1 = false;
79+
}
80+
81+
pShear->unkB8->SetPosition(&pShear->unk78);
82+
pShear->unkB8->SetRotation(&pShear->unk88);
83+
84+
pShear->unkBC->SetPosition(&pShear->unk78);
85+
pShear->unkBC->SetRotation(&pShear->unk88);
86+
87+
pShear->mCollisionInfo.Init(false, 0, NULL);
88+
89+
Collision_AddDynamicModel(pShear->unkB8, &pShear->mCollisionInfo, -1);
90+
}
91+
92+
return pShear;
93+
}
94+
95+
void Shears_Update(void) {
96+
if (bShearsLoaded) {
97+
ShearsStruct** ppShears = Shears.GetMem();
98+
while (*ppShears) {
99+
ShearsStruct* pShear = *ppShears;
100+
pShear->unkD4++;
101+
102+
switch (pShear->unkD0) {
103+
case 1:
104+
pShear->Logic();
105+
break;
106+
}
107+
108+
pShear->unkE4 = Range_WhichZone(&pShear->unk78, &pShear->unkE8);
109+
110+
ppShears++;
111+
}
112+
}
113+
}
114+
115+
void Shears_Draw(void) {
116+
if (bShearsLoaded) {
117+
ShearsStruct** ppShears = Shears.GetMem();
118+
while (*ppShears) {
119+
ShearsStruct* pShear = *ppShears;
120+
121+
if (pShear->unkD0 > 0 && pShear->unkE4 > -1 && pShear->unkE4 < 2) {
122+
pShear->unkB8->pAnimation->Tween(pShear->unkE0, 1.0f);
123+
124+
pShear->unkC0 = pShear->unkB8->Draw(NULL);
125+
126+
if (pShear->unkC0 != 0) {
127+
for (int i = 0; i < ARRAY_SIZE(pShear->blades); i++) {
128+
if (!pShear->blades[i].bRefPointExists) {
129+
pShear->blades[i].b1 = false;
130+
} else {
131+
pShear->unkBC->GetRefPointWorldPosition(pShear->blades[i].unk4, &pShear->blades[i].unk8);
132+
pShear->blades[i].b1 = true;
133+
}
134+
}
135+
} else {
136+
for (int i = 0; i < ARRAY_SIZE(pShear->blades); i++) {
137+
pShear->blades[i].b1 = false;
138+
}
139+
}
140+
}
141+
142+
ppShears++;
143+
}
144+
}
145+
}
146+
147+
void ShearsStruct::Logic(void) {
148+
if (unkD4 == 1) {
149+
unkD8 = 0;
150+
unkDC = unkC4;
151+
unkE0 = startFrame;
152+
}
153+
154+
switch (unkD8) {
155+
case 0:
156+
unkDC--;
157+
if (unkDC <= 0) {
158+
unkD8 = 3;
159+
mCollisionInfo.Enable();
160+
SoundBank_Play(0xBD, &unk78, NULL);
161+
}
162+
break;
163+
case 3:
164+
unkE0++;
165+
if (unkE0 >= midFrame) {
166+
unkE0 = midFrame;
167+
unkD8 = 2;
168+
unkDC = unkCC;
169+
}
170+
CheckForTy();
171+
break;
172+
case 2:
173+
unkDC--;
174+
if (unkDC <= 0) {
175+
unkD8 = 4;
176+
SoundBank_Play(0xBE, &unk78, NULL);
177+
}
178+
CheckForTy();
179+
break;
180+
case 4:
181+
unkE0++;
182+
if (unkE0 >= endFrame - 60) {
183+
unkE0 = endFrame;
184+
unkD8 = 1;
185+
unkDC = unkC8;
186+
mCollisionInfo.Disable();
187+
}
188+
CheckForTy();
189+
break;
190+
case 1:
191+
unkDC--;
192+
if (unkDC <= 0) {
193+
unkE0 = startFrame;
194+
unkD8 = 3;
195+
mCollisionInfo.Enable();
196+
SoundBank_Play(0xBD, &unk78, NULL);
197+
}
198+
break;
199+
}
200+
}
201+
202+
void ShearsStruct::CheckForTy(void) {
203+
for (int i = 0; i < ARRAY_SIZE(blades); i++) {
204+
if (blades[i].b1 && ApproxMag(&ty.pos, &blades[i].unk8) < 130.0f) {
205+
if (unkD8 == 4) {
206+
ty.SetKnockBackFromPos(&blades[i].unk8, 15.0f, KB_TYPE_0);
207+
} else {
208+
ty.Hurt(HURT_TYPE_1, DDA_DAMAGE_4, false, &unk78, 15.0f);
209+
}
210+
211+
break;
212+
}
213+
}
214+
}
215+
216+
void ShearsStruct::Load(ShearsLoadInfo* pLoadInfo) {
217+
unk98 = pLoadInfo->unk0;
218+
unkA8 = pLoadInfo->unk10;
219+
220+
unkC4 = pLoadInfo->unk20;
221+
unkCC = pLoadInfo->unk24;
222+
unkC8 = pLoadInfo->unk28;
223+
224+
Reset();
225+
}
226+
227+
void ShearsStruct::Reset(void) {
228+
unk78 = unk98;
229+
unk88 = unkA8;
230+
231+
unkD0 = 1;
232+
unkD4 = 0;
233+
234+
unkE0 = startFrame;
235+
}

0 commit comments

Comments
 (0)