diff --git a/src/game/chraction.c b/src/game/chraction.c index 5c70e3e00..ed2b902b4 100644 --- a/src/game/chraction.c +++ b/src/game/chraction.c @@ -4623,20 +4623,20 @@ void chr_damage(struct chrdata *chr, f32 damage, struct coord *vector, struct gs if (!alreadydead && hitpart) { switch (hitpart) { case HITPART_HEAD: - mpstats_increment_player_shot_count2(gset, SHOTREGION_HEAD); + mpstats_increment_player_shotcount(gset, SHOTREGION_HEAD); break; case HITPART_GUN: - mpstats_increment_player_shot_count2(gset, SHOTREGION_GUN); + mpstats_increment_player_shotcount(gset, SHOTREGION_GUN); break; case HITPART_HAT: - mpstats_increment_player_shot_count2(gset, SHOTREGION_HAT); + mpstats_increment_player_shotcount(gset, SHOTREGION_HAT); break; case HITPART_PELVIS: case HITPART_TORSO: - mpstats_increment_player_shot_count2(gset, SHOTREGION_BODY); + mpstats_increment_player_shotcount(gset, SHOTREGION_BODY); break; default: - mpstats_increment_player_shot_count2(gset, SHOTREGION_LIMB); + mpstats_increment_player_shotcount(gset, SHOTREGION_LIMB); break; } } diff --git a/src/game/endscreen.c b/src/game/endscreen.c index aa874528a..6f7f4bbad 100644 --- a/src/game/endscreen.c +++ b/src/game/endscreen.c @@ -253,44 +253,44 @@ char *endscreen_menu_text_num_kills(struct menuitem *item) char *endscreen_menu_text_num_shots(struct menuitem *item) { - sprintf(g_StringPointer, "%d", mpstats_get_player_shot_count_by_region(SHOTREGION_TOTAL)); + sprintf(g_StringPointer, "%d", mpstats_get_player_shotcount_by_region(SHOTREGION_TOTAL)); return g_StringPointer; } char *endscreen_menu_text_num_head_shots(struct menuitem *item) { - sprintf(g_StringPointer, "%d", mpstats_get_player_shot_count_by_region(SHOTREGION_HEAD)); + sprintf(g_StringPointer, "%d", mpstats_get_player_shotcount_by_region(SHOTREGION_HEAD)); return g_StringPointer; } char *endscreen_menu_text_num_body_shots(struct menuitem *item) { - sprintf(g_StringPointer, "%d", mpstats_get_player_shot_count_by_region(SHOTREGION_BODY)); + sprintf(g_StringPointer, "%d", mpstats_get_player_shotcount_by_region(SHOTREGION_BODY)); return g_StringPointer; } char *endscreen_menu_text_num_limb_shots(struct menuitem *item) { - sprintf(g_StringPointer, "%d", mpstats_get_player_shot_count_by_region(SHOTREGION_LIMB)); + sprintf(g_StringPointer, "%d", mpstats_get_player_shotcount_by_region(SHOTREGION_LIMB)); return g_StringPointer; } char *endscreen_menu_text_num_other_shots(struct menuitem *item) { - u32 total = mpstats_get_player_shot_count_by_region(SHOTREGION_GUN) + mpstats_get_player_shot_count_by_region(SHOTREGION_HAT); + u32 total = mpstats_get_player_shotcount_by_region(SHOTREGION_GUN) + mpstats_get_player_shotcount_by_region(SHOTREGION_HAT); sprintf(g_StringPointer, "%d", total); return g_StringPointer; } char *endscreen_menu_text_accuracy(struct menuitem *item) { - s32 total = mpstats_get_player_shot_count_by_region(SHOTREGION_TOTAL); - s32 numhead = mpstats_get_player_shot_count_by_region(SHOTREGION_HEAD); - s32 numbody = mpstats_get_player_shot_count_by_region(SHOTREGION_BODY); - s32 numlimb = mpstats_get_player_shot_count_by_region(SHOTREGION_LIMB); - s32 numgun = mpstats_get_player_shot_count_by_region(SHOTREGION_GUN); - s32 numhat = mpstats_get_player_shot_count_by_region(SHOTREGION_HAT); - s32 numobject = mpstats_get_player_shot_count_by_region(SHOTREGION_OBJECT); + s32 total = mpstats_get_player_shotcount_by_region(SHOTREGION_TOTAL); + s32 numhead = mpstats_get_player_shotcount_by_region(SHOTREGION_HEAD); + s32 numbody = mpstats_get_player_shotcount_by_region(SHOTREGION_BODY); + s32 numlimb = mpstats_get_player_shotcount_by_region(SHOTREGION_LIMB); + s32 numgun = mpstats_get_player_shotcount_by_region(SHOTREGION_GUN); + s32 numhat = mpstats_get_player_shotcount_by_region(SHOTREGION_HAT); + s32 numobject = mpstats_get_player_shotcount_by_region(SHOTREGION_OBJECT); f32 accuracy; if (total > 0) { diff --git a/src/game/mplayer/mplayer.c b/src/game/mplayer/mplayer.c index e1dd95aa3..d5b9afb18 100644 --- a/src/game/mplayer/mplayer.c +++ b/src/game/mplayer/mplayer.c @@ -2018,8 +2018,8 @@ void mp_calculate_awards(void) g_Vars.currentplayer->award1 = NULL; g_Vars.currentplayer->award2 = NULL; - metrics[i].numshots = mpstats_get_player_shot_count_by_region(SHOTREGION_TOTAL); - metrics[i].numheadshots = mpstats_get_player_shot_count_by_region(SHOTREGION_HEAD); + metrics[i].numshots = mpstats_get_player_shotcount_by_region(SHOTREGION_TOTAL); + metrics[i].numheadshots = mpstats_get_player_shotcount_by_region(SHOTREGION_HEAD); metrics[i].numkills = 0; metrics[i].numdeaths = 0; metrics[i].numsuicides = 0; @@ -2056,12 +2056,12 @@ void mp_calculate_awards(void) metrics[i].longestlife = g_Vars.playerstats[i].longestlife; metrics[i].shortestlife = g_Vars.playerstats[i].shortestlife; - sum = mpstats_get_player_shot_count_by_region(SHOTREGION_HEAD) - + mpstats_get_player_shot_count_by_region(SHOTREGION_BODY) - + mpstats_get_player_shot_count_by_region(SHOTREGION_LIMB) - + mpstats_get_player_shot_count_by_region(SHOTREGION_GUN) - + mpstats_get_player_shot_count_by_region(SHOTREGION_HAT) - + mpstats_get_player_shot_count_by_region(SHOTREGION_OBJECT); + sum = mpstats_get_player_shotcount_by_region(SHOTREGION_HEAD) + + mpstats_get_player_shotcount_by_region(SHOTREGION_BODY) + + mpstats_get_player_shotcount_by_region(SHOTREGION_LIMB) + + mpstats_get_player_shotcount_by_region(SHOTREGION_GUN) + + mpstats_get_player_shotcount_by_region(SHOTREGION_HAT) + + mpstats_get_player_shotcount_by_region(SHOTREGION_OBJECT); if (metrics[i].numshots > 0) { metrics[i].accuracyfrac = sum / (f32)metrics[i].numshots; diff --git a/src/game/mpstats.c b/src/game/mpstats.c index c21394d0c..9960de98f 100644 --- a/src/game/mpstats.c +++ b/src/game/mpstats.c @@ -17,41 +17,51 @@ #include "data.h" #include "types.h" -u32 var80070590 = 0x00000000; +bool g_AllowRegionShot = false; -void mpstats_increment_player_shot_count(struct gset *gset, s32 region) +void mpstats_increment_player_shotcount_projectiles(struct gset *gset, s32 region) { if (!gset_has_weapon_flag(gset->weaponnum, WEAPONFLAG_DONTCOUNTSHOTS)) { g_Vars.currentplayerstats->shotcount[region]++; } } -void mpstats_increment_player_shot_count2(struct gset *gset, s32 region) +/** + * The usage of g_AllowRegionShot ensures that the sum of region shots does not + * exceed the total shots. + * + * The sequence of calls when firing a shot is: + * - Call mpstats_increment_player_shotcount with SHOTREGION_TOTAL. + * - For each hits that landed (there can be multiple with the shotgun), + * call mpstats_increment_player_shotcount with that region. + * - Call mpstats_end_shot so any unexpected region shots will not be counted. + */ +void mpstats_increment_player_shotcount(struct gset *gset, s32 region) { - if (region == 0) { + if (region == SHOTREGION_TOTAL) { if (!gset_has_weapon_flag(gset->weaponnum, WEAPONFLAG_DONTCOUNTSHOTS)) { - var80070590 = 1; + g_AllowRegionShot = true; g_Vars.currentplayerstats->shotcount[region]++; } } else { - if (var80070590) { + if (g_AllowRegionShot) { if (!gset_has_weapon_flag(gset->weaponnum, WEAPONFLAG_DONTCOUNTSHOTS)) { g_Vars.currentplayerstats->shotcount[region]++; } - var80070590 = 0; + g_AllowRegionShot = false; } } } -void mpstats0f0b0520(void) +void mpstats_end_shot(void) { - var80070590 = 0; + g_AllowRegionShot = false; } -s32 mpstats_get_player_shot_count_by_region(u32 type) +s32 mpstats_get_player_shotcount_by_region(s32 region) { - return g_Vars.currentplayerstats->shotcount[type]; + return g_Vars.currentplayerstats->shotcount[region]; } void mpstats_increment_total_kill_count(void) diff --git a/src/game/prop.c b/src/game/prop.c index bc121406b..b918531fe 100644 --- a/src/game/prop.c +++ b/src/game/prop.c @@ -1316,7 +1316,7 @@ void hand_tick_attack(s32 handnum) // right hand is not (ie. prevent firing both guns on the same tick) if (handnum == HAND_RIGHT || !bgun_is_firing(HAND_RIGHT)) { chr_uncloak_temporarily(g_Vars.currentplayer->prop->chr); - mpstats_increment_player_shot_count2(&gset, 0); + mpstats_increment_player_shotcount(&gset, SHOTREGION_TOTAL); if (weaponnum == WEAPON_SHOTGUN) { shot_create(handnum, true, true, 1, true); @@ -1329,7 +1329,7 @@ void hand_tick_attack(s32 handnum) shot_create(handnum, true, true, bgun_get_shots_to_take(handnum), g_Vars.mplayerisrunning); } - mpstats0f0b0520(); + mpstats_end_shot(); } break; case HANDATTACKTYPE_MELEE: diff --git a/src/game/propobj.c b/src/game/propobj.c index 50665a4d2..60f1e7bd3 100644 --- a/src/game/propobj.c +++ b/src/game/propobj.c @@ -7161,12 +7161,12 @@ bool projectile_tick(struct defaultobj *obj, bool *embedded) if (obj->projectile->ownerprop && obj->projectile->ownerprop->type == PROPTYPE_PLAYER) { s32 prevplayernum = g_Vars.currentplayernum; set_current_player_num(playermgr_get_player_num_by_prop(obj->projectile->ownerprop)); - mpstats_increment_player_shot_count(&weapon->gset, SHOTREGION_TOTAL); + mpstats_increment_player_shotcount_projectiles(&weapon->gset, SHOTREGION_TOTAL); if (g_EmbedProp != NULL) { if (g_EmbedProp->type == PROPTYPE_OBJ) { if (obj_is_healthy(g_EmbedProp->obj)) { - mpstats_increment_player_shot_count(&weapon->gset, SHOTREGION_OBJECT); + mpstats_increment_player_shotcount_projectiles(&weapon->gset, SHOTREGION_OBJECT); } } else if (g_EmbedProp->type == PROPTYPE_CHR || g_EmbedProp->type == PROPTYPE_PLAYER) { struct chrdata *embedchr = g_EmbedProp->chr; @@ -7185,20 +7185,20 @@ bool projectile_tick(struct defaultobj *obj, bool *embedded) case 0: break; case HITPART_HEAD: - mpstats_increment_player_shot_count(&weapon->gset, SHOTREGION_HEAD); + mpstats_increment_player_shotcount_projectiles(&weapon->gset, SHOTREGION_HEAD); break; case HITPART_GUN: - mpstats_increment_player_shot_count(&weapon->gset, SHOTREGION_GUN); + mpstats_increment_player_shotcount_projectiles(&weapon->gset, SHOTREGION_GUN); break; case HITPART_HAT: - mpstats_increment_player_shot_count(&weapon->gset, SHOTREGION_HAT); + mpstats_increment_player_shotcount_projectiles(&weapon->gset, SHOTREGION_HAT); break; case HITPART_PELVIS: case HITPART_TORSO: - mpstats_increment_player_shot_count(&weapon->gset, SHOTREGION_BODY); + mpstats_increment_player_shotcount_projectiles(&weapon->gset, SHOTREGION_BODY); break; default: - mpstats_increment_player_shot_count(&weapon->gset, SHOTREGION_LIMB); + mpstats_increment_player_shotcount_projectiles(&weapon->gset, SHOTREGION_LIMB); break; } } @@ -14853,7 +14853,7 @@ void obj_hit(struct shotdata *shotdata, struct hit *hit) // Increment object hit count if (obj_is_healthy(obj) && obj_is_mortal(obj) && hit->slowsbullet) { - mpstats_increment_player_shot_count2(&shotdata->gset, SHOTREGION_OBJECT); + mpstats_increment_player_shotcount(&shotdata->gset, SHOTREGION_OBJECT); } // Play hit sound diff --git a/src/include/game/mpstats.h b/src/include/game/mpstats.h index 0d192fb82..e98bf0d5b 100644 --- a/src/include/game/mpstats.h +++ b/src/include/game/mpstats.h @@ -4,10 +4,10 @@ #include "data.h" #include "types.h" -void mpstats_increment_player_shot_count(struct gset *gset, s32 region); -void mpstats_increment_player_shot_count2(struct gset *gset, s32 region); -void mpstats0f0b0520(void); -s32 mpstats_get_player_shot_count_by_region(u32 type); +void mpstats_increment_player_shotcount_projectiles(struct gset *gset, s32 region); +void mpstats_increment_player_shotcount(struct gset *gset, s32 region); +void mpstats_end_shot(void); +s32 mpstats_get_player_shotcount_by_region(s32 region); void mpstats_increment_total_kill_count(void); void mpstats_increment_total_knockout_count(void); void mpstats_decrement_total_knockout_count(void);