private void UpdatePregnancy() { if (IsPregnant && World.Time.CurrentDate > CurrentPregnancy.EndDate) { if (!_speciesCounts.ContainsKey(Species) || _speciesCounts[Species] < _maxPerSpecies) { if (EntityFactory.HasEntity(BabyType)) { var baby = EntityFactory.CreateEntity <GameComponent>(BabyType, Physics.Position); baby.GetRoot().GetComponent <CreatureAI>().PositionConstraint = AI.PositionConstraint; } } CurrentPregnancy = null; } }
public bool RemoveResourcesWithToss(ResourceAmount resources, Vector3 position, Zone Zone) // Todo: Kill this one. { if (!Zone.Resources.HasResource(resources)) { return(false); } if (!(Zone is Stockpile)) { return(false); } var stock = Zone as Stockpile; // Todo: Stockpile deals with it's own boxes. var resourceType = Library.GetResourceType(resources.Type); var num = stock.Resources.RemoveMaxResources(resources, resources.Count); stock.HandleBoxes(); foreach (var tag in resourceType.Tags) { if (PersistentData.CachedResourceTagCounts.ContainsKey(tag)) // Move cache into worldmanager... { PersistentData.CachedResourceTagCounts[tag] -= num; Trace.Assert(PersistentData.CachedResourceTagCounts[tag] >= 0); } } for (int i = 0; i < num; i++) { // Make a toss from the last crate to the agent. var startPosition = stock.Voxels.First().Center + new Vector3(0.0f, 1.0f, 0.0f); if (stock.Boxes.Count > 0) { startPosition = stock.Boxes.Last().Position + MathFunctions.RandVector3Cube() * 0.5f; } GameComponent newEntity = EntityFactory.CreateEntity <GameComponent>(resources.Type + " Resource", startPosition); TossMotion toss = new TossMotion(1.0f + MathFunctions.Rand(0.1f, 0.2f), 2.5f + MathFunctions.Rand(-0.5f, 0.5f), newEntity.LocalTransform, position); newEntity.GetRoot().GetComponent <Physics>().CollideMode = Physics.CollisionMode.None; newEntity.AnimationQueue.Add(toss); toss.OnComplete += () => newEntity.Die(); } RecomputeCachedVoxelstate(); return(true); }
/// <summary> /// Kills the creature and releases its resources. /// </summary> public override void Die() { // This is just a silly hack to make sure that creatures // carrying resources to a trade depot release their resources // when they die. CreateMeatAndBones(); NoiseMaker.MakeNoise("Die", Physics.Position, true); if (AI.Status.Money > 0) { EntityFactory.CreateEntity <CoinPile>("Coins Resource", AI.Position, Blackboard.Create("Money", AI.Status.Money)); } base.Die(); }
public void LayEgg() { NoiseMaker.MakeNoise("Lay Egg", AI.Position, true, 1.0f); // Todo: Egg resource type and the baby made need to be in the species. if (!Library.DoesResourceTypeExist(Stats.CurrentClass.Name + " Egg") || !EntityFactory.EnumerateEntityTypes().Contains(Stats.CurrentClass.Name + " Egg Resource")) { var newEggResource = Library.CreateResourceType(Library.GetResourceType("Egg")); newEggResource.Name = Stats.CurrentClass.Name + " Egg"; Library.AddResourceType(newEggResource); } var parent = EntityFactory.CreateEntity <GameComponent>(Stats.CurrentClass.Name + " Egg Resource", Physics.Position); parent.AddChild(new Egg(parent, Stats.Species.BabyType, Manager, Physics.Position, AI.PositionConstraint)); }
public void CreateCoins(Vector3 pos) { Vector3 startPos = pos + new Vector3(0.5f, -0.1f, 0.5f); Vector3 endPos = pos + new Vector3(0.5f, 1.5f, 0.5f); Body coins = EntityFactory.CreateEntity <Body>("Coins", startPos); coins.AnimationQueue.Add(new EaseMotion(0.8f, coins.LocalTransform, endPos)); Coins.Add(coins); AddBody(coins, false); SoundManager.PlaySound(ContentPaths.Audio.Oscar.sfx_ic_dwarf_stash_money, startPos); if (Faction != null) { Faction.World.ParticleManager.Trigger("puff", pos + new Vector3(0.5f, 1.5f, 0.5f), Color.White, 90); } }
public override IEnumerable <Status> Run() { Body item = EntityFactory.CreateEntity <Body>(CraftLibrary.CraftItems[ItemType].Name, Voxel.Position + Vector3.One * 0.5f); PlayState.ParticleManager.Trigger("puff", Voxel.Position + Vector3.One * 0.5f, Color.White, 10); if (item == null) { yield return(Status.Fail); } else { Creature.Faction.CraftBuilder.RemoveDesignation(Voxel); Creature.AI.AddXP(10); yield return(Status.Success); } }
private GameComponent CreatePreviewBody() { Blackboard blackboard = new Blackboard(); blackboard.SetData <Resource>("Resource", new Resource(CraftType)); var previewBody = EntityFactory.CreateEntity <GameComponent>( CraftType.Placement_EntityToCreate, World.UserInterface.VoxSelector.VoxelUnderMouse.WorldPosition, blackboard).GetRoot() as GameComponent; previewBody.SetFlagRecursive(GameComponent.Flag.Active, false); previewBody.SetVertexColorRecursive(Color.White); previewBody.SetFlag(GameComponent.Flag.ShouldSerialize, false); return(previewBody); }
public void LayEgg() { NoiseMaker.MakeNoise("Lay Egg", AI.Position, true, 1.0f); if (ResourceLibrary.GetResourceByName(Species + " Egg") == null || !EntityFactory.EnumerateEntityTypes().Contains(Species + " Egg Resource")) { Resource newEggResource = new Resource(ResourceLibrary.GetResourceByName(ResourceType.Egg)); newEggResource.Name = Species + " Egg"; ResourceLibrary.Add(newEggResource); } var parent = EntityFactory.CreateEntity <Body>(this.Species + " Egg Resource", Physics.Position); parent.AddChild(new Egg(parent, this.Species, Manager, Physics.Position, AI.PositionConstraint)); }
private void UpdatePregnancy() { if (IsPregnant && World.Time.CurrentDate > CurrentPregnancy.EndDate) { // Todo: This check really belongs before the creature becomes pregnant. if (World.GetSpeciesPopulation(Stats.CurrentClass) < Stats.Species.SpeciesLimit) { if (EntityFactory.HasEntity(Stats.Species.BabyType)) { var baby = EntityFactory.CreateEntity <GameComponent>(Stats.Species.BabyType, Physics.Position); baby.GetRoot().GetComponent <CreatureAI>().PositionConstraint = AI.PositionConstraint; } } CurrentPregnancy = null; } }
public void CreateBox(Vector3 pos) { Vector3 startPos = pos + new Vector3(0.0f, -0.1f, 0.0f) + BoxOffset; Vector3 endPos = pos + new Vector3(0.0f, 0.9f, 0.0f) + BoxOffset; Body crate = EntityFactory.CreateEntity <Body>(BoxType, startPos); crate.AnimationQueue.Add(new EaseMotion(0.8f, crate.LocalTransform, endPos)); Boxes.Add(crate); AddBody(crate, false); SoundManager.PlaySound(ContentPaths.Audio.whoosh, startPos); if (Faction != null) { Faction.World.ParticleManager.Trigger("puff", pos + new Vector3(0.5f, 1.5f, 0.5f), Color.White, 90); } }
public void Update(DwarfTime gameTime, GameMaster player) { if (!IsEnabled) { if (CurrentCraftBody != null) { CurrentCraftBody.Delete(); CurrentCraftBody = null; } return; } if (Faction == null) { Faction = player.Faction; } if (CurrentCraftType != null && CurrentCraftBody == null) { CurrentCraftBody = EntityFactory.CreateEntity <Body>(CurrentCraftType.Name, player.VoxSelector.VoxelUnderMouse.Position); CurrentCraftBody.SetActiveRecursive(false); CurrentDesignation = new CraftDesignation() { ItemType = CurrentCraftType, Location = new Voxel(new Point3(0, 0, 0), null) }; SetDisplayColor(Color.Green); } if (CurrentCraftBody == null || player.VoxSelector.VoxelUnderMouse == null) { return; } CurrentCraftBody.LocalPosition = player.VoxSelector.VoxelUnderMouse.Position + Vector3.One * 0.5f; CurrentCraftBody.GlobalTransform = CurrentCraftBody.LocalTransform; CurrentCraftBody.OrientToWalls(); if (CurrentDesignation.Location.IsSameAs(player.VoxSelector.VoxelUnderMouse)) { return; } CurrentDesignation.Location = new Voxel(player.VoxSelector.VoxelUnderMouse); SetDisplayColor(IsValid(CurrentDesignation) ? Color.Green : Color.Red); }
public override void Destroy() { DwarfBux moneyLeft = Money; foreach (Body coinPile in Coins) { CoinPile coins = EntityFactory.CreateEntity <CoinPile>("Coins Resource", coinPile.Position); coins.Money = Math.Min(MoneyPerPile, moneyLeft); moneyLeft -= coins.Money; } Faction.Economy.CurrentMoney -= Money; if (Faction != null) { Faction.Treasurys.Remove(this); } base.Destroy(); }
public Egg(string adult, ComponentManager manager, Vector3 position) : base(false, manager) { Adult = adult; Birthday = Manager.World.Time.CurrentDate + new TimeSpan(0, 12, 0, 0); if (ResourceLibrary.GetResourceByName(adult + " Egg") == null) { Resource newEggResource = new Resource(ResourceLibrary.GetResourceByName(ResourceLibrary.ResourceType.Egg)); newEggResource.Type = adult + " Egg"; ResourceLibrary.Add(newEggResource); } ParentBody = EntityFactory.CreateEntity <Body>(adult + " Egg Resource", position); ParentBody.AddChild(this); manager.AddComponent(this); }
private IEnumerable <Status> FinallyPlaceObject() { Item.Finished = true; if (Item.WorkPile != null) { Item.WorkPile.Die(); } var blackboard = new Blackboard(); blackboard.SetData("Resource", Item.SelectedResource); var previewBody = EntityFactory.CreateEntity <GameComponent>( Item.ItemType.Placement_EntityToCreate, Item.Location.WorldPosition, blackboard).GetRoot(); previewBody.LocalTransform = Item.Entity.LocalTransform; previewBody.SetFlagRecursive(GameComponent.Flag.Active, true); previewBody.SetVertexColorRecursive(Color.White); previewBody.SetFlagRecursive(GameComponent.Flag.Visible, true); foreach (var tinter in previewBody.EnumerateAll().OfType <Tinter>()) { tinter.Stipple = false; } if (Item.ItemType.Placement_MarkDestructable) { previewBody.Tags.Add("Deconstructable"); } if (Item.ItemType.Placement_AddToOwnedPool) { Creature.Faction.OwnedObjects.Add(previewBody); } Creature.Manager.World.ParticleManager.Trigger("puff", Voxel.WorldPosition, Color.White, 10); Creature.AI.AddXP((int)(5 * (Item.ItemType.Placement_PlaceTime / Creature.AI.Stats.Intelligence))); Item.Entity.Delete(); yield return(Status.Success); }
public void CreateAdult() { SoundManager.PlaySound(ContentPaths.Audio.Oscar.sfx_env_plant_grow, Position, true); var adult = EntityFactory.CreateEntity <Plant>(AdultName, LocalPosition); adult.IsGrown = true; if (Farm != null) { adult.Farm = Farm; var task = new ChopEntityTask(adult) { Priority = Task.PriorityType.Low }; World.Master.TaskManager.AddTask(task); } Die(); }
public void CreatePlant(string SeedResourceType, WorldManager world) { PlantedType = SeedResourceType; Plant = EntityFactory.CreateEntity <Plant>(ResourceLibrary.Resources[SeedResourceType].PlantToGenerate, Voxel.WorldPosition + new Vector3(0.5f, 1.0f, 0.5f)); if (Plant is Seedling) { (Plant as Seedling).Farm = this; } Matrix original = Plant.LocalTransform; original.Translation += Vector3.Down; Plant.AnimationQueue.Add(new EaseMotion(0.5f, original, Plant.LocalTransform.Translation)); world.ParticleManager.Trigger("puff", original.Translation, Color.White, 20); SoundManager.PlaySound(ContentPaths.Audio.Oscar.sfx_env_plant_grow, Voxel.WorldPosition, true); }
public static Zone GenerateInitialBalloonPort(float x, float z, int size, Generation.ChunkGeneratorSettings Settings) { var roomVoxels = Generation.Generator.GenerateBalloonPort(Settings.World.ChunkManager, x, z, size, Settings); // Actually create the BuildRoom. var toBuild = Library.CreateZone("Balloon Port", Settings.World); Settings.World.AddZone(toBuild); toBuild.CompleteRoomImmediately(roomVoxels.StockpileVoxels); var box = toBuild.GetBoundingBox(); var at = new Vector3((box.Min.X + box.Max.X - 1) / 2, box.Max.Y, (box.Min.Z + box.Max.Z - 1) / 2); var flag = EntityFactory.CreateEntity <Flag>("Flag", at + new Vector3(0.5f, 0.5f, 0.5f)); Settings.World.PlayerFaction.OwnedObjects.Add(flag); return(toBuild); }
public override void Die() { var body = Parent.GetRoot().GetComponent <Body>(); if (body != null) { var bounds = body.GetBoundingBox(); foreach (var resource in Resources) { for (int i = 0; i < resource.NumResources; i++) { Vector3 pos = MathFunctions.RandVector3Box(bounds); EntityFactory.CreateEntity <Body>(resource.ResourceType + " Resource", pos); } } } base.Die(); }
public List <Body> RemoveAndCreate(ResourceAmount resources) { List <Body> toReturn = new List <Body>(); if (!Resources.RemoveResource(resources.CloneResource())) { return(toReturn); } for (int i = 0; i < resources.NumResources; i++) { Body newEntity = EntityFactory.CreateEntity <Body>(resources.ResourceType.ResourceName + " Resource", GlobalTransform.Translation + MathFunctions.RandVector3Cube() * 0.5f); toReturn.Add(newEntity); } return(toReturn); }
public override void Destroy() { BoundingBox box = GetBoundingBox(); foreach (ResourceAmount resource in Resources) { for (int i = 0; i < resource.NumResources; i++) { Physics body = EntityFactory.CreateEntity <Physics>(resource.ResourceType.Type + " Resource", Vector3.Up + MathFunctions.RandVector3Box(box)) as Physics; if (body != null) { body.Velocity = MathFunctions.RandVector3Cube(); } } } base.Destroy(); }
public override void Die() { if (!Active) { base.Die(); } List <Body> release = new List <Body>(); foreach (var resource in Resources) { if (MathFunctions.RandEvent(DropRate)) { const int maxIters = 10; for (int i = 0; i < maxIters; i++) { Vector3 pos = MathFunctions.RandVector3Box(GetBoundingBox()); var voxel = new VoxelHandle(World.ChunkManager.ChunkData, GlobalVoxelCoordinate.FromVector3(pos)); if ((!voxel.IsValid) || !voxel.IsEmpty) { continue; } Physics item = EntityFactory.CreateEntity <Physics>(resource.Resource + " Resource", pos) as Physics; if (item != null) { release.Add(item); item.Velocity = pos - GetBoundingBox().Center(); item.Velocity.Normalize(); item.Velocity *= 5.0f; item.IsSleeping = false; } break; } } } OnOnDeath(release); base.Die(); }
public void CreateBox(Vector3 pos) { //WorldManager.DoLazy(() => //{ Vector3 startPos = pos + new Vector3(0.0f, -0.1f, 0.0f) + BoxOffset; Vector3 endPos = pos + new Vector3(0.0f, 1.1f, 0.0f) + BoxOffset; GameComponent crate = EntityFactory.CreateEntity <GameComponent>(BoxType, startPos); crate.AnimationQueue.Add(new EaseMotion(0.8f, crate.LocalTransform, endPos)); Boxes.Add(crate); AddBody(crate); SoundManager.PlaySound(ContentPaths.Audio.whoosh, startPos); if (World.ParticleManager != null) { World.ParticleManager.Trigger("puff", pos + new Vector3(0.5f, 1.5f, 0.5f), Color.White, 90); } //}); }
public override void Die() { foreach (var resource in Resources.Where(resource => resource.NumResources > 0)) { for (int i = 0; i < resource.NumResources; i++) { Vector3 pos = MathFunctions.RandVector3Box(GetBoundingBox()); Physics item = EntityFactory.CreateEntity <Physics>(resource.ResourceType.ResourceName + " Resource", pos) as Physics; if (item != null) { item.Velocity = pos - GetBoundingBox().Center(); item.Velocity.Normalize(); item.Velocity *= 2.0f; } } } base.Die(); }
public Egg(string adult, ComponentManager manager, Vector3 position, BoundingBox positionConstraint) : base(manager) { PositionConstrain = positionConstraint; Adult = adult; Birthday = Manager.World.Time.CurrentDate + new TimeSpan(0, 12, 0, 0); if (ResourceLibrary.GetResourceByName(adult + " Egg") == null || !EntityFactory.EnumerateEntityTypes().Contains(adult + " Egg Resource")) { Resource newEggResource = new Resource(ResourceLibrary.GetResourceByName(ResourceType.Egg)); newEggResource.Name = adult + " Egg"; ResourceLibrary.Add(newEggResource); } ParentBody = EntityFactory.CreateEntity <Body>(adult + " Egg Resource", position); ParentBody.AddChild(this); }
public override void Die() { World.RemoveFromSpeciesTracking(Stats.CurrentClass); NoiseMaker.MakeNoise("Die", Physics.Position, true); if (AI.Stats.Money > 0) { EntityFactory.CreateEntity <CoinPile>("Coins Resource", AI.Position, Blackboard.Create("Money", AI.Stats.Money)); } if (Stats.Species.HasMeat) { String type = Stats.CurrentClass.Name + " " + "Meat"; if (!Library.DoesResourceTypeExist(type)) { var r = Library.CreateResourceType(Library.GetResourceType(Stats.Species.BaseMeatResource)); r.Name = type; r.ShortName = type; Library.AddResourceType(r); } Inventory.AddResource(new ResourceAmount(type, 1)); } if (Stats.Species.HasBones) { String type = Stats.CurrentClass.Name + " Bone"; if (!Library.DoesResourceTypeExist(type)) { var r = Library.CreateResourceType(Library.GetResourceType("Bone")); r.Name = type; r.ShortName = type; Library.AddResourceType(r); } Inventory.AddResource(new ResourceAmount(type, 1)); } base.Die(); }
/* * public void GenerateOres(VoxelChunk chunk, ComponentManager components, ContentManager content, * GraphicsDevice graphics) * { * Vector3 origin = chunk.Origin; * int chunkSizeX = chunk.SizeX; * int chunkSizeY = chunk.SizeY; * int chunkSizeZ = chunk.SizeZ; * Voxel v = chunk.MakeVoxel(0, 0, 0); * for (int x = 0; x < chunkSizeX; x++) * { * for (int z = 0; z < chunkSizeZ; z++) * { * int h = chunk.GetFilledVoxelGridHeightAt(x, chunkSizeY - 1, z); * for (int y = 1; y < chunkSizeY; y++) * { * foreach ( * KeyValuePair<string, VoxelLibrary.ResourceSpawnRate> spawns in VoxelLibrary.ResourceSpawns) * { * float s = spawns.Value.VeinSize; * float p = spawns.Value.VeinSpawnThreshold; * v.GridPosition = new Vector3(x, y, z); * if (v.IsEmpty || y >= h - 1 || !(y - h/2 < spawns.Value.MaximumHeight) || * !(y - h/2 > spawns.Value.MinimumHeight) || * !(PlayState.Random.NextDouble() <= spawns.Value.Probability) || v.Type.Name != "Stone") * { * continue; * } * * float caviness = (float) NoiseGenerator.Noise((float) (x + origin.X)*s, * (float) (z + origin.Z)*s, * (float) (y + origin.Y + h)*s); * * if (caviness > p) * { * v.Type = VoxelLibrary.GetVoxelType(spawns.Key); * } * continue; * } * } * } * } * } */ public void GenerateFauna(VoxelChunk chunk, ComponentManager components, ContentManager content, GraphicsDevice graphics, FactionLibrary factions) { int waterHeight = (int)(SeaLevel * chunk.SizeY); Voxel v = chunk.MakeVoxel(0, 0, 0); for (int x = 0; x < chunk.SizeX; x++) { for (int z = 0; z < chunk.SizeZ; z++) { Vector2 vec = new Vector2(x + chunk.Origin.X, z + chunk.Origin.Z) / PlayState.WorldScale; Overworld.Biome biome = Overworld.Map[(int)MathFunctions.Clamp(vec.X, 0, Overworld.Map.GetLength(0) - 1), (int)MathFunctions.Clamp(vec.Y, 0, Overworld.Map.GetLength(1) - 1)].Biome; BiomeData biomeData = BiomeLibrary.Biomes[biome]; int y = chunk.GetFilledVoxelGridHeightAt(x, chunk.SizeY - 1, z); if (!chunk.IsCellValid(x, (int)(y - chunk.Origin.Y), z)) { continue; } v.GridPosition = new Vector3(x, y, z); if (chunk.Data.Water[v.Index].WaterLevel != 0 || y <= waterHeight) { continue; } foreach (FaunaData animal in biomeData.Fauna) { if (y <= 0 || !(PlayState.Random.NextDouble() < animal.SpawnProbability)) { continue; } EntityFactory.CreateEntity <Body>(animal.Name, chunk.Origin + new Vector3(x, y, z) + Vector3.Up * 1.0f); break; } } } }
public List <Body> RemoveAndCreate(ResourceAmount resources, RestockType type) { var parentBody = GetRoot() as Body; var pos = parentBody == null ? GlobalTransform.Translation : parentBody.Position; List <Body> toReturn = new List <Body>(); if (!Remove(resources.CloneResource(), type)) { return(toReturn); } for (int i = 0; i < resources.NumResources; i++) { Body newEntity = EntityFactory.CreateEntity <Body>(resources.ResourceType + " Resource", pos + MathFunctions.RandVector3Cube() * 0.5f); toReturn.Add(newEntity); } return(toReturn); }
public void Splash(DwarfTime time, IEnumerable <LiquidSplash> Splashes) { foreach (var splash in Splashes) { Chunks.World.ParticleManager.Trigger(splash.name, splash.position + new Vector3(0.5f, 0.5f, 0.5f), Color.White, splash.numSplashes); if (splash.entity != null) { EntityFactory.CreateEntity <GameComponent>(splash.entity, splash.position + Vector3.One * 0.5f); } if (splashNoiseLimiter[splash.name].HasTriggered) { SoundManager.PlaySound(splash.sound, splash.position + new Vector3(0.5f, 0.5f, 0.5f), true); } } foreach (var t in splashNoiseLimiter.Values) { t.Update(time); } }
private GameComponent CreatePreviewBody() { Blackboard blackboard = new Blackboard(); if (SelectedResources != null && SelectedResources.Count > 0) { blackboard.SetData <List <ResourceAmount> >("Resources", SelectedResources); } blackboard.SetData <string>("CraftType", CraftType.Name); var previewBody = EntityFactory.CreateEntity <GameComponent>( CraftType.EntityName, World.UserInterface.VoxSelector.VoxelUnderMouse.WorldPosition, blackboard).GetRoot() as GameComponent; previewBody.SetFlagRecursive(GameComponent.Flag.Active, false); previewBody.SetVertexColorRecursive(Color.White); previewBody.SetFlag(GameComponent.Flag.ShouldSerialize, false); return(previewBody); }
private void UpdatePregnancy() { if (IsPregnant && World.Time.CurrentDate > CurrentPregnancy.EndDate) { // Todo: This check really belongs before the creature becomes pregnant. if (World.CanSpawnWithoutExceedingSpeciesLimit(Stats.Species)) { if (EntityFactory.HasEntity(Stats.Species.BabyType)) { var baby = EntityFactory.CreateEntity <GameComponent>(Stats.Species.BabyType, Physics.Position); if (baby.GetRoot().GetComponent <CreatureAI>().HasValue(out var ai)) // Set position constraint so baby stays inside pen. { ai.PositionConstraint = AI.PositionConstraint; } } } CurrentPregnancy = null; } }