Esempio n. 1
0
        public void Update(DwarfTime time, DateTime currentDate)
        {
            foreach (var mypolitics in FactionPolitics)
            {
                Pair <Faction> pair = mypolitics.Key;
                if (!pair.IsSelfPair() && pair.Contains(PlayState.PlayerFaction))
                {
                    Faction otherFaction = null;

                    otherFaction = pair.First.Equals(PlayState.PlayerFaction) ? pair.Second : pair.First;

                    Race     race     = otherFaction.Race;
                    Politics relation = mypolitics.Value;

                    /*
                     * if (race.IsIntelligent  && !otherFaction.IsRaceFaction && relation.GetCurrentRelationship() != Relationship.Hateful && MathFunctions.RandEvent(1e-3f))
                     * {
                     *  SendTradeEnvoy(otherFaction);
                     * }
                     *
                     * if (race.IsIntelligent  && !otherFaction.IsRaceFaction && relation.GetCurrentRelationship() == Relationship.Hateful && MathFunctions.RandEvent(1e-3f))
                     * {
                     *  SendWarParty(otherFaction);
                     * }
                     */
                }
                mypolitics.Value.UpdateEvents(currentDate);
            }
        }
Esempio n. 2
0
        public WarParty SendWarParty(Faction natives)
        {
            natives.World.MakeAnnouncement(String.Format("War party from {0} has arrived!", natives.Name), null);
            natives.World.Tutorial("war");
            SoundManager.PlaySound(ContentPaths.Audio.Oscar.sfx_gui_negative_generic, 0.5f);
            Politics politics = GetPolitics(natives, natives.World.PlayerFaction);

            politics.WasAtWar = true;
            List <CreatureAI> creatures = natives.World.MonsterSpawner.Spawn(natives.World.MonsterSpawner.GenerateSpawnEvent(natives, natives.World.PlayerFaction, MathFunctions.Random.Next(5) + 1, true));
            var party = new WarParty(natives.World.Time.CurrentDate)
            {
                Creatures    = creatures,
                OtherFaction = natives.World.PlayerFaction,
                ShouldRemove = false,
                OwnerFaction = natives
            };

            natives.WarParties.Add(party);

            foreach (var creature in creatures)
            {
                if (natives.Economy == null)
                {
                    natives.Economy = new Economy(natives, (decimal)MathFunctions.Rand(1000, 9999), World, null);
                }
                if (natives.Economy.Company.Information == null)
                {
                    natives.Economy.Company.Information = new CompanyInformation();
                }

                creature.Physics.AddChild(new Flag(World.ComponentManager, Vector3.Up * 0.5f + Vector3.Backward * 0.25f, natives.Economy.Company.Information));
            }
            return(party);
        }
Esempio n. 3
0
        public WarParty SendWarParty()
        {
            World.Tutorial("war");
            SoundManager.PlaySound(ContentPaths.Audio.Oscar.sfx_gui_negative_generic, 0.5f);
            Politics politics = World.Overworld.GetPolitics(ParentFaction, World.PlayerFaction.ParentFaction);

            politics.IsAtWar = true;
            List <CreatureAI> creatures = World.MonsterSpawner.Spawn(World.MonsterSpawner.GenerateSpawnEvent(this, World.PlayerFaction, MathFunctions.Random.Next(World.Overworld.Difficulty) + 1, false));
            var party = new WarParty(World.Time.CurrentDate)
            {
                Creatures    = creatures,
                OtherFaction = World.PlayerFaction,
                ShouldRemove = false,
                OwnerFaction = this
            };

            WarParties.Add(party);

            World.MakeAnnouncement(new Gui.Widgets.QueuedAnnouncement()
            {
                Text           = String.Format("A war party from {0} has arrived!", ParentFaction.Name),
                SecondsVisible = 60,
                ClickAction    = (gui, sender) =>
                {
                    if (party.Creatures.Count > 0)
                    {
                        party.Creatures.First().ZoomToMe();
                        World.UserInterface.MakeWorldPopup(String.Format("Warriors from {0} ({1}) have entered our territory. They will prepare for a while and then attack us.", ParentFaction.Name, Race.Name), party.Creatures.First().Physics, -10);
                    }
                },
                ShouldKeep = () =>
                {
                    return(party.ExpiditionState == Expedition.State.Arriving);
                }
            });

            SoundManager.PlaySound(ContentPaths.Audio.Oscar.sfx_gui_negative_generic, 0.15f);

            foreach (var creature in creatures)
            {
                if (Economy == null)
                {
                    Economy = new Company(this, (decimal)MathFunctions.Rand(1000, 9999), null);
                }

                if (Economy.Information == null)
                {
                    Economy.Information = new CompanyInformation();
                }

                creature.Physics.AddChild(new Flag(World.ComponentManager, Vector3.Up * 0.5f + Vector3.Backward * 0.25f, Economy.Information));
            }
            return(party);
        }
