Exemplo n.º 1
0
        public override Act CreateScript(Creature creature)
        {
            var voxtype  = VoxelLibrary.GetVoxelType(VoxType);
            var resource = creature.Faction.ListResources().Where(r => voxtype.CanBuildWith(ResourceLibrary.GetResourceByName(r.Key))).FirstOrDefault();

            if (resource.Key == null)
            {
                return(null);
            }

            var resources = new ResourceAmount(resource.Value.ResourceType, 1);

            return(new Select(
                       new Sequence(
                           new GetResourcesAct(creature.AI, new List <ResourceAmount>()
            {
                resources
            }),
                           new Domain(() => Validate(creature.AI, Voxel, resources),
                                      new GoToVoxelAct(Voxel, PlanAct.PlanType.Radius, creature.AI, 4.0f)),
                           new PlaceVoxelAct(Voxel, creature.AI, resources, VoxType)),
                       new Wrap(creature.RestockAll))
            {
                Name = "Build Voxel"
            });
        }
Exemplo n.º 2
0
        private void impl_CreateCosmeticChildren(ComponentManager Manager)
        {
            PropogateTransforms();
            var mesh = AddChild(new InstanceMesh(Manager, "Model",
                                                 Matrix.CreateRotationY((float)(MathFunctions.Random.NextDouble() * Math.PI)) * Matrix.CreateScale(MeshScale, MeshScale, MeshScale) * Matrix.CreateTranslation(GetBoundingBox().Center() - Position), MeshAsset,
                                                 this.BoundingBoxSize, Vector3.Zero));

            mesh.SetFlag(Flag.ShouldSerialize, false);

            AddChild(new GenericVoxelListener(Manager,
                                              Matrix.Identity,
                                              new Vector3(0.25f, 0.25f, 0.25f), // Position just below surface.
                                              new Vector3(0.0f, -0.30f, 0.0f),
                                              (v) =>
            {
                if (v.Type == VoxelChangeEventType.VoxelTypeChanged &&
                    (v.NewVoxelType == 0 || !VoxelLibrary.GetVoxelType(v.NewVoxelType).IsSoil))
                {
                    Die();
                }
                else if (v.Type == VoxelChangeEventType.RampsChanged)
                {
                    if (v.OldRamps != RampType.None && v.NewRamps == RampType.None)
                    {
                        LocalTransform = Matrix.CreateRotationY(RandomAngle) * Matrix.CreateTranslation(BasePosition);
                    }
                    else if (v.OldRamps == RampType.None && v.NewRamps != RampType.None)
                    {
                        LocalTransform = Matrix.CreateRotationY(RandomAngle) * Matrix.CreateTranslation(BasePosition - new Vector3(0.0f, 0.5f, 0.0f));
                    }
                }
            }))
            .SetFlag(Flag.ShouldSerialize, false);
        }
Exemplo n.º 3
0
        public void HandleTransfers(DwarfTime time)
        {
            Voxel atPos = new Voxel();

            while (Transfers.Count > 0)
            {
                Transfer transfer;

                if (!Transfers.TryDequeue(out transfer))
                {
                    break;
                }

                if ((transfer.cellFrom.Type == LiquidType.Lava &&
                     transfer.cellTo.Type == LiquidType.Water) ||
                    (transfer.cellFrom.Type == LiquidType.Water && transfer.cellTo.Type == LiquidType.Lava))
                {
                    bool success = Chunks.ChunkData.GetVoxel(transfer.worldLocation, ref atPos);

                    if (success)
                    {
                        Voxel v = atPos;

                        VoxelLibrary.PlaceType(VoxelLibrary.GetVoxelType("Stone"), v);
                        VoxelChunk chunk = Chunks.ChunkData.ChunkMap[v.ChunkID];
                        chunk.Data.Water[v.Index].Type       = LiquidType.None;
                        chunk.Data.Water[v.Index].WaterLevel = 0;
                        chunk.ShouldRebuild             = true;
                        chunk.ShouldRecalculateLighting = true;
                    }
                }
            }
        }
