fork/training-mode-ce

git clone https://git.julia.blue/fork/training-mode-ce

Alex Harrisonbump version v1.3 d4437ed46

master
10.5 KiB351 linesraw
1#ifndef EVENTS_H
2#define EVENTS_H
3
4#include "../MexTK/mex.h"
5#include "menu.h"
6#include "savestate.h"
7#include <stdint.h>
8
9#define TM_VERSSHORT "TM-CE v1.3 d4"
10#define TM_VERSLONG "TM Community Edition v1.3 d4"
11#define EVENT_DATASIZE 512
12#define TM_FUNC -(50 * 4)
13
14#define ANALOG_TRIGGER_THRESHOLD 43
15
16// disable all logs in release mode
17#if TM_DEBUG
18#define TMLOG(...) do { \
19    DevelopText_AddString(event_vars->db_console_text, __VA_ARGS__); \
20    OSReport(__VA_ARGS__); \
21} while (0)
22#define TMLOG_ONCE(...) do { \
23    static int __logged_once = 0; \
24    if (!__logged_once) { \
25        __logged_once = 1; \
26        TMLOG(__VA_ARGS__); \
27    } \
28} while (0)
29#else
30#define TMLOG(...) (void)0
31#endif
32
33typedef struct EventMatchData //r8
34{
35    unsigned int timer : 2;
36    unsigned int matchType : 3;
37    unsigned int hideGo : 1;
38    unsigned int hideReady : 1;
39    unsigned int isCreateHUD : 1;       // Display Stocks/Percents/Timer
40    unsigned int timerRunOnPause : 1;
41    unsigned int isCheckForZRetry : 1;
42    unsigned int isShowScore : 1;
43    unsigned int isRunStockLogic : 1;
44    unsigned int isDisableHit : 1;
45    unsigned int useKOCounter : 1;
46    unsigned int timerSeconds : 32;   // 0xFFFFFFFF
47} EventMatchData;
48enum CSSID {
49    CSSID_DOCTOR_MARIO   = 1 << 0,
50    CSSID_MARIO          = 1 << 1,
51    CSSID_LUIGI          = 1 << 2,
52    CSSID_BOWSER         = 1 << 3,
53    CSSID_PEACH          = 1 << 4,
54    CSSID_YOSHI          = 1 << 5,
55    CSSID_DONKEY_KONG    = 1 << 6,
56    CSSID_CAPTAIN_FALCON = 1 << 7,
57    CSSID_GANONDORF      = 1 << 8,
58    CSSID_FALCO          = 1 << 9,
59    CSSID_FOX            = 1 << 10,
60    CSSID_NESS           = 1 << 11,
61    CSSID_ICE_CLIMBERS   = 1 << 12,
62    CSSID_KIRBY          = 1 << 13,
63    CSSID_SAMUS          = 1 << 14,
64    CSSID_ZELDA          = 1 << 15,
65    CSSID_LINK           = 1 << 16,
66    CSSID_YOUNG_LINK     = 1 << 17,
67    CSSID_PICHU          = 1 << 18,
68    CSSID_PIKACHU        = 1 << 19,
69    CSSID_JIGGLYPUFF     = 1 << 20,
70    CSSID_MEWTWO         = 1 << 21,
71    CSSID_GAME_AND_WATCH = 1 << 22,
72    CSSID_MARTH          = 1 << 23,
73    CSSID_ROY            = 1 << 24
74};
75// This order must match the EventJumpTable in Globals.s
76enum JumpTableIndex {
77    JUMP_AMSAHTECH,
78    JUMP_ATTACKONSHIELD,
79    JUMP_COMBO,
80    JUMP_ESCAPESHIEK,
81    JUMP_GRABMASH,
82    JUMP_LEDGESTALL,
83    JUMP_LEDGETECH,
84    JUMP_LEDGETECHCOUNTER,
85    JUMP_MULTISHINE,
86    JUMP_REACTION,
87    JUMP_REVERSAL,
88    JUMP_SDITRAINING,
89    JUMP_SHIELDDROP,
90    JUMP_SLIDEOFF,
91    JUMP_WAVESHINESDI
92};
93typedef struct AllowedCharacters
94{
95    // whitelist bitfields of CSSID_* characters
96    int hmn;
97    int cpu;
98} AllowedCharacters;
99typedef struct EventDesc
100{
101    char *eventName;
102    char *eventDescription;
103    char *eventFile;
104    int jumpTableIndex;
105    char *eventCSSFile;
106    u8 disable_hazards : 1; // removes stage hazards
107    u8 force_sopo : 1;
108    u8 CSSType;
109    AllowedCharacters allowed_characters;
110    s8 playerKind;                    // -1 = use selected fighter
111    s8 cpuKind;                       // -1 = no CPU
112    s16 stage;                        // -1 = use selected stage
113    u8 scoreType;
114    u8 callbackPriority;
115    EventMatchData *matchData;
116} EventDesc;
117typedef struct EventPage
118{
119    char *name;
120    int eventNum;
121    EventDesc **events;
122} EventPage;
123
124typedef struct evFunction
125{
126    void (*Event_Init)(GOBJ *event);
127    void (*Event_Update)(void);
128    void (*Event_Think)(GOBJ *event);
129    EventMenu **menu_start;
130} evFunction;
131
132typedef struct Rect
133{
134    float x, y, w, h;
135} Rect;
136
137static inline void RectShrink(Rect *dst, float size)
138{
139    dst->x += size;
140    dst->y += size;
141    dst->w -= size * 2.f;
142    dst->h -= size * 2.f;
143}
144
145static inline void RectSplitL(Rect *dst, Rect *src, float size, float padding)
146{
147    *dst = (Rect) { src->x, src->y, size, src->h };
148    src->x += size + padding;
149    src->w -= size + padding;
150}
151
152static inline void RectSplitR(Rect *dst, Rect *src, float size, float padding)
153{
154    *dst = (Rect) { src->x + src->w - size, src->y, size, src->h };
155    src->w -= size + padding;
156}
157
158static inline void RectSplitU(Rect *dst, Rect *src, float size, float padding)
159{
160    *dst = (Rect) { src->x, src->y, src->w, size };
161    src->y += size + padding;
162    src->h -= size + padding;
163}
164
165static inline void RectSplitD(Rect *dst, Rect *src, float size, float padding)
166{
167    *dst = (Rect) { src->x, src->y + src->h - size, src->w, size };
168    src->h -= size + padding;
169}
170
171void HUD_DrawRects(Rect *rects, GXColor *colors, int count);
172void HUD_DrawText(const char *text, Rect *pos, float size);
173void HUD_DrawActionLogBar(u8 *action_log, GXColor *color_lookup, int log_count);
174void HUD_DrawActionLogKey(char **action_names, GXColor *action_colors, int action_count);
175
176typedef struct RNGControl
177{
178    u8 peach_item;      // 0x0
179    u8 peach_fsmash;    // 0x1
180    u8 luigi_misfire;   // 0x2
181    u8 gnw_hammer;      // 0x3
182    u8 nana_throw;      // 0x4
183} RNGControl;
184
185typedef struct HUDCamData {
186    bool hide;
187    int canvas;
188    u32 text_cache_used;
189    Text *text_cache[32];
190} HUDCamData;
191
192typedef struct EventVars
193{
194    EventDesc *event_desc;                                                                   // event information
195    evMenu *menu_assets;                                                                     // menu assets
196    GOBJ *event_gobj;                                                                        // event gobj
197    GOBJ *menu_gobj;                                                                         // event menu gobj
198    RNGControl *rng;                                                                         // rng struct pointer
199    int game_timer;                                                                          // amount of game frames passed
200    int (*Savestate_Save_v1)(Savestate_v1 *savestate, int flags);                                  // function pointer to save state
201    int (*Savestate_Load_v1)(Savestate_v1 *savestate, int flags);                                  // function pointer to load state
202    GOBJ *(*Message_Display)(int msg_kind, int queue_num, int msg_color, char *format, ...); // function pointer to display message
203    int (*Tip_Display)(int lifetime, char *fmt, ...);
204    void (*Tip_Destroy)(void);      // function pointer to destroy tip
205    Savestate_v1 *savestate;       // points to the events main savestate
206
207    // To allow minor savestates during mirrored playback, 
208    // we need to record if the minor savestate was saved duting mirroring.
209    // Otherwise, the savestate will be loaded as mirrored AGAIN.
210    int savestate_saved_while_mirrored;
211    int loaded_mirrored;
212
213    evFunction evFunction;      // event specific functions
214    HSD_Archive *event_archive; // event archive header
215    DevText *db_console_text;
216    Text *watermark;
217    GOBJ *hudcam_gobj;
218    void (*HUD_DrawRects)(Rect *rects, GXColor *colors, int count);
219    void (*HUD_DrawText)(const char *text, Rect *pos, float size);
220    void (*HUD_DrawActionLogBar)(u8 *action_log, GXColor *color_lookup, int log_count);
221    void (*HUD_DrawActionLogKey)(char **action_names, GXColor *action_colors, int action_count);
222} EventVars;
223#define event_vars_ptr_loc ((EventVars**)0x803d7054)
224#define event_vars (*event_vars_ptr_loc)
225
226// Function prototypes
227EventDesc *GetEventDesc(int page, int event);
228void EventInit(int page, int eventID, MatchInit *matchData);
229void EventLoad(void);
230int Text_AddSubtextManual(Text *text, char *string, int posx, int posy, int scalex, int scaley);
231GOBJ *GOBJToID(GOBJ *gobj);
232FighterData *FtDataToID(FighterData *fighter_data);
233JOBJ *BoneToID(FighterData *fighter_data, JOBJ *bone);
234GOBJ *IDToGOBJ(GOBJ *id_as_ptr);
235FighterData *IDToFtData(FighterData *id_as_ptr);
236JOBJ *IDToBone(FighterData *fighter_data, JOBJ *id_as_ptr);
237void UpdateDevCamera(void);
238void EventUpdate(void);
239void Event_IncTimer(GOBJ *gobj);
240void Events_StoreEventScore(int event_id, int score);
241int Events_GetSavedScore(int event_id);
242void Event_Retry(void);
243void Events_SetEventAsPlayed(int event_id);
244void Test_Think(GOBJ *gobj);
245void Hazards_Disable(void);
246void TM_CreateWatermark(void);
247
248// GX Link args
249#define GXLINK_MENUMODEL 12
250#define GXPRI_MENUMODEL 80
251#define GXLINK_MENUTEXT 12
252#define GXPRI_MENUTEXT GXPRI_MENUMODEL + 1
253
254#define GXLINK_HUD 18
255#define GXPRI_HUD 78
256
257// Message
258void Message_Init(void);
259GOBJ *Message_Display(int msg_kind, int queue_num, int msg_color, char *format, ...);
260void Message_Manager(GOBJ *mngr_gobj);
261void Message_Destroy(GOBJ **msg_queue, int msg_num);
262void Message_Add(GOBJ *msg_gobj, int queue_num);
263void Message_CObjThink(GOBJ *gobj);
264
265void HUD_CObjThink(GOBJ *gobj);
266
267#define MSGQUEUE_NUM 7
268#define MSGQUEUE_SIZE 8
269#define MSGQUEUE_GENERAL 6
270enum MsgState
271{
272    MSGSTATE_WAIT,
273    MSGSTATE_SHIFT,
274    MSGSTATE_DELETE,
275};
276enum MsgArea
277{
278    MSGKIND_P1,
279    MSGKIND_P2,
280    MSGKIND_P3,
281    MSGKIND_P4,
282    MSGKIND_P5,
283    MSGKIND_P6,
284    MSGKIND_GENERAL,
285};
286typedef struct MsgData
287{
288    Text *text;      // text pointer
289    int kind;        // the type of message this is
290    int state;       // unused atm
291    int prev_index;  // used to animate the messages position during shifts
292    int orig_index;  // used to tell if the message moved throughout the course of the frame
293    int anim_timer;  // used to track animation frame
294    int lifetime;    // amount of frames after spawning to kill this message
295    int alive_timer; // amount of frames this message has been alive for
296} MsgData;
297typedef struct MsgMngrData
298{
299    COBJ *cobj;
300    int state;
301    int canvas;
302    GOBJ *msg_queue[MSGQUEUE_NUM][MSGQUEUE_SIZE]; // array 7 is for miscellaneous messages, not related to a player
303} MsgMngrData;
304
305enum MsgColors
306{
307    MSGCOLOR_WHITE,
308    MSGCOLOR_GREEN,
309    MSGCOLOR_RED,
310    MSGCOLOR_YELLOW
311};
312
313#define MSGTIMER_SHIFT 6
314#define MSGTIMER_DELETE 6
315#define MSG_LIFETIME (2 * 60)
316#define MSG_LINEMAX 3  // lines per message
317#define MSG_CHARMAX 32 // characters per line
318#define MSG_HUDYOFFSET 8
319#define MSGJOINT_SCALE 3
320#define MSGJOINT_X 0
321#define MSGJOINT_Y 0
322#define MSGJOINT_Z 0
323#define MSGTEXT_BASESCALE 1.4
324#define MSGTEXT_BASEWIDTH (330 / MSGTEXT_BASESCALE)
325#define MSGTEXT_BASEX 0
326#define MSGTEXT_BASEY -1
327#define MSGTEXT_YOFFSET 30
328
329// GX stuff
330#define MSG_GXLINK 13
331#define MSG_GXPRI 80
332#define MSGTEXT_GXPRI MSG_GXPRI + 1
333#define MSG_COBJLGXLINKS (1 << MSG_GXLINK)
334#define MSG_COBJLGXPRI 8
335
336typedef struct TipMgr
337{
338    GOBJ *gobj;   // tip gobj
339    Text *text;   // tip text object
340    int state;    // state this tip is in. 0 = in, 1 = wait, 2 = out
341    int lifetime; // tips time spent onscreen
342} TipMgr;
343
344int Tip_Display(int lifetime, char *fmt, ...);
345void Tip_Destroy(void); // 0 = immediately destroy, 1 = force exit
346void Tip_Think(GOBJ *gobj);
347void Tip_Init(void);
348
349#define TIP_TXTJOINT 2
350
351#endif