コード例 #1
0
ファイル: Diplomacy.cs プロジェクト: Solsund/dwarfcorp
        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);
            }
        }
コード例 #2
0
ファイル: Diplomacy.cs プロジェクト: jeason1997/dwarfcorp
        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);
            }
        }
コード例 #3
0
ファイル: Diplomacy.cs プロジェクト: Solsund/dwarfcorp
        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;
                    }
                }
            }
        }
コード例 #4
0
ファイル: Diplomacy.cs プロジェクト: jeason1997/dwarfcorp
        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>(),
                    };

                    politics.DispatchNewTradeEnvoy(Now);

                    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
                            });
                        }
                    }

                    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
            });
        }