Skip to content

Commit

Permalink
Implemented aiVehicleOpponent::Update (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
KcRobin9 authored Jun 19, 2024
1 parent e8018e3 commit bb6ac76
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
37 changes: 37 additions & 0 deletions code/midtown/mmai/aiVehicleOpponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,20 @@ define_dummy_symbol(mmai_aiVehicleOpponent);
#include "agi/getdlp.h"
#include "agiworld/quality.h"
#include "data7/str.h"
#include "memory/allocator.h"
#include "mmcar/trailer.h"
#include "mmcity/cullcity.h"
#include "mmcityinfo/vehlist.h"
#include "mmphysics/joint3dof.h"
#include "mmphysics/phys.h"

#include "aiData.h"
#include "aiGoalBackup.h"
#include "aiGoalFollowWayPts.h"
#include "aiGoalStop.h"
#include "aiMap.h"

static mem::cmd_param PARAM_detachopptrailermph {"detachopptrailermph"};
static mem::cmd_param PARAM_maxoppcolors {"maxoppcolors"};

void aiVehicleOpponent::DrawDamage()
Expand Down Expand Up @@ -76,3 +83,33 @@ void aiVehicleOpponent::Init(i32 opp_id, aiRaceData* race_data, char* race_name)

AudIndexNumber = -1;
}

void aiVehicleOpponent::Update()
{
if (AudIndexNumber == -1)
AddToAiAudMgr();

if (IsSemi || Car.Sim.ICS.Matrix.m3.Dist2(AIMAP.PlayerPos()) < (200.0f * 200.0f))
PHYS.DeclareMover(
&Car.Model, MOVER_TYPE_PERM, MOVER_FLAG_ACTIVE | MOVER_FLAG_COLLIDE_TERRAIN | MOVER_FLAG_COLLIDE_MOVERS);
else
PHYS.DeclareMover(&Car.Model, MOVER_TYPE_PERM,
(CullCity()->GetRoomFlags(Car.Model.ChainId) & INST_FLAG_100)
? MOVER_FLAG_ACTIVE | MOVER_FLAG_COLLIDE_TERRAIN | MOVER_FLAG_COLLIDE_MOVERS
: MOVER_FLAG_ACTIVE | MOVER_FLAG_COLLIDE_TERRAIN | MOVER_FLAG_20);

if (Car.Model.HasTrailer())
PHYS.DeclareMover(&Car.Trailer->Inst, MOVER_TYPE_PERM, MOVER_FLAG_COLLIDE_TERRAIN | MOVER_FLAG_COLLIDE_MOVERS);

if (Car.Sim.HasCollided)
if (Car.Sim.SpeedMPH > PARAM_detachopptrailermph.get_or(50.0f) && !Car.TrailerJoint->IsBroken())
Car.ReleaseTrailer();

ALLOCATOR.CheckPointer(WayPts.get());
ALLOCATOR.CheckPointer(BackupGoal.get());
ALLOCATOR.CheckPointer(StopGoal.get());
aiVehicle::Update();
ALLOCATOR.CheckPointer(WayPts.get());
ALLOCATOR.CheckPointer(BackupGoal.get());
ALLOCATOR.CheckPointer(StopGoal.get());
}
2 changes: 1 addition & 1 deletion code/midtown/mmai/aiVehicleOpponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class aiVehicleOpponent final : public aiVehicle
ARTS_IMPORT void UnAssignSounds();

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

// ?UpdateAudio@aiVehicleOpponent@@QAEXXZ
ARTS_IMPORT void UpdateAudio();
Expand Down
5 changes: 5 additions & 0 deletions code/midtown/mmphysics/joint3dof.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ class Joint3Dof final : public JointedStruct
// ?DeclareFields@Joint3Dof@@SAXXZ
ARTS_IMPORT static void DeclareFields();

b32 IsBroken() const
{
return (JointFlags & JOINT_FLAG_BROKEN) != 0;
}

asInertialCS* ICS1;
asInertialCS* ICS2;
Vector3 Offset1;
Expand Down
1 change: 1 addition & 0 deletions docs/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ For a tutorial on how to use command line arguments, click [here](https://www.bl
| aiphysics | false | Sets AI-like physics midair
| allcars | false | Unlocks All Cars |
| allrace | false | Unlocks All Races |
| detachopptrailermph | 50 | Speed at which the opponent semi will detach its trailer
| maxcops | 3 | Max cops chasing you at once |
| nodamage | false | Disables Damage |
| maxoppcolors | auto | Cycles through the opponent car colors based on the number of paintjobs available |
Expand Down

0 comments on commit bb6ac76

Please sign in to comment.