Esempio n. 4
0
        public void Update(DwarfTime time, DateTime currentDate)
        {
            foreach (var mypolitics in FactionPolitics)
            {
                Pair <string> pair = mypolitics.Key;
                if (!pair.IsSelfPair() && pair.Contains(PlayState.PlayerFaction.Name))
                {
                    Faction otherFaction = null;

                    otherFaction = pair.First.Equals(PlayState.PlayerFaction.Name) ? Factions.Factions[pair.Second] : Factions.Factions[pair.First];
                    UpdateTradeEnvoys(otherFaction);
                    UpdateWarParties(otherFaction);
                    Race     race     = otherFaction.Race;
                    Politics relation = mypolitics.Value;


                    if (race.IsIntelligent && !otherFaction.IsRaceFaction &&
                        relation.GetCurrentRelationship() != Relationship.Hateful)
                    {
                        if (otherFaction.TradeEnvoys.Count == 0 && !relation.TradePartyTimer.HasTriggered)
                        {
                            relation.TradePartyTimer.Update(currentDate);

                            if (relation.TradePartyTimer.HasTriggered)
                            {
                                SendTradeEnvoy(otherFaction);
                            }
                        }
                        else if (otherFaction.TradeEnvoys.Count == 0)
                        {
                            relation.DispatchNewTradeEnvoy();
                        }
                    }
                    else if (race.IsIntelligent && !otherFaction.IsRaceFaction &&
                             relation.GetCurrentRelationship() == Relationship.Hateful)
                    {
                        if (otherFaction.WarParties.Count == 0 && !relation.WarPartyTimer.HasTriggered)
                        {
                            relation.WarPartyTimer.Update(currentDate);

                            if (relation.WarPartyTimer.HasTriggered)
                            {
                                SendWarParty(otherFaction);
                            }
                        }
                        else if (otherFaction.WarParties.Count == 0)
                        {
                            relation.DispatchNewWarParty();
                        }
                    }
                }
                mypolitics.Value.UpdateEvents(currentDate);
            }
        }
Esempio n. 5
0
        public void SendWarParty(Faction natives)
        {
            // todo
            PlayState.AnnouncementManager.Announce(Drawer2D.WrapColor("War party from " + natives.Name + " has arrived!", Color.DarkRed), "");
            Politics politics = GetPolitics(natives, PlayState.PlayerFaction);

            politics.WasAtWar = true;
            List <CreatureAI> creatures = PlayState.MonsterSpawner.Spawn(PlayState.MonsterSpawner.GenerateSpawnEvent(natives, PlayState.PlayerFaction, PlayState.Random.Next(5) + 1, true));

            natives.WarParties.Add(new Faction.WarParty()
            {
                Creatures    = creatures,
                OtherFaction = PlayState.PlayerFaction,
                ShouldRemove = false
            });
        }
Esempio n. 6
0
        public void SendWarParty(Faction natives)
        {
            // todo
            natives.World.MakeAnnouncement(String.Format("War party from {0} has arrived!", natives.Name), null);
            Politics politics = GetPolitics(natives, natives.World.PlayerFaction);

            politics.WasAtWar = true;
            List <CreatureAI> creatures = natives.World.MonsterSpawner.Spawn(natives.World.MonsterSpawner.GenerateSpawnEvent(natives, natives.World.PlayerFaction, MathFunctions.Random.Next(5) + 1, true));

            natives.WarParties.Add(new Faction.WarParty(natives.World.Time.CurrentDate)
            {
                Creatures    = creatures,
                OtherFaction = natives.World.PlayerFaction,
                ShouldRemove = false
            });
        }
