summaryrefslogtreecommitdiff
path: root/src/bossThwompaDomp.cpp
blob: e84867dbd522712ecc96ae7a9b07be266608aafe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
#include <common.h>
#include <game.h>
#include <g3dhax.h>
#include <sfx.h>

#include "daEnDosun_c.h"

#if 0
/* called from _vf228 */
/* handles overall scale */
void sub_8009ea50( _464_struct* data ) {
	u32 ctr   = data->ctr;	// _0x14
	dEn_c* en = data->en;	// _0x18

	if(!ctr) {
		en->scale.x = en->scale.y = en->scale.z = 1.0;
		data->x = data->y = data->z = data->_0xC = 1.0
		return;
	}
	data->ctr--;

	/*FIXME continue */
}
#endif


//FIXME find if needed
extern "C" int s_800b56e0(Vec,float*,float*,u8 zone);
//FIXME
extern "C" void* unk_8042A008;
extern "C" void UnknownBullshit(void*,int,int,int,int);
//FIXME
extern "C" void* SoundRelatedClass;
extern "C" Vec ConvertStagePositionIntoScreenPosition__Maybe(Vec);
extern "C" void AnotherSoundRelatedFunction(void*,SFX,Vec,int);

#define OLD 0
#define STATES_NEEDED 1
#define SETTINGS1CHANGE 1
class daEnMegaDosun_c : public daEnDosun_c {
	int onCreate();		// overload for mega
	int onExecute();
	static daEnMegaDosun_c *build();

	//int checkZoneBoundaries(int);

#if STATES_NEEDED
	//FIXME
	USING_STATES(daEnMegaDosun_c);
	DECLARE_STATE(UpWait);
	DECLARE_STATE(DownMoveWait);
	DECLARE_STATE(PuruMove);
	DECLARE_STATE(DownMoveKameck);
	DECLARE_STATE(DownMove);
	DECLARE_STATE(DownWait);
	DECLARE_STATE(UpMove);
#endif
};

#if STATES_NEEDED
CREATE_STATE(daEnMegaDosun_c, UpWait);
CREATE_STATE(daEnMegaDosun_c, DownMoveWait);
CREATE_STATE(daEnMegaDosun_c, PuruMove);
CREATE_STATE(daEnMegaDosun_c, DownMoveKameck);
CREATE_STATE(daEnMegaDosun_c, DownMove);
CREATE_STATE(daEnMegaDosun_c, DownWait);
CREATE_STATE(daEnMegaDosun_c, UpMove);
#endif

daEnMegaDosun_c *daEnMegaDosun_c::build() {
	OSReport("Building MegaThwomp\n");
	void *buffer = AllocFromGameHeap1(sizeof(daEnMegaDosun_c));
	return new(buffer) daEnMegaDosun_c;
}

