add non-functional c1 Hatchery
[openc2e.git] / caosVM_compound.cpp
blob3d6d011011b0a2e714a6733ad4160cfdd9442441
1 /*
2 * caosVM_compound.cpp
3 * openc2e
5 * Created by Alyssa Milburn on Mon May 31 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 "CompoundAgent.h"
22 #include "CameraPart.h"
23 #include "Blackboard.h"
24 #include "openc2e.h"
25 #include "World.h"
26 #include "Engine.h"
28 /**
29 PART (command) part_id (integer)
30 %status maybe
31 %pragma variants c1 c2 cv c3 sm
33 Sets the part number of the TARGeted compound agent or vehicle to work on (ANIM/POSE use this,
34 amongst other commands).
36 void caosVM::c_PART() {
37 VM_VERIFY_SIZE(1)
38 VM_PARAM_INTEGER(part_id)
40 caos_assert((part_id >= 0) || (part_id == -1));
41 part = part_id;
44 /**
45 PART (integer) part_id (integer)
46 %status maybe
48 Returns 1 if the given part number exists on the target agent, or 0 if otherwise.
50 void caosVM::v_PART() {
51 VM_PARAM_INTEGER(part_id)
53 caos_assert(part_id >= 0); // TODO: should we do this?
54 valid_agent(targ);
55 if (targ->part(part_id))
56 result.setInt(1);
57 else
58 result.setInt(0);
61 /**
62 NEW: PART (command) part (integer) x (integer) y (integer) first_image (integer) plane (integer)
63 %status maybe
64 %pragma variants c1 c2
66 void caosVM::c_NEW_PART() {
67 VM_PARAM_INTEGER(plane)
68 VM_PARAM_INTEGER(first_image)
69 VM_PARAM_INTEGER(y)
70 VM_PARAM_INTEGER(x)
71 VM_PARAM_INTEGER(partno)
73 caos_assert(partno >= 0 && partno <= 9);
74 valid_agent(targ);
75 CompoundAgent *a = dynamic_cast<CompoundAgent *>(targ.get());
76 caos_assert(a);
78 CompoundPart *p = new DullPart(a, partno, a->getSpriteFile(), a->getFirstImage() + first_image, x, y, plane - a->zorder);
79 a->addPart(p);
81 part = partno;
84 /**
85 PAT: DULL (command) part (integer) sprite (string) first_image (integer) x (integer) y (integer) plane (integer)
86 %status maybe
87 %pragma variants cv c3
89 Adds a new 'dull' part to the TARGed compound agent/vehicle which does nothing but display an image.
90 Part ID numbers begin at 1. x/y/plane are relative to the agent you're working on.
92 void caosVM::c_PAT_DULL() {
93 VM_VERIFY_SIZE(6)
94 VM_PARAM_INTEGER(plane)
95 // TODO: should x/y be int? original docs say 'decimal'
96 VM_PARAM_INTEGER(y)
97 VM_PARAM_INTEGER(x)
98 VM_PARAM_INTEGER(first_image)
99 VM_PARAM_STRING(sprite)
100 VM_PARAM_INTEGER(part)
102 caos_assert(part >= 0);
103 valid_agent(targ);
104 CompoundAgent *a = dynamic_cast<CompoundAgent *>(targ.get());
105 caos_assert(a);
107 CompoundPart *p = new DullPart(a, part, sprite, first_image, x, y, plane);
108 a->addPart(p);
112 PAT: BUTT (command) part (integer) sprite (string) first_image (integer) image_count (integer) x (integer) y (integer) plane (integer) hoveranim (byte-string) messageid (integer) option (integer)
113 %status maybe
115 Adds a new 'button' part to the TARGed compound agent/vehicle.
116 Part ID numbers begin at 1. x/y/plane are relative to the agent you're working on.
117 'hoveranim' is the animation to use when the part is mouse-overed - see ANIM for details.
118 'messageid' is the message sent when the button is clicked - _p1_ of the message is set to the part number.
119 If option is 1, mouseclicks/hovers only apply to non-transparent areas. otherwise, option should be 0.
121 void caosVM::c_PAT_BUTT() {
122 VM_VERIFY_SIZE(10)
123 VM_PARAM_INTEGER(option)
124 VM_PARAM_INTEGER(messageid)
125 VM_PARAM_BYTESTR(hoveranim)
126 VM_PARAM_INTEGER(plane)
127 // TODO: should x/y be int? original docs say 'decimal'
128 VM_PARAM_INTEGER(y)
129 VM_PARAM_INTEGER(x)
130 VM_PARAM_INTEGER(image_count)
131 VM_PARAM_INTEGER(first_image)
132 VM_PARAM_STRING(sprite)
133 VM_PARAM_INTEGER(part)
135 caos_assert(part >= 0);
136 // caos_assert((option == 0) || (option == 1)); .. I've seen '1000' and '255' used, so, gah. TODO: make sure all non-zero values are identical
137 valid_agent(targ);
138 CompoundAgent *a = dynamic_cast<CompoundAgent *>(targ.get());
139 caos_assert(a);
141 // TODO TODO TODO we don't take image_count!!
142 CompoundPart *p = new ButtonPart(a, part, sprite, first_image, x, y, plane, hoveranim, messageid, option);
143 a->addPart(p);
147 PAT: FIXD (command) part (integer) sprite (string) first_image (integer) x (integer) y (integer) plane (integer) fontsprite (string)
148 %status maybe
150 Adds a new 'fixed' text part to the TARGed compound agent/vehicle,
151 Part ID numbers begin at 1. x/y/plane are relative to the agent you're working on.
152 The 'first_image' frame of the given sprite file will be used underneath the text, which is set with PTXT.
154 void caosVM::c_PAT_FIXD() {
155 VM_PARAM_STRING(fontsprite)
156 VM_PARAM_INTEGER(plane)
157 // TODO: should x/y be int? original docs say 'decimal'
158 VM_PARAM_INTEGER(y)
159 VM_PARAM_INTEGER(x)
160 VM_PARAM_INTEGER(first_image)
161 VM_PARAM_STRING(sprite)
162 VM_PARAM_INTEGER(part)
164 caos_assert(part >= 0);
165 valid_agent(targ);
166 CompoundAgent *a = dynamic_cast<CompoundAgent *>(targ.get());
167 caos_assert(a);
169 CompoundPart *p = new FixedTextPart(a, part, sprite, first_image, x, y, plane, fontsprite);
170 a->addPart(p);
174 PAT: TEXT (command) part (integer) sprite (string) first_image (integer) x (integer) y (integer) plane (integer) message_id (integer) fontsprite (string)
175 %status maybe
177 Adds a new text entry part to the TARGed compound agent/vehicle.
178 Part ID numbers begin at 1. x/y/plane are relative to the agent you're working on.
179 The 'first_image' frame of the given sprite file will be used underneath the text. The part will
180 gain the focus when FCUS is called or when it is clicked. A message of the given type will be sent.
182 void caosVM::c_PAT_TEXT() {
183 VM_PARAM_STRING(fontsprite)
184 VM_PARAM_INTEGER(message_id)
185 VM_PARAM_INTEGER(plane)
186 // TODO: should x/y be int? original docs say 'decimal'
187 VM_PARAM_INTEGER(y)
188 VM_PARAM_INTEGER(x)
189 VM_PARAM_INTEGER(first_image)
190 VM_PARAM_STRING(sprite)
191 VM_PARAM_INTEGER(part)
193 caos_assert(part >= 0);
194 valid_agent(targ);
195 CompoundAgent *a = dynamic_cast<CompoundAgent *>(targ.get());
196 caos_assert(a);
198 CompoundPart *p = new TextEntryPart(a, part, sprite, first_image, x, y, plane, message_id, fontsprite);
199 a->addPart(p);
203 PAT: CMRA (command) part (integer) sprite (string) first_image (integer) x (integer) y (integer) plane (integer) viewwidth (integer) viewheight (integer) camerawidth (integer) cameraheight(integer)
204 %status maybe
206 void caosVM::c_PAT_CMRA() {
207 VM_PARAM_INTEGER(cameraheight)
208 VM_PARAM_INTEGER(camerawidth)
209 VM_PARAM_INTEGER(viewheight)
210 VM_PARAM_INTEGER(viewwidth)
211 VM_PARAM_INTEGER(plane)
212 // TODO: should x/y be int? original docs say 'decimal'
213 VM_PARAM_INTEGER(y)
214 VM_PARAM_INTEGER(x)
215 VM_PARAM_INTEGER(first_image)
216 VM_PARAM_STRING(sprite)
217 VM_PARAM_INTEGER(part)
219 caos_assert(part >= 0);
220 valid_agent(targ);
221 CompoundAgent *a = dynamic_cast<CompoundAgent *>(targ.get());
222 caos_assert(a);
224 CompoundPart *p = new CameraPart(a, part, sprite, first_image, x, y, plane, viewwidth, viewheight, camerawidth, cameraheight);
225 a->addPart(p);
229 PAT: GRPH (command) part (integer) sprite (string) first_image (integer) x (integer) y (integer) plane (integer) numvalues (integer)
230 %status maybe
234 void caosVM::c_PAT_GRPH() {
235 VM_PARAM_INTEGER(numvalues)
236 VM_PARAM_INTEGER(plane)
237 // TODO: should x/y be int? original docs say 'decimal'
238 VM_PARAM_INTEGER(y)
239 VM_PARAM_INTEGER(x)
240 VM_PARAM_INTEGER(first_image)
241 VM_PARAM_STRING(sprite)
242 VM_PARAM_INTEGER(part)
244 caos_assert(part >= 0);
245 valid_agent(targ);
246 CompoundAgent *a = dynamic_cast<CompoundAgent *>(targ.get());
247 caos_assert(a);
249 CompoundPart *p = new GraphPart(a, part, sprite, first_image, x, y, plane, numvalues);
250 a->addPart(p);
254 PAT: KILL (command) part (integer)
255 %status maybe
257 Kills the specified part of the TARGed compound agent or vehicle.
259 void caosVM::c_PAT_KILL() {
260 VM_VERIFY_SIZE(1)
261 VM_PARAM_INTEGER(part)
263 caos_assert(part > 0);
264 valid_agent(targ);
265 CompoundAgent *a = dynamic_cast<CompoundAgent *>(targ.get());
266 caos_assert(a);
267 if (!a->part(part)) return; // Edynn does PAT: KILL on nonexistant parts
269 a->delPart(part);
273 PAT: MOVE (command) part (integer) x (integer) y (integer)
274 %status maybe
276 move the compound part specified to the new relative position specified
278 void caosVM::c_PAT_MOVE() {
279 // TODO: should x/y be int? original docs say 'decimal'
280 VM_PARAM_INTEGER(y)
281 VM_PARAM_INTEGER(x)
282 VM_PARAM_INTEGER(part)
284 valid_agent(targ);
285 CompoundAgent *a = dynamic_cast<CompoundAgent *>(targ.get());
286 caos_assert(a);
287 CompoundPart *p = a->part(part);
288 caos_assert(p);
290 p->x = x;
291 p->y = y;
295 FCUS (command)
296 %status maybe
298 Focus the current targeted part, which must be a PAT: TEXT.
299 If the target is null, then the current part will be unfocused.
301 void caosVM::c_FCUS() {
302 VM_VERIFY_SIZE(0)
304 if (!targ)
305 world.setFocus(0);
306 else {
307 CompoundAgent *c = dynamic_cast<CompoundAgent *>(targ.get());
308 caos_assert(c);
309 TextEntryPart *p = dynamic_cast<TextEntryPart *>(c->part(part));
310 caos_assert(p);
311 world.setFocus(p);
316 FRMT (command) left_margin (integer) top_margin (integer) right_margin (integer) button_margin (integer) line_spacing (integer) char_spacing (integer) justification (integer)
317 %status maybe
319 Alters the appearance of the target text part. The spacing values and margins are to be specified in
320 pixels. Justification can be 0 for left, 1 for right, 2 for center, 4 for bottom, 8 for middle or 16
321 for 'last page scroll' (TODO?), and you can add these together (except 0/1 are mutually exclusive, obviously).
323 void caosVM::c_FRMT() {
324 VM_PARAM_INTEGER(justification)
325 VM_PARAM_INTEGER(char_spacing)
326 VM_PARAM_INTEGER(line_spacing)
327 VM_PARAM_INTEGER(bottom_margin)
328 VM_PARAM_INTEGER(right_margin)
329 VM_PARAM_INTEGER(top_margin)
330 VM_PARAM_INTEGER(left_margin)
332 valid_agent(targ);
333 CompoundAgent *c = dynamic_cast<CompoundAgent *>(targ.get());
334 caos_assert(c);
335 TextPart *p = dynamic_cast<TextPart *>(c->part(part));
336 caos_assert(p);
338 horizontalalign h;
339 if ((justification & 3) == 1) h = rightalign;
340 else if ((justification & 3) == 2) h = centeralign;
341 else h = leftalign;
343 verticalalign v;
344 if ((justification & 12) == 4) v = bottom;
345 else if ((justification & 12) == 8) v = middle;
346 else v = top; // TODO: i haven't verified this is the correct fallback - fuzzie
348 if (char_spacing == 1) char_spacing = 0; // TODO: horrible hack to try and fix issues
350 p->setFormat(left_margin, top_margin, right_margin, bottom_margin, line_spacing, char_spacing, h, v, (justification & 16));
354 PTXT (command) text (string)
355 %status maybe
357 Sets the text displayed in the current text part.
359 void caosVM::c_PTXT() {
360 VM_PARAM_STRING(text)
362 valid_agent(targ);
363 CompoundAgent *c = dynamic_cast<CompoundAgent *>(targ.get());
364 caos_assert(c);
365 TextPart *p = dynamic_cast<TextPart *>(c->part(part));
366 caos_assert(p);
368 p->setText(text);
372 PTXT (string)
373 %status maybe
375 Returns the text displayed in the current text part.
377 void caosVM::v_PTXT() {
378 valid_agent(targ);
379 CompoundAgent *c = dynamic_cast<CompoundAgent *>(targ.get());
380 caos_assert(c);
381 TextPart *p = dynamic_cast<TextPart *>(c->part(part));
382 caos_assert(p);
384 result.setString(p->getText());
388 PNXT (integer) previous_part (integer)
389 %status maybe
391 Returns the next part of the TARG compound agent or vehicle, (or -1 if you have reached the end, or
392 the first part if you go past -1).
394 void caosVM::v_PNXT() {
395 VM_PARAM_INTEGER(previous_part)
397 valid_agent(targ);
398 CompoundAgent *c = dynamic_cast<CompoundAgent *>(targ.get());
400 if (!c) { // handle non-compound agents
401 if (previous_part == -1)
402 result.setInt(0);
403 else
404 result.setInt(-1);
405 return;
408 // TODO: this might not be the best way to do this..
409 CompoundPart *curpart = 0;
411 for (std::vector<CompoundPart *>::iterator x = c->parts.begin(); x != c->parts.end(); x++) {
412 unsigned int i = (*x)->id;
413 if ((int)i > previous_part)
414 if (!curpart || i < curpart->id)
415 curpart = *x;
418 if (curpart) result.setInt(curpart->id);
419 else result.setInt(-1);
423 PAGE (command) page (integer)
424 %status maybe
426 Sets the zero-based page number of the current text part. This must be less than NPGS.
428 void caosVM::c_PAGE() {
429 VM_PARAM_INTEGER(page)
431 valid_agent(targ);
432 CompoundAgent *c = dynamic_cast<CompoundAgent *>(targ.get());
433 caos_assert(c);
434 CompoundPart *p = c->part(part);
435 caos_assert(p);
436 FixedTextPart *t = dynamic_cast<FixedTextPart *>(p);
437 caos_assert(t);
439 t->setPage(page);
443 PAGE (integer)
444 %status maybe
446 Returns the zero-based page number of the current text part.
448 void caosVM::v_PAGE() {
449 valid_agent(targ);
450 CompoundAgent *c = dynamic_cast<CompoundAgent *>(targ.get());
451 caos_assert(c);
452 CompoundPart *p = c->part(part);
453 caos_assert(p);
454 FixedTextPart *t = dynamic_cast<FixedTextPart *>(p);
455 caos_assert(t);
457 result.setInt(t->getPage());
461 NPGS (integer)
462 %status maybe
464 Returns the number of pages for the current text part.
466 void caosVM::v_NPGS() {
467 valid_agent(targ);
468 CompoundAgent *c = dynamic_cast<CompoundAgent *>(targ.get());
469 caos_assert(c);
470 CompoundPart *p = c->part(part);
471 caos_assert(p);
472 FixedTextPart *t = dynamic_cast<FixedTextPart *>(p);
473 caos_assert(t);
475 result.setInt(t->noPages());
479 GRPV (command) line (integer) value (float)
480 %status stub
482 Add the given value to the given line on a graph.
484 void caosVM::c_GRPV() {
485 VM_PARAM_FLOAT(value)
486 VM_PARAM_INTEGER(line)
488 valid_agent(targ);
489 CompoundAgent *c = dynamic_cast<CompoundAgent *>(targ.get());
490 caos_assert(c);
491 CompoundPart *p = c->part(part);
492 caos_assert(p);
493 GraphPart *t = dynamic_cast<GraphPart *>(p);
494 caos_assert(t);
496 // TODO
500 GRPL (command) red (integer) green (integer) blue (integer) min (float) max (float)
501 %status stub
503 Add a new line to a graph created with PAT: GRPH with the given
504 characteristics.
506 void caosVM::c_GRPL() {
507 VM_PARAM_FLOAT(max)
508 VM_PARAM_FLOAT(min)
509 VM_PARAM_INTEGER(blue)
510 VM_PARAM_INTEGER(green)
511 VM_PARAM_INTEGER(red)
513 valid_agent(targ);
514 CompoundAgent *c = dynamic_cast<CompoundAgent *>(targ.get());
515 caos_assert(c);
516 CompoundPart *p = c->part(part);
517 caos_assert(p);
518 GraphPart *t = dynamic_cast<GraphPart *>(p);
519 caos_assert(t);
521 // TODO
525 BBD: WORD (command) index (integer) id (integer) text (string)
526 %status maybe
527 %pragma variants c1 c2
529 Change the word at index to target blackboard, setting to the provided id and text.
531 void caosVM::c_BBD_WORD() {
532 VM_PARAM_STRING(text)
533 VM_PARAM_INTEGER(id)
534 VM_PARAM_INTEGER(index)
536 if (engine.version == 1) {
537 caos_assert(index < 16);
538 } else {
539 caos_assert(index < 48);
542 valid_agent(targ);
543 Blackboard *b = dynamic_cast<Blackboard *>(targ.get());
544 caos_assert(b);
546 b->addBlackboardString(index, id, text);
550 BBD: SHOW (command) show (integer)
551 %status maybe
552 %pragma variants c1 c2
554 If show is 1, draw the current text onto part 0 of the target blackboard. If 0,
555 remove it from the blackboard.
557 void caosVM::c_BBD_SHOW() {
558 VM_PARAM_INTEGER(show)
560 valid_agent(targ);
561 Blackboard *b = dynamic_cast<Blackboard *>(targ.get());
562 caos_assert(b);
564 b->showText(show);
568 BBD: EMIT (command) audible (integer)
569 %status stub
570 %pragma variants c1 c2
572 Broadcast the current word of the target blackboard. If audible is 1, broadcast
573 to all nearby creatures. If 0, broadcast to all creatures looking at it.
575 void caosVM::c_BBD_EMIT() {
576 VM_PARAM_INTEGER(audible)
578 valid_agent(targ);
579 // TODO
583 BBD: EDIT (command) allow (integer)
584 %status stub
585 %pragma variants c1
587 If allow is 1, switch target blackboard into editing mode, give it focus. If it
588 is 0, remove focus from target blackboard.
590 void caosVM::c_BBD_EDIT() {
591 VM_PARAM_INTEGER(allow)
593 valid_agent(targ);
594 // TODO
598 BBD: VOCB (command) blackboardstart (integer) globalstart (integer) count (integer)
599 %status stub
600 %pragma variants c2
602 Copy count words into the blackboard word list from the global word list.
604 void caosVM::c_BBD_VOCB() {
605 VM_PARAM_INTEGER(count)
606 VM_PARAM_INTEGER(globalstart)
607 VM_PARAM_INTEGER(blackboardstart)
609 valid_agent(targ);
610 // TODO
614 NEW: BBTX (command) part (integer) x (integer) y (integer) width (integer)
615 %status stub
616 %pragma variants c2
618 Create a new C2 text part for a compound bubble object. Text will wrap as required to fit width.
620 void caosVM::c_NEW_BBTX() {
621 VM_PARAM_INTEGER(width)
622 VM_PARAM_INTEGER(y)
623 VM_PARAM_INTEGER(x)
624 VM_PARAM_INTEGER(part)
626 valid_agent(targ);
627 // TODO
631 BBTX (command) part (integer) stringindex (integer)
632 %status stub
633 %pragma variants c2
635 void caosVM::c_BBTX() {
636 VM_PARAM_INTEGER(stringindex)
637 VM_PARAM_INTEGER(part)
639 valid_agent(targ);
640 // TODO
644 SPOT (command) spotno (integer) left (integer) top (integer) right (integer) bottom (integer)
645 %status maybe
646 %pragma variants c1 c2
648 void caosVM::c_SPOT() {
649 VM_PARAM_INTEGER(bottom)
650 VM_PARAM_INTEGER(right)
651 VM_PARAM_INTEGER(top)
652 VM_PARAM_INTEGER(left)
653 VM_PARAM_INTEGER(spotno)
655 valid_agent(targ);
656 CompoundAgent *c = dynamic_cast<CompoundAgent *>(targ.get());
657 caos_assert(c);
659 c->setHotspotLoc(spotno, left, top, right, bottom);
663 KNOB (command) function (integer) spotno (integer)
664 %status maybe
665 %pragma variants c1 c2
667 void caosVM::c_KNOB() {
668 VM_PARAM_INTEGER(spotno)
669 VM_PARAM_INTEGER(function)
671 valid_agent(targ);
672 CompoundAgent *c = dynamic_cast<CompoundAgent *>(targ.get());
673 caos_assert(c);
675 c->setHotspotFunc(function, spotno);
679 KMSG (command) function (integer) flags (integer) message (integer)
680 %status maybe
681 %pragma variants c2
683 void caosVM::c_KMSG() {
684 VM_PARAM_INTEGER(message)
685 VM_PARAM_INTEGER(flags)
686 VM_PARAM_INTEGER(function)
688 valid_agent(targ);
689 CompoundAgent *c = dynamic_cast<CompoundAgent *>(targ.get());
690 caos_assert(c);
692 c->setHotspotFuncDetails(function, message, flags);
696 BBLE (command) text (string) ticks (integer) type (integer) track (integer)
697 %status stub
698 %pragma variants c2
700 Display the given text for the given number of ticks, in a bubble (type is 0 for speech or 1 for thought).
702 void caosVM::c_BBLE() {
703 VM_PARAM_INTEGER(track)
704 VM_PARAM_INTEGER(type)
705 VM_PARAM_INTEGER(ticks)
706 VM_PARAM_STRING(text)
708 // TODO
712 BBFD (command) part (integer) red (integer) green (integer) blue (integer)
713 %status stub
714 %pragma variants c2
716 void caosVM::c_BBFD() {
717 VM_PARAM_INTEGER(blue)
718 VM_PARAM_INTEGER(green)
719 VM_PARAM_INTEGER(red)
720 VM_PARAM_INTEGER(part)
722 valid_agent(targ);
723 // TODO
726 /* vim: set noet: */