fork/training-mode-ce
git clone https://git.julia.blue/fork/training-mode-ce
437ed46
nix
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{ 35unsigned int timer :2 ; 36unsigned int matchType :3 ; 37unsigned int hideGo :1 ; 38unsigned int hideReady :1 ; 39unsigned int isCreateHUD :1 ;// Display Stocks/Percents/Timer 40unsigned int timerRunOnPause :1 ; 41unsigned int isCheckForZRetry :1 ; 42unsigned int isShowScore :1 ; 43unsigned int isRunStockLogic :1 ; 44unsigned int isDisableHit :1 ; 45unsigned int useKOCounter :1 ; 46unsigned int timerSeconds :32 ;// 0xFFFFFFFF 47}EventMatchData ; 48enum CSSID { 49CSSID_DOCTOR_MARIO = 1 <<0 , 50CSSID_MARIO = 1 <<1 , 51CSSID_LUIGI = 1 <<2 , 52CSSID_BOWSER = 1 <<3 , 53CSSID_PEACH = 1 <<4 , 54CSSID_YOSHI = 1 <<5 , 55CSSID_DONKEY_KONG = 1 <<6 , 56CSSID_CAPTAIN_FALCON = 1 <<7 , 57CSSID_GANONDORF = 1 <<8 , 58CSSID_FALCO = 1 <<9 , 59CSSID_FOX = 1 <<10 , 60CSSID_NESS = 1 <<11 , 61CSSID_ICE_CLIMBERS = 1 <<12 , 62CSSID_KIRBY = 1 <<13 , 63CSSID_SAMUS = 1 <<14 , 64CSSID_ZELDA = 1 <<15 , 65CSSID_LINK = 1 <<16 , 66CSSID_YOUNG_LINK = 1 <<17 , 67CSSID_PICHU = 1 <<18 , 68CSSID_PIKACHU = 1 <<19 , 69CSSID_JIGGLYPUFF = 1 <<20 , 70CSSID_MEWTWO = 1 <<21 , 71CSSID_GAME_AND_WATCH = 1 <<22 , 72CSSID_MARTH = 1 <<23 , 73CSSID_ROY = 1 <<24 74}; 75// This order must match the EventJumpTable in Globals.s 76enum JumpTableIndex { 77JUMP_AMSAHTECH , 78JUMP_ATTACKONSHIELD , 79JUMP_COMBO , 80JUMP_ESCAPESHIEK , 81JUMP_GRABMASH , 82JUMP_LEDGESTALL , 83JUMP_LEDGETECH , 84JUMP_LEDGETECHCOUNTER , 85JUMP_MULTISHINE , 86JUMP_REACTION , 87JUMP_REVERSAL , 88JUMP_SDITRAINING , 89JUMP_SHIELDDROP , 90JUMP_SLIDEOFF , 91JUMP_WAVESHINESDI 92}; 93typedef struct AllowedCharacters 94{ 95// whitelist bitfields of CSSID_* characters 96int hmn ; 97int cpu ; 98}AllowedCharacters ; 99typedef struct EventDesc 100{ 101char * eventName ; 102char * eventDescription ; 103char * eventFile ; 104int jumpTableIndex ; 105char * eventCSSFile ; 106u8 disable_hazards :1 ;// removes stage hazards 107u8 force_sopo :1 ; 108u8 CSSType ; 109AllowedCharacters allowed_characters ; 110s8 playerKind ;// -1 = use selected fighter 111s8 cpuKind ;// -1 = no CPU 112s16 stage ;// -1 = use selected stage 113u8 scoreType ; 114u8 callbackPriority ; 115EventMatchData * matchData ; 116}EventDesc ; 117typedef struct EventPage 118{ 119char * name ; 120int eventNum ; 121EventDesc ** events ; 122}EventPage ; 123 124typedef struct evFunction 125{ 126void (* Event_Init )(GOBJ * event ); 127void (* Event_Update )(void ); 128void (* Event_Think )(GOBJ * event ); 129EventMenu ** menu_start ; 130}evFunction ; 131 132typedef struct Rect 133{ 134float x ,y ,w ,h ; 135}Rect ; 136 137static inline void RectShrink (Rect * dst ,float size ) 138{ 139dst -> x += size ; 140dst -> y += size ; 141dst -> w -= size * 2.f ; 142dst -> 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 }; 148src -> x += size + padding ; 149src -> 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 }; 155src -> 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 }; 161src -> y += size + padding ; 162src -> 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 }; 168src -> 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{ 178u8 peach_item ;// 0x0 179u8 peach_fsmash ;// 0x1 180u8 luigi_misfire ;// 0x2 181u8 gnw_hammer ;// 0x3 182u8 nana_throw ;// 0x4 183}RNGControl ; 184 185typedef struct HUDCamData { 186bool hide ; 187int canvas ; 188u32 text_cache_used ; 189Text * text_cache [32 ]; 190}HUDCamData ; 191 192typedef struct EventVars 193{ 194EventDesc * event_desc ;// event information 195evMenu * menu_assets ;// menu assets 196GOBJ * event_gobj ;// event gobj 197GOBJ * menu_gobj ;// event menu gobj 198RNGControl * rng ;// rng struct pointer 199int game_timer ;// amount of game frames passed 200int (* Savestate_Save_v1 )(Savestate_v1 * savestate ,int flags );// function pointer to save state 201int (* Savestate_Load_v1 )(Savestate_v1 * savestate ,int flags );// function pointer to load state 202GOBJ * (* Message_Display )(int msg_kind ,int queue_num ,int msg_color ,char * format , ...);// function pointer to display message 203int (* Tip_Display )(int lifetime ,char * fmt , ...); 204void (* Tip_Destroy )(void );// function pointer to destroy tip 205Savestate_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. 210int savestate_saved_while_mirrored ; 211int loaded_mirrored ; 212 213evFunction evFunction ;// event specific functions 214HSD_Archive * event_archive ;// event archive header 215DevText * db_console_text ; 216Text * watermark ; 217GOBJ * hudcam_gobj ; 218void (* HUD_DrawRects )(Rect * rects ,GXColor * colors ,int count ); 219void (* HUD_DrawText )(const char * text ,Rect * pos ,float size ); 220void (* HUD_DrawActionLogBar )(u8 * action_log ,GXColor * color_lookup ,int log_count ); 221void (* 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{ 272MSGSTATE_WAIT , 273MSGSTATE_SHIFT , 274MSGSTATE_DELETE , 275}; 276enum MsgArea 277{ 278MSGKIND_P1 , 279MSGKIND_P2 , 280MSGKIND_P3 , 281MSGKIND_P4 , 282MSGKIND_P5 , 283MSGKIND_P6 , 284MSGKIND_GENERAL , 285}; 286typedef struct MsgData 287{ 288Text * text ;// text pointer 289int kind ;// the type of message this is 290int state ;// unused atm 291int prev_index ;// used to animate the messages position during shifts 292int orig_index ;// used to tell if the message moved throughout the course of the frame 293int anim_timer ;// used to track animation frame 294int lifetime ;// amount of frames after spawning to kill this message 295int alive_timer ;// amount of frames this message has been alive for 296}MsgData ; 297typedef struct MsgMngrData 298{ 299COBJ * cobj ; 300int state ; 301int canvas ; 302GOBJ * msg_queue [MSGQUEUE_NUM ][MSGQUEUE_SIZE ];// array 7 is for miscellaneous messages, not related to a player 303}MsgMngrData ; 304 305enum MsgColors 306{ 307MSGCOLOR_WHITE , 308MSGCOLOR_GREEN , 309MSGCOLOR_RED , 310MSGCOLOR_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{ 338GOBJ * gobj ;// tip gobj 339Text * text ;// tip text object 340int state ;// state this tip is in. 0 = in, 1 = wait, 2 = out 341int 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