Advertisement
Guest User

GetOrientation method rework

a guest
Oct 9th, 2014
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.78 KB | None | 0 0
  1. private string[] GetOrientation(Map map, Address a)
  2. {
  3.     string[] orientation = new string[2];
  4.     orientation[0] = "Default";
  5.     orientation[1] = "";
  6.  
  7.     /* Create list of tiles around centre tile
  8.           N
  9.         0 1 2
  10.      W  7 c 3  E
  11.         6 5 4
  12.           S
  13.     */
  14.     string[] cellsaround = new string[8]; /* Holds the names of cell types around centre cell */
  15.     /* Cell 0 */
  16.     if( a.x-1 >= 0 && a.x-1 < map.size_X && a.y+1 >= 0 && a.y+1 < map.size_Y ) { /* Make sure cell is within map bounds */
  17.         cellsaround[0] = map.cellsOnMap[a.x-1, a.y+1].type; /* Grab the cell type from the map and store it */
  18.     } else {
  19.         cellsaround[0] = "OffMap"; /* Cell was off the map */
  20.     }
  21.     /* Cell 1 */
  22.     if( a.x >= 0 && a.x < map.size_X && a.y+1 >= 0 && a.y+1 < map.size_Y ) { /* Make sure cell is within map bounds */
  23.         cellsaround[1] = map.cellsOnMap[a.x, a.y+1].type; /* Grab the cell type from the map and store it */
  24.     } else {
  25.         cellsaround[1] = "OffMap"; /* Cell was off the map */
  26.     }
  27.     /* Cell 2 */
  28.     if( a.x+1 >= 0 && a.x+1 < map.size_X && a.y+1 >= 0 && a.y+1 < map.size_Y ) { /* Make sure cell is within map bounds */
  29.         cellsaround[2] = map.cellsOnMap[a.x+1, a.y+1].type; /* Grab the cell type from the map and store it */
  30.     } else {
  31.         cellsaround[2] = "OffMap"; /* Cell was off the map */
  32.     }
  33.     /* Cell 3 */
  34.     if( a.x+1 >= 0 && a.x+1 < map.size_X && a.y >= 0 && a.y < map.size_Y ) { /* Make sure cell is within map bounds */
  35.         cellsaround[3] = map.cellsOnMap[a.x+1, a.y].type; /* Grab the cell type from the map and store it */
  36.     } else {
  37.         cellsaround[3] = "OffMap"; /* Cell was off the map */
  38.     }
  39.     /* Cell 4 */
  40.     if( a.x+1 >= 0 && a.x+1 < map.size_X && a.y-1 >= 0 && a.y-1 < map.size_Y ) { /* Make sure cell is within map bounds */
  41.         cellsaround[4] = map.cellsOnMap[a.x+1, a.y-1].type; /* Grab the cell type from the map and store it */
  42.     } else {
  43.         cellsaround[4] = "OffMap"; /* Cell was off the map */
  44.     }
  45.     /* Cell 5 */
  46.     if( a.x >= 0 && a.x < map.size_X && a.y-1 >= 0 && a.y-1 < map.size_Y ) { /* Make sure cell is within map bounds */
  47.         cellsaround[5] = map.cellsOnMap[a.x, a.y-1].type; /* Grab the cell type from the map and store it */
  48.     } else {
  49.         cellsaround[5] = "OffMap"; /* Cell was off the map */
  50.     }
  51.     /* Cell 6 */
  52.     if( a.x-1 >= 0 && a.x-1 < map.size_X && a.y-1 >= 0 && a.y-1 < map.size_Y ) { /* Make sure cell is within map bounds */
  53.         cellsaround[6] = map.cellsOnMap[a.x-1, a.y-1].type; /* Grab the cell type from the map and store it */
  54.     } else {
  55.         cellsaround[6] = "OffMap"; /* Cell was off the map */
  56.     }
  57.     /* Cell 7 */
  58.     if( a.x-1 >= 0 && a.x-1 < map.size_X && a.y >= 0 && a.y < map.size_Y ) { /* Make sure cell is within map bounds */
  59.         cellsaround[7] = map.cellsOnMap[a.x-1, a.y].type; /* Grab the cell type from the map and store it */
  60.     } else {
  61.         cellsaround[7] = "OffMap"; /* Cell was off the map */
  62.     }
  63.  
  64.     /* Rules list to determine what prefab type to place */
  65.     string type = map.cellsOnMap[a.x,a.y].type;
  66.     if( type == "Door" ) {
  67.         /* Check if door should be vertical */
  68.         if( cellsaround[1] == "Wall" && cellsaround[5] == "Wall" ) {
  69.             orientation[0] = "Vertical"; orientation[1] = "Default";
  70.         }
  71.         /* Check if door should be horizontal */
  72.         else if( cellsaround[3] == "Wall" && cellsaround[7] == "Wall" ) {
  73.             orientation[0] = "Horizontal"; orientation[1] = "Default";
  74.         }
  75.     }
  76.     else if( type == "Path" ) { /* Check what type of path tile should be used */
  77.         orientation[0] = "Default"; /* No rules for floor tiles yet */
  78.     }
  79.     else if( type == "Wall" ) { /* Check what type of wall tile should be used */
  80.         /* Core */
  81.         if( cellsaround[1] == "Wall" && cellsaround[3] == "Wall" && cellsaround[5] == "Wall" && cellsaround[7] == "Wall" ) {
  82.             orientation[0] = "Core"; orientation[1] = "Default";
  83.         }
  84.         /* Column */
  85.         else if( cellsaround[1] == "Path" && cellsaround[3] == "Path" && cellsaround[5] == "Path" && cellsaround[7] == "Path" ) {
  86.             orientation[0] = "Column"; orientation[1] = "Default";
  87.         }
  88.         /* Corner - North East */
  89.         else if( cellsaround[1] == "Wall" && cellsaround[3] == "Wall" && cellsaround[5] != "Wall" && cellsaround[7] != "Wall" ) {
  90.             orientation[0] = "Corner"; orientation[1] = "NE";
  91.         }
  92.         /* Corner - North West */
  93.         else if( cellsaround[1] == "Wall" && cellsaround[3] != "Wall" && cellsaround[5] != "Wall" && cellsaround[7] == "Wall" ) {
  94.             orientation[0] = "Corner"; orientation[1] = "NW";
  95.         }
  96.         /* Corner - South East */
  97.         else if( cellsaround[1] != "Wall" && cellsaround[3] == "Wall" && cellsaround[5] == "Wall" && cellsaround[7] != "Wall" ) {
  98.             orientation[0] = "Corner"; orientation[1] = "SE";
  99.         }
  100.         /* Corner - South West */
  101.         else if( cellsaround[1] != "Wall" && cellsaround[3] != "Wall" && cellsaround[5] == "Wall" && cellsaround[7] == "Wall" ) {
  102.             orientation[0] = "Corner"; orientation[1] = "SW";
  103.         }
  104.         /* Tip North */
  105.         else if( cellsaround[1] != "Wall" && cellsaround[3] != "Wall" && cellsaround[5] == "Wall" && cellsaround[7] != "Wall" ) {
  106.             orientation[0] = "Tip"; orientation[1] = "N";
  107.         }
  108.         /* Tip South */
  109.         else if( cellsaround[1] == "Wall" && cellsaround[3] != "Wall" && cellsaround[5] != "Wall" && cellsaround[7] != "Wall" ) {
  110.             orientation[0] = "Tip"; orientation[1] = "S";
  111.         }
  112.         /* Tip East */
  113.         else if( cellsaround[1] != "Wall" && cellsaround[3] != "Wall" && cellsaround[5] != "Wall" && cellsaround[7] == "Wall" ) {
  114.             orientation[0] = "Tip"; orientation[1] = "E";
  115.         }
  116.         /* Tip West */
  117.         else if( cellsaround[1] != "Wall" && cellsaround[3] == "Wall" && cellsaround[5] != "Wall" && cellsaround[7] != "Wall" ) {
  118.             orientation[0] = "Tip"; orientation[1] = "W";
  119.         }
  120.         /* One Sided North */
  121.         else if( cellsaround[1] == "Wall" && cellsaround[3] == "Wall" && cellsaround[5] != "Wall" && cellsaround[7] == "Wall" ) {
  122.             orientation[0] = "OneSided"; orientation[1] = "N";
  123.         }
  124.         /* One Sided South */
  125.         else if( cellsaround[1] != "Wall" && cellsaround[3] == "Wall" && cellsaround[5] == "Wall" && cellsaround[7] == "Wall" ) {
  126.             orientation[0] = "OneSided"; orientation[1] = "S";
  127.         }
  128.         /* One Sided East */
  129.         else if( cellsaround[1] == "Wall" && cellsaround[3] == "Wall" && cellsaround[5] == "Wall" && cellsaround[7] != "Wall" ) {
  130.             orientation[0] = "OneSided"; orientation[1] = "E";
  131.         }
  132.         /* One Sided West */
  133.         else if( cellsaround[1] == "Wall" && cellsaround[3] != "Wall" && cellsaround[5] == "Wall" && cellsaround[7] == "Wall" ) {
  134.             orientation[0] = "OneSided"; orientation[1] = "W";
  135.         }
  136.         /* Two Sided Vertical */
  137.         else if( cellsaround[1] == "Wall" && cellsaround[3] != "Wall" && cellsaround[5] == "Wall" && cellsaround[7] != "Wall" ) {
  138.             orientation[0] = "TwoSided"; orientation[1] = "V";
  139.         }
  140.         /* Two Sided Horizontal */
  141.         else if( cellsaround[1] != "Wall" && cellsaround[3] == "Wall" && cellsaround[5] != "Wall" && cellsaround[7] == "Wall" ) {
  142.             orientation[0] = "TwoSided"; orientation[1] = "V";
  143.         }      
  144.     }
  145.    
  146.     return orientation; /* Return with what the tile prefab should be */
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement