2022-02-03 11:20:28 -05:00
|
|
|
makeclass('player')
|
|
|
|
|
|
2022-02-03 16:23:14 -05:00
|
|
|
--
|
|
|
|
|
-- Data Structure
|
|
|
|
|
-- Army.Count
|
|
|
|
|
-- Army.Kind 'r','p','s'
|
|
|
|
|
--
|
|
|
|
|
|
2022-02-03 11:20:28 -05:00
|
|
|
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)
|
2022-02-03 16:23:14 -05:00
|
|
|
t.kind='r'
|
|
|
|
|
t.count=5
|
2022-02-03 11:20:28 -05:00
|
|
|
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={}
|
2022-02-03 16:23:14 -05:00
|
|
|
local lis=tangible.near(actor,rad,true,false)
|
2022-02-03 11:20:28 -05:00
|
|
|
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
|
2022-02-03 16:23:14 -05:00
|
|
|
if not scratch[offset].armies then scratch[offset].armies={} end
|
|
|
|
|
if cl=='player' then table.insert(scratch[offset].armies,t) end
|
|
|
|
|
if not scratch[offset].count then scratch[offset].count={}
|
2022-02-03 11:20:28 -05:00
|
|
|
if not scratch[offset].count[cl] then scratch[offset].count[cl]=0 end
|
2022-02-03 16:23:14 -05:00
|
|
|
if t.count then scratch[offset].count[cl]=scratch[offset].count[cl]+t.count end
|
2022-02-03 11:20:28 -05:00
|
|
|
end
|
2022-02-03 16:23:14 -05:00
|
|
|
for dy=-rad,rad do for line=0,1 do
|
2022-02-03 11:20:28 -05:00
|
|
|
local lbuf=""
|
2022-02-03 16:23:14 -05:00
|
|
|
for dx=-rad,rad do
|
2022-02-03 11:20:28 -05:00
|
|
|
if line==0 then lbuf=lbuf.."---"
|
2022-02-03 16:23:14 -05:00
|
|
|
elseif line==1 then
|
|
|
|
|
local kc=0
|
|
|
|
|
local tc=0
|
|
|
|
|
local kstr=' '
|
|
|
|
|
for k,c in pairs(scratch[offset].count) do if c>0 then
|
|
|
|
|
kc=kc+1
|
|
|
|
|
tc=tc+c
|
|
|
|
|
if kc>1 then kstr='M' else kstr=k end
|
|
|
|
|
end end
|
|
|
|
|
lbuf=lbuf.."-"..kstr..(tc>0 and tc or " ")
|
|
|
|
|
end end
|
|
|
|
|
lbuf=lbuf.."-"
|
2022-02-03 11:20:28 -05:00
|
|
|
print(lbuf)
|
|
|
|
|
end end
|
2022-02-03 16:23:14 -05:00
|
|
|
lbuf=""
|
|
|
|
|
for dx=-rad,rad do lbuf=lbuf.."---" end
|
|
|
|
|
lbuf=lbuf.."-"
|
|
|
|
|
print(lbuf)
|
|
|
|
|
end
|
2022-02-03 11:20:28 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|