fork/slippc
git clone https://git.julia.blue/fork/slippc
81596bb
0.4.0
1#ifndef ANALYZER_H_ 2#define ANALYZER_H_ 3 4#include <iostream> 5#include <fstream> 6#include <math.h> //sqrt 7 8#include "enums.h" 9#include "util.h" 10#include "replay.h" 11#include "analysis.h" 12 13//Version number for the analyzer 14const std ::string ANALYZER_VERSION = "0.4.0" ; 15 16const unsigned TIMER_MINS = 8 ;//Assuming a fixed 8 minute time for now (TODO: might need to change later) 17const unsigned SHARK_THRES = 15 ;//Minimum frames to be out of hitstun before comboing becomes sharking 18const unsigned POKE_THRES = 30 ;//Frames since either player entered hitstun to consider neutral a poke 19const float FOOTSIE_THRES = 10.0f ;//Distance cutoff between FOOTSIES and POSITIONING dynamics 20 21namespace slip { 22 23class Analyzer { 24private : 25int _debug ;//Current debug level 26 27bool get1v1Ports (const SlippiReplay & s ,Analysis * a )const ; 28void analyzeInteractions (const SlippiReplay & s ,Analysis * a )const ; 29void analyzePunishes (const SlippiReplay & s ,Analysis * a )const ; 30void analyzeCancels (const SlippiReplay & s ,Analysis * a )const ; 31void analyzeShield (const SlippiReplay & s ,Analysis * a )const ; 32void analyzeLedgedashes (const SlippiReplay & s ,Analysis * a )const ; 33void getBasicGameInfo (const SlippiReplay & s ,Analysis * a )const ; 34void summarizeInteractions (const SlippiReplay & s ,Analysis * a )const ; 35void computeAirtime (const SlippiReplay & s ,Analysis * a )const ; 36void countLCancels (const SlippiReplay & s ,Analysis * a )const ; 37void countTechs (const SlippiReplay & s ,Analysis * a )const ; 38void countDashdances (const SlippiReplay & s ,Analysis * a )const ; 39void countAirdodgesAndWavelands (const SlippiReplay & s ,Analysis * a )const ; 40void countBasicAnimations (const SlippiReplay & s ,Analysis * a )const ; 41void countPhantoms (const SlippiReplay & s ,Analysis * a )const ; 42void showActionStates (const SlippiReplay & s ,Analysis * a )const ; 43void computeTrivialInfo (const SlippiReplay & s ,Analysis * a )const ; 44unsigned countTransitions (const SlippiReplay & s ,Analysis * a ,unsigned pnum ,bool (* cb )(const SlippiFrame & ))const ; 45unsigned countTransitions (const SlippiReplay & s ,Analysis * a ,unsigned pnum ,bool (* cb )(const SlippiPlayer & ,const unsigned ))const ; 46 47static inline float getHitStun (const SlippiFrame & f ) { 48return f .hitstun ; 49 } 50static inline float playerDistance (const SlippiFrame & pf ,const SlippiFrame & of ) { 51float xd = pf .pos_x_pre - of .pos_x_pre ; 52float yd = pf .pos_y_pre - of .pos_y_pre ; 53return sqrt (xd * xd + yd * yd ); 54 } 55static inline bool isOffStage (const SlippiReplay & s ,const SlippiFrame & f ) { 56return isAirborne (f )&& ( 57f .pos_x_pre > Stage ::ledge [s .stage ]|| 58f .pos_x_pre < - Stage ::ledge [s .stage ]|| 59f .pos_y_pre < 0 ); 60 } 61static inline bool wasHitByPhantom (const SlippiPlayer & p ,const SlippiPlayer & o ,const unsigned f ) { 62//Phantom detection: 63//Defender is in hitlag at least 2 frames before taking damage 64//Attacker is NOT in hitlag at least 2 frames before taking damage 65//Defender is NOT in hitstun -> TODO: misses edge cases where players are hit by phantoms while in hitstun from another attack 66//Attacker is not throwing 67//Defender's damage increased since last frame 68return isInHitlag (p .frame [f - 2 ])&& 69 (not isInHitlag (o .frame [f - 2 ]))&& 70 (not isInHitstun (p .frame [f ]))&& 71 (not isThrowing (o .frame [f ]))&& 72p .frame [f - 1 ].percent_pre < p .frame [f ].percent_post 73 ; 74 } 75static inline bool wasShieldStabbed (const SlippiPlayer & p ,const unsigned f ) { 76return p .frame [f - 1 ].action_post >=Action ::GuardOn 77&& p .frame [f - 1 ].action_post <=Action ::GuardReflect 78&& p .frame [f ].percent_post > p .frame [f - 1 ].percent_post ; 79 } 80static inline bool wasStageSpiked (const SlippiFrame & f ) { 81return (f .action_pre == Action ::FlyReflectWall || f .action_pre == Action ::FlyReflectCeil ) 82&& f .action_post <=Action ::DeadUpFallHitCameraIce ; 83 } 84static inline bool didEdgeCancelAerial (const SlippiFrame & f ) { 85return f .action_post >=Action ::Fall 86&& f .action_post <=Action ::FallB 87&& f .action_pre >=Action ::LandingAirN 88&& f .action_pre <=Action ::LandingAirLw ; 89 } 90static inline bool didTeeterCancelAerial (const SlippiFrame & f ) { 91return f .action_post >=Action ::Ottotto 92&& f .action_post <=Action ::OttottoWait 93&& f .action_pre >=Action ::LandingAirN 94&& f .action_pre <=Action ::LandingAirLw ; 95 } 96static inline bool didAutoCancelAerial (const SlippiFrame & f ) { 97return f .action_post == Action ::Landing 98&& f .action_pre >=Action ::AttackAirN 99&& f .action_pre <=Action ::AttackAirLw ; 100 } 101static inline bool didNoImpactLand (const SlippiFrame & f ) { 102return f .action_pre >=Action ::JumpF 103&& f .action_pre <=Action ::JumpAerialB 104&& f .action_post == Action ::Wait ; 105 } 106static inline bool didShieldDrop (const SlippiFrame & f ) { 107return f .action_pre >=Action ::GuardOn 108&& f .action_pre <=Action ::GuardOff 109&& f .action_post == Action ::Pass ; 110 } 111static inline bool didEdgeCancelSpecial (const SlippiFrame & f ) { 112return f .action_post >=Action ::Fall 113&& f .action_post <=Action ::FallB 114&& f .action_pre == Action ::LandingFallSpecial ; 115 } 116static inline bool didTeeterCancelSpecial (const SlippiFrame & f ) { 117return f .action_post >=Action ::Ottotto 118&& f .action_post <=Action ::OttottoWait 119&& f .action_pre == Action ::LandingFallSpecial ; 120 } 121static inline bool didPivot (const SlippiPlayer & p ,const unsigned f ) { 122return p .frame [f ].action_pre == Action ::Turn 123&& p .frame [f - 1 ].action_pre == Action ::Dash 124&& p .frame [f ].action_post != Action ::Dash 125&& (not isInHitstun (p .frame [f ])) 126 ; 127 } 128static inline bool isJumpHeld (const SlippiPlayer & p ,const unsigned f ) { 129return p .frame [f ].buttons & 0x0C00 ;//0000 1100 0000 0000 130 } 131static inline bool didHop (const SlippiPlayer & p ,const unsigned f ) { 132return p .frame [f - 1 ].action_post == Action ::KneeBend 133&& (p .frame [f ].action_post == Action ::JumpF || p .frame [f ].action_post == Action ::JumpB ); 134 } 135static inline bool didShortHop (const SlippiPlayer & p ,const unsigned f ) { 136return didHop (p ,f )&& (not isJumpHeld (p ,f )); 137 } 138static inline bool didPowerShield (const SlippiPlayer & p ,const unsigned f ) { 139return (p .frame [f ].flags_4 & 0x20 )&& (not (p .frame [f - 1 ].flags_4 & 0x20 )); 140 } 141static inline bool didMeteorCancel (const SlippiPlayer & p ,const unsigned f ) { 142return isInHitstun (p .frame [f - 1 ]) 143&& (getHitStun (p .frame [f - 1 ]) >=2.0f ) 144&& (!isInHitstun (p .frame [f ])) 145&& (p .frame [f ].action_post > Action ::Wait1 146|| p .frame [f ].action_post == Action ::JumpAerialF 147|| p .frame [f ].action_post == Action ::JumpAerialB ); 148 } 149static inline bool didCliffCatchEnd (const SlippiPlayer & p ,const unsigned f ) { 150return p .frame [f ].action_pre == Action ::CliffWait && p .frame [f - 1 ].action_pre == Action ::CliffCatch ; 151 } 152static inline bool didAttemptLedgedash (const SlippiPlayer & p ,const unsigned f ) { 153return p .frame [f - 1 ].action_pre == Action ::CliffWait && p .frame [f ].action_pre == Action ::Fall ; 154 } 155static inline unsigned deathDirection (const SlippiPlayer & p ,const unsigned f ) { 156if (p .frame [f ].action_post == Action ::DeadDown ) {return Dir ::DOWN ; } 157if (p .frame [f ].action_post == Action ::DeadLeft ) {return Dir ::LEFT ; } 158if (p .frame [f ].action_post == Action ::DeadRight ) {return Dir ::RIGHT ; } 159if (p .frame [f ].action_post < Action ::Sleep ) {return Dir ::UP ; } 160return Dir ::NEUT ; 161 } 162//NOTE: the next few functions do not check for valid frame indices 163// This is technically unsafe, but boolean shortcut logic should ensure the unsafe 164// portions never get called. 165static inline bool maybeWavelanding (const SlippiPlayer & p ,const unsigned f ) { 166//Code credit to Fizzi 167return p .frame [f ].action_pre == Action ::LandingFallSpecial && ( 168p .frame [f - 1 ].action_pre == Action ::EscapeAir || ( 169p .frame [f - 1 ].action_pre >=Action ::KneeBend && 170p .frame [f - 1 ].action_pre <=Action ::FallAerialB 171 ) 172 ); 173 } 174static inline bool isDashdancing (const SlippiPlayer & p ,const unsigned f ) { 175//Code credit to Fizzi. This SHOULD never thrown an exception, since we 176// should never be in turn animation before frame 2 177return (p .frame [f ].action_pre == Action ::Dash ) 178&& (p .frame [f - 1 ].action_pre == Action ::Turn ) 179&& (p .frame [f - 2 ].action_pre == Action ::Dash ); 180 } 181static inline bool isShieldBroken (const SlippiFrame & f ) { 182return f .action_pre == Action ::ShieldBreakFly 183|| f .action_pre == Action ::ShieldBreakFall ; 184 } 185static inline bool isInJumpsquat (const SlippiFrame & f ) { 186return f .action_pre == Action ::KneeBend ; 187 } 188static inline bool isSpotdodging (const SlippiFrame & f ) { 189return f .action_pre == Action ::Escape ; 190 } 191static inline bool isAirdodging (const SlippiFrame & f ) { 192return f .action_pre == Action ::EscapeAir ; 193 } 194static inline bool isGrabbing (const SlippiFrame & f ) { 195return (f .action_pre >=Action ::CatchPull )&& (f .action_pre <=Action ::CatchAttack ); 196 } 197static inline bool isTaunting (const SlippiFrame & f ) { 198return (f .action_pre == Action ::AppealR )|| (f .action_pre == Action ::AppealL ); 199 } 200static inline bool isReleasing (const SlippiFrame & f ) { 201return f .action_pre == Action ::CatchCut ; 202 } 203static inline bool isRolling (const SlippiFrame & f ) { 204return (f .action_pre == Action ::EscapeF )|| (f .action_pre == Action ::EscapeB ); 205 } 206static inline bool isDodging (const SlippiFrame & f ) { 207return (f .action_pre >=Action ::EscapeF )&& (f .action_pre <=Action ::Escape ); 208 } 209static inline bool isLanding (const SlippiFrame & f ) { 210return (f .action_post == Action ::Landing )|| (f .action_post == Action ::LandingFallSpecial ); 211 } 212static inline bool inTumble (const SlippiFrame & f ) { 213return f .action_pre == Action ::DamageFall ; 214 } 215static inline bool inDamagedState (const SlippiFrame & f ) { 216return (f .action_pre >=Action ::DamageHi1 )&& (f .action_pre <=Action ::DamageFlyRoll ); 217 } 218static inline bool inMissedTechState (const SlippiFrame & f ) { 219return (f .action_pre >=Action ::DownBoundU )&& (f .action_pre <=Action ::DownSpotD ); 220 } 221//Excludes wall techs, wall jumps, and ceiling techs 222static inline bool inFloorTechState (const SlippiFrame & f ) { 223return (f .action_pre >=Action ::DownBoundU )&& (f .action_pre <=Action ::PassiveStandB ); 224 } 225//Includes wall techs, wall jumps, and ceiling techs 226static inline bool inTechState (const SlippiFrame & f ) { 227return (f .action_pre >=Action ::DownBoundU )&& (f .action_pre <=Action ::PassiveCeil ); 228 } 229static inline bool isInShieldstun (const SlippiFrame & f ) { 230return f .action_pre == Action ::GuardSetOff ; 231 } 232static inline bool isGrabbed (const SlippiFrame & f ) { 233return 234 ((f .action_pre >=Action ::CapturePulledHi )&& (f .action_pre <=Action ::CaptureFoot ))|| 235 ((f .action_pre >=Action ::CaptureCaptain )&& (f .action_pre <=Action ::ThrownKirby )); 236 } 237static inline bool isThrown (const SlippiFrame & f ) { 238return (f .action_pre >=Action ::ThrownF )&& (f .action_pre <=Action ::ThrownLwWomen ); 239 } 240static inline bool isThrowing (const SlippiFrame & f ) { 241return (f .action_pre >=Action ::ThrowF )&& (f .action_pre <=Action ::ThrowLw ); 242 } 243static inline bool isOnLedge (const SlippiFrame & f ) { 244return f .action_pre == Action ::CliffWait ; 245 } 246static inline bool isAirborne (const SlippiFrame & f ) { 247return f .airborne ; 248 } 249static inline bool isInHitlag (const SlippiFrame & f ) { 250return f .flags_2 & 0x20 ; 251 } 252static inline bool isShielding (const SlippiFrame & f ) { 253return f .flags_3 & 0x80 ; 254 } 255static inline bool isInHitstun (const SlippiFrame & f ) { 256return f .flags_4 & 0x02 ; 257 } 258static inline bool isOffscreen (const SlippiFrame & f ) { 259return f .flags_5 & 0x80 ; 260 } 261static inline bool isDead (const SlippiFrame & f ) { 262return (f .flags_5 & 0x10 )|| f .action_pre < Action ::Sleep ; 263 } 264static inline std ::string frameAsTimer (unsigned fnum ,unsigned startmins ) { 265if (startmins == 0 ) { 266return "no timer" ; 267 } 268int startframes = 3600 * startmins ;//Total number of frames in the match 269int elapsed = fnum + LOAD_FRAME ;//Number of frames elapsed since timer started 270if (elapsed < 0 ) { 271return std ::to_string (startmins )+ ":00:00" ; 272 } 273int remaining = startframes - elapsed ; 274int lmins = remaining /3600 ; 275int lsecs = (remaining %3600 )/60 ; 276int lframes = remaining %60 ; 277return std ::to_string (lmins )+ ":" 278+ (lsecs < 10 ?"0" :"" )+ std ::to_string (lsecs )+ ":" 279+ (lframes < 6 ?"0" :"" )+ std ::to_string (int (100 * (float )lframes /60.0f )); 280 } 281public : 282Analyzer (int debug_level ); 283~ Analyzer (); 284Analysis * analyze ( const SlippiReplay & s); 285}; 286 287} 288 289#endif /* ANALYZER_H_ */