private IEnumerable <SpeechNode> DeclareWar() { BackButton.IsVisible = true; if (!Politics.HasEvent("you declared war on us")) { Politics.RecentEvents.Add(new Diplomacy.PoliticalEvent() { Change = -2.0f, Description = "you declared war on us", Duration = new TimeSpan(4, 0, 0, 0), Time = World.Time.CurrentDate }); Politics.WasAtWar = true; } yield return(new SpeechNode() { Text = Datastructures.SelectRandom(Faction.Race.Speech.WarDeclarations), Actions = new List <SpeechNode.SpeechAction>() }); }
IEnumerable <SpeechNode> WaitForTrade() { TradeDialog dialog = TradeDialog.Popup(GUI, GUI.RootComponent, Faction, Resources); LastEvent = null; dialog.OnTraded += dialog_OnClicked; while (LastEvent == null && dialog.IsVisible) { yield return(null); } if (LastEvent != null) { TradeEvent.Profit profit = LastEvent.GetProfit(); if (LastEvent.IsHate() && !Politics.HasEvent("you tried to give us something offensive")) { Politics.RecentEvents.Add(new Diplomacy.PoliticalEvent() { Change = -0.25f, Description = "you tried to give us something offensive", Duration = new TimeSpan(4, 0, 0, 0), Time = World.Time.CurrentDate }); } else if ((!LastEvent.IsHate() && LastEvent.IsLike()) && !Politics.HasEvent("you gave us something we liked")) { Politics.RecentEvents.Add(new Diplomacy.PoliticalEvent() { Change = 0.25f, Description = "you gave us something we liked", Duration = new TimeSpan(4, 0, 0, 0), Time = World.Time.CurrentDate }); } if (profit.PercentProfit > 0.25f && !LastEvent.IsHate()) { DoTrade(LastEvent); if (!Politics.HasEvent("we had profitable trade")) { Politics.RecentEvents.Add(new Diplomacy.PoliticalEvent() { Change = 0.25f, Description = "we had profitable trade", Duration = new TimeSpan(2, 0, 0, 0), Time = World.Time.CurrentDate }); } yield return(new SpeechNode() { Text = GetGoodTradeText(), Actions = new List <SpeechNode.SpeechAction>() { new SpeechNode.SpeechAction() { Text = "Ok", Action = () => SpeechNode.Echo(DialougeTree) } } }); } else { yield return(new SpeechNode() { Text = GetBadTradeText(), Actions = new List <SpeechNode.SpeechAction>() { new SpeechNode.SpeechAction() { Text = "Sorry.", Action = () => SpeechNode.Echo(DialougeTree) } } }); } yield break; } else { yield return(DialougeTree); } yield break; }
void Initialize() { Envoy.TradeMoney = Faction.TradeMoney + MathFunctions.Rand(-100.0f, 100.0f); Envoy.TradeMoney = Math.Max(Envoy.TradeMoney, 0.0f); TalkerName = TextGenerator.GenerateRandom(Datastructures.SelectRandom(Faction.Race.NameTemplates).ToArray()); Tabs = new Dictionary <string, GUIComponent>(); GUI = new DwarfGUI(Game, Game.Content.Load <SpriteFont>(ContentPaths.Fonts.Default), Game.Content.Load <SpriteFont>(ContentPaths.Fonts.Title), Game.Content.Load <SpriteFont>(ContentPaths.Fonts.Small), Input) { DebugDraw = false }; IsInitialized = true; MainWindow = new GUIComponent(GUI, GUI.RootComponent) { LocalBounds = new Rectangle(EdgePadding, EdgePadding, Game.GraphicsDevice.Viewport.Width - EdgePadding * 2, Game.GraphicsDevice.Viewport.Height - EdgePadding * 2) }; Layout = new GridLayout(GUI, MainWindow, 11, 4); Layout.UpdateSizes(); Talker = new SpeakerComponent(GUI, Layout, new Animation(Faction.Race.TalkAnimation)); Layout.SetComponentPosition(Talker, 0, 0, 4, 4); DialougeSelector = new ListSelector(GUI, Layout) { Mode = ListItem.SelectionMode.ButtonList, DrawButtons = true, DrawPanel = false, Label = "", ItemHeight = 35, Padding = 5 }; DialougeSelector.OnItemSelected += DialougeSelector_OnItemSelected; Layout.SetComponentPosition(DialougeSelector, 2, 3, 1, 8); BackButton = new Button(GUI, Layout, "Back", GUI.DefaultFont, Button.ButtonMode.ToolButton, GUI.Skin.GetSpecialFrame(GUISkin.Tile.LeftArrow)); Layout.SetComponentPosition(BackButton, 2, 10, 1, 1); BackButton.OnClicked += back_OnClicked; BackButton.IsVisible = false; DialougeTree = new SpeechNode() { Text = GetGreeting(), Actions = new List <SpeechNode.SpeechAction>() { new SpeechNode.SpeechAction() { Text = "Trade...", Action = WaitForTrade }, new SpeechNode.SpeechAction() { Text = "Ask a question...", Action = AskAQuestion }, new SpeechNode.SpeechAction() { Text = "Declare war!", Action = DeclareWar }, new SpeechNode.SpeechAction() { Text = "Leave", Action = () => { BackButton.IsVisible = true; if (Envoy != null) { Diplomacy.RecallEnvoy(Envoy); } return(SpeechNode.Echo(new SpeechNode() { Text = GetFarewell(), Actions = new List <SpeechNode.SpeechAction>() })); } } } }; if (Politics.WasAtWar) { PreeTree = new SpeechNode() { Text = Datastructures.SelectRandom(Faction.Race.Speech.PeaceDeclarations), Actions = new List <SpeechNode.SpeechAction>() { new SpeechNode.SpeechAction() { Text = "Make peace with " + Faction.Name, Action = () => { if (!Politics.HasEvent("you made peace with us")) { Politics.RecentEvents.Add(new Diplomacy.PoliticalEvent() { Change = 0.4f, Description = "you made peace with us", Duration = new TimeSpan(4, 0, 0, 0), Time = World.Time.CurrentDate }); } return(SpeechNode.Echo(DialougeTree)); } }, new SpeechNode.SpeechAction() { Text = "Continue the war with " + Faction.Name, Action = DeclareWar } } }; Transition(PreeTree); Politics.WasAtWar = false; } else { Transition(DialougeTree); } if (!Politics.HasMet) { Politics.HasMet = true; Politics.RecentEvents.Add(new Diplomacy.PoliticalEvent() { Change = 0.0f, Description = "we just met", Duration = new TimeSpan(1, 0, 0, 0), Time = World.Time.CurrentDate }); } Layout.UpdateSizes(); Talker.TweenIn(Drawer2D.Alignment.Top, 0.25f); DialougeSelector.TweenIn(Drawer2D.Alignment.Right, 0.25f); }
public void InitializeFactionPolitics(Faction New, DateTime Now) { TimeSpan forever = new TimeSpan(999999, 0, 0, 0); foreach (var faction in Factions.Factions) { Pair <string> pair = new Pair <string>(faction.Value.Name, New.Name); if (FactionPolitics.ContainsKey(pair)) { continue; } if (faction.Key == New.Name) { FactionPolitics[pair] = new Politics(Now, new TimeSpan(0, 0, 0)) { Faction = faction.Value, HasMet = true, RecentEvents = new List <PoliticalEvent>() { new PoliticalEvent() { Change = 1.0f, Description = "we are of the same faction", Duration = forever, Time = Now } } }; } else { Point c1 = faction.Value.Center; Point c2 = New.Center; double dist = Math.Sqrt(Math.Pow(c1.X - c2.X, 2) + Math.Pow(c1.Y - c2.Y, 2)); // Time always takes between 1 and 4 days of travel. double timeInMinutes = Math.Min(Math.Max(dist * 2.0f, 1440), 1440 * 4) + MathFunctions.RandInt(0, 250); Politics politics = new Politics(Now, new TimeSpan(0, (int)(timeInMinutes), 0)) { Faction = New, HasMet = false, RecentEvents = new List <PoliticalEvent>(), }; if (faction.Value.Race == New.Race) { politics.RecentEvents.Add(new PoliticalEvent() { Change = 0.5f, Description = "we are of the same people", Duration = forever, Time = Now }); } if (faction.Value.Race.NaturalEnemies.Any(name => name == New.Race.Name)) { if (!politics.HasEvent("we are taught to hate your kind")) { politics.RecentEvents.Add(new PoliticalEvent() { Change = -10.0f, // Make this negative and we get an instant war party rush. Description = "we are taught to hate your kind", Duration = forever, Time = Now }); } } if (faction.Value.Race.IsIntelligent && New.Race.IsIntelligent) { float trustingness = faction.Value.GoodWill; if (trustingness < -0.8f) { if (!politics.HasEvent("we just don't trust you")) { politics.RecentEvents.Add(new PoliticalEvent() { Change = -10.0f, // Make this negative and we get an instant war party rush. Description = "we just don't trust you", Duration = forever, Time = Now }); } } else if (trustingness > 0.8f) { if (!politics.HasEvent("we trust you")) { politics.RecentEvents.Add(new PoliticalEvent() { Change = 10.0f, Description = "we trust you", Duration = forever, Time = Now }); } } } FactionPolitics[pair] = politics; } } FactionPolitics[new Pair <string>("Undead", "Player")].RecentEvents.Add(new PoliticalEvent() { Change = -10.0f, Description = "Test hate", Duration = forever, Time = Now }); }
public static void Initialize(Overworld Overworld) { foreach (var otherFaction in Overworld.Natives) { foreach (var thisFaction in Overworld.Natives) { if (thisFaction.Name == otherFaction.Name) { var politics = new Politics() { OwnerFaction = thisFaction, OtherFaction = otherFaction, HasMet = true }; politics.AddEvent(new PoliticalEvent() { Change = 1.0f, Description = "we are of the same faction", }); thisFaction.Politics[otherFaction.Name] = politics; } else { Politics politics = new Politics() { OwnerFaction = thisFaction, OtherFaction = otherFaction, HasMet = false, }; if (thisFaction.Race == otherFaction.Race) { politics.AddEvent(new PoliticalEvent() { Change = 0.5f, Description = "we are of the same people", }); } var thisFactionRace = Library.GetRace(thisFaction.Race); var otherRace = Library.GetRace(otherFaction.Race); if (thisFactionRace.NaturalEnemies.Any(name => name == otherRace.Name)) { if (!politics.HasEvent("we are taught to hate your kind")) { politics.AddEvent(new PoliticalEvent() { Change = -10.0f, // Make this negative and we get an instant war party rush. Description = "we are taught to hate your kind", }); } } if (thisFactionRace.IsIntelligent && otherRace.IsIntelligent) { float trustingness = thisFaction.GoodWill; if (trustingness < -0.8f) { if (!politics.HasEvent("we just don't trust you")) { politics.AddEvent(new PoliticalEvent() { Change = -10.0f, // Make this negative and we get an instant war party rush. Description = "we just don't trust you", }); politics.IsAtWar = true; } } else if (trustingness > 0.8f) { if (!politics.HasEvent("we just trust you")) { politics.AddEvent(new PoliticalEvent() { Change = 10.0f, Description = "we just trust you", }); } } } thisFaction.Politics[otherFaction.Name] = politics; } } } }
public static Politics CreatePolitivs(OverworldFaction thisFaction, OverworldFaction otherFaction) { if (thisFaction.Name == otherFaction.Name) { var politics = new Politics() { OwnerFaction = thisFaction, OtherFaction = otherFaction, HasMet = true }; politics.AddEvent(new PoliticalEvent() { Change = 1.0f, Description = "we are of the same faction", }); return(politics); } else { var politics = new Politics() { OwnerFaction = thisFaction, OtherFaction = otherFaction, HasMet = false, }; if (thisFaction.Race == otherFaction.Race) { politics.AddEvent(new PoliticalEvent() { Change = 0.5f, Description = "we are of the same people", }); } if (Library.GetRace(thisFaction.Race).HasValue(out var thisFactionRace) && Library.GetRace(otherFaction.Race).HasValue(out var otherRace)) { if (thisFactionRace.NaturalEnemies.Any(name => name == otherRace.Name) || otherRace.NaturalEnemies.Any(name => name == thisFactionRace.Name)) { if (!politics.HasEvent("we are taught to hate your kind")) { politics.AddEvent(new PoliticalEvent() { Change = -10.0f, // Make this negative and we get an instant war party rush. Description = "we are taught to hate your kind", }); } } if (thisFactionRace.IsIntelligent && otherRace.IsIntelligent) { if (thisFaction.GoodWill < -0.8f || otherFaction.GoodWill < -0.8f) { if (!politics.HasEvent("we just don't trust you")) { politics.AddEvent(new PoliticalEvent() { Change = -10.0f, // Make this negative and we get an instant war party rush. Description = "we just don't trust you", }); politics.IsAtWar = true; } } else if (thisFaction.GoodWill > 0.8f || otherFaction.GoodWill > 0.8f) { if (!politics.HasEvent("we just trust you")) { politics.AddEvent(new PoliticalEvent() { Change = 10.0f, Description = "we just trust you", }); } } } } return(politics); } }
public void Initialize(DateTime now) { TimeSpan forever = new TimeSpan(999999, 0, 0, 0); foreach (var faction in Factions.Factions) { foreach (var otherFaction in Factions.Factions) { Pair <string> pair = new Pair <string>(faction.Value.Name, otherFaction.Value.Name); if (FactionPolitics.ContainsKey(pair)) { continue; } if (faction.Key == otherFaction.Key) { FactionPolitics[pair] = new Politics() { Faction = faction.Value, HasMet = true, RecentEvents = new List <PoliticalEvent>() { new PoliticalEvent() { Change = 1.0f, Description = "we are of the same faction", Duration = forever, Time = now } } }; } else { Point c1 = faction.Value.Center; Point c2 = otherFaction.Value.Center; double dist = Math.Sqrt(Math.Pow(c1.X - c2.X, 2) + Math.Pow(c1.Y - c2.Y, 2)); // Time always takes between 1 and 4 days of travel. double timeInMinutes = Math.Min(Math.Max(dist * 8.0f, 1440), 1440 * 4); Politics politics = new Politics() { Faction = otherFaction.Value, HasMet = false, RecentEvents = new List <PoliticalEvent>(), DistanceToCapital = new TimeSpan(0, (int)(timeInMinutes), 0) }; politics.DispatchNewTradeEnvoy(); if (faction.Value.Race == otherFaction.Value.Race) { politics.RecentEvents.Add(new PoliticalEvent() { Change = 0.5f, Description = "we are of the same people", Duration = forever, Time = now }); } if (faction.Value.Race.NaturalEnemies.Any(name => name == otherFaction.Value.Race.Name)) { if (!politics.HasEvent("we are taught to hate your kind")) { politics.RecentEvents.Add(new PoliticalEvent() { Change = -2.0f, Description = "we are taught to hate your kind", Duration = forever, Time = now }); } } FactionPolitics[pair] = politics; } } } }
public void Initialize(DateTime now) { TimeSpan forever = new TimeSpan(999999, 0, 0, 0); foreach (var faction in Factions.Factions) { foreach (var otherFaction in Factions.Factions) { Pair <Faction> pair = new Pair <Faction>(faction.Value, otherFaction.Value); if (FactionPolitics.ContainsKey(pair)) { continue; } if (faction.Key == otherFaction.Key) { FactionPolitics[pair] = new Politics() { Faction = faction.Value, HasMet = true, RecentEvents = new List <PoliticalEvent>() { new PoliticalEvent() { Change = 1.0f, Description = "we are of the same faction", Duration = forever, Time = now } } }; } else { Politics politics = new Politics() { Faction = otherFaction.Value, HasMet = false, RecentEvents = new List <PoliticalEvent>() }; if (faction.Value.Race == otherFaction.Value.Race) { politics.RecentEvents.Add(new PoliticalEvent() { Change = 0.5f, Description = "we are of the same people", Duration = forever, Time = now }); } if (faction.Value.Race.NaturalEnemies.Any(name => name == otherFaction.Value.Race.Name)) { if (!politics.HasEvent("we are taught to hate your kind")) { politics.RecentEvents.Add(new PoliticalEvent() { Change = -2.0f, Description = "we are taught to hate your kind", Duration = forever, Time = now }); } } FactionPolitics[pair] = politics; } } } }