From fa6e376242d7e7de95ff8419b226286b650fe304 Mon Sep 17 00:00:00 2001 From: Enne Walker Date: Sun, 29 Nov 2009 13:29:27 -0500 Subject: Change mapgrd and mapbld funcs to be 0-indexed. All the other dgn and map functions in Crawl are 0-indexed, so this makes everything more consistent. I've changed all the uses in the master branch, but if you're using these functions in another branch (dpeg and due), then you'll need to adjust all your coordinates to match. --- crawl-ref/docs/develop/levels/advanced.txt | 4 ++-- crawl-ref/source/dat/layout.des | 8 ++++---- crawl-ref/source/dat/vaults.des | 8 ++++---- crawl-ref/source/l_dgnbld.cc | 29 ++++++++++++----------------- crawl-ref/source/l_mapgrd.cc | 4 ++-- 5 files changed, 24 insertions(+), 29 deletions(-) (limited to 'crawl-ref') diff --git a/crawl-ref/docs/develop/levels/advanced.txt b/crawl-ref/docs/develop/levels/advanced.txt index a477d446e5..4a061f0034 100644 --- a/crawl-ref/docs/develop/levels/advanced.txt +++ b/crawl-ref/docs/develop/levels/advanced.txt @@ -811,11 +811,11 @@ Additionally, the dgn module provides a global "mapgrd" variable that can access the current map glyphs. The top left symbol in the map can be assigned like this: - mapgrd[1][1] = 'x' + mapgrd[0][0] = 'x' The bottom right symbol can be assigned like this: - mapgrd[width()][height()] = "." + mapgrd[width()-1][height()-1] = "." Lua API - global game state diff --git a/crawl-ref/source/dat/layout.des b/crawl-ref/source/dat/layout.des index 64fe16d2be..a620e3bd0c 100644 --- a/crawl-ref/source/dat/layout.des +++ b/crawl-ref/source/dat/layout.des @@ -267,7 +267,7 @@ TAGS: layout allow_dup replace_first({ required = true, x = gxm/2 + i - 2, - y = 1, + y = 0, xdir = 0, ydir = 1, find = ".", @@ -275,7 +275,7 @@ TAGS: layout allow_dup elseif loc == 3 then replace_first({ required = true, - x = gxm, + x = gxm - 1, y = gym/2 + i - 2, xdir = -1, ydir = 0, @@ -285,7 +285,7 @@ TAGS: layout allow_dup replace_first({ required = true, x = gxm/2 + i - 2, - y = gym, + y = gym - 1, xdir = 0, ydir = -1, find = ".", @@ -293,7 +293,7 @@ TAGS: layout allow_dup elseif loc == 5 then replace_first({ required = true, - x = 1, + x = 0, y = gym/2 + i - 2, xdir = 1, ydir = 0, diff --git a/crawl-ref/source/dat/vaults.des b/crawl-ref/source/dat/vaults.des index abcba262cd..5c25c750eb 100644 --- a/crawl-ref/source/dat/vaults.des +++ b/crawl-ref/source/dat/vaults.des @@ -564,10 +564,10 @@ TAGS: vault8_room for i in iter.subvault_iterator(_G) do if i.x == 0 or i.x == w-1 or i.y == 0 or i.y == h-1 then -- border - mapgrd[i.x+1][i.y+1] = '.' + mapgrd[i.x][i.y] = '.' else -- inside - mapgrd[i.x+1][i.y+1] = '*' + mapgrd[i.x][i.y] = '*' end end }} @@ -589,9 +589,9 @@ TAGS: vault8_room local i for i in iter.subvault_iterator(_G) do if (i.x + i.y) % 2 == 0 then - mapgrd[i.x+1][i.y+1] = '$' + mapgrd[i.x][i.y] = '$' else - mapgrd[i.x+1][i.y+1] = '.' + mapgrd[i.x][i.y] = '.' end end }} diff --git a/crawl-ref/source/l_dgnbld.cc b/crawl-ref/source/l_dgnbld.cc index fb78e6d15d..354ba4dad7 100644 --- a/crawl-ref/source/l_dgnbld.cc +++ b/crawl-ref/source/l_dgnbld.cc @@ -109,21 +109,16 @@ static bool _coords(lua_State *ls, map_lines &lines, int &x1, int &y1, int &x2, int &y2, int border = 0) { const int idx = -1; - x1 = _table_int(ls, idx, "x1", 1); - y1 = _table_int(ls, idx, "y1", 1); - x2 = _table_int(ls, idx, "x2", lines.width()); - y2 = _table_int(ls, idx, "y2", lines.height()); + x1 = _table_int(ls, idx, "x1", 0); + y1 = _table_int(ls, idx, "y1", 0); + x2 = _table_int(ls, idx, "x2", lines.width() - 1); + y2 = _table_int(ls, idx, "y2", lines.height() - 1); if (x2 < x1) std::swap(x1, x2); if (y2 < y1) std::swap(y1, y2); - x1--; - y1--; - x2--; - y2--; - return (x1 + border <= x2 - border && y1 + border <= y2 - border); } @@ -186,7 +181,7 @@ LUAFN(dgn_count_neighbors) TABLE_INT(ls, x, -1); TABLE_INT(ls, y, -1); - if (!_valid_coord(ls, lines, --x, --y)) + if (!_valid_coord(ls, lines, x, y)) return (0); coord_def tl(x-1, y-1); @@ -285,9 +280,9 @@ LUAFN(dgn_join_the_dots) TABLE_STR(ls, passable, traversable_glyphs); TABLE_CHAR(ls, fill, '.'); - if (!_valid_coord(ls, lines, --x1, --y1)) + if (!_valid_coord(ls, lines, x1, y1)) return (0); - if (!_valid_coord(ls, lines, --x2, --y2)) + if (!_valid_coord(ls, lines, x2, y2)) return (0); coord_def from(x1, y1); @@ -345,7 +340,7 @@ LUAFN(dgn_make_circle) TABLE_INT(ls, radius, 1); TABLE_CHAR(ls, fill, 'x'); - if (!_valid_coord(ls, lines, --x, --y)) + if (!_valid_coord(ls, lines, x, y)) return (0); for (int ry = -radius; ry <= radius; ++ry) @@ -365,7 +360,7 @@ LUAFN(dgn_make_diamond) TABLE_INT(ls, radius, 1); TABLE_CHAR(ls, fill, 'x'); - if (!_valid_coord(ls, lines, --x, --y)) + if (!_valid_coord(ls, lines, x, y)) return (0); for (int ry = -radius; ry <= radius; ++ry) @@ -385,7 +380,7 @@ LUAFN(dgn_make_rounded_square) TABLE_INT(ls, radius, 1); TABLE_CHAR(ls, fill, 'x'); - if (!_valid_coord(ls, lines, --x, --y)) + if (!_valid_coord(ls, lines, x, y)) return (0); for (int ry = -radius; ry <= radius; ++ry) @@ -405,7 +400,7 @@ LUAFN(dgn_make_square) TABLE_INT(ls, radius, 1); TABLE_CHAR(ls, fill, 'x'); - if (!_valid_coord(ls, lines, --x, --y)) + if (!_valid_coord(ls, lines, x, y)) return (0); for (int ry = -radius; ry <= radius; ++ry) @@ -492,7 +487,7 @@ LUAFN(dgn_replace_first) TABLE_CHAR(ls, replace, '\0'); TABLE_BOOL(ls, required, false); - if (!_valid_coord(ls, lines, --x, --y)) + if (!_valid_coord(ls, lines, x, y)) return (0); if (xdir < -1 || xdir > 1) diff --git a/crawl-ref/source/l_mapgrd.cc b/crawl-ref/source/l_mapgrd.cc index efefb583c5..f3098cfc23 100644 --- a/crawl-ref/source/l_mapgrd.cc +++ b/crawl-ref/source/l_mapgrd.cc @@ -40,12 +40,12 @@ static char* mapgrd_glyph(lua_State *ls, int &col, int &row) col = mapc->col; map_lines &lines = mapc->map->map; - if (row < 1 || col < 1 || col > lines.width() || row > lines.height()) + if (row < 0 || col < 0 || col >= lines.width() || row >= lines.height()) { return (NULL); } - coord_def mc(col - 1, row - 1); + coord_def mc(col, row); return (&lines(mc)); } -- cgit v1.2.3-54-g00ecf