private void UpdateFlags(Creature selectedUnit) { for (int i = 0; i < 32; i++) { uint item = 1u << i; UnitFlags1 flag = (UnitFlags1)item; string name = flag.ToString(); bool enabled = (selectedUnit.flags1 & flag) == flag; flag1List[i].Enabled = enabled; } for (int i = 0; i < 32; i++) { uint item = 1u << i; UnitFlags2 flag = (UnitFlags2)item; string name = flag.ToString(); bool enabled = (selectedUnit.flags2 & flag) == flag; flag2List[i].Enabled = enabled; } for (int i = 0; i < 29; i++) { uint item = 1u << i; UnitFlags3 flag = (UnitFlags3)item; string name = flag.ToString(); bool enabled = (selectedUnit.flags3 & flag) == flag; flag3List[i].Enabled = enabled; } }
public MainWindow() { InitializeComponent(); UnitList = new ObservableCollection <Creature>(); RaceList = new ObservableCollection <Creature>(); flag1List = new ObservableCollection <FlagDisplay>(); flag2List = new ObservableCollection <FlagDisplay>(); flag3List = new ObservableCollection <FlagDisplay>(); unitListView.ItemsSource = UnitList; raceListView.ItemsSource = RaceList; flags1ListView.ItemsSource = flag1List; flags2ListView.ItemsSource = flag2List; flags3ListView.ItemsSource = flag3List; for (int i = 0; i < 32; i++) { uint item = 1u << i; UnitFlags1 flag = (UnitFlags1)item; string name = flag.ToString(); name = name.Replace('_', ' '); name = TI.ToTitleCase(name); flag1List.Add(new FlagDisplay() { Name = name, Enabled = false }); } for (int i = 0; i < 32; i++) { uint item = 1u << i; UnitFlags2 flag = (UnitFlags2)item; string name = flag.ToString(); name = name.Replace('_', ' '); name = TI.ToTitleCase(name); flag2List.Add(new FlagDisplay() { Name = name, Enabled = false }); } for (int i = 0; i < 29; i++) { uint item = 1u << i; UnitFlags3 flag = (UnitFlags3)item; string name = flag.ToString(); name = name.Replace('_', ' '); name = TI.ToTitleCase(name); flag3List.Add(new FlagDisplay() { Name = name, Enabled = false }); } }
public static bool IsValidCreature(UnitDefinition unit) { UnitFlags1 flags1 = (UnitFlags1)unit.flags1; if (((flags1 & UnitFlags1.dead) == UnitFlags1.dead) || ((flags1 & UnitFlags1.left) == UnitFlags1.left) || ((flags1 & UnitFlags1.caged) == UnitFlags1.caged) || ((flags1 & UnitFlags1.forest) == UnitFlags1.forest) ) { return(false); } return(true); }
void UpdateSpriteUnit(UnitDefinition unit, ref int creatureCount) { UnitFlags1 flags1 = (UnitFlags1)unit.flags1; //UnitFlags2 flags2 = (UnitFlags2)unit.flags2; //UnitFlags3 flags3 = (UnitFlags3)unit.flags3; if (!IsValidCreature(unit)) { if (creatureList.ContainsKey(unit.id)) { Destroy(creatureList[unit.id].gameObject); creatureList.Remove(unit.id); } } else { MapDataStore.Tile tile = null; if (MapDataStore.Main != null) { tile = MapDataStore.Main[unit.pos_x, unit.pos_y, unit.pos_z]; } if (!ShouldRender(unit.pos_x, unit.pos_y, unit.pos_z, tile) && !singleRow) { if (creatureList.ContainsKey(unit.id)) { creatureList[unit.id].gameObject.SetActive(false); } return; } else if (creatureList.ContainsKey(unit.id)) { creatureList[unit.id].gameObject.SetActive(true); } if (!creatureList.ContainsKey(unit.id)) { creatureList[unit.id] = Instantiate(creatureTemplate, gameObject.transform); creatureList[unit.id].name = "Unit_" + unit.id; creatureList[unit.id].transform.position = new Vector3(-3000, -3000, -3000); } if (creatureList[unit.id].gameObject.activeSelf) //Only update stuff if it's actually visible. { if (singleRow) { creatureList[unit.id].transform.position = new Vector3(creatureCount * spacing, 0, 0); } else { var position = GameMap.DFtoUnityCoord(unit.pos_x + unit.subpos_x, unit.pos_y + unit.subpos_y, unit.pos_z + unit.subpos_z); //RaycastHit hitInfo; //if (((flags1 & UnitFlags1.projectile) != UnitFlags1.projectile) && Physics.Raycast(position + new Vector3(0, 2.9f, 0), Vector3.down, out hitInfo, 3, Physics.DefaultRaycastLayers, QueryTriggerInteraction.Ignore)) // creatureList[unit.id].TargetPos = hitInfo.point; //else creatureList[unit.id].TargetPos = position + new Vector3(0, GameMap.floorHeight, 0); } if (unit.rider_id >= 0 && creatureList.ContainsKey(unit.rider_id)) { creatureList[unit.id].TargetPos += new Vector3(0, creatureList[unit.rider_id].transform.localScale.y, 0); } UnitScaler unitScaler = creatureList[unit.id].GetComponentInChildren <UnitScaler>(); if (unitScaler != null) { unitScaler.UpdateSize(unit, creatureList[unit.id].GetComponentInChildren <LayeredSprite>()); } CameraFacing cameraFacing = creatureList[unit.id].GetComponentInChildren <CameraFacing>(); if ((flags1 & UnitFlags1.on_ground) == UnitFlags1.on_ground) { cameraFacing.transform.localPosition = Vector3.zero; cameraFacing.enabled = false; cameraFacing.transform.rotation = Quaternion.Euler(90, 0, 0); } else { cameraFacing.transform.localPosition = new Vector3(0, 1, 0); cameraFacing.enabled = true; } creatureList[unit.id].UpdateCreature(unit); } creatureCount++; } }
private void Update3DUnit(UnitDefinition unit, ref int creatureCount) { UnitFlags1 flags1 = (UnitFlags1)unit.flags1; //UnitFlags2 flags2 = (UnitFlags2)unit.flags2; //UnitFlags3 flags3 = (UnitFlags3)unit.flags3; if (!IsValidCreature(unit)) { if (creatureList3D.ContainsKey(unit.id)) { Destroy(creatureList3D[unit.id].gameObject); creatureList3D.Remove(unit.id); } return; } MapDataStore.Tile tile = null; if (MapDataStore.Main != null) { tile = MapDataStore.Main[unit.pos_x, unit.pos_y, unit.pos_z]; } if (!ShouldRender(unit.pos_x, unit.pos_y, unit.pos_z, tile) && !singleRow) { if (creatureList3D.ContainsKey(unit.id)) { creatureList3D[unit.id].gameObject.SetActive(false); } return; } else if (creatureList3D.ContainsKey(unit.id)) { creatureList3D[unit.id].gameObject.SetActive(true); } if (!creatureList3D.ContainsKey(unit.id)) { var creatureBase = new GameObject().AddComponent <CreatureBody>(); creatureBase.race = CreatureRaws.Instance[unit.race.mat_type]; creatureBase.caste = creatureBase.race.caste[unit.race.mat_index]; creatureBase.unit = unit; if (string.IsNullOrEmpty(unit.name)) { creatureBase.name = creatureBase.race.name[0]; } else { creatureBase.name = unit.name; } creatureList3D[unit.id] = creatureBase; creatureBase.transform.parent = transform; } var placedUnit = creatureList3D[unit.id]; if (!placedUnit.gameObject.activeSelf) { return; } placedUnit.UpdateUnit(unit); if (unit.rider_id >= 0 && creatureList3D.ContainsKey(unit.rider_id)) { placedUnit.transform.parent = creatureList3D[unit.rider_id].transform; if (creatureList3D[unit.rider_id].riderPosition == null) { placedUnit.transform.position = creatureList3D[unit.rider_id].rootPart.transform.position; placedUnit.transform.rotation = creatureList3D[unit.rider_id].rootPart.transform.rotation; } else { placedUnit.transform.position = creatureList3D[unit.rider_id].riderPosition.transform.position; placedUnit.transform.rotation = creatureList3D[unit.rider_id].riderPosition.transform.rotation; } } else { placedUnit.transform.parent = transform; placedUnit.transform.position = GameMap.DFtoUnityCoord(unit.pos_x + unit.subpos_x, unit.pos_y + unit.subpos_y, unit.pos_z + unit.subpos_z) + new Vector3(0, GameMap.floorHeight, 0); } }
void UpdateCreatures() { unitList = DFConnection.Instance.PopUnitListUpdate(); if (unitList == null) { return; } foreach (var unit in unitList.creature_list) { if (creatureList == null) { creatureList = new Dictionary <int, AtlasSprite>(); } UnitFlags1 flags1 = (UnitFlags1)unit.flags1; //UnitFlags2 flags2 = (UnitFlags2)unit.flags2; //UnitFlags3 flags3 = (UnitFlags3)unit.flags3; if (((flags1 & UnitFlags1.dead) == UnitFlags1.dead) || ((flags1 & UnitFlags1.left) == UnitFlags1.left)) { if (creatureList.ContainsKey(unit.id)) { Destroy(creatureList[unit.id]); creatureList.Remove(unit.id); } } else { CreatureRaw creatureRaw = null; if (DFConnection.Instance.NetCreatureRawList != null) { creatureRaw = DFConnection.Instance.NetCreatureRawList.creature_raws[unit.race.mat_type]; } if (!creatureList.ContainsKey(unit.id)) { creatureList[unit.id] = Instantiate(creatureTemplate); creatureList[unit.id].transform.parent = gameObject.transform; creatureList[unit.id].ClearMesh(); Color color = new Color(unit.profession_color.red / 255.0f, unit.profession_color.green / 255.0f, unit.profession_color.blue / 255.0f, 1); if (creatureRaw != null) { creatureList[unit.id].AddTile(creatureRaw.creature_tile, color); } } creatureList[unit.id].gameObject.SetActive(unit.pos_z <PosZ && unit.pos_z> (PosZ - cameraViewDist)); if (creatureList[unit.id].gameObject.activeSelf) //Only update stuff if it's actually visible. { Vector3 position = DFtoUnityCoord(unit.pos_x, unit.pos_y, unit.pos_z); if ((flags1 & UnitFlags1.on_ground) == UnitFlags1.on_ground) { creatureList[unit.id].transform.position = position + new Vector3(0, 0.51f, 0); creatureList[unit.id].cameraFacing.enabled = false; creatureList[unit.id].transform.rotation = Quaternion.Euler(90, 0, 0); } else { creatureList[unit.id].transform.position = position + new Vector3(0, 1.5f, 0); creatureList[unit.id].cameraFacing.enabled = true; } creatureList[unit.id].SetColor(0, new Color(unit.profession_color.red / 255.0f, unit.profession_color.green / 255.0f, unit.profession_color.blue / 255.0f, 1)); if (creatureRaw != null) { if (unit.is_soldier) { creatureList[unit.id].SetTile(0, creatureRaw.creature_soldier_tile); } else { creatureList[unit.id].SetTile(0, creatureRaw.creature_tile); } } } } } }
void ShowCursorInfo() { cursorProperties.text = ""; cursorProperties.text += "Cursor: "; cursorProperties.text += cursX + ","; cursorProperties.text += cursY + ","; cursorProperties.text += cursZ + "\n"; var maybeTile = MapDataStore.Main[cursX, cursY, cursZ]; if (maybeTile != null) { var tile = maybeTile.Value; cursorProperties.text += "Tiletype:\n"; var tiletype = DFConnection.Instance.NetTiletypeList.tiletype_list [tile.tileType]; cursorProperties.text += tiletype.name + "\n"; cursorProperties.text += tiletype.shape + ":" + tiletype.special + ":" + tiletype.material + ":" + tiletype.variant + ":" + tiletype.direction + "\n"; var mat = tile.material; cursorProperties.text += "Material: "; cursorProperties.text += mat.mat_type + ","; cursorProperties.text += mat.mat_index + "\n"; if (materials.ContainsKey(mat)) { cursorProperties.text += "Material Name: "; cursorProperties.text += materials[mat].id + "\n"; } else { cursorProperties.text += "Unknown Material\n"; } cursorProperties.text += "\n"; var basemat = tile.base_material; cursorProperties.text += "Base Material: "; cursorProperties.text += basemat.mat_type + ","; cursorProperties.text += basemat.mat_index + "\n"; if (materials.ContainsKey(basemat)) { cursorProperties.text += "Base Material Name: "; cursorProperties.text += materials[basemat].id + "\n"; } else { cursorProperties.text += "Unknown Base Material\n"; } cursorProperties.text += "\n"; var layermat = tile.layer_material; cursorProperties.text += "Layer Material: "; cursorProperties.text += layermat.mat_type + ","; cursorProperties.text += layermat.mat_index + "\n"; if (materials.ContainsKey(layermat)) { cursorProperties.text += "Layer Material Name: "; cursorProperties.text += materials[layermat].id + "\n"; } else { cursorProperties.text += "Unknown Layer Material\n"; } cursorProperties.text += "\n"; var veinmat = tile.vein_material; cursorProperties.text += "Vein Material: "; cursorProperties.text += veinmat.mat_type + ","; cursorProperties.text += veinmat.mat_index + "\n"; if (materials.ContainsKey(veinmat)) { cursorProperties.text += "Vein Material Name: "; cursorProperties.text += materials[veinmat].id + "\n"; } else { cursorProperties.text += "Unknown Vein Material\n"; } cursorProperties.text += "\n"; var cons = tile.construction_item; cursorProperties.text += "Construction Item: "; cursorProperties.text += cons.mat_type + ","; cursorProperties.text += cons.mat_index + "\n"; if (materials.ContainsKey(cons)) { cursorProperties.text += "Construction Item Name: "; cursorProperties.text += items[cons].id + "\n"; } else { cursorProperties.text += "Unknown Construction Item\n"; } } if (unitList != null) { foreach (UnitDefinition unit in unitList.creature_list) { UnitFlags1 flags1 = (UnitFlags1)unit.flags1; UnitFlags2 flags2 = (UnitFlags2)unit.flags2; UnitFlags3 flags3 = (UnitFlags3)unit.flags3; if (((flags1 & UnitFlags1.dead) == UnitFlags1.dead) || ((flags1 & UnitFlags1.left) == UnitFlags1.left)) { continue; } if (unit.pos_x != cursX || unit.pos_y != cursY || unit.pos_z != cursZ) { continue; } CreatureRaw creatureRaw = null; if (DFConnection.Instance.NetCreatureRawList != null) { creatureRaw = DFConnection.Instance.NetCreatureRawList.creature_raws[unit.race.mat_type]; } if (creatureRaw != null) { cursorProperties.text += "Unit: \n"; cursorProperties.text += "Race: "; cursorProperties.text += creatureRaw.creature_id + ":"; cursorProperties.text += creatureRaw.caste[unit.race.mat_index].caste_id; cursorProperties.text += "\n"; cursorProperties.text += flags1 + "\n"; cursorProperties.text += flags2 + "\n"; cursorProperties.text += flags3 + "\n"; } break; } } }
void UpdateCreatures() { if (!GameSettings.Instance.units.drawUnits) { return; } if (creatureTemplate == null) { return; } if (ContentLoader.Instance == null) { return; } var tempUnitList = DFConnection.Instance.PopUnitListUpdate(); if (tempUnitList == null) { return; } else { Units = tempUnitList; } UnityEngine.Profiling.Profiler.BeginSample("UpdateCreatures", this); int creatureCount = 0; foreach (var unit in Units.creature_list) { if (creatureList == null) { creatureList = new Dictionary <int, Creature>(); } UnitFlags1 flags1 = (UnitFlags1)unit.flags1; //UnitFlags2 flags2 = (UnitFlags2)unit.flags2; //UnitFlags3 flags3 = (UnitFlags3)unit.flags3; if (((flags1 & UnitFlags1.dead) == UnitFlags1.dead) || ((flags1 & UnitFlags1.left) == UnitFlags1.left) || ((flags1 & UnitFlags1.caged) == UnitFlags1.caged) || ((flags1 & UnitFlags1.forest) == UnitFlags1.forest) ) { if (creatureList.ContainsKey(unit.id)) { Destroy(creatureList[unit.id].gameObject); creatureList.Remove(unit.id); } } else { if (!creatureList.ContainsKey(unit.id)) { creatureList[unit.id] = Instantiate(creatureTemplate, gameObject.transform); creatureList[unit.id].name = "Unit_" + unit.id; creatureList[unit.id].transform.position = new Vector3(-3000, -3000, -3000); } if (!singleRow) { MapDataStore.Tile tile = null; if (MapDataStore.Main != null) { tile = MapDataStore.Main[unit.pos_x, unit.pos_y, unit.pos_z]; } creatureList[unit.id].gameObject.SetActive( (unit.pos_z < (GameMap.Instance.firstPerson ? GameMap.Instance.PosZ + GameSettings.Instance.rendering.drawRangeUp : GameMap.Instance.PosZ)) && unit.pos_z >= (GameMap.Instance.PosZ - GameSettings.Instance.rendering.drawRangeDown) && (unit.pos_x / GameMap.blockSize > (GameMap.Instance.PosXBlock - GameSettings.Instance.rendering.drawRangeSide)) && (unit.pos_x / GameMap.blockSize < (GameMap.Instance.PosXBlock + GameSettings.Instance.rendering.drawRangeSide)) && (unit.pos_y / GameMap.blockSize > (GameMap.Instance.PosYBlock - GameSettings.Instance.rendering.drawRangeSide)) && (unit.pos_y / GameMap.blockSize < (GameMap.Instance.PosYBlock + GameSettings.Instance.rendering.drawRangeSide)) && (tile != null ? !tile.Hidden : true) ); } if (creatureList[unit.id].gameObject.activeSelf) //Only update stuff if it's actually visible. { if (singleRow) { creatureList[unit.id].transform.position = new Vector3(creatureCount * spacing, 0, 0); } else { var position = GameMap.DFtoUnityCoord(unit.pos_x + unit.subpos_x, unit.pos_y + unit.subpos_y, unit.pos_z + unit.subpos_z); RaycastHit hitInfo; if (((flags1 & UnitFlags1.projectile) != UnitFlags1.projectile) && Physics.Raycast(position + new Vector3(0, 2.9f, 0), Vector3.down, out hitInfo, 3, Physics.DefaultRaycastLayers, QueryTriggerInteraction.Ignore)) { creatureList[unit.id].TargetPos = hitInfo.point; } else { creatureList[unit.id].TargetPos = position + new Vector3(0, GameMap.floorHeight, 0); } } if (unit.rider_id >= 0 && creatureList.ContainsKey(unit.rider_id)) { creatureList[unit.id].TargetPos += new Vector3(0, creatureList[unit.rider_id].transform.localScale.y, 0); } UnitScaler unitScaler = creatureList[unit.id].GetComponentInChildren <UnitScaler>(); if (unitScaler != null) { unitScaler.UpdateSize(unit, creatureList[unit.id].GetComponentInChildren <LayeredSprite>()); } CameraFacing cameraFacing = creatureList[unit.id].GetComponentInChildren <CameraFacing>(); if ((flags1 & UnitFlags1.on_ground) == UnitFlags1.on_ground) { cameraFacing.transform.localPosition = Vector3.zero; cameraFacing.enabled = false; cameraFacing.transform.rotation = Quaternion.Euler(90, 0, 0); } else { cameraFacing.transform.localPosition = new Vector3(0, 1, 0); cameraFacing.enabled = true; } creatureList[unit.id].GetComponent <Creature>().UpdateCreature(unit); } creatureCount++; } } UnityEngine.Profiling.Profiler.EndSample(); }