Add kartstats
This commit is contained in:
1 parent
62a65c5c1d
commit
4942db2806
12 files changed
+232
-24
No files matched your search
@@ -173,6 +173,7 @@ set(SRB2_CORE_GAME_SOURCES
|
||||
p_user.c
|
||||
k_director.c
|
||||
k_kart.c
|
||||
k_stats.c
|
||||
i_time.c
|
||||
|
||||
p_local.h
|
||||
@@ -187,6 +188,7 @@ set(SRB2_CORE_GAME_SOURCES
|
||||
p_tick.h
|
||||
k_director.h
|
||||
k_kart.h
|
||||
k_stats.h
|
||||
)
|
||||
|
||||
if(NOT (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
|
||||
|
||||
@@ -506,6 +506,7 @@ OBJS:=$(i_main_o) \
|
||||
$(OBJDIR)/st_stuff.o \
|
||||
$(OBJDIR)/k_director.o \
|
||||
$(OBJDIR)/k_kart.o \
|
||||
$(OBJDIR)/k_stats.o \
|
||||
$(OBJDIR)/m_aatree.o \
|
||||
$(OBJDIR)/m_anigif.o \
|
||||
$(OBJDIR)/m_argv.o \
|
||||
|
||||
@@ -338,9 +338,6 @@ enum GameType // SRB2Kart
|
||||
// String names for gametypes
|
||||
extern const char *Gametype_Names[NUMGAMETYPES];
|
||||
|
||||
extern tic_t totalplaytime;
|
||||
extern UINT32 matchesplayed;
|
||||
|
||||
extern UINT8 stagefailed;
|
||||
|
||||
// Emeralds stored as bits to throw savegame hackers off.
|
||||
|
||||
+6
-9
@@ -52,6 +52,7 @@
|
||||
#include "md5.h" // demo checksums
|
||||
#include "k_director.h" // SRB2kart
|
||||
#include "k_kart.h" // SRB2kart
|
||||
#include "k_stats.h" // SRB2kart
|
||||
#include "r_fps.h" // frame interpolation/uncapped
|
||||
|
||||
#ifdef HAVE_DISCORDRPC
|
||||
@@ -175,8 +176,6 @@ INT32 tokenbits; // Used for setting token bits
|
||||
// Old Special Stage
|
||||
INT32 sstimer; // Time allotted in the special stage
|
||||
|
||||
tic_t totalplaytime;
|
||||
UINT32 matchesplayed; // SRB2Kart
|
||||
boolean gamedataloaded = false;
|
||||
|
||||
// Time attack data for levels
|
||||
@@ -2011,7 +2010,7 @@ static inline void G_PlayerFinishLevel(INT32 player)
|
||||
{
|
||||
if (legitimateexit && !demo.playback && !mapreset) // (yes you're allowed to unlock stuff this way when the game is modified)
|
||||
{
|
||||
matchesplayed++;
|
||||
kartstats.matchesplayed++;
|
||||
if (M_UpdateUnlockablesAndExtraEmblems(true))
|
||||
S_StartSound(NULL, sfx_ncitem);
|
||||
G_SaveGameData(true);
|
||||
@@ -3139,6 +3138,8 @@ static void G_DoCompleted(void)
|
||||
|
||||
if (demo.playback) goto demointermission;
|
||||
|
||||
K_StatRound();
|
||||
|
||||
// go to next level
|
||||
// nextmap is 0-based, unlike gamemap
|
||||
if (nextmapoverride != 0)
|
||||
@@ -3482,8 +3483,6 @@ void G_LoadGameData(void)
|
||||
// to new gamedata
|
||||
G_ClearRecords(); // main and nights records
|
||||
M_ClearSecrets(); // emblems, unlocks, maps visited, etc
|
||||
totalplaytime = 0; // total play time (separate from all)
|
||||
matchesplayed = 0; // SRB2Kart: matches played & finished
|
||||
|
||||
if (M_CheckParm("-nodata"))
|
||||
return; // Don't load.
|
||||
@@ -3512,8 +3511,7 @@ void G_LoadGameData(void)
|
||||
I_Error("Game data is from another version of SRB2.\nDelete %s(maybe in %s) and try again.", gamedatafilename, gdfolder);
|
||||
}
|
||||
|
||||
totalplaytime = READUINT32(save.p);
|
||||
matchesplayed = READUINT32(save.p);
|
||||
K_ReadStats(&save, true);
|
||||
|
||||
modded = READUINT8(save.p);
|
||||
|
||||
@@ -3627,8 +3625,7 @@ void G_SaveGameData(boolean force)
|
||||
// Version test
|
||||
WRITEUINT32(save.p, 0xFCAFE211);
|
||||
|
||||
WRITEUINT32(save.p, totalplaytime);
|
||||
WRITEUINT32(save.p, matchesplayed);
|
||||
K_WriteStats(&save, true);
|
||||
|
||||
btemp = (UINT8)(savemoddata); // what used to be here was profoundly dunderheaded
|
||||
WRITEUINT8(save.p, btemp);
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "m_cond.h"
|
||||
#include "k_director.h"
|
||||
#include "k_kart.h"
|
||||
#include "k_stats.h"
|
||||
#include "f_finale.h"
|
||||
#include "lua_hud.h" // For Lua hud checks
|
||||
#include "lua_hook.h" // For MobjDamage and ShouldDamage
|
||||
@@ -2518,6 +2519,8 @@ void K_SpinPlayer(player_t *player, mobj_t *source, INT32 type, mobj_t *inflicto
|
||||
if (LUA_HookPlayerSpin(player, inflictor, source)) // Let Lua do its thing or overwrite if it wants to. Make sure to let any possible instashield happen because we didn't get "damaged" in this case.
|
||||
return;
|
||||
|
||||
K_StatPlayerHit(player, source ? source->player : NULL);
|
||||
|
||||
if (source && source != player->mo && source->player)
|
||||
K_PlayHitEmSound(source, player->mo);
|
||||
|
||||
|
||||
+146
@@ -0,0 +1,146 @@
|
||||
#include "k_stats.h"
|
||||
#include "doomstat.h"
|
||||
#include "g_game.h"
|
||||
#include "byteptr.h"
|
||||
|
||||
kartstats_t kartstats = {0};
|
||||
|
||||
void K_StatTicker(void)
|
||||
{
|
||||
if (demo.playback)
|
||||
return;
|
||||
|
||||
kartstats.totalplaytime++;
|
||||
|
||||
if (netgame)
|
||||
kartstats.onlineplaytime++;
|
||||
else if (modeattacking)
|
||||
kartstats.raplaytime++;
|
||||
|
||||
if (G_RaceGametype())
|
||||
kartstats.raceplaytime++;
|
||||
else
|
||||
kartstats.battleplaytime++;
|
||||
|
||||
// Should this also track splitscreen players?
|
||||
if (!players[consoleplayer].spectator)
|
||||
{
|
||||
player_t *p = &players[consoleplayer];
|
||||
|
||||
if (p->kartstuff[k_position] == spbplace)
|
||||
kartstats.spbtargettime++;
|
||||
|
||||
if (max(p->kartstuff[k_spinouttimer], p->kartstuff[k_wipeoutslow]) > 0)
|
||||
kartstats.spinouttime++;
|
||||
}
|
||||
}
|
||||
|
||||
void K_StatPlayerHit(player_t *victim, player_t *source)
|
||||
{
|
||||
if (demo.playback)
|
||||
return;
|
||||
|
||||
if (victim == &players[consoleplayer])
|
||||
{
|
||||
if (victim == source)
|
||||
kartstats.selfhits++;
|
||||
}
|
||||
else if (source == &players[consoleplayer])
|
||||
kartstats.hits++;
|
||||
}
|
||||
|
||||
void K_StatPlayerSink(player_t *victim, player_t *source)
|
||||
{
|
||||
if (demo.playback)
|
||||
return;
|
||||
|
||||
if (victim == &players[consoleplayer])
|
||||
kartstats.sinked++;
|
||||
else if (source == &players[consoleplayer])
|
||||
kartstats.sinks++;
|
||||
}
|
||||
|
||||
void K_StatRound(void)
|
||||
{
|
||||
if (demo.playback)
|
||||
return;
|
||||
|
||||
int numplayers = 0;
|
||||
|
||||
for (int i = 0; i < MAXPLAYERS; ++i)
|
||||
{
|
||||
if (playeringame[i] && !players[i].spectator)
|
||||
++numplayers;
|
||||
}
|
||||
|
||||
if (numplayers > 1)
|
||||
{
|
||||
if (players[consoleplayer].kartstuff[k_position] == 1)
|
||||
kartstats.totalwins++;
|
||||
else if (players[consoleplayer].kartstuff[k_position] <= 3) // Should this check if there are more than 3 players in game?
|
||||
kartstats.totalpodium++;
|
||||
}
|
||||
}
|
||||
|
||||
void K_EraseStats(void)
|
||||
{
|
||||
// The only field we want to remember
|
||||
boolean vanilla = kartstats.vanilla;
|
||||
|
||||
memset(&kartstats, 0, sizeof(kartstats_t));
|
||||
|
||||
kartstats.vanilla = vanilla;
|
||||
}
|
||||
|
||||
void K_ReadStats(savebuffer_t *save, boolean vanilla)
|
||||
{
|
||||
memset(&kartstats, 0, sizeof(kartstats_t));
|
||||
|
||||
kartstats.vanilla = vanilla;
|
||||
|
||||
kartstats.totalplaytime = READUINT32(save->p);
|
||||
kartstats.matchesplayed = READUINT32(save->p);
|
||||
|
||||
// Vanilla only has those 2
|
||||
if (vanilla)
|
||||
return;
|
||||
|
||||
// So many similar-looking read's... scary...
|
||||
kartstats.raplaytime = READUINT32(save->p);
|
||||
kartstats.onlineplaytime = READUINT32(save->p);
|
||||
kartstats.raceplaytime = READUINT32(save->p);
|
||||
kartstats.battleplaytime = READUINT32(save->p);
|
||||
kartstats.spbtargettime = READUINT32(save->p);
|
||||
kartstats.spinouttime = READUINT32(save->p);
|
||||
kartstats.totalwins = READUINT32(save->p);
|
||||
kartstats.totalpodium = READUINT32(save->p);
|
||||
kartstats.hits = READUINT32(save->p);
|
||||
kartstats.selfhits = READUINT32(save->p);
|
||||
kartstats.sinks = READUINT32(save->p);
|
||||
kartstats.sinked = READUINT32(save->p);
|
||||
kartstats.respawns = READUINT32(save->p);
|
||||
}
|
||||
|
||||
void K_WriteStats(savebuffer_t *save, boolean vanilla)
|
||||
{
|
||||
WRITEUINT32(save->p, kartstats.totalplaytime);
|
||||
WRITEUINT32(save->p, kartstats.matchesplayed);
|
||||
|
||||
// Vanilla only has those 2
|
||||
if (vanilla)
|
||||
return;
|
||||
|
||||
WRITEUINT32(save->p, kartstats.raplaytime);
|
||||
WRITEUINT32(save->p, kartstats.onlineplaytime);
|
||||
WRITEUINT32(save->p, kartstats.raceplaytime);
|
||||
WRITEUINT32(save->p, kartstats.battleplaytime);
|
||||
WRITEUINT32(save->p, kartstats.spbtargettime);
|
||||
WRITEUINT32(save->p, kartstats.spinouttime);
|
||||
WRITEUINT32(save->p, kartstats.totalwins);
|
||||
WRITEUINT32(save->p, kartstats.totalpodium);
|
||||
WRITEUINT32(save->p, kartstats.hits);
|
||||
WRITEUINT32(save->p, kartstats.selfhits);
|
||||
WRITEUINT32(save->p, kartstats.sinks);
|
||||
WRITEUINT32(save->p, kartstats.sinked);
|
||||
WRITEUINT32(save->p, kartstats.respawns);
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
#ifndef __K_STATS__
|
||||
#define __K_STATS__
|
||||
|
||||
#include "doomtype.h"
|
||||
#include "d_player.h"
|
||||
#include "p_saveg.h"
|
||||
|
||||
typedef struct kartstats_s {
|
||||
// Remember if stats we loaded are vanilla ones or not
|
||||
boolean vanilla;
|
||||
|
||||
// Vanilla
|
||||
tic_t totalplaytime;
|
||||
UINT32 matchesplayed;
|
||||
|
||||
tic_t raplaytime;
|
||||
tic_t onlineplaytime;
|
||||
tic_t raceplaytime;
|
||||
tic_t battleplaytime;
|
||||
tic_t spbtargettime;
|
||||
tic_t spinouttime;
|
||||
UINT32 totalwins; // 1st place
|
||||
UINT32 totalpodium; // 2nd and 3rd place, *but not 1st*
|
||||
UINT32 hits;
|
||||
UINT32 selfhits;
|
||||
UINT32 sinks; // Times hitting *others* by kitchen sink
|
||||
UINT32 sinked; // Times *being hit* by kitchen sink
|
||||
UINT32 respawns;
|
||||
} kartstats_t;
|
||||
|
||||
extern kartstats_t kartstats;
|
||||
|
||||
// Note: All stat-tracking functions check for demo.playback and early return if its true
|
||||
|
||||
// Update global stats such as total play time, etc
|
||||
void K_StatTicker(void);
|
||||
|
||||
// Update hit-related stats (PlayerSpin, PlayerSquish, PlayerExplode)
|
||||
void K_StatPlayerHit(player_t *victim, player_t *source);
|
||||
|
||||
// Separate from stuff above
|
||||
void K_StatPlayerSink(player_t *victim, player_t *source);
|
||||
|
||||
// Update round-related stats (such as matchesplayed, totalwins, etc)
|
||||
void K_StatRound(void);
|
||||
|
||||
void K_EraseStats(void);
|
||||
|
||||
// If vanilla is true, only read vanilla-supported fields. Everything else is initialized to 0
|
||||
void K_ReadStats(savebuffer_t *save, boolean vanilla);
|
||||
|
||||
// Same as above, except it just doesn't write non-vanilla fields if vanilla is true
|
||||
void K_WriteStats(savebuffer_t *save, boolean vanilla);
|
||||
|
||||
|
||||
#endif
|
||||
+3
-2
@@ -21,6 +21,7 @@
|
||||
#include "r_things.h" // numskins
|
||||
//#include "r_draw.h" // R_GetColorByName
|
||||
#include "k_kart.h" // K_GetKartColorByName
|
||||
#include "k_stats.h"
|
||||
|
||||
// Map triggers for linedef executors
|
||||
// 32 triggers, one bit each
|
||||
@@ -286,9 +287,9 @@ UINT8 M_CheckCondition(condition_t *cn)
|
||||
switch (cn->type)
|
||||
{
|
||||
case UC_PLAYTIME: // Requires total playing time >= x
|
||||
return (totalplaytime >= (unsigned)cn->requirement);
|
||||
return (kartstats.totalplaytime >= (unsigned)cn->requirement);
|
||||
case UC_MATCHESPLAYED: // Requires any level completed >= x times
|
||||
return (matchesplayed >= (unsigned)cn->requirement);
|
||||
return (kartstats.matchesplayed >= (unsigned)cn->requirement);
|
||||
case UC_GAMECLEAR: // Requires game beaten >= x times
|
||||
return (timesBeaten >= (unsigned)cn->requirement);
|
||||
case UC_ALLEMERALDS: // Requires game beaten with all 7 emeralds >= x times
|
||||
|
||||
+6
-6
@@ -70,6 +70,7 @@
|
||||
#include "st_stuff.h"
|
||||
#include "i_sound.h"
|
||||
#include "k_kart.h" // SRB2kart
|
||||
#include "k_stats.h" // SRB2kart
|
||||
#include "d_player.h" // KITEM_ constants
|
||||
|
||||
#include "i_joy.h" // for joystick menu controls
|
||||
@@ -8759,11 +8760,11 @@ static void M_DrawLevelStats(void)
|
||||
|
||||
V_DrawString(20, 24, highlightflags|MENUCAPS, "Total Play Time:");
|
||||
V_DrawCenteredString(BASEVIDWIDTH/2, 32, MENUCAPS, va("%i hours, %i minutes, %i seconds",
|
||||
G_TicsToHours(totalplaytime),
|
||||
G_TicsToMinutes(totalplaytime, false),
|
||||
G_TicsToSeconds(totalplaytime)));
|
||||
G_TicsToHours(kartstats.totalplaytime),
|
||||
G_TicsToMinutes(kartstats.totalplaytime, false),
|
||||
G_TicsToSeconds(kartstats.totalplaytime)));
|
||||
V_DrawString(20, 42, highlightflags|MENUCAPS, "Total Matches:");
|
||||
V_DrawRightAlignedString(BASEVIDWIDTH-16, 42, MENUCAPS, va("%i played", matchesplayed));
|
||||
V_DrawRightAlignedString(BASEVIDWIDTH-16, 42, MENUCAPS, va("%i played", kartstats.matchesplayed));
|
||||
|
||||
for (i = 0; i < NUMMAPS; i++)
|
||||
{
|
||||
@@ -11745,8 +11746,7 @@ static void M_EraseDataResponse(INT32 ch)
|
||||
if (erasecontext == 2)
|
||||
{
|
||||
// SRB2Kart: This actually needs to be done FIRST, so that you don't immediately regain playtime/matches secrets
|
||||
totalplaytime = 0;
|
||||
matchesplayed = 0;
|
||||
K_EraseStats();
|
||||
F_StartIntro();
|
||||
}
|
||||
if (erasecontext != 1)
|
||||
|
||||
+2
-2
@@ -14,7 +14,7 @@
|
||||
|
||||
#include "doomdef.h"
|
||||
#include "doomtype.h"
|
||||
#include "doomstat.h" // totalplaytime
|
||||
#include "k_stats.h" // kartstats.totalplaytime
|
||||
|
||||
#include "m_random.h"
|
||||
#include "m_fixed.h"
|
||||
@@ -252,5 +252,5 @@ void P_SetRandSeedD(const char *rfile, INT32 rline, UINT32 seed)
|
||||
*/
|
||||
UINT32 M_RandomizedSeed(void)
|
||||
{
|
||||
return ((totalplaytime & 0xFFFF) << 16)|M_RandomFixed();
|
||||
return ((kartstats.totalplaytime & 0xFFFF) << 16)|M_RandomFixed();
|
||||
}
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "s_sound.h"
|
||||
#include "w_wad.h"
|
||||
#include "k_kart.h" // SRB2kart 011617
|
||||
#include "k_stats.h"
|
||||
|
||||
#include "hu_stuff.h" // SRB2kart
|
||||
#include "i_system.h" // SRB2kart
|
||||
@@ -719,6 +720,8 @@ static boolean PIT_CheckThing(mobj_t *thing)
|
||||
|
||||
if (thing->type == MT_PLAYER)
|
||||
{
|
||||
K_StatPlayerSink(thing->player, P_MobjWasRemoved(tmthing->target) ? NULL : tmthing->target->player);
|
||||
|
||||
S_StartSound(NULL, sfx_bsnipe); //let all players hear it.
|
||||
HU_SetCEchoFlags(0);
|
||||
HU_SetCEchoDuration(5);
|
||||
@@ -986,6 +989,8 @@ static boolean PIT_CheckThing(mobj_t *thing)
|
||||
if ((thing->target == tmthing) && (thing->threshold > 0))
|
||||
return true;
|
||||
|
||||
K_StatPlayerSink(tmthing->player, P_MobjWasRemoved(thing->target) ? NULL : thing->target->player);
|
||||
|
||||
S_StartSound(NULL, sfx_cgot); //let all players hear it.
|
||||
HU_SetCEchoFlags(0);
|
||||
HU_SetCEchoDuration(5);
|
||||
|
||||
+2
-2
@@ -25,6 +25,7 @@
|
||||
#include "lua_hook.h"
|
||||
#include "k_director.h"
|
||||
#include "k_kart.h"
|
||||
#include "k_stats.h"
|
||||
#include "i_system.h"
|
||||
#include "r_main.h"
|
||||
#include "r_fps.h"
|
||||
@@ -610,8 +611,7 @@ void P_Ticker(boolean run)
|
||||
}
|
||||
|
||||
// Keep track of how long they've been playing!
|
||||
if (!demo.playback) // Don't increment if a demo is playing.
|
||||
totalplaytime++;
|
||||
K_StatTicker();
|
||||
|
||||
if (run)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user