public override Activity Tick(Actor self) { if (IsCanceled) { return(NextActivity); } if (requireSpace && !aircraft.CanLand(self.Location)) { return(this); } if (!soundPlayed && aircraft.Info.LandingSounds.Length > 0 && !self.IsAtGroundLevel()) { Game.Sound.Play(SoundType.World, aircraft.Info.LandingSounds.Random(self.World.SharedRandom), aircraft.CenterPosition); soundPlayed = true; } if (HeliFly.AdjustAltitude(self, aircraft, landAltitude)) { return(this); } return(NextActivity); }
public override Activity Tick(Actor self) { if (IsCanceled) { return(NextActivity); } if (requireSpace && !helicopter.CanLand(self.Location)) { return(this); } if (!playedSound && helicopter.Info.LandingSound != null && !self.IsAtGroundLevel()) { Game.Sound.Play(helicopter.Info.LandingSound); playedSound = true; } if (HeliFly.AdjustAltitude(self, helicopter, helicopter.Info.LandAltitude)) { return(this); } return(NextActivity); }
public override Activity Tick(Actor self) { // Refuse to take off if it would land immediately again. if (helicopter.ForceLanding) { Cancel(self); return(NextActivity); } if (IsCanceled) { return(NextActivity); } if (HeliFly.AdjustAltitude(self, helicopter, helicopter.Info.CruiseAltitude)) { return(this); } var move = helicopter.FlyStep(helicopter.Facing); helicopter.SetPosition(self, helicopter.CenterPosition + move); var desiredFacing = helicopter.Facing + 64; helicopter.Facing = Util.TickFacing(helicopter.Facing, desiredFacing, helicopter.TurnSpeed / 3); return(this); }
public override Activity Tick(Actor self) { if (cargo.IsDead || !carryall.IsBusy) { carryall.UnreserveCarryable(); return(NextActivity); } switch (state) { case State.Intercept: state = State.LockCarryable; return(ActivityUtils.SequenceActivities(movement.MoveWithinRange(Target.FromActor(cargo), WDist.FromCells(4)), this)); case State.LockCarryable: // Last check if (carryable.StandbyForPickup(self)) { state = State.MoveToCarryable; return(this); } // We got cancelled carryall.UnreserveCarryable(); return(NextActivity); case State.MoveToCarryable: // We arrived, move on top if (self.Location == cargo.Location) { state = State.Turn; return(this); } return(ActivityUtils.SequenceActivities(movement.MoveTo(cargo.Location, 0), this)); case State.Turn: // Align facing and Land if (selfFacing.Facing != cargoFacing.Facing) { return(ActivityUtils.SequenceActivities(new Turn(self, cargoFacing.Facing), this)); } state = State.Pickup; return(ActivityUtils.SequenceActivities(new HeliLand(self, false), new Wait(10), this)); case State.Pickup: // Remove our carryable from world self.World.AddFrameEndTask(w => cargo.World.Remove(cargo)); carryall.AttachCarryable(cargo); state = State.TakeOff; return(this); case State.TakeOff: if (HeliFly.AdjustAltitude(self, aircraft, aircraft.Info.CruiseAltitude)) { return(this); } return(NextActivity); } return(NextActivity); }
public override Activity Tick(Actor self) { if (IsCanceled || !target.IsValidFor(self)) { return(NextActivity); } // If all ammo pools are depleted and none reload automatically, return to helipad to reload and then move to next activity // TODO: This should check whether there is ammo left that is actually suitable for the target if (ammoPools != null && ammoPools.All(x => !x.Info.SelfReloads && !x.HasAmmo())) { return(Util.SequenceActivities(new HeliReturn(self), NextActivity)); } var dist = target.CenterPosition - self.CenterPosition; // Can rotate facing while ascending var desiredFacing = Util.GetFacing(dist, helicopter.Facing); helicopter.Facing = Util.TickFacing(helicopter.Facing, desiredFacing, helicopter.ROT); if (HeliFly.AdjustAltitude(self, helicopter, helicopter.Info.CruiseAltitude)) { return(this); } // Fly towards the target // TODO: Fix that the helicopter won't do anything if it has multiple weapons with different ranges // and the weapon with the longest range is out of ammo if (!target.IsInRange(self.CenterPosition, attackHeli.GetMaximumRange())) { helicopter.SetPosition(self, helicopter.CenterPosition + helicopter.FlyStep(desiredFacing)); } // Fly backwards from the target // TODO: Same problem as with MaximumRange if (target.IsInRange(self.CenterPosition, attackHeli.GetMinimumRange())) { // Facing 0 doesn't work with the following position change var facing = 1; if (desiredFacing != 0) { facing = desiredFacing; } else if (helicopter.Facing != 0) { facing = helicopter.Facing; } helicopter.SetPosition(self, helicopter.CenterPosition + helicopter.FlyStep(-facing)); } attackHeli.DoAttack(self, target); return(this); }
public override Activity Tick(Actor self) { if (IsCanceled) { return(NextActivity); } if (requireSpace && !helicopter.CanLand(self.Location)) { return(this); } if (HeliFly.AdjustAltitude(self, helicopter, landAltitude)) { return(this); } return(NextActivity); }
public override Activity Tick(Actor self) { if (cargo.IsDead || !carryall.IsBusy) { carryall.UnreserveCarryable(); return(NextActivity); } switch (state) { case State.Transport: var targetl = GetLocationToDrop(carryable.Destination); state = State.Land; return(ActivityUtils.SequenceActivities(movement.MoveTo(targetl, 0), this)); case State.Land: if (!CanDropHere()) { state = State.Transport; return(this); } if (HeliFly.AdjustAltitude(self, aircraft, aircraft.Info.LandAltitude)) { return(this); } state = State.Release; return(ActivityUtils.SequenceActivities(new Wait(15), this)); case State.Release: if (!CanDropHere()) { state = State.Transport; return(this); } Release(); return(NextActivity); } return(NextActivity); }
public override Activity Tick(Actor self) { if (IsCanceled) { return(NextActivity); } if (HeliFly.AdjustAltitude(self, helicopter, helicopter.Info.CruiseAltitude)) { return(this); } var move = helicopter.FlyStep(helicopter.Facing); helicopter.SetPosition(self, helicopter.CenterPosition + move); var desiredFacing = helicopter.Facing + 64; helicopter.Facing = Util.TickFacing(helicopter.Facing, desiredFacing, helicopter.ROT / 3); return(this); }
public override Activity Tick(Actor self) { if (IsCanceled || !target.IsValidFor(self)) { return(NextActivity); } if (attackOnlyVisibleTargets && target.Type == TargetType.Actor && canHideUnderFog && !self.Owner.CanTargetActor(target.Actor)) { var newTarget = Target.FromCell(self.World, self.World.Map.CellContaining(target.CenterPosition)); self.CancelActivity(); self.SetTargetLine(newTarget, Color.Green); return(ActivityUtils.SequenceActivities(new HeliFly(self, newTarget))); } // If all ammo pools are depleted and none reload automatically, return to helipad to reload and then move to next activity // TODO: This should check whether there is ammo left that is actually suitable for the target if (ammoPools.All(x => !x.Info.SelfReloads && !x.HasAmmo())) { return(ActivityUtils.SequenceActivities(new HeliReturnToBase(self), NextActivity)); } var dist = target.CenterPosition - self.CenterPosition; // Can rotate facing while ascending var desiredFacing = dist.HorizontalLengthSquared != 0 ? dist.Yaw.Facing : helicopter.Facing; helicopter.Facing = Util.TickFacing(helicopter.Facing, desiredFacing, helicopter.TurnSpeed); if (HeliFly.AdjustAltitude(self, helicopter, helicopter.Info.CruiseAltitude)) { return(this); } // Fly towards the target // TODO: Fix that the helicopter won't do anything if it has multiple weapons with different ranges // and the weapon with the longest range is out of ammo if (!target.IsInRange(self.CenterPosition, attackHeli.GetMaximumRange())) { helicopter.SetPosition(self, helicopter.CenterPosition + helicopter.FlyStep(desiredFacing)); } // Fly backwards from the target // TODO: Same problem as with MaximumRange if (target.IsInRange(self.CenterPosition, attackHeli.GetMinimumRange())) { // Facing 0 doesn't work with the following position change var facing = 1; if (desiredFacing != 0) { facing = desiredFacing; } else if (helicopter.Facing != 0) { facing = helicopter.Facing; } helicopter.SetPosition(self, helicopter.CenterPosition + helicopter.FlyStep(-facing)); } attackHeli.DoAttack(self, target); return(this); }
public override Activity Tick(Actor self) { // Refuse to take off if it would land immediately again. if (helicopter.ForceLanding) { Cancel(self); return(NextActivity); } if (IsCanceled || !target.IsValidFor(self)) { return(NextActivity); } var pos = self.CenterPosition; var targetPos = attackHeli.GetTargetPosition(pos, target); if (attackOnlyVisibleTargets && target.Type == TargetType.Actor && canHideUnderFog && !target.Actor.CanBeViewedByPlayer(self.Owner)) { var newTarget = Target.FromCell(self.World, self.World.Map.CellContaining(targetPos)); Cancel(self); self.SetTargetLine(newTarget, Color.Green); return(new HeliFly(self, newTarget)); } // If all valid weapons have depleted their ammo and RearmBuilding is defined, return to RearmBuilding to reload and then resume the activity if (!autoReloads && helicopter.Info.RearmBuildings.Any() && attackHeli.Armaments.All(x => x.IsTraitPaused || !x.Weapon.IsValidAgainst(target, self.World, self))) { return(ActivityUtils.SequenceActivities(new HeliReturnToBase(self, helicopter.Info.AbortOnResupply), this)); } var dist = targetPos - pos; // Can rotate facing while ascending var desiredFacing = dist.HorizontalLengthSquared != 0 ? dist.Yaw.Facing : helicopter.Facing; helicopter.Facing = Util.TickFacing(helicopter.Facing, desiredFacing, helicopter.TurnSpeed); if (HeliFly.AdjustAltitude(self, helicopter, helicopter.Info.CruiseAltitude)) { return(this); } // Fly towards the target if (!target.IsInRange(pos, attackHeli.GetMaximumRangeVersusTarget(target))) { helicopter.SetPosition(self, helicopter.CenterPosition + helicopter.FlyStep(desiredFacing)); } // Fly backwards from the target if (target.IsInRange(pos, attackHeli.GetMinimumRangeVersusTarget(target))) { // Facing 0 doesn't work with the following position change var facing = 1; if (desiredFacing != 0) { facing = desiredFacing; } else if (helicopter.Facing != 0) { facing = helicopter.Facing; } helicopter.SetPosition(self, helicopter.CenterPosition + helicopter.FlyStep(-facing)); } attackHeli.DoAttack(self, target); return(this); }
public override Activity Tick(Actor self) { if (IsCanceled || !target.IsValidFor(self)) { return(NextActivity); } if (attackOnlyVisibleTargets && target.Type == TargetType.Actor && canHideUnderFog && !self.Owner.CanTargetActor(target.Actor)) { var newTarget = Target.FromCell(self.World, self.World.Map.CellContaining(target.CenterPosition)); Cancel(self); self.SetTargetLine(newTarget, Color.Green); return(new HeliFly(self, newTarget)); } // If any AmmoPool is depleted and no weapon is valid against target, return to helipad to reload and then resume the activity if (ammoPools.Any(x => !x.Info.SelfReloads && !x.HasAmmo()) && !attackHeli.HasAnyValidWeapons(target)) { return(ActivityUtils.SequenceActivities(new HeliReturnToBase(self, helicopter.Info.AbortOnResupply), this)); } var dist = target.CenterPosition - self.CenterPosition; // Can rotate facing while ascending var desiredFacing = dist.HorizontalLengthSquared != 0 ? dist.Yaw.Facing : helicopter.Facing; helicopter.Facing = Util.TickFacing(helicopter.Facing, desiredFacing, helicopter.TurnSpeed); if (HeliFly.AdjustAltitude(self, helicopter, helicopter.Info.CruiseAltitude)) { return(this); } // Fly towards the target if (!target.IsInRange(self.CenterPosition, attackHeli.GetMaximumRangeVersusTarget(target))) { helicopter.SetPosition(self, helicopter.CenterPosition + helicopter.FlyStep(desiredFacing)); } // Fly backwards from the target if (target.IsInRange(self.CenterPosition, attackHeli.GetMinimumRangeVersusTarget(target))) { // Facing 0 doesn't work with the following position change var facing = 1; if (desiredFacing != 0) { facing = desiredFacing; } else if (helicopter.Facing != 0) { facing = helicopter.Facing; } helicopter.SetPosition(self, helicopter.CenterPosition + helicopter.FlyStep(-facing)); } attackHeli.DoAttack(self, target); return(this); }
public override Activity Tick(Actor self) { if (ChildActivity != null) { ChildActivity = ActivityUtils.RunActivityTick(self, ChildActivity); if (ChildActivity != null) { return(this); } } // Refuse to take off if it would land immediately again. if (aircraft.ForceLanding) { Cancel(self); } if (IsCanceling) { // Cancel the requested target, but keep firing on it while in range if (attackAircraft.Info.PersistentTargeting) { attackAircraft.OpportunityTarget = attackAircraft.RequestedTarget; attackAircraft.OpportunityForceAttack = attackAircraft.RequestedForceAttack; attackAircraft.OpportunityTargetIsPersistentTarget = true; } attackAircraft.RequestedTarget = Target.Invalid; return(NextActivity); } // Check that AttackFollow hasn't cancelled the target by modifying attack.Target // Having both this and AttackFollow modify that field is a horrible hack. if (hasTicked && attackAircraft.RequestedTarget.Type == TargetType.Invalid) { return(NextActivity); } if (attackAircraft.IsTraitPaused) { return(this); } bool targetIsHiddenActor; attackAircraft.RequestedTarget = target = target.Recalculate(self.Owner, out targetIsHiddenActor); attackAircraft.RequestedTargetLastTick = self.World.WorldTick; hasTicked = true; if (!targetIsHiddenActor && target.Type == TargetType.Actor) { lastVisibleTarget = Target.FromTargetPositions(target); lastVisibleMaximumRange = attackAircraft.GetMaximumRangeVersusTarget(target); lastVisibleOwner = target.Actor.Owner; lastVisibleTargetTypes = target.Actor.GetEnabledTargetTypes(); } var oldUseLastVisibleTarget = useLastVisibleTarget; useLastVisibleTarget = targetIsHiddenActor || !target.IsValidFor(self); // Update target lines if required if (useLastVisibleTarget != oldUseLastVisibleTarget) { self.SetTargetLine(useLastVisibleTarget ? lastVisibleTarget : target, Color.Red, false); } // Target is hidden or dead, and we don't have a fallback position to move towards if (useLastVisibleTarget && !lastVisibleTarget.IsValidFor(self)) { attackAircraft.RequestedTarget = Target.Invalid; return(NextActivity); } // If all valid weapons have depleted their ammo and Rearmable trait exists, return to RearmActor to reload and then resume the activity if (rearmable != null && !useLastVisibleTarget && attackAircraft.Armaments.All(x => x.IsTraitPaused || !x.Weapon.IsValidAgainst(target, self.World, self))) { QueueChild(self, new ReturnToBase(self, aircraft.Info.AbortOnResupply), true); return(this); } var pos = self.CenterPosition; var checkTarget = useLastVisibleTarget ? lastVisibleTarget : target; // Update facing var delta = attackAircraft.GetTargetPosition(pos, checkTarget) - pos; var desiredFacing = delta.HorizontalLengthSquared != 0 ? delta.Yaw.Facing : aircraft.Facing; aircraft.Facing = Util.TickFacing(aircraft.Facing, desiredFacing, aircraft.TurnSpeed); if (HeliFly.AdjustAltitude(self, aircraft, aircraft.Info.CruiseAltitude)) { return(this); } // We don't know where the target actually is, so move to where we last saw it if (useLastVisibleTarget) { // We've reached the assumed position but it is not there - give up if (checkTarget.IsInRange(pos, lastVisibleMaximumRange)) { attackAircraft.RequestedTarget = Target.Invalid; return(NextActivity); } // Fly towards the last known position aircraft.SetPosition(self, aircraft.CenterPosition + aircraft.FlyStep(desiredFacing)); return(this); } // Fly towards the target if (!target.IsInRange(pos, attackAircraft.GetMaximumRangeVersusTarget(target))) { aircraft.SetPosition(self, aircraft.CenterPosition + aircraft.FlyStep(desiredFacing)); } // Fly backwards from the target if (target.IsInRange(pos, attackAircraft.GetMinimumRangeVersusTarget(target))) { // Facing 0 doesn't work with the following position change var facing = 1; if (desiredFacing != 0) { facing = desiredFacing; } else if (aircraft.Facing != 0) { facing = aircraft.Facing; } aircraft.SetPosition(self, aircraft.CenterPosition + aircraft.FlyStep(-facing)); } return(this); }
public override Activity Tick(Actor self) { if (ChildActivity != null) { ChildActivity = ActivityUtils.RunActivityTick(self, ChildActivity); if (ChildActivity != null) { return(this); } } if (IsCanceling || target.Type == TargetType.Invalid) { aircraft.RemoveInfluence(); return(NextActivity); } if (!landingInitiated) { var landingCell = !aircraft.Info.VTOL ? self.World.Map.CellContaining(target.CenterPosition + offset) : self.Location; if (!aircraft.CanLand(landingCell, target.Actor)) { // Maintain holding pattern. if (!aircraft.Info.CanHover) { QueueChild(self, new FlyCircle(self, 25), true); } self.NotifyBlocker(landingCell); return(this); } aircraft.AddInfluence(landingCell); aircraft.EnteringCell(self); landingInitiated = true; } var altitude = self.World.Map.DistanceAboveTerrain(self.CenterPosition); var landAltitude = self.World.Map.DistanceAboveTerrain(target.CenterPosition + offset) + aircraft.LandAltitude; if (!soundPlayed && aircraft.Info.LandingSounds.Length > 0 && altitude != landAltitude) { Game.Sound.Play(SoundType.World, aircraft.Info.LandingSounds, self.World, aircraft.CenterPosition); soundPlayed = true; } // For VTOLs we assume we've already arrived at the target location and just need to move downward if (aircraft.Info.VTOL) { if (HeliFly.AdjustAltitude(self, aircraft, landAltitude)) { return(this); } return(NextActivity); } var d = (target.CenterPosition + offset) - self.CenterPosition; // The next move would overshoot, so just set the final position var move = aircraft.FlyStep(aircraft.Facing); if (d.HorizontalLengthSquared < move.HorizontalLengthSquared) { var landingAltVec = new WVec(WDist.Zero, WDist.Zero, aircraft.LandAltitude); aircraft.SetPosition(self, target.CenterPosition + offset + landingAltVec); return(NextActivity); } var landingAlt = self.World.Map.DistanceAboveTerrain(target.CenterPosition + offset) + aircraft.LandAltitude; Fly.FlyToward(self, aircraft, d.Yaw.Facing, landingAlt); return(this); }