Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
events.c
Go to the documentation of this file.
1#include "engine/game.h"
2#include "field/field_map.h"
3
4/* Whether bit `index` of a bitset is set (set != 0) or clear (set 0) */
5s32 testBit(u8 *bits, s32 index, s32 set) {
6 s32 byte = index >> 3;
7 s32 mask = 1 << (index & 7);
8
9 if (set != 0) {
10 return (bits[byte] & mask) != 0;
11 }
12 return (bits[byte] & mask) == 0;
13}
14
15/* Sets or clears bit `index` of a bitset */
16void setBit(u8 *bits, s32 index, s32 set) {
17 s32 byte = index >> 3;
18 s32 mask = 1 << (index & 7);
19
20 if (set) {
21 bits[byte] |= mask;
22 } else {
23 bits[byte] &= ~mask;
24 }
25}
26
27/* Special condition 0x00: the player has every item of a set (the European
28 and Japanese versions have a second set) */
30 s32 ret = 0;
31
32#if VERSION_US
33 if ((GAME.items[7] != 0 || GAME.equippedItems[7] != 0) &&
34 (GAME.items[0x59] != 0 || GAME.equippedItems[0x59] != 0) &&
35 (GAME.items[0xA7] != 0 || GAME.equippedItems[0xA7] != 0)) {
36 ret = 1;
37 }
38#elif VERSION_EU || VERSION_JP
39 switch (op) {
40 case 0:
41 if ((GAME.items[7] != 0 || GAME.equippedItems[7] != 0) &&
42 (GAME.items[0x59] != 0 || GAME.equippedItems[0x59] != 0) &&
43 (GAME.items[0xA7] != 0 || GAME.equippedItems[0xA7] != 0)) {
44 ret = 1;
45 }
46 break;
47 case 1:
48 if ((GAME.items[0x69] != 0 || GAME.equippedItems[0x69] != 0) &&
49 (GAME.items[0x77] != 0 || GAME.equippedItems[0x77] != 0) &&
50 (GAME.items[0x83] != 0 || GAME.equippedItems[0x83] != 0) &&
51 (GAME.items[0x90] != 0 || GAME.equippedItems[0x90] != 0) &&
52 (GAME.items[0x9C] != 0 || GAME.equippedItems[0x9C] != 0)) {
53 ret = 1;
54 }
55 break;
56 }
57#endif
58 return ret;
59}
60
61/*
62 * Special conditions 0x10: tests partners (unlocked, in the party, levels) or unlocks one; the
63 * European and Japanese versions add four
64 */
66 s32 result = 0;
67 s32 i;
68 s32 total;
69 s32 id;
70#if VERSION_EU || VERSION_JP
71 s32 partner;
72#endif
73
74 switch (op) {
75 case 0:
76 if (GAME.partySet == arg) {
77 result = 1;
78 }
79 break;
80 case 1:
81 if (GAME.partners[arg].unlocked != 0) {
82 result = 1;
83 }
84 break;
85 case 2:
86 for (i = 0; i < PARTY_SIZE; i++) {
87 if (GAME.funcs.getPartyMember(i) == arg) {
88 result = 1;
89 break;
90 }
91 }
92 break;
93 case 3:
94 GAME.partners[arg].unlocked = arg + 3;
95 result = 1;
96 break;
97 case 4:
98 if (GAME.partners[arg].unlocked != 0 && GAME.partners[arg].info.stats[STAT_LEVEL] >= 0x2D) {
99 result = 1;
100 }
101 break;
102 case 5:
103 total = 0;
104 for (i = 0; i < PARTY_SIZE; i++) {
105 id = GAME.funcs.getPartyMember(i);
106 if (id >= 0) {
108 }
109 }
110 if (total >= arg * 15 + 30) {
111 result = 1;
112 }
113 break;
114 case 6:
115 if (GAME.partners[arg].unlocked == 0) {
116 result = 1;
117 }
118 break;
119#if VERSION_EU || VERSION_JP
120 case 7:
121 result = 1;
122 for (id = 0; id < PARTNER_COUNT; id++) {
123 if (GAME.partners[id].unlocked != 0 && GAME.partners[id].info.stats[STAT_LEVEL] < 0x2D) {
124 result = 0;
125 break;
126 }
127 }
128 break;
129 case 8:
130 for (i = 0; i < PARTY_SIZE; i++) {
131 partner = GAME.funcs.getPartyMember(i);
132 if (partner >= 0) {
135 }
136 }
137 result = 1;
138 break;
139 case 9:
144 result = 1;
145 }
146 break;
147#endif
148 }
149 return result;
150}
151
152/*
153 * Special conditions 0x20: whether the player has MONEY_REQUIRED[item], or gives or takes an
154 * amount
155 */
157 s32 ret = 0;
158
159 switch (op) {
160 case 0:
161 if (MONEY_REQUIRED[item] <= GAME.money) {
162 ret = 1;
163 }
164 break;
165 case 1:
166 GAME.money += MONEY_GAINS[item];
167 if (GAME.money > MONEY_MAX) {
169 }
170 break;
171 case 2:
172 GAME.money -= MONEY_LOSSES[item];
173 if (GAME.money < 0) {
174 GAME.money = 0;
175 }
176 break;
177 }
178 return ret;
179}
180
181/* Special conditions 0x30: whether GAME.progress is within PROGRESS_RANGES[index] */
183 s32 value = GAME.progress;
184 s32 min = PROGRESS_RANGES[index][0];
185 s32 max = PROGRESS_RANGES[index][1];
186 s32 ret = 0;
187
188 if (value >= min) {
189 ret = max >= value;
190 }
191 return ret;
192}
193
194#if VERSION_US
195/* Special conditions 0x40: counts flags 0x27-0x2D of GAME.flags1C; mode 0 is whether any is set,
196 1 whether two or more are clear, 2 whether exactly one is clear */
197s32 checkFlagCount(s32 unused, s32 mode) {
198 s32 ret = 0;
199 s32 on = 0;
200 s32 off = 0;
201 s32 i;
202
203 for (i = 0x27; i < 0x2E; i++) {
204 if (testBit(GAME.flags1C, i, 1) != 0) {
205 on++;
206 } else {
207 off++;
208 }
209 }
210 switch (mode) {
211 case 0:
212 if (on != 0) {
213 ret = 1;
214 }
215 break;
216 case 1:
217 if (off >= 2) {
218 ret = 1;
219 }
220 break;
221 case 2:
222 if (off == 1) {
223 ret = 1;
224 }
225 break;
226 }
227 return ret;
228}
229#elif VERSION_EU || VERSION_JP
230/* Special conditions 0x40: group 0 as in the USA version; group 1 whether four flags of group 0x10 are set */
231s32 checkFlagCount(s32 group, s32 mode) {
232 s32 ret = 0;
233 s32 on = 0;
234 s32 off = 0;
235 s32 i;
236
237 switch (group) {
238 case 0:
239 for (i = 0x27; i < 0x2E; i++) {
240 if (testBit(GAME.flags1C, i, 1) != 0) {
241 on++;
242 } else {
243 off++;
244 }
245 }
246 switch (mode) {
247 case 0:
248 if (on != 0) {
249 ret = 1;
250 }
251 break;
252 case 1:
253 if (off >= 2) {
254 ret = 1;
255 }
256 break;
257 case 2:
258 if (off == 1) {
259 ret = 1;
260 }
261 break;
262 }
263 break;
264 case 1:
265 if (testBit(GAME.flags10, 0xD, 1) && testBit(GAME.flags10, 0xE, 1) && testBit(GAME.flags10, 0xF, 1) &&
266 testBit(GAME.flags10, 0x10, 1)) {
267 ret = 1;
268 }
269 break;
270 }
271 return ret;
272}
273#endif
274
275/* Special condition 0x50: the field actor's icon (FIELDSTG's task 0x16, FIELD_TASK_ICON)
276 plays its animation 3, as event command 0x34A does */
278 Task *obj = TASK_REGISTRY.funcs.find(0x16, -1, -1);
279
280 obj->setSubstate(obj, 3);
281 return 1;
282}
283
284/* Runs SPECIAL_CONDITIONS entry `id`; whether its result equals `expected` */
286 SpecialCondition *cond;
287 s32 result = 0;
288 s32 op;
289 s32 arg;
290
291 for (cond = SPECIAL_CONDITIONS; cond->id != 0xFF; cond++) {
292 if (cond->id == id) {
293 op = cond->check & 0xF;
294 arg = cond->arg;
295 switch (cond->check & 0xF0) {
296 case 0x00:
297 result = checkItemSet(op, arg);
298 break;
299 case 0x10:
300 result = checkPartner(op, arg);
301 break;
302 case 0x20:
303 result = checkMoney(op, arg);
304 break;
305 case 0x30:
306 result = checkProgressRange(op, arg);
307 break;
308 case 0x40:
309 result = checkFlagCount(op, arg);
310 break;
311 case 0x50:
312 result = showActorIcon(op, arg);
313 break;
314 }
315 break;
316 }
317 }
318 return expected == result;
319}
320
321/* Conditions 0x60: whether GAME.progress is `value` (mode != 0) or not */
322s32 checkProgress(s32 value, s32 mode) {
323 if (mode != 0) {
324 if (GAME.progress == value) {
325 return 1;
326 }
327 } else {
328 if (GAME.progress != value) {
329 return 1;
330 }
331 }
332 return 0;
333}
334
335/*
336 * Conditions 0x80-0x8E: whether the player has item `index`, in the bag or equipped (mode != 0),
337 * or not
338 */
339s32 checkItem(s32 index, s32 mode) {
340 if (mode != 0) {
341 if (GAME.items[index] != 0 || GAME.equippedItems[index] != 0) {
342 return 1;
343 }
344 } else {
345 if (GAME.items[index] == 0 && GAME.equippedItems[index] == 0) {
346 return 1;
347 }
348 }
349 return 0;
350}
351
352/* Conditions 0x92: whether the player has card `item` (have != 0) or not */
353s32 checkCard(s32 card, s32 have) {
354 if (have != 0) {
355 if (GAME.cards[card] != 0) {
356 return 1;
357 }
358 } else {
359 if (GAME.cards[card] == 0) {
360 return 1;
361 }
362 }
363 return 0;
364}
365
366/*
367 * Conditions 0x72: whether the party's total of battle stat 5 reaches PARTY_STAT_THRESHOLDS[index]
368 * (mode != 0) or not
369 */
370s32 checkPartyStat(s32 index, s32 mode) {
371 PartnerTotals buf;
372 s32 total = 0;
373 s32 i;
374 s32 id;
375
376 for (i = 0; i < PARTY_SIZE; i++) {
377 id = GAME.funcs.getPartyMember(i);
378 if (id >= 0) {
379 GAME.funcs.computeStats(id, &buf);
380 total += buf.fields.battle[5];
381 }
382 }
383 if (mode != 0) {
384 if (total >= PARTY_STAT_THRESHOLDS[index]) {
385 return 1;
386 }
387 } else {
388 if (total < PARTY_STAT_THRESHOLDS[index]) {
389 return 1;
390 }
391 }
392 return 0;
393}
394
395/* Conditions 0x7E: the values a warp leaves for its stage (GAME.place for
396 ids under 30, GAME.placeArg above) */
398#if VERSION_US
399 if (id < 30) {
400 if (GAME.place == id + 1) {
401 return 1;
402 }
403 } else {
404 if (GAME.placeArg == id - 29) {
405 return 1;
406 }
407 }
408#elif VERSION_EU || VERSION_JP
409 /* mode zero: the opposite test, as checkProgress's */
410 if (id < 30) {
411 if (mode != 0) {
412 if (GAME.place == id + 1) {
413 return 1;
414 }
415 } else {
416 if (GAME.place != id + 1) {
417 return 1;
418 }
419 }
420 } else {
421 if (mode != 0) {
422 if (GAME.placeArg == id - 29) {
423 return 1;
424 }
425 } else {
426 if (GAME.placeArg != id - 29) {
427 return 1;
428 }
429 }
430 }
431#endif
432 return 0;
433}
434
435/* Takes item `item` off a partner (one of type 7 empties slots 2 and 3 both); 1 if it had it */
436s32 unequipItem(s32 partner, s32 item) {
437 PartnerStats *d = &GAME.partners[partner].info;
438 u8 *info = ITEM_FUNCS.get(item)->data.bytes;
439 s16 *equip = d->equip;
440 s32 i;
441
442 for (i = 0; i < 6; i++) {
443 if (equip[i] == item) {
444 if (info[2] == 7) {
445 d->equip[2] = 0;
446 d->equip[3] = 0;
447 } else {
448 equip[i] = 0;
449 }
450 return 1;
451 }
452 }
453 return 0;
454}
455
456/* Actions 0x80-0x8E: gives an item (up to 99) or takes one, from the bag or else off a partner */
457void changeItem(s32 item, s32 add) {
458 s32 i;
459
460 if (add != 0) {
461 if (++GAME.items[item] >= 100) {
462 GAME.items[item] = 99;
463 }
464 } else if (GAME.items[item] != 0) {
465 if (--GAME.items[item] < 0) {
466 GAME.items[item] = 0;
467 }
468 } else if (GAME.equippedItems[item] != 0) {
469 for (i = 0; i < PARTY_SIZE; i++) {
470 if (unequipItem(GAME.funcs.getPartyMember(i), item) != 0) {
471 goto found;
472 }
473 }
474 for (i = 0; i < PARTNER_COUNT; i++) {
475 if (GAME.partners[i].unlocked >= 3 && unequipItem(i, item) != 0) {
476 break;
477 }
478 }
479 found:
480 GAME.equippedItems[item]--;
481 }
482}
483
484/* Actions 0x92: gives or takes a copy of a card */
485void changeCard(s32 card, s32 add) {
486 if (add != 0) {
487 GAME.funcs.addCards(card, 1);
488 return;
489 }
490 GAME.cards[card]--;
491 if (GAME.cards[card] < 0) {
492 GAME.cards[card] = 0;
493 }
494}
495
496/* Actions 0x76 and 0x78: a card battle (MODE_CARD_GAME) against an opponent */
497void startCardBattle(s32 opponent, s32 kind) {
498 FIELDSTG_leaveField(MODE_CARD_GAME, opponent * 2 + kind + 1, 0, 0, 0);
499}
500
501/*
502 * Event scripts test conditions and run actions given as (code, value)
503 * pairs. code >> 9 picks the kind, code & 0x1FF the flag or item:
504 * groups 0x00-0x40 (code >> 8 & ~1): the flag bitsets FLAGS_00 and
505 * GAME.flags02-flags40
506 * 0x60 GAME.progress, 0x70 SPECIAL_CONDITIONS, 0x72 party stat totals,
507 * 0x80-0x8E items, 0x92 cards. A condition holds when it equals value.
508 */
509s32 checkCondition(u16 code, u16 value) {
510 u16 group = (code >> 8) & 0xFE;
511 s32 id = code & 0x1FF;
512 u16 arg = value;
513
514 if (group == 0x00) {
515 return testBit(FLAGS_00.bits, id, arg);
516 } else if (group == 0x02) {
517 return testBit(GAME.flags02, id, arg);
518 } else if (group == 0x04) {
519 return testBit(GAME.flags04, id, arg);
520 } else if (group == 0x06) {
521 return testBit(GAME.flags06, id, arg);
522 } else if (group == 0x08) {
523 return testBit(GAME.flags08, id, arg);
524 } else if (group == 0x0A) {
525 return testBit(GAME.flags0A, id, arg);
526 } else if (group == 0x0C) {
527 return testBit(GAME.flags0C, id, arg);
528 } else if (group == 0x0E) {
529 return testBit(GAME.flags0E, id, arg);
530 } else if (group == 0x10) {
531 return testBit(GAME.flags10, id, arg);
532 } else if (group == 0x18) {
533 return testBit(GAME.flags18, id, arg);
534 } else if (group == 0x1A) {
535 return testBit(GAME.flags1A, id, arg);
536 } else if (group == 0x1C) {
537 return testBit(GAME.flags1C, id, arg);
538 } else if (group == 0x20) {
539 return testBit(GAME.flags20, id, arg);
540 } else if (group == 0x40) {
541 return testBit(GAME.flags40, id, arg);
542 } else if (group == 0x60) {
543 return checkProgress(id, arg);
544 } else if (group == 0x70) {
545 return checkSpecialCondition(id, arg);
546 } else if (group == 0x72) {
547 return checkPartyStat(id, arg);
548 } else if (group == 0x7E) {
549 return checkWarpArg(id, arg);
550 } else if (group >= 0x80 && group < 0x8F) {
551 return checkItem(id, arg);
552 } else if (group == 0x92) {
553 return checkCard(id, arg);
554 }
555 return 1;
556}
557
558/*
559 * Actions: the same flag groups (set to value), 0x70 special actions, 0x74
560 * an overlay hook, 0x76/0x78, 0x7A, 0x7C, 0x94 mode changes through the
561 * overlay (0x8008AEB4), 0x80-0x8E give/take an item, 0x92 a card.
562 */
563void applyAction(s32 code, s32 value) {
564 u16 group = (code >> 8) & ~1;
565 s32 id = code & 0x1FF;
566
567 if (group == 0x00) {
568 setBit(FLAGS_00.bits, id, value);
569 }
570 if (group == 0x02) {
571 setBit(GAME.flags02, id, value);
572 }
573 if (group == 0x04) {
574 setBit(GAME.flags04, id, value);
575 }
576 if (group == 0x06) {
577 setBit(GAME.flags06, id, value);
578 }
579 if (group == 0x08) {
580 setBit(GAME.flags08, id, value);
581 }
582 if (group == 0x0A) {
583 setBit(GAME.flags0A, id, value);
584 }
585 if (group == 0x0C) {
586 setBit(GAME.flags0C, id, value);
587 }
588 if (group == 0x0E) {
589 setBit(GAME.flags0E, id, value);
590 }
591 if (group == 0x10) {
592 setBit(GAME.flags10, id, value);
593 }
594 if (group == 0x18) {
595 setBit(GAME.flags18, id, value);
596 }
597 if (group == 0x1A) {
598 setBit(GAME.flags1A, id, value);
599 }
600 if (group == 0x1C) {
601 setBit(GAME.flags1C, id, value);
602 }
603 if (group == 0x20) {
604 setBit(GAME.flags20, id, value);
605 }
606 if (group == 0x40) {
607 setBit(GAME.flags40, id, value);
608 }
609 if (group == 0x70) {
611 }
612 if (group == 0x74) {
614 }
615 if (group == 0x76) {
616 startCardBattle(id, 0);
617 }
618 if (group == 0x78) {
619 startCardBattle(id, 1);
620 }
621 if (group >= 0x80 && group < 0x8F) {
622 changeItem(id, value);
623 }
624 if (group == 0x90) {
626 }
627 if (group == 0x92) {
628 changeCard(id, value);
629 }
630 if (group == 0x94) {
632 }
633 if (group == 0x7A) {
634 if ((u16)id < 30) {
636 } else if ((u32)(id - 0x31) < 0x13 || (u32)(id - 0x46) < 5) {
638 } else {
640 }
641 }
642 if (group == 0x7C) {
643 if ((u16)id == 0) {
645 } else if ((u16)id == 1) {
646 FIELDSTG_leaveField(MODE_NAMING, 0, 0, 0, 0);
647 }
648 }
649}
650
651/* All the (code, value) pairs until 0xFFFF must hold */
653 u16 a;
654
655 for (a = *list; a != 0xFFFF; a = *list) {
656 list++;
657 if (!checkCondition(a, *list++)) {
658 return 0;
659 }
660 }
661 return 1;
662}
663
664/* Runs every (code, value) action until 0xFFFF */
665void applyActions(u16 *list) {
666 u16 a;
667
668 for (a = *list; a != 0xFFFF; a = *list) {
669 list++;
670 applyAction(a, *list++);
671 }
672}
673
674/*
675 * On a mode change: clears the temporary flags if asked, and sets flags 0x10-0x12 after a card
676 * battle
677 */
678void updateModeFlags(void) {
679 s32 i;
680 u8 *p;
681
682 if (GAME.clearTempFlags != 0) {
683 for (i = 2, p = &FLAGS_00.bits[i]; i >= 0; i--) {
684 *p-- = 0;
685 }
686 applyAction(0x12, 0);
687 }
690 applyAction(0x12, 1);
691 if (FLAGS_00.cardBattleWon != 0) {
693 } else {
695 }
697 }
698}
699
700/* The flag bitset FLAGS_00 and the event functions */
704
705/* checkSpecialCondition's conditions, up to an id of 0xFF */
707#if VERSION_US
708 { 0x3A, 0x00, 0x00 }, { 0x00, 0x10, 0x00 }, { 0x01, 0x10, 0x01 }, { 0x02, 0x10, 0x02 }, { 0x10, 0x11, 0x00 },
709 { 0x12, 0x11, 0x01 }, { 0x11, 0x11, 0x02 }, { 0x0B, 0x11, 0x03 }, { 0x0D, 0x11, 0x04 }, { 0x0C, 0x11, 0x05 },
710 { 0x0F, 0x11, 0x06 }, { 0x0E, 0x11, 0x07 }, { 0x42, 0x12, 0x00 }, { 0x44, 0x12, 0x01 }, { 0x43, 0x12, 0x02 },
711 { 0x47, 0x12, 0x03 }, { 0x46, 0x12, 0x04 }, { 0x45, 0x12, 0x05 }, { 0x49, 0x12, 0x06 }, { 0x48, 0x12, 0x07 },
712 { 0x37, 0x13, 0x00 }, { 0x39, 0x13, 0x01 }, { 0x38, 0x13, 0x02 }, { 0x31, 0x13, 0x03 }, { 0x32, 0x13, 0x04 },
713 { 0x33, 0x13, 0x05 }, { 0x35, 0x13, 0x06 }, { 0x34, 0x13, 0x07 }, { 0x4A, 0x14, 0x00 }, { 0x4C, 0x14, 0x01 },
714 { 0x4B, 0x14, 0x02 }, { 0x4F, 0x14, 0x03 }, { 0x4E, 0x14, 0x04 }, { 0x4D, 0x14, 0x05 }, { 0x51, 0x14, 0x06 },
715 { 0x50, 0x14, 0x07 }, { 0x25, 0x15, 0x00 }, { 0x26, 0x15, 0x01 }, { 0x27, 0x15, 0x02 }, { 0x28, 0x15, 0x03 },
716 { 0x29, 0x15, 0x04 }, { 0x2E, 0x16, 0x00 }, { 0x30, 0x16, 0x01 }, { 0x2F, 0x16, 0x02 }, { 0x2A, 0x16, 0x03 },
717 { 0x2B, 0x16, 0x04 }, { 0x2C, 0x16, 0x05 }, { 0x36, 0x16, 0x06 }, { 0x2D, 0x16, 0x07 }, { 0x74, 0x20, 0x00 },
718 { 0x75, 0x20, 0x01 }, { 0x76, 0x20, 0x02 }, { 0x77, 0x20, 0x03 }, { 0x78, 0x20, 0x04 }, { 0x79, 0x20, 0x05 },
719 { 0x7A, 0x20, 0x06 }, { 0x7B, 0x20, 0x07 }, { 0x7C, 0x20, 0x08 }, { 0x7D, 0x20, 0x09 }, { 0x8B, 0x21, 0x00 },
720 { 0x8C, 0x21, 0x01 }, { 0x8D, 0x21, 0x02 }, { 0x8E, 0x21, 0x03 }, { 0x8F, 0x21, 0x04 }, { 0x90, 0x21, 0x05 },
721 { 0x91, 0x21, 0x06 }, { 0x92, 0x21, 0x07 }, { 0x7E, 0x22, 0x00 }, { 0x7F, 0x22, 0x01 }, { 0x80, 0x22, 0x02 },
722 { 0x81, 0x22, 0x03 }, { 0x82, 0x22, 0x04 }, { 0x83, 0x22, 0x05 }, { 0x84, 0x22, 0x06 }, { 0x85, 0x22, 0x07 },
723 { 0x86, 0x22, 0x08 }, { 0x87, 0x22, 0x09 }, { 0x06, 0x30, 0x00 }, { 0x03, 0x30, 0x01 }, { 0x0A, 0x30, 0x02 },
724 { 0x07, 0x30, 0x03 }, { 0x04, 0x30, 0x04 }, { 0x05, 0x30, 0x05 }, { 0x09, 0x30, 0x06 }, { 0x14, 0x30, 0x07 },
725 { 0x08, 0x30, 0x08 }, { 0x3F, 0x30, 0x09 }, { 0x40, 0x30, 0x0A }, { 0x41, 0x30, 0x0B }, { 0x93, 0x30, 0x0C },
726 { 0x94, 0x30, 0x0D }, { 0x15, 0x30, 0x0E }, { 0x16, 0x30, 0x0F }, { 0x17, 0x30, 0x10 }, { 0x18, 0x30, 0x11 },
727 { 0x19, 0x30, 0x12 }, { 0x1A, 0x30, 0x13 }, { 0x1C, 0x30, 0x14 }, { 0x1D, 0x30, 0x15 }, { 0x21, 0x30, 0x16 },
728 { 0x1E, 0x30, 0x17 }, { 0x1F, 0x30, 0x18 }, { 0x20, 0x30, 0x19 }, { 0x22, 0x30, 0x1A }, { 0x23, 0x30, 0x1B },
729 { 0x24, 0x30, 0x1C }, { 0x3B, 0x30, 0x1D }, { 0x3C, 0x30, 0x1E }, { 0x3D, 0x30, 0x1F }, { 0x3E, 0x30, 0x20 },
730 { 0x71, 0x40, 0x00 }, { 0x70, 0x40, 0x01 }, { 0x73, 0x40, 0x02 }, { 0x72, 0x40, 0x03 }, { 0x13, 0x50, 0x00 },
731 { 0xFF },
732#elif VERSION_EU || VERSION_JP
733 { 0x3A, 0x00, 0x00 }, { 0x96, 0x01, 0x00 }, { 0x00, 0x10, 0x00 }, { 0x01, 0x10, 0x01 }, { 0x02, 0x10, 0x02 },
734 { 0x10, 0x11, 0x00 }, { 0x12, 0x11, 0x01 }, { 0x11, 0x11, 0x02 }, { 0x0B, 0x11, 0x03 }, { 0x0D, 0x11, 0x04 },
735 { 0x0C, 0x11, 0x05 }, { 0x0F, 0x11, 0x06 }, { 0x0E, 0x11, 0x07 }, { 0x42, 0x12, 0x00 }, { 0x44, 0x12, 0x01 },
736 { 0x43, 0x12, 0x02 }, { 0x47, 0x12, 0x03 }, { 0x46, 0x12, 0x04 }, { 0x45, 0x12, 0x05 }, { 0x49, 0x12, 0x06 },
737 { 0x48, 0x12, 0x07 }, { 0x37, 0x13, 0x00 }, { 0x39, 0x13, 0x01 }, { 0x38, 0x13, 0x02 }, { 0x31, 0x13, 0x03 },
738 { 0x32, 0x13, 0x04 }, { 0x33, 0x13, 0x05 }, { 0x35, 0x13, 0x06 }, { 0x34, 0x13, 0x07 }, { 0x4A, 0x14, 0x00 },
739 { 0x4C, 0x14, 0x01 }, { 0x4B, 0x14, 0x02 }, { 0x4F, 0x14, 0x03 }, { 0x4E, 0x14, 0x04 }, { 0x4D, 0x14, 0x05 },
740 { 0x51, 0x14, 0x06 }, { 0x50, 0x14, 0x07 }, { 0x25, 0x15, 0x00 }, { 0x26, 0x15, 0x01 }, { 0x27, 0x15, 0x02 },
741 { 0x28, 0x15, 0x03 }, { 0x29, 0x15, 0x04 }, { 0x2E, 0x16, 0x00 }, { 0x30, 0x16, 0x01 }, { 0x2F, 0x16, 0x02 },
742 { 0x2A, 0x16, 0x03 }, { 0x2B, 0x16, 0x04 }, { 0x2C, 0x16, 0x05 }, { 0x36, 0x16, 0x06 }, { 0x2D, 0x16, 0x07 },
743 { 0x95, 0x17, 0x00 }, { 0x53, 0x18, 0x00 }, { 0x55, 0x19, 0x00 }, { 0x74, 0x20, 0x00 }, { 0x75, 0x20, 0x01 },
744 { 0x76, 0x20, 0x02 }, { 0x77, 0x20, 0x03 }, { 0x78, 0x20, 0x04 }, { 0x79, 0x20, 0x05 }, { 0x7A, 0x20, 0x06 },
745 { 0x7B, 0x20, 0x07 }, { 0x7C, 0x20, 0x08 }, { 0x7D, 0x20, 0x09 }, { 0x8B, 0x21, 0x00 }, { 0x8C, 0x21, 0x01 },
746 { 0x8D, 0x21, 0x02 }, { 0x8E, 0x21, 0x03 }, { 0x8F, 0x21, 0x04 }, { 0x90, 0x21, 0x05 }, { 0x91, 0x21, 0x06 },
747 { 0x92, 0x21, 0x07 }, { 0x7E, 0x22, 0x00 }, { 0x7F, 0x22, 0x01 }, { 0x80, 0x22, 0x02 }, { 0x81, 0x22, 0x03 },
748 { 0x82, 0x22, 0x04 }, { 0x83, 0x22, 0x05 }, { 0x84, 0x22, 0x06 }, { 0x85, 0x22, 0x07 }, { 0x86, 0x22, 0x08 },
749 { 0x87, 0x22, 0x09 }, { 0x06, 0x30, 0x00 }, { 0x03, 0x30, 0x01 }, { 0x0A, 0x30, 0x02 }, { 0x07, 0x30, 0x03 },
750 { 0x04, 0x30, 0x04 }, { 0x05, 0x30, 0x05 }, { 0x09, 0x30, 0x06 }, { 0x14, 0x30, 0x07 }, { 0x08, 0x30, 0x08 },
751 { 0x3F, 0x30, 0x09 }, { 0x40, 0x30, 0x0A }, { 0x41, 0x30, 0x0B }, { 0x93, 0x30, 0x0C }, { 0x94, 0x30, 0x0D },
752 { 0x15, 0x30, 0x0E }, { 0x16, 0x30, 0x0F }, { 0x17, 0x30, 0x10 }, { 0x18, 0x30, 0x11 }, { 0x19, 0x30, 0x12 },
753 { 0x1A, 0x30, 0x13 }, { 0x1C, 0x30, 0x14 }, { 0x1D, 0x30, 0x15 }, { 0x21, 0x30, 0x16 }, { 0x1E, 0x30, 0x17 },
754 { 0x1F, 0x30, 0x18 }, { 0x20, 0x30, 0x19 }, { 0x22, 0x30, 0x1A }, { 0x23, 0x30, 0x1B }, { 0x24, 0x30, 0x1C },
755 { 0x3B, 0x30, 0x1D }, { 0x3C, 0x30, 0x1E }, { 0x3D, 0x30, 0x1F }, { 0x3E, 0x30, 0x20 }, { 0x71, 0x40, 0x00 },
756 { 0x70, 0x40, 0x01 }, { 0x73, 0x40, 0x02 }, { 0x72, 0x40, 0x03 }, { 0x54, 0x41, 0x00 }, { 0x13, 0x50, 0x00 },
757 { 0xFF },
758#endif
759};
760
761/* checkMoney's amounts, by its argument */
763 800, 1600, 2700, 4000, 6000, 8700, 11500, 17500, 24000, 32000,
764};
766 100, 300, 600, 1000, 1600, 3000, 5000, 8500,
767};
769 800, 1600, 2700, 4000, 6000, 8700, 11500, 17500, 24000, 32000,
770};
771
772/* checkProgressRange's ranges of GAME.progress: { min, max }; 0x63 is past the end of the story */
776 { STORY_GENJI_BEATEN, 0x2C },
779 { STORY_ASUKA_HEADQUARTERS, 0x2A },
780 { STORY_GENJI_BEATEN, 0x63 },
783 { STORY_CONTROL_ROOM, 0x2A },
784 { STORY_LISA_SAVED, 0x63 },
786 { STORY_DE_SINCERITY, 0x63 },
787 { STORY_DE_KNOWLEDGE, 0x63 },
807 { 0x00, 0x00 },
808};
809
810/* checkPartyStat's thresholds */
812 60, 150, 210, 285, 378, 492, 630, 795, 990, 1218, 1482, 1785, 2049, 2277, 2472,
813};
signed int s32
Definition common.h:11
unsigned int u32
Definition common.h:12
signed short s16
Definition common.h:9
unsigned short u16
Definition common.h:10
unsigned char u8
Definition common.h:8
s32 checkProgressRange(s32 unused, s32 index)
Special conditions 0x30: whether GAME.progress is within PROGRESS_RANGES[index].
Definition events.c:182
s32 testBit(u8 *bits, s32 index, s32 set)
Whether bit index of a bitset is set (set != 0) or clear (set 0)
Definition events.c:5
s32 checkPartner(u32 op, s32 arg)
Special conditions 0x10: tests partners (unlocked, in the party, levels) or unlocks one; the European...
Definition events.c:65
s32 checkItemSet(s32 op, s32 arg)
Special condition 0x00: the player has every item of a set (the European and Japanese versions have a...
Definition events.c:29
s32 checkCard(s32 card, s32 have)
Conditions 0x92: whether the player has card item (have != 0) or not.
Definition events.c:353
void startCardBattle(s32 opponent, s32 kind)
Actions 0x76 and 0x78: a card battle (MODE_CARD_GAME) against an opponent.
Definition events.c:497
void applyActions(u16 *list)
Runs every (code, value) action until 0xFFFF.
Definition events.c:665
s32 MONEY_LOSSES[]
Definition events.c:768
s32 PARTY_STAT_THRESHOLDS[]
checkPartyStat's thresholds
Definition events.c:811
s32 checkConditions(u16 *list)
All the (code, value) pairs until 0xFFFF must hold.
Definition events.c:652
u8 PROGRESS_RANGES[][2]
checkProgressRange's ranges of GAME.progress: { min, max }; 0x63 is past the end of the story
Definition events.c:773
s32 checkFlagCount(s32 group, s32 mode)
Special conditions 0x40: group 0 as in the USA version; group 1 whether four flags of group 0x10 are ...
Definition events.c:231
s32 checkWarpArg(s32 id, s32 mode)
Conditions 0x7E: the values a warp leaves for its stage (GAME.place for ids under 30,...
Definition events.c:397
s32 checkSpecialCondition(s32 id, s32 expected)
Runs SPECIAL_CONDITIONS entry id; whether its result equals expected
Definition events.c:285
s32 checkCondition(u16 code, u16 value)
Event scripts test conditions and run actions given as (code, value) pairs.
Definition events.c:509
s32 checkMoney(s32 op, s32 item)
Special conditions 0x20: whether the player has MONEY_REQUIRED[item], or gives or takes an amount.
Definition events.c:156
s32 unequipItem(s32 partner, s32 item)
Takes item item off a partner (one of type 7 empties slots 2 and 3 both); 1 if it had it.
Definition events.c:436
void applyAction(s32 code, s32 value)
Actions: the same flag groups (set to value), 0x70 special actions, 0x74 an overlay hook,...
Definition events.c:563
s32 MONEY_REQUIRED[]
checkMoney's amounts, by its argument
Definition events.c:762
SpecialCondition SPECIAL_CONDITIONS[]
checkSpecialCondition's conditions, up to an id of 0xFF
Definition events.c:706
void changeCard(s32 card, s32 add)
Actions 0x92: gives or takes a copy of a card.
Definition events.c:485
s32 MONEY_GAINS[]
Definition events.c:765
void changeItem(s32 item, s32 add)
Actions 0x80-0x8E: gives an item (up to 99) or takes one, from the bag or else off a partner.
Definition events.c:457
s32 showActorIcon(s32 op, s32 arg)
Special condition 0x50: the field actor's icon (FIELDSTG's task 0x16, FIELD_TASK_ICON) plays its anim...
Definition events.c:277
s32 checkPartyStat(s32 index, s32 mode)
Conditions 0x72: whether the party's total of battle stat 5 reaches PARTY_STAT_THRESHOLDS[index] (mod...
Definition events.c:370
void setBit(u8 *bits, s32 index, s32 set)
Sets or clears bit index of a bitset.
Definition events.c:16
void updateModeFlags(void)
On a mode change: clears the temporary flags if asked, and sets flags 0x10-0x12 after a card battle.
Definition events.c:678
s32 checkProgress(s32 value, s32 mode)
Conditions 0x60: whether GAME.progress is value (mode != 0) or not.
Definition events.c:322
s32 checkItem(s32 index, s32 mode)
Conditions 0x80-0x8E: whether the player has item index, in the bag or equipped (mode !...
Definition events.c:339
GameFlags FLAGS_00
The flag bitset FLAGS_00 and the event functions.
Definition events.c:701
GameState GAME
The save data, the game mode and the methods.
Definition state.c:64
void FIELDSTG_startListedEvent(s32 index)
Starts the event FIELDSTG_eventIds[index] (the executable calls it)
Definition field.c:1019
void FIELDSTG_openInn(void)
Opens the inn: the field task waits for it (the executable calls it)
Definition field.c:1027
void FIELDSTG_leaveField(s32 mode, s32 arg, s32 x, s32 y, s32 dir)
Leaves the field for a mode now (the executable calls it by this name)
Definition field.c:702
What the stage overlays and the executable use of FIELDSTG (fieldstg.h has the rest): its layers and ...
FieldBattleFuncs FIELDSTG_battleFuncs
Definition fieldstg.c:3653
#define MONEY_MAX
The most money the player can have.
Definition game_state.h:482
#define MODE_NAMING
STDGNAME.
Definition game_state.h:435
#define MODE_DIGI_LAB
STGDGLAB.
Definition game_state.h:437
#define STAT_MP
Definition game_state.h:283
#define PARTY_SIZE
How many partners the party holds.
Definition game_state.h:475
#define STAT_MAX_HP
Definition game_state.h:282
#define STAT_HP
Definition game_state.h:281
#define MODE_CARD_GAME
CARDGAME: a card battle.
Definition game_state.h:433
#define MODE_TRAINING
STGTRAIN.
Definition game_state.h:434
#define MODE_ITEM_SHOP
STITSHOP.
Definition game_state.h:449
#define STAT_LEVEL
Indices of a partner's stats (PartnerStats.stats, computeStats, setStat)
Definition game_state.h:279
#define STAT_MAX_MP
Definition game_state.h:284
@ PARTNER_PATAMON
Definition game_state.h:471
@ PARTNER_VEEMON
Definition game_state.h:468
@ PARTNER_KOTEMON
Definition game_state.h:464
@ PARTNER_GUILMON
Definition game_state.h:469
@ PARTNER_RENAMON
Definition game_state.h:470
@ PARTNER_AGUMON
Definition game_state.h:467
@ PARTNER_MONMON
Definition game_state.h:466
@ PARTNER_KUMAMON
Definition game_state.h:465
@ PARTNER_COUNT
Definition game_state.h:472
#define MODE_CARD_SHOP
STCRDSHP.
Definition game_state.h:452
ItemFuncs ITEM_FUNCS
Definition items.c:890
TaskRegistry TASK_REGISTRY
Definition registry.c:122
@ STORY_BLACK_ID_PASS
WSTAG756 (Battle Gate), event 911: the Black ID Pass.
Definition story.h:131
@ STORY_BYAKKO_BADGE
WSTAG655 (Mirage Room), event 431: HiAndromon guards the way to Numemon (the Byakko Badge)
Definition story.h:76
@ STORY_PRESIDENT_ARRESTED
WSTAG226 (Login Room, Amaterasu City), event 935, after the President of MAGAMI gives himself up (WST...
Definition story.h:136
@ STORY_BULBMON_FOUND
WSTAG520 (Suzaku Hall), event 695: another earthquake; Bulbmon digs the holes.
Definition story.h:103
@ STORY_BLUE_ID_PASS
WSTAG421 (Qing Long City), event 743: with the Blue ID Pass a Trooper takes the player for the Qing L...
Definition story.h:109
@ STORY_LOGGED_IN
WSTAG225 (Login Room, Asuka City), event 5: the first login, where the account clerk explains Digimon...
Definition story.h:29
@ STORY_OPERATION_SIGMA
WSTAG311 (A.o.A Headquarters, Amaterasu City), event 982, after event 981, where the A....
Definition story.h:141
@ STORY_BYAKKO_LEADER_FOUGHT
WSTAG620 (the rebels' hideout), event 534: the Byakko Leader takes the player for the A....
Definition story.h:85
@ STORY_AMATERASU_BRIDGE
WSTAG206 (Amaterasu Bridge), event 922: an Attacker holds the bridge.
Definition story.h:133
@ STORY_ZANBAMON_DRIVEN_OFF
WSTAG475 (Shaman House), event 230: the Smelly Herb drives Zanbamon off the way.
Definition story.h:55
@ STORY_CONTROL_ROOM
WSTAG325 (Control Room, Asuka City), event 560: a Soldier guards the way.
Definition story.h:90
@ STORY_BULBMON_BEATEN
WSTAG521 (Zhu Que Hall), event 751: Bulbmon is beaten (the Red ID Pass); its hole leads on to the Ama...
Definition story.h:112
@ STORY_GENJI_BEATEN
WSTAG200, event 52: after the first battle, won against Tamer Genji (event 50), the Digimon Navi give...
Definition story.h:36
@ STORY_KNIGHTMON_REPROGRAMMED
WSTAG210 (Main Lobby, Asuka City), event 685: the A.o.A have reprogrammed Knightmon,...
Definition story.h:97
@ STORY_TEDDY_FOUND
WSTAG212, event 352: Teddy is found; MAGAMI is part of the A.o.A, and the player sets off to beat the...
Definition story.h:67
@ STORY_LISA_SAVED
WSTAG605 (Operation Room), event 511: the player saves Lisa from WaruMonzaemon (the Rusty Rifle)
Definition story.h:79
@ STORY_LOOKING_FOR_TEDDY
WSTAG212, event 273: Kail and the player will put on the Agumon Suits to look for Teddy.
Definition story.h:61
@ STORY_JUNGLE_SOUND
WSTAG545 (Bug Maze Pit), event 711: Patamon heard a weird sound from the jungle, where its leader wen...
Definition story.h:106
@ STORY_SOUTH_STATION_GHOST
WSTAG440 (South Station), event 152: a ghost's voice in the empty station.
Definition story.h:45
@ STORY_WAY_TO_AMATERASU
WSTAG305, events 893 and 895: the way into Amaterasu City, the A.o.A's headquarters,...
Definition story.h:126
@ STORY_DE_KNOWLEDGE
WSTAG526 (Zhu Que UG Lake), event 760: the fight with Zanbamon (the DE Knowledge)
Definition story.h:115
@ STORY_STAFF_PASS
WSTAG620, event 551: Nick finds a Staff Pass for the player.
Definition story.h:87
@ STORY_ASUKA_HEADQUARTERS
WSTAG310 (A.o.A Headquarters, Asuka City), event 961.
Definition story.h:138
@ STORY_SEIRYU_BADGE
WSTAG420, event 71: the Seiryu Leader is beaten (the Silver ID and the Seiryu Badge),...
Definition story.h:39
@ STORY_AGUMON_DISGUISE
WSTAG237 (Underground Path), event 300: in the Agumon Suit; Kail goes on ahead alone.
Definition story.h:64
@ STORY_GAME_MASTER_CAUGHT
WSTAG305 (Master Room), event 661: the Game Master is caught, but Vemmon takes over the Optical Netwo...
Definition story.h:94
@ STORY_NETWORK_OFFLINE
WSTAG750, event 886: the news say the Optical Network is offline.
Definition story.h:123
@ STORY_DE_SINCERITY
WSTAG460 (Reliability Spot), event 370: the Qing Long Chief, asked for the Digi-Egg of Knowledge,...
Definition story.h:70
#define FLAG_CARD_BATTLE_WON
set by updateModeFlags on the way back from a card battle: 1 if the player won it (FLAGS_00....
Definition story.h:166
#define FLAG_CARD_BATTLE_ENDED
set by updateModeFlags on the way back from a card battle; the talks that follow one test it and clea...
Definition story.h:169
void(* startEventBattle)(s32 index)
FIELDSTG_startEventBattle.
Definition field_map.h:502
FLAGS_00, the first flag bitset, followed by the event functions: FIELDSTG and the stages call them t...
Definition game_state.h:48
s32 cardBattleWon
1 when the player won the card battle; updateModeFlags copies it to FLAG_CARD_BATTLE_WON
Definition game_state.h:50
u8 bits[4]
Definition game_state.h:49
struct PartnerStats *(* getPartnerStats)(s32 partner)
Definition game_state.h:38
void(* computeStats)(s32 partner, union PartnerTotals *out)
Definition game_state.h:31
s32(* getPrevMode)()
Definition game_state.h:23
s32(* getPartyMember)(u32 index)
Definition game_state.h:24
void(* addCards)(s32 card, s32 count)
Definition game_state.h:26
s8 cards[0x13D]
counts, up to CARD_COPIES_MAX
Definition game_state.h:514
u8 flags02[0x12]
flags02-flags40: the event flag groups 0x02-0x40 (checkCondition, applyAction), bitsets packed one af...
Definition game_state.h:555
u8 flags04[0x2]
Definition game_state.h:556
s8 items[0x193]
counts, up to 99
Definition game_state.h:512
u8 flags10[0x4]
Definition game_state.h:562
u16 place
where the last warp or trigger put the player (FieldBattles.id)
Definition game_state.h:506
u8 flags0E[0xC]
Definition game_state.h:561
Partner partners[PARTNER_COUNT]
Definition game_state.h:517
s8 equippedItems[0x193]
Definition game_state.h:513
u16 placeArg
the place's argument, which the stage reads with it
Definition game_state.h:507
u8 flags0C[0x8]
Definition game_state.h:560
u8 flags18[0x2]
Definition game_state.h:563
u8 flags06[0x1]
Definition game_state.h:557
u8 flags20[0x1E]
Definition game_state.h:566
s32 partySet
setParty's: the starter pack (enum StarterPack)
Definition game_state.h:519
u8 flags1C[0xB]
Definition game_state.h:565
s32 clearTempFlags
Definition game_state.h:573
u8 flags0A[0x4]
Definition game_state.h:559
u8 flags40[0x1A]
Definition game_state.h:567
GameFuncs funcs
Definition game_state.h:582
u8 flags08[0x1]
Definition game_state.h:558
u8 flags1A[0x9]
Definition game_state.h:564
struct ItemInfo *(* get)(s32 item)
getItem
Definition game_state.h:670
ItemRecord data
the type's record, or the usable items' effect
Definition game_state.h:226
A partner Digimon from its name on (Partner.info), as getPartnerStats gives it.
Definition game_state.h:303
s16 stats[19]
Definition game_state.h:306
PartnerStats info
Definition game_state.h:349
s32 unlocked
partner id + 3, 0 while locked
Definition game_state.h:347
A special condition (SPECIAL(id)): checkSpecialCondition runs the check function of kind check >> 4 (...
Definition game_state.h:662
void *(* find)(s32 id, s32 key1, s32 key2)
Definition task.h:18
TaskFuncs funcs
Definition task.h:76
Any task, seen through its header.
Definition task.h:62
void(* setSubstate)(struct Task *task, s32 substate)
Definition task.h:63
computeStats' result: the stats with the equipment added, by STAT_* or by name.
Definition game_state.h:409
s16 battle[6]
strength (raised by weapons), defense (by armour), spirit, wisdom, speed and charisma (by all equipme...
Definition game_state.h:418
struct PartnerTotals::@10 fields