-
Notifications
You must be signed in to change notification settings - Fork 10
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
KcRobin9
wants to merge
5
commits into
0x1F9F1:master
Choose a base branch
from
KcRobin9:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9932117
[1] aiGoalFollowWayPts::Update()
KcRobin9 be27998
[2] aiGoalFollowWayPts::Update()
KcRobin9 0602712
[3] aiGoalFollowWayPts::Update()
KcRobin9 58b0208
[4] aiGoalFollowWayPts::Update()
KcRobin9 0088613
Update aiGoalFollowWayPts.cpp
KcRobin9 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,8 @@ define_dummy_symbol(mmai_aiGoalFollowWayPts); | |
|
||
#include "aiData.h" | ||
#include "aiMap.h" | ||
#include "aiPath.h" | ||
#include "aiVehicleOpponent.h" | ||
|
||
b32 aiGoalFollowWayPts::Context() | ||
{ | ||
|
@@ -55,3 +57,124 @@ b32 aiGoalFollowWayPts::Context() | |
return false; | ||
} | ||
} | ||
|
||
i32 aiGoalFollowWayPts::GetWayPtId(i16 index, i32 num_waypts) | ||
{ | ||
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this |
||
} | ||
} | ||
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,6 +58,10 @@ | |
|
||
class aiVehicleOpponent; | ||
|
||
#define CAR_NOT_STUCK 0 | ||
#define CAR_MAYBE_STUCK 1 | ||
#define CAR_STUCK 2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move these to the mmStuck header |
||
|
||
class aiGoalFollowWayPts final : public aiGoal | ||
{ | ||
public: | ||
|
@@ -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(); | ||
|
@@ -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; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 usingNumWayPts
directly?There was a problem hiding this comment.
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