From 6c46caa24e4a02d3b6ac208b8b2cfffb91c0946c Mon Sep 17 00:00:00 2001
From: dg <dg@51575b47-30f0-44d4-a5cc-537603b46e54>
Date: Tue, 22 Nov 2011 08:24:26 +0000
Subject: [PATCH] fix

git-svn-id: http://svn.net-core.org/repos/t-engine4@4663 51575b47-30f0-44d4-a5cc-537603b46e54
---
 game/modules/tome/class/Player.lua            |  6 +--
 .../data/quests/tutorial-combat-stats.lua     |  2 +-
 .../tome/data/talents/gifts/cold-drake.lua    | 37 ++++++++++---
 src/fov.c                                     | 54 +++++++++++++++++++
 4 files changed, 89 insertions(+), 10 deletions(-)

diff --git a/game/modules/tome/class/Player.lua b/game/modules/tome/class/Player.lua
index 7360214efa..0e88ffa5a4 100644
--- a/game/modules/tome/class/Player.lua
+++ b/game/modules/tome/class/Player.lua
@@ -79,7 +79,7 @@ function _M:init(t, no_default)
 
 	t.rank = t.rank or 3
 	t.old_life = 0
-	
+
 	t.money_value_multiplier = 1 -- changes amounts in gold piles and such
 
 	mod.class.Actor.init(self, t, no_default)
@@ -167,8 +167,8 @@ function _M:describeFloor(x, y)
 		local obj = game.level.map:getObject(x, y, i)
 		while obj do
 			local desc = true
-			if (obj.auto_pickup and not obj.unique) and self:pickupFloor(i, true) then desc = false end
-			if self:attr("has_transmo") and obj.__transmo == nil and (not obj.quest and not obj.plot) then
+			if obj.auto_pickup and self:pickupFloor(i, true) then desc = false end
+			if desc and self:attr("has_transmo") and obj.__transmo == nil and (not obj.quest and not obj.plot) then
 				if self:pickupFloor(i, true) then
 					desc = false
 					obj.__transmo = true
diff --git a/game/modules/tome/data/quests/tutorial-combat-stats.lua b/game/modules/tome/data/quests/tutorial-combat-stats.lua
index f4aa381a26..78f446b75f 100644
--- a/game/modules/tome/data/quests/tutorial-combat-stats.lua
+++ b/game/modules/tome/data/quests/tutorial-combat-stats.lua
@@ -78,7 +78,7 @@ choose_combat_stats = function(self, who, status, sub)
 end
 ]=]
 on_grant = function(self)
-	game.player.combat_atk = 24
+	game.player.combat_atk = 25
 	game.player.combat_dam = 7
 	game.player.combat_spellpower = 88
 	game.player.combat_def = 18
