Esempio n. 1
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. 2
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);
            }
        }