tr1/stats: introduce stat incrementing functions

This commit is contained in:
walkawayy 2025-03-20 01:12:53 -04:00
parent 2ef5723457
commit 0c6ee1b4c5
8 changed files with 82 additions and 24 deletions

View file

@ -9,6 +9,7 @@
#include "game/savegame.h"
#include "game/sound.h"
#include "game/spawn.h"
#include "game/stats.h"
#include "global/const.h"
#include "global/vars.h"
@ -431,7 +432,7 @@ int32_t Gun_FireWeapon(
}
ammo->ammo--;
Savegame_GetCurrentInfo(Game_GetCurrentLevel())->stats.ammo_used++;
Stats_AddAmmoUsed();
const XYZ_32 view_pos = {
.x = src->pos.x,
@ -471,7 +472,7 @@ int32_t Gun_FireWeapon(
GAME_VECTOR vdest;
if (best >= 0) {
ammo->hit++;
Savegame_GetCurrentInfo(Game_GetCurrentLevel())->stats.ammo_hits++;
Stats_AddAmmoHits();
vdest.x = vsrc.x + ((bestdist * g_MatrixPtr->_20) >> W2V_SHIFT);
vdest.y = vsrc.y + ((bestdist * g_MatrixPtr->_21) >> W2V_SHIFT);
vdest.z = vsrc.z + ((bestdist * g_MatrixPtr->_22) >> W2V_SHIFT);
@ -493,7 +494,7 @@ int32_t Gun_FireWeapon(
void Gun_HitTarget(ITEM *item, GAME_VECTOR *hitpos, int16_t damage)
{
if (item->hit_points > 0 && item->hit_points <= damage) {
Savegame_GetCurrentInfo(Game_GetCurrentLevel())->stats.kill_count++;
Stats_AddKill();
if (g_Config.gameplay.target_mode == TLM_SEMI) {
g_Lara.target = nullptr;
}

View file

@ -19,6 +19,7 @@
#include "game/savegame.h"
#include "game/sound.h"
#include "game/spawn.h"
#include "game/stats.h"
#include "global/const.h"
#include "global/vars.h"
@ -334,12 +335,7 @@ void Lara_Control(void)
break;
}
Savegame_GetCurrentInfo(Game_GetCurrentLevel())->stats.distance_travelled +=
Math_Sqrt(
SQUARE(item->pos.z - g_Lara.last_pos.z)
+ SQUARE(item->pos.y - g_Lara.last_pos.y)
+ SQUARE(item->pos.x - g_Lara.last_pos.x));
Stats_AddDistanceTravelled(item->pos, g_Lara.last_pos);
g_Lara.last_pos = item->pos;
}
@ -410,8 +406,7 @@ void Lara_UseItem(const GAME_OBJECT_ID obj_id)
CLAMPG(g_LaraItem->hit_points, LARA_MAX_HITPOINTS);
Inv_RemoveItem(O_MEDI_ITEM);
Sound_Effect(SFX_MENU_MEDI, nullptr, SPM_ALWAYS);
Savegame_GetCurrentInfo(Game_GetCurrentLevel())->stats.medipacks_used +=
.5;
Stats_AddMedipacksUsed(.5);
break;
case O_BIGMEDI_ITEM:
@ -424,8 +419,7 @@ void Lara_UseItem(const GAME_OBJECT_ID obj_id)
CLAMPG(g_LaraItem->hit_points, LARA_MAX_HITPOINTS);
Inv_RemoveItem(O_BIGMEDI_ITEM);
Sound_Effect(SFX_MENU_MEDI, nullptr, SPM_ALWAYS);
Savegame_GetCurrentInfo(Game_GetCurrentLevel())->stats.medipacks_used +=
1;
Stats_AddMedipacksUsed(1);
break;
case O_KEY_ITEM_1:

View file

@ -4,6 +4,7 @@
#include "game/items.h"
#include "game/objects/common.h"
#include "game/savegame.h"
#include "game/stats.h"
#include "global/const.h"
#include "global/vars.h"
@ -71,7 +72,7 @@ static void M_Control(const int16_t item_num)
if (item->status == IS_DEACTIVATED) {
// Count kill if Lara touches mummy and it falls.
if (item->hit_points > 0) {
Savegame_GetCurrentInfo(Game_GetCurrentLevel())->stats.kill_count++;
Stats_AddKill();
}
Item_RemoveActive(item_num);
if (item->hit_points != DONT_TARGET) {

View file

@ -9,6 +9,7 @@
#include "game/overlay.h"
#include "game/random.h"
#include "game/savegame.h"
#include "game/stats.h"
#include "global/const.h"
#include "global/vars.h"
@ -111,7 +112,7 @@ static void M_GetItem(int16_t item_num, ITEM *item, ITEM *lara_item)
Item_RemoveDrawn(item_num);
Item_RemoveActive(item_num);
Savegame_GetCurrentInfo(Game_GetCurrentLevel())->stats.pickup_count++;
Stats_AddPickup();
g_Lara.interact_target.is_moving = false;
}

View file

@ -11,6 +11,7 @@
#include "game/objects/common.h"
#include "game/overlay.h"
#include "game/savegame.h"
#include "game/stats.h"
#include "global/vars.h"
#define EXTRA_ANIM_PEDESTAL_SCION 0
@ -80,8 +81,7 @@ static void M_Collision(
Inv_AddItem(item->object_id);
item->status = IS_INVISIBLE;
Item_RemoveDrawn(item_num);
Savegame_GetCurrentInfo(Game_GetCurrentLevel())
->stats.pickup_count++;
Stats_AddPickup();
}
} else if (
g_Input.action && g_Lara.gun_status == LGS_ARMLESS

View file

@ -14,6 +14,7 @@
#include "game/savegame.h"
#include "game/shell.h"
#include "game/sound.h"
#include "game/stats.h"
#include "global/vars.h"
#include <libtrx/game/game_buf.h>
@ -626,14 +627,9 @@ void Room_TestSectorTrigger(const ITEM *const item, const SECTOR *const sector)
case TO_SECRET: {
const int16_t secret_num = 1 << (int16_t)(intptr_t)cmd->parameter;
RESUME_INFO *resume_info =
Savegame_GetCurrentInfo(Game_GetCurrentLevel());
if (resume_info->stats.secret_flags & secret_num) {
break;
if (Stats_AddSecret(secret_num)) {
Music_Play(MX_SECRET, MPM_ALWAYS);
}
resume_info->stats.secret_flags |= secret_num;
resume_info->stats.secret_count++;
Music_Play(MX_SECRET, MPM_ALWAYS);
break;
}
}

View file

@ -13,6 +13,7 @@
#include <libtrx/game/game_buf.h>
#include <libtrx/log.h>
#include <libtrx/utils.h>
#include <stdio.h>
#include <string.h>
@ -271,3 +272,59 @@ void Stats_UpdateSecrets(LEVEL_STATS *const stats)
stats->secret_count += (stats->secret_flags & (1 << i)) ? 1 : 0;
}
}
void Stats_AddKill(void)
{
RESUME_INFO *const current_info =
Savegame_GetCurrentInfo(Game_GetCurrentLevel());
current_info->stats.kill_count++;
}
bool Stats_AddSecret(const int16_t secret_number)
{
RESUME_INFO *const current_info =
Savegame_GetCurrentInfo(Game_GetCurrentLevel());
if (current_info->stats.secret_flags & secret_number) {
return false;
}
current_info->stats.secret_flags |= secret_number;
current_info->stats.secret_count++;
return true;
}
void Stats_AddPickup(void)
{
RESUME_INFO *const current_info =
Savegame_GetCurrentInfo(Game_GetCurrentLevel());
current_info->stats.pickup_count++;
}
void Stats_AddAmmoHits(void)
{
RESUME_INFO *const current_info =
Savegame_GetCurrentInfo(Game_GetCurrentLevel());
current_info->stats.ammo_hits++;
}
void Stats_AddAmmoUsed(void)
{
RESUME_INFO *const current_info =
Savegame_GetCurrentInfo(Game_GetCurrentLevel());
current_info->stats.ammo_used++;
}
void Stats_AddMedipacksUsed(const double medipack_value)
{
RESUME_INFO *const current_info =
Savegame_GetCurrentInfo(Game_GetCurrentLevel());
current_info->stats.medipacks_used += medipack_value;
}
void Stats_AddDistanceTravelled(const XYZ_32 pos, const XYZ_32 last_pos)
{
RESUME_INFO *const current_info =
Savegame_GetCurrentInfo(Game_GetCurrentLevel());
current_info->stats.distance_travelled += Math_Sqrt(
SQUARE(pos.z - last_pos.z) + SQUARE(pos.y - last_pos.y)
+ SQUARE(pos.x - last_pos.x));
}

View file

@ -15,3 +15,11 @@ bool Stats_CheckAllSecretsCollected(GF_LEVEL_TYPE level_type);
void Stats_StartTimer(void);
void Stats_UpdateTimer(void);
void Stats_UpdateSecrets(LEVEL_STATS *stats);
void Stats_AddKill(void);
bool Stats_AddSecret(int16_t secret_number);
void Stats_AddPickup(void);
void Stats_AddAmmoHits(void);
void Stats_AddAmmoUsed(void);
void Stats_AddMedipacksUsed(double medipack_value);
void Stats_AddDistanceTravelled(XYZ_32 pos, XYZ_32 last_pos);