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.
21 #include "CompoundAgent.h"
22 #include "CameraPart.h"
23 #include "Blackboard.h"
29 PART (command) part_id (integer)
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() {
38 VM_PARAM_INTEGER(part_id
)
40 caos_assert((part_id
>= 0) || (part_id
== -1));
45 PART (integer) part_id (integer)
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?
55 if (targ
->part(part_id
))
62 NEW: PART (command) part (integer) x (integer) y (integer) first_image (integer) plane (integer)
64 %pragma variants c1 c2
66 void caosVM::c_NEW_PART() {
67 VM_PARAM_INTEGER(plane
)
68 VM_PARAM_INTEGER(first_image
)
71 VM_PARAM_INTEGER(partno
)
73 caos_assert(partno
>= 0 && partno
<= 9);
75 CompoundAgent
*a
= dynamic_cast<CompoundAgent
*>(targ
.get());
78 CompoundPart
*p
= new DullPart(a
, partno
, a
->getSpriteFile(), a
->getFirstImage() + first_image
, x
, y
, plane
- a
->zorder
);
85 PAT: DULL (command) part (integer) sprite (string) first_image (integer) x (integer) y (integer) plane (integer)
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() {
94 VM_PARAM_INTEGER(plane
)
95 // TODO: should x/y be int? original docs say 'decimal'
98 VM_PARAM_INTEGER(first_image
)
99 VM_PARAM_STRING(sprite
)
100 VM_PARAM_INTEGER(part
)
102 caos_assert(part
>= 0);
104 CompoundAgent
*a
= dynamic_cast<CompoundAgent
*>(targ
.get());
107 CompoundPart
*p
= new DullPart(a
, part
, sprite
, first_image
, x
, y
, plane
);
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)
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() {
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'
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
138 CompoundAgent
*a
= dynamic_cast<CompoundAgent
*>(targ
.get());
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
);
147 PAT: FIXD (command) part (integer) sprite (string) first_image (integer) x (integer) y (integer) plane (integer) fontsprite (string)
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'
160 VM_PARAM_INTEGER(first_image
)
161 VM_PARAM_STRING(sprite
)
162 VM_PARAM_INTEGER(part
)
164 caos_assert(part
>= 0);
166 CompoundAgent
*a
= dynamic_cast<CompoundAgent
*>(targ
.get());
169 CompoundPart
*p
= new FixedTextPart(a
, part
, sprite
, first_image
, x
, y
, plane
, fontsprite
);
174 PAT: TEXT (command) part (integer) sprite (string) first_image (integer) x (integer) y (integer) plane (integer) message_id (integer) fontsprite (string)
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'
189 VM_PARAM_INTEGER(first_image
)
190 VM_PARAM_STRING(sprite
)
191 VM_PARAM_INTEGER(part
)
193 caos_assert(part
>= 0);
195 CompoundAgent
*a
= dynamic_cast<CompoundAgent
*>(targ
.get());
198 CompoundPart
*p
= new TextEntryPart(a
, part
, sprite
, first_image
, x
, y
, plane
, message_id
, fontsprite
);
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)
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'
215 VM_PARAM_INTEGER(first_image
)
216 VM_PARAM_STRING(sprite
)
217 VM_PARAM_INTEGER(part
)
219 caos_assert(part
>= 0);
221 CompoundAgent
*a
= dynamic_cast<CompoundAgent
*>(targ
.get());
224 CompoundPart
*p
= new CameraPart(a
, part
, sprite
, first_image
, x
, y
, plane
, viewwidth
, viewheight
, camerawidth
, cameraheight
);
229 PAT: GRPH (command) part (integer) sprite (string) first_image (integer) x (integer) y (integer) plane (integer) numvalues (integer)
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'
240 VM_PARAM_INTEGER(first_image
)
241 VM_PARAM_STRING(sprite
)
242 VM_PARAM_INTEGER(part
)
244 caos_assert(part
>= 0);
246 CompoundAgent
*a
= dynamic_cast<CompoundAgent
*>(targ
.get());
249 CompoundPart
*p
= new GraphPart(a
, part
, sprite
, first_image
, x
, y
, plane
, numvalues
);
254 PAT: KILL (command) part (integer)
257 Kills the specified part of the TARGed compound agent or vehicle.
259 void caosVM::c_PAT_KILL() {
261 VM_PARAM_INTEGER(part
)
263 caos_assert(part
> 0);
265 CompoundAgent
*a
= dynamic_cast<CompoundAgent
*>(targ
.get());
267 if (!a
->part(part
)) return; // Edynn does PAT: KILL on nonexistant parts
273 PAT: MOVE (command) part (integer) x (integer) y (integer)
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'
282 VM_PARAM_INTEGER(part
)
285 CompoundAgent
*a
= dynamic_cast<CompoundAgent
*>(targ
.get());
287 CompoundPart
*p
= a
->part(part
);
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() {
307 CompoundAgent
*c
= dynamic_cast<CompoundAgent
*>(targ
.get());
309 TextEntryPart
*p
= dynamic_cast<TextEntryPart
*>(c
->part(part
));
316 FRMT (command) left_margin (integer) top_margin (integer) right_margin (integer) button_margin (integer) line_spacing (integer) char_spacing (integer) justification (integer)
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
)
333 CompoundAgent
*c
= dynamic_cast<CompoundAgent
*>(targ
.get());
335 TextPart
*p
= dynamic_cast<TextPart
*>(c
->part(part
));
339 if ((justification
& 3) == 1) h
= rightalign
;
340 else if ((justification
& 3) == 2) h
= centeralign
;
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)
357 Sets the text displayed in the current text part.
359 void caosVM::c_PTXT() {
360 VM_PARAM_STRING(text
)
363 CompoundAgent
*c
= dynamic_cast<CompoundAgent
*>(targ
.get());
365 TextPart
*p
= dynamic_cast<TextPart
*>(c
->part(part
));
375 Returns the text displayed in the current text part.
377 void caosVM::v_PTXT() {
379 CompoundAgent
*c
= dynamic_cast<CompoundAgent
*>(targ
.get());
381 TextPart
*p
= dynamic_cast<TextPart
*>(c
->part(part
));
384 result
.setString(p
->getText());
388 PNXT (integer) previous_part (integer)
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
)
398 CompoundAgent
*c
= dynamic_cast<CompoundAgent
*>(targ
.get());
400 if (!c
) { // handle non-compound agents
401 if (previous_part
== -1)
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
)
418 if (curpart
) result
.setInt(curpart
->id
);
419 else result
.setInt(-1);
423 PAGE (command) page (integer)
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
)
432 CompoundAgent
*c
= dynamic_cast<CompoundAgent
*>(targ
.get());
434 CompoundPart
*p
= c
->part(part
);
436 FixedTextPart
*t
= dynamic_cast<FixedTextPart
*>(p
);
446 Returns the zero-based page number of the current text part.
448 void caosVM::v_PAGE() {
450 CompoundAgent
*c
= dynamic_cast<CompoundAgent
*>(targ
.get());
452 CompoundPart
*p
= c
->part(part
);
454 FixedTextPart
*t
= dynamic_cast<FixedTextPart
*>(p
);
457 result
.setInt(t
->getPage());
464 Returns the number of pages for the current text part.
466 void caosVM::v_NPGS() {
468 CompoundAgent
*c
= dynamic_cast<CompoundAgent
*>(targ
.get());
470 CompoundPart
*p
= c
->part(part
);
472 FixedTextPart
*t
= dynamic_cast<FixedTextPart
*>(p
);
475 result
.setInt(t
->noPages());
479 GRPV (command) line (integer) value (float)
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
)
489 CompoundAgent
*c
= dynamic_cast<CompoundAgent
*>(targ
.get());
491 CompoundPart
*p
= c
->part(part
);
493 GraphPart
*t
= dynamic_cast<GraphPart
*>(p
);
500 GRPL (command) red (integer) green (integer) blue (integer) min (float) max (float)
503 Add a new line to a graph created with PAT: GRPH with the given
506 void caosVM::c_GRPL() {
509 VM_PARAM_INTEGER(blue
)
510 VM_PARAM_INTEGER(green
)
511 VM_PARAM_INTEGER(red
)
514 CompoundAgent
*c
= dynamic_cast<CompoundAgent
*>(targ
.get());
516 CompoundPart
*p
= c
->part(part
);
518 GraphPart
*t
= dynamic_cast<GraphPart
*>(p
);
525 BBD: WORD (command) index (integer) id (integer) text (string)
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
)
534 VM_PARAM_INTEGER(index
)
536 if (engine
.version
== 1) {
537 caos_assert(index
< 16);
539 caos_assert(index
< 48);
543 Blackboard
*b
= dynamic_cast<Blackboard
*>(targ
.get());
546 b
->addBlackboardString(index
, id
, text
);
550 BBD: SHOW (command) show (integer)
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
)
561 Blackboard
*b
= dynamic_cast<Blackboard
*>(targ
.get());
568 BBD: EMIT (command) audible (integer)
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
)
583 BBD: EDIT (command) allow (integer)
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
)
598 BBD: VOCB (command) blackboardstart (integer) globalstart (integer) count (integer)
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
)
614 NEW: BBTX (command) part (integer) x (integer) y (integer) width (integer)
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
)
624 VM_PARAM_INTEGER(part
)
631 BBTX (command) part (integer) stringindex (integer)
635 void caosVM::c_BBTX() {
636 VM_PARAM_INTEGER(stringindex
)
637 VM_PARAM_INTEGER(part
)
644 SPOT (command) spotno (integer) left (integer) top (integer) right (integer) bottom (integer)
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
)
656 CompoundAgent
*c
= dynamic_cast<CompoundAgent
*>(targ
.get());
659 c
->setHotspotLoc(spotno
, left
, top
, right
, bottom
);
663 KNOB (command) function (integer) spotno (integer)
665 %pragma variants c1 c2
667 void caosVM::c_KNOB() {
668 VM_PARAM_INTEGER(spotno
)
669 VM_PARAM_INTEGER(function
)
672 CompoundAgent
*c
= dynamic_cast<CompoundAgent
*>(targ
.get());
675 c
->setHotspotFunc(function
, spotno
);
679 KMSG (command) function (integer) flags (integer) message (integer)
683 void caosVM::c_KMSG() {
684 VM_PARAM_INTEGER(message
)
685 VM_PARAM_INTEGER(flags
)
686 VM_PARAM_INTEGER(function
)
689 CompoundAgent
*c
= dynamic_cast<CompoundAgent
*>(targ
.get());
692 c
->setHotspotFuncDetails(function
, message
, flags
);
696 BBLE (command) text (string) ticks (integer) type (integer) track (integer)
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
)
712 BBFD (command) part (integer) red (integer) green (integer) blue (integer)
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
)