From 81781a53ed9ad7ce5bf99c0646449efaab4150b7 Mon Sep 17 00:00:00 2001 From: husho Date: Mon, 18 Jun 2018 07:23:20 +0300 Subject: [PATCH] Various opcodes (#499) Various opcodes --- rwengine/src/ai/PlayerController.cpp | 2 +- rwengine/src/engine/GameState.hpp | 4 +- rwengine/src/objects/VehicleObject.cpp | 9 +- rwengine/src/objects/VehicleObject.hpp | 2 + rwengine/src/script/ScriptMachine.cpp | 9 +- rwengine/src/script/ScriptMachine.hpp | 18 +- .../src/script/modules/GTA3ModuleImpl.inl | 155 +++++++++--------- 7 files changed, 107 insertions(+), 92 deletions(-) diff --git a/rwengine/src/ai/PlayerController.cpp b/rwengine/src/ai/PlayerController.cpp index dc178773..2f55671f 100644 --- a/rwengine/src/ai/PlayerController.cpp +++ b/rwengine/src/ai/PlayerController.cpp @@ -128,7 +128,7 @@ void PlayerController::restart() { if (!state->playerInfo.thaneOfLibertyCity) { // @todo implement wanted system uint8_t wantedLevel = 0; - uint32_t penalty = 0; + int32_t penalty = 0; switch (wantedLevel) { case 0: diff --git a/rwengine/src/engine/GameState.hpp b/rwengine/src/engine/GameState.hpp index 409379e5..6aa28801 100644 --- a/rwengine/src/engine/GameState.hpp +++ b/rwengine/src/engine/GameState.hpp @@ -76,12 +76,12 @@ struct BasicState { /** Block 16 player info */ struct PlayerInfo { - uint32_t money; + int32_t money; uint8_t unknown1; uint32_t unknown2; uint16_t unknown3; float unknown4; - uint32_t displayedMoney; + int32_t displayedMoney; uint32_t hiddenPackagesCollected; uint32_t hiddenPackageCount; uint8_t neverTired; diff --git a/rwengine/src/objects/VehicleObject.cpp b/rwengine/src/objects/VehicleObject.cpp index b54f2c24..54fe9ebc 100644 --- a/rwengine/src/objects/VehicleObject.cpp +++ b/rwengine/src/objects/VehicleObject.cpp @@ -519,8 +519,13 @@ void VehicleObject::tickPhysics(float dt) { } bool VehicleObject::isFlipped() const { - auto up = getRotation() * glm::vec3(0.f, 0.f, 1.f); - return up.z <= -0.1f; + auto forward = getRotation() * glm::vec3(0.f, 0.f, 1.f); + return forward.z <= -0.97f; +} + +bool VehicleObject::isUpright() const { + auto forward = getRotation() * glm::vec3(0.f, 0.f, 1.f); + return forward.z >= 0.f; } float VehicleObject::getVelocity() const { diff --git a/rwengine/src/objects/VehicleObject.hpp b/rwengine/src/objects/VehicleObject.hpp index 485059e2..2f86cbf9 100644 --- a/rwengine/src/objects/VehicleObject.hpp +++ b/rwengine/src/objects/VehicleObject.hpp @@ -128,6 +128,8 @@ public: bool isFlipped() const; + bool isUpright() const; + float getVelocity() const; void ejectAll(); diff --git a/rwengine/src/script/ScriptMachine.cpp b/rwengine/src/script/ScriptMachine.cpp index 517548f0..bd6fcb20 100644 --- a/rwengine/src/script/ScriptMachine.cpp +++ b/rwengine/src/script/ScriptMachine.cpp @@ -22,7 +22,13 @@ void ScriptMachine::executeThread(SCMThread& t, int msPassed) { t.programCounter = t.calls[t.stackDepth]; } } - + // There is 02a1 opcode that is used only during "Kingdom Come", which + // basically acts like a wait command, but waiting time can be skipped + // by pressing 'X'? PS2 button + if (t.allowWaitSkip && getState()->input[0].pressed(GameInputState::Jump)) { + t.wakeCounter = 0; + t.allowWaitSkip = false; + } if (t.wakeCounter > 0) { t.wakeCounter = std::max(t.wakeCounter - msPassed, 0); } @@ -211,6 +217,7 @@ void ScriptMachine::startThread(SCMThread::pc_t start, bool mission) { t.stackDepth = 0; t.deathOrArrestCheck = true; t.wastedOrBusted = false; + t.allowWaitSkip = false; _activeThreads.push_back(t); } diff --git a/rwengine/src/script/ScriptMachine.hpp b/rwengine/src/script/ScriptMachine.hpp index a0445177..6ef5f30b 100644 --- a/rwengine/src/script/ScriptMachine.hpp +++ b/rwengine/src/script/ScriptMachine.hpp @@ -5,12 +5,12 @@ #include #include #include +#include #include #include +#include #include #include -#include -#include #include