qtgui: parent the agent injector/brain viewer correctly, and fix some onSelect functi...
[openc2e.git] / Lift.cpp
blobc6d959be1d242142106f43450d8e823664b36ac6
1 /*
2 * Lift.cpp
3 * openc2e
5 * Created by Alyssa Milburn on Sat Dec 2 2006.
6 * Copyright (c) 2006 Alyssa Milburn. All rights reserved.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
20 #include "Lift.h"
23 * TODO: this code is a first attempt and might be completely wrong
26 bool Lift::fireScript(unsigned short event, Agent *from, caosVar one, caosVar two) {
27 if (event == 1 || event == 2) {
28 if (!liftAvailable()) return false; // TODO: hack to make sure the lifts aren't activated when not ready
31 // if we need to select a new callbutton.. TODO: this is hacky
32 if (y + cabinbottom == callbuttony[currentbutton]) {
33 if (event == 1) {
34 if (currentbutton + 1 == callbuttony.size()) return false;
35 currentbutton++;
36 } else if (event == 2) {
37 if (currentbutton == 0) return false;
38 currentbutton--;
42 return Agent::fireScript(event, from, one, two);
45 void Lift::tick() {
46 Vehicle::tick();
47 if (paused) return;
49 // if we're moving..
50 if (yvec.getInt() != 0) {
51 // TODO: we should align to agent bottom rather than cabin bottom if LACB is set to 0 (c2)
53 // are we beyond the call button y point?
54 if (
55 (yvec.getInt() < 0 && y + cabinbottom <= callbuttony[currentbutton]) || // upwards
56 (yvec.getInt() > 0 && y + cabinbottom >= callbuttony[currentbutton]) // downwards
57 ) {
58 // stop movement (and make sure we're in the right spot)
59 yvec.setInt(0);
60 y = callbuttony[currentbutton] - cabinbottom;
62 // send deactivate event
63 queueScript(0);
68 /* vim: set noet: */