summaryrefslogtreecommitdiff
path: root/src/effectvideo.cpp
blob: d69026305c80db34e8ebacfc886b0029c9884839 (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
#include <common.h>
#include <game.h>
#include <g3dhax.h>
#include <sfx.h>


extern "C" void *PlaySoundAsync(dEn_c *, int soundID);
extern "C" bool SpawnEffect(const char*, int, Vec*, S16Vec*, Vec*);


class EffectVideo : public dEn_c {
	int onCreate();
	int onExecute();
	int onDelete();

	u64 eventFlag;
	s32 timer;
	u32 delay;

	u32 effect;
	u8 type;
	float scale;

	static EffectVideo *build();

};

struct EventTable_t {
	u64 events;
};

extern EventTable_t *EventTable;


EffectVideo *EffectVideo::build() {
	void *buffer = AllocFromGameHeap1(sizeof(EffectVideo));
	return new(buffer) EffectVideo;
}


int EffectVideo::onCreate() {
	
	this->timer = 0;

	char eventNum	= (this->settings >> 24) & 0xFF;

	this->eventFlag = (u64)1 << (eventNum - 1);
	
	this->type		= (this->settings >> 16) & 0xF;
	this->effect	= this->settings & 0xFFF;
	this->scale		= float((this->settings >> 20) & 0xF) / 4.0;
	this->delay		= (this->settings >> 12) & 0xF * 30;
	
	if (this->scale == 0.0) { this->scale = 1.0; }

	this->onExecute();
	return true;
}


int EffectVideo::onDelete() {
	return true;
}


int EffectVideo::onExecute() {

	if (EventTable->events & this->eventFlag) {		

		if (this->timer == this->delay) {

			if (this->type == 0) { // Plays a sound
				PlaySoundAsync(this, this->effect);
			}
	
			else {	// Plays an Effect

				const char *efName = 0;

				switch (this->effect) {
					case 1: efName = "Wm_mr_cmnsndlandsmk"; break;
					case 3: efName = "Wm_en_landsmoke"; break;
					case 5: efName = "Wm_en_sndlandsmk"; break;
					case 6: efName = "Wm_en_sndlandsmk_s"; break;
					case 43: efName = "Wm_ob_cmnspark"; break;
					case 159: efName = "Wm_mr_hardhit_grain"; break;
					case 177: efName = "Wm_ob_greencoinkira_b"; break;
					case 193: efName = "Wm_mr_electricshock_biri01_s"; break;
					case 216: efName = "Wm_en_blockcloud"; break;
					case 365: efName = "Wm_en_kuribobigsplit"; break;
					case 514: efName = "Wm_ob_fireworks_y"; break;
					case 517: efName = "Wm_ob_fireworks_b"; break;
					case 520: efName = "Wm_ob_fireworks_g"; break;
					case 523: efName = "Wm_ob_fireworks_p"; break;
					case 526: efName = "Wm_ob_fireworks_k"; break;
					case 533: efName = "Wm_ob_fireworks_1up"; break;
					case 540: efName = "Wm_ob_fireworks_star"; break;
				}

				if (efName != 0)
					SpawnEffect(efName, 0, &this->pos, &(S16Vec){0,0,0}, &(Vec){this->scale, this->scale, this->scale});
			}
	
			this->timer = 0;
			if (this->delay == 0) { this->delay = -1; }
		}
		
		this->timer += 1;
	}
	return true;
}