Esempio n. 1
0
 public TradeTask(Zone tradePort, TradeEnvoy envoy)
 {
     Name      = "Trade";
     Priority  = PriorityType.High;
     TradePort = tradePort;
     Envoy     = envoy;
 }
Esempio n. 2
0
        public void BeginTrade(TradeEnvoy Envoy, Faction PlayerFaction)
        {
            PlayerFaction.World.Tutorial("trade_screen");
            TradePanel = GuiRoot.ConstructWidget(new Gui.Widgets.TradePanel
            {
                Rect   = GuiRoot.RenderData.VirtualScreen,
                Envoy  = Envoy.OwnerFaction.ParentFaction.CreateTradeEntity(Envoy),
                Player = new Trade.PlayerTradeEntity(PlayerFaction),
            }) as Gui.Widgets.TradePanel;

            TradePanel.Layout();

            GuiRoot.ShowDialog(TradePanel);
            GuiRoot.RootItem.SendToBack(TradePanel);

            AutoHideBubble = true;

            SpeakerBorder.Rect = new Rectangle(16, GuiRoot.RenderData.VirtualScreen.Height - (256 - 16), 256 - 32, 256 - 32);
            SpeakerRectangle   = Gui.Mesh.Quad().Scale(256, 256).Translate(0, GuiRoot.RenderData.VirtualScreen.Height - 256);
            _Output.Rect       = new Rectangle(256, GuiRoot.RenderData.VirtualScreen.Height - 260, global::System.Math.Min(GuiRoot.RenderData.VirtualScreen.Width - 256, 550), 260);

            SpeakerBorder.Invalidate();
            _Output.Invalidate();
            GuiRoot.RootItem.Invalidate();
        }
Esempio n. 3
0
        public void BeginMarket(TradeEnvoy Envoy, Faction PlayerFaction)
        {
            PlayerFaction.World.Tutorial("market_screen");
            MarketPanel = GuiRoot.ConstructWidget(new Gui.Widgets.MarketPanel
            {
                Rect   = GuiRoot.RenderData.VirtualScreen,
                Player = new Trade.PlayerTradeEntity(PlayerFaction),
            }) as Gui.Widgets.MarketPanel;

            MarketPanel.Layout();

            GuiRoot.ShowDialog(MarketPanel);
            GuiRoot.RootItem.SendToBack(MarketPanel);

            AutoHideBubble = true;

            SpeakerBorder.Rect = new Rectangle(16, GuiRoot.RenderData.VirtualScreen.Height - (256 - 16), 256 - 32, 256 - 32);
            SpeakerRectangle.EntireMeshAsPart()
            .ResetQuad()
            .Scale(256, 256).Translate(0, GuiRoot.RenderData.VirtualScreen.Height - 256);
            _Output.Rect = new Rectangle(256, GuiRoot.RenderData.VirtualScreen.Height - 260, global::System.Math.Min(GuiRoot.RenderData.VirtualScreen.Width - 256, 550), 260);

            SpeakerBorder.Invalidate();
            _Output.Invalidate();
            GuiRoot.RootItem.Invalidate();
        }
Esempio n. 4
0
 public static void RecallEnvoy(TradeEnvoy envoy)
 {
     // TODO: do ths more naturally
     envoy.ExpiditionState = Expedition.State.Leaving;
     foreach (CreatureAI creature in envoy.Creatures)
     {
         creature.LeaveWorld();
     }
 }
Esempio n. 5
0
 public void RecallEnvoy(TradeEnvoy envoy)
 {
     // TODO: do ths more naturally
     envoy.ShouldRemove = true;
     foreach (CreatureAI creature in envoy.Creatures)
     {
         creature.GetRootComponent().Delete();
     }
 }
Esempio n. 6
0
 public Trade.ITradeEntity CreateTradeEntity(TradeEnvoy Envoy)
 {
     if (IsCorporate)
     {
         return(new Trade.CorporateTradeEntity(Envoy));
     }
     else
     {
         return(new Trade.EnvoyTradeEntity(Envoy));
     }
 }