diff --git a/game/modules/tome/data/talents/gifts/cold-drake.lua b/game/modules/tome/data/talents/gifts/cold-drake.lua
index 79162e84eb..171c056524 100644
--- a/game/modules/tome/data/talents/gifts/cold-drake.lua
+++ b/game/modules/tome/data/talents/gifts/cold-drake.lua
@@ -134,17 +134,42 @@ newTalent{
 		local x1, y1 = x + math.cos(angle) * size, y + math.sin(angle) * size
 		local x2, y2 = x - math.cos(angle) * size, y - math.sin(angle) * size
 
-		local l = line.new(x, y, x1, y1)
+		local dx1, dy1 = math.abs(x1 - x), math.abs(y1 - y)
+		local dx2, dy2 = math.abs(x2 - x), math.abs(y2 - y)
+		local block_corner = function(_, bx, by)
+				if game.level.map:checkAllEntities(bx, by, "block_move") then return true
+				else addwall(bx, by) ; return false end
+			end
+
+		local l = core.fov.line(x, y, x1, y1, function(_, bx, by) return true end)
+		l:set_corner_block(block_corner)
+		-- use the correct tangent (not approximate) and round corner tie-breakers toward the player (via wiggles!)
+		if dx1 < dy1 then
+			l:change_step((x1-x)/dy1, (y1-y)/dy1)
+			if y < self.y then l:wiggle(true) else l:wiggle() end
+		else
+			l:change_step((x1-x)/dx1, (y1-y)/dx1)
+			if x < self.x then l:wiggle(true) else l:wiggle() end
+		end
 		while true do
-			local lx, ly = l()
-			if not lx or game.level.map:checkAllEntities(lx, ly, "block_move") then break end
+			local lx, ly, is_corner_blocked = l:step()
+			if not lx or is_corner_blocked or game.level.map:checkAllEntities(lx, ly, "block_move") then break end
 			addwall(lx, ly)
 		end
 
-		local l = line.new(x, y, x2, y2)
+		local l = core.fov.line(x, y, x2, y2, function(_, bx, by) return true end)
+		l:set_corner_block(block_corner)
+		-- use the correct tangent (not approximate) and round corner tie-breakers toward the player (via wiggles!)
+		if dx2 < dy2 then
+			l:change_step((x2-x)/dy2, (y2-y)/dy2)
+			if y < self.y then l:wiggle(true) else l:wiggle() end
+		else
+			l:change_step((x2-x)/dx2, (y2-y)/dx2)
+			if x < self.x then l:wiggle(true) else l:wiggle() end
+		end
 		while true do
-			local lx, ly = l()
-			if not lx or game.level.map:checkAllEntities(lx, ly, "block_move") then break end
+			local lx, ly, is_corner_blocked = l:step()
+			if not lx or is_corner_blocked or game.level.map:checkAllEntities(lx, ly, "block_move") then break end
 			addwall(lx, ly)
 		end
 
diff --git a/src/fov.c b/src/fov.c
index 0bd5f21081..24a22f09de 100644
--- a/src/fov.c
+++ b/src/fov.c
@@ -697,6 +697,58 @@ static int lua_fov_line_step(lua_State *L)
 	return 4;
 }
 
+// Hmm, this function was just added and may change in the near-future.  We probably want
+// to create a line at a specific angle, so let's simply make a function that does just that.
+static int lua_fov_line_change_step(lua_State *L)
+{
+	lua_fov_line *lua_line;
+	if (lua_istable(L, 1)) {
+		lua_getfield(L, 1, "line");
+		lua_line = (lua_fov_line*)auxiliar_checkclass(L, "core{fovline}", -1);
+		lua_pop(L, 1);
+	} else {
+		lua_line = (lua_fov_line*)auxiliar_checkclass(L, "core{fovline}", 1);
+	}
+	fov_line_data *line = &(lua_line->line);
+	float step_x = lua_tonumber(L, 2);
+	float step_y = lua_tonumber(L, 3);
+
+	line->step_x = step_x;
+	line->step_y = step_y;
+	return 0;
+}
+
+// use to "wiggle" away from boundary cases
+static int lua_fov_line_wiggle(lua_State *L)
+{
+	lua_fov_line *lua_line;
+	if (lua_istable(L, 1)) {
+		lua_getfield(L, 1, "line");
+		lua_line = (lua_fov_line*)auxiliar_checkclass(L, "core{fovline}", -1);
+		lua_pop(L, 1);
+	} else {
+		lua_line = (lua_fov_line*)auxiliar_checkclass(L, "core{fovline}", 1);
+	}
+	fov_line_data *line = &(lua_line->line);
+	bool wiggle_me_gently = lua_toboolean(L, 2);
+
+	if (fabs(line->step_x) < fabs(line->step_y)) {
+		if (wiggle_me_gently) {
+			line->step_y += 0.001f;
+		} else {
+			line->step_y -= 0.001f;
+		}
+	} else {
+		if (wiggle_me_gently) {
+			line->step_x += 0.001f;
+		} else {
+			line->step_x -= 0.001f;
+		}
+	}
+
+	return 0;
+}
+
 // The next three functions aren't used anywhere and can probably be deleted
 static int lua_fov_line_blocked_xy(lua_State *L)
 {
@@ -913,6 +965,8 @@ static const struct luaL_reg fovline_reg[] =
 	{"__gc", lua_free_fov_line},
 	{"__call", lua_fov_line_step},
 	{"step", lua_fov_line_step},
+	{"change_step", lua_fov_line_change_step},
+	{"wiggle", lua_fov_line_wiggle},
 	{"is_blocked", lua_fov_line_is_blocked},
 	{"blocked_xy", lua_fov_line_blocked_xy},
 	{"last_open_xy", lua_fov_line_last_open_xy},
-- 
GitLab