private float GetWonderProgress(MajorEmpire empire)
    {
        DepartmentOfTheInterior agency  = empire.GetAgency <DepartmentOfTheInterior>();
        DepartmentOfIndustry    agency2 = empire.GetAgency <DepartmentOfIndustry>();
        float num = 0f;

        for (int i = 0; i < agency.Cities.Count; i++)
        {
            Construction construction = agency2.GetConstructionQueue(agency.Cities[i]).Get((Construction x) => x.ConstructibleElement.SubCategory == "SubCategoryVictory");
            if (construction != null)
            {
                for (int j = 0; j < construction.CurrentConstructionStock.Length; j++)
                {
                    if (construction.CurrentConstructionStock[j].PropertyName == "Production")
                    {
                        float stock = construction.CurrentConstructionStock[j].Stock;
                        if (stock > 0f)
                        {
                            float num2 = stock / DepartmentOfTheTreasury.GetProductionCostWithBonus(agency.Cities[i], construction.ConstructibleElement, "Production");
                            if (num2 > num)
                            {
                                num = num2;
                            }
                        }
                    }
                }
            }
        }
        return(num);
    }
Exemple #2
0
    private void OnVisibityRefreshed(object sender, VisibilityRefreshedEventArgs args)
    {
        MajorEmpire majorEmpire = args.Empire as MajorEmpire;

        if (majorEmpire == null)
        {
            return;
        }
        DepartmentOfScience agency = majorEmpire.GetAgency <DepartmentOfScience>();

        for (int i = 0; i < this.majorEmpires.Length; i++)
        {
            global::Empire empire = this.majorEmpires[i];
            if (majorEmpire.Index != empire.Index)
            {
                WorldPosition worldPosition = this.CheckMetting(majorEmpire, empire);
                if (worldPosition != WorldPosition.Invalid)
                {
                    WorldPosition worldPosition2 = this.CheckMetting(empire, majorEmpire);
                    if (worldPosition2 != WorldPosition.Invalid)
                    {
                        this.OnEmpireSymetricDiscovery(majorEmpire, empire, worldPosition, worldPosition2);
                    }
                    else if (agency.GetTechnologyState(this.technologyDefinitionDrakkenVisionDuringFirstTurn) == DepartmentOfScience.ConstructibleElement.State.Researched)
                    {
                        this.OnEmpireAsymetricDiscovery(majorEmpire, empire, worldPosition);
                    }
                }
            }
        }
    }
Exemple #3
0
    private void CreateEmpireFilters(List <global::Empire> empiresToSelect = null)
    {
        if (empiresToSelect != null && empiresToSelect.Count == 1 && empiresToSelect[0] == base.Empire)
        {
            empiresToSelect.Clear();
        }
        this.empireToFilter.Clear();
        DepartmentOfIntelligence agency = base.Empire.GetAgency <DepartmentOfIntelligence>();
        bool         flag = DepartmentOfTheInterior.CanSeeAllExchangeTransactions(base.Empire);
        global::Game game = base.Game as global::Game;

        for (int i = 0; i < game.Empires.Length; i++)
        {
            MajorEmpire majorEmpire = game.Empires[i] as MajorEmpire;
            if (majorEmpire != null)
            {
                if (base.Empire.Index == majorEmpire.Index)
                {
                    this.empireToFilter.Add(majorEmpire);
                }
                else if (!majorEmpire.IsEliminated)
                {
                    DepartmentOfScience agency2 = majorEmpire.GetAgency <DepartmentOfScience>();
                    if (agency2.CanTradeHeroes(true) || agency2.CanTradeUnits(true) || agency2.CanTradeResourcesAndBoosters(true))
                    {
                        if (flag)
                        {
                            this.empireToFilter.Add(majorEmpire);
                        }
                        else if (agency != null && agency.IsEmpireInfiltrated(majorEmpire))
                        {
                            this.empireToFilter.Add(majorEmpire);
                        }
                    }
                }
            }
        }
        this.empireFilterWidth = Mathf.Floor((this.EmpireFiltersContainer.Width - this.EmpireFiltersContainer.HorizontalSpacing * (float)(this.empireToFilter.Count - 1)) / (float)this.empireToFilter.Count);
        this.EmpireFiltersContainer.ReserveChildren(this.empireToFilter.Count, this.EmpireFilterPrefab, "EmpireFilterToggle");
        this.EmpireFiltersContainer.RefreshChildrenIList <global::Empire>(this.empireToFilter, new AgeTransform.RefreshTableItem <global::Empire>(this.SetupEmpireFilterToggle), true, false);
        this.EmpireFiltersContainer.ArrangeChildren();
        if (empiresToSelect != null && empiresToSelect.Count > 0)
        {
            this.SetEmpiresToShow(empiresToSelect);
        }
        else
        {
            this.SetEmpiresToShow(this.empireToFilter);
        }
        AgeTooltip ageTooltip = this.EmpireFilterPrefab.GetComponent <AgeTransform>().AgeTooltip;

        if (ageTooltip != null)
        {
            ageTooltip.Content = "%MarketplaceEmpireFilterDescription";
        }
    }
    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);
            }
        }
    }
