74 lines
1.2 KiB
Plaintext
74 lines
1.2 KiB
Plaintext
########################################
|
|
#
|
|
# BARRIER-RELATED FUNCTIONS
|
|
#
|
|
########################################
|
|
|
|
#
|
|
# Constants
|
|
#
|
|
BARRIER_TIMEOUT = 200 # in steps
|
|
timeW = 0
|
|
|
|
#
|
|
# Sets a barrier
|
|
#
|
|
function barrier_create(vstig_nb) {
|
|
# reset
|
|
timeW = 0
|
|
# create barrier vstig
|
|
barrier = stigmergy.create(vstig_nb)
|
|
}
|
|
|
|
function barrier_set(threshold, transf, resumef, vstig_nb) {
|
|
statef = function() {
|
|
barrier_wait(threshold, transf, resumef);
|
|
}
|
|
UAVSTATE = "BARRIERWAIT"
|
|
barrier_create(vstig_nb)
|
|
}
|
|
|
|
#
|
|
# Make yourself ready
|
|
#
|
|
function barrier_ready() {
|
|
log("BARRIER READY -------")
|
|
barrier.put(id, 1)
|
|
barrier.put("d", 0)
|
|
}
|
|
|
|
#
|
|
# Executes the barrier
|
|
#
|
|
function barrier_wait(threshold, transf, resumef) {
|
|
barrier.put(id, 1)
|
|
|
|
barrier.get(id)
|
|
if(barrier.size() >= threshold or barrier.get("d")==1) {
|
|
barrier.put("d", 1)
|
|
# barrier = nil
|
|
timeW = 0
|
|
transf()
|
|
} else if(timeW >= BARRIER_TIMEOUT) {
|
|
timeW = 0
|
|
# barrier = nil
|
|
resumef()
|
|
}
|
|
|
|
timeW = timeW+1
|
|
}
|
|
|
|
# get the lowest id of the fleet, but requires too much bandwidth...
|
|
function getlowest(){
|
|
Lid = 15;
|
|
u=15
|
|
while(u>=0){
|
|
tab = barrier.get(u)
|
|
if(tab!=nil){
|
|
if(tab<Lid)
|
|
Lid=tab
|
|
}
|
|
u=u-1
|
|
}
|
|
log("--> LOWEST ID:",Lid)
|
|
} |