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
459
460
461
462
463
464
465
466
467
468
469
470
471
|
#include "koopatlas/shop.h"
int getStarCoinCountShop() {
SaveBlock *save = GetSaveFile()->GetBlock(-1);
int coinsSpent = save->credits_hiscore;
int coinsEarned = 0;
for (int w = 0; w < 10; w++) {
for (int l = 0; l < 10; l++) {
u32 conds = save->GetLevelCondition(w, l);
if (conds & COND_COIN1) { coinsEarned++; }
if (conds & COND_COIN2) { coinsEarned++; }
if (conds & COND_COIN3) { coinsEarned++; }
}
}
int coinsLeft = coinsEarned - coinsSpent;
return coinsLeft;
}
const char* Produce[10][4] = {
{ "I_kinoko", "g3d/I_kinoko.brres", "I_kinoko", "wait2" },
{ "I_fireflower", "g3d/I_fireflower.brres", "I_fireflower", "wait2" },
{ "I_iceflower", "g3d/I_iceflower.brres", "I_iceflower", "wait2" },
{ "I_penguin", "g3d/I_penguin.brres", "I_penguin", "wait2" },
{ "I_propeller", "g3d/I_propeller_model.brres", "I_propeller_model", "wait2" },
{ "I_kinoko_bundle","g3d/I_mini_kinoko.brres", "I_mini_kinoko", "wait2" },
{ "I_star", "g3d/I_star.brres", "I_star", "wait2" },
{ "I_hammer", "g3d/I_hammer.brres", "I_hammer", "wait2" },
{ "I_kinoko_bundle","g3d/I_life_kinoko.brres", "I_life_kinoko", "wait2" },
{ "obj_coin", "g3d/obj_coin.brres", "obj_coin", "wait2" }
};
/*****************************************************************************/
// Shop Model
class dShopItem: public dActor_c {
public:
int onCreate();
int onDelete();
int onExecute();
int onDraw();
int p;
mHeapAllocator_c allocator;
nw4r::g3d::ResFile resFile;
m3d::mdl_c bodyModel;
m3d::anmChr_c aw;
static dShopItem *build();
};
dShopItem *dShopItem::build() {
void *buffer = AllocFromGameHeap1(sizeof(dShopItem));
return new(buffer) dShopItem;
}
int dShopItem::onCreate() {
// Settings
p = settings & 0xF;
// Model creation
allocator.link(-1, GameHeaps[0], 0, 0x20);
resFile.data = getResource(Produce[p][0], Produce[p][1]);
nw4r::g3d::ResMdl mdl = resFile.GetResMdl(Produce[p][2]);
bodyModel.setup(mdl, &allocator, 0x224, 1, 0);
SetupTextures_Item(&bodyModel, 0); // 800B42B0
// Animation Assignment
nw4r::g3d::ResAnmChr anmChr = resFile.GetResAnmChr("wait2");
aw.setup(mdl, anmChr, &allocator, 0);
aw.bind(&bodyModel, anmChr, 1);
bodyModel.bindAnim(&aw, 0.0);
aw.setUpdateRate(1.0);
allocator.unlink();
return true;
}
int dShopItem::onDelete() { return true; }
int dShopItem::onExecute() { return true; }
int dShopItem::onDraw() {
if (p == 9) { matrix.translation(pos.x, pos.y + (8.0 * scale.y), pos.z); }
else { matrix.translation(pos.x, pos.y, pos.z); }
matrix.applyRotationYXZ(&rot.x, &rot.y, &rot.z);
bodyModel.setDrawMatrix(matrix);
bodyModel.setScale(&scale);
bodyModel.calcWorld(false);
bodyModel.scheduleForDrawing();
bodyModel._vf1C();
if(this->aw.isAnimationDone())
this->aw.setCurrentFrame(0.0);
return true;
}
/*****************************************************************************/
// Shop Layout
//
const char* Lakitu[10] = {
"g3d/yoshi.brres", "g3d/desert.brres", "g3d/mountain.brres", "g3d/sakura.brres", "g3d/santa.brres",
"g3d/ghost.brres", "g3d/space.brres", "g3d/koopa.brres", "g3d/sewer.brres", "g3d/goldwood.brres"
};
dWMShop_c *dWMShop_c::instance = 0;
dWMShop_c *dWMShop_c::build() {
void *buffer = AllocFromGameHeap1(sizeof(dWMShop_c));
dWMShop_c *c = new(buffer) dWMShop_c;
instance = c;
return c;
}
dWMShop_c::dWMShop_c() {
layoutLoaded = false;
isHidden = true;
}
int dWMShop_c::onCreate() {
if (!layoutLoaded) {
bool gotFile = layout.loadArc("shop.arc", false);
if (!gotFile)
return false;
currentItem = 0;
static const char *brlanNames[5] = {"shop_hitButton.brlan", "shop_offButton.brlan", "shop_onButton.brlan", "shop_inWindow.brlan", "shop_outWindow.brlan"};
static const char *groupNames[20] = {"B00_Button", "B01_Button", "B02_Button", "B03_Button", "B05_Button", "B08_Button",
"B00_Button", "B01_Button", "B02_Button", "B03_Button", "B05_Button", "B08_Button",
"B00_Button", "B01_Button", "B02_Button", "B03_Button", "B05_Button", "B08_Button",
"A00_Window", "A00_Window"};
bool output = layout.build("shop.brlyt");
if (!IsWideScreen()) {
layout.clippingEnabled = true;
layout.clipX = 0;
layout.clipY = 52;
layout.clipWidth = 640;
layout.clipHeight = 352;
layout.layout.rootPane->scale.x = 0.7711f;
layout.layout.rootPane->scale.y = 0.7711f;
}
layout.loadAnimations(brlanNames, 5);
layout.loadGroups(groupNames, (int[20]){0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 4}, 20);
layout.disableAllAnimations();
for (int i = 6; i < 12; i++) {
layout.enableNonLoopAnim(i);
}
layout.drawOrder = 0x01;
layoutLoaded = true;
}
return true;
}
int dWMShop_c::onDelete() {
return layout.free();
}
int dWMShop_c::onExecute() {
layout.execAnimations();
layout.update();
if (!isHidden) {
int nowPressed = Remocon_GetPressed(GetActiveRemocon());
if (!layout.isAnyAnimOn()) {
if (nowPressed & WPAD_B) {
MapSoundPlayer(SoundRelatedClass, SE_SYS_DIALOGUE_OUT_AUTO, 1);
CloseUpShop();
} else if (nowPressed & WPAD_DOWN) {
if (currentItem == 6) { return true; }
MapSoundPlayer(SoundRelatedClass, SE_SYS_CURSOR, 1);
int last = currentItem;
if (currentItem == 0) { currentItem = 1; }
else if (currentItem < 5) { currentItem = 5; }
else { currentItem = 6; }
changeItem(last, currentItem);
} else if (nowPressed & WPAD_UP) {
if (currentItem == 0) { return true; }
MapSoundPlayer(SoundRelatedClass, SE_SYS_CURSOR, 1);
int last = currentItem;
if (currentItem < 5) { currentItem = 0; }
else if (currentItem == 5) { currentItem = 1; }
else { currentItem = 5; }
changeItem(last, currentItem);
} else if (nowPressed & WPAD_RIGHT) {
if (currentItem == 6) { currentItem = 6; return true; }
MapSoundPlayer(SoundRelatedClass, SE_SYS_CURSOR, 1);
int last = currentItem;
currentItem += 1;
changeItem(last, currentItem);
} else if (nowPressed & WPAD_LEFT) {
if (currentItem == 0) { return true; }
MapSoundPlayer(SoundRelatedClass, SE_SYS_CURSOR, 1);
int last = currentItem;
currentItem -= 1;
changeItem(last, currentItem);
} else if (nowPressed & WPAD_TWO) {
BuyItem(currentItem);
}
}
shopkeep._vf1C();
}
return true;
}
int dWMShop_c::onDraw() {
if (isHidden) {
if (layout.isAnimOn(19)) { layout.scheduleForDrawing(); }
}
if (!isHidden) {
layout.scheduleForDrawing();
}
return true;
}
void dWMShop_c::specialDraw1() {
if (!isHidden) {
// Vec pos = {250.0f, 170.0f, -1000.0f};
// S16Vec rot = {0,0,0};
// Vec scale = {1.0f, 1.0f, 1.0f};
// matrix.translation(pos.x, pos.y, pos.z);
// matrix.applyRotationYXZ(&rot.x, &rot.y, &rot.z);
// shopkeep.setDrawMatrix(matrix);
// shopkeep.setScale(&scale);
// shopkeep.calcWorld(false);
// shopkeep.scheduleForDrawing();
// if(this->ska.isAnimationDone())
// this->ska.setCurrentFrame(0.0);
}
return;
}
void dWMShop_c::changeItem(int last, int current) {
if (last) { layout.enableNonLoopAnim(last - 1 + 6); }
if (current) { layout.enableNonLoopAnim(current - 1 + 12); }
}
// Powerup Listing:
// 0 = Mushroom - 1
// 1 = Fireflower - 2
// 2 = Iceflower - 2
// 3 = Penguin - 3
// 4 = Propeller - 3
// 5 = MiniShroom - 2
// 6 = Starman - 2
// 7 = Hammer - 3
// 8 = 1-ups - 2
// 9 = Coins - 1
//
// Format: 1coin, 1coin, 2coins, 3coins, 5coins[3] (Value 6-9), 8coins[5] (Value 10-15)
//
// Possible 5 coin combos = 2,2,2 / 1,2,3 / 2,3,2 / 3,2,3 / 3,3,3
// Possible 8 coin combos = 1,1,2,3,3 / 1,2,2,3,3 / 1,2,3,3,3 / 2,2,2,3,3 / 2,2,3,3,3 / 1,3,3,3,3 / 2,3,3,3,3 / 3,3,3,3,3
int Inventory[10][12] = {
{ 9, 0, 1, 4, 1, 2, 1, 0, 0, 8, 4, 4 }, // Yoshi Island Shop
{ 9, 0, 1, 4, 1, 6, 1, 0, 1, 1, 4, 4 }, // Desert Shop
{ 9, 0, 5, 4, 0, 5, 4, 0, 5, 4, 4, 7 }, // Mountain Shop
{ 9, 0, 8, 7, 8, 8, 8, 4, 2, 8, 1, 4 }, // Japan Shop
{ 9, 0, 2, 3, 2, 3, 2, 2, 3, 3, 3, 2 }, // FreezeFlame Shop
{ 9, 0, 6, 4, 5, 4, 5, 4, 4, 9, 4, 4 }, // Ghost Shop
{ 9, 0, 6, 7, 6, 6, 6, 7, 7, 8, 7, 7 }, // Space Shop
{ 0, 8, 4, 7, 7, 4, 7, 4, 7, 4, 7, 4 }, // Koopa Shop
{ 9, 0, 1, 3, 0, 0, 0, 0, 0, 0, 0, 0 }, // Sewer Shop?
{ 0, 8, 1, 5, 1, 4, 1, 1, 1, 6, 1, 1 }, // Goldwood Shop
};
void dWMShop_c::LoadShopForWorld(int world) {
if (!isHidden) {
return; }
// Handle showing it
MapSoundPlayer(SoundRelatedClass, SE_SYS_DIALOGUE_IN, 1);
isHidden = false;
layout.enableNonLoopAnim(18);
// Model creation
allocator.link(-1, GameHeaps[0], 0, 0x20);
res.data = getResource("lakitu", Lakitu[world]);
nw4r::g3d::ResMdl mdl = res.GetResMdl("lakitu");
shopkeep.setup(mdl, &allocator, 0x224, 1, 0);
SetupTextures_Item(&shopkeep, 1);
// Animation Assignment (idle, notenough)
nw4r::g3d::ResAnmChr anmChr = res.GetResAnmChr("idle");
ska.setup(mdl, anmChr, &allocator, 0);
ska.bind(&shopkeep, anmChr, 1);
shopkeep.bindAnim(&ska, 0.0);
ska.setUpdateRate(1.0);
allocator.unlink();
Vec pos = {layout.posX, layout.posY, 40000.0};
// Setup all the item buttons for sale
// itemA = (dShopItem*)CreateChildObject(WM_SHOPITEM, this, Inventory[world][0], 0, 0);
// itemB = (dShopItem*)CreateChildObject(WM_SHOPITEM, this, Inventory[world][1], 0, 0);
// itemC = (dShopItem*)CreateChildObject(WM_SHOPITEM, this, Inventory[world][2], 0, 0);
// itemD = (dShopItem*)CreateChildObject(WM_SHOPITEM, this, Inventory[world][3], 0, 0);
// itemEA = (dShopItem*)CreateChildObject(WM_SHOPITEM, this, Inventory[world][4], 0, 0);
// itemEB = (dShopItem*)CreateChildObject(WM_SHOPITEM, this, Inventory[world][5], 0, 0);
// itemEC = (dShopItem*)CreateChildObject(WM_SHOPITEM, this, Inventory[world][6], 0, 0);
// itemFA = (dShopItem*)CreateChildObject(WM_SHOPITEM, this, Inventory[world][7], 0, 0);
// itemFB = (dShopItem*)CreateChildObject(WM_SHOPITEM, this, Inventory[world][8], 0, 0);
// itemFC = (dShopItem*)CreateChildObject(WM_SHOPITEM, this, Inventory[world][9], 0, 0);
// itemFD = (dShopItem*)CreateChildObject(WM_SHOPITEM, this, Inventory[world][10], 0, 0);
// itemFE = (dShopItem*)CreateChildObject(WM_SHOPITEM, this, Inventory[world][11], 0, 0);
}
void dWMShop_c::CloseUpShop() {
isHidden = true;
layout.enableNonLoopAnim(19);
changeItem(currentItem, 0);
currentItem = 0;
// itemA->Delete();
// itemB->Delete();
// itemC->Delete();
// itemD->Delete();
// itemEA->Delete();
// itemEB->Delete();
// itemEC->Delete();
// itemFA->Delete();
// itemFB->Delete();
// itemFC->Delete();
// itemFD->Delete();
// itemFE->Delete();
}
void dWMShop_c::BuyItem(int item) {
OSReport("Buy item %d", item);
if (item == 0) {
MapSoundPlayer(SoundRelatedClass, SE_SYS_INVALID, 1);
return;
}
layout.enableNonLoopAnim(item-1);
int cash = getStarCoinCountShop();
int cost;
int Powerups[10];
Powerups[0] = 0; // Mushroom
Powerups[1] = 0; // Fireflower
Powerups[2] = 0; // Iceflower
Powerups[3] = 0; // Penguin
Powerups[4] = 0; // Propeller
Powerups[5] = 0; // MiniShroom
Powerups[6] = 0; // Starman
Powerups[7] = 0; // Hammer
Powerups[8] = 0; // 1-ups
Powerups[9] = 0; // Coins
switch(item) {
case 1:
cost = 1;
Powerups[Inventory[world][item-1]]++;
break;
case 2:
cost = 1;
Powerups[Inventory[world][item-1]]++;
break;
case 3:
cost = 2;
Powerups[Inventory[world][item-1]]++;
break;
case 4:
cost = 3;
Powerups[Inventory[world][item-1]]++;
break;
case 5:
cost = 5;
Powerups[Inventory[world][item-1]]++;
Powerups[Inventory[world][item+0]]++;
Powerups[Inventory[world][item+1]]++;
break;
case 6:
cost = 8;
Powerups[Inventory[world][item+1]]++;
Powerups[Inventory[world][item+2]]++;
Powerups[Inventory[world][item+3]]++;
Powerups[Inventory[world][item+4]]++;
Powerups[Inventory[world][item+5]]++;
break;
}
if (cost > cash) {
MapSoundPlayer(SoundRelatedClass, SE_SYS_INVALID, 1);
return;
}
MapSoundPlayer(SoundRelatedClass, SE_SYS_DECIDE, 1);
SaveFile *file = GetSaveFile();
SaveBlock *block = file->GetBlock(file->header.current_file);
block->credits_hiscore += cost;
for (int i = 0; i < 7; i++) { // Change this to 8 to support hammers
block->powerups_available[i] = block->powerups_available[i] + Powerups[i];
if (block->powerups_available[i] > 99) { block->powerups_available[i] = 99; }
}
for (int i = 0; i < 4; i++) { // Make sure all players get the reward!
block->player_coins[i] = (Powerups[9] * 50) + block->player_coins[i];
for (;block->player_coins[i] < 100; block->player_coins[i] - 100) {
block->player_coins[i] = 1 + block->player_coins[i];
}
block->player_lives[i] = Powerups[8] + block->player_lives[i];
if (block->player_lives[i] > 99) { block->player_lives[i] = 99; }
}
CloseUpShop();
return;
}
|