fork/slippc
git clone https://git.julia.blue/fork/slippc
81596bb
0.4.0
1 2#ifndef ANALYSIS_H_ 3#define ANALYSIS_H_ 4 5#include <iostream> 6#include <fstream> 7#include <unistd.h> //usleep 8#include <math.h> //sqrt 9 10#include "enums.h" 11#include "util.h" 12 13const unsigned MAX_ATTACKS = 65535 ;//Maximum number of attacks per player per game (increase later if needed) 14const unsigned MAX_PUNISHES = 65535 ;//Maximum number of punishes per player per game (increase later if needed) 15 16namespace slip { 17 18//Struct for storing information about each attack landed 19struct Attack { 20uint8_t move_id = 0 ;//ID of the move that hit 21float anim_frame = 0 ;//Animation frame when the move hit 22uint8_t punish_id = 0 ;//Index of the punish this move is a part of (one punish per opening) 23uint8_t hit_id = 0 ;//Index of the hit number for the current move (applies only to multihits) 24unsigned frame = 0 ;//Frame the move connected (0 == internal frame -123) 25float damage = 0 ;//Damage dealt by the move 26uint8_t opening = 0 ;//Opening type for first hit of punish (TODO: make an enum for this) 27uint8_t kill_dir = 0 ;//Direction of kill, as specified in Dir enum (-1 = didn't kill) 28uint8_t cancel_type = 0 ;//How the move was canceled (as applicable) 29}; 30 31//Struct for storing basic punish infomations 32struct Punish { 33uint8_t num_moves = 0 ;//Number of moves (hitboxes connected) in the current punish 34unsigned start_frame = 0 ;//First frame of punish (0 == internal frame -123) 35unsigned end_frame = 0 ;//Last frame of punish (0 == internal frame -123) 36float start_pct = 0 ;//Opponent's damage on first frame of punish 37float end_pct = 0 ;//Opponent's damage on last frame of punish 38uint8_t last_move_id = 0 ;//ID of the last move that hit 39uint8_t opening = 0 ;//Opening type for first hit of punish (TODO: make an enum for this) 40uint8_t kill_dir = 0 ;//Direction of kill, as specified in Dir enum (-1 = didn't kill) 41}; 42 43//Struct for holding analysis data for a particular player within a game 44struct AnalysisPlayer { 45unsigned port = 0 ;//0-indexed port number of the player (0-3 are valid) 46std ::string tag_player = "";//Tag of the player as recorded in the game metadata 47std ::string tag_css = "";//Tag of the player as chosen on the char. select screen 48unsigned char_id = 0 ;//External ID of the selected character 49std ::string char_name = "";//Name of the selected character 50unsigned player_type = 0 ;//Type of player (0=human, 1=CPU, 2=demo, 3=none) 51unsigned cpu_level = 0 ;//Our level if we're a CPU 52unsigned start_stocks = 0 ;//Number of stocks we started with 53unsigned color = 0 ;//Costume color 54unsigned team_id = 0 ;//ID of the team we're on 55unsigned end_stocks = 0 ;//Stock count on the last frame 56unsigned end_pct = 0 ;//Damage on the last frame 57 58unsigned airdodges = 0 ;//Number of airdodges performed 59unsigned spotdodges = 0 ;//Number of spotdodges performed 60unsigned rolls = 0 ;//Number of rolls performed 61unsigned dashdances = 0 ;//Number of dashdances performed 62unsigned l_cancels_hit = 0 ;//Number of L-cancels performed 63unsigned l_cancels_missed = 0 ;//Number of L-cancels failed 64unsigned techs = 0 ;//Number of ground techs performed 65unsigned walltechs = 0 ;//Number of wall techs performed 66unsigned walljumps = 0 ;//Number of wall jumps performed 67unsigned walltechjumps = 0 ;//Number of wall tech jumps performed 68unsigned missed_techs = 0 ;//Number of (ground) techs missed 69unsigned ledge_grabs = 0 ;//Number of times we grabbed the ledge 70unsigned air_frames = 0 ;//Number of frames spent airborne 71unsigned wavedashes = 0 ;//Number of wavedashes performed 72unsigned wavelands = 0 ;//Number of wavelands performed 73unsigned neutral_wins = 0 ;//Number of times we won neutral 74unsigned pokes = 0 ;//Number of times we poked (single hits not leading to punishes) 75unsigned counters = 0 ;//Number of counterattacks we performed 76unsigned powershields = 0 ;//Number of times we successfully powershielded 77unsigned shield_breaks = 0 ;//Number of times we broke our opponent's shield 78unsigned grabs = 0 ;//Number of grabs we landed 79unsigned grab_escapes = 0 ;//Number of grabs we mashed out of 80unsigned taunts = 0 ;//Number of taunts we performed 81unsigned meteor_cancels = 0 ;//Number of meteor cancels we performed 82float damage_dealt = 0 ;//Total damage the player has dealth over the course of the game 83unsigned hits_blocked = 0 ;//Number of hits blocked by shield 84unsigned shield_stabs = 0 ;//Number of times we've shield stabbed our opponent 85unsigned edge_cancel_aerials = 0 ;//Number of aerials edge cancelled 86unsigned edge_cancel_specials = 0 ;//Number of special moves / air dodges / zairs edge cancelled 87unsigned phantom_hits = 0 ;//Number of phantoms we hit our opponent with 88unsigned shield_drops = 0 ;//Number of shield drops performed 89unsigned no_impact_lands = 0 ;//Number of no impact lands (NILs) performed 90unsigned pivots = 0 ;//Number of pivots performed 91unsigned reverse_edgeguards = 0 ;//Number of times we scored a KO while recovering 92unsigned self_destructs = 0 ;//Number of times we died in neutral 93unsigned stage_spikes = 0 ;//Number of times we KO'd our opponents with a stage spike 94unsigned short_hops = 0 ;//Number of short hops we performed 95unsigned full_hops = 0 ;//Number of full hops we performed 96unsigned shield_time = 0 ;//Number of frames we spent in shield 97float shield_damage = 0 ;//Cumulative shield damage taken over the course of the game 98float shield_lowest = 60 ;//Lowest shield health we had at any point in the match 99unsigned teeter_cancel_aerials = 0 ;//Number of aerials teeter cancelled 100unsigned teeter_cancel_specials = 0 ;//Number of special moves / air dodges / zairs teeter cancelled 101unsigned total_openings = 0 ;//Total number of openings (poke + neutral win + counterattack) 102float mean_kill_openings = 0 ;//Average number of openings needed before getting a kill 103float mean_kill_percent = 0 ;//Average damage done before taking a stock 104float mean_opening_percent = 0 ;//Average damage done during each opening / punish 105unsigned galint_ledgedashes = 0 ;//Number of intangible ledgedashes performed 106float mean_galint = 0 ;//Average GALINT frames after a ledgedash 107 108unsigned * move_counts ;//Counts for each move the player landed 109unsigned * dyn_counts ;//Frame counts for player interaction dynamics 110float * dyn_damage ;//Damage done during each player interaction dynamic 111Attack * attacks ;//List of all attacks we connected with throughout the game 112Punish * punishes ;//List of all punishes we performed throughout the game 113 114AnalysisPlayer () { 115move_counts = new unsigned [Move ::__LAST ]{0 }; 116dyn_counts = new unsigned [Dynamic ::__LAST ]{0 }; 117dyn_damage = new float [Dynamic ::__LAST ]{0 }; 118attacks = new Attack [MAX_ATTACKS ]; 119punishes = new Punish [MAX_PUNISHES ]; 120 } 121 ~AnalysisPlayer () { 122delete []punishes ; 123delete []attacks ; 124delete []dyn_damage ; 125delete []dyn_counts ; 126delete []move_counts ; 127 } 128}; 129 130//Struct for holding all analysis data within a game 131struct Analysis { 132bool success = false;//Whether we succeeded analyzing a replay 133std ::string game_time = "" ;//When the game was played, from replay metadata 134std ::string slippi_version = "" ;//Version of Slippi the replay was recorded with 135std ::string parser_version = "" ;//Version of parser the replay was parsed with 136std ::string analyzer_version = "" ;//Version of this analyzer we are using 137 unsignedstage_id = 0 ;//Internal ID of the stage 138std ::string stage_name = "" ;//Readable name of the stage 139int winner_port = 0 ;//Port index of the winning player (-1 == no winner) 140 unsignedgame_length = 0 ;//Length of the game in frames (0 == internal frame -123) 141AnalysisPlayer * ap ;//Analysis of individual players in the game 142 unsigned* dynamics ;//Interaction dynamics on a per-frame basis 143 144Analysis (unsigned frame_count ) { 145dynamics = new unsigned [frame_count ]{0 };// List of dynamics active at each frame 146ap = new AnalysisPlayer [2 ];// The two players being analyzed 147 } 148 ~Analysis () { 149delete []ap ; 150delete []dynamics ; 151 } 152 153std ::string asJson ();//Convert the analysis structure to a JSON 154void save (const char * outfilename );//Write the analysis out to a JSON file 155}; 156 157} 158 159#endif /* ANALYSIS_H_ */