add wraparound support to C2 physics
[openc2e.git] / Lift.cpp
blob7fd4aeabe96cd03d506debf953fb1e39606d03e8
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"
21 #include "Engine.h" // version
23 Lift::Lift(std::string spritefile, unsigned int firstimage, unsigned int imagecount)
24 : Vehicle(spritefile, firstimage, imagecount) {
25 if (engine.version == 1) {
26 alignwithcabin = true;
27 } else {
28 alignwithcabin = false;
33 * TODO: this code is a first attempt and might be completely wrong
36 #include "World.h"
37 bool Lift::fireScript(unsigned short event, Agent *from, caosVar one, caosVar two) {
38 if (event == 1 || event == 2) {
39 if (!liftAvailable()) return false; // TODO: hack to make sure the lifts aren't activated when not ready
42 // if we need to select a new callbutton.. TODO: this is hacky
43 if (from == (Agent *)world.hand()) {
44 if (event == 1) {
45 if (currentbutton + 1 == callbuttony.size()) return false;
46 currentbutton++; newbutton = currentbutton;
47 } else if (event == 2) {
48 if (currentbutton == 0) return false;
49 currentbutton--; newbutton = currentbutton;
53 return Agent::fireScript(event, from, one, two);
56 void Lift::tick() {
57 Vehicle::tick();
58 if (paused) return;
60 // if we're moving..
61 if (yvec.getInt() != 0) {
62 // are we beyond the call button y point?
63 if (
64 (yvec.getInt() < 0 && liftBottom() <= callbuttony[currentbutton]) || // upwards
65 (yvec.getInt() > 0 && liftBottom() >= callbuttony[currentbutton]) // downwards
66 ) {
67 // stop movement (and make sure we're in the right spot)
68 yvec.setInt(0);
69 y = callbuttony[currentbutton] - (alignwithcabin ? cabinbottom : getHeight());
71 // send deactivate event
72 queueScript(0);
76 if (liftAvailable() && newbutton != currentbutton) {
77 currentbutton = newbutton;
79 if (liftBottom() < callbuttony[currentbutton])
80 queueScript(1, this);
81 else
82 queueScript(2, this);
86 float Lift::liftBottom() {
87 if (alignwithcabin)
88 return y + cabinbottom;
89 else
90 return y + getHeight();
93 /* vim: set noet: */