Esempio n. 7
0
        public TradeEnvoy SendTradeEnvoy()
        {
            if (!World.EnumerateZones().Any(room => room is BalloonPort && room.IsBuilt))
            {
                World.MakeAnnouncement(String.Format("Trade envoy from {0} left: No balloon port!", ParentFaction.Name));
                SoundManager.PlaySound(ContentPaths.Audio.Oscar.sfx_gui_negative_generic, 0.15f);
                return(null);
            }

            TradeEnvoy envoy = null;

            var creatures = World.MonsterSpawner.Spawn(World.MonsterSpawner.GenerateSpawnEvent(this, World.PlayerFaction, MathFunctions.Random.Next(4) + 1, false));

            envoy = new TradeEnvoy(World.Time.CurrentDate)
            {
                Creatures    = creatures,
                OtherFaction = World.PlayerFaction,
                ShouldRemove = false,
                OwnerFaction = this,
                TradeGoods   = Race.GenerateTradeItems(World),
                TradeMoney   = new DwarfBux((decimal)MathFunctions.Rand(150.0f, 550.0f))
            };

            if (Race.IsNative)
            {
                if (Economy == null)
                {
                    Economy = new Company(this, 1000.0m, new CompanyInformation()
                    {
                        Name = ParentFaction.Name
                    });
                }

                foreach (CreatureAI creature in envoy.Creatures)
                {
                    creature.Physics.AddChild(new ResourcePack(World.ComponentManager));
                    creature.Physics.AddChild(new Flag(World.ComponentManager, Vector3.Up * 0.5f + Vector3.Backward * 0.25f, Economy.Information));
                }
            }
            else
            {
                GameComponent balloon = null;

                var rooms = World.EnumerateZones().Where(room => room.Type.Name == "Balloon Port").ToList();

                if (rooms.Count != 0)
                {
                    Vector3 pos = rooms.First().GetBoundingBox().Center();
                    balloon = Balloon.CreateBalloon(pos + new Vector3(0, 1000, 0), pos + Vector3.UnitY * 15, World.ComponentManager, this);
                }

                if (balloon != null)
                {
                    foreach (CreatureAI creature in creatures)
                    {
                        Matrix tf = creature.Physics.LocalTransform;
                        tf.Translation = balloon.LocalTransform.Translation;
                        creature.Physics.LocalTransform = tf;
                    }
                }
                else
                {
                    if (Economy == null)
                    {
                        Economy = new Company(this, 1000.0m, new CompanyInformation()
                        {
                            Name = ParentFaction.Name
                        });
                    }

                    foreach (CreatureAI creature in envoy.Creatures)
                    {
                        creature.Physics.AddChild(new ResourcePack(World.ComponentManager));
                        creature.Physics.AddChild(new Flag(World.ComponentManager, Vector3.Up * 0.5f + Vector3.Backward * 0.25f, Economy.Information));
                    }
                }
            }

            foreach (CreatureAI creature in envoy.Creatures)
            {
                creature.Physics.AddChild(new ResourcePack(World.ComponentManager));
            }

            envoy.DistributeGoods();
            TradeEnvoys.Add(envoy);

            World.MakeAnnouncement(new DwarfCorp.Gui.Widgets.QueuedAnnouncement
            {
                Text        = String.Format("Trade envoy from {0} has arrived!", ParentFaction.Name),
                ClickAction = (gui, sender) =>
                {
                    if (envoy.Creatures.Count > 0)
                    {
                        envoy.Creatures.First().ZoomToMe();
                        World.UserInterface.MakeWorldPopup(String.Format("Traders from {0} ({1}) have entered our territory.\nThey will try to get to our balloon port to trade with us.", ParentFaction.Name, Race.Name),
                                                           envoy.Creatures.First().Physics, -10);
                    }
                },
                ShouldKeep = () =>
                {
                    return(envoy.ExpiditionState == Expedition.State.Arriving);
                }
            });

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

            World.Tutorial("trade");
            if (!String.IsNullOrEmpty(Race.TradeMusic))
            {
                SoundManager.PlayMusic(Race.TradeMusic);
            }

            return(envoy);
        }
