int CreatePassageway(ref List <RoomNode> rooms_list, ref int id_counter, int first, CardinalDirection dir, int count) { List <RoomNode> passage = new List <RoomNode>(); //Route 1 for (int i = 0; i < count; ++i) { RoomNode room = new RoomNode(id_counter++); room.room_prefab_ = (GameObject)FindRoomType(RandomRoom()); if (i > 0) { RoomNode prev_room = passage[i - 1]; switch (dir) { case CardinalDirection.North: prev_room.ConN(ref room); break; case CardinalDirection.South: prev_room.ConS(ref room); break; case CardinalDirection.East: prev_room.ConE(ref room); break; case CardinalDirection.West: prev_room.ConW(ref room); break; } passage[i - 1] = prev_room; } else { RoomNode prev_room = rooms_list[first]; switch (dir) { case CardinalDirection.North: prev_room.ConN(ref room); break; case CardinalDirection.South: prev_room.ConS(ref room); break; case CardinalDirection.East: prev_room.ConE(ref room); break; case CardinalDirection.West: prev_room.ConW(ref room); break; } rooms_list[first] = prev_room; } passage.Add(room); } int first_room = rooms_list.Count; foreach (RoomNode room in passage) { rooms_list.Add(room); } return(first_room); }
void LoadRooms() { rooms_ = new List <RoomNode>(); room_prefabs_ = Resources.LoadAll("Prefabs/Rooms", typeof(GameObject)); int id_counter = 1000; RoomNode starting_room = new RoomNode(id_counter++); RoomNode first_room = new RoomNode(id_counter++); RoomNode computer_room = new RoomNode(id_counter++); RoomNode skyrim_room = new RoomNode(id_counter++); computer_room.room_prefab_ = (GameObject)FindRoomType("ComputerRoom"); skyrim_room.room_prefab_ = (GameObject)FindRoomType("emptyRoom"); starting_room.room_prefab_ = (GameObject)FindRoomType("emptyRoom"); first_room.room_prefab_ = starting_room.room_prefab_; first_room.ConS(ref starting_room); rooms_.Add(starting_room); rooms_.Add(first_room); int locked_count = CreatePassageway(ref rooms_, ref id_counter, 1, CardinalDirection.East, 3); RoomNode locked_room = rooms_[locked_count]; locked_room.AddLockedDoor(CardinalDirection.West, 2); rooms_[locked_count] = locked_room; int other_weapon_int = CreatePassageway(ref rooms_, ref id_counter, rooms_.Count - 1, CardinalDirection.North, 3); RoomNode weapon_room = rooms_[other_weapon_int]; weapon_room.room_prefab_ = (GameObject)FindRoomType("spawnerRoomAK"); rooms_[other_weapon_int] = weapon_room; RoomNode last = rooms_[rooms_.Count - 1]; computer_room.ConE(ref last); last.room_prefab_ = (GameObject)FindRoomType("spawnerRoomKey3"); last.AddLockedDoor(CardinalDirection.West, 3); rooms_[rooms_.Count - 1] = last; CreatePassageway(ref rooms_, ref id_counter, 1, CardinalDirection.North, 3); last = rooms_[rooms_.Count - 1]; last.room_prefab_ = (GameObject)FindRoomType("spawnerRoomKey1"); computer_room.ConS(ref last); rooms_[rooms_.Count - 1] = last; int route_to_key_1 = CreatePassageway(ref rooms_, ref id_counter, 1, CardinalDirection.West, 1); weapon_room = rooms_[route_to_key_1]; weapon_room.AddLockedDoor(CardinalDirection.East, 1); weapon_room.room_prefab_ = (GameObject)FindRoomType("spawnerRoomSG"); rooms_[route_to_key_1] = weapon_room; CreatePassageway(ref rooms_, ref id_counter, route_to_key_1, CardinalDirection.North, 5); RoomNode armor_room = rooms_[rooms_.Count - 2]; armor_room.room_prefab_ = (GameObject)FindRoomType("spawnerRoomArmor"); rooms_[rooms_.Count - 2] = armor_room; RoomNode key_room = rooms_[rooms_.Count - 1]; armor_room.room_prefab_ = (GameObject)FindRoomType("spawnerRoomKey2"); key_room.AddLockedDoor(CardinalDirection.East, 2); computer_room.ConW(ref key_room); rooms_[rooms_.Count - 1] = key_room; skyrim_room.ConS(ref computer_room); skyrim_room.AddLockedDoor(CardinalDirection.South, 3); rooms_.Add(computer_room); rooms_.Add(skyrim_room); }