Beispiel #1
0
        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);
                }
            }
        }