Exemplo n.º 4
0
        public override Feasibility IsFeasible(Creature agent)
        {
            if (!agent.AI.Stats.CurrentClass.IsTaskAllowed(TaskCategory.BuildBlock))
            {
                return(Feasibility.Infeasible);
            }

            if (agent.AI.Status.IsAsleep)
            {
                return(Feasibility.Infeasible);
            }

            if (!agent.AI.Faction.Designations.IsVoxelDesignation(Voxel, DesignationType.Put))
            {
                return(Feasibility.Infeasible);
            }

            Dictionary <ResourceType, int> numResources = new Dictionary <ResourceType, int>();
            int numFeasibleVoxels = 0;

            var voxtype = VoxelLibrary.GetVoxelType(VoxType);
            int count   = agent.Faction.ListResources().Where(r => voxtype.CanBuildWith(ResourceLibrary.GetResourceByName(r.Key))).Sum(r => r.Value.NumResources);

            if (count == 0)
            {
                return(Feasibility.Infeasible);
            }
            numFeasibleVoxels++;
            return(numFeasibleVoxels > 0 ? Feasibility.Feasible : Feasibility.Infeasible);
        }
Exemplo n.º 5
0
        public void GenerateWater(VoxelChunk chunk, float maxHeight)
        {
            int waterHeight = Math.Min((int)(VoxelConstants.ChunkSizeY * NormalizeHeight(SeaLevel + 1.0f / VoxelConstants.ChunkSizeY, maxHeight)), VoxelConstants.ChunkSizeY - 1);
            var iceID       = VoxelLibrary.GetVoxelType("Ice");

            for (var x = 0; x < VoxelConstants.ChunkSizeX; ++x)
            {
                for (var z = 0; z < VoxelConstants.ChunkSizeZ; ++z)
                {
                    var biome    = Overworld.GetBiomeAt(new Vector3(x, 0, z) + chunk.Origin, chunk.Manager.World.WorldScale, chunk.Manager.World.WorldOrigin);
                    var topVoxel = VoxelHelpers.FindFirstVoxelBelow(new VoxelHandle(
                                                                        chunk, new LocalVoxelCoordinate(x, VoxelConstants.ChunkSizeY - 1, z)));

                    for (var y = 0; y <= waterHeight; ++y)
                    {
                        var vox = new VoxelHandle(chunk, new LocalVoxelCoordinate(x, y, z));
                        if (vox.IsEmpty && y > topVoxel.Coordinate.Y)
                        {
                            if (biome.WaterSurfaceIce && y == waterHeight)
                            {
                                vox.RawSetType(iceID);
                            }
                            else
                            {
                                vox.QuickSetLiquid(biome.WaterIsLava ? LiquidType.Lava : LiquidType.Water, WaterManager.maxWaterLevel);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 6
0
        public VoxelChunk ToChunk(ChunkManager Manager)
        {
            VoxelChunk c = new VoxelChunk(Manager, Origin, ID);

            for (var i = 0; i < VoxelConstants.ChunkVoxelCount; ++i)
            {
                c.Data.Types[i] = Types[i];

                if (Types[i] > 0)
                {
                    c.Data.Health[i] = (byte)VoxelLibrary.GetVoxelType(Types[i]).StartingHealth;

                    // Rebuild the VoxelsPresentInSlice counters
                    c.Data.VoxelsPresentInSlice[(i >> VoxelConstants.ZDivShift) >> VoxelConstants.XDivShift] += 1;
                }
            }

            Explored.CopyTo(c.Data.IsExplored, 0);
            // Separate loop for cache effeciency
            for (var i = 0; i < VoxelConstants.ChunkVoxelCount; ++i)
            {
                c.Data.Water[i].WaterLevel = Liquid[i];
                c.Data.Water[i].Type       = (LiquidType)LiquidTypes[i];

                // Rebuild the LiquidPresent counters
                if ((LiquidType)LiquidTypes[i] != LiquidType.None)
                {
                    c.Data.LiquidPresent[(i >> VoxelConstants.ZDivShift) >> VoxelConstants.XDivShift] += 1;
                }
            }
            c.CalculateInitialSunlight();
            return(c);
        }
Exemplo n.º 7
0
            public static void InitializeStatics(ParticleManager particles)
            {
                if (staticsInitialized)
                {
                    return;
                }

                staticsInitialized = true;
                Properties         = new Dictionary <StormType, StormProperties>()
                {
                    {
                        StormType.RainStorm, new StormProperties()
                        {
                            RainEffect     = particles.Effects["rain"],
                            HitEffect      = particles.Effects["splat"],
                            RainSpeed      = 30,
                            CreatesLiquid  = true,
                            LiquidToCreate = LiquidType.Water
                        }
                    },
                    {
                        StormType.SnowStorm, new StormProperties()
                        {
                            RainEffect    = particles.Effects["snowflake"],
                            HitEffect     = particles.Effects["snow_particle"],
                            RainSpeed     = 10,
                            RainRandom    = 10f,
                            CreatesVoxel  = true,
                            VoxelToCreate = VoxelLibrary.GetVoxelType("Snow")
                        }
                    }
                };
            }
Exemplo n.º 8
0
 static Storm()
 {
     Properties = new Dictionary <StormType, StormProperties>()
     {
         {
             StormType.RainStorm, new StormProperties()
             {
                 RainEffect     = PlayState.ParticleManager.Effects["rain"],
                 HitEffect      = PlayState.ParticleManager.Effects["splat"],
                 RainSpeed      = 30,
                 CreatesLiquid  = true,
                 LiquidToCreate = LiquidType.Water
             }
         },
         {
             StormType.SnowStorm, new StormProperties()
             {
                 RainEffect    = PlayState.ParticleManager.Effects["snowflake"],
                 HitEffect     = PlayState.ParticleManager.Effects["snow_particle"],
                 RainSpeed     = 10,
                 RainRandom    = 10f,
                 CreatesVoxel  = true,
                 VoxelToCreate = VoxelLibrary.GetVoxelType("Snow")
             }
         }
     };
 }
Exemplo n.º 9
0
        public override void OnVoxelsSelected(SpellTree tree, List <VoxelHandle> voxels)
        {
            bool placed = false;

            foreach (var selected in voxels)
            {
                if (selected.IsValid && ((!Transmute && selected.IsEmpty) || Transmute && !selected.IsEmpty) && OnCast(tree))
                {
                    Vector3 p = selected.WorldPosition + Vector3.One * 0.5f;
                    IndicatorManager.DrawIndicator("-" + ManaCost + " M", p, 1.0f, GameSettings.Default.Colors.GetColor("Negative", Color.Red));
                    World.ParticleManager.Trigger("star_particle", p, Color.White, 4);
                    var lSelected = selected;
                    lSelected.Type = VoxelLibrary.GetVoxelType(VoxelType);
                    lSelected.QuickSetLiquid(LiquidType.None, 0);

                    if (VoxelType == "Magic")
                    {
                        World.ComponentManager.RootComponent.AddChild(new DestroyOnTimer(World.ComponentManager, World.ChunkManager, selected)
                        {
                            DestroyTimer = new Timer(5.0f + MathFunctions.Rand(-0.5f, 0.5f), true)
                        });
                    }
                    placed = true;
                }
            }

            if (placed)
            {
                SoundManager.PlaySound(ContentPaths.Audio.tinkle, World.CursorLightPos, true, 1.0f);
            }

            RechargeTimer.Reset(RechargeTimer.TargetTimeSeconds);
            base.OnVoxelsSelected(tree, voxels);
        }
Exemplo n.º 10
0
        public VoxelChunk ToChunk(ChunkManager manager)
        {
            int        chunkSizeX = this.Size.X;
            int        chunkSizeY = this.Size.Y;
            int        chunkSizeZ = this.Size.Z;
            Vector3    origin     = this.Origin;
            VoxelChunk c          = new VoxelChunk(manager, origin, 1, ID, chunkSizeX, chunkSizeY, chunkSizeZ)
            {
                ShouldRebuild             = true,
                ShouldRecalculateLighting = true
            };

            for (int x = 0; x < chunkSizeX; x++)
            {
                for (int z = 0; z < chunkSizeZ; z++)
                {
                    for (int y = 0; y < chunkSizeY; y++)
                    {
                        int index = c.Data.IndexAt(x, y, z);
                        if (Types[x, y, z] > 0)
                        {
                            c.Data.Types[index]  = Types[x, y, z];
                            c.Data.Health[index] = (byte)VoxelLibrary.GetVoxelType(Types[x, y, z]).StartingHealth;
                        }
                        c.Data.IsExplored[index]       = Explored[x, y, z];
                        c.Data.Water[index].WaterLevel = Liquid[x, y, z];
                        c.Data.Water[index].Type       = (LiquidType)LiquidTypes[x, y, z];
                    }
                }
            }
            c.ShouldRebuildWater = true;

            return(c);
        }
Exemplo n.º 11
0
        public IEnumerable <Status> FarmATile()
        {
            FarmTool.FarmTile tile = FarmToWork;
            if (tile == null)
            {
                yield return(Status.Fail);
            }
            else if (tile.PlantExists())
            {
                tile.Farmer = null;
                yield return(Status.Success);
            }
            else
            {
                if (tile.Plant != null && tile.Plant.IsDead)
                {
                    tile.Plant = null;
                }
                Creature.CurrentCharacterMode = Creature.CharacterMode.Attacking;
                Creature.Sprite.ResetAnimations(Creature.CharacterMode.Attacking);
                Creature.Sprite.PlayAnimations(Creature.CharacterMode.Attacking);
                while (tile.Progress < 100.0f && !Satisfied())
                {
                    Creature.Physics.Velocity *= 0.1f;
                    tile.Progress             += Creature.Stats.BaseFarmSpeed;

                    Drawer2D.DrawLoadBar(Agent.Position + Vector3.Up, Color.White, Color.Black, 100, 16,
                                         tile.Progress / 100.0f);

                    if (tile.Progress >= 100.0f && !Satisfied())
                    {
                        tile.Progress = 0.0f;
                        if (Mode == FarmAct.FarmMode.Plant)
                        {
                            FarmToWork.CreatePlant(PlantToCreate);
                            DestroyResources();
                        }
                        else
                        {
                            FarmToWork.Vox.Type = VoxelLibrary.GetVoxelType("TilledSoil");
                            FarmToWork.Vox.Chunk.NotifyTotalRebuild(true);
                        }
                    }
                    if (MathFunctions.RandEvent(0.01f))
                    {
                        PlayState.ParticleManager.Trigger("dirt_particle", Creature.AI.Position, Color.White, 1);
                    }
                    yield return(Status.Running);

                    Creature.Sprite.ReloopAnimations(Creature.CharacterMode.Attacking);
                }
                Creature.CurrentCharacterMode = Creature.CharacterMode.Idle;
                Creature.AI.AddThought(Thought.ThoughtType.Farmed);
                Creature.AI.AddXP(1);
                tile.Farmer = null;
                Creature.Sprite.PauseAnimations(Creature.CharacterMode.Attacking);
                yield return(Status.Success);
            }
        }
Exemplo n.º 12
0
 public Stockpile(Faction faction, WorldManager world) :
     base(false, new List <Voxel>(), RoomLibrary.GetData(StockpileName), world)
 {
     Boxes           = new List <Body>();
     ReplacementType = VoxelLibrary.GetVoxelType("Stockpile");
     faction.Stockpiles.Add(this);
     Faction = faction;
 }
Exemplo n.º 13
0
 public Treasury(Faction faction, IEnumerable <VoxelHandle> voxels, WorldManager world) :
     base(voxels, RoomLibrary.GetData(TreasuryName), world, faction)
 {
     Coins           = new List <Body>();
     ReplacementType = VoxelLibrary.GetVoxelType("Blue Tile");
     faction.Treasurys.Add(this);
     Faction = faction;
 }
Exemplo n.º 14
0
        public static void Render(
            GraphicsDevice Device,
            Shader Effect,
            OrbitCamera Camera,
            DesignationDrawer DesignationDrawer,
            DesignationSet Designations,
            WorldManager World)
        {
            lock (renderLock)
            {
                Drawer3D.Effect = Effect;
                Drawer3D.Camera = Camera;

                var colorModulation = Math.Abs(Math.Sin(DwarfTime.LastTime.TotalGameTime.TotalSeconds * 2.0f));

                DesignationDrawer.DrawHilites(
                    World,
                    Designations,
                    _addBox,
                    (pos, type) =>
                {
                    Effect.MainTexture = AssetManager.GetContentTexture(ContentPaths.Terrain.terrain_tiles);
                    Effect.LightRamp   = Color.White;
                    // Todo: Alpha pulse
                    Effect.VertexColorTint  = new Color(0.1f, 0.9f, 1.0f, 1.0f);
                    var prevTechnique       = Effect.CurrentTechnique;
                    Effect.CurrentTechnique = Effect.Techniques[Shader.Technique.Stipple];
                    var pos_distorted       = pos + Vector3.Up * 0.15f + VertexNoise.GetNoiseVectorFromRepeatingTexture(pos + Vector3.One * 0.5f);
                    Effect.World            = Matrix.CreateTranslation(pos_distorted);

                    foreach (EffectPass pass in Effect.CurrentTechnique.Passes)
                    {
                        pass.Apply();
                        VoxelLibrary.GetPrimitive(type).Render(Device);
                    }

                    Effect.LightRamp        = Color.White;
                    Effect.VertexColorTint  = Color.White;
                    Effect.World            = Matrix.Identity;
                    Effect.CurrentTechnique = prevTechnique;
                });

                foreach (var box in Boxes)
                {
                    _addBox(box.RealBox.Min, box.RealBox.Max - box.RealBox.Min, box.Color, box.Thickness, box.Warp);
                }

                foreach (var segment in Segments)
                {
                    _addLineSegment(segment.A, segment.B, segment.Color, segment.Thickness, false);
                }

                _flush();

                Boxes.Clear();
                Segments.Clear();
            }
        }
Exemplo n.º 15
0
 public void RecomputeCachedVoxelstate()
 {
     foreach (var type in VoxelLibrary.GetTypes())
     {
         bool nospecialRequried = type.BuildRequirements.Count == 0;
         CachedCanBuildVoxel[type.Name] = type.IsBuildable && ((nospecialRequried && HasResources(type.ResourceToRelease)) ||
                                                               (!nospecialRequried && HasResourcesCached(type.BuildRequirements)));
     }
 }
Exemplo n.º 16
0
 private Treasury(RoomData Data, Faction Faction, WorldManager World) :
     base(Data, World, Faction)
 {
     Coins           = new List <Body>();
     ReplacementType = VoxelLibrary.GetVoxelType("Blue Tile");
     Faction.Treasurys.Add(this);
     this.Faction = Faction;
     Money        = 0;
 }
Exemplo n.º 17
0
        public ChunkGenerator(VoxelLibrary voxLibrary, int randomSeed, float noiseScale, float maxMountainHeight, float worldScale)
        {
            WorldScale     = worldScale;
            NoiseGenerator = new Perlin(randomSeed);
            NoiseScale     = noiseScale;

            MaxMountainHeight = maxMountainHeight;
            VoxLibrary        = voxLibrary;
            CaveNoiseScale    = noiseScale * 10.0f;
            CaveSize          = 0.03f;
            CaveLevels        = new List <int>()
            {
                4, 8, 11, 16
            };
            CaveFrequencies = new List <float>()
            {
                0.5f, 0.7f, 0.9f, 1.0f
            };

            CaveNoise = new FastRidgedMultifractal(randomSeed)
            {
                Frequency    = 0.5f,
                Lacunarity   = 0.5f,
                NoiseQuality = NoiseQuality.Standard,
                OctaveCount  = 1,
                Seed         = randomSeed
            };

            AquiverLevels = new List <int>()
            {
                5
            };

            AquiferSize  = 0.02f;
            AquiferNoise = new FastRidgedMultifractal(randomSeed + 100)
            {
                Frequency    = 0.25f,
                Lacunarity   = 0.5f,
                NoiseQuality = NoiseQuality.Standard,
                OctaveCount  = 1,
                Seed         = randomSeed
            };

            LavaLevels = new List <int>()
            {
                1, 2
            };
            LavaSize  = 0.01f;
            LavaNoise = new FastRidgedMultifractal(randomSeed + 200)
            {
                Frequency    = 0.15f,
                Lacunarity   = 0.5f,
                NoiseQuality = NoiseQuality.Standard,
                OctaveCount  = 1,
                Seed         = randomSeed
            };
        }
Exemplo n.º 18
0
        public ChunkGenerator(VoxelLibrary voxLibrary, int randomSeed, float noiseScale, float maxMountainHeight)
        {
            NoiseGenerator = new Perlin(randomSeed);
            NoiseScale     = noiseScale;

            MaxMountainHeight = maxMountainHeight;
            VoxLibrary        = voxLibrary;
            CaveNoiseScale    = noiseScale * 2.0f;
        }
Exemplo n.º 19
0
        public override void OnVoxelsSelected(List <VoxelHandle> voxels, InputManager.MouseButton button)
        {
            var Faction = Player.Faction;

            if (CurrentVoxelType == 0)
            {
                return;
            }
            Selected.Clear();
            switch (button)
            {
            case (InputManager.MouseButton.Left):
            {
                List <Task> assignments = new List <Task>();
                var         validRefs   = voxels.Where(r => !Faction.Designations.IsVoxelDesignation(r, DesignationType.Put) &&
                                                       Player.World.Master.VoxSelector.SelectionType == VoxelSelectionType.SelectEmpty ? r.IsEmpty : !r.IsEmpty).ToList();

                foreach (var r in voxels)
                {
                    // Todo: Mode should be a property of the tool, not grabbed out of the vox selector.
                    if (Player.World.Master.VoxSelector.SelectionType == VoxelSelectionType.SelectEmpty && !r.IsEmpty)
                    {
                        continue;
                    }
                    if (Player.World.Master.VoxSelector.SelectionType == VoxelSelectionType.SelectFilled && r.IsEmpty)
                    {
                        continue;
                    }

                    var existingDesignation = Player.Faction.Designations.GetVoxelDesignation(r, DesignationType.Put);
                    if (existingDesignation != null)
                    {
                        Player.TaskManager.CancelTask(existingDesignation.Task);
                    }

                    assignments.Add(new BuildVoxelTask(r, VoxelLibrary.GetVoxelType(CurrentVoxelType).Name));
                }

                //TaskManager.AssignTasks(assignments, Faction.FilterMinionsWithCapability(Player.World.Master.SelectedMinions, GameMaster.ToolMode.BuildZone));
                Player.TaskManager.AddTasks(assignments);
                break;
            }

            case (InputManager.MouseButton.Right):
            {
                foreach (var r in voxels)
                {
                    var designation = Faction.Designations.GetVoxelDesignation(r, DesignationType.Put);
                    if (designation != null)
                    {
                        Player.TaskManager.CancelTask(designation.Task);
                    }
                }
                break;
            }
            }
        }
Exemplo n.º 20
0
 public void HandleLiquidInteraction(VoxelHandle Vox, WaterCell From, WaterCell To)
 {
     if ((From.Type == LiquidType.Lava && To.Type == LiquidType.Water) ||
         (From.Type == LiquidType.Water && To.Type == LiquidType.Lava))
     {
         Vox.Type      = VoxelLibrary.GetVoxelType("Stone");
         Vox.WaterCell = WaterCell.Empty;
     }
 }
Exemplo n.º 21
0
 public void HandleLiquidInteraction(VoxelHandle Vox, LiquidType From, LiquidType To)
 {
     if ((From == LiquidType.Lava && To == LiquidType.Water) ||
         (From == LiquidType.Water && To == LiquidType.Lava))
     {
         Vox.Type = VoxelLibrary.GetVoxelType("Stone");
         Vox.QuickSetLiquid(LiquidType.None, 0);
     }
 }
Exemplo n.º 22
0
 public Room(bool designation, IEnumerable <Voxel> designations, RoomData data, WorldManager world) :
     base(data.Name + " " + Counter, world)
 {
     RoomData        = data;
     ReplacementType = VoxelLibrary.GetVoxelType(RoomData.FloorType);
     Counter++;
     Designations = designations.ToList();
     IsBuilt      = false;
 }
Exemplo n.º 23
0
 public Stockpile()
 {
     Boxes              = new List <Body>();
     ReplacementType    = VoxelLibrary.GetVoxelType("Stockpile");
     Faction            = null;
     BlacklistResources = new List <Resource.ResourceTags>()
     {
         Resource.ResourceTags.Corpse
     };
 }
Exemplo n.º 24
0
        public void GenerateWater(VoxelChunk chunk)
        {
            int waterHeight = (int)(SeaLevel * VoxelConstants.ChunkSizeY) + 1;
            var iceID       = VoxelLibrary.GetVoxelType("Ice");

            for (var x = 0; x < VoxelConstants.ChunkSizeX; ++x)
            {
                for (var z = 0; z < VoxelConstants.ChunkSizeZ; ++z)
                {
                    var biome    = GetBiomeAt(new Vector2(x, z) + new Vector2(chunk.Origin.X, chunk.Origin.Z));
                    var topVoxel = VoxelHelpers.FindFirstVoxelBelow(new VoxelHandle(
                                                                        chunk, new LocalVoxelCoordinate(x, VoxelConstants.ChunkSizeY - 1, z)));

                    for (var y = 0; y <= waterHeight; ++y)
                    {
                        var vox = new VoxelHandle(chunk, new LocalVoxelCoordinate(x, y, z));
                        if (vox.IsEmpty && y > topVoxel.Coordinate.Y)
                        {
                            if (biome.WaterSurfaceIce && y == waterHeight)
                            {
                                vox.RawSetType(iceID);
                            }
                            else
                            {
                                vox.WaterCell = new WaterCell
                                {
                                    Type       = LiquidType.Water,
                                    WaterLevel = WaterManager.maxWaterLevel
                                };
                            }
                        }
                    }

                    Vector2 vec = new Vector2(x + chunk.Origin.X, z + chunk.Origin.Z) / WorldScale;


                    if (topVoxel.Coordinate.Y < VoxelConstants.ChunkSizeY - 1 &&
                        Overworld.GetWater(Overworld.Map, vec) == Overworld.WaterType.Volcano)
                    {
                        var localCoord = topVoxel.Coordinate.GetLocalVoxelCoordinate();
                        topVoxel = new VoxelHandle(topVoxel.Chunk, new LocalVoxelCoordinate(
                                                       localCoord.X, localCoord.Y + 1, localCoord.Z));

                        if (topVoxel.IsEmpty)
                        {
                            topVoxel.WaterCell = new WaterCell
                            {
                                Type       = LiquidType.Lava,
                                WaterLevel = WaterManager.maxWaterLevel
                            };
                        }
                    }
                }
            }
        }
Exemplo n.º 25
0
 public Room(
     RoomData data,
     WorldManager world,
     Faction faction) :
     base(data.Name + " " + Counter, world, faction)
 {
     RoomData        = data;
     ReplacementType = VoxelLibrary.GetVoxelType(RoomData.FloorType);
     Designations    = new List <VoxelHandle>();
     Counter++;
 }
Exemplo n.º 26
0
 public Stockpile(Faction faction, WorldManager world) :
     base(false, new List <VoxelHandle>(), RoomLibrary.GetData(StockpileName), world, faction)
 {
     Boxes           = new List <Body>();
     ReplacementType = VoxelLibrary.GetVoxelType("Stockpile");
     faction.Stockpiles.Add(this);
     Faction            = faction;
     BlacklistResources = new List <Resource.ResourceTags>()
     {
         Resource.ResourceTags.Corpse
     };
 }
Exemplo n.º 27
0
 protected Stockpile(RoomData Data, Faction Faction, WorldManager World) :
     base(Data, World, Faction)
 {
     Boxes = new List <Body>();
     Faction.Stockpiles.Add(this);
     ReplacementType    = VoxelLibrary.GetVoxelType("Stockpile");
     this.Faction       = Faction;
     BlacklistResources = new List <Resource.ResourceTags>()
     {
         Resource.ResourceTags.Corpse,
         Resource.ResourceTags.Money
     };
 }
Exemplo n.º 28
0
        public void Render(DwarfTime gameTime, GraphicsDevice graphics, Shader effect)
        {
            DepthStencilState state = graphics.DepthStencilState;

            graphics.DepthStencilState = DepthStencilState.DepthRead;

            float t  = (float)gameTime.TotalGameTime.TotalSeconds;
            float st = (float)Math.Sin(t * 4) * 0.5f + 0.5f;

            effect.MainTexture     = World.ChunkManager.ChunkData.Tilemap;
            effect.LightRampTint   = Color.White;
            effect.VertexColorTint = new Color(0.1f, 0.9f, 1.0f, 0.5f * st + 0.45f);
            foreach (WallBuilder put in Designations)
            {
                //Drawer3D.DrawBox(put.Vox.GetBoundingBox(), Color.LightBlue, st * 0.01f + 0.05f);
                effect.World = Matrix.CreateTranslation(put.Vox.Position);

                foreach (EffectPass pass in effect.CurrentTechnique.Passes)
                {
                    pass.Apply();
                    VoxelLibrary.GetPrimitive(put.Type.Name).Render(graphics);
                }
            }

            if (Selected == null)
            {
                Selected = new List <Voxel>();
            }

            if (CurrentVoxelType == null)
            {
                Selected.Clear();
            }

            effect.VertexColorTint = verified ? new Color(0.0f, 1.0f, 0.0f, 0.5f * st + 0.45f) : new Color(1.0f, 0.0f, 0.0f, 0.5f * st + 0.45f);
            foreach (Voxel voxel in Selected)
            {
                effect.World = Matrix.CreateTranslation(voxel.Position);

                foreach (EffectPass pass in effect.CurrentTechnique.Passes)
                {
                    pass.Apply();
                    VoxelLibrary.GetPrimitive(CurrentVoxelType).Render(graphics);
                }
            }

            effect.LightRampTint       = Color.White;
            effect.VertexColorTint     = Color.White;
            effect.World               = Matrix.Identity;
            graphics.DepthStencilState = state;
        }
Exemplo n.º 29
0
        public IEnumerable <Status> FarmATile()
        {
            FarmTool.FarmTile tile = FarmToWork;
            if (tile == null)
            {
                yield return(Status.Fail);
            }
            else if (tile.PlantExists())
            {
                tile.Farmer = null;
                yield return(Status.Success);
            }
            else
            {
                if (tile.Plant != null && tile.Plant.IsDead)
                {
                    tile.Plant = null;
                }
                while (tile.Progress < 100.0f && !Satisfied())
                {
                    Creature.CurrentCharacterMode = Creature.CharacterMode.Attacking;
                    Creature.Physics.Velocity    *= 0.1f;
                    tile.Progress += Creature.Stats.BaseFarmSpeed;

                    Drawer2D.DrawLoadBar(Agent.Position + Vector3.Up, Color.White, Color.Black, 100, 16,
                                         tile.Progress / 100.0f);
                    if (tile.Progress >= 100.0f && !Satisfied())
                    {
                        tile.Progress = 0.0f;
                        if (Mode == FarmAct.FarmMode.Plant)
                        {
                            FarmToWork.CreatePlant(PlantToCreate);
                            DestroyResources();
                        }
                        else
                        {
                            FarmToWork.Vox.Type = VoxelLibrary.GetVoxelType("TilledSoil");
                            FarmToWork.Vox.Chunk.ShouldRebuild = true;
                        }
                    }

                    yield return(Status.Running);
                }
                Creature.CurrentCharacterMode = Creature.CharacterMode.Idle;
                Creature.AI.AddThought(Thought.ThoughtType.Farmed);
                Creature.AI.AddXP(10);
                tile.Farmer = null;
                yield return(Status.Success);
            }
        }
Exemplo n.º 30
0
        public Room(IEnumerable <Voxel> voxels, RoomData data, WorldManager world) :
            base(data.Name + " " + Counter, world)
        {
            RoomData        = data;
            ReplacementType = VoxelLibrary.GetVoxelType(RoomData.FloorType);

            Designations = new List <Voxel>();
            Counter++;

            IsBuilt = true;
            foreach (Voxel voxel in voxels)
            {
                AddVoxel(voxel);
            }
        }