From e9e28775fcc02280f0ac3c9a22ab8778dc43eca4 Mon Sep 17 00:00:00 2001 From: fuzzie Date: Mon, 21 Apr 2008 21:15:09 +0000 Subject: [PATCH] Lift/CallButton: add some horrible newbutton hack for call button ordering, to avoid fuzzie having to rewrite the code git-svn-id: svn://openc2e.ccdevnet.org/openc2e/trunk@1793 5a3b5b51-85f2-0310-b56e-886e3cf1dda3 --- CallButton.cpp | 19 ++++++++++++------- Lift.cpp | 17 ++++++++++++----- Lift.h | 1 + SFCFile.cpp | 2 +- 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/CallButton.cpp b/CallButton.cpp index 0584f55..e7ab355 100644 --- a/CallButton.cpp +++ b/CallButton.cpp @@ -33,15 +33,20 @@ void CallButton::tick() { if (ourlift->currentbutton == buttonid && ourlift->liftBottom() == ourlift->callbuttony[buttonid]) { // has arrived at us queueScript(0); // deactivate ourselves } - // TODO: this is a broken hack + if (ourlift->liftAvailable()) { // not moving if (ourlift->currentbutton != buttonid) { - ourlift->currentbutton = buttonid; - // TODO: mmh - if (ourlift->liftBottom() < ourlift->callbuttony[buttonid]) - ourlift->queueScript(1, this); - else - ourlift->queueScript(2, this); + /* + * all active call buttons need to fight it out to work out who gets to be + * 'newbutton' on the lift (which should be the closest button) + */ + int buttondist = abs(ourlift->currentbutton - buttonid); + int currbuttondist = abs(ourlift->currentbutton - ourlift->newbutton); + + // if there's no change to newbutton yet, or if we're 'nearer' than the last newbutton.. + if (currbuttondist == 0 || currbuttondist > buttondist) + // .. then set newbutton to point to us instead + ourlift->newbutton = buttonid; } } } diff --git a/Lift.cpp b/Lift.cpp index 8805dc1..93d23c9 100644 --- a/Lift.cpp +++ b/Lift.cpp @@ -59,21 +59,28 @@ void Lift::tick() { // if we're moving.. if (yvec.getInt() != 0) { - // TODO: we should align to agent bottom rather than cabin bottom if LACB is set to 0 (c2) - // are we beyond the call button y point? if ( - (yvec.getInt() < 0 && y + cabinbottom <= callbuttony[currentbutton]) || // upwards - (yvec.getInt() > 0 && y + cabinbottom >= callbuttony[currentbutton]) // downwards + (yvec.getInt() < 0 && liftBottom() <= callbuttony[currentbutton]) || // upwards + (yvec.getInt() > 0 && liftBottom() >= callbuttony[currentbutton]) // downwards ) { // stop movement (and make sure we're in the right spot) yvec.setInt(0); - y = callbuttony[currentbutton] - cabinbottom; + y = callbuttony[currentbutton] - (alignwithcabin ? cabinbottom : getHeight()); // send deactivate event queueScript(0); } } + + if (liftAvailable() && newbutton != currentbutton) { + currentbutton = newbutton; + + if (liftBottom() < callbuttony[currentbutton]) + queueScript(1, this); + else + queueScript(2, this); + } } float Lift::liftBottom() { diff --git a/Lift.h b/Lift.h index 2c094b3..15e7e7e 100644 --- a/Lift.h +++ b/Lift.h @@ -26,6 +26,7 @@ class Lift : public Vehicle { public: bool alignwithcabin; unsigned int currentbutton; + unsigned int newbutton; std::vector callbuttony; Lift(unsigned char family, unsigned char genus, unsigned short species, unsigned int plane, diff --git a/SFCFile.cpp b/SFCFile.cpp index ded0c7a..450156b 100644 --- a/SFCFile.cpp +++ b/SFCFile.cpp @@ -1090,7 +1090,7 @@ void SFCLift::copyToWorld() { SFCVehicle::copyToWorld(); // set current button - a->currentbutton = currentbutton; + a->currentbutton = a->newbutton = currentbutton; // set call button y locations for (unsigned int i = 0; i < nobuttons; i++) { -- 2.11.4.GIT