Advertisement
Tetrikitty

swimpathing

Dec 23rd, 2020
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. if (from_tags["area"] == "mansion_2"){
  2. //First room in the second half of the mansion.
  3.  
  4. //Draw a line through the mansion layout from the last mansion_1 corridor room to
  5. //get the coordinates of the first mansion_2 corridor room.
  6. //todo: when we add the climb detour we'll have to change this
  7. class room_data last_corridor_room = DM->query_room_data(dun_id,
  8. features["grounds"]+features["ingress"]+features["mansion_1"] - 1);
  9. int *last_coords = last_corridor_room->tags["coords"];
  10. int *detour_coords;
  11. float *vector_1, *vector_2, mag_1, mag_2;
  12. int *sign;
  13. string dir_1, dir_2;
  14.  
  15. from_coords = ({ features["mansion_length"] - last_coords[0] - 1,
  16. features["mansion_length"] - last_coords[1] - 1,
  17. last_coords[2] });
  18. from_tags["coords"] = from_coords;
  19. from_tags["room_type"] = "corridor";
  20.  
  21. detour_coords = ({ features["mansion_length"] - (last_coords[0] * 2) - 1,
  22. features["mansion_length"] - (last_coords[1] * 2) - 1 });
  23. sign = ({
  24. detour_coords[0] ? detour_coords[0] / abs(detour_coords[0]) : 0,
  25. detour_coords[1] ? detour_coords[1] / abs(detour_coords[1]) : 0,
  26. });
  27.  
  28. //Separate out the diagonal and cardinal components of the vector.
  29. //The diagonal component is in vector_1 and the cardinal component is in vector_2.
  30. if (abs(detour_coords[0]) >= abs(detour_coords[1])){
  31. vector_1 = ({ 0.0 + sign[0] * abs(detour_coords[1]), 0.0 + detour_coords[1] });
  32. vector_2 = ({ 0.0 + detour_coords[0] - vector_1[0], 0.0 });
  33. } else {
  34. vector_1 = ({ 0.0 + detour_coords[0], 0.0 + sign[1] * abs(detour_coords[0]) });
  35. vector_2 = ({ 0.0, 0.0 + detour_coords[1] - vector_1[1] });
  36. }
  37.  
  38. //Then, find the direction of each component to determine which exit directions we're
  39. //using.
  40. dir_1 = "";
  41. if (vector_1[1] < 0)
  42. dir_1 += "north";
  43. else if (vector_1[1] > 0)
  44. dir_1 += "south";
  45. if (vector_1[0] < 0)
  46. dir_1 += "west";
  47. else if (vector_1[0] > 0)
  48. dir_1 += "east";
  49.  
  50. dir_2 = "";
  51. if (vector_2[1] < 0)
  52. dir_2 += "north";
  53. else if (vector_2[1] > 0)
  54. dir_2 += "south";
  55. if (vector_2[0] < 0)
  56. dir_2 += "west";
  57. else if (vector_2[0] > 0)
  58. dir_2 += "east";
  59.  
  60. //Finally, find the ratio between the magnitudes of each component to determine
  61. //how many of each exit we'll use.
  62. mag_1 = sqrt(pow(vector_1[0], 2) + pow(vector_1[1], 2));
  63. mag_2 = sqrt(pow(vector_2[0], 2) + pow(vector_2[1], 2));
  64.  
  65. features["detour_directions"] = ({ });
  66.  
  67. for (int i=1;i<4;i++){
  68. if ((mag_1+mag_2) * i/4 < mag_1)
  69. features["detour_directions"] += ({ dir_1 });
  70. else
  71. features["detour_directions"] += ({ dir_2 });
  72. }
  73.  
  74. features["detour_directions"] = shuffle(features["detour_directions"]);
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement