summaryrefslogtreecommitdiff
path: root/src/bossPlayerClown.cpp
blob: 583174853d14a789cd86f1b8c44c8d703b653c2e (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
#include <common.h>
#include <game.h>
#include <g3dhax.h>
#include <sfx.h>
#include "boss.h"


#define CLOWN_MODEL(clown) ((m3d::mdl_c*)( ((u32)(clown)) + 0xFD0 ))
#define playerOccupying (((u32)(clown)) + 0x738 )

// candidates for player are 0x738. Load the vtable from the actor at 0x738, then fire function 0x6C
// Or just fire 0x6C
// or just check 0x38D 

extern "C" int PClownCarExecute(dEn_c *clown);
extern "C" void PClownCarAfterCreate(dEn_c *clown, u32);
extern "C" int PClownCarDraw(dEn_c *clown);
extern "C" void PClownCarMove(dEn_c *clown);


int CConDraw(dEn_c *clown) {
	// setup cannon model
	matrix.translation(pos.x, pos.y, pos.z);
	newrot = rot.y + 0x4000;
	matrix.applyRotationYXZ(&rot.x, &newrot, &rot.z);

	CLOWN_MODEL(clown).setDrawMatrix(matrix);
	CLOWN_MODEL(clown).setScale(&scale);
	CLOWN_MODEL(clown).calcWorld(false);

	CLOWN_MODEL(clown).scheduleForDrawing();


	return PClownCarDraw(clown);
	// run normal clown function
}

int CConExecute(dEn_c *clown) {
	return PClownCarExecute(clown);
}

void CCafterCreate(dEn_c *clown, u32 param) {

	clown->scale.x *= 1.25;
	clown->scale.y *= 1.25;
	clown->scale.z *= 1.25;

	// setup the model
	mHeapAllocator_c allocator;
	nw4r::g3d::ResFile resFile;

	allocator.link(-1, GameHeaps[0], 0, 0x20);

	this->resFile.data = getResource("koopaJr_clown_ply", "g3d/cannon.brres");
	nw4r::g3d::ResMdl mdl = this->resFile.GetResMdl("Cannon");
	CLOWN_MODEL(clown).setup(mdl, &allocator, 0x224, 1, 0);
	SetupTextures_MapObject(&CLOWN_MODEL(clown), 0);

	allocator.unlink();

	// Original AfterCreate
	PClownCarAfterCreate(clown, param);
}

void CConExecuteMove(dEn_c *clown) {

	u8 player = ((dStageActor_c *)playerOccupying)->which_player;
	OSReport("Angle = %x, %x, %x", (GetSpecificPlayerActor(player))->rot.y, (GetSpecificPlayerActor(player))->rot.x, (GetSpecificPlayerActor(player))->rot.z);
	OSReport("Clown = %x, %x, %x", (clown)->rot.y, (clown)->rot.x, (clown)->rot.z);

	RemoconMngClass* Remo = GetRemoconMng();

	Vec tempPos;
	
	u32 buttonPushed = Remocon_GetPressed(Remo->controllers[player]);
	if (buttonPushed & 0x0100) {

		if (clown->direction == 0) { // Going right
			tempPos = (Vec){clown->pos.x + 32.0, clown->pos.y + 32.0, 3564.0};
			dStageActor_c *spawned = CreateActor(347, clown->direction, tempPos, 0, 0);
			spawned->speed.x = 5.0;
		}
		else {
			tempPos = (Vec){clown->pos.x - 32.0, clown->pos.y + 32.0, 3564.0};
			dStageActor_c *spawned = CreateActor(347, clown->direction, tempPos, 0, 0);
			spawned->speed.x = -5.0;
		}

		SpawnEffect("Wm_en_killervanish", 0, &tempPos, &(S16Vec){0,0,0}, &(Vec){1.0, 1.0, 1.0});
		PlaySoundAsync(clown, SE_OBJ_HOUDAI_S_SHOT);

	}

	// run normal move
	PClownCarMove(clown);

	// check for wiimote button presses

	// spawn effect and attack if there are any
}


extern "C" m3d::mdl_c *__ct__Q23m3d5mdl_cFv(m3d::mdl_c *mdl);
extern "C" dEn_c *__ct__20daJrClownForPlayer_cFv(dEn_c *clown);

dEn_c *newClownCtor(dEn_c *clown) {
	OSReport("ctor");
	__ct__20daJrClownForPlayer_cFv(clown);
	__ct__Q23m3d5mdl_cFv(CLOWN_MODEL(clown));
	return clown;
}


extern "C" void __dt__Q23m3d5mdl_cFv(m3d::mdl_c *mdl, u32 willDelete);
extern "C" void __dt__20daJrClownForPlayer_cFv(dEn_c *mdl, u32 willDelete);

void newClownDtor(dEn_c *clown, u32 willDelete) {
	__dt__Q23m3d5mdl_cFv(CLOWN_MODEL(clown), 0xFFFFFFFF);
	__dt__20daJrClownForPlayer_cFv(clown, willDelete);
}