2016-04-13 06:07:23 +00:00
|
|
|
#ifndef __URDE_CGAMESTATE_HPP__
|
|
|
|
#define __URDE_CGAMESTATE_HPP__
|
2015-08-17 05:26:58 +00:00
|
|
|
|
2015-08-17 20:33:58 +00:00
|
|
|
#include <memory>
|
2015-08-20 02:52:07 +00:00
|
|
|
#include "CBasics.hpp"
|
2015-08-17 20:33:58 +00:00
|
|
|
#include "CPlayerState.hpp"
|
|
|
|
#include "CGameOptions.hpp"
|
2016-08-23 00:52:51 +00:00
|
|
|
#include "CRelayTracker.hpp"
|
2016-04-16 23:48:29 +00:00
|
|
|
#include "World/CWorldTransManager.hpp"
|
2016-08-23 00:52:51 +00:00
|
|
|
#include "AutoMapper/CMapWorldInfo.hpp"
|
2016-10-09 07:45:04 +00:00
|
|
|
#include "World/CWorld.hpp"
|
|
|
|
#include "DataSpec/DNACommon/DNACommon.hpp"
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
namespace urde
|
2015-08-17 22:05:00 +00:00
|
|
|
{
|
2016-09-25 01:58:20 +00:00
|
|
|
class CSaveWorldMemory;
|
|
|
|
|
2016-10-09 07:45:04 +00:00
|
|
|
class CWorldLayerState
|
2016-09-25 01:58:20 +00:00
|
|
|
{
|
2016-09-30 22:43:19 +00:00
|
|
|
friend class CSaveWorldIntermediate;
|
2016-10-09 07:45:04 +00:00
|
|
|
std::vector<CWorldLayers::Area> x0_areaLayers;
|
|
|
|
DataSpec::WordBitmap x10_saveLayers;
|
2017-01-07 01:58:05 +00:00
|
|
|
|
2016-09-25 01:58:20 +00:00
|
|
|
public:
|
2016-10-09 07:45:04 +00:00
|
|
|
CWorldLayerState() = default;
|
|
|
|
CWorldLayerState(CBitStreamReader& reader, const CSaveWorld& saveWorld);
|
|
|
|
|
2017-01-07 01:58:05 +00:00
|
|
|
bool IsLayerActive(int areaIdx, int layerIdx) const { return (x0_areaLayers[areaIdx].m_layerBits >> layerIdx) & 1; }
|
2016-09-25 01:58:20 +00:00
|
|
|
|
2016-10-09 07:45:04 +00:00
|
|
|
void SetLayerActive(int areaIdx, int layerIdx, bool active)
|
|
|
|
{
|
|
|
|
if (active)
|
2016-12-11 01:54:08 +00:00
|
|
|
x0_areaLayers[areaIdx].m_layerBits |= uint64_t(1) << layerIdx;
|
2016-10-09 07:45:04 +00:00
|
|
|
else
|
2016-12-11 01:54:08 +00:00
|
|
|
x0_areaLayers[areaIdx].m_layerBits &= ~(uint64_t(1) << layerIdx);
|
2016-09-25 01:58:20 +00:00
|
|
|
}
|
2016-10-09 07:45:04 +00:00
|
|
|
|
|
|
|
void InitializeWorldLayers(const std::vector<CWorldLayers::Area>& layers);
|
2016-10-09 21:41:23 +00:00
|
|
|
|
2017-01-07 01:58:05 +00:00
|
|
|
u32 GetAreaLayerCount(int areaIdx) const { return x0_areaLayers[areaIdx].m_layerCount; }
|
2016-10-09 21:41:23 +00:00
|
|
|
|
|
|
|
void PutTo(CBitStreamWriter& writer) const;
|
2016-09-25 01:58:20 +00:00
|
|
|
};
|
2015-08-17 22:05:00 +00:00
|
|
|
|
2016-08-14 03:00:58 +00:00
|
|
|
class CWorldState
|
|
|
|
{
|
|
|
|
ResId x0_mlvlId;
|
2016-09-25 01:58:20 +00:00
|
|
|
TAreaId x4_areaId = kInvalidAreaId;
|
2016-08-23 00:52:51 +00:00
|
|
|
std::shared_ptr<CRelayTracker> x8_relayTracker;
|
|
|
|
std::shared_ptr<CMapWorldInfo> xc_mapWorldInfo;
|
2017-02-12 03:17:18 +00:00
|
|
|
ResId x10_desiredAreaAssetId;
|
2016-10-09 07:45:04 +00:00
|
|
|
std::shared_ptr<CWorldLayerState> x14_layerState;
|
2017-01-07 01:58:05 +00:00
|
|
|
|
2016-08-14 03:00:58 +00:00
|
|
|
public:
|
2016-10-08 20:32:36 +00:00
|
|
|
CWorldState(ResId id);
|
2016-09-25 01:58:20 +00:00
|
|
|
CWorldState(CBitStreamReader& reader, ResId mlvlId, const CSaveWorld& saveWorld);
|
2017-01-07 01:58:05 +00:00
|
|
|
ResId GetWorldAssetId() const { return x0_mlvlId; }
|
2016-08-14 03:00:58 +00:00
|
|
|
void SetAreaId(TAreaId aid) { x4_areaId = aid; }
|
2016-09-30 22:43:19 +00:00
|
|
|
TAreaId GetCurrentAreaId() const { return x4_areaId; }
|
2017-02-12 03:17:18 +00:00
|
|
|
ResId GetDesiredAreaAssetId() const { return x10_desiredAreaAssetId; }
|
2017-02-18 02:19:50 +00:00
|
|
|
void SetDesiredAreaAssetId(ResId id) { x10_desiredAreaAssetId = id; }
|
2016-09-30 22:43:19 +00:00
|
|
|
const std::shared_ptr<CRelayTracker>& RelayTracker() const { return x8_relayTracker; }
|
|
|
|
const std::shared_ptr<CMapWorldInfo>& MapWorldInfo() const { return xc_mapWorldInfo; }
|
2016-10-09 07:45:04 +00:00
|
|
|
const std::shared_ptr<CWorldLayerState>& GetLayerState() const { return x14_layerState; }
|
2016-10-09 21:41:23 +00:00
|
|
|
void PutTo(CBitStreamWriter& writer, const CSaveWorld& savw) const;
|
2016-08-14 03:00:58 +00:00
|
|
|
};
|
|
|
|
|
2015-08-17 05:26:58 +00:00
|
|
|
class CGameState
|
|
|
|
{
|
2016-08-14 21:11:44 +00:00
|
|
|
friend class CStateManager;
|
|
|
|
|
2016-08-15 20:58:07 +00:00
|
|
|
bool x0_[128] = {};
|
2016-12-26 07:58:44 +00:00
|
|
|
u32 x80_;
|
2016-08-14 03:00:58 +00:00
|
|
|
ResId x84_mlvlId = -1;
|
|
|
|
std::vector<CWorldState> x88_worldStates;
|
2016-08-15 20:58:07 +00:00
|
|
|
std::shared_ptr<CPlayerState> x98_playerState;
|
|
|
|
std::shared_ptr<CWorldTransManager> x9c_transManager;
|
2016-12-30 06:37:01 +00:00
|
|
|
double xa0_playTime = 0.0;
|
2016-09-25 01:58:20 +00:00
|
|
|
CPersistentOptions xa8_systemOptions;
|
2016-09-08 02:01:29 +00:00
|
|
|
CGameOptions x17c_gameOptions;
|
2016-09-25 01:58:20 +00:00
|
|
|
CHintOptions x1f8_hintOptions;
|
2016-12-30 06:37:01 +00:00
|
|
|
u32 x20c_saveFileIdx = 0;
|
|
|
|
u64 x210_cardSerial = 0;
|
2016-12-23 06:41:39 +00:00
|
|
|
std::vector<u8> x218_backupBuf;
|
2016-08-14 21:11:44 +00:00
|
|
|
|
|
|
|
union
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
2016-12-30 06:37:01 +00:00
|
|
|
bool x228_24_hardMode : 1;
|
|
|
|
bool x228_25_deferPowerupInit : 1;
|
2016-08-14 21:11:44 +00:00
|
|
|
};
|
|
|
|
u8 _dummy = 0;
|
|
|
|
};
|
2016-09-25 01:58:20 +00:00
|
|
|
|
2016-10-09 21:41:23 +00:00
|
|
|
static void EnsureWorldPakReady(ResId mlvl);
|
|
|
|
|
2015-08-17 20:33:58 +00:00
|
|
|
public:
|
2016-08-14 21:11:44 +00:00
|
|
|
CGameState();
|
2016-12-30 06:37:01 +00:00
|
|
|
CGameState(CBitStreamReader& stream, u32 saveIdx);
|
2016-10-09 21:41:23 +00:00
|
|
|
void SetCurrentWorldId(ResId id);
|
2017-01-07 01:58:05 +00:00
|
|
|
std::shared_ptr<CPlayerState> GetPlayerState() { return x98_playerState; }
|
|
|
|
std::shared_ptr<CWorldTransManager> GetWorldTransitionManager() { return x9c_transManager; }
|
2016-03-28 08:54:02 +00:00
|
|
|
void SetTotalPlayTime(float time);
|
2016-09-25 01:58:20 +00:00
|
|
|
CPersistentOptions& SystemOptions() { return xa8_systemOptions; }
|
|
|
|
CGameOptions& GameOptions() { return x17c_gameOptions; }
|
2016-12-30 06:37:01 +00:00
|
|
|
CHintOptions& HintOptions() { return x1f8_hintOptions; }
|
2016-08-14 03:00:58 +00:00
|
|
|
CWorldState& StateForWorld(ResId mlvlId);
|
|
|
|
CWorldState& CurrentWorldState() { return StateForWorld(x84_mlvlId); }
|
2016-08-15 20:58:07 +00:00
|
|
|
ResId CurrentWorldAssetId() const { return x84_mlvlId; }
|
2016-12-16 23:05:29 +00:00
|
|
|
void SetHardMode(bool v) { x228_24_hardMode = v; }
|
2017-03-31 19:51:40 +00:00
|
|
|
bool GetHardMode() const { return x228_24_hardMode; }
|
2016-12-30 06:37:01 +00:00
|
|
|
void ReadPersistentOptions(CBitStreamReader& r);
|
2016-12-29 21:38:59 +00:00
|
|
|
void SetPersistentOptions(const CPersistentOptions& opts) { xa8_systemOptions = opts; }
|
2016-12-23 06:41:39 +00:00
|
|
|
void ImportPersistentOptions(const CPersistentOptions& opts);
|
|
|
|
void ExportPersistentOptions(CPersistentOptions& opts) const;
|
2016-12-29 21:38:59 +00:00
|
|
|
void SetGameOptions(const CGameOptions& opts) { x17c_gameOptions = opts; }
|
2016-12-23 06:41:39 +00:00
|
|
|
void WriteBackupBuf();
|
2016-12-30 06:37:01 +00:00
|
|
|
u32 GetFileIdx() const { return x20c_saveFileIdx; }
|
|
|
|
void SetFileIdx(u32 idx) { x20c_saveFileIdx = idx; }
|
2016-12-23 06:41:39 +00:00
|
|
|
void SetCardSerial(u64 serial) { x210_cardSerial = serial; }
|
2017-01-22 01:40:12 +00:00
|
|
|
u64 GetCardSerial() const { return x210_cardSerial; }
|
2016-10-09 21:41:23 +00:00
|
|
|
void PutTo(CBitStreamWriter& writer) const;
|
2016-12-24 06:08:48 +00:00
|
|
|
float GetHardModeDamageMultiplier() const;
|
|
|
|
float GetHardModeWeaponMultiplier() const;
|
2017-02-06 03:21:58 +00:00
|
|
|
void InitializeMemoryWorlds();
|
|
|
|
void InitializeMemoryStates();
|
2016-12-20 21:51:50 +00:00
|
|
|
|
|
|
|
struct GameFileStateInfo
|
|
|
|
{
|
|
|
|
double x0_playTime;
|
|
|
|
u32 x8_mlvlId;
|
|
|
|
float xc_health;
|
|
|
|
u32 x10_energyTanks;
|
|
|
|
u32 x14_timestamp;
|
|
|
|
u32 x18_itemPercent;
|
|
|
|
float x1c_scanPercent;
|
|
|
|
bool x20_hardMode;
|
|
|
|
};
|
|
|
|
static GameFileStateInfo LoadGameFileState(const u8* data);
|
2015-08-17 05:26:58 +00:00
|
|
|
};
|
2015-08-17 22:05:00 +00:00
|
|
|
}
|
|
|
|
|
2016-04-13 06:07:23 +00:00
|
|
|
#endif // __URDE_CGAMESTATE_HPP__
|