示例#1
0
 public override void WorldComponentTick()
 {
     foreach (var defense in searchingDefenses)
     {
         AerialVehicleInFlight aerialVehicleSearchingFor = defense.Key;
         for (int j = defense.Value.Count - 1; j >= 0; j--)
         {
             AirDefense airDefense        = defense.Value.ElementAt(j);
             float      distance          = Ext_Math.SphericalDistance(airDefense.parent.DrawPos, aerialVehicleSearchingFor.DrawPos);
             bool       withinMaxDistance = distance <= airDefense.MaxDistance;
             if (airDefense.CurrentTarget != aerialVehicleSearchingFor)
             {
                 airDefense.angle = (airDefense.angle + RotationRate * airDefense.searchDirection).ClampAndWrap(0, 360);
                 float angleToTarget = airDefense.parent.DrawPos.AngleToPoint(aerialVehicleSearchingFor.DrawPos);
                 if (withinMaxDistance && Mathf.Abs(angleToTarget - airDefense.angle) <= (airDefense.Arc / 2))
                 {
                     airDefense.activeTargets.Add(aerialVehicleSearchingFor);
                 }
             }
             else
             {
                 float headingToTarget   = WorldHelper.TryFindHeading(airDefense.parent.DrawPos, airDefense.CurrentTarget.DrawPos);
                 int   dirSignMultiplier = headingToTarget < airDefense.angle ? -2 : 2;
                 if (Mathf.Abs(headingToTarget - airDefense.angle) < 1 || Mathf.Abs(headingToTarget - airDefense.angle) > 359)
                 {
                     airDefense.angle = headingToTarget;
                     airDefense.Attack();
                 }
                 else
                 {
                     airDefense.angle = (airDefense.angle + RotationRate * dirSignMultiplier).ClampAndWrap(0, 360);
                 }
                 if (!withinMaxDistance)
                 {
                     airDefense.activeTargets.Remove(aerialVehicleSearchingFor);
                 }
             }
         }
     }
 }
示例#2
0
 public AntiAircraftWorker(AirDefense airDefense, AntiAircraftDef def)
 {
     this.airDefense = airDefense;
     this.def        = def;
 }