static public void MarkHallWalls(ref AreaMap new_map, int x_loc, int y_loc) { int x_offset = 0; int y_offset = 0; for (int dir = 0; dir < Globals.Directions.Count(); dir += Globals.AllDirItr) { x_offset = Globals.Directions[dir].X + x_loc; y_offset = Globals.Directions[dir].Y + y_loc; if (!new_map.OffMap(x_offset, y_offset)) { if (new_map.ChkMSForState(ref new_map.MSGrid[y_offset][x_offset], MSFlag.BL, MSFlagIndex.BL_ST)) { new_map.MSGrid[y_offset][x_offset].MSStates[(int)MSFlagIndex.WALL_RM_ENT] = MSFlag.PWALL; } } } }
static public bool CheckForGoodPathEnds(ref AreaMap new_map, int room_index, int sqr_index, ref Point sqr_point) { if (!new_map.ChkAdjacentForRoomID(ref new_map, ref sqr_point, room_index, Globals.AllDirItr, 4)) // is corner? { return(false); } else if (new_map.ChkMSForState(ref new_map.MSGrid[sqr_point.Y][sqr_point.X], MSFlag.ENT, MSFlagIndex.WALL_RM_ENT)) // is entrance? { return(false); } else if (!new_map.ChkAdjacentForMState(ref new_map, ref sqr_point, MSFlag.BL, MSFlagIndex.BL_ST, Globals.NESWItr, 1)) // is blocked off? { return(false); } return(true); }
static public bool CheckForGoodPathEnds(ref AreaMap new_map, int room_index, int sqr_index, ref Point sqr_point) { if (new_map.RoomList[room_index].IsCorner(sqr_index)) { return(false); } else if (new_map.ChkMSForState(ref new_map.MSGrid[sqr_point.Y][sqr_point.X], MSFlag.ENT, MSFlagIndex.WALL_RM_ENT)) { return(false); } else if (!new_map.ChkAdjacentForMState(ref new_map, ref sqr_point, MSFlag.BL, MSFlagIndex.BL_ST, Globals.NESWItr, 1)) { return(false); } return(true); }
static public void MarkHallWalls(ref AreaMap new_map, ref List <List <Point> > hall_paths) { int x_offset = 0; int y_offset = 0; for (int hall = 0; hall < hall_paths.Count; hall++) { for (int sqr = 0; sqr < hall_paths[hall].Count(); sqr++) { for (int dir = 0; dir < Globals.Directions.Count(); dir += Globals.AllDirItr) { x_offset = Globals.Directions[dir].X + hall_paths[hall][sqr].X; y_offset = Globals.Directions[dir].Y + hall_paths[hall][sqr].Y; if (!new_map.OffMap(x_offset, y_offset)) { if (new_map.ChkMSForState(ref new_map.MSGrid[y_offset][x_offset], MSFlag.BL, MSFlagIndex.BL_ST)) { new_map.MSGrid[y_offset][x_offset].MSStates[(int)MSFlagIndex.WALL_RM_ENT] = MSFlag.PWALL; } } } } } }
static public bool FloodIsConnectedCheck(ref AreaMap new_map, bool unmark_after) { int adjacent_x = 0; int adjacent_y = 0; int curr_ID = 0; List <int> visited_rooms = new List <int>(); Stack <Point> squares = new Stack <Point>(); Point cur_sqr = Point.Zero; visited_rooms.Add(0); squares.Push(new_map.RoomList[0].RoomSquares[0]); if (new_map.MSGrid[new_map.RoomList[0].RoomSquares[0].Y] [new_map.RoomList[0].RoomSquares[0].X].MSStates[(int)MSFlagIndex.IS_MKD] == MSFlag.MKD) { MapGenHelper.UnmarkMap(ref new_map); /// } while (squares.Count > 0) { cur_sqr = squares.Pop(); for (int dir = 0; dir < Globals.Directions.Count(); dir += Globals.NESWItr) { adjacent_x = cur_sqr.X + Globals.Directions[dir].X; adjacent_y = cur_sqr.Y + Globals.Directions[dir].Y; if (new_map.OffMap(adjacent_x, adjacent_y)) { continue; } if (!new_map.ChkMSForState(ref new_map.MSGrid[adjacent_y][adjacent_x], MSFlag.WALL, MSFlagIndex.WALL_RM_ENT)) // changed: WALL->ROOM { if (new_map.ChkMSForState(ref new_map.MSGrid[adjacent_y][adjacent_x], MSFlag.NT_MKD, MSFlagIndex.IS_MKD)) { curr_ID = new_map.MSGrid[adjacent_y][adjacent_x].RoomID; new_map.MSGrid[adjacent_y][adjacent_x].MSStates[(int)MSFlagIndex.IS_MKD] = MSFlag.MKD; squares.Push(new Point(adjacent_x, adjacent_y)); if (!visited_rooms.Contains(curr_ID)) { visited_rooms.Add(curr_ID); } } } } } MapGenHelper.disconnectedRooms.Clear(); for (int i = 0; i < new_map.RoomList.Count(); i++) { if (!visited_rooms.Contains(i)) { MapGenHelper.disconnectedRooms.Add(i); } } if (MapGenHelper.disconnectedRooms.Count == 0) { MapGenHelper.UnmarkMap(ref new_map); } MapGenHelper.dcCount = MapGenHelper.disconnectedRooms.Count(); if (MapGenHelper.disconnectedRooms.Count > 0) { return(false); } return(true); }
static public Vector4 FindClosestRoom(ref AreaMap new_map, int start_room_index, int room_count) { int shortest, distance, start_room_id, stop_room_id, end_room_index; shortest = distance = start_room_id = stop_room_id = end_room_index = -1; Point endRoomPT = new Point(); Point curRoomWSqrPT = new Point(); Point endRoomWSqrPT = new Point(); Point startWsqrPT = new Point(); Point endWsqrPT = new Point(); List <Point> possible_starts = new List <Point>(); List <Point> possible_ends = new List <Point>(); List <int> ignored_rm_index = new List <int>(); int wall_square_count = new_map.RoomList[start_room_index].WallSquares.Count(); int otherRoomWSqrLst_count = 0; ignored_rm_index.Clear(); ignored_rm_index.Add(start_room_index); // check each room for (int room = 0; room < room_count; room++) { if (!ignored_rm_index.Contains(room)) { if (AreRoomsConnected(ref new_map, room, start_room_index)) { ignored_rm_index.Add(room); continue; } // check each wall square in this room for path start square for (int wall_square = 0; wall_square < wall_square_count; wall_square++) { curRoomWSqrPT = new_map.RoomList[start_room_index].WallSquares[wall_square]; // check if this first something if (shortest < 0) { int rndEndRoomWSqrIndex = rand.Next(1, new_map.RoomList[room].WallSquares.Count - 1); while (new_map.RoomList[room].IsCorner(rndEndRoomWSqrIndex)) { rndEndRoomWSqrIndex = rand.Next(1, new_map.RoomList[room].WallSquares.Count - 1); } endRoomPT = new_map.RoomList[room].WallSquares[rndEndRoomWSqrIndex]; shortest = AreaMap.StepDistance(curRoomWSqrPT, ref endRoomPT); } // check if start square is a corner or already an entrance if (new_map.RoomList[start_room_index].IsCorner(wall_square)) { continue; } else if (new_map.ChkMSForState(ref new_map.MSGrid[curRoomWSqrPT.Y][curRoomWSqrPT.X], MSFlag.ENT, MSFlagIndex.WALL_RM_ENT)) { continue; } otherRoomWSqrLst_count = new_map.RoomList[room].WallSquares.Count(); // check wall squares in other room for (int other_square = 0; other_square < otherRoomWSqrLst_count; other_square++) { endRoomWSqrPT = new_map.RoomList[room].WallSquares[other_square]; // check if end square is a corner or already an entrance if (new_map.RoomList[room].IsCorner(other_square)) { continue; } else if (new_map.ChkMSForState(ref new_map.MSGrid[endRoomWSqrPT.Y][endRoomWSqrPT.X], MSFlag.ENT, MSFlagIndex.WALL_RM_ENT)) { continue; } // get distance from start_room[wall_square] to room[other_square] distance = AreaMap.StepDistance(curRoomWSqrPT, ref endRoomWSqrPT); if (distance <= shortest) { if (distance < shortest) { possible_ends.Clear(); possible_starts.Clear(); } possible_ends.Add(endRoomWSqrPT); possible_starts.Add(curRoomWSqrPT); shortest = distance; end_room_index = room; } } } if (possible_ends.Count == 0) { ignored_rm_index.Add(room); } } } if (shortest == 1) { int square_index = rand.Next(0, possible_starts.Count() - 1); startWsqrPT = possible_starts[square_index]; endWsqrPT = possible_ends[square_index]; } else { if (possible_ends.Count != 0) { startWsqrPT = possible_starts[rand.Next(0, possible_starts.Count() - 1)]; endWsqrPT = possible_ends[rand.Next(0, possible_ends.Count() - 1)]; } else { return(new Vector4(-1f, -1f, -1f, -1f)); } } start_room_id = new_map.MSGrid[(int)startWsqrPT.Y][(int)startWsqrPT.X].RoomID; stop_room_id = new_map.MSGrid[(int)endWsqrPT.Y][(int)endWsqrPT.X].RoomID; new_map.RoomList[start_room_id].OutConnections.Add(stop_room_id); new_map.RoomList[stop_room_id].InConnections.Add(start_room_id); new_map.MSGrid[(int)startWsqrPT.Y][(int)startWsqrPT.X].MSStates[(int)MSFlagIndex.WALL_RM_ENT] = MSFlag.ENT; new_map.MSGrid[(int)endWsqrPT.Y][(int)endWsqrPT.X].MSStates[(int)MSFlagIndex.WALL_RM_ENT] = MSFlag.ENT; return(new Vector4(startWsqrPT.X, startWsqrPT.Y, endWsqrPT.X, endWsqrPT.Y)); }