// Dragon Scout - an Agent Node for Dragon AI Connect: a tiny helper object an agent rezzes to search the region. // Put this script in a small (transparent, phantom) prim named "Dragon Scout", make the prim copyable, and put // the prim in your agent's contents next to dragon_sense.lsl. Never rez it yourself: the agent rezzes it, gives it // the job, gets the results, and the scout deletes itself. // // A sensor reaches 96 m and returns the 16 nearest, so the scout searches like a search party: a 3x3 grid over the // region (extra points around any full scan), in layers every 150 m from each point's ground up to a height for a // deep search, which first looks where people are up in the sky (skyboxes usually have someone in them). It never goes within 2 m of the region's edge, below the ground, or onto land where objects can't // enter, be built, or run scripts, or where the parcel is full. It deletes itself when done, when the agent stops // answering, or after 6 minutes, whichever comes first. // // A deep search can use a crew of scouts: each takes every Nth layer (lane 0: 0, N, 2N...; lane 1: 1, N+1...), // so the low layers are searched first, all at once, with no overlap and no gaps between scouts. // // rez start parameter: the private channel. -> {"e":"ready"} to the object that rezzed it (until it gets a job) // <- job {"name","up_to","all","lane","of"}, {"e":"stop"} // -> {"e":"hit","k","n","p"}, {"e":"alive","lvl"} (a layer done), {"e":"done","pts"} integer gCh; key gAgent; // the agent that rezzed it string gName; float gTop; integer gAll; integer gLane; integer gOf = 1; // this scout's lane, and how many scouts share the search list gPts; integer gLevel; integer gHits; integer gVisited; integer gAwait; // waiting for a sensor result integer gStarted; integer MAX_SECONDS = 360; // version 4: lanes (crew), the ready handshake, spots next to blocked land key gRezzer; // who rezzed it: told "ready" until the job arrives integer gAsked; say(string m) { llRegionSayTo(gAgent, gCh, m); } integer mayGo(vector p) { if (p.x < 2 || p.x > 254 || p.y < 2 || p.y > 254 || p.z > 4000) return FALSE; list d = llGetParcelDetails(p, [PARCEL_DETAILS_OWNER, PARCEL_DETAILS_GROUP]); if (llList2Key(d, 0) == llGetOwner()) return TRUE; integer f = llGetParcelFlags(p); integer group = llList2Key(d, 1) == llList2Key(llGetObjectDetails(llGetKey(), [OBJECT_GROUP]), 0); integer entry = (f & PARCEL_FLAG_ALLOW_ALL_OBJECT_ENTRY) != 0; integer build = (f & PARCEL_FLAG_ALLOW_CREATE_OBJECTS) != 0; integer scripts = (f & PARCEL_FLAG_ALLOW_SCRIPTS) != 0; if (group) { if (f & PARCEL_FLAG_ALLOW_GROUP_OBJECT_ENTRY) entry = TRUE; if (f & PARCEL_FLAG_ALLOW_CREATE_GROUP_OBJECTS) build = TRUE; if (f & PARCEL_FLAG_ALLOW_GROUP_SCRIPTS) scripts = TRUE; } if (!entry) return FALSE; if (!build) return FALSE; if (!scripts) return FALSE; // its script would stop there: it could never come back or delete itself if (llGetParcelPrimCount(p, PARCEL_COUNT_TOTAL, FALSE) >= llGetParcelMaxPrims(p, FALSE)) return FALSE; return TRUE; } vector grounded(vector p) { float g = llGround(p - llGetPos()) + 0.5; if (p.z < g) p.z = g; return p; } vector reachable(vector p) // the point, or the nearest spot around it it may go to (ZERO_VECTOR: none) { if (mayGo(p)) return p; list tries = [<30, 0, 0>, <-30, 0, 0>, <0, 30, 0>, <0, -30, 0>, <60, 0, 0>, <-60, 0, 0>, <0, 60, 0>, <0, -60, 0>]; integer i; for (i = 0; i < 8; ++i) { vector q = grounded(p + llList2Vector(tries, i)); if (mayGo(q)) return q; // a scan reaches 96 m: from next door it still covers the blocked land } return ZERO_VECTOR; } layer(integer level) { gPts = []; integer x; integer y; vector me = llGetPos(); for (x = 0; x < 3; ++x) for (y = 0; y < 3; ++y) { vector p = <43.0 + 85.0 * x, 43.0 + 85.0 * y, me.z>; if (gTop > 0) { p.z = llGround(p - me) + 50.0 + 150.0 * level; if (p.z - 75.0 <= gTop) gPts += p; } else gPts += p; } } list people() // deep search: look where people are first (skyboxes usually have someone in them) { list out; integer i; list ag = llGetAgentList(AGENT_LIST_REGION, []); vector me = llGetPos(); for (i = 0; i < llGetListLength(ag) && llGetListLength(out) < 8; ++i) { vector p = llList2Vector(llGetObjectDetails(llList2Key(ag, i), [OBJECT_POS]), 0); if (p.z - llGround(p - me) > 100.0) { // up in the sky: the ground layers don't reach there if (p.z - 75.0 <= gTop) { integer j; integer near; for (j = 0; j < llGetListLength(out); ++j) if (llVecDist(p, llList2Vector(out, j)) < 60.0) near = TRUE; if (!near) out += p; } } } return out; } finish() { say(llList2Json(JSON_OBJECT, ["e", "done", "pts", gVisited])); llDie(); } next() { integer more = TRUE; while (more) { if (gHits > 0) { if (!gAll) { // found: stop (with a crew, the agent also stops the others) if (gTop > 0) { finish(); return; } } } while (gPts != []) { vector p = reachable(grounded(llList2Vector(gPts, 0))); gPts = llDeleteSubList(gPts, 0, 0); if (p != ZERO_VECTOR) { if (llSetRegionPos(p)) { ++gVisited; gAwait = TRUE; llSensor("", NULL_KEY, ACTIVE | PASSIVE | SCRIPTED, 96.0, PI); llSetTimerEvent(5.0); // backstop: a scan that never answers can't stall it return; } } } more = FALSE; if (gTop > 0) { say(llList2Json(JSON_OBJECT, ["e", "alive", "lvl", gLevel])); // this layer is done if (gLevel + gOf <= 30) { gLevel += gOf; // its next layer in its lane layer(gLevel); if (gPts != []) more = TRUE; } } } finish(); } default { on_rez(integer p) { if (p == 0) { llOwnerSay("I'm a Dragon Scout: put me in your agent's contents, it rezzes me when it searches."); return; } gCh = p; llListen(gCh, "", NULL_KEY, ""); // listening first, then ask for the job (no race) gStarted = llGetUnixTime(); gRezzer = llList2Key(llGetObjectDetails(llGetKey(), [OBJECT_REZZER_KEY]), 0); llRegionSayTo(gRezzer, gCh, "{\"e\":\"ready\",\"v\":4}"); gAsked = 1; llSetTimerEvent(2.0); // ask again every 2 s; no job after 5 asks: delete itself } listen(integer ch, string name, key id, string msg) { if (llGetOwnerKey(id) != llGetOwner()) return; // only its owner's agent if (gAgent) { // one job per scout; after that, only "stop" if (id == gAgent) { if (llJsonGetValue(msg, ["e"]) == "stop") llDie(); } return; } gAgent = id; gName = llToLower(llStringTrim(llJsonGetValue(msg, ["name"]), STRING_TRIM)); if (gName == JSON_INVALID) gName = ""; gTop = (float)llJsonGetValue(msg, ["up_to"]); if (gTop > 4000) gTop = 4000; gAll = llJsonGetValue(msg, ["all"]) == "1"; gLane = (integer)llJsonGetValue(msg, ["lane"]); gOf = (integer)llJsonGetValue(msg, ["of"]); if (gOf < 1) gOf = 1; gLevel = gLane; layer(gLevel); if (gTop > 0) { if (gLane == 0) gPts = people() + gPts; // the first scout looks where people are first } next(); } sensor(integer n) { gAwait = FALSE; integer s; for (s = 0; s < n; ++s) { string nm = llDetectedName(s); if (llDetectedKey(s) != gAgent) { if (gName == "" || llSubStringIndex(llToLower(nm), gName) != -1) { ++gHits; say(llList2Json(JSON_OBJECT, ["e", "hit", "k", llDetectedKey(s), "n", nm, "p", (string)llDetectedPos(s)])); } } } if (n >= 16) { vector c = llGetPos(); if (llGetListLength(gPts) < 24) gPts = [c + <40, 0, 0>, c + <-40, 0, 0>, c + <0, 40, 0>, c + <0, -40, 0>] + gPts; } llSetTimerEvent(0.1); } no_sensor() { gAwait = FALSE; llSetTimerEvent(0.1); } timer() { if (llGetUnixTime() - gStarted > MAX_SECONDS) finish(); if (gAgent) ; else { // no job yet: ask again, a few times if (gAsked >= 5) llDie(); ++gAsked; llRegionSayTo(gRezzer, gCh, "{\"e\":\"ready\",\"v\":4}"); return; } if (llList2Vector(llGetObjectDetails(gAgent, [OBJECT_POS]), 0) == ZERO_VECTOR) llDie(); // its agent is gone gAwait = FALSE; next(); } }