private bool CheckStraightSideAreaInternal(MapArea fromArea,MapAreaTypeDir dir) { MapArea connectArea = this.GetNextMapArea(fromArea.X,fromArea.Y, dir); if( connectArea != null //&& connectArea.Type != MapAreaType.None ){ && connectArea.Type == MapAreaType.Room ){ ConnectArea(fromArea,connectArea, dir); return true; } return false; }
private MapArea GetNextMapArea(int x,int y, MapAreaTypeDir dir) { // 上下方向 int next = 0; if( dir == MapAreaTypeDir.Upper ){ next = y - 1; if( next < 0 ){ return null;// マップの端っこに到達 } return this.AreaList[next,x]; }else if( dir == MapAreaTypeDir.Bottom ){ next = y + 1; if( this.AreaList.GetLength(0) <= next ){ return null;// マップの端っこに到達 } return this.AreaList[next,x]; } // 左右方向 if( dir == MapAreaTypeDir.Left ){ next = x - 1; if( next < 0 ){ return null;// マップの端っこに到達 } return this.AreaList[y,next]; }else if( dir == MapAreaTypeDir.Right ){ next = x + 1; if( this.AreaList.GetLength(1) <= next ){ return null;// マップの端っこに到達 } return this.AreaList[y,next]; } return null; }
private bool CheckStraightSideArea(MapArea fromArea,MapAreaTypeDir dir) { if( fromArea.Type != MapAreaType.None ){ return false; } // つながるとこがあるならつなげておしまい。 if( dir == MapAreaTypeDir.Upper || dir == MapAreaTypeDir.Bottom ){ // 進行方向が上下 if( CheckStraightSideAreaInternal(fromArea, MapAreaTypeDir.Left) ){ return true; }else if( CheckStraightSideAreaInternal(fromArea, MapAreaTypeDir.Right) ){ return true; } }else{//if( dir == MapAreaTypeDir.Left || dir == MapAreaTypeDir.Right ){ // 進行方向が左右 if( CheckStraightSideAreaInternal(fromArea, MapAreaTypeDir.Upper) ){ return true; }else if( CheckStraightSideAreaInternal(fromArea, MapAreaTypeDir.Bottom) ){ return true; } } return false; }
/// 指定方向にまっすぐエリアを検索し、部屋を見つけたらつなげる private bool CheckStraightRoad(MapArea fromArea, MapAreaTypeDir dir) { // 進行方向のサイドのエリアをチェック if( this.CheckStraightSideArea(fromArea, dir) ){ return true; } // その先を検索 MapArea connectArea = GetNextMapArea(fromArea.X,fromArea.Y, dir); if( connectArea == null ){ return false; } if( connectArea.Type == MapAreaType.None ){ // なにもない if( this.CheckStraightRoad(connectArea, dir) ){ ConnectArea(fromArea,connectArea, dir); return true; }else{ return false; } }else{// if( connectArea.Type == MapAreaType.Room || connectArea.Type == MapAreaType.Road ){ // 部屋につながった ConnectArea(fromArea,connectArea, dir); return true; } }
private bool CalcBlockConnectOne(MapArea from, int x,int y, MapAreaTypeDir dir) { MapArea checkArea = this.AreaList[y,x]; if( checkArea.Type != MapAreaType.None && checkArea.BlockID != from.BlockID ){ // 違うブロックが隣あっているので、連結する。 Debug.Log("Connect Block : " + from.BlockID.ToString() + ", " + checkArea.BlockID.ToString()); ConnectArea(from, checkArea, dir); return true; } return false; }
private bool CalcBlockConnectLine(MapArea from, int x,int y, MapAreaTypeDir dir) { MapArea checkArea = this.AreaList[y,x]; if( checkArea.Type != MapAreaType.None ){ if( checkArea.BlockID == from.BlockID ){ return false;// 同一ブロックにつながった }else{ // 違うブロックが隣あっているので、連結する。 Debug.Log("Connect Block Line : " + string.Format("({0},{1})",from.X,from.Y) + " <=> " + string.Format("({0},{1})",checkArea.X,checkArea.Y)); ConnectArea(from, checkArea, dir); return true; } }else{ // なにもないエリア:次のエリアへ int nextX = x + (dir == MapAreaTypeDir.Right ? 1 : 0); if( nextX >= this.AreaList.GetLength(1) ){ return false; } int nextY = y + (dir == MapAreaTypeDir.Bottom ? 1 : 0); if( nextY >= this.AreaList.GetLength(0) ){ return false; } if( CalcBlockConnectLine(checkArea, nextX,nextY, dir) ){ ConnectArea(from, checkArea, dir); return true; } } return false; }
private static void ConnectArea(MapArea from,MapArea to, MapAreaTypeDir dir) { from.ConnectDir[(int)dir] = to; to.ConnectDir[ (int)MapAreaReverseDirList[(int)dir] ] = from; if( from.Type == MapAreaType.None ){ from.Type = MapAreaType.Road; } }