Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1] aiGoalFollowWayPts::Update() #137

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 136 additions & 0 deletions code/midtown/mmai/aiGoalFollowWayPts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ define_dummy_symbol(mmai_aiGoalFollowWayPts);

#include "aiData.h"
#include "aiMap.h"
#include "aiPath.h"
#include "aiVehicleOpponent.h"

b32 aiGoalFollowWayPts::Context()
{
Expand Down Expand Up @@ -55,3 +57,137 @@ b32 aiGoalFollowWayPts::Context()
return false;
}
}

void aiGoalFollowWayPts::Update()
{
i16 unk_var1 = 0;
i32 unk_var2 = 1;

++UpdateCount;

if ((Car->Sim.ICS.Constraints & (ICS_CONSTRAIN_TX | ICS_CONSTRAIN_TZ)) != 0)
{
if (Car->Sim.FrontLeft.OnGround)
{
Car->Sim.Steering = 0.0f;
Car->Sim.Brakes = 0.0f;
Car->Sim.Engine.Throttle = 1.0f;
}
}
KcRobin9 marked this conversation as resolved.
Show resolved Hide resolved
else
{
Stuck.Update();

if (Car->Sim.Stuck.State == 2)
KcRobin9 marked this conversation as resolved.
Show resolved Hide resolved
{
PlanRoute();
*BackingUp = true;
Car->Sim.ICS.LinearMomentum = {0.0f, 0.0f, 0.0f};
Car->Sim.ICS.AngularMomentum = {0.0f, 0.0f, 0.0f};
UpdateCount = 0;
}
else if (Stuck.State == 2)
{
Car->Sim.Steering = 0.5f;
Car->Sim.Brakes = 0.0f;
Car->Sim.Engine.Throttle = 1.0f;
Car->Sim.Stuck.State = 0;
}
else
{
i16 road_segment_id;

if (WayPtIdx <= 1 || WayPtIdx >= NumWayPts - 1)
{
road_segment_id = -1;
}
else
{
i16 prev_wp_index = WayPtIdx - 1;

i32 prev_wp_id;
i32 cur_wp_id;

if (prev_wp_index < 0 || prev_wp_index > NumWayPts)
{
Warningf("Check Point Index: %d, is outside of the array bounds.", prev_wp_index);
Warningf("Requested by: Opp %d.", Vehicle->OppId);
prev_wp_id = WayPtIds[NumWayPts];
}
else
{
prev_wp_id = WayPtIds[prev_wp_index];
}
KcRobin9 marked this conversation as resolved.
Show resolved Hide resolved

if (WayPtIdx < 0 || WayPtIdx > NumWayPts)
{
Warningf("Check Point Index: %d, is outside of the array bounds.", WayPtIdx);
Warningf("Requested by: Opp %d.", Vehicle->OppId);
cur_wp_id = WayPtIds[NumWayPts];
}
else
{
cur_wp_id = WayPtIds[WayPtIdx];
}

road_segment_id =
DetRdSegBetweenInts(AIMAP.Intersection(prev_wp_id), AIMAP.Intersection(cur_wp_id))->Id;
}
LastMapCompType = road_segment_id;

CurMapCompIdx = AIMAP.DetermineOppMapComponent(Car->Sim.ICS.Matrix, Rail, &CurMapCompType, &CurRdVertIdx,
&Rail->RoadDist, &DistToSide, &unk_var1, &TargetPtOffset, Car->Sim.Speed, LastMapCompType,
road_segment_id);

PlanRoute();

if (Rail->NextLink)
{
Rail->NextLink->StopDestinationSources(1);
}

if (Vehicle->IsSemi || !DetectCollision(&unk_var2))
{
aiVehicleOpponent* collision_opp = DetectOpponentCollision();

if (collision_opp)
{
AvoidOpponentCollision(collision_opp);
}
else
{
SolveTargetPoint();
}
}
else
{
AvoidCollision(unk_var2);
}

Vector3 car_pos = Car->Sim.ICS.Matrix.m3;
Vector3 target_dir = {TargetPt.x - car_pos.x, TargetPt.y - car_pos.y, TargetPt.z - car_pos.z};
KcRobin9 marked this conversation as resolved.
Show resolved Hide resolved

f32 angle = atan2(target_dir ^ Car->Sim.ICS.Matrix.m0, target_dir ^ -Car->Sim.ICS.Matrix.m2);
KcRobin9 marked this conversation as resolved.
Show resolved Hide resolved

Steering = std::clamp(angle, -1.0f, 1.0f);

if (Car->Model.Flags & INST_FLAG_COLLIDED_PLAYER)
{
*(Car->Sim.Realism) = 1.0f;
KcRobin9 marked this conversation as resolved.
Show resolved Hide resolved
}
else
{
*(Car->Sim.Realism) = 0.0f;
KcRobin9 marked this conversation as resolved.
Show resolved Hide resolved

if (angle < 0.1f && angle > -0.1f)
{
Car->Sim.ICS.AngularMomentum *= 0.1f;
}
}
Car->Sim.Steering = Steering;
Car->Sim.Brakes = Brakes;
Car->Sim.Engine.Throttle = Throttle;
LastMapCompType = CurMapCompType;
}
}
}
10 changes: 9 additions & 1 deletion code/midtown/mmai/aiGoalFollowWayPts.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class aiGoalFollowWayPts final : public aiGoal
ARTS_IMPORT void Reset() override;

