/// <summary> /// Set the type of a voxel without triggering all the bookkeeping mechanisms. /// Should only be used by ChunkGenerator as it can break geometry building. /// </summary> /// <param name="NewType"></param> public void RawSetType(VoxelType NewType) { var previous = _cache_Chunk.Data.Types[_cache_Index]; // Change actual data _cache_Chunk.Data.Types[_cache_Index] = (byte)NewType.ID; // Changing the voxel type clears grass. _cache_Chunk.Data.Grass[_cache_Index] = 0; // Did we go from empty to filled or vice versa? Update filled counter. if (previous == 0 && NewType.ID != 0) { _cache_Chunk.Data.VoxelsPresentInSlice[Coordinate.Y] += 1; } else if (previous != 0 && NewType.ID == 0) { _cache_Chunk.Data.VoxelsPresentInSlice[Coordinate.Y] -= 1; } }
public VoxelType(VoxelType parent, string subtype) { ID = maxID; maxID++; Name = subtype; ReleasesResource = parent.ReleasesResource; ResourceToRelease = parent.ResourceToRelease; StartingHealth = parent.StartingHealth; ProbabilityOfRelease = parent.ProbabilityOfRelease; CanRamp = parent.CanRamp; RampSize = parent.RampSize; IsBuildable = parent.IsBuildable; ParticleType = parent.ParticleType; IsInvincible = parent.IsInvincible; ExplosionSound = parent.ExplosionSound; HasTransitionTextures = parent.HasTransitionTextures; TransitionTextures = parent.TransitionTextures; IsSoil = parent.IsSoil; EmitsLight = parent.EmitsLight; Tint = parent.Tint; IsSurface = parent.IsSurface; if (!TypeList.Contains(this)) { TypeList.Add(this); } MinSpawnHeight = -999; MaxSpawnHeight = 999; SpawnProbability = 1.0f; ClusterSize = 0.0f; VeinLength = 0.0f; SpawnClusters = false; SpawnVeins = false; Rarity = 1.0f; SpawnOnSurface = false; HitSound = parent.HitSound; }
private static BoxTransition ComputeTransitions( ChunkData Data, VoxelHandle V, VoxelType Type) { if (Type.Transitions == VoxelType.TransitionType.Horizontal) { var value = ComputeTransitionValueOnPlane( VoxelHelpers.EnumerateManhattanNeighbors2D(V.Coordinate) .Select(c => new VoxelHandle(Data, c)), Type); return(new BoxTransition() { Top = (TransitionTexture)value }); } else { var transitionFrontBack = ComputeTransitionValueOnPlane( VoxelHelpers.EnumerateManhattanNeighbors2D(V.Coordinate, ChunkManager.SliceMode.Z) .Select(c => new VoxelHandle(Data, c)), Type); var transitionLeftRight = ComputeTransitionValueOnPlane( VoxelHelpers.EnumerateManhattanNeighbors2D(V.Coordinate, ChunkManager.SliceMode.X) .Select(c => new VoxelHandle(Data, c)), Type); return(new BoxTransition() { Front = (TransitionTexture)transitionFrontBack, Back = (TransitionTexture)transitionFrontBack, Left = (TransitionTexture)transitionLeftRight, Right = (TransitionTexture)transitionLeftRight }); } }
public static void InitializeDefaultLibrary(GraphicsDevice graphics, Texture2D cubeTexture) { TypeList = FileUtils.LoadJson <List <VoxelType> >(ContentPaths.voxel_types, false); emptyType = TypeList[0]; short ID = 0; foreach (VoxelType type in TypeList) { type.ID = ID; ++ID; Types[type.Name] = type; PrimitiveMap[type] = type.ID == 0 ? null : CreatePrimitive(graphics, cubeTexture, 32, 32, type.Top, type.Bottom, type.Sides); if (type.HasTransitionTextures) { type.TransitionTextures = CreateTransitionUVs(graphics, cubeTexture, 32, 32, type.TransitionTiles, type.Transitions); } type.ExplosionSound = SoundSource.Create(type.ExplosionSoundResource); type.HitSound = SoundSource.Create(type.HitSoundResources); } }
public BuildVoxelAct(CreatureAI creature, Voxel voxel, VoxelType type) : base(creature) { Voxel = voxel; Name = "Build voxel"; List <ResourceAmount> resources = new List <ResourceAmount>() { new ResourceAmount(ResourceLibrary.Resources[type.ResourceToRelease], 1) }; if (Agent.Faction.WallBuilder.IsDesignation(voxel)) { Tree = new Sequence(new GetResourcesAct(Agent, resources), new Sequence( new GoToVoxelAct(voxel, PlanAct.PlanType.Adjacent, Agent), new PlaceVoxelAct(voxel, creature, resources.First()), new Wrap(Creature.RestockAll)) | new Wrap(Creature.RestockAll) ); } else { Tree = null; } }
public static void InitializeDefaultLibrary(GraphicsDevice graphics, Texture2D cubeTexture) { if (PrimitiveMap.Count > 0) { return; } BoxPrimitive grassCube = CreatePrimitive(graphics, cubeTexture, 32, 32, new Point(0, 0), new Point(2, 0), new Point(2, 0)); BoxPrimitive dirtCube = CreatePrimitive(graphics, cubeTexture, 32, 32, new Point(2, 0), new Point(2, 0), new Point(2, 0)); BoxPrimitive stoneCube = CreatePrimitive(graphics, cubeTexture, 32, 32, new Point(4, 2), new Point(1, 0), new Point(4, 2)); BoxPrimitive sandCube = CreatePrimitive(graphics, cubeTexture, 32, 32, new Point(1, 1), new Point(1, 1), new Point(1, 1)); BoxPrimitive ironCube = CreatePrimitive(graphics, cubeTexture, 32, 32, new Point(4, 1), new Point(1, 2), new Point(4, 1)); BoxPrimitive goldCube = CreatePrimitive(graphics, cubeTexture, 32, 32, new Point(3, 1), new Point(0, 2), new Point(3, 1)); BoxPrimitive coalCube = CreatePrimitive(graphics, cubeTexture, 32, 32, new Point(3, 2), new Point(2, 2), new Point(2, 2)); BoxPrimitive manaCube = CreatePrimitive(graphics, cubeTexture, 32, 32, new Point(7, 1), new Point(6, 1), new Point(7, 1)); BoxPrimitive frostCube = CreatePrimitive(graphics, cubeTexture, 32, 32, new Point(0, 1), new Point(2, 1), new Point(2, 0)); BoxPrimitive scaffoldCube = CreatePrimitive(graphics, cubeTexture, 32, 32, new Point(7, 0), new Point(7, 0), new Point(7, 0)); BoxPrimitive plankCube = CreatePrimitive(graphics, cubeTexture, 32, 32, new Point(4, 0), new Point(4, 0), new Point(4, 0)); BoxPrimitive waterCube = CreatePrimitive(graphics, cubeTexture, cubeTexture.Width, cubeTexture.Height, new Point(0, 0), new Point(0, 0), new Point(0, 0)); BoxPrimitive cobblestoneCube = CreatePrimitive(graphics, cubeTexture, 32, 32, new Point(5, 2), new Point(5, 2), new Point(5, 2)); BoxPrimitive magicCube = CreatePrimitive(graphics, cubeTexture, 32, 32, new Point(0, 10), new Point(0, 10), new Point(0, 10)); BoxPrimitive bedrockCube = CreatePrimitive(graphics, cubeTexture, 32, 32, new Point(6, 2), new Point(6, 2), new Point(6, 2)); BoxPrimitive brownTileCube = CreatePrimitive(graphics, cubeTexture, 32, 32, new Point(5, 0), new Point(5, 0), new Point(5, 0)); BoxPrimitive blueTileCube = CreatePrimitive(graphics, cubeTexture, 32, 32, new Point(6, 0), new Point(6, 0), new Point(6, 0)); BoxPrimitive tilledSoilCube = CreatePrimitive(graphics, cubeTexture, 32, 32, new Point(5, 1), new Point(2, 0), new Point(2, 0)); emptyType = new VoxelType { Name = "empty", ReleasesResource = false, IsBuildable = false }; VoxelType tilledSoil = new VoxelType { Name = "TilledSoil", ReleasesResource = false, StartingHealth = 20, CanRamp = true, IsBuildable = false, ParticleType = "dirt_particle", IsSoil = true }; RegisterType(tilledSoil, tilledSoilCube); VoxelType brownTileFloor = new VoxelType { Name = "BrownTileFloor", ReleasesResource = false, StartingHealth = 20, CanRamp = false, IsBuildable = false, ParticleType = "stone_particle" }; RegisterType(brownTileFloor, brownTileCube); VoxelType blueTileFloor = new VoxelType { Name = "BlueTileFloor", ReleasesResource = false, StartingHealth = 20, CanRamp = false, IsBuildable = false, ParticleType = "stone_particle" }; RegisterType(blueTileFloor, blueTileCube); VoxelType cobblestoneFloor = new VoxelType { Name = "CobblestoneFloor", ReleasesResource = false, StartingHealth = 20, CanRamp = false, IsBuildable = false, ParticleType = "stone_particle", HasTransitionTextures = true }; RegisterType(cobblestoneFloor, cobblestoneCube); CreateTransitionUVs(graphics, cubeTexture, 32, 32, new Point(0, 8), new Point(5, 2), new Point(5, 2), cobblestoneFloor.TransitionTextures); VoxelType stockpileType = new VoxelType { Name = "Stockpile", ReleasesResource = false, StartingHealth = 20, CanRamp = false, IsBuildable = false, ParticleType = "stone_particle", HasTransitionTextures = true }; RegisterType(stockpileType, plankCube); CreateTransitionUVs(graphics, cubeTexture, 32, 32, new Point(0, 9), new Point(4, 0), new Point(4, 0), stockpileType.TransitionTextures); VoxelType plankType = new VoxelType { Name = "Plank", ProbabilityOfRelease = 1.0f, ResourceToRelease = ResourceLibrary.ResourceType.Wood, StartingHealth = 20, ReleasesResource = true, CanRamp = true, RampSize = 0.5f, IsBuildable = true, ParticleType = "stone_particle", HasTransitionTextures = true }; CreateTransitionUVs(graphics, cubeTexture, 32, 32, new Point(0, 9), new Point(4, 0), new Point(4, 0), plankType.TransitionTextures); VoxelType magicType = new VoxelType { Name = "Magic", ProbabilityOfRelease = 0.0f, ResourceToRelease = ResourceLibrary.ResourceType.Mana, StartingHealth = 1, ReleasesResource = true, CanRamp = false, IsBuildable = false, ParticleType = "star_particle", ExplosionSound = ContentPaths.Audio.wurp, HasTransitionTextures = false, EmitsLight = true }; CreateTransitionUVs(graphics, cubeTexture, 32, 32, new Point(0, 10), new Point(15, 10), new Point(15, 10), magicType.TransitionTextures); VoxelType scaffoldType = new VoxelType { Name = "Scaffold", StartingHealth = 20, ProbabilityOfRelease = 1.0f, ResourceToRelease = ResourceLibrary.ResourceType.Wood, ReleasesResource = false, CanRamp = false, RampSize = 0.5f, IsBuildable = true, ParticleType = "stone_particle" }; VoxelType grassType = new VoxelType { Name = "Grass", ProbabilityOfRelease = 0.1f, ResourceToRelease = ResourceLibrary.ResourceType.Dirt, StartingHealth = 10, ReleasesResource = true, CanRamp = true, RampSize = 0.5f, IsBuildable = false, ParticleType = "dirt_particle", HasTransitionTextures = true, IsSoil = true }; CreateTransitionUVs(graphics, cubeTexture, 32, 32, new Point(0, 3), new Point(2, 0), new Point(2, 0), grassType.TransitionTextures); VoxelType frostType = new VoxelType { Name = "Frost", ProbabilityOfRelease = 0.1f, ResourceToRelease = ResourceLibrary.ResourceType.Dirt, StartingHealth = 10, ReleasesResource = true, CanRamp = true, RampSize = 0.5f, IsBuildable = false, ParticleType = "dirt_particle", HasTransitionTextures = true }; CreateTransitionUVs(graphics, cubeTexture, 32, 32, new Point(0, 4), new Point(2, 0), new Point(2, 0), frostType.TransitionTextures); VoxelType desertGrass = new VoxelType { Name = "DesertGrass", ProbabilityOfRelease = 0.1f, ResourceToRelease = ResourceLibrary.ResourceType.Sand, StartingHealth = 10, ReleasesResource = true, CanRamp = true, RampSize = 0.5f, IsBuildable = false, ParticleType = "sand_particle", HasTransitionTextures = true }; CreateTransitionUVs(graphics, cubeTexture, 32, 32, new Point(0, 6), new Point(1, 1), new Point(1, 1), desertGrass.TransitionTextures); VoxelType jungleGrass = new VoxelType { Name = "JungleGrass", ProbabilityOfRelease = 0.1f, ResourceToRelease = ResourceLibrary.ResourceType.Dirt, StartingHealth = 10, ReleasesResource = true, CanRamp = true, RampSize = 0.5f, IsBuildable = false, ParticleType = "dirt_particle", HasTransitionTextures = true }; CreateTransitionUVs(graphics, cubeTexture, 32, 32, new Point(0, 5), new Point(2, 0), new Point(2, 0), jungleGrass.TransitionTextures); VoxelType dirtType = new VoxelType { Name = "Dirt", ReleasesResource = true, ResourceToRelease = ResourceLibrary.ResourceType.Dirt, ProbabilityOfRelease = 0.3f, StartingHealth = 10, RampSize = 0.5f, CanRamp = true, IsBuildable = true, ParticleType = "dirt_particle", IsSoil = true }; VoxelType stoneType = new VoxelType { Name = "Stone", ProbabilityOfRelease = 0.5f, ReleasesResource = true, ResourceToRelease = ResourceLibrary.ResourceType.Stone, StartingHealth = 30, IsBuildable = true, ParticleType = "stone_particle" }; VoxelType bedrockType = new VoxelType { Name = "Bedrock", StartingHealth = 255, IsBuildable = false, IsInvincible = true }; VoxelType waterType = new VoxelType { Name = "water", ReleasesResource = false, IsBuildable = false, StartingHealth = 255 }; VoxelType sandType = new VoxelType { Name = "Sand", ReleasesResource = false, StartingHealth = 5, CanRamp = true, RampSize = 0.5f, IsBuildable = false, ParticleType = "sand_particle" }; VoxelType ironType = new VoxelType { Name = "Iron", ProbabilityOfRelease = 0.99f, ReleasesResource = true, ResourceToRelease = ResourceLibrary.ResourceType.Iron, StartingHealth = 80, IsBuildable = false, ParticleType = "stone_particle" }; ResourceSpawns["Iron"] = new ResourceSpawnRate { VeinSize = 0.2f, VeinSpawnThreshold = 0.9f, MinimumHeight = -100, MaximumHeight = 100, Probability = 0.5f }; VoxelType coalType = new VoxelType { Name = "Coal", ProbabilityOfRelease = 0.99f, ReleasesResource = true, ResourceToRelease = ResourceLibrary.ResourceType.Coal, StartingHealth = 75, IsBuildable = false, ParticleType = "stone_particle" }; ResourceSpawns["Coal"] = new ResourceSpawnRate { VeinSize = 0.085f, VeinSpawnThreshold = 0.9f, MinimumHeight = -100, MaximumHeight = 100, Probability = 0.5f }; VoxelType goldType = new VoxelType { Name = "Gold", ProbabilityOfRelease = 1.0f, ReleasesResource = true, ResourceToRelease = ResourceLibrary.ResourceType.Gold, StartingHealth = 90, IsBuildable = false, ParticleType = "stone_particle" }; ResourceSpawns["Gold"] = new ResourceSpawnRate { VeinSize = 0.07f, VeinSpawnThreshold = 0.8f, MinimumHeight = -150, MaximumHeight = 15, Probability = 0.6f }; VoxelType manaType = new VoxelType { Name = "Mana", ProbabilityOfRelease = 1.0f, ReleasesResource = true, ResourceToRelease = ResourceLibrary.ResourceType.Mana, StartingHealth = 200, IsBuildable = false, ParticleType = "stone_particle" }; ResourceSpawns["Mana"] = new ResourceSpawnRate { VeinSize = 0.05f, VeinSpawnThreshold = 0.85f, MinimumHeight = -800, MaximumHeight = 8, Probability = 0.5f }; RegisterType(grassType, grassCube); RegisterType(frostType, frostCube); RegisterType(desertGrass, grassCube); RegisterType(jungleGrass, grassCube); RegisterType(emptyType, null); RegisterType(dirtType, dirtCube); RegisterType(stoneType, stoneCube); RegisterType(waterType, waterCube); RegisterType(sandType, sandCube); RegisterType(ironType, ironCube); RegisterType(goldType, goldCube); RegisterType(manaType, manaCube); RegisterType(plankType, plankCube); RegisterType(scaffoldType, scaffoldCube); RegisterType(bedrockType, bedrockCube); RegisterType(coalType, coalCube); RegisterType(magicType, magicCube); foreach (VoxelType type in VoxelType.TypeList) { Types[type.Name] = type; } }
public static void RegisterType(VoxelType type, BoxPrimitive primitive) { PrimitiveMap[type] = primitive; }
private void OnTypeSet(VoxelType NewType) { // Changing a voxel is actually a relatively rare event, so we can afford to do a bit of // bookkeeping here. var previous = _cache_Chunk.Data.Types[_cache_Index]; var blockDestroyed = false; // Change actual data _cache_Chunk.Data.Types[_cache_Index] = (byte)NewType.ID; // Changing the voxel type clears grass. _cache_Chunk.Data.Grass[_cache_Index] = 0; // Did we go from empty to filled or vice versa? Update filled counter. if (previous == 0 && NewType.ID != 0) { _cache_Chunk.Data.VoxelsPresentInSlice[_cache_Local_Y] += 1; } else if (previous != 0 && NewType.ID == 0) { blockDestroyed = true; _cache_Chunk.Data.VoxelsPresentInSlice[_cache_Local_Y] -= 1; } var voxelAbove = VoxelHelpers.GetVoxelAbove(this); if (voxelAbove.IsValid) { InvalidateVoxel(voxelAbove); } InvalidateVoxel(this); // Propogate sunlight (or lack thereof) downwards. var sunlight = (NewType.ID == 0 || NewType.IsTransparent) ? this.Sunlight : false; var below = this; while (true) { below = VoxelHelpers.GetVoxelBelow(below); if (!below.IsValid) { break; } below.Sunlight = sunlight; if (!below.IsEmpty) { InvalidateVoxel(below); } if (!below.IsEmpty && !below.Type.IsTransparent) { break; } } if (blockDestroyed) { // Reveal! VoxelHelpers.RadiusReveal(_cache_Chunk.Manager, this, 10); // Clear player built flag! IsPlayerBuilt = false; } // Invoke new voxel listener. _cache_Chunk.Manager.NotifyChangedVoxel(new VoxelChangeEvent { Type = VoxelChangeEventType.VoxelTypeChanged, Voxel = this, OriginalVoxelType = previous, NewVoxelType = NewType.ID }); }
public static void InitializeDefaultLibrary(GraphicsDevice graphics, Texture2D cubeTexture) { if (PrimitiveMap.Count > 0) { return; } BoxPrimitive grassCube = CreatePrimitive(graphics, cubeTexture, 32, 32, new Point(0, 0), new Point(2, 0), new Point(2, 0)); BoxPrimitive dirtCube = CreatePrimitive(graphics, cubeTexture, 32, 32, new Point(2, 0), new Point(2, 0), new Point(2, 0)); BoxPrimitive stoneCube = CreatePrimitive(graphics, cubeTexture, 32, 32, new Point(4, 2), new Point(1, 0), new Point(4, 2)); BoxPrimitive sandCube = CreatePrimitive(graphics, cubeTexture, 32, 32, new Point(1, 1), new Point(1, 1), new Point(1, 1)); BoxPrimitive ironCube = CreatePrimitive(graphics, cubeTexture, 32, 32, new Point(4, 1), new Point(1, 2), new Point(4, 1)); BoxPrimitive goldCube = CreatePrimitive(graphics, cubeTexture, 32, 32, new Point(3, 1), new Point(0, 2), new Point(3, 1)); BoxPrimitive coalCube = CreatePrimitive(graphics, cubeTexture, 32, 32, new Point(3, 2), new Point(2, 2), new Point(2, 2)); BoxPrimitive manaCube = CreatePrimitive(graphics, cubeTexture, 32, 32, new Point(7, 1), new Point(6, 1), new Point(7, 1)); BoxPrimitive frostCube = CreatePrimitive(graphics, cubeTexture, 32, 32, new Point(0, 1), new Point(2, 1), new Point(2, 0)); BoxPrimitive snowCube = CreatePrimitive(graphics, cubeTexture, 32, 32, new Point(3, 7), new Point(3, 7), new Point(3, 7)); BoxPrimitive iceCube = CreatePrimitive(graphics, cubeTexture, 32, 32, new Point(2, 7), new Point(2, 7), new Point(2, 7)); BoxPrimitive scaffoldCube = CreatePrimitive(graphics, cubeTexture, 32, 32, new Point(7, 0), new Point(7, 0), new Point(7, 0)); BoxPrimitive plankCube = CreatePrimitive(graphics, cubeTexture, 32, 32, new Point(4, 0), new Point(4, 0), new Point(4, 0)); BoxPrimitive waterCube = CreatePrimitive(graphics, cubeTexture, cubeTexture.Width, cubeTexture.Height, new Point(0, 0), new Point(0, 0), new Point(0, 0)); BoxPrimitive cobblestoneCube = CreatePrimitive(graphics, cubeTexture, 32, 32, new Point(5, 2), new Point(5, 2), new Point(5, 2)); BoxPrimitive magicCube = CreatePrimitive(graphics, cubeTexture, 32, 32, new Point(0, 10), new Point(0, 10), new Point(0, 10)); BoxPrimitive bedrockCube = CreatePrimitive(graphics, cubeTexture, 32, 32, new Point(6, 2), new Point(6, 2), new Point(6, 2)); BoxPrimitive brownTileCube = CreatePrimitive(graphics, cubeTexture, 32, 32, new Point(5, 0), new Point(5, 0), new Point(5, 0)); BoxPrimitive blueTileCube = CreatePrimitive(graphics, cubeTexture, 32, 32, new Point(6, 0), new Point(6, 0), new Point(6, 0)); BoxPrimitive tilledSoilCube = CreatePrimitive(graphics, cubeTexture, 32, 32, new Point(5, 1), new Point(2, 0), new Point(2, 0)); BoxPrimitive redGemCube = CreatePrimitive(graphics, cubeTexture, 32, 32, new Point(0, 11), new Point(0, 12), new Point(0, 11)); BoxPrimitive orangeGemCube = CreatePrimitive(graphics, cubeTexture, 32, 32, new Point(1, 11), new Point(1, 12), new Point(1, 11)); BoxPrimitive yellowGemCube = CreatePrimitive(graphics, cubeTexture, 32, 32, new Point(2, 11), new Point(2, 12), new Point(2, 11)); BoxPrimitive greenGemCube = CreatePrimitive(graphics, cubeTexture, 32, 32, new Point(3, 11), new Point(3, 12), new Point(3, 11)); BoxPrimitive blueGemCube = CreatePrimitive(graphics, cubeTexture, 32, 32, new Point(4, 11), new Point(4, 12), new Point(4, 11)); BoxPrimitive purpleGemCube = CreatePrimitive(graphics, cubeTexture, 32, 32, new Point(5, 11), new Point(5, 12), new Point(5, 11)); emptyType = new VoxelType { Name = "empty", ReleasesResource = false, IsBuildable = false }; VoxelType tilledSoil = new VoxelType { Name = "TilledSoil", ReleasesResource = false, StartingHealth = 20, CanRamp = true, IsBuildable = false, ParticleType = "dirt_particle", IsSoil = true, IsSurface = true }; RegisterType(tilledSoil, tilledSoilCube); VoxelType brownTileFloor = new VoxelType { Name = "BrownTileFloor", ReleasesResource = false, StartingHealth = 20, CanRamp = false, IsBuildable = false, ParticleType = "stone_particle" }; RegisterType(brownTileFloor, brownTileCube); VoxelType blueTileFloor = new VoxelType { Name = "BlueTileFloor", ReleasesResource = false, StartingHealth = 20, CanRamp = false, IsBuildable = false, ParticleType = "stone_particle" }; RegisterType(blueTileFloor, blueTileCube); VoxelType cobblestoneFloor = new VoxelType { Name = "CobblestoneFloor", ReleasesResource = false, StartingHealth = 20, CanRamp = false, IsBuildable = false, ParticleType = "stone_particle", HasTransitionTextures = true }; RegisterType(cobblestoneFloor, cobblestoneCube); CreateTransitionUVs(graphics, cubeTexture, 32, 32, new Point(0, 8), new Point(5, 2), new Point(5, 2), cobblestoneFloor.TransitionTextures); VoxelType stockpileType = new VoxelType { Name = "Stockpile", ReleasesResource = false, StartingHealth = 20, CanRamp = false, IsBuildable = false, ParticleType = "stone_particle", HasTransitionTextures = true }; RegisterType(stockpileType, plankCube); CreateTransitionUVs(graphics, cubeTexture, 32, 32, new Point(0, 9), new Point(4, 0), new Point(4, 0), stockpileType.TransitionTextures); VoxelType plankType = new VoxelType { Name = "Plank", ProbabilityOfRelease = 1.0f, ResourceToRelease = ResourceLibrary.ResourceType.Wood, StartingHealth = 20, ReleasesResource = true, CanRamp = true, RampSize = 0.5f, IsBuildable = true, ParticleType = "stone_particle", HasTransitionTextures = true }; CreateTransitionUVs(graphics, cubeTexture, 32, 32, new Point(0, 9), new Point(4, 0), new Point(4, 0), plankType.TransitionTextures); VoxelType magicType = new VoxelType { Name = "Magic", ProbabilityOfRelease = 0.0f, ResourceToRelease = ResourceLibrary.ResourceType.Mana, StartingHealth = 1, ReleasesResource = true, CanRamp = false, IsBuildable = false, ParticleType = "star_particle", ExplosionSound = ContentPaths.Audio.wurp, HasTransitionTextures = false, EmitsLight = true }; CreateTransitionUVs(graphics, cubeTexture, 32, 32, new Point(0, 10), new Point(15, 10), new Point(15, 10), magicType.TransitionTextures); VoxelType scaffoldType = new VoxelType { Name = "Scaffold", StartingHealth = 20, ProbabilityOfRelease = 1.0f, ResourceToRelease = ResourceLibrary.ResourceType.Wood, ReleasesResource = false, CanRamp = false, RampSize = 0.5f, IsBuildable = true, ParticleType = "stone_particle" }; VoxelType grassType = new VoxelType { Name = "Grass", ProbabilityOfRelease = 0.1f, ResourceToRelease = ResourceLibrary.ResourceType.Dirt, StartingHealth = 10, ReleasesResource = true, CanRamp = true, RampSize = 0.5f, IsBuildable = false, ParticleType = "dirt_particle", HasTransitionTextures = true, IsSoil = true, IsSurface = true }; CreateTransitionUVs(graphics, cubeTexture, 32, 32, new Point(0, 3), new Point(2, 0), new Point(2, 0), grassType.TransitionTextures); VoxelType frostType = new VoxelType { Name = "Frost", ProbabilityOfRelease = 0.1f, ResourceToRelease = ResourceLibrary.ResourceType.Dirt, StartingHealth = 10, ReleasesResource = true, CanRamp = true, RampSize = 0.5f, IsBuildable = false, ParticleType = "dirt_particle", HasTransitionTextures = true, IsSurface = true }; CreateTransitionUVs(graphics, cubeTexture, 32, 32, new Point(0, 4), new Point(2, 0), new Point(2, 0), frostType.TransitionTextures); VoxelType snowType = new VoxelType { Name = "Snow", StartingHealth = 1, ReleasesResource = false, CanRamp = true, RampSize = 0.5f, IsBuildable = false, ParticleType = "snow_particle", HasTransitionTextures = false, IsSurface = true, IsSoil = false }; RegisterType(snowType, snowCube); VoxelType iceType = new VoxelType { Name = "Ice", StartingHealth = 1, ReleasesResource = false, CanRamp = false, IsBuildable = false, ParticleType = "snow_particle", HasTransitionTextures = false, IsSurface = true, IsSoil = false }; RegisterType(iceType, iceCube); VoxelType desertGrass = new VoxelType { Name = "DesertGrass", ProbabilityOfRelease = 0.1f, ResourceToRelease = ResourceLibrary.ResourceType.Sand, StartingHealth = 20, ReleasesResource = true, CanRamp = true, RampSize = 0.5f, IsBuildable = false, ParticleType = "sand_particle", HasTransitionTextures = true, IsSurface = true, IsSoil = true }; CreateTransitionUVs(graphics, cubeTexture, 32, 32, new Point(0, 6), new Point(1, 1), new Point(1, 1), desertGrass.TransitionTextures); VoxelType jungleGrass = new VoxelType { Name = "JungleGrass", ProbabilityOfRelease = 0.1f, ResourceToRelease = ResourceLibrary.ResourceType.Dirt, StartingHealth = 30, ReleasesResource = true, CanRamp = true, RampSize = 0.5f, IsBuildable = false, ParticleType = "dirt_particle", HasTransitionTextures = true, IsSurface = true, IsSoil = true }; CreateTransitionUVs(graphics, cubeTexture, 32, 32, new Point(0, 5), new Point(2, 0), new Point(2, 0), jungleGrass.TransitionTextures); VoxelType caveFungus = new VoxelType { Name = "CaveFungus", ProbabilityOfRelease = 0.25f, ResourceToRelease = ResourceLibrary.ResourceType.Stone, StartingHealth = 30, ReleasesResource = true, CanRamp = false, RampSize = 0.5f, IsBuildable = false, ParticleType = "stone_particle", HasTransitionTextures = true, IsSurface = false, IsSoil = true }; CreateTransitionUVs(graphics, cubeTexture, 32, 32, new Point(0, 13), new Point(1, 0), new Point(1, 0), caveFungus.TransitionTextures); VoxelType dirtType = new VoxelType { Name = "Dirt", ReleasesResource = true, ResourceToRelease = ResourceLibrary.ResourceType.Dirt, ProbabilityOfRelease = 0.3f, StartingHealth = 10, RampSize = 0.5f, CanRamp = true, IsBuildable = true, ParticleType = "dirt_particle", IsSoil = true }; VoxelType stoneType = new VoxelType { Name = "Stone", ProbabilityOfRelease = 0.5f, ReleasesResource = true, ResourceToRelease = ResourceLibrary.ResourceType.Stone, StartingHealth = 40, IsBuildable = true, ParticleType = "stone_particle" }; VoxelType bedrockType = new VoxelType { Name = "Bedrock", StartingHealth = 255, IsBuildable = false, IsInvincible = true }; VoxelType waterType = new VoxelType { Name = "water", ReleasesResource = false, IsBuildable = false, StartingHealth = 255 }; VoxelType sandType = new VoxelType { Name = "Sand", ReleasesResource = true, StartingHealth = 15, CanRamp = true, RampSize = 0.5f, IsBuildable = false, ParticleType = "sand_particle", IsSurface = true, ResourceToRelease = ResourceLibrary.ResourceType.Sand, ProbabilityOfRelease = 0.5f }; VoxelType ironType = new VoxelType { Name = "Iron", ProbabilityOfRelease = 0.99f, ReleasesResource = true, ResourceToRelease = ResourceLibrary.ResourceType.Iron, StartingHealth = 80, IsBuildable = false, ParticleType = "stone_particle", SpawnClusters = true, ClusterSize = 5, SpawnVeins = true, VeinLength = 10, Rarity = 0.0f, MinSpawnHeight = 8, MaxSpawnHeight = 40, SpawnProbability = 0.99f }; VoxelType coalType = new VoxelType { Name = "Coal", ProbabilityOfRelease = 0.99f, ReleasesResource = true, ResourceToRelease = ResourceLibrary.ResourceType.Coal, StartingHealth = 75, IsBuildable = false, ParticleType = "stone_particle", SpawnClusters = true, ClusterSize = 5, MinSpawnHeight = 15, MaxSpawnHeight = 50, SpawnProbability = 0.3f, Rarity = 0.05f, SpawnOnSurface = true }; VoxelType goldType = new VoxelType { Name = "Gold", ProbabilityOfRelease = 1.0f, ReleasesResource = true, ResourceToRelease = ResourceLibrary.ResourceType.Gold, StartingHealth = 90, IsBuildable = false, ParticleType = "stone_particle", SpawnVeins = true, VeinLength = 20, Rarity = 0.2f, MinSpawnHeight = 0, MaxSpawnHeight = 20, SpawnProbability = 0.99f }; VoxelType greenGem = new VoxelType { Name = "Emerald", ProbabilityOfRelease = 1.0f, ReleasesResource = true, ResourceToRelease = "Emerald", StartingHealth = 90, IsBuildable = false, ParticleType = "stone_particle", SpawnClusters = true, ClusterSize = 3, MinSpawnHeight = 0, MaxSpawnHeight = 18, SpawnProbability = 0.8f, Rarity = 0.9f }; VoxelType redGem = new VoxelType { Name = "Ruby", ProbabilityOfRelease = 1.0f, ReleasesResource = true, ResourceToRelease = "Ruby", StartingHealth = 90, IsBuildable = false, ParticleType = "stone_particle", SpawnClusters = true, ClusterSize = 3, MinSpawnHeight = 0, MaxSpawnHeight = 18, SpawnProbability = 0.8f, Rarity = 0.9f }; VoxelType purpleGem = new VoxelType { Name = "Amethyst", ProbabilityOfRelease = 1.0f, ReleasesResource = true, ResourceToRelease = "Amethyst", StartingHealth = 90, IsBuildable = false, ParticleType = "stone_particle", ClusterSize = 3, SpawnClusters = true, MinSpawnHeight = 0, MaxSpawnHeight = 18, SpawnProbability = 0.8f, Rarity = 0.9f }; VoxelType blueGem = new VoxelType { Name = "Sapphire", ProbabilityOfRelease = 1.0f, ReleasesResource = true, ResourceToRelease = "Sapphire", StartingHealth = 90, IsBuildable = false, ParticleType = "stone_particle", SpawnClusters = true, ClusterSize = 3, MinSpawnHeight = 0, MaxSpawnHeight = 18, SpawnProbability = 0.8f, Rarity = 0.9f }; VoxelType yellowGem = new VoxelType { Name = "Citrine", ProbabilityOfRelease = 1.0f, ReleasesResource = true, ResourceToRelease = "Citrine", StartingHealth = 90, IsBuildable = false, ParticleType = "stone_particle", SpawnClusters = true, ClusterSize = 3, MinSpawnHeight = 0, MaxSpawnHeight = 18, SpawnProbability = 0.8f, Rarity = 0.9f }; VoxelType orangeGem = new VoxelType { Name = "Garnet", ProbabilityOfRelease = 1.0f, ReleasesResource = true, ResourceToRelease = "Garnet", StartingHealth = 90, IsBuildable = false, ParticleType = "stone_particle", SpawnClusters = true, ClusterSize = 3, MinSpawnHeight = 0, MaxSpawnHeight = 18, SpawnProbability = 0.8f, Rarity = 0.9f }; VoxelType manaType = new VoxelType { Name = "Mana", ProbabilityOfRelease = 1.0f, ReleasesResource = true, ResourceToRelease = ResourceLibrary.ResourceType.Mana, StartingHealth = 200, IsBuildable = false, ParticleType = "stone_particle", SpawnVeins = true, VeinLength = 25, Rarity = 0.1f, MinSpawnHeight = 0, MaxSpawnHeight = 14, SpawnProbability = 0.99f }; RegisterType(greenGem, greenGemCube); RegisterType(redGem, redGemCube); RegisterType(purpleGem, purpleGemCube); RegisterType(blueGem, blueGemCube); RegisterType(orangeGem, orangeGemCube); RegisterType(yellowGem, yellowGemCube); RegisterType(grassType, grassCube); RegisterType(frostType, frostCube); RegisterType(desertGrass, grassCube); RegisterType(jungleGrass, grassCube); RegisterType(caveFungus, grassCube); RegisterType(emptyType, null); RegisterType(dirtType, dirtCube); RegisterType(stoneType, stoneCube); RegisterType(waterType, waterCube); RegisterType(sandType, sandCube); RegisterType(ironType, ironCube); RegisterType(goldType, goldCube); RegisterType(manaType, manaCube); RegisterType(plankType, plankCube); RegisterType(scaffoldType, scaffoldCube); RegisterType(bedrockType, bedrockCube); RegisterType(coalType, coalCube); RegisterType(magicType, magicCube); foreach (VoxelType type in VoxelType.TypeList) { Types[type.Name] = type; } }
public static void PlaceType(VoxelType type, Voxel voxel) { voxel.Type = type; voxel.Water = new WaterCell(); voxel.Health = voxel.Type.StartingHealth; }
public static BoxPrimitive GetPrimitive(VoxelType type) { return(GetPrimitive(type.Name)); }
public WallBuilder(Voxel v, VoxelType t) { Vox = v; Type = t; }
public WallBuilder(Voxel v, VoxelType t, WorldManager world) { World = world; Vox = v; Type = t; }
public static BoxPrimitive GetVoxelPrimitive(VoxelType type) { InitializeVoxels(); return(GetVoxelPrimitive(type.Name)); }
public bool CanBuildVoxel(VoxelType type) { return(CachedCanBuildVoxel[type.Name]); }
private static int ComputeTransitionValueOnPlane(IEnumerable <VoxelHandle> Neighbors, VoxelType Type) { int index = 0; int accumulator = 0; foreach (var v in Neighbors) { if (v.IsValid && !v.IsEmpty && v.Type == Type) { accumulator += TransitionMultipliers[index]; } index += 1; } return(accumulator); }
private void OnTypeSet(VoxelType NewType) { // Changing a voxel is actually a relatively rare event, so we can afford to do a bit of // bookkeeping here. var previous = _cache_Chunk.Data.Types[_cache_Index]; var blockDestroyed = false; // Change actual data _cache_Chunk.Data.Types[_cache_Index] = (byte)NewType.ID; _cache_Chunk.Data.Health[_cache_Index] = (byte)NewType.StartingHealth; // Changing the voxel type clears grass. _cache_Chunk.Data.GrassType[_cache_Index] = 0; // Did we go from empty to filled or vice versa? Update filled counter. if (previous == 0 && NewType.ID != 0) { _cache_Chunk.Data.VoxelsPresentInSlice[Coordinate.Y] += 1; } else if (previous != 0 && NewType.ID == 0) { blockDestroyed = true; _cache_Chunk.Data.VoxelsPresentInSlice[Coordinate.Y] -= 1; } if (Coordinate.Y < VoxelConstants.ChunkSizeY - 1) { InvalidateVoxel(_cache_Chunk, Coordinate, Coordinate.Y + 1); } InvalidateVoxel(_cache_Chunk, Coordinate, Coordinate.Y); // Propogate sunlight (or lack thereof) downwards. if (Coordinate.Y > 0) { var localCoordinate = Coordinate.GetLocalVoxelCoordinate(); var Y = localCoordinate.Y - 1; var sunColor = (NewType.ID == 0 || NewType.IsTransparent) ? this.SunColor : 0; var below = VoxelHandle.InvalidHandle; while (Y >= 0) { below = new VoxelHandle(Chunk, new LocalVoxelCoordinate(localCoordinate.X, Y, localCoordinate.Z)); below.SunColor = sunColor; InvalidateVoxel(Chunk, new GlobalVoxelCoordinate(Coordinate.X, Y, Coordinate.Z), Y); if (!below.IsEmpty && !below.Type.IsTransparent) { break; } Y -= 1; } } if (blockDestroyed) { // Invoke old voxel listener. _cache_Chunk.NotifyDestroyed(Coordinate.GetLocalVoxelCoordinate()); // Reveal! VoxelHelpers.RadiusReveal(_cache_Chunk.Manager.ChunkData, this, 10); } // Invoke new voxel listener. _cache_Chunk.Manager.NotifyChangedVoxel(new VoxelChangeEvent { Type = VoxelChangeEventType.VoxelTypeChanged, Voxel = this, OriginalVoxelType = previous, NewVoxelType = NewType.ID }); }
public bool CanBuildVoxel(VoxelType type) { return(PersistentData.CachedCanBuildVoxel[type.Name]); }
public static void InitializeDefaultLibrary(GraphicsDevice graphics) { if (TypeList != null) { return; } var cubeTexture = AssetManager.GetContentTexture(ContentPaths.Terrain.terrain_tiles); TypeList = FileUtils.LoadJsonListFromDirectory <VoxelType>(ContentPaths.voxel_types, null, v => v.Name); emptyType = TypeList.FirstOrDefault(v => v.Name == "_empty"); DesignationType = TypeList.FirstOrDefault(v => v.Name == "_designation"); // Todo: Stabalize ids across save games. short id = 2; foreach (VoxelType type in TypeList) { Types[type.Name] = type; if (type.Name == "_empty") { emptyType = type; type.ID = 0; } else { PrimitiveMap[type.Name] = CreatePrimitive(graphics, cubeTexture, 32, 32, type.Top, type.Bottom, type.Sides); if (type.Name == "_designation") { DesignationType = type; type.ID = 1; } else { type.ID = id; id += 1; } } if (type.HasTransitionTextures) { type.TransitionTextures = CreateTransitionUVs(graphics, cubeTexture, 32, 32, type.TransitionTiles, type.Transitions); } type.ExplosionSound = SoundSource.Create(type.ExplosionSoundResource); type.HitSound = SoundSource.Create(type.HitSoundResources); if (type.ReleasesResource) { if (ResourceLibrary.GetResourceByName(type.Name) == null) { var resource = new Resource(ResourceLibrary.GetResourceByName(type.ResourceToRelease)) { Name = type.Name, ShortName = type.Name, Tint = type.Tint, Generated = false }; ResourceLibrary.Add(resource); type.ResourceToRelease = resource.Name; } } } TypeList = TypeList.OrderBy(v => v.ID).ToList(); if (TypeList.Count > VoxelConstants.MaximumVoxelTypes) { throw new InvalidProgramException(String.Format("There can be only {0} voxel types.", VoxelConstants.MaximumVoxelTypes)); } }