add support to SDLBackend for rendering 24bit data
[openc2e.git] / caosVM_map.cpp
blobc06d0be6605993cfde7a3457aae28989738ab8ba
1 /*
2 * caosVM_map.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 "caosVM.h"
21 #include "World.h"
22 #include "MetaRoom.h"
23 #include "Room.h"
24 #include <assert.h>
25 #include <iostream>
26 #include <boost/format.hpp>
27 using std::cerr;
29 #define CAOS_LVALUE_TARG_ROOM(name, check, get, set) \
30 CAOS_LVALUE_TARG(name, \
31 shared_ptr<Room> r = roomContainingAgent(targ); \
32 caos_assert(r); \
33 check, \
34 get, \
35 set)
37 #define CAOS_LVALUE_ROOM_SIMPLE(name, expr) \
38 CAOS_LVALUE_TARG_ROOM(name, (void)0, expr, expr = newvalue)
40 /**
41 ADDM (integer) x (integer) y (integer) width (integer) height (integer) background (string)
42 %status maybe
44 Creates a metaroom with the given height and width, at the coordinates given. Returns the id of the new metaroom.
46 void caosVM::v_ADDM() {
47 VM_VERIFY_SIZE(5)
48 VM_PARAM_STRING(background)
49 VM_PARAM_INTEGER(height)
50 VM_PARAM_INTEGER(width)
51 VM_PARAM_INTEGER(y)
52 VM_PARAM_INTEGER(x)
54 MetaRoom *r = new MetaRoom(x, y, width, height, background);
55 caosVar v;
56 v.setInt(world.map.addMetaRoom(r));
57 result = v;
60 /**
61 ADDB (command) metaroom_id (integer) background (string)
62 %status maybe
64 Adds a new background to an existing metaroom, to be displayed with BKGD.
66 void caosVM::c_ADDB() {
67 VM_PARAM_STRING(background)
68 VM_PARAM_INTEGER(metaroomid)
70 MetaRoom *m = world.map.getMetaRoom(metaroomid);
71 caos_assert(m);
73 m->addBackground(background);
76 /**
77 BRMI (command) metaroom_base (integer) room_base (integer)
78 %status maybe
80 Sets the base ID numbers for new metarooms and rooms to the given values.
82 void caosVM::c_BRMI() {
83 VM_VERIFY_SIZE(2)
85 VM_PARAM_INTEGER(room_base)
86 VM_PARAM_INTEGER(metaroom_base)
88 world.map.room_base = room_base;
89 world.map.metaroom_base = metaroom_base;
92 /**
93 MAPD (command) width (integer) height (integer)
94 %status maybe
96 Sets the world map dimensions, inside which metarooms are placed.
98 void caosVM::c_MAPD() {
99 VM_VERIFY_SIZE(2)
100 VM_PARAM_INTEGER(height)
101 VM_PARAM_INTEGER(width)
103 world.map.SetMapDimensions(width, height);
107 MAPW (integer)
108 %status maybe
110 Returns the width of the world map.
112 void caosVM::v_MAPW() {
113 result.setInt(world.map.getWidth());
117 MAPH (integer)
118 %status maybe
120 Returns the height of the world map.
122 void caosVM::v_MAPH() {
123 result.setInt(world.map.getHeight());
127 MAPK (command)
128 %status maybe
130 Resets and empties the world map.
132 void caosVM::c_MAPK() {
133 VM_VERIFY_SIZE(0)
135 world.map.Reset();
139 BKDS (string) metaroomid (integer)
140 %status maybe
142 Determines all of the background names in use by the given metaroom, and returns them in a comma-seperated string.
144 void caosVM::v_BKDS() {
145 VM_PARAM_INTEGER(metaroomid)
147 MetaRoom *m = world.map.getMetaRoom(metaroomid);
148 caos_assert(m);
150 std::vector<std::string> backs = m->backgroundList();
151 std::string s;
152 for (std::vector<std::string>::iterator i = backs.begin(); i != backs.end(); i++) {
153 if (s.empty())
154 s = *i;
155 else
156 s = s + "," + *i;
159 result.setString(s);
163 ADDR (integer) metaroomid (integer) x_left (integer) x_right (integer) y_left_ceiling (integer) y_right_ceiling (integer) y_left_floor (integer) y_right_floor (integer)
164 %status maybe
166 Makes a new room inside the given metaroom. Rooms can have sloped floors and ceilings, but only vertical walls.
167 The id of the new room is returned.
169 void caosVM::v_ADDR() {
170 VM_VERIFY_SIZE(7)
171 VM_PARAM_INTEGER(y_right_floor)
172 VM_PARAM_INTEGER(y_left_floor)
173 VM_PARAM_INTEGER(y_right_ceiling)
174 VM_PARAM_INTEGER(y_left_ceiling)
175 VM_PARAM_INTEGER(x_right)
176 VM_PARAM_INTEGER(x_left)
177 VM_PARAM_INTEGER(metaroomid)
179 shared_ptr<Room> r(new Room(x_left, x_right,
180 y_left_ceiling, y_right_ceiling,
181 y_left_floor, y_right_floor));
182 MetaRoom *m = world.map.getMetaRoom(metaroomid);
183 caos_assert(m);
184 r->metaroom = m;
185 r->id = m->addRoom(r);
186 result.setInt(r->id);
190 RTYP (command) roomid (integer) roomtype (integer)
191 %status maybe
193 Defines the 'type' of the given room. The types vary with different games.
195 void caosVM::c_RTYP() {
196 VM_VERIFY_SIZE(2)
197 VM_PARAM_INTEGER(roomtype)
198 VM_PARAM_INTEGER(roomid)
200 shared_ptr<Room> room = world.map.getRoom(roomid);
201 caos_assert(room);
202 room->type = roomtype;
206 RTYP (integer) roomid (integer)
207 %status maybe
209 Returns the 'type' of the given room, or -1 if 'roomid' is invalid.
211 void caosVM::v_RTYP() {
212 VM_VERIFY_SIZE(1)
213 VM_PARAM_INTEGER(roomid)
215 shared_ptr<Room> room = world.map.getRoom(roomid);
216 if (room)
217 result.setInt(room->type.getInt());
218 else
219 result.setInt(-1);
223 RTYP (integer)
224 %status maybe
225 %pragma variants c2
226 %pragma implementation caosVM::v_RTYP_c2
228 Returns the room type of the room at the centre point of targ.
230 void caosVM::v_RTYP_c2() {
231 valid_agent(targ);
232 shared_ptr<Room> r = world.map.roomAt(targ->x + (targ->getWidth() / 2.0f), targ->y + (targ->getHeight() / 2.0f));
233 if (!r) result.setInt(-1);
234 else {
235 result.setInt(r->type.getInt());
240 SETV RTYP (command) roomtype (integer)
241 %status maybe
242 %pragma variants c2
244 Sets the type of the given room to roomtype.
246 void caosVM::c_SETV_RTYP() {
247 VM_VERIFY_SIZE(1);
248 VM_PARAM_INTEGER(roomtype);
250 // TODO: this does actually work on targ, right?
251 // seems to work for the airlock, anyway -nornagon
252 valid_agent(targ);
253 shared_ptr<Room> r = world.map.roomAt(targ->x + (targ->getWidth() / 2.0f), targ->y + (targ->getHeight() / 2.0f));
254 if (!r) return; // TODO: correct behaviour?
255 else
256 r->type.setInt(roomtype);
260 DOOR (command) room1 (integer) room2 (integer) perm (integer)
261 %status maybe
263 Sets how permeable the door between the two given rooms will be. (See PERM).
265 void caosVM::c_DOOR() {
266 VM_VERIFY_SIZE(3)
267 VM_PARAM_INTEGER(perm)
268 VM_PARAM_INTEGER(room2)
269 VM_PARAM_INTEGER(room1)
271 shared_ptr<Room> r1 = world.map.getRoom(room1);
272 shared_ptr<Room> r2 = world.map.getRoom(room2);
273 caos_assert(r1); caos_assert(r2);
274 if (r1->doors.find(r2) == r1->doors.end()) {
275 RoomDoor *door = new RoomDoor;
276 door->first = r1;
277 door->second = r2;
278 door->perm = perm;
279 r1->doors[r2] = door;
280 r2->doors[r1] = door;
281 } else {
282 RoomDoor *door = r1->doors[r2];
283 door->perm = perm;
288 DOOR (integer) room1 (integer) room2 (integer)
289 %status stub
291 void caosVM::v_DOOR() {
292 VM_PARAM_INTEGER(room2)
293 VM_PARAM_INTEGER(room1)
295 result.setInt(-1); // TODO
299 RATE (command) roomtype (integer) caindex (integer) gain (float) loss (float) diffusion (float)
300 %status maybe
302 Defines the rates of the given CA in the given room. 'gain' defines how easily the CA will be absorbed from
303 agents inside the room, 'loss' defines how much will be lost into the air, and 'diffusion' defines how easily it
304 will spread to other rooms.
306 void caosVM::c_RATE() {
307 VM_VERIFY_SIZE(5)
308 VM_PARAM_FLOAT(diffusion)
309 VM_PARAM_FLOAT(loss)
310 VM_PARAM_FLOAT(gain)
311 VM_PARAM_INTEGER(caindex)
312 VM_PARAM_INTEGER(roomtype)
314 cainfo info;
315 info.gain = gain;
316 info.loss = loss;
317 info.diffusion = diffusion;
318 world.carates[roomtype][caindex] = info;
321 shared_ptr<Room> roomContainingAgent(AgentRef agent) {
322 MetaRoom *m = world.map.metaRoomAt(agent->x, agent->y);
323 if (!m) return shared_ptr<Room>();
324 return m->roomAt(agent->x + (agent->getWidth() / 2.0f), agent->y + (agent->getHeight() / 2.0f));
328 ROOM (integer) agent (agent)
329 %status maybe
331 Returns the room that contains the given agent (jugding by its center).
333 void caosVM::v_ROOM() {
334 VM_VERIFY_SIZE(1)
335 VM_PARAM_VALIDAGENT(agent)
337 shared_ptr<Room> r = roomContainingAgent(agent);
338 if (r)
339 result.setInt(r->id);
340 else
341 result.setInt(-1);
345 LEFT (integer)
346 %status maybe
348 Returns the left constant (0).
350 void caosVM::v_LEFT() {
351 VM_VERIFY_SIZE(0)
353 result.setInt(0);
357 RGHT (integer)
358 %status maybe
360 Returns the right constant (1).
362 void caosVM::v_RGHT() {
363 VM_VERIFY_SIZE(0)
365 result.setInt(1);
369 _UP_ (integer)
370 %status maybe
371 %pragma implementation caosVM::v_UP
373 Returns the up constant (2).
375 void caosVM::v_UP() {
376 VM_VERIFY_SIZE(0)
378 result.setInt(2);
382 DOWN (integer)
383 %status maybe
385 Returns the down constant (3).
387 void caosVM::v_DOWN() {
388 VM_VERIFY_SIZE(0)
390 result.setInt(3);
394 PROP (command) roomid (integer) caindex (integer) cavalue (float)
395 %status maybe
397 Defines the level of the given CA in the given room. Valid settings are between 0 and 1; if higher, it will be
398 reset to 1.
400 void caosVM::c_PROP() {
401 VM_VERIFY_SIZE(3)
402 VM_PARAM_FLOAT(cavalue)
403 VM_PARAM_INTEGER(caindex)
404 VM_PARAM_INTEGER(roomid)
406 if (cavalue > 1.0f)
407 cavalue = 1.0f;
408 else
409 caos_assert(0.0f <= cavalue);
410 caos_assert(0 <= caindex && caindex <= 19);
412 shared_ptr<Room> room = world.map.getRoom(roomid);
413 caos_assert(room);
414 room->ca[caindex] = cavalue;
418 PROP (float) roomid (integer) caindex (integer)
419 %status maybe
421 Returns the level of the given CA in the given room, or 0 if a roomid of -1 is passed.
423 void caosVM::v_PROP() {
424 VM_VERIFY_SIZE(2)
425 VM_PARAM_INTEGER(caindex)
426 VM_PARAM_INTEGER(roomid)
428 caos_assert(0 <= caindex && caindex <= 19);
430 if (roomid == -1) {
431 result.setFloat(0.0f);
432 return;
435 shared_ptr<Room> room = world.map.getRoom(roomid);
436 caos_assert(room);
437 result.setFloat(room->ca[caindex]);
441 PERM (command) perm (integer)
442 %status maybe
444 Sets the TARG agent's permiability. Valid settings are between 1 and 100.
446 void caosVM::c_PERM() {
447 VM_VERIFY_SIZE(1)
448 VM_PARAM_INTEGER(perm)
450 // TODO: setting of 0 valid?
451 if (perm < 0) perm = 0;
452 if (perm > 100) perm = 100;
454 valid_agent(targ);
455 targ->perm = perm;
459 PERM (integer)
460 %status maybe
462 Returns the TARG agent's permiability.
464 void caosVM::v_PERM() {
465 VM_VERIFY_SIZE(0)
467 valid_agent(targ);
468 result.setInt(targ->perm);
472 GRAP (integer) x (float) y (float)
473 %status maybe
475 Returns the id of the room at the coordinates (x, y), or -1 if nothing's there.
477 void caosVM::v_GRAP() {
478 VM_VERIFY_SIZE(2)
479 VM_PARAM_FLOAT(y)
480 VM_PARAM_FLOAT(x)
482 shared_ptr<Room> room = world.map.roomAt(x, y);
483 if (room) {
484 result.setInt(room->id);
485 } else {
486 result.setInt(-1);
491 GMAP (integer) x (float) y (float)
492 %status maybe
494 Returns the id of the metaroom at the coordinates (x, y), or -1 if nothing's there.
496 void caosVM::v_GMAP() {
497 VM_VERIFY_SIZE(2)
498 VM_PARAM_FLOAT(y)
499 VM_PARAM_FLOAT(x)
501 MetaRoom *room = world.map.metaRoomAt(x, y);
502 if (room) {
503 result.setInt(room->id);
504 } else {
505 result.setInt(-1);
510 LINK (command) room1 (integer) room2 (integer) perm (integer)
511 %status stub
513 Defines the permeability of the link between the two given rooms. This is used for CA diffusion.
515 void caosVM::c_LINK() {
516 VM_VERIFY_SIZE(3)
517 VM_PARAM_INTEGER(perm)
518 VM_PARAM_INTEGER(room2)
519 VM_PARAM_INTEGER(room1)
521 shared_ptr<Room> one = world.map.getRoom(room1);
522 shared_ptr<Room> two = world.map.getRoom(room2);
523 caos_assert(one && two);
525 // TODO
529 LINK (integer) room1 (integer) room2 (integer)
530 %status stub
532 Returns the permeability of the link between the given two rooms, or 0 if no link exists.
534 void caosVM::v_LINK() {
535 VM_PARAM_INTEGER(room2)
536 VM_PARAM_INTEGER(room1)
538 shared_ptr<Room> one = world.map.getRoom(room1);
539 shared_ptr<Room> two = world.map.getRoom(room2);
540 caos_assert(one && two);
542 result.setInt(0); // TODO
546 GRID (integer) agent (agent) direction (integer)
547 %status maybe
549 Returns the nearest adjacent room to the specified agent in the given direction (one of the direction constants), or
550 -1 otherwise.
552 void caosVM::v_GRID() {
553 VM_VERIFY_SIZE(2)
554 VM_PARAM_INTEGER(direction) caos_assert(direction >= 0); caos_assert(direction <= 3);
555 VM_PARAM_VALIDAGENT(agent)
557 valid_agent(targ);
558 Point src = targ->boundingBoxPoint(direction);
559 Point dest = src;
561 switch (direction) {
562 case 0: // left
563 dest.x -= targ->range.getFloat(); break;
564 case 1: // right
565 dest.x += targ->range.getFloat(); break;
566 case 2: // top
567 dest.y -= targ->range.getFloat(); break;
568 case 3: // bottom
569 dest.y += targ->range.getFloat(); break;
572 shared_ptr<Room> ourRoom = world.map.roomAt(src.x, src.y);
573 if (!ourRoom) {
574 // (should we REALLY check for it being in the room system, here?)
575 cerr << agent->identify() << " tried using GRID but isn't in the room system!\n";
576 result.setInt(-1);
577 return;
580 unsigned int dummy1; Line dummy2; Point point; shared_ptr<Room> room;
581 bool collided = world.map.collideLineWithRoomBoundaries(src, dest, ourRoom, room, point, dummy2, dummy1, targ->perm);
583 if (!room) result.setInt(-1);
584 else result.setInt(room->id);
588 EMIT (command) caindex (integer) amount (float)
589 %status maybe
591 Makes the TARG agent continually emit the specified amount of the specified CA into the room.
593 void caosVM::c_EMIT() {
594 VM_VERIFY_SIZE(2)
595 VM_PARAM_FLOAT(amount)
596 VM_PARAM_INTEGER(caindex)
598 caos_assert((0 <= caindex && caindex <= 19) || caindex == -1);
599 valid_agent(targ);
601 targ->emitca_index = caindex;
602 targ->emitca_amount = amount;
606 WALL (integer)
607 %status maybe
608 %pragma variants c2 cv c3
610 Returns the direction of the last wall the TARG agent collided with.
612 void caosVM::v_WALL() {
613 VM_VERIFY_SIZE(0)
615 valid_agent(targ);
616 result.setInt(targ->lastcollidedirection);
620 ALTR (command) roomid (integer) caindex (integer) delta (float)
621 %status maybe
623 Modifies the level of the given CA in the room specified.
624 If 'roomid' is -1, the room containing the TARG agent will be used.
626 void caosVM::c_ALTR() {
627 VM_VERIFY_SIZE(3)
628 VM_PARAM_FLOAT(delta);
629 VM_PARAM_INTEGER(caindex);
630 VM_PARAM_INTEGER(roomid);
632 caos_assert(0 <= caindex && caindex <= 19);
634 shared_ptr<Room> room;
635 if (roomid == -1) {
636 valid_agent(targ);
637 room = world.map.roomAt(targ->x + (targ->getWidth() / 2.0f), targ->y + (targ->getHeight() / 2.0f));
638 } else
639 room = world.map.getRoom(roomid);
640 caos_assert(room);
641 float newvalue = room->ca[caindex] + delta;
642 if (newvalue < 0.0f) newvalue = 0.0f;
643 else if (newvalue > 1.0f) newvalue = 1.0f;
644 room->ca[caindex] = newvalue;
648 RLOC (string) roomid (integer)
649 %status maybe
651 Returns a string containing the location of the given room in the following format: x_left, x_right, y_left_ceiling,
652 y_right_ceiling, y_left_floor, y_right_floor.
654 void caosVM::v_RLOC() {
655 VM_PARAM_INTEGER(roomid)
657 shared_ptr<Room> r = world.map.getRoom(roomid);
658 caos_assert(r);
660 result.setString(boost::str(boost::format("%d %d %d %d %d %d") % r->x_left % r->x_right % r->y_left_ceiling % r->y_right_ceiling % r->y_left_floor % r->y_right_floor));
664 MLOC (string) metaroomid (integer)
665 %status maybe
667 Returns a string containing the location of the given metaroom in the following format: x y width height
669 void caosVM::v_MLOC() {
670 VM_PARAM_INTEGER(metaroomid)
672 MetaRoom *r = world.map.getMetaRoom(metaroomid);
673 caos_assert(r);
675 result.setString(boost::str(boost::format("%d %d %d %d") % r->x() % r->y() % r->width() % r->height()));
679 DMAP (command) mapon (integer)
680 %status maybe
682 Turns the debug map on and off, which shows the edges of rooms and vehicles.
684 void caosVM::c_DMAP() {
685 VM_PARAM_INTEGER(mapon)
687 world.showrooms = mapon;
691 SYS: DMAP (command) mapon (integer)
692 %status maybe
693 %pragma variants c2
695 void caosVM::c_SYS_DMAP() {
696 c_DMAP();
700 ERID (string) metaroom_id (integer)
701 %status maybe
703 Returns a space-seperated list of all room id's contained by the given metaroom.
705 void caosVM::v_ERID() {
706 VM_PARAM_INTEGER(metaroom_id)
708 std::string out;
710 if (metaroom_id == -1) {
711 // TODO
712 } else {
713 MetaRoom *r = world.map.getMetaRoom(metaroom_id);
714 for (std::vector<shared_ptr<Room> >::iterator i = r->rooms.begin(); i != r->rooms.end(); i++) {
715 if (out.size() > 0) out = out + " ";
716 out = out + boost::str(boost::format("%d") % (*i)->id);
720 result.setString(out);
724 DELR (command) room_id (integer)
725 %status stub
726 %pragma variants c2 cv c3
728 Removes the given room from the map.
730 void caosVM::c_DELR() {
731 VM_PARAM_INTEGER(room_id)
733 shared_ptr<Room> r = world.map.getRoom(room_id);
734 caos_assert(r);
736 // TODO
740 DELM (command) metaroom_id (integer)
741 %status stub
743 Removes the given metaroom from the map.
745 void caosVM::c_DELM() {
746 VM_PARAM_INTEGER(metaroom_id)
748 MetaRoom *r = world.map.getMetaRoom(metaroom_id);
749 caos_assert(r);
751 // TODO
755 HIRP (integer) roomid (integer) caindex (integer) direction (integer)
756 %status stub
758 void caosVM::v_HIRP() {
759 VM_PARAM_INTEGER(direction)
760 VM_PARAM_INTEGER(caindex) caos_assert(0 <= caindex && caindex <= 19);
761 VM_PARAM_INTEGER(roomid)
763 shared_ptr<Room> r = world.map.getRoom(roomid);
764 caos_assert(r);
766 result.setInt(roomid); // TODO
770 LORP (integer) roomid (integer) caindex (integer) direction (integer)
771 %status stub
773 void caosVM::v_LORP() {
774 VM_PARAM_INTEGER(direction)
775 VM_PARAM_INTEGER(caindex) caos_assert(0 <= caindex && caindex <= 19);
776 VM_PARAM_INTEGER(roomid)
778 shared_ptr<Room> r = world.map.getRoom(roomid);
779 caos_assert(r);
781 result.setInt(roomid); // TODO
785 TORX (float) roomid (integer)
786 %status maybe
788 void caosVM::v_TORX() {
789 VM_PARAM_INTEGER(roomid)
791 shared_ptr<Room> r = world.map.getRoom(roomid);
792 caos_assert(r);
793 valid_agent(targ);
795 float centrex = r->x_left + ((r->x_right - r->x_left) / 2.0f);
796 result.setFloat(centrex - targ->x);
800 TORY (float) roomid (integer)
801 %status maybe
803 void caosVM::v_TORY() {
804 VM_PARAM_INTEGER(roomid)
806 shared_ptr<Room> r = world.map.getRoom(roomid);
807 caos_assert(r);
808 valid_agent(targ);
810 // TODO: calculate this however c2e does it.. or at least check this is right
811 float topy = (r->y_left_ceiling - r->y_right_ceiling) / 2.0f;
812 if (topy >= 0.0f) topy = r->y_left_ceiling + topy;
813 else topy = r->y_right_ceiling - topy;
815 float bottomy = (r->y_left_floor - r->y_right_floor) / 2.0f;
816 if (bottomy >= 0.0f) topy = r->y_left_floor + bottomy;
817 else bottomy = r->y_right_floor - bottomy;
819 float centrey = topy + ((bottomy - topy) / 2.0f);
820 result.setFloat(centrey - targ->y);
824 CACL (command) family (integer) genus (integer) species (integer) caindex (integer)
825 %status stub
827 void caosVM::c_CACL() {
828 VM_PARAM_INTEGER(caindex) caos_assert(0 <= caindex && caindex <= 19);
829 VM_PARAM_INTEGER(species) caos_assert(0 <= species && species <= 65535);
830 VM_PARAM_INTEGER(genus) caos_assert(0 <= genus && genus <= 255);
831 VM_PARAM_INTEGER(family) caos_assert(0 <= family && family <= 255);
833 // TODO
837 WIND (integer)
838 %status stub
839 %pragma variants c1
841 Always returns zero, since this command was stubbed in C1.
843 void caosVM::v_WIND() {
844 result.setInt(0);
848 TEMP (variable)
849 %status maybe
850 %pragma variants c1 c2
852 CAOS_LVALUE_ROOM_SIMPLE(TEMP, r->temp);
855 LITE (variable)
856 %status maybe
857 %pragma variants c2
859 CAOS_LVALUE_ROOM_SIMPLE(LITE, r->lite);
862 RADN (variable)
863 %status maybe
864 %pragma variants c2
866 CAOS_LVALUE_ROOM_SIMPLE(RADN, r->radn);
869 ONTR (variable)
870 %status maybe
871 %pragma variants c2
873 CAOS_LVALUE_ROOM_SIMPLE(ONTR, r->ontr);
876 INTR (variable)
877 %status maybe
878 %pragma variants c2
880 CAOS_LVALUE_ROOM_SIMPLE(INTR, r->intr);
883 PRES (variable)
884 %status maybe
885 %pragma variants c2
887 CAOS_LVALUE_ROOM_SIMPLE(PRES, r->pres);
890 HSRC (variable)
891 %status maybe
892 %pragma variants c2
894 CAOS_LVALUE_ROOM_SIMPLE(HSRC, r->hsrc);
897 LSRC (variable)
898 %status maybe
899 %pragma variants c2
901 CAOS_LVALUE_ROOM_SIMPLE(LSRC, r->lsrc);
904 RSRC (variable)
905 %status maybe
906 %pragma variants c2
908 CAOS_LVALUE_ROOM_SIMPLE(RSRC, r->rsrc);
911 PSRC (variable)
912 %status maybe
913 %pragma variants c2
915 CAOS_LVALUE_ROOM_SIMPLE(PSRC, r->psrc);
918 WNDX (integer)
919 %status maybe
920 %pragma variants c2
922 void caosVM::v_WNDX() {
923 valid_agent(targ);
924 shared_ptr<Room> r = roomContainingAgent(targ);
925 caos_assert(r);
926 result.setInt(r->windx);
930 WNDY (integer)
931 %status maybe
932 %pragma variants c2
934 void caosVM::v_WNDY() {
935 valid_agent(targ);
936 shared_ptr<Room> r = roomContainingAgent(targ);
937 caos_assert(r);
938 result.setInt(r->windy);
942 DOCA (command) times (integer)
943 %status stub
945 void caosVM::c_DOCA() {
946 VM_PARAM_INTEGER(times)
948 // TODO
952 SETV DOOR (command) direction (integer) room1 (integer) room2 (integer) value (integer)
953 %status maybe
954 %pragma variants c2
956 void caosVM::c_SETV_DOOR() {
957 VM_PARAM_INTEGER(value)
958 VM_PARAM_INTEGER(room2)
959 VM_PARAM_INTEGER(room1)
960 VM_PARAM_INTEGER(perm)
962 // TODO: what's direction for?
964 // code identical to c2e DOOR
965 shared_ptr<Room> r1 = world.map.getRoom(room1);
966 shared_ptr<Room> r2 = world.map.getRoom(room2);
967 caos_assert(r1); caos_assert(r2);
968 if (r1->doors.find(r2) == r1->doors.end()) {
969 RoomDoor *door = new RoomDoor;
970 door->first = r1;
971 door->second = r2;
972 door->perm = perm;
973 r1->doors[r2] = door;
974 r2->doors[r1] = door;
975 } else {
976 RoomDoor *door = r1->doors[r2];
977 door->perm = perm;
982 FLOR (integer)
983 %status stub
984 %pragma variants c2
986 Return y coordinate of floor below centre of target agent.
988 void caosVM::v_FLOR() {
989 valid_agent(targ);
991 result.setInt(0); // TODO
995 GNDW (integer)
996 %status stub
997 %pragma variants c1
999 Return the number of horizontal pixels per piece of ground level data.
1001 void caosVM::v_GNDW() {
1002 result.setInt(4); // TODO: is it always 4? :)
1006 GRND (integer) index (integer)
1007 %status stub
1008 %pragma variants c1
1010 Return the ground level data at the provided index. See GNDW to work out the index required.
1012 void caosVM::v_GRND() {
1013 VM_PARAM_INTEGER(index)
1015 result.setInt(0); // TODO
1019 ROOM (command) roomno (integer) left (integer) top (integer) right (integer) bottom (integer) type (integer)
1020 %status maybe
1021 %pragma variants c1
1023 Create or modify a room.
1025 void caosVM::c_ROOM() {
1026 VM_PARAM_INTEGER(type)
1027 VM_PARAM_INTEGER(bottom)
1028 VM_PARAM_INTEGER(right)
1029 VM_PARAM_INTEGER(top)
1030 VM_PARAM_INTEGER(left)
1031 VM_PARAM_INTEGER(roomno)
1033 shared_ptr<Room> r = world.map.getRoom(roomno);
1034 if (!r) {
1035 shared_ptr<Room> r2(new Room(left, right, top, top, bottom, bottom));
1036 r = r2;
1038 MetaRoom *m = world.map.getMetaRoom(0);
1039 unsigned int roomid = m->addRoom(r);
1040 assert(roomid == (unsigned int)roomno); // TODO: this is fairly likely to fail, but is a major bug if it does, FIX ME!
1041 } else {
1042 r->x_left = left;
1043 r->x_right = right;
1044 r->y_left_ceiling = r->y_right_ceiling = top;
1045 r->y_left_floor = r->y_right_floor = bottom;
1048 r->type.setInt(type);
1052 ROOM (integer) roomno (integer) data (integer)
1053 %status maybe
1054 %pragma variants c1
1055 %pragma implementation caosVM::v_ROOM_c1
1057 Return some data for the specified room number. Data of 0 is left, 1 is right, 2 is top, 3 is bottom, 4 is room type. Returns 0 if no such room.
1059 void caosVM::v_ROOM_c1() {
1060 VM_PARAM_INTEGER(data) caos_assert(data >= 0 && data <= 4);
1061 VM_PARAM_INTEGER(roomno)
1063 shared_ptr<Room> r = world.map.getRoom(data);
1064 if (!r) {
1065 result.setInt(0);
1066 return;
1069 switch (data) {
1070 case 0:
1071 result.setInt(r->x_left);
1072 break;
1074 case 1:
1075 result.setInt(r->x_right);
1076 break;
1078 case 2:
1079 result.setInt(r->y_left_ceiling);
1080 break;
1082 case 3:
1083 result.setInt(r->y_left_floor);
1084 break;
1086 case 4:
1087 result.setInt(r->type.getInt());
1088 break;
1092 /* vim: set noet: */