summaryrefslogtreecommitdiff
path: root/src/spritespawner.cpp
blob: 47dbf1388e1f33c6188e53357ba69df19ff6c998 (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
#include <common.h>
#include <game.h>

struct SpriteSpawner {
	u32 id;			// 0x00
	u32 settings;	// 0x04
	u16 name;		// 0x08
	u8 _0A[6];		// 0x0A
	u8 _10[0x9C];	// 0x10
	float x;		// 0xAC
	float y;		// 0xB0
	float z;		// 0xB4
	u8 _B8[0x318];	// 0xB8
	// Any variables you add to the class go here; starting at offset 0x3D0
	u64 eventFlag;	// 0x3D0
	u16 type;		// 0x3D4
	u32 inheritSet;	// 0x3D6
	u8 lastEvState;	// 0x3DA
	u32 createdActor;
	u8 respawn;
};



struct VEC {
	float x;
	float y;
	float z;
};



void SpriteSpawner_Update(SpriteSpawner *self);

#define ACTIVATE	1
#define DEACTIVATE	0




bool SpriteSpawner_Create(SpriteSpawner *self) {

	char eventNum		= (self->settings >> 28)	& 0xF;

	self->eventFlag 	= (u64)1 << (eventNum - 1);
	self->createdActor 	= 0;
	self->type			= (self->settings >> 16) & 0x7FF;
	self->respawn		= (self->settings >> 27) & 0x1;
	
	short tempSet = self->settings & 0xFFFF;
	self->inheritSet = (tempSet & 3) | ((tempSet & 0xC) << 2) | ((tempSet & 0x30) << 4) | ((tempSet & 0xC0) << 6) | ((tempSet & 0x300) << 8) | ((tempSet & 0xC00) << 10) | ((tempSet & 0x3000) << 12) | ((tempSet & 0xC000) << 14);
		
	SpriteSpawner_Update(self);
	
	return true;
}

bool SpriteSpawner_Execute(SpriteSpawner *self) {
	SpriteSpawner_Update(self);
	return true;
}


void SpriteSpawner_Update(SpriteSpawner *self) {
	
	// If the event is active...	
	if (dFlagMgr_c::instance->flags & self->eventFlag) {		

		// And if the spawner hasn't spawned anything...
		if (self->createdActor == 0)
		{
			Vec pos;
			pos.x = self->x;
			pos.y = self->y;
			pos.z = self->z;
	
	
			dStageActor_c *spawned = CreateActor(self->type, self->inheritSet, pos, 0, 0);
			self->createdActor = spawned->id;
		}		
	}
	else {
		if (self->respawn) { return; }

		if (self->createdActor != 0) { 
			dStageActor_c *spawned = Actor_SearchByID(self->createdActor);
			if (spawned != 0) {
				self->x = spawned->pos.x;
				self->y = spawned->pos.y;
				self->z = spawned->pos.z;

				spawned->Delete(1);
			}
			self->createdActor = 0;
		}
	}

	if (self->respawn) {
		if (self->createdActor != 0) { 
			dStageActor_c *spawned = Actor_SearchByID(self->createdActor);
			if (spawned == 0) {
				Vec pos;
				pos.x = self->x;
				pos.y = self->y;
				pos.z = self->z;
		
		
				dStageActor_c *spawned = CreateActor(self->type, self->inheritSet, pos, 0, 0);
				self->createdActor = spawned->id;
			}
		}	
	}
}