From 00d00f9cdcd0279e3e3014080508e571abd7795f Mon Sep 17 00:00:00 2001 From: Vladimir Menshakov Date: Sun, 7 Feb 2010 17:12:52 +0000 Subject: pathfinding improvements, added async flag setting svn-id: r47968 --- engines/teenagent/scene.cpp | 65 +++++++++++++++++++++++++++++---------------- engines/teenagent/scene.h | 3 ++- 2 files changed, 44 insertions(+), 24 deletions(-) diff --git a/engines/teenagent/scene.cpp b/engines/teenagent/scene.cpp index 8767a23498..5c41e17c64 100644 --- a/engines/teenagent/scene.cpp +++ b/engines/teenagent/scene.cpp @@ -95,6 +95,8 @@ bool Scene::findPath(Scene::Path &p, const Common::Point &src, const Common::Poi w.rect.side(w1, w2, w.side_hint[3], p1); debug(1, "hint: %d,%d-%d,%d", w1.x, w1.y, w2.x, w2.y); p.insert(next, w1); + if (mask & 2) + p.insert(next, w2); boxes.erase(wi); break; } @@ -105,6 +107,8 @@ bool Scene::findPath(Scene::Path &p, const Common::Point &src, const Common::Poi w.rect.side(w1, w2, w.side_hint[1], p1); debug(1, "hint: %d,%d-%d,%d", w1.x, w1.y, w2.x, w2.y); p.insert(next, w1); + if (mask & 8) + p.insert(next, w2); boxes.erase(wi); break; } @@ -117,6 +121,8 @@ bool Scene::findPath(Scene::Path &p, const Common::Point &src, const Common::Poi w.rect.side(w1, w2, w.side_hint[0], p1); debug(1, "hint: %d,%d-%d,%d", w1.x, w1.y, w2.x, w2.y); p.insert(next, w1); + if (mask & 4) + p.insert(next, w2); boxes.erase(wi); break; } @@ -127,6 +133,8 @@ bool Scene::findPath(Scene::Path &p, const Common::Point &src, const Common::Poi w.rect.side(w1, w2, w.side_hint[2], p1); debug(1, "hint: %d,%d-%d,%d", w1.x, w1.y, w2.x, w2.y); p.insert(next, w1); + if (mask & 1) + p.insert(next, w2); boxes.erase(wi); break; } @@ -144,29 +152,28 @@ void Scene::moveTo(const Common::Point &_point, byte orient, bool validate) { debug(0, "moveTo(%d, %d, %u)", point.x, point.y, orient); const Common::Array &scene_walkboxes = walkboxes[_id - 1]; - if (validate) { - for (byte i = 0; i < scene_walkboxes.size(); ++i) { - const Walkbox &w = scene_walkboxes[i]; - if (w.rect.in(point)) { - debug(0, "bumped into walkbox %u", i); - w.dump(); - byte o = w.orientation; - switch (o) { - case 1: - point.y = w.rect.top - 1; - break; - case 2: - point.x = w.rect.right + 1; - break; - case 3: - point.y = w.rect.bottom + 1; - break; - case 4: - point.x = w.rect.left - 1; - break; - default: + for (byte i = 0; i < scene_walkboxes.size(); ++i) { + const Walkbox &w = scene_walkboxes[i]; + if (w.rect.in(point)) { + debug(0, "bumped into walkbox %u", i); + w.dump(); + byte o = w.orientation; + switch (o) { + case 1: + point.y = w.rect.top - 1; + break; + case 2: + point.x = w.rect.right + 1; + break; + case 3: + point.y = w.rect.bottom + 1; + break; + case 4: + point.x = w.rect.left - 1; + break; + default: + if (validate) return; - } } } } @@ -251,6 +258,12 @@ void Scene::loadObjectData() { for (byte j = 0; j < walkboxes_n; ++j) { Walkbox w; w.load(walkboxes_base + 14 * j); + if ((w.side_hint[0] | w.side_hint[1] | w.side_hint[2] | w.side_hint[3]) == 0) { + w.side_hint[0] = 2; + w.side_hint[1] = 3; + w.side_hint[2] = 4; + w.side_hint[3] = 1; + } //walkbox[i]->dump(); scene_walkboxes.push_back(w); } @@ -481,7 +494,7 @@ bool Scene::processEvent(const Common::Event &event) { } break; } -#if 0 +#if 1 case '1': case '2': case '3': @@ -1093,6 +1106,12 @@ bool Scene::processEventQueue() { _engine->quitGame(); break; + case SceneEvent::kSetFlag: + debug(0, "async set_flag(%04x, %d)", current_event.callback, current_event.color); + Resources::instance()->dseg.set_byte(current_event.callback, current_event.color); + current_event.clear(); + break; + default: error("empty/unhandler event[%d]", (int)current_event.type); } diff --git a/engines/teenagent/scene.h b/engines/teenagent/scene.h index ef47ce0fc1..0e0a3440bf 100644 --- a/engines/teenagent/scene.h +++ b/engines/teenagent/scene.h @@ -62,6 +62,7 @@ struct SceneEvent { kEffect, kFade, kWait, + kSetFlag, kQuit } type; @@ -133,7 +134,7 @@ public: void warp(const Common::Point &point, byte orientation = 0); - void moveTo(const Common::Point &point, byte orientation = 0, bool validate = 0); + void moveTo(const Common::Point &point, byte orientation = 0, bool validate = false); Common::Point getPosition() const { return position; } void displayMessage(const Common::String &str, byte color = 0xd1, const Common::Point &pos = Common::Point()); -- cgit v1.2.3