* move imageManager code into new imageManager.h/imageManager.cpp
[openc2e.git] / caosVM_vehicles.cpp
blob95d3827fe7886f1beaacda2a85c058c8b2595cab
1 /*
2 * caosVM_vehicles.cpp
3 * openc2e
5 * Created by Alyssa Milburn on 02/02/2005.
6 * Copyright 2005 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 "caosVM.h"
21 #include <iostream>
22 #include "openc2e.h"
23 #include "Vehicle.h"
24 #include "World.h"
25 #include "AgentHelpers.h" // agentsTouching
27 /**
28 CABN (command) left (integer) top (integer) right (integer) bottom (integer)
29 %status maybe
30 %pragma variants c1 c2 cv c3
32 void caosVM::c_CABN() {
33 VM_VERIFY_SIZE(4)
34 VM_PARAM_INTEGER(bottom)
35 VM_PARAM_INTEGER(right)
36 VM_PARAM_INTEGER(top)
37 VM_PARAM_INTEGER(left)
39 valid_agent(targ);
40 Vehicle *v = dynamic_cast<Vehicle *>(targ.get());
41 caos_assert(v);
42 v->setCabinRect(left, top, right, bottom);
45 /**
46 CABW (command) cap (integer)
47 %status maybe
49 void caosVM::c_CABW() {
50 VM_VERIFY_SIZE(1)
51 VM_PARAM_INTEGER(cap)
53 valid_agent(targ);
54 Vehicle *v = dynamic_cast<Vehicle *>(targ.get());
55 caos_assert(v);
56 v->setCapacity(cap);
59 /**
60 SPAS (command) vehicle (agent) passenger (agent)
61 %status stub
62 %pragma variants c1 c2 cv c3
64 make specified vehicle agent pick up specified passenger
66 void caosVM::c_SPAS() {
67 VM_VERIFY_SIZE(2)
68 VM_PARAM_AGENT(passenger)
69 VM_PARAM_AGENT(vehicle)
71 valid_agent(vehicle);
72 valid_agent(passenger);
74 // TODO: ensure passenger is a creature for c1/c2?
76 Vehicle *v = dynamic_cast<Vehicle *>(vehicle.get());
77 caos_assert(v);
78 v->addCarried(passenger);
81 /**
82 GPAS (command) family (integer) genus (integer) species (integer) options (integer)
83 %status stub
85 pick up all nearby agents matching classifier, as passengers to target vehicle
86 options = 0 to pick up based on agent bounding rect, or 1 to pick up based on cabin rect
88 void caosVM::c_GPAS() {
89 VM_VERIFY_SIZE(4)
90 VM_PARAM_INTEGER(options)
91 // TODO: assert ranges for these
92 VM_PARAM_INTEGER(species)
93 VM_PARAM_INTEGER(genus)
94 VM_PARAM_INTEGER(family)
96 valid_agent(targ);
97 Vehicle *v = dynamic_cast<Vehicle *>(targ.get());
98 caos_assert(v);
100 // TODO: see other GPAS below
101 // TODO: are we sure c2e grabs passengers by agent rect?
102 // TODO: do we need to check greedycabin attr for anything?
103 for (std::list<boost::shared_ptr<Agent> >::iterator i = world.agents.begin(); i != world.agents.end(); i++) {
104 boost::shared_ptr<Agent> a = (*i);
105 if (!a) continue;
106 if (a.get() == v) continue;
107 if (family && family != a->family) continue;
108 if (genus && genus != a->genus) continue;
109 if (species && species != a->species) continue;
111 if (agentsTouching(a.get(), v)) {
112 v->addCarried(a);
118 GPAS (command)
119 %status stub
120 %pragma variants c1 c2
121 %pragma implementation caosVM::c_GPAS_c2
123 void caosVM::c_GPAS_c2() {
124 valid_agent(targ);
125 Vehicle *v = dynamic_cast<Vehicle *>(targ.get());
126 caos_assert(v);
128 // TODO: are we sure c1/c2 grab passengers by agent rect?
129 // TODO: do we need to check greedycabin attr for anything?
130 for (std::list<boost::shared_ptr<Agent> >::iterator i = world.agents.begin(); i != world.agents.end(); i++) {
131 boost::shared_ptr<Agent> a = (*i);
132 if (!a) continue;
133 if (a.get() == v) continue;
134 if (a->family != 4) continue; // only pickup creatures (TODO: good check?)
136 if (agentsTouching(a.get(), v)) {
137 v->addCarried(a);
143 DPAS (command) family (integer) genus (integer) species (integer)
144 %status stub
146 drop all agents matching classifier from target vehicle
148 void caosVM::c_DPAS() {
149 VM_VERIFY_SIZE(3)
150 // TODO: assert ranges for these
151 VM_PARAM_INTEGER(species)
152 VM_PARAM_INTEGER(genus)
153 VM_PARAM_INTEGER(family)
155 valid_agent(targ);
156 Vehicle *v = dynamic_cast<Vehicle *>(targ.get());
157 caos_assert(v);
159 for (unsigned int i = 0; i < v->passengers.size(); i++) {
160 AgentRef a = v->passengers[i];
161 if (!a) continue;
162 if (a.get() == v) continue;
163 if (family && family != a->family) continue;
164 if (genus && genus != a->genus) continue;
165 if (species && species != a->species) continue;
166 v->drop(a);
167 i--; // since we dropped the last one out of the list
172 DPAS (command)
173 %status stub
174 %pragma variants c1 c2
175 %pragma implementation caosVM::c_DPAS_c2
177 void caosVM::c_DPAS_c2() {
178 valid_agent(targ);
179 Vehicle *v = dynamic_cast<Vehicle *>(targ.get());
180 caos_assert(v);
182 for (unsigned int i = 0; i < v->passengers.size(); i++) {
183 AgentRef a = v->passengers[i];
184 if (!a) continue;
185 if (a.get() == v) continue;
186 if (a->family != 4) continue; // only drop creatures (TODO: good check?)
187 v->drop(a);
188 i--; // since we dropped the last one out of the list
193 CABP (command) plane (integer)
194 %status stub
196 void caosVM::c_CABP() {
197 VM_PARAM_INTEGER(plane)
199 valid_agent(targ);
200 Vehicle *v = dynamic_cast<Vehicle *>(targ.get());
201 caos_assert(v);
203 v->cabinplane = plane;
207 CABV (command) room_id (integer)
208 %status stub
210 void caosVM::c_CABV() {
211 VM_PARAM_INTEGER(room_id)
213 valid_agent(targ);
214 Vehicle *v = dynamic_cast<Vehicle *>(targ.get());
215 caos_assert(v);
217 // TODO
221 CABV (integer)
222 %status stub
224 void caosVM::v_CABV() {
225 valid_agent(targ);
226 Vehicle *v = dynamic_cast<Vehicle *>(targ.get());
227 caos_assert(v);
229 result.setInt(-1); // TODO
233 RPAS (command) vehicle (agent) passenger (agent)
234 %status stub
236 void caosVM::c_RPAS() {
237 VM_PARAM_AGENT(passenger)
238 VM_PARAM_AGENT(vehicle)
240 // TODO
244 XVEC (variable)
245 %status stub
246 %pragma variants c1 c2
248 CAOS_LVALUE_TARG(XVEC,
249 Vehicle *v = dynamic_cast<Vehicle *>(targ.get()); caos_assert(v)
250 , v->xvec
251 , v->xvec = newvalue
255 YVEC (variable)
256 %status stub
257 %pragma variants c1 c2
259 CAOS_LVALUE_TARG(YVEC,
260 Vehicle *v = dynamic_cast<Vehicle *>(targ.get()); caos_assert(v)
261 , v->yvec
262 , v->yvec = newvalue
266 BUMP (integer)
267 %status stub
268 %pragma variants c1 c2
270 void caosVM::v_BUMP() {
271 valid_agent(targ);
272 Vehicle *v = dynamic_cast<Vehicle *>(targ.get());
273 caos_assert(v);
275 result.setInt(v->getBump());
279 TELE (command) x (integer) y (integer)
280 %status stub
281 %pragma variants c1 c2
283 Teleport occupants of target vehicle to (x, y).
285 void caosVM::c_TELE() {
286 VM_PARAM_INTEGER(y)
287 VM_PARAM_INTEGER(x)
289 valid_agent(targ);
290 Vehicle *v = dynamic_cast<Vehicle *>(targ.get());
291 caos_assert(v);
293 // TODO
297 DPS2 (command) gravity (integer)
298 %status stub
299 %pragma variants c2
301 Drop passengers of targ vehicle, like DPAS. If gravity is zero, passengers do not get gravity activated.
303 void caosVM::c_DPS2() {
304 VM_PARAM_INTEGER(gravity)
306 valid_agent(targ);
307 Vehicle *v = dynamic_cast<Vehicle *>(targ.get());
308 caos_assert(v);
310 // TODO
313 /* vim: set noet: */