protected override void CalculateCurrentOrder() { Vec2 direction1 = this.formation.Direction; float num = 5f; Vec2 direction2; if (this._tacticalDefendPosition != null) { direction2 = this._tacticalDefendPosition.IsInsurmountable ? (this.formation.Team.QuerySystem.AverageEnemyPosition - this._tacticalDefendPosition.Position.AsVec2).Normalized() : this._tacticalDefendPosition.Direction; } else if (this.formation.QuerySystem.ClosestEnemyFormation == null) { direction2 = this.formation.Direction; } else if (this._defendedSiegeWeapon != null) { direction2 = this.formation.QuerySystem.ClosestEnemyFormation.MedianPosition.AsVec2 - this._defendedSiegeWeapon.GameEntity.GlobalPosition.AsVec2; num = Math.Max(Math.Min(direction2.Normalize(), 5f), !((NativeObject)this._defendedSiegeWeapon.WaitEntity != (NativeObject)null) ? 3f : (this._defendedSiegeWeapon.WaitEntity.GlobalPosition - this._defendedSiegeWeapon.GameEntity.GlobalPosition).Length); } else { direction2 = ((double)this.formation.Direction.DotProduct((this.formation.QuerySystem.ClosestEnemyFormation.MedianPosition.AsVec2 - this.formation.QuerySystem.AveragePosition).Normalized()) < 0.5 ? this.formation.QuerySystem.ClosestEnemyFormation.MedianPosition.AsVec2 - this.formation.QuerySystem.AveragePosition : this.formation.Direction).Normalized(); } if (this._tacticalDefendPosition != null) { if (!this._tacticalDefendPosition.IsInsurmountable) { this.CurrentOrder = MovementOrder.MovementOrderMove(this._tacticalDefendPosition.Position); } else { Vec2 vec2 = this._tacticalDefendPosition.Position.AsVec2 + this._tacticalDefendPosition.Width * 0.5f * direction2; WorldPosition position = this._tacticalDefendPosition.Position; position.SetVec2(vec2); this.CurrentOrder = MovementOrder.MovementOrderMove(position); } if (!this._tacticalDefendPosition.IsInsurmountable) { this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtDirection(direction2); } else { this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtEnemy; } } else if (this._defensePosition.IsValid) { WorldPosition defensePosition = this._defensePosition; defensePosition.SetVec2(this._defensePosition.AsVec2 + direction2 * num); this.CurrentOrder = MovementOrder.MovementOrderMove(defensePosition); this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtDirection(direction2); } else { WorldPosition medianPosition = this.formation.QuerySystem.MedianPosition; medianPosition.SetVec2(this.formation.QuerySystem.AveragePosition); this.CurrentOrder = MovementOrder.MovementOrderMove(medianPosition); this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtDirection(direction2); } }
private void ResetOrderPositions() { this._behaviourState = BehaviorRetakeCastleKeyPosition.BehaviourState.UnSet; this._gatheringSide = this.DetermineGatheringSide(); SiegeLane siegeLane = TeamAISiegeComponent.SiegeLanes.FirstOrDefault <SiegeLane>((Func <SiegeLane, bool>)(sl => sl.LaneSide == this._gatheringSide)); WorldFrame defenseWaitFrame = siegeLane.DefensePoints.FirstOrDefault <ICastleKeyPosition>().DefenseWaitFrame; this._gatheringTacticalPos = siegeLane.DefensePoints.FirstOrDefault <ICastleKeyPosition>().WaitPosition; if (this._gatheringTacticalPos != null) { this._gatherOrder = MovementOrder.MovementOrderMove(this._gatheringTacticalPos.Position); this._gatheringFacingOrder = FacingOrder.FacingOrderLookAtEnemy; } else if (defenseWaitFrame.Origin.IsValid) { double num = (double)defenseWaitFrame.Rotation.f.Normalize(); this._gatherOrder = MovementOrder.MovementOrderMove(defenseWaitFrame.Origin); this._gatheringFacingOrder = FacingOrder.FacingOrderLookAtEnemy; } else { this._gatherOrder = MovementOrder.MovementOrderMove(this.formation.QuerySystem.MedianPosition); this._gatheringFacingOrder = FacingOrder.FacingOrderLookAtEnemy; } this._attackOrder = MovementOrder.MovementOrderMove(TeamAISiegeComponent.SiegeLanes.FirstOrDefault <SiegeLane>((Func <SiegeLane, bool>)(sl => sl.LaneSide == this.behaviorSide)).DefensePoints.FirstOrDefault <ICastleKeyPosition>().MiddleFrame.Origin); this._attackFacingOrder = FacingOrder.FacingOrderLookAtEnemy; this.CurrentOrder = this._behaviourState == BehaviorRetakeCastleKeyPosition.BehaviourState.Attacking ? this._attackOrder : this._gatherOrder; this.CurrentFacingOrder = this._behaviourState == BehaviorRetakeCastleKeyPosition.BehaviourState.Attacking ? this._attackFacingOrder : this._gatheringFacingOrder; }
private void ResetOrderPositions() { this.behaviorSide = this.DetermineGatheringSide(); SiegeLane siegeLane = TeamAISiegeComponent.SiegeLanes.FirstOrDefault <SiegeLane>((Func <SiegeLane, bool>)(sl => sl.LaneSide == this.behaviorSide)); WorldFrame worldFrame = siegeLane == null ? WorldFrame.Invalid : siegeLane.DefensePoints.FirstOrDefault <ICastleKeyPosition>().DefenseWaitFrame; this._gatheringTacticalPos = siegeLane != null?siegeLane.DefensePoints.FirstOrDefault <ICastleKeyPosition>().WaitPosition : (TacticalPosition)null; if (this._gatheringTacticalPos != null) { this._gatherOrder = MovementOrder.MovementOrderMove(this._gatheringTacticalPos.Position); this._gatheringFacingOrder = FacingOrder.FacingOrderLookAtEnemy; } else if (worldFrame.Origin.IsValid) { double num = (double)worldFrame.Rotation.f.Normalize(); this._gatherOrder = MovementOrder.MovementOrderMove(worldFrame.Origin); this._gatheringFacingOrder = FacingOrder.FacingOrderLookAtEnemy; } else { this._gatherOrder = MovementOrder.MovementOrderMove(this.formation.QuerySystem.MedianPosition); this._gatheringFacingOrder = FacingOrder.FacingOrderLookAtEnemy; } this._attackOrder = MovementOrder.MovementOrderChargeToTarget(this._targetEnemyFormation); this._attackFacingOrder = FacingOrder.FacingOrderLookAtEnemy; this.CurrentOrder = this._behaviourState == BehaviorEliminateEnemyInsideCastle.BehaviourState.Attacking ? this._attackOrder : this._gatherOrder; this.CurrentFacingOrder = this._behaviourState == BehaviorEliminateEnemyInsideCastle.BehaviourState.Attacking ? this._attackFacingOrder : this._gatheringFacingOrder; }
protected override void CalculateCurrentOrder() { BehaviorWaitForLadders.BehaviourState behaviourState = this._followOrder != (object)null ? BehaviorWaitForLadders.BehaviourState.Follow : BehaviorWaitForLadders.BehaviourState.Stop; if (behaviourState == this._behaviourState) { return; } if (behaviourState == BehaviorWaitForLadders.BehaviourState.Follow) { this.CurrentOrder = this._followOrder; if (this._followTacticalPosition != null) { this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtDirection(this._followTacticalPosition.Direction); } else { this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtEnemy; } } else { this.CurrentOrder = this._stopOrder; this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtEnemy; } this._behaviourState = behaviourState; }
protected override void CalculateCurrentOrder() { WorldPosition medianPosition; Vec2 direction; if (this.formation.QuerySystem.ClosestEnemyFormation != null) { medianPosition = this.formation.QuerySystem.MedianPosition; medianPosition.SetVec2((double)this.formation.QuerySystem.AveragePosition.DistanceSquared(this.formation.QuerySystem.ClosestEnemyFormation.MedianPosition.AsVec2) > 400.0 ? this.formation.QuerySystem.HighGroundCloseToForeseenBattleGround : this.formation.QuerySystem.AveragePosition); Vec2 vec2_1; if ((double)this.formation.QuerySystem.AveragePosition.DistanceSquared(this.formation.QuerySystem.HighGroundCloseToForeseenBattleGround) <= 25.0) { Vec2 vec2_2 = this.formation.Direction; vec2_2 = (double)vec2_2.DotProduct((this.formation.QuerySystem.ClosestEnemyFormation.MedianPosition.AsVec2 - this.formation.QuerySystem.AveragePosition).Normalized()) < 0.5 ? this.formation.QuerySystem.ClosestEnemyFormation.MedianPosition.AsVec2 - this.formation.QuerySystem.AveragePosition : this.formation.Direction; vec2_1 = vec2_2.Normalized(); } else { vec2_1 = (this.formation.QuerySystem.Team.MedianTargetFormationPosition.AsVec2 - medianPosition.AsVec2).Normalized(); } direction = vec2_1; } else { direction = this.formation.Direction; medianPosition = this.formation.QuerySystem.MedianPosition; medianPosition.SetVec2(this.formation.QuerySystem.AveragePosition); } this.CurrentOrder = MovementOrder.MovementOrderMove(medianPosition); this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtDirection(direction); }
protected override void CalculateCurrentOrder() { WorldPosition position = this.formation.AI.Side == FormationAI.BehaviorSide.Right ? this.formation.QuerySystem.Team.RightFlankEdgePosition : this.formation.QuerySystem.Team.LeftFlankEdgePosition; Vec2 direction = (position.AsVec2 - this.formation.QuerySystem.AveragePosition).Normalized(); this.CurrentOrder = MovementOrder.MovementOrderMove(position); this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtDirection(direction); }
protected override void CalculateCurrentOrder() { switch (this._behaviourState) { case BehaviorAssaultWalls.BehaviorState.Deciding: this.CurrentOrder = this._stopOrder; break; case BehaviorAssaultWalls.BehaviorState.ClimbWall: this.CurrentOrder = this._wallSegmentMoveOrder; this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtDirection(-this._wallSegment.MiddleFrame.Rotation.f.AsVec2.Normalized()); this.CurrentArrangementOrder = ArrangementOrder.ArrangementOrderLine; break; case BehaviorAssaultWalls.BehaviorState.AttackEntity: if (!this._teamAISiegeComponent.OuterGate.IsGateOpen) { this.CurrentOrder = this._attackEntityOrderOuterGate; } else { this.CurrentOrder = this._attackEntityOrderInnerGate; } this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtEnemy; this.CurrentArrangementOrder = ArrangementOrder.ArrangementOrderLine; break; case BehaviorAssaultWalls.BehaviorState.TakeControl: if (this.formation.QuerySystem.ClosestEnemyFormation != null) { this.CurrentOrder = MovementOrder.MovementOrderChargeToTarget(this.formation.QuerySystem.ClosestEnemyFormation.Formation); } else { this.CurrentOrder = MovementOrder.MovementOrderCharge; } this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtDirection(-this._wallSegment.MiddleFrame.Rotation.f.AsVec2.Normalized()); this.CurrentArrangementOrder = ArrangementOrder.ArrangementOrderLine; break; case BehaviorAssaultWalls.BehaviorState.MoveToGate: this.CurrentOrder = this._castleGateMoveOrder; this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtDirection(-this._innerGate.MiddleFrame.Rotation.f.AsVec2.Normalized()); this.CurrentArrangementOrder = ArrangementOrder.ArrangementOrderLine; break; case BehaviorAssaultWalls.BehaviorState.Charging: this.CurrentOrder = this._chargeOrder; this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtEnemy; this.CurrentArrangementOrder = ArrangementOrder.ArrangementOrderLoose; break; case BehaviorAssaultWalls.BehaviorState.Stop: this.CurrentOrder = this._stopOrder; break; } }
protected override void CalculateCurrentOrder() { Vec2 direction = this.formation.QuerySystem.ClosestEnemyFormation == null ? this.formation.Direction : (this.formation.QuerySystem.ClosestEnemyFormation.MedianPosition.AsVec2 - this.formation.QuerySystem.AveragePosition).Normalized(); WorldPosition medianPosition = this.formation.QuerySystem.MedianPosition; medianPosition.SetVec2(this.formation.QuerySystem.AveragePosition); this.CurrentOrder = MovementOrder.MovementOrderMove(medianPosition); this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtDirection(direction); }
protected override void CalculateCurrentOrder() { if (this._switchedToShieldWallRecently && !this._switchedToShieldWallTimer.Check(Mission.Current.Time) && (double)this.formation.QuerySystem.FormationDispersedness > 2.0) { WorldPosition medianPosition = this.formation.QuerySystem.MedianPosition; if (this._reformPosition.IsValid) { medianPosition.SetVec2(this._reformPosition); } else { this._reformPosition = this.formation.QuerySystem.AveragePosition + (this.formation.QuerySystem.Team.MedianTargetFormationPosition.AsVec2 - this.formation.QuerySystem.AveragePosition).Normalized() * 5f; medianPosition.SetVec2(this._reformPosition); } this.CurrentOrder = MovementOrder.MovementOrderMove(medianPosition); } else { this._switchedToShieldWallRecently = false; bool flag = false; Vec2 vec2_1; if (this.formation.QuerySystem.ClosestEnemyFormation != null && this.formation.QuerySystem.ClosestEnemyFormation.IsCavalryFormation) { Vec2 vec2_2 = this.formation.QuerySystem.AveragePosition - this.formation.QuerySystem.ClosestEnemyFormation.AveragePosition; double num1 = (double)vec2_2.Normalize(); Vec2 currentVelocity = this.formation.QuerySystem.ClosestEnemyFormation.CurrentVelocity; float num2 = currentVelocity.Normalize(); if (num1 < 30.0 && (double)num2 > 2.0 && (double)vec2_2.DotProduct(currentVelocity) > 0.5) { flag = true; WorldPosition medianPosition = this.formation.QuerySystem.MedianPosition; if (this._reformPosition.IsValid) { medianPosition.SetVec2(this._reformPosition); } else { vec2_1 = this.formation.QuerySystem.Team.MedianTargetFormationPosition.AsVec2 - this.formation.QuerySystem.AveragePosition; this._reformPosition = this.formation.QuerySystem.AveragePosition + vec2_1.Normalized() * 5f; medianPosition.SetVec2(this._reformPosition); } this.CurrentOrder = MovementOrder.MovementOrderMove(medianPosition); } } if (flag) { return; } this._reformPosition = Vec2.Invalid; WorldPosition position = this.formation.Team.QuerySystem.EnemyTeams.SelectMany <TeamQuerySystem, Formation>((Func <TeamQuerySystem, IEnumerable <Formation> >)(t => t.Team.FormationsIncludingSpecial)).Count <Formation>() == 1 ? this.formation.QuerySystem.ClosestEnemyFormation.MedianPosition : this.formation.QuerySystem.Team.MedianTargetFormationPosition; vec2_1 = this.formation.QuerySystem.Team.MedianTargetFormationPosition.AsVec2 - this.formation.QuerySystem.AveragePosition; Vec2 direction = vec2_1.Normalized(); this.CurrentOrder = MovementOrder.MovementOrderMove(position); this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtDirection(direction); } }
protected override void CalculateCurrentOrder() { if (this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation == null || (double)this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.MedianPosition.AsVec2.DistanceSquared(this.formation.QuerySystem.AveragePosition) > 2500.0) { this.CurrentOrder = this.UncapturedFlagMoveOrder(); this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtEnemy; } else { FlagCapturePoint flagCapturePoint = (FlagCapturePoint)null; if (this._flagpositions.Any <FlagCapturePoint>((Func <FlagCapturePoint, bool>)(fp => this._flagDominationGameMode.GetFlagOwnerTeam(fp) != this.formation.Team && !fp.IsContested))) { flagCapturePoint = this._flagpositions.Where <FlagCapturePoint>((Func <FlagCapturePoint, bool>)(fp => this._flagDominationGameMode.GetFlagOwnerTeam(fp) != this.formation.Team && !fp.IsContested)).MinBy <FlagCapturePoint, float>((Func <FlagCapturePoint, float>)(fp => this.formation.QuerySystem.AveragePosition.DistanceSquared(fp.Position.AsVec2))); } if (!this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.IsInfantryFormation && flagCapturePoint != null) { this.CurrentOrder = MovementOrder.MovementOrderMove(new WorldPosition(Mission.Current.Scene, UIntPtr.Zero, flagCapturePoint.Position, false)); this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtEnemy; } else if (this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.IsRangedFormation) { this.CurrentOrder = MovementOrder.MovementOrderChargeToTarget(this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.Formation); this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtEnemy; } else { Vec2 direction = this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.MedianPosition.AsVec2 - this.formation.QuerySystem.AveragePosition; float num = direction.Normalize(); WorldPosition medianPosition = this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.MedianPosition; if ((double)num > (double)this.formation.QuerySystem.MissileRange) { medianPosition.SetVec2(medianPosition.AsVec2 - direction * (this.formation.QuerySystem.MissileRange - this.formation.Depth * 0.5f)); } else if ((double)num < (double)this.formation.QuerySystem.MissileRange * 0.400000005960464) { medianPosition.SetVec2(medianPosition.AsVec2 - direction * (this.formation.QuerySystem.MissileRange * 0.7f)); } else { direction = direction.RightVec(); medianPosition.SetVec2(this.formation.QuerySystem.AveragePosition + direction * 20f); } this.CurrentOrder = MovementOrder.MovementOrderMove(medianPosition); this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtDirection(direction); } } }
protected override void CalculateCurrentOrder() { Vec2 direction = this.TacticalDefendPosition == null ? (this.formation.QuerySystem.ClosestEnemyFormation != null ? ((double)this.formation.Direction.DotProduct((this.formation.QuerySystem.ClosestEnemyFormation.MedianPosition.AsVec2 - this.formation.QuerySystem.AveragePosition).Normalized()) < 0.5 ? this.formation.QuerySystem.ClosestEnemyFormation.MedianPosition.AsVec2 - this.formation.QuerySystem.AveragePosition : this.formation.Direction).Normalized() : this.formation.Direction) : this.TacticalDefendPosition.Direction; if (this.TacticalDefendPosition != null) { this.CurrentOrder = MovementOrder.MovementOrderMove(this.TacticalDefendPosition.Position); this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtDirection(direction); } else { WorldPosition medianPosition = this.formation.QuerySystem.MedianPosition; medianPosition.SetVec2(this.formation.QuerySystem.AveragePosition); this.CurrentOrder = MovementOrder.MovementOrderMove(medianPosition); this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtDirection(direction); } }
private void ResetOrderPositions() { this._primarySiegeWeapons = Mission.Current.ActiveMissionObjects.FindAllWithType <UsableMachine>().Where <UsableMachine>((Func <UsableMachine, bool>)(amo => amo is IPrimarySiegeWeapon)).Select <UsableMachine, IPrimarySiegeWeapon>((Func <UsableMachine, IPrimarySiegeWeapon>)(amo => amo as IPrimarySiegeWeapon)).ToList <IPrimarySiegeWeapon>(); this._primarySiegeWeapons.RemoveAll((Predicate <IPrimarySiegeWeapon>)(uM => uM.WeaponSide != this.behaviorSide)); IEnumerable <ICastleKeyPosition> source = TeamAISiegeComponent.SiegeLanes.Where <SiegeLane>((Func <SiegeLane, bool>)(sl => sl.LaneSide == this.behaviorSide)).SelectMany <SiegeLane, ICastleKeyPosition>((Func <SiegeLane, IEnumerable <ICastleKeyPosition> >)(sila => (IEnumerable <ICastleKeyPosition>)sila.DefensePoints)); this._innerGate = this._teamAISiegeComponent.InnerGate; this._isGateLane = this._teamAISiegeComponent.OuterGate.DefenseSide == this.behaviorSide; this._wallSegment = !this._isGateLane ? (!(source.FirstOrDefault <ICastleKeyPosition>((Func <ICastleKeyPosition, bool>)(dp => dp is WallSegment && (dp as WallSegment).IsBreachedWall)) is WallSegment wallSegment) ? this._primarySiegeWeapons.MaxBy <IPrimarySiegeWeapon, float>((Func <IPrimarySiegeWeapon, float>)(psw => psw.SiegeWeaponPriority)).TargetCastlePosition as WallSegment : wallSegment) : (WallSegment)null; this._stopOrder = MovementOrder.MovementOrderStop; this._chargeOrder = MovementOrder.MovementOrderCharge; bool flag = this._teamAISiegeComponent.OuterGate != null && this.behaviorSide == this._teamAISiegeComponent.OuterGate.DefenseSide; this._attackEntityOrderOuterGate = !flag || this._teamAISiegeComponent.OuterGate.IsDeactivated || this._teamAISiegeComponent.OuterGate.State == CastleGate.GateState.Open ? MovementOrder.MovementOrderStop : MovementOrder.MovementOrderAttackEntity(this._teamAISiegeComponent.OuterGate.GameEntity, false); this._attackEntityOrderInnerGate = !flag || this._teamAISiegeComponent.InnerGate == null || (this._teamAISiegeComponent.InnerGate.IsDeactivated || this._teamAISiegeComponent.InnerGate.State == CastleGate.GateState.Open) ? MovementOrder.MovementOrderStop : MovementOrder.MovementOrderAttackEntity(this._teamAISiegeComponent.InnerGate.GameEntity, false); this._castleGateMoveOrder = MovementOrder.MovementOrderMove(this._teamAISiegeComponent.OuterGate.MiddleFrame.Origin); this._wallSegmentMoveOrder = !this._isGateLane ? MovementOrder.MovementOrderMove(this._wallSegment.MiddleFrame.Origin) : this._castleGateMoveOrder; this._facingOrder = FacingOrder.FacingOrderLookAtEnemy; }
protected override void CalculateCurrentOrder() { Vec2 direction; WorldPosition medianPosition; if (this._mainFormation != null) { direction = this._mainFormation.Direction; Vec2 vec2 = (this.formation.QuerySystem.Team.MedianTargetFormationPosition.AsVec2 - this._mainFormation.QuerySystem.MedianPosition.AsVec2).Normalized(); medianPosition = this._mainFormation.QuerySystem.MedianPosition; medianPosition.SetVec2(this._mainFormation.CurrentPosition + vec2 * (float)(((double)this._mainFormation.Depth + (double)this.formation.Depth) * 0.5 + 10.0)); } else { direction = this.formation.Direction; medianPosition = this.formation.QuerySystem.MedianPosition; medianPosition.SetVec2(this.formation.QuerySystem.AveragePosition); } this.CurrentOrder = MovementOrder.MovementOrderMove(medianPosition); this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtDirection(direction); }
protected override void CalculateCurrentOrder() { if (this._mainFormation == null || this.formation.AI.IsMainFormation || this.formation.QuerySystem.ClosestEnemyFormation == null) { this.CurrentOrder = MovementOrder.MovementOrderStop; this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtEnemy; } else { if (this._protectFlankState != BehaviorProtectFlank.BehaviourState.HoldingFlank && this._protectFlankState != BehaviorProtectFlank.BehaviourState.Returning) { return; } Vec2 direction = this._mainFormation.Direction; Vec2 vec2_1 = (this.formation.QuerySystem.Team.MedianTargetFormationPosition.AsVec2 - this._mainFormation.QuerySystem.MedianPosition.AsVec2).Normalized(); Vec2 vec2_2 = this.behaviorSide == FormationAI.BehaviorSide.Right || this.FlankSide == FormationAI.BehaviorSide.Right ? this._mainFormation.CurrentPosition + vec2_1.RightVec().Normalized() * (float)((double)this._mainFormation.Width + (double)this.formation.Width + 10.0) - vec2_1 * (this._mainFormation.Depth + this.formation.Depth) : (this.behaviorSide == FormationAI.BehaviorSide.Left || this.FlankSide == FormationAI.BehaviorSide.Left ? this._mainFormation.CurrentPosition + vec2_1.LeftVec().Normalized() * (float)((double)this._mainFormation.Width + (double)this.formation.Width + 10.0) - vec2_1 * (this._mainFormation.Depth + this.formation.Depth) : this._mainFormation.CurrentPosition + vec2_1 * (float)(((double)this._mainFormation.Depth + (double)this.formation.Depth) * 0.5 + 10.0)); WorldPosition medianPosition = this._mainFormation.QuerySystem.MedianPosition; medianPosition.SetVec2(vec2_2); this._movementOrder = MovementOrder.MovementOrderMove(medianPosition); this.CurrentOrder = this._movementOrder; this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtDirection(direction); } }
protected override void CalculateCurrentOrder() { BehaviorSergeantMPInfantry.BehaviorState behaviorState = this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation == null || (!this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.IsRangedFormation || (double)this.formation.QuerySystem.AveragePosition.DistanceSquared(this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.MedianPosition.AsVec2) > (this._behaviorState == BehaviorSergeantMPInfantry.BehaviorState.Attacking ? 3600.0 : 2500.0)) && (!this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.IsInfantryFormation || (double)this.formation.QuerySystem.AveragePosition.DistanceSquared(this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.MedianPosition.AsVec2) > (this._behaviorState == BehaviorSergeantMPInfantry.BehaviorState.Attacking ? 900.0 : 400.0)) ? BehaviorSergeantMPInfantry.BehaviorState.GoingToFlag : BehaviorSergeantMPInfantry.BehaviorState.Attacking; if (behaviorState == BehaviorSergeantMPInfantry.BehaviorState.Attacking && (this._behaviorState != BehaviorSergeantMPInfantry.BehaviorState.Attacking || this.CurrentOrder.OrderEnum != MovementOrder.MovementOrderEnum.ChargeToTarget || this.CurrentOrder.TargetFormation.QuerySystem != this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation)) { this._behaviorState = BehaviorSergeantMPInfantry.BehaviorState.Attacking; this.CurrentOrder = MovementOrder.MovementOrderChargeToTarget(this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.Formation); } if (behaviorState != BehaviorSergeantMPInfantry.BehaviorState.GoingToFlag) { return; } this._behaviorState = behaviorState; WorldPosition position; if (this._flagpositions.Any <FlagCapturePoint>((Func <FlagCapturePoint, bool>)(fp => this._flagDominationGameMode.GetFlagOwnerTeam(fp) != this.formation.Team))) { position = new WorldPosition(Mission.Current.Scene, UIntPtr.Zero, this._flagpositions.Where <FlagCapturePoint>((Func <FlagCapturePoint, bool>)(fp => this._flagDominationGameMode.GetFlagOwnerTeam(fp) != this.formation.Team)).MinBy <FlagCapturePoint, float>((Func <FlagCapturePoint, float>)(fp => fp.Position.AsVec2.DistanceSquared(this.formation.QuerySystem.AveragePosition))).Position, false); } else if (this._flagpositions.Any <FlagCapturePoint>((Func <FlagCapturePoint, bool>)(fp => this._flagDominationGameMode.GetFlagOwnerTeam(fp) == this.formation.Team))) { position = new WorldPosition(Mission.Current.Scene, UIntPtr.Zero, this._flagpositions.Where <FlagCapturePoint>((Func <FlagCapturePoint, bool>)(fp => this._flagDominationGameMode.GetFlagOwnerTeam(fp) == this.formation.Team)).MinBy <FlagCapturePoint, float>((Func <FlagCapturePoint, float>)(fp => fp.Position.AsVec2.DistanceSquared(this.formation.QuerySystem.AveragePosition))).Position, false); } else { position = this.formation.QuerySystem.MedianPosition; position.SetVec2(this.formation.QuerySystem.AveragePosition); } if (this.CurrentOrder.OrderEnum != MovementOrder.MovementOrderEnum.Invalid && !(this.CurrentOrder.GetPosition(this.formation).AsVec2 != position.AsVec2)) { return; } Vec2 direction = this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation != null ? (this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.MedianPosition.AsVec2 - this.formation.QuerySystem.AveragePosition).Normalized() : this.formation.Direction; this.CurrentOrder = MovementOrder.MovementOrderMove(position); this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtDirection(direction); }
protected override void CalculateCurrentOrder() { WorldPosition medianPosition = this.formation.QuerySystem.MedianPosition; bool flag = false; Vec2 vec2_1; WorldPosition worldPosition; Vec2 vec2_2; if (this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation == null || this._archerFormation == null) { vec2_1 = this.formation.Direction; medianPosition.SetVec2(this.formation.QuerySystem.AveragePosition); } else { worldPosition = this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.MedianPosition; vec2_1 = worldPosition.AsVec2 - this.formation.QuerySystem.AveragePosition; float val2 = vec2_1.Normalize(); float num = this._archerFormation.QuerySystem.RangedUnitRatio * 0.5f / (float)this._archerFormation.arrangement.RankCount; switch (this._behaviorState) { case BehaviorCautiousAdvance.BehaviorState.Approaching: if ((double)val2 < (double)this._cantShootDistance * 0.800000011920929) { this._behaviorState = BehaviorCautiousAdvance.BehaviorState.Shooting; this._cantShoot = false; flag = true; } else if ((double)this._archerFormation.QuerySystem.MakingRangedAttackRatio >= (double)num * 1.20000004768372) { this._behaviorState = BehaviorCautiousAdvance.BehaviorState.Shooting; this._cantShoot = false; flag = true; } if (this._behaviorState == BehaviorCautiousAdvance.BehaviorState.Shooting) { this._shootPosition = this.formation.QuerySystem.AveragePosition + vec2_1 * 5f; break; } break; case BehaviorCautiousAdvance.BehaviorState.Shooting: if ((double)this._archerFormation.QuerySystem.MakingRangedAttackRatio <= (double)num) { if ((double)val2 > (double)this._archerFormation.QuerySystem.MissileRange) { this._behaviorState = BehaviorCautiousAdvance.BehaviorState.Approaching; this._cantShootDistance = Math.Min(this._cantShootDistance, this._archerFormation.QuerySystem.MissileRange * 0.9f); this._shootPosition = Vec2.Invalid; break; } if (!this._cantShoot) { this._cantShoot = true; this._cantShootTimer.Reset(Mission.Current.Time, this._archerFormation == null ? 10f : MBMath.Lerp(10f, 15f, (float)(((double)MBMath.ClampFloat((float)this._archerFormation.CountOfUnits, 10f, 60f) - 10.0) * 0.0199999995529652))); break; } if (this._cantShootTimer.Check(Mission.Current.Time)) { this._behaviorState = BehaviorCautiousAdvance.BehaviorState.Approaching; this._cantShootDistance = Math.Min(this._cantShootDistance, val2); this._shootPosition = Vec2.Invalid; break; } break; } this._cantShootDistance = Math.Max(this._cantShootDistance, val2); this._cantShoot = false; if ((!this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.IsRangedFormation && !this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.IsRangedCavalryFormation || (double)val2 < (double)this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.MissileRange && (double)this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.MakingRangedAttackRatio < 0.100000001490116) && (double)val2 < (double)Math.Min(this._archerFormation.QuerySystem.MissileRange * 0.4f, this._cantShootDistance * 0.667f)) { this._behaviorState = BehaviorCautiousAdvance.BehaviorState.PullingBack; this._shootPosition = Vec2.Invalid; break; } break; case BehaviorCautiousAdvance.BehaviorState.PullingBack: if ((double)val2 > (double)Math.Min(this._cantShootDistance, this._archerFormation.QuerySystem.MissileRange) * 0.800000011920929) { this._behaviorState = BehaviorCautiousAdvance.BehaviorState.Shooting; this._cantShoot = false; this._shootPosition = this.formation.QuerySystem.AveragePosition + vec2_1 * 5f; flag = true; break; } break; } switch (this._behaviorState) { case BehaviorCautiousAdvance.BehaviorState.Approaching: medianPosition = this.formation.QuerySystem.ClosestEnemyFormation.MedianPosition; if (this._switchedToShieldWallRecently && !this._switchedToShieldWallTimer.Check(Mission.Current.Time) && (double)this.formation.QuerySystem.FormationDispersedness > 2.0) { if (this._reformPosition.IsValid) { medianPosition.SetVec2(this._reformPosition); break; } worldPosition = this.formation.QuerySystem.Team.MedianTargetFormationPosition; vec2_2 = worldPosition.AsVec2 - this.formation.QuerySystem.AveragePosition; vec2_1 = vec2_2.Normalized(); this._reformPosition = this.formation.QuerySystem.AveragePosition + vec2_1 * 5f; medianPosition.SetVec2(this._reformPosition); break; } this._switchedToShieldWallRecently = false; this._reformPosition = Vec2.Invalid; medianPosition.SetVec2(this.formation.QuerySystem.ClosestEnemyFormation.AveragePosition); break; case BehaviorCautiousAdvance.BehaviorState.Shooting: if (this._shootPosition.IsValid) { medianPosition.SetVec2(this._shootPosition); break; } medianPosition.SetVec2(this.formation.QuerySystem.AveragePosition); break; case BehaviorCautiousAdvance.BehaviorState.PullingBack: medianPosition = this.formation.QuerySystem.MedianPosition; medianPosition.SetVec2(this.formation.QuerySystem.AveragePosition); break; } } worldPosition = this.CurrentOrder.GetPosition(this.formation); if (((!worldPosition.IsValid ? 1 : (this._behaviorState != BehaviorCautiousAdvance.BehaviorState.Shooting ? 1 : 0)) | (flag ? 1 : 0)) == 0) { worldPosition = this.CurrentOrder.GetPosition(this.formation); if ((double)worldPosition.GetNavMeshVec3().DistanceSquared(medianPosition.GetNavMeshVec3()) < (double)this.formation.Depth * (double)this.formation.Depth) { goto label_34; } } this.CurrentOrder = MovementOrder.MovementOrderMove(medianPosition); label_34: vec2_2 = this.CurrentFacingOrder.GetDirection(this.formation); if (vec2_2.IsValid && !(this._behaviorState != BehaviorCautiousAdvance.BehaviorState.Shooting | flag)) { vec2_2 = this.CurrentFacingOrder.GetDirection(this.formation); if ((double)vec2_2.DotProduct(vec2_1) > (double)MBMath.Lerp(0.5f, 1f, (float)(1.0 - (double)MBMath.ClampFloat(this.formation.Width, 1f, 20f) * 0.0500000007450581))) { return; } } this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtDirection(vec2_1); }
protected override void CalculateCurrentOrder() { List <Formation> list = this.formation.Team.QuerySystem.EnemyTeams.SelectMany <TeamQuerySystem, Formation>((Func <TeamQuerySystem, IEnumerable <Formation> >)(t => t.Team.Formations)).ToList <Formation>(); if (this.formation.Team.Formations.Any <Formation>((Func <Formation, bool>)(f => f != this.formation && f.QuerySystem.IsInfantryFormation))) { this._attachedInfantry = this.formation.Team.Formations.Where <Formation>((Func <Formation, bool>)(f => f != this.formation && f.QuerySystem.IsInfantryFormation)).MinBy <Formation, float>((Func <Formation, float>)(f => f.QuerySystem.MedianPosition.AsVec2.DistanceSquared(this.formation.QuerySystem.AveragePosition))); Formation formation = (Formation)null; if (list.Any <Formation>()) { if ((double)this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.MedianPosition.AsVec2.DistanceSquared(this.formation.QuerySystem.AveragePosition) <= 4900.0) { formation = this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.Formation; } else if (list.Any <Formation>((Func <Formation, bool>)(ef => ef.QuerySystem.IsCavalryFormation || ef.QuerySystem.IsRangedCavalryFormation))) { formation = list.Where <Formation>((Func <Formation, bool>)(ef => ef.QuerySystem.IsCavalryFormation || ef.QuerySystem.IsRangedCavalryFormation)).MinBy <Formation, float>((Func <Formation, float>)(ecf => ecf.QuerySystem.MedianPosition.AsVec2.DistanceSquared(this.formation.QuerySystem.AveragePosition))); } } Vec2 vec2; if (formation != null) { WorldPosition medianPosition = formation.QuerySystem.MedianPosition; Vec2 asVec2_1 = medianPosition.AsVec2; medianPosition = this._attachedInfantry.QuerySystem.MedianPosition; Vec2 asVec2_2 = medianPosition.AsVec2; vec2 = (asVec2_1 - asVec2_2).Normalized(); } else { vec2 = this._attachedInfantry.Direction; } Vec2 direction = vec2; WorldPosition medianPosition1 = this._attachedInfantry.QuerySystem.MedianPosition; medianPosition1.SetVec2(medianPosition1.AsVec2 - direction * (float)(((double)this._attachedInfantry.Depth + (double)this.formation.Depth) / 2.0)); this.CurrentOrder = MovementOrder.MovementOrderMove(medianPosition1); this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtDirection(direction); } else if (this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation != null && (double)this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.MedianPosition.AsVec2.DistanceSquared(this.formation.QuerySystem.AveragePosition) <= 4900.0) { Vec2 direction = (this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.MedianPosition.AsVec2 - this.formation.QuerySystem.AveragePosition).Normalized(); float num = this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.MedianPosition.AsVec2.Distance(this.formation.QuerySystem.AveragePosition); WorldPosition medianPosition = this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.MedianPosition; if ((double)num > (double)this.formation.QuerySystem.MissileRange) { medianPosition.SetVec2(medianPosition.AsVec2 - direction * (this.formation.QuerySystem.MissileRange - this.formation.Depth * 0.5f)); } else if ((double)num < (double)this.formation.QuerySystem.MissileRange * 0.400000005960464) { medianPosition.SetVec2(medianPosition.AsVec2 - direction * (this.formation.QuerySystem.MissileRange * 0.4f)); } else { medianPosition.SetVec2(this.formation.QuerySystem.AveragePosition); } this.CurrentOrder = MovementOrder.MovementOrderMove(medianPosition); this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtDirection(direction); } else if (this._flagpositions.Any <FlagCapturePoint>((Func <FlagCapturePoint, bool>)(fp => this._flagDominationGameMode.GetFlagOwnerTeam(fp) != this.formation.Team))) { Vec3 position = this._flagpositions.Where <FlagCapturePoint>((Func <FlagCapturePoint, bool>)(fp => this._flagDominationGameMode.GetFlagOwnerTeam(fp) != this.formation.Team)).MinBy <FlagCapturePoint, float>((Func <FlagCapturePoint, float>)(fp => fp.Position.AsVec2.DistanceSquared(this.formation.QuerySystem.AveragePosition))).Position; WorldPosition worldPosition; if (this.CurrentOrder.OrderEnum != MovementOrder.MovementOrderEnum.Invalid) { worldPosition = this.CurrentOrder.GetPosition(this.formation); if (!(worldPosition.AsVec2 != position.AsVec2)) { return; } } Vec2 direction; if (this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation == null) { direction = this.formation.Direction; } else { worldPosition = this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.MedianPosition; direction = (worldPosition.AsVec2 - this.formation.QuerySystem.AveragePosition).Normalized(); } this.CurrentOrder = MovementOrder.MovementOrderMove(new WorldPosition(Mission.Current.Scene, UIntPtr.Zero, position, false)); this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtDirection(direction); } else if (this._flagpositions.Any <FlagCapturePoint>((Func <FlagCapturePoint, bool>)(fp => this._flagDominationGameMode.GetFlagOwnerTeam(fp) == this.formation.Team))) { Vec3 position = this._flagpositions.Where <FlagCapturePoint>((Func <FlagCapturePoint, bool>)(fp => this._flagDominationGameMode.GetFlagOwnerTeam(fp) == this.formation.Team)).MinBy <FlagCapturePoint, float>((Func <FlagCapturePoint, float>)(fp => fp.Position.AsVec2.DistanceSquared(this.formation.QuerySystem.AveragePosition))).Position; this.CurrentOrder = MovementOrder.MovementOrderMove(new WorldPosition(Mission.Current.Scene, UIntPtr.Zero, position, false)); this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtEnemy; } else { WorldPosition medianPosition = this.formation.QuerySystem.MedianPosition; medianPosition.SetVec2(this.formation.QuerySystem.AveragePosition); this.CurrentOrder = MovementOrder.MovementOrderMove(medianPosition); this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtEnemy; } }
private void ResetOrderPositions() { this.behaviorSide = this.formation.AI.Side; this._innerGate = (CastleGate)null; this._outerGate = (CastleGate)null; this._laddersOnThisSide.Clear(); int num1 = Mission.Current.ActiveMissionObjects.FindAllWithType <CastleGate>().Any <CastleGate>((Func <CastleGate, bool>)(cg => cg.DefenseSide == this.behaviorSide && cg.GameEntity.HasTag("outer_gate"))) ? 1 : 0; this._isDefendingWideGap = false; WorldFrame worldFrame1; WorldFrame worldFrame2; if (num1 != 0) { CastleGate outerGate = this._teamAISiegeDefender.OuterGate; this._innerGate = this._teamAISiegeDefender.InnerGate; this._outerGate = this._teamAISiegeDefender.OuterGate; worldFrame1 = outerGate.MiddleFrame; worldFrame2 = outerGate.DefenseWaitFrame; this._tacticalMiddlePos = outerGate.MiddlePosition; this._tacticalWaitPos = outerGate.WaitPosition; this._isDefendingWideGap = false; } else { WallSegment wallSegment = Mission.Current.ActiveMissionObjects.FindAllWithType <WallSegment>().Where <WallSegment>((Func <WallSegment, bool>)(ws => ws.DefenseSide == this.behaviorSide && ws.IsBreachedWall)).FirstOrDefault <WallSegment>(); if (wallSegment != null) { worldFrame1 = wallSegment.MiddleFrame; worldFrame2 = wallSegment.DefenseWaitFrame; this._tacticalMiddlePos = wallSegment.MiddlePosition; this._tacticalWaitPos = wallSegment.WaitPosition; this._isDefendingWideGap = false; } else { IEnumerable <SiegeWeapon> source = Mission.Current.ActiveMissionObjects.FindAllWithType <SiegeWeapon>().Where <SiegeWeapon>((Func <SiegeWeapon, bool>)(sw => { if (!(sw is IPrimarySiegeWeapon) || (sw as IPrimarySiegeWeapon).WeaponSide != this.behaviorSide) { return(false); } return(!sw.IsDestroyed || (sw as IPrimarySiegeWeapon).HasCompletedAction()); })); if (!source.Any <SiegeWeapon>()) { worldFrame1 = WorldFrame.Invalid; worldFrame2 = WorldFrame.Invalid; this._tacticalMiddlePos = (TacticalPosition)null; this._tacticalWaitPos = (TacticalPosition)null; } else { this._laddersOnThisSide = source.Where <SiegeWeapon>((Func <SiegeWeapon, bool>)(aw => aw is SiegeLadder)).Select <SiegeWeapon, SiegeLadder>((Func <SiegeWeapon, SiegeLadder>)(aw => aw as SiegeLadder)).ToList <SiegeLadder>(); ICastleKeyPosition targetCastlePosition = (source.FirstOrDefault <SiegeWeapon>() as IPrimarySiegeWeapon).TargetCastlePosition as ICastleKeyPosition; worldFrame1 = targetCastlePosition.MiddleFrame; worldFrame2 = targetCastlePosition.DefenseWaitFrame; this._tacticalMiddlePos = targetCastlePosition.MiddlePosition; this._tacticalWaitPos = targetCastlePosition.WaitPosition; } } } if (this._tacticalMiddlePos != null) { this._readyOrder = MovementOrder.MovementOrderMove(this._tacticalMiddlePos.Position); this._readyFacingOrder = FacingOrder.FacingOrderLookAtDirection(this._tacticalMiddlePos.Direction); } else if (worldFrame1.Origin.IsValid) { double num2 = (double)worldFrame1.Rotation.f.Normalize(); this._readyOrder = MovementOrder.MovementOrderMove(worldFrame1.Origin); this._readyFacingOrder = FacingOrder.FacingOrderLookAtDirection(worldFrame1.Rotation.f.AsVec2); } else { this._readyOrder = MovementOrder.MovementOrderStop; this._readyFacingOrder = FacingOrder.FacingOrderLookAtEnemy; } if (this._tacticalWaitPos != null) { this._waitOrder = MovementOrder.MovementOrderMove(this._tacticalWaitPos.Position); this._waitFacingOrder = FacingOrder.FacingOrderLookAtDirection(this._tacticalWaitPos.Direction); } else if (worldFrame2.Origin.IsValid) { double num2 = (double)worldFrame2.Rotation.f.Normalize(); this._waitOrder = MovementOrder.MovementOrderMove(worldFrame2.Origin); this._waitFacingOrder = FacingOrder.FacingOrderLookAtDirection(worldFrame2.Rotation.f.AsVec2); } else { this._waitOrder = MovementOrder.MovementOrderStop; this._waitFacingOrder = FacingOrder.FacingOrderLookAtEnemy; } this.CurrentOrder = this._behaviourState == BehaviorDefendCastleKeyPosition.BehaviourState.Ready ? this._readyOrder : this._waitOrder; this.CurrentFacingOrder = this.formation.QuerySystem.ClosestEnemyFormation == null || !TeamAISiegeComponent.IsFormationInsideCastle(this.formation.QuerySystem.ClosestEnemyFormation.Formation, true) ? (this._behaviourState == BehaviorDefendCastleKeyPosition.BehaviourState.Ready ? this._readyFacingOrder : this._waitFacingOrder) : FacingOrder.FacingOrderLookAtEnemy; }
protected override void CalculateCurrentOrder() { if (this.formation.QuerySystem.ClosestEnemyFormation == null) { this.CurrentOrder = MovementOrder.MovementOrderCharge; } else { BehaviorTacticalCharge.ChargeState chargeState = this.CheckAndChangeState(); if (chargeState != this._chargeState) { this._chargeState = chargeState; switch (this._chargeState) { case BehaviorTacticalCharge.ChargeState.Undetermined: this.CurrentOrder = MovementOrder.MovementOrderCharge; break; case BehaviorTacticalCharge.ChargeState.Charging: this._lastTarget = this.formation.QuerySystem.ClosestEnemyFormation; if (this.formation.QuerySystem.IsCavalryFormation || this.formation.QuerySystem.IsRangedCavalryFormation) { this._initialChargeDirection = this._lastTarget.MedianPosition.AsVec2 - this.formation.QuerySystem.AveragePosition; this._desiredChargeStopDistance = MBMath.ClampFloat(this._initialChargeDirection.Normalize(), 20f, 50f); break; } break; case BehaviorTacticalCharge.ChargeState.ChargingPast: this._chargingPastTimer = new Timer(MBCommon.GetTime(MBCommon.TimeType.Mission), 5f); break; case BehaviorTacticalCharge.ChargeState.Reforming: this._reformTimer = new Timer(MBCommon.GetTime(MBCommon.TimeType.Mission), 2f); break; case BehaviorTacticalCharge.ChargeState.Bracing: this._bracePosition = this.formation.QuerySystem.AveragePosition + (this.formation.QuerySystem.Team.MedianTargetFormationPosition.AsVec2 - this.formation.QuerySystem.AveragePosition).Normalized() * 5f; break; } } switch (this._chargeState) { case BehaviorTacticalCharge.ChargeState.Undetermined: if (this.formation.QuerySystem.ClosestEnemyFormation != null && (this.formation.QuerySystem.IsCavalryFormation || this.formation.QuerySystem.IsRangedCavalryFormation)) { this.CurrentOrder = MovementOrder.MovementOrderMove(this.formation.QuerySystem.ClosestEnemyFormation.MedianPosition); } else { this.CurrentOrder = MovementOrder.MovementOrderCharge; } this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtEnemy; break; case BehaviorTacticalCharge.ChargeState.Charging: if (!this.formation.QuerySystem.IsCavalryFormation && !this.formation.QuerySystem.IsRangedCavalryFormation) { this.CurrentOrder = MovementOrder.MovementOrderMove(this.formation.QuerySystem.ClosestEnemyFormation.MedianPosition); this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtEnemy; break; } Vec2 direction1 = (this._lastTarget.MedianPosition.AsVec2 - this.formation.QuerySystem.AveragePosition).Normalized(); WorldPosition medianPosition1 = this._lastTarget.MedianPosition; Vec2 vec2 = medianPosition1.AsVec2 + direction1 * this._desiredChargeStopDistance; medianPosition1.SetVec2(vec2); this.CurrentOrder = MovementOrder.MovementOrderMove(medianPosition1); this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtDirection(direction1); break; case BehaviorTacticalCharge.ChargeState.ChargingPast: Vec2 averagePosition = this.formation.QuerySystem.AveragePosition; WorldPosition medianPosition2 = this._lastTarget.MedianPosition; Vec2 asVec2 = medianPosition2.AsVec2; Vec2 direction2 = averagePosition - asVec2; if ((double)direction2.Normalize() <= 20.0) { Vec2 initialChargeDirection = this._initialChargeDirection; } this._lastReformDestination = this._lastTarget.MedianPosition; medianPosition2 = this._lastTarget.MedianPosition; this._lastReformDestination.SetVec2(medianPosition2.AsVec2 + direction2 * this._desiredChargeStopDistance); this.CurrentOrder = MovementOrder.MovementOrderMove(this._lastReformDestination); this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtDirection(direction2); break; case BehaviorTacticalCharge.ChargeState.Reforming: this.CurrentOrder = MovementOrder.MovementOrderMove(this._lastReformDestination); this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtEnemy; break; case BehaviorTacticalCharge.ChargeState.Bracing: WorldPosition medianPosition3 = this.formation.QuerySystem.MedianPosition; medianPosition3.SetVec2(this._bracePosition); this.CurrentOrder = MovementOrder.MovementOrderMove(medianPosition3); break; } } }
protected override void CalculateCurrentOrder() { WorldPosition medianPosition = this.formation.QuerySystem.MedianPosition; bool flag = false; Vec2 direction; WorldPosition worldPosition; if (this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation == null) { direction = this.formation.Direction; medianPosition.SetVec2(this.formation.QuerySystem.AveragePosition); } else { worldPosition = this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.MedianPosition; direction = worldPosition.AsVec2 - this.formation.QuerySystem.AveragePosition; float val2 = direction.Normalize(); float num = MBMath.Lerp(0.1f, 0.33f, (float)(1.0 - (double)MBMath.ClampFloat((float)this.formation.CountOfUnits, 1f, 50f) * 0.0199999995529652)) * this.formation.QuerySystem.RangedUnitRatio; switch (this._behaviorState) { case BehaviorSkirmish.BehaviorState.Approaching: if ((double)val2 < (double)this._cantShootDistance * 0.800000011920929) { this._behaviorState = BehaviorSkirmish.BehaviorState.Shooting; this._cantShoot = false; flag = true; break; } if ((double)this.formation.QuerySystem.MakingRangedAttackRatio >= (double)num * 1.20000004768372) { this._behaviorState = BehaviorSkirmish.BehaviorState.Shooting; this._cantShoot = false; flag = true; break; } break; case BehaviorSkirmish.BehaviorState.Shooting: if ((double)this.formation.QuerySystem.MakingRangedAttackRatio <= (double)num) { if ((double)val2 > (double)this.formation.QuerySystem.MissileRange) { this._behaviorState = BehaviorSkirmish.BehaviorState.Approaching; this._cantShootDistance = Math.Min(this._cantShootDistance, this.formation.QuerySystem.MissileRange * 0.9f); break; } if (!this._cantShoot) { this._cantShoot = true; this._cantShootTimer.Reset(Mission.Current.Time, MBMath.Lerp(5f, 10f, (float)(((double)MBMath.ClampFloat((float)this.formation.CountOfUnits, 10f, 60f) - 10.0) * 0.0199999995529652))); break; } if (this._cantShootTimer.Check(Mission.Current.Time)) { this._behaviorState = BehaviorSkirmish.BehaviorState.Approaching; this._cantShootDistance = Math.Min(this._cantShootDistance, val2); break; } break; } this._cantShootDistance = Math.Max(this._cantShootDistance, val2); this._cantShoot = false; if (this.formation.QuerySystem.IsInfantryFormation && (double)val2 < (double)Math.Min(this.formation.QuerySystem.MissileRange * 0.4f, this._cantShootDistance * 0.666f)) { this._behaviorState = BehaviorSkirmish.BehaviorState.PullingBack; break; } break; case BehaviorSkirmish.BehaviorState.PullingBack: if ((double)val2 > (double)Math.Min(this._cantShootDistance, this.formation.QuerySystem.MissileRange) * 0.800000011920929) { this._behaviorState = BehaviorSkirmish.BehaviorState.Shooting; this._cantShoot = false; flag = true; break; } break; } switch (this._behaviorState) { case BehaviorSkirmish.BehaviorState.Approaching: medianPosition = this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.MedianPosition; medianPosition.SetVec2(this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.AveragePosition); break; case BehaviorSkirmish.BehaviorState.Shooting: medianPosition.SetVec2(this.formation.QuerySystem.AveragePosition); break; case BehaviorSkirmish.BehaviorState.PullingBack: medianPosition = this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.MedianPosition; medianPosition.SetVec2(medianPosition.AsVec2 - direction * (float)((double)this.formation.QuerySystem.MissileRange - (double)this.formation.Depth * 0.5 - 10.0)); break; } } worldPosition = this.CurrentOrder.GetPosition(this.formation); if (((!worldPosition.IsValid ? 1 : (this._behaviorState != BehaviorSkirmish.BehaviorState.Shooting ? 1 : 0)) | (flag ? 1 : 0)) != 0) { this.CurrentOrder = MovementOrder.MovementOrderMove(medianPosition); } if (((!this.CurrentFacingOrder.GetDirection(this.formation).IsValid ? 1 : (this._behaviorState != BehaviorSkirmish.BehaviorState.Shooting ? 1 : 0)) | (flag ? 1 : 0)) == 0) { return; } this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtDirection(direction); }