Advertisement
Guest User

Untitled

a guest
Feb 19th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.19 KB | None | 0 0
  1. [quote author=Khamukkamu link=action=profile;u=178899 date=1487510167]
  2. Thanks for your reply. Yea, i'm afraid of touching AI cause it can do so much harm.
  3.  
  4. I have another unrelated question, it is more of a 'programming' type of question, cause i really feel like this could be done better/more elegantly:
  5.  
  6. Goal: Don't let the scout camp spawn on water, mountains, river.
  7.  
  8. [spoiler][code]
  9. (assign, ":terrain_check", 0), # Check if spawned camp is not in weird terrain
  10. (try_for_range, ":iterate", 0, 10),
  11. (eq, ":terrain_check",0),
  12. (set_spawn_radius, 35),
  13. (spawn_around_party,"$g_talk_troop",":quest_target_party_template"),
  14. (try_begin),
  15. (party_get_current_terrain, ":terrain_type", reg0),
  16. (neq, ":terrain_type", rt_water),
  17. (neq, ":terrain_type", rt_mountain),
  18. (neq, ":terrain_type", rt_river),
  19. (assign, "$qst_destroy_scout_camp_party", reg0),
  20. (assign, ":terrain_check", 1),
  21. (else_try),
  22. (remove_party, reg0),
  23. (try_end),
  24. (try_end),
  25. (try_begin), #last ditch effort, if 10 iterations of the above doesnt work, just spawn it, and hope for the best
  26. (party_is_active, "$qst_destroy_scout_camp_party"),
  27. (else_try),
  28. (set_spawn_radius, 35),
  29. (spawn_around_party,"$g_talk_troop",":quest_target_party_template"),
  30. (assign, "$qst_destroy_scout_camp_party", reg0),
  31. (try_end),
  32. [/code][/spoiler]
  33.  
  34. Can you take a look on how to improve this? I put a last ditch effort condition there, just in case the iteration fails (im not even sure if i did the iteration right).
  35.  
  36. Thanks
  37. [/quote]
  38.  
  39. At a glance it makes sense, try it out, if it doesn't work I can help you tweak it.
  40.  
  41. The alternative is probing along a '[i]grid[/i]' centered in the point you want to test, and doing increasingly bigger sweeps along the border:
  42.  
  43. [tt]
  44. + + +
  45. + X +
  46. + + +
  47.  
  48. + - + - +
  49. - = = = -
  50. + = X = +
  51. - = = = -
  52. + - + - +
  53.  
  54. + - - + - - +
  55. - = o = o = -
  56. - o = = = o -
  57. + = = X = = +
  58. - o = = = o -
  59. - = o = o = -
  60. + - - + - - +
  61.  
  62. + - - - + - - - +
  63. - = o o = o o = -
  64. - o = o = o = o -
  65. - o o = = = o o -
  66. + = = = X = = = +
  67. - o o = = = o o -
  68. - o = o = o = o -
  69. - = o o = o o = -
  70. + - - - + - - - +
  71.  
  72. diagram legend:
  73. + => probe point
  74. - => unprobed point in this sweep
  75. = => unsucesfully probed point in previous sweep
  76. o => hole in the grid, unprobed point
  77. X => sweep center
  78.  
  79.  
  80. /* pseudocode */
  81.  
  82. max_area = 4 points
  83. x, y = center point of the sweep
  84.  
  85. if not probe(x, y)
  86. for (sweep_size=1; sweep_size<=max_area; sweep_size++)
  87. # precompute the coordinates
  88. top = y - sweep_size
  89. mid = y
  90. bot = y + sweep_size
  91.  
  92. lef = x - sweep_size
  93. cen = x
  94. rig = x + sweep_size
  95.  
  96. # probe and bail out if we have a match
  97. probe(lef, top) # top left
  98. probe(cen, top) # top center
  99. probe(rig, top) # top right
  100.  
  101. probe(lef, mid) # center left
  102. #probe(cen, mid) # center center, we already tested this once
  103. probe(rig, mid) # center right
  104.  
  105. probe(lef, bot) # bottom left
  106. probe(cen, bot) # bottom center
  107. probe(rig, bot) # bottom right[/tt]
  108.  
  109. Feel free to make it a bit more complicated to cover the increasingly bigger holes.
  110.  
  111. Hope that helps.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement