From 93010a840734507b84554ad47e50eec7db34a939 Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 8 Jun 2014 14:26:42 +0200 Subject: CGE2: Implement CGE2Engine::mapCross(). Rework Map during the process. --- engines/cge2/hero.cpp | 20 ++++++++++++++++++-- engines/cge2/map.cpp | 4 ++-- engines/cge2/map.h | 2 +- 3 files changed, 21 insertions(+), 5 deletions(-) (limited to 'engines') diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index de0dc2688a..530ff11458 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -28,6 +28,7 @@ #include "cge2/hero.h" #include "cge2/text.h" #include "cge2/cge2_main.h" +#include "cge2/map.h" namespace CGE2 { @@ -437,8 +438,23 @@ int Hero::mapCross(const V3D &a, const V3D &b) { } int CGE2Engine::mapCross(const V2D &a, const V2D &b) { - warning("STUB: CGE2Engine::mapCross()"); - return 0; + int cnt = 0; + V2D *n0 = nullptr; + V2D *p = nullptr; + for (int i = 0; i < _map->size(); i++) { + V2D *n = _map->getCoord(i); + if (p) { + if (cross(a, b, *n0, *n)) + ++cnt; + + if (n == p) + p = nullptr; + } else { + p = n; + } + n0 = n; + } + return cnt; } void Hero::setCave(int c) { diff --git a/engines/cge2/map.cpp b/engines/cge2/map.cpp index 6dbf57f08d..8a9a5db4e2 100644 --- a/engines/cge2/map.cpp +++ b/engines/cge2/map.cpp @@ -86,8 +86,8 @@ int Map::size() { return _container.size(); } -V2D &Map::operator[](int idx) { - return _container[idx]; +V2D *Map::getCoord(int idx) { + return &_container[idx]; } } // End of namespace CGE2 diff --git a/engines/cge2/map.h b/engines/cge2/map.h index 10448f0fd5..206479b929 100644 --- a/engines/cge2/map.h +++ b/engines/cge2/map.h @@ -47,7 +47,7 @@ public: void clear(); void load(int scene); int size(); - V2D &operator[](int idx); + V2D *getCoord(int idx); }; } // End of namespace CGE2 -- cgit v1.2.3