Merge branch 'main' of https://github.com/jyelon/luprex into main
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
makeclass('player')
|
makeclass('player')
|
||||||
makeclass('army')
|
makeclass('army')
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- HORPS game: Walk around the board collecting armies and buffs
|
-- HORPS game: Walk around the board collecting armies and buffs
|
||||||
-- Captured armies eat each turn
|
-- Captured armies eat each turn
|
||||||
@@ -71,11 +72,33 @@ function shuffle(t)
|
|||||||
return s
|
return s
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function qbuildarmy(x,y)
|
||||||
|
t={class='army',x=x,y=y,z=0,plane='main',graphic='army'}
|
||||||
|
local nt=tangible.build(t)
|
||||||
|
nt.Count={}
|
||||||
|
setmetatable(nt.Count,NilIsZero)
|
||||||
|
nt.Count['r']=1
|
||||||
|
return nt
|
||||||
|
end
|
||||||
|
|
||||||
|
function MakeMap2()
|
||||||
|
for i=-2,2 do
|
||||||
|
qbuildarmy( i, 3)
|
||||||
|
qbuildarmy( i,-3)
|
||||||
|
qbuildarmy(-3, i)
|
||||||
|
qbuildarmy( 3, i)
|
||||||
|
end
|
||||||
|
qbuildarmy(-3, 3)
|
||||||
|
qbuildarmy( 3,-3)
|
||||||
|
qbuildarmy(-3,-3)
|
||||||
|
qbuildarmy( 3, 3)
|
||||||
|
end
|
||||||
|
|
||||||
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 if math.random(1,5)==1 then
|
||||||
t={class='army',x=x,y=y,z=0,plane='main',graphic='army'}
|
t={class='army',x=x,y=y,z=0,plane='main',graphic='army'}
|
||||||
print("Building an army:")
|
-- print("Building an army:")
|
||||||
-- pprint(t)
|
-- pprint(t)
|
||||||
local nt=tangible.build(t)
|
local nt=tangible.build(t)
|
||||||
nt.Count={}
|
nt.Count={}
|
||||||
@@ -84,7 +107,7 @@ function MakeMap()
|
|||||||
local type=armytypes[math.random(1,#armytypes)]
|
local type=armytypes[math.random(1,#armytypes)]
|
||||||
nt.Count[type]=nt.Count[type]+math.random(1,3)
|
nt.Count[type]=nt.Count[type]+math.random(1,3)
|
||||||
end end
|
end end
|
||||||
print("Here's what was built:")
|
-- print("Here's what was built:")
|
||||||
-- pprint(nt)
|
-- pprint(nt)
|
||||||
end end end
|
end end end
|
||||||
end
|
end
|
||||||
@@ -93,6 +116,7 @@ function MakeMap()
|
|||||||
-- For each creature type, select the optimal target. Select randomly among identical targets.
|
-- For each creature type, select the optimal target. Select randomly among identical targets.
|
||||||
--
|
--
|
||||||
function army.fight0(ak,ac,dk,dc,rules) -- returns number of attacker casualties, defender casualties
|
function army.fight0(ak,ac,dk,dc,rules) -- returns number of attacker casualties, defender casualties
|
||||||
|
if not rules then rules={} end
|
||||||
local adv0=advantage[ak][dk]
|
local adv0=advantage[ak][dk]
|
||||||
local adv1=advantage[dk][ak]
|
local adv1=advantage[dk][ak]
|
||||||
if rules.counterattack=='one' then adv1=1
|
if rules.counterattack=='one' then adv1=1
|
||||||
@@ -104,17 +128,15 @@ function army.fight0(ak,ac,dk,dc,rules) -- returns number of attacker casualties
|
|||||||
return rval0,rval1
|
return rval0,rval1
|
||||||
end
|
end
|
||||||
|
|
||||||
function army.cb_fight(actor,place,dialog)
|
function player:fight(enemy)
|
||||||
for ak,ac in pairs(actor.Count) do -- Should randomize the order
|
for ak,ac in pairs(self.Count) do -- Should randomize the order
|
||||||
local enemyk, enemyc
|
local enemyk, enemyc
|
||||||
local acas
|
local acas
|
||||||
local maxcas=-1
|
local maxcas=-1
|
||||||
local Loss0,Loss1
|
local Loss0,Loss1
|
||||||
local whichdk, whichdc
|
local whichdk, whichdc
|
||||||
for dk,dc in pairs(place.Count) do
|
for dk,dc in pairs(enemy.Count) do
|
||||||
local rem0,rem1=army.fight0(ak,ac,dk,dc)
|
Loss0,Loss1=army.fight0(ak,ac,dk,dc)
|
||||||
Loss0=ac-rem0
|
|
||||||
Loss1=dc-rem1
|
|
||||||
print("When "..ac.." "..ak.." fight "..dc.." "..dk.." they kill "..Loss1.." and suffer "..Loss0)
|
print("When "..ac.." "..ak.." fight "..dc.." "..dk.." they kill "..Loss1.." and suffer "..Loss0)
|
||||||
if Loss1>maxcas then
|
if Loss1>maxcas then
|
||||||
enemyk=dk
|
enemyk=dk
|
||||||
@@ -144,9 +166,8 @@ function player:droparmy(actor,kind)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function player:newlocation()
|
function player:newlocation()
|
||||||
local lis=tangible.near(self,0,false,false)
|
local lis=tangible.near(self,0,true,true)
|
||||||
-- print("New Location")
|
for _,t in ipairs(lis) do self:fight(t) end
|
||||||
-- pprint(lis)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function player:printanimstate()
|
function player:printanimstate()
|
||||||
@@ -156,21 +177,25 @@ function player:printanimstate()
|
|||||||
|
|
||||||
function player:cb_north()
|
function player:cb_north()
|
||||||
tangible.animate(self, {action="walk", dy=1})
|
tangible.animate(self, {action="walk", dy=1})
|
||||||
|
self:cb_map()
|
||||||
self:newlocation()
|
self:newlocation()
|
||||||
end
|
end
|
||||||
|
|
||||||
function player:cb_south(place, dialog)
|
function player:cb_south()
|
||||||
tangible.animate(place, {action="walk", dy=-1})
|
tangible.animate(self, {action="walk", dy=-1})
|
||||||
|
self:cb_map()
|
||||||
self:newlocation()
|
self:newlocation()
|
||||||
end
|
end
|
||||||
|
|
||||||
function player.cb_east(actor, place, dialog)
|
function player:cb_east()
|
||||||
tangible.animate(actor, {action="walk", dx=1})
|
tangible.animate(self, {action="walk", dx=1})
|
||||||
|
self:cb_map()
|
||||||
self:newlocation()
|
self:newlocation()
|
||||||
end
|
end
|
||||||
|
|
||||||
function player:cb_west(actor, place, dialog)
|
function player:cb_west()
|
||||||
tangible.animate(actor, {action="walk", dx=-1})
|
tangible.animate(self, {action="walk", dx=-1})
|
||||||
|
self:cb_map()
|
||||||
self:newlocation()
|
self:newlocation()
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -210,16 +235,17 @@ function num2(a) if a<=9 then return " "..a else return a end end
|
|||||||
|
|
||||||
function player.cb_map(actor,place,dialog)
|
function player.cb_map(actor,place,dialog)
|
||||||
local rad=4
|
local rad=4
|
||||||
scratch={}
|
local ax,ay=tangible.xyz(actor)
|
||||||
|
local scratch={}
|
||||||
local lis=tangible.near(actor,1.5*rad,true,false)
|
local lis=tangible.near(actor,1.5*rad,true,false)
|
||||||
print("\27[38;5;9mMap:\27[0m")
|
print("\27c\27[38;5;9mMap:\27[0m")
|
||||||
for _,t in pairs(lis) do
|
for _,t in pairs(lis) do
|
||||||
local graphic,plane,x,y,z,facing = tangible.animstate(t)
|
-- local graphic,plane,x,y,z,facing = tangible.animstate(t)
|
||||||
local c=tangible.getclass(t)
|
local c=tangible.getclass(t)
|
||||||
local dx,dy=tangible.xyz(t)
|
local dx,dy=tangible.xyz(t)
|
||||||
local offset=(dy+rad)*(rad*2+1)+dx+rad
|
local offset=(-dy+ay+rad)*(rad*2+1)+dx-ax+rad
|
||||||
local cl=tangible.getclass(t)
|
local cl=tangible.getclass(t)
|
||||||
if 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') then
|
||||||
if not scratch[offset] then scratch[offset]={} scratch[offset].Count={} setmetatable(scratch[offset].Count,NilIsZero) end
|
if not scratch[offset] then scratch[offset]={} scratch[offset].Count={} setmetatable(scratch[offset].Count,NilIsZero) end
|
||||||
if t.Count then
|
if t.Count then
|
||||||
for i,k in ipairs(armytypes) do
|
for i,k in ipairs(armytypes) do
|
||||||
@@ -235,7 +261,7 @@ function player.cb_map(actor,place,dialog)
|
|||||||
end
|
end
|
||||||
-- pprint(scratch)
|
-- pprint(scratch)
|
||||||
for dy=-rad,rad do for line=0,1 do
|
for dy=-rad,rad do for line=0,1 do
|
||||||
local lbuf=""
|
local lbuf="|"
|
||||||
for dx=-rad,rad do
|
for dx=-rad,rad do
|
||||||
local offset=(dy+rad)*(rad*2+1)+dx+rad
|
local offset=(dy+rad)*(rad*2+1)+dx+rad
|
||||||
if line==0 then lbuf=lbuf.."----"
|
if line==0 then lbuf=lbuf.."----"
|
||||||
@@ -251,13 +277,11 @@ function player.cb_map(actor,place,dialog)
|
|||||||
lbuf=lbuf.."-"
|
lbuf=lbuf.."-"
|
||||||
print(lbuf)
|
print(lbuf)
|
||||||
-- print("In Player "..tangible.id(actor)..":")
|
-- print("In Player "..tangible.id(actor)..":")
|
||||||
for k,v in pairs(actor.Count) do print(" "..k.." "..v) end
|
-- for k,v in pairs(actor.Count) do print(" "..k.." "..v) end
|
||||||
local lis=tangible.near(actor,0,true,true)
|
-- local lis=tangible.near(actor,0,true,true)
|
||||||
for k,v in pairs(lis) do
|
-- for k,v in pairs(lis) do
|
||||||
-- print("In Army "..tangible.id(v)..":")
|
-- print("In Army "..tangible.id(v)..":")
|
||||||
for k2,v2 in pairs(v.Count) do print(" "..k2.." "..v2) end
|
-- for k2,v2 in pairs(v.Count) do print(" "..k2.." "..v2) end
|
||||||
end
|
-- end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
7
luprex/core/lua/prng.lua
Normal file
7
luprex/core/lua/prng.lua
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
makeclass('prng')
|
||||||
|
|
||||||
|
function prng.seed(n)
|
||||||
|
ug.set(prngseed,n)
|
||||||
|
end
|
||||||
|
|
||||||
|
function
|
||||||
20
luprex/core/lua/uglyglobals.lua
Normal file
20
luprex/core/lua/uglyglobals.lua
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
makeclass('ug')
|
||||||
|
|
||||||
|
function ug.the()
|
||||||
|
return tangible.scan('globals',0,0,0,true)[1]
|
||||||
|
end
|
||||||
|
|
||||||
|
lis=tangible.scan('globals',0,0,0,true)
|
||||||
|
if #lis==0 then
|
||||||
|
local ugid=tangible.build{class='ug',x=0,y=0,z=0,plane='globals',graphic='box'}
|
||||||
|
print("The global table is "..tangible.id(ugid))
|
||||||
|
end
|
||||||
|
|
||||||
|
function ug.set(var,val)
|
||||||
|
ug.the()[var]=val
|
||||||
|
end
|
||||||
|
|
||||||
|
function ug.get(var)
|
||||||
|
return ug.the()[var]
|
||||||
|
end
|
||||||
|
|
||||||
Reference in New Issue
Block a user