From 60574ae667a37f5ed7af04b63abb159f594e4e20 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Mon, 3 Jul 2017 15:45:21 +0300 Subject: [PATCH] [General] Implement jail time as a death penalty --- apps/openmw-mp/Script/Functions/Death.cpp | 8 ++++ apps/openmw-mp/Script/Functions/Death.hpp | 6 ++- apps/openmw/mwgui/jailscreen.cpp | 48 ++++++++++++++++++- apps/openmw/mwmp/LocalPlayer.cpp | 1 + .../player/ProcessorPlayerResurrect.hpp | 9 ++++ components/openmw-mp/Base/BasePlayer.hpp | 2 + .../Packets/Player/PacketPlayerResurrect.cpp | 1 + 7 files changed, 73 insertions(+), 2 deletions(-) diff --git a/apps/openmw-mp/Script/Functions/Death.cpp b/apps/openmw-mp/Script/Functions/Death.cpp index 83467df81..df2500484 100644 --- a/apps/openmw-mp/Script/Functions/Death.cpp +++ b/apps/openmw-mp/Script/Functions/Death.cpp @@ -7,6 +7,14 @@ #include using namespace std; +void DeathFunctions::SetDeathPenaltyJailDays(unsigned short pid, int days) noexcept +{ + Player *player; + GET_PLAYER(pid, player, ); + + player->deathPenaltyJailDays = days; +} + void DeathFunctions::Resurrect(unsigned short pid, unsigned int type) noexcept { Player *player; diff --git a/apps/openmw-mp/Script/Functions/Death.hpp b/apps/openmw-mp/Script/Functions/Death.hpp index 3dccbeb7c..a9ed09c27 100644 --- a/apps/openmw-mp/Script/Functions/Death.hpp +++ b/apps/openmw-mp/Script/Functions/Death.hpp @@ -4,11 +4,15 @@ #include "../Types.hpp" #define DEATHAPI \ - {"Resurrect", DeathFunctions::Resurrect} + {"SetDeathPenaltyJailDays", DeathFunctions::SetDeathPenaltyJailDays},\ + \ + {"Resurrect", DeathFunctions::Resurrect} class DeathFunctions { public: + static void SetDeathPenaltyJailDays(unsigned short pid, int days) noexcept; + static void Resurrect(unsigned short pid, unsigned int type) noexcept; }; diff --git a/apps/openmw/mwgui/jailscreen.cpp b/apps/openmw/mwgui/jailscreen.cpp index 211e0c5f9..50c7474cc 100644 --- a/apps/openmw/mwgui/jailscreen.cpp +++ b/apps/openmw/mwgui/jailscreen.cpp @@ -1,5 +1,17 @@ #include +/* + Start of tes3mp addition + + Include additional headers for multiplayer purposes +*/ +#include "../mwmp/Main.hpp" +#include "../mwmp/LocalPlayer.hpp" +#include +/* + End of tes3mp addition +*/ + #include #include "../mwbase/windowmanager.hpp" @@ -59,7 +71,18 @@ namespace MWGui if (mFadeTimeRemaining <= 0) { MWWorld::Ptr player = MWMechanics::getPlayer(); - MWBase::Environment::get().getWorld()->teleportToClosestMarker(player, "prisonmarker"); + + /* + Start of tes3mp change (minor) + + If the jail code is being used from elsewhere to lower skills, don't + teleport the player to the nearest prison + */ + if (!mwmp::Main::get().getLocalPlayer()->ignoreJailTeleportation) + MWBase::Environment::get().getWorld()->teleportToClosestMarker(player, "prisonmarker"); + /* + End of tes3mp change (minor) + */ setVisible(true); mTimeAdvancer.run(100); @@ -104,6 +127,29 @@ namespace MWGui else message = gmst.find("sNotifyMessage43")->getString(); + /* + Start of tes3mp addition + + If the jail code is being used from elsewhere to lower skills, reset the + corresponding boolean and use more ambiguous wording for the message displayed + */ + if (mwmp::Main::get().getLocalPlayer()->ignoreJailTeleportation) + { + mwmp::Main::get().getLocalPlayer()->ignoreJailTeleportation = false; + + const std::string stringToReplace = "been released"; + const std::string stringToReplace2 = "in prison"; + + if (message.find(stringToReplace) != std::string::npos) + message.replace(message.find(stringToReplace), stringToReplace.size(), "recovered"); + + if (message.find(stringToReplace2) != std::string::npos) + message.replace(message.find(stringToReplace2), stringToReplace2.size(), "incapacitated"); + } + /* + End of tes3mp addition + */ + std::stringstream dayStr; dayStr << mDays; if (message.find("%d") != std::string::npos) diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index 42e62f7b7..ea02ff498 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -51,6 +51,7 @@ LocalPlayer::LocalPlayer() difficulty = 0; ignorePosPacket = false; + ignoreJailTeleportation = false; attack.shouldSend = false; diff --git a/apps/openmw/mwmp/processors/player/ProcessorPlayerResurrect.hpp b/apps/openmw/mwmp/processors/player/ProcessorPlayerResurrect.hpp index e79df2ce1..f9bab41d1 100644 --- a/apps/openmw/mwmp/processors/player/ProcessorPlayerResurrect.hpp +++ b/apps/openmw/mwmp/processors/player/ProcessorPlayerResurrect.hpp @@ -5,6 +5,8 @@ #ifndef OPENMW_PROCESSORPLAYERRESURRECT_HPP #define OPENMW_PROCESSORPLAYERRESURRECT_HPP +#include "apps/openmw/mwbase/environment.hpp" +#include "apps/openmw/mwgui/windowmanagerimp.hpp" #include "../PlayerProcessor.hpp" #include "apps/openmw/mwmp/Main.hpp" @@ -59,6 +61,13 @@ namespace mwmp static_cast(player)->updateStatsDynamic(true); Main::get().getNetworking()->getPlayerPacket(ID_PLAYER_STATS_DYNAMIC)->setPlayer(player); Main::get().getNetworking()->getPlayerPacket(ID_PLAYER_STATS_DYNAMIC)->Send(serverAddr); + + // Apply death penalties + if (player->deathPenaltyJailDays > 0) + { + player->ignoreJailTeleportation = true; + MWBase::Environment::get().getWindowManager()->goToJail(player->deathPenaltyJailDays); + } } else if (player != 0) { diff --git a/components/openmw-mp/Base/BasePlayer.hpp b/components/openmw-mp/Base/BasePlayer.hpp index 4da795c3f..6dfb4c372 100644 --- a/components/openmw-mp/Base/BasePlayer.hpp +++ b/components/openmw-mp/Base/BasePlayer.hpp @@ -242,6 +242,8 @@ namespace mwmp bool isChangingRegion; std::string deathReason; + int deathPenaltyJailDays; + bool ignoreJailTeleportation; unsigned int resurrectType; }; diff --git a/components/openmw-mp/Packets/Player/PacketPlayerResurrect.cpp b/components/openmw-mp/Packets/Player/PacketPlayerResurrect.cpp index 9a35e3784..db1b3c832 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerResurrect.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerResurrect.cpp @@ -14,4 +14,5 @@ void PacketPlayerResurrect::Packet(RakNet::BitStream *bs, bool send) PlayerPacket::Packet(bs, send); RW(player->resurrectType, send); + RW(player->deathPenaltyJailDays, send); }