diff --git a/code/midtown/mmai/aiGoalChase.cpp b/code/midtown/mmai/aiGoalChase.cpp index c4c2b916..be3b95b7 100644 --- a/code/midtown/mmai/aiGoalChase.cpp +++ b/code/midtown/mmai/aiGoalChase.cpp @@ -22,6 +22,10 @@ define_dummy_symbol(mmai_aiGoalChase); #include "arts7/sim.h" +#include "aiMap.h" +#include "aiPath.h" +#include "aiVehiclePolice.h" + static mem::cmd_param PARAM_speedycops {"speedycops"}; static f32 CopSpeedBoost = 1.0f; @@ -66,4 +70,104 @@ hook_func(FRAME_pre_update, [] { CopSteerBoost1 = std::pow(0.5f, exp); CopSteerBoost2 = std::pow(0.85f, exp); -}); \ No newline at end of file +}); + +b32 aiGoalChase::Collision(mmCar* perp) +{ + return perp->Sim.HasCollided; +} + +void aiGoalChase::Dump() +{ + Displayf("PerpMapCompIdx: %d", PerpMapCompIdx); + Displayf("PerpMapCompType: %d", PerpMapCompType); + Displayf("PerpRdVertIdx: %d", PerpRdVertIdx); + Displayf("PerpCullRoom: %d", PerpCullRoom); + Displayf("PerpRoadDist: %f", PerpRoadDist); + Displayf("PerpDistToSide: %f", PerpDistToSide); + Displayf("CurMapCompIdx: %d", CurMapCompIdx); + Displayf("PrevMapCompIdx: %d", PrevMapCompIdx); + Displayf("CurMapCompType: %d", CurMapCompType); + Displayf("PrevMapCompType: %d", PrevMapCompType); + Displayf("CurRdVertIdx: %d", CurRdVertIdx); + Displayf("CurCullRoom: %d", CurCullRoom); + Displayf("ForwardDist: %f", ForwardDist); + Displayf("SideDist: %f", SideDist); + Displayf("TargetOffset: %f", TargetOffset); + Displayf("ApprehendState: %d", ApprehendState); + Displayf("State: %d", State); + Displayf("LastState: %d", LastState); + Displayf("StartedChase: %d", StartedChase); + Displayf("Angle: %f", Angle); + Displayf("SteerVal: %f", SteerVal); + Displayf("SeparationDist: %f", SeparationDist); + Displayf("RotAngle: %f", RotAngle); + Displayf("Throttle: %f", Throttle); + Displayf("Brake: %f", Brake); + Displayf("Dist2Perp: %f", Dist2Perp); + Displayf("DistToSide: %f", DistToSide); + Displayf("WaitTime: %f", WaitTime); + Displayf("Offset: %f", Offset); + Displayf("NumBehaviors: %d", NumBehaviors); + Displayf("NumCloseObs: %d", NumCloseObs); + Displayf("NumFarObs: %d", NumFarObs); +} + +void aiGoalChase::Follow() +{ + if (Dist2Perp <= 20.0f) + { + CalcSpeed(AIMAP.PlayerCar->Sim.Speed); + } + else + { + CalcSpeed(AIMAP.PlayerCar->Sim.Speed + 10.0f); + } + + f32 path_center_length = RailSet->CurLink->CenterLength(1, RailSet->CurLink->VertexCount - 2); + + if (CurMapCompIdx != PerpMapCompIdx || CurMapCompType != 1 || path_center_length - 30.0f <= PerpRoadDist) + { + Offset = DistToSide; + } + else + { + f32 lane_width = RailSet->CurLink->LaneWidths[2 * RailSet->CurLink->NumLanes + 4] - RailSet->RSideDist - 1.5f; + + if (PerpDistToSide <= -lane_width) + { + Offset = -lane_width; + } + else if (PerpDistToSide < lane_width) + { + Offset = PerpDistToSide; + } + else + { + Offset = lane_width; + } + } + + RailSet->CalcCopRailPosition(*TargetPos, PoliceCar->Sim.ICS.Matrix.m3, TargetOffset + RailSet->RoadDist, Offset); + TargetPos->y = PoliceCar->Sim.ICS.Matrix.m3.y; +} + +b32 aiGoalChase::Priority() +{ + return true; +} + +b32 aiGoalChase::Speeding(mmCar* perp) +{ + f32 speed_limit = 40.0f; + + if (RailSet->CurLink->NumLanes == 4) + speed_limit = 70.0f; + + return perp->Sim.Speed * 2.2360249 > speed_limit; +} + +b32 aiGoalChase::Stopped(mmCar* perp) +{ + return perp->Sim.Speed < 1.0f; +} diff --git a/code/midtown/mmai/aiGoalChase.h b/code/midtown/mmai/aiGoalChase.h index 54ee4e5f..d164fbd0 100644 --- a/code/midtown/mmai/aiGoalChase.h +++ b/code/midtown/mmai/aiGoalChase.h @@ -58,6 +58,8 @@ */ #include "aiGoal.h" +#include "aiPoliceForce.h" +#include "aiStuck.h" class aiVehiclePolice; @@ -71,16 +73,16 @@ class aiGoalChase final : public aiGoal ARTS_IMPORT ~aiGoalChase(); // ?Context@aiGoalChase@@UAEHXZ - ARTS_IMPORT b32 Context() override; + ARTS_IMPORT i32 Context() override; // ?Dump@aiGoalChase@@QAEXXZ - ARTS_IMPORT void Dump(); + ARTS_EXPORT void Dump(); // ?Init@aiGoalChase@@UAEXXZ ARTS_IMPORT void Init() override; // ?Priority@aiGoalChase@@UAEHXZ - ARTS_IMPORT i32 Priority() override; + ARTS_EXPORT b32 Priority() override; // ?Reset@aiGoalChase@@UAEXXZ ARTS_IMPORT void Reset() override; @@ -114,7 +116,7 @@ class aiGoalChase final : public aiGoal ARTS_IMPORT void CloseInRoad(); // ?Collision@aiGoalChase@@AAEHPAVmmCar@@@Z - ARTS_IMPORT i32 Collision(mmCar* arg1); + ARTS_EXPORT b32 Collision(mmCar* perp); // ?DetectAmbientCollision@aiGoalChase@@AAEHPAH@Z ARTS_IMPORT i32 DetectAmbientCollision(i32* arg1); @@ -126,7 +128,7 @@ class aiGoalChase final : public aiGoal ARTS_IMPORT i32 FindPerp(i32 arg1, i32 arg2, aiPath* arg3); // ?Follow@aiGoalChase@@AAEXXZ - ARTS_IMPORT void Follow(); + ARTS_EXPORT void Follow(); // ?Fov@aiGoalChase@@AAEHPAVmmCar@@@Z ARTS_IMPORT i32 Fov(mmCar* arg1); @@ -156,12 +158,62 @@ class aiGoalChase final : public aiGoal ARTS_IMPORT void Push(); // ?Speeding@aiGoalChase@@AAEHPAVmmCar@@@Z - ARTS_IMPORT i32 Speeding(mmCar* arg1); + ARTS_EXPORT b32 Speeding(mmCar* perp); // ?Stopped@aiGoalChase@@AAEHPAVmmCar@@@Z - ARTS_IMPORT i32 Stopped(mmCar* arg1); + ARTS_EXPORT b32 Stopped(mmCar* perp); - u8 gap8[0x1A4]; +public: + aiVehiclePolice* PoliceVehicle; + aiRailSet* RailSet; + mmCar* PoliceCar; + mmCar* TargetCar; + aiPoliceForce* PoliceForce; + aiStuck Stuck; + Vector3* TargetPos; + Timer WaitTimer; + i16 PerpMapCompIdx; + i16 PerpMapCompType; + i16 PerpRdVertIdx; + i16 PerpCullRoom; + f32 PerpRoadDist; + f32 PerpDistToSide; + i16 CurMapCompIdx; + i16 PrevMapCompIdx; + i16 CurMapCompType; + i16 PrevMapCompType; + i16 CurRdVertIdx; + i16 CurCullRoom; + f32 ForwardDist; + f32 SideDist; + f32 TargetOffset; + i16 ApprehendState; + i16 State; + i32* StopId; + i16* TargetPt; + i16 LastState; + b16 StartedChase; + f32 Angle; + f32 SteerVal; + f32 SeparationDist; + f32 RotAngle; + f32 Throttle; + f32 Brake; + f32 Dist2Perp; + f32 DistToSide; + f32 WaitTime; + f32 Offset; + i16 NumBehaviors; + i16 BehaviourStates[4]; + i16 NumCloseObs; + i16 NumFarObs; + u16 field_EA; + i32 field_EC; + i32 field_F0; + char _field_F4[0xAC]; + i32 field_1A0; + i32 field_1A4; + i32 field_1A8; }; check_size(aiGoalChase, 0x1AC); diff --git a/code/midtown/mmai/aiStuck.h b/code/midtown/mmai/aiStuck.h index 957865c4..4cfdd505 100644 --- a/code/midtown/mmai/aiStuck.h +++ b/code/midtown/mmai/aiStuck.h @@ -36,6 +36,8 @@ #include "arts7/node.h" +#include "vector7/vector3.h" + class mmCarSim; class aiStuck final : public asNode @@ -69,7 +71,18 @@ class aiStuck final : public asNode // ?Update@aiStuck@@UAEXXZ ARTS_IMPORT void Update() override; - u8 gap20[0x38]; + i32 State; + i32 Impacted; + i32 field_28; + Vector3 field_2C; + i32 TimeThresh; + i32 PosThresh; + i32 MoveThresh; + i32 PosThreshSqr; + i32 MoveThreshSqr; + i32 RotAmount; + i32* ICS; + mmCarSim* CarSim; }; check_size(aiStuck, 0x58);