Files
integration/luprex/core/lua/horps.lua
2022-02-03 16:23:14 -05:00

111 lines
3.1 KiB
Lua

makeclass('player')
--
-- Data Structure
-- Army.Count
-- Army.Kind 'r','p','s'
--
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)
t.kind='r'
t.count=5
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,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].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={}
if not scratch[offset].count[cl] then scratch[offset].count[cl]=0 end
if t.count then scratch[offset].count[cl]=scratch[offset].count[cl]+t.count end
end
for dy=-rad,rad do for line=0,1 do
local lbuf=""
for dx=-rad,rad do
if line==0 then lbuf=lbuf.."---"
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.."-"
print(lbuf)
end end
lbuf=""
for dx=-rad,rad do lbuf=lbuf.."---" end
lbuf=lbuf.."-"
print(lbuf)
end
end