public T this[string token] { set { BuildingStruct bld = new BuildingStruct(); if (token == "*") { bld = new BuildingStruct(-1, -1, -1); } else { if (!BuildingTokenList.BuildingLookup.ContainsKey(token)) { Debug.Log("Invalid building: " + token); return; } bld = BuildingTokenList.BuildingLookup[token].building_type; } if (buildingList == null) { buildingList = new Dictionary <BuildingStruct, T>(); } buildingList[bld] = value; } }
public bool Get(BuildingStruct bld, out T value) { if (buildingList != null) { T output; if (buildingList.TryGetValue(bld, out output)) { value = output; return(true); } bld = new BuildingStruct(bld.building_type, bld.building_subtype, -1);//Try once more with a more generic value. if (buildingList.TryGetValue(bld, out output)) { value = output; return(true); } bld = new BuildingStruct(bld.building_type, -1, -1); //and even more generic if (buildingList.TryGetValue(bld, out output)) { value = output; return(true); } bld = new BuildingStruct(-1, -1, -1); //and finally check if there's a universal default set. if (buildingList.TryGetValue(bld, out output)) { value = output; return(true); } } value = default(T); return(false); }
public override Response ApplyEffect(Cell cell, StateManager sm) { BuildingStruct building = new BuildingStruct(); // include info about the illuminated cell if (cell.building != null) { building.type = cell.building.type; building.religion = cell.building.religion; building.activeState = cell.building.activeState; building.level = cell.building.level; building.exists = true; } else { building.exists = false; } var res = new ApplyIlluminateSpellResponse { coord = cell.gridPos, building = building, buffs = cell.buffs, altitude = cell.ground.altitude, }; return(res); }
private static void AddPlant(string plant, string growth, string print, BuildingStruct index) { if (GrowthIDs == null) GrowthIDs = new Dictionary<string, Dictionary<string, Dictionary<string, BuildingStruct>>>(); if (!GrowthIDs.ContainsKey(plant)) GrowthIDs[plant] = new Dictionary<string, Dictionary<string, BuildingStruct>>(); if (!GrowthIDs[plant].ContainsKey(growth)) GrowthIDs[plant][growth] = new Dictionary<string, BuildingStruct>(); GrowthIDs[plant][growth][print] = index; }
public T this[BuildingStruct bld] { set { if (buildingList == null) { buildingList = new Dictionary <BuildingStruct, T>(); } buildingList[bld] = value; } }
public void SetBuildingOnCell(Cell cell, BuildingStruct building) { if (cell.building != null && cell.building.type != building.type) { Destroy(cell.building.gameObject); } instantiator.SpawnBuildingOnCellByType(cell, building.type); cell.building.hp = building.hp != 0 ? building.hp : cell.building.hp; cell.building.religion = building.religion != 0 ? building.religion : cell.building.religion; cell.building.activeState = building.activeState; cell.building.level = building.level != 0 ? building.level : cell.building.level; }
void TrySetMatch(GrowthMatch match, BuildingStruct growth) { if (matList == null) { matList = new Dictionary <BuildingStruct, GrowthMatch>(); } if (matList.ContainsKey(growth)) { if (matList[growth].difference < match.difference) //overwrite existing exact matches { return; //the comparitor can be changed to <= if that behavior is not desired. } } matList[growth] = match; }
public void BuyBuilding(BuildingStruct building) { if (CanBuyBuilding(building.key)) { buildingToPlace = building; hologramToDisplay = Instantiate(buildingToPlace.holoObject, transform.position, Quaternion.identity, transform); hologramToDisplay.GetComponent <Hologram>().shop = this; holoMaterial = hologramToDisplay.GetComponent <Renderer>(); tryingToPlace = true; } else { // TODO play SFX Debug.LogError("Not enough resources"); } }
private static void AddPlant(string plant, string growth, string print, BuildingStruct index) { if (GrowthIDs == null) { GrowthIDs = new Dictionary <string, Dictionary <string, Dictionary <string, BuildingStruct> > >(); } if (!GrowthIDs.ContainsKey(plant)) { GrowthIDs[plant] = new Dictionary <string, Dictionary <string, BuildingStruct> >(); } if (!GrowthIDs[plant].ContainsKey(growth)) { GrowthIDs[plant][growth] = new Dictionary <string, BuildingStruct>(); } GrowthIDs[plant][growth][print] = index; }
public bool TryGetValue(BuildingStruct growth, out T value) { if (matList != null) { GrowthMatch output; if (matList.TryGetValue(growth, out output)) { value = output.item; return(true); } growth = new BuildingStruct(growth.building_type, growth.building_subtype, -1); //Try once more with a more generic value. if (matList.TryGetValue(growth, out output)) { value = output.item; return(true); } } value = default(T); return(false); }
public T this[BuildingStruct growth] { get { T output; if (!TryGetValue(growth, out output)) { throw new KeyNotFoundException(); } return(output); } set { if (matList == null) { matList = new Dictionary <BuildingStruct, GrowthMatch>(); } GrowthMatch newItem; newItem.item = value; newItem.difference = 0; //a material pair will always be an exact match. matList[growth] = newItem; //actually, is that desired? } }
public void Modify (int? tileType = null, MatPairStruct? material = null, MatPairStruct? base_material = null, MatPairStruct? layer_material = null, MatPairStruct? vein_material = null, int? waterLevel = null, int? magmaLevel = null, MatPairStruct? construction_item = null, int? rampType = null, BuildingStruct? buildingType = null, MatPairStruct? buildingMaterial = null, DFCoord2d? buildingLocalPos = null, BuildingDirection? buildingDirection = null, bool? hidden = null) { if (tileType != null) { this.tileType = tileType.Value; } if (material != null) { this.material = material.Value; } if (base_material != null) { this.base_material = base_material.Value; } if (layer_material != null) { this.layer_material = layer_material.Value; } if (vein_material != null) { this.vein_material = vein_material.Value; } if (waterLevel != null) { this.waterLevel = waterLevel.Value; } if (magmaLevel != null) { this.magmaLevel = magmaLevel.Value; } if (construction_item != null) { this.construction_item = construction_item.Value; } if(rampType != null) { this.rampType = rampType.Value; } if(buildingType != null) { this.buildingType = buildingType.Value; } if(buildingMaterial != null) { this.buildingMaterial = buildingMaterial.Value; } if (buildingLocalPos != null) this.buildingLocalPos = buildingLocalPos.Value; if (buildingDirection != null) this.buildingDirection = buildingDirection.Value; if (hidden != null) this.hidden = hidden.Value; }
public override bool GetValue(MapDataStore.Tile tile, MeshLayer layer, out T value) { //let's just get rid of dead trees right away if (tile.special == TiletypeSpecial.DEAD || tile.special == TiletypeSpecial.SMOOTH_DEAD) { value = default(T); return(false); } int growthLayer = int.MaxValue; switch (layer) { case MeshLayer.GrowthMaterial: case MeshLayer.GrowthCutout: case MeshLayer.GrowthTransparent: growthLayer = 0; break; case MeshLayer.GrowthMaterial1: case MeshLayer.GrowthCutout1: case MeshLayer.GrowthTransparent1: growthLayer = 1; break; case MeshLayer.GrowthMaterial2: case MeshLayer.GrowthCutout2: case MeshLayer.GrowthTransparent2: growthLayer = 2; break; case MeshLayer.GrowthMaterial3: case MeshLayer.GrowthCutout3: case MeshLayer.GrowthTransparent3: growthLayer = 3; break; default: break; } MatPairStruct mat = tile.material; if (mat.mat_type != PlantType || mat.mat_index < 0 || DFConnection.Instance.NetPlantRawList == null || DFConnection.Instance.NetPlantRawList.plant_raws.Count <= mat.mat_index || DFConnection.Instance.NetPlantRawList.plant_raws[mat.mat_index].growths.Count <= growthLayer) { value = default(T); return(false); } TreeGrowth growth = DFConnection.Instance.NetPlantRawList.plant_raws[mat.mat_index].growths[growthLayer]; if (!tile.GrowthAppliesNow(growth)) { value = default(T); return(false); } int currentTicks = TimeHolder.DisplayedTime.CurrentYearTicks; GrowthPrint print = null; int printIndex = 0; for (int i = 0; i < growth.prints.Count; i++) { var tempPrint = growth.prints[i]; if (!((tempPrint.timing_start != -1 && tempPrint.timing_start > currentTicks) || (tempPrint.timing_end != -1 && tempPrint.timing_end < currentTicks))) { print = tempPrint; printIndex = i; } } if (print == null) { value = default(T); return(false); } BuildingStruct growthIndex = new BuildingStruct(mat.mat_index, growthLayer, printIndex); Content cont; if (growthMatcher.TryGetValue(growthIndex, out cont)) { value = cont.GetValue(tile, layer); return(true); } value = default(T); return(false); }
public BuildingTriple(BuildingStruct buildingStruct) { Power = buildingStruct.Power; Culture = buildingStruct.Culture; Building = buildingStruct.Building; }
public void InitOrModifyTile(DFCoord coord, int? tileType = null, MatPairStruct? material = null, MatPairStruct? base_material = null, MatPairStruct? layer_material = null, MatPairStruct? vein_material = null, int? waterLevel = null, int? magmaLevel = null, MatPairStruct? construction_item = null, int? rampType = null, BuildingStruct? buildingType = null, MatPairStruct? buildingMaterial = null, DFCoord2d? buildingLocalPos = null, BuildingDirection? buildingDirection = null, bool? hidden = null, byte? trunkPercent = null, DFCoord? positionOnTree = null, TileDigDesignation? digDesignation = null, List<Spatter> spatters = null) { if (!InSliceBounds(coord)) { throw new UnityException("Can't modify tile outside of slice"); } if (this[coord] == null) this[coord] = new Tile(this, coord); this[coord].Modify( tileType, material, base_material, layer_material, vein_material, waterLevel, magmaLevel, construction_item, rampType, buildingType, buildingMaterial, buildingLocalPos, buildingDirection, hidden, trunkPercent, positionOnTree, digDesignation, spatters ); }
public Tile(MapDataStore container, DFCoord position) { this.container = container; this.position = position; tileType = default(int); material = default(MatPairStruct); base_material = default(MatPairStruct); layer_material = default(MatPairStruct); vein_material = default(MatPairStruct); construction_item = default(MatPairStruct); waterLevel = default(int); magmaLevel = default(int); rampType = 0; buildingMaterial = default(MatPairStruct); buildingType = default(BuildingStruct); buildingLocalPos = default(DFCoord2d); buildingDirection = 0; Hidden = false; trunkPercent = 0; positionOnTree = default(DFCoord); digDesignation = TileDigDesignation.NO_DIG; spatters = null; }
public void CopyFrom(Tile orig) { container = orig.container; position = orig.position; tileType = orig.tileType; material = orig.material; base_material = orig.base_material; layer_material = orig.layer_material; vein_material = orig.vein_material; construction_item = orig.construction_item; waterLevel = orig.waterLevel; magmaLevel = orig.magmaLevel; RampType = orig.RampType; buildingType = orig.buildingType; buildingMaterial = orig.buildingMaterial; buildingLocalPos = orig.buildingLocalPos; buildingDirection = orig.buildingDirection; Hidden = orig.Hidden; trunkPercent = orig.trunkPercent; positionOnTree = orig.positionOnTree; digDesignation = orig.digDesignation; spatters = orig.spatters; }
public void Modify(int? tileType = null, MatPairStruct? material = null, MatPairStruct? base_material = null, MatPairStruct? layer_material = null, MatPairStruct? vein_material = null, int? waterLevel = null, int? magmaLevel = null, MatPairStruct? construction_item = null, int? rampType = null, BuildingStruct? buildingType = null, MatPairStruct? buildingMaterial = null, DFCoord2d? buildingLocalPos = null, BuildingDirection? buildingDirection = null, bool? hidden = null, byte? trunkPercent = null, DFCoord? positionOnTree = null, TileDigDesignation? digDesignation = null, List<Spatter> spatters = null) { if (tileType != null) { this.tileType = tileType.Value; } if (material != null) { this.material = material.Value; } if (base_material != null) { this.base_material = base_material.Value; } if (layer_material != null) { this.layer_material = layer_material.Value; } if (vein_material != null) { this.vein_material = vein_material.Value; } if (waterLevel != null) { this.waterLevel = waterLevel.Value; } if (magmaLevel != null) { this.magmaLevel = magmaLevel.Value; } if (construction_item != null) { this.construction_item = construction_item.Value; } if(rampType != null) { this.rampType = rampType.Value; } if(buildingType != null) { this.buildingType = buildingType.Value; } if(buildingMaterial != null) { this.buildingMaterial = buildingMaterial.Value; } if (buildingLocalPos != null) this.buildingLocalPos = buildingLocalPos.Value; if (buildingDirection != null) this.buildingDirection = buildingDirection.Value; if (hidden != null) Hidden = hidden.Value; if (trunkPercent != null) this.trunkPercent = trunkPercent.Value; if (positionOnTree != null) this.positionOnTree = positionOnTree.Value; if (digDesignation != null) this.digDesignation = digDesignation.Value; if (spatters != null) this.spatters = spatters; }
private void RemoveHologram() { Destroy(hologramToDisplay); buildingToPlace = new BuildingStruct(null, null, null); tryingToPlace = false; }
private void PlaceBuilding(BuildingStruct building) { Instantiate(buildingToPlace.building, hologramToDisplay.transform.position, hologramToDisplay.transform.rotation, BuildingsHolder); Economy._instance.AdjustResourceBalance(buildingToPlace.building.cost); RemoveHologram(); }
public void InitOrModifyTile(DFCoord coord, int? tileType = null, MatPairStruct? material = null, MatPairStruct? base_material = null, MatPairStruct? layer_material = null, MatPairStruct? vein_material = null, int? waterLevel = null, int? magmaLevel = null, MatPairStruct? construction_item = null, int? rampType = null, BuildingStruct? buildingType = null, MatPairStruct? buildingMaterial = null, DFCoord2d? buildingLocalPos = null) { DFCoord local = WorldToLocalSpace(coord); if (!InSliceBoundsLocal(local.x, local.y, local.z)) { throw new UnityException("Can't modify tile outside of slice"); } tilesPresent[PresentIndex(local.x, local.y, local.z)] = true; tiles[local.x, local.y, local.z].Modify(tileType, material, base_material, layer_material, vein_material, waterLevel, magmaLevel, construction_item, rampType, buildingType, buildingMaterial, buildingLocalPos); }
public Tile(MapDataStore container, DFCoord position) { this.container = container; this.position = position; tileType = default(int); material = default(MatPairStruct); base_material = default(MatPairStruct); layer_material = default(MatPairStruct); vein_material = default(MatPairStruct); construction_item = default(MatPairStruct); waterLevel = default(int); magmaLevel = default(int); rampType = 0; buildingMaterial = default(MatPairStruct); buildingType = default(BuildingStruct); buildingLocalPos = default(DFCoord2d); }
internal void LoadBlock(MapBlock block) { if (block.buildings.Count > 0) { loadedAnyBuildngs = true; } foreach (var building in block.buildings) { removedBuildings.Remove(building.index); if (building.pos_x_max == default(int) && building.pos_x_min == default(int) && building.pos_y_max == default(int) && building.pos_y_min == default(int) && building.pos_z_max == default(int) && building.pos_z_min == default(int)) { continue; } if (building.building_type.building_type == 30)//Civzone { continue; } BuildingModel builtBuilding; if (!sceneBuildings.ContainsKey(building.index)) { Profiler.BeginSample("Init Building " + building.index); BuildingStruct type = building.building_type; DFCoord origin = new DFCoord( (building.pos_x_min + building.pos_x_max) / 2, (building.pos_y_min + building.pos_y_max) / 2, building.pos_z_max); if (type.building_type == 19) //Bridge { switch (building.direction) { case BuildingDirection.NORTH: origin = new DFCoord( (building.pos_x_min + building.pos_x_max) / 2, building.pos_y_min, building.pos_z_max); break; case BuildingDirection.EAST: origin = new DFCoord( building.pos_x_max, (building.pos_y_min + building.pos_y_max) / 2, building.pos_z_max); break; case BuildingDirection.SOUTH: origin = new DFCoord( (building.pos_x_min + building.pos_x_max) / 2, building.pos_y_max, building.pos_z_max); break; case BuildingDirection.WEST: origin = new DFCoord( building.pos_x_min, (building.pos_y_min + building.pos_y_max) / 2, building.pos_z_max); break; case BuildingDirection.NONE: break; default: break; } } if (!buildingPrefabs.ContainsKey(type)) { type = new BuildingStruct(type.building_type, type.building_subtype, -1); } if (!buildingPrefabs.ContainsKey(type)) { type = new BuildingStruct(type.building_type, -1, -1); } if (!buildingPrefabs.ContainsKey(type)) { type = new BuildingStruct(-1, -1, -1); } if (buildingPrefabs.ContainsKey(type)) { builtBuilding = Instantiate(buildingPrefabs[type], GameMap.DFtoUnityCoord(origin), TranslateDirection(building.direction), transform); } else { builtBuilding = Instantiate(defaultBuilding, GameMap.DFtoUnityCoord(origin), TranslateDirection(building.direction), transform); } sceneBuildings[building.index] = builtBuilding; Profiler.EndSample(); } else { builtBuilding = sceneBuildings[building.index]; } Profiler.BeginSample("BuildingModel.Initialize"); builtBuilding.Initialize(building); Profiler.EndSample(); StoreBuildingInfo(building); } }
public void Modify(int?tileType = null, MatPairStruct?material = null, MatPairStruct?base_material = null, MatPairStruct?layer_material = null, MatPairStruct?vein_material = null, int?waterLevel = null, int?magmaLevel = null, MatPairStruct?construction_item = null, int?rampType = null, BuildingStruct?buildingType = null, MatPairStruct?buildingMaterial = null, DFCoord2d?buildingLocalPos = null, BuildingDirection?buildingDirection = null, bool?hidden = null, byte?trunkPercent = null, DFCoord?positionOnTree = null, TileDigDesignation?digDesignation = null, List <Spatter> spatters = null) { if (tileType != null) { this.tileType = tileType.Value; } if (material != null) { this.material = material.Value; } if (base_material != null) { this.base_material = base_material.Value; } if (layer_material != null) { this.layer_material = layer_material.Value; } if (vein_material != null) { this.vein_material = vein_material.Value; } if (waterLevel != null) { this.waterLevel = waterLevel.Value; } if (magmaLevel != null) { this.magmaLevel = magmaLevel.Value; } if (construction_item != null) { this.construction_item = construction_item.Value; } if (rampType != null) { this.rampType = rampType.Value; } if (buildingType != null) { this.buildingType = buildingType.Value; } if (buildingMaterial != null) { this.buildingMaterial = buildingMaterial.Value; } if (buildingLocalPos != null) { this.buildingLocalPos = buildingLocalPos.Value; } if (buildingDirection != null) { this.buildingDirection = buildingDirection.Value; } if (hidden != null) { Hidden = hidden.Value; } if (trunkPercent != null) { this.trunkPercent = trunkPercent.Value; } if (positionOnTree != null) { this.positionOnTree = positionOnTree.Value; } if (digDesignation != null) { this.digDesignation = digDesignation.Value; } if (spatters != null) { this.spatters = spatters; } }
public void InitOrModifyTile(DFCoord coord, int? tileType = null, MatPairStruct? material = null, MatPairStruct? base_material = null, MatPairStruct? layer_material = null, MatPairStruct? vein_material = null, int? waterLevel = null, int? magmaLevel = null, MatPairStruct? construction_item = null, int? rampType = null, BuildingStruct? buildingType = null, MatPairStruct? buildingMaterial = null, DFCoord2d? buildingLocalPos = null, BuildingDirection? buildingDirection = null, bool? hidden = null) { DFCoord local = WorldToLocalSpace(coord); if (!InSliceBoundsLocal(local.x, local.y, local.z)) { throw new UnityException("Can't modify tile outside of slice"); } if (tiles[local.x, local.y, local.z] == null) tiles[local.x, local.y, local.z] = new Tile(this, local); tiles[local.x, local.y, local.z].Modify(tileType, material, base_material, layer_material, vein_material, waterLevel, magmaLevel, construction_item, rampType, buildingType, buildingMaterial, buildingLocalPos, buildingDirection, hidden); }