public void AddAgentResultNotification(bool Good, string result, Empire Owner)
 {
     if (Owner != EmpireManager.GetEmpireByName(Ship.universeScreen.PlayerLoyalty))
     {
         return;
     }
     Notification cNote = new Notification()
     {
         Message = result,
         IconPath = (Good ? "NewUI/icon_spy_notification" : "NewUI/icon_spy_notification_bad"),
         ClickRect = new Rectangle(this.NotificationArea.X, this.NotificationArea.Y, 64, 64),
         DestinationRect = new Rectangle(this.NotificationArea.X, this.NotificationArea.Y + this.NotificationArea.Height - (this.NotificationList.Count + 1) * 70, 64, 64)
     };
     if (!Good)
     {
         AudioManager.PlayCue("sd_ui_spy_fail_02");
     }
     else
     {
         AudioManager.PlayCue("sd_ui_spy_win_02");
     }
     lock (GlobalStats.NotificationLocker)
     {
         this.NotificationList.Add(cNote);
     }
 }
 public Bomb(Vector3 Position, Empire e)
 {
     this.owner = e;
     this.projTexture = ResourceManager.ProjTextDict[this.TextureName];
     this.projModel = ResourceManager.ProjectileModelDict[this.ModelName];
     this.WeaponName = "NuclearBomb";
     this.Position = Position;
 }
 public Goal(string ShipType, string forWhat, Empire e)
 {
     this.ToBuildUID = ShipType;
     this.empire = e;
     this.beingBuilt = ResourceManager.ShipsDict[ShipType];
     this.GoalName = forWhat;
     this.Evaluate();
 }
 public Goal(Planet toColonize, Empire e)
 {
     this.empire = e;
     this.GoalName = "MarkForColonization";
     this.type = GoalType.Colonize;
     this.markedPlanet = toColonize;
     this.colonyShip = (Ship)null;
 }
 public Goal(Vector2 BuildPosition, string platformUID, Empire Owner)
 {
     this.GoalName = "BuildConstructionShip";
     this.type = GoalType.DeepSpaceConstruction;
     this.BuildPosition = BuildPosition;
     this.ToBuildUID = platformUID;
     this.empire = Owner;
     this.DoBuildConstructionShip();
 }
 public Goal(Troop toCopy, Empire Owner, Planet p)
 {
     this.GoalName = "Build Troop";
     this.type = GoalType.DeepSpaceConstruction;
     this.PlanetBuildingAt = p;
     this.ToBuildUID = toCopy.Name;
     this.empire = Owner;
     this.type = GoalType.BuildTroop;
 }
 //private float transitionElapsedTime;
 public EventScreen(UniverseScreen screen, Empire playerEmpire, ExplorationEvent e, Outcome outcome)
 {
     this.outcome = outcome;
     this.ExpEvent = e;
     this.screen = screen;
     base.IsPopup = true;
     base.TransitionOnTime = TimeSpan.FromSeconds(0.25);
     base.TransitionOffTime = TimeSpan.FromSeconds(0.25);
 }
 public GSAI(Empire e)
 {
     this.EmpireName = e.data.Traits.Name;
     this.empire = e;
     this.DefensiveCoordinator = new Ship_Game.DefensiveCoordinator(e);
     if (this.empire.data.EconomicPersonality != null)
     {
         this.numberOfShipGoals = this.numberOfShipGoals + this.empire.data.EconomicPersonality.ShipGoalsPlus;
     }
        // this.desired_ColonyGoals = (int)this.empire.data.difficulty;
 }
 public EventPopup(UniverseScreen s, Empire playerEmpire, ExplorationEvent e, Outcome outcome)
 {
     this.screen = s;
     this.outcome = outcome;
     this.ExpEvent = e;
     this.fade = true;
     base.IsPopup = true;
     this.FromGame = true;
     base.TransitionOnTime = TimeSpan.FromSeconds(0.25);
     base.TransitionOffTime = TimeSpan.FromSeconds(0);
     this.r = new Rectangle(0, 0, 600, 600);
 }
 //private float transitionElapsedTime;
 public EncounterScreen(UniverseScreen screen, Empire playerEmpire, Empire targetEmp, SolarSystem tarSys, Encounter e)
 {
     this.encounter = e;
     this.encounter.CurrentMessage = 0;
     this.encounter.SetPlayerEmpire(playerEmpire);
     this.encounter.SetSys(tarSys);
     this.encounter.SetTarEmp(targetEmp);
     this.screen = screen;
     base.IsPopup = true;
     base.TransitionOnTime = TimeSpan.FromSeconds(0.25);
     base.TransitionOffTime = TimeSpan.FromSeconds(0.25);
 }
 public EncounterPopup(UniverseScreen s, Empire playerEmpire, Empire targetEmp, SolarSystem tarSys, Encounter e)
 {
     this.screen = s;
     this.encounter = e;
     this.encounter.CurrentMessage = 0;
     this.encounter.SetPlayerEmpire(playerEmpire);
     this.encounter.SetSys(tarSys);
     this.encounter.SetTarEmp(targetEmp);
     this.fade = true;
     base.IsPopup = true;
     this.FromGame = true;
     base.TransitionOnTime = TimeSpan.FromSeconds(0.25);
     base.TransitionOffTime = TimeSpan.FromSeconds(0);
     this.r = new Rectangle(0, 0, 600, 600);
 }
 public static Mole PlantMole(Empire Owner, Empire Target)
 {
     List<Planet> Potentials = new List<Planet>();
     foreach (Planet p in Target.GetPlanets())
     {
         if (!p.ExploredDict[Owner])
         {
             continue;
         }
         bool GoodPlanet = true;
         foreach (Mole m in Target.data.MoleList)
         {
             if (m.PlanetGuid != p.guid)
             {
                 continue;
             }
             GoodPlanet = false;
             break;
         }
         if (!GoodPlanet)
         {
             break;
         }
         Potentials.Add(p);
     }
     if (Potentials.Count == 0)
     {
         Potentials = Target.GetPlanets();
     }
     Mole mole = null;
     if (Potentials.Count > 0)
     {
         int Random = (int)RandomMath.RandomBetween(0f, (float)Potentials.Count + 0.7f);
         if (Random > Potentials.Count - 1)
         {
             Random = Potentials.Count - 1;
         }
         mole = new Mole()
         {
             PlanetGuid = Potentials[Random].guid
         };
         Owner.data.MoleList.Add(mole);
     }
     return mole;
 }
 public void AddBeingInvadedNotification(SolarSystem beingInvaded, Empire Invader)
 {
     Notification cNote = new Notification()
     {
         RelevantEmpire = Invader
     };
     string[] singular = new string[] { Invader.data.Traits.Singular, Localizer.Token(1500), "\n", Localizer.Token(1501), beingInvaded.Name, Localizer.Token(1502) };
     cNote.Message = string.Concat(singular);
     cNote.ReferencedItem1 = beingInvaded;
     cNote.IconPath = "NewUI/icon_planet_terran_01_mid";
     cNote.Action = "SnapToSystem";
     cNote.ClickRect = new Rectangle(this.NotificationArea.X, this.NotificationArea.Y, 64, 64);
     cNote.DestinationRect = new Rectangle(this.NotificationArea.X, this.NotificationArea.Y + this.NotificationArea.Height - (this.NotificationList.Count + 1) * 70, 64, 64);
     AudioManager.PlayCue("sd_notify_alert");
     lock (GlobalStats.NotificationLocker)
     {
         this.NotificationList.Add(cNote);
     }
 }
 public void AssignMission(AgentMission mission, Empire Owner, string empname)
 {
     this.Initialize(mission, Owner);
     if (this.Mission == AgentMission.Undercover)
     {
         foreach (Mole m in Owner.data.MoleList)
         {
             if (m.PlanetGuid != this.TargetGUID)
             {
                 continue;
             }
             Owner.data.MoleList.QueuePendingRemoval(m);
             break;
         }
     }
     Owner.data.MoleList.ApplyPendingRemovals();
     this.Mission = mission;
     this.TargetEmpire = empname;
 }
 public void Draw(Ship_Game.ScreenManager ScreenManager, Empire e)
 {
     Primitives2D.FillRectangle(ScreenManager.SpriteBatch, this.NodeRect, new Color(54, 54, 54));
     Rectangle underRect = new Rectangle(this.NodeRect.X, this.NodeRect.Y + 28, this.NodeRect.Width, 22);
     Primitives2D.FillRectangle(ScreenManager.SpriteBatch, underRect, new Color(37, 37, 37));
     if (!this.isResearched)
     {
         Primitives2D.DrawRectangle(ScreenManager.SpriteBatch, this.NodeRect, Color.Black);
     }
     else
     {
         Primitives2D.DrawRectangle(ScreenManager.SpriteBatch, this.NodeRect, new Color(243, 134, 53));
     }
     if (e.ResearchTopic == this.tech.UID)
     {
         Primitives2D.DrawRectangle(ScreenManager.SpriteBatch, this.NodeRect, new Color(24, 81, 91), 3f);
     }
     else if (e.data.ResearchQueue.Contains(this.tech.UID))
     {
         Primitives2D.DrawRectangle(ScreenManager.SpriteBatch, this.NodeRect, Color.White, 3f);
     }
     Vector2 cursor = new Vector2((float)(this.NodeRect.X + 10), (float)(this.NodeRect.Y + 4));
     HelperFunctions.DrawDropShadowText(ScreenManager, Localizer.Token(ResourceManager.TechTree[this.tech.UID].NameIndex), cursor, Fonts.Arial12Bold);
     Rectangle BlackBar = new Rectangle(this.NodeRect.X + 215, this.NodeRect.Y + 1, 1, this.NodeRect.Height - 2);
     Primitives2D.FillRectangle(ScreenManager.SpriteBatch, BlackBar, Color.Black);
     Rectangle rIconRect = new Rectangle(BlackBar.X + 4, BlackBar.Y + 4, 19, 20);
     ScreenManager.SpriteBatch.Draw(ResourceManager.TextureDict["NewUI/icon_science"], rIconRect, Color.White);
     cursor.X = (float)(rIconRect.X + 24);
     SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
     SpriteFont arial12Bold = Fonts.Arial12Bold;
     int cost = (int)ResourceManager.TechTree[this.tech.UID].Cost;
     spriteBatch.DrawString(arial12Bold, cost.ToString(), cursor, Color.White);
     float progress = this.tech.Progress / ResourceManager.TechTree[this.tech.UID].Cost;
     this.pb.Draw(ScreenManager, progress);
     cursor.X = (float)(this.pb.rect.X + this.pb.rect.Width + 33);
     cursor.Y = (float)(this.pb.rect.Y - 2);
     int num = (int)(progress * 100f);
     string s = string.Concat(num.ToString(), "%");
     cursor.X = cursor.X - Fonts.Arial12Bold.MeasureString(s).X;
     ScreenManager.SpriteBatch.DrawString(Fonts.Arial12Bold, s, cursor, new Color(24, 81, 91));
 }
 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 SpaceRoad(SolarSystem Origin, SolarSystem Destination, Empire empire, float SSPBudget, float nodeMaintenance)
        {
            this.Origin = Origin;
            this.Destination = Destination;
            float Distance = Vector2.Distance(Origin.Position, Destination.Position);

            //int galaxySizeMod = (int)((Empire.universeScreen.Size.X ) / 250);
            float offset = (Empire.ProjectorRadius * 1.5f);// +galaxySizeMod;
            this.NumberOfProjectors = (int)(Math.Ceiling(Distance / offset));
            if (SSPBudget - nodeMaintenance * this.NumberOfProjectors <= 0)
            {
                this.NumberOfProjectors = 0;
                return ;
            }
            for (int i = 0; i < this.NumberOfProjectors; i++)
            {
                RoadNode node = new RoadNode();
                float angle = HelperFunctions.findAngleToTarget(Origin.Position, Destination.Position);
                node.Position = HelperFunctions.GeneratePointOnCircle(angle, Origin.Position,  (float)i * (Distance / this.NumberOfProjectors));
                bool reallyAdd = true;
                empire.BorderNodeLocker.EnterReadLock();
                {
                    foreach (Empire.InfluenceNode bordernode in empire.BorderNodes)
                    {
                        if (Vector2.Distance(node.Position, bordernode.Position) >= bordernode.Radius)
                        {
                            continue;
                        }
                        reallyAdd = false;
                    }
                }
                empire.BorderNodeLocker.ExitReadLock();
                if (reallyAdd)
                {
                    this.RoadNodesList.Add(node);
                }
            }
            return ;
        }
        /**
            Constructor for MilitaryTask class.
            @param location - vector specifying game board space
            @param radius - area of operation radius (bounds of military task)
            @param GoalsToHold - contains Goals
            @param Owner - the faction to whom the MilitaryTask targets, i.e. the opposition faction

        */
        public MilitaryTask(Vector2 location, float radius, List<Goal> GoalsToHold, Empire Owner)
        {
            this.type = MilitaryTask.TaskType.ClearAreaOfEnemies; //enumerated value
            this.AO = location;
            this.AORadius = radius;
            //pools GoalsToHold into this MilitaryTask
            //by "held," the goal is acknowledge as having been accepted for MilitaryTask to fulfill: this.HeldGoals
            foreach (Goal g in GoalsToHold)
            {
                g.Held = true;
                this.HeldGoals.Add(g.guid);
            }
            //KeyValuePair is an enumarted variable type from System.Collections.Generic
            //A pin is an embedded sublass of ThreatMatrix; containing details on the threat: location, faction, etc.
            //This "foreach" loop selects all threats in this Empire's recognized threats
            foreach (KeyValuePair<Guid, ThreatMatrix.Pin> pin in Owner.GetGSAI().ThreatMatrix.Pins)
            {
                //if threat is outside the area of operation (AO), ignore it
                //"contine" increments the loop to the next threat (pin)
                if (Vector2.Distance(this.AO, pin.Value.Position) >= this.AORadius || EmpireManager.GetEmpireByName(pin.Value.EmpireName) == Owner)
                {
                    continue;
                }
                //declare new MilitaryTask, assign it equal to this current instance of MiliTaryTask
                //what is the purpose of assigning initial enemy strength, and enemy strenght?
                MilitaryTask initialEnemyStrength = this;
                initialEnemyStrength.InitialEnemyStrength = initialEnemyStrength.InitialEnemyStrength + pin.Value.Strength;
                MilitaryTask enemyStrength = this;
                enemyStrength.EnemyStrength = enemyStrength.EnemyStrength + pin.Value.Strength;
            }
            //what is MinimumTaskForceStrength used for?
            //minimum task force must be at least 75% of enemy strength
            //convential military doctrine requires 3:1 Attackers:Defenders advantage for minimal success potential
            this.MinimumTaskForceStrength = this.EnemyStrength * 3f;//*.75f; //why by 75%?
                                                                    //Ermenildo V. Castro, Jr.
                                                                    //07/25/15
                                                                    //Altered to "* 3f", instead of original  "* .75f"
            this.empire = Owner; //Empire specifies the opposition faction
        }
 public void SetTarEmp(Empire e)
 {
     this.empToDiscuss = e;
 }
 public static void CreateFleetFromDataAt(FleetDesign data, Empire Owner, Vector2 Position, float facing)
 {
     Fleet fleet = new Fleet()
     {
         Position = Position,
         facing = facing,
         Owner = Owner,
         DataNodes = new BatchRemovalCollection<FleetDataNode>()
     };
     foreach (FleetDataNode node in data.Data)
     {
         fleet.DataNodes.Add(node);
     }
     fleet.AssignDataPositions(facing);
     fleet.Name = data.Name;
     fleet.FleetIconIndex = data.FleetIconIndex;
     fleet.DataNodes.thisLock.EnterWriteLock();
     foreach (FleetDataNode node in fleet.DataNodes)
     {
         Ship s = ResourceManager.CreateShipAtPoint(node.ShipName, Owner, Position + node.OrdersOffset, facing);
         s.RelativeFleetOffset = node.FleetOffset;
         node.SetShip(s);
         fleet.AddShip(s);
     }
     fleet.DataNodes.thisLock.ExitWriteLock();
     foreach (Ship s in Owner.GetFleetsDict()[1].Ships)
     {
         s.fleet = null;
     }
     Owner.GetFleetsDict()[1] = fleet;
 }
 public void SetPlayerEmpire(Empire e)
 {
     this.playerEmpire = e;
 }
        private float GetMaintCostShipyardProportional(ShipData ship, float fCost, Empire empire)
        {
            float maint = 0f;
            float maintModReduction = 1;
            string role = ship.Role;

            // Calculate maintenance by proportion of ship cost, Duh.
            if (ship.Role == "fighter" || ship.Role == "scout")
                maint = fCost * GlobalStats.ActiveModInfo.UpkeepFighter;
            else if (ship.Role == "corvette")
                maint = fCost * GlobalStats.ActiveModInfo.UpkeepCorvette;
            else if (ship.Role == "frigate" || ship.Role == "destroyer")
                maint = fCost * GlobalStats.ActiveModInfo.UpkeepFrigate;
            else if (ship.Role == "cruiser")
                maint = fCost * GlobalStats.ActiveModInfo.UpkeepCruiser;
            else if (ship.Role == "carrier")
                maint = fCost * GlobalStats.ActiveModInfo.UpkeepCarrier;
            else if (ship.Role == "capital")
                maint = fCost * GlobalStats.ActiveModInfo.UpkeepCapital;
            else if (ship.Role == "freighter")
                maint = fCost * GlobalStats.ActiveModInfo.UpkeepFreighter;
            else if (ship.Role == "platform")
                maint = fCost * GlobalStats.ActiveModInfo.UpkeepPlatform;
            else if (ship.Role == "station")
                maint = fCost * GlobalStats.ActiveModInfo.UpkeepStation;
            else if (ship.Role == "drone" && GlobalStats.ActiveModInfo.useDrones)
                maint = fCost * GlobalStats.ActiveModInfo.UpkeepDrone;
            else
                maint = fCost * GlobalStats.ActiveModInfo.UpkeepBaseline;
            if (maint == 0f && GlobalStats.ActiveModInfo.UpkeepBaseline > 0)
                maint = fCost * GlobalStats.ActiveModInfo.UpkeepBaseline;
            else if (maint == 0f && GlobalStats.ActiveModInfo.UpkeepBaseline == 0)
                maint = fCost * 0.004f;

            // Modifiers below here

            if ((ship.Role == "freighter" || ship.Role == "platform") && empire != null && !empire.isFaction && empire.data.CivMaintMod != 1.0)
            {
                maint *= empire.data.CivMaintMod;
            }

            if ((ship.Role == "freighter" || ship.Role == "platform") && empire != null && !empire.isFaction && empire.data.Privatization)
            {
                maint *= 0.5f;
            }

            if (GlobalStats.OptionIncreaseShipMaintenance > 1)
            {
                maintModReduction = GlobalStats.OptionIncreaseShipMaintenance;
                maint *= (float)maintModReduction;
            }
            return maint;
        }
        public static void CreateFleetAt(string FleetUID, Empire Owner, Vector2 Position)
        {
            FileInfo theFleetFI;

            if (GlobalStats.ActiveMod != null && Directory.Exists(string.Concat(Ship_Game.ResourceManager.WhichModPath, "/FleetDesigns")) && File.Exists(string.Concat(Ship_Game.ResourceManager.WhichModPath, "/FleetDesigns/", FleetUID, ".xml")))
            {
                theFleetFI = new FileInfo(string.Concat(Ship_Game.ResourceManager.WhichModPath, "/FleetDesigns/", FleetUID, ".xml"));
            }
            else if (File.Exists(string.Concat("Content/FleetDesigns/", FleetUID, ".xml")))
            {
                theFleetFI = new FileInfo(string.Concat("Content/FleetDesigns/", FleetUID, ".xml"));
            }
            else
            {
                string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                theFleetFI = new FileInfo(string.Concat(path, "/StarDrive/Fleet Designs/", FleetUID, ".xml"));
            }
            XmlSerializer serializer1 = new XmlSerializer(typeof(FleetDesign));
            FleetDesign data = (FleetDesign)serializer1.Deserialize(theFleetFI.OpenRead());
            Fleet fleet = new Fleet()
            {
                Position = Position,
                Owner = Owner,
                DataNodes = new BatchRemovalCollection<FleetDataNode>()
            };
            foreach (FleetDataNode node in data.Data)
            {
                fleet.DataNodes.Add(node);
            }
            fleet.Name = data.Name;
            fleet.FleetIconIndex = data.FleetIconIndex;
            fleet.DataNodes.thisLock.EnterWriteLock();
            foreach (FleetDataNode node in fleet.DataNodes)
            {
                Ship s = ResourceManager.CreateShipAtPoint(node.ShipName, Owner, Position + node.FleetOffset);
                s.RelativeFleetOffset = node.FleetOffset;
                node.SetShip(s);
                fleet.AddShip(s);
            }
            fleet.DataNodes.thisLock.ExitWriteLock();
            foreach (Ship s in Owner.GetFleetsDict()[1].Ships)
            {
                s.fleet = null;
            }
            Owner.GetFleetsDict()[1] = fleet;
        }
 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 "";
 }
        private float GetMaintCostShipyard(ShipData ship, float Size, Empire empire)
        {
            float maint = 0f;
            string role = ship.Role;
            string str = role;
            //bool nonCombat = false;
            //added by gremlin: Maintenance changes
            float maintModReduction = 1;

            //Get Maintanence of ship role
            bool foundMaint = false;
            if (ResourceManager.ShipRoles.ContainsKey(ship.Role))
            {
                for (int i = 0; i < ResourceManager.ShipRoles[ship.Role].RaceList.Count; i++)
                {
                    if (ResourceManager.ShipRoles[ship.Role].RaceList[i].ShipType == empire.data.Traits.ShipType)
                    {
                        maint = ResourceManager.ShipRoles[ship.Role].RaceList[i].Upkeep;
                        foundMaint = true;
                        break;
                    }
                }
                if (!foundMaint)
                    maint = ResourceManager.ShipRoles[ship.Role].Upkeep;
            }
            else
                return 0f;

            //Modify Maintanence by freighter size
            if (ship.Role == "freighter")
            {
                switch ((int)Size / 50)
                {
                    case 0:
                        {
                            break;
                        }

                    case 1:
                        {
                            maint *= 1.5f;
                            break;
                        }

                    case 2:
                    case 3:
                    case 4:
                        {
                            maint *= 2f;
                            break;
                        }
                    default:
                        {
                            maint *= (int)Size / 50;
                            break;
                        }
                }
            }

            if ((ship.Role == "freighter" || ship.Role == "platform") && empire.data.CivMaintMod != 1.0)
            {
                maint *= empire.data.CivMaintMod;
            }

            //Apply Privatization
            if ((ship.Role == "freighter" || ship.Role == "platform") && empire.data.Privatization)
            {
                maint *= 0.5f;
            }

            //Subspace Projectors do not get any more modifiers
            if (ship.Name == "Subspace Projector")
            {
                return maint;
            }

            //Maintenance fluctuator
            //string configvalue1 = ConfigurationManager.AppSettings["countoffiles"];
            float OptionIncreaseShipMaintenance = GlobalStats.OptionIncreaseShipMaintenance;
            if (OptionIncreaseShipMaintenance > 1)
            {
                maintModReduction = OptionIncreaseShipMaintenance;
                maint *= maintModReduction;
            }
            return maint;
        }
 public void GetWarDeclaredOnUs(Empire WarDeclarant, WarType wt)
 {
     this.empire.GetRelations()[WarDeclarant].AtWar = true;
     this.empire.GetRelations()[WarDeclarant].FedQuest = null;
     this.empire.GetRelations()[WarDeclarant].Posture = Posture.Hostile;
     this.empire.GetRelations()[WarDeclarant].ActiveWar = new War(this.empire, WarDeclarant, this.empire.GetUS().StarDate)
     {
         WarType = wt
     };
     if (EmpireManager.GetEmpireByName(this.empire.GetUS().PlayerLoyalty) != this.empire)
     {
         string name = this.empire.data.DiplomaticPersonality.Name;
         if (name != null && name == "Pacifist")
         {
             if (this.empire.GetRelations()[WarDeclarant].ActiveWar.StartingNumContestedSystems <= 0)
             {
                 this.empire.GetRelations()[WarDeclarant].ActiveWar.WarType = WarType.DefensiveWar;
             }
             else
             {
                 this.empire.GetRelations()[WarDeclarant].ActiveWar.WarType = WarType.BorderConflict;
             }
         }
     }
     if (this.empire.GetRelations()[WarDeclarant].Trust > 0f)
     {
         this.empire.GetRelations()[WarDeclarant].Trust = 0f;
     }
     this.empire.GetRelations()[WarDeclarant].Treaty_Alliance = false;
     this.empire.GetRelations()[WarDeclarant].Treaty_NAPact = false;
     this.empire.GetRelations()[WarDeclarant].Treaty_OpenBorders = false;
     this.empire.GetRelations()[WarDeclarant].Treaty_Trade = false;
     this.empire.GetRelations()[WarDeclarant].Treaty_Peace = false;
 }
 private float GetDistance(Empire e)
 {
     if (e.GetPlanets().Count == 0 || this.empire.GetPlanets().Count == 0)
     {
         return 0f;
     }
     Vector2 AvgPos = new Vector2();
     foreach (Planet p in e.GetPlanets())
     {
         AvgPos = AvgPos + p.Position;
     }
     AvgPos = AvgPos / (float)e.GetPlanets().Count;
     Vector2 Ouravg = new Vector2();
     foreach (Planet p in this.empire.GetPlanets())
     {
         Ouravg = Ouravg + p.Position;
     }
     Ouravg = Ouravg / (float)this.empire.GetPlanets().Count;
     return Vector2.Distance(AvgPos, Ouravg);
 }
 private Vector2 FindAveragePosition(Empire e)
 {
     Vector2 AvgPos = new Vector2();
     foreach (Planet p in e.GetPlanets())
     {
         AvgPos = AvgPos + p.Position;
     }
     if (e.GetPlanets().Count <= 0)
     {
         return Vector2.Zero;
     }
     Vector2 count = AvgPos / (float)e.GetPlanets().Count;
     AvgPos = count;
     return count;
 }
        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 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;
 }