Exemple #6
0
    public static EmpireInfo Read(Amplitude.Unity.Session.Session session, int empireIndex)
    {
        if (session == null)
        {
            throw new ArgumentNullException("session");
        }
        if (empireIndex < 0)
        {
            throw new IndexOutOfRangeException("Empire index must be a positive integer.");
        }
        if (empireIndex == 0)
        {
            try
            {
                string lobbyData = session.GetLobbyData <string>(EmpireInfo.EmpireInfoAccessibility, null);
                EmpireInfo.LastAccessibilityLevel = (EmpireInfo.Accessibility)((int)Enum.Parse(typeof(EmpireInfo.Accessibility), lobbyData));
            }
            catch
            {
                EmpireInfo.LastAccessibilityLevel = EmpireInfo.Accessibility.Default;
            }
        }
        string x          = string.Format("Empire{0}", empireIndex);
        string lobbyData2 = session.GetLobbyData <string>(x, null);

        if (string.IsNullOrEmpty(lobbyData2))
        {
            return(null);
        }
        string     x2         = string.Format("Faction{0}", empireIndex);
        string     x3         = string.Format("Color{0}", empireIndex);
        string     lobbyData3 = session.GetLobbyData <string>(x2, null);
        string     lobbyData4 = session.GetLobbyData <string>(x3, null);
        EmpireInfo empireInfo = new EmpireInfo();

        empireInfo.EmpireIndex  = empireIndex;
        empireInfo.EmpireName   = "Empire#" + empireIndex;
        empireInfo.Faction      = Faction.Decode(lobbyData3);
        empireInfo.FactionColor = Color.white;
        empireInfo.Players      = lobbyData2;
        string value = Amplitude.Unity.Framework.Application.Registry.GetValue <string>("Settings/UI/EmpireColorPalette", "Standard");
        IDatabase <Palette> database = Databases.GetDatabase <Palette>(false);
        Palette             palette;

        if (database != null && database.TryGetValue(value, out palette))
        {
            if (palette.Colors == null || palette.Colors.Length == 0)
            {
                Diagnostics.LogError("Invalid color palette (name: '{0}').", new object[]
                {
                    value
                });
            }
            else
            {
                try
                {
                    int num = int.Parse(lobbyData4);
                    empireInfo.FactionColor = palette.Colors[num];
                }
                catch
                {
                    Diagnostics.LogError("Failed to retrieve faction color from palette (palette name: '{0}', color index: '{1}').", new object[]
                    {
                        value,
                        lobbyData4
                    });
                }
            }
        }
        string lobbyData5 = session.GetLobbyData <string>(VictoryCondition.ReadOnlyVictory, null);

        if (!string.IsNullOrEmpty(lobbyData5))
        {
            IDatabase <VictoryCondition> database2 = Databases.GetDatabase <VictoryCondition>(false);
            if (database2 != null)
            {
                char[] separator = new char[]
                {
                    '&'
                };
                string[] array = lobbyData5.Split(separator, StringSplitOptions.RemoveEmptyEntries);
                if (array.Length != 0)
                {
                    List <VictoryCondition> list = new List <VictoryCondition>();
                    string[] array2 = array;
                    for (int i = 0; i < array2.Length; i++)
                    {
                        string[] array3 = array2[i].Split(Amplitude.String.Separators, StringSplitOptions.RemoveEmptyEntries);
                        int      j      = 1;
                        while (j < array3.Length)
                        {
                            int num2;
                            if (int.TryParse(array3[j], out num2) && num2 == empireIndex)
                            {
                                VictoryCondition item;
                                if (database2.TryGetValue(array3[0], out item))
                                {
                                    list.Add(item);
                                    break;
                                }
                                break;
                            }
                            else
                            {
                                j++;
                            }
                        }
                    }
                    empireInfo.VictoryConditions = list.ToArray();
                }
            }
            else
            {
                Diagnostics.LogError("Unable to retrieve the database of victory conditions.");
            }
        }
        ILocalizationService service = Services.GetService <ILocalizationService>();

        empireInfo.LocalizedName = string.Empty;
        string[] array4 = lobbyData2.Split(Amplitude.String.Separators, StringSplitOptions.RemoveEmptyEntries);
        for (int k = 0; k < array4.Length; k++)
        {
            if (service != null)
            {
                if (array4[k].StartsWith("AI"))
                {
                    if (empireInfo.Faction.Name == "FactionELCPSpectator")
                    {
                        empireInfo.LocalizedName = AgeLocalizer.Instance.LocalizeString("%NotificationEncounterParticipationModeSpectatorTitle");
                    }
                    else
                    {
                        empireInfo.LocalizedName = MajorEmpire.GenerateAIName(empireInfo.Faction.Affinity.Name, empireInfo.EmpireIndex);
                    }
                }
                else
                {
                    Steamworks.SteamID steamID  = new Steamworks.SteamID(Convert.ToUInt64(array4[k], 16));
                    string             newValue = AgeLocalizer.Instance.LocalizeString("%DefaultPlayerName");
                    if (Steamworks.SteamAPI.IsSteamRunning)
                    {
                        newValue = Steamworks.SteamAPI.SteamFriends.GetFriendPersonaName(steamID);
                    }
                    string     name        = (empireInfo.LocalizedName.Length != 0) ? "%EmpireNameFormatAdditionnalHuman" : "%EmpireNameFormatHuman";
                    EmpireInfo empireInfo2 = empireInfo;
                    empireInfo2.LocalizedName += service.Localize(name).ToString().Replace("$PlayerName", newValue);
                }
            }
        }
        empireInfo.IsActiveOrLocalPlayer  = false;
        empireInfo.EmpireEliminated       = false;
        empireInfo.EmpireExplorationBits  = 0;
        empireInfo.EmpireInfiltrationBits = 0;
        IGameService service2 = Services.GetService <IGameService>();

        if (service2 != null && service2.Game != null)
        {
            IPlayerControllerRepositoryService service3 = service2.Game.Services.GetService <IPlayerControllerRepositoryService>();
            if (service3 != null && service3.ActivePlayerController != null && service3.ActivePlayerController.Empire != null)
            {
                empireInfo.IsActiveOrLocalPlayer = (service3.ActivePlayerController.Empire.Index == empireIndex);
            }
            else
            {
                Steamworks.SteamUser steamUser = Steamworks.SteamAPI.SteamUser;
                if (steamUser != null)
                {
                    empireInfo.IsActiveOrLocalPlayer = empireInfo.Players.Contains(steamUser.SteamID.ToString());
                }
            }
            global::Game game = service2.Game as global::Game;
            if (game != null && game.Empires != null)
            {
                MajorEmpire majorEmpire = game.Empires[empireIndex] as MajorEmpire;
                if (majorEmpire.IsEliminated)
                {
                    empireInfo.EmpireEliminated = true;
                }
                empireInfo.AlliedIndexList = new List <int>();
                for (int l = 0; l < game.Empires.Length; l++)
                {
                    MajorEmpire majorEmpire2 = game.Empires[l] as MajorEmpire;
                    if (majorEmpire2 == null)
                    {
                        break;
                    }
                    if (majorEmpire2.Index == empireIndex)
                    {
                        empireInfo.EmpireExplorationBits  |= 1 << empireIndex;
                        empireInfo.EmpireInfiltrationBits |= 1 << empireIndex;
                    }
                    else
                    {
                        DepartmentOfForeignAffairs agency = majorEmpire2.GetAgency <DepartmentOfForeignAffairs>();
                        if (agency != null)
                        {
                            DiplomaticRelation diplomaticRelation = agency.GetDiplomaticRelation(majorEmpire);
                            if (diplomaticRelation != null && diplomaticRelation.State != null && diplomaticRelation.State.Name != DiplomaticRelationState.Names.Unknown)
                            {
                                empireInfo.EmpireExplorationBits |= 1 << majorEmpire2.Index;
                                if (diplomaticRelation.State.Name == DiplomaticRelationState.Names.Alliance)
                                {
                                    empireInfo.AlliedIndexList.Add(majorEmpire2.Index);
                                }
                            }
                        }
                        DepartmentOfIntelligence agency2 = majorEmpire2.GetAgency <DepartmentOfIntelligence>();
                        if (agency2 != null && agency2.IsEmpireInfiltrated(majorEmpire))
                        {
                            empireInfo.EmpireInfiltrationBits |= 1 << majorEmpire2.Index;
                        }
                    }
                }
            }
        }
        return(empireInfo);
    }