Esempio n. 7
0
 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>()
     });
 }
Esempio n. 8
0
        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);
        }
Esempio n. 9
0
        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;
        }
Esempio n. 10
0
        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
            });
        }
Esempio n. 11
0
        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;
                    }
                }
            }
        }
Esempio n. 12
0
        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);
            }
        }
Esempio n. 13
0
        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;
                    }
                }
            }
        }
Esempio n. 14
0
        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;
                    }
                }
            }
        }
Esempio n. 15
0
        public void Update(DwarfTime time, DateTime currentDate, WorldManager world)
        {
            World = world;
#if UPTIME_TEST
            return;
#endif
            var timeSinceLastTrade = world.Time.CurrentDate - TimeOfLastTrade;
            foreach (var mypolitics in FactionPolitics)
            {
                Pair <string> pair = mypolitics.Key;
                if (!pair.IsSelfPair() && pair.Contains(world.PlayerFaction.Name))
                {
                    Faction otherFaction = null;

                    otherFaction = pair.First.Equals(world.PlayerFaction.Name) ? Factions.Factions[pair.Second] : Factions.Factions[pair.First];
                    UpdateTradeEnvoys(otherFaction);
                    UpdateWarParties(otherFaction);
                    Politics relation = mypolitics.Value;

                    bool needsNewTradeEnvoy = true;

                    if (CurrentTradeEnvoy != null)
                    {
                        needsNewTradeEnvoy = CurrentTradeEnvoy.Creatures.Count == 0 ||
                                             CurrentTradeEnvoy.Creatures.All(creature => creature.IsDead);
                    }

                    if (needsNewTradeEnvoy)
                    {
                        CurrentTradeEnvoy = null;
                    }

                    bool needsNewWarparty = true;

                    if (CurrentWarParty != null)
                    {
                        needsNewWarparty = CurrentWarParty.Creatures.Count == 0 ||
                                           CurrentWarParty.Creatures.All(creature => creature.IsDead);
                    }

                    if (needsNewWarparty)
                    {
                        CurrentWarParty = null;
                    }


                    if (needsNewTradeEnvoy && otherFaction.Race.IsIntelligent && !otherFaction.IsRaceFaction &&
                        relation.GetCurrentRelationship() != Relationship.Hateful)
                    {
                        if (otherFaction.TradeEnvoys.Count == 0)
                        {
                            relation.TradePartyTimer.Update(currentDate);

                            if (relation.TradePartyTimer.HasTriggered && timeSinceLastTrade.TotalDays > 1.0 && LastTradeEmpire != otherFaction.Name)
                            {
                                relation.TradePartyTimer.Reset(World.Time.CurrentDate);
                                CurrentTradeEnvoy = SendTradeEnvoy(otherFaction, world);
                                TimeOfLastTrade   = world.Time.CurrentDate;
                                LastTradeEmpire   = otherFaction.Name;
                            }
                        }
                        else if (otherFaction.TradeEnvoys.Count == 0)
                        {
                            relation.DispatchNewTradeEnvoy(world.Time.CurrentDate);
                        }
                    }
                    else if (needsNewWarparty &&
                             otherFaction.Race.IsIntelligent && !otherFaction.IsRaceFaction &&
                             relation.GetCurrentRelationship() == Relationship.Hateful)
                    {
                        if (otherFaction.WarParties.Count == 0 && !relation.WarPartyTimer.HasTriggered)
                        {
                            relation.WarPartyTimer.Update(currentDate);

                            if (relation.WarPartyTimer.HasTriggered)
                            {
                                CurrentWarParty = SendWarParty(otherFaction);
                            }
                        }
                        else if (otherFaction.WarParties.Count == 0)
                        {
                            relation.DispatchNewWarParty(world.Time.CurrentDate);
                        }
                    }
                }
                mypolitics.Value.UpdateEvents(currentDate);
            }
        }