Esempio n. 8
0
        public void UpdateTradeEnvoys(Faction faction)
        {
            foreach (TradeEnvoy envoy in faction.TradeEnvoys)
            {
                if (envoy.ExpiditionState == Expedition.State.Trading)
                {
                    if (envoy.UpdateWaitTimer(World.Time.CurrentDate))
                    {
                        World.MakeAnnouncement(String.Format("The envoy from {0} is leaving.", envoy.OwnerFaction.Name));
                        RecallEnvoy(envoy);
                    }
                }

                envoy.Creatures.RemoveAll(creature => creature.IsDead);
                if (envoy.DeathTimer.Update(faction.World.Time.CurrentDate))
                {
                    envoy.Creatures.ForEach((creature) => creature.GetRoot().Die());
                }

                Diplomacy.Politics politics = faction.World.Diplomacy.GetPolitics(faction, envoy.OtherFaction);
                if (politics.GetCurrentRelationship() == Relationship.Hateful)
                {
                    World.MakeAnnouncement(String.Format("The envoy from {0} is leaving.", envoy.OwnerFaction.Name));
                    RecallEnvoy(envoy);
                }
                else
                {
                    if (envoy.Creatures.Any(
                            // TODO (mklingen) why do I need this null check?
                            creature => creature.Creature != null &&
                            envoy.OtherFaction.Designations.IsDesignation(creature.Physics, DesignationType.Attack)))
                    {
                        if (!politics.HasEvent("You attacked our trade delegates"))
                        {
                            politics.RecentEvents.Add(new Diplomacy.PoliticalEvent()
                            {
                                Change      = -1.0f,
                                Description = "You attacked our trade delegates",
                                Duration    = new TimeSpan(1, 0, 0, 0),
                                Time        = faction.World.Time.CurrentDate
                            });
                        }
                        else
                        {
                            politics.RecentEvents.Add(new Diplomacy.PoliticalEvent()
                            {
                                Change      = -2.0f,
                                Description = "You attacked our trade delegates more than once",
                                Duration    = new TimeSpan(1, 0, 0, 0),
                                Time        = faction.World.Time.CurrentDate
                            });
                        }
                    }
                }

                if (!envoy.ShouldRemove && envoy.ExpiditionState == Expedition.State.Arriving)
                {
                    foreach (CreatureAI creature in envoy.Creatures)
                    {
                        Room tradePort = envoy.OtherFaction.GetNearestRoomOfType(BalloonPort.BalloonPortName,
                                                                                 creature.Position);

                        if (tradePort == null)
                        {
                            World.MakeAnnouncement("We need a balloon trade port to trade.", null, () =>
                            {
                                return(envoy.OtherFaction.GetNearestRoomOfType(BalloonPort.BalloonPortName, creature.Position) == null);
                            });
                            World.Tutorial("trade");
                            SoundManager.PlaySound(ContentPaths.Audio.Oscar.sfx_gui_negative_generic, 0.5f);
                            RecallEnvoy(envoy);
                            break;
                        }

                        if (creature.Tasks.Count == 0)
                        {
                            TradeEnvoy envoy1 = envoy;
                            creature.Tasks.Add(new TradeTask(tradePort, envoy1));
                        }

                        if (!tradePort.IsRestingOnZone(creature.Position))
                        {
                            continue;
                        }

                        if (envoy.ExpiditionState != Expedition.State.Trading ||
                            !envoy.IsTradeWidgetValid())
                        {
                            envoy.MakeTradeWidget(World);
                        }
                        envoy.ExpiditionState = Expedition.State.Trading;
                        break;
                    }
                }
                else if (envoy.ExpiditionState == Expedition.State.Leaving)
                {
                    BoundingBox worldBBox = faction.World.ChunkManager.Bounds;

                    foreach (CreatureAI creature in envoy.Creatures)
                    {
                        if (creature.Tasks.Count == 0)
                        {
                            creature.LeaveWorld();
                        }
                    }

                    foreach (CreatureAI creature in envoy.Creatures)
                    {
                        if (MathFunctions.Dist2D(worldBBox, creature.Position) < 2.0f)
                        {
                            creature.GetRoot().Delete();
                        }
                    }
                }
                else
                {
                    if (!envoy.IsTradeWidgetValid())
                    {
                        envoy.MakeTradeWidget(World);
                    }
                }
                if (envoy.Creatures.All(creature => creature.IsDead))
                {
                    envoy.ShouldRemove = true;

                    World.GoalManager.OnGameEvent(new Goals.Triggers.TradeEnvoyKilled
                    {
                        PlayerFaction = envoy.OtherFaction,
                        OtherFaction  = envoy.OwnerFaction
                    });
                }
            }

            bool hadFactions = faction.TradeEnvoys.Count > 0;

            faction.TradeEnvoys.RemoveAll(t => t == null || t.ShouldRemove);

            if (hadFactions && faction.TradeEnvoys.Count == 0)
            {
                var music = World.Time.IsDay() ? "main_theme_day" : "main_theme_night";
                SoundManager.PlayMusic(music);
            }
        }
