2017-06-16 20:31:54 -03:00
|
|
|
########################################
|
|
|
|
#
|
|
|
|
# BARRIER-RELATED FUNCTIONS
|
|
|
|
#
|
|
|
|
########################################
|
|
|
|
|
|
|
|
#
|
|
|
|
# Constants
|
|
|
|
#
|
2017-09-11 19:01:56 -03:00
|
|
|
BARRIER_TIMEOUT = 1200 # in steps
|
2017-09-06 00:48:50 -03:00
|
|
|
BARRIER_VSTIG = 80
|
2017-09-05 01:34:59 -03:00
|
|
|
timeW = 0
|
2017-09-06 00:48:50 -03:00
|
|
|
barrier = nil
|
2017-06-16 20:31:54 -03:00
|
|
|
|
|
|
|
#
|
|
|
|
# Sets a barrier
|
|
|
|
#
|
2017-09-06 00:48:50 -03:00
|
|
|
function barrier_create() {
|
2017-09-05 01:34:59 -03:00
|
|
|
# reset
|
|
|
|
timeW = 0
|
|
|
|
# create barrier vstig
|
2017-09-06 00:48:50 -03:00
|
|
|
#log("---> Prev. br. ", barrier, " ", BARRIER_VSTIG)
|
|
|
|
if(barrier!=nil) {
|
|
|
|
barrier=nil
|
|
|
|
BARRIER_VSTIG = BARRIER_VSTIG +1
|
|
|
|
}
|
|
|
|
#log("---> New. br. ", barrier, " ", BARRIER_VSTIG)
|
|
|
|
barrier = stigmergy.create(BARRIER_VSTIG)
|
2017-09-05 01:34:59 -03:00
|
|
|
}
|
|
|
|
|
2017-09-06 00:48:50 -03:00
|
|
|
function barrier_set(threshold, transf, resumef, bdt) {
|
2017-06-16 20:31:54 -03:00
|
|
|
statef = function() {
|
2017-09-06 20:18:20 -03:00
|
|
|
barrier_wait(threshold, transf, resumef, bdt);
|
2017-06-16 20:31:54 -03:00
|
|
|
}
|
2017-09-05 01:34:59 -03:00
|
|
|
UAVSTATE = "BARRIERWAIT"
|
2017-09-06 00:48:50 -03:00
|
|
|
barrier_create()
|
2017-06-16 20:31:54 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Make yourself ready
|
|
|
|
#
|
|
|
|
function barrier_ready() {
|
2017-11-27 23:55:32 -04:00
|
|
|
#log("BARRIER READY -------")
|
2017-06-16 20:31:54 -03:00
|
|
|
barrier.put(id, 1)
|
2017-09-05 01:34:59 -03:00
|
|
|
barrier.put("d", 0)
|
2017-06-16 20:31:54 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Executes the barrier
|
|
|
|
#
|
2017-09-06 00:48:50 -03:00
|
|
|
function barrier_wait(threshold, transf, resumef, bdt) {
|
2017-06-16 20:31:54 -03:00
|
|
|
barrier.put(id, 1)
|
2017-08-30 18:22:37 -03:00
|
|
|
|
|
|
|
barrier.get(id)
|
2017-11-27 23:55:32 -04:00
|
|
|
#log("--->BS: ", barrier.size(), " (", BARRIER_VSTIG, ")")
|
2017-09-06 00:48:50 -03:00
|
|
|
if(barrier.size() - 1 >= threshold or barrier.get("d") == 1) {
|
2017-09-05 01:34:59 -03:00
|
|
|
barrier.put("d", 1)
|
|
|
|
timeW = 0
|
2017-06-16 20:31:54 -03:00
|
|
|
transf()
|
2017-08-30 15:58:44 -03:00
|
|
|
} else if(timeW >= BARRIER_TIMEOUT) {
|
2017-09-06 00:48:50 -03:00
|
|
|
log("------> Barrier Timeout !!!!")
|
2017-09-19 17:20:23 -03:00
|
|
|
barrier=nil
|
2017-09-05 01:34:59 -03:00
|
|
|
timeW = 0
|
2017-06-16 20:31:54 -03:00
|
|
|
resumef()
|
2017-09-06 00:48:50 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
if(bdt!=-1)
|
|
|
|
neighbors.broadcast("cmd", bdt)
|
2017-08-30 18:22:37 -03:00
|
|
|
|
2017-06-16 20:31:54 -03:00
|
|
|
timeW = timeW+1
|
2017-08-09 20:23:42 -03:00
|
|
|
}
|
|
|
|
|
2017-08-30 18:22:37 -03:00
|
|
|
# get the lowest id of the fleet, but requires too much bandwidth...
|
2017-08-09 20:23:42 -03:00
|
|
|
function getlowest(){
|
2017-08-30 18:22:37 -03:00
|
|
|
Lid = 15;
|
|
|
|
u=15
|
2017-08-09 20:23:42 -03:00
|
|
|
while(u>=0){
|
|
|
|
tab = barrier.get(u)
|
|
|
|
if(tab!=nil){
|
|
|
|
if(tab<Lid)
|
|
|
|
Lid=tab
|
|
|
|
}
|
|
|
|
u=u-1
|
|
|
|
}
|
|
|
|
log("--> LOWEST ID:",Lid)
|
2017-09-11 19:01:56 -03:00
|
|
|
}
|