From e5984a8f49ba91440d47f65a49382a915bc8df13 Mon Sep 17 00:00:00 2001 From: fuzzie Date: Wed, 23 Apr 2008 17:34:25 +0000 Subject: [PATCH] fix agentOnCamera to cope with the wrap git-svn-id: svn://openc2e.ccdevnet.org/openc2e/trunk@1813 5a3b5b51-85f2-0310-b56e-886e3cf1dda3 --- caosVM_camera.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/caosVM_camera.cpp b/caosVM_camera.cpp index f1cb99e..c59e1e8 100644 --- a/caosVM_camera.cpp +++ b/caosVM_camera.cpp @@ -30,11 +30,22 @@ Camera *caosVM::getCamera() { } bool agentOnCamera(Agent *targ, bool checkall) { - // TODO: check non-main cameras + MetaRoom *m = world.map.metaRoomAt(targ->x, targ->y); + if (!m || m != world.camera.getMetaRoom()) return false; + + // TODO: check non-main cameras? // TODO: do compound parts stick out of the agent? - if ((targ->x > (world.camera.getX() + world.camera.getWidth())) || ((targ->x + targ->getWidth()) < world.camera.getX()) || - (targ->y > (world.camera.getY() + world.camera.getHeight())) || ((targ->y + targ->getHeight()) < world.camera.getY())) { + // y coordinates don't wrap + if (targ->y + targ->getHeight() < world.camera.getY()) return false; + if (targ->y > world.camera.getX() + world.camera.getHeight()) return false; + + // if an agent is off-camera to the right, it's not visible + if (targ->x > world.camera.getX() + world.camera.getHeight()) return false; + + if (targ->x + targ->getHeight() < world.camera.getX()) { + // if an agent is off-camera to the left, it might be wrapping + if (!m->wraparound() || (targ->x + targ->getHeight() + m->width() < world.camera.getX())) return false; } -- 2.11.4.GIT