#if 1
//FIXME stops halfway up
int daEnMegaDosun_c::onCreate() {
	OSReport("daEnMegaDosun::onCreate()\n");

	this->bigOrSmall = 1;	// 0=small,1=big,2=mega

	this->setupBodyModel();	// add this for linking/rename

	this->_36D = 0;			// byte
	this->holdsFromSettings = this->settings & 0xf;	//0=normal,1=??,2=fall

	this->frzMgr.setSomething(1,1,1);	//@0x809f5c5c

	this->pos.y -= 21.0;
	this->pos.z = -280.0;		// behind layer1 (hides spikes)

	this->collision_struct[0] = 0x11804101;
	this->collision_struct[1] = 0xFFFE1000;
	this->collision_struct[2] = 0x0001F000;
	this->collision_struct[3] = 0x00005000;

	/*
	//0x80ACF990 + 0x8C = 80acfa1C
	0.0,41.0,36.0,38.0,
	0x03, 0x00, 0x0000,0x0000004F,0x0000820E,0x0100,0x0000
	dEn_c::collisionCallback (0x80095950)
	*/
	ActivePhysics::Info hm;
	hm.xDistToCenter = 0.0;
	//FIXME find the missing link
	hm.yDistToCenter = 41.0;
	hm.xDistToEdge = 36.0;
	hm.yDistToEdge = 38.0;
	hm.category1 = 0x03;
	hm.category2 = 0x00;
	hm.bitfield1 = 0x0000004F;
	hm.bitfield2 = 0x0000820E;
	hm.unkShort1C = 0x0100;
	hm.callback = &dEn_c::collisionCallback;
	OSReport("this->aPhysiscs.initWithStruct(this,&hm);\n");
	this->aPhysics.initWithStruct(this, &hm);

	/* 0x00000001,0xfffe1000,0x0001f000,0x00055000,
	 * 0.0,20.0,16.0,19.0
	 * 0x03000000,0x0000004f,0x0000820e,0x01000000,
	 * dEn_c::collisionCallback
	 */
	//u8 s3[] = {0,0,0,1,0xff,0xfe,0x10,0,0,1,0xf0,0,0,5,0x50,0};
	u8 s3[] = {0,0,0,1,0xff,0xfe,0x10,0,0,1,0xf0,0,0xff,0xfe,0x10,0};
	OSReport("this->collMgr.Init(this,(u8*)&this->collision_struct,(u8*)&s3,0);\n");
	this->collMgr.Init(this,(u8*)&this->collision_struct,(u8*)&s3,0);

	this->pos_delta2.x = 0.0;
	this->pos_delta2.y = 36.0;
	this->pos_delta2.z = 0.0;
	this->_320 = 0.0;
	this->_324 = 48.0;

	OSReport("this->aPhysics.addToList();\n");
	this->aPhysics.addToList();

	this->scale.x = 1.0;
	this->scale.y = 1.0;
	this->scale.z = 1.0;
	this->max_speed.x = 0.0;
	this->max_speed.y = -8.0;
	this->max_speed.z = 0.0;
	this->y_speed_inc = -0.25;
	this->rot.x = 0;
	this->rot.y = 0;
	this->rot.z = 0;

	OSReport("this->doStateChange(FOO): %d\n", this->holdsFromSettings);
	// check settings bit
	if(this->holdsFromSettings == 2) {
		this->doStateChange(&StateID_DownMove_Kameck);
	}else{
		this->doStateChange(&StateID_UpWait);
	}

	return 1;
}
#endif

int daEnMegaDosun_c::onExecute() {

	acState.execute();

	/*
	float tempRect[4] = {this->_320,this->_324,0.5*this->spriteSomeRectX,0.5*this->spriteSomeRectY};
	int foo = this->outOfZone(this->pos, tempRect, this->currentZoneID);
	//float tempRect2[4] = {this->_338, this->_33C, this->_340, this->_344};
	//OSReport("s_800b56e0()\n");
	//int bar = s_800b56e0(this->pos, tempRect, tempRect2, this->currentZoneID);
	//OSReport("foo: %d, bar: %d\n", foo, bar);
	if(foo) {
		OSReport("this->outOfZone(%d) : %d\n", this->currentZoneID, foo);
		OSReport("daEnMegaDosun_c has left the building\n");
		this->Delete(this->_390);
		//FIXME change to do outro when leaving screen
	}else{
		OSReport("this->outOfZone(%d) : %d\n", this->currentZoneID, foo);
	}
	*/
	int ret = this->checkZoneBoundaries(0);
	if(ret) {
		OSReport("daEnMegaDosun_c has left the building\n");
	}

	return 1;
}

#if STATES_NEEDED
//FIXME add sideways moving
//StateID_UpWait
void daEnMegaDosun_c::beginState_UpWait() {
	OSReport("beginState_UpWait()\n");
	this->countdownTimer = 0;
	if(!this->bigOrSmall)
		return;
	this->collision_struct[0] = 0x11804101;
}
void daEnMegaDosun_c::executeState_UpWait() {
	OSReport("executeState_UpWait()\n");
	if(this->countdownTimer != 0) {
		this->countdownTimer--;
		return;
	}

	//FIXME need megasized - also needs to be less leeway
	float _array[] = { 48.0, 80.0 }; // small, big
	//CheckIfPlayerBelow(xDelta, yDelta);
	//if(this->CheckIfPlayerBelow(80.0, 256.0)) {
	if(this->CheckIfPlayerBelow(40.0, 256.0)) {
		this->doStateChange(&StateID_DownMoveWait);
		this->speed.y = 0.0;
	}
}
void daEnMegaDosun_c::endState_UpWait() {
	OSReport("endState_UpWait()\n");
	return;
}

