Example #1
0
        public static WorldObject DropItem(RockCube cube)
        {
            int random = DwarfRandom.GetRandomInt(1, 100);
            if (cube.Level == 1)
            {
                return new Stone(cube.Position, 1);
            }
            else if (cube.Level == 2)
            {
                if (random >= 50)
                    return new Stone(cube.Position, 1);
                else if (random >= 2)
                    return new IronOre(cube.Position, 1);
                else
                    return new GoldOre(cube.Position, 1);
            }
            else if (cube.Level == 3)
            {
                if (random >= 65)
                    return new Stone(cube.Position, 1);
                else if (random >= 30)
                    return new IronOre(cube.Position, 1);
                else if (random >= 5)
                    return new MithrilOre(cube.Position, 1);
                else
                    return new GoldOre(cube.Position, 1);
            }
            else if (cube.Level == 4)
            {
                if (random >= 80)
                    return new Stone(cube.Position, 1);
                else if (random >= 45)
                    return new IronOre(cube.Position, 1);
                else if (random >= 20)
                    return new MithrilOre(cube.Position, 1);
                else if (random >= 5)
                    return new TungstenOre(cube.Position, 1);
                else
                    return new GoldOre(cube.Position, 1);
            }
            else if (cube.Level == 5)
            {
                if (random >= 80)
                    return new Stone(cube.Position, 1);
                else if (random >= 55)
                    return new IronOre(cube.Position, 1);
                else if (random >= 40)
                    return new MithrilOre(cube.Position, 1);
                else if (random >= 20)
                    return new TungstenOre(cube.Position, 1);
                else if (random >= 5)
                    return new TitaniumOre(cube.Position, 1);
                else
                    return new GoldOre(cube.Position, 1);
            }

            throw new Exception("Missing cube level");
        }
Example #2
0
 private int GetRockCubeDeepness(RockCube rockCube, int orgX, int orgY, int currentDeep)
 {
     if (
         IsRockCube(orgX - currentDeep, orgY) &&
         IsRockCube(orgX + currentDeep, orgY) &&
         IsRockCube(orgX, orgY - currentDeep) &&
         IsRockCube(orgX, orgY + currentDeep))
     {
         currentDeep++;
         return GetRockCubeDeepness(rockCube, orgX, orgY, currentDeep);
     }
     else
         return currentDeep;
 }
Example #3
0
        public void CreateFromTexture()
        {
            Texture2D texture = GetContent().Load<Texture2D>("perlin");

            _mapX = texture.Width;
            _mapY = texture.Height;

            _mapElements = new MapElement[_mapX, _mapY, _mapZ];
            UpdateAstar();

            Color[] data = new Color[texture.Width * texture.Height];
            texture.GetData<Color>(data);

            for (int x = 0; x < texture.Width; x++)
            {
                for (int y = 0; y < texture.Height; y++)
                {
                    Color color = data[x + y * texture.Width];
                    _mapElements[x, y, _surfacePoint + 1] = new GrassCube(new Vector3Int(x, y, _surfacePoint + 1));
                    if (color.R > 150)
                    {
                        _mapElements[x, y, _surfacePoint] = new RockCube(new Vector3Int(x, y, _surfacePoint));
                        _mapElements[x, y, _surfacePoint+2] = new RockGroundCube(new Vector3Int(x, y, _surfacePoint + 1));
                    }
                    else
                    {

                    }
                }
            }

            UpdateAllTiles();

            UpdateAstar();
        }
