public T GetPrefab(VirtualCell.CellType cell_type, VirtualMap.DirectionType orientation = VirtualMap.DirectionType.None) { S[] type_choices = null; type_choices = GetVariations(cell_type, orientation); if (type_choices == null) { return(default(T)); } // Get one with a weighted random int tot = 0; foreach (S choice in type_choices) { tot += choice.weight; } int rnd = DungeonGenerator.Random.Instance.Next(1, tot); // Debug.Log(cell_type + " " + tot + " " + rnd); int current = 0; foreach (S choice in type_choices) { current += choice.weight; if (rnd <= current) { // Debug.Log("YTYPE " + cell_type + " CHOICE: " + choice.choice); return(choice.choice); } } return(default(T)); }
// 3D protected void ConvertCeiling(VirtualMap map, VirtualCell conversion_cell) { // Checking if we need to add a ceiling VirtualCell.CellType cell_type = conversion_cell.Type; //Debug.Log(conversion_cell); if (conversion_cell.IsFloor()) { VirtualCell.CellType ceiling_type = VirtualCell.CellType.None; if (VirtualCell.IsRoomFloor(cell_type)) { if (behaviour.addCeilingToRooms) { ceiling_type = VirtualCell.CellType.RoomCeiling; } } else { if (behaviour.addCeilingToCorridors) { ceiling_type = VirtualCell.CellType.CorridorCeiling; } } if (ceiling_type != VirtualCell.CellType.None) { conversion_cell.AddCellInstance(ceiling_type, conversion_cell.Orientation); } } }
override public void CreateObject(VirtualMap map, MetricLocation l, VirtualCell.CellType cell_type, VirtualMap.DirectionType orientation) { GameObject prefab = behaviour.GetPrefab(cell_type); DaedalusDebugUtils.Assert(prefab != null, "No variation was chosen for " + cell_type); GameObject go = (GameObject)GameObject.Instantiate(prefab, new Vector3(l.x * behaviour.tileSize, l.storey * (behaviour.wallHeight + behaviour.storeySeparationHeight), l.y * behaviour.tileSize), Quaternion.identity); go.name = cell_type.ToString(); if (orientation == VirtualMap.DirectionType.None) { orientation = VirtualMap.DirectionType.North; } switch (orientation) { case VirtualMap.DirectionType.West: go.transform.localEulerAngles = new Vector3(0, 180, 0); break; case VirtualMap.DirectionType.North: go.transform.localEulerAngles = new Vector3(0, 270, 0); break; case VirtualMap.DirectionType.East: go.transform.localEulerAngles = new Vector3(0, 0, 0); break; case VirtualMap.DirectionType.South: go.transform.localEulerAngles = new Vector3(0, 90, 0); break; } go.transform.localEulerAngles += new Vector3(0, 180, 0); // Orientation fix AddToMapGameObject(cell_type, go, cell_type == VirtualCell.CellType.Door, l.storey); }
protected void BuildObject(VirtualMap map, CellLocation loc, int storey, VirtualCell.CellType type, VirtualMap.DirectionType dir) { if (type == VirtualCell.CellType.None || type == VirtualCell.CellType.EmptyPassage) { return; // TODO: Maybe this check should be in the physical map } // Debug.Log (loc + " " + type); MetricLocation metricLocation = GetWorldLocation(loc, storey); physical_map.CreateObject(map, metricLocation, type, dir); }
override public void CreateObject(VirtualMap map, MetricLocation l, VirtualCell.CellType cell_type, VirtualMap.DirectionType orientation) { GameObject go = null; if (alreadyCreated && currentIndex < spawnedSpriteGos.Count) { go = spawnedSpriteGos[currentIndex]; currentIndex++; } else { go = (GameObject)GameObject.Instantiate(behaviour.spritePrefab, new Vector3(l.x * behaviour.tileSize, 0, l.y * behaviour.tileSize), Quaternion.identity); spawnedSpriteGos.Add(go); } Sprite sprite = behaviour.GetPrefab(cell_type); go.GetComponent <SpriteRenderer>().sprite = sprite; go.name = cell_type.ToString(); go.GetComponent <BoxCollider2D>().size = new Vector2(behaviour.tileSize, behaviour.tileSize); AddToMapGameObject(cell_type, go); // Debug.Log ("Cell at " + l.x+"-"+l.y + " has orientation " + orientation); go.transform.localEulerAngles = new Vector3(90, 0, 0); switch (orientation) { case VirtualMap.DirectionType.West: go.transform.localEulerAngles = new Vector3(90, 0, 0); break; case VirtualMap.DirectionType.North: go.transform.localEulerAngles = new Vector3(90, 90, 0); break; case VirtualMap.DirectionType.East: go.transform.localEulerAngles = new Vector3(90, 180, 0); break; case VirtualMap.DirectionType.South: go.transform.localEulerAngles = new Vector3(90, 270, 0); break; } // Move walls up a bit if (VirtualCell.IsFloor(cell_type)) { // Already good } else { go.transform.localPosition += Vector3.up * 0.01f; } if (cell_type == VirtualCell.CellType.DoorHorizontalBottom) { go.transform.localPosition += Vector3.forward * behaviour.tileSize * 0.25f; } }
public void Set(VirtualCell.CellType k, GameObjectList v) { if (hidden_dict == null) { RebuildHiddenDictionary(); } hidden_dict[k] = v; keys.Add(k); GameObjectListContainer v_container = new GameObjectListContainer(); v_container._inner_list = v; values.Add(v_container); }
public float MeasureSize(VirtualCell.CellType type) { GameObject prefab = GetPrefab(type); BoxCollider2D collider = prefab.GetComponent <BoxCollider2D>(); if (collider != null) { return(collider.size.x); } DaedalusDebugUtils.Assert(false, "Cannot Measure Tile Size For Prefab " + prefab.name); return(0); }
public List <GameObject> Get(VirtualCell.CellType k) { if (hidden_dict == null) { RebuildHiddenDictionary(); // Debug.Log("Dictionary keys: " + hidden_dict.Keys.Count); // foreach (VirtualCell.CellType c in hidden_dict.Keys){ // Debug.Log("KEY: " + c); // Debug.Log("VALUE: " + hidden_dict[c]); // } // Debug.Log("Chosen list: " + (hidden_dict[k] as List<GameObject>)); } return(hidden_dict[k] as List <GameObject>); }
override public void CreateObject(VirtualMap map, MetricLocation l, VirtualCell.CellType cell_type, VirtualMap.DirectionType orientation) { Texture2D tile_texture = null; tile_texture = behaviour.GetPrefab(cell_type); GameObject go = (GameObject)GameObject.Instantiate(behaviour.tilePrefab, new Vector3(l.x * behaviour.tileSize, 0, l.y * behaviour.tileSize), Quaternion.identity); var tempMaterial = new Material(go.transform.GetComponent <Renderer>().sharedMaterial); tempMaterial.SetTexture("_MainTex", tile_texture); tempMaterial.name = cell_type.ToString() + "_Material"; go.transform.GetComponent <Renderer>().sharedMaterial = tempMaterial; if (createdMaterialsList == null) { createdMaterialsList = new List <Material>(); } createdMaterialsList.Add(tempMaterial); go.name = cell_type.ToString(); AddToMapGameObject(cell_type, go); go.transform.localEulerAngles = new Vector3(0, 0, 0); switch (orientation) { case VirtualMap.DirectionType.West: go.transform.localEulerAngles = new Vector3(0, 0, 0); break; case VirtualMap.DirectionType.North: go.transform.localEulerAngles = new Vector3(0, 90, 0); break; case VirtualMap.DirectionType.East: go.transform.localEulerAngles = new Vector3(0, 180, 0); break; case VirtualMap.DirectionType.South: go.transform.localEulerAngles = new Vector3(0, 270, 0); break; } // Move walls up a bit if (VirtualCell.IsFloor(cell_type)) { // Already good } else { go.transform.localPosition += Vector3.up * 0.01f; } }
override protected GameObjectChoice[] GetVariations(VirtualCell.CellType cell_type, VirtualMap.DirectionType orientation = VirtualMap.DirectionType.None) { // Treats floors as prefab sections GameObjectChoice[] type_choices = null; switch (cell_type) { case VirtualCell.CellType.CorridorFloorU: type_choices = sectionUVariations; break; case VirtualCell.CellType.CorridorFloorI: type_choices = sectionIVariations; break; case VirtualCell.CellType.CorridorFloorL: type_choices = sectionLVariations; break; case VirtualCell.CellType.CorridorFloorT: type_choices = sectionTVariations; break; case VirtualCell.CellType.CorridorFloorX: type_choices = sectionXVariations; break; //case VirtualCell.CellType.Ladder: type_choices = sectionLadderVariations; break; default: type_choices = base.GetVariations(cell_type, orientation); break; } return type_choices; }
override protected GameObjectChoice[] GetVariations(VirtualCell.CellType cell_type, VirtualMap.DirectionType orientation = VirtualMap.DirectionType.None) { GameObjectChoice[] type_choices = null; //Debug.Log(cell_type); switch (cell_type) { case VirtualCell.CellType.CorridorCeiling: type_choices = corridorCeilingVariations; break; case VirtualCell.CellType.RoomCeiling: type_choices = roomCeilingVariations; break; case VirtualCell.CellType.Ladder: type_choices = ladderVariations; break; case VirtualCell.CellType.Ladder2: type_choices = ladder2Variations; break; default: type_choices = base.GetVariations(cell_type, orientation); break; } return(type_choices); }
// A dead end cell has one and only one direction free for walking (i.e. there is no wall there -> empty) public bool IsDeadEnd(CellLocation l, bool alsoConsiderDoors = false) { int emptyCount = 0; CellLocation[] locs = GetAllNeighbours(l); foreach (CellLocation n_l in locs) { VirtualCell.CellType type = this.GetCell(n_l.x, n_l.y).Type; if (type == VirtualCell.CellType.EmptyPassage || (alsoConsiderDoors && VirtualCell.IsDoor(type))) { emptyCount++; //Debug.Log("For loc " + l + " neigh " + n_l + " is empty!"); } } return(emptyCount == 1); }
// Fixed orientation! override public void CreateObject(VirtualMap map, MetricLocation l, VirtualCell.CellType cell_type, VirtualMap.DirectionType orientation) { if (cell_type != VirtualCell.CellType.CorridorFloor) { Debug.Log("Bobor!"); } GameObject prefab = behaviour.GetPrefab(cell_type, orientation); // NOTE THE ORIENTATION HERE TOO! DaedalusDebugUtils.Assert(prefab != null, "No variation was chosen for " + cell_type); GameObject go = (GameObject)GameObject.Instantiate(prefab, new Vector3(l.x * behaviour.tileSize, l.storey * (behaviour.wallHeight + behaviour.storeySeparationHeight), l.y * behaviour.tileSize), Quaternion.identity); go.name = cell_type.ToString() + "_" + orientation.ToString(); go.transform.localEulerAngles += new Vector3(0, 90, 0); // Orientation fix AddToMapGameObject(cell_type, go, cell_type == VirtualCell.CellType.Door, l.storey); }
override protected SpriteChoice[] GetVariations(VirtualCell.CellType cell_type, VirtualMap.DirectionType orientation = VirtualMap.DirectionType.None) { SpriteChoice[] type_choices = null; switch (cell_type) { case VirtualCell.CellType.Fake3D_Corridor_WallAbove: type_choices = fake3DCorridorWallAbove; break; case VirtualCell.CellType.Fake3D_Corridor_WallFront: type_choices = fake3DCorridorWallFront; break; case VirtualCell.CellType.Fake3D_Room_WallAbove: type_choices = fake3DRoomWallAbove; break; case VirtualCell.CellType.Fake3D_Room_WallFront: type_choices = fake3DRoomWallFront; break; // case VirtualCell.CellType.DoorHorizontalTop: type_choices = doorsHorizontalTop; break; case VirtualCell.CellType.DoorHorizontalBottom: type_choices = doorsHorizontalBottom; break; case VirtualCell.CellType.DoorVertical: type_choices = doorsVertical; break; default: type_choices = base.GetVariations(cell_type, orientation); break; } return(type_choices); }
override public void CreateObject(VirtualMap map, MetricLocation l, VirtualCell.CellType cell_type, VirtualMap.DirectionType orientation) { GameObject prefab = behaviour.GetPrefab(cell_type); DaedalusDebugUtils.Assert(prefab != null, "No variation was chosen for " + cell_type); // Debug.Log (cell_type); GameObject go = (GameObject)GameObject.Instantiate(prefab, new Vector3(l.x * behaviour.tileSize, l.storey * (behaviour.wallHeight + behaviour.storeySeparationHeight), l.y * behaviour.tileSize), Quaternion.identity); go.name = cell_type.ToString(); switch (orientation) { case VirtualMap.DirectionType.West: go.transform.localEulerAngles = new Vector3(0, 180, 0); break; case VirtualMap.DirectionType.North: go.transform.localEulerAngles = new Vector3(0, 270, 0); break; case VirtualMap.DirectionType.East: break; case VirtualMap.DirectionType.South: go.transform.localEulerAngles = new Vector3(0, 90, 0); break; } // Checking orientation and position for ceiling if (cell_type == VirtualCell.CellType.CorridorCeiling || cell_type == VirtualCell.CellType.RoomCeiling) { Vector3 tmpPos = go.transform.position; tmpPos.y += behaviour.wallHeight; go.transform.position = tmpPos; Vector3 tmpRot = go.transform.localEulerAngles; tmpRot.x = 180; go.transform.localEulerAngles = tmpRot; } bool isDynamicCell = GetIsDynamicCell(cell_type); AddToMapGameObject(cell_type, go, isDynamicCell, l.storey); }
override public void CreateObject(VirtualMap map, MetricLocation l, VirtualCell.CellType cell_type, VirtualMap.DirectionType orientation) { GameObject prefab = behaviour.GetPrefab(cell_type); DaedalusDebugUtils.Assert(prefab != null, "No variation was chosen for " + cell_type); GameObject go = (GameObject)GameObject.Instantiate(prefab, new Vector3(l.x * behaviour.tileSize, 0, l.y * behaviour.tileSize), Quaternion.identity); go.name = cell_type.ToString(); if (orientation == VirtualMap.DirectionType.None) { orientation = VirtualMap.DirectionType.North; } switch (orientation) { case VirtualMap.DirectionType.West: go.transform.localEulerAngles = new Vector3(90, 0, 0); break; case VirtualMap.DirectionType.North: go.transform.localEulerAngles = new Vector3(90, 90, 0); break; case VirtualMap.DirectionType.East: go.transform.localEulerAngles = new Vector3(90, 180, 0); break; case VirtualMap.DirectionType.South: go.transform.localEulerAngles = new Vector3(90, 270, 0); break; } AddToMapGameObject(cell_type, go, cell_type == VirtualCell.CellType.Door, l.storey); // Move walls up a bit if (VirtualCell.IsFloor(cell_type)) { // Already good } else { go.transform.localPosition += Vector3.up * 0.01f; } }
virtual protected S[] GetVariations(VirtualCell.CellType cell_type) { return(GetVariations(cell_type, VirtualMap.DirectionType.None)); }
public bool GetIsDynamicCell(VirtualCell.CellType cell_type) { return(VirtualCell.IsDynamic(cell_type)); }
override protected GameObjectChoice[] GetVariations(VirtualCell.CellType cell_type, VirtualMap.DirectionType orientation = VirtualMap.DirectionType.None) { if (orientation == VirtualMap.DirectionType.None) { orientation = VirtualMap.DirectionType.North; } // Treats floors as prefab sections GameObjectChoice[] type_choices = null; switch (cell_type) { case VirtualCell.CellType.CorridorFloorU: switch (orientation) { case VirtualMap.DirectionType.East: type_choices = sectionUVariations_E; break; case VirtualMap.DirectionType.North: type_choices = sectionUVariations_N; break; case VirtualMap.DirectionType.West: type_choices = sectionUVariations_W; break; case VirtualMap.DirectionType.South: type_choices = sectionUVariations_S; break; } break; case VirtualCell.CellType.CorridorFloorI: switch (orientation) { case VirtualMap.DirectionType.East: type_choices = sectionIVariations_WE; break; case VirtualMap.DirectionType.North: type_choices = sectionIVariations_NS; break; case VirtualMap.DirectionType.West: type_choices = sectionIVariations_WE; break; case VirtualMap.DirectionType.South: type_choices = sectionIVariations_NS; break; } break; case VirtualCell.CellType.CorridorFloorL: switch (orientation) { case VirtualMap.DirectionType.East: type_choices = sectionLVariations_SE; break; case VirtualMap.DirectionType.North: type_choices = sectionLVariations_NE; break; case VirtualMap.DirectionType.West: type_choices = sectionLVariations_NW; break; case VirtualMap.DirectionType.South: type_choices = sectionLVariations_SW; break; } break; case VirtualCell.CellType.CorridorFloorT: switch (orientation) { case VirtualMap.DirectionType.East: type_choices = sectionTVariations_XE; break; case VirtualMap.DirectionType.North: type_choices = sectionTVariations_XN; break; case VirtualMap.DirectionType.West: type_choices = sectionTVariations_XW; break; case VirtualMap.DirectionType.South: type_choices = sectionTVariations_XS; break; } break; case VirtualCell.CellType.CorridorFloorX: type_choices = sectionXVariations; break; default: type_choices = base.GetVariations(cell_type, orientation); break; } return(type_choices); }
protected void AddFillingFloors(VirtualMap map, VirtualCell conversion_cell) { if (conversion_cell.Type == VirtualCell.CellType.None) { return; } // Fill with floors VirtualCell.CellType initial_type = conversion_cell.Type; VirtualMap.DirectionType initial_dir = conversion_cell.Orientation; bool addedFloor = false; if (behaviour.fillWithFloors) { bool mayBeDirectional = false; if (CheckRoom(map, conversion_cell.location)) { if (conversion_cell.IsDoor() || conversion_cell.IsEmpty()) { AddToCorrectRoom(map, conversion_cell.location); conversion_cell.Type = VirtualCell.CellType.RoomFloor; ConvertDirectionalRoomFloor(map, conversion_cell); mayBeDirectional = true; } else { conversion_cell.Type = VirtualCell.CellType.RoomFloor; } } else { if (conversion_cell.IsDoor() || conversion_cell.IsEmpty()) { conversion_cell.Type = VirtualCell.CellType.CorridorFloor; ConvertDirectionalCorridorFloor(map, conversion_cell); mayBeDirectional = true; } else { conversion_cell.Type = VirtualCell.CellType.CorridorFloor; } } ConvertFloor(map, conversion_cell, mayBeDirectional); addedFloor = true; } else { // Special case: when not filling with floors AND we do not draw doors, we still need to place a floor underneath the empty passage representing the doors! if (conversion_cell.IsEmpty()) // Decomment this if you want floors underneath doors ALWAYS: // || input_cell.IsDoor()){ { conversion_cell.Type = VirtualCell.CellType.CorridorFloor; ConvertDirectionalCorridorFloor(map, conversion_cell); ConvertFloor(map, conversion_cell); addedFloor = true; } } if (addedFloor) { // The initial type is switched in, the floor becomes a subtype VirtualCell.CellType new_subtype = conversion_cell.Type; VirtualMap.DirectionType new_dir = conversion_cell.Orientation; conversion_cell.Type = initial_type; conversion_cell.Orientation = initial_dir; conversion_cell.AddCellInstance(new_subtype, new_dir); } }
private bool ShouldBeFilled(VirtualCell.CellType type) { return(!(type == VirtualCell.CellType.CorridorFloor || type == VirtualCell.CellType.RoomFloor)); }
public void AddCellInstance(VirtualCell.CellType type, VirtualMap.DirectionType dir) { // TODO: Should we check if we add two times the same type? this.instances.Add(new CellInstance(type, dir)); }
public CellInstance(VirtualCell.CellType type, VirtualMap.DirectionType dir) { this.type = type; this.dir = dir; }
virtual protected S[] GetVariations(VirtualCell.CellType cell_type, VirtualMap.DirectionType orientation) { S[] type_choices = null; switch (cell_type) { case VirtualCell.CellType.CorridorWall: type_choices = corridorWallVariations; break; case VirtualCell.CellType.CorridorFloor: type_choices = corridorFloorVariations; break; case VirtualCell.CellType.CorridorColumn: type_choices = corridorColumnVariations; break; case VirtualCell.CellType.RoomWall: type_choices = roomWallVariations; break; case VirtualCell.CellType.RoomFloor: type_choices = roomFloorVariations; break; case VirtualCell.CellType.RoomColumn: type_choices = roomColumnVariations; break; case VirtualCell.CellType.InsideRoomColumn: type_choices = insideRoomColumnVariations; break; case VirtualCell.CellType.Door: type_choices = doorVariations; break; case VirtualCell.CellType.RoomDoor: type_choices = roomDoorVariations; break; case VirtualCell.CellType.PassageColumn: type_choices = passageColumnVariations; break; case VirtualCell.CellType.Rock: type_choices = rockVariations; break; case VirtualCell.CellType.CorridorFloorU: type_choices = corridorFloorUVariations; break; case VirtualCell.CellType.CorridorFloorI: type_choices = corridorFloorIVariations; break; case VirtualCell.CellType.CorridorFloorL: type_choices = corridorFloorLVariations; break; case VirtualCell.CellType.CorridorFloorT: type_choices = corridorFloorTVariations; break; case VirtualCell.CellType.CorridorFloorX: type_choices = corridorFloorXVariations; break; case VirtualCell.CellType.RoomFloorInside: type_choices = roomFloorInsideVariations; break; case VirtualCell.CellType.RoomFloorBorder: type_choices = roomFloorBorderVariations; break; case VirtualCell.CellType.RoomFloorCorner: type_choices = roomFloorCornerVariations; break; case VirtualCell.CellType.PerimeterWall: type_choices = perimeterWallVariations; break; case VirtualCell.CellType.PerimeterColumn: type_choices = perimeterColumnVariations; break; case VirtualCell.CellType.CorridorWallO: type_choices = corridorWallOVariations; break; case VirtualCell.CellType.CorridorWallU: type_choices = corridorWallUVariations; break; case VirtualCell.CellType.CorridorWallI: type_choices = corridorWallIVariations; break; case VirtualCell.CellType.CorridorWallL: type_choices = corridorWallLVariations; break; case VirtualCell.CellType.CorridorWallT: type_choices = corridorWallTVariations; break; case VirtualCell.CellType.CorridorWallX: type_choices = corridorWallXVariations; break; case VirtualCell.CellType.RoomWallO: type_choices = roomWallOVariations; break; case VirtualCell.CellType.RoomWallU: type_choices = roomWallUVariations; break; case VirtualCell.CellType.RoomWallI: type_choices = roomWallIVariations; break; case VirtualCell.CellType.RoomWallL: type_choices = roomWallLVariations; break; case VirtualCell.CellType.RoomWallT: type_choices = roomWallTVariations; break; case VirtualCell.CellType.RoomWallX: type_choices = roomWallXVariations; break; default: Debug.LogError("No prefab for cell type " + cell_type); break; } return(type_choices); }