diff --git a/luprex/core/lua/control.lst b/luprex/core/lua/control.lst index d4e9d236..66b051de 100644 --- a/luprex/core/lua/control.lst +++ b/luprex/core/lua/control.lst @@ -7,6 +7,6 @@ ut-table.lua ut-globaldb.lua ut-tablecmp.lua basics.lua +uglyglobals.lua login.lua -horps.lua - +spectra.lua diff --git a/luprex/core/lua/login.lua b/luprex/core/lua/login.lua index 9adf5722..2eabdde1 100644 --- a/luprex/core/lua/login.lua +++ b/luprex/core/lua/login.lua @@ -20,6 +20,7 @@ function login.cb_becomeplayer(actor, place, dialog) actor.food={} setmetatable(actor.food,NilIsZero) actor.spectra={} setmetatable(actor.spectra,NilIsZero) actor.stack={} + actor.team='red' tangible.setclass(actor, player) tangible.animate(actor,{action="warp",plane="main",x=0,y=0,z=0}) end diff --git a/luprex/core/lua/spectra.lua b/luprex/core/lua/spectra.lua index 87c7e076..668ddc84 100644 --- a/luprex/core/lua/spectra.lua +++ b/luprex/core/lua/spectra.lua @@ -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, 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 i=1 return function() while i<=#lis do 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 function tandist(t1,t2) @@ -31,14 +31,19 @@ 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 end -function player.interface(actor, place) +function player:interface(place) gui.menu_item("cb_dir0" ,"Go North") gui.menu_item("cb_dir180" ,"Go South") gui.menu_item("cb_dir270" ,"Go West") gui.menu_item("cb_dir90" ,"Go East") 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 + function player:cb_dir0() self:move(0) end function player:cb_dir45() self:move(45) end function player:cb_dir90() self:move(90) end @@ -54,19 +59,41 @@ function player:power() return rval 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() 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 - nspec={} + local nspec={} setmetatable(nspec,NilIsZero) 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(nspec) do self.spectra[k]=v lt.spectra[k]=v end end end - for lt in self:radius_iter(3.1,player) do if self.team~=lt.team then - local p1=self.power() - local p2=lt.power() - print("Attacker Power:",p1," Defender Power:",p2) - end end + for lt in self:radius_iter(3.1,player) do if self.team~=lt.team then p1:fight(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 end @@ -105,22 +132,29 @@ function player:cb_map(place,dialog) self:map(10) end +teamcolor={ red='\27[91m', green='\27[92m', yellow='\27[93m', blue='\27[94m', magenta='\27[95m', cyan='\27[96m' } + function player:map(radius) local radius=10 radius=radius or 10 local cells={} 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) lx=lx-px+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 + setcell(cells,math.floor(0.5+lx),math.floor(0.5+ly),celltext) end end - setcell(cells,radius,radius,string.format("Me:%3.3f",self:power())) + setcell(cells,radius,radius,teamcolor[self.team]..string.format("Me:%-3.0f",self:power()).."\27[0m") for ly=0,1+2*radius do local line='|' 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 print(line) end diff --git a/luprex/core/lua/uglyglobals.lua b/luprex/core/lua/uglyglobals.lua index f7f0299a..6b299929 100644 --- a/luprex/core/lua/uglyglobals.lua +++ b/luprex/core/lua/uglyglobals.lua @@ -28,12 +28,12 @@ function login.cb_uglytimedaemon() function time() return ug.get('time') end -function isa(k1,k2) - if k1==k2 then return true end +function isa(k1,k2,k3,k4) + if k1==k2 or k1==k3 or k1==k4 then return true end if k1==nil then return false end local mt=getmetatable(k1) if not mt then return false end - return isa(mt.__index,k2) + return isa(mt.__index,k2,k3,k4) end function tabcat(t1,t2) @@ -41,9 +41,10 @@ function tabcat(t1,t2) 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) 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 end