Merge pull request #631 from erorcun/miami

Peds, mission switcher & fixes
This commit is contained in:
erorcun 2020-06-14 22:59:02 +03:00 committed by GitHub
commit f64d3ad7de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 838 additions and 186 deletions

View File

@ -166,6 +166,9 @@ bool doingMissionRetry;
#endif #endif
#ifdef MISSION_SWITCHER
int switchMissionTo = -1;
#endif
const uint32 CRunningScript::nSaveStructSize = const uint32 CRunningScript::nSaveStructSize =
#ifdef COMPATIBLE_SAVES #ifdef COMPATIBLE_SAVES
@ -886,10 +889,18 @@ void CRunningScript::Process()
int8 CRunningScript::ProcessOneCommand() int8 CRunningScript::ProcessOneCommand()
{ {
++CTheScripts::CommandsExecuted; int32 command;
int32 command = CTheScripts::Read2BytesFromScript(&m_nIp); #ifdef MISSION_SWITCHER
m_bNotFlag = (command & 0x8000); if (switchMissionTo != -1)
command &= 0x7FFF; command = COMMAND_LOAD_AND_LAUNCH_MISSION_INTERNAL;
else
#endif
{
++CTheScripts::CommandsExecuted;
command = CTheScripts::Read2BytesFromScript(&m_nIp);
m_bNotFlag = (command & 0x8000);
command &= 0x7FFF;
}
if (command < 100) if (command < 100)
return ProcessCommands0To99(command); return ProcessCommands0To99(command);
if (command < 200) if (command < 200)
@ -2032,7 +2043,13 @@ int8 CRunningScript::ProcessCommands100To199(int32 command)
ped->ClearAll(); ped->ClearAll();
int8 path = ScriptParams[1]; int8 path = ScriptParams[1];
if (ScriptParams[1] < 0 || ScriptParams[1] > 7) if (ScriptParams[1] < 0 || ScriptParams[1] > 7)
// Max number GetRandomNumberInRange returns is max-1
#ifdef FIX_BUGS
path = CGeneral::GetRandomNumberInRange(0, 8);
#else
path = CGeneral::GetRandomNumberInRange(0, 7); path = CGeneral::GetRandomNumberInRange(0, 7);
#endif
ped->SetWanderPath(path); ped->SetWanderPath(path);
return 0; return 0;
} }
@ -2051,10 +2068,11 @@ int8 CRunningScript::ProcessCommands100To199(int32 command)
eMoveState state; eMoveState state;
switch (ScriptParams[5]) { switch (ScriptParams[5]) {
case 0: state = PEDMOVE_WALK; break; case 0: state = PEDMOVE_WALK; break;
case 1: state = PEDMOVE_SPRINT; break; case 1: state = PEDMOVE_RUN; break;
default: assert(0); default: assert(0);
} }
ped->ClearAll(); ped->ClearAll();
ped->m_pathNodeTimer = 0;
ped->SetFollowPath(pos, radius, state, nil, nil, 999999); ped->SetFollowPath(pos, radius, state, nil, nil, 999999);
return 0; return 0;
} }
@ -9125,7 +9143,14 @@ int8 CRunningScript::ProcessCommands1000To1099(int32 command)
return 0; return 0;
case COMMAND_LOAD_AND_LAUNCH_MISSION_INTERNAL: case COMMAND_LOAD_AND_LAUNCH_MISSION_INTERNAL:
{ {
#ifdef MISSION_SWITCHER
if (switchMissionTo != -1) {
ScriptParams[0] = switchMissionTo;
switchMissionTo = -1;
} else
#endif
CollectParameters(&m_nIp, 1); CollectParameters(&m_nIp, 1);
if (CTheScripts::NumberOfExclusiveMissionScripts > 0 && ScriptParams[0] <= UINT16_MAX - 2) if (CTheScripts::NumberOfExclusiveMissionScripts > 0 && ScriptParams[0] <= UINT16_MAX - 2)
return 0; return 0;
#ifdef MISSION_REPLAY #ifdef MISSION_REPLAY
@ -10676,7 +10701,7 @@ int8 CRunningScript::ProcessCommands1200To1299(int32 command)
CPed* pTargetPed = CPools::GetPedPool()->GetAt(ScriptParams[1]); CPed* pTargetPed = CPools::GetPedPool()->GetAt(ScriptParams[1]);
assert(pTargetPed); assert(pTargetPed);
pPed->bScriptObjectiveCompleted = false; pPed->bScriptObjectiveCompleted = false;
pPed->SetObjective(OBJECTIVE_GOTO_CHAR_ON_FOOT_WALKING, pPed); pPed->SetObjective(OBJECTIVE_GOTO_CHAR_ON_FOOT_WALKING, pTargetPed);
return 0; return 0;
} }
//case COMMAND_IS_PICKUP_IN_ZONE: //case COMMAND_IS_PICKUP_IN_ZONE:
@ -14220,7 +14245,7 @@ void CTheScripts::CleanUpThisPed(CPed* pPed)
pPed->CharCreatedBy = RANDOM_CHAR; pPed->CharCreatedBy = RANDOM_CHAR;
if (pPed->m_nPedType == PEDTYPE_PROSTITUTE) if (pPed->m_nPedType == PEDTYPE_PROSTITUTE)
pPed->m_objectiveTimer = CTimer::GetTimeInMilliseconds() + 30000; pPed->m_objectiveTimer = CTimer::GetTimeInMilliseconds() + 30000;
if (pPed->bInVehicle) { if (pPed->InVehicle()) {
if (pPed->m_pMyVehicle->pDriver == pPed) { if (pPed->m_pMyVehicle->pDriver == pPed) {
if (pPed->m_pMyVehicle->m_vehType == VEHICLE_TYPE_CAR) { if (pPed->m_pMyVehicle->m_vehType == VEHICLE_TYPE_CAR) {
CCarCtrl::JoinCarWithRoadSystem(pPed->m_pMyVehicle); CCarCtrl::JoinCarWithRoadSystem(pPed->m_pMyVehicle);
@ -14245,10 +14270,14 @@ void CTheScripts::CleanUpThisPed(CPed* pPed)
pPed->ClearObjective(); pPed->ClearObjective();
pPed->bRespondsToThreats = true; pPed->bRespondsToThreats = true;
pPed->bScriptObjectiveCompleted = false; pPed->bScriptObjectiveCompleted = false;
pPed->bKindaStayInSamePlace = false;
pPed->ClearLeader(); pPed->ClearLeader();
if (pPed->IsPedInControl()) if (pPed->IsPedInControl())
pPed->SetWanderPath(CGeneral::GetRandomNumber() & 7); pPed->SetWanderPath(CGeneral::GetRandomNumber() & 7);
if (flees) { if (flees) {
if (pPed->m_nPedState == PED_FOLLOW_PATH && state != PED_FOLLOW_PATH)
pPed->ClearFollowPath();
pPed->m_nPedState = state; pPed->m_nPedState = state;
pPed->SetMoveState(ms); pPed->SetMoveState(ms);
} }

View File

@ -545,4 +545,8 @@ void RetryMission(int, int);
#ifdef USE_DEBUG_SCRIPT_LOADER #ifdef USE_DEBUG_SCRIPT_LOADER
extern int scriptToLoad; extern int scriptToLoad;
#endif
#ifdef MISSION_SWITCHER
extern int switchMissionTo;
#endif #endif

View File

@ -1801,6 +1801,21 @@ CColSphere::Set(float radius, const CVector &center, uint8 surf, uint8 piece)
this->piece = piece; this->piece = piece;
} }
bool
CColSphere::IntersectRay(CVector const& from, CVector const& dir, CVector &entry, CVector &exit)
{
CVector distToCenter = from - center;
float distToTouchSqr = distToCenter.MagnitudeSqr() - sq(radius);
float root1, root2;
if (!CGeneral::SolveQuadratic(1.0f, DotProduct(distToCenter, dir) * 2.f, distToTouchSqr, root1, root2))
return false;
entry = from + dir * root1;
exit = from + dir * root2;
return true;
}
void void
CColBox::Set(const CVector &min, const CVector &max, uint8 surf, uint8 piece) CColBox::Set(const CVector &min, const CVector &max, uint8 surf, uint8 piece)
{ {

View File

@ -31,6 +31,7 @@ struct CColSphere : public CSphere
uint8 piece; uint8 piece;
void Set(float radius, const CVector &center, uint8 surf, uint8 piece); void Set(float radius, const CVector &center, uint8 surf, uint8 piece);
bool IntersectRay(CVector const &from, CVector const &dir, CVector &entry, CVector &exit);
using CSphere::Set; using CSphere::Set;
}; };

View File

@ -134,6 +134,18 @@ public:
return *str2 != '\0'; return *str2 != '\0';
} }
static bool SolveQuadratic(float a, float b, float c, float &root1, float &root2)
{
float discriminant = b * b - 4.f * a * c;
if (discriminant < 0.f)
return false;
float discriminantSqrt = Sqrt(discriminant);
root2 = (-b + discriminantSqrt) / (2.f * a);
root1 = (-b - discriminantSqrt) / (2.f * a);
return true;
}
// not too sure about all these... // not too sure about all these...
static uint16 GetRandomNumber(void) static uint16 GetRandomNumber(void)
{ return myrand() & MYRAND_MAX; } { return myrand() & MYRAND_MAX; }

View File

@ -202,12 +202,11 @@ enum Config {
#define COMPATIBLE_SAVES // this allows changing structs while keeping saves compatible #define COMPATIBLE_SAVES // this allows changing structs while keeping saves compatible
#define FIX_HIGH_FPS_BUGS_ON_FRONTEND #define FIX_HIGH_FPS_BUGS_ON_FRONTEND
// Rendering/display
#define ASPECT_RATIO_SCALE // Not just makes everything scale with aspect ratio, also adds support for all aspect ratios
// Just debug menu entries // Just debug menu entries
#ifdef DEBUGMENU #ifdef DEBUGMENU
#define TOGGLEABLE_BETA_FEATURES // not too many things #define TOGGLEABLE_BETA_FEATURES // not too many things
#define RELOADABLES // some debug menu options to reload TXD files #define RELOADABLES // some debug menu options to reload TXD files
#define MISSION_SWITCHER // from debug menu
#endif #endif
// Rendering/display // Rendering/display

View File

@ -31,6 +31,7 @@
#include "Text.h" #include "Text.h"
#include "WaterLevel.h" #include "WaterLevel.h"
#include "main.h" #include "main.h"
#include "Script.h"
#ifndef _WIN32 #ifndef _WIN32
#include "assert.h" #include "assert.h"
@ -309,6 +310,15 @@ ResetCamStatics(void)
TheCamera.Cams[TheCamera.ActiveCam].ResetStatics = true; TheCamera.Cams[TheCamera.ActiveCam].ResetStatics = true;
} }
#ifdef MISSION_SWITCHER
int8 nextMissionToSwitch = 0;
static void
SwitchToMission(void)
{
switchMissionTo = nextMissionToSwitch;
}
#endif
static const char *carnames[] = { static const char *carnames[] = {
"landstal", "idaho", "stinger", "linerun", "peren", "sentinel", "rio", "firetruk", "trash", "stretch", "manana", "landstal", "idaho", "stinger", "linerun", "peren", "sentinel", "rio", "firetruk", "trash", "stretch", "manana",
"infernus", "voodoo", "pony", "mule", "cheetah", "ambulan", "fbicar", "moonbeam", "esperant", "taxi", "washing", "infernus", "voodoo", "pony", "mule", "cheetah", "ambulan", "fbicar", "moonbeam", "esperant", "taxi", "washing",
@ -512,7 +522,10 @@ DebugMenuPopulate(void)
#ifdef TIMEBARS #ifdef TIMEBARS
DebugMenuAddVarBool8("Debug", "Show Timebars", &gbShowTimebars, nil); DebugMenuAddVarBool8("Debug", "Show Timebars", &gbShowTimebars, nil);
#endif #endif
#ifdef MISSION_SWITCHER
DebugMenuAddInt8("Debug", "Select mission no", &nextMissionToSwitch, nil, 1, 0, 96, nil);
DebugMenuAddCmd("Debug", "Start selected mission ", SwitchToMission);
#endif
extern bool PrintDebugCode; extern bool PrintDebugCode;
extern int16 DebugCamMode; extern int16 DebugCamMode;
DebugMenuAddVarBool8("Cam", "Use mouse Cam", &CCamera::m_bUseMouse3rdPerson, nil); DebugMenuAddVarBool8("Cam", "Use mouse Cam", &CCamera::m_bUseMouse3rdPerson, nil);

File diff suppressed because it is too large Load Diff

View File

@ -10,11 +10,11 @@
#include "Weapon.h" #include "Weapon.h"
#include "WeaponInfo.h" #include "WeaponInfo.h"
#include "AnimationId.h" #include "AnimationId.h"
#include "PathFind.h"
#define FEET_OFFSET 1.04f #define FEET_OFFSET 1.04f
#define CHECK_NEARBY_THINGS_MAX_DIST 15.0f #define CHECK_NEARBY_THINGS_MAX_DIST 15.0f
struct CPathNode;
class CAccident; class CAccident;
class CObject; class CObject;
class CFire; class CFire;
@ -346,6 +346,9 @@ enum eMoveState {
PEDMOVE_NONE, PEDMOVE_NONE,
PEDMOVE_STILL, PEDMOVE_STILL,
PEDMOVE_WALK, PEDMOVE_WALK,
PEDMOVE_UNK,
PEDMOVE_RUN, PEDMOVE_RUN,
PEDMOVE_SPRINT, PEDMOVE_SPRINT,
}; };
@ -521,13 +524,20 @@ public:
int32 m_nPrevMoveState; int32 m_nPrevMoveState;
eWaitState m_nWaitState; eWaitState m_nWaitState;
uint32 m_nWaitTimer; uint32 m_nWaitTimer;
void *m_pPathNodesStates[8]; // unused, probably leftover from VC CPathNode* m_pathNodesToGo[8];
CVector2D m_stPathNodeStates[10]; int16 m_nNumPathNodes;
uint16 m_nPathNodes; int16 m_nCurPathNodeId;
int16 m_nCurPathNode; CEntity* m_followPathWalkAroundEnt;
int8 m_nPathDir; CEntity* m_followPathTargetEnt;
CPathNode *m_pLastPathNode; uint32 m_pathNodeTimer;
CPathNode *m_pNextPathNode; CPathNode m_pathNodeObjPool[8];
CPathNode* m_pCurPathNode;
char m_nPathDir;
CPathNode* m_pLastPathNode;
CPathNode* m_pNextPathNode;
CVector m_followPathDestPos;
float m_followPathAbortDist;
eMoveState m_followPathMoveState;
float m_fHealth; float m_fHealth;
float m_fArmour; float m_fArmour;
uint32 m_nExtendedRangeTimer; uint32 m_nExtendedRangeTimer;
@ -756,6 +766,7 @@ public:
void RemoveInCarAnims(void); void RemoveInCarAnims(void);
void CollideWithPed(CPed*); void CollideWithPed(CPed*);
void SetDirectionToWalkAroundObject(CEntity*); void SetDirectionToWalkAroundObject(CEntity*);
bool SetDirectionToWalkAroundVehicle(CVehicle*);
void RemoveWeaponAnims(int, float); void RemoveWeaponAnims(int, float);
void CreateDeadPedMoney(void); void CreateDeadPedMoney(void);
void CreateDeadPedWeaponPickups(void); void CreateDeadPedWeaponPickups(void);
@ -778,7 +789,7 @@ public:
bool FindBestCoordsFromNodes(CVector, CVector*); bool FindBestCoordsFromNodes(CVector, CVector*);
void Wait(void); void Wait(void);
void ProcessObjective(void); void ProcessObjective(void);
bool SeekFollowingPath(CVector*); CVector *SeekFollowingPath(void);
void Flee(void); void Flee(void);
void FollowPath(void); void FollowPath(void);
CVector GetFormationPosition(void); CVector GetFormationPosition(void);

View File

@ -4,47 +4,65 @@
#include "General.h" #include "General.h"
#include "Ped.h" #include "Ped.h"
// --MIAMI: Done
// Corresponds to ped sounds (from SOUND_PED_DEATH to SOUND_PED_TAXI_CALL) // Corresponds to ped sounds (from SOUND_PED_DEATH to SOUND_PED_TAXI_CALL)
PedAudioData CommentWaitTime[39] = { PedAudioData CommentWaitTime[56] = {
{500, 800, 500, 2}, { 500, 800, 500, 2 },
{500, 800, 500, 2}, { 500, 800, 500, 2 },
{500, 800, 500, 2}, { 500, 800, 500, 2 },
{500, 800, 500, 2}, { 500, 800, 500, 2 },
{100, 2, 100, 2}, { 100, 2, 100, 2 },
{700, 500, 1000, 500}, { 500, 500, 2000, 1000 },
{700, 500, 1000, 500}, { 2000, 50, 2050, 1000 },
{5000, 2000, 15000, 3000}, { 5000, 2000, 7000, 3000 },
{5000, 2000, 15000, 3000}, { 5000, 2000, 7000, 3000 },
{5000, 2000, 15000, 3000}, { 300, 200, 500, 200 },
{6000, 6000, 6000, 6000}, { 3000, 1000, 4000, 1000 },
{1000, 1000, 2000, 2000}, { 6000, 6000, 6000, 6000 },
{1000, 500, 2000, 1500}, { 4000, 1000, 5000, 1000 },
{1000, 500, 2000, 1500}, { 3000, 1000, 4000, 1000 },
{800, 200, 1000, 500}, { 1000, 1000, 2000, 2000 },
{800, 200, 1000, 500}, { 1000, 500, 2000, 1500 },
{800, 400, 2000, 1000}, { 1700, 1000, 3000, 1000 },
{800, 400, 2000, 1000}, { 800, 200, 1000, 500 },
{400, 300, 2000, 1000}, { 800, 200, 1000, 500 },
{2000, 1000, 2500, 1500}, { 800, 400, 2000, 1000 },
{200, 200, 200, 200}, { 800, 400, 2000, 1000 },
{6000, 3000, 5000, 6000}, { 2000, 2000, 4000, 4000 },
{6000, 3000, 9000, 5000}, { 2000, 2000, 4000, 1000 },
{6000, 3000, 9000, 5000}, { 4000, 1000, 5000, 1000 },
{6000, 3000, 9000, 5000}, { 800, 400, 1200, 500 },
{400, 300, 4000, 1000}, { 5000, 1000, 6000, 2000 },
{400, 300, 4000, 1000}, { 5000, 1000, 6000, 2000 },
{400, 300, 4000, 1000}, { 5000, 1000, 6000, 2000 },
{1000, 500, 3000, 1000}, { 5000, 1000, 6000, 2000 },
{1000, 500, 1000, 1000}, { 5000, 1000, 6000, 2000 },
{3000, 2000, 3000, 2000}, { 5000, 1000, 6000, 2000 },
{1000, 500, 3000, 6000}, { 5000, 1000, 6000, 2000 },
{1000, 500, 2000, 4000}, { 4000, 2000, 7000, 2000 },
{1000, 500, 2000, 5000}, { 1000, 300, 2000, 1000 },
{1000, 500, 3000, 2000}, { 1500, 1000, 2500, 1000 },
{1600, 1000, 2000, 2000}, { 200, 200, 200, 200 },
{3000, 2000, 5000, 3000}, { 2000, 1000, 4000, 1000 },
{1000, 1000, 1000, 1000}, { 2000, 1000, 4000, 1000 },
{1000, 1000, 5000, 5000}, { 1000, 500, 3000, 1000 },
{ 1000, 500, 1000, 1000 },
{ 3000, 2000, 5000, 1000 },
{ 3000, 2000, 5000, 1000 },
{ 3000, 2000, 3000, 2000 },
{ 2000, 1000, 3000, 1000 },
{ 2500, 1000, 5000, 5000 },
{ 2000, 1000, 3000, 2000 },
{ 4000, 1000, 5000, 1000 },
{ 1000, 500, 2000, 4000 },
{ 1000, 500, 2000, 5000 },
{ 2000, 500, 2500, 500 },
{ 1000, 500, 3000, 2000 },
{ 1600, 1000, 2000, 2000 },
{ 2000, 1000, 4000, 2000 },
{ 1500, 1000, 2500, 1000 },
{ 1000, 1000, 5000, 5000 },
{ 0, 0, 0, 0 }
}; };
// --MIAMI: Done // --MIAMI: Done
@ -54,7 +72,7 @@ CPed::ServiceTalkingWhenDead(void)
return m_queuedSound == SOUND_PED_DEATH; return m_queuedSound == SOUND_PED_DEATH;
} }
// --MIAMI: Done except ifdef // --MIAMI: Done
void void
CPed::ServiceTalking(void) CPed::ServiceTalking(void)
{ {
@ -84,7 +102,7 @@ CPed::ServiceTalking(void)
} }
} }
// --MIAMI: Done except ifdef // --MIAMI: Done
void void
CPed::Say(uint16 audio) CPed::Say(uint16 audio)
{ {