This commit is contained in:
2022-05-18 19:02:46 -04:00
parent 608f7fe6d6
commit 1095d6677a
3 changed files with 67 additions and 19 deletions

View File

@@ -20,8 +20,36 @@ setmetatable(player,army)
--
-- New Data Structure:
-- Player.Stack={ 1=kind, 2=qty, 3=kind, 4=qty,... }
-- orchard.crop='r'
-- orchard.size=integer -- Max size it can grow to
-- orchard.rate=integer -- How many grow per unit time()
-- orchard.pick=integer -- time() it was last harvested
--
function mapable(a)
if isa(a,login) then return false end
return not isa(a,player)
end
function orchard:available()
return math.min(self.size,self.rate*(time()-self.pick))
end
function bound(a,b,c)
if b<a then return b elseif b>c then return c else return b end
end
function lerp(a,b,c,d,e)
return d+(e-d)*(a-b)/(c-b)
end
function orchard:harvest(n)
local a=self:available()
if n>=a then self.pick=time() return a end
self.pick=lerp(n,0,a,self.pick,time())
return n
end
function player.interface(actor, place)
gui.menu_item("cb_north" ,"Go North")
gui.menu_item("cb_south" ,"Go South")
@@ -67,6 +95,7 @@ function army.interface(actor,place)
-- Spock dismantles Scissors 2
armytypes={'r','p','s'}
armynames={r="Rock Golem" ,p="Paper Dragon",s="Scissor Beast",l="Fire Lizzard",v="Mr. Spock"}
foodtypes={'r','p','s','l','v'}
foodnames={r="Raspberry" ,p="Pomegranite" ,s="Strawberry" ,l="Lemon" ,v="Mango" }
--advantage={ r={ r=1, p=1/2, s=3, l=2, v=1/3 },
-- p={ r=2, p=1, s=1/2, l=1/3, v=3 },
@@ -89,17 +118,25 @@ function shuffle(t)
function MakeMap()
local rad=6
for x=-rad,rad do for y=-rad,rad do if math.random(1,5)==1 then
t={class='army',x=x,y=y,z=0,plane='main',graphic='army'}
local nt=tangible.build(t)
local stack={}
local shuf=shuffle(armytypes)
for i=1,#shuf do if math.random(1,2)==1 then
stack[1+#stack]=shuf[i]
stack[1+#stack]=math.random(1,3)
end end
nt.stack=stack
end end end
for x=-rad,rad do for y=-rad,rad do
itemkind=math.random(1,7)
if itemkind==1 then
local nt=tangible.build{class='army',x=x,y=y,z=0,plane='main',graphic='army'}
local stack={}
local shuf=shuffle(armytypes)
for i=1,#shuf do if math.random(1,2)==1 then
stack[1+#stack]=shuf[i]
stack[1+#stack]=math.random(1,3)
end end
nt.stack=stack
elseif itemkind==2 then
local nt=tangible.build{class='orchard',x=x,y=y,z=0,plane='main',graphic='orchard'}
nt.crop=foodtypes[math.random(1,#foodtypes)]
nt.size=10
nt.rate=0.1
nt.pick=time()
end
end end
end
@@ -303,13 +340,16 @@ function where()
function mapcelltext(lis)
if lis==nil then return ' ' end
if #lis>1 then return '++++++' end
local acc={} setmetatable(acc,NilIsZero)
local rval=""
local prefix=""
local suffix=""
if isa(lis[1],player) then prefix="\27[91;7m" suffix="\27[0m" end
for k,c in stack_iter(lis[1].stack) do rval=rval..k..(c>9 and '+' or tostring(c)) end
rval=rval..string.sub(' ',1,6-string.len(rval))
if isa(lis[1],army) then
for k,c in stack_iter(lis[1].stack) do rval=rval..k..(c>9 and '+' or tostring(c)) end
rval=rval..string.sub(' ',1,6-string.len(rval))
elseif isa(lis[1],orchard) then
rval=rval.." OO "
end
return prefix..rval..suffix
end
@@ -325,7 +365,7 @@ function player.cb_map(actor,place,dialog)
local dx,dy=tangible.xyz(t)
local offset=(-dy+ay+rad)*(rad*2+1)+dx-ax+rad
local cl=tangible.getclass(t)
if seq(ax-rad,dx,ax+rad) and seq(ay-rad,dy,ay+rad) and (cl=='player' or cl=='army') then
if seq(ax-rad,dx,ax+rad) and seq(ay-rad,dy,ay+rad) and (cl=='player' or cl=='army' or cl=='orchard') then
if not scratch[offset] then scratch[offset]={} end
scratch[offset][1+#scratch[offset]]=t
end end

View File

@@ -5,13 +5,20 @@ function login.interface(actor, place)
gui.menu_item("cb_p123", "Print 1, 2, 3")
gui.menu_item("cb_p123_nopredict", "Print 1, 2, 3 nopredict")
gui.menu_item("cb_uglytimedaemon","Start the Time Daemon")
gui.menu_item("cb_seedprng","Seed the PRNG")
end
function login.cb_seedprng(actor,place,dialog)
local result=http.get{method='GET',host='www.random.org',path='/cgi-bin/randbyte',params={nbytes='32',format='f'},verifycertificate=false}
pprint(result)
end -- "GET /cgi-bin/randbyte?nbytes=16384&format=f HTTP/1.0\nHost: www.random.org\n\n"
function login.cb_becomeplayer(actor, place, dialog)
actor.kind='P'
actor.Count={} setmetatable(actor.Count,NilIsZero)
actor.Food={} setmetatable(actor.Food,NilIsZero)
actor.Stack={}
actor.stack={}
tangible.setclass(actor, player)
tangible.animate(actor,{action="warp",plane="main",x=0,y=0,z=0})
end

View File

@@ -40,10 +40,11 @@ function tabcat(t1,t2)
for i=1,#t2 do t1[#t1+1]=t2[i] end
end
-- Example: multistart(function(t) return tangible.id(t)%3==0 end,function() print("Tangible "..tangible.id(tangible.place()).." here") end)
function multistart(filter,closure)
local lis=tangible.scan('nowhere',0,0,1000000000,false)
lis=tabcat(lis,tangible.scan('main',0,0,1000000000,true)
for _,t in iparis(lis) do if filter(t) then closure(t) end end
local lis=tangible.scan('nowhere',0,0,100,false)
tabcat(lis,tangible.scan('main',0,0,100,true))
for _,t in ipairs(lis) do if filter(t) then tangible.start(t,closure) end end
end