public override void RefreshContent() { base.RefreshContent(); IDatabase <GameScoreDefinition> database = Databases.GetDatabase <GameScoreDefinition>(false); GameScoreDefinition[] values = database.GetValues(); Diagnostics.Assert(values != null && values.Length > 0); this.ScoreFiltersTable.ReserveChildren(values.Length, this.ScoreFilterTogglePrefab, "Item"); this.ScoreFiltersTable.RefreshChildrenArray <GameScoreDefinition>(values, new AgeTransform.RefreshTableItem <GameScoreDefinition>(this.RefreshScoreFilter), true, false); this.CurrentScoreDefinition = values[0]; IGameStatisticsManagementService service = Services.GetService <IGameStatisticsManagementService>(); this.Snapshot = service.Snapshot; Snapshot[] snapshots = this.Snapshot.Snapshots; this.HorizontalGridContainer.DestroyAllChildren(); if (snapshots.Length > 1) { float f = (float)snapshots.Length; float num = Mathf.Log10(f); float num2 = Mathf.Floor(num); int num3 = (int)Mathf.Pow(10f, num2); int num4 = -1; if (num - num2 < 0.7f) { num4 = num3 / 2; } for (int i = 1; i < snapshots.Length; i++) { if (i % num3 == 0 || (num4 > 0 && i % num4 == 0)) { AgeTransform ageTransform = this.HorizontalGridContainer.InstanciateChild(this.ScoreHorizontalGridPrefab, "Grid" + i); ageTransform.X = this.HorizontalGridContainer.Width * ((float)i / (float)(snapshots.Length - 1)); ageTransform.GetComponent <ScoreGridLabel>().GridLabel.Text = (i + 1).ToString(); } } } this.OnSwitchScoreFilterCB(this.ScoreFiltersTable.GetChildren()[0].GetComponent <ScoreFilterToggle>().Toggle.gameObject); }
void IVictoryManagementService.CheckForAlerts(int turn) { if (turn < 0 || this.HasAlreadyWon) { return; } Diagnostics.Assert(this.InterpreterContext != null); Snapshot snapshot = null; IGameStatisticsManagementService service = Services.GetService <IGameStatisticsManagementService>(); if (service != null && service.Snapshot != null) { string name = string.Format("Turn #{0}", turn); if (!service.Snapshot.TryGetSnapshot(name, out snapshot)) { Diagnostics.LogWarning("Skipping check because snapshot is missing (turn: {0}).", new object[] { turn }); return; } if (snapshot != null) { foreach (KeyValuePair <string, float> keyValuePair in snapshot.KeyValuePairs) { this.InterpreterContext.Register(keyValuePair.Key, keyValuePair.Value); } } } Diagnostics.Assert(base.Game != null); this.InterpreterContext.Register("Turn", base.Game.Turn); int num = 0; int num2 = 0; int num3 = 0; int num4 = 0; int num5 = 0; for (int i = 0; i < base.Game.Empires.Length; i++) { MajorEmpire majorEmpire = base.Game.Empires[i] as MajorEmpire; if (majorEmpire == null) { break; } num++; num3++; if (majorEmpire.SimulationObject.Tags.Contains(Empire.TagEmpireEliminated)) { num2++; num3--; } else { for (int j = 0; j < this.simulationPathNumberOfMainCities.Length; j++) { num4 += (int)this.simulationPathNumberOfMainCities[j].CountValidatedObjects(majorEmpire); } DepartmentOfTheInterior agency = majorEmpire.GetAgency <DepartmentOfTheInterior>(); if (agency != null) { num5 += agency.Cities.Count; } } } this.InterpreterContext.Register("NumberOfMajorEmpires", num); this.InterpreterContext.Register("NumberOfMajorEmpiresEliminated", num2); this.InterpreterContext.Register("NumberOfMajorEmpiresLeft", num3); this.InterpreterContext.Register("NumberOfMainCitiesLeft", num4); this.InterpreterContext.Register("NumberOfCitiesLeft", num5); for (int k = 0; k < base.Game.Empires.Length; k++) { MajorEmpire majorEmpire2 = base.Game.Empires[k] as MajorEmpire; if (majorEmpire2 == null) { break; } if (snapshot != null) { Snapshot snapshot2 = snapshot.TakeSnapshot(majorEmpire2.Name); if (snapshot2 != null) { foreach (KeyValuePair <string, float> keyValuePair2 in snapshot2.KeyValuePairs) { this.InterpreterContext.Register(keyValuePair2.Key, keyValuePair2.Value); } } } try { int num6 = 0; for (int l = 0; l < this.simulationPathNumberOfMainCities.Length; l++) { num6 += (int)this.simulationPathNumberOfMainCities[l].CountValidatedObjects(majorEmpire2); } this.InterpreterContext.Register("NumberOfMainCities", num6); this.InterpreterContext.Register("VictoryWonderProgress", this.GetWonderProgress(majorEmpire2)); majorEmpire2.SimulationObject.AddChild(this.InterpreterContext.SimulationObject); foreach (VictoryCondition victoryCondition in this.VictoryConditionsFilteredThisGame) { if (majorEmpire2.VictoryConditionStatuses != null) { MajorEmpire.VictoryConditionStatus victoryConditionStatus; if (!majorEmpire2.VictoryConditionStatuses.TryGetValue(victoryCondition.Name, out victoryConditionStatus)) { victoryConditionStatus = new MajorEmpire.VictoryConditionStatus(); majorEmpire2.VictoryConditionStatuses.Add(victoryCondition.Name, victoryConditionStatus); } if (victoryCondition.Alerts != null) { if (victoryConditionStatus.LastTurnWhenAlertWasTriggered == null || victoryConditionStatus.LastTurnWhenAlertWasTriggered.Length != victoryCondition.Alerts.Length) { victoryConditionStatus.LastTurnWhenAlertWasTriggered = new int[victoryCondition.Alerts.Length]; } for (int m = 0; m < victoryCondition.Alerts.Length; m++) { VictoryCondition.Alert alert = victoryCondition.Alerts[m]; if (alert != null && (victoryConditionStatus.LastTurnWhenAlertWasTriggered[m] == 0 || (victoryConditionStatus.LastTurnWhenAlertWasTriggered[m] < 0 && alert.Repeat))) { if (alert.Evaluate(this.InterpreterContext)) { victoryConditionStatus.LastTurnWhenAlertWasTriggered[m] = base.Game.Turn; } else if (victoryConditionStatus.LastTurnWhenAlertWasTriggered[m] > 0) { victoryConditionStatus.LastTurnWhenAlertWasTriggered[m] = -victoryConditionStatus.LastTurnWhenAlertWasTriggered[m]; } } } } if (victoryCondition.Progression != null) { if (victoryConditionStatus.Variables == null || victoryConditionStatus.Variables.Length != victoryCondition.Progression.Vars.Length) { victoryConditionStatus.Variables = new float[victoryCondition.Progression.Vars.Length]; } for (int n = 0; n < victoryCondition.Progression.Vars.Length; n++) { victoryConditionStatus.Variables[n] = victoryCondition.Progression.Vars[n].Evaluate(this.InterpreterContext); } } } } } catch { } finally { majorEmpire2.SimulationObject.RemoveChild(this.InterpreterContext.SimulationObject); } } for (int num7 = 0; num7 < base.Game.Empires.Length; num7++) { MajorEmpire majorEmpire3 = base.Game.Empires[num7] as MajorEmpire; if (majorEmpire3 == null) { break; } foreach (VictoryCondition victoryCondition2 in this.VictoryConditionsFilteredThisGame) { MajorEmpire.VictoryConditionStatus victoryConditionStatus2; if (victoryCondition2.Alerts != null && majorEmpire3.VictoryConditionStatuses != null && majorEmpire3.VictoryConditionStatuses.TryGetValue(victoryCondition2.Name, out victoryConditionStatus2)) { for (int num8 = 0; num8 < victoryCondition2.Alerts.Length; num8++) { if (victoryConditionStatus2.LastTurnWhenAlertWasTriggered != null && num8 < victoryConditionStatus2.LastTurnWhenAlertWasTriggered.Length && victoryConditionStatus2.LastTurnWhenAlertWasTriggered[num8] >= base.Game.Turn && victoryCondition2.Alerts[num8] != null) { EventVictoryConditionAlert eventToNotify = new EventVictoryConditionAlert(majorEmpire3, victoryCondition2, victoryConditionStatus2, num8); this.EventService.Notify(eventToNotify); } } } } } }
void IVictoryManagementService.CheckForVictoryConditions(int turn) { if (turn <= this.TurnWhenVictoryConditionsWereLastChecked) { Diagnostics.Log("Skipping check because victory conditions have already been already checked for (turn: {0}, last checked: {1}).", new object[] { turn, this.TurnWhenVictoryConditionsWereLastChecked }); return; } this.TurnWhenVictoryConditionsWereLastChecked = turn; this.VictoryConditionsRaisedThisTurn.Clear(); Diagnostics.Assert(this.InterpreterContext != null); Snapshot snapshot = null; IGameStatisticsManagementService service = Services.GetService <IGameStatisticsManagementService>(); if (service != null && service.Snapshot != null) { string name = string.Format("Turn #{0}", turn); if (!service.Snapshot.TryGetSnapshot(name, out snapshot)) { Diagnostics.LogWarning("Skipping check because snapshot is missing (turn: {0}, last checked: {1}).", new object[] { turn, this.TurnWhenVictoryConditionsWereLastChecked }); return; } if (snapshot != null) { foreach (KeyValuePair <string, float> keyValuePair in snapshot.KeyValuePairs) { this.InterpreterContext.Register(keyValuePair.Key, keyValuePair.Value); } } } Diagnostics.Assert(base.Game != null); this.InterpreterContext.Register("Turn", base.Game.Turn); int num = 0; int num2 = 0; int num3 = 0; int num4 = 0; int num5 = 0; for (int i = 0; i < base.Game.Empires.Length; i++) { MajorEmpire majorEmpire = base.Game.Empires[i] as MajorEmpire; if (majorEmpire == null) { break; } num++; num3++; if (majorEmpire.SimulationObject.Tags.Contains(Empire.TagEmpireEliminated)) { num2++; num3--; } else { for (int j = 0; j < this.simulationPathNumberOfMainCities.Length; j++) { num4 += (int)this.simulationPathNumberOfMainCities[j].CountValidatedObjects(majorEmpire); } DepartmentOfTheInterior agency = majorEmpire.GetAgency <DepartmentOfTheInterior>(); if (agency != null) { num5 += agency.Cities.Count; } } } this.InterpreterContext.Register("NumberOfMajorEmpires", num); this.InterpreterContext.Register("NumberOfMajorEmpiresEliminated", num2); this.InterpreterContext.Register("NumberOfMajorEmpiresLeft", num3); this.InterpreterContext.Register("NumberOfMainCitiesLeft", num4); this.InterpreterContext.Register("NumberOfCitiesLeft", num5); for (int k = 0; k < base.Game.Empires.Length; k++) { MajorEmpire majorEmpire2 = base.Game.Empires[k] as MajorEmpire; if (majorEmpire2 == null) { break; } if (snapshot != null) { Snapshot snapshot2 = snapshot.TakeSnapshot(majorEmpire2.Name); if (snapshot2 != null) { foreach (KeyValuePair <string, float> keyValuePair2 in snapshot2.KeyValuePairs) { this.InterpreterContext.Register(keyValuePair2.Key, keyValuePair2.Value); } } } try { int num6 = 0; for (int l = 0; l < this.simulationPathNumberOfMainCities.Length; l++) { num6 += (int)this.simulationPathNumberOfMainCities[l].CountValidatedObjects(majorEmpire2); } this.InterpreterContext.Register("NumberOfMainCities", num6); majorEmpire2.SimulationObject.AddChild(this.InterpreterContext.SimulationObject); bool flag = false; VictoryCondition victoryCondition = null; foreach (VictoryCondition victoryCondition2 in this.VictoryConditionsFilteredThisGame) { if (victoryCondition2.Evaluate(new object[] { this.InterpreterContext })) { if (victoryCondition2.Name == "Shared") { victoryCondition = victoryCondition2; } else if (!majorEmpire2.SimulationObject.Tags.Contains(Empire.TagEmpireEliminated)) { this.OnVictoryConditionRaised(new VictoryConditionRaisedEventArgs(victoryCondition2, majorEmpire2)); flag = true; } } } if (victoryCondition != null && flag) { DepartmentOfForeignAffairs agency2 = majorEmpire2.GetAgency <DepartmentOfForeignAffairs>(); if (agency2 != null && agency2.DiplomaticRelations != null) { foreach (Empire empire in base.Game.Empires) { if (empire != majorEmpire2) { DiplomaticRelation diplomaticRelation = agency2.GetDiplomaticRelation(empire); if (diplomaticRelation != null && diplomaticRelation.State != null && diplomaticRelation.State.Name == DiplomaticRelationState.Names.Alliance) { this.OnVictoryConditionRaised(new VictoryConditionRaisedEventArgs(victoryCondition, empire)); } } } } } } catch { } finally { majorEmpire2.SimulationObject.RemoveChild(this.InterpreterContext.SimulationObject); } } }