From e087db268006102f5607bd3fe2e31cb1b05cbd54 Mon Sep 17 00:00:00 2001 From: teppy999 Date: Mon, 31 Jan 2022 17:32:30 -0500 Subject: [PATCH 1/4] changes --- luprex/core/lua/teppygame.lua | 41 +++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 luprex/core/lua/teppygame.lua diff --git a/luprex/core/lua/teppygame.lua b/luprex/core/lua/teppygame.lua new file mode 100644 index 00000000..278775dc --- /dev/null +++ b/luprex/core/lua/teppygame.lua @@ -0,0 +1,41 @@ +maketangible('grass') + +if global.once("build grass") then + for y=0,4 do for x=0,y%2==1 and 3 or 4 do + tangible.build{class="grass",x=y%2==1 and 2*x+1 or 2*x+1,y=2*y+1,z=0,plane="main",graphic="grass"} + end end + end + +if global.once("walkable") then global.walkable={} end +if global.once("walkable main") then global.walkable["main"]={} end + + +function walkable(pl,x,y) + if not global.walkable then return false end + if not global.walkable[pl] then return false end + if not global.walkable[pl][y] then return false end + return global.walkable[pl][y][x] or false + end + +function setwalkable(pl,x,y,val) + if not global.walkable[pl][y] then global.walkable[pl][y]={} end + global.walkable[pl][y][x]=val + end + +if global.once("walkablexy") then for y=0,4 do for x=0,4 do setwalkable("main",x,y,true) end end end + +function player.move(actor,place,dx,dy) + local _,pl,x,y,_,_=tangible.animstate(actor) + print("Checking walkable "..pl.." "..x.." "..y.." is "..(walkable(pl,x+dx,y+dy) and "true" or "false")) + if not walkable(pl,x+dx,y+dy) then print("Not walkable") else + tangible.animate(place, {action="walk", dx=dx,dy=dy}) + local lis=tangible.near(actor,1,false,true) + if #lis==0 then print("The area is empty") + else for _,t in pairs(lis) do + print("There is a "..tangible.getclass(t).." here") + end end + end + _,pl,x,y,_,_=tangible.animstate(actor) + print("Your location is "..x.." "..y) +end + From 157c5fbbdf47ef5ec9e9183f7c37c1d50de04fa6 Mon Sep 17 00:00:00 2001 From: teppy999 Date: Tue, 1 Feb 2022 10:48:48 -0500 Subject: [PATCH 2/4] changes --- luprex/core/lua/control.lst | 3 ++- luprex/core/lua/player.lua | 42 ----------------------------------- luprex/core/lua/teppygame.lua | 2 +- 3 files changed, 3 insertions(+), 44 deletions(-) diff --git a/luprex/core/lua/control.lst b/luprex/core/lua/control.lst index f645dd9d..1e392a1f 100644 --- a/luprex/core/lua/control.lst +++ b/luprex/core/lua/control.lst @@ -6,5 +6,6 @@ ut-table.lua ut-globaldb.lua ut-tablecmp.lua -player.lua login.lua +horps.lua + diff --git a/luprex/core/lua/player.lua b/luprex/core/lua/player.lua index f879f2ea..e69de29b 100644 --- a/luprex/core/lua/player.lua +++ b/luprex/core/lua/player.lua @@ -1,42 +0,0 @@ -makeclass('player') - -function player.interface(actor, place) - -- print("actor=", actor) - -- print("place=", place) - -- print("t.actor=", tangible.actor()) - -- print("t.place=", tangible.place()) - gui.menu_item("cb_north", "Go North") - gui.menu_item("cb_south", "Go South") - gui.menu_item("cb_east", "Go East") - gui.menu_item("cb_west", "Go West") -end - -function player:printanimstate() - local graphic,plane,x,y,z,facing = tangible.animstate(self) - print("Resulting state: ", graphic, plane, x, y, z, facing) -end - -function player.cb_north(actor, place, dialog) - print("Moving north") - tangible.animate(place, {action="walk", dy=1}) - actor:printanimstate() -end - -function player.cb_south(actor, place, dialog) - print("Moving south") - tangible.animate(place, {action="walk", dy=-1}) - actor:printanimstate() -end - -function player.cb_east(actor, place, dialog) - print("Moving east") - tangible.animate(place, {action="walk", dx=1}) - actor:printanimstate() -end - -function player.cb_west(actor, place, dialog) - print("Moving west") - tangible.animate(place, {action="walk", dx=-1}) - actor:printanimstate() -end - diff --git a/luprex/core/lua/teppygame.lua b/luprex/core/lua/teppygame.lua index 278775dc..888ce6ce 100644 --- a/luprex/core/lua/teppygame.lua +++ b/luprex/core/lua/teppygame.lua @@ -1,4 +1,4 @@ -maketangible('grass') +makeclass('grass') if global.once("build grass") then for y=0,4 do for x=0,y%2==1 and 3 or 4 do From 4f4e905c0c2767ff523c2b4c86e5aab96470dc67 Mon Sep 17 00:00:00 2001 From: teppy999 Date: Thu, 3 Feb 2022 11:20:28 -0500 Subject: [PATCH 3/4] changes --- luprex/core/lua/horps.lua | 86 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 luprex/core/lua/horps.lua diff --git a/luprex/core/lua/horps.lua b/luprex/core/lua/horps.lua new file mode 100644 index 00000000..ad74aa1f --- /dev/null +++ b/luprex/core/lua/horps.lua @@ -0,0 +1,86 @@ +makeclass('player') + +function player.interface(actor, place) + gui.menu_item("cb_north", "Go North") + gui.menu_item("cb_south", "Go South") + gui.menu_item("cb_east", "Go East") + gui.menu_item("cb_west", "Go West") + gui.menu_item("cb_map", "Show the Map") + gui.menu_item("cb_emit_army","Emit an Army") + gui.menu_item("cb_emit_buff","Emit a Buff") +end + +function player:printanimstate() + local graphic,plane,x,y,z,facing = tangible.animstate(self) + print("Resulting state: ", graphic, plane, x, y, z, facing) +end + +function player.cb_north(actor, place, dialog) + tangible.animate(place, {action="walk", dy=1}) + actor:printanimstate() +end + +function player.cb_south(actor, place, dialog) + tangible.animate(place, {action="walk", dy=-1}) + actor:printanimstate() +end + +function player.cb_east(actor, place, dialog) + tangible.animate(place, {action="walk", dx=1}) + actor:printanimstate() +end + +function player.cb_west(actor, place, dialog) + tangible.animate(place, {action="walk", dx=-1}) + actor:printanimstate() +end + +function player.cb_emit_army(actor,place,dialog) + local _,pl,ax,ay=tangible.animstate(actor) + t={class='army',x=ax,y=ay,z=0,plane=pl,graphic='army'} + pprint("building ",t) + tangible.build(t) + end + +function player.cb_emit_buff(actor,place,dialog) + local _,pl,ax,ay=tangible.animstate(actor) + t={class='army',x=ax,y=ay,z=0,plane=pl,graphic='buff'} + pprint("building ",t) + tangible.build(t) + end + +makeclass('army') +makeclass('buff') + +function seq(a,b,c) return a<=b and b<=c or false end + +function player.cb_map(actor,place,dialog) + local rad=2 + local scratch={} + local lis=tangible.near(actor,rad*2+1,true,false) + pprint("cb_map ",lis) + for _,t in pairs(lis) do + local graphic,plane,x,y,z,facing = tangible.animstate(t) + local c=tangible.getclass(t) + local dx,dy=tangible.xyz(t) + local offset=(dy+rad)*(rad*2+1)+dx+rad + local cl=tangible.getclass(t) + print("Offset of "..cl.." is "..offset) + if not scratch[offset] then scratch[offset]={} end + if not scratch[offset].count then scratch[offset].count={} end + if not scratch[offset].count[cl] then scratch[offset].count[cl]=0 end + scratch[offset].count[cl]=scratch[offset].count[cl]+1 + end + for dy=0,rad*2+1 do for line=0,2 do + local lbuf="" + for dx=0,rad*2+1 do + if line==0 then lbuf=lbuf.."---" + elseif line==1 then lbuf=lbuf.."-x-" + elseif line==2 then lbuf=lbuf.."---" + end end + print(lbuf) + end end + end + + + From 310233ad27ab2c6e0d359fa2e5cb342cad992383 Mon Sep 17 00:00:00 2001 From: teppy999 Date: Thu, 3 Feb 2022 16:23:14 -0500 Subject: [PATCH 4/4] changes --- luprex/core/lua/horps.lua | 40 +++++++++++++++++++++++++++++++-------- luprex/core/lua/login.lua | 1 + 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/luprex/core/lua/horps.lua b/luprex/core/lua/horps.lua index ad74aa1f..51c09dc7 100644 --- a/luprex/core/lua/horps.lua +++ b/luprex/core/lua/horps.lua @@ -1,5 +1,11 @@ makeclass('player') +-- +-- Data Structure +-- Army.Count +-- Army.Kind 'r','p','s' +-- + function player.interface(actor, place) gui.menu_item("cb_north", "Go North") gui.menu_item("cb_south", "Go South") @@ -40,6 +46,8 @@ function player.cb_emit_army(actor,place,dialog) t={class='army',x=ax,y=ay,z=0,plane=pl,graphic='army'} pprint("building ",t) tangible.build(t) + t.kind='r' + t.count=5 end function player.cb_emit_buff(actor,place,dialog) @@ -57,7 +65,7 @@ function seq(a,b,c) return a<=b and b<=c or false end function player.cb_map(actor,place,dialog) local rad=2 local scratch={} - local lis=tangible.near(actor,rad*2+1,true,false) + local lis=tangible.near(actor,rad,true,false) pprint("cb_map ",lis) for _,t in pairs(lis) do local graphic,plane,x,y,z,facing = tangible.animstate(t) @@ -67,19 +75,35 @@ function player.cb_map(actor,place,dialog) local cl=tangible.getclass(t) print("Offset of "..cl.." is "..offset) if not scratch[offset] then scratch[offset]={} end - if not scratch[offset].count then scratch[offset].count={} end + if not scratch[offset].armies then scratch[offset].armies={} end + if cl=='player' then table.insert(scratch[offset].armies,t) end + if not scratch[offset].count then scratch[offset].count={} if not scratch[offset].count[cl] then scratch[offset].count[cl]=0 end - scratch[offset].count[cl]=scratch[offset].count[cl]+1 + if t.count then scratch[offset].count[cl]=scratch[offset].count[cl]+t.count end end - for dy=0,rad*2+1 do for line=0,2 do + for dy=-rad,rad do for line=0,1 do local lbuf="" - for dx=0,rad*2+1 do + for dx=-rad,rad do if line==0 then lbuf=lbuf.."---" - elseif line==1 then lbuf=lbuf.."-x-" - elseif line==2 then lbuf=lbuf.."---" - end end + elseif line==1 then + local kc=0 + local tc=0 + local kstr=' ' + for k,c in pairs(scratch[offset].count) do if c>0 then + kc=kc+1 + tc=tc+c + if kc>1 then kstr='M' else kstr=k end + end end + lbuf=lbuf.."-"..kstr..(tc>0 and tc or " ") + end end + lbuf=lbuf.."-" print(lbuf) end end + lbuf="" + for dx=-rad,rad do lbuf=lbuf.."---" end + lbuf=lbuf.."-" + print(lbuf) + end end diff --git a/luprex/core/lua/login.lua b/luprex/core/lua/login.lua index ed236251..b8d4eb67 100644 --- a/luprex/core/lua/login.lua +++ b/luprex/core/lua/login.lua @@ -7,6 +7,7 @@ end function login.cb_becomeplayer(actor, place, dialog) tangible.setclass(actor, player) + tangible.animate(actor,{action="warp",plane="main",x=0,y=0,z=0}) end function login.cb_p123(actor, place, dialog)