fork/slippc

git clone https://git.julia.blue/fork/slippc

Patrick Crainadded ability to parse and analyze partially corrupt files; added punish stock info to analysis json output7fcd71c

compression
12.1 KiB193 linesraw
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 {
20  uint8_t  move_id      = 0;  //ID of the move that hit
21  float    anim_frame   = 0;  //Animation frame when the move hit
22  uint8_t  punish_id    = 0;  //Index of the punish this move is a part of (one punish per opening)
23  uint8_t  hit_id       = 0;  //Index of the hit number for the current move (applies only to multihits)
24  unsigned frame        = 0;  //Frame the move connected (0 == internal frame -123)
25  float    damage       = 0;  //Damage dealt by the move
26  uint8_t  opening      = 0;  //Opening type for first hit of punish (TODO: make an enum for this)
27  uint8_t  kill_dir     = 0;  //Direction of kill, as specified in Dir enum (-1 = didn't kill)
28  uint8_t  cancel_type  = 0;  //How the move was canceled (as applicable)
29};
30
31//Struct for storing basic punish infomations
32struct Punish {
33  uint8_t  num_moves    = 0;  //Number of moves (hitboxes connected) in the current punish
34  unsigned start_frame  = 0;  //First frame of punish (0 == internal frame -123)
35  unsigned end_frame    = 0;  //Last frame of punish (0 == internal frame -123)
36  float    start_pct    = 0;  //Opponent's damage on first frame of punish
37  float    end_pct      = 0;  //Opponent's damage on last frame of punish
38  int      stocks       = 0;  //Opponent's stocks on first frame of punish
39  uint8_t  last_move_id = 0;  //ID of the last move that hit
40  uint8_t  opening      = 0;  //Opening type for first hit of punish (TODO: make an enum for this)
41  uint8_t  kill_dir     = 0;  //Direction of kill, as specified in Dir enum (-1 = didn't kill)
42};
43
44//Struct for holding analysis data for a particular player within a game
45struct AnalysisPlayer {
46  unsigned     port                   =  0;  //0-indexed port number of the player (0-3 are valid)
47  std::string  tag_player             =  ""; //Tag of the player as recorded in the game metadata
48  std::string  tag_css                =  ""; //Tag of the player as chosen on the char. select screen
49  std::string  tag_code               =  ""; //Code for the player on Slippi Online
50  unsigned     char_id                =  0;  //External ID of the selected character
51  std::string  char_name              =  ""; //Name of the selected character
52  unsigned     player_type            =  0;  //Type of player (0=human, 1=CPU, 2=demo, 3=none)
53  unsigned     cpu_level              =  0;  //Our level if we're a CPU
54  unsigned     start_stocks           =  0;  //Number of stocks we started with
55  unsigned     color                  =  0;  //Costume color
56  unsigned     team_id                =  0;  //ID of the team we're on
57  unsigned     end_stocks             =  0;  //Stock count on the last frame
58  unsigned     end_pct                =  0;  //Damage on the last frame
59
60  unsigned     airdodges              =  0;  //Number of airdodges performed
61  unsigned     spotdodges             =  0;  //Number of spotdodges performed
62  unsigned     rolls                  =  0;  //Number of rolls performed
63  unsigned     dashdances             =  0;  //Number of dashdances performed
64  unsigned     l_cancels_hit          =  0;  //Number of L-cancels performed
65  unsigned     l_cancels_missed       =  0;  //Number of L-cancels failed
66  unsigned     techs                  =  0;  //Number of ground techs performed
67  unsigned     walltechs              =  0;  //Number of wall techs performed
68  unsigned     walljumps              =  0;  //Number of wall jumps performed
69  unsigned     walltechjumps          =  0;  //Number of wall tech jumps performed
70  unsigned     missed_techs           =  0;  //Number of (ground) techs missed
71  unsigned     ledge_grabs            =  0;  //Number of times we grabbed the ledge
72  unsigned     air_frames             =  0;  //Number of frames spent airborne
73  unsigned     wavedashes             =  0;  //Number of wavedashes performed
74  unsigned     wavelands              =  0;  //Number of wavelands performed
75  unsigned     neutral_wins           =  0;  //Number of times we won neutral
76  unsigned     pokes                  =  0;  //Number of times we poked (single hits not leading to punishes)
77  unsigned     counters               =  0;  //Number of counterattacks we performed
78  unsigned     powershields           =  0;  //Number of times we successfully powershielded
79  unsigned     shield_breaks          =  0;  //Number of times we broke our opponent's shield
80  unsigned     grabs                  =  0;  //Number of grabs we landed
81  unsigned     grab_escapes           =  0;  //Number of grabs we mashed out of
82  unsigned     taunts                 =  0;  //Number of taunts we performed
83  unsigned     meteor_cancels         =  0;  //Number of meteor cancels we performed
84  float        damage_dealt           =  0;  //Total damage the player has dealth over the course of the game
85  unsigned     hits_blocked           =  0;  //Number of hits blocked by shield
86  unsigned     shield_stabs           =  0;  //Number of times we've shield stabbed our opponent
87  unsigned     edge_cancel_aerials    =  0;  //Number of aerials edge cancelled
88  unsigned     edge_cancel_specials   =  0;  //Number of special moves / air dodges / zairs edge cancelled
89  unsigned     phantom_hits           =  0;  //Number of phantoms we hit our opponent with
90  unsigned     shield_drops           =  0;  //Number of shield drops performed
91  unsigned     no_impact_lands        =  0;  //Number of no impact lands (NILs) performed
92  unsigned     pivots                 =  0;  //Number of pivots performed
93  unsigned     reverse_edgeguards     =  0;  //Number of times we scored a KO while recovering
94  unsigned     self_destructs         =  0;  //Number of times we died in neutral
95  unsigned     stage_spikes           =  0;  //Number of times we KO'd our opponents with a stage spike
96  unsigned     short_hops             =  0;  //Number of short hops we performed
97  unsigned     full_hops              =  0;  //Number of full hops we performed
98  unsigned     shield_time            =  0;  //Number of frames we spent in shield
99  float        shield_damage          =  0;  //Cumulative shield damage taken over the course of the game
100  float        shield_lowest          = 60;  //Lowest shield health we had at any point in the match
101  unsigned     teeter_cancel_aerials  =  0;  //Number of aerials teeter cancelled
102  unsigned     teeter_cancel_specials =  0;  //Number of special moves / air dodges / zairs teeter cancelled
103  unsigned     total_openings         =  0;  //Total number of openings (pokes + neutral wins)
104  float        mean_kill_openings     =  0;  //Average number of openings needed before getting a kill
105  float        mean_kill_percent      =  0;  //Average damage done before taking a stock
106  float        mean_opening_percent   =  0;  //Average damage done during each opening / punish
107  unsigned     galint_ledgedashes     =  0;  //Number of intangible ledgedashes performed
108  float        mean_galint            =  0;  //Average GALINT frames after a ledgedash
109  unsigned     shieldstun_times       =  0;  //Number of times we entered shieldstun
110  unsigned     shieldstun_act_frames  =  0;  //Total frames we spent acting out of shieldstun
111  unsigned     hitstun_times          =  0;  //Number of times we entered hitstun
112  unsigned     hitstun_act_frames     =  0;  //Total frames we spent acting out of hitstun
113  unsigned     wait_times             =  0;  //Number of times we entered wait
114  unsigned     wait_act_frames        =  0;  //Total frames we spent acting out of wait
115
116  unsigned     max_galint             =  0;  //Maximum GALINT frames after a ledgedash
117  unsigned     button_count           =  0;  //Button presses
118  unsigned     cstick_count           =  0;  //C stick movements
119  unsigned     astick_count           =  0;  //Action state changes
120  float        apm                    =  0;  //Actions per minute (combines buttons and csticks)
121  unsigned     state_changes          =  0;  //Analog stick movements
122  float        aspm                   =  0;  //Action states per minute
123
124  unsigned     used_throws            =  0;  //Number of throws we threw out
125  unsigned     used_norm_moves        =  0;  //Number of normals we threw out
126  unsigned     used_spec_moves        =  0;  //Number of specials we threw out
127  unsigned     used_misc_moves        =  0;  //Number of misc. moves (getups, ledge attacks, etc.) we threw out
128  unsigned     used_grabs             =  0;  //Number of grabs we threw out
129  unsigned     used_pummels           =  0;  //Number of pummels we threw out
130  unsigned     total_moves_used       =  0;  //Total number of moves we threw out
131  unsigned     total_moves_landed     =  0;  //Total number of moves we landed
132  float        move_accuracy          =  0;  //Computed as total_moves_used / total_moves_landed
133  float        actionability          =  0;  //Mean actionability based on act out of stun and wait
134  float        neutral_wins_per_min   =  0;  //Number of times we won neutral per minute spent in neutral
135  float        mean_death_percent     =  0;  //Average damage received before losing a stock
136
137  unsigned*    move_counts;                  //Counts for each move the player landed
138  unsigned*    dyn_counts;                   //Frame counts for player interaction dynamics
139  float*       dyn_damage;                   //Damage done during each player interaction dynamic
140  Attack*      attacks;                      //List of all attacks we connected with throughout the game
141  Punish*      punishes;                     //List of all punishes we performed throughout the game
142
143  AnalysisPlayer() {
144    move_counts = new unsigned[Move::__LAST]{0};
145    dyn_counts  = new unsigned[Dynamic::__LAST]{0};
146    dyn_damage  = new float[Dynamic::__LAST]{0};
147    attacks     = new Attack[MAX_ATTACKS];
148    punishes    = new Punish[MAX_PUNISHES];
149  }
150  ~AnalysisPlayer() {
151    delete [] punishes;
152    delete [] attacks;
153    delete [] dyn_damage;
154    delete [] dyn_counts;
155    delete [] move_counts;
156  }
157};
158
159//Struct for holding all analysis data within a game
160struct Analysis {
161  bool            success          = false;  //Whether we succeeded analyzing a replay
162  unsigned        parse_errors     = 0;      //Number of errors that occurred during replay parsing
163  std::string     game_time        = "";     //When the game was played, from replay metadata
164  std::string     original_file    = "";     //Path to the original input file
165  std::string     slippi_version   = "";     //Version of Slippi the replay was recorded with
166  std::string     parser_version   = "";     //Version of parser the replay was parsed with
167  std::string     analyzer_version = "";     //Version of this analyzer we are using
168  unsigned        stage_id         = 0;      //Internal ID of the stage
169  std::string     stage_name       = "";     //Readable name of the stage
170  int             winner_port      = 0;      //Port index of the winning player (-1 == no winner)
171  unsigned        game_length      = 0;      //Length of the game in frames (0 == internal frame -123)
172  unsigned        timer            = 0;      //Game timer starting minutes
173  AnalysisPlayer* ap;                        //Analysis of individual players in the game
174  unsigned*       dynamics;                  //Interaction dynamics on a per-frame basis
175  unsigned        end_type;                  //Game end type
176  int             lras_player;               //Player port who LRAS-ed (-1 if none)
177
178  Analysis(unsigned frame_count) {
179    dynamics = new unsigned[frame_count]{0}; // List of dynamics active at each frame
180    ap       = new AnalysisPlayer[2];        // The two players being analyzed
181  }
182  ~Analysis() {
183    delete [] ap;
184    delete [] dynamics;
185  }
186
187  std::string asJson();                      //Convert the analysis structure to a JSON
188  void save(const char* outfilename);        //Write the analysis out to a JSON file
189};
190
191}
192
193#endif /* ANALYSIS_H_ */