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 3 commits
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
123 changes: 123 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,124 @@ b32 aiGoalFollowWayPts::Context()
return false;
}
}

i32 aiGoalFollowWayPts::GetWayPtId(i16 index, i32 num_waypts)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was there a reason for passing in num_waypts instead of using NumWayPts directly?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it was an oversight. I changed it now

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

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;
return;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this return should be outside the inner if

}
}
KcRobin9 marked this conversation as resolved.
Show resolved Hide resolved

Stuck.Update();

if (Car->Sim.Stuck.State == CAR_STUCK)
{
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 == CAR_STUCK)
{
Car->Sim.Steering = 0.5f;
Car->Sim.Brakes = 0.0f;
Car->Sim.Engine.Throttle = 1.0f;
Car->Sim.Stuck.State = CAR_NOT_STUCK;
}
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 = GetWayPtId(prev_wp_index, NumWayPts);
i32 cur_wp_id = GetWayPtId(WayPtIdx, NumWayPts);

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

LastMapCompType = road_segment_id;

CurMapCompIdx = static_cast<i16>(
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 target_dir = TargetPt - Car->Sim.ICS.Matrix.m3;

f32 angle = std::atan2(target_dir ^ Car->Sim.ICS.Matrix.m0, target_dir ^ -Car->Sim.ICS.Matrix.m2);

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

if (Car->Model.Flags & INST_FLAG_COLLIDED_PLAYER)
{
*Car->Sim.Realism = 1.0f;
}
else
{
*Car->Sim.Realism = 0.0f;

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;
}
}
9 changes: 8 additions & 1 deletion code/midtown/mmai/aiGoalFollowWayPts.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@

class aiVehicleOpponent;

#define CAR_NOT_STUCK 0
#define CAR_MAYBE_STUCK 1
#define CAR_STUCK 2
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move these to the mmStuck header


class aiGoalFollowWayPts final : public aiGoal
{
public:
Expand Down Expand Up @@ -96,7 +100,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 @@ -135,6 +139,9 @@ class aiGoalFollowWayPts final : public aiGoal
// ?SolveTargetPoint@aiGoalFollowWayPts@@AAEXXZ
ARTS_IMPORT void SolveTargetPoint();

i32 GetWayPtId(i16 index, i32 num_waypts);

public:
aiVehicleOpponent* Vehicle;
aiRailSet* Rail;
mmCar* Car;
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