Skip to content

Commit dc60b9d

Browse files
Ripper LOF check update and new collision function
- Made the ripper line of fire check in KAI_ProjectileLOFCheck not decrement its' rip depth if one of the actors that would be ripped by the projectile is an enemy of the shooter. - Added a new CheckTurretCollision() vehicle function, to be used in KAI_MoveTowards(). Right now it's untested and not used yet. - Removed some debug messages.
1 parent 954498c commit dc60b9d

File tree

6 files changed

+53
-29
lines changed

6 files changed

+53
-29
lines changed

ZScript/Bases/AIFunctions.zsc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ Extend Class KAI_Actor
134134
Vector3 ZigZagPos;
135135

136136
//Makes the actor move towards the specified actor.
137-
//FIXME: There's some flickering between different sprite angles, try fixing it.
137+
//TODO: Add a check for if a vehicles' turret would collide with the next move. And probably find a way to call it recursively for turrets on turrets.
138138
//CREDIT: Written by Custodian. Modified and expanded by me (inkoalawetrust).
139139
//Other: The actor to move to.
140140
//DetourFactor: How long the actor is allowed to move in a direction after hitting an obstacle, before heading straight for the target again.

ZScript/Bases/Base.zsc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,6 @@ Class KAI_BaseProjectile : FastProjectile
503503
//Estimate the travel time the projectile needs.
504504
If (Vel.Length() != 0)
505505
TravelTics = Distance3D (Tracer)/Vel.Length();
506-
//console.printf ("traveltics %.2f",traveltics);
507506
TravelTics = Clamp (TravelTics,1,INT.MAX); //Needs at least 1 tic.
508507
FloatTics = TravelTics; //Finer precision on multiplier the extrapolated velocity, for extra accuracy.
509508
Vector3 OldPos = Tracer.Pos;
@@ -520,8 +519,8 @@ Class KAI_BaseProjectile : FastProjectile
520519
Result = Level.Vec3Offset(Result,(FRandom(Inaccuracy.X,-Inaccuracy.X),FRandom(Inaccuracy.Y,-Inaccuracy.Y),FRandom(Inaccuracy.Z,-Inaccuracy.Z)));
521520
//console.printf ("the tracers' current trajectory is %d %d %d",pos);
522521
//console.printf ("the tracers' future trajectory is %d %d %d",result);
523-
FSpawnParticleParams P; P.Color1 = "White"; P.Style = STYLE_None; P.Lifetime = 1; P.Size = 4; P.StartAlpha = 1; P.FadeStep = -1; P.Flags = SPF_FULLBRIGHT;
524-
KAI_LOFRaycast.VisualizeTracePath(Pos,result,distance3d(tracer),8,p);
522+
//FSpawnParticleParams P; P.Color1 = "White"; P.Style = STYLE_None; P.Lifetime = 1; P.Size = 4; P.StartAlpha = 1; P.FadeStep = -1; P.Flags = SPF_FULLBRIGHT;
523+
//KAI_LOFRaycast.VisualizeTracePath(Pos,result,distance3d(tracer),8,p);
525524
Return Result;
526525
}
527526

ZScript/Bases/OtherCode.zsc

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,9 @@ Class KAI_ProjectileLOFCheck : KAI_LOFRaycast
625625
Return False;
626626
}
627627

