public Vector2 GetPositionOfNearestEnemyWithinRadius(Vector2 Position, float Radius, Empire Us)
 {
     List<ThreatMatrix.Pin> Enemies = new List<ThreatMatrix.Pin>();
     foreach (KeyValuePair<Guid, ThreatMatrix.Pin> pin in this.Pins)
     {
         if (Vector2.Distance(Position, pin.Value.Position) >= Radius || EmpireManager.GetEmpireByName(pin.Value.EmpireName) == Us || !Us.isFaction && !EmpireManager.GetEmpireByName(pin.Value.EmpireName).isFaction && !Us.GetRelations()[EmpireManager.GetEmpireByName(pin.Value.EmpireName)].AtWar)
         {
             continue;
         }
         Enemies.Add(pin.Value);
     }
     if (Enemies.Count == 0)
     {
         return Vector2.Zero;
     }
     IOrderedEnumerable<ThreatMatrix.Pin> sortedList =
         from pos in Enemies
         orderby Vector2.Distance(pos.Position, Position)
         select pos;
     return sortedList.First<ThreatMatrix.Pin>().Position;
 }
 public void CallAllyToWar(Empire Ally, Empire Enemy)
 {
     Offer offer = new Offer()
     {
         AcceptDL = "HelpUS_War_Yes",
         RejectDL = "HelpUS_War_No"
     };
     string dialogue = "HelpUS_War";
     Offer OurOffer = new Offer()
     {
         ValueToModify = new Ref<bool>(() => Ally.GetRelations()[Enemy].AtWar, (bool x) => {
             if (x)
             {
                 Ally.GetGSAI().DeclareWarOnViaCall(Enemy, WarType.ImperialistWar);
                 return;
             }
             float Amount = 30f;
             if (this.empire.data.DiplomaticPersonality != null && this.empire.data.DiplomaticPersonality.Name == "Honorable")
             {
                 Amount = 60f;
                 offer.RejectDL = "HelpUS_War_No_BreakAlliance";
                 this.empire.GetRelations()[Ally].Treaty_Alliance = false;
                 Ally.GetRelations()[this.empire].Treaty_Alliance = false;
                 this.empire.GetRelations()[Ally].Treaty_OpenBorders = false;
                 this.empire.GetRelations()[Ally].Treaty_NAPact = false;
             }
             Relationship item = this.empire.GetRelations()[Ally];
             item.Trust = item.Trust - Amount;
             Relationship angerDiplomaticConflict = this.empire.GetRelations()[Ally];
             angerDiplomaticConflict.Anger_DiplomaticConflict = angerDiplomaticConflict.Anger_DiplomaticConflict + Amount;
         })
     };
     if (Ally == EmpireManager.GetEmpireByName(this.empire.GetUS().PlayerLoyalty))
     {
         this.empire.GetUS().ScreenManager.AddScreen(new DiplomacyScreen(this.empire, EmpireManager.GetEmpireByName(this.empire.GetUS().PlayerLoyalty), dialogue, OurOffer, offer, Enemy));
     }
 }
        public void UpdateRelationship(Empire us, Empire them)
        {
            if (us.data.Defeated)
            {
                return;
            }
            #if PERF
            if (EmpireManager.GetEmpireByName(us.GetUS().PlayerLoyalty) == them)
                return;
            #endif
            if (GlobalStats.perf && EmpireManager.GetEmpireByName(us.GetUS().PlayerLoyalty) == them)
                return;
            if (this.FedQuest != null)
            {
                if (this.FedQuest.type == QuestType.DestroyEnemy && EmpireManager.GetEmpireByName(this.FedQuest.EnemyName).data.Defeated)
                {
                    DiplomacyScreen ds = new DiplomacyScreen(us, EmpireManager.GetEmpireByName(Ship.universeScreen.PlayerLoyalty), "Federation_YouDidIt_KilledEnemy", true)
                    {
                        empToDiscuss = EmpireManager.GetEmpireByName(this.FedQuest.EnemyName)
                    };
                    us.GetUS().ScreenManager.AddScreen(ds);
                    EmpireManager.GetEmpireByName(Ship.universeScreen.PlayerLoyalty).AbsorbEmpire(us);
                    this.FedQuest = null;
                    return;
                }
                if (this.FedQuest.type == QuestType.AllyFriend)
                {
                    if (EmpireManager.GetEmpireByName(this.FedQuest.EnemyName).data.Defeated)
                    {
                        this.FedQuest = null;
                    }
                    else if (EmpireManager.GetEmpireByName(Ship.universeScreen.PlayerLoyalty).GetRelations()[EmpireManager.GetEmpireByName(this.FedQuest.EnemyName)].Treaty_Alliance)
                    {
                        DiplomacyScreen ds = new DiplomacyScreen(us, EmpireManager.GetEmpireByName(Ship.universeScreen.PlayerLoyalty), "Federation_YouDidIt_AllyFriend", true)
                        {
                            empToDiscuss = EmpireManager.GetEmpireByName(this.FedQuest.EnemyName)
                        };
                        us.GetUS().ScreenManager.AddScreen(ds);
                        EmpireManager.GetEmpireByName(Ship.universeScreen.PlayerLoyalty).AbsorbEmpire(us);
                        this.FedQuest = null;
                        return;
                    }
                }
            }
            if (this.Posture == Ship_Game.Gameplay.Posture.Hostile && this.Trust > 50f && this.TotalAnger < 10f)
            {
                this.Posture = Ship_Game.Gameplay.Posture.Neutral;
            }
            if (them.isFaction)
            {
                this.AtWar = false;
            }
            this.UpdateIntelligence(us, them);
            if (this.AtWar && this.ActiveWar != null)
            {
                War activeWar = this.ActiveWar;
                activeWar.TurnsAtWar = activeWar.TurnsAtWar + 1f;
            }
            foreach (TrustEntry te in this.TrustEntries)
            {
                TrustEntry turnsInExistence = te;
                turnsInExistence.TurnsInExistence = turnsInExistence.TurnsInExistence + 1;
                if (te.TurnTimer == 0 || te.TurnsInExistence <= 250)
                {
                    continue;
                }
                this.TrustEntries.QueuePendingRemoval(te);
            }
            this.TrustEntries.ApplyPendingRemovals();
            foreach (FearEntry te in this.FearEntries)
            {
                FearEntry fearEntry = te;
                fearEntry.TurnsInExistence = fearEntry.TurnsInExistence + 1f;
                if (te.TurnTimer == 0 || te.TurnsInExistence <= 250f)
                {
                    continue;
                }
                this.FearEntries.QueuePendingRemoval(te);
            }
            this.FearEntries.ApplyPendingRemovals();
            if (!this.Treaty_Alliance)
            {
                this.TurnsAllied = 0;
            }
            else
            {
                Relationship turnsAllied = this;
                turnsAllied.TurnsAllied = turnsAllied.TurnsAllied + 1;
            }
            DTrait dt = us.data.DiplomaticPersonality;
            if (this.Posture == Ship_Game.Gameplay.Posture.Friendly)
            {
                Relationship trust = this;
                trust.Trust = trust.Trust + dt.TrustGainedAtPeace;
                if (this.Trust > 100f && !us.GetRelations()[them].Treaty_Alliance)
                {
                    this.Trust = 100f;
                }
                else if (this.Trust > 150f && us.GetRelations()[them].Treaty_Alliance)
                {
                    this.Trust = 150f;
                }
            }
            else if (this.Posture == Ship_Game.Gameplay.Posture.Hostile)
            {
                Relationship relationship = this;
                relationship.Trust = relationship.Trust - dt.TrustGainedAtPeace;
            }
            if (this.Treaty_NAPact)
            {
                Relationship trust1 = this;
                trust1.Trust = trust1.Trust + 0.0125f;
            }
            if (this.Treaty_OpenBorders)
            {
                Relationship relationship1 = this;
                relationship1.Trust = relationship1.Trust + 0.0125f;
            }
            if (this.Treaty_Trade)
            {
                Relationship trust2 = this;
                trust2.Trust = trust2.Trust + 0.0125f;
                Relationship treatyTradeTurnsExisted = this;
                treatyTradeTurnsExisted.Treaty_Trade_TurnsExisted = treatyTradeTurnsExisted.Treaty_Trade_TurnsExisted + 1;
            }
            if (this.Treaty_Peace)
            {
                Relationship peaceTurnsRemaining = this;
                peaceTurnsRemaining.PeaceTurnsRemaining = peaceTurnsRemaining.PeaceTurnsRemaining - 1;
                if (this.PeaceTurnsRemaining <= 0)
                {
                    this.Treaty_Peace = false;
                    us.GetRelations()[them].Treaty_Peace = false;
                }
                Relationship angerDiplomaticConflict = this;
                angerDiplomaticConflict.Anger_DiplomaticConflict = angerDiplomaticConflict.Anger_DiplomaticConflict - 0.1f;
                Relationship angerFromShipsInOurBorders = this;
                angerFromShipsInOurBorders.Anger_FromShipsInOurBorders = angerFromShipsInOurBorders.Anger_FromShipsInOurBorders - 0.1f;
                Relationship angerMilitaryConflict = this;
                angerMilitaryConflict.Anger_MilitaryConflict = angerMilitaryConflict.Anger_MilitaryConflict - 0.1f;
                Relationship angerTerritorialConflict = this;
                angerTerritorialConflict.Anger_TerritorialConflict = angerTerritorialConflict.Anger_TerritorialConflict - 0.1f;
            }
            if (this.Trust <= 95f)
            {
                this.TurnsAbove95 = 0;
            }
            else
            {
                Relationship turnsAbove95 = this;
                turnsAbove95.TurnsAbove95 = turnsAbove95.TurnsAbove95 + 1;
            }
            this.TrustUsed = 0f;
            foreach (TrustEntry te in this.TrustEntries)
            {
                Relationship trustUsed = this;
                trustUsed.TrustUsed = trustUsed.TrustUsed + te.TrustCost;
            }
            foreach (FearEntry te in this.FearEntries)
            {
                Relationship fearUsed = this;
                fearUsed.FearUsed = fearUsed.FearUsed + te.FearCost;
            }
            //foreach (Ship ship in us.GetShipsInOurBorders())
            //{
            //    if (ship.loyalty != them || them.GetRelations()[us].Treaty_OpenBorders || this.Treaty_Alliance)
            //    {
            //        continue;
            //    }
            //    if (!this.Treaty_NAPact)
            //    {
            //        Relationship angerFromShipsInOurBorders1 = this;
            //        angerFromShipsInOurBorders1.Anger_FromShipsInOurBorders = angerFromShipsInOurBorders1.Anger_FromShipsInOurBorders + (100f - this.Trust) / 100f * (float)ship.Size / 150f;
            //    }
            //    else
            //    {
            //        Relationship angerFromShipsInOurBorders2 = this;
            //        angerFromShipsInOurBorders2.Anger_FromShipsInOurBorders = angerFromShipsInOurBorders2.Anger_FromShipsInOurBorders + (100f - this.Trust) / 100f * (float)ship.Size / 300f;
            //    }
            //}

            // Inborders us.GetGSAI().ThreatMatrix.StrengthOfAllEmpireShipsInBorders(them)
            if(!this.Treaty_Alliance && !this.Treaty_OpenBorders)
            {

                float strengthofshipsinborders = us.GetGSAI().ThreatMatrix.StrengthOfAllEmpireShipsInBorders(them);
                if(strengthofshipsinborders>0)
                if (!this.Treaty_NAPact)
                {

                    Relationship angerFromShipsInOurBorders1 = this;
                    angerFromShipsInOurBorders1.Anger_FromShipsInOurBorders += (100f - this.Trust) / 100f * strengthofshipsinborders / (us.MilitaryScore);
                    //shipsInOurBorder.isDecloaking = true;
                }
                else
                {
                    Relationship angerFromShipsInOurBorders2 = this;
                    //angerFromShipsInOurBorders2.Anger_FromShipsInOurBorders = angerFromShipsInOurBorders2.Anger_FromShipsInOurBorders + (100f - this.Trust) / 100f * (float)shipsInOurBorder.Size / 300f;
                    angerFromShipsInOurBorders2.Anger_FromShipsInOurBorders += (100f - this.Trust) / 100f * strengthofshipsinborders / (us.MilitaryScore * 2f);

                }

            }
            //foreach (Ship shipsInOurBorder in us.GetShipsInOurBorders().Where(ship => ship.loyalty != null && ship.loyalty != us && !ship.loyalty.isFaction))
            //{
            //    //shipsInOurBorder.WeaponCentered = false;
            //    //added by gremlin: maintenance in enemy space
            //    if (shipsInOurBorder.loyalty != them || them.GetRelations()[us].Treaty_OpenBorders || this.Treaty_Alliance)
            //    {
            //        if (shipsInOurBorder.loyalty == them && (them.GetRelations()[us].Treaty_OpenBorders))
            //        {
            //            shipsInOurBorder.isCloaking = true;
            //            if (this.Treaty_Alliance)
            //            {
            //                shipsInOurBorder.isCloaked = true;
            //            }

            //        }
            //        continue;

            //    }

            //    if (!this.Treaty_NAPact)
            //    {

            //        Relationship angerFromShipsInOurBorders1 = this;
            //        angerFromShipsInOurBorders1.Anger_FromShipsInOurBorders = angerFromShipsInOurBorders1.Anger_FromShipsInOurBorders + (100f - this.Trust) / 100f * (float)shipsInOurBorder.Size / 150f;
            //        shipsInOurBorder.isDecloaking = true;
            //    }
            //    else
            //    {
            //        Relationship angerFromShipsInOurBorders2 = this;
            //        angerFromShipsInOurBorders2.Anger_FromShipsInOurBorders = angerFromShipsInOurBorders2.Anger_FromShipsInOurBorders + (100f - this.Trust) / 100f * (float)shipsInOurBorder.Size / 300f;

            //    }
            //}

            float OurMilScore = 230f + us.MilitaryScore;
            float TheirMilScore = 230f + them.MilitaryScore;
            this.Threat = (1f - OurMilScore / TheirMilScore) * 100f;
            if (this.Threat > 100f)
            {
                this.Threat = 100f;
            }
            if (us.MilitaryScore < 1000f)
            {
                this.Threat = 0f;
            }
            if (this.Trust > 100f && !us.GetRelations()[them].Treaty_Alliance)
            {
                this.Trust = 100f;
            }
            else if (this.Trust > 150f && us.GetRelations()[them].Treaty_Alliance)
            {
                this.Trust = 150f;
            }
            Relationship initialStrength = this;
            initialStrength.InitialStrength = initialStrength.InitialStrength + dt.NaturalRelChange;
            if (this.Anger_TerritorialConflict > 0f)
            {
                Relationship angerTerritorialConflict1 = this;
                angerTerritorialConflict1.Anger_TerritorialConflict = angerTerritorialConflict1.Anger_TerritorialConflict - dt.AngerDissipation;
            }
            if (this.Anger_TerritorialConflict < 0f)
            {
                this.Anger_TerritorialConflict = 0f;
            }
            if (this.Anger_FromShipsInOurBorders > 100f)
            {
                this.Anger_FromShipsInOurBorders = 100f;
            }
            if (this.Anger_FromShipsInOurBorders > 0f)
            {
                Relationship relationship2 = this;
                relationship2.Anger_FromShipsInOurBorders = relationship2.Anger_FromShipsInOurBorders - dt.AngerDissipation;
            }
            if (this.Anger_FromShipsInOurBorders < 0f)
            {
                this.Anger_FromShipsInOurBorders = 0f;
            }
            if (this.Anger_MilitaryConflict > 0f)
            {
                Relationship angerTerritorialConflict2 = this;
                angerTerritorialConflict2.Anger_TerritorialConflict = angerTerritorialConflict2.Anger_TerritorialConflict - dt.AngerDissipation;
            }
            if (this.Anger_MilitaryConflict < 0f)
            {
                this.Anger_MilitaryConflict = 0f;
            }
            if (this.Anger_DiplomaticConflict > 0f)
            {
                Relationship angerDiplomaticConflict1 = this;
                angerDiplomaticConflict1.Anger_DiplomaticConflict = angerDiplomaticConflict1.Anger_DiplomaticConflict - dt.AngerDissipation;
            }
            if (this.Anger_DiplomaticConflict < 0f)
            {
                this.Anger_DiplomaticConflict = 0f;
            }
            this.TotalAnger = 0f;
            Relationship totalAnger = this;
            totalAnger.TotalAnger = totalAnger.TotalAnger + this.Anger_DiplomaticConflict;
            Relationship totalAnger1 = this;
            totalAnger1.TotalAnger = totalAnger1.TotalAnger + this.Anger_FromShipsInOurBorders;
            Relationship totalAnger2 = this;
            totalAnger2.TotalAnger = totalAnger2.TotalAnger + this.Anger_MilitaryConflict;
            Relationship totalAnger3 = this;
            totalAnger3.TotalAnger = totalAnger3.TotalAnger + this.Anger_TerritorialConflict;
            Relationship turnsKnown = this;
            turnsKnown.TurnsKnown = turnsKnown.TurnsKnown + 1;
            Relationship relationship3 = this;
            relationship3.turnsSinceLastContact = relationship3.turnsSinceLastContact + 1;
        }
 public void UpdatePlayerRelations(Empire us, Empire them)
 {
     this.UpdateIntelligence(us, them);
     if (this.Treaty_Trade)
     {
         Relationship treatyTradeTurnsExisted = this;
         treatyTradeTurnsExisted.Treaty_Trade_TurnsExisted = treatyTradeTurnsExisted.Treaty_Trade_TurnsExisted + 1;
     }
     if (this.Treaty_Peace)
     {
         Relationship peaceTurnsRemaining = this;
         peaceTurnsRemaining.PeaceTurnsRemaining = peaceTurnsRemaining.PeaceTurnsRemaining - 1;
         if (this.PeaceTurnsRemaining <= 0)
         {
             this.Treaty_Peace = false;
             us.GetRelations()[them].Treaty_Peace = false;
             us.GetUS().NotificationManager.AddPeaceTreatyExpiredNotification(them);
         }
     }
 }
        public void DamageRelationship(Empire Us, Empire Them, string why, float Amount, Planet p)
        {
            if (Us.data.DiplomaticPersonality == null)
            {
                return;
            }
            #if PERF
            if (EmpireManager.GetEmpireByName(Us.GetUS().PlayerLoyalty)==Them)
                return;
            #endif

            if (GlobalStats.perf && EmpireManager.GetEmpireByName(Us.GetUS().PlayerLoyalty) == Them)
                return;
            string str = why;
            string str1 = str;
            if (str != null)
            {
                if (str1 == "Caught Spying")
                {
                    Relationship angerDiplomaticConflict = this;
                    angerDiplomaticConflict.Anger_DiplomaticConflict = angerDiplomaticConflict.Anger_DiplomaticConflict + Amount;
                    Relationship totalAnger = this;
                    totalAnger.TotalAnger = totalAnger.TotalAnger + Amount;
                    Relationship trust = this;
                    trust.Trust = trust.Trust - Amount;
                    Relationship spiesDetected = this;
                    spiesDetected.SpiesDetected = spiesDetected.SpiesDetected + 1;
                    if (Us.data.DiplomaticPersonality.Name == "Honorable" || Us.data.DiplomaticPersonality.Name == "Xenophobic")
                    {
                        Relationship relationship = this;
                        relationship.Anger_DiplomaticConflict = relationship.Anger_DiplomaticConflict + Amount;
                        Relationship totalAnger1 = this;
                        totalAnger1.TotalAnger = totalAnger1.TotalAnger + Amount;
                        Relationship trust1 = this;
                        trust1.Trust = trust1.Trust - Amount;
                    }
                    if (this.Treaty_Alliance)
                    {
                        Relationship timesSpiedOnAlly = this;
                        timesSpiedOnAlly.TimesSpiedOnAlly = timesSpiedOnAlly.TimesSpiedOnAlly + 1;
                        if (this.TimesSpiedOnAlly == 1)
                        {
                            if (EmpireManager.GetEmpireByName(Us.GetUS().PlayerLoyalty) == Them && !Us.isFaction)
                            {
                                Us.GetUS().ScreenManager.AddScreen(new DiplomacyScreen(Us, Them, "Caught_Spying_Ally_1", true));
                                return;
                            }
                        }
                        else if (this.TimesSpiedOnAlly > 1)
                        {
                            if (EmpireManager.GetEmpireByName(Us.GetUS().PlayerLoyalty) == Them && !Us.isFaction)
                            {
                                Us.GetUS().ScreenManager.AddScreen(new DiplomacyScreen(Us, Them, "Caught_Spying_Ally_2", true));
                            }
                            this.Treaty_Alliance = false;
                            this.Treaty_NAPact = false;
                            this.Treaty_OpenBorders = false;
                            this.Treaty_Trade = false;
                            this.Posture = Ship_Game.Gameplay.Posture.Hostile;
                            return;
                        }
                    }
                    else if (this.SpiesDetected == 1 && !this.AtWar && EmpireManager.GetEmpireByName(Us.GetUS().PlayerLoyalty) == Them && !Us.isFaction)
                    {
                        if (this.SpiesDetected == 1)
                        {
                            if (EmpireManager.GetEmpireByName(Us.GetUS().PlayerLoyalty) == Them && !Us.isFaction)
                            {
                                Us.GetUS().ScreenManager.AddScreen(new DiplomacyScreen(Us, Them, "Caught_Spying_1", true));
                                return;
                            }
                        }
                        else if (this.SpiesDetected == 2)
                        {
                            if (EmpireManager.GetEmpireByName(Us.GetUS().PlayerLoyalty) == Them && !Us.isFaction)
                            {
                                Us.GetUS().ScreenManager.AddScreen(new DiplomacyScreen(Us, Them, "Caught_Spying_2", true));
                                return;
                            }
                        }
                        else if (this.SpiesDetected >= 3)
                        {
                            if (EmpireManager.GetEmpireByName(Us.GetUS().PlayerLoyalty) == Them && !Us.isFaction)
                            {
                                Us.GetUS().ScreenManager.AddScreen(new DiplomacyScreen(Us, Them, "Caught_Spying_3", true));
                            }
                            this.Treaty_Alliance = false;
                            this.Treaty_NAPact = false;
                            this.Treaty_OpenBorders = false;
                            this.Treaty_Trade = false;
                            this.Posture = Ship_Game.Gameplay.Posture.Hostile;
                            return;
                        }
                    }
                }
                else if (str1 == "Caught Spying Failed")
                {
                    Relationship angerDiplomaticConflict1 = this;
                    angerDiplomaticConflict1.Anger_DiplomaticConflict = angerDiplomaticConflict1.Anger_DiplomaticConflict + Amount;
                    Relationship relationship1 = this;
                    relationship1.TotalAnger = relationship1.TotalAnger + Amount;
                    Relationship trust2 = this;
                    trust2.Trust = trust2.Trust - Amount;
                    if (Us.data.DiplomaticPersonality.Name == "Honorable" || Us.data.DiplomaticPersonality.Name == "Xenophobic")
                    {
                        Relationship angerDiplomaticConflict2 = this;
                        angerDiplomaticConflict2.Anger_DiplomaticConflict = angerDiplomaticConflict2.Anger_DiplomaticConflict + Amount;
                        Relationship totalAnger2 = this;
                        totalAnger2.TotalAnger = totalAnger2.TotalAnger + Amount;
                        Relationship relationship2 = this;
                        relationship2.Trust = relationship2.Trust - Amount;
                    }
                    Relationship spiesKilled = this;
                    spiesKilled.SpiesKilled = spiesKilled.SpiesKilled + 1;
                    if (this.Treaty_Alliance)
                    {
                        Relationship timesSpiedOnAlly1 = this;
                        timesSpiedOnAlly1.TimesSpiedOnAlly = timesSpiedOnAlly1.TimesSpiedOnAlly + 1;
                        if (this.TimesSpiedOnAlly == 1)
                        {
                            if (EmpireManager.GetEmpireByName(Us.GetUS().PlayerLoyalty) == Them && !Us.isFaction)
                            {
                                Us.GetUS().ScreenManager.AddScreen(new DiplomacyScreen(Us, Them, "Caught_Spying_Ally_1", true));
                                return;
                            }
                        }
                        else if (this.TimesSpiedOnAlly > 1)
                        {
                            if (EmpireManager.GetEmpireByName(Us.GetUS().PlayerLoyalty) == Them && !Us.isFaction)
                            {
                                Us.GetUS().ScreenManager.AddScreen(new DiplomacyScreen(Us, Them, "Caught_Spying_Ally_2", true));
                            }
                            this.Treaty_Alliance = false;
                            this.Treaty_NAPact = false;
                            this.Treaty_OpenBorders = false;
                            this.Treaty_Trade = false;
                            this.Posture = Ship_Game.Gameplay.Posture.Hostile;
                            return;
                        }
                    }
                    else if (EmpireManager.GetEmpireByName(Us.GetUS().PlayerLoyalty) == Them && !Us.isFaction)
                    {
                        Us.GetUS().ScreenManager.AddScreen(new DiplomacyScreen(Us, Them, "Killed_Spy_1", true));
                        return;
                    }
                }
                else if (str1 == "Insulted")
                {
                    Relationship angerDiplomaticConflict3 = this;
                    angerDiplomaticConflict3.Anger_DiplomaticConflict = angerDiplomaticConflict3.Anger_DiplomaticConflict + Amount;
                    Relationship totalAnger3 = this;
                    totalAnger3.TotalAnger = totalAnger3.TotalAnger + Amount;
                    Relationship trust3 = this;
                    trust3.Trust = trust3.Trust - Amount;
                    if (Us.data.DiplomaticPersonality.Name == "Honorable" || Us.data.DiplomaticPersonality.Name == "Xenophobic")
                    {
                        Relationship relationship3 = this;
                        relationship3.Anger_DiplomaticConflict = relationship3.Anger_DiplomaticConflict + Amount;
                        Relationship totalAnger4 = this;
                        totalAnger4.TotalAnger = totalAnger4.TotalAnger + Amount;
                        Relationship trust4 = this;
                        trust4.Trust = trust4.Trust - Amount;
                        return;
                    }
                }
                else if (str1 == "Colonized Owned System")
                {
                    List<Planet> OurTargetPlanets = new List<Planet>();
                    List<Planet> TheirTargetPlanets = new List<Planet>();
                    foreach (Goal g in Us.GetGSAI().Goals)
                    {
                        if (g.type != GoalType.Colonize)
                        {
                            continue;
                        }
                        OurTargetPlanets.Add(g.GetMarkedPlanet());
                    }
                    foreach (Planet theirp in Them.GetPlanets())
                    {
                        TheirTargetPlanets.Add(theirp);
                    }
                    bool MatchFound = false;
                    SolarSystem sharedSystem = null;
                    foreach (Planet planet in OurTargetPlanets)
                    {
                        foreach (Planet other in TheirTargetPlanets)
                        {
                            if (p == null || other == null || p.system != other.system)
                            {
                                continue;
                            }
                            sharedSystem = p.system;
                            MatchFound = true;
                            break;
                        }
                        if (!MatchFound || !Us.GetRelations()[Them].WarnedSystemsList.Contains(sharedSystem.guid))
                        {
                            continue;
                        }
                        return;
                    }
                    Relationship angerTerritorialConflict = this;
                    angerTerritorialConflict.Anger_TerritorialConflict = angerTerritorialConflict.Anger_TerritorialConflict + Amount;
                    Relationship relationship4 = this;
                    relationship4.Trust = relationship4.Trust - Amount;
                    if (this.Anger_TerritorialConflict < (float)Us.data.DiplomaticPersonality.Territorialism && !this.AtWar)
                    {
                        if (this.AtWar)
                        {
                            return;
                        }
                        if (EmpireManager.GetEmpireByName(Us.GetUS().PlayerLoyalty) == Them && !Us.isFaction)
                        {
                            if (!this.WarnedAboutShips)
                            {
                                Us.GetUS().ScreenManager.AddScreen(new DiplomacyScreen(Us, Them, "Colonized Warning", p));
                            }
                            else if (!this.AtWar)
                            {
                                Us.GetUS().ScreenManager.AddScreen(new DiplomacyScreen(Us, Them, "Warning Ships then Colonized", p));
                            }
                            this.turnsSinceLastContact = 0;
                            this.WarnedAboutColonizing = true;
                            this.contestedSystem = p.system;
                            this.contestedSystemGuid = p.system.guid;
                            return;
                        }
                    }
                }
                else
                {
                    if (str1 != "Destroyed Ship")
                    {
                        return;
                    }
                    if (this.Anger_MilitaryConflict == 0f && !this.AtWar)
                    {
                        Relationship angerMilitaryConflict = this;
                        angerMilitaryConflict.Anger_MilitaryConflict = angerMilitaryConflict.Anger_MilitaryConflict + Amount;
                        Relationship trust5 = this;
                        trust5.Trust = trust5.Trust - Amount;
                        if (EmpireManager.GetEmpireByName(Us.GetUS().PlayerLoyalty) == Them && !Us.isFaction)
                        {
                            if (this.Anger_MilitaryConflict < 2f)
                            {
                                Us.GetUS().ScreenManager.AddScreen(new DiplomacyScreen(Us, Them, "Aggression Warning"));
                            }
                            Relationship relationship5 = this;
                            relationship5.Trust = relationship5.Trust - Amount;
                        }
                    }
                    Relationship angerMilitaryConflict1 = this;
                    angerMilitaryConflict1.Anger_MilitaryConflict = angerMilitaryConflict1.Anger_MilitaryConflict + Amount;
                }
            }
        }
        private void LoadEverything(object sender, RunWorkerCompletedEventArgs ev)
        {
            bool stop;
            List<SolarSystem>.Enumerator enumerator;
            base.ScreenManager.inter.ObjectManager.Clear();
            this.data = new UniverseData();
            RandomEventManager.ActiveEvent = this.savedData.RandomEvent;
            UniverseScreen.DeepSpaceManager = new SpatialManager();
            this.ThrusterEffect = base.ScreenManager.Content.Load<Effect>("Effects/Thrust");
            int count = this.data.SolarSystemsList.Count;
            this.data.loadFogPath = this.savedData.FogMapName;
            this.data.difficulty = UniverseData.GameDifficulty.Normal;
            this.data.difficulty = this.savedData.gameDifficulty;
            this.data.Size = this.savedData.Size;
            this.data.FTLSpeedModifier = this.savedData.FTLModifier;
            this.data.EnemyFTLSpeedModifier = this.savedData.EnemyFTLModifier;
            this.data.GravityWells = this.savedData.GravityWells;
            //added by gremlin: adjuse projector radius to map size. but only normal or higher.
            //this is pretty bad as its not connected to the creating game screen code that sets the map sizes. If someone changes the map size they wont know to change this as well.
            if (this.data.Size.X > 7300000f)
            Empire.ProjectorRadius = this.data.Size.X / 70f;
            EmpireManager.EmpireList.Clear();
            if (Empire.universeScreen!=null && Empire.universeScreen.MasterShipList != null)
                Empire.universeScreen.MasterShipList.Clear();

            foreach (SavedGame.EmpireSaveData d in this.savedData.EmpireDataList)
            {
                Empire e =new Empire();
                e.data = new EmpireData();
                    e= this.CreateEmpireFromEmpireSaveData(d);
                this.data.EmpireList.Add(e);
                if (e.data.Traits.Name == this.PlayerLoyalty)
                {
                    e.AutoColonize = this.savedData.AutoColonize;
                    e.AutoExplore = this.savedData.AutoExplore;
                    e.AutoFreighters = this.savedData.AutoFreighters;
                    e.AutoBuild = this.savedData.AutoProjectors;
                }
                EmpireManager.EmpireList.Add(e);
            }
            foreach (Empire e in this.data.EmpireList)
            {
                if (e.data.AbsorbedBy == null)
                {
                    continue;
                }
                foreach (KeyValuePair<string, TechEntry> tech in EmpireManager.GetEmpireByName(e.data.AbsorbedBy).GetTDict())
                {
                    if (!tech.Value.Unlocked)
                    {
                        continue;
                    }
                    EmpireManager.GetEmpireByName(e.data.AbsorbedBy).UnlockHullsSave(tech.Key, e.data.Traits.ShipType);
                }
            }
            foreach (SavedGame.EmpireSaveData d in this.savedData.EmpireDataList)
            {
                Empire e = EmpireManager.GetEmpireByName(d.Name);
                foreach (Relationship r in d.Relations)
                {
                    e.GetRelations().Add(EmpireManager.GetEmpireByName(r.Name), r);
                    if (r.ActiveWar == null)
                    {
                        continue;
                    }
                    r.ActiveWar.SetCombatants(e, EmpireManager.GetEmpireByName(r.Name));
                }
            }
            this.data.SolarSystemsList = new List<SolarSystem>();
            foreach (SavedGame.SolarSystemSaveData sdata in this.savedData.SolarSystemDataList)
            {
                SolarSystem system = this.CreateSystemFromData(sdata);
                system.guid = sdata.guid;
                this.data.SolarSystemsList.Add(system);
            }
            foreach (SavedGame.EmpireSaveData d in this.savedData.EmpireDataList)
            {
                Empire e = EmpireManager.GetEmpireByName(d.empireData.Traits.Name);
                foreach (SavedGame.ShipSaveData shipData in d.OwnedShips)
                {
                    Ship ship = Ship.LoadSavedShip(shipData.data);
                    ship.guid = shipData.guid;
                    ship.Name = shipData.Name;
                    if (!string.IsNullOrEmpty(shipData.VanityName))
                        ship.VanityName = shipData.VanityName;
                    else
                    {
                        if (ship.Role == "troop")
                        {
                            if (shipData.TroopList.Count > 0)
                            {
                                ship.VanityName = shipData.TroopList[0].Name;
                            }
                            else
                                ship.VanityName = shipData.Name;
                        }
                        else
                            ship.VanityName = shipData.Name;
                    }
                    ship.Position = shipData.Position;
                    if (shipData.IsPlayerShip)
                    {
                        this.playerShip = ship;
                        this.playerShip.PlayerShip = true;
                        this.data.playerShip = this.playerShip;
                    }
                    ship.experience = shipData.experience;
                    ship.kills = shipData.kills;
                    if (!Ship_Game.ResourceManager.ShipsDict.ContainsKey(shipData.Name))
                    {
                        shipData.data.Hull = shipData.Hull;
                        Ship newShip = Ship.CreateShipFromShipData(shipData.data);
                        newShip.SetShipData(shipData.data);
                        if (!newShip.InitForLoad())
                        {
                            continue;
                        }
                        newShip.InitializeStatus();
                        newShip.IsPlayerDesign = false;
                        newShip.FromSave = true;
                        Ship_Game.ResourceManager.ShipsDict.Add(shipData.Name, newShip);
                    }
                    else if (Ship_Game.ResourceManager.ShipsDict[shipData.Name].FromSave)
                    {
                        ship.IsPlayerDesign = false;
                        ship.FromSave = true;
                    }
                    float oldbasestr = ship.BaseStrength;
                    float newbasestr = ResourceManager.CalculateBaseStrength(ship);
                    ship.BaseStrength = newbasestr;

                    foreach(ModuleSlotData moduleSD in shipData.data.ModuleSlotList)
                    {
                        ShipModule mismatch =null;
                        bool exists =ResourceManager.ShipModulesDict.TryGetValue(moduleSD.InstalledModuleUID,out mismatch);
                        if (exists)
                            continue;
                        System.Diagnostics.Debug.WriteLine(string.Concat("mismatch =", moduleSD.InstalledModuleUID));
                    }

                    ship.PowerCurrent = shipData.Power;
                    ship.yRotation = shipData.yRotation;
                    ship.Ordinance = shipData.Ordnance;
                    ship.Rotation = shipData.Rotation;
                    ship.Velocity = shipData.Velocity;
                    ship.isSpooling = shipData.AfterBurnerOn;
                    ship.InCombatTimer = shipData.InCombatTimer;
                    foreach (Troop t in shipData.TroopList)
                    {
                        t.SetOwner(EmpireManager.GetEmpireByName(t.OwnerString));
                        ship.TroopList.Add(t);
                    }

                    foreach (Rectangle AOO in shipData.AreaOfOperation)
                    {
                        ship.AreaOfOperation.Add(AOO);
                    }
                    ship.TetherGuid = shipData.TetheredTo;
                    ship.TetherOffset = shipData.TetherOffset;
                    if (ship.InCombatTimer > 0f)
                    {
                        ship.InCombat = true;
                    }
                    ship.loyalty = e;
                    ship.InitializeAI();
                    ship.GetAI().CombatState = shipData.data.CombatState;
                    ship.GetAI().FoodOrProd = shipData.AISave.FoodOrProd;
                    ship.GetAI().State = shipData.AISave.state;
                    ship.GetAI().DefaultAIState = shipData.AISave.defaultstate;
                    ship.GetAI().GotoStep = shipData.AISave.GoToStep;
                    ship.GetAI().MovePosition = shipData.AISave.MovePosition;
                    ship.GetAI().OrbitTargetGuid = shipData.AISave.OrbitTarget;
                    ship.GetAI().ColonizeTargetGuid = shipData.AISave.ColonizeTarget;
                    ship.GetAI().TargetGuid = shipData.AISave.AttackTarget;
                    ship.GetAI().SystemToDefendGuid = shipData.AISave.SystemToDefend;
                    ship.GetAI().EscortTargetGuid = shipData.AISave.EscortTarget;
                    bool hasCargo = false;
                    if (shipData.FoodCount > 0f)
                    {
                        ship.AddGood("Food", (int)shipData.FoodCount);
                        ship.GetAI().FoodOrProd = "Food";
                        hasCargo = true;
                    }
                    if (shipData.ProdCount > 0f)
                    {
                        ship.AddGood("Production", (int)shipData.ProdCount);
                        ship.GetAI().FoodOrProd = "Prod";
                        hasCargo = true;
                    }
                    if (shipData.PopCount > 0f)
                    {
                        ship.AddGood("Colonists_1000", (int)shipData.PopCount);
                    }
                    AIState state = ship.GetAI().State;
                    if (state == AIState.SystemTrader)
                    {
                        ship.GetAI().OrderTradeFromSave(hasCargo, shipData.AISave.startGuid, shipData.AISave.endGuid);
                    }
                    else if (state == AIState.PassengerTransport)
                    {
                        ship.GetAI().OrderTransportPassengersFromSave();
                    }
                    e.AddShip(ship);
                    foreach (SavedGame.ProjectileSaveData pdata in shipData.Projectiles)
                    {
                        Weapon w = Ship_Game.ResourceManager.GetWeapon(pdata.Weapon);
                        Projectile p = w.LoadProjectiles(pdata.Velocity, ship);
                        p.Velocity = pdata.Velocity;
                        p.Position = pdata.Position;
                        p.Center = pdata.Position;
                        p.duration = pdata.Duration;
                        ship.Projectiles.Add(p);
                    }
                    this.data.MasterShipList.Add(ship);
                }
            }
            foreach (SavedGame.EmpireSaveData d in this.savedData.EmpireDataList)
            {
                Empire e = EmpireManager.GetEmpireByName(d.Name);
                foreach (SavedGame.FleetSave fleetsave in d.FleetsList)
                {
                    Ship_Game.Gameplay.Fleet fleet = new Ship_Game.Gameplay.Fleet()
                    {
                        guid = fleetsave.FleetGuid,
                        IsCoreFleet = fleetsave.IsCoreFleet,
                        facing = fleetsave.facing
                    };
                    foreach (SavedGame.FleetShipSave ssave in fleetsave.ShipsInFleet)
                    {
                        foreach (Ship ship in this.data.MasterShipList)
                        {
                            if (ship.guid != ssave.shipGuid)
                            {
                                continue;
                            }
                            ship.RelativeFleetOffset = ssave.fleetOffset;
                            fleet.AddShip(ship);
                        }
                    }
                    foreach (FleetDataNode node in fleetsave.DataNodes)
                    {
                        fleet.DataNodes.Add(node);
                    }
                    foreach (FleetDataNode node in fleet.DataNodes)
                    {
                        foreach (Ship ship in fleet.Ships)
                        {
                            if (!(node.ShipGuid != Guid.Empty) || !(ship.guid == node.ShipGuid))
                            {
                                continue;
                            }
                            node.SetShip(ship);
                            node.ShipName = ship.Name;
                            break;
                        }
                    }
                    fleet.AssignPositions(fleet.facing);
                    fleet.Name = fleetsave.Name;
                    fleet.TaskStep = fleetsave.TaskStep;
                    fleet.Owner = e;
                    fleet.Position = fleetsave.Position;

                    if (e.GetFleetsDict().ContainsKey(fleetsave.Key))
                    {
                        e.GetFleetsDict()[fleetsave.Key] = fleet;
                    }
                    else
                    {
                        e.GetFleetsDict().TryAdd(fleetsave.Key, fleet);
                    }
                    e.GetFleetsDict()[fleetsave.Key].SetSpeed();
                    fleet.findAveragePositionset();
                    fleet.Setavgtodestination();

                }
                foreach (SavedGame.ShipSaveData shipData in d.OwnedShips)
                {
                    foreach (Ship ship in e.GetShips())
                    {
                        if (ship.Position != shipData.Position)
                        {
                            continue;
                        }
                    }
                }
            }
            foreach (SavedGame.EmpireSaveData d in this.savedData.EmpireDataList)
            {
                Empire e = EmpireManager.GetEmpireByName(d.Name);
                e.SpaceRoadsList = new List<SpaceRoad>();
                foreach (SavedGame.SpaceRoadSave roadsave in d.SpaceRoadData)
                {
                    SpaceRoad road = new SpaceRoad();
                    foreach (SolarSystem s in this.data.SolarSystemsList)
                    {
                        if (roadsave.OriginGUID == s.guid)
                        {
                            road.SetOrigin(s);
                        }
                        if (roadsave.DestGUID != s.guid)
                        {
                            continue;
                        }
                        road.SetDestination(s);
                    }
                    foreach (SavedGame.RoadNodeSave nodesave in roadsave.RoadNodes)
                    {
                        RoadNode node = new RoadNode();
                        foreach (Ship s in this.data.MasterShipList)
                        {
                            if (nodesave.Guid_Platform != s.guid)
                            {
                                continue;
                            }
                            node.Platform = s;
                        }
                        node.Position = nodesave.Position;
                        road.RoadNodesList.Add(node);
                    }
                    e.SpaceRoadsList.Add(road);
                }
                foreach (SavedGame.GoalSave gsave in d.GSAIData.Goals)
                {
                    Goal g = new Goal()
                    {
                        empire = e,
                        type = gsave.type
                    };
                    if (g.type == GoalType.BuildShips && gsave.ToBuildUID != null && !Ship_Game.ResourceManager.ShipsDict.ContainsKey(gsave.ToBuildUID))
                    {
                        continue;
                    }
                    g.ToBuildUID = gsave.ToBuildUID;
                    g.Step = gsave.GoalStep;
                    g.guid = gsave.GoalGuid;
                    g.GoalName = gsave.GoalName;
                    g.BuildPosition = gsave.BuildPosition;
                    if (gsave.fleetGuid != Guid.Empty)
                    {
                        foreach (KeyValuePair<int, Ship_Game.Gameplay.Fleet> Fleet in e.GetFleetsDict())
                        {
                            if (Fleet.Value.guid != gsave.fleetGuid)
                            {
                                continue;
                            }
                            g.SetFleet(Fleet.Value);
                        }
                    }
                    foreach (SolarSystem s in this.data.SolarSystemsList)
                    {
                        foreach (Planet p in s.PlanetList)
                        {
                            if (p.guid == gsave.planetWhereBuildingAtGuid)
                            {
                                g.SetPlanetWhereBuilding(p);
                            }
                            if (p.guid != gsave.markedPlanetGuid)
                            {
                                continue;
                            }
                            g.SetMarkedPlanet(p);
                        }
                    }
                    foreach (Ship s in this.data.MasterShipList)
                    {
                        if (gsave.colonyShipGuid == s.guid)
                        {
                            g.SetColonyShip(s);
                        }
                        if (gsave.beingBuiltGUID != s.guid)
                        {
                            continue;
                        }
                        g.SetBeingBuilt(s);
                    }
                    e.GetGSAI().Goals.Add(g);
                }
                for (int i = 0; i < d.GSAIData.PinGuids.Count; i++)
                {
                    e.GetGSAI().ThreatMatrix.Pins.TryAdd(d.GSAIData.PinGuids[i], d.GSAIData.PinList[i]);
                }
                e.GetGSAI().UsedFleets = d.GSAIData.UsedFleets;
                lock (GlobalStats.TaskLocker)
                {
                    foreach (MilitaryTask task in d.GSAIData.MilitaryTaskList)
                    {
                        task.SetEmpire(e);
                        e.GetGSAI().TaskList.Add(task);
                        if (task.TargetPlanetGuid != Guid.Empty)
                        {
                            enumerator = this.data.SolarSystemsList.GetEnumerator();
                            try
                            {
                                do
                                {
                                    if (!enumerator.MoveNext())
                                    {
                                        break;
                                    }
                                    SolarSystem s = enumerator.Current;
                                    stop = false;
                                    foreach (Planet p in s.PlanetList)
                                    {
                                        if (p.guid != task.TargetPlanetGuid)
                                        {
                                            continue;
                                        }
                                        task.SetTargetPlanet(p);
                                        stop = true;
                                        break;
                                    }
                                }
                                while (!stop);
                            }
                            finally
                            {
                                ((IDisposable)enumerator).Dispose();
                            }
                        }
                        foreach (Guid guid in task.HeldGoals)
                        {
                            foreach (Goal g in e.GetGSAI().Goals)
                            {
                                if (g.guid != guid)
                                {
                                    continue;
                                }
                                g.Held = true;
                            }
                        }
                        try
                        {
                            if (task.WhichFleet != -1)
                            {
                                e.GetFleetsDict()[task.WhichFleet].Task = task;
                            }
                        }
                        catch
                        {
                            task.WhichFleet = 0;
                        }
                    }
                }
                foreach (SavedGame.ShipSaveData shipData in d.OwnedShips)
                {
                    foreach (Ship ship in this.data.MasterShipList)
                    {
                        if (ship.guid != shipData.guid)
                        {
                            continue;
                        }
                        foreach (Vector2 waypoint in shipData.AISave.ActiveWayPoints)
                        {
                            ship.GetAI().ActiveWayPoints.Enqueue(waypoint);
                        }
                        foreach (SavedGame.ShipGoalSave sg in shipData.AISave.ShipGoalsList)
                        {
                            ArtificialIntelligence.ShipGoal g = new ArtificialIntelligence.ShipGoal(sg.Plan, sg.MovePosition, sg.FacingVector);
                            foreach (SolarSystem s in this.data.SolarSystemsList)
                            {
                                foreach (Planet p in s.PlanetList)
                                {
                                    if (sg.TargetPlanetGuid == p.guid)
                                    {
                                        g.TargetPlanet = p;
                                        ship.GetAI().ColonizeTarget = p;
                                    }
                                    if (p.guid == shipData.AISave.startGuid)
                                    {
                                        ship.GetAI().start = p;
                                    }
                                    if (p.guid != shipData.AISave.endGuid)
                                    {
                                        continue;
                                    }
                                    ship.GetAI().end = p;
                                }
                            }
                            if (sg.fleetGuid != Guid.Empty)
                            {
                                foreach (KeyValuePair<int, Ship_Game.Gameplay.Fleet> fleet in e.GetFleetsDict())
                                {
                                    if (fleet.Value.guid != sg.fleetGuid)
                                    {
                                        continue;
                                    }
                                    g.fleet = fleet.Value;
                                }
                            }
                            g.VariableString = sg.VariableString;
                            g.DesiredFacing = sg.DesiredFacing;
                            g.SpeedLimit = sg.SpeedLimit;
                            foreach (Goal goal in ship.loyalty.GetGSAI().Goals)
                            {
                                if (sg.goalGuid != goal.guid)
                                {
                                    continue;
                                }
                                g.goal = goal;
                            }
                            ship.GetAI().OrderQueue.AddLast(g);
                        }
                    }
                }
            }
            foreach (SavedGame.SolarSystemSaveData sdata in this.savedData.SolarSystemDataList)
            {
                foreach (SavedGame.RingSave rsave in sdata.RingList)
                {
                    Planet p = new Planet();
                    foreach (SolarSystem s in this.data.SolarSystemsList)
                    {
                        foreach (Planet p1 in s.PlanetList)
                        {
                            if (p1.guid != rsave.Planet.guid)
                            {
                                continue;
                            }
                            p = p1;
                            break;
                        }
                    }
                    if (p.Owner == null)
                    {
                        continue;
                    }
                    foreach (SavedGame.QueueItemSave qisave in rsave.Planet.QISaveList)
                    {
                        QueueItem qi = new QueueItem();
                        if (qisave.isBuilding)
                        {
                            qi.isBuilding = true;
                            qi.Building = Ship_Game.ResourceManager.BuildingsDict[qisave.UID];
                            qi.Cost = qi.Building.Cost * this.savedData.GamePacing;
                            qi.NotifyOnEmpty = false;
                            foreach (PlanetGridSquare pgs in p.TilesList)
                            {
                                if ((float)pgs.x != qisave.pgsVector.X || (float)pgs.y != qisave.pgsVector.Y)
                                {
                                    continue;
                                }
                                pgs.QItem = qi;
                                qi.pgs = pgs;
                                break;
                            }
                        }
                        if (qisave.isTroop)
                        {
                            qi.isTroop = true;
                            qi.troop = Ship_Game.ResourceManager.TroopsDict[qisave.UID];
                            qi.Cost = qi.troop.GetCost();
                            qi.NotifyOnEmpty = false;
                        }
                        if (qisave.isShip)
                        {
                            qi.isShip = true;
                            if (!Ship_Game.ResourceManager.ShipsDict.ContainsKey(qisave.UID))
                            {
                                continue;
                            }
                            qi.sData = Ship_Game.ResourceManager.GetShip(qisave.UID).GetShipData();
                            qi.DisplayName = qisave.DisplayName;
                            qi.Cost = 0f;
                            foreach (ModuleSlot slot in Ship_Game.ResourceManager.GetShip(qisave.UID).ModuleSlotList)
                            {
                                if (slot.InstalledModuleUID == null)
                                {
                                    continue;
                                }
                                QueueItem cost = qi;
                                cost.Cost = cost.Cost + Ship_Game.ResourceManager.GetModule(slot.InstalledModuleUID).Cost * this.savedData.GamePacing;
                            }
                            QueueItem queueItem = qi;
                            queueItem.Cost += qi.Cost * p.Owner.data.Traits.ShipCostMod;
                            queueItem.Cost *= (GlobalStats.ActiveModInfo != null && GlobalStats.ActiveModInfo.useHullBonuses && ResourceManager.HullBonuses.ContainsKey(Ship_Game.ResourceManager.GetShip(qisave.UID).GetShipData().Hull) ? 1f - ResourceManager.HullBonuses[Ship_Game.ResourceManager.GetShip(qisave.UID).GetShipData().Hull].CostBonus : 1);
                            if (qi.sData.HasFixedCost)
                            {
                                qi.Cost = (float)qi.sData.FixedCost;
                            }
                            if (qisave.IsRefit)
                            {
                                qi.isRefit = true;
                                qi.Cost = qisave.RefitCost;
                            }
                        }
                        foreach (Goal g in p.Owner.GetGSAI().Goals)
                        {
                            if (g.guid != qisave.GoalGUID)
                            {
                                continue;
                            }
                            qi.Goal = g;
                            qi.NotifyOnEmpty = false;
                        }
                        if (qisave.isShip && qi.Goal != null)
                        {
                            qi.Goal.beingBuilt = Ship_Game.ResourceManager.GetShip(qisave.UID);
                        }
                        qi.productionTowards = qisave.ProgressTowards;
                        p.ConstructionQueue.Add(qi);
                    }
                }
            }
            this.Loaded = true;
        }
        public void AcceptThreat(Offer ToUs, Offer FromUs, Empire us, Empire Them)
        {
            if (ToUs.PeaceTreaty)
            {
                this.empire.GetRelations()[Them].AtWar = false;
                this.empire.GetRelations()[Them].PreparingForWar = false;
                this.empire.GetRelations()[Them].ActiveWar.EndStarDate = this.empire.GetUS().StarDate;
                this.empire.GetRelations()[Them].WarHistory.Add(this.empire.GetRelations()[Them].ActiveWar);
                this.empire.GetRelations()[Them].Posture = Posture.Neutral;
                if (this.empire.GetRelations()[Them].Anger_FromShipsInOurBorders > (float)(this.empire.data.DiplomaticPersonality.Territorialism / 3))
                {
                    this.empire.GetRelations()[Them].Anger_FromShipsInOurBorders = (float)(this.empire.data.DiplomaticPersonality.Territorialism / 3);
                }
                if (this.empire.GetRelations()[Them].Anger_TerritorialConflict > (float)(this.empire.data.DiplomaticPersonality.Territorialism / 3))
                {
                    this.empire.GetRelations()[Them].Anger_TerritorialConflict = (float)(this.empire.data.DiplomaticPersonality.Territorialism / 3);
                }
                this.empire.GetRelations()[Them].Anger_MilitaryConflict = 0f;
                this.empire.GetRelations()[Them].WarnedAboutShips = false;
                this.empire.GetRelations()[Them].WarnedAboutColonizing = false;
                this.empire.GetRelations()[Them].HaveRejected_Demand_Tech = false;
                this.empire.GetRelations()[Them].HaveRejected_OpenBorders = false;
                this.empire.GetRelations()[Them].HaveRejected_TRADE = false;
                this.empire.GetRelations()[Them].HasDefenseFleet = false;
                if (this.empire.GetRelations()[Them].DefenseFleet != -1)
                {
                    this.empire.GetFleetsDict()[this.empire.GetRelations()[Them].DefenseFleet].Task.EndTask();
                }
                lock (GlobalStats.TaskLocker)
                {
                    foreach (MilitaryTask task in this.TaskList)
                    {
                        if (task.GetTargetPlanet() == null || task.GetTargetPlanet().Owner == null || task.GetTargetPlanet().Owner != Them)
                        {
                            continue;
                        }
                        task.EndTask();
                    }
                }
                this.empire.GetRelations()[Them].ActiveWar = null;
                Them.GetRelations()[this.empire].AtWar = false;
                Them.GetRelations()[this.empire].PreparingForWar = false;
                Them.GetRelations()[this.empire].ActiveWar.EndStarDate = Them.GetUS().StarDate;
                Them.GetRelations()[this.empire].WarHistory.Add(Them.GetRelations()[this.empire].ActiveWar);
                Them.GetRelations()[this.empire].Posture = Posture.Neutral;
                if (EmpireManager.GetEmpireByName(Them.GetUS().PlayerLoyalty) != Them)
                {
                    if (Them.GetRelations()[this.empire].Anger_FromShipsInOurBorders > (float)(Them.data.DiplomaticPersonality.Territorialism / 3))
                    {
                        Them.GetRelations()[this.empire].Anger_FromShipsInOurBorders = (float)(Them.data.DiplomaticPersonality.Territorialism / 3);
                    }
                    if (Them.GetRelations()[this.empire].Anger_TerritorialConflict > (float)(Them.data.DiplomaticPersonality.Territorialism / 3))
                    {
                        Them.GetRelations()[this.empire].Anger_TerritorialConflict = (float)(Them.data.DiplomaticPersonality.Territorialism / 3);
                    }
                    Them.GetRelations()[this.empire].Anger_MilitaryConflict = 0f;
                    Them.GetRelations()[this.empire].WarnedAboutShips = false;
                    Them.GetRelations()[this.empire].WarnedAboutColonizing = false;
                    Them.GetRelations()[this.empire].HaveRejected_Demand_Tech = false;
                    Them.GetRelations()[this.empire].HaveRejected_OpenBorders = false;
                    Them.GetRelations()[this.empire].HaveRejected_TRADE = false;
                    if (Them.GetRelations()[this.empire].DefenseFleet != -1)
                    {
                        Them.GetFleetsDict()[Them.GetRelations()[this.empire].DefenseFleet].Task.EndTask();
                    }
                    lock (GlobalStats.TaskLocker)
                    {
                        foreach (MilitaryTask task in Them.GetGSAI().TaskList)
                        {
                            if (task.GetTargetPlanet() == null || task.GetTargetPlanet().Owner == null || task.GetTargetPlanet().Owner != this.empire)
                            {
                                continue;
                            }
                            task.EndTask();
                        }
                    }
                }
                Them.GetRelations()[this.empire].ActiveWar = null;
            }
            if (ToUs.NAPact)
            {
                us.GetRelations()[Them].Treaty_NAPact = true;
                FearEntry te = new FearEntry();
                if (EmpireManager.GetEmpireByName(this.empire.GetUS().PlayerLoyalty) != us)
                {
                    string name = us.data.DiplomaticPersonality.Name;
                    string str = name;
                    if (name != null)
                    {
                        if (str == "Pacifist")
                        {
                            te.FearCost = 0f;
                        }
                        else if (str == "Cunning")
                        {
                            te.FearCost = 0f;
                        }
                        else if (str == "Xenophobic")
                        {
                            te.FearCost = 15f;
                        }
                        else if (str == "Aggressive")
                        {
                            te.FearCost = 35f;
                        }
                        else if (str == "Honorable")
                        {
                            te.FearCost = 5f;
                        }
                        else if (str == "Ruthless")
                        {
                            te.FearCost = 50f;
                        }
                    }
                }
                us.GetRelations()[Them].FearEntries.Add(te);
            }
            if (FromUs.NAPact)
            {
                Them.GetRelations()[us].Treaty_NAPact = true;
                if (EmpireManager.GetEmpireByName(this.empire.GetUS().PlayerLoyalty) != Them)
                {
                    FearEntry te = new FearEntry();
                    string name1 = Them.data.DiplomaticPersonality.Name;
                    string str1 = name1;
                    if (name1 != null)
                    {
                        if (str1 == "Pacifist")
                        {
                            te.FearCost = 0f;
                        }
                        else if (str1 == "Cunning")
                        {
                            te.FearCost = 0f;
                        }
                        else if (str1 == "Xenophobic")
                        {
                            te.FearCost = 15f;
                        }
                        else if (str1 == "Aggressive")
                        {
                            te.FearCost = 35f;
                        }
                        else if (str1 == "Honorable")
                        {
                            te.FearCost = 5f;
                        }
                        else if (str1 == "Ruthless")
                        {
                            te.FearCost = 50f;
                        }
                    }
                    Them.GetRelations()[us].FearEntries.Add(te);
                }
            }
            if (ToUs.TradeTreaty)
            {
                us.GetRelations()[Them].Treaty_Trade = true;
                us.GetRelations()[Them].Treaty_Trade_TurnsExisted = 0;
                FearEntry te = new FearEntry()
                {
                    FearCost = 5f
                };
                us.GetRelations()[Them].FearEntries.Add(te);
            }
            if (FromUs.TradeTreaty)
            {
                Them.GetRelations()[us].Treaty_Trade = true;
                Them.GetRelations()[us].Treaty_Trade_TurnsExisted = 0;
                FearEntry te = new FearEntry()
                {
                    FearCost = 0.1f
                };
                Them.GetRelations()[us].FearEntries.Add(te);
            }
            if (ToUs.OpenBorders)
            {
                us.GetRelations()[Them].Treaty_OpenBorders = true;
                FearEntry te = new FearEntry()
                {
                    FearCost = 5f
                };
                us.GetRelations()[Them].FearEntries.Add(te);
            }
            if (FromUs.OpenBorders)
            {
                Them.GetRelations()[us].Treaty_OpenBorders = true;
                FearEntry te = new FearEntry()
                {
                    FearCost = 5f
                };
                Them.GetRelations()[us].FearEntries.Add(te);
            }
            foreach (string tech in FromUs.TechnologiesOffered)
            {
                Them.UnlockTech(tech);
                if (EmpireManager.GetEmpireByName(this.empire.GetUS().PlayerLoyalty) == us)
                {
                    continue;
                }
                FearEntry te = new FearEntry()
                {
                    FearCost = (us.data.EconomicPersonality.Name == "Technologists" ? ResourceManager.TechTree[tech].Cost / 100f * 0.25f + ResourceManager.TechTree[tech].Cost / 100f : ResourceManager.TechTree[tech].Cost / 100f),
                    TurnTimer = 40
                };
                us.GetRelations()[Them].FearEntries.Add(te);
            }
            foreach (string tech in ToUs.TechnologiesOffered)
            {
                us.UnlockTech(tech);
                if (EmpireManager.GetEmpireByName(this.empire.GetUS().PlayerLoyalty) == Them)
                {
                    continue;
                }
                FearEntry te = new FearEntry()
                {
                    FearCost = (Them.data.EconomicPersonality.Name == "Technologists" ? ResourceManager.TechTree[tech].Cost / 100f * 0.25f + ResourceManager.TechTree[tech].Cost / 100f : ResourceManager.TechTree[tech].Cost / 100f)
                };
                Them.GetRelations()[us].FearEntries.Add(te);
            }
            foreach (string Art in FromUs.ArtifactsOffered)
            {
                Artifact toGive = ResourceManager.ArtifactsDict[Art];
                foreach (Artifact arti in us.data.OwnedArtifacts)
                {
                    if (arti.Name != Art)
                    {
                        continue;
                    }
                    toGive = arti;
                }
                us.RemoveArtifact(toGive);
                Them.AddArtifact(toGive);
            }
            foreach (string Art in ToUs.ArtifactsOffered)
            {
                Artifact toGive = ResourceManager.ArtifactsDict[Art];
                foreach (Artifact arti in Them.data.OwnedArtifacts)
                {
                    if (arti.Name != Art)
                    {
                        continue;
                    }
                    toGive = arti;
                }
                Them.RemoveArtifact(toGive);
                us.AddArtifact(toGive);

            }
            foreach (string planetName in FromUs.ColoniesOffered)
            {
                List<Planet> toRemove = new List<Planet>();
                List<Ship> TroopShips = new List<Ship>();
                foreach (Planet p in us.GetPlanets())
                {
                    if (p.Name != planetName)
                    {
                        continue;
                    }
                    foreach (PlanetGridSquare pgs in p.TilesList)
                    {
                        if (pgs.TroopsHere.Count <= 0 || pgs.TroopsHere[0].GetOwner() != this.empire)
                        {
                            continue;
                        }
                        TroopShips.Add(pgs.TroopsHere[0].Launch());
                    }
                    toRemove.Add(p);
                    p.Owner = Them;
                    Them.AddPlanet(p);
                    p.system.OwnerList.Clear();
                    foreach (Planet pl in p.system.PlanetList)
                    {
                        if (pl.Owner == null || p.system.OwnerList.Contains(pl.Owner))
                        {
                            continue;
                        }
                        p.system.OwnerList.Add(pl.Owner);
                    }
                    float value = p.Population / 1000f + p.FoodHere / 50f + p.ProductionHere / 50f + p.Fertility + p.MineralRichness + p.MaxPopulation / 10000f;
                    foreach (Building b in p.BuildingList)
                    {
                        value = value + b.Cost / 50f;
                    }
                    FearEntry te = new FearEntry();
                    if (value < 15f)
                    {
                        value = 15f;
                    }
                    te.FearCost = (us.data.EconomicPersonality.Name == "Expansionists" ? value + value : value + 0.5f * value);
                    te.TurnTimer = 40;
                    us.GetRelations()[Them].FearEntries.Add(te);
                }
                foreach (Planet p in toRemove)
                {
                    us.GetPlanets().Remove(p);
                }
                foreach (Ship ship in TroopShips)
                {
                    ship.GetAI().OrderRebaseToNearest();
                }
            }
            foreach (string planetName in ToUs.ColoniesOffered)
            {
                List<Planet> toRemove = new List<Planet>();
                List<Ship> TroopShips = new List<Ship>();
                foreach (Planet p in Them.GetPlanets())
                {
                    if (p.Name != planetName)
                    {
                        continue;
                    }
                    toRemove.Add(p);
                    p.Owner = us;
                    us.AddPlanet(p);
                    p.system.OwnerList.Clear();
                    foreach (Planet pl in p.system.PlanetList)
                    {
                        if (pl.Owner == null || p.system.OwnerList.Contains(pl.Owner))
                        {
                            continue;
                        }
                        p.system.OwnerList.Add(pl.Owner);
                    }
                    float value = p.Population / 1000f + p.FoodHere / 50f + p.ProductionHere / 50f + p.Fertility + p.MineralRichness + p.MaxPopulation / 10000f;
                    foreach (Building b in p.BuildingList)
                    {
                        value = value + b.Cost / 50f;
                    }
                    foreach (PlanetGridSquare pgs in p.TilesList)
                    {
                        if (pgs.TroopsHere.Count <= 0 || pgs.TroopsHere[0].GetOwner() != Them)
                        {
                            continue;
                        }
                        TroopShips.Add(pgs.TroopsHere[0].Launch());
                    }
                    if (EmpireManager.GetEmpireByName(this.empire.GetUS().PlayerLoyalty) == Them)
                    {
                        continue;
                    }
                    FearEntry te = new FearEntry()
                    {
                        FearCost = (Them.data.EconomicPersonality.Name == "Expansionists" ? value + value : value + 0.5f * value),
                        TurnTimer = 40
                    };
                    Them.GetRelations()[us].FearEntries.Add(te);
                }
                foreach (Planet p in toRemove)
                {
                    Them.GetPlanets().Remove(p);
                }
                foreach (Ship ship in TroopShips)
                {
                    ship.GetAI().OrderRebaseToNearest();
                }
            }
            us.GetRelations()[Them].UpdateRelationship(us, Them);
        }
 public void EndWarFromEvent(Empire them)
 {
     this.empire.GetRelations()[them].AtWar = false;
     them.GetRelations()[this.empire].AtWar = false;
     lock (GlobalStats.TaskLocker)
     {
         foreach (MilitaryTask task in this.TaskList)
         {
             if (this.empire.GetFleetsDict().ContainsKey(task.WhichFleet) && this.empire.data.Traits.Name == "Corsairs")
             {
                 bool foundhome = false;
                 foreach (Ship ship in this.empire.GetShips())
                 {
                     if (!(ship.Role == "station") && !(ship.Role == "platform"))
                     {
                         continue;
                     }
                     foundhome = true;
                     List<Ship>.Enumerator enumerator = this.empire.GetFleetsDict()[task.WhichFleet].Ships.GetEnumerator();
                     try
                     {
                         while (enumerator.MoveNext())
                         {
                             Ship fship = enumerator.Current;
                             fship.GetAI().OrderQueue.Clear();
                             fship.DoEscort(ship);
                         }
                         break;
                     }
                     finally
                     {
                         ((IDisposable)enumerator).Dispose();
                     }
                 }
                 if (!foundhome)
                 {
                     foreach (Ship ship in this.empire.GetFleetsDict()[task.WhichFleet].Ships)
                     {
                         ship.GetAI().OrderQueue.Clear();
                         ship.GetAI().State = AIState.AwaitingOrders;
                     }
                 }
             }
             task.EndTaskWithMove();
         }
     }
 }
 public DiplomacyScreen(Empire e, Empire us, string which, Planet p)
 {
     float TheirOpinionOfUs;
     e.GetRelations()[us].turnsSinceLastContact = 0;
     this.pToDiscuss = p;
     this.sysToDiscuss = p.system;
     this.them = e;
     this.playerEmpire = us;
     this.whichDialogue = which;
     base.TransitionOnTime = TimeSpan.FromSeconds(1);
     string str = which;
     string str1 = str;
     if (str != null)
     {
         if (str1 == "Declare War Defense")
         {
             this.TheirText = this.GetDialogueByName(which);
             this.dState = DiplomacyScreen.DialogState.End;
             this.WarDeclared = true;
             base.TransitionOnTime = TimeSpan.FromSeconds(1);
             return;
         }
         else if (str1 == "Declare War BC")
         {
             this.TheirText = this.GetDialogueByName(which);
             this.dState = DiplomacyScreen.DialogState.End;
             this.WarDeclared = true;
             base.TransitionOnTime = TimeSpan.FromSeconds(1);
             return;
         }
         else
         {
             if (str1 != "Declare War BC TarSys")
             {
                 TheirOpinionOfUs = this.them.GetRelations()[this.playerEmpire].GetStrength();
                 if (TheirOpinionOfUs < 0f)
                 {
                     TheirOpinionOfUs = 0f;
                 }
                 this.TheirText = this.GetDialogue(TheirOpinionOfUs);
                 base.TransitionOnTime = TimeSpan.FromSeconds(1);
                 return;
             }
             this.TheirText = this.GetDialogueByName(which);
             this.dState = DiplomacyScreen.DialogState.End;
             this.WarDeclared = true;
             base.TransitionOnTime = TimeSpan.FromSeconds(1);
             return;
         }
     }
     TheirOpinionOfUs = this.them.GetRelations()[this.playerEmpire].GetStrength();
     if (TheirOpinionOfUs < 0f)
     {
         TheirOpinionOfUs = 0f;
     }
     this.TheirText = this.GetDialogue(TheirOpinionOfUs);
     base.TransitionOnTime = TimeSpan.FromSeconds(1);
 }
 public DiplomacyScreen(Empire e, Empire us, string which, Offer OurOffer, Offer TheirOffer, Empire taremp)
 {
     e.GetRelations()[us].turnsSinceLastContact = 0;
     this.them = e;
     this.playerEmpire = us;
     this.empToDiscuss = taremp;
     this.whichDialogue = which;
     base.IsPopup = true;
     this.dState = DiplomacyScreen.DialogState.TheirOffer;
     this.TheirText = this.GetDialogueByName(which);
     this.OurOffer = OurOffer;
     this.TheirOffer = TheirOffer;
     base.TransitionOnTime = TimeSpan.FromSeconds(1);
 }
 public DiplomacyScreen(Empire e, Empire us, string which, bool EndOnly)
 {
     e.GetRelations()[us].turnsSinceLastContact = 0;
     this.them = e;
     this.playerEmpire = us;
     this.whichDialogue = which;
     base.IsPopup = true;
     this.TheirText = this.GetDialogueByName(which);
     this.dState = DiplomacyScreen.DialogState.End;
     base.TransitionOnTime = TimeSpan.FromSeconds(1);
 }
 public float GetPredictedEnemyPresence(float time, Empire us)
 {
     float prediction = 0f;
     Relationship war = null;
     foreach (Ship ship in this.ShipList)
     {
         if (ship == null || ship.loyalty == us || (us.GetRelations().TryGetValue(ship.loyalty,out war) && war.Treaty_Alliance ))
         {
             continue;
         }
         if (war.Trust > 25)
             prediction = prediction + ship.GetStrength() * ( (125 -war.Trust) /100 );
         else
             prediction = prediction + ship.GetStrength();
     }
     List<GameplayObject> nearby = UniverseScreen.ShipSpatialManager.GetNearby(this.Position);
     for (int i = 0; i < nearby.Count; i++)
     {
         Ship ship = nearby[i] as Ship;
         if (ship != null && ship.loyalty != us && !this.ShipList.Contains(ship) && (ship.loyalty.isFaction || us.GetRelations()[ship.loyalty].AtWar) && HelperFunctions.IntersectCircleSegment(this.Position, 100000f * UniverseScreen.GameScaleStatic, ship.Center, ship.Center + (ship.Velocity * time)))
         {
             prediction = prediction + ship.GetStrength();
         }
     }
     return prediction;
 }
 public Vector2 PingRadarAvgPos(Vector2 Position, float Radius, Empire Us)
 {
     Vector2 pos = new Vector2();
     int num = 0;
     foreach (KeyValuePair<Guid, ThreatMatrix.Pin> pin in this.Pins)
     {
         if (Vector2.Distance(Position, pin.Value.Position) >= Radius || EmpireManager.GetEmpireByName(pin.Value.EmpireName) == Us || !Us.isFaction && !EmpireManager.GetEmpireByName(pin.Value.EmpireName).isFaction && !Us.GetRelations()[EmpireManager.GetEmpireByName(pin.Value.EmpireName)].AtWar)
         {
             continue;
         }
         num++;
         pos = pos + pin.Value.Position;
     }
     if (num > 0)
     {
         pos = pos / (float)num;
     }
     return pos;
 }
 public float PingRadarStr(Vector2 Position, float Radius, Empire Us)
 {
     float str = 0f;
     foreach (KeyValuePair<Guid, ThreatMatrix.Pin> pin in this.Pins)
     {
         if (Vector2.Distance(Position, pin.Value.Position) >= Radius
             || EmpireManager.GetEmpireByName(pin.Value.EmpireName) == Us
             || !Us.isFaction && !EmpireManager.GetEmpireByName(pin.Value.EmpireName).isFaction
             && !Us.GetRelations()[EmpireManager.GetEmpireByName(pin.Value.EmpireName)].AtWar)
         {
             continue;
         }
         str = str + pin.Value.Strength;
     }
     return str;
 }
 public void DeclareWarOn(Empire them, WarType wt)
 {
     this.empire.GetRelations()[them].PreparingForWar = false;
     if (this.empire.isFaction || this.empire.data.Defeated || (them.data.Defeated || them.isFaction))
         return;
     this.empire.GetRelations()[them].FedQuest = (FederationQuest)null;
     if (this.empire == EmpireManager.GetEmpireByName(this.empire.GetUS().PlayerLoyalty) && this.empire.GetRelations()[them].Treaty_NAPact)
     {
         this.empire.GetRelations()[them].Treaty_NAPact = false;
         foreach (KeyValuePair<Empire, Relationship> keyValuePair in this.empire.GetRelations())
         {
             if (keyValuePair.Key != them)
             {
                 keyValuePair.Key.GetRelations()[this.empire].Trust -= 50f;
                 keyValuePair.Key.GetRelations()[this.empire].Anger_DiplomaticConflict += 20f;
                 keyValuePair.Key.GetRelations()[this.empire].UpdateRelationship(keyValuePair.Key, this.empire);
             }
         }
         them.GetRelations()[this.empire].Trust -= 50f;
         them.GetRelations()[this.empire].Anger_DiplomaticConflict += 50f;
         them.GetRelations()[this.empire].UpdateRelationship(them, this.empire);
     }
     if (them == EmpireManager.GetEmpireByName(this.empire.GetUS().PlayerLoyalty) && !this.empire.GetRelations()[them].AtWar)
     {
         switch (wt)
         {
             case WarType.BorderConflict:
                 if (this.empire.GetRelations()[them].contestedSystemGuid != Guid.Empty)
                 {
                     this.empire.GetUS().ScreenManager.AddScreen((GameScreen)new DiplomacyScreen(this.empire, them, "Declare War BC TarSys", this.empire.GetRelations()[them].GetContestedSystem()));
                     break;
                 }
                 else
                 {
                     this.empire.GetUS().ScreenManager.AddScreen((GameScreen)new DiplomacyScreen(this.empire, them, "Declare War BC"));
                     break;
                 }
             case WarType.ImperialistWar:
                 if (this.empire.GetRelations()[them].Treaty_NAPact)
                 {
                     this.empire.GetUS().ScreenManager.AddScreen((GameScreen)new DiplomacyScreen(this.empire, them, "Declare War Imperialism Break NA"));
                     using (Dictionary<Empire, Relationship>.Enumerator enumerator = this.empire.GetRelations().GetEnumerator())
                     {
                         while (enumerator.MoveNext())
                         {
                             KeyValuePair<Empire, Relationship> current = enumerator.Current;
                             if (current.Key != them)
                             {
                                 current.Value.Trust -= 50f;
                                 current.Value.Anger_DiplomaticConflict += 20f;
                             }
                         }
                         break;
                     }
                 }
                 else
                 {
                     this.empire.GetUS().ScreenManager.AddScreen((GameScreen)new DiplomacyScreen(this.empire, them, "Declare War Imperialism"));
                     break;
                 }
             case WarType.DefensiveWar:
                 if (!this.empire.GetRelations()[them].Treaty_NAPact)
                 {
                     this.empire.GetUS().ScreenManager.AddScreen((GameScreen)new DiplomacyScreen(this.empire, them, "Declare War Defense"));
                     this.empire.GetRelations()[them].Anger_DiplomaticConflict += 25f;
                     this.empire.GetRelations()[them].Trust -= 25f;
                     break;
                 }
                 else if (this.empire.GetRelations()[them].Treaty_NAPact)
                 {
                     this.empire.GetUS().ScreenManager.AddScreen((GameScreen)new DiplomacyScreen(this.empire, them, "Declare War Defense BrokenNA"));
                     this.empire.GetRelations()[them].Treaty_NAPact = false;
                     foreach (KeyValuePair<Empire, Relationship> keyValuePair in this.empire.GetRelations())
                     {
                         if (keyValuePair.Key != them)
                         {
                             keyValuePair.Value.Trust -= 50f;
                             keyValuePair.Value.Anger_DiplomaticConflict += 20f;
                         }
                     }
                     this.empire.GetRelations()[them].Trust -= 50f;
                     this.empire.GetRelations()[them].Anger_DiplomaticConflict += 50f;
                     break;
                 }
                 else
                     break;
         }
     }
     if (them == EmpireManager.GetEmpireByName(this.empire.GetUS().PlayerLoyalty) || this.empire == EmpireManager.GetEmpireByName(this.empire.GetUS().PlayerLoyalty))
         Ship.universeScreen.NotificationManager.AddWarDeclaredNotification(this.empire, them);
     else if (EmpireManager.GetEmpireByName(this.empire.GetUS().PlayerLoyalty).GetRelations()[them].Known && EmpireManager.GetEmpireByName(this.empire.GetUS().PlayerLoyalty).GetRelations()[this.empire].Known)
         Ship.universeScreen.NotificationManager.AddWarDeclaredNotification(this.empire, them);
     this.empire.GetRelations()[them].AtWar = true;
     this.empire.GetRelations()[them].Posture = Posture.Hostile;
     this.empire.GetRelations()[them].ActiveWar = new War(this.empire, them, this.empire.GetUS().StarDate);
     this.empire.GetRelations()[them].ActiveWar.WarType = wt;
     if ((double)this.empire.GetRelations()[them].Trust > 0.0)
         this.empire.GetRelations()[them].Trust = 0.0f;
     this.empire.GetRelations()[them].Treaty_OpenBorders = false;
     this.empire.GetRelations()[them].Treaty_NAPact = false;
     this.empire.GetRelations()[them].Treaty_Trade = false;
     this.empire.GetRelations()[them].Treaty_Alliance = false;
     this.empire.GetRelations()[them].Treaty_Peace = false;
     them.GetGSAI().GetWarDeclaredOnUs(this.empire, wt);
 }
 public DiplomacyScreen(Empire e, Empire us, string which, SolarSystem s)
 {
     float TheirOpinionOfUs;
     e.GetRelations()[us].turnsSinceLastContact = 0;
     this.sysToDiscuss = s;
     this.them = e;
     this.playerEmpire = us;
     this.whichDialogue = which;
     base.TransitionOnTime = TimeSpan.FromSeconds(1);
     string str = which;
     string str1 = str;
     if (str != null)
     {
         switch (str1)
         {
             case "Invaded NA Pact":
             {
                 this.TheirText = this.GetDialogueByName(which);
                 this.dState = DiplomacyScreen.DialogState.End;
                 this.WarDeclared = true;
                 break;
             }
             case "Invaded Start War":
             {
                 this.TheirText = this.GetDialogueByName(which);
                 this.dState = DiplomacyScreen.DialogState.End;
                 this.WarDeclared = true;
                 break;
             }
             case "Declare War Defense":
             {
                 this.TheirText = this.GetDialogueByName(which);
                 this.dState = DiplomacyScreen.DialogState.End;
                 this.WarDeclared = true;
                 break;
             }
             case "Declare War BC":
             {
                 this.TheirText = this.GetDialogueByName(which);
                 this.dState = DiplomacyScreen.DialogState.End;
                 this.WarDeclared = true;
                 break;
             }
             case "Declare War BC TarSys":
             {
                 this.TheirText = this.GetDialogueByName(which);
                 this.dState = DiplomacyScreen.DialogState.End;
                 this.WarDeclared = true;
                 break;
             }
             case "Stole Claim":
             {
                 this.TheirText = this.GetDialogueByName(which);
                 this.dState = DiplomacyScreen.DialogState.End;
                 break;
             }
             case "Stole Claim 2":
             {
                 this.TheirText = this.GetDialogueByName(which);
                 this.dState = DiplomacyScreen.DialogState.End;
                 break;
             }
             case "Stole Claim 3":
             {
                 this.TheirText = this.GetDialogueByName(which);
                 this.dState = DiplomacyScreen.DialogState.End;
                 break;
             }
             default:
             {
                 TheirOpinionOfUs = this.them.GetRelations()[this.playerEmpire].GetStrength();
                 if (TheirOpinionOfUs < 0f)
                 {
                     TheirOpinionOfUs = 0f;
                 }
                 this.TheirText = this.GetDialogue(TheirOpinionOfUs);
                 base.TransitionOnTime = TimeSpan.FromSeconds(1);
                 return;
             }
         }
     }
     else
     {
         TheirOpinionOfUs = this.them.GetRelations()[this.playerEmpire].GetStrength();
         if (TheirOpinionOfUs < 0f)
         {
             TheirOpinionOfUs = 0f;
         }
         this.TheirText = this.GetDialogue(TheirOpinionOfUs);
         base.TransitionOnTime = TimeSpan.FromSeconds(1);
         return;
     }
     base.TransitionOnTime = TimeSpan.FromSeconds(1);
 }
 public void DeclareWarOnViaCall(Empire them, WarType wt)
 {
     this.empire.GetRelations()[them].PreparingForWar = false;
     if (this.empire.isFaction || this.empire.data.Defeated || them.data.Defeated || them.isFaction)
     {
         return;
     }
     this.empire.GetRelations()[them].FedQuest = null;
     if (this.empire == EmpireManager.GetEmpireByName(this.empire.GetUS().PlayerLoyalty) && this.empire.GetRelations()[them].Treaty_NAPact)
     {
         this.empire.GetRelations()[them].Treaty_NAPact = false;
         Relationship item = them.GetRelations()[this.empire];
         item.Trust = item.Trust - 50f;
         Relationship angerDiplomaticConflict = them.GetRelations()[this.empire];
         angerDiplomaticConflict.Anger_DiplomaticConflict = angerDiplomaticConflict.Anger_DiplomaticConflict + 50f;
         them.GetRelations()[this.empire].UpdateRelationship(them, this.empire);
     }
     if (them == EmpireManager.GetEmpireByName(this.empire.GetUS().PlayerLoyalty) && !this.empire.GetRelations()[them].AtWar)
     {
         switch (wt)
         {
             case WarType.BorderConflict:
             {
                 if (this.empire.GetRelations()[them].contestedSystemGuid == Guid.Empty)
                 {
                     this.empire.GetUS().ScreenManager.AddScreen(new DiplomacyScreen(this.empire, them, "Declare War BC"));
                     break;
                 }
                 else
                 {
                     this.empire.GetUS().ScreenManager.AddScreen(new DiplomacyScreen(this.empire, them, "Declare War BC Tarsys", this.empire.GetRelations()[them].GetContestedSystem()));
                     break;
                 }
             }
             case WarType.ImperialistWar:
             {
                 if (!this.empire.GetRelations()[them].Treaty_NAPact)
                 {
                     this.empire.GetUS().ScreenManager.AddScreen(new DiplomacyScreen(this.empire, them, "Declare War Imperialism"));
                     break;
                 }
                 else
                 {
                     this.empire.GetUS().ScreenManager.AddScreen(new DiplomacyScreen(this.empire, them, "Declare War Imperialism Break NA"));
                     break;
                 }
             }
             case WarType.DefensiveWar:
             {
                 if (this.empire.GetRelations()[them].Treaty_NAPact)
                 {
                     if (!this.empire.GetRelations()[them].Treaty_NAPact)
                     {
                         break;
                     }
                     this.empire.GetUS().ScreenManager.AddScreen(new DiplomacyScreen(this.empire, them, "Declare War Defense BrokenNA"));
                     this.empire.GetRelations()[them].Treaty_NAPact = false;
                     Relationship trust = this.empire.GetRelations()[them];
                     trust.Trust = trust.Trust - 50f;
                     Relationship relationship = this.empire.GetRelations()[them];
                     relationship.Anger_DiplomaticConflict = relationship.Anger_DiplomaticConflict + 50f;
                     break;
                 }
                 else
                 {
                     this.empire.GetUS().ScreenManager.AddScreen(new DiplomacyScreen(this.empire, them, "Declare War Defense"));
                     Relationship item1 = this.empire.GetRelations()[them];
                     item1.Anger_DiplomaticConflict = item1.Anger_DiplomaticConflict + 25f;
                     Relationship trust1 = this.empire.GetRelations()[them];
                     trust1.Trust = trust1.Trust - 25f;
                     break;
                 }
             }
         }
     }
     if (them == EmpireManager.GetEmpireByName(this.empire.GetUS().PlayerLoyalty) || this.empire == EmpireManager.GetEmpireByName(this.empire.GetUS().PlayerLoyalty))
     {
         Ship.universeScreen.NotificationManager.AddWarDeclaredNotification(this.empire, them);
     }
     else if (EmpireManager.GetEmpireByName(this.empire.GetUS().PlayerLoyalty).GetRelations()[them].Known && EmpireManager.GetEmpireByName(this.empire.GetUS().PlayerLoyalty).GetRelations()[this.empire].Known)
     {
         Ship.universeScreen.NotificationManager.AddWarDeclaredNotification(this.empire, them);
     }
     this.empire.GetRelations()[them].AtWar = true;
     this.empire.GetRelations()[them].Posture = Posture.Hostile;
     this.empire.GetRelations()[them].ActiveWar = new War(this.empire, them, this.empire.GetUS().StarDate)
     {
         WarType = wt
     };
     if (this.empire.GetRelations()[them].Trust > 0f)
     {
         this.empire.GetRelations()[them].Trust = 0f;
     }
     this.empire.GetRelations()[them].Treaty_OpenBorders = false;
     this.empire.GetRelations()[them].Treaty_NAPact = false;
     this.empire.GetRelations()[them].Treaty_Trade = false;
     this.empire.GetRelations()[them].Treaty_Alliance = false;
     this.empire.GetRelations()[them].Treaty_Peace = false;
     them.GetGSAI().GetWarDeclaredOnUs(this.empire, wt);
 }
 public DiplomacyScreen(Empire e, Empire us, string which)
 {
     float TheirOpinionOfUs;
     e.GetRelations()[us].turnsSinceLastContact = 0;
     this.them = e;
     this.playerEmpire = us;
     this.whichDialogue = which;
     base.IsPopup = true;
     string str = which;
     string str1 = str;
     if (str != null)
     {
         switch (str1)
         {
             case "Conquered_Player":
             {
                 this.TheirText = this.GetDialogueByName(which);
                 this.dState = DiplomacyScreen.DialogState.End;
                 break;
             }
             case "Declare War Imperialism":
             {
                 this.TheirText = this.GetDialogueByName(which);
                 this.dState = DiplomacyScreen.DialogState.End;
                 this.WarDeclared = true;
                 break;
             }
             case "Declare War Imperialism Break NA":
             {
                 this.TheirText = this.GetDialogueByName(which);
                 this.dState = DiplomacyScreen.DialogState.End;
                 this.WarDeclared = true;
                 break;
             }
             case "Declare War Defense":
             {
                 this.TheirText = this.GetDialogueByName(which);
                 this.dState = DiplomacyScreen.DialogState.End;
                 this.WarDeclared = true;
                 break;
             }
             case "Declare War Defense BrokenNA":
             {
                 this.TheirText = this.GetDialogueByName(which);
                 this.dState = DiplomacyScreen.DialogState.End;
                 this.WarDeclared = true;
                 break;
             }
             case "Compliment Military":
             {
                 this.TheirText = this.GetDialogueByName(which);
                 this.dState = DiplomacyScreen.DialogState.End;
                 break;
             }
             case "Compliment Military Better":
             {
                 this.TheirText = this.GetDialogueByName(which);
                 this.dState = DiplomacyScreen.DialogState.End;
                 break;
             }
             case "Insult Military":
             {
                 this.TheirText = this.GetDialogueByName(which);
                 this.dState = DiplomacyScreen.DialogState.End;
                 break;
             }
             case "Declare War BC":
             {
                 this.TheirText = this.GetDialogueByName(which);
                 this.dState = DiplomacyScreen.DialogState.End;
                 this.WarDeclared = true;
                 break;
             }
             default:
             {
                 TheirOpinionOfUs = this.them.GetRelations()[this.playerEmpire].GetStrength();
                 if (TheirOpinionOfUs < 0f)
                 {
                     TheirOpinionOfUs = 0f;
                 }
                 this.TheirText = this.GetDialogue(TheirOpinionOfUs);
                 base.TransitionOnTime = TimeSpan.FromSeconds(1);
                 return;
             }
         }
     }
     else
     {
         TheirOpinionOfUs = this.them.GetRelations()[this.playerEmpire].GetStrength();
         if (TheirOpinionOfUs < 0f)
         {
             TheirOpinionOfUs = 0f;
         }
         this.TheirText = this.GetDialogue(TheirOpinionOfUs);
         base.TransitionOnTime = TimeSpan.FromSeconds(1);
         return;
     }
     base.TransitionOnTime = TimeSpan.FromSeconds(1);
 }
 public void SetAlliance(bool ally, Empire them)
 {
     if (ally)
     {
         this.empire.GetRelations()[them].Treaty_Alliance = true;
         this.empire.GetRelations()[them].Treaty_OpenBorders = true;
         them.GetRelations()[this.empire].Treaty_Alliance = true;
         them.GetRelations()[this.empire].Treaty_OpenBorders = true;
         return;
     }
     this.empire.GetRelations()[them].Treaty_Alliance = false;
     this.empire.GetRelations()[them].Treaty_OpenBorders = false;
     them.GetRelations()[this.empire].Treaty_Alliance = false;
     them.GetRelations()[this.empire].Treaty_OpenBorders = false;
 }
        public bool TroopsHereAreEnemies(Empire empire)
        {
            bool enemies = false;
            this.TroopsHere.thisLock.EnterReadLock();
            foreach (Troop trooper in this.TroopsHere)
            {
                Relationship trouble;
                if (!empire.GetRelations().TryGetValue(trooper.GetOwner(), out trouble) || trouble.AtWar)
                {
                    enemies=true;
                    break;
                }

            }
            this.TroopsHere.thisLock.ExitReadLock();
            return enemies;
        }
 public string AnalyzeOffer(Offer ToUs, Offer FromUs, Empire them, Offer.Attitude attitude)
 {
     if (ToUs.Alliance)
     {
         if (!ToUs.IsBlank() || !FromUs.IsBlank())
         {
             return "OFFER_ALLIANCE_TOO_COMPLICATED";
         }
         if (this.empire.GetRelations()[them].Trust < 90f || this.empire.GetRelations()[them].TotalAnger >= 20f || this.empire.GetRelations()[them].TurnsKnown <= 100)
         {
             return "AI_ALLIANCE_REJECT";
         }
         this.SetAlliance(true, them);
         return "AI_ALLIANCE_ACCEPT";
     }
     if (ToUs.PeaceTreaty)
     {
         GSAI.PeaceAnswer answer = this.AnalyzePeaceOffer(ToUs, FromUs, them, attitude);
         if (!answer.peace)
         {
             return answer.answer;
         }
         this.AcceptOffer(ToUs, FromUs, this.empire, them);
         this.empire.GetRelations()[them].Treaty_Peace = true;
         this.empire.GetRelations()[them].PeaceTurnsRemaining = 100;
         them.GetRelations()[this.empire].Treaty_Peace = true;
         them.GetRelations()[this.empire].PeaceTurnsRemaining = 100;
         return answer.answer;
     }
     Empire us = this.empire;
     float TotalTrustRequiredFromUS = 0f;
     DTrait dt = us.data.DiplomaticPersonality;
     if (FromUs.TradeTreaty)
     {
         TotalTrustRequiredFromUS = TotalTrustRequiredFromUS + (float)dt.Trade;
     }
     if (FromUs.OpenBorders)
     {
         TotalTrustRequiredFromUS = TotalTrustRequiredFromUS + ((float)dt.NAPact + 7.5f);
     }
     if (FromUs.NAPact)
     {
         TotalTrustRequiredFromUS = TotalTrustRequiredFromUS + (float)dt.NAPact;
         int numWars = 0;
         foreach (KeyValuePair<Empire, Ship_Game.Gameplay.Relationship> Relationship in us.GetRelations())
         {
             if (Relationship.Key.isFaction || !Relationship.Value.AtWar)
             {
                 continue;
             }
             numWars++;
         }
         if (numWars > 0 && !us.GetRelations()[them].AtWar)
         {
             TotalTrustRequiredFromUS = TotalTrustRequiredFromUS - (float)dt.NAPact;
         }
         else if (us.GetRelations()[them].Threat >= 20f)
         {
             TotalTrustRequiredFromUS = TotalTrustRequiredFromUS - (float)dt.NAPact;
         }
     }
     foreach (string tech in FromUs.TechnologiesOffered)
     {
         TotalTrustRequiredFromUS = TotalTrustRequiredFromUS + ResourceManager.TechTree[tech].Cost / 50f;
     }
     float ValueFromUs = 0f;
     float ValueToUs = 0f;
     if (FromUs.OpenBorders)
     {
         ValueFromUs = ValueFromUs + 5f;
     }
     if (ToUs.OpenBorders)
     {
         ValueToUs = ValueToUs + 0.01f;
     }
     if (FromUs.NAPact)
     {
         ValueFromUs = ValueFromUs + 5f;
     }
     if (ToUs.NAPact)
     {
         ValueToUs = ValueToUs + 5f;
     }
     if (FromUs.TradeTreaty)
     {
         ValueFromUs = ValueFromUs + 5f;
     }
     if (ToUs.TradeTreaty)
     {
         ValueToUs = ValueToUs + 5f;
         if ((double)this.empire.EstimateIncomeAtTaxRate(0.5f) < 1)
         {
             ValueToUs = ValueToUs + 20f;
         }
     }
     foreach (string tech in FromUs.TechnologiesOffered)
     {
         ValueFromUs = ValueFromUs + (us.data.EconomicPersonality.Name == "Technologists" ? ResourceManager.TechTree[tech].Cost / 50f * 0.25f + ResourceManager.TechTree[tech].Cost / 50f : ResourceManager.TechTree[tech].Cost / 50f);
     }
     foreach (string artifactsOffered in FromUs.ArtifactsOffered)
     {
         ValueFromUs = ValueFromUs + 15f;
     }
     foreach (string str in ToUs.ArtifactsOffered)
     {
         ValueToUs = ValueToUs + 15f;
     }
     foreach (string tech in ToUs.TechnologiesOffered)
     {
         ValueToUs = ValueToUs + (us.data.EconomicPersonality.Name == "Technologists" ? ResourceManager.TechTree[tech].Cost / 50f * 0.25f + ResourceManager.TechTree[tech].Cost / 50f : ResourceManager.TechTree[tech].Cost / 50f);
     }
     if (us.GetPlanets().Count - FromUs.ColoniesOffered.Count + ToUs.ColoniesOffered.Count < 1)
     {
         us.GetRelations()[them].DamageRelationship(us, them, "Insulted", 25f, null);
         return "OfferResponse_Reject_Insulting";
     }
     foreach (string planetName in FromUs.ColoniesOffered)
     {
         foreach (Planet p in us.GetPlanets())
         {
             if (p.Name != planetName)
             {
                 continue;
             }
             float value = p.Population / 1000f + p.FoodHere / 25f + p.ProductionHere / 25f + p.Fertility + p.MineralRichness + p.MaxPopulation / 1000f;
             foreach (Building b in p.BuildingList)
             {
                 value = value + b.Cost / 25f;
                 if (b.Name != "Capital City")
                 {
                     continue;
                 }
                 value = value + 100f;
             }
             float multiplier = 0f;
             foreach (Planet other in p.system.PlanetList)
             {
                 if (other.Owner != p.Owner)
                 {
                     continue;
                 }
                 multiplier = multiplier + 1.25f;
             }
             value = value * multiplier;
             if (value < 15f)
             {
                 value = 15f;
             }
             ValueFromUs = ValueFromUs + (us.data.EconomicPersonality.Name == "Expansionists" ? value + value : value + 0.5f * value);
         }
     }
     foreach (string planetName in ToUs.ColoniesOffered)
     {
         foreach (Planet p in them.GetPlanets())
         {
             if (p.Name != planetName)
             {
                 continue;
             }
             float value = p.Population / 1000f + p.FoodHere / 50f + p.ProductionHere / 50f + p.Fertility + p.MineralRichness + p.MaxPopulation / 2000f;
             foreach (Building b in p.BuildingList)
             {
                 value = value + b.Cost / 50f;
             }
             int multiplier = 1;
             foreach (Planet other in p.system.PlanetList)
             {
                 if (other.Owner != p.Owner)
                 {
                     continue;
                 }
                 multiplier++;
             }
             value = value * (float)multiplier;
             ValueToUs = ValueToUs + (us.data.EconomicPersonality.Name == "Expansionists" ? value * 0.5f + value : value);
         }
     }
     ValueToUs = ValueToUs + them.data.Traits.DiplomacyMod * ValueToUs;
     if (ValueFromUs == 0f && ValueToUs > 0f)
     {
         us.GetRelations()[them].ImproveRelations(ValueToUs, ValueToUs);
         this.AcceptOffer(ToUs, FromUs, us, them);
         return "OfferResponse_Accept_Gift";
     }
     ValueToUs = ValueToUs - ValueToUs * us.GetRelations()[them].TotalAnger / 100f;
     float offerdifferential = ValueToUs / (ValueFromUs + 0.01f);
     string OfferQuality = "";
     if (offerdifferential < 0.6f)
     {
         OfferQuality = "Insulting";
     }
     else if (offerdifferential < 0.9f && offerdifferential >= 0.6f)
     {
         OfferQuality = "Poor";
     }
     else if (offerdifferential >= 0.9f && offerdifferential < 1.1f)
     {
         OfferQuality = "Fair";
     }
     else if ((double)offerdifferential >= 1.1 && (double)offerdifferential < 1.45)
     {
         OfferQuality = "Good";
     }
     else if (offerdifferential >= 1.45f)
     {
         OfferQuality = "Great";
     }
     if (ValueToUs == ValueFromUs)
     {
         OfferQuality = "Fair";
     }
     switch (attitude)
     {
         case Offer.Attitude.Pleading:
         {
             if (TotalTrustRequiredFromUS > us.GetRelations()[them].Trust)
             {
                 if (OfferQuality != "Great")
                 {
                     return "OfferResponse_InsufficientTrust";
                 }
                 us.GetRelations()[them].ImproveRelations(ValueToUs - ValueFromUs, ValueToUs - ValueFromUs);
                 this.AcceptOffer(ToUs, FromUs, us, them);
                 return "OfferResponse_AcceptGreatOffer_LowTrust";
             }
             if (offerdifferential < 0.6f)
             {
                 OfferQuality = "Insulting";
             }
             else if (offerdifferential < 0.8f && offerdifferential > 0.65f)
             {
                 OfferQuality = "Poor";
             }
             else if (offerdifferential >= 0.8f && offerdifferential < 1.1f)
             {
                 OfferQuality = "Fair";
             }
             else if ((double)offerdifferential >= 1.1 && (double)offerdifferential < 1.45)
             {
                 OfferQuality = "Good";
             }
             else if (offerdifferential >= 1.45f)
             {
                 OfferQuality = "Great";
             }
             if (OfferQuality == "Poor")
             {
                 return "OfferResponse_Reject_PoorOffer_EnoughTrust";
             }
             if (OfferQuality == "Insulting")
             {
                 us.GetRelations()[them].DamageRelationship(us, them, "Insulted", ValueFromUs - ValueToUs, null);
                 return "OfferResponse_Reject_Insulting";
             }
             if (OfferQuality == "Fair")
             {
                 us.GetRelations()[them].ImproveRelations(ValueToUs - ValueFromUs, ValueToUs - ValueFromUs);
                 this.AcceptOffer(ToUs, FromUs, us, them);
                 return "OfferResponse_Accept_Fair_Pleading";
             }
             if (OfferQuality == "Good")
             {
                 us.GetRelations()[them].ImproveRelations(ValueToUs - ValueFromUs, ValueToUs - ValueFromUs);
                 this.AcceptOffer(ToUs, FromUs, us, them);
                 return "OfferResponse_Accept_Good";
             }
             if (OfferQuality != "Great")
             {
                 break;
             }
             us.GetRelations()[them].ImproveRelations(ValueToUs - ValueFromUs, ValueToUs - ValueFromUs);
             this.AcceptOffer(ToUs, FromUs, us, them);
             return "OfferResponse_Accept_Great";
         }
         case Offer.Attitude.Respectful:
         {
             if (TotalTrustRequiredFromUS + us.GetRelations()[them].TrustUsed <= us.GetRelations()[them].Trust)
             {
                 if (OfferQuality == "Poor")
                 {
                     return "OfferResponse_Reject_PoorOffer_EnoughTrust";
                 }
                 if (OfferQuality == "Insulting")
                 {
                     us.GetRelations()[them].DamageRelationship(us, them, "Insulted", ValueFromUs - ValueToUs, null);
                     return "OfferResponse_Reject_Insulting";
                 }
                 if (OfferQuality == "Fair")
                 {
                     us.GetRelations()[them].ImproveRelations(ValueToUs - ValueFromUs, ValueToUs - ValueFromUs);
                     this.AcceptOffer(ToUs, FromUs, us, them);
                     return "OfferResponse_Accept_Fair";
                 }
                 if (OfferQuality == "Good")
                 {
                     us.GetRelations()[them].ImproveRelations(ValueToUs - ValueFromUs, ValueToUs - ValueFromUs);
                     this.AcceptOffer(ToUs, FromUs, us, them);
                     return "OfferResponse_Accept_Good";
                 }
                 if (OfferQuality != "Great")
                 {
                     break;
                 }
                 us.GetRelations()[them].ImproveRelations(ValueToUs - ValueFromUs, ValueToUs - ValueFromUs);
                 this.AcceptOffer(ToUs, FromUs, us, them);
                 return "OfferResponse_Accept_Great";
             }
             else
             {
                 if (OfferQuality == "Great")
                 {
                     us.GetRelations()[them].ImproveRelations(ValueToUs - ValueFromUs, ValueToUs);
                     this.AcceptOffer(ToUs, FromUs, us, them);
                     return "OfferResponse_AcceptGreatOffer_LowTrust";
                 }
                 if (OfferQuality == "Poor")
                 {
                     return "OfferResponse_Reject_PoorOffer_LowTrust";
                 }
                 if (OfferQuality == "Fair" || OfferQuality == "Good")
                 {
                     return "OfferResponse_InsufficientTrust";
                 }
                 if (OfferQuality != "Insulting")
                 {
                     break;
                 }
                 us.GetRelations()[them].DamageRelationship(us, them, "Insulted", ValueFromUs - ValueToUs, null);
                 return "OfferResponse_Reject_Insulting";
             }
         }
         case Offer.Attitude.Threaten:
         {
             if (dt.Name == "Ruthless")
             {
                 return "OfferResponse_InsufficientFear";
             }
             us.GetRelations()[them].DamageRelationship(us, them, "Insulted", ValueFromUs - ValueToUs, null);
             if (OfferQuality == "Great")
             {
                 this.AcceptThreat(ToUs, FromUs, us, them);
                 return "OfferResponse_AcceptGreatOffer_LowTrust";
             }
             if (offerdifferential < 0.95f)
             {
                 OfferQuality = "Poor";
             }
             else if (offerdifferential >= 0.95f)
             {
                 OfferQuality = "Fair";
             }
             if (us.GetRelations()[them].Threat <= ValueFromUs || us.GetRelations()[them].FearUsed + ValueFromUs >= us.GetRelations()[them].Threat)
             {
                 return "OfferResponse_InsufficientFear";
             }
             if (OfferQuality == "Poor")
             {
                 this.AcceptThreat(ToUs, FromUs, us, them);
                 return "OfferResponse_Accept_Bad_Threatening";
             }
             if (OfferQuality != "Fair")
             {
                 break;
             }
             this.AcceptThreat(ToUs, FromUs, us, them);
             return "OfferResponse_Accept_Fair_Threatening";
         }
     }
     return "";
 }
 public void DoFirstContact(Empire e)
 {
     this.Relationships[e].SetInitialStrength(e.data.Traits.DiplomacyMod * 100f);
     this.Relationships[e].Known = true;
     if (!e.GetRelations()[this].Known)
         e.DoFirstContact(this);
     #if PERF
     if (Empire.universeScreen.player == this)
         return;
     #endif
     if (GlobalStats.perf && Empire.universeScreen.player == this)
         return;
     try
     {
         if (EmpireManager.GetEmpireByName(Empire.universeScreen.PlayerLoyalty) == this && !e.isFaction && !e.MinorRace)
         {
             Empire.universeScreen.ScreenManager.AddScreen((GameScreen)new DiplomacyScreen(e, EmpireManager.GetEmpireByName(Empire.universeScreen.PlayerLoyalty), "First Contact"));
         }
         else
         {
             if (EmpireManager.GetEmpireByName(Empire.universeScreen.PlayerLoyalty) != this || !e.isFaction)
                 return;
             foreach (Encounter e1 in ResourceManager.Encounters)
             {
                 if (e1.Faction == e.data.Traits.Name && e1.Name == "First Contact")
                     Empire.universeScreen.ScreenManager.AddScreen((GameScreen)new EncounterPopup(Empire.universeScreen, EmpireManager.GetEmpireByName(Empire.universeScreen.PlayerLoyalty), e, (SolarSystem)null, e1));
             }
         }
     }
     catch (ArgumentException)
     {   //this feels bad
     }
 }