makeclass('player') function player.interface(actor, place) gui.menu_item("cb_north", "Go North") gui.menu_item("cb_south", "Go South") gui.menu_item("cb_east", "Go East") gui.menu_item("cb_west", "Go West") gui.menu_item("cb_map", "Show the Map") gui.menu_item("cb_emit_army","Emit an Army") gui.menu_item("cb_emit_buff","Emit a Buff") end function player:printanimstate() local graphic,plane,x,y,z,facing = tangible.animstate(self) print("Resulting state: ", graphic, plane, x, y, z, facing) end function player.cb_north(actor, place, dialog) tangible.animate(place, {action="walk", dy=1}) actor:printanimstate() end function player.cb_south(actor, place, dialog) tangible.animate(place, {action="walk", dy=-1}) actor:printanimstate() end function player.cb_east(actor, place, dialog) tangible.animate(place, {action="walk", dx=1}) actor:printanimstate() end function player.cb_west(actor, place, dialog) tangible.animate(place, {action="walk", dx=-1}) actor:printanimstate() end function player.cb_emit_army(actor,place,dialog) local _,pl,ax,ay=tangible.animstate(actor) t={class='army',x=ax,y=ay,z=0,plane=pl,graphic='army'} pprint("building ",t) tangible.build(t) end function player.cb_emit_buff(actor,place,dialog) local _,pl,ax,ay=tangible.animstate(actor) t={class='army',x=ax,y=ay,z=0,plane=pl,graphic='buff'} pprint("building ",t) tangible.build(t) end makeclass('army') makeclass('buff') function seq(a,b,c) return a<=b and b<=c or false end function player.cb_map(actor,place,dialog) local rad=2 local scratch={} local lis=tangible.near(actor,rad*2+1,true,false) pprint("cb_map ",lis) for _,t in pairs(lis) do local graphic,plane,x,y,z,facing = tangible.animstate(t) local c=tangible.getclass(t) local dx,dy=tangible.xyz(t) local offset=(dy+rad)*(rad*2+1)+dx+rad local cl=tangible.getclass(t) print("Offset of "..cl.." is "..offset) if not scratch[offset] then scratch[offset]={} end if not scratch[offset].count then scratch[offset].count={} end if not scratch[offset].count[cl] then scratch[offset].count[cl]=0 end scratch[offset].count[cl]=scratch[offset].count[cl]+1 end for dy=0,rad*2+1 do for line=0,2 do local lbuf="" for dx=0,rad*2+1 do if line==0 then lbuf=lbuf.."---" elseif line==1 then lbuf=lbuf.."-x-" elseif line==2 then lbuf=lbuf.."---" end end print(lbuf) end end end