Exemple #7
0
    public override void UpdateRole()
    {
        base.Role = BaseNavyArmy.ArmyRole.Forteress;
        this.WantToKeepArmyFitness.Reset();
        NavyRegionData navyRegionData = base.Commander.RegionData as NavyRegionData;

        this.WantToKeepArmyFitness.Add(0.3f, "constant", new object[0]);
        if (navyRegionData.NumberOfWaterEnemy > 0)
        {
            HeuristicValue heuristicValue = new HeuristicValue(0f);
            heuristicValue.Add((float)navyRegionData.NumberOfWaterEnemy, "Number of enemy water region around.", new object[0]);
            heuristicValue.Multiply(0.1f, "boost constant", new object[0]);
            heuristicValue.Min(0.5f, "Avoid too big factor!", new object[0]);
            this.WantToKeepArmyFitness.Boost(heuristicValue, "Water region owned by enemy around.", new object[0]);
        }
        if (navyRegionData.NumberOfEnemyCityOnTheBorder > 0)
        {
            this.WantToKeepArmyFitness.Boost(0.2f, "Enemy city in the region.", new object[0]);
        }
        if (navyRegionData.EnemyNavalPower > 0f)
        {
            this.WantToKeepArmyFitness.Boost(0.9f, "Enemy roaming in the region.", new object[0]);
        }
        MajorEmpire occupant = this.Fortress.Occupant;

        if (occupant != null && !AILayer_Military.AreaIsSave(this.Fortress.WorldPosition, 10, occupant.GetAgency <DepartmentOfForeignAffairs>(), true))
        {
            this.WantToKeepArmyFitness.Boost(0.9f, "Enemy roaming in the region.", new object[0]);
        }
    }
    public void CleanVillageAfterEncounter(Village village, Encounter encounter)
    {
        Diagnostics.Assert(this.villages.Contains(village));
        DepartmentOfDefense agency = base.Empire.GetAgency <DepartmentOfDefense>();

        Diagnostics.Assert(agency != null);
        agency.UpdateLifeAfterEncounter(village);
        agency.CleanGarrisonAfterEncounter(village);
        bool flag = true;

        foreach (Contender contender in encounter.GetAlliedContendersFromEmpire(village.Empire))
        {
            if (contender.IsTakingPartInBattle && contender.ContenderState != ContenderState.Defeated)
            {
                flag = false;
            }
        }
        if (village.Units.Count <Unit>() == 0 && flag)
        {
            if (village.PointOfInterest != null)
            {
                village.PointOfInterest.RemovePointOfInterestImprovement();
            }
            for (int i = 0; i < encounter.Empires.Count; i++)
            {
                if (encounter.Empires[i].Index != this.MinorEmpire.Index)
                {
                    this.EventService.Notify(new EventVillageDestroyed(encounter.Empires[i], village));
                }
            }
            List <global::Empire> list = new List <global::Empire>(encounter.Empires);
            list.Remove(this.MinorEmpire);
            MajorEmpire converter = village.Converter;
            this.PacifyVillage(village, list);
            this.BindMinorFactionToCity();
            if (converter != null)
            {
                if (village.Region.City != null)
                {
                    if (village.Region.City.Empire.Index == converter.Index)
                    {
                        DepartmentOfTheInterior agency2 = converter.GetAgency <DepartmentOfTheInterior>();
                        Diagnostics.Assert(agency2 != null);
                        if (agency2.MainCity != null)
                        {
                            agency2.BindMinorFactionToCity(agency2.MainCity, this.MinorEmpire);
                        }
                    }
                    else
                    {
                        DepartmentOfTheInterior agency3 = converter.GetAgency <DepartmentOfTheInterior>();
                        Diagnostics.Assert(agency3 != null);
                        agency3.UnbindConvertedVillage(village);
                    }
                }
                else
                {
                    DepartmentOfTheInterior agency4 = converter.GetAgency <DepartmentOfTheInterior>();
                    Diagnostics.Assert(agency4 != null);
                    agency4.UnbindConvertedVillage(village);
                }
            }
        }
        village.Refresh(false);
    }
