@@ grid code 16-Dec-2007 @@ player version: +grid and inits @@ coded by Tai@Ark of Fools MUX @@ @@ NOTE: edit the LISTEN-INIT attribute to match whatever the message happens @@ to be for init rolls on your game, if there is an init roll. @@ @@ This code makes up an ASCII grid to help players keep track of locations @@ in, for example, a combat scene. @@ It creates one grid code object, and one grid fn object. @@ @@ The "grid code" object should be dropped to enable other players in @@ your location to use the commands. Remember to pick it up again before @@ you disconnect (or "@adisconnect me=get grid code" to do it automatically) @@ On some games, you may need to set a flag to allow your grid code object @@ to execute commands. Check the local help files ("help flags"). @create grid fn @create grid code @force me=&xx-grid grid code=[num(grid fn)] @@ FUNCTION OBJECT @set grid fn=inherit @set grid fn=halt @lock grid fn=me @desc grid fn=functions for the grid code &show-grid grid fn=[ulocal(header-x)][iter(u(list-y),%r[rjust(##,2)][ulocal(show-line,%0,##)])]%r[ulocal(header-x)] &header-x grid fn=%b%b%b[iter(u(list-x),##%b)] &show-line grid fn=[edit(iter(u(list-x),[setq(0,grab(%0,*|##-%1))][center(ifelse(words(%q0),strtrunc(first(%q0,|),3),...),3,.)]),%b,)] &random-x grid fn=extract(get(me/list-x),die(1,25),1) &random-y grid fn=extract(get(me/list-y),die(1,18),1) @@ %0=item, %1=x, %2=y, %3=room &add-item grid fn=[set(%3,an_grid_items:[get(%3/an_grid_items)] %0|[ucstr(%1-%2)])] @@ %0=item, %1=room &add-item-random grid fn=ulocal(add-item,%0,ulocal(random-x),ulocal(random-y),%1) @@ %0=room @@ [max(sub(die(4,2),4),1)] &add-item-tree grid fn=[setq(0,ulocal(tree-diameter))][setq(1,die(1,25))][setq(2,ulocal(random-y))][iter(lnum(%q0),ulocal(add-item-tree-x,%0,%q0,%q1,add(%q2,##)))] &add-item-tree grid fn=[setq(0,ulocal(tree-diameter))][setq(1,die(1,25))][setq(2,ulocal(random-y))][iter(lnum(%q0),ulocal(add-item-tree-x,%0,%q0,ifelse(rand(4),%q1,inc(%q1)),add(%q2,##)))] @@ %0=room, %1=diameter, %2=x start(numerical), %3=y start (numerical) &add-item-tree-x grid fn=[iter(lnum(%1),ifelse(and(lte(%3,18),lte(add(##,%2),25)),ulocal(add-item,TTT,extract(v(list-x),add(##,%2),1),%3,%0),))] &tree-diameter grid fn=max(sub(die(4,2),4),1) &tree-diameter grid fn=max(sub(div(die(8,2),2),4),1) @@ %0=room, %1=attr, %2=xnew, %3=ynew &func-recenter-big grid fn=[setq(0,get(%0/%1))][set(%0,%1:[iter(%q0,ulocal(func-recenter,##,%2,%3))])] @@ %0=item|x-y, %1=new x (ltr), %2=new y (num) &func-recenter grid fn=[first(%0,|)]|[ulocal(func-shift-x,first(after(%0,|),-),%1)]-[ulocal(func-shift-y,last(after(%0,|),-),%2)] &func-conv-x grid fn=ifelse(strmatch(%0,+n*),-[after(%0,+n)],ifelse(strmatch(%0,+*),[add(24,after(%0,+))],[dec(match(u(list-x),%0))])) &func-conv-y grid fn=ifelse(strmatch(%0,+n*),-[after(%0,+n)],ifelse(strmatch(%0,+*),[add(17,after(%0,+))],[dec(%0)])) &func-unconv-x grid fn=ifelse(gte(%0,25),+[sub(%0,24)],ifelse(lt(%0,0),+n[abs(%0)],extract(u(list-x),[inc(%0)],1))) &func-unconv-y grid fn=ifelse(gte(%0,18),+[sub(%0,17)],ifelse(lt(%0,0),+n[abs(%0)],[inc(%0)])) @@ %0=old coord %1=center coord &func-shift-x grid fn=[setq(0,u(func-conv-x,%0))][setq(1,u(func-conv-x,%1))][setq(2,u(func-conv-x,M))][u(func-unconv-x,[add(%q0,sub(%q2,%q1))])] &func-shift-y grid fn=[setq(0,u(func-conv-y,%0))][setq(1,u(func-conv-y,%1))][setq(2,u(func-conv-y,9))][u(func-unconv-y,[add(%q0,sub(%q2,%q1))])] @@ %0=tag, %1=x start, %2=y start, %3=size @@ return |x0-y0 |x1-y1 |x2-y2 etc &func-makebig grid fn=iter(lnum(%3),ulocal(func-makebig-row,%0,%1,add(%2,##),%3)) @@ %0=tag, %1=x start, %2=y, %3=size &func-makebig-row grid fn=iter(lnum(%3),%0|[u(func-unconv-x,add(%1,##))]-[u(func-unconv-y,%2)]) &list-x grid fn=A B C D E F G H I J K L M N O P Q R S T U V W X Y &list-y grid fn=1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 &text-help1 grid fn=Commands: grid%t%t%t%tgrid/clear%r[space(10)]grid/add =-%tgrid/random \[=\]%r[space(10)]grid/move =-%tgrid/trees %r[space(10)]grid/rem [=-]%tgrid/rem0 -%r[space(10)]grid/recenter -%t%tgrid/where %r%r[space(10)]grid/addlayer %t%tgrid/hline = at -%r[space(10)]grid/remlayer %t%tgrid/vline = at -%r[space(10)]grid/save %t%tgrid/addbig = at -%r[space(10)]grid/list%t%t%tgrid/rembig %r[space(10)]grid/show %t%tgrid/movebig =,%r[space(10)]grid/recall %t%tgrid/distance - to -%r[space(10)]grid/clear %r%rContinued in "grid/help 2" &text-help2 grid fn="X" represents a letter from A-Y, and "Y" represents a number from 1-18.%r%rUse these commands for a crude ASCII grid map (e.g., for combat situations.)%rThe base scale is one "square"=5'x5', but the DM is free to redefine it.%rAnyone may use any of the commands, but please wait for DM instructions.%rGrids may be saved, viewed, and recalled (only by the person who saved it).%r%r "grid/clear" clears the current grid.%r "grid/clear " clears a saved grid.%r "grid/list" shows the grids you have saved.%r "grid/rem0 x-y" removes an item from grid position x-y.%r "grid/spammadd =-" same as grid/add but silent.%r "grid/spamrem0 -" same as grid/rem but silent.%r "grid/recenter -" recenters the grid at a new point. Note that the data is saved until you "grid/clear" or "grid/recall" a different "grid", so items that went "off-grid" are still there.%r%rContinued in "grid/help 3" &text-help3 grid fn="grid/random [=]" places at a random location on the +grid.%r"grid/trees" places "TTT" objects on the +grid, with the size also randomized.%r"grid/distance" calculates the distance to the closest 5' between 2 grid points.%r"grid/where " gives the coordinates of .%r"grid/addlayer " and "grid/remlayer " add or delete a previously saved grid to the current grid in the room. (It will overlay the existing grid.)%r"grid/addbig = at -" adds "" in a square block units long on each side, with the upper left corner at -.%r"grid/rembig " removes a big item previously set.%r"grid/movebig =," moves a big item previously set on the +grid with . A positive displacement moves it in the direction of increasing letters and numbers (that is, rightwards and downwards). You can use a negative number to move it the other way.%r"grid/hline = at -" and "grid/vline = at -" add horizontal and vertical lines respectively. Useful for drawing walls.%r%rContinued in "grid/help 4" &text-help4 grid fn=[center(Examples:,79,-)]%r grid/add A=f-10%r grid/add Orc=D-12%r grid/move Orc=h-8%r grid/rem Orc%r grid/rem A=f-10%t%t(if there's more than one "A" on the grid)%r grid/rem0 f-10%t%t%t(if you just want to remove whatever's at f-10)%r grid/save room1%r grid/recall room1%r grid/random RCK%r grid/random RCK=10%r grid/trees 15%r grid/distance c-3 to g-1%r grid/where Orc%r%rContinued in "grid/help 5" &text-help5 grid fn=[center(More examples:,79,-)]%r grid/bigadd FOO=4 at d-7%r grid/movebig foo=-1,5%r grid/rembig foo%r grid/hline +++=10 at c-4%r grid/vline xxx=5 at d-4%r%rContinued in "grid/help 6" &text-help6 grid fn=Timestop commands:%r "inits" --- view the initiative order%r%r[center(Owner commands:,79,-)]%r "init/add =" --- add someone to the init order.%r "init/rem " --- remove someone from the init order.%r "init/move =" --- move someone to a new init.%r "init/clear" --- clear all inits. @@ COMMAND OBJECT @set grid code=inherit @lock grid code=me @desc grid code=Grid code &cmd-grid grid code=$grid:@pemit %#=[ulocal(v(xx-grid)/show-grid,get(me/an_grid_items))]; &cmd-add grid code=$grid/add *=*-*:@pemit %#=[ifelse(and(match(setr(0,get(v(xx-grid)/list-x)),%1),match(setr(1,get(v(xx-grid)/list-y)),%2)),Item %0 added to the grid at %1-%2.[set(me,an_grid_items:[get(me/an_grid_items)] [edit(strtrunc(%0,3),%b,_)]|[ucstr(%1-%2)])],Not a valid coordinate. Please use grid/add =x-y where x is a letter between [first(%q0)] and [last(%q0)] and y is a number between [first(%q1)] and [last(%q1)].)]; &cmd-addbig grid code=$grid/addbig *=* at *-*:@pemit %#=[setq(0,edit(strtrunc(%0,3),%b,_))][ifelse(and(gte(%1,1),lte(%1,18),match(setr(1,get(v(xx-grid)/list-x)),%2),match(setr(2,get(v(xx-grid)/list-y)),%3)),Item %q0 added to the grid at %2-%3 with size=%1.[setq(3,ulocal(v(xx-grid)/func-conv-x,%2))][setq(4,ulocal(v(xx-grid)/func-conv-y,%3))][set(me,an_gbig-%q0:[ulocal(v(xx-grid)/func-makebig,%q0,%q3,%q4,%1)])][set(me,an_grid_items:[get(me/an_grid_items)] [get(me/an_gbig-%q0)])],Not a valid coordinate. Please use grid/addbig = at x-y where x is a letter between [first(%q1)] and [last(%q1)] and y is a number between [first(%q2)] and [last(%q2)] and is a number between 1 and 18.)]; &cmd-rembig grid code=$grid/rembig *:@pemit %#=[setq(0,get(me/an_gbig-%0))][set(me,an_grid_items:[setdiff(get(me/an_grid_items),%q0)])]You remove the big item "%0" from the current grid.[set(me,an_gbig-%0:)] &cmd-movebig grid code=$grid/movebig *=*,*:@pemit %#=[setq(0,get(me/an_gbig-%0))][setq(1,iter(%q0,ulocal(v(xx-grid)/func-recenter,##,ulocal(v(xx-grid)/func-unconv-x,sub(12,%1)),sub(9,%2))))][set(me,an_grid_items:[setdiff(get(me/an_grid_items),%q0)])]You move the big item "%0" by %1 in the X direction and %2 in the Y direction.[set(me,an_gbig-%0:%q1)][set(me,an_grid_items:[get(me/an_grid_items)] %q1)]; &cmd-recenter grid code=$grid/recenter *-*:@pemit %#=[ifelse(and(match(setr(0,get(v(xx-grid)/list-x)),%0),match(setr(1,get(v(xx-grid)/list-y)),%1)),[setq(2,iter(get(me/an_grid_items),ulocal(v(xx-grid)/func-recenter,##,%0,%1)))]grid recentered at what was %0-%1.[set(me,an_grid_items:%q2)][iter(lattr(me/an_gbig*),ulocal(v(xx-grid)/func-recenter-big,num(me),##,%0,%1))],Not a valid coordinate. Please use "grid/recenter x y" where x is a letter between [first(%q0)] and [last(%q0)] and y is a number between [first(%q1)] and [last(%q1)].)]; &cmd-spamadd grid code=$grid/spamadd *=*-*:think [ifelse(and(match(setr(0,get(v(xx-grid)/list-x)),%1),match(setr(1,get(v(xx-grid)/list-y)),%2)),Item %0 added to the grid at %1-%2.[set(me,an_grid_items:[get(me/an_grid_items)] [edit(strtrunc(%0,3),%b,_)]|[ucstr(%1-%2)])],Not a valid coordinate. Please use grid/add =x-y where x is a letter between [first(%q0)] and [last(%q0)] and y is a number between [first(%q1)] and [last(%q1)].)]; &cmd-rem-coord grid code=$grid/rem *=*-*:@pemit %#=Item %0 removed from grid position %1-%2.[set(me,an_grid_items:[remove(get(me/an_grid_items),%0|[ucstr(%1-%2)])])]; &cmd-rem-coord0 grid code=$grid/rem0 *-*:@pemit %#=[setq(0,get(me/an_grid_items))][set(me,an_grid_items:[remove(%q0,setr(1,grab(%q0,*|%0-%1)))])]Item [first(%q1,|)] removed from grid position %0-%1.; &cmd-spamrem-coord0 grid code=$grid/spamrem0 *-*:think [setq(0,get(me/an_grid_items))][set(me,an_grid_items:[remove(%q0,setr(1,grab(%q0,*|%0-%1)))])]Item [first(%q1,|)] removed from grid position %0-%1.; &cmd-rem grid code=$grid/rem *:@pemit %#=[ifelse(words(after(%0,=)),,Item %0 removed from grid position [setq(0,grab(get(me/an_grid_items),%0|*))][after(%q0,|)].[set(me,an_grid_items:[remove(get(me/an_grid_items),%q0)])])]; &cmd-move grid code=$grid/move *=*-*:@pemit %#=[setq(5,strtrunc(%0,3))][ifelse(and(match(setr(0,get(v(xx-grid)/list-x)),%1),match(setr(1,get(v(xx-grid)/list-y)),%2)),Item %q5 moved to grid position %1-%2.[setq(0,grab(get(me/an_grid_items),%q5|*))][set(me,an_grid_items:[remove(get(me/an_grid_items),%q0)] %q5|[ucstr(%1-%2)])],Not a valid coordinate. Please use grid/add =x-y where x is a letter between [first(%q0)] and [last(%q0)] and y is a number between [first(%q1)] and [last(%q1)].)]; &cmd-clear grid code=$grid/clear:@pemit %#=You clear the current grid from this room.;&an_grid_items me; &cmd-grid-show grid code=$grid/show *:@pemit %#=[setq(0,get(me/an_grid-%0))][ifelse(and(hasattr(me,an_grid-%0),match(first(%q0,|),%#)),[center(Grid: %0,79,-)]%r[ulocal(v(xx-grid)/show-grid,after(%q0,|))],You do not have a grid named "%0" saved in this room. Type "grid/list" for a list.)] &cmd-grid-list grid code=$grid/list:@pemit %#=You have the following grids saved in this room:%r [s(iter(sort(lattr(me/an_grid-*)),ifelse(match(first(get(me/##),|),%#),[after(##,-)],)))]; &cmd-grid-clear grid code=$grid/clear *:@pemit %#=[setq(0,get(me/an_grid-%0))][ifelse(and(hasattr(me,an_grid-%0),match(first(%q0,|),%#)),You remove the "%0" grid from the grids saved in this room.[set(me,an_grid-%0:)],You do not have a grid named "%0" saved in this room. Type "grid/list" for a list.)] &cmd-grid-save grid code=$grid/save *:@pemit %#=[ifelse(hasattr(me,an_grid-%0),A grid with that name already exists. Note: it may be owned by another player.,You save the current grid as "%0".[set(me,an_grid-%0:%#|[get(me/an_grid_items)])])]; &cmd-grid-recall grid code=$grid/recall *:@pemit %#=[setq(0,get(me/an_grid-%0))][ifelse(and(hasattr(me,an_grid-%0),match(first(%q0,|),%#)),You set the current grid to "%0".[pemit(lcon(room(%#)),%N resets the current grid.)][set(me,an_grid_items:[after(get(me/an_grid-%0),|)])],You do not have a grid named "%0" saved in this room. Type "grid/list" for a list.)] &cmd-grid-addlayer grid code=$grid/addlayer *:@pemit %#=[setq(0,get(me/an_grid-%0))][ifelse(and(hasattr(me,an_grid-%0),match(first(%q0,|),%#)),You add "%0" to the current grid.[pemit(lcon(room(%#)),%N adds a layer to the current grid.)][set(me,an_grid_items:[get(me/an_grid_items)] [after(get(me/an_grid-%0),|)])],You do not have a grid named "%0" saved in this room. Type "grid/list" for a list.)] &cmd-grid-remlayer grid code=$grid/remlayer *:@pemit %#=[setq(0,get(me/an_grid-%0))][ifelse(and(hasattr(me,an_grid-%0),match(first(%q0,|),%#)),You remove "%0" from the current grid.[pemit(lcon(room(%#)),%N removes a layer from the current grid.)][set(me,an_grid_items:[setdiff(get(me/an_grid_items),[after(get(me/an_grid-%0),|)])])],You do not have a grid named "%0" saved in this room. Type "grid/list" for a list.)] &cmd-grid-random0 grid code=$grid/random *:@pemit %#=Randomly adding [setr(0,strtrunc(edit(%0,%b,_),3))] to the grid at [setr(1,ulocal(v(xx-grid)/random-x))]-[setr(2,ulocal(v(xx-grid)/random-y))][ulocal(v(xx-grid)/add-item,%q0,%q1,%q2,num(me))]; &cmd-grid-random grid code=$grid/random *=*:@pemit %#=Randomly adding %1 units of %0[iter(lnum(%1),ulocal(v(xx-grid)/add-item-random,strtrunc(edit(%0,%b,_),3),num(me)))]; &cmd-grid-trees grid code=$grid/trees *:@pemit %#=Randomly adding %0 trees as "TTT".[iter(lnum(%0),ulocal(v(xx-grid)/add-item-tree,num(me)))]; &cmd-distance grid code=$grid/distance *-* to *-*:@pemit %#=The distance from %0-%1 to %2-%3 (to the nearest 5') is: [mul(round(sqrt(add(power(sub(ulocal(v(xx-grid)/func-conv-x,%2),ulocal(v(xx-grid)/func-conv-x,%0)),2),power(sub(%3,%1),2))),0),5)]. &grid-where grid code=$grid/where *:@pemit %#=The item [setr(0,strtrunc(%0,3))] is at: [setq(1,grab(get(me/an_grid_items),%q0|*))][after(%q1,|)] &CMD-GRID-VLINE grid code=$grid/vline *=* at *-*:@dolist [lnum(%1)]=@force me=grid/spamadd %0=%2-[add(%3,##)]; &CMD-GRID-HLINE grid code=$grid/hline *=* at *-*:@dolist [lnum(%1)]=@force me=grid/spamadd %0=[extract(get(v(xx-grid)/list-x),add(##,match(get(v(xx-grid)/list-x),%2)),1)]-%3; @@ timestop &xis-owner grid code=match(owner(me),%0) &LISTEN-INIT grid code=^* ROLL> * rolls for initiative * and scores a *<*>.:&list-inits me=[get(me/list-inits)] [ifelse(gte(%3,10),%3,0%3)].[setq(0,extract(get(%1/an_abils),2,1))][ifelse(gte(%q0,10),%q0,0%q0)]|[edit(%1,%b,_)]; &CMD-SHOWINITS grid code=$inits:@pemit %#=[center(Init rolls for this round: ,79,=)]%r [iter(revwords(sort(get(me/list-inits))),[rjust(first(##,|),5)] [after(##,|)]%r)][repeat(=,79)] &CMD-MOVEINIT grid code=$init/move *=*:@switch [ulocal(xis-owner,%#)]=1,{@pemit %#=Moving %0 to init %1.[setq(0,grab(u(list-inits),*|[edit(%0,%b,_)]))];&list-inits me=[edit(get(me/list-inits),%q0,[ifelse(gte(%1,10),%1,0[mul(%1,1)])]|[after(%q0,|)])];},{@pemit %#=You can't do that.} &CMD-CLEARINITS grid code=$init/clear:@switch [ulocal(xis-owner,%#)]=1,{@pemit/contents [loc(%#)]=Inits cleared.;&list-inits me;},{@pemit %#=You can't do that.} &CMD-REMINIT grid code=$init/rem *:@switch [ulocal(xis-owner,%#)]=1,{@pemit %#=Removing %0 from the list.;&list-inits me=[remove(get(me/list-inits),grab(get(me/list-inits),*|[edit(%0,%b,_)]))];},{@pemit %#=You can't do that.;} &CMD-ADDINITS grid code=$init/add *=*:@switch [ulocal(xis-owner,%#)]=1,{@pemit %#=Init added: %0 at %1.;&list-inits me=[get(me/list-inits)] [ifelse(gte(%1,10),%1,0%1)]|[edit(%0,%b,_)];},{@pemit %#=You can't do that.} @desc grid code=[center(Coded grid and init tracker.,79,-)]%rType "grid" to see the grid.%rType "inits" to see the initiative order.%rType "grid/add =-" to add an item to the grid.%rType "grid/move =-" to move an item on the grid.%rType "grid/rem " to remove an item from the grid.%rType "grid/help" for more commands.%r[center(Code by: tai@Ark of Fools MUX,79,-)] &Cmd-help grid code=$grid/help:@pemit %#=[Center(+Grid help:,79,=)]%r[u(v(xx-grid)/text-help1)]%r[repeat(=,79)] &Cmd-help-num grid code=$grid/help *:@pemit %#=[Center(+Grid help - part %0:,79,=)]%r[ifelse(hasattr(v(xx-grid),text-help%0),[u(v(xx-grid)/text-help%0)],Not a valid section of help.)]%r[repeat(=,79)] @tel grid fn=grid code think DONE!