private void GoBack() { if ((this.BelongedFaction != null) && (this.StartingArchitecture != null)) { Architecture currentArchitecture = this.CurrentArchitecture; if (((currentArchitecture != null) && (currentArchitecture.BelongedFaction == this.BelongedFaction)) && ((currentArchitecture.Endurance >= (currentArchitecture.EnduranceCeiling * 0.2f)) || (!this.HasHostileTroopInView() && !currentArchitecture.HasHostileTroopsInView()))) { if (this.CanEnter()) { this.Enter(); } } else { CreditPack selfStratagemCredit; Architecture movableBaseViewSelfArchitecture = this.GetMovableBaseViewSelfArchitecture(); if (movableBaseViewSelfArchitecture != null) { this.WillArchitecture = movableBaseViewSelfArchitecture; } else if (this.StartingArchitecture.BelongedFaction == this.BelongedFaction) { this.WillArchitecture = this.StartingArchitecture; } else if (this.BelongedLegion != null) { Architecture legionTroopFactionStartArchitecture = this.BelongedLegion.GetLegionTroopFactionStartArchitecture(); if (legionTroopFactionStartArchitecture != null) { this.WillArchitecture = legionTroopFactionStartArchitecture; } else { this.WillArchitecture = this.BelongedFaction.Capital; } } else { this.WillArchitecture = this.BelongedFaction.Capital; } int credit = 0; CreditPack pack = null; GameArea dayArea = this.GetDayArea(1); if ((((this.Morale < 0x4b) && !this.ViewingWillArchitecture) && !this.HasHostileTroopInView()) && !this.HasHostileArchitectureInView()) { foreach (Point point in dayArea.Area) { selfStratagemCredit = new CreditPack(); selfStratagemCredit.Position = point; selfStratagemCredit.Credit = this.GetFoodCredit(point); selfStratagemCredit.Credit += this.GetTerrainCredit(point); if (selfStratagemCredit.Credit > credit) { credit = selfStratagemCredit.Credit; pack = selfStratagemCredit; } } } bool flag = false; foreach (Stratagem stratagem in this.Stratagems.Stratagems.Values) { if (this.HasStratagem(stratagem.ID)) { if (stratagem.Self) { selfStratagemCredit = this.GetSelfStratagemCredit(stratagem); if (selfStratagemCredit.Credit > credit) { credit = selfStratagemCredit.Credit; pack = selfStratagemCredit; flag = true; } } else { this.SetCurrentStratagem(stratagem); selfStratagemCredit = this.GetStratagemCreditByPosition(stratagem, this.Position); if (selfStratagemCredit.Credit > credit) { credit = selfStratagemCredit.Credit; pack = selfStratagemCredit; flag = true; } this.SetCurrentStratagem(null); } } } if (flag && (pack.CurrentStratagem != null)) { this.SetCurrentStratagem(pack.CurrentStratagem); if (pack.CurrentStratagem.Self) { this.SelfCastPosition = pack.SelfCastPosition; } } else if (credit > 0) { this.TempDestination = new Point?(pack.Position); } } } }
private CreditPack GetStratagemCreditByPosition(Stratagem stratagem, Point position) { int num = -2147483648; Troop troop = null; foreach (Point point in this.GetStratagemArea(position).Area) { if ((this.BelongedFaction == null) || this.BelongedFaction.IsPositionKnown(point)) { int num2 = base.Scenario.GetSimpleDistance(position, point) * 5; Troop troopByPositionNoCheck = base.Scenario.GetTroopByPositionNoCheck(point); if ((troopByPositionNoCheck != null) && (stratagem.Friendly == this.IsFriendly(troopByPositionNoCheck.BelongedFaction))) { if (!(stratagem.Friendly || (troopByPositionNoCheck.Status != TroopStatus.埋伏))) { continue; } int credit = stratagem.GetCredit(this, troopByPositionNoCheck); if (!stratagem.Friendly && (((this.WillArchitecture != null) && (this.WillArchitecture.BelongedFaction != this.BelongedFaction)) && (this.WillArchitecture.BelongedFaction != troopByPositionNoCheck.BelongedFaction))) { credit /= 2; } if (((troopByPositionNoCheck != this) && (this.Army.Scales > 4)) && (troopByPositionNoCheck.Army.Scales <= 4)) { credit /= 2; } if (credit > 0) { credit += num2; if (credit > num) { num = credit; troop = troopByPositionNoCheck; } } } } } if (stratagem.Friendly && (position != this.Position)) { int num4 = stratagem.GetCredit(this, this); if (num4 > 0) { num4 += base.Scenario.GetSimpleDistance(this.Position, position) * 5; if (num4 > num) { num = num4; troop = this; } } } CreditPack pack = new CreditPack(); pack.Position = position; if (troop != null) { pack.Distance = base.Scenario.GetDistance(position, troop.Position); } if (((num > 0) && base.Scenario.PositionIsOnFire(position)) && (((this.BelongedFaction == null) && this.ViewArea.HasPoint(position)) || ((this.BelongedFaction != null) && this.BelongedFaction.IsPositionKnown(position)))) { num -= 300; } if (num > 0) { num += this.GetFoodCredit(position); num += this.GetLegionCredit(position); num += this.GetHostileRoutewayCredit(position); num += this.GetTerrainCredit(position); int positionHostileOffencingDiscredit = 0; Architecture architectureByPositionNoCheck = base.Scenario.GetArchitectureByPositionNoCheck(position); if ((architectureByPositionNoCheck != null) && (architectureByPositionNoCheck.Endurance > 0)) { if (!stratagem.Friendly) { num *= 4; } } else { positionHostileOffencingDiscredit = base.Scenario.GetPositionHostileOffencingDiscredit(this, position); } if (position != this.Position) { float terranRateByPosition = this.GetTerranRateByPosition(position); num = (int) ((num * Math.Pow((double) terranRateByPosition, 2.0)) - (((double) positionHostileOffencingDiscredit) / Math.Pow((double) terranRateByPosition, 2.0))); } else { num -= positionHostileOffencingDiscredit; } pack.Credit = num; pack.CurrentStratagem = stratagem; } else { pack.Credit = 0; } pack.TargetTroop = troop; return pack; }
private CreditPack GetSelfStratagemCredit(Stratagem stratagem) { int creditWithPosition = 0; Point? position = null; if (stratagem.IsValid(this)) { creditWithPosition = stratagem.GetCreditWithPosition(this, out position); } if (((creditWithPosition > 0) && base.Scenario.PositionIsOnFire(this.Position)) && (((this.BelongedFaction == null) && this.ViewArea.HasPoint(this.Position)) || ((this.BelongedFaction != null) && this.BelongedFaction.IsPositionKnown(this.Position)))) { creditWithPosition -= 300; } CreditPack pack = new CreditPack(); if (creditWithPosition > 0) { creditWithPosition += this.GetFoodCredit(this.Position); creditWithPosition += this.GetLegionCredit(this.Position); creditWithPosition += this.GetHostileRoutewayCredit(this.position); creditWithPosition += this.GetTerrainCredit(this.position); int positionHostileOffencingDiscredit = 0; Architecture architectureByPositionNoCheck = base.Scenario.GetArchitectureByPositionNoCheck(this.Position); if ((architectureByPositionNoCheck == null) || (architectureByPositionNoCheck.Endurance == 0)) { positionHostileOffencingDiscredit = base.Scenario.GetPositionHostileOffencingDiscredit(this, this.Position); } pack.Credit = creditWithPosition - positionHostileOffencingDiscredit; if (position.HasValue) { pack.SelfCastPosition = position.Value; } pack.CurrentStratagem = stratagem; } else { pack.Credit = 0; } pack.Position = this.Position; return pack; }
private CreditPack GetMoveCreditByPosition(Point p) { List<RoutePoint> supplyRoutePointsByPositionAndFaction = base.Scenario.GetSupplyRoutePointsByPositionAndFaction(p, this.BelongedFaction); CreditPack pack = new CreditPack(); pack.Position = p; pack.Credit += this.GetFoodCredit(p); pack.Credit += this.GetHostileRoutewayCredit(p); pack.Credit += this.GetTerrainCredit(p); if (pack.Position == this.Position) { pack.Credit /= 2; } double distance = base.Scenario.GetDistance(p, this.WillArchitecture.ArchitectureArea); TerrainKind terrainKindByPosition = base.Scenario.GetTerrainKindByPosition(p); if (this.BelongedLegion.Troops.Count > 1) { if (this != this.BelongedLegion.CoreTroop) { if ((((this.Army.Kind.Type == MilitaryType.水军) && (terrainKindByPosition == TerrainKind.水域)) || ((this.Army.Kind.Type != MilitaryType.水军) && (terrainKindByPosition != TerrainKind.水域))) && ((((supplyRoutePointsByPositionAndFaction.Count > 0) && (this.Position == p)) && (this.BelongedLegion.GetWillClosestTroop() == this)) && GameObject.Chance((20 + this.Leader.Calmness) - this.Leader.Braveness))) { pack.Credit += 0x2710; return pack; } if ((distance <= this.DistanceToWillArchitecture) && this.BelongedLegion.CoreTroop.ViewArea.HasPoint(p)) { pack.Credit += 1 + ((int) ((this.DistanceToWillArchitecture - distance) * 100.0)); } } else if (((this.Position == p) && (((this.Army.Kind.Type == MilitaryType.水军) && (terrainKindByPosition == TerrainKind.水域)) || ((this.Army.Kind.Type != MilitaryType.水军) && (terrainKindByPosition != TerrainKind.水域)))) && (((supplyRoutePointsByPositionAndFaction.Count > 0) && (this.BelongedLegion.GetWillClosestTroop() == this)) && GameObject.Chance((50 + this.Leader.Calmness) - this.Leader.Braveness))) { pack.Credit += 0x2710; return pack; } } if (this.BelongedLegion.PreferredRouteway != null) { if (distance >= this.DistanceToWillArchitecture) { return pack; } if (GameObject.Random(this.RationDaysLeft) > 0) { return pack; } if ((GameObject.Random(this.RationDaysLeft) == 0) && (((this.Army.Kind.Type == MilitaryType.水军) && (terrainKindByPosition == TerrainKind.水域)) || ((this.Army.Kind.Type != MilitaryType.水军) && (terrainKindByPosition != TerrainKind.水域)))) { foreach (RoutePoint point in supplyRoutePointsByPositionAndFaction) { if ((point.BelongedRouteway == this.BelongedLegion.PreferredRouteway) && (point.BelongedRouteway.DestinationArchitecture == this.WillArchitecture)) { double num2 = base.Scenario.GetDistance(point.Position, this.WillArchitecture.ArchitectureArea); if (num2 >= this.DistanceToWillArchitecture) { continue; } if (this.WillArchitecture.BelongedFaction != this.BelongedFaction) { pack.Credit += point.Index + ((int) ((this.DistanceToWillArchitecture - num2) * 100.0)); } else { pack.Credit += -point.Index + ((int) ((this.DistanceToWillArchitecture - num2) * 100.0)); } return pack; } } } } return pack; }
private CreditPack GetCreditByPosition(Point position) { int num = -2147483648; bool flag = false; bool flag2 = false; Troop troop = null; Architecture architecture = null; Point zero = Point.Zero; if ((!this.OffenceOnlyBeforeMove || (position == this.Position)) || this.OffenceOnlyBeforeMoveFlag) { foreach (Point point2 in this.GetOffenceArea(position).Area) { if (((this.BelongedFaction == null) || this.BelongedFaction.IsPositionKnown(point2)) || base.Scenario.PositionIsArchitecture(point2)) { int attackArchitecutreCredit; Troop troopByPositionNoCheck; int simpleDistance; int surroundingCredit; int num2 = base.Scenario.GetSimpleDistance(position, point2) * 10; Architecture architectureByPositionNoCheck = base.Scenario.GetArchitectureByPositionNoCheck(point2); if ((((architectureByPositionNoCheck != null) && (architectureByPositionNoCheck.Endurance > 0)) && (architectureByPositionNoCheck == this.WillArchitecture)) && !this.IsFriendly(architectureByPositionNoCheck.BelongedFaction)) { flag = true; attackArchitecutreCredit = this.GetAttackArchitecutreCredit(architectureByPositionNoCheck); if ((this.ViewingHostileTroopCount > 0) || GameObject.Chance(0x21)) { attackArchitecutreCredit += num2; } if (((this.WillArchitecture != null) && (this.WillArchitecture.BelongedFaction != this.BelongedFaction)) && (this.WillArchitecture.BelongedFaction != architectureByPositionNoCheck.BelongedFaction)) { attackArchitecutreCredit /= 2; } float terranRateByPosition = this.GetTerranRateByPosition(position); attackArchitecutreCredit = (int) (attackArchitecutreCredit * Math.Pow((double) terranRateByPosition, 2.0)); if (attackArchitecutreCredit > num) { num = attackArchitecutreCredit; troop = null; architecture = architectureByPositionNoCheck; zero = point2; } if ((this.BelongedFaction == null) || this.BelongedFaction.IsPositionKnown(point2)) { troopByPositionNoCheck = base.Scenario.GetTroopByPositionNoCheck(point2); if ((troopByPositionNoCheck != null) && !this.IsFriendly(troopByPositionNoCheck.BelongedFaction)) { if (this.AirOffence) { attackArchitecutreCredit = this.GetAttackTroopCredit(troopByPositionNoCheck, position) - this.GetCounterStrikeDiscredit(troopByPositionNoCheck, position); if ((this.SimulatingCombatMethod != null) && this.SimulatingCombatMethod.ViewingHostile) { if (GameObject.Random(5 + this.ViewingHostileTroopCount) > 5) { simpleDistance = base.Scenario.GetSimpleDistance(position, this.Position); if (simpleDistance > 10) { simpleDistance = 10; } attackArchitecutreCredit += GameObject.Square(simpleDistance + this.ViewingHostileTroopCount) * 5; } else { attackArchitecutreCredit /= 2; } } surroundingCredit = this.GetSurroundingCredit(troopByPositionNoCheck); if (surroundingCredit > 0) { attackArchitecutreCredit += surroundingCredit * (100 - troopByPositionNoCheck.AvoidSurroundedChance); } attackArchitecutreCredit += num2; if (((this.WillArchitecture != null) && (this.WillArchitecture.BelongedFaction != this.BelongedFaction)) && (this.WillArchitecture.BelongedFaction != troopByPositionNoCheck.BelongedFaction)) { attackArchitecutreCredit /= 2; } if (attackArchitecutreCredit > num) { num = attackArchitecutreCredit; troop = troopByPositionNoCheck; architecture = null; } } else { flag2 = true; } } } } else if ((this.BelongedFaction == null) || this.BelongedFaction.IsPositionKnown(point2)) { troopByPositionNoCheck = base.Scenario.GetTroopByPositionNoCheck(point2); if (((troopByPositionNoCheck != null) && !this.IsFriendly(troopByPositionNoCheck.BelongedFaction)) && (troopByPositionNoCheck.Status != TroopStatus.埋伏)) { flag = true; attackArchitecutreCredit = this.GetAttackTroopCredit(troopByPositionNoCheck, position) - this.GetCounterStrikeDiscredit(troopByPositionNoCheck, position); if ((this.SimulatingCombatMethod != null) && this.SimulatingCombatMethod.ViewingHostile) { if (GameObject.Random(5 + this.ViewingHostileTroopCount) > 5) { simpleDistance = base.Scenario.GetSimpleDistance(position, this.Position); if (simpleDistance > 10) { simpleDistance = 10; } attackArchitecutreCredit += GameObject.Square(simpleDistance + this.ViewingHostileTroopCount) * 5; } else { attackArchitecutreCredit /= 2; } } surroundingCredit = this.GetSurroundingCredit(troopByPositionNoCheck); if (surroundingCredit > 0) { attackArchitecutreCredit += surroundingCredit * (100 - troopByPositionNoCheck.AvoidSurroundedChance); } attackArchitecutreCredit += num2; if (((this.WillArchitecture != null) && (this.WillArchitecture.BelongedFaction != this.BelongedFaction)) && (this.WillArchitecture.BelongedFaction != troopByPositionNoCheck.BelongedFaction)) { attackArchitecutreCredit /= 2; } if (attackArchitecutreCredit > num) { num = attackArchitecutreCredit; troop = troopByPositionNoCheck; architecture = null; } } } } } } if (((num > 0) && base.Scenario.PositionIsOnFire(position)) && (((this.BelongedFaction == null) && this.ViewArea.HasPoint(position)) || ((this.BelongedFaction != null) && this.BelongedFaction.IsPositionKnown(position)))) { num -= 300; } CreditPack pack = new CreditPack(); pack.Position = position; if (troop != null) { pack.Distance = base.Scenario.GetDistance(position, troop.Position); } if (architecture != null) { pack.Distance = base.Scenario.GetDistance(position, zero); } if (flag && (num > 0)) { num += this.GetFoodCredit(position); num += this.GetLegionCredit(position); num += this.GetHostileRoutewayCredit(position); num += this.GetTerrainCredit(position); pack.Credit = num; pack.TargetTroop = troop; pack.TargetArchitecture = architecture; } else if (this.RationDaysLeft <= GameObject.Random(2)) { pack.Credit = this.GetFoodCredit(position); } else { pack.Credit = 0; } pack.HasUnAttackableTroop = flag2; return pack; }
private CreditPack GetStratagemCreditByPosition(Stratagem stratagem, Troop troop) { int credit = stratagem.GetCredit(this, troop); if (credit <= 0) return new CreditPack(); if (!stratagem.Friendly && this.WillArchitecture != null && this.WillArchitecture.BelongedFaction != this.BelongedFaction && this.WillArchitecture.BelongedFaction != troop.BelongedFaction) { credit /= 2; } if (troop != this && this.Army.Scales > 4 && troop.Army.Scales <= 4) { credit /= 2; } CreditPack pack = new CreditPack(); pack.Position = troop.position; pack.Distance = base.Scenario.GetDistance(this.position, troop.Position); pack.Credit = credit; pack.CurrentStratagem = stratagem; pack.TargetTroop = troop; return pack; }