From 37d1aa41296f3ea1e912041d4fc201df54ad2639 Mon Sep 17 00:00:00 2001 From: Nikolay Korolev Date: Sat, 23 Jan 2021 23:04:24 +0300 Subject: [PATCH] script fixes --- src/control/Remote.cpp | 3 ++- src/control/Remote.h | 2 +- src/control/Script.cpp | 14 ++++++++------ src/control/Script10.cpp | 5 +++-- src/control/Script4.cpp | 1 + src/control/Script9.cpp | 6 +++--- src/core/re3.cpp | 2 +- src/vehicles/Bike.cpp | 1 + 8 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/control/Remote.cpp b/src/control/Remote.cpp index 047b19f3..dc025549 100644 --- a/src/control/Remote.cpp +++ b/src/control/Remote.cpp @@ -9,7 +9,7 @@ #include "PlayerInfo.h" #include "Vehicle.h" -void +CVehicle* CRemote::GivePlayerRemoteControlledCar(float x, float y, float z, float rot, uint16 model) { CAutomobile *car = new CAutomobile(model, MISSION_VEHICLE); @@ -40,6 +40,7 @@ CRemote::GivePlayerRemoteControlledCar(float x, float y, float z, float rot, uin TheCamera.SetZoomValueCamStringScript(0); } else TheCamera.TakeControl(car, CCam::MODE_BEHINDCAR, INTERPOLATION, CAMCONTROL_SCRIPT); + return car; } void diff --git a/src/control/Remote.h b/src/control/Remote.h index 72cabb7c..4c40dd96 100644 --- a/src/control/Remote.h +++ b/src/control/Remote.h @@ -3,6 +3,6 @@ class CRemote { public: - static void GivePlayerRemoteControlledCar(float, float, float, float, uint16); + static CVehicle* GivePlayerRemoteControlledCar(float, float, float, float, uint16); static void TakeRemoteControlledCarFromPlayer(bool blowUp = true); }; diff --git a/src/control/Script.cpp b/src/control/Script.cpp index 7712a335..e1e1fbc2 100644 --- a/src/control/Script.cpp +++ b/src/control/Script.cpp @@ -426,7 +426,7 @@ const tScriptCommandData commands[] = { REGISTER_COMMAND(COMMAND_ADD_SCORE, INPUT_ARGUMENTS(ARGTYPE_INT, ARGTYPE_INT, ), OUTPUT_ARGUMENTS(), false, -1, ""), REGISTER_COMMAND(COMMAND_IS_SCORE_GREATER, INPUT_ARGUMENTS(ARGTYPE_INT, ARGTYPE_INT, ), OUTPUT_ARGUMENTS(), true, -1, ""), REGISTER_COMMAND(COMMAND_STORE_SCORE, INPUT_ARGUMENTS(ARGTYPE_INT, ), OUTPUT_ARGUMENTS(ARGTYPE_INT, ), false, -1, ""), - REGISTER_COMMAND(COMMAND_GIVE_REMOTE_CONTROLLED_CAR_TO_PLAYER, INPUT_ARGUMENTS(ARGTYPE_INT, ARGTYPE_FLOAT, ARGTYPE_FLOAT, ARGTYPE_FLOAT, ARGTYPE_FLOAT, ), OUTPUT_ARGUMENTS(), false, -1, ""), + REGISTER_COMMAND(COMMAND_GIVE_REMOTE_CONTROLLED_CAR_TO_PLAYER, INPUT_ARGUMENTS(ARGTYPE_INT, ARGTYPE_FLOAT, ARGTYPE_FLOAT, ARGTYPE_FLOAT, ARGTYPE_FLOAT, ), OUTPUT_ARGUMENTS(ARGTYPE_INT, ), false, -1, ""), REGISTER_COMMAND(COMMAND_ALTER_WANTED_LEVEL, INPUT_ARGUMENTS(ARGTYPE_INT, ARGTYPE_INT, ), OUTPUT_ARGUMENTS(), false, -1, ""), REGISTER_COMMAND(COMMAND_ALTER_WANTED_LEVEL_NO_DROP, INPUT_ARGUMENTS(ARGTYPE_INT, ARGTYPE_INT, ), OUTPUT_ARGUMENTS(), false, -1, ""), REGISTER_COMMAND(COMMAND_IS_WANTED_LEVEL_GREATER, INPUT_ARGUMENTS(ARGTYPE_INT, ARGTYPE_INT, ), OUTPUT_ARGUMENTS(), true, -1, ""), @@ -2140,9 +2140,7 @@ void CMissionCleanup::Process() default: break; } - m_sEntities[i].id = 0; - m_sEntities[i].type = CLEANUP_UNUSED; - m_nCount--; + RemoveEntityFromList(i, m_sEntities[i].type); } for (int i = 1; i < NUMSTREAMINFO; i++) { if (CStreaming::IsScriptOwnedModel(i)) @@ -2517,7 +2515,7 @@ int32* GetPointerToScriptVariable(CRunningScript* pScript, uint32* pIp) return &pScript->m_anLocalVariables[NUM_LOCAL_VARS + 8 + (type - ARGUMENT_TIMER)]; } script_assert(false && "wrong type for variable"); - return nil; + return &pScript->m_anLocalVariables[pScript->m_nLocalsPointer + (type - ARGUMENT_LOCAL)]; } int32 *CRunningScript::GetPointerToScriptVariable(uint32* pIp, int16 type) @@ -2912,7 +2910,9 @@ int8 CRunningScript::ProcessOneCommand() uint8 nLocalsOffset; if (command < ARRAY_SIZE(commands)) { script_assert(commands[command].id == command); + m_nIp -= 2; sprintf(commandInfo, m_nIp >= CTheScripts::MainScriptSize ? "M<%5d> " : "<%6d> ", m_nIp >= CTheScripts::MainScriptSize ? m_nIp - CTheScripts::MainScriptSize : m_nIp); + m_nIp += 2; if (m_bNotFlag) strcat(commandInfo, "NOT "); if (commands[command].position == -1) @@ -4934,7 +4934,9 @@ int8 CRunningScript::ProcessCommands200To299(int32 command) CVector pos = GET_VECTOR_PARAM(1); if (pos.z <= MAP_Z_LOW_LIMIT) pos.z = CWorld::FindGroundZForCoord(pos.x, pos.y); - CRemote::GivePlayerRemoteControlledCar(pos.x, pos.y, pos.z, DEGTORAD(GET_FLOAT_PARAM(4)), MI_RCBANDIT); + CVehicle* pVehicle = CRemote::GivePlayerRemoteControlledCar(pos.x, pos.y, pos.z, DEGTORAD(GET_FLOAT_PARAM(4)), MI_RCBANDIT); + SET_INTEGER_PARAM(0, CPools::GetVehiclePool()->GetIndex(pVehicle)); + StoreParameters(&m_nIp, 1); return 0; } case COMMAND_ALTER_WANTED_LEVEL: diff --git a/src/control/Script10.cpp b/src/control/Script10.cpp index 536701b3..fef33848 100644 --- a/src/control/Script10.cpp +++ b/src/control/Script10.cpp @@ -74,7 +74,7 @@ int8 CRunningScript::ProcessCommands1600To1699(int32 command) case COMMAND_ADD_ARROW_3D_MARKER: { uint32 ip = m_nIp; - uint32 id = (uint32)(uintptr)GetPointerToScriptVariable(&m_nIp, 0); + uint32 id = (uint32)(uintptr)GetPointerToScriptVariable(&ip, 0); CollectParameters(&m_nIp, 10); CVector pos = GET_VECTOR_PARAM(0); CVector dir = GET_VECTOR_PARAM(3); @@ -213,7 +213,7 @@ int8 CRunningScript::ProcessCommands1600To1699(int32 command) case COMMAND_PRINT_WITH_2_NUMBERS_NOW_NO_BRIEF: { wchar* key = CTheScripts::GetTextByKeyFromScript(&m_nIp); - CollectParameters(&m_nIp, 3); + CollectParameters(&m_nIp, 4); CMessages::AddMessageJumpQWithNumber(key, GET_INTEGER_PARAM(2), GET_INTEGER_PARAM(3), GET_INTEGER_PARAM(0), GET_INTEGER_PARAM(1), -1, -1, -1, -1); // 0 return 0; } @@ -321,6 +321,7 @@ int8 CRunningScript::ProcessCommands1600To1699(int32 command) strncpy(onscreen_str2, (char*)&CTheScripts::ScriptSpace[m_nIp], KEY_LENGTH_IN_SCRIPT); m_nIp += KEY_LENGTH_IN_SCRIPT; CUserDisplay::OnscnTimer.AddCounter(var, GET_INTEGER_PARAM(1), onscreen_str1, 0); // TODO - second set of data + return 0; } case COMMAND_GET_PLAYER_STORED_WEAPON: { diff --git a/src/control/Script4.cpp b/src/control/Script4.cpp index c3eb2e89..d6a08c3d 100644 --- a/src/control/Script4.cpp +++ b/src/control/Script4.cpp @@ -935,6 +935,7 @@ int8 CRunningScript::ProcessCommands800To899(int32 command) script_assert(pVehicle); pPed->SetObjective(OBJECTIVE_ENTER_CAR_AS_DRIVER, pVehicle); pPed->WarpPedIntoCar(pVehicle); + pPed->RestorePreviousObjective(); return 0; } case COMMAND_WARP_CHAR_INTO_CAR: diff --git a/src/control/Script9.cpp b/src/control/Script9.cpp index 183f73e7..020221c4 100644 --- a/src/control/Script9.cpp +++ b/src/control/Script9.cpp @@ -636,7 +636,7 @@ int8 CRunningScript::ProcessCommands1500To1599(int32 command) case COMMAND_ADD_POINT_3D_MARKER: { uint32 ip = m_nIp; - uint32 id = (uint32)(uintptr)GetPointerToScriptVariable(&m_nIp, 0); + uint32 id = (uint32)(uintptr)GetPointerToScriptVariable(&ip, 0); static CVector vPreviousLocation; CollectParameters(&m_nIp, 7); CVector pos = GET_VECTOR_PARAM(0); @@ -737,10 +737,10 @@ int8 CRunningScript::ProcessCommands1500To1599(int32 command) } case COMMAND_SET_CHAR_ATTACKS_PLAYER_WITH_COPS: { - CollectParameters(&m_nIp, 1); + CollectParameters(&m_nIp, 2); CPed* pPed = CPools::GetPedPool()->GetAt(GET_INTEGER_PARAM(0)); script_assert(pPed); - pPed->bAttacksPlayerWithCops = (GET_INTEGER_PARAM(0) != 0); + pPed->bAttacksPlayerWithCops = (GET_INTEGER_PARAM(1) != 0); return 0; } case COMMAND_REGISTER_FACE_PLANT_DISTANCE: diff --git a/src/core/re3.cpp b/src/core/re3.cpp index cc3e93cb..06621cf0 100644 --- a/src/core/re3.cpp +++ b/src/core/re3.cpp @@ -767,7 +767,7 @@ extern bool gbRenderDebugEnvMap; "A Date with Death (Toshiko Kasen)", "Cash in Kazuki's Chips (Toshiko Kasen)" }; - missionEntry = DebugMenuAddVar("Debug", "Select mission", &nextMissionToSwitch, nil, 1, 0, 96, missions); + missionEntry = DebugMenuAddVar("Debug", "Select mission", &nextMissionToSwitch, nil, 1, 0, ARRAY_SIZE(missions) - 1, missions); DebugMenuEntrySetWrap(missionEntry, true); DebugMenuAddCmd("Debug", "Start selected mission ", SwitchToMission); #endif diff --git a/src/vehicles/Bike.cpp b/src/vehicles/Bike.cpp index 7b6787c7..6ad59769 100644 --- a/src/vehicles/Bike.cpp +++ b/src/vehicles/Bike.cpp @@ -79,6 +79,7 @@ CBike::CBike(int32 id, uint8 CreatedBy) m_bikeAnimType = ASSOCGRP_BIKE_STANDARD; break; case MI_SANCHEZ: + case MI_SANCHEZ2: m_bikeAnimType = ASSOCGRP_BIKE_DIRT; break; default: m_bikeAnimType = ASSOCGRP_BIKE_STANDARD; //assert(0 && "invalid bike model ID"); // TODO