From cac05a263d826685343b5b6356076cf84d147c09 Mon Sep 17 00:00:00 2001 From: XProger Date: Tue, 16 Oct 2018 06:32:47 +0300 Subject: [PATCH] add level stats (non-UI) --- src/character.h | 2 ++ src/debug.h | 7 +++++++ src/lara.h | 24 +++++++++++++++++++++++- src/level.h | 11 ++++++++++- src/savegame.h | 2 +- 5 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/character.h b/src/character.h index 1a487d5..26efff3 100644 --- a/src/character.h +++ b/src/character.h @@ -127,6 +127,8 @@ struct Character : Controller { } virtual void hit(float damage, Controller *enemy = NULL, TR::HitType hitType = TR::HIT_DEFAULT) { + if (getEntity().isEnemy() && health > 0.0f && health <= damage) + level->levelStats.kills++; health = max(0.0f, health - damage); } diff --git a/src/debug.h b/src/debug.h index 859080d..5f6a266 100644 --- a/src/debug.h +++ b/src/debug.h @@ -711,6 +711,13 @@ namespace Debug { sprintf(buf, "floor = %d, roomBelow = %d, roomAbove = %d, roomNext = %d, height = %d", info.floorIndex, info.roomBelow, info.roomAbove, info.roomNext, int(info.floor - info.ceiling)); Debug::Draw::text(vec2(16, y += 16), vec4(1.0f), buf); + const SaveProgress &stats = game->getLevel()->levelStats; + sprintf(buf, "stats: time = %d, distance = %d, secrets = %c%c%c, pickups = %d, mediUsed = %d, ammoUsed = %d, kills = %d", stats.time, stats.distance, + (stats.secrets & 4) ? '1' : '0', + (stats.secrets & 2) ? '1' : '0', + (stats.secrets & 1) ? '1' : '0', stats.pickups, stats.mediUsed, stats.ammoUsed, stats.kills); + Debug::Draw::text(vec2(16, y += 16), vec4(1.0f), buf); + y += 16; if (info.lava) Debug::Draw::text(vec2(16, y += 16), vec4(1.0f, 0.5f, 0.3f, 1.0f), "LAVA"); diff --git a/src/lara.h b/src/lara.h index 9a55bb0..6394bb2 100644 --- a/src/lara.h +++ b/src/lara.h @@ -56,6 +56,8 @@ #define DESCENT_SPEED 2048.0f #define TARGET_MAX_DIST (8.0f * 1024.0f) +#define UNITS_PER_METER 445.0f + struct Lara : Character { // http://www.tombraiderforums.com/showthread.php?t=148859 @@ -274,6 +276,7 @@ struct Lara : Character { int hitDir; vec3 collisionOffset; vec3 flowVelocity; + float statsDistDelta; Camera *camera; @@ -467,6 +470,8 @@ struct Lara : Character { rangeChest = vec4(-0.50f, 0.50f, -0.95f, 0.95f) * PI; rangeHead = vec4(-0.30f, 0.30f, -0.55f, 0.55f) * PI; + statsDistDelta = 0.0f; + oxygen = LARA_MAX_OXYGEN; hitDir = -1; damageTime = LARA_DAMAGE_TIME; @@ -614,6 +619,8 @@ struct Lara : Character { virtual void setSaveData(const SaveEntity &data) { Character::setSaveData(data); + statsDistDelta = 0.0f; + velocity = vec3(data.extra.lara.velX, data.extra.lara.velY, data.extra.lara.velZ); angle.x = TR::angle(data.extra.lara.angleX); health = data.extra.lara.health; @@ -650,6 +657,8 @@ struct Lara : Character { } void reset(int room, const vec3 &pos, float angle, Stand forceStand = STAND_GROUND) { + statsDistDelta = 0.0f; + visibleMask = 0xFFFFFFFF; health = LARA_MAX_HEALTH; oxygen = LARA_MAX_OXYGEN; @@ -1011,6 +1020,8 @@ struct Lara : Character { } if (shots) { + level->levelStats.ammoUsed += ((wpnCurrent == TR::Entity::SHOTGUN) ? 1 : 2); + game->playSound(wpnGetSound(), pos, Sound::PAN); game->playSound(TR::SND_RICOCHET, nearPos, Sound::PAN); @@ -1624,6 +1635,7 @@ struct Lara : Character { case TR::Entity::INV_UZIS : wpnChange(TR::Entity::UZIS); break; case TR::Entity::INV_MEDIKIT_SMALL : case TR::Entity::INV_MEDIKIT_BIG : + level->levelStats.mediUsed += (item == TR::Entity::INV_MEDIKIT_SMALL) ? 1 : 2; damageTime = LARA_DAMAGE_TIME; health = min(LARA_MAX_HEALTH, health + (item == TR::Entity::INV_MEDIKIT_SMALL ? LARA_MAX_HEALTH / 2 : LARA_MAX_HEALTH)); game->playSound(TR::SND_HEALTH, pos, Sound::PAN); @@ -2827,6 +2839,7 @@ struct Lara : Character { pickupList[i]->deactivate(); pickupList[i]->flags.invisible = true; game->invAdd(pickupList[i]->getEntity().type, 1); + level->levelStats.pickups++; } pickupListCount = 0; } @@ -3102,8 +3115,17 @@ struct Lara : Character { collisionOffset = vec3(0.0f); - if (checkCollisions() || (velocity + flowVelocity + collisionOffset).length2() >= 1.0f) // TODO: stop & smash anim + if (checkCollisions() || (velocity + flowVelocity + collisionOffset).length2() >= 1.0f) { // TODO: stop & smash anim + vec3 oldPos = pos; + move(); + + statsDistDelta += (pos - oldPos).length(); + while (statsDistDelta >= UNITS_PER_METER) { + statsDistDelta -= UNITS_PER_METER; + level->levelStats.distance++; + } + } } virtual vec3 getPos() { diff --git a/src/level.h b/src/level.h index 0b8f592..913f6f1 100644 --- a/src/level.h +++ b/src/level.h @@ -67,6 +67,7 @@ struct Level : IGame { int effectIdx; float cutsceneWaitTimer; float animTexTimer; + float statsTimeDelta; // IGame implementation ======== virtual void loadLevel(TR::LevelID id) { @@ -247,6 +248,8 @@ struct Level : IGame { playTrack(track); } else memset(&level.levelStats, 0, sizeof(level.levelStats)); + + statsTimeDelta = 0.0f; } static void saveGameWriteAsync(Stream *stream, void *userData) { @@ -787,7 +790,7 @@ struct Level : IGame { } //============================== - Level(Stream &stream) : level(stream), waitTrack(false), isEnded(false), cutsceneWaitTimer(0.0f), animTexTimer(0.0f) { + Level(Stream &stream) : level(stream), waitTrack(false), isEnded(false), cutsceneWaitTimer(0.0f), animTexTimer(0.0f), statsTimeDelta(0.0f) { #ifdef _OS_PSP GAPI::freeEDRAM(); #endif @@ -1765,6 +1768,12 @@ struct Level : IGame { volWater = 0.0f; volTrack = level.isTitle() ? 0.9f : 0.0f; } else { + statsTimeDelta += Core::deltaTime; + while (statsTimeDelta >= 1.0f) { + statsTimeDelta -= 1.0f; + level.levelStats.time++; + } + params->time += Core::deltaTime; animTexTimer += Core::deltaTime; diff --git a/src/savegame.h b/src/savegame.h index e1ce771..7c87ebc 100644 --- a/src/savegame.h +++ b/src/savegame.h @@ -24,9 +24,9 @@ struct SaveItem { struct SaveProgress { uint32 time; uint32 distance; - uint32 mediUsed; uint32 secrets; uint32 pickups; + uint32 mediUsed; uint32 ammoUsed; uint32 kills; };