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 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 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 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;
                }
            }
        }