protected float GetRatioOfEnemyTargettedNeighboursAroundTargetPosition(BattleSimulationUnit unit, BattleSimulationTarget potentialTarget) { float result = 0f; if (potentialTarget.Neighbours == null) { return(result); } int count = potentialTarget.Neighbours.Count; int num = 0; if (count > 0 && potentialTarget.Unit != null) { for (int i = 0; i < count; i++) { if (potentialTarget.Neighbours[i].Targeters != null) { int count2 = potentialTarget.Neighbours[i].Targeters.Count; if (count2 - potentialTarget.Neighbours[i].GetTargetersCountByGroup(unit.Contender.Group) > 0) { num++; } } } result = (float)num / (float)count; } return(result); }
protected float RatioOfOpponentsAroundTargetPositionWhoPlayAfterMe(BattleSimulationUnit unit, BattleSimulationTarget potentialTarget) { float result = 0f; if (potentialTarget.Neighbours == null) { return(result); } int count = potentialTarget.Neighbours.Count; int num = 0; if (count > 0) { for (int i = 0; i < count; i++) { BattleSimulationUnit unit2 = potentialTarget.Neighbours[i].Unit; if (unit2 != null && unit2.Contender.Group != unit.Contender.Group && (unit.HasUnitActions || unit.UnitRoundRank < unit2.UnitRoundRank) && this.pathfindingService.IsTransitionPassable(potentialTarget.StaticPosition, unit2.Position, unit, PathfindingFlags.IgnoreArmies | PathfindingFlags.IgnoreOtherEmpireDistrict | PathfindingFlags.IgnoreDiplomacy | PathfindingFlags.IgnoreEncounterAreas | PathfindingFlags.IgnoreFogOfWar | PathfindingFlags.IgnorePOI | PathfindingFlags.IgnoreSieges | PathfindingFlags.IgnoreKaijuGarrisons, null)) { num++; } } result = (float)num / (float)count; } return(result); }
protected float GetRatioOfAlliesAroundTargetPosition(BattleSimulationUnit unit, BattleSimulationTarget potentialTarget) { float result = 0f; if (potentialTarget.Neighbours == null) { return(result); } int count = potentialTarget.Neighbours.Count; int num = 0; if (count > 0) { for (int i = 0; i < count; i++) { BattleSimulationUnit unit2 = potentialTarget.Neighbours[i].Unit; if (unit2 != null && unit2.Contender.Group == unit.Contender.Group) { num++; } } result = (float)num / (float)count; } return(result); }
public void RefreshAttachment(BattleSimulationUnit unit) { if (unit == null) { throw new ArgumentNullException("unit"); } Diagnostics.Assert(base.SimulationObject != null); bool flag = base.SimulationObject.Children != null && base.SimulationObject.Children.Contains(unit.SimulationObject); bool isDead = unit.IsDead; if (unit.Position.IsValid) { if (isDead && flag) { base.SimulationObject.RemoveChild(unit.SimulationObject); this.Refresh(false); } else if (!isDead && !flag) { base.SimulationObject.AddChild(unit.SimulationObject); this.Refresh(false); } } else if (flag) { base.SimulationObject.RemoveChild(unit.SimulationObject); this.Refresh(false); } }
protected float GetRatioOfLowerNeighboursAroundTargetPosition(BattleSimulationUnit unit, BattleSimulationTarget potentialTarget) { float result = 0f; if (potentialTarget.Neighbours == null) { return(result); } int count = potentialTarget.Neighbours.Count; float num = (float)unit.ElevationMap.GetValue(potentialTarget.StaticPosition); int num2 = 0; if (count > 0) { for (int i = 0; i < count; i++) { float num3 = (float)unit.ElevationMap.GetValue(potentialTarget.Neighbours[i].StaticPosition); if (num3 < num) { num2++; } } result = (float)num2 / (float)count; } return(result); }
protected float GetNumberOfNegativeGroundBattleActionsAtTargetPosition(BattleSimulationUnit unit, BattleSimulationTarget potentialTarget) { int positiveGroundActionsCountByGroup = this.battleSimulation.GetPositiveGroundActionsCountByGroup(potentialTarget.StaticPosition, unit.Contender.Group); int groundActionsCount = this.battleSimulation.GetGroundActionsCount(potentialTarget.StaticPosition); return((float)(groundActionsCount - positiveGroundActionsCountByGroup)); }
protected bool IsGroundUnit(BattleSimulationUnit unit, BattleSimulationTarget potentialTarget) { if (potentialTarget.Unit == null) { return(false); } return(potentialTarget.Unit.SimulationObject.DescriptorHolders.Exists((SimulationDescriptorHolder match) => match.Descriptor.Name == PathfindingContext.MovementCapacityWalkDescriptor)); }
protected float GetDoesTargetPlaysBeforeMe(BattleSimulationUnit unit, BattleSimulationTarget potentialTarget) { if (potentialTarget.Unit != null && (potentialTarget.Unit.HasUnitActions || potentialTarget.Unit.UnitRoundRank < unit.UnitRoundRank)) { return(1f); } return(0f); }
protected float GetIsTargetTransportShipUnit(BattleSimulationUnit unit, BattleSimulationTarget potentialTarget) { if (potentialTarget.Unit != null && potentialTarget.Unit.SimulationObject.Tags.Contains(DownloadableContent16.TransportShipUnit)) { return(1f); } return(0f); }
protected bool IAmInDarkForm(BattleSimulationUnit unit, BattleSimulationTarget potentialTarget) { if (unit.Unit == null) { return(false); } SimulationProperty property = unit.Unit.SimulationObject.GetProperty(SimulationProperties.ShiftingForm); return(property != null && property.Value == 1f); }
public void OnUnitDeath(BattleSimulationUnit unit, List <IUnitReportInstruction> executionInstructions = null) { this.reportCopy = executionInstructions; foreach (BattleEffectController battleEffectController in this.battleEffectsContexts.Values) { Diagnostics.Assert(battleEffectController != null); battleEffectController.OnUnitDeath(unit, this); } this.reportCopy = null; }
protected float GetIsTargetLower(BattleSimulationUnit unit, BattleSimulationTarget potentialTarget) { float propertyValue = unit.GetPropertyValue(SimulationProperties.Altitude); float num = (float)unit.ElevationMap.GetValue(potentialTarget.StaticPosition); if (propertyValue > num) { return(1f); } return(0f); }
protected float GetNumberOfTurnToReachTargetWithCapacities(BattleSimulationUnit unit, BattleSimulationTarget potentialTarget) { float result = 0f; float propertyValue = unit.GetPropertyValue(SimulationProperties.BattleMaximumMovement); if (propertyValue != 0f) { result = unit.GetDistanceByGround(potentialTarget.StaticPosition) / propertyValue; } return(result); }
protected float GetNumberOfTurnToReachTargetByAir(BattleSimulationUnit unit, BattleSimulationTarget potentialTarget) { float result = 0f; float propertyValue = unit.GetPropertyValue(SimulationProperties.BattleMaximumMovement); if (propertyValue != 0f) { result = (float)this.worldPositionningService.GetDistance(unit.Position, potentialTarget.StaticPosition) / propertyValue; } return(result); }
protected float GetRatioOfTargetSpeedToBattleArea(BattleSimulationUnit unit, BattleSimulationTarget potentialTarget) { float result = 0f; if (potentialTarget.Unit != null) { float propertyValue = potentialTarget.Unit.GetPropertyValue(SimulationProperties.BattleMaximumMovement); int num = potentialTarget.Unit.Contender.Deployment.DeploymentArea.MaxColumn - potentialTarget.Unit.Contender.Deployment.DeploymentArea.MinColumn + 1; result = propertyValue / (float)num; } return(result); }
public void RemoveUnit(BattleSimulationUnit unit) { if (unit == null) { throw new ArgumentNullException("unit"); } Diagnostics.Assert(this.units != null); if (this.units.Contains(unit)) { this.units.Remove(unit); } }
protected float GetRatioOfTargetAltitudeToMyAltitude(BattleSimulationUnit unit, BattleSimulationTarget potentialTarget) { float result = 0f; float propertyValue = unit.GetPropertyValue(SimulationProperties.Altitude); if (propertyValue != 0f) { float num = (float)unit.ElevationMap.GetValue(potentialTarget.StaticPosition); result = num / propertyValue; } return(result); }
protected float GetParamValueByName(StaticString weightName, BattleSimulationUnit unit, BattleSimulationTarget potentialTarget) { BattleTargetingController.ParamComputationDelegate paramComputationDelegate; if (this.paramsComputationDelegates.TryGetValue(weightName, out paramComputationDelegate)) { return(paramComputationDelegate(unit, potentialTarget)); } Diagnostics.Assert("This criteria {0} evaluation doesn't seem to be implemented. Did you modify the criteria name?", new object[] { weightName }); return(0f); }
protected bool GetFilterValueByName(StaticString filterName, BattleSimulationUnit unit, BattleSimulationTarget potentialTarget) { BattleTargetingController.FilterComputationDelegate filterComputationDelegate; if (this.filtersComputationDelegates.TryGetValue(filterName, out filterComputationDelegate)) { return(filterComputationDelegate(unit, potentialTarget)); } Diagnostics.Assert("This filter {0} evaluation doesn't seem to be implemented. Did you modify the filter name?", new object[] { filterName }); return(false); }
protected float GetRatioDistanceToAttackAndMoveRange(BattleSimulationUnit unit, BattleSimulationTarget potentialTarget) { float result = 0f; float distanceByGround = unit.GetDistanceByGround(potentialTarget.StaticPosition); if (distanceByGround > 0f) { float propertyValue = unit.GetPropertyValue(SimulationProperties.BattleMaximumMovement); float propertyValue2 = unit.GetPropertyValue(SimulationProperties.BattleRange); result = distanceByGround / (propertyValue + propertyValue2); } return(result); }
public void AddUnit(BattleSimulationUnit unit) { if (unit == null) { throw new ArgumentNullException("unit"); } Diagnostics.Assert(this.units != null); if (!this.units.Contains(unit)) { unit.UpdateBattleTargetingUnitBehaviorWeight(); this.units.Add(unit); this.RefreshAttachment(unit); } }
public void SpawnUnit(BattleSimulationUnit unit, WorldPosition spawnPosition) { if (unit == null) { throw new ArgumentNullException("unit"); } if (!spawnPosition.IsValid) { throw new ArgumentException("The spawnPosition must be a valid position.", "spawnPosition"); } Diagnostics.Assert(this.units != null); Diagnostics.Assert(this.units.Contains(unit)); unit.Spawn(spawnPosition); this.RefreshAttachment(unit); }
protected float GetTargetDefensiveMilitaryPowerRatio(BattleSimulationUnit unit, BattleSimulationTarget potentialTarget) { float result = 0f; if (potentialTarget.Unit != null) { float propertyValue = potentialTarget.Unit.GetPropertyValue(SimulationProperties.DefensiveMilitaryPower); float unitsSimulationAverageData = this.battleSimulation.GetUnitsSimulationAverageData(potentialTarget.Unit.Contender.Group, SimulationProperties.DefensiveMilitaryPower); if (unitsSimulationAverageData != 0f) { result = propertyValue / unitsSimulationAverageData; } } return(result); }
protected float GetTargetHPRatio(BattleSimulationUnit unit, BattleSimulationTarget potentialTarget) { float result = 0f; if (potentialTarget.Unit != null) { float propertyValue = potentialTarget.Unit.GetPropertyValue(SimulationProperties.Health); float propertyValue2 = potentialTarget.Unit.GetPropertyValue(SimulationProperties.MaximumHealth); if (propertyValue2 != 0f) { result = propertyValue / propertyValue2; } } return(result); }
protected float GetRatioMyDefenseToTargetAttack(BattleSimulationUnit unit, BattleSimulationTarget potentialTarget) { float result = 2f; BattleSimulationUnit unit2 = potentialTarget.Unit; if (unit2 != null) { float propertyValue = unit2.GetPropertyValue(SimulationProperties.Attack); if (propertyValue != 0f) { result = Mathf.Clamp(unit.GetPropertyValue(SimulationProperties.Defense) / propertyValue, 0.5f, 2f); } } return(result); }
public void DoReportInstructions(RoundReport currentReport, bool postRound = false) { if (currentReport == null) { throw new ArgumentNullException("currentReport"); } Diagnostics.Assert(this.reportInstructions != null); Diagnostics.Assert(this.Simulation != null); for (int i = 0; i < this.reportInstructions.Count; i++) { IUnitReportInstruction unitReportInstruction = this.reportInstructions[i]; Diagnostics.Assert(unitReportInstruction != null); BattleSimulationUnit battleUnit = this.Simulation.GetBattleUnit(unitReportInstruction.UnitGUID); currentReport.DoReportInstruction(battleUnit, unitReportInstruction, postRound); } this.reportInstructions.Clear(); }
public void ExecuteBattleEffect(BattleSimulationUnit initiator, BattleSimulationUnit activator, BattleSimulationTarget target, BattleEffect battleEffect, BattleActionContext actionContext) { Diagnostics.Assert(this.battleEffectsContexts != null, "this.battleEffectsContexts != null"); BattleEffectController battleEffectController; if (this.battleEffectsContexts.ContainsKey(target)) { battleEffectController = this.battleEffectsContexts[target]; } else { battleEffectController = new BattleEffectController(target, this.Simulation); this.battleEffectsContexts.Add(target, battleEffectController); } Diagnostics.Assert(battleEffectController != null); battleEffectController.Execute(battleEffect, initiator, activator, this, actionContext); }
protected float GetTargetedByAlliesWithMyBodyCount(BattleSimulationUnit unit, BattleSimulationTarget potentialTarget) { float result = 0f; List <BattleSimulationUnit> targeters = potentialTarget.Targeters; if (potentialTarget.Unit != null) { targeters = potentialTarget.Unit.Targeters; } if (targeters != null) { int num = 0; for (int i = 0; i < targeters.Count; i++) { if (targeters[i].Contender.Group == unit.Contender.Group && targeters[i].UnitGUID != unit.UnitGUID && targeters[i].Unit.UnitDesign.UnitBodyDefinition == unit.Unit.UnitDesign.UnitBodyDefinition) { num++; } } result = (float)num; } return(result); }
protected float IsMyBattleEffectAppliedOnTarget(BattleSimulationUnit unit, BattleSimulationTarget potentialTarget) { if (potentialTarget.Unit != null) { IEnumerable <BattleUnitActionController.UnitAction> availableActions; if (potentialTarget.Unit.Contender.Group == unit.Contender.Group) { availableActions = this.battleSimulation.BattleUnitActionController.GetAvailableActions(unit, BattleActionUnit.ActionType.Support); } else { availableActions = this.battleSimulation.BattleUnitActionController.GetAvailableActions(unit, BattleActionUnit.ActionType.Attack); } if (availableActions != null) { foreach (BattleUnitActionController.UnitAction unitAction in availableActions) { for (int i = 0; i < unitAction.BattleAction.BattleEffects.Length; i++) { BattleEffects battleEffects = unitAction.BattleAction.BattleEffects[i]; if (battleEffects != null && battleEffects.BattleEffectList != null) { for (int j = 0; j < battleEffects.BattleEffectList.Length; j++) { BattleEffectContext contextFromBattleEffect = unit.GetContextFromBattleEffect(battleEffects.BattleEffectList[j]); if (contextFromBattleEffect != null && contextFromBattleEffect.Target.Unit == potentialTarget.Unit) { return(1f); } } } } } } } return(0f); }
protected float GetRatioOfImpassableNeighboursAroundTargetPosition(BattleSimulationUnit unit, BattleSimulationTarget potentialTarget) { float result = 0f; if (potentialTarget.Neighbours == null) { return(result); } int count = potentialTarget.Neighbours.Count; int num = 0; if (count > 0 && potentialTarget.Unit != null) { for (int i = 0; i < count; i++) { if (!this.pathfindingService.IsTransitionPassable(potentialTarget.StaticPosition, potentialTarget.Neighbours[i].StaticPosition, potentialTarget.Unit, PathfindingFlags.IgnoreArmies | PathfindingFlags.IgnoreOtherEmpireDistrict | PathfindingFlags.IgnoreDiplomacy | PathfindingFlags.IgnoreEncounterAreas | PathfindingFlags.IgnoreFogOfWar | PathfindingFlags.IgnorePOI | PathfindingFlags.IgnoreSieges | PathfindingFlags.IgnoreKaijuGarrisons, null)) { num++; } } result = (float)num / (float)count; } return(result); }