//StateID_DownMoveWait
void daEnMegaDosun_c::beginState_DownMoveWait() {
	OSReport("beginState_DownMoveWait()\n");
	this->anmVis.playState = 1;
	this->bodyModel.bindAnim(&this->anmVis, 0.5);
}
void daEnMegaDosun_c::executeState_DownMoveWait() {
	OSReport("executeState_DownMoveWait()\n");
	if(this->anmVis.isAnimationDone())
		this->doStateChange(&StateID_PuruMove);
	this->anmVis.process();
}
void daEnMegaDosun_c::endState_DownMoveWait() {
	OSReport("endState_DownMoveWait()\n");
	return;
}

//StateID_PuruMove
void daEnMegaDosun_c::beginState_PuruMove() {
	OSReport("beginState_PuruMove()\n");
	this->puruMoveCounter = 8;
	this->shakeIndex = 0;
}
void daEnMegaDosun_c::executeState_PuruMove() {
	OSReport("executeState_PuruMove()\n");
	if(this->puruMoveCounter == 0) {
		this->shakePosXoffset = 0.0;
		this->doStateChange(&StateID_DownMove);
		return;
	}

	this->puruMoveCounter--;
	if(this->puruMoveCounter & 2 == 0)
		return;

	float _array[] = {2.0, 0.0};
	this->shakeIndex ^= 1;
	this->shakePosXoffset = _array[this->shakeIndex];
}
void daEnMegaDosun_c::endState_PuruMove() {
	OSReport("endState_PuruMove()\n");
	return;
}

//StateID_DownMoveKameck
void daEnMegaDosun_c::beginState_DownMoveKameck() {
	OSReport("beginState_DownMoveKameck()\n");
	this->anmVis.playState = 1;
	this->bodyModel.bindAnim(&this->anmVis, 0.5);
}
void daEnMegaDosun_c::executeState_DownMoveKameck() {
	OSReport("executeState_DownMoveKameck()\n");
	if(this->anmVis.isAnimationDone())
		this->doStateChange(&StateID_DownMove);
	this->anmVis.process();
}
void daEnMegaDosun_c::endState_DownMoveKameck() {
	OSReport("endState_DownMoveKameck()\n");
	return;
}

//StateID_DownMove
void daEnMegaDosun_c::beginState_DownMove() {
	OSReport("beginState_DownMove()\n");
	this->speed.y = 0.0;
}
void daEnMegaDosun_c::executeState_DownMove() {
	OSReport("executeState_DownMove()\n");
	this->HandleYSpeed();
	this->UpdateObjectPosBasedOnSpeedValuesReal();

	//FIXME what do I do? - bottom detection
	int ret = this->collMgr.execute();
	OSReport("s_80072BC0(): %08x\n", ret);
	if(!ret)
		return;

#if SETTINGS1CHANGE
	if((this->holdsFromSettings == 1) && (ret & 0x8000)) {
		OSReport("this->speed.y = 0.0;\n");
		this->speed.y = 0.0;
	}

	if(this->holdsFromSettings == 2) {
		OSReport("ret |= 0x400000\n");
		ret |= 0x400000;
	}
#else
	if(this->holdsFromSettings == 1) {
		OSReport("ret |= 0x400000\n");
		ret |= 0x400000;
	}
#endif

	if(!(ret & 0x400000)) {
		OSReport("doStateChange(&StateID_DownWait)\n");
		this->doStateChange(&StateID_DownWait);
		this->countdownTimer = 0x40;
		this->speed.y = 0.0;
		UnknownBullshit(unk_8042A008, 0, 1, 0, 0);
	}else{
		this->collision_struct[0] = 0x00000001;
		this->speed.y = 0.0;
		OSReport("UnknownBullshit(%x,%d,%d,%d,%d)\n", unk_8042A008,0,1,0,0);
		UnknownBullshit(unk_8042A008, 0, 1, 0, 0);
		this->collMgr.Clear2();
	}

	this->spawnEffects();
	Vec p = ConvertStagePositionIntoScreenPosition__Maybe(this->pos);
	AnotherSoundRelatedFunction(SoundRelatedClass, SE_EMY_BIG_DOSSUN, p, 0);
	//SoundRelatedClass.AnotherSoundRelatedFunction(SE_EMY_BIG_DOSSUN, p, 0);
}
void daEnMegaDosun_c::endState_DownMove() {
	OSReport("endState_DownMove()\n");
	return;
}

