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

struct LevelSpecial {
	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
	u8 type;		// 0x3D4
	u8 effect;		// 0x3D5
	u8 lastEvState;	// 0x3D6
	u8 func;		// 0x3D7
};

struct EventTable_t {
	u64 events;
	// ...
};

extern EventTable_t *EventTable;

extern u16 TimeStopFlag;
extern u32 TimerBranch;
extern u32 AlwaysDrawFlag;
extern u32 AlwaysDrawBranch;

extern float MarioDescentRate;
extern float MarioJumpMax;
extern float MarioJumpArc;
extern float MiniMarioJumpArc;
extern float MarioSize;

extern float GlobalSpriteSize;
extern float GlobalSpriteSpeed;
extern float GlobalRiderSize;
extern char SizerOn;
extern char ZOrderOn;


float GlobalSizeFloatModifications [] = {1, 0.25, 0.5, 0.75, 1.25, 1.5, 1.75, 2, 2.5, 3, 4, 5, 6, 7, 8, 10 };
float GlobalRiderFloatModifications [] = {1, 0.6, 0.7, 0.9, 1, 1, 1, 1.1, 1.25, 1.5, 2, 2.5, 3, 3.5, 4, 5};



extern "C" dAc_Py_c *GetSpecificPlayerActor(int number);
void LevelSpecial_Update(LevelSpecial *self);
bool ResetAfterLevel();

#define ACTIVATE	1
#define DEACTIVATE	0

fBase_c *FindActorByID(u32 id);



bool ResetAfterLevel(void) {
	TimeStopFlag = 0;
	TimerBranch = 0x3403FFA4;
	MarioDescentRate = -4;
	MarioJumpMax = 3.628;
	MarioJumpArc = 2.5;
	MiniMarioJumpArc = 2.5;
	MarioSize = 1.0;
	GlobalSpriteSize = 1.0;
	GlobalSpriteSpeed = 1.0;
	GlobalRiderSize = 1.0;
	SizerOn = 0;
	AlwaysDrawFlag = 0x9421FFF0;
	AlwaysDrawBranch = 0x7C0802A6;
	ZOrderOn = 0;
	return true;
}

bool LevelSpecial_Create(LevelSpecial *self) {
	char eventNum	= (self->settings >> 24)	& 0xFF;
	self->eventFlag = (u64)1 << (eventNum - 1);
	
	OSReport("Special Event created @%p event %d\n", self, eventNum);
	
	OSReport("Eventnum: %d. Event flag: %08x %08x\n", eventNum, self->eventFlag >> 32, self->eventFlag & 0xFFFFFFFF);
	
	self->type		= (self->settings)			& 15;
	self->effect	= (self->settings >> 4)		& 15;
	
	self->lastEvState = 0xFF;
	
	LevelSpecial_Update(self);
	
	return true;
}

bool LevelSpecial_Execute(LevelSpecial *self) {
	LevelSpecial_Update(self);
	return true;
}