628-
If (!CantRipActor (Who,ProjInfo.RipLevel,ProjInfo.NoBossRip))
628+
//Decrement the rip depth for the ripper LOF check. Unless the actor to be ripped is an enemy. That we can shoot anyway.
629+
//MAYDO: Add a flag in LOFProjInfo that ignores the enemy check ?
630+
If ((!IsHostile (Shooter,Who) || IsInanimateObject(Who)) && !CantRipActor (Who,ProjInfo.RipLevel,ProjInfo.NoBossRip))
629631
{
630632
If (ProjInfo.RipOnce && ProjInfo.RipDepth)
631633
ProjInfo.RipDepth--;
@@ -657,13 +659,13 @@ Class KAI_ProjectileLOFCheck : KAI_LOFRaycast
657659

658660
If (Mobj == Shooter.Master) Return Trace_Skip;
659661

660-
//The target is in the line of fire. Shoot them anyway.
661-
If (Other && Mobj == Other)
662+
//The target is in the line of fire. Or the Mobj is an enemy. Shoot them anyway.
663+
If (Other && Mobj == Other || !IsInanimateObject(Mobj) && IsHostile(Shooter,Mobj))
662664
Return Trace_Stop;
663665

664666
//If friendly fire prevention is on, return false if an ally is in the way.
665667
If (FriendlyFire && Mobj && !IsDead(Mobj) && IsCollidable (Mobj) && !IsInanimateObject(Mobj) && !IsHostile(Shooter,Mobj))
666-
{
668+
{//console.printf ("blue on blue !");
667669
BadLOF = True;
668670
Return Trace_Stop;
669671
}
@@ -672,43 +674,43 @@ Class KAI_ProjectileLOFCheck : KAI_LOFRaycast
672674

673675
//Indestructible prop in the way.
674676
If (Mobj && !OtherInBlast && IsCollidable (Mobj) && IsIndestructible (Mobj) && IsInanimateObject (Mobj))
675-
{
677+
{//console.printf ("invincible object in the way");
676678
BadLOF = True;
677679
Return Trace_Stop;
678680
}
679681

680682
//Destructible prop, but far too strong to shoot through in a timely manner.
681683
If (Mobj && !OtherInBlast && IsCollidable (Mobj) && !IsIndestructible(Mobj) && IsInanimateObject (Mobj) && !CanShootAtProp(Mobj,PropHealthThreshold))
682-
{
684+
{//console.printf("vincible object in the way, but too durable");
683685
BadLOF = True;
684686
Return Trace_Stop;
685687
}
686688

687689
//Solid corpse in the way, attack can't go through.
688690
Bool StopAtCorpse = !FriendlyFire ? IsHostile(Shooter,Mobj) : True;
689691
If (Mobj && !OtherInBlast && IsSolidCorpse(Mobj) && StopAtCorpse)
690-
{
692+
{//console.printf ("dead actor in the way");
691693
BadLOF = True;
692694
Return Trace_Stop;
693695
}
694696

695697
//A projectile class has been passed that is a ripper, but it can no longer rip the actor.
696698
If (ProjInfo && ProjInfo.Projectile && ProjInfo.IsRipper && IsCollidable (Mobj) && !CanRipActor (Mobj))
697-
{console.printf ("epic ripping fail");
699+
{//console.printf ("epic ripping fail");
698700
BadLOF = True;
699701
Return Trace_Stop;
700702
}
701703

702704
//The trace specifically hit a projectile blocking line. e.g a window linedef or a polyobject.
703705
If (BlockingLineInTheWay (Results.HitLine,0))
704-
{
706+
{//console.printf ("blocking line in the way");
705707
BadLOF = True;
706708
Return Trace_Stop;
707709
}
708710

709711
//Level geometry is in the way.
710712
If (HitLevelGeometry (Results))
711-
{
713+
{//console.printf ("level geometry in the way");
712714
//Don't return BadLOF if the target would be caught in the blast radius anyway. Unless they are immune to splash damage of course.
713715
Double Distance;
714716
If (SplashRadius > 0 && Other && !Other.bNoRadiusDmg && Distance <= SplashRadius)

ZScript/Bases/OtherFunctions.zsc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ Extend Class KAI_Actor
2828
Vector3 Diff = Level.Vec3Diff (LastEnemyPosition,Target.Pos);
2929
Vector3 TPOnly = Level.Vec3Diff (Diff,Target.Vel); //Get the teleport movement, sans velocity.
3030
TPOnly = GetTeleportMoveDivision();
31-
console.printf ("tponly is %.3f %.3f %.3f",tponly.x,tponly.y,tponly.z);
31+
//console.printf ("tponly is %.3f %.3f %.3f",tponly.x,tponly.y,tponly.z);
3232
Vector3 FakeVel = Level.Vec3Offset (TPOnly,Target.Vel);
33-
console.printf ("fakevel is %.3f %.3f %.3f",fakevel.xy,fakevel.z);
33+
//console.printf ("fakevel is %.3f %.3f %.3f",fakevel.xy,fakevel.z);
3434
Target.Vel = FakeVel;
3535
Projectile.VelIntercept (Target);
3636
AddProjectileSpread (Projectile,SpreadHorz,SpreadVert);

ZScript/Bases/Vehicle/CommonFunctions.zsc

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,35 @@
22
//Vehicle functions
33
Extend Class KAI_BaseVehicle
44
{
5+
//=====|Check functions|=====\\
6+
//Checks if the vehicle itself or any of its' turrets would collide at the specified position. Returns false if one of the turrets is colliding.
7+
//PLAYTEST: This function is still untested, chances are, it freezes the game, probably even with the depth set to like 5.
8+
Bool CheckTurretCollision (Vector3 NewPosition, Int TurretDepth = INT.MAX)
9+
{
10+
Vector3 TurPos, OldPos;
11+
KAI_BaseVehicle Veh = Self;
12+
While (Veh.Turret)
13+
{
14+
If (TurretDepth <= 0)
15+
Break;
16+
17+
TurPos = Level.Vec3Diff (NewPosition,Veh.Pos); //Subtract the new absolute pos from the current pos to get the relative pos.
18+
19+
OldPos = Veh.Turret.Pos;
20+
Veh.Turret.SetOrigin (Vec3Offset(TurPos.X,TurPos.Y,TurPos.Z),False); //Check where the turret will be in the future.
21+
If (!Veh.Turret.TestMobjLocation()) //One of the turrets will bonk something.
22+
{
23+
Veh.Turret.SetOrigin (OldPos,False);
24+
Return False;
25+
}
26+
Veh.Turret.SetOrigin (OldPos,False);
27+
OldPos = (Double.NaN,Double.NaN,Double.NaN);
28+
Veh = Veh.Turret; //Now check the turrets' turret, recursively.
29+
TurretDepth--;
30+
}
31+
Return True;
32+
}
33+
534
//=====|Spawn functions|=====\\
635
//The barebones code for spawning a vehicle turret. Useful for SpawnVehicleTurret virtuals with custom logic.
736
Void SpawnTurret (Class <KAI_BaseTurret> TurretClass)
@@ -119,6 +148,9 @@ Extend Class KAI_BaseVehicle
119148

120149
Bool IsColliding = (IsCollidable (Mobj,Source) && CheckHitboxIntersection (Source,Mobj)); //Are you clipping into a collidable actor ?
121150

151+
//The pusher can't collide with the pushee, so ignore it.
152+
If (!Source.CanCollideWith (Mobj, False) || !Mobj.CanCollideWith(Source, True)) Continue;
153+
122154
If (Blockers && IsColliding)
123155
Blockers.Push (Mobj);
124156

@@ -129,7 +161,7 @@ Extend Class KAI_BaseVehicle
129161
If (MaxPushRadius != 0 && MaxPushRadius < Mobj.Radius || MaxPushHeight != 0 && MaxPushHeight < Mobj.Height) Continue;
130162

131163
If (IsColliding)
132-
{
164+
{//console.printf ("%s is pushing %s",source.getclassname(),mobj.getclassname());
133165
//Double PushDist = ((Source.Radius + Mobj.Radius - Source.Distance2D (Mobj))*1.1); //Push it enough for the corner of the pushover to JUST be away from the vehicle.
134166
Double PushDist = (/*Source.*/Distance2D (Mobj)-/*Source.*/Radius);
135167
Vector3 PushPos = Mobj.Vec3Angle (-PushDist,Mobj.AngleTo (/*Source*/Self));
@@ -250,8 +282,6 @@ Extend Class KAI_BaseVehicle
250282
CheckPos.XY = Vec2Angle (Distance,CheckAngle);
251283
CheckPos.Z = GetZAt (CheckPos.X,CheckPos.Y,0,GZF_ABSOLUTEPOS)+(Height/2);
252284
}
253-
FSpawnParticleParams P; P.Color1 = "Green"; P.Style = STYLE_None; P.Lifetime = 5; P.Size = 4; P.StartAlpha = 1; P.FadeStep = -1; P.Flags = SPF_FULLBRIGHT;
254-
KAI_LOFRaycast.VisualizeTracePath(Pos,CheckPos,MaxTargetRange,8,p);
255285
NextMovePos = CheckPos;
256286
}
257287

@@ -344,7 +374,7 @@ Extend Class KAI_BaseVehicle
344374
}
345375
//If your turrets' target is too high up for it to reach.
346376
Else If (Turret && Turret.Target && Turret.ElevationState == Turret.ELEVATION_TOOHIGH)
347-
{a_log ("moving back so my turret can fire");
377+
{
348378
If (!(Flags & LVC_USERETREATSTATE))
349379
KAI_MoveAway (Turret.Target,MoveParams.Attempts,MoveParams.RunRad,MoveParams.StepThreshold,0.5,TurnRadius,ChaseFlags); //Back off to allow your turret to shoot.
350380
Else If (Flags & LVC_USERETREATSTATE && RetreatState)
@@ -460,7 +490,7 @@ Extend Class KAI_BaseVehicle
460490
//Target the hull if it's stronger than the turret, basically targeting the strongest part of the vehicle.
461491
If (Flags & RVHF_STRONGERHULL && Target.Master.Health > Target.Health)
462492
{
463-
If (!(Flags & RVHF_NOTARGETCHANGE)) Target = Target.Master;a_log ("targeting the stronger hull instead");
493+
If (!(Flags & RVHF_NOTARGETCHANGE)) Target = Target.Master;
464494
Return True;
465495
}
466496
}

ZScript/Bases/Vehicle/TurretFunctions.zsc

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,18 +168,11 @@ Extend Class KAI_BaseTurret
168168
If (DeltaAngle(Angle,OldSoundAngle) != 0)
169169
{
170170
Double AimDiff;
171-
Bool AimDir = (AimDiff = DeltaAngle(Angle,OldSoundAngle) < 0);// a_log ("aiming left relative to caller");
172-
//else a_log ("aiming right relative to caller");
171+
Bool AimDir = (AimDiff = DeltaAngle(Angle,OldSoundAngle) < 0);
173172

174173
Double TargDiff;
175174
Bool TargDir = (TargDiff = DeltaAngle (Angle,AngleTo(Target)) < 0);
176175

177-
//If (DeltaAngle (TargDiff, AimDiff) <= (1/65536.))
178-
//Return True;
179-
//a_log ("target to the left");
180-
//else
181-
//a_log ("target to the right");
182-
183176
Return (AimDir == TargDir); //The turret is aiming ahead if the aim and target directions don't match. Otherwise it's lagging behind (Skill issue)
184177
}
185178
//If there is no angle diff from last tick, then assume that the turret is sitting still, meaning it aiming straight to its' target.

0 commit comments

Comments
 (0)