//StateID_DownWait
void daEnMegaDosun_c::beginState_DownWait() {
	OSReport("beginState_DownWait()\n");
	return;
}
void daEnMegaDosun_c::executeState_DownWait() {
	OSReport("executeState_DownWait()\n");
	if(this->countdownTimer == 0) {
		this->doStateChange(&StateID_UpMove);
	}else{
		this->countdownTimer--;
		if(this->countdownTimer & 0xff == 0x20)
			this->anmVis.playState = 3;
	}

	this->anmVis.process();
}
void daEnMegaDosun_c::endState_DownWait() {
	OSReport("endState_DownWait()\n");
	return;
}

//StateID_UpMove
void daEnMegaDosun_c::beginState_UpMove() {
	OSReport("beginState_UpMove()\n");
	this->collMgr.Clear2();
}
void daEnMegaDosun_c::executeState_UpMove() {
	OSReport("executeState_UpMove()\n");
	this->speed.y = 0.875;
	this->UpdateObjectPosBasedOnSpeedValuesReal();
	int ret = this->collMgr.SomethingSemiImportant(0);
	OSReport("this->collMgr.SomethingSemiImportant(0): %08x\n", ret);
	if(ret != 0) { // at top
		this->doStateChange(&StateID_UpWait);
		this->countdownTimer = 0xc;
	}
}
void daEnMegaDosun_c::endState_UpMove() {
	OSReport("endState_UpMove()\n");
	return;
}
#endif

#if 0
int daEnMegaDosun_c::checkZoneBoundaries(int foo) {
	if(this->eatenState == 2) {	// is eaten
		return 0;
	}

	if( (0 == (foo&0x8)) && \
		(this->collMgr.checkBits15and16ofBitfield() != 0) ) {
		return 0;
	}

	int ret = 0;

	Rect tempRect = (Rect){this->_320, this->_324,
		0.5 * this->spriteSomeRectX, 0.5 * this->spriteSomeRectY};
	Rect tempRect2 = (Rect){_338, _33C, _340, _344};
	if(this->outOfZone(this->pos, &tempRect, currentZoneId) ||
		(!(foo&0x4) && s_800b56e0(pos, &tempRect, &tempRect2, currentZoneId)) )
	{
		ret = 1;
	}

	if(ret && !(foo & 0x2))
		this->Delete(this->_390);

	return ret;
}
#endif

#if 0
extern "C" bool CollidedWithTile(u8 *);
extern "C" void *SomeStrangeModification(dEn_c *);

void ThwompaDompMoveC(dEn_c *Sprite) {



	bool FirstCheck;
	bool SecondCheck;

	// Check for collisions with walls?
	FirstCheck = CollidedWithTile(Sprite->collMgr);
	SomeStrangeModification(Sprite);
	SecondCheck = CollidedWithTile(Sprite->collMgr);

	OSReport("XPos = %f, FirstCheck = %d, SecondCheck = %d", Sprite->pos.x, FirstCheck, SecondCheck); 

	if ((FirstCheck != 0) && (SecondCheck != 0)) {	
		OSReport("Actually doing something, I swear");

		Sprite->pos.y = Sprite->pos.y + 16.0;
		Sprite->pos.x = Sprite->pos.x - 180.0;

		if (Sprite->direction == 0) {
			Sprite->direction = 1; 
			Sprite->pos.x = Sprite->pos.x - 80.0; }
		else {
			Sprite->direction = 0; 
			Sprite->pos.x = Sprite->pos.x + 80.0; }
	}
	else {
		if (Sprite->direction == 0) {
			Sprite->pos.x = Sprite->pos.x + 1.0; }
		else {
			Sprite->pos.x = Sprite->pos.x - 1.0; }
	}		


	return;
}
#endif

/*
class daYoshi_c : public dStageActor_c {
	u32 _1520;	// holds actorID of actor eaten
};
*/