public void Init(SimMapType mapType, SimBox box, int sizeX, int sizeY) { this.id = mapType.id; this.mapType = mapType; this.box = box; values = new int[sizeX * sizeY]; this.sizeX = sizeX; this.sizeY = sizeY; context.box = box; context.mapPositionRadius = 0; }
private void ParseMap() { string line = GetNextLine(); string[] lineSplit = SplitLine(line); if (lineSplit.Length == 1) { ThrowInvalidLine("ParseMap()"); } SimMapType mapType = new SimMapType(); mapType.id = lineSplit[1]; mapType.rules = new SimRuleMap[0]; int splitOffset = 2; while (splitOffset < lineSplit.Length) { switch (lineSplit[splitOffset++]) { case "color": mapType.color = ParseUint(lineSplit[splitOffset++]); break; case "capacity": mapType.capacity = ParseInt(lineSplit[splitOffset++]); break; case "rules": { string[] rulesIds = ParseStringArray(lineSplit, ref splitOffset); mapType.rules = FindRules <SimRuleMap>(rulesIds); break; } default: ThrowInvalidLine("ParseMap()"); break; } } definition.mapTypes.Add(mapType.id, mapType); }
public SimMap AddMap(SimMapType mapType) { if (mapType == null) { throw new ArgumentNullException("mapType"); } if (GetMap(mapType.id) != null) { throw new ArgumentException("Duplicated mapType", "mapType"); } SimMap map = new SimMap(); map.Init(mapType, this, gridSizeX, gridSizeY); maps.Add(map.id, map); boxListener.OnMapAdded(map); return(map); }
private SimulationDefinition CreateDefinition() { SimulationDefinition definition = new SimulationDefinition(); SimResource resourceWater = new SimResource(); resourceWater.id = "Water"; SimResource resourceGrass = new SimResource(); resourceGrass.id = "Grass"; definition.resourceTypes.Add(resourceWater.id, resourceWater); definition.resourceTypes.Add(resourceGrass.id, resourceGrass); //Add 2 of water every 10 ticks SimRuleValueMap valueMapWater = new SimRuleValueMap(); valueMapWater.mapId = "Water"; SimRuleCommandAdd commandAddWater = new SimRuleCommandAdd(); commandAddWater.amount = 2; commandAddWater.target = valueMapWater; SimRuleMap ruleMapAddWater = new SimRuleMap(); ruleMapAddWater.id = "AddWater"; ruleMapAddWater.rate = 10; ruleMapAddWater.randomTiles = true; ruleMapAddWater.randomTilesPercent = 25; ruleMapAddWater.commands = new SimRuleCommand[] { commandAddWater }; //Water Map SimMapType mapTypeWater = new SimMapType(); mapTypeWater.id = "Water"; mapTypeWater.color = 0x0000FF; mapTypeWater.capacity = 100; mapTypeWater.rules = new SimRuleMap[] { ruleMapAddWater }; definition.mapTypes.Add(mapTypeWater.id, mapTypeWater); //Add grass every 7 ticks if there is 10 of water available SimRuleValueMap valueMapGrass = new SimRuleValueMap(); valueMapGrass.mapId = "Grass"; SimRuleCommandRemove commandRemoveWater = new SimRuleCommandRemove(); commandRemoveWater.amount = 10; commandRemoveWater.target = valueMapWater; SimRuleCommandAdd commandAddGrass = new SimRuleCommandAdd(); commandAddGrass.amount = 1; commandAddGrass.target = valueMapGrass; SimRuleMap ruleMapCreateGrass = new SimRuleMap(); ruleMapCreateGrass.id = "CreateGrass"; ruleMapCreateGrass.rate = 7; ruleMapCreateGrass.commands = new SimRuleCommand[] { commandRemoveWater, commandAddGrass }; //Grass Map SimMapType mapTypeGrass = new SimMapType(); mapTypeGrass.id = "Grass"; mapTypeGrass.color = 0x00FF00; mapTypeGrass.capacity = 10; mapTypeGrass.rules = new SimRuleMap[] { ruleMapCreateGrass }; definition.mapTypes.Add(mapTypeGrass.id, mapTypeGrass); return(definition); }