Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [quote author=Khamukkamu link=action=profile;u=178899 date=1487510167]
- Thanks for your reply. Yea, i'm afraid of touching AI cause it can do so much harm.
- 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:
- Goal: Don't let the scout camp spawn on water, mountains, river.
- [spoiler][code]
- (assign, ":terrain_check", 0), # Check if spawned camp is not in weird terrain
- (try_for_range, ":iterate", 0, 10),
- (eq, ":terrain_check",0),
- (set_spawn_radius, 35),
- (spawn_around_party,"$g_talk_troop",":quest_target_party_template"),
- (try_begin),
- (party_get_current_terrain, ":terrain_type", reg0),
- (neq, ":terrain_type", rt_water),
- (neq, ":terrain_type", rt_mountain),
- (neq, ":terrain_type", rt_river),
- (assign, "$qst_destroy_scout_camp_party", reg0),
- (assign, ":terrain_check", 1),
- (else_try),
- (remove_party, reg0),
- (try_end),
- (try_end),
- (try_begin), #last ditch effort, if 10 iterations of the above doesnt work, just spawn it, and hope for the best
- (party_is_active, "$qst_destroy_scout_camp_party"),
- (else_try),
- (set_spawn_radius, 35),
- (spawn_around_party,"$g_talk_troop",":quest_target_party_template"),
- (assign, "$qst_destroy_scout_camp_party", reg0),
- (try_end),
- [/code][/spoiler]
- 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).
- Thanks
- [/quote]
- At a glance it makes sense, try it out, if it doesn't work I can help you tweak it.
- 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:
- [tt]
- + + +
- + X +
- + + +
- + - + - +
- - = = = -
- + = X = +
- - = = = -
- + - + - +
- + - - + - - +
- - = o = o = -
- - o = = = o -
- + = = X = = +
- - o = = = o -
- - = o = o = -
- + - - + - - +
- + - - - + - - - +
- - = o o = o o = -
- - o = o = o = o -
- - o o = = = o o -
- + = = = X = = = +
- - o o = = = o o -
- - o = o = o = o -
- - = o o = o o = -
- + - - - + - - - +
- diagram legend:
- + => probe point
- - => unprobed point in this sweep
- = => unsucesfully probed point in previous sweep
- o => hole in the grid, unprobed point
- X => sweep center
- /* pseudocode */
- max_area = 4 points
- x, y = center point of the sweep
- if not probe(x, y)
- for (sweep_size=1; sweep_size<=max_area; sweep_size++)
- # precompute the coordinates
- top = y - sweep_size
- mid = y
- bot = y + sweep_size
- lef = x - sweep_size
- cen = x
- rig = x + sweep_size
- # probe and bail out if we have a match
- probe(lef, top) # top left
- probe(cen, top) # top center
- probe(rig, top) # top right
- probe(lef, mid) # center left
- #probe(cen, mid) # center center, we already tested this once
- probe(rig, mid) # center right
- probe(lef, bot) # bottom left
- probe(cen, bot) # bottom center
- probe(rig, bot) # bottom right[/tt]
- Feel free to make it a bit more complicated to cover the increasingly bigger holes.
- Hope that helps.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement