This commit is contained in:
2022-05-21 12:49:54 -04:00
parent b950cc3cff
commit 407aef6793
4 changed files with 55 additions and 19 deletions

View File

@@ -7,6 +7,6 @@ ut-table.lua
ut-globaldb.lua ut-globaldb.lua
ut-tablecmp.lua ut-tablecmp.lua
basics.lua basics.lua
uglyglobals.lua
login.lua login.lua
horps.lua spectra.lua

View File

@@ -20,6 +20,7 @@ function login.cb_becomeplayer(actor, place, dialog)
actor.food={} setmetatable(actor.food,NilIsZero) actor.food={} setmetatable(actor.food,NilIsZero)
actor.spectra={} setmetatable(actor.spectra,NilIsZero) actor.spectra={} setmetatable(actor.spectra,NilIsZero)
actor.stack={} actor.stack={}
actor.team='red'
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

View File

@@ -7,13 +7,13 @@ freqcolor={ azure=152, black=35200, blue=59300, brown=20000, chocolate=1840, cre
pink=27200, purple=13700, red=52200, rose=4310, ruby=994, russet=68, pink=27200, purple=13700, red=52200, rose=4310, ruby=994, russet=68,
scarlet=315, silver=13200, violet=3590, white=45100, yellow=24400 } scarlet=315, silver=13200, violet=3590, white=45100, yellow=24400 }
function player:near_iter(rad,kind) function player:near_iter(rad,kind1,kind2,kind3)
local lis=tangible.near(self,rad,true,true) local lis=tangible.near(self,rad,true,true)
local i=1 local i=1
return function() return function()
while i<=#lis do while i<=#lis do
i=i+1 i=i+1
if not kind or isa(lis[i-1],kind) then return lis[i-1] end end end if not kind1 or isa(lis[i-1],kind1,kind2,kind3) then return lis[i-1] end end end
end end
function tandist(t1,t2) function tandist(t1,t2)
@@ -31,12 +31,17 @@ function player:radius_iter(rad,kind)
if (not kind or isa(lis[i-1],kind)) and tandist(self,lis[i-1])<=rad then return lis[i-1] end end end if (not kind or isa(lis[i-1],kind)) and tandist(self,lis[i-1])<=rad then return lis[i-1] end end end
end end
function player.interface(actor, place) function player:interface(place)
gui.menu_item("cb_dir0" ,"Go North") gui.menu_item("cb_dir0" ,"Go North")
gui.menu_item("cb_dir180" ,"Go South") gui.menu_item("cb_dir180" ,"Go South")
gui.menu_item("cb_dir270" ,"Go West") gui.menu_item("cb_dir270" ,"Go West")
gui.menu_item("cb_dir90" ,"Go East") gui.menu_item("cb_dir90" ,"Go East")
gui.menu_item("cb_map" ,"Map") gui.menu_item("cb_map" ,"Map")
gui.menu_item("cb_spectra" ,"Show Spectra")
end
function player:cb_spectra()
for k,v in pairs(self.spectra) do print(string.format("%-6.6s:%s",k,string.sub('+++++++++++++++++++++++++',1,v))) end
end end
function player:cb_dir0() self:move(0) end function player:cb_dir0() self:move(0) end
@@ -54,19 +59,41 @@ function player:power()
return rval return rval
end end
function player:respawn()
tangible.animate(self,{action='warp',plane='main',x=math.random(-40,40),y=math.random(-40,40),z=0})
self:cb_map()
print("You just died!") --
end
function player:fight(enemy)
local common={}
for k,v in pairs(self.spectra) do if enemy.spectra[k]>0 then common[k]=1 end end
local p0=self:power()
local p1=enemy:power()
local winner
if p0==p1 then
for k,v in pairs(common) self.spectra[k]=nil enemy.spectra[k]=nil end
else if p0>p1 then
for k,v in pairs(common) enemy.spectra[k]=nil end
else
for k,v in pairs(common) self.spectra[k]=nil end
end
p0=self:power()
p1=enemy:power()
if p1==0 then self.kills =self.kills+1 enemy.deaths=enemy.deaths+1 enemy:respawn() end
if p0==0 then self.deaths=self.deaths+1 enemy.kills =enemy.kills+1 self:respawn() end
end
function player:newlocation() function player:newlocation()
for lt in self:radius_iter(3.1,light) do self.spectra[lt.color]=25 end for lt in self:radius_iter(3.1,light) do self.spectra[lt.color]=25 end
for lt in self:radius_iter(3.1,player) do if self.team==lt.team then for lt in self:radius_iter(3.1,player) do if self.team==lt.team then
nspec={} local nspec={} setmetatable(nspec,NilIsZero)
for k,v in pairs(self.spectra) do nspec[k]=v end for k,v in pairs(self.spectra) do nspec[k]=v end
for k,v in pairs(lt.spectra) do nspec[k]=math.max(v,nspec[k]) end for k,v in pairs(lt.spectra) do nspec[k]=math.max(v,nspec[k]) end
for k,v in pairs(nspec) do self.spectra[k]=v lt.spectra[k]=v end for k,v in pairs(nspec) do self.spectra[k]=v lt.spectra[k]=v end
end end end end
for lt in self:radius_iter(3.1,player) do if self.team~=lt.team then for lt in self:radius_iter(3.1,player) do if self.team~=lt.team then p1:fight(p2) end end
local p1=self.power()
local p2=lt.power()
print("Attacker Power:",p1," Defender Power:",p2)
end end
for k,v in pairs(self.spectra) do self.spectra[k]=self.spectra[k]-1 if self.spectra[k]<=0 then self.spectra[k]=nil end end for k,v in pairs(self.spectra) do self.spectra[k]=self.spectra[k]-1 if self.spectra[k]<=0 then self.spectra[k]=nil end end
end end
@@ -105,22 +132,29 @@ function player:cb_map(place,dialog)
self:map(10) self:map(10)
end end
teamcolor={ red='\27[91m', green='\27[92m', yellow='\27[93m', blue='\27[94m', magenta='\27[95m', cyan='\27[96m' }
function player:map(radius) function player:map(radius)
local radius=10 local radius=10
radius=radius or 10 radius=radius or 10
local cells={} local cells={}
local px,py=tangible.xyz(tangible.actor()) local px,py=tangible.xyz(tangible.actor())
for lt in self:near_iter(1.5*radius,light) do for lt in self:near_iter(1.5*radius,light,player) do
local lx,ly=tangible.xyz(lt) local lx,ly=tangible.xyz(lt)
lx=lx-px+radius lx=lx-px+radius
ly=ly-py+radius ly=ly-py+radius
if seq(0,ly,1+2*radius) and seq(0,lx,1+2*radius) then setcell(cells,math.floor(0.5+lx),math.floor(0.5+ly),lt.color) end if seq(0,ly,1+2*radius) and seq(0,lx,1+2*radius) then
local celltext
if isa(lt,light) then celltext=string.format("%-6.6s",lt.color)
elseif isa(lt,player) then celltext=teamcolor[lt.team].."Pl:"..string.format("%-3.0f",lt:power()).."\27[0m"
end end
setcell(cells,radius,radius,string.format("Me:%3.3f",self:power())) setcell(cells,math.floor(0.5+lx),math.floor(0.5+ly),celltext) end
end
setcell(cells,radius,radius,teamcolor[self.team]..string.format("Me:%-3.0f",self:power()).."\27[0m")
for ly=0,1+2*radius do for ly=0,1+2*radius do
local line='|' local line='|'
for lx=0,1+2*radius do for lx=0,1+2*radius do
if cells[ly] and cells[ly][lx] then line=line..string.format("%-6.6s",cells[ly][lx])..'|' else line=line..' |' end if cells[ly] and cells[ly][lx] then line=line..cells[ly][lx]..'|' else line=line..' |' end
end end
print(line) print(line)
end end

View File

@@ -28,12 +28,12 @@ function login.cb_uglytimedaemon()
function time() return ug.get('time') end function time() return ug.get('time') end
function isa(k1,k2) function isa(k1,k2,k3,k4)
if k1==k2 then return true end if k1==k2 or k1==k3 or k1==k4 then return true end
if k1==nil then return false end if k1==nil then return false end
local mt=getmetatable(k1) local mt=getmetatable(k1)
if not mt then return false end if not mt then return false end
return isa(mt.__index,k2) return isa(mt.__index,k2,k3,k4)
end end
function tabcat(t1,t2) function tabcat(t1,t2)
@@ -41,9 +41,10 @@ function tabcat(t1,t2)
end end
-- Example: multistart(function(t) return tangible.id(t)%3==0 end,function() print("Tangible "..tangible.id(tangible.place()).." here") 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(fil,closure)
local lis=tangible.scan('nowhere',0,0,100,false) local lis=tangible.scan('nowhere',0,0,100,false)
tabcat(lis,tangible.scan('main',0,0,100,true)) tabcat(lis,tangible.scan('main',0,0,100,true))
local filter=type(fil)=='function' and fil or function(t) return isa(t,fil) end
for _,t in ipairs(lis) do if filter(t) then tangible.start(t,closure) end end for _,t in ipairs(lis) do if filter(t) then tangible.start(t,closure) end end
end end