/////////////////////////////////////////////////////////////////////////// // Copyright (C) Wizardry and Steamworks 2011 - License: GNU GPLv3 // // Please see: http://www.gnu.org/licenses/gpl.html for legal details, // // rights of fair usage, the disclaimer and warranty conditions. // /////////////////////////////////////////////////////////////////////////// list wasListSubtract(list input, integer value) { integer v = llList2Integer(input, 0); input = llDeleteSubList(input, 0, 0); if(input == []) return [v-value] + input; return [v-value] + wasListSubtract(input, value); } list dualQuicksort(list a, list b) { if(llGetListLength(a) <= 1) return a+b; integer pivot_a = llList2Integer(a, llGetListLength(a)/2); string pivot_b = llList2String(b, llGetListLength(b)/2); a = llDeleteSubList(a, llGetListLength(a)/2, llGetListLength(a)/2); b = llDeleteSubList(b, llGetListLength(b)/2, llGetListLength(b)/2); list less = []; list less_b = []; list more = []; list more_b = []; integer i = 0; do { if(llList2Integer(a, i) > pivot_a) { less += llList2List(a, i, i); less_b += llList2List(b, i, i); } else { more += llList2List(a, i, i); more_b += llList2List(b, i, i); } } while(++i0); llOwnerSay("ERROR: Failed to find notecard."); return; @found_notecard; nQuery = llGetNotecardLine(nName, nLine); } dataserver(key id, string data) { if(id != nQuery) return; if(data == EOF) { state compute; } if(data == "") jump next_line; if(PUNCH_COLUMNS == 0) PUNCH_COLUMNS = llStringLength(data)+1; if(PUNCH_COLUMNS != llStringLength(data)+1) { llOwnerSay("ERROR: Differing number of columns. Please check the notecard."); state default; } integer itra=0; do { program += (integer)llGetSubString(data, itra, itra); } while(++itra 1) wasListSubtract(program, 1); // Decrease probability. integer current_tile=llList2Integer(program, cursor)+1; program=llListReplaceList(program, (list)current_tile, cursor, cursor); // Determine next direction. // up, down, left, right list directions = [ 0, 0, 0, 0 ]; // up, current position - number of columns if(cursor-PUNCH_COLUMNS >= 0) directions=llListReplaceList(directions, (list)llList2Integer(program, cursor-PUNCH_COLUMNS), 0, 0); // down, current position + number of columns if(cursor+PUNCH_COLUMNS < llGetListLength(program)) directions=llListReplaceList(directions, (list)llList2Integer(program, cursor+PUNCH_COLUMNS), 1, 1); // left, current position - 1 if(cursor-1 >= 0) directions=llListReplaceList(directions, (list)llList2Integer(program, cursor-1), 2, 2); // right, current position + 1 if(cursor+1 < llGetListLength(program)); directions=llListReplaceList(directions, (list)llList2Integer(program, cursor+1), 3, 3); directions = dualQuicksort(directions, [ "up", "down", "left", "right" ]); integer itra=llGetListLength(directions)-1; do { if(llList2Integer(directions, itra-1) == 0) jump next; string d = llList2String(directions, itra); if(d == "up") { cursor -= PUNCH_COLUMNS; state up; } if(d == "down") { cursor += PUNCH_COLUMNS; state down; } if(d == "left") { cursor -= 1; state left; } if(d == "right") { cursor += 1; state right; } @next; } while (~(itra-=2)); } } state up { state_entry() { vector cPos = llGetPos(); llSetPos(); state compute; } } state down { state_entry() { vector cPos = llGetPos(); llSetPos(); state compute; } } state left { state_entry() { vector cPos = llGetPos(); llSetPos(); state compute; } } state right { state_entry() { vector cPos = llGetPos(); llSetPos(); state compute; } }