Пример #1
0
        public static bool CanCatch(WorldManager World, GameComponent Animal, bool Print)
        {
            if (Animal.GetRoot().GetComponent <Creature>().HasValue(out var creature))
            {
                if (!Animal.GetRoot().Tags.Contains("DomesticAnimal"))
                {
                    return(false);
                }

                var pens = World.EnumerateZones().Where(room => room is AnimalPen).Cast <AnimalPen>().Where(pen => pen.IsBuilt && pen.CanHold(creature.Stats.SpeciesName));

                if (pens.Any())
                {
                    if (Print)
                    {
                        World.UserInterface.ShowTooltip("Will wrangle this " + creature.Stats.SpeciesName);
                    }
                    return(true);
                }
                else
                {
                    if (Print)
                    {
                        World.UserInterface.ShowTooltip("Can't wrangle this " + creature.Stats.SpeciesName + " : need more animal pens.");
                    }
                }
            }

            return(false);
        }
Пример #2
0
        public void MakeTradeWidget(WorldManager World)
        {
            var liveCreatures = Creatures.Where(creature => creature != null && !creature.IsDead);

            if (!liveCreatures.Any())
            {
                return;
            }

            var zones = World.EnumerateZones().OfType <BalloonPort>();

            CreatureAI closestCreature = null;
            float      closestDist     = float.MaxValue;

            if (zones.Any())
            {
                var zoneCenter = zones.First().GetBoundingBox().Center();
                foreach (var creature in liveCreatures)
                {
                    float dist = (creature.Position - zoneCenter).LengthSquared();
                    if (dist < closestDist)
                    {
                        closestDist     = dist;
                        closestCreature = creature;
                    }
                }
            }
            else
            {
                closestCreature = liveCreatures.First();
            }

            TradeWidget = World.UserInterface.MakeWorldPopup(new Events.TimedIndicatorWidget()
            {
                Text    = string.Format("Click here to trade with the {0}!", OwnerFaction.Race.Name),
                OnClick = (gui, sender) =>
                {
                    OpenDiplomacyConversation(World);
                },
                ShouldKeep = () => { return(this.ExpiditionState == Expedition.State.Trading && !this.ShouldRemove); }
            }, closestCreature.Physics, new Vector2(0, -10));
            World.MakeAnnouncement(String.Format("Click here to trade with the {0}!", OwnerFaction.Race.Name), (gui, sender) =>
            {
                OpenDiplomacyConversation(World);
            }, () => { return(this.ExpiditionState == Expedition.State.Trading && !this.ShouldRemove); }, false);
            SoundManager.PlaySound(ContentPaths.Audio.Oscar.sfx_gui_positive_generic, 0.15f);
        }
Пример #3
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);
        }
Пример #4
0
        public bool CanBuildHere(List <VoxelHandle> Voxels, WorldManager World)
        {
            if (Voxels.Count == 0)
            {
                return(false);
            }

            if (World.EnumerateZones().Where(room => room.Type.Name == this.Name).Count() + 1 > MaxNumRooms)
            {
                World.UserInterface.ShowTooltip(String.Format("We can only build {0} {1}. Destroy the existing to build a new one.", MaxNumRooms, Name));
                return(false);
            }

            if (Voxels.Any(v => World.PersistentData.Designations.GetVoxelDesignation(v, DesignationType._All).HasValue(out var _)))
            {
                World.UserInterface.ShowTooltip("Something else is designated for this area.");
                return(false);
            }

            List <BoundingBox> boxes = Voxels.Select(voxel => voxel.GetBoundingBox()).ToList();
            BoundingBox        box   = MathFunctions.GetBoundingBox(boxes);

            Vector3 extents = box.Max - box.Min;

            float maxExtents = Math.Max(extents.X, extents.Z);
            float minExtents = Math.Min(extents.X, extents.Z);

            if (maxExtents < MinimumSideLength || minExtents < MinimumSideWidth)
            {
                World.UserInterface.ShowTooltip("Room is too small (minimum is " + MinimumSideLength + " x " + MinimumSideWidth + ")!");
                return(false);
            }

            int height = Voxels[0].Coordinate.Y;

            foreach (var voxel in Voxels)
            {
                if (voxel.IsEmpty)
                {
                    World.UserInterface.ShowTooltip("Room must be built on solid ground.");
                    return(false);
                }

                var above = VoxelHelpers.GetVoxelAbove(voxel);

                if (above.IsValid && !above.IsEmpty)
                {
                    World.UserInterface.ShowTooltip("Room must be built in free space.");
                    return(false);
                }

                if (voxel.Type.IsInvincible)
                {
                    continue;
                }

                if (height != (int)voxel.Coordinate.Y)
                {
                    World.UserInterface.ShowTooltip("Room must be on flat ground!");
                    return(false);
                }

                if (!CanBuildAboveGround && voxel.Sunlight)
                {
                    World.UserInterface.ShowTooltip("Room can't be built aboveground!");
                    return(false);
                }

                if (!CanBuildBelowGround && !voxel.Sunlight)
                {
                    World.UserInterface.ShowTooltip("Room can't be built belowground!");
                    return(false);
                }

                if (World.IsInZone(voxel) || World.IsBuildDesignation(voxel))
                {
                    World.UserInterface.ShowTooltip("Room's can't overlap!");
                    return(false);
                }
            }

            return(true);
        }