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.
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;
28 alignwithcabin
= false;
33 * TODO: this code is a first attempt and might be completely wrong
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()) {
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
);
61 if (yvec
.getInt() != 0) {
62 // are we beyond the call button y point?
64 (yvec
.getInt() < 0 && liftBottom() <= callbuttony
[currentbutton
]) || // upwards
65 (yvec
.getInt() > 0 && liftBottom() >= callbuttony
[currentbutton
]) // downwards
67 // stop movement (and make sure we're in the right spot)
69 y
= callbuttony
[currentbutton
] - (alignwithcabin
? cabinbottom
: getHeight());
71 // send deactivate event
76 if (liftAvailable() && newbutton
!= currentbutton
) {
77 currentbutton
= newbutton
;
79 if (liftBottom() < callbuttony
[currentbutton
])
86 float Lift::liftBottom() {
88 return y
+ cabinbottom
;
90 return y
+ getHeight();