don't include OpenALBackend.h in qtgui/qtopenc2e.cpp
[openc2e.git] / Vehicle.cpp
blob4ed40ad0c301abce0c323ef288c2d79e4a80fc80
1 /*
2 * Vehicle.cpp
3 * openc2e
5 * Created by Alyssa Milburn on Tue May 25 2004.
6 * Copyright (c) 2004 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 "Vehicle.h"
21 #include "Engine.h"
22 #include "World.h"
23 #include "MetaRoom.h"
25 Vehicle::Vehicle(unsigned int family, unsigned int genus, unsigned int species, unsigned int plane,
26 std::string spritefile, unsigned int firstimage, unsigned int imagecount) :
27 CompoundAgent(family, genus, species, plane, spritefile, firstimage, imagecount) {
28 capacity = 0;
29 bump = 0;
31 cabinleft = 0; cabintop = 0; cabinright = getWidth(); cabinbottom = getHeight();
32 cabinplane = 1; // TODO: is this sane? seems to be the default in c2e
35 Vehicle::Vehicle(std::string spritefile, unsigned int firstimage, unsigned int imagecount) : CompoundAgent(spritefile, firstimage, imagecount) {
36 capacity = 0;
37 bump = 0;
39 // TODO: set cabin bounds? we don't know width/height at this point..
40 cabinplane = 95; // TODO: arbitarily-chosen value (see also SFCFile)
43 void Vehicle::tick() {
44 CompoundAgent::tick();
45 if (paused) return;
47 // move by xvec/yvec!
48 moveTo(x + xvec.getInt() / 256.0, y + yvec.getInt() / 256.0);
51 void Vehicle::carry(AgentRef passenger) {
52 // TODO: 'return' is not a good idea here, because the callung function already does stuff
54 if (passenger->carriedby) return; // TODO: change to assert?
55 if (passenger->invehicle) return; // TODO: change to assert?
57 int cabinwidth = cabinright - cabinleft;
58 int cabinheight = cabinbottom - cabintop;
60 // reject if passenger is too big
61 if ((int)passenger->getWidth() > cabinwidth) return;
62 // TODO: you can put too-high things into cabins in c1. can you in the other games?
63 //if (passenger->getHeight() > cabinheight) return;
65 // push into our cabin
66 // TODO: should we use moveTo here?
67 if (passenger->x < (x + cabinleft)) passenger->x = x + cabinleft;
68 if (passenger->x + passenger->getWidth() > (x + cabinright)) passenger->x = x + cabinright - passenger->getWidth();
69 if (engine.version > 1) {
70 // TODO: not sure if this is good for too-high agents, if it's possible for them to exist (see comment above)
71 if (passenger->y < (y + cabintop)) passenger->y = y + cabintop;
72 if (passenger->y + passenger->getHeight() > (y + cabinbottom)) passenger->y = y + cabinbottom - passenger->getHeight();
73 } else {
74 passenger->y = y + cabinbottom - passenger->getHeight();
77 passengers.push_back(passenger);
78 passenger->invehicle = this;
80 if (engine.version >= 3)
81 passenger->queueScript(122, this); // Vehicle Drop, TODO: is this valid call?
84 void Vehicle::drop(AgentRef passenger) {
85 std::vector<AgentRef>::iterator i = std::find(passengers.begin(), passengers.end(), passenger);
86 assert(i != passengers.end());
87 assert(passenger->invehicle == AgentRef(this));
88 passengers.erase(i);
90 passenger->beDropped();
92 if (engine.version >= 3)
93 passenger->queueScript(122, this); // Vehicle Drop, TODO: is this valid call?
96 void Vehicle::adjustCarried(float xoffset, float yoffset) {
97 Agent::adjustCarried(xoffset, yoffset);
99 for (std::vector<AgentRef>::iterator i = passengers.begin(); i != passengers.end(); i++) {
100 if (!(*i)) continue; // TODO: muh
101 (*i)->moveTo((*i)->x + xoffset, (*i)->y + yoffset);
105 void Vehicle::kill() {
106 // TODO: sane?
107 while (passengers.size() > 0) {
108 if (passengers[0]) dropCarried(passengers[0]);
109 else passengers.erase(passengers.begin());
113 /* vim: set noet: */