public static SiegeWeaponOrderType GetActiveOrderOf(SiegeWeapon weapon) { if (!weapon.ForcedUse) { return(SiegeWeaponOrderType.Stop); } if (!(weapon is RangedSiegeWeapon)) { return(SiegeWeaponOrderType.Attack); } switch (((RangedSiegeWeapon)weapon).Focus) { case RangedSiegeWeapon.FiringFocus.Troops: return(SiegeWeaponOrderType.FireAtTroops); case RangedSiegeWeapon.FiringFocus.Walls: return(SiegeWeaponOrderType.FireAtWalls); case RangedSiegeWeapon.FiringFocus.RangedSiegeWeapons: return(SiegeWeaponOrderType.FireAtRangedSiegeWeapons); case RangedSiegeWeapon.FiringFocus.PrimarySiegeWeapons: return(SiegeWeaponOrderType.FireAtPrimarySiegeWeapons); default: return(SiegeWeaponOrderType.FireAtTroops); } }
protected internal override void TickOccasionally() { base.TickOccasionally(); this._targetWeapons.RemoveAll((Predicate <SiegeWeapon>)(tw => tw.IsDestroyed)); if (this._targetWeapons.Count == 0) { this.DetermineTargetWeapons(); } if (this.formation.AI.ActiveBehavior != this) { return; } if (this._targetWeapons.Count == 0) { if (this.CurrentOrder != (object)MovementOrder.MovementOrderCharge) { this.CurrentOrder = MovementOrder.MovementOrderCharge; } this._isTargetPrimaryWeapon = false; } else { SiegeWeapon siegeWeapon = this._targetWeapons.MinBy <SiegeWeapon, float>((Func <SiegeWeapon, float>)(tw => this.formation.QuerySystem.AveragePosition.DistanceSquared(tw.GameEntity.GlobalPosition.AsVec2))); if (this.CurrentOrder.OrderEnum != MovementOrder.MovementOrderEnum.AttackEntity || this.LastTargetWeapon != siegeWeapon) { this.LastTargetWeapon = siegeWeapon; this.CurrentOrder = MovementOrder.MovementOrderAttackEntity(this.LastTargetWeapon.GameEntity, true); } } this.formation.MovementOrder = this.CurrentOrder; }
public int GetShortcutIndexOf(SiegeWeapon weapon) { int num1; switch (SiegeWeaponController.GetSideOf(weapon)) { case FormationAI.BehaviorSide.Left: num1 = 1; break; case FormationAI.BehaviorSide.Right: num1 = 2; break; default: num1 = 0; break; } int num2 = num1; if (!(weapon is IPrimarySiegeWeapon)) { num2 += 3; } return(num2); }
public void Deploy(SiegeWeapon s) { this.DeployedWeapon = (SynchedMissionObject)s; this.DisbandedWeapon = (SynchedMissionObject)null; this.OnDeploymentStateChangedAux((SynchedMissionObject)s); this.ToggleDeploymentPointVisibility(false); this.ToggleDeployedWeaponVisibility(true); }
private static FormationAI.BehaviorSide GetSideOf(SiegeWeapon weapon) { if (weapon is IPrimarySiegeWeapon primarySiegeWeapon) { return(primarySiegeWeapon.WeaponSide); } RangedSiegeWeapon rangedSiegeWeapon = weapon as RangedSiegeWeapon; return(FormationAI.BehaviorSide.Middle); }
private void ArrangeSiegeMachinesForNonAssaultMission() { foreach (GameEntity gameEntity in Mission.Current.GetActiveEntitiesWithScriptComponentOfType <SiegeWeapon>()) { SiegeWeapon firstScriptOfType = gameEntity.GetFirstScriptOfType <SiegeWeapon>(); SiegeEngineType siegeEngineType = firstScriptOfType.GetSiegeEngineType(); if (siegeEngineType != DefaultSiegeEngineTypes.Ballista && siegeEngineType != DefaultSiegeEngineTypes.FireBallista && (siegeEngineType != DefaultSiegeEngineTypes.Catapult && siegeEngineType != DefaultSiegeEngineTypes.FireCatapult) && (siegeEngineType != DefaultSiegeEngineTypes.Onager && siegeEngineType != DefaultSiegeEngineTypes.FireOnager)) { firstScriptOfType.Deactivate(); } } }
private void SetOrderAux(SiegeWeaponOrderType order, SiegeWeapon weapon) { switch (order) { case SiegeWeaponOrderType.Stop: case SiegeWeaponOrderType.AIControlOff: weapon.ForcedUse = false; break; case SiegeWeaponOrderType.Attack: case SiegeWeaponOrderType.AIControlOn: weapon.ForcedUse = true; break; case SiegeWeaponOrderType.FireAtWalls: weapon.ForcedUse = true; if (!(weapon is RangedSiegeWeapon rangedSiegeWeapon5)) { break; } rangedSiegeWeapon5.Focus = RangedSiegeWeapon.FiringFocus.Walls; break; case SiegeWeaponOrderType.FireAtTroops: weapon.ForcedUse = true; if (!(weapon is RangedSiegeWeapon rangedSiegeWeapon6)) { break; } rangedSiegeWeapon6.Focus = RangedSiegeWeapon.FiringFocus.Troops; break; case SiegeWeaponOrderType.FireAtRangedSiegeWeapons: weapon.ForcedUse = true; if (!(weapon is RangedSiegeWeapon rangedSiegeWeapon7)) { break; } rangedSiegeWeapon7.Focus = RangedSiegeWeapon.FiringFocus.RangedSiegeWeapons; break; case SiegeWeaponOrderType.FireAtPrimarySiegeWeapons: weapon.ForcedUse = true; if (!(weapon is RangedSiegeWeapon rangedSiegeWeapon8)) { break; } rangedSiegeWeapon8.Focus = RangedSiegeWeapon.FiringFocus.PrimarySiegeWeapons; break; } }
public void Deselect(SiegeWeapon weapon) { if (!this.SelectedWeapons.Contains(weapon)) { return; } if (GameNetwork.IsClient) { GameNetwork.BeginModuleEventAsClient(); GameNetwork.WriteMessage((GameNetworkMessage) new UnselectSiegeWeapon(weapon)); GameNetwork.EndModuleEventAsClient(); } this._selectedWeapons.Remove(weapon); Action siegeWeaponsChanged = this.OnSelectedSiegeWeaponsChanged; if (siegeWeaponsChanged == null) { return; } siegeWeaponsChanged(); }
public void Select(SiegeWeapon weapon) { if (this.SelectedWeapons.Contains(weapon) || !SiegeWeaponController.IsWeaponSelectable(weapon)) { return; } if (GameNetwork.IsClient) { GameNetwork.BeginModuleEventAsClient(); GameNetwork.WriteMessage((GameNetworkMessage) new SelectSiegeWeapon(weapon)); GameNetwork.EndModuleEventAsClient(); } this._selectedWeapons.Add(weapon); Action siegeWeaponsChanged = this.OnSelectedSiegeWeaponsChanged; if (siegeWeaponsChanged == null) { return; } siegeWeaponsChanged(); }
private void DefendSingleMainPosition() { if (this._mainInfantry != null) { this._mainInfantry.AI.ResetBehaviorWeights(); TacticComponent.SetDefaultBehaviorWeights(this._mainInfantry); if (this._destructableSiegeWeapons.FirstOrDefault <SiegeWeapon>((Func <SiegeWeapon, bool>)(dsw => dsw is IPrimarySiegeWeapon && dsw is IMoveableSiegeWeapon)) is IPrimarySiegeWeapon primarySiegeWeapon2) { this._mainInfantry.AI.SetBehaviorWeight <BehaviorDefendSiegeWeapon>(1f); BehaviorDefendSiegeWeapon behavior = this._mainInfantry.AI.GetBehavior <BehaviorDefendSiegeWeapon>(); behavior.SetDefensePositionFromTactic(this._teamAISallyOutDefender.CalculateSallyOutReferencePosition(primarySiegeWeapon2.WeaponSide).ToWorldPosition()); behavior.SetDefendedSiegeWeaponFromTactic(primarySiegeWeapon2 as SiegeWeapon); } else { if (this._destructableSiegeWeapons.Any <SiegeWeapon>((Func <SiegeWeapon, bool>)(dsw => !dsw.IsDisabled))) { SiegeWeapon siegeWeapon = this._destructableSiegeWeapons.Where <SiegeWeapon>((Func <SiegeWeapon, bool>)(dsw => !dsw.IsDisabled)).MinBy <SiegeWeapon, float>((Func <SiegeWeapon, float>)(dsw => dsw.GameEntity.GlobalPosition.AsVec2.DistanceSquared(this._mainInfantry.QuerySystem.AveragePosition))); this._mainInfantry.AI.ResetBehaviorWeights(); TacticComponent.SetDefaultBehaviorWeights(this._mainInfantry); this._mainInfantry.AI.SetBehaviorWeight <BehaviorDefendSiegeWeapon>(1f); BehaviorDefendSiegeWeapon behavior = this._mainInfantry.AI.GetBehavior <BehaviorDefendSiegeWeapon>(); behavior.SetDefensePositionFromTactic(siegeWeapon.GameEntity.GlobalPosition.ToWorldPosition()); behavior.SetDefendedSiegeWeaponFromTactic(siegeWeapon); } else { this._mainInfantry.AI.ResetBehaviorWeights(); TacticComponent.SetDefaultBehaviorWeights(this._mainInfantry); this._mainInfantry.AI.SetBehaviorWeight <BehaviorDefend>(1f); this._mainInfantry.AI.GetBehavior <BehaviorDefend>().DefensePosition = this._teamAISallyOutDefender.CalculateSallyOutReferencePosition(FormationAI.BehaviorSide.Middle).ToWorldPosition(); } this._mainInfantry.AI.SetBehaviorWeight <BehaviorTacticalCharge>(1f); } this._mainInfantry.AI.SetBehaviorWeight <BehaviorTacticalCharge>(1f); } if (this._archers != null) { this._archers.AI.ResetBehaviorWeights(); TacticComponent.SetDefaultBehaviorWeights(this._archers); this._archers.AI.SetBehaviorWeight <BehaviorSkirmishLine>(1f); this._archers.AI.SetBehaviorWeight <BehaviorScreenedSkirmish>(1f); this._archers.AI.SetBehaviorWeight <BehaviorSkirmish>(1f); } if (this._leftCavalry != null) { this._leftCavalry.AI.ResetBehaviorWeights(); TacticComponent.SetDefaultBehaviorWeights(this._leftCavalry); this._leftCavalry.AI.SetBehaviorWeight <BehaviorProtectFlank>(1f).FlankSide = FormationAI.BehaviorSide.Left; } if (this._rightCavalry != null) { this._rightCavalry.AI.ResetBehaviorWeights(); TacticComponent.SetDefaultBehaviorWeights(this._rightCavalry); this._rightCavalry.AI.SetBehaviorWeight <BehaviorProtectFlank>(1f).FlankSide = FormationAI.BehaviorSide.Right; } if (this._rangedCavalry == null) { return; } this._rangedCavalry.AI.ResetBehaviorWeights(); TacticComponent.SetDefaultBehaviorWeights(this._rangedCavalry); this._rangedCavalry.AI.SetBehaviorWeight <BehaviorMountedSkirmish>(1f); this._rangedCavalry.AI.SetBehaviorWeight <BehaviorHorseArcherSkirmish>(1f); }
private void DefendTwoMainPositions() { FormationAI.BehaviorSide infantrySide = FormationAI.BehaviorSide.BehaviorSideNotSet; if (this._mainInfantry != null) { this._mainInfantry.AI.ResetBehaviorWeights(); TacticComponent.SetDefaultBehaviorWeights(this._mainInfantry); this._mainInfantry.AI.SetBehaviorWeight <BehaviorDefendSiegeWeapon>(1f); BehaviorDefendSiegeWeapon behavior = this._mainInfantry.AI.GetBehavior <BehaviorDefendSiegeWeapon>(); SiegeWeapon siegeWeapon = this._destructableSiegeWeapons.FirstOrDefault <SiegeWeapon>((Func <SiegeWeapon, bool>)(dsw => dsw is IPrimarySiegeWeapon && dsw is IMoveableSiegeWeapon && (dsw as IPrimarySiegeWeapon).WeaponSide == FormationAI.BehaviorSide.Middle)); if (siegeWeapon != null) { infantrySide = FormationAI.BehaviorSide.Middle; } else { siegeWeapon = this._destructableSiegeWeapons.Where <SiegeWeapon>((Func <SiegeWeapon, bool>)(dsw => dsw is IPrimarySiegeWeapon && dsw is IMoveableSiegeWeapon)).MinBy <SiegeWeapon, float>((Func <SiegeWeapon, float>)(dsw => dsw.GameEntity.GlobalPosition.AsVec2.DistanceSquared(this._mainInfantry.QuerySystem.AveragePosition))); infantrySide = (siegeWeapon as IPrimarySiegeWeapon).WeaponSide; } behavior.SetDefensePositionFromTactic(this._teamAISallyOutDefender.CalculateSallyOutReferencePosition(infantrySide).ToWorldPosition()); behavior.SetDefendedSiegeWeaponFromTactic(siegeWeapon); this._mainInfantry.AI.SetBehaviorWeight <BehaviorTacticalCharge>(1f); } if (this._archers != null) { this._archers.AI.ResetBehaviorWeights(); TacticComponent.SetDefaultBehaviorWeights(this._archers); this._archers.AI.SetBehaviorWeight <BehaviorSkirmishLine>(1f); this._archers.AI.SetBehaviorWeight <BehaviorScreenedSkirmish>(1f); this._archers.AI.SetBehaviorWeight <BehaviorSkirmish>(1f); } if (this._cavalryFormation != null) { if (infantrySide != FormationAI.BehaviorSide.BehaviorSideNotSet) { this._cavalryFormation.AI.ResetBehaviorWeights(); TacticComponent.SetDefaultBehaviorWeights(this._cavalryFormation); this._cavalryFormation.AI.SetBehaviorWeight <BehaviorDefendSiegeWeapon>(1f); BehaviorDefendSiegeWeapon behavior = this._cavalryFormation.AI.GetBehavior <BehaviorDefendSiegeWeapon>(); SiegeWeapon siegeWeapon = this._destructableSiegeWeapons.FirstOrDefault <SiegeWeapon>((Func <SiegeWeapon, bool>)(dsw => dsw is IPrimarySiegeWeapon && (dsw as IPrimarySiegeWeapon).WeaponSide != infantrySide)); behavior.SetDefensePositionFromTactic(this._teamAISallyOutDefender.CalculateSallyOutReferencePosition(siegeWeapon == null ? (this._destructableSiegeWeapons.Where <SiegeWeapon>((Func <SiegeWeapon, bool>)(dsw => dsw is IPrimarySiegeWeapon && dsw is IMoveableSiegeWeapon)).MinBy <SiegeWeapon, float>((Func <SiegeWeapon, float>)(dsw => dsw.GameEntity.GlobalPosition.AsVec2.DistanceSquared(this._cavalryFormation.QuerySystem.AveragePosition))) as IPrimarySiegeWeapon).WeaponSide : (siegeWeapon as IPrimarySiegeWeapon).WeaponSide).ToWorldPosition()); behavior.SetDefendedSiegeWeaponFromTactic(siegeWeapon); this._cavalryFormation.AI.SetBehaviorWeight <BehaviorTacticalCharge>(1f); } else { this._cavalryFormation.AI.ResetBehaviorWeights(); TacticComponent.SetDefaultBehaviorWeights(this._cavalryFormation); this._cavalryFormation.AI.SetBehaviorWeight <BehaviorDefendSiegeWeapon>(1f); BehaviorDefendSiegeWeapon behavior = this._cavalryFormation.AI.GetBehavior <BehaviorDefendSiegeWeapon>(); SiegeWeapon siegeWeapon = this._destructableSiegeWeapons.FirstOrDefault <SiegeWeapon>((Func <SiegeWeapon, bool>)(dsw => dsw is IPrimarySiegeWeapon && (dsw as IPrimarySiegeWeapon).WeaponSide == FormationAI.BehaviorSide.Middle)); FormationAI.BehaviorSide side; if (siegeWeapon != null) { side = FormationAI.BehaviorSide.Middle; } else { siegeWeapon = this._destructableSiegeWeapons.Where <SiegeWeapon>((Func <SiegeWeapon, bool>)(dsw => dsw is IPrimarySiegeWeapon && dsw is IMoveableSiegeWeapon)).MinBy <SiegeWeapon, float>((Func <SiegeWeapon, float>)(dsw => dsw.GameEntity.GlobalPosition.AsVec2.DistanceSquared(this._cavalryFormation.QuerySystem.AveragePosition))); side = (siegeWeapon as IPrimarySiegeWeapon).WeaponSide; } behavior.SetDefensePositionFromTactic(this._teamAISallyOutDefender.CalculateSallyOutReferencePosition(side).ToWorldPosition()); behavior.SetDefendedSiegeWeaponFromTactic(siegeWeapon); this._cavalryFormation.AI.SetBehaviorWeight <BehaviorTacticalCharge>(1f); } } if (this._rangedCavalry == null) { return; } this._rangedCavalry.AI.ResetBehaviorWeights(); TacticComponent.SetDefaultBehaviorWeights(this._rangedCavalry); this._rangedCavalry.AI.SetBehaviorWeight <BehaviorMountedSkirmish>(1f); this._rangedCavalry.AI.SetBehaviorWeight <BehaviorHorseArcherSkirmish>(1f); }
internal void SetDefendedSiegeWeaponFromTactic(SiegeWeapon siegeWeapon) => this._defendedSiegeWeapon = siegeWeapon;
public static bool IsWeaponSelectable(SiegeWeapon weapon) => !weapon.IsDeactivated;
public static SiegeWeaponOrderType GetActiveMovementOrderOf( SiegeWeapon weapon) { return(!weapon.ForcedUse ? SiegeWeaponOrderType.Stop : SiegeWeaponOrderType.Attack); }
public static SiegeWeaponOrderType GetActiveFiringOrderOf(SiegeWeapon weapon) => !weapon.ForcedUse ? SiegeWeaponOrderType.Stop : SiegeWeaponOrderType.Attack;
private void ArrangeDestructedMeshes() { float num1 = 0.0f; foreach (float hitPointPercentage in this._wallHitPointPercentages) { num1 += hitPointPercentage; } if (!((IEnumerable <float>) this._wallHitPointPercentages).IsEmpty <float>()) { num1 /= (float)this._wallHitPointPercentages.Length; } float num2 = MBMath.Lerp(0.0f, 0.7f, 1f - num1); IEnumerable <SynchedMissionObject> source1 = this.Mission.MissionObjects.OfType <SynchedMissionObject>(); IEnumerable <DestructableComponent> destructibleComponents = source1.OfType <DestructableComponent>(); foreach (StrategicArea strategicArea in this.Mission.ActiveMissionObjects.OfType <StrategicArea>().ToList <StrategicArea>()) { strategicArea.DetermineAssociatedDestructibleComponents(destructibleComponents); } foreach (SynchedMissionObject synchedMissionObject in source1) { if (this._hasAnySiegeTower && synchedMissionObject.GameEntity.HasTag("tower_merlon")) { synchedMissionObject.SetVisibleSynched(false, true); } else { DestructableComponent firstScriptOfType = synchedMissionObject.GameEntity.GetFirstScriptOfType <DestructableComponent>(); if (firstScriptOfType != null && firstScriptOfType.CanBeDestroyedInitially && ((double)num2 > 0.0 && (double)MBRandom.RandomFloat <= (double)num2)) { firstScriptOfType.PreDestroy(); } } } if ((double)num2 >= 0.100000001490116) { List <GameEntity> list = this.Mission.Scene.FindEntitiesWithTag("damage_decal").ToList <GameEntity>(); foreach (GameEntity gameEntity in list) { gameEntity.GetFirstScriptOfType <SynchedMissionObject>().SetVisibleSynched(false); } for (double num3 = Math.Floor((double)list.Count * (double)num2); num3 > 0.0; --num3) { GameEntity gameEntity = list[MBRandom.RandomInt(list.Count)]; list.Remove(gameEntity); gameEntity.GetFirstScriptOfType <SynchedMissionObject>().SetVisibleSynched(true); } } List <WallSegment> source2 = new List <WallSegment>(); List <WallSegment> list1 = this.Mission.ActiveMissionObjects.FindAllWithType <WallSegment>().Where <WallSegment>((Func <WallSegment, bool>)(ws => ws.DefenseSide != FormationAI.BehaviorSide.BehaviorSideNotSet && ws.GameEntity.GetChildren().Any <GameEntity>((Func <GameEntity, bool>)(ge => ge.HasTag("broken_child"))))).ToList <WallSegment>(); int val2 = 0; foreach (float hitPointPercentage in this._wallHitPointPercentages) { if ((double)Math.Abs(hitPointPercentage) < 9.99999974737875E-06) { ++val2; } } int num4 = Math.Min(list1.Count <WallSegment>(), val2); while (num4 > 0) { WallSegment randomElement = list1.GetRandomElement <WallSegment>(); randomElement.OnChooseUsedWallSegment(true); list1.Remove(randomElement); --num4; source2.Add(randomElement); } foreach (WallSegment wallSegment in list1) { wallSegment.OnChooseUsedWallSegment(false); } if ((double)num2 < 0.100000001490116) { return; } List <SiegeWeapon> siegeWeaponList = new List <SiegeWeapon>(); foreach (SiegeWeapon siegeWeapon in this.Mission.ActiveMissionObjects.FindAllWithType <SiegeWeapon>().Where <SiegeWeapon>((Func <SiegeWeapon, bool>)(sw => sw is IPrimarySiegeWeapon))) { SiegeWeapon primarySiegeWeapon = siegeWeapon; if (source2.Any <WallSegment>((Func <WallSegment, bool>)(b => b.DefenseSide == ((IPrimarySiegeWeapon)primarySiegeWeapon).WeaponSide))) { siegeWeaponList.Add(primarySiegeWeapon); } } siegeWeaponList.ForEach((Action <SiegeWeapon>)(siegeWeaponToRemove => siegeWeaponToRemove.SetDisabledSynched())); }
public static SiegeWeaponOrderType GetActiveAIControlOrderOf( SiegeWeapon weapon) { return(weapon.ForcedUse ? SiegeWeaponOrderType.AIControlOn : SiegeWeaponOrderType.AIControlOff); }