void LevelSpecial_Update(LevelSpecial *self) {
	//OSReport("%08x%08x", EventTable->events >> 32, EventTable->events & 0xFFFFFFFF);
	
	u8 newEvState = 0;
	if (EventTable->events & self->eventFlag)
		newEvState = 1;
	
	if (newEvState == self->lastEvState)
		return;
		
	OSReport("Event state changed from %d to %d\n", self->lastEvState, newEvState);
	
	u8 offState;
	if (newEvState == ACTIVATE)
	{
		offState = (newEvState == 1) ? 1 : 0;
		OSReport("Activate Special Event!", offState);

		switch (self->type) {
			case 1:											// Time Freeze
				TimeStopFlag = self->effect * 0x100;
				break;
				
			case 2:											// Stop Timer
				TimerBranch = 0x7C601B78;
				break;
		
	
			case 3:											// Mario Gravity
				if (self->effect == 0)
				{											//Low grav
					MarioDescentRate = -2;
					MarioJumpArc = 0.5;
					MiniMarioJumpArc = 0.5;
					MarioJumpMax = 4.5;
				}
				else
				{											//Anti-grav
					MarioDescentRate = 0.5;
					MarioJumpArc = 4.0;
					MiniMarioJumpArc = 4.0;
					MarioJumpMax = 0.0;
				}
				break;
	
			case 4:											// Mario Size
				dAc_Py_c *Mario;
				if (self->effect == 0)							//Super Size
					{
					MarioSize = 4.0;
					
					for(int n=0; n<4; n++) {
						OSReport("Changing Physics for Player %d\n", n);
						Mario = GetSpecificPlayerActor(n);
						OSReport("Player Actor at %08x\n", Mario);
//						Mario->aPhysics.info.xDistToCenter = Mario->aPhysics.info.xDistToCenter * 4.0;
//						Mario->aPhysics.info.xDistToEdge = Mario->aPhysics.info.xDistToEdge * 4.0;
//						Mario->aPhysics.info.yDistToCenter = Mario->aPhysics.info.yDistToCenter * 4.0;
//						Mario->aPhysics.info.yDistToEdge = Mario->aPhysics.info.yDistToEdge * 4.0;
//
						Mario->bPhysics.info.xDistToCenter = Mario->bPhysics.info.xDistToCenter * 4.0;
						Mario->bPhysics.info.xDistToEdge = Mario->bPhysics.info.xDistToEdge * 4.0;
						Mario->bPhysics.info.yDistToCenter = Mario->bPhysics.info.yDistToCenter * 4.0;
						Mario->bPhysics.info.yDistToEdge = Mario->bPhysics.info.yDistToEdge * 4.0;
//
//						Mario->cPhysics.info.xDistToCenter = Mario->cPhysics.info.xDistToCenter * 4.0;
//						Mario->cPhysics.info.xDistToEdge = Mario->cPhysics.info.xDistToEdge * 4.0;
//						Mario->cPhysics.info.yDistToCenter = Mario->cPhysics.info.yDistToCenter * 4.0;
//						Mario->cPhysics.info.yDistToEdge = Mario->cPhysics.info.yDistToEdge * 4.0;
//
//						Mario->dPhysics.info.xDistToCenter = Mario->dPhysics.info.xDistToCenter * 4.0;
//						Mario->dPhysics.info.xDistToEdge = Mario->dPhysics.info.xDistToEdge * 4.0;
//						Mario->dPhysics.info.yDistToCenter = Mario->dPhysics.info.yDistToCenter * 4.0;
//						Mario->dPhysics.info.yDistToEdge = Mario->dPhysics.info.yDistToEdge * 4.0;
//
//						Mario->ePhysics.info.xDistToCenter = Mario->ePhysics.info.xDistToCenter * 4.0;
//						Mario->ePhysics.info.xDistToEdge = Mario->ePhysics.info.xDistToEdge * 4.0;
//						Mario->ePhysics.info.yDistToCenter = Mario->ePhysics.info.yDistToCenter * 4.0;
//						Mario->ePhysics.info.yDistToEdge = Mario->ePhysics.info.yDistToEdge * 4.0;
					}
					}
					
				else											//Half-Pint
					{
					MarioSize = 0.25;

					for(int n=0; n<4; n++) {
						Mario = GetSpecificPlayerActor(n);
						Mario->aPhysics.info.xDistToCenter = Mario->aPhysics.info.xDistToCenter * 0.25;
						Mario->aPhysics.info.xDistToEdge = Mario->aPhysics.info.xDistToEdge * 0.25;
						Mario->aPhysics.info.yDistToCenter = Mario->aPhysics.info.yDistToCenter * 0.25;
						Mario->aPhysics.info.yDistToEdge = Mario->aPhysics.info.yDistToEdge * 0.25;

						Mario->bPhysics.info.xDistToCenter = Mario->bPhysics.info.xDistToCenter * 0.25;
						Mario->bPhysics.info.xDistToEdge = Mario->bPhysics.info.xDistToEdge * 0.25;
						Mario->bPhysics.info.yDistToCenter = Mario->bPhysics.info.yDistToCenter * 0.25;
						Mario->bPhysics.info.yDistToEdge = Mario->bPhysics.info.yDistToEdge * 0.25;

						Mario->cPhysics.info.xDistToCenter = Mario->cPhysics.info.xDistToCenter * 0.25;
						Mario->cPhysics.info.xDistToEdge = Mario->cPhysics.info.xDistToEdge * 0.25;
						Mario->cPhysics.info.yDistToCenter = Mario->cPhysics.info.yDistToCenter * 0.25;
						Mario->cPhysics.info.yDistToEdge = Mario->cPhysics.info.yDistToEdge * 0.25;

						Mario->dPhysics.info.xDistToCenter = Mario->dPhysics.info.xDistToCenter * 0.25;
						Mario->dPhysics.info.xDistToEdge = Mario->dPhysics.info.xDistToEdge * 0.25;
						Mario->dPhysics.info.yDistToCenter = Mario->dPhysics.info.yDistToCenter * 0.25;
						Mario->dPhysics.info.yDistToEdge = Mario->dPhysics.info.yDistToEdge * 0.25;

						Mario->ePhysics.info.xDistToCenter = Mario->ePhysics.info.xDistToCenter * 0.25;
						Mario->ePhysics.info.xDistToEdge = Mario->ePhysics.info.xDistToEdge * 0.25;
						Mario->ePhysics.info.yDistToCenter = Mario->ePhysics.info.yDistToCenter * 0.25;
						Mario->ePhysics.info.yDistToEdge = Mario->ePhysics.info.yDistToEdge * 0.25;
					}
					}
				break;


			case 5:											// Global Enemy Size
				SizerOn = 3;

				GlobalSpriteSize = GlobalSizeFloatModifications[self->effect];
				GlobalRiderSize = GlobalRiderFloatModifications[self->effect];
				GlobalSpriteSpeed = GlobalRiderFloatModifications[self->effect];

				AlwaysDrawFlag = 0x38600001;
				AlwaysDrawBranch = 0x4E800020;
				break;
	
			case 6:											// Individual Enemy Size
				AlwaysDrawFlag = 0x38600001;
				AlwaysDrawBranch = 0x4E800020;

				if (self->effect == 0)
				{	
					SizerOn = 1;							// Nyb 5
				}
				else
				{											
					SizerOn = 2;							// Nyb 7
				}
				break;
		
			case 7:											// Z Order Hack
				ZOrderOn = 1;
				break;

			default:
				break;
		}
	}
	
	else
	{
		offState = (newEvState == 1) ? 0 : 1;
		OSReport("Deactivate Special Event", offState);

		switch (self->type) {
			case 1:											// Time Freeze
				TimeStopFlag = 0;
				break;
				
			case 2:											// Stop Timer
				TimerBranch = 0x3403FFA4;
				break;
		
	
			case 3:											// Mario Gravity
				MarioDescentRate = -4;
				MarioJumpArc = 2.5;
				MiniMarioJumpArc = 2.5;
				MarioJumpMax = 3.628;
				break;
	
			case 4:											// Mario Size
				dAc_Py_c *Mario;
//				if (self->effect == 0)							//Super Size
//					{
//					MarioSize = 4.0;
//					
//					for(int n=0; n<4; n++) {
//						OSReport("Changing Physics for Player %d\n", n);
//						Mario = GetSpecificPlayerActor(n);
//						OSReport("Player Actor at %08x\n", Mario);
//						Mario->aPhysics.info.xDistToCenter = Mario->aPhysics.info.xDistToCenter / 4.0;
//						Mario->aPhysics.info.xDistToEdge = Mario->aPhysics.info.xDistToEdge / 4.0;
//						Mario->aPhysics.info.yDistToCenter = Mario->aPhysics.info.yDistToCenter / 4.0;
//						Mario->aPhysics.info.yDistToEdge = Mario->aPhysics.info.yDistToEdge / 4.0;
//
//						Mario->bPhysics.info.xDistToCenter = Mario->bPhysics.info.xDistToCenter / 4.0;
//						Mario->bPhysics.info.xDistToEdge = Mario->bPhysics.info.xDistToEdge / 4.0;
//						Mario->bPhysics.info.yDistToCenter = Mario->bPhysics.info.yDistToCenter / 4.0;
//						Mario->bPhysics.info.yDistToEdge = Mario->bPhysics.info.yDistToEdge / 4.0;
//
//						Mario->cPhysics.info.xDistToCenter = Mario->cPhysics.info.xDistToCenter / 4.0;
//						Mario->cPhysics.info.xDistToEdge = Mario->cPhysics.info.xDistToEdge / 4.0;
//						Mario->cPhysics.info.yDistToCenter = Mario->cPhysics.info.yDistToCenter / 4.0;
//						Mario->cPhysics.info.yDistToEdge = Mario->cPhysics.info.yDistToEdge / 4.0;
//
//						Mario->dPhysics.info.xDistToCenter = Mario->dPhysics.info.xDistToCenter / 4.0;
//						Mario->dPhysics.info.xDistToEdge = Mario->dPhysics.info.xDistToEdge / 4.0;
//						Mario->dPhysics.info.yDistToCenter = Mario->dPhysics.info.yDistToCenter / 4.0;
//						Mario->dPhysics.info.yDistToEdge = Mario->dPhysics.info.yDistToEdge / 4.0;
//
//						Mario->ePhysics.info.xDistToCenter = Mario->ePhysics.info.xDistToCenter / 4.0;
//						Mario->ePhysics.info.xDistToEdge = Mario->ePhysics.info.xDistToEdge / 4.0;
//						Mario->ePhysics.info.yDistToCenter = Mario->ePhysics.info.yDistToCenter / 4.0;
//						Mario->ePhysics.info.yDistToEdge = Mario->ePhysics.info.yDistToEdge / 4.0;
//					}
//					}
//					
//				else											//Half-Pint
//					{
//					MarioSize = 0.25;
//
//					for(int n=0; n<4; n++) {
//						Mario = GetSpecificPlayerActor(n);
//						Mario->aPhysics.info.xDistToCenter = Mario->aPhysics.info.xDistToCenter / 0.25;
//						Mario->aPhysics.info.xDistToEdge = Mario->aPhysics.info.xDistToEdge / 0.25;
//						Mario->aPhysics.info.yDistToCenter = Mario->aPhysics.info.yDistToCenter / 0.25;
//						Mario->aPhysics.info.yDistToEdge = Mario->aPhysics.info.yDistToEdge / 0.25;
//
//						Mario->bPhysics.info.xDistToCenter = Mario->bPhysics.info.xDistToCenter / 0.25;
//						Mario->bPhysics.info.xDistToEdge = Mario->bPhysics.info.xDistToEdge / 0.25;
//						Mario->bPhysics.info.yDistToCenter = Mario->bPhysics.info.yDistToCenter / 0.25;
//						Mario->bPhysics.info.yDistToEdge = Mario->bPhysics.info.yDistToEdge / 0.25;
//
//						Mario->cPhysics.info.xDistToCenter = Mario->cPhysics.info.xDistToCenter / 0.25;
//						Mario->cPhysics.info.xDistToEdge = Mario->cPhysics.info.xDistToEdge / 0.25;
//						Mario->cPhysics.info.yDistToCenter = Mario->cPhysics.info.yDistToCenter / 0.25;
//						Mario->cPhysics.info.yDistToEdge = Mario->cPhysics.info.yDistToEdge / 0.25;
//
//						Mario->dPhysics.info.xDistToCenter = Mario->dPhysics.info.xDistToCenter / 0.25;
//						Mario->dPhysics.info.xDistToEdge = Mario->dPhysics.info.xDistToEdge / 0.25;
//						Mario->dPhysics.info.yDistToCenter = Mario->dPhysics.info.yDistToCenter / 0.25;
//						Mario->dPhysics.info.yDistToEdge = Mario->dPhysics.info.yDistToEdge / 0.25;
//
//						Mario->ePhysics.info.xDistToCenter = Mario->ePhysics.info.xDistToCenter / 0.25;
//						Mario->ePhysics.info.xDistToEdge = Mario->ePhysics.info.xDistToEdge / 0.25;
//						Mario->ePhysics.info.yDistToCenter = Mario->ePhysics.info.yDistToCenter / 0.25;
//						Mario->ePhysics.info.yDistToEdge = Mario->ePhysics.info.yDistToEdge / 0.25;
//					}
//					}
				break;
		
			case 5:											// Global Enemy Size
				SizerOn = 0;

				GlobalSpriteSize = 1.0;
				GlobalRiderSize = 1.0;
				GlobalSpriteSpeed = 1.0;

				AlwaysDrawFlag = 0x9421FFF0;
				AlwaysDrawBranch = 0x7C0802A6;
				break;

			case 6:											// Individual Enemy Size
				SizerOn = 0;

				AlwaysDrawFlag = 0x9421FFF0;
				AlwaysDrawBranch = 0x7C0802A6;
				break;
		
			case 7:											// Z Order Hack
				ZOrderOn = 0;
				break;
				
			default:
				break;
		}
	}
	OSReport("Special Event is %d\n", offState);




	OSReport("Success!\n");
	
	
	self->lastEvState = newEvState;
}