Skip to content

Commit

Permalink
Ripper LOF check update and new collision function
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
inkoalawetrust committed Aug 30, 2023
1 parent 954498c commit dc60b9d
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 29 deletions.
2 changes: 1 addition & 1 deletion ZScript/Bases/AIFunctions.zsc
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Extend Class KAI_Actor
Vector3 ZigZagPos;

//Makes the actor move towards the specified actor.
//FIXME: There's some flickering between different sprite angles, try fixing it.
//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.
//CREDIT: Written by Custodian. Modified and expanded by me (inkoalawetrust).
//Other: The actor to move to.
//DetourFactor: How long the actor is allowed to move in a direction after hitting an obstacle, before heading straight for the target again.
Expand Down
5 changes: 2 additions & 3 deletions ZScript/Bases/Base.zsc
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,6 @@ Class KAI_BaseProjectile : FastProjectile
//Estimate the travel time the projectile needs.
If (Vel.Length() != 0)
TravelTics = Distance3D (Tracer)/Vel.Length();
//console.printf ("traveltics %.2f",traveltics);
TravelTics = Clamp (TravelTics,1,INT.MAX); //Needs at least 1 tic.
FloatTics = TravelTics; //Finer precision on multiplier the extrapolated velocity, for extra accuracy.
Vector3 OldPos = Tracer.Pos;
Expand All @@ -520,8 +519,8 @@ Class KAI_BaseProjectile : FastProjectile
Result = Level.Vec3Offset(Result,(FRandom(Inaccuracy.X,-Inaccuracy.X),FRandom(Inaccuracy.Y,-Inaccuracy.Y),FRandom(Inaccuracy.Z,-Inaccuracy.Z)));
//console.printf ("the tracers' current trajectory is %d %d %d",pos);
//console.printf ("the tracers' future trajectory is %d %d %d",result);
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;
KAI_LOFRaycast.VisualizeTracePath(Pos,result,distance3d(tracer),8,p);
//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;
//KAI_LOFRaycast.VisualizeTracePath(Pos,result,distance3d(tracer),8,p);
Return Result;
}

Expand Down
22 changes: 12 additions & 10 deletions ZScript/Bases/OtherCode.zsc
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,9 @@ Class KAI_ProjectileLOFCheck : KAI_LOFRaycast
Return False;
}

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

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

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

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

