/// <summary>
        /// Return a list of tuples (IAgent, float), where float is the period in seconds at which the agent should be executed.
        /// </summary>
        public World Create()
        {
            Contract.Requires(this.Size.X > 0, "size.X must be positive");
            Contract.Requires(this.Size.Y > 0, "size.Y must be positive");

            WorldRules rules = this.WorldRulesFactory.Create(this.Random);

            var terrainMap  = this.TerrainGenerator.GenerateTerrainMap(rules, this.Size);
            var zoneMap     = new ArrayMap <int>(this.Size, rules.Zones[Zones.Empty]);
            var buildingMap = new ArrayMap <int>(this.Size, MapTypes.NoBuilding);

            Maps maps = new Maps(this.Size);

            terrainMap.RegisterTerrain(maps);
            zoneMap.RegisterZone(maps);
            buildingMap.RegisterBuilding(maps);

            var buildings = new AnonymousEntities(MapTypes.Building);

            foreach (var buildingComponents in rules.BuildingComponents.Values)
            {
                buildings.Extend(buildingComponents);
            }

            return(new World(maps, buildings, rules, new Ticker(), new RoadGraph(zoneMap, rules.Zones[Zones.Road])));
        }
        public Action <World> Execute(IWorldView worldView)
        {
            Contract.Requires(worldView != null);

            List <(Vector, int)> posBuildingModelToBuild = worldView.GetZoneMapView()
                                                           .GetAllPositions()
                                                           .Select(p => (p, this.buildingConstructorVoter.Vote(p)))
                                                           .Where(posBuildingModelTuple => posBuildingModelTuple.Item2 != BuildingModels.NoModel)
                                                           .ToList();

            return((world) =>
            {
                IMap <int> buildingMap = world.GetBuildingMap();
                IMap <int> zoneMap = world.GetZoneMap();
                AnonymousEntities buildings = world.Buildings;
                TypedComponents <int> buildingVariant = buildings.GetMutableTypedComponents <int>(BuildingVariants.Component);
                TypedComponents <int> buildingModels = buildings.GetMutableTypedComponents <int>(Buildings.BuildingModelComponent);
                TypedComponents <Vector> buildingLocations = buildings.GetMutableTypedComponents <Vector>(Buildings.LocationComponent);
                Random random = world.Rules.Random;

                foreach (var posBuildingModelTuple in posBuildingModelToBuild
                         .Where((posBuildingModelTuple) => buildingMap[posBuildingModelTuple.Item1] == MapTypes.NoBuilding))
                {
                    int buildingId = buildings.Register();
                    buildingVariant[buildingId] = random.Next();
                    buildingLocations[buildingId] = posBuildingModelTuple.Item1;
                    buildingModels[buildingId] = posBuildingModelTuple.Item2;

                    buildingMap[posBuildingModelTuple.Item1] = buildingId;
                }
            });
        }
Beispiel #3
0
 public World(Maps maps, AnonymousEntities buildings, WorldRules rules, Ticker ticker, IGraph <Vector> transportGraph)
 {
     this.maps           = maps;
     this.Buildings      = buildings;
     this.Rules          = rules;
     this.ticker         = ticker;
     this.transportGraph = transportGraph;
 }