// ?Update@aiGoalFollowWayPts@@UAEXXZ
ARTS_IMPORT void Update() override;
ARTS_EXPORT void Update() override;

// ?DeclareFields@aiGoalFollowWayPts@@SAXXZ
ARTS_IMPORT static void DeclareFields();
Expand Down Expand Up @@ -143,7 +143,11 @@ class aiGoalFollowWayPts final : public aiGoal
aiPath* StartLink;
aiPath* LastLink;
aiPath* NLastLink;

public:
KcRobin9 marked this conversation as resolved.
Show resolved Hide resolved
Vector3 TargetPt;

private:
i16* WayPtIds;
b16* BackingUp;
b16* IsFinished;
Expand All @@ -159,10 +163,14 @@ class aiGoalFollowWayPts final : public aiGoal
i16 NumCloseObstacles;
i16 NumFarObstacles;
i16 DamageState;

public:
f32 Brakes;
f32 Throttle;
f32 Steering;
f32 DistToSide;

private:
f32 Offset;
f32 TargetPtOffset;
f32 MaxThrottle;
Expand Down
14 changes: 13 additions & 1 deletion code/midtown/mmai/aiStuck.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
*/

#include "arts7/node.h"
#include "vector7/vector3.h"

class mmCarSim;

Expand Down Expand Up @@ -69,7 +70,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);
6 changes: 5 additions & 1 deletion code/midtown/mmai/aiVehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
0x61BC40 | const aiVehicle::`vftable' | ??_7aiVehicle@@6B@
*/

#include "data7/list.h"

class aiVehicle
{
public:
Expand All @@ -51,7 +53,9 @@ class aiVehicle
// ?Init@aiVehicle@@QAEXH@Z
ARTS_IMPORT void Init(i32 arg1);

u8 gap4[0x10];
List Goals;
i16 OppId;
i16 UpdateGroup;
};

check_size(aiVehicle, 0x14);
2 changes: 1 addition & 1 deletion code/midtown/mmcity/inst.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ class mmInstance : public Base
#define INST_FLAG_TERRAIN 0x800
#define INST_FLAG_1000 0x1000 // mmBangerInstance::Draw - Increment lod
#define INST_FLAG_2000 0x2000 // Important shadows
#define INST_FLAG_4000 0x4000 // Collided with Player?
#define INST_FLAG_COLLIDED_PLAYER 0x4000

// INST_FLAG_*
u16 Flags {INST_FLAG_ACTIVE};
Expand Down