Implement god mode, and CWeaponMgr

This commit is contained in:
Phillip Stephens 2018-06-13 12:36:11 -07:00
parent 4d8cf17078
commit de952f8e8b
5 changed files with 67 additions and 24 deletions

View File

@ -128,6 +128,8 @@ private:
std::vector<std::pair<CAssetId, float>> x170_scanTimes; std::vector<std::pair<CAssetId, float>> x170_scanTimes;
std::pair<u32, u32> x180_scanCompletionRate = {}; std::pair<u32, u32> x180_scanCompletionRate = {};
CStaticInterference x188_staticIntf; CStaticInterference x188_staticIntf;
bool m_canTakeDamage = true;
public: public:
u32 GetMissileCostForAltAttack() const; u32 GetMissileCostForAltAttack() const;
@ -186,6 +188,8 @@ public:
void PutTo(CBitStreamWriter& stream); void PutTo(CBitStreamWriter& stream);
static u32 GetPowerUpMaxValue(EItemType type) { return PowerUpMaxValues[u32(type)]; } static u32 GetPowerUpMaxValue(EItemType type) { return PowerUpMaxValues[u32(type)]; }
static EItemType ItemNameToType(std::string_view name); static EItemType ItemNameToType(std::string_view name);
bool CanTakeDamage() const { return m_canTakeDamage; }
void SetCanTakeDamage(bool c) { m_canTakeDamage = c; }
}; };
} }

View File