//Indestructible prop in the way.
If (Mobj && !OtherInBlast && IsCollidable (Mobj) && IsIndestructible (Mobj) && IsInanimateObject (Mobj))
{
{//console.printf ("invincible object in the way");
BadLOF = True;
Return Trace_Stop;
}

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

//Solid corpse in the way, attack can't go through.
Bool StopAtCorpse = !FriendlyFire ? IsHostile(Shooter,Mobj) : True;
If (Mobj && !OtherInBlast && IsSolidCorpse(Mobj) && StopAtCorpse)
{
{//console.printf ("dead actor in the way");
BadLOF = True;
Return Trace_Stop;
}

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

//The trace specifically hit a projectile blocking line. e.g a window linedef or a polyobject.
If (BlockingLineInTheWay (Results.HitLine,0))
{
{//console.printf ("blocking line in the way");
BadLOF = True;
Return Trace_Stop;
}

//Level geometry is in the way.
If (HitLevelGeometry (Results))
{
{//console.printf ("level geometry in the way");
//Don't return BadLOF if the target would be caught in the blast radius anyway. Unless they are immune to splash damage of course.
Double Distance;
If (SplashRadius > 0 && Other && !Other.bNoRadiusDmg && Distance <= SplashRadius)
Expand Down
4 changes: 2 additions & 2 deletions ZScript/Bases/OtherFunctions.zsc
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ Extend Class KAI_Actor
Vector3 Diff = Level.Vec3Diff (LastEnemyPosition,Target.Pos);
Vector3 TPOnly = Level.Vec3Diff (Diff,Target.Vel); //Get the teleport movement, sans velocity.
TPOnly = GetTeleportMoveDivision();
console.printf ("tponly is %.3f %.3f %.3f",tponly.x,tponly.y,tponly.z);
//console.printf ("tponly is %.3f %.3f %.3f",tponly.x,tponly.y,tponly.z);
Vector3 FakeVel = Level.Vec3Offset (TPOnly,Target.Vel);
console.printf ("fakevel is %.3f %.3f %.3f",fakevel.xy,fakevel.z);
//console.printf ("fakevel is %.3f %.3f %.3f",fakevel.xy,fakevel.z);
Target.Vel = FakeVel;
Projectile.VelIntercept (Target);
AddProjectileSpread (Projectile,SpreadHorz,SpreadVert);
Expand Down
40 changes: 35 additions & 5 deletions ZScript/Bases/Vehicle/CommonFunctions.zsc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,35 @@
//Vehicle functions
Extend Class KAI_BaseVehicle
{
//=====|Check functions|=====\\
//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.
//PLAYTEST: This function is still untested, chances are, it freezes the game, probably even with the depth set to like 5.
Bool CheckTurretCollision (Vector3 NewPosition, Int TurretDepth = INT.MAX)
{
Vector3 TurPos, OldPos;
KAI_BaseVehicle Veh = Self;
While (Veh.Turret)
{
If (TurretDepth <= 0)
Break;

TurPos = Level.Vec3Diff (NewPosition,Veh.Pos); //Subtract the new absolute pos from the current pos to get the relative pos.

OldPos = Veh.Turret.Pos;
Veh.Turret.SetOrigin (Vec3Offset(TurPos.X,TurPos.Y,TurPos.Z),False); //Check where the turret will be in the future.
If (!Veh.Turret.TestMobjLocation()) //One of the turrets will bonk something.
{
Veh.Turret.SetOrigin (OldPos,False);
Return False;
}
Veh.Turret.SetOrigin (OldPos,False);
OldPos = (Double.NaN,Double.NaN,Double.NaN);
Veh = Veh.Turret; //Now check the turrets' turret, recursively.
TurretDepth--;
}
Return True;
}

//=====|Spawn functions|=====\\
//The barebones code for spawning a vehicle turret. Useful for SpawnVehicleTurret virtuals with custom logic.
Void SpawnTurret (Class <KAI_BaseTurret> TurretClass)
Expand Down Expand Up @@ -119,6 +148,9 @@ Extend Class KAI_BaseVehicle

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

//The pusher can't collide with the pushee, so ignore it.
If (!Source.CanCollideWith (Mobj, False) || !Mobj.CanCollideWith(Source, True)) Continue;

If (Blockers && IsColliding)
Blockers.Push (Mobj);

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

If (IsColliding)
{
{//console.printf ("%s is pushing %s",source.getclassname(),mobj.getclassname());
//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.
Double PushDist = (/*Source.*/Distance2D (Mobj)-/*Source.*/Radius);
Vector3 PushPos = Mobj.Vec3Angle (-PushDist,Mobj.AngleTo (/*Source*/Self));
Expand Down Expand Up @@ -250,8 +282,6 @@ Extend Class KAI_BaseVehicle
CheckPos.XY = Vec2Angle (Distance,CheckAngle);
CheckPos.Z = GetZAt (CheckPos.X,CheckPos.Y,0,GZF_ABSOLUTEPOS)+(Height/2);
}
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;
KAI_LOFRaycast.VisualizeTracePath(Pos,CheckPos,MaxTargetRange,8,p);
NextMovePos = CheckPos;
}

Expand Down Expand Up @@ -344,7 +374,7 @@ Extend Class KAI_BaseVehicle
}
//If your turrets' target is too high up for it to reach.
Else If (Turret && Turret.Target && Turret.ElevationState == Turret.ELEVATION_TOOHIGH)
{a_log ("moving back so my turret can fire");
{
If (!(Flags & LVC_USERETREATSTATE))
KAI_MoveAway (Turret.Target,MoveParams.Attempts,MoveParams.RunRad,MoveParams.StepThreshold,0.5,TurnRadius,ChaseFlags); //Back off to allow your turret to shoot.
Else If (Flags & LVC_USERETREATSTATE && RetreatState)
Expand Down Expand Up @@ -460,7 +490,7 @@ Extend Class KAI_BaseVehicle
//Target the hull if it's stronger than the turret, basically targeting the strongest part of the vehicle.
If (Flags & RVHF_STRONGERHULL && Target.Master.Health > Target.Health)
{
If (!(Flags & RVHF_NOTARGETCHANGE)) Target = Target.Master;a_log ("targeting the stronger hull instead");
If (!(Flags & RVHF_NOTARGETCHANGE)) Target = Target.Master;
Return True;
}
}
Expand Down
9 changes: 1 addition & 8 deletions ZScript/Bases/Vehicle/TurretFunctions.zsc
Original file line number Diff line number Diff line change
Expand Up @@ -168,18 +168,11 @@ Extend Class KAI_BaseTurret
If (DeltaAngle(Angle,OldSoundAngle) != 0)
{
Double AimDiff;
Bool AimDir = (AimDiff = DeltaAngle(Angle,OldSoundAngle) < 0);// a_log ("aiming left relative to caller");
//else a_log ("aiming right relative to caller");
Bool AimDir = (AimDiff = DeltaAngle(Angle,OldSoundAngle) < 0);

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

//If (DeltaAngle (TargDiff, AimDiff) <= (1/65536.))
//Return True;
//a_log ("target to the left");
//else
//a_log ("target to the right");

Return (AimDir == TargDir); //The turret is aiming ahead if the aim and target directions don't match. Otherwise it's lagging behind (Skill issue)
}
//If there is no angle diff from last tick, then assume that the turret is sitting still, meaning it aiming straight to its' target.
Expand Down

0 comments on commit dc60b9d

Please sign in to comment.