Exemple #9
0
    void IDiplomacyControl.OnServerBeginTurn()
    {
        this.firstBeginTurnDone = true;
        if (this.majorEmpires == null)
        {
            return;
        }
        while (this.visibilityControllerRefreshedArgs.Count > 0)
        {
            KeyValuePair <object, VisibilityRefreshedEventArgs> keyValuePair = this.visibilityControllerRefreshedArgs.Dequeue();
            this.OnVisibityRefreshed(keyValuePair.Key, keyValuePair.Value);
        }
        int turn = base.Game.Turn;

        for (int i = 0; i < this.majorEmpires.Length; i++)
        {
            MajorEmpire majorEmpire           = this.majorEmpires[i] as MajorEmpire;
            DepartmentOfForeignAffairs agency = majorEmpire.GetAgency <DepartmentOfForeignAffairs>();
            Diagnostics.Assert(agency != null);
            for (int j = i + 1; j < this.majorEmpires.Length; j++)
            {
                MajorEmpire        majorEmpire2       = this.majorEmpires[j] as MajorEmpire;
                DiplomaticRelation diplomaticRelation = agency.GetDiplomaticRelation(majorEmpire2);
                Diagnostics.Assert(diplomaticRelation != null && diplomaticRelation.State != null);
                if (majorEmpire.IsSpectator || majorEmpire.ELCPIsEliminated || majorEmpire2.IsSpectator || majorEmpire2.ELCPIsEliminated)
                {
                    if (diplomaticRelation.State.Name != DiplomaticRelationState.Names.Dead)
                    {
                        OrderChangeDiplomaticRelationState order = new OrderChangeDiplomaticRelationState(this.majorEmpires[i].Index, majorEmpire2.Index, DiplomaticRelationState.Names.Dead);
                        this.PlayerController.PostOrder(order);
                    }
                }
                else
                {
                    DiplomaticRelationState.Transition automaticTransition = diplomaticRelation.State.AutomaticTransition;
                    if (automaticTransition != null && automaticTransition.GetRemainingTurns(diplomaticRelation) <= 0)
                    {
                        OrderChangeDiplomaticRelationState order2 = new OrderChangeDiplomaticRelationState(i, j, automaticTransition.DestinationState);
                        this.PlayerController.PostOrder(order2);
                    }
                }
            }
        }
        bool[][] array = new bool[this.majorEmpires.Length][];
        for (int k = 0; k < this.majorEmpires.Length; k++)
        {
            array[k] = new bool[this.majorEmpires.Length];
        }
        Diagnostics.Assert(this.diplomaticContracts != null);
        for (int l = 0; l < this.diplomaticContracts.Count; l++)
        {
            DiplomaticContract diplomaticContract = this.diplomaticContracts[l];
            Diagnostics.Assert(diplomaticContract != null);
            if (diplomaticContract.EmpireWhichInitiated.Index >= array.Length || diplomaticContract.EmpireWhichReceives.Index >= array[diplomaticContract.EmpireWhichInitiated.Index].Length)
            {
                Diagnostics.Assert(false, "ELCP: Unexpected EmpireIndex {0}", new object[]
                {
                    diplomaticContract.ToString()
                });
            }
            else
            {
                if (diplomaticContract.State == DiplomaticContractState.Proposed && turn > diplomaticContract.TurnAtTheBeginningOfTheState)
                {
                    OrderChangeDiplomaticContractState order3 = new OrderChangeDiplomaticContractState(diplomaticContract, DiplomaticContractState.Refused);
                    this.PlayerController.PostOrder(order3);
                }
                if (diplomaticContract.State == DiplomaticContractState.Negotiation && turn > diplomaticContract.TurnAtTheBeginningOfTheState)
                {
                    if (diplomaticContract.EmpireWhichInitiated != diplomaticContract.EmpireWhichProposes || diplomaticContract.ContractRevisionNumber > 0 || array[diplomaticContract.EmpireWhichInitiated.Index][diplomaticContract.EmpireWhichReceives.Index])
                    {
                        DiplomaticContractState            newState = DiplomaticContractState.Refused;
                        OrderChangeDiplomaticContractState order4   = new OrderChangeDiplomaticContractState(diplomaticContract, newState);
                        this.PlayerController.PostOrder(order4);
                    }
                    else
                    {
                        array[diplomaticContract.EmpireWhichInitiated.Index][diplomaticContract.EmpireWhichReceives.Index] = true;
                    }
                }
            }
        }
    }