public void DeclareWarOnViaCall(Empire them, WarType wt) { this.empire.GetRelations()[them].PreparingForWar = false; if (this.empire.isFaction || this.empire.data.Defeated || them.data.Defeated || them.isFaction) { return; } this.empire.GetRelations()[them].FedQuest = null; if (this.empire == EmpireManager.GetEmpireByName(this.empire.GetUS().PlayerLoyalty) && this.empire.GetRelations()[them].Treaty_NAPact) { this.empire.GetRelations()[them].Treaty_NAPact = false; Relationship item = them.GetRelations()[this.empire]; item.Trust = item.Trust - 50f; Relationship angerDiplomaticConflict = them.GetRelations()[this.empire]; angerDiplomaticConflict.Anger_DiplomaticConflict = angerDiplomaticConflict.Anger_DiplomaticConflict + 50f; them.GetRelations()[this.empire].UpdateRelationship(them, this.empire); } if (them == EmpireManager.GetEmpireByName(this.empire.GetUS().PlayerLoyalty) && !this.empire.GetRelations()[them].AtWar) { switch (wt) { case WarType.BorderConflict: { if (this.empire.GetRelations()[them].contestedSystemGuid == Guid.Empty) { this.empire.GetUS().ScreenManager.AddScreen(new DiplomacyScreen(this.empire, them, "Declare War BC")); break; } else { this.empire.GetUS().ScreenManager.AddScreen(new DiplomacyScreen(this.empire, them, "Declare War BC Tarsys", this.empire.GetRelations()[them].GetContestedSystem())); break; } } case WarType.ImperialistWar: { if (!this.empire.GetRelations()[them].Treaty_NAPact) { this.empire.GetUS().ScreenManager.AddScreen(new DiplomacyScreen(this.empire, them, "Declare War Imperialism")); break; } else { this.empire.GetUS().ScreenManager.AddScreen(new DiplomacyScreen(this.empire, them, "Declare War Imperialism Break NA")); break; } } case WarType.DefensiveWar: { if (this.empire.GetRelations()[them].Treaty_NAPact) { if (!this.empire.GetRelations()[them].Treaty_NAPact) { break; } this.empire.GetUS().ScreenManager.AddScreen(new DiplomacyScreen(this.empire, them, "Declare War Defense BrokenNA")); this.empire.GetRelations()[them].Treaty_NAPact = false; Relationship trust = this.empire.GetRelations()[them]; trust.Trust = trust.Trust - 50f; Relationship relationship = this.empire.GetRelations()[them]; relationship.Anger_DiplomaticConflict = relationship.Anger_DiplomaticConflict + 50f; break; } else { this.empire.GetUS().ScreenManager.AddScreen(new DiplomacyScreen(this.empire, them, "Declare War Defense")); Relationship item1 = this.empire.GetRelations()[them]; item1.Anger_DiplomaticConflict = item1.Anger_DiplomaticConflict + 25f; Relationship trust1 = this.empire.GetRelations()[them]; trust1.Trust = trust1.Trust - 25f; break; } } } } if (them == EmpireManager.GetEmpireByName(this.empire.GetUS().PlayerLoyalty) || this.empire == EmpireManager.GetEmpireByName(this.empire.GetUS().PlayerLoyalty)) { Ship.universeScreen.NotificationManager.AddWarDeclaredNotification(this.empire, them); } else if (EmpireManager.GetEmpireByName(this.empire.GetUS().PlayerLoyalty).GetRelations()[them].Known && EmpireManager.GetEmpireByName(this.empire.GetUS().PlayerLoyalty).GetRelations()[this.empire].Known) { Ship.universeScreen.NotificationManager.AddWarDeclaredNotification(this.empire, them); } this.empire.GetRelations()[them].AtWar = true; this.empire.GetRelations()[them].Posture = Posture.Hostile; this.empire.GetRelations()[them].ActiveWar = new War(this.empire, them, this.empire.GetUS().StarDate) { WarType = wt }; if (this.empire.GetRelations()[them].Trust > 0f) { this.empire.GetRelations()[them].Trust = 0f; } this.empire.GetRelations()[them].Treaty_OpenBorders = false; this.empire.GetRelations()[them].Treaty_NAPact = false; this.empire.GetRelations()[them].Treaty_Trade = false; this.empire.GetRelations()[them].Treaty_Alliance = false; this.empire.GetRelations()[them].Treaty_Peace = false; them.GetGSAI().GetWarDeclaredOnUs(this.empire, wt); }
public 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 DeclareWarFromEvent(Empire them, WarType wt) { this.empire.GetRelations()[them].AtWar = true; this.empire.GetRelations()[them].Posture = Posture.Hostile; this.empire.GetRelations()[them].ActiveWar = new War(this.empire, them, this.empire.GetUS().StarDate) { WarType = wt }; if (this.empire.GetRelations()[them].Trust > 0f) { this.empire.GetRelations()[them].Trust = 0f; } this.empire.GetRelations()[them].Treaty_OpenBorders = false; this.empire.GetRelations()[them].Treaty_NAPact = false; this.empire.GetRelations()[them].Treaty_Trade = false; this.empire.GetRelations()[them].Treaty_Alliance = false; this.empire.GetRelations()[them].Treaty_Peace = false; them.GetGSAI().GetWarDeclaredOnUs(this.empire, wt); }
public void DeclareWarOn(Empire them, WarType wt) { this.empire.GetRelations()[them].PreparingForWar = false; if (this.empire.isFaction || this.empire.data.Defeated || (them.data.Defeated || them.isFaction)) return; this.empire.GetRelations()[them].FedQuest = (FederationQuest)null; if (this.empire == EmpireManager.GetEmpireByName(this.empire.GetUS().PlayerLoyalty) && this.empire.GetRelations()[them].Treaty_NAPact) { this.empire.GetRelations()[them].Treaty_NAPact = false; foreach (KeyValuePair<Empire, Relationship> keyValuePair in this.empire.GetRelations()) { if (keyValuePair.Key != them) { keyValuePair.Key.GetRelations()[this.empire].Trust -= 50f; keyValuePair.Key.GetRelations()[this.empire].Anger_DiplomaticConflict += 20f; keyValuePair.Key.GetRelations()[this.empire].UpdateRelationship(keyValuePair.Key, this.empire); } } them.GetRelations()[this.empire].Trust -= 50f; them.GetRelations()[this.empire].Anger_DiplomaticConflict += 50f; them.GetRelations()[this.empire].UpdateRelationship(them, this.empire); } if (them == EmpireManager.GetEmpireByName(this.empire.GetUS().PlayerLoyalty) && !this.empire.GetRelations()[them].AtWar) { switch (wt) { case WarType.BorderConflict: if (this.empire.GetRelations()[them].contestedSystemGuid != Guid.Empty) { this.empire.GetUS().ScreenManager.AddScreen((GameScreen)new DiplomacyScreen(this.empire, them, "Declare War BC TarSys", this.empire.GetRelations()[them].GetContestedSystem())); break; } else { this.empire.GetUS().ScreenManager.AddScreen((GameScreen)new DiplomacyScreen(this.empire, them, "Declare War BC")); break; } case WarType.ImperialistWar: if (this.empire.GetRelations()[them].Treaty_NAPact) { this.empire.GetUS().ScreenManager.AddScreen((GameScreen)new DiplomacyScreen(this.empire, them, "Declare War Imperialism Break NA")); using (Dictionary<Empire, Relationship>.Enumerator enumerator = this.empire.GetRelations().GetEnumerator()) { while (enumerator.MoveNext()) { KeyValuePair<Empire, Relationship> current = enumerator.Current; if (current.Key != them) { current.Value.Trust -= 50f; current.Value.Anger_DiplomaticConflict += 20f; } } break; } } else { this.empire.GetUS().ScreenManager.AddScreen((GameScreen)new DiplomacyScreen(this.empire, them, "Declare War Imperialism")); break; } case WarType.DefensiveWar: if (!this.empire.GetRelations()[them].Treaty_NAPact) { this.empire.GetUS().ScreenManager.AddScreen((GameScreen)new DiplomacyScreen(this.empire, them, "Declare War Defense")); this.empire.GetRelations()[them].Anger_DiplomaticConflict += 25f; this.empire.GetRelations()[them].Trust -= 25f; break; } else if (this.empire.GetRelations()[them].Treaty_NAPact) { this.empire.GetUS().ScreenManager.AddScreen((GameScreen)new DiplomacyScreen(this.empire, them, "Declare War Defense BrokenNA")); this.empire.GetRelations()[them].Treaty_NAPact = false; foreach (KeyValuePair<Empire, Relationship> keyValuePair in this.empire.GetRelations()) { if (keyValuePair.Key != them) { keyValuePair.Value.Trust -= 50f; keyValuePair.Value.Anger_DiplomaticConflict += 20f; } } this.empire.GetRelations()[them].Trust -= 50f; this.empire.GetRelations()[them].Anger_DiplomaticConflict += 50f; break; } else break; } } if (them == EmpireManager.GetEmpireByName(this.empire.GetUS().PlayerLoyalty) || this.empire == EmpireManager.GetEmpireByName(this.empire.GetUS().PlayerLoyalty)) Ship.universeScreen.NotificationManager.AddWarDeclaredNotification(this.empire, them); else if (EmpireManager.GetEmpireByName(this.empire.GetUS().PlayerLoyalty).GetRelations()[them].Known && EmpireManager.GetEmpireByName(this.empire.GetUS().PlayerLoyalty).GetRelations()[this.empire].Known) Ship.universeScreen.NotificationManager.AddWarDeclaredNotification(this.empire, them); this.empire.GetRelations()[them].AtWar = true; this.empire.GetRelations()[them].Posture = Posture.Hostile; this.empire.GetRelations()[them].ActiveWar = new War(this.empire, them, this.empire.GetUS().StarDate); this.empire.GetRelations()[them].ActiveWar.WarType = wt; if ((double)this.empire.GetRelations()[them].Trust > 0.0) this.empire.GetRelations()[them].Trust = 0.0f; this.empire.GetRelations()[them].Treaty_OpenBorders = false; this.empire.GetRelations()[them].Treaty_NAPact = false; this.empire.GetRelations()[them].Treaty_Trade = false; this.empire.GetRelations()[them].Treaty_Alliance = false; this.empire.GetRelations()[them].Treaty_Peace = false; them.GetGSAI().GetWarDeclaredOnUs(this.empire, wt); }
public 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 CallAllyToWar(Empire Ally, Empire Enemy) { Offer offer = new Offer() { AcceptDL = "HelpUS_War_Yes", RejectDL = "HelpUS_War_No" }; string dialogue = "HelpUS_War"; Offer OurOffer = new Offer() { ValueToModify = new Ref<bool>(() => Ally.GetRelations()[Enemy].AtWar, (bool x) => { if (x) { Ally.GetGSAI().DeclareWarOnViaCall(Enemy, WarType.ImperialistWar); return; } float Amount = 30f; if (this.empire.data.DiplomaticPersonality != null && this.empire.data.DiplomaticPersonality.Name == "Honorable") { Amount = 60f; offer.RejectDL = "HelpUS_War_No_BreakAlliance"; this.empire.GetRelations()[Ally].Treaty_Alliance = false; Ally.GetRelations()[this.empire].Treaty_Alliance = false; this.empire.GetRelations()[Ally].Treaty_OpenBorders = false; this.empire.GetRelations()[Ally].Treaty_NAPact = false; } Relationship item = this.empire.GetRelations()[Ally]; item.Trust = item.Trust - Amount; Relationship angerDiplomaticConflict = this.empire.GetRelations()[Ally]; angerDiplomaticConflict.Anger_DiplomaticConflict = angerDiplomaticConflict.Anger_DiplomaticConflict + Amount; }) }; if (Ally == EmpireManager.GetEmpireByName(this.empire.GetUS().PlayerLoyalty)) { this.empire.GetUS().ScreenManager.AddScreen(new DiplomacyScreen(this.empire, EmpireManager.GetEmpireByName(this.empire.GetUS().PlayerLoyalty), dialogue, OurOffer, offer, Enemy)); } }
public void 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; } } }
public bool Initialize(AgentMission TheMission, Empire Owner) { float spyBudget =0;// = Owner.GetGSAI().spyBudget; if (Owner.isPlayer) Owner.GetGSAI().spyBudget = Owner.Money; bool returnvalue = false; switch (TheMission) { case AgentMission.Training: { if (Owner.GetGSAI().spyBudget >= ResourceManager.AgentMissionData.TrainingCost) { this.TurnsRemaining = ResourceManager.AgentMissionData.TrainingTurns; spyBudget -= ResourceManager.AgentMissionData.TrainingCost; this.MissionNameIndex = 2196; returnvalue = true; } break; } case AgentMission.Infiltrate: { if (Owner.GetGSAI().spyBudget >= ResourceManager.AgentMissionData.InfiltrateCost) { this.TurnsRemaining = ResourceManager.AgentMissionData.InfiltrateTurns; spyBudget -= ResourceManager.AgentMissionData.InfiltrateCost; this.MissionNameIndex = 2188; returnvalue = true; } break; } case AgentMission.Assassinate: { if (Owner.GetGSAI().spyBudget >= ResourceManager.AgentMissionData.AssassinateCost) { this.TurnsRemaining = ResourceManager.AgentMissionData.AssassinateTurns; spyBudget -= ResourceManager.AgentMissionData.AssassinateCost; this.MissionNameIndex = 2184; returnvalue = true; } break; } case AgentMission.Sabotage: { if (Owner.GetGSAI().spyBudget > ResourceManager.AgentMissionData.SabotageCost) { this.TurnsRemaining = ResourceManager.AgentMissionData.SabotageTurns; spyBudget -= ResourceManager.AgentMissionData.SabotageCost; this.MissionNameIndex = 2190; returnvalue = true; } break; } case AgentMission.StealTech: { if (Owner.GetGSAI().spyBudget >= ResourceManager.AgentMissionData.StealTechCost) { this.TurnsRemaining = ResourceManager.AgentMissionData.StealTechTurns; spyBudget -= ResourceManager.AgentMissionData.StealTechCost; this.MissionNameIndex = 2194; returnvalue = true; } break; } case AgentMission.Robbery: { if (Owner.GetGSAI().spyBudget >= ResourceManager.AgentMissionData.RobberyCost) { this.TurnsRemaining = ResourceManager.AgentMissionData.RobberyTurns; spyBudget -= ResourceManager.AgentMissionData.RobberyCost; this.MissionNameIndex = 2192; returnvalue = true; } break; } case AgentMission.InciteRebellion: { if (Owner.GetGSAI().spyBudget >= ResourceManager.AgentMissionData.RebellionCost) { this.TurnsRemaining = ResourceManager.AgentMissionData.RebellionTurns; spyBudget -= ResourceManager.AgentMissionData.RebellionCost; this.MissionNameIndex = 2186; returnvalue = true; } break; } case AgentMission.Recovering: { this.TurnsRemaining = ResourceManager.AgentMissionData.RecoveringTurns; this.MissionNameIndex = 6024; return true; } default: { return false; } } if (Owner.isPlayer) Owner.Money+=spyBudget; else { Owner.GetGSAI().spyBudget += spyBudget; } return returnvalue; }
private void LoadEverything(object sender, RunWorkerCompletedEventArgs ev) { bool stop; List<SolarSystem>.Enumerator enumerator; base.ScreenManager.inter.ObjectManager.Clear(); this.data = new UniverseData(); RandomEventManager.ActiveEvent = this.savedData.RandomEvent; UniverseScreen.DeepSpaceManager = new SpatialManager(); this.ThrusterEffect = base.ScreenManager.Content.Load<Effect>("Effects/Thrust"); int count = this.data.SolarSystemsList.Count; this.data.loadFogPath = this.savedData.FogMapName; this.data.difficulty = UniverseData.GameDifficulty.Normal; this.data.difficulty = this.savedData.gameDifficulty; this.data.Size = this.savedData.Size; this.data.FTLSpeedModifier = this.savedData.FTLModifier; this.data.EnemyFTLSpeedModifier = this.savedData.EnemyFTLModifier; this.data.GravityWells = this.savedData.GravityWells; //added by gremlin: adjuse projector radius to map size. but only normal or higher. //this is pretty bad as its not connected to the creating game screen code that sets the map sizes. If someone changes the map size they wont know to change this as well. if (this.data.Size.X > 7300000f) Empire.ProjectorRadius = this.data.Size.X / 70f; EmpireManager.EmpireList.Clear(); if (Empire.universeScreen!=null && Empire.universeScreen.MasterShipList != null) Empire.universeScreen.MasterShipList.Clear(); foreach (SavedGame.EmpireSaveData d in this.savedData.EmpireDataList) { Empire e =new Empire(); e.data = new EmpireData(); e= this.CreateEmpireFromEmpireSaveData(d); this.data.EmpireList.Add(e); if (e.data.Traits.Name == this.PlayerLoyalty) { e.AutoColonize = this.savedData.AutoColonize; e.AutoExplore = this.savedData.AutoExplore; e.AutoFreighters = this.savedData.AutoFreighters; e.AutoBuild = this.savedData.AutoProjectors; } EmpireManager.EmpireList.Add(e); } foreach (Empire e in this.data.EmpireList) { if (e.data.AbsorbedBy == null) { continue; } foreach (KeyValuePair<string, TechEntry> tech in EmpireManager.GetEmpireByName(e.data.AbsorbedBy).GetTDict()) { if (!tech.Value.Unlocked) { continue; } EmpireManager.GetEmpireByName(e.data.AbsorbedBy).UnlockHullsSave(tech.Key, e.data.Traits.ShipType); } } foreach (SavedGame.EmpireSaveData d in this.savedData.EmpireDataList) { Empire e = EmpireManager.GetEmpireByName(d.Name); foreach (Relationship r in d.Relations) { e.GetRelations().Add(EmpireManager.GetEmpireByName(r.Name), r); if (r.ActiveWar == null) { continue; } r.ActiveWar.SetCombatants(e, EmpireManager.GetEmpireByName(r.Name)); } } this.data.SolarSystemsList = new List<SolarSystem>(); foreach (SavedGame.SolarSystemSaveData sdata in this.savedData.SolarSystemDataList) { SolarSystem system = this.CreateSystemFromData(sdata); system.guid = sdata.guid; this.data.SolarSystemsList.Add(system); } foreach (SavedGame.EmpireSaveData d in this.savedData.EmpireDataList) { Empire e = EmpireManager.GetEmpireByName(d.empireData.Traits.Name); foreach (SavedGame.ShipSaveData shipData in d.OwnedShips) { Ship ship = Ship.LoadSavedShip(shipData.data); ship.guid = shipData.guid; ship.Name = shipData.Name; if (!string.IsNullOrEmpty(shipData.VanityName)) ship.VanityName = shipData.VanityName; else { if (ship.Role == "troop") { if (shipData.TroopList.Count > 0) { ship.VanityName = shipData.TroopList[0].Name; } else ship.VanityName = shipData.Name; } else ship.VanityName = shipData.Name; } ship.Position = shipData.Position; if (shipData.IsPlayerShip) { this.playerShip = ship; this.playerShip.PlayerShip = true; this.data.playerShip = this.playerShip; } ship.experience = shipData.experience; ship.kills = shipData.kills; if (!Ship_Game.ResourceManager.ShipsDict.ContainsKey(shipData.Name)) { shipData.data.Hull = shipData.Hull; Ship newShip = Ship.CreateShipFromShipData(shipData.data); newShip.SetShipData(shipData.data); if (!newShip.InitForLoad()) { continue; } newShip.InitializeStatus(); newShip.IsPlayerDesign = false; newShip.FromSave = true; Ship_Game.ResourceManager.ShipsDict.Add(shipData.Name, newShip); } else if (Ship_Game.ResourceManager.ShipsDict[shipData.Name].FromSave) { ship.IsPlayerDesign = false; ship.FromSave = true; } float oldbasestr = ship.BaseStrength; float newbasestr = ResourceManager.CalculateBaseStrength(ship); ship.BaseStrength = newbasestr; foreach(ModuleSlotData moduleSD in shipData.data.ModuleSlotList) { ShipModule mismatch =null; bool exists =ResourceManager.ShipModulesDict.TryGetValue(moduleSD.InstalledModuleUID,out mismatch); if (exists) continue; System.Diagnostics.Debug.WriteLine(string.Concat("mismatch =", moduleSD.InstalledModuleUID)); } ship.PowerCurrent = shipData.Power; ship.yRotation = shipData.yRotation; ship.Ordinance = shipData.Ordnance; ship.Rotation = shipData.Rotation; ship.Velocity = shipData.Velocity; ship.isSpooling = shipData.AfterBurnerOn; ship.InCombatTimer = shipData.InCombatTimer; foreach (Troop t in shipData.TroopList) { t.SetOwner(EmpireManager.GetEmpireByName(t.OwnerString)); ship.TroopList.Add(t); } foreach (Rectangle AOO in shipData.AreaOfOperation) { ship.AreaOfOperation.Add(AOO); } ship.TetherGuid = shipData.TetheredTo; ship.TetherOffset = shipData.TetherOffset; if (ship.InCombatTimer > 0f) { ship.InCombat = true; } ship.loyalty = e; ship.InitializeAI(); ship.GetAI().CombatState = shipData.data.CombatState; ship.GetAI().FoodOrProd = shipData.AISave.FoodOrProd; ship.GetAI().State = shipData.AISave.state; ship.GetAI().DefaultAIState = shipData.AISave.defaultstate; ship.GetAI().GotoStep = shipData.AISave.GoToStep; ship.GetAI().MovePosition = shipData.AISave.MovePosition; ship.GetAI().OrbitTargetGuid = shipData.AISave.OrbitTarget; ship.GetAI().ColonizeTargetGuid = shipData.AISave.ColonizeTarget; ship.GetAI().TargetGuid = shipData.AISave.AttackTarget; ship.GetAI().SystemToDefendGuid = shipData.AISave.SystemToDefend; ship.GetAI().EscortTargetGuid = shipData.AISave.EscortTarget; bool hasCargo = false; if (shipData.FoodCount > 0f) { ship.AddGood("Food", (int)shipData.FoodCount); ship.GetAI().FoodOrProd = "Food"; hasCargo = true; } if (shipData.ProdCount > 0f) { ship.AddGood("Production", (int)shipData.ProdCount); ship.GetAI().FoodOrProd = "Prod"; hasCargo = true; } if (shipData.PopCount > 0f) { ship.AddGood("Colonists_1000", (int)shipData.PopCount); } AIState state = ship.GetAI().State; if (state == AIState.SystemTrader) { ship.GetAI().OrderTradeFromSave(hasCargo, shipData.AISave.startGuid, shipData.AISave.endGuid); } else if (state == AIState.PassengerTransport) { ship.GetAI().OrderTransportPassengersFromSave(); } e.AddShip(ship); foreach (SavedGame.ProjectileSaveData pdata in shipData.Projectiles) { Weapon w = Ship_Game.ResourceManager.GetWeapon(pdata.Weapon); Projectile p = w.LoadProjectiles(pdata.Velocity, ship); p.Velocity = pdata.Velocity; p.Position = pdata.Position; p.Center = pdata.Position; p.duration = pdata.Duration; ship.Projectiles.Add(p); } this.data.MasterShipList.Add(ship); } } foreach (SavedGame.EmpireSaveData d in this.savedData.EmpireDataList) { Empire e = EmpireManager.GetEmpireByName(d.Name); foreach (SavedGame.FleetSave fleetsave in d.FleetsList) { Ship_Game.Gameplay.Fleet fleet = new Ship_Game.Gameplay.Fleet() { guid = fleetsave.FleetGuid, IsCoreFleet = fleetsave.IsCoreFleet, facing = fleetsave.facing }; foreach (SavedGame.FleetShipSave ssave in fleetsave.ShipsInFleet) { foreach (Ship ship in this.data.MasterShipList) { if (ship.guid != ssave.shipGuid) { continue; } ship.RelativeFleetOffset = ssave.fleetOffset; fleet.AddShip(ship); } } foreach (FleetDataNode node in fleetsave.DataNodes) { fleet.DataNodes.Add(node); } foreach (FleetDataNode node in fleet.DataNodes) { foreach (Ship ship in fleet.Ships) { if (!(node.ShipGuid != Guid.Empty) || !(ship.guid == node.ShipGuid)) { continue; } node.SetShip(ship); node.ShipName = ship.Name; break; } } fleet.AssignPositions(fleet.facing); fleet.Name = fleetsave.Name; fleet.TaskStep = fleetsave.TaskStep; fleet.Owner = e; fleet.Position = fleetsave.Position; if (e.GetFleetsDict().ContainsKey(fleetsave.Key)) { e.GetFleetsDict()[fleetsave.Key] = fleet; } else { e.GetFleetsDict().TryAdd(fleetsave.Key, fleet); } e.GetFleetsDict()[fleetsave.Key].SetSpeed(); fleet.findAveragePositionset(); fleet.Setavgtodestination(); } foreach (SavedGame.ShipSaveData shipData in d.OwnedShips) { foreach (Ship ship in e.GetShips()) { if (ship.Position != shipData.Position) { continue; } } } } foreach (SavedGame.EmpireSaveData d in this.savedData.EmpireDataList) { Empire e = EmpireManager.GetEmpireByName(d.Name); e.SpaceRoadsList = new List<SpaceRoad>(); foreach (SavedGame.SpaceRoadSave roadsave in d.SpaceRoadData) { SpaceRoad road = new SpaceRoad(); foreach (SolarSystem s in this.data.SolarSystemsList) { if (roadsave.OriginGUID == s.guid) { road.SetOrigin(s); } if (roadsave.DestGUID != s.guid) { continue; } road.SetDestination(s); } foreach (SavedGame.RoadNodeSave nodesave in roadsave.RoadNodes) { RoadNode node = new RoadNode(); foreach (Ship s in this.data.MasterShipList) { if (nodesave.Guid_Platform != s.guid) { continue; } node.Platform = s; } node.Position = nodesave.Position; road.RoadNodesList.Add(node); } e.SpaceRoadsList.Add(road); } foreach (SavedGame.GoalSave gsave in d.GSAIData.Goals) { Goal g = new Goal() { empire = e, type = gsave.type }; if (g.type == GoalType.BuildShips && gsave.ToBuildUID != null && !Ship_Game.ResourceManager.ShipsDict.ContainsKey(gsave.ToBuildUID)) { continue; } g.ToBuildUID = gsave.ToBuildUID; g.Step = gsave.GoalStep; g.guid = gsave.GoalGuid; g.GoalName = gsave.GoalName; g.BuildPosition = gsave.BuildPosition; if (gsave.fleetGuid != Guid.Empty) { foreach (KeyValuePair<int, Ship_Game.Gameplay.Fleet> Fleet in e.GetFleetsDict()) { if (Fleet.Value.guid != gsave.fleetGuid) { continue; } g.SetFleet(Fleet.Value); } } foreach (SolarSystem s in this.data.SolarSystemsList) { foreach (Planet p in s.PlanetList) { if (p.guid == gsave.planetWhereBuildingAtGuid) { g.SetPlanetWhereBuilding(p); } if (p.guid != gsave.markedPlanetGuid) { continue; } g.SetMarkedPlanet(p); } } foreach (Ship s in this.data.MasterShipList) { if (gsave.colonyShipGuid == s.guid) { g.SetColonyShip(s); } if (gsave.beingBuiltGUID != s.guid) { continue; } g.SetBeingBuilt(s); } e.GetGSAI().Goals.Add(g); } for (int i = 0; i < d.GSAIData.PinGuids.Count; i++) { e.GetGSAI().ThreatMatrix.Pins.TryAdd(d.GSAIData.PinGuids[i], d.GSAIData.PinList[i]); } e.GetGSAI().UsedFleets = d.GSAIData.UsedFleets; lock (GlobalStats.TaskLocker) { foreach (MilitaryTask task in d.GSAIData.MilitaryTaskList) { task.SetEmpire(e); e.GetGSAI().TaskList.Add(task); if (task.TargetPlanetGuid != Guid.Empty) { enumerator = this.data.SolarSystemsList.GetEnumerator(); try { do { if (!enumerator.MoveNext()) { break; } SolarSystem s = enumerator.Current; stop = false; foreach (Planet p in s.PlanetList) { if (p.guid != task.TargetPlanetGuid) { continue; } task.SetTargetPlanet(p); stop = true; break; } } while (!stop); } finally { ((IDisposable)enumerator).Dispose(); } } foreach (Guid guid in task.HeldGoals) { foreach (Goal g in e.GetGSAI().Goals) { if (g.guid != guid) { continue; } g.Held = true; } } try { if (task.WhichFleet != -1) { e.GetFleetsDict()[task.WhichFleet].Task = task; } } catch { task.WhichFleet = 0; } } } foreach (SavedGame.ShipSaveData shipData in d.OwnedShips) { foreach (Ship ship in this.data.MasterShipList) { if (ship.guid != shipData.guid) { continue; } foreach (Vector2 waypoint in shipData.AISave.ActiveWayPoints) { ship.GetAI().ActiveWayPoints.Enqueue(waypoint); } foreach (SavedGame.ShipGoalSave sg in shipData.AISave.ShipGoalsList) { ArtificialIntelligence.ShipGoal g = new ArtificialIntelligence.ShipGoal(sg.Plan, sg.MovePosition, sg.FacingVector); foreach (SolarSystem s in this.data.SolarSystemsList) { foreach (Planet p in s.PlanetList) { if (sg.TargetPlanetGuid == p.guid) { g.TargetPlanet = p; ship.GetAI().ColonizeTarget = p; } if (p.guid == shipData.AISave.startGuid) { ship.GetAI().start = p; } if (p.guid != shipData.AISave.endGuid) { continue; } ship.GetAI().end = p; } } if (sg.fleetGuid != Guid.Empty) { foreach (KeyValuePair<int, Ship_Game.Gameplay.Fleet> fleet in e.GetFleetsDict()) { if (fleet.Value.guid != sg.fleetGuid) { continue; } g.fleet = fleet.Value; } } g.VariableString = sg.VariableString; g.DesiredFacing = sg.DesiredFacing; g.SpeedLimit = sg.SpeedLimit; foreach (Goal goal in ship.loyalty.GetGSAI().Goals) { if (sg.goalGuid != goal.guid) { continue; } g.goal = goal; } ship.GetAI().OrderQueue.AddLast(g); } } } } foreach (SavedGame.SolarSystemSaveData sdata in this.savedData.SolarSystemDataList) { foreach (SavedGame.RingSave rsave in sdata.RingList) { Planet p = new Planet(); foreach (SolarSystem s in this.data.SolarSystemsList) { foreach (Planet p1 in s.PlanetList) { if (p1.guid != rsave.Planet.guid) { continue; } p = p1; break; } } if (p.Owner == null) { continue; } foreach (SavedGame.QueueItemSave qisave in rsave.Planet.QISaveList) { QueueItem qi = new QueueItem(); if (qisave.isBuilding) { qi.isBuilding = true; qi.Building = Ship_Game.ResourceManager.BuildingsDict[qisave.UID]; qi.Cost = qi.Building.Cost * this.savedData.GamePacing; qi.NotifyOnEmpty = false; foreach (PlanetGridSquare pgs in p.TilesList) { if ((float)pgs.x != qisave.pgsVector.X || (float)pgs.y != qisave.pgsVector.Y) { continue; } pgs.QItem = qi; qi.pgs = pgs; break; } } if (qisave.isTroop) { qi.isTroop = true; qi.troop = Ship_Game.ResourceManager.TroopsDict[qisave.UID]; qi.Cost = qi.troop.GetCost(); qi.NotifyOnEmpty = false; } if (qisave.isShip) { qi.isShip = true; if (!Ship_Game.ResourceManager.ShipsDict.ContainsKey(qisave.UID)) { continue; } qi.sData = Ship_Game.ResourceManager.GetShip(qisave.UID).GetShipData(); qi.DisplayName = qisave.DisplayName; qi.Cost = 0f; foreach (ModuleSlot slot in Ship_Game.ResourceManager.GetShip(qisave.UID).ModuleSlotList) { if (slot.InstalledModuleUID == null) { continue; } QueueItem cost = qi; cost.Cost = cost.Cost + Ship_Game.ResourceManager.GetModule(slot.InstalledModuleUID).Cost * this.savedData.GamePacing; } QueueItem queueItem = qi; queueItem.Cost += qi.Cost * p.Owner.data.Traits.ShipCostMod; queueItem.Cost *= (GlobalStats.ActiveModInfo != null && GlobalStats.ActiveModInfo.useHullBonuses && ResourceManager.HullBonuses.ContainsKey(Ship_Game.ResourceManager.GetShip(qisave.UID).GetShipData().Hull) ? 1f - ResourceManager.HullBonuses[Ship_Game.ResourceManager.GetShip(qisave.UID).GetShipData().Hull].CostBonus : 1); if (qi.sData.HasFixedCost) { qi.Cost = (float)qi.sData.FixedCost; } if (qisave.IsRefit) { qi.isRefit = true; qi.Cost = qisave.RefitCost; } } foreach (Goal g in p.Owner.GetGSAI().Goals) { if (g.guid != qisave.GoalGUID) { continue; } qi.Goal = g; qi.NotifyOnEmpty = false; } if (qisave.isShip && qi.Goal != null) { qi.Goal.beingBuilt = Ship_Game.ResourceManager.GetShip(qisave.UID); } qi.productionTowards = qisave.ProgressTowards; p.ConstructionQueue.Add(qi); } } } this.Loaded = true; }
private Empire CreateEmpireFromEmpireSaveData(SavedGame.EmpireSaveData data) { Empire e = new Empire(); //TempEmpireData Tdata = new TempEmpireData(); if (data.IsFaction) { e.isFaction = true; } if (data.isMinorRace) { e.MinorRace = true; } if (data.empireData == null) { e.data.Traits = data.Traits; e.EmpireColor = new Color((byte)data.Traits.R, (byte)data.Traits.G, (byte)data.Traits.B); } else { e.data = new EmpireData(); //Tdata = data.empireData as TempEmpireData; foreach (string key in e.data.WeaponTags.Keys) { if(data.empireData.WeaponTags.ContainsKey(key)) continue; data.empireData.WeaponTags.Add(key,new WeaponTagModifier()); } e.data = data.empireData; // e.data. e.data.ResearchQueue = data.empireData.ResearchQueue; e.ResearchTopic = data.ResearchTopic; if (e.ResearchTopic == null) { e.ResearchTopic = ""; } e.dd = Ship_Game.ResourceManager.DDDict[e.data.DiplomacyDialogPath]; e.PortraitName = e.data.PortraitName; e.EmpireColor = new Color((byte)e.data.Traits.R, (byte)e.data.Traits.G, (byte)e.data.Traits.B); if (data.CurrentAutoScout != null) e.data.CurrentAutoScout = data.CurrentAutoScout; else e.data.CurrentAutoScout = e.data.StartingScout; if (data.CurrentAutoFreighter != null) e.data.CurrentAutoFreighter = data.CurrentAutoFreighter; else e.data.CurrentAutoFreighter = e.data.DefaultSmallTransport; if (data.CurrentAutoColony != null) e.data.CurrentAutoColony = data.CurrentAutoColony; else e.data.CurrentAutoColony = e.data.DefaultColonyShip; if (data.CurrentConstructor != null) e.data.CurrentConstructor = data.CurrentConstructor; else e.data.CurrentConstructor = e.data.DefaultConstructor; } e.Initialize(); e.Money = data.Money; e.Research = data.Research; e.GetGSAI().AreasOfOperations = data.AOs; foreach (TechEntry tech in data.TechTree) { if (!e.GetTDict().ContainsKey(tech.UID)) { continue; } if (tech.AcquiredFrom != null) e.GetTDict()[tech.UID].AcquiredFrom = tech.AcquiredFrom; if (tech.Unlocked) { e.UnlockTechFromSave(tech.UID); } e.GetTDict()[tech.UID].Progress = tech.Progress; e.GetTDict()[tech.UID].Discovered = tech.Discovered; e.GetTDict()[tech.UID].level = tech.level; } return e; }
/** 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 }