Esempio n. 9
0
 IEnumerable <Act.Status> RecallEnvoyOnFail(TradeEnvoy envoy)
 {
     Diplomacy.RecallEnvoy(envoy);
     TradePort.Faction.World.MakeAnnouncement("Envoy from " + envoy.OwnerFaction.Name + " left. Trade port inaccessible.");
     yield return(Act.Status.Success);
 }
Esempio n. 10
0
        public TradeEnvoy SendTradeEnvoy(Faction natives, WorldManager world)
        {
            if (!world.PlayerFaction.GetRooms().Any(room => room is BalloonPort && room.IsBuilt))
            {
                world.MakeAnnouncement(String.Format("Trade envoy from {0} left. No balloon port!", natives.Name));
                SoundManager.PlaySound(ContentPaths.Audio.Oscar.sfx_gui_negative_generic, 0.15f);
                return(null);
            }
            TradeEnvoy envoy = null;

            List <CreatureAI> creatures =
                world.MonsterSpawner.Spawn(world.MonsterSpawner.GenerateSpawnEvent(natives,
                                                                                   world.PlayerFaction, MathFunctions.Random.Next(4) + 1, false));

            if (natives.TradeMoney < 100m)
            {
                natives.TradeMoney += MathFunctions.Rand(250.0f, 5000.0f);
            }

            envoy = new TradeEnvoy(world.Time.CurrentDate)
            {
                Creatures    = creatures,
                OtherFaction = world.PlayerFaction,
                ShouldRemove = false,
                OwnerFaction = natives,
                TradeGoods   = natives.Race.GenerateResources(world),
                TradeMoney   = natives.TradeMoney
            };

            if (natives.Race.IsNative)
            {
                if (natives.Economy == null)
                {
                    natives.Economy = new Economy(natives, 1000.0m, World, new CompanyInformation()
                    {
                        Name = natives.Name
                    });
                }

                foreach (CreatureAI creature in envoy.Creatures)
                {
                    creature.Physics.AddChild(new ResourcePack(World.ComponentManager));
                    if (natives.Economy == null)
                    {
                        natives.Economy = new Economy(natives, 1000.0m, World, new CompanyInformation()
                        {
                            Name = natives.Name
                        });
                    }

                    creature.Physics.AddChild(new Flag(World.ComponentManager, Vector3.Up * 0.5f + Vector3.Backward * 0.25f, natives.Economy.Company.Information));
                }
            }
            else
            {
                Body balloon = world.PlayerFaction.DispatchBalloon();

                foreach (CreatureAI creature in creatures)
                {
                    Matrix tf = creature.Physics.LocalTransform;
                    tf.Translation = balloon.LocalTransform.Translation;
                    creature.Physics.LocalTransform = tf;
                }
            }

            foreach (CreatureAI creature in envoy.Creatures)
            {
                creature.Physics.AddChild(new ResourcePack(World.ComponentManager));
            }

            envoy.DistributeGoods();
            natives.TradeEnvoys.Add(envoy);
            world.MakeAnnouncement(new DwarfCorp.Gui.Widgets.QueuedAnnouncement
            {
                Text        = String.Format("Trade envoy from {0} has arrived!", natives.Name),
                ClickAction = (gui, sender) =>
                {
                    if (envoy.Creatures.Count > 0)
                    {
                        envoy.Creatures.First().ZoomToMe();
                        World.MakeWorldPopup(String.Format("Traders from {0} ({1}) have entered our territory. They will try to get to our balloon port to trade with us.", natives.Name, natives.Race.Name),
                                             envoy.Creatures.First().Physics, -10);
                    }
                },
                ShouldKeep = () =>
                {
                    return(envoy.ExpiditionState == Expedition.State.Arriving);
                }
            });

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


            world.Tutorial("trade");
            if (!String.IsNullOrEmpty(natives.Race.TradeMusic))
            {
                SoundManager.PlayMusic(natives.Race.TradeMusic);
            }

            return(envoy);
        }
Esempio n. 11
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);
            }
        }