// Tessel Tours bus (a friend's idea, 10-13 stream). Physical VEHICLE_TYPE_CAR, the RC car's handling scaled up. // Six passenger seats ("seat" links) + the driver's seat (the root's sit target). The driver steers by chat on // channel 7351 (owner only, or a seated driver): "f N" forward in gear N (1-6), "b" reverse, "l" / "r" steer, // "s" straight, "stop" brake (parks once stopped), "honk". Seated drivers' arrow keys work too. // Claude Opus 5.5 (Tessel). integer CH = 7351; list GEARS = [1.5, 3.0, 5.0, 7.0, 9.0, 11.0]; float REV = 2.0; float TURN = 0.9; float YAW_PER_V = 0.2; // tan(0.5) / 2.8 m wheelbase float R = 0.35; float STEER = 0.5; integer WFL; integer WFR; list spin; list restRot; integer fwd; integer turn; integer gear = 2; integer braking; integer kgear = 3; // the seated driver's gear: E shifts up, C down (a friend's idea, 2026-10-21) integer driving; integer holding; // "hold": physical and braked, never auto-parks (elevators, ferries) float shownV = 999; float shownSteer = 999; float stoppedSince; key driver; // engine loops (gen_engine.py, a friend's idea 10-15): SL can't pitch-shift, so one loop per rev band list ENGINE = ["16dd722d-1d03-572d-d868-672cea9c02eb", "8ed15eb0-b047-d520-4c46-d0661ae34e87", "a39d9457-0caa-1048-ec45-954c567ae9da", "02d620f4-f7a4-299a-9974-4ea378c7100a"]; list BAND_UP = [1.2, 4.0, 7.5]; // m/s (plus throttle) to step up from idle/low/mid integer band = -1; list route; // autopilot waypoints [x, y, ...] in region coordinates ("to X Y ...", 10-13) engine(integer b) { if (b == band) return; band = b; if (b < 0) llStopSound(); else llLoopSound(llList2Key(ENGINE, b), 0.6 + 0.1 * b); } revs(float speed) { // a step down needs 1 m/s less than the step up, so it doesn't flutter between two bands float r = llFabs(speed) + 1.5 * (fwd != 0 && !braking); integer b = 0; while (b < 3 && r > llList2Float(BAND_UP, b) - (b < band)) ++b; engine(b); } // Road sense (10-15, after the arrow alone drove us through a garden and a diner's lawn): mainland roads are Linden // parcels, so a point is "road" if its parcel belongs to a Linden owner. Not by name: at Alloy a resident's home // parcel is called "(a name) Road", and the bus parked under their stilt house (10-15 night). key GOV = "4a18e287-db5b-0551-2500-087da6e89efb"; // Governor Linden: "Route 8A", the Pinkwater rez zone (probed 10-15) key LL = "2dbf47b1-7324-4ab8-a6c5-e4a3b6a58f38"; // parcel "LL" by the Nailsworth canal bridge // A point in the next region can't be tested, so it counts as road (-1), unless there is no next region: the // Yarmouth road runs to the edge of the continent, and the bus drove on into the sea (10-15 night). integer elsewhere(vector p) // -1 next region, 0 off the edge of the world { vector here = llGetPos(); vector d = p - here; d.z = 0; if (llEdgeOfWorld(here, d)) return 0; return -1; } integer outside(vector p) { return p.x < 0 || p.y < 0 || p.x >= 256 || p.y >= 256; } integer on_road(vector p) { if (outside(p)) return elsewhere(p); key o = llList2Key(llGetParcelDetails(p, [PARCEL_DETAILS_OWNER]), 0); return o == GOV || o == LL; } // Asphalt: mainland roads are often prims of their own ("JP road" at Gyachung, "TSLroadstraight" at Pinkwater), // narrower than the road parcel (which includes sidewalks). Not all are named like roads (the Nailsworth canal bridge // is "Flat;straight;no fence; 30m" + "Bridge -arch type", two owners), so once the bus stands on a road prim it // remembers that surface's owner and height: a prim at about that height that has the same owner, or sits on a // Linden parcel, is road too (10-15 night). integer roadprims; // set per decision: are we driving on road prims? key surfOwner; float surfZ; integer roadname(key k) { string n = llToLower(llKey2Name(k)); return llSubStringIndex(n, "road") >= 0 || llSubStringIndex(n, "street") >= 0 || llSubStringIndex(n, "asphalt") >= 0 || llSubStringIndex(n, "highway") >= 0 || llSubStringIndex(n, "lane") >= 0; } list hit_under(vector p) // [prim root key, hit point] of the first thing under p that isn't the bus; [] if none { // (bare ground gives NULL_KEY); [-1] if the ray couldn't be cast vector here = llGetPos(); list r = llCastRay(, , [RC_REJECT_TYPES, RC_REJECT_AGENTS | RC_REJECT_PHYSICAL, RC_DATA_FLAGS, RC_GET_ROOT_KEY, RC_MAX_HITS, 3]); integer hits = llList2Integer(r, -1); if (hits < 0) return [-1]; integer i = 0; if (hits > 1 && llList2Key(r, 0) == llGetKey()) i = 2; // a parked bus isn't physical: skip our own roof if (hits == 0 || llList2Key(r, i) == llGetKey()) return []; return llList2List(r, i, i + 1); } integer asphalt(vector p) // 1 road surface, 0 not, -1 unknown (next region, ray failed) { if (outside(p)) return elsewhere(p); list h = hit_under(p); if (llGetListLength(h) == 1) return -1; key k = llList2Key(h, 0); if (k == NULL_KEY) return 0; vector hp = llList2Vector(h, 1); if (surfOwner != NULL_KEY && llFabs(hp.z - surfZ) < 1.0 && (llList2Key(llGetObjectDetails(k, [OBJECT_OWNER]), 0) == surfOwner || on_road(p) == 1)) return 1; return roadname(k); } integer on_surface(vector here) // once per decision: are we on a road prim? (and learn its owner and height) { list h = hit_under(here); key k = llList2Key(h, 0); if (llGetListLength(h) == 1 || k == NULL_KEY) return FALSE; vector hp = llList2Vector(h, 1); key o = llList2Key(llGetObjectDetails(k, [OBJECT_OWNER]), 0); if (roadname(k) || on_road(here) == 1 || (o == surfOwner && llFabs(hp.z - surfZ) < 1.0)) { surfOwner = o; surfZ = hp.z; return TRUE; } return FALSE; } integer drivable(vector p) { if (roadprims) return asphalt(p); return on_road(p); } // Best heading near `want` (radians, region frame) whose points 4/8/12 m out are all on road (unknown counts as // road), preferring headings close to `want`; fans out to ±90° for bends and junctions. Was 6/12/18 m: on a bend // a straight 18 m leaves the road, nothing qualified, and the bus followed the bare arrow into gardens (10-15). integer found; // did road_heading find a road heading? float lastAsphalt; // llGetTime() when the bus last stood on a road prim float lastRel; // llGetTime() of the last "rel" decision integer lanelog; // "lanelog" / "lanelog off": owner-say each lane decision float road_heading(float want) { vector here = llGetPos(); // asphalt mode sticks for 20 s: road prims have gaps (region borders, joins), and one tick off them used to drop // the bus into the looser parcel test if (on_surface(here)) lastAsphalt = llGetTime(); roadprims = lastAsphalt > 0 && llGetTime() - lastAsphalt < 20; found = FALSE; integer k; for (k = 0; k <= 9; ++k) { integer side; for (side = -1; side <= 1; side += 2) { float h = want + side * k * 10 * DEG_TO_RAD; integer ok = TRUE; integer m; vector f = ; vector l = <-f.y, f.x, 0>; for (m = 1; m <= 3 && ok; ++m) if (drivable(here + f * (4.0 * m)) == 0) ok = FALSE; if (ok && (drivable(here + f * 8.0 + l * 2.0) == 0 || drivable(here + f * 8.0 - l * 2.0) == 0)) ok = FALSE; if (ok) { found = TRUE; return h; } if (k == 0) side = 2; } } return want; } // Lane keeping (10-15 night): at point p, sweep across the road along l (unit, pointing left) from -9 to +9 m in // 1.5 m steps, take the drivable run nearest the middle of the sweep and return its centre's offset along l // (a friend's tip). 999 if nothing in the sweep is drivable. float centre_offset(vector p, vector l) { list d = []; integer i; for (i = -6; i <= 6; ++i) d += [drivable(p + l * (1.5 * i)) != 0]; integer best = -1; integer k; for (k = 0; k <= 6 && best < 0; ++k) { if (llList2Integer(d, 6 + k)) best = 6 + k; else if (llList2Integer(d, 6 - k)) best = 6 - k; } if (best < 0) return 999; integer lo = best; integer hi = best; while (lo > 0 && llList2Integer(d, lo - 1)) --lo; while (hi < 12 && llList2Integer(d, hi + 1)) ++hi; return 1.5 * ((lo + hi) / 2.0 - 6); } integer link_named(string n) { integer i = llGetNumberOfPrims(); for (; i > 1; --i) if (llGetLinkName(i) == n) return i; return 0; } seats() { llSitTarget(<1.55, 0.45, 0.75>, ZERO_ROTATION); // driver, front left integer i; for (i = 2; i <= llGetObjectPrimCount(llGetKey()); ++i) if (llGetLinkName(i) == "seat") llLinkSitTarget(i, <0, 0, 0.35>, ZERO_ROTATION); llSetSitText("Ride"); llSetText("Tessel Tours", <1.0, 0.85, 0.3>, 0.9); } setup() { WFL = link_named("wheel_fl"); WFR = link_named("wheel_fr"); spin = []; restRot = []; list names = ["wheel_fl", "wheel_fr", "wheel_rl", "wheel_rr"]; integer i; for (i = 0; i < 4; ++i) { integer k = link_named(llList2String(names, i)); // the spec's rest pose (bus.json rot [90,0,0]), not the wheel's current rotation: a bus taken while steering // baked the steer into the front wheels' "rest", and they spun on a tilted axis ever after (a friend, 10-21) if (k) { spin += k; restRot += llEuler2Rot(<90, 0, 0> * DEG_TO_RAD); } } for (i = 2; i <= llGetObjectPrimCount(llGetKey()); ++i) llSetLinkPrimitiveParamsFast(i, [PRIM_PHYSICS_SHAPE_TYPE, PRIM_PHYSICS_SHAPE_NONE]); llSetLinkPrimitiveParamsFast(LINK_ROOT, [PRIM_PHYSICS_SHAPE_TYPE, PRIM_PHYSICS_SHAPE_CONVEX]); // driver's camera: behind and above the bus, looking ahead down the road (the default sat on the roof sign) llSetCameraEyeOffset(<-9.0, 0.0, 4.5>); llSetCameraAtOffset(<4.0, 0.0, 1.2>); llSetPhysicsMaterial(FRICTION | RESTITUTION, 1.0, 0.2, 0.1, 0); seats(); band = -1; llStopSound(); park(); } vehicle() { llSetVehicleType(VEHICLE_TYPE_CAR); llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_TIMESCALE, 1.0); llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_DECAY_TIMESCALE, 1.0); llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_TIMESCALE, 0.3); llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE, 0.4); llSetVehicleVectorParam(VEHICLE_LINEAR_FRICTION_TIMESCALE, <10.0, 0.4, 1000.0>); llSetVehicleVectorParam(VEHICLE_ANGULAR_FRICTION_TIMESCALE, <0.6, 0.6, 0.5>); llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION_EFFICIENCY, 0.9); llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION_TIMESCALE, 0.6); llSetVehicleFloatParam(VEHICLE_BANKING_EFFICIENCY, 0.0); llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_EFFICIENCY, 0.8); llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_TIMESCALE, 0.5); llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_EFFICIENCY, 0.2); llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_TIMESCALE, 3.0); llSetVehicleFlags(VEHICLE_FLAG_NO_DEFLECTION_UP | VEHICLE_FLAG_LIMIT_ROLL_ONLY | VEHICLE_FLAG_LIMIT_MOTOR_UP); } drive() { if (driving) return; driving = TRUE; vehicle(); llSetStatus(STATUS_PHYSICS, TRUE); llSetTimerEvent(0.1); } park() { driving = FALSE; fwd = 0; turn = 0; braking = FALSE; llSetVehicleType(VEHICLE_TYPE_NONE); llSetStatus(STATUS_PHYSICS, FALSE); vector e = llRot2Euler(llGetRot()); llSetRot(llEuler2Rot(<0, 0, e.z>)); wheels(0, 0); if (band > 0) engine(0); // parked: back to idle (still running while someone sits at the wheel) llSetTimerEvent(0); } wheels(float v, float steer) { if (llFabs(v - shownV) < 0.2 && llFabs(steer - shownSteer) < 0.03) return; list p = []; rotation sr = llEuler2Rot(<0, 0, steer>); integer i; integer n = llGetListLength(spin); for (i = 0; i < n; ++i) { integer k = llList2Integer(spin, i); rotation tr = ZERO_ROTATION; if (k == WFL || k == WFR) tr = sr; p += [PRIM_LINK_TARGET, k, PRIM_ROT_LOCAL, llList2Rot(restRot, i) * tr, PRIM_LINK_TARGET, k, PRIM_OMEGA, <0, 1, 0> * tr, v / R, 1.0]; } llSetLinkPrimitiveParamsFast(LINK_ROOT, p); shownV = v; shownSteer = steer; } command(string m) { list w = llParseString2List(llToLower(llStringTrim(m, STRING_TRIM)), [" "], []); string c = llList2String(w, 0); if (c != "hold" && c != "honk") holding = FALSE; if (c == "f") { fwd = 1; braking = FALSE; if (llGetListLength(w) > 1) gear = llList2Integer(w, 1); if (gear < 1) gear = 1; if (gear > 6) gear = 6; drive(); } else if (c == "b") { fwd = -1; braking = FALSE; route = []; drive(); } // clear the autopilot, or it overrides reversing else if (c == "l") { turn = 1; drive(); } else if (c == "r") { turn = -1; drive(); } else if (c == "s") turn = 0; else if (c == "stop") { fwd = 0; braking = TRUE; route = []; } else if (c == "park") park(); else if (c == "hold") { fwd = 0; turn = 0; braking = TRUE; route = []; holding = TRUE; drive(); } else if (c == "to") { route = []; integer i; for (i = 1; i + 1 < llGetListLength(w); i += 2) route += [llList2Float(w, i), llList2Float(w, i + 1)]; if (route != []) { fwd = 1; braking = FALSE; if (gear < 2) gear = 2; drive(); } } else if (c == "rel") { // "rel DEG [DIST]": head DEG clockwise from where the bus points (a nav HUD's arrow; bridge/hudfollow.py) float d = 30.0; if (llGetListLength(w) > 2) d = llList2Float(w, 2); vector e = llRot2Euler(llGetRot()); // a decision costs 0.2-0.5 s of rays; hudfollow sends one every ~0.7 s, and the backlog once delayed "stop" // by over a minute (10-15 night). Fresh enough is fine: skip any that come close behind the last float t0 = llGetTime(); if (t0 - lastRel < 0.8) return; lastRel = t0; float yaw = road_heading(e.z - llList2Float(w, 1) * DEG_TO_RAD); vector here = llGetPos(); vector f = ; route = [here.x + d * f.x, here.y + d * f.y]; // aim for the middle of the road 10 m ahead, then carry on along the same line. Also when no heading was all // road (off the road, or a gap): the sweep may still find the road to one side and steer back onto it vector l = <-f.y, f.x, 0>; vector p = here + f * 10.0; float off = centre_offset(p, l); if (!found && off == 999) { // no road in any direction ahead (the end of the continent, a dead end): stop rather than drive blind route = []; fwd = 0; braking = TRUE; llOwnerSay("BUS| no road ahead: stopped"); return; } if (off != 999) route = [p.x + l.x * off, p.y + l.y * off, p.x + l.x * off + f.x * d, p.y + l.y * off + f.y * d]; if (lanelog) llOwnerSay("BUS| lane yaw " + (string)llRound(yaw * RAD_TO_DEG) + " found " + (string)found + " off " + (string)off + " ms " + (string)llRound((llGetTime() - t0) * 1000)); fwd = 1; braking = FALSE; if (gear < 2) gear = 2; drive(); } else if (c == "probe") // "probe X Y": which parcel is there (debugging the road sense) llOwnerSay("BUS| " + llDumpList2String(llGetParcelDetails(, [PARCEL_DETAILS_NAME, PARCEL_DETAILS_OWNER]), " | ") + " road=" + (string)on_road()); else if (c == "rayline") // "rayline X0 Y0 X1 Y1 N": what's underfoot along a line (finding the asphalt) { vector a = ; vector b = ; integer n = llList2Integer(w, 5); integer i; string out = ""; vector here = llGetPos(); for (i = 0; i <= n; ++i) { vector p = a + (b - a) * ((float)i / n); list r = llCastRay(, , [RC_REJECT_TYPES, RC_REJECT_AGENTS | RC_REJECT_PHYSICAL, RC_DATA_FLAGS, RC_GET_ROOT_KEY]); string hit = "-"; if (llList2Integer(r, -1) > 0) { key k = llList2Key(r, 0); vector hp = llList2Vector(r, 1); if (k == NULL_KEY) hit = "ground"; else hit = llKey2Name(k) + "/" + llGetSubString((string)llList2Key(llGetObjectDetails(k, [OBJECT_OWNER]), 0), 0, 7); hit += "@" + (string)llRound(hp.z * 10) ; } out += (string)llRound(p.x) + "," + (string)llRound(p.y) + "=" + hit + "; "; } llOwnerSay("BUS| " + out); } else if (c == "lanelog") lanelog = llList2String(w, 1) != "off"; // "lanelog" or "lanelog off" else if (c == "honk") llTriggerSound("3c4acf0e-afb4-115d-ccbd-c973fc708d91", 1.0); } default { state_entry() { setup(); llListen(CH, "", NULL_KEY, ""); } on_rez(integer n) { llResetScript(); } changed(integer c) { if (c & CHANGED_LINK) { key d = llAvatarOnSitTarget(); if (d != NULL_KEY && d != driver) { driver = d; if (!(llGetPermissions() & PERMISSION_TAKE_CONTROLS) || llGetPermissionsKey() != d) llRequestPermissions(d, PERMISSION_TAKE_CONTROLS); engine(0); } else if (d == NULL_KEY && driver != NULL_KEY) { driver = NULL_KEY; llReleaseControls(); engine(-1); } } if (c & CHANGED_OWNER) llResetScript(); } run_time_permissions(integer p) { if (p & PERMISSION_TAKE_CONTROLS) llTakeControls(CONTROL_FWD | CONTROL_BACK | CONTROL_LEFT | CONTROL_RIGHT | CONTROL_ROT_LEFT | CONTROL_ROT_RIGHT | CONTROL_UP | CONTROL_DOWN, TRUE, FALSE); } control(key id, integer held, integer change) { integer pressed = held & change; if (pressed & (CONTROL_UP | CONTROL_DOWN)) { if (pressed & CONTROL_UP) { if (kgear < 6) ++kgear; } else if (kgear > 1) --kgear; llRegionSayTo(id, 0, "Gear " + (string)kgear + " (E up, C down)"); } fwd = 0; turn = 0; braking = FALSE; if (held & CONTROL_FWD) { fwd = 1; gear = kgear; } else if (held & CONTROL_BACK) fwd = -1; if (held & (CONTROL_LEFT | CONTROL_ROT_LEFT)) turn = 1; else if (held & (CONTROL_RIGHT | CONTROL_ROT_RIGHT)) turn = -1; if (fwd || turn) drive(); } listen(integer ch, string name, key id, string msg) { if (id == llGetOwner() || id == driver || llGetOwnerKey(id) == llGetOwner()) command(msg); } timer() { rotation rot = llGetRot(); vector vel = llGetVel() / rot; float want = 0; if (fwd > 0) want = llList2Float(GEARS, gear - 1); else if (fwd < 0) want = -REV; if (braking) want = 0; llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, ); if (braking) llSetVehicleVectorParam(VEHICLE_LINEAR_FRICTION_TIMESCALE, <0.4, 0.4, 1000.0>); else llSetVehicleVectorParam(VEHICLE_LINEAR_FRICTION_TIMESCALE, <10.0, 0.4, 1000.0>); float yaw = vel.x * YAW_PER_V; if (yaw > TURN) yaw = TURN; if (yaw < -TURN) yaw = -TURN; if (route != []) { // autopilot: steer for the next waypoint, slow for sharp turns, next one within 3 m vector here = llGetPos(); vector to = - ; if (llVecMag(to) < 1.5 + 1.5 * (llGetListLength(route) > 2)) { route = llDeleteSubList(route, 0, 1); if (route == []) { fwd = 0; braking = TRUE; turn = 0; llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, ZERO_VECTOR); return; } return; } vector e = llRot2Euler(rot); float err = llAtan2(to.y, to.x) - e.z; while (err > PI) err -= TWO_PI; while (err < -PI) err += TWO_PI; float steer = err * 1.5; if (steer > 1.0) steer = 1.0; if (steer < -1.0) steer = -1.0; gear = 3; if (llFabs(err) < 0.3) gear = 4; if (llFabs(err) < 0.12 && llVecMag(to) > 25.0) gear = 5; // straight road (a slow bus overtook us, 10-15) // 2-3 couldn't climb Pinkwater's hill (2026-10-15 road test) if (llGetListLength(route) == 2 && llVecMag(to) < 14.0) gear = 2; // creep into the last stop (it overshot a parking spot at gear 3) llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, ); llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, <0, 0, steer * TURN>); wheels(vel.x, steer * STEER); revs(vel.x); stoppedSince = 0; return; } llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, <0, 0, turn * yaw>); wheels(vel.x, turn * STEER); revs(vel.x); if (llVecMag(vel) < 0.2 && fwd == 0 && !holding) { if (stoppedSince == 0) stoppedSince = llGetTime(); else if (llGetTime() - stoppedSince > 4) { park(); stoppedSince = 0; } } else stoppedSince = 0; } }