Example #4
0
        public void CreateDebugOld()
        {
            _mapElements = new MapElement[_mapX, _mapY, _mapZ];

            UpdateAstar();

            AddWorldObject(new Tree(new Vector3Int(10, 10, _surfacePoint), 1));

            AddCreature(new Dwarf(new Vector3(40, 20, _surfacePoint), LivingType.Dwarf));
            AddCreature(new Dwarf(new Vector3(40, 21, _surfacePoint), LivingType.Dwarf));
            AddCreature(new Dwarf(new Vector3(40, 22, _surfacePoint), LivingType.Dwarf));

            AddCreature(new Pig(new Vector3(25, 40, _surfacePoint)));
            AddCreature(new Pig(new Vector3(26, 40, _surfacePoint)));

            AddCreature(new Cow(new Vector3(27, 40, _surfacePoint)));
            AddCreature(new Sheep(new Vector3(28, 40, _surfacePoint)));
            //_creatures.Add(new Dwarf(new Vector3(41, 20, _surfacePoint)));
            //_creatures.Add(new Dwarf(new Vector3(41, 21, _surfacePoint)));
            //_creatures.Add(new Dwarf(new Vector3(41, 22, _surfacePoint)));
            //_creatures.Add(new Dwarf(new Vector3(42, 20, _surfacePoint)));

            AddBuilding(new Depot(new Vector3Int(26, 40, _surfacePoint), 100));

            for (int x = 0; x < _mapX; x++)
            {
                for (int y = 0; y < _mapY; y++)
                {
                    for (int z = _surfacePoint; z < _mapZ; z++)
                    {

                        //if (z > _surfacePoint + 2)
                        //{
                        //    _mapElements[x, y, z] = new DirtCube(null, new Vector3Int(x,y,z));
                        //}
                        if (z == _surfacePoint + 1 || (z == _surfacePoint && x == 0 && y == 0))
                        {
                            _mapElements[x, y, z] = new GrassCube(new Vector3Int(x,y,z));
                        }
                        if (z == _surfacePoint + 2 && (y == 20 || y == 21 || y ==22) && x < 20)
                        {
                            _mapElements[x, y, z] = new DirtCube(new Vector3Int(x, y, z));
                        }
                        if (z == _surfacePoint + 2 && (y == 15 || y == 16) && x < 20)
                        {
                            _mapElements[x, y, z] = new WaterCube(new Vector3Int(x, y, z));
                        }
                        if (z == _surfacePoint && (
                            (x >= 0 && x < 25 && y > 25) ||
                            (x >= 75 && y > 25) ||
                            (y > 50) ||
                            (y == 26 && x > 27) ||
                            (y == 27 && x > 27)))
                        {
                            int random = DwarfRandom.GetRandomInt(0, 1);
                            if (random == 0)
                                _mapElements[x, y, z] = new RockCube(new Vector3Int(x, y, z));
                            if (random == 1)
                                _mapElements[x, y, z] = new IronOreCube(new Vector3Int(x, y, z));

                        }
                        if (z == _surfacePoint + 1 && (
                            (x >= 0 && x < 25 && y > 25) ||
                            (x >= 75 && y > 25) ||
                            (y > 50) ||
                            (y == 26 && x > 27) ||
                            (y == 27 && x > 27)))
                        {
                            _mapElements[x, y, z + 1] = new RockGroundCube(new Vector3Int(x, y, z));
                        }
                    }
                }
            }

            UpdateAllTiles();

            UpdateAstar();
        }
Example #5
0
        public void CreateDebugNew()
        {
            _mapElements = new MapElement[_mapX, _mapY, _mapZ];

            UpdateAstar();

            AddCreature(new Dwarf(new Vector3(20, 80, _surfacePoint), LivingType.Dwarf));
            AddCreature(new Dwarf(new Vector3(20, 81, _surfacePoint), LivingType.Dwarf));
            AddCreature(new Dwarf(new Vector3(20, 82, _surfacePoint), LivingType.Dwarf));

            AddCreature(new Pig(new Vector3(25, 80, _surfacePoint)));
            AddCreature(new Pig(new Vector3(26, 80, _surfacePoint)));

            AddCreature(new Cow(new Vector3(27, 80, _surfacePoint)));
            AddCreature(new Sheep(new Vector3(28, 80, _surfacePoint)));
            //_creatures.Add(new Dwarf(new Vector3(41, 20, _surfacePoint)));
            //_creatures.Add(new Dwarf(new Vector3(41, 21, _surfacePoint)));
            //_creatures.Add(new Dwarf(new Vector3(41, 22, _surfacePoint)));
            //_creatures.Add(new Dwarf(new Vector3(42, 20, _surfacePoint)));

            AddBuilding(new Depot(new Vector3Int(26, 80, _surfacePoint), 100));

            for (int x = 0; x < _mapX; x++)
            {
                for (int y = 0; y < _mapY; y++)
                {
                    for (int z = _surfacePoint; z < _mapZ; z++)
                    {

                        //if (z > _surfacePoint + 2)
                        //{
                        //    _mapElements[x, y, z] = new DirtCube(null, new Vector3Int(x,y,z));
                        //}
                        if (z == _surfacePoint + 1 || (z == _surfacePoint && x == 0 && y == 0))
                        {
                            _mapElements[x, y, z] = new GrassCube(new Vector3Int(x, y, z));
                        }
                        //if (z == _surfacePoint + 2 && (y == 20 || y == 21 || y == 22) && x < 20)
                        //{
                        //    _mapElements[x, y, z] = new DirtCube(new Vector3Int(x, y, z));
                        //}
                        //if (z == _surfacePoint + 2 && (y == 15 || y == 16) && x < 20)
                        //{
                        //    _mapElements[x, y, z] = new WaterCube(new Vector3Int(x, y, z));
                        //}
                        if (x >=40)
                        {
                            _mapElements[x, y, _surfacePoint] = new RockCube(new Vector3Int(x, y, _surfacePoint));
                            _mapElements[x, y, _surfacePoint + 2] = new RockGroundCube(new Vector3Int(x, y, _surfacePoint + 1));
                        }

                        if (x < 10)
                        {
                            AddWorldObject(new Tree(new Vector3Int(x, y, _surfacePoint), 1));
                        }
                    }
                }
            }

            Stopwatch s = new Stopwatch();
            s.Start();
            AssignRockLevels();
            s.Stop();
            DwarfConsole.WriteLine("AssignRockLevel time: " + s.Elapsed.TotalMilliseconds);
            UpdateAllTiles();
            UpdateAstar();
        }