private static void AddCreatures(MapBlock _block, Random _rnd) { var itmcnt = 2 + _rnd.Next(_rnd.Next(2)); for (var i = 0; i < itmcnt; ++i) { var x = _rnd.Next(Constants.MAP_BLOCK_SIZE); var y = _rnd.Next(Constants.MAP_BLOCK_SIZE); var attr = TerrainAttribute.GetAttribute(_block.Map[x, y]); if (attr.IsPassable) { var point = new Point(x, y); if (_block.Creatures.Values.Contains(point)) { continue; } var creature = (AbstractMonster)EssenceHelper.GetRandomFakedCreature <AbstractMonster>(World.Rnd).Essence.Clone(World.TheWorld.Avatar); if (creature.Is <Stair>() && (x == Constants.MAP_BLOCK_SIZE - 1 || y == Constants.MAP_BLOCK_SIZE - 1)) { continue; } if (!_block.Rooms.Any(_room => _room.RoomRectangle.Contains(point) && _room.IsConnected)) { continue; } _block.CreaturesAdd(creature, point); } } }
protected override MapBlock GenerateBlock(Point _blockId) { var block = new MapBlock(_blockId); var rnd = new Random(block.RandomSeed); MapBlockHelper.Clear(block, rnd, this, DefaultEmptySpaces); const int v = Constants.MAP_BLOCK_SIZE / 2 - 2; for (var i = 0; i < v; ++i) { block.Map[i, 0] = ETerrains.STONE_WALL; block.Map[0, i] = ETerrains.STONE_WALL; block.Map[Constants.MAP_BLOCK_SIZE - 1 - i, 0] = ETerrains.STONE_WALL; block.Map[0, Constants.MAP_BLOCK_SIZE - 1 - i] = ETerrains.STONE_WALL; } block.AddEssence(new OnWallTorch(new LightSource(8, new FColor(5f, 1f, 0, 0)), EDirections.DOWN, EssenceHelper.GetFirstFoundedMaterial <WoodMaterial>()), new Point(1, 1)); block.AddEssence(new OnWallTorch(new LightSource(8, new FColor(1f, 0f, 1f, 0f)), EDirections.UP, EssenceHelper.GetFirstFoundedMaterial <WoodMaterial>()), new Point(Constants.MAP_BLOCK_SIZE - 1, Constants.MAP_BLOCK_SIZE - 1)); block.AddEssence(new OnWallTorch(new LightSource(8, new FColor(1f, 0f, 0f, 1f)), EDirections.RIGHT, EssenceHelper.GetFirstFoundedMaterial <WoodMaterial>()), new Point(Constants.MAP_BLOCK_SIZE - 1, 1)); block.AddEssence(new OnWallTorch(new LightSource(8, new FColor(1f, 1f, 0f, 1f)), EDirections.LEFT, EssenceHelper.GetFirstFoundedMaterial <WoodMaterial>()), new Point(1, Constants.MAP_BLOCK_SIZE - 1)); { var x = rnd.Next(Constants.MAP_BLOCK_SIZE); var y = rnd.Next(Constants.MAP_BLOCK_SIZE); block.CreaturesAdd(EssenceHelper.GetFirstFoundedCreature <AbstractMonster>(), new Point(x, y)); } block.Map[9, 9] = ETerrains.RED_BRICK_WALL; block.Map[10, 9] = ETerrains.RED_BRICK_WINDOW; block.Map[11, 9] = ETerrains.RED_BRICK_WALL; block.Map[11, 10] = ETerrains.RED_BRICK_WINDOW; block.Map[9, 10] = ETerrains.RED_BRICK_WINDOW; block.Map[9, 11] = ETerrains.RED_BRICK_WALL; block.AddEssence(new ClosedDoor(null), new Point(10, 11)); block.Map[11, 11] = ETerrains.RED_BRICK_WALL; //block.AddLightSource(new Point(10, 10), new LightSource(18, new FColor(53f, 0f, 1f, 1f))); return(block); }
protected override MapBlock GenerateBlock(Point _blockId) { var block = new MapBlock(_blockId); var rnd = new Random(block.RandomSeed); MapBlockHelper.Clear(block, rnd, this, DefaultEmptySpaces); const int v = Constants.MAP_BLOCK_SIZE/2 - 2; for (var i = 0; i < v; ++i) { block.Map[i, 0] = ETerrains.STONE_WALL; block.Map[0, i] = ETerrains.STONE_WALL; block.Map[Constants.MAP_BLOCK_SIZE - 1 - i, 0] = ETerrains.STONE_WALL; block.Map[0, Constants.MAP_BLOCK_SIZE - 1 - i] = ETerrains.STONE_WALL; } block.AddEssence(new OnWallTorch(new LightSource(8, new FColor(5f, 1f, 0, 0)), EDirections.DOWN, EssenceHelper.GetFirstFoundedMaterial<WoodMaterial>()), new Point(1, 1)); block.AddEssence(new OnWallTorch(new LightSource(8, new FColor(1f, 0f, 1f, 0f)), EDirections.UP, EssenceHelper.GetFirstFoundedMaterial<WoodMaterial>()), new Point(Constants.MAP_BLOCK_SIZE - 1, Constants.MAP_BLOCK_SIZE - 1)); block.AddEssence(new OnWallTorch(new LightSource(8, new FColor(1f, 0f, 0f, 1f)), EDirections.RIGHT, EssenceHelper.GetFirstFoundedMaterial<WoodMaterial>()), new Point(Constants.MAP_BLOCK_SIZE - 1, 1)); block.AddEssence(new OnWallTorch(new LightSource(8, new FColor(1f, 1f, 0f, 1f)), EDirections.LEFT, EssenceHelper.GetFirstFoundedMaterial<WoodMaterial>()), new Point(1, Constants.MAP_BLOCK_SIZE - 1)); { var x = rnd.Next(Constants.MAP_BLOCK_SIZE); var y = rnd.Next(Constants.MAP_BLOCK_SIZE); block.CreaturesAdd(EssenceHelper.GetFirstFoundedCreature<AbstractMonster>(), new Point(x, y)); } block.Map[9, 9] = ETerrains.RED_BRICK_WALL; block.Map[10, 9] = ETerrains.RED_BRICK_WINDOW; block.Map[11, 9] = ETerrains.RED_BRICK_WALL; block.Map[11, 10] = ETerrains.RED_BRICK_WINDOW; block.Map[9, 10] = ETerrains.RED_BRICK_WINDOW; block.Map[9, 11] = ETerrains.RED_BRICK_WALL; block.AddEssence(new ClosedDoor(null), new Point(10, 11)); block.Map[11, 11] = ETerrains.RED_BRICK_WALL; //block.AddLightSource(new Point(10, 10), new LightSource(18, new FColor(53f, 0f, 1f, 1f))); return block; }
private static void AddCreatures(MapBlock _block, Random _rnd) { var itmcnt = 2 + _rnd.Next(_rnd.Next(2)); for (var i = 0; i < itmcnt; ++i) { var x = _rnd.Next(Constants.MAP_BLOCK_SIZE); var y = _rnd.Next(Constants.MAP_BLOCK_SIZE); var attr = TerrainAttribute.GetAttribute(_block.Map[x, y]); if (attr.IsPassable) { var point = new Point(x, y); if (_block.Creatures.Values.Contains(point)) { continue; } var creature = (AbstractMonster)EssenceHelper.GetRandomFakedCreature<AbstractMonster>(World.Rnd).Essence.Clone(World.TheWorld.Avatar); if (creature.Is<Stair>() && (x == Constants.MAP_BLOCK_SIZE - 1 || y == Constants.MAP_BLOCK_SIZE - 1)) { continue; } if (!_block.Rooms.Any(_room => _room.RoomRectangle.Contains(point) && _room.IsConnected)) { continue; } _block.CreaturesAdd(creature, point); } } }
public override void GenerateCityBlock(MapBlock _block, Random _rnd, WorldLayer _layer) { var roadPoints = new List <Point>(); for (var i = 0; i < Constants.MAP_BLOCK_SIZE; ++i) { if (_rnd.Next(2) == 0) { roadPoints.Add(new Point(0, i)); } if (_rnd.Next(2) == 0) { roadPoints.Add(new Point(1, i)); } if (_rnd.Next(2) == 0) { roadPoints.Add(new Point(i, 0)); } if (_rnd.Next(2) == 0) { roadPoints.Add(new Point(i, 1)); } } if (roadPoints.All(point => TerrainAttribute.GetAttribute(_block.Map[point.X, point.Y]).IsPassable)) { foreach (var point in roadPoints) { _block.Map[point.X, point.Y] = ETerrains.ROAD; } } var terrains = m_buildings.Where(_building => _building.BlockId == _block.BlockId).ToDictionary(_b => _b, _building => _building.Room.AreaRectangle.AllPoints.Select(_point => _block.Map[_point.X, _point.Y]).Distinct().ToArray()); foreach (var pair in terrains) { if (pair.Value.Any(_terrains => TerrainAttribute.GetAttribute(_terrains).IsNotPassable)) { m_buildings.Remove(pair.Key); } } var buildings = m_buildings.Where(_pair => _pair.BlockId == _block.BlockId).ToArray(); foreach (var building in buildings) { _block.AddRoom(building.Room); building.Fill(_block, _layer); var citizens = m_citizens.Where(_citizen => _citizen.Roles.OfType <AbstractCitizenRole>().First().Building == building).ToArray(); foreach (var citizen in citizens) { if (m_already.Contains(citizen)) { throw new ApplicationException(); } m_already.Add(citizen); Tuple <ETileset, FColor> tuple = null; foreach (var color in citizen.Roles.First().Colors) { tuple = Tuple.Create(citizen.Tileset, color); if (!m_conf.Contains(tuple)) { break; } } if (tuple == null) { throw new ApplicationException(); } m_conf.Add(tuple); citizen.SetLerpColor(tuple.Item2); _block.CreaturesAdd(citizen, building.Room.RoomRectangle.Center); } } }