Beispiel #1
0
        private double ComputeWarRatio()
        {
            double peaceCounter = 0f;
            double warCounter   = 0f;

            foreach (EmpireData empire in GlobalData.world.empires)
            {
                EmpireStanding standings = Diplomacy.FindStandings(m_empireData, empire);
                if (standings == null)
                {
                    continue;
                }
                if ((Diplomacy.EmpireType)empire.empireType == Diplomacy.EmpireType.TRUE_HOSTILE)
                {
                    continue;
                }
                if (standings.atWar)
                {
                    warCounter += 1.0f;
                }
                else
                {
                    peaceCounter += 1.0f;
                }
            }
            return(warCounter / (warCounter + peaceCounter));
        }
Beispiel #2
0
        /**
         * Determine based on empire A's type, how it default feels about empire B.
         */
        private static EmpireStanding GetDefaultStanding(EmpireData empireA, EmpireData empireB)
        {
            Util.Log("Generating default standing for " + empireA.empireTag + " and " + empireB.empireTag);
            EmpireStanding standing = new EmpireStanding();

            standing.inStateTill = long.MaxValue;
            standing.reputation  = 0;
            standing.empireTag   = empireB.empireTag;

            switch ((EmpireType)empireA.empireType)
            {
            case EmpireType.TRUE_HOSTILE:
            case EmpireType.HOSTILE:
                standing.atWar = true;
                break;

            case EmpireType.NEUTRAL:
            case EmpireType.POLICE:
            case EmpireType.TRUE_NEUTRAL:
            case EmpireType.PLAYER:
                standing.atWar = false;
                break;
            }

            return(standing);
        }
Beispiel #3
0
        /**
         * Declares a temporary war between two factions.
         */
        public static void DeclareWar(EmpireData empireA, EmpireData empireB)
        {
            EmpireStanding standings = FindStandings(empireA, empireB);

            if (standings == null)
            {
                return;
            }
            bool previouslyAtWar = standings.atWar;

            standings.atWar = true;
            if (!WarIsDefault(empireA))
            {
                standings.inStateTill = GlobalData.world.currentTick + AGRESSION_TIMER_TICKS;
            }
            if (!previouslyAtWar)
            {
                TryDeclareWar(empireA, empireB);
            }
        }
Beispiel #4
0
        /**
         * Refresh reputation
         */
        public static void RefreshReputation()
        {
            foreach (EmpireData empireA in GlobalData.world.empires)
            {
                if ((EmpireType)empireA.empireType == EmpireType.PLAYER)
                {
                    continue;
                }
                foreach (EmpireData empireB in GlobalData.world.empires)
                {
                    if (empireA == empireB)
                    {
                        continue;
                    }
                    EmpireStanding standing = FindStandings(empireA, empireB);
                    if (standing == null)
                    {
                        standing = GetDefaultStanding(empireA, empireB);
                        if (standing == null)
                        {
                            Util.Warning("Could not repute " + empireA.empireTag + " and " + empireB.empireTag);
                            continue;
                        }
                        empireA.standings.Add(standing);
                    }

                    // Reputation tends towards 0
                    int standingsChange = 0;
                    if (standing.reputation > 0)
                    {
                        standingsChange = -1;
                    }
                    else if (standing.reputation < 0)
                    {
                        standingsChange = 1;
                    }
                    // But war holds reputation static for the duration of the war.
                    if (!standing.atWar)
                    {
                        standing.reputation += standingsChange;
                    }

                    // If we're normally peaceful, try to stay peaceful.
                    if (standing.atWar && PeaceIsDefault(empireA) && GlobalData.world.currentTick >= standing.inStateTill)
                    {
                        standing.atWar       = false;
                        standing.inStateTill = long.MaxValue;
                    }

                    // If we're normally war-like, try to go to war.
                    if (!standing.atWar && WarIsDefault(empireA) && GlobalData.world.currentTick >= standing.inStateTill)
                    {
                        standing.atWar       = true;
                        standing.inStateTill = long.MaxValue;
                    }

                    // If we're not at war, accept any peace offers.
                    if (!standing.atWar && MyAPIGateway.Session.Factions.IsPeaceRequestStatePending(empireA.m_faction.FactionId, empireB.m_faction.FactionId))
                    {
                        MyAPIGateway.Session.Factions.AcceptPeace(empireA.m_faction.FactionId, empireB.m_faction.FactionId);
                    }
                    // If we're the police, force accept the peace offer for player factions
                    if (!standing.atWar &&
                        MyAPIGateway.Session.Factions.IsPeaceRequestStateSent(empireA.m_faction.FactionId, empireB.m_faction.FactionId) &&
                        (EmpireType)empireB.empireType == EmpireType.PLAYER &&
                        (EmpireType)empireA.empireType == EmpireType.POLICE)
                    {
                        MyAPIGateway.Session.Factions.AcceptPeace(empireA.m_faction.FactionId, empireB.m_faction.FactionId);
                        MyAPIGateway.Session.Factions.AcceptPeace(empireB.m_faction.FactionId, empireA.m_faction.FactionId);
                    }

                    if (!standing.atWar)
                    {
                        TryDeclarePeace(empireA, empireB);
                    }
                    else
                    {
                        TryDeclareWar(empireA, empireB);
                    }
                }
            }

            EventManager.AddEvent(GlobalData.world.currentTick + REPUTATION_REFRESH_TIMER, RefreshReputation);
        }