From ec5940b4e743d2ed1e1225c768056648630a2f35 Mon Sep 17 00:00:00 2001 From: dg <dg@51575b47-30f0-44d4-a5cc-537603b46e54> Date: Sun, 31 Oct 2010 21:25:42 +0000 Subject: [PATCH] plop git-svn-id: http://svn.net-core.org/repos/t-engine4@1747 51575b47-30f0-44d4-a5cc-537603b46e54 --- game/engines/default/engine/Astar.lua | 8 ++++ game/modules/tome/ai/worldnpcs.lua | 6 +-- game/modules/tome/class/Encounter.lua | 9 +++-- .../tome/data/general/encounters/maj-eyal.lua | 40 ++----------------- .../tome/data/maps/wilderness/eyal.lua | 2 + game/modules/tome/data/wda/eyal.lua | 4 +- .../tome/data/zones/wilderness/zone.lua | 11 +++-- tiled-maps/eyal.tmx | 14 +++++++ 8 files changed, 46 insertions(+), 48 deletions(-) diff --git a/game/engines/default/engine/Astar.lua b/game/engines/default/engine/Astar.lua index e658741107..271cac16ae 100644 --- a/game/engines/default/engine/Astar.lua +++ b/game/engines/default/engine/Astar.lua @@ -86,6 +86,10 @@ function _M:calc(sx, sy, tx, ty, use_has_seen, heuristic) local cache = self.map._fovcache.path_caches[self.actor:getPathString()] local checkPos if cache then + if not (self.map:isBound(tx, ty) and ((use_has_seen and not self.map.has_seens(tx, ty)) or not cache:get(tx, ty))) then + print("Astar fail: destination unreachable") + return nil + end checkPos = function(node, nx, ny) local nnode = self:toSingle(nx, ny) if not closed[nnode] and self.map:isBound(nx, ny) and ((use_has_seen and not self.map.has_seens(nx, ny)) or not cache:get(nx, ny)) then @@ -104,6 +108,10 @@ function _M:calc(sx, sy, tx, ty, use_has_seen, heuristic) end end else + if not (self.map:isBound(tx, ty) and ((use_has_seen and not self.map.has_seens(tx, ty)) or not self.map:checkEntity(tx, ty, Map.TERRAIN, "block_move", self.actor, nil, true))) then + print("Astar fail: destination unreachable") + return nil + end checkPos = function(node, nx, ny) local nnode = self:toSingle(nx, ny) if not closed[nnode] and self.map:isBound(nx, ny) and ((use_has_seen and not self.map.has_seens(nx, ny)) or not self.map:checkEntity(nx, ny, Map.TERRAIN, "block_move", self.actor, nil, true)) then diff --git a/game/modules/tome/ai/worldnpcs.lua b/game/modules/tome/ai/worldnpcs.lua index 9710a80e2c..e39a07dc8a 100644 --- a/game/modules/tome/ai/worldnpcs.lua +++ b/game/modules/tome/ai/worldnpcs.lua @@ -63,13 +63,13 @@ newAI("move_world_patrol", function(self) self.ai_state.route = game.level:pickSpot{type="patrol", subtype=self.ai_state.route_kind} local a = Astar.new(game.level.map, self) self.ai_state.route_path = a:calc(self.x, self.y, self.ai_state.route.x, self.ai_state.route.y) --- print(self.name, "Selecting route!", self.ai_state.route_path, "from", self.x, self.y, "to", self.ai_state.route.x, self.ai_state.route.y) + print(self.name, "Selecting route!", self.ai_state.route_path, "from", self.x, self.y, "to", self.ai_state.route.x, self.ai_state.route.y) else local path = self.ai_state.route_path --- print("Using route", self.ai_state.route_path) + print("Using route", self.ai_state.route_path) if not path or not path[1] or (path[1] and math.floor(core.fov.distance(self.x, self.y, path[1].x, path[1].y)) > 1) then self.ai_state.route_path = nil self.ai_state.route = nil --- print("Nulling!", path, path and path[1], path and path[1] and math.floor(core.fov.distance(self.x, self.y, path[1].x, path[1].y))) + print("Nulling!", path, path and path[1], path and path[1] and math.floor(core.fov.distance(self.x, self.y, path[1].x, path[1].y))) return true else local ret = self:move(path[1].x, path[1].y) diff --git a/game/modules/tome/class/Encounter.lua b/game/modules/tome/class/Encounter.lua index db7e28bb04..6fb66f0f03 100644 --- a/game/modules/tome/class/Encounter.lua +++ b/game/modules/tome/class/Encounter.lua @@ -23,13 +23,12 @@ require "engine.Entity" module(..., package.seeall, class.inherit(engine.Entity)) function _M:init(t, no_default) - assert(t.coords, "no encounter coords") assert(t.level_range, "no encounter level_range") assert(t.on_encounter, "no encounter on_encounter") engine.Entity.init(self, t, no_default) - self:parseCoords() + if self.coords then self:parseCoords() end end function _M:parseCoords() @@ -59,9 +58,13 @@ end function _M:checkFilter(filter) if self.special_filter and not self.special_filter(self) then return false end - if filter.mapx and filter.mapy then + if filter.mapx and filter.mapy and self.on_map then if not self.on_map[filter.mapx.."x"..filter.mapy] then return false end end + if filter.mapx and filter.mapy and self.on_world_encounter then + local we = game.level.map.attrs(filter.mapx, filter.mapy, "world-encounter") + if not we or not we[self.on_world_encounter] then return false end + end return true end diff --git a/game/modules/tome/data/general/encounters/maj-eyal.lua b/game/modules/tome/data/general/encounters/maj-eyal.lua index 7a9705b4c8..855783cec0 100644 --- a/game/modules/tome/data/general/encounters/maj-eyal.lua +++ b/game/modules/tome/data/general/encounters/maj-eyal.lua @@ -21,20 +21,8 @@ newEntity{ name = "Novice mage", type = "harmless", subtype = "special", unique = true, level_range = {1, 10}, - rarity = 3, - coords = {{ x=10, y=18, likelymap={ - [[ 11111111 ]], - [[ 1111111111111 ]], - [[111111111111111]], - [[111111111111111]], - [[111111111111111]], - [[111111111111111]], - [[111111111111111]], - [[111111111111111]], - [[111111111111111]], - [[ 1111111111111 ]], - [[ 111111111 ]], - }}}, + rarity = 1, + on_world_encounter = "angolwen", -- Spawn the novice mage near the player on_encounter = function(self, who) local x, y = self:findSpot(who) @@ -130,7 +118,6 @@ newEntity{ type = "harmless", subtype = "special", unique = true, level_range = {30, 40}, rarity = 8, - coords = {{ x=0, y=0, w=100, h=100}}, on_encounter = function(self, who) local x, y = self:findSpot(who) if not x then return end @@ -154,27 +141,7 @@ newEntity{ type = "harmless", subtype = "special", unique = true, level_range = {5, 15}, rarity = 8, - coords = {{ x=61, y=15, likelymap={ - [[ 11111111 ]], - [[ 1111111111111 ]], - [[111111111111111]], - [[111111111111111]], - [[111111111111111]], - [[111111111111111]], - [[111111111111111]], - [[111111111111111]], - [[111111111111111]], - [[111111111111111]], - [[111111111111111]], - [[111111111111111]], - [[111111111111111]], - [[111111111111111]], - [[111111111111111]], - [[111111111111111]], - [[111111111111111]], - [[ 1111111111111 ]], - [[ 111111111 ]], - }}}, + on_world_encounter = "lumberjack-cursed", on_encounter = function(self, who) local Chat = require "engine.Chat" local chat = Chat.new("lumberjack-quest", {name="Half-dead lumberjack"}, who) @@ -188,7 +155,6 @@ newEntity{ type = "harmless", subtype = "special", unique = true, level_range = {15, 25}, rarity = 7, - coords = {{ x=0, y=0, w=100, h=100}}, special_filter = function(self) local p = game.player if p.level < 15 then return false end diff --git a/game/modules/tome/data/maps/wilderness/eyal.lua b/game/modules/tome/data/maps/wilderness/eyal.lua index bcccf2cae1..f94cb3b806 100644 --- a/game/modules/tome/data/maps/wilderness/eyal.lua +++ b/game/modules/tome/data/maps/wilderness/eyal.lua @@ -148,6 +148,8 @@ addZone({7, 54, 75, 86}, "zonename", "Tar'Eyal") addZone({11, 51, 21, 54}, "zonename", "Tar'Eyal") addZone({64, 52, 66, 53}, "zonename", "Tar'Eyal") addZone({11, 87, 16, 94}, "zonename", "Tar'Eyal") +addZone({54, 23, 65, 37}, "world-encounter", "lumberjack-cursed") +addZone({3, 15, 19, 33}, "world-encounter", "angolwen") -- ASCII map section return { diff --git a/game/modules/tome/data/wda/eyal.lua b/game/modules/tome/data/wda/eyal.lua index 0b9450c78c..4c5e812e4c 100644 --- a/game/modules/tome/data/wda/eyal.lua +++ b/game/modules/tome/data/wda/eyal.lua @@ -75,7 +75,7 @@ if zone == "Maj'Eyal" then -- Spawn some hostiles if wda.cur_hostiles < 4 and rng.percent(5) then - local e = game.zone:makeEntity(game.level, "maj_eyal_encounters_npcs", {type="hostile", subtype="maj eyal"}, nil, true) + local e = game.zone:makeEntity(game.level, "maj_eyal_encounters_npcs", {type="hostile"}, nil, true) if e then local spot = game.level:pickSpot{type="hostile", subtype="maj-eyal"} if spot and not game.level.map(spot.x, spot.y, Map.ACTOR) and not game.level.map.seens(spot.x, spot.y) then @@ -142,7 +142,7 @@ elseif zone == "Far East" then -- Spawn some hostiles if wda.cur_hostiles < 4 and rng.percent(5) then - local e = game.zone:makeEntity(game.level, "fareast_encounters_npcs", {type="hostile", subtype="fareast"}, nil, true) + local e = game.zone:makeEntity(game.level, "fareast_encounters_npcs", {type="hostile"}, nil, true) if e then local spot = game.level:pickSpot{type="hostile", subtype="fareast"} if spot and not game.level.map(spot.x, spot.y, Map.ACTOR) and not game.level.map.seens(spot.x, spot.y) then diff --git a/game/modules/tome/data/zones/wilderness/zone.lua b/game/modules/tome/data/zones/wilderness/zone.lua index d3e90a0e52..881b9677b4 100644 --- a/game/modules/tome/data/zones/wilderness/zone.lua +++ b/game/modules/tome/data/zones/wilderness/zone.lua @@ -24,12 +24,12 @@ return { level_range = {1, 1}, max_level = 1, width = 170, height = 100, - all_remembered = true, - all_lited = true, +-- all_remembered = true, +-- all_lited = true, persistant = "memory", ambiant_music = "Remembrance.ogg", wilderness = true, --- wilderness_see_radius = 4, + wilderness_see_radius = 4, generator = { map = { class = "engine.generator.map.Static", @@ -42,6 +42,11 @@ return { for x = z.x1, z.x2 do for y = z.y1, z.y2 do game.level.map.attrs(x, y, "zonename", z.subtype) end end + elseif z.type == "world-encounter" then + for x = z.x1, z.x2 do for y = z.y1, z.y2 do + if not game.level.map.attrs(x, y, "world-encounter") then game.level.map.attrs(x, y, "world-encounter", {}) end + game.level.map.attrs(x, y, "world-encounter")[z.subtype] = true + end end end end diff --git a/tiled-maps/eyal.tmx b/tiled-maps/eyal.tmx index 90524da61c..77c89d6e22 100644 --- a/tiled-maps/eyal.tmx +++ b/tiled-maps/eyal.tmx @@ -518,4 +518,18 @@ </properties> </object> </objectgroup> + <objectgroup name="addZone" width="170" height="100"> + <object name="Lumjberjack quest" x="1759" y="741" width="348" height="469"> + <properties> + <property name="subtype" value=""lumberjack-cursed""/> + <property name="type" value=""world-encounter""/> + </properties> + </object> + <object name="Angolwen quest" x="123" y="485" width="510" height="597"> + <properties> + <property name="subtype" value=""angolwen""/> + <property name="type" value=""world-encounter""/> + </properties> + </object> + </objectgroup> </map> -- GitLab