fork/training-mode-ce
git clone https://git.julia.blue/fork/training-mode-ce
1da5d99
techchase-camera
1#include "events.h" 2 3static Vec2 ledge_positions [2 ]; 4 5static void GetLedgePositions (Vec2 coords_out [2 ]) { 6static char ledge_ids [34 ][2 ]= { 7 {0xFF ,0xFF }, {0xFF ,0xFF }, {0x03 ,0x07 }, {0x33 ,0x36 }, 8 {0x03 ,0x0D }, {0x29 ,0x45 }, {0x05 ,0x11 }, {0x09 ,0x1A }, 9 {0x02 ,0x06 }, {0x15 ,0x17 }, {0x00 ,0x00 }, {0x43 ,0x4C }, 10 {0x00 ,0x00 }, {0x00 ,0x00 }, {0x0E ,0x0D }, {0x00 ,0x00 }, 11 {0x00 ,0x05 }, {0x1E ,0x2E }, {0x0C ,0x0E }, {0x02 ,0x04 }, 12 {0x03 ,0x05 }, {0x00 ,0x00 }, {0x06 ,0x12 }, {0x00 ,0x00 }, 13 {0xD7 ,0xE2 }, {0x00 ,0x00 }, {0x00 ,0x00 }, {0x00 ,0x00 }, 14 {0x03 ,0x05 }, {0x03 ,0x0B }, {0x06 ,0x10 }, {0x00 ,0x05 }, 15 {0x00 ,0x02 }, {0x01 ,0x01 }, 16 }; 17 18int stage_id = Stage_GetExternalID (); 19char left_id = ledge_ids [stage_id ][0 ]; 20char right_id = ledge_ids [stage_id ][1 ]; 21 22Vec3 pos ; 23Stage_GetLeftOfLineCoordinates (left_id ,& pos ); 24coords_out [0 ]= (Vec2 ) {pos .X ,pos .Y }; 25Stage_GetRightOfLineCoordinates (right_id ,& pos ); 26coords_out [1 ]= (Vec2 ) {pos .X ,pos .Y }; 27} 28 29static void UpdatePosition (GOBJ * fighter ) { 30FighterData * data = fighter -> userdata ; 31 32Vec3 pos = data -> phys .pos ; 33data -> coll_data .topN_Curr = pos ; 34data -> coll_data .topN_CurrCorrect = pos ; 35data -> coll_data .topN_Prev = pos ; 36data -> coll_data .topN_Proj = pos ; 37data -> coll_data .coll_test = * stc_colltest ; 38 39JOBJ * jobj = fighter -> hsd_object ; 40jobj -> trans = data -> phys .pos ; 41JOBJ_SetMtxDirtySub (jobj ); 42 43// Update static hmn block coords 44Fighter_SetPosition (data -> ply ,data -> flags .ms ,& data -> phys .pos ); 45} 46 47static bool FindGroundNearPlayer (GOBJ * fighter ,Vec3 * pos ,int * line_idx ) { 48FighterData * data = fighter -> userdata ; 49float x = data -> phys .pos .X ; 50float y1 = data -> phys .pos .Y + 10 ; 51float y2 = data -> phys .pos .Y - 100 ; 52 53Vec3 _line_unk ; 54int _line_kind ; 55 56return GrColl_RaycastGround (pos ,line_idx ,& _line_kind ,& _line_unk , 57-1 ,-1 ,-1 ,0 ,x ,y1 ,x ,y2 ,0 ); 58} 59 60static void PlacePlayerOnGround (GOBJ * fighter ) { 61FighterData * data = fighter -> userdata ; 62 63Vec3 pos ; 64int line_idx ; 65if (FindGroundNearPlayer (fighter ,& pos ,& line_idx )) { 66data -> phys .pos .X = pos .X ; 67data -> phys .pos .Y = pos .Y ; 68data -> coll_data .ground_index = line_idx ; 69 } 70UpdatePosition (fighter ); 71EnvironmentCollision_WaitLanding (fighter ); 72Fighter_SetGrounded (data ); 73} 74 75static void UpdateCameraBox (GOBJ * fighter ) { 76Fighter_UpdateCameraBox (fighter ); 77 78FighterData * data = fighter -> userdata ; 79CmSubject * subject = data -> camera_subject ; 80subject -> boundleft_curr = subject -> boundleft_proj ; 81subject -> boundright_curr = subject -> boundright_proj ; 82 83Match_CorrectCamera (); 84} 85 86void Exit (GOBJ * menu ); 87void Reset (int side_idx ); 88 89enum menu_options { 90OPT_LINES , 91}; 92 93enum ledge_direction { 94DIRECTION_RANDOM , 95DIRECTION_LEFT , 96DIRECTION_RIGHT , 97}; 98 99static EventOption Options_Main []= { 100 { 101 .kind = OPTKIND_TOGGLE , 102 .name = "Enable Line Guides" , 103 .desc = {"Draws horizontal lines at the ledges and at your" , 104"Calculated ledgegrab position" }, 105 }, 106 { 107 .kind = OPTKIND_INFO , 108 .name = "Help" , 109 .desc = {"D-Pad left/right to reset manually to that side" } 110 }, 111 { 112 .kind = OPTKIND_FUNC , 113 .name = "Exit" , 114 .desc = {"Return to the Event Select Screen." }, 115 .OnSelect = Exit , 116 }, 117}; 118 119static EventMenu Menu_Main = { 120 .name = "Sweetspot Training" , 121 .option_num = sizeof (Options_Main ) /sizeof (EventOption ), 122 .options = Options_Main , 123}; 124 125enum event_state { 126STATE_ENDLAG , 127STATE_WAIT_ATTACK , 128STATE_ATTACK_THINK , 129STATE_RESET , 130}; 131 132static struct sideb { 133bool attempted ; 134Vec3 pos ; 135int dir ; 136}sideb = {0 }; 137static int reset_timer = 0 ; 138static int state = STATE_ENDLAG ; 139 140void Draw_Lines () { 141GOBJ * hmn = Fighter_GetGObj (0 ); 142FighterData * hmn_data = hmn -> userdata ; 143CollData * coll_data = & hmn_data -> coll_data ; 144 145if (!Options_Main [OPT_LINES ].val ) 146return ; 147 148COBJ * cur_cam = COBJ_GetCurrent (); 149CObj_SetCurrent (* stc_matchcam_cobj ); 150 151PRIM_DrawMode draw_mode = { 152 .line_width = 16 , 153 .z_compare_enable = true, 154 .z_logic_eq = true, 155 .z_logic_lt = true, 156 .shape = PRIM_SHAPE_LINE_STRIP , 157 }; 158PRIM_BlendMode blend_mode = {0 }; 159 160// Melee calculation for the top of the ledgegrab box 161float ledgegrab_offset = coll_data -> cliffgrab_y_offset + 0.5 * coll_data -> cliffgrab_height ; 162if (hmn_data -> kind == FTKIND_FOX ) { 163// Only Fox drops a small amount during sideb before moving 164ledgegrab_offset -= 1.0 /6.0 ; 165 } 166 167float y = hmn_data -> phys .pos .Y + ledgegrab_offset ; 168float x = hmn_data -> phys .pos .X ; 169u32 color = 0x0000ffff ; 170if (sideb .attempted ) { 171x = sideb .pos .X ; 172y = sideb .pos .Y + ledgegrab_offset ; 173 174Vec2 target_ledge ; 175if (sideb .dir == 1 ) 176target_ledge = ledge_positions [0 ]; 177else 178target_ledge = ledge_positions [1 ]; 179 180float delta = y - target_ledge .Y ; 181 182if (delta <=0 ) {// failure (SD) 183color = 0xff0000ff ; 184 }else if (hmn_data -> state_id == ASID_CLIFFCATCH 185|| hmn_data -> state_id == ASID_CLIFFWAIT ) {// success 186color = 0x00ff00ff ; 187 } 188 } 189 190// draw line at top of ledgegrab box 191PRIM_NEW (2 ,draw_mode ,blend_mode ); 192PRIM_DRAW (-300 ,y ,0 ,color ); 193PRIM_DRAW (300 ,y ,0 ,color ); 194 195// draw line from left edge 196color = 0xffffffff ; 197x = ledge_positions [0 ].X ; 198y = ledge_positions [0 ].Y ; 199PRIM_NEW (2 ,draw_mode ,blend_mode ); 200PRIM_DRAW (x ,y ,0 ,color ); 201PRIM_DRAW (x - 100 ,y ,0 ,color ); 202 203// draw line from right edge 204x = ledge_positions [1 ].X ; 205y = ledge_positions [1 ].Y ; 206PRIM_NEW (2 ,draw_mode ,blend_mode ); 207PRIM_DRAW (x ,y ,0 ,color ); 208PRIM_DRAW (x + 100 ,y ,0 ,color ); 209 210PRIM_CLOSE (); 211CObj_SetCurrent (cur_cam ); 212} 213 214void Event_Init (GOBJ * gobj ) { 215GetLedgePositions (ledge_positions ); 216GOBJ * draw_gobj = GObj_Create (0 ,0 ,0 ); 217GObj_AddGXLink (draw_gobj ,Draw_Lines ,3 ,0 ); 218} 219 220void Event_Think (GOBJ * menu ) { 221if (event_vars -> game_timer == 1 ) { 222event_vars -> Savestate_Save_v1 (event_vars -> savestate ,Savestate_Silent ); 223Reset (0 ); 224 } 225 226// Reset timer is 0 when off, otherwise counts down until reset 227if (reset_timer == 1 ) { 228reset_timer = 0 ; 229Reset (2 ); 230 } 231if (reset_timer > 1 ) 232reset_timer -- ; 233 234GOBJ * hmn = Fighter_GetGObj (0 ); 235FighterData * hmn_data = hmn -> userdata ; 236GOBJ * cpu = Fighter_GetGObj (1 ); 237FighterData * cpu_data = cpu -> userdata ; 238 239// Reset left/right when user presses dpad manually 240if (hmn_data -> input .down & HSD_BUTTON_DPAD_LEFT ) { 241Reset (0 ); 242 }else if (hmn_data -> input .down & HSD_BUTTON_DPAD_RIGHT ) { 243Reset (1 ); 244 } 245 246// Reset when dead 247if (hmn_data -> flags .dead ) 248Reset (2 ); 249 250if (hmn_data -> state_id == 350 ) {// Aerial sideb startup for fox/falco 251sideb .attempted = true; 252sideb .pos = hmn_data -> phys .pos ; 253sideb .dir = hmn_data -> facing_direction ; 254 } 255 256// Begin CPU AI logic 257Fighter_ZeroCPUInputs (cpu_data ); 258 259// always hold crouch when state is higher than endlag 260if (state > STATE_ENDLAG ) 261cpu_data -> cpu .lstickY = -127 ; 262 263switch (state ) { 264case STATE_ENDLAG : 265if (cpu_data -> state_id == ASID_WAIT ) { 266cpu_data -> cpu .lstickY = -127 ; 267state = STATE_WAIT_ATTACK ; 268 } 269break ; 270case STATE_WAIT_ATTACK : 271if (hmn_data -> state_id == 0x15F ) {// side b asid 272// input dtilt 273cpu_data -> cpu .lstickY = -38 ; 274cpu_data -> cpu .held = PAD_BUTTON_A ; 275state = STATE_ATTACK_THINK ; 276 }else if (hmn_data -> state_id == 0x162 // up b asid 277|| hmn_data -> state_id == ASID_ESCAPEAIR ) { 278SFX_Play (0xAF ); 279reset_timer = 30 ; 280state = STATE_RESET ; 281 } 282break ; 283case STATE_ATTACK_THINK : 284if (cpu_data -> state_id != ASID_ATTACKLW3 )break ; 285if (cpu_data -> state .frame == 7 ) { 286FrameSpeedChange (cpu ,0 );// freeze cpu 287if (hmn_data -> victim ) {// if hit 288FrameSpeedChange (cpu ,1.0 );// unfreeze 289reset_timer = 30 ; 290state = STATE_RESET ; 291 } 292 } 293if (hmn_data -> state_id == ASID_CLIFFCATCH ) { 294SFX_Play (0xAD ); 295FrameSpeedChange (cpu ,1.0 ); 296reset_timer = 60 ; 297state = STATE_RESET ; 298 } 299break ; 300case STATE_RESET : 301break ; 302 } 303 304} 305 306void Exit (GOBJ * menu ) { 307stc_match -> state = 3 ; 308Match_EndVS (); 309} 310 311void Reset (int side_idx ) { 312if (side_idx == 2 ) 313side_idx = HSD_Randi (2 ); 314if (side_idx != 0 && side_idx != 1 ) 315assert ("invalid side" ); 316 317event_vars -> Savestate_Load_v1 (event_vars -> savestate ,Savestate_Silent ); 318sideb .attempted = false; 319 320GOBJ * hmn = Fighter_GetGObj (0 ); 321FighterData * hmn_data = hmn -> userdata ; 322GOBJ * cpu = Fighter_GetGObj (1 ); 323FighterData * cpu_data = cpu -> userdata ; 324 325int side = side_idx * 2 - 1 ; 326hmn_data -> facing_direction = - side ; 327cpu_data -> facing_direction = side ; 328 329hmn_data -> phys .pos .X = side * 12 + ledge_positions [side_idx ].X ; 330hmn_data -> phys .pos .Y = 6 ; 331cpu_data -> phys .pos .X = side * -15 + ledge_positions [side_idx ].X ; 332cpu_data -> phys .pos .Y = 0 ; 333 334UpdatePosition (hmn ); 335UpdatePosition (cpu ); 336PlacePlayerOnGround (cpu ); 337 338// cpu state 339cpu_data -> gfx = 0 ; 340FSmash_GetASForAnalogAngle (cpu ); 341Fighter_ApplyAnimation (cpu ,11 ,1 ,0 ); 342cpu_data -> state .frame = 11 ; 343cpu_data -> script .script_event_timer = 0 ; 344Fighter_SubactionFastForward (cpu ); 345Fighter_UpdateStateFrameInfo (cpu ); 346Fighter_HitboxDisableAll (cpu ); 347cpu_data -> script .script_current = 0 ; 348UpdateCameraBox (cpu ); 349 350// hmn state 351ActionStateChange (0 ,1 ,0 ,hmn ,ASID_DAMAGEFLYN ,0x40 ,0 ); 352Fighter_UpdateStateFrameInfo (hmn ); 353UpdateCameraBox (hmn ); 354float dmg = 50 * HSD_Randf ()+ 50 ; 355hmn_data -> dmg .percent = dmg ; 356Fighter_SetHUDDamage (hmn_data -> ply ,dmg ); 357 358// hmn knockback 359float angle = (15 * HSD_Randf ()+ 45 )* M_1DEGREE ; 360float mag = 30 * HSD_Randf ()+ 105 ; 361float vel = mag * (* stc_ftcommon )-> force_applied_to_kb_mag_multiplier ; 362hmn_data -> phys .kb_vel .X = cos (angle )* vel * side ; 363hmn_data -> phys .kb_vel .Y = sin (angle )* vel ; 364float kb_frames = (float )(int )((* stc_ftcommon )-> x154 * mag ); 365 366union IntToFloat { 367int i ; 368float f ; 369 }itf ; 370itf .f = kb_frames ; 371hmn_data -> state_var .state_var1 = itf .i ; 372 373hmn_data -> flags .hitstun = 1 ; 374Fighter_EnableCollUpdate (hmn_data ); 375 376// give both hitlag 377hmn_data -> dmg .hitlag_frames = 10 ; 378hmn_data -> flags .hitlag = 1 ; 379hmn_data -> flags .hitlag_unk = 1 ; 380cpu_data -> dmg .hitlag_frames = 10 ; 381cpu_data -> flags .hitlag = 1 ; 382cpu_data -> flags .hitlag_unk = 1 ; 383 384reset_timer = 0 ; 385state = STATE_ENDLAG ; 386} 387 388EventMenu * Event_Menu = & Menu_Main ;