From 67c8bb6f116aeba46e06f51adb48fed97386e545 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Wed, 30 Jul 2014 22:53:05 +1000 Subject: [PATCH] rsc/ and common/ seem OK from the splice (read more) common compiles correctly, although there are issues: * There needs to be support for multiple pagers at once * There needs to be a way to support multiple generation algorithms --- common/map/makefile | 2 +- rsc/scripts/file_format.lua | 9 -------- rsc/scripts/generator.lua | 16 ------------- rsc/scripts/in_world.lua | 33 --------------------------- rsc/scripts/setup_server.lua | 44 ++++++++++++++++++++++-------------- 5 files changed, 28 insertions(+), 76 deletions(-) delete mode 100644 rsc/scripts/file_format.lua delete mode 100644 rsc/scripts/generator.lua delete mode 100644 rsc/scripts/in_world.lua diff --git a/common/map/makefile b/common/map/makefile index 769709e..f78feb9 100644 --- a/common/map/makefile +++ b/common/map/makefile @@ -1,5 +1,5 @@ #config -INCLUDES+=. ../utilities +INCLUDES+=. ../utilities ../graphics LIBS+= CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) diff --git a/rsc/scripts/file_format.lua b/rsc/scripts/file_format.lua deleted file mode 100644 index 5cff60a..0000000 --- a/rsc/scripts/file_format.lua +++ /dev/null @@ -1,9 +0,0 @@ ---overwriting the existing hard coded methods -function Region.Load(region) - --the return value signals if this succeeded or failed - return false -end - -function Region.Save(region) - -- -end diff --git a/rsc/scripts/generator.lua b/rsc/scripts/generator.lua deleted file mode 100644 index f736ac1..0000000 --- a/rsc/scripts/generator.lua +++ /dev/null @@ -1,16 +0,0 @@ ---uber lazy declarations -function math.sqr(x) return x*x end -function math.dist(x, y, i, j) return math.sqrt(math.sqr(x-i) + math.sqr(y-j)) end - ---define these -function Region.Create(region) - for i = 1, Region.GetWidth() do - for j = 1, Region.GetHeight() do - Region.SetTile(region, i, j, 1, 1) --to show the basics are working - end - end -end - -function Region.Unload(region) - -- -end diff --git a/rsc/scripts/in_world.lua b/rsc/scripts/in_world.lua deleted file mode 100644 index 43350aa..0000000 --- a/rsc/scripts/in_world.lua +++ /dev/null @@ -1,33 +0,0 @@ -local sheet = TileSheet.GetTileSheet() -local pager = RegionPager.GetRegionPager() - ---the selected tilesheet -TileSheet.Load(sheet, config.dir.tilesets .. "terrain.bmp", 32, 32) - ---tile macros, mapped to this tilesheet -local base = 14 -local shift = 36 -tiles = { - plains = base + shift * 0, - grass = base + shift * 1, - dirt = base + shift * 2, - sand = base + shift * 3, - water = base + shift * 4 -} - ---could set custom generation systems here, that differ from the global generators, etc. -function Region.Create(region) - for i = 1, Region.GetWidth() do - for j = 1, Region.GetHeight() do - local dist = math.dist(0, 0, i + Region.GetX(region) -1, j + Region.GetY(region) -1) - if dist < 10 then - Region.SetTile(region, i, j, 1, tiles.plains) - elseif dist < 12 then - Region.SetTile(region, i, j, 1, tiles.sand) - else - Region.SetTile(region, i, j, 1, tiles.water) - Region.SetSolid(region, i, j, true) - end - end - end -end diff --git a/rsc/scripts/setup_server.lua b/rsc/scripts/setup_server.lua index ceb735e..f71aa36 100644 --- a/rsc/scripts/setup_server.lua +++ b/rsc/scripts/setup_server.lua @@ -1,35 +1,45 @@ print("Lua script check") --uber lazy declarations -function square(x) return x*x end -function distance(x, y, i, j) return math.sqrt(square(x - i) + square(y - j)) end +function math.sqr(x) return x*x end +function math.dist(x, y, i, j) return math.sqrt(math.sqr(x - i) + math.sqr(y - j)) end ---tile macros, mapped to the tilesheet +--objects to work on +--TODO: sheet is not accessable in the server +local sheet = TileSheet.GetTileSheet() +local pager = RegionPager.GetRegionPager() + +--the selected tilesheet +TileSheet.Load(sheet, config.dir.tilesets .. "terrain.bmp", 32, 32) + +--tile macros, mapped to this tilesheet local base = 14 local shift = 36 -plains = base + shift * 0 -grass = base + shift * 1 -dirt = base + shift * 2 -sand = base + shift * 3 -water = base + shift * 4 +tiles = { + plains = base + shift * 0, + grass = base + shift * 1, + dirt = base + shift * 2, + sand = base + shift * 3, + water = base + shift * 4 +} ---Overwrite the original OnCreate with my own version -Region.hcOnCreate = Region.OnCreate -Region.OnCreate = function(region) - local ret = Region.hcOnCreate(region) --best practices +--TODO: could set custom generation systems here, that differ from the global generators, etc. +--TODO: I need a way to allow for different generation algorithms for different pager objects +--TODO: This design requires only one pager, but this is not good. +function Region.Create(region) for i = 1, Region.GetWidth() do for j = 1, Region.GetHeight() do - local dist = distance(0, 0, i + Region.GetX(region) -1, j + Region.GetY(region) -1) + local dist = math.dist(0, 0, i + Region.GetX(region) -1, j + Region.GetY(region) -1) if dist < 10 then - Region.SetTile(region, i, j, 1, plains) + Region.SetTile(region, i, j, 1, tiles.plains) elseif dist < 12 then - Region.SetTile(region, i, j, 1, sand) + Region.SetTile(region, i, j, 1, tiles.sand) else - Region.SetTile(region, i, j, 1, water) + Region.SetTile(region, i, j, 1, tiles.water) + Region.SetSolid(region, i, j, true) end end end - return ret end print("Finished the lua script") \ No newline at end of file