Merge branch 'main' of https://github.com/jyelon/luprex into main
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
ut-table.lua
|
||||
ut-globaldb.lua
|
||||
ut-tablecmp.lua
|
||||
basics.lua
|
||||
login.lua
|
||||
horps.lua
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ makeclass('army')
|
||||
--
|
||||
-- Data Structure
|
||||
-- Army.Count[kind]=number Where kind is r,p,s
|
||||
-- Player.Count[kind]=number Where kind is r,p,s
|
||||
--
|
||||
|
||||
function player.interface(actor, place)
|
||||
@@ -70,13 +71,41 @@ function shuffle(t)
|
||||
return s
|
||||
end
|
||||
|
||||
NilIsZero={
|
||||
__index=function(t,k)
|
||||
return 0
|
||||
end,
|
||||
__newindex=function(t,k,v)
|
||||
if v~=nil and v~=0 then rawset(t,k,v) end
|
||||
end }
|
||||
|
||||
function MakeMap()
|
||||
local rad=2
|
||||
for x=-rad,rad do for y=-rad,rad do
|
||||
t={class='army',x=x,y=y,z=0,plane='main',graphic='army'}
|
||||
print("Building an army:")
|
||||
pprint(t)
|
||||
local nt=tangible.build(t)
|
||||
nt.Count={}
|
||||
setmetatable(nt.Count,NilIsZero)
|
||||
for i=1,#armytypes do if math.random(1,2)==1 then
|
||||
local type=armytypes[math.random(1,#armytypes)]
|
||||
nt.Count[type]=nt.Count[type]+math.random(1,3)
|
||||
end end
|
||||
print("Here's what was built:")
|
||||
pprint(nt)
|
||||
end end
|
||||
end
|
||||
|
||||
--
|
||||
-- For each creature type, select the optimal target. Select randomly among identical targets.
|
||||
--
|
||||
function army.fight0(ak,ac,dk,dc) -- returns number of attacker casualties, defender casualties
|
||||
function army.fight0(ak,ac,dk,dc,rules) -- returns number of attacker casualties, defender casualties
|
||||
local adv0=advantage[ak][dk]
|
||||
local adv1=advantage[dk][ak]
|
||||
if rules.counterattack=='one' then adv1=1
|
||||
elseif rules.counterattack=='best' then adv1=adv1<1 and 1 or 1
|
||||
end
|
||||
local rval0=(ac*adv0-dc)/adv0
|
||||
if rval0<0 then rval0=0 end
|
||||
local rval1=(dc*adv1-rval0)/adv1
|
||||
@@ -113,7 +142,7 @@ function player:cb_droppaper(actor) player:droparmy(actor,'p') end
|
||||
function player:cb_dropscissor(actor) player:droparmy(actor,'s') end
|
||||
|
||||
function player:droparmy(actor,kind)
|
||||
if actor.Count[kind]<=0 then print("No armies of typem "..kind.." available") return end
|
||||
if actor.Count[kind]<=0 then print("No armies of type "..kind.." available") return end
|
||||
local lis=tangible.near(actor,0,true,true)
|
||||
if #lis>1 then print("Multiple Tangibles Nearby") return end
|
||||
local t=lis[1]
|
||||
@@ -124,8 +153,8 @@ function player:droparmy(actor,kind)
|
||||
|
||||
function player:newlocation()
|
||||
local lis=tangible.near(self,0,false,false)
|
||||
print("New Location")
|
||||
pprint(lis)
|
||||
-- print("New Location")
|
||||
-- pprint(lis)
|
||||
end
|
||||
|
||||
function player:printanimstate()
|
||||
@@ -171,7 +200,7 @@ function player.cb_emit_army(actor,place,dialog)
|
||||
local nt=tangible.build(t)
|
||||
setmetatable(nt,{r=0,p=0,s=0})
|
||||
nt.kind='r'
|
||||
nt.count=1
|
||||
nt.Count=1
|
||||
end
|
||||
|
||||
function player.cb_emit_buff(actor,place,dialog)
|
||||
@@ -188,40 +217,41 @@ function seq(a,b,c) return a<=b and b<=c or false end
|
||||
function num2(a) if a<=9 then return " "..a else return a end end
|
||||
|
||||
function player.cb_map(actor,place,dialog)
|
||||
local rad=2
|
||||
local rad=1
|
||||
scratch={}
|
||||
local lis=tangible.near(actor,rad,true,false)
|
||||
pprint("cb_map ",lis)
|
||||
local lis=tangible.near(actor,1.5*rad,true,false)
|
||||
print("\27[38;5;9mMap:\27[0m")
|
||||
for _,t in pairs(lis) do
|
||||
if t~=actor then print(tangible.getclass(t)) end
|
||||
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)
|
||||
local kind=t.kind or 'Nil'
|
||||
if not scratch[offset] then scratch[offset]={} end
|
||||
if not scratch[offset].count then scratch[offset].count={} end
|
||||
if not scratch[offset].count[kind] then scratch[offset].count[kind]=0 end
|
||||
if t.count then scratch[offset].count[kind]=scratch[offset].count[kind]+t.count end
|
||||
if cl=='player' or cl=='army' then
|
||||
if not scratch[offset] then scratch[offset]={} scratch[offset].Count={} setmetatable(scratch[offset].Count,NilIsZero) end
|
||||
if t.Count then
|
||||
for i,k in ipairs(armytypes) do
|
||||
local a0=scratch[offset]
|
||||
local a1=a0.Count
|
||||
local a2=a1[i]
|
||||
local a3=t.Count
|
||||
local a4=a3[k]
|
||||
if not a4 then print("a4 is nil") pprint(t) end
|
||||
scratch[offset].Count[i]=a2+a4
|
||||
end end
|
||||
end
|
||||
end
|
||||
pprint(scratch)
|
||||
for dy=-rad,rad do for line=0,1 do
|
||||
local lbuf=""
|
||||
for dx=-rad,rad do
|
||||
local offset=(dy+rad)*(rad*2+1)+dx+rad
|
||||
if line==0 then lbuf=lbuf.."----"
|
||||
elseif line==1 then
|
||||
local kc=0
|
||||
local tc=0
|
||||
local kstr=' '
|
||||
if scratch[offset] then 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 end
|
||||
lbuf=lbuf.."-"..kstr..(tc>0 and num2(tc) or " ")
|
||||
end end
|
||||
if scratch[offset] then for i,k in ipairs(armytypes) do lbuf=lbuf..scratch[offset].Count[i] end
|
||||
else for i=1,#armytypes do lbuf=lbuf..' ' end end
|
||||
lbuf=lbuf.."-"
|
||||
end end
|
||||
print(lbuf)
|
||||
end end
|
||||
lbuf=""
|
||||
|
||||
@@ -8,7 +8,8 @@ end
|
||||
function login.cb_becomeplayer(actor, place, dialog)
|
||||
actor.kind='P'
|
||||
actor.Count={}
|
||||
setmetatable(actor.Count,{jones=5,__index=function(t,k) return 0 end,__newindex=function(t,k,v) if v~=nil and v~=0 then rawset(t,k,v) end end})
|
||||
actor.Count.Foobar=42
|
||||
setmetatable(actor.Count,NilIsZero)
|
||||
tangible.setclass(actor, player)
|
||||
tangible.animate(actor,{action="warp",plane="main",x=0,y=0,z=0})
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user