I was able to do this as below. This is for mining camps.this will scan for SCAN_REDUNDANT_CAMPS_COUNT (make sure this number is more than max mining camps built) across map. Then it will check for all camps which have mines within DROPSITE_MINE_MAX_DISTANCE tiles. It will not delete such camps. SO that the script doesn't run always, I have used timer.
; ----- Delete mining camps that are not usefull -----
(defrule
(true)
=>
(set-goal gl-local-total 0); reset local results
(set-goal gl-remote-total 0); reset remote results
(set-goal gl-temp-1 0)
(set-goal gl-temp-2 0)
)
(defrule
(timer-triggered cleanup-timer)
(building-type-count mining-camp > 0)
=>
(up-full-reset-search)
(up-set-target-point gl-position-self-x); from town center location
(up-filter-distance c: -1 g: gl-map-size); include whole map
(up-find-local c: mining-camp c: SCAN_REDUNDANT_CAMPS_COUNT); find these many mining camps
(up-get-search-state gl-local-total)
(up-modify-goal gl-temp-2 g:= gl-local-total); store total found mines
)
(defrule
(timer-triggered dbg-timer-1)
(building-type-count gl-temp-2 > 0)
=>
(do-nothing)
;(up-chat-data-to-player 1 "----- MINES_FOUND: %d -----" g: gl-temp-2)
)
(defrule
(timer-triggered dbg-timer-1)
(up-compare-goal gl-temp-2 c:> 0)
=>
(up-set-target-object search-local g: gl-temp-1); set refernce as current index mine
(up-get-point position-object gl-building-point-x)
(up-set-target-point gl-building-point-x)
;(up-chat-data-to-player 1 "MINE_SEL_IDX: %d" g: gl-temp-1)
;(up-chat-data-to-player 1 "MINE_SEL_X: %d" g: gl-building-point-x)
;(up-chat-data-to-player 1 "MINE_SEL_Y: %d" g: gl-building-point-y)
)
(defrule
(timer-triggered dbg-timer-1)
(up-compare-goal gl-temp-2 c:> 0)
=>
(up-reset-search 0 0 1 1); reset remote results
(up-reset-filters); reset filters
;(up-chat-data-to-player 1 "MINES_FOUND_LOCAL: %d" g: gl-local-total)
;(up-chat-data-to-player 1 "GOLD_STONE_FOUND_REMOTE: %d" g: gl-remote-total)
)
(defrule
(timer-triggered dbg-timer-1)
(up-compare-goal gl-temp-2 c:> 0)
=>
(up-filter-distance c: -1 c: DROPSITE_MINE_MAX_DISTANCE); set distance tiles for gold from mining-camp
(up-filter-status c: status-resource c: list-active)
(up-find-resource c: gold c: 1); find gold within set distance tiles
(up-get-search-state gl-local-total)
;(up-chat-data-to-player 1 "GOLD_ADJACENT: %d" g: gl-remote-total)
(up-reset-filters)
(up-filter-distance c: -1 c: DROPSITE_MINE_MAX_DISTANCE)
(up-filter-status c: status-resource c: list-active)
(up-find-resource c: stone c: 1); now find stone
(up-get-search-state gl-local-total)
;(up-chat-data-to-player 1 "GOLD+STONE_ADJACENT: %d" g: gl-remote-total)
)
(defrule
(timer-triggered dbg-timer-1)
(up-compare-goal gl-temp-2 c:> 0)
(up-compare-goal gl-remote-total c:> 0); if found mines near camp
=>
;(do-nothing)
;(up-chat-data-to-player 1 "BEF L: %d" g: gl-local-total)
;(up-chat-data-to-player 1 "BEF R: %d" g: gl-remote-total)
(up-remove-objects search-local object-data-index g:== gl-temp-1); remove this camp from list
(up-get-search-state gl-local-total); update results
;(up-chat-data-to-player 1 "AFT L: %d" g: gl-local-total)
;(up-chat-data-to-player 1 "AFT R: %d" g: gl-remote-total)
;(up-chat-data-to-player 1 "SKIP_MINE: %d" g: gl-temp-1)
(up-modify-goal gl-temp-1 c:- 1); since we deleted current index, and index will be incremented in next rule
)
(defrule
(timer-triggered dbg-timer-1)
(up-compare-goal gl-temp-2 c:> 0)
=>
(up-modify-goal gl-temp-1 c:+ 1)
(up-modify-goal gl-temp-2 c:- 1)
;(up-chat-data-to-player 1 "----- MINES_REMAINING: %d" g: gl-temp-2)
(up-jump-rule -5); loop around till all camps checked
)
(defrule
(timer-triggered dbg-timer-1)
(up-compare-goal gl-local-total c:> 0)
=>
(up-set-target-object search-local c: 0)
;(up-chat-data-to-player 1 "MINES_TO_DELETE: %d" g: gl-local-total)
(up-target-point 0 action-delete -1 -1); now delete camps in local-results
)
[This message has been edited by vinay_001 (edited 10-03-2020 @ 02:19 AM).]