changes
This commit is contained in:
@@ -20,8 +20,36 @@ setmetatable(player,army)
|
|||||||
--
|
--
|
||||||
-- New Data Structure:
|
-- New Data Structure:
|
||||||
-- Player.Stack={ 1=kind, 2=qty, 3=kind, 4=qty,... }
|
-- 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)
|
function player.interface(actor, place)
|
||||||
gui.menu_item("cb_north" ,"Go North")
|
gui.menu_item("cb_north" ,"Go North")
|
||||||
gui.menu_item("cb_south" ,"Go South")
|
gui.menu_item("cb_south" ,"Go South")
|
||||||
@@ -67,6 +95,7 @@ function army.interface(actor,place)
|
|||||||
-- Spock dismantles Scissors 2
|
-- Spock dismantles Scissors 2
|
||||||
armytypes={'r','p','s'}
|
armytypes={'r','p','s'}
|
||||||
armynames={r="Rock Golem" ,p="Paper Dragon",s="Scissor Beast",l="Fire Lizzard",v="Mr. Spock"}
|
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" }
|
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 },
|
--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 },
|
-- p={ r=2, p=1, s=1/2, l=1/3, v=3 },
|
||||||
@@ -89,17 +118,25 @@ function shuffle(t)
|
|||||||
|
|
||||||
function MakeMap()
|
function MakeMap()
|
||||||
local rad=6
|
local rad=6
|
||||||
for x=-rad,rad do for y=-rad,rad do if math.random(1,5)==1 then
|
for x=-rad,rad do for y=-rad,rad do
|
||||||
t={class='army',x=x,y=y,z=0,plane='main',graphic='army'}
|
itemkind=math.random(1,7)
|
||||||
local nt=tangible.build(t)
|
if itemkind==1 then
|
||||||
local stack={}
|
local nt=tangible.build{class='army',x=x,y=y,z=0,plane='main',graphic='army'}
|
||||||
local shuf=shuffle(armytypes)
|
local stack={}
|
||||||
for i=1,#shuf do if math.random(1,2)==1 then
|
local shuf=shuffle(armytypes)
|
||||||
stack[1+#stack]=shuf[i]
|
for i=1,#shuf do if math.random(1,2)==1 then
|
||||||
stack[1+#stack]=math.random(1,3)
|
stack[1+#stack]=shuf[i]
|
||||||
end end
|
stack[1+#stack]=math.random(1,3)
|
||||||
nt.stack=stack
|
end end
|
||||||
end 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
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -303,13 +340,16 @@ function where()
|
|||||||
function mapcelltext(lis)
|
function mapcelltext(lis)
|
||||||
if lis==nil then return ' ' end
|
if lis==nil then return ' ' end
|
||||||
if #lis>1 then return '++++++' end
|
if #lis>1 then return '++++++' end
|
||||||
local acc={} setmetatable(acc,NilIsZero)
|
|
||||||
local rval=""
|
local rval=""
|
||||||
local prefix=""
|
local prefix=""
|
||||||
local suffix=""
|
local suffix=""
|
||||||
if isa(lis[1],player) then prefix="\27[91;7m" suffix="\27[0m" end
|
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
|
if isa(lis[1],army) then
|
||||||
rval=rval..string.sub(' ',1,6-string.len(rval))
|
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
|
return prefix..rval..suffix
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -325,7 +365,7 @@ function player.cb_map(actor,place,dialog)
|
|||||||
local dx,dy=tangible.xyz(t)
|
local dx,dy=tangible.xyz(t)
|
||||||
local offset=(-dy+ay+rad)*(rad*2+1)+dx-ax+rad
|
local offset=(-dy+ay+rad)*(rad*2+1)+dx-ax+rad
|
||||||
local cl=tangible.getclass(t)
|
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
|
if not scratch[offset] then scratch[offset]={} end
|
||||||
scratch[offset][1+#scratch[offset]]=t
|
scratch[offset][1+#scratch[offset]]=t
|
||||||
end end
|
end end
|
||||||
|
|||||||
@@ -5,13 +5,20 @@ function login.interface(actor, place)
|
|||||||
gui.menu_item("cb_p123", "Print 1, 2, 3")
|
gui.menu_item("cb_p123", "Print 1, 2, 3")
|
||||||
gui.menu_item("cb_p123_nopredict", "Print 1, 2, 3 nopredict")
|
gui.menu_item("cb_p123_nopredict", "Print 1, 2, 3 nopredict")
|
||||||
gui.menu_item("cb_uglytimedaemon","Start the Time Daemon")
|
gui.menu_item("cb_uglytimedaemon","Start the Time Daemon")
|
||||||
|
gui.menu_item("cb_seedprng","Seed the PRNG")
|
||||||
end
|
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)
|
function login.cb_becomeplayer(actor, place, dialog)
|
||||||
actor.kind='P'
|
actor.kind='P'
|
||||||
actor.Count={} setmetatable(actor.Count,NilIsZero)
|
actor.Count={} setmetatable(actor.Count,NilIsZero)
|
||||||
actor.Food={} setmetatable(actor.Food,NilIsZero)
|
actor.Food={} setmetatable(actor.Food,NilIsZero)
|
||||||
actor.Stack={}
|
actor.stack={}
|
||||||
tangible.setclass(actor, player)
|
tangible.setclass(actor, player)
|
||||||
tangible.animate(actor,{action="warp",plane="main",x=0,y=0,z=0})
|
tangible.animate(actor,{action="warp",plane="main",x=0,y=0,z=0})
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -40,10 +40,11 @@ function tabcat(t1,t2)
|
|||||||
for i=1,#t2 do t1[#t1+1]=t2[i] end
|
for i=1,#t2 do t1[#t1+1]=t2[i] end
|
||||||
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)
|
function multistart(filter,closure)
|
||||||
local lis=tangible.scan('nowhere',0,0,1000000000,false)
|
local lis=tangible.scan('nowhere',0,0,100,false)
|
||||||
lis=tabcat(lis,tangible.scan('main',0,0,1000000000,true)
|
tabcat(lis,tangible.scan('main',0,0,100,true))
|
||||||
for _,t in iparis(lis) do if filter(t) then closure(t) end end
|
for _,t in ipairs(lis) do if filter(t) then tangible.start(t,closure) end end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user