@ -1705,6 +1705,8 @@ bool CStateManager::ApplyLocalDamage(const zeus::CVector3f& vec1, const zeus::CV
#endif #endif
if (player) if (player)
{
if (GetPlayerState()->CanTakeDamage())
{ {
if (x870_cameraManager->IsInCinematicCamera() || if (x870_cameraManager->IsInCinematicCamera() ||
(weapMode.GetType() == EWeaponType::Phazon && (weapMode.GetType() == EWeaponType::Phazon &&
@ -1724,6 +1726,9 @@ bool CStateManager::ApplyLocalDamage(const zeus::CVector3f& vec1, const zeus::CV
mulDam = -(damReduction * mulDam - mulDam); mulDam = -(damReduction * mulDam - mulDam);
} }
else
mulDam = 0.f;
}
float newHp = hInfo->GetHP() - mulDam; float newHp = hInfo->GetHP() - mulDam;
hInfo->SetHP(newHp); hInfo->SetHP(newHp);

View File

@ -515,6 +515,18 @@ void CMain::Give(hecl::Console* console, const std::vector<std::string>& args)
console->report(hecl::Console::Level::Info, "Cheater....., Greatly increasing Metroid encounters, have fun!"); console->report(hecl::Console::Level::Info, "Cheater....., Greatly increasing Metroid encounters, have fun!");
} }
void CMain::God(hecl::Console* con, const std::vector<std::string> &)
{
if (g_GameState && g_GameState->GetPlayerState())
{
g_GameState->GetPlayerState()->SetCanTakeDamage(!g_GameState->GetPlayerState()->CanTakeDamage());
if (!g_GameState->GetPlayerState()->CanTakeDamage())
con->report(hecl::Console::Level::Info, "God Mode Enabled");
else
con->report(hecl::Console::Level::Info, "God Mode Disabled");
}
}
void CMain::Teleport(hecl::Console *, const std::vector<std::string>& args) void CMain::Teleport(hecl::Console *, const std::vector<std::string>& args)
{ {
if (!g_StateManager || args.size() < 3) if (!g_StateManager || args.size() < 3)
@ -655,6 +667,7 @@ void CMain::Init(const hecl::Runtime::FileStoreManager& storeMgr,
m_console->registerCommand("quit"sv, "Quits the game immediately"sv, ""sv, std::bind(&CMain::quit, this, std::placeholders::_1, std::placeholders::_2)); m_console->registerCommand("quit"sv, "Quits the game immediately"sv, ""sv, std::bind(&CMain::quit, this, std::placeholders::_1, std::placeholders::_2));
m_console->registerCommand("Give"sv, "Gives the player the specified item, maxing it out"sv, ""sv, std::bind(&CMain::Give, this, std::placeholders::_1, std::placeholders::_2), hecl::SConsoleCommand::ECommandFlags::Cheat); m_console->registerCommand("Give"sv, "Gives the player the specified item, maxing it out"sv, ""sv, std::bind(&CMain::Give, this, std::placeholders::_1, std::placeholders::_2), hecl::SConsoleCommand::ECommandFlags::Cheat);
m_console->registerCommand("Teleport"sv, "Teleports the player to the specified coordinates in worldspace"sv, "x y z [dX dY dZ]"sv, std::bind(&CMain::Teleport, this, std::placeholders::_1, std::placeholders::_2), (hecl::SConsoleCommand::ECommandFlags::Cheat | hecl::SConsoleCommand::ECommandFlags::Developer)); m_console->registerCommand("Teleport"sv, "Teleports the player to the specified coordinates in worldspace"sv, "x y z [dX dY dZ]"sv, std::bind(&CMain::Teleport, this, std::placeholders::_1, std::placeholders::_2), (hecl::SConsoleCommand::ECommandFlags::Cheat | hecl::SConsoleCommand::ECommandFlags::Developer));
m_console->registerCommand("God"sv, "Disables damage given by enemies and objects"sv, ""sv, std::bind(&CMain::God, this, std::placeholders::_1, std::placeholders::_2), hecl::SConsoleCommand::ECommandFlags::Cheat);
m_console->registerCommand("listWorlds"sv, "Lists loaded worlds"sv, ""sv, std::bind(&CMain::ListWorlds, this, std::placeholders::_1, std::placeholders::_2), hecl::SConsoleCommand::ECommandFlags::Normal); m_console->registerCommand("listWorlds"sv, "Lists loaded worlds"sv, ""sv, std::bind(&CMain::ListWorlds, this, std::placeholders::_1, std::placeholders::_2), hecl::SConsoleCommand::ECommandFlags::Normal);
InitializeSubsystems(storeMgr); InitializeSubsystems(storeMgr);

View File

@ -332,6 +332,7 @@ public:
m_doQuit = true; m_doQuit = true;
} }
void Give(hecl::Console*, const std::vector<std::string>&); void Give(hecl::Console*, const std::vector<std::string>&);
void God(hecl::Console*, const std::vector<std::string>&);
void Teleport(hecl::Console*, const std::vector<std::string>&); void Teleport(hecl::Console*, const std::vector<std::string>&);
void ListWorlds(hecl::Console*, const std::vector<std::string>&); void ListWorlds(hecl::Console*, const std::vector<std::string>&);
hecl::Console* Console() const { return m_console.get(); } hecl::Console* Console() const { return m_console.get(); }

View File

@ -3,34 +3,54 @@
namespace urde namespace urde
{ {
void CWeaponMgr::Add(TUniqueId, EWeaponType) void CWeaponMgr::Add(TUniqueId uid, EWeaponType type)
{ {
x0_weapons.insert(std::make_pair(uid, rstl::reserved_vector<s32, 10>()));
x0_weapons[uid].resize(10);
++x0_weapons[uid][u32(type)];
} }
void CWeaponMgr::Remove(TUniqueId) void CWeaponMgr::Remove(TUniqueId uid)
{ {
s32 totalActive = 0;
for (u32 i = 0; i < 10; ++i)
totalActive += x0_weapons[uid][i];
if (totalActive == 0)
x0_weapons.erase(uid);
} }
void CWeaponMgr::IncrCount(TUniqueId, EWeaponType) void CWeaponMgr::IncrCount(TUniqueId uid, EWeaponType type)
{ {
if (GetIndex(uid) < 0)
Add(uid, type);
else
x0_weapons[uid][u32(type)]++;
} }
void CWeaponMgr::DecrCount(TUniqueId, EWeaponType) void CWeaponMgr::DecrCount(TUniqueId uid, EWeaponType type)
{ {
if (GetIndex(uid) < 0)
return;
x0_weapons[uid][u32(type)]--;
if (x0_weapons[uid][u32(type)] <= 0)
Remove(uid);
} }
s32 CWeaponMgr::GetNumActive(TUniqueId, EWeaponType) const s32 CWeaponMgr::GetNumActive(TUniqueId uid, EWeaponType type) const
{ {
if (GetIndex(uid) < 0)
return 0; return 0;
return x0_weapons.at(uid)[u32(type)];
} }
s32 CWeaponMgr::GetIndex(TUniqueId) const s32 CWeaponMgr::GetIndex(TUniqueId uid) const
{ {
return 0; if (x0_weapons.find(uid) == x0_weapons.end())
return -1;
return s32(std::distance(x0_weapons.begin(), x0_weapons.find(uid)));
} }
} }