5 * Created by Alyssa Milburn on Tue Jun 01 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.
25 #include "SkeletalCreature.h"
29 CreatureAgent
*caosVM::getTargCreatureAgent() {
31 CreatureAgent
*c
= dynamic_cast<CreatureAgent
*>(targ
.get());
36 Creature
*caosVM::getTargCreature() {
37 return getTargCreatureAgent()->getCreature();
40 oldCreature
*getoldCreature(Agent
*a
) {
42 CreatureAgent
*b
= dynamic_cast<CreatureAgent
*>(a
);
44 oldCreature
*c
= dynamic_cast<oldCreature
*>(b
->getCreature());
48 c2eCreature
*getc2eCreature(Agent
*a
) {
50 CreatureAgent
*b
= dynamic_cast<CreatureAgent
*>(a
);
52 c2eCreature
*c
= dynamic_cast<c2eCreature
*>(b
->getCreature());
57 STM# SHOU (command) stimulusno (integer)
59 %pragma variants c1 c2
62 void caosVM::c_STM_SHOU() {
63 VM_PARAM_INTEGER(stimulusno
)
69 STM# SIGN (command) stimulusno (integer)
71 %pragma variants c1 c2
74 void caosVM::c_STM_SIGN() {
75 VM_PARAM_INTEGER(stimulusno
)
81 STM# TACT (command) stimulusno (integer)
83 %pragma variants c1 c2
86 void caosVM::c_STM_TACT() {
87 VM_PARAM_INTEGER(stimulusno
)
93 STM# WRIT (command) object (agent) stimulusno (integer)
95 %pragma variants c1 c2
98 void caosVM::c_STM_WRIT() {
99 VM_PARAM_INTEGER(stimulusno
)
100 VM_PARAM_VALIDAGENT(object
)
106 STIM SHOU (command) stimulus (integer) strength (float)
109 Send a stimulus of the given type to all Creatures who can hear OWNR.
111 void caosVM::c_STIM_SHOU() {
113 VM_PARAM_FLOAT(strength
)
114 VM_PARAM_INTEGER(stimulus
)
120 STIM SIGN (command) stimulus (integer) strength (float)
123 Sends a stimulus of the given type to all Creatures who can see OWNR.
125 void caosVM::c_STIM_SIGN() {
127 VM_PARAM_FLOAT(strength
)
128 VM_PARAM_INTEGER(stimulus
)
134 STIM TACT (command) stimulus (integer) strength (float)
137 Sends a stimulus of the given type to all Creatures who are touching OWNR.
139 void caosVM::c_STIM_TACT() {
141 VM_PARAM_FLOAT(strength
)
142 VM_PARAM_INTEGER(stimulus
)
148 STIM WRIT (command) creature (agent) stimulus (integer) strength (float)
151 Sends a stimulus of the given type to specific Creature.
153 void caosVM::c_STIM_WRIT() {
155 VM_PARAM_FLOAT(strength
)
156 VM_PARAM_INTEGER(stimulus
)
157 VM_PARAM_VALIDAGENT(creature
)
159 c2eCreature
*c
= getc2eCreature(creature
.get());
160 if (!c
) return; // ignored on non-creatures
163 c
->handleStimulus(stimulus
, strength
);
167 STIM SHOU (command) significance (integer) input (integer) intensity (integer) features (integer) chem0 (integer) amount0 (integer) chem1 (integer) amount1 (integer) chem2 (integer) amount2 (integer) chem3 (integer) amount3 (integer)
169 %pragma implementation caosVM::c_STIM_SHOU_c2
170 %pragma variants c1 c2
173 void caosVM::c_STIM_SHOU_c2() {
174 VM_PARAM_INTEGER(amount3
)
175 VM_PARAM_INTEGER(chem3
)
176 VM_PARAM_INTEGER(amount2
)
177 VM_PARAM_INTEGER(chem2
)
178 VM_PARAM_INTEGER(amount1
)
179 VM_PARAM_INTEGER(chem1
)
180 VM_PARAM_INTEGER(amount0
)
181 VM_PARAM_INTEGER(chem0
)
182 VM_PARAM_INTEGER(features
)
183 VM_PARAM_INTEGER(intensity
)
184 VM_PARAM_INTEGER(input
)
185 VM_PARAM_INTEGER(significance
)
191 STIM SIGN (command) significance (integer) input (integer) intensity (integer) features (integer) chem0 (integer) amount0 (integer) chem1 (integer) amount1 (integer) chem2 (integer) amount2 (integer) chem3 (integer) amount3 (integer)
193 %pragma implementation caosVM::c_STIM_SIGN_c2
194 %pragma variants c1 c2
197 void caosVM::c_STIM_SIGN_c2() {
198 VM_PARAM_INTEGER(amount3
)
199 VM_PARAM_INTEGER(chem3
)
200 VM_PARAM_INTEGER(amount2
)
201 VM_PARAM_INTEGER(chem2
)
202 VM_PARAM_INTEGER(amount1
)
203 VM_PARAM_INTEGER(chem1
)
204 VM_PARAM_INTEGER(amount0
)
205 VM_PARAM_INTEGER(chem0
)
206 VM_PARAM_INTEGER(features
)
207 VM_PARAM_INTEGER(intensity
)
208 VM_PARAM_INTEGER(input
)
209 VM_PARAM_INTEGER(significance
)
215 STIM TACT (command) significance (integer) input (integer) intensity (integer) features (integer) chem0 (integer) amount0 (integer) chem1 (integer) amount1 (integer) chem2 (integer) amount2 (integer) chem3 (integer) amount3 (integer)
217 %pragma implementation caosVM::c_STIM_TACT_c2
218 %pragma variants c1 c2
221 void caosVM::c_STIM_TACT_c2() {
222 VM_PARAM_INTEGER(amount3
)
223 VM_PARAM_INTEGER(chem3
)
224 VM_PARAM_INTEGER(amount2
)
225 VM_PARAM_INTEGER(chem2
)
226 VM_PARAM_INTEGER(amount1
)
227 VM_PARAM_INTEGER(chem1
)
228 VM_PARAM_INTEGER(amount0
)
229 VM_PARAM_INTEGER(chem0
)
230 VM_PARAM_INTEGER(features
)
231 VM_PARAM_INTEGER(intensity
)
232 VM_PARAM_INTEGER(input
)
233 VM_PARAM_INTEGER(significance
)
239 STIM WRIT (command) creature (agent) significance (integer) input (integer) intensity (integer) features (integer) chem0 (integer) amount0 (integer) chem1 (integer) amount1 (integer) chem2 (integer) amount2 (integer) chem3 (integer) amount3 (integer)
241 %pragma implementation caosVM::c_STIM_WRIT_c2
242 %pragma variants c1 c2
245 void caosVM::c_STIM_WRIT_c2() {
246 VM_PARAM_INTEGER(amount3
)
247 VM_PARAM_INTEGER(chem3
)
248 VM_PARAM_INTEGER(amount2
)
249 VM_PARAM_INTEGER(chem2
)
250 VM_PARAM_INTEGER(amount1
)
251 VM_PARAM_INTEGER(chem1
)
252 VM_PARAM_INTEGER(amount0
)
253 VM_PARAM_INTEGER(chem0
)
254 VM_PARAM_INTEGER(features
)
255 VM_PARAM_INTEGER(intensity
)
256 VM_PARAM_INTEGER(input
)
257 VM_PARAM_INTEGER(significance
)
258 VM_PARAM_AGENT(creature
)
261 //oldCreature *c = getoldCreature(creature.get());
262 //if (!c) return; // ignored on non-creatures
268 STIM FROM (command) significance (integer) input (integer) intensity (integer) features (integer) chem0 (integer) amount0 (integer) chem1 (integer) amount1 (integer) chem2 (integer) amount2 (integer) chem3 (integer) amount3 (integer)
270 %pragma implementation caosVM::c_STIM_FROM_c1
274 void caosVM::c_STIM_FROM_c1() {
275 VM_PARAM_INTEGER(amount3
)
276 VM_PARAM_INTEGER(chem3
)
277 VM_PARAM_INTEGER(amount2
)
278 VM_PARAM_INTEGER(chem2
)
279 VM_PARAM_INTEGER(amount1
)
280 VM_PARAM_INTEGER(chem1
)
281 VM_PARAM_INTEGER(amount0
)
282 VM_PARAM_INTEGER(chem0
)
283 VM_PARAM_INTEGER(features
)
284 VM_PARAM_INTEGER(intensity
)
285 VM_PARAM_INTEGER(input
)
286 VM_PARAM_INTEGER(significance
)
288 valid_agent(from
.getAgent());
293 SWAY SHOU (command) drive (integer) adjust (float) drive (integer) adjust (float) drive (integer) adjust (float) drive (integer) adjust (float)
296 Adjusts these four drives in all Creatures who can hear OWNR.
298 void caosVM::c_SWAY_SHOU() {
300 VM_PARAM_FLOAT(adjust4
)
301 VM_PARAM_INTEGER(drive4
)
302 VM_PARAM_FLOAT(adjust3
)
303 VM_PARAM_INTEGER(drive3
)
304 VM_PARAM_FLOAT(adjust2
)
305 VM_PARAM_INTEGER(drive2
)
306 VM_PARAM_FLOAT(adjust1
)
307 VM_PARAM_INTEGER(drive1
)
314 SWAY SIGN (command) drive (integer) adjust (float) drive (integer) adjust (float) drive (integer) adjust (float) drive (integer) adjust (float)
317 Adjusts these four drives in all Creatures who can see OWNR.
319 void caosVM::c_SWAY_SIGN() {
321 VM_PARAM_FLOAT(adjust4
)
322 VM_PARAM_INTEGER(drive4
)
323 VM_PARAM_FLOAT(adjust3
)
324 VM_PARAM_INTEGER(drive3
)
325 VM_PARAM_FLOAT(adjust2
)
326 VM_PARAM_INTEGER(drive2
)
327 VM_PARAM_FLOAT(adjust1
)
328 VM_PARAM_INTEGER(drive1
)
335 SWAY TACT (command) drive (integer) adjust (float) drive (integer) adjust (float) drive (integer) adjust (float) drive (integer) adjust (float)
338 Adjusts these four drives in all Creatures who are touching OWNR.
340 void caosVM::c_SWAY_TACT() {
342 VM_PARAM_FLOAT(adjust4
)
343 VM_PARAM_INTEGER(drive4
)
344 VM_PARAM_FLOAT(adjust3
)
345 VM_PARAM_INTEGER(drive3
)
346 VM_PARAM_FLOAT(adjust2
)
347 VM_PARAM_INTEGER(drive2
)
348 VM_PARAM_FLOAT(adjust1
)
349 VM_PARAM_INTEGER(drive1
)
356 SWAY WRIT (command) creature (agent) drive (integer) adjust (float) drive (integer) adjust (float) drive (integer) adjust (float) drive (integer) adjust (float)
359 Adjusts these four drives in the specified creature.
361 void caosVM::c_SWAY_WRIT() {
363 VM_PARAM_FLOAT(adjust4
)
364 VM_PARAM_INTEGER(drive4
)
365 VM_PARAM_FLOAT(adjust3
)
366 VM_PARAM_INTEGER(drive3
)
367 VM_PARAM_FLOAT(adjust2
)
368 VM_PARAM_INTEGER(drive2
)
369 VM_PARAM_FLOAT(adjust1
)
370 VM_PARAM_INTEGER(drive1
)
371 VM_PARAM_VALIDAGENT(creature
)
381 Tells the target Creature to stop holding hands with the pointer.
383 void caosVM::c_NOHH() {
386 if (!targ
) return; // DS agent help, at least, does 'targ hhld nohh'
388 Creature
*c
= getTargCreature();
393 ZOMB (command) zombie (integer)
396 Turns zombification of the target Creature on and off. Set to 1 to disconnect the brain and
397 motor of the target Creature, and 0 to undo.
399 void caosVM::c_ZOMB() {
401 VM_PARAM_INTEGER(zombie
)
403 Creature
*c
= getTargCreature();
405 c
->setZombie(zombie
);
412 Returns 1 if target Creature is zombified, or 0 if otherwise.
414 void caosVM::v_ZOMB() {
415 Creature
*c
= getTargCreature();
416 result
.setInt(c
->isZombie());
420 DIRN (command) direction (integer)
423 Changes the target Creature to face a different direction.
425 void caosVM::c_DIRN() {
427 VM_PARAM_INTEGER(direction
)
429 caos_assert(direction
>= 0 && direction
<= 3);
431 CreatureAgent
*c
= getTargCreatureAgent();
432 c
->setDirection(direction
);
438 %pragma variants c2 cv c3
440 Returns the direction the target Creatures is facing.
442 void caosVM::v_DIRN() {
443 CreatureAgent
*c
= getTargCreatureAgent();
445 result
.setInt(c
->getDirection());
452 Returns Creatures that are holding hands with pointer, or NULL if none.
454 void caosVM::v_HHLD() {
457 result
.setAgent(0); // TODO
461 MVFT (command) x (float) y (float)
464 Move the target Creature's foot (along with the rest of the Creature, obviously) to the given
465 coordinates. You should use this rather than MVTO for Creatures.
467 void caosVM::c_MVFT() {
473 SkeletalCreature
*c
= dynamic_cast<SkeletalCreature
*>(targ
.get());
476 // TODO: this should be nicer
477 float downfootxoffset
= c
->attachmentX(c
->isLeftFootDown() ? 11 : 12, 0);
478 float downfootyoffset
= c
->attachmentY(c
->isLeftFootDown() ? 11 : 12, 0);
480 targ
->moveTo(x
- downfootxoffset
, y
- downfootyoffset
);
484 CREA (integer) agent (agent)
487 Determines whether the given agent is a creature or not (0 or 1).
489 void caosVM::v_CREA() {
491 VM_PARAM_AGENT(agent
)
493 CreatureAgent
*c
= dynamic_cast<CreatureAgent
*>(agent
.get());
494 if (c
) result
.setInt(1);
495 else result
.setInt(0);
502 Makes the target Creature learn all vocabulary words immediately.
504 void caosVM::c_VOCB() {
507 Creature
*c
= getTargCreature();
516 Kill the target Creature biologically.
518 void caosVM::c_DEAD() {
519 Creature
*c
= getTargCreature();
527 %pragma variants c1 c2 cv c3
529 Determines whether the target Creature is dead (0 or 1).
531 void caosVM::v_DEAD() {
532 Creature
*c
= getTargCreature();
534 result
.setInt(!c
->isAlive());
538 NORN (command) creature (agent)
541 Sets the target Creature to the given one.
543 void caosVM::c_NORN() {
544 VM_PARAM_AGENT(creature
)
546 world
.selectCreature(creature
);
552 %pragma variants cv c3
554 Returns the target Creature.
559 %pragma variants c1 c2
561 Returns the target Creature.
563 CAOS_LVALUE(NORN
, (void)0,
564 caosVar(world
.selectedcreature
),
565 world
.selectCreature(newvalue
.getAgent())
568 #include "AgentHelpers.h"
571 URGE SHOU (command) noun_stim (float) verb_id (integer) verb_stim (float)
574 Urges all Creatures who can hear OWNR to perform the given action on OWNR.
575 The two stimuli parameters can range from -1.0 (discourage) to 1.0 (encourage).
577 void caosVM::c_URGE_SHOU() {
578 VM_PARAM_FLOAT(verb_stim
)
579 VM_PARAM_INTEGER(verb_id
)
580 VM_PARAM_FLOAT(noun_stim
)
588 URGE SIGN (command) noun_stim (float) verb_id (integer) verb_stim (float)
591 Urges all Creatures who can see OWNR to perform the given action on OWNR.
592 The two stimuli parameters can range from -1.0 (discourage) to 1.0 (encourage).
594 void caosVM::c_URGE_SIGN() {
595 VM_PARAM_FLOAT(verb_stim
)
596 VM_PARAM_INTEGER(verb_id
)
597 VM_PARAM_FLOAT(noun_stim
)
601 // TODO: sanitise stim params (bind to -1.0/1.0)
603 stim
.noun_id
= owner
->category
;
604 if (stim
.noun_id
== -1) return; // TODO: correct?
605 stim
.noun_amount
= noun_stim
;
606 stim
.verb_id
= verb_id
;
607 stim
.verb_amount
= verb_stim
;
609 std::vector
<boost::shared_ptr
<Agent
> > agents
= getVisibleList(owner
, 0, 0, 0);
610 for (std::vector
<boost::shared_ptr
<Agent
> >::iterator i
= agents
.begin(); i
!= agents
.end(); i
++) {
611 boost::shared_ptr
<Agent
> a
= *i
; // guaranteed to be valid from getVisibleList
613 CreatureAgent
*ca
= dynamic_cast<CreatureAgent
*>(a
.get());
615 c2eCreature
*c
= dynamic_cast<c2eCreature
*>(ca
->getCreature());
618 c
->handleStimulus(stim
);
623 URGE TACT (command) noun_stim (float) verb_id (integer) verb_stim (float)
626 Urges all Creatures who are touching OWNR to perform the given action on OWNR.
627 The two stimuli parameters can range from -1.0 (discourage) to 1.0 (encourage).
629 void caosVM::c_URGE_TACT() {
630 VM_PARAM_FLOAT(verb_stim
)
631 VM_PARAM_INTEGER(verb_id
)
632 VM_PARAM_FLOAT(noun_stim
)
640 URGE WRIT (command) creature (agent) noun_id (integer) noun_stim (float) verb_id (integer) verb_stim (float)
643 Urges the specified Creature to perform the specified action (verb) on the specified object type
644 (noun). Provide a stim greater than 1 to force, and an id of -1 and a stim greater than 1 to unforce.
646 void caosVM::c_URGE_WRIT() {
647 VM_PARAM_FLOAT(verb_stim
)
648 VM_PARAM_INTEGER(verb_id
)
649 VM_PARAM_FLOAT(noun_stim
)
650 VM_PARAM_INTEGER(noun_id
)
651 VM_PARAM_AGENT(creature
)
653 if (!creature
) return;
654 c2eCreature
*c
= getc2eCreature(creature
.get());
655 if (!c
) return; // ignored on non-creatures
661 DRIV (command) drive_id (integer) adjust (float)
664 Modifies the level of a drive in target Creature by the given level, which can range from -1.0 (decrease) to 1.0 (increase).
666 void caosVM::c_DRIV() {
667 VM_PARAM_FLOAT(adjust
)
668 VM_PARAM_INTEGER(drive_id
) caos_assert(drive_id
>= 0 && drive_id
< 20);
671 c2eCreature
*c
= getc2eCreature(targ
.get());
672 if (!c
) return; // ignored on non-creatures
674 c
->adjustDrive(drive_id
, adjust
);
678 DRIV (float) drive_id (integer)
681 Returns the level of a drive (0.0 to 1.0) in target Creature.
683 void caosVM::v_DRIV() {
684 VM_PARAM_INTEGER(drive_id
) caos_assert(drive_id
>= 0 && drive_id
< 20);
686 c2eCreature
*c
= getc2eCreature(targ
.get());
689 result
.setFloat(c
->getDrive(drive_id
));
693 CHEM (command) chemical_id (integer) adjust (float)
696 Modifies the level of a chemical in target Creature's bloodstream by adjust, which can range from -1.0 (decrease) to 1.0 (increase).
698 void caosVM::c_CHEM() {
699 VM_PARAM_FLOAT(adjust
)
700 VM_PARAM_INTEGER(chemical_id
) caos_assert(chemical_id
>= 0 && chemical_id
< 256);
703 c2eCreature
*c
= getc2eCreature(targ
.get());
704 if (!c
) return; // ignored on non-creatures
706 c
->adjustChemical(chemical_id
, adjust
);
710 CHEM (command) chemical_id (integer) adjust (integer)
712 %pragma variants c1 c2
713 %pragma implementation caosVM::c_CHEM_c1
716 Set the level of a chemical (0 to 255) in target creature's bloodstream.
718 void caosVM::c_CHEM_c1() {
719 VM_PARAM_INTEGER(adjust
)
720 VM_PARAM_INTEGER(chemical_id
) caos_assert(chemical_id
>= 0 && chemical_id
< 256);
722 // TODO: can adjust be negative?
725 oldCreature
*c
= getoldCreature(targ
.get());
726 if (!c
) return; // ignored on non-creatures
728 c
->addChemical(chemical_id
, adjust
);
732 CHEM (float) chemical_id (integer)
735 Returns the level of a chemical (0.0 to 1.0) in target creature's bloodstream.
737 void caosVM::v_CHEM() {
738 VM_PARAM_INTEGER(chemical_id
) caos_assert(chemical_id
>= 0 && chemical_id
< 256);
741 c2eCreature
*c
= getc2eCreature(targ
.get());
744 result
.setFloat(c
->getChemical(chemical_id
));
748 CHEM (integer) chemical_id (integer)
750 %pragma variants c1 c2
751 %pragma implementation caosVM::v_CHEM_c1
753 Returns the level of a chemical (0 to 255) in target creature's bloodstream.
755 void caosVM::v_CHEM_c1() {
756 VM_PARAM_INTEGER(chemical_id
) caos_assert(chemical_id
>= 0 && chemical_id
< 256);
759 oldCreature
*c
= getoldCreature(targ
.get());
762 result
.setInt(c
->getChemical(chemical_id
));
766 ASLP (command) asleep (integer)
768 %pragma variants c1 c2 cv c3
770 If asleep is 1, makes the target creature sleep. If asleep is 0, makes the target creature wake.
772 void caosVM::c_ASLP() {
773 VM_PARAM_INTEGER(asleep
)
775 Creature
*c
= getTargCreature();
777 c
->setAsleep(asleep
);
783 %pragma variants c1 c2 cv c3
786 Determines whether the target Creature is asleep.
788 void caosVM::v_ASLP() {
789 Creature
*c
= getTargCreature();
791 result
.setInt(c
->isAsleep());
794 #include "AgentHelpers.h"
796 class blockUntilApproached
: public blockCond
{
799 CreatureAgent
*parentcreature
;
802 blockUntilApproached(AgentRef p
, AgentRef i
) : parent(p
), it(i
) {
804 parentcreature
= dynamic_cast<CreatureAgent
*>(parent
.get());
805 assert(parentcreature
);
807 virtual bool operator()() {
808 if (!parent
) return false;
809 if (!it
) return false; // TODO: CAs
811 if (agentsTouching(parent
, it
)) return false;
813 // parentcreature is guaranteed to be valid if parent is
815 // TODO: cope with this problem (eg: another APPR, creature paused, non-skeletal creature, etc)
816 //if (parentcreature->isApproaching()) return false;
818 // note that this merely sets up the approach to be done on the next tick of the creature
819 parentcreature
->approach(it
);
828 %pragma variants c1 c2 cv c3
830 Makes the target Creature approach the IT agent (or if none, an agent of that category using CAs),
831 blocking until it makes it there or gives up.
833 void caosVM::c_APPR() {
834 CreatureAgent
*a
= getTargCreatureAgent();
837 startBlocking(new blockUntilApproached(targ
, _it_
));
841 UNCS (command) unconscious (integer)
844 Makes the target Creature conscious if 0, or unconscious if 1.
846 void caosVM::c_UNCS() {
847 VM_PARAM_INTEGER(unconscious
)
849 Creature
*c
= getTargCreature();
857 %pragma variants c2 cv c3
859 Returns 1 if the target Creature is unconscious, or 0 otherwise.
861 void caosVM::v_UNCS() {
862 Creature
*c
= getTargCreature();
864 result
.setInt(0); // TODO
868 FACE (command) number (integer)
871 void caosVM::c_FACE() {
872 VM_PARAM_INTEGER(number
)
875 SkeletalCreature
*c
= dynamic_cast<SkeletalCreature
*>(targ
.get());
885 Returns the front-facing pose for the current facial expression of the target creature.
887 void caosVM::v_FACE_INT() {
889 SkeletalCreature
*c
= dynamic_cast<SkeletalCreature
*>(targ
.get());
892 result
.setInt(c
->getFaceSpriteFrame());
899 Returns the current sprite filename for the face of the target creature.
901 void caosVM::v_FACE_STRING() {
903 SkeletalCreature
*c
= dynamic_cast<SkeletalCreature
*>(targ
.get());
906 result
.setString(c
->getFaceSpriteName());
910 LIKE (command) creature (agent)
913 Causes the target Creature to state an opinion about the specified Creature.
915 void caosVM::c_LIKE() {
916 VM_PARAM_VALIDAGENT(creature
)
918 Creature
*c
= getTargCreature();
924 LIMB (string) bodypart (integer) genus (integer) gender (integer) age (integer) variant (integer)
927 Returns the filename for the specified part of a Creature, substituting as necessary.
929 void caosVM::v_LIMB() {
930 VM_PARAM_INTEGER(variant
)
931 VM_PARAM_INTEGER(age
)
932 VM_PARAM_INTEGER(gender
)
933 VM_PARAM_INTEGER(genus
)
934 VM_PARAM_INTEGER(bodypart
)
936 Creature
*c
= getTargCreature();
938 result
.setString(""); // TODO
942 ORDR SHOU (command) speech (string)
945 Makes the target Creature speak the specified speech to all creatures in hearing range.
947 void caosVM::c_ORDR_SHOU() {
948 VM_PARAM_STRING(speech
)
955 ORDR SIGN (command) speech (string)
958 Makes the target Creature speak the specified speech to all creatures that can see it.
960 void caosVM::c_ORDR_SIGN() {
961 VM_PARAM_STRING(speech
)
968 ORDR TACT (command) speech (string)
971 Makes the target Creature speak the specified speech to all creatures that are touching it.
973 void caosVM::c_ORDR_TACT() {
974 VM_PARAM_STRING(speech
)
981 ORDR WRIT (command) creature (agent) speech (string)
984 Makes the target Creature speak the specified speech to the specified creature.
986 void caosVM::c_ORDR_WRIT() {
987 VM_PARAM_STRING(speech
)
988 VM_PARAM_VALIDAGENT(creature
)
995 DREA (command) dream (integer)
998 Turns a Creature's dreaming on and off. A Creature's instincts are
999 processed while it is dreaming. If it is not asleep already, then it
1000 will be made to sleep before dreaming begins.
1002 void caosVM::c_DREA() {
1003 VM_PARAM_INTEGER(dream
)
1005 Creature
*c
= getTargCreature();
1006 c
->setDreaming(dream
);
1013 Returns whether or not the target Creature is dreaming (0 or 1).
1015 void caosVM::v_DREA() {
1016 Creature
*c
= getTargCreature();
1017 result
.setInt(c
->isDreaming());
1024 Registers the birth of the target Creature, and sends a birth event to
1027 void caosVM::c_BORN() {
1028 Creature
*c
= getTargCreature();
1035 %pragma variants c1 c2 cv c3
1037 Returns the integer value of the target Creature's current life stage.
1039 void caosVM::v_CAGE() {
1040 Creature
*c
= getTargCreature();
1041 result
.setInt((int)c
->getStage());
1048 Determines whether or not the target Creature can reach the IT agent (0
1051 void caosVM::v_BYIT() {
1052 Creature
*c
= getTargCreature();
1054 if (_it_
&& agentsTouching(targ
, _it_
)) // TODO
1063 %pragma implementation caosVM::v_IT
1064 %pragma variants c1 c2 cv c3
1066 Returns the agent that the OWNR creature was focused on when the
1067 current script began running.
1069 void caosVM::v_IT() {
1071 caos_assert(dynamic_cast<CreatureAgent
*>(owner
.get())); // TODO: return null instead?
1072 result
.setAgent(_it_
);
1076 NEWC (command) family (integer) gene_agent (agent) gene_slot (integer) sex (integer) variant (integer)
1079 Creates a new creature over the space of a few ticks, using the specified agent/slot for genetic data. sex is 0 for random, 1 for male or 2 for female.
1081 void caosVM::c_NEWC() {
1082 VM_PARAM_INTEGER(variant
)
1083 VM_PARAM_INTEGER(sex
)
1084 VM_PARAM_INTEGER(gene_slot
)
1085 VM_PARAM_VALIDAGENT(gene_agent
)
1086 VM_PARAM_INTEGER(family
)
1088 // TODO: creation should be blocking and multiple-tick!
1090 std::map
<unsigned int, shared_ptr
<class genomeFile
> >::iterator i
= gene_agent
->slots
.find(gene_slot
);
1091 caos_assert(i
!= gene_agent
->slots
.end());
1093 // randomise sex if necessary
1094 if (sex
== 0) sex
= 1 + (int) (2.0 * (rand() / (RAND_MAX
+ 1.0)));
1095 caos_assert(sex
== 1 || sex
== 2); // TODO: correct?
1097 // TODO: if variant is 0, randomise between 1 and 8
1098 SkeletalCreature
*a
= new SkeletalCreature(family
);
1100 c2eCreature
*c
= new c2eCreature(i
->second
, (sex
== 2), variant
, a
);
1109 world
.history
.getMoniker(world
.history
.findMoniker(i
->second
)).moveToCreature(a
);
1110 i
->second
.reset(); // TODO: remove the slot from the gene_agent entirely
1116 NEW: CREA (command) family (integer) gene_agent (agent) gene_slot (integer) sex (integer) variant (integer)
1119 Creates a new creature using the specified agent/slot for genetic data. sex is 0 for random, 1 for male or 2 for female.
1121 void caosVM::c_NEW_CREA() {
1122 /*VM_PARAM_INTEGER(variant)
1123 VM_PARAM_INTEGER(sex)
1124 VM_PARAM_INTEGER(gene_slot)
1125 VM_PARAM_VALIDAGENT(gene_agent)
1126 VM_PARAM_INTEGER(family)*/
1129 //targ = NULL; // TODO
1133 NEW: CREA (command) moniker (integer) sex (integer)
1135 %pragma variants c1 c2
1136 %pragma implementation caosVM::c_NEW_CREA_c1
1138 Creates a new creature using the specified moniker for genetic data. sex is 0 for random, 1 for male or 2 for female.
1140 void caosVM::c_NEW_CREA_c1() {
1141 VM_PARAM_INTEGER(sex
)
1142 VM_PARAM_INTEGER(moniker
)
1144 caos_assert(moniker
!= 0);
1146 std::string realmoniker
= std::string((char *)&moniker
, 4);
1147 shared_ptr
<genomeFile
> genome
= world
.loadGenome(realmoniker
);
1149 throw creaturesException("failed to find genome file '" + realmoniker
+ '"');
1151 caos_assert(genome
->getVersion() == engine
.version
);
1153 // randomise sex if necessary
1154 if (sex
== 0) sex
= 1 + (int) (2.0 * (rand() / (RAND_MAX
+ 1.0)));
1155 caos_assert(sex
== 1 || sex
== 2); // TODO: correct?
1157 SkeletalCreature
*a
= new SkeletalCreature(4);
1159 // TODO: why do we even need to pass a variant here?
1163 if (engine
.version
== 1) c
= new c1Creature(genome
, (sex
== 2), 0, a
);
1164 else c
= new c2Creature(genome
, (sex
== 2), 0, a
);
1173 a
->slots
[0] = genome
;
1174 world
.newMoniker(genome
, realmoniker
, a
);
1175 world
.history
.getMoniker(world
.history
.findMoniker(genome
)).moveToCreature(a
);
1180 int calculateRand(int value1
, int value2
); // caosVM_variables.cpp
1183 LTCY (command) action (integer) min (integer) max (integer)
1185 %pragma variants c1 c2 cv c3
1187 void caosVM::c_LTCY() {
1188 VM_PARAM_INTEGER(max
); caos_assert(max
>= 0 && max
<= 255);
1189 VM_PARAM_INTEGER(min
); caos_assert(min
>= 0 && min
<= 255);
1190 VM_PARAM_INTEGER(action
);
1192 int n
= calculateRand(min
, max
);
1194 Creature
*c
= getTargCreature();
1196 c2eCreature
*c2ec
= dynamic_cast<c2eCreature
*>(c
);
1198 c2ec
->setInvolActionLatency(action
, n
);
1201 // TODO: ltcy support for c1/c2
1208 %pragma implementation caosVM::c_MATE
1213 %pragma variants c2 cv c3
1216 void caosVM::c_MATE() {
1217 Creature
*c
= getTargCreature();
1219 CreatureAgent
*t
= dynamic_cast<CreatureAgent
*>(_it_
.get());
1221 Creature
*d
= t
->getCreature();
1229 %pragma implementation caosVM::v_DRV
1230 %pragma variants c1 c2 cv c3
1232 void caosVM::v_DRV() {
1233 Creature
*c
= getTargCreature();
1234 result
.setInt(0); // TODO
1241 Return the agent which the target creature is currently focused on. Note that you should probably use _IT_ in creature scripts.
1243 void caosVM::v_IITT() {
1244 Creature
*c
= getTargCreature();
1245 result
.setAgent(c
->getAttentionFocus());
1249 AGES (command) times (integer)
1252 Age (ie, increase the life stage of) the target creature the specified number of times.
1254 void caosVM::c_AGES() {
1255 VM_PARAM_INTEGER(times
)
1256 caos_assert(times
>= 0);
1258 Creature
*c
= getTargCreature();
1259 for (int i
= 0; i
< times
; i
++) {
1265 LOCI (command) type (integer) organ (integer) tissue (integer) id (integer) value (float)
1268 Set the value of the specified loci of the target creature. 'type' is 0 for receptor loci and 1 for emitter loci.
1269 See genetics documentation for details of the parameters.
1271 void caosVM::c_LOCI() {
1272 VM_PARAM_FLOAT(value
)
1273 VM_PARAM_INTEGER(id
)
1274 VM_PARAM_INTEGER(tissue
)
1275 VM_PARAM_INTEGER(organ
)
1276 VM_PARAM_INTEGER(type
)
1278 c2eCreature
*c
= getc2eCreature(targ
.get());
1280 float *f
= c
->getLocusPointer(!type
, organ
, tissue
, id
);
1286 LOCI (float) type (integer) organ (integer) tissue (integer) id (integer)
1289 Return the current value of the specified loci of the target creature. 'type' is 0 for receptor loci and 1 for emitter loci.
1290 See genetics documentation for details of thei parameters.
1292 void caosVM::v_LOCI() {
1293 VM_PARAM_INTEGER(id
)
1294 VM_PARAM_INTEGER(tissue
)
1295 VM_PARAM_INTEGER(organ
)
1296 VM_PARAM_INTEGER(type
)
1298 c2eCreature
*c
= getc2eCreature(targ
.get());
1300 float *f
= c
->getLocusPointer(!type
, organ
, tissue
, id
);
1302 result
.setFloat(*f
);
1309 Returns age of target creature, in ticks. Only counts ticks since it was BORN.
1311 void caosVM::v_TAGE() {
1312 Creature
*c
= getTargCreature();
1313 result
.setInt(c
->getAge());
1320 Return the number of organs the target creature has.
1322 void caosVM::v_ORGN() {
1323 c2eCreature
*c
= getc2eCreature(targ
.get());
1324 result
.setInt(c
->noOrgans());
1328 ORGF (float) organ (integer) value (integer)
1331 Return some data about the specified organ (numbered starting at zero) of the target creature.
1333 value should be one of the following types of data:
1335 1: short term life force as a proportion of the initial life force
1338 4: initial life force
1339 5: short term life force
1340 6: long term life force
1343 9: atp damage coefficient
1345 Returns -1 if the specified organ or value is invalid.
1347 void caosVM::v_ORGF() {
1348 VM_PARAM_INTEGER(value
)
1349 VM_PARAM_INTEGER(organ
)
1351 c2eCreature
*c
= getc2eCreature(targ
.get());
1352 if (organ
< 0 || (unsigned int)organ
>= c
->noOrgans()) {
1353 result
.setFloat(-1.0f
);
1357 shared_ptr
<c2eOrgan
> o
= c
->getOrgan(organ
);
1360 case 0: result
.setFloat(o
->getClockRate()); break;
1361 case 1: result
.setFloat(o
->getShortTermLifeforce() / o
->getInitialLifeforce()); break;
1362 case 2: result
.setFloat(o
->getRepairRate()); break;
1363 case 3: result
.setFloat(o
->getInjuryToApply()); break;
1364 case 4: result
.setFloat(o
->getInitialLifeforce()); break;
1365 case 5: result
.setFloat(o
->getShortTermLifeforce()); break;
1366 case 6: result
.setFloat(o
->getLongTermLifeforce()); break;
1367 case 7: result
.setFloat(o
->getDamageRate()); break;
1368 case 8: result
.setFloat(o
->getEnergyCost()); break;
1369 case 9: result
.setFloat(o
->getATPDamageCoefficient()); break;
1370 default: result
.setFloat(-1.0f
); break;
1375 ORGI (integer) organ (integer) value (integer)
1378 Returns a count of receptors (value 0), emitters (value 1) or reactions (value 2) in the specified organ (numbered starting at zero) of the target creature.
1380 Returns -1 if the specified organ or value is invalid.
1382 void caosVM::v_ORGI() {
1383 VM_PARAM_INTEGER(value
)
1384 VM_PARAM_INTEGER(organ
)
1386 c2eCreature
*c
= getc2eCreature(targ
.get());
1387 if (organ
< 0 || (unsigned int)organ
>= c
->noOrgans()) {
1388 result
.setFloat(-1.0f
);
1392 shared_ptr
<c2eOrgan
> o
= c
->getOrgan(organ
);
1395 case 0: result
.setInt(o
->getReceptorCount()); break;
1396 case 1: result
.setInt(o
->getEmitterCount()); break;
1397 case 2: result
.setInt(o
->getReactionCount()); break;
1398 default: result
.setFloat(-1.0f
); break;
1403 SOUL (command) part (integer) on (integer)
1406 void caosVM::c_SOUL() {
1407 VM_PARAM_INTEGER(on
)
1408 VM_PARAM_INTEGER(part
)
1409 caos_assert(part
>= 0 && part
<= 8);
1411 Creature
*c
= getTargCreature();
1416 SOUL (integer) part (integer)
1419 void caosVM::v_SOUL() {
1420 VM_PARAM_INTEGER(part
)
1421 caos_assert(part
>= 0 && part
<= 8);
1423 Creature
*c
= getTargCreature();
1424 result
.setInt(1); // TODO
1431 void caosVM::v_DECN() {
1432 Creature
*c
= getTargCreature();
1433 result
.setInt(c
->getDecisionId());
1440 void caosVM::v_ATTN() {
1441 Creature
*c
= getTargCreature();
1442 result
.setInt(c
->getAttentionId());
1448 %pragma variants c1 c2 cv c3
1450 void caosVM::c_TOUC() {
1451 Creature
*c
= getTargCreature();
1457 FORF (command) creature (agent)
1460 void caosVM::c_FORF() {
1461 VM_PARAM_VALIDAGENT(creature
)
1463 Creature
*c
= getTargCreature();
1464 // TODO: do we handle pointer as well?
1465 Creature
*learn
= dynamic_cast<Creature
*>(creature
.get());
1474 %pragma variants c1 c2 cv c3
1476 void caosVM::c_WALK() {
1477 CreatureAgent
*c
= getTargCreatureAgent();
1485 %pragma variants c1 c2 cv c3
1487 void caosVM::c_DONE() {
1488 Creature
*c
= getTargCreature();
1496 %pragma variants c1 c2 cv c3
1498 void caosVM::c_SAYN() {
1499 Creature
*c
= getTargCreature();
1505 IMPT (command) nudge (integer)
1507 %pragma variants c1 c2
1509 void caosVM::c_IMPT() {
1510 VM_PARAM_INTEGER(nudge
)
1512 // TODO: check for creature targ?
1517 AIM: (command) actionno (integer)
1519 %pragma variants c1 c2
1521 void caosVM::c_AIM() {
1522 VM_PARAM_INTEGER(actionno
)
1524 // TODO: check for creature targ? who knows?
1531 %pragma variants c1 c2
1533 CAOS_LVALUE_TARG_SIMPLE(BABY
, targ
->babymoniker
); // TODO
1538 %pragma variants c1 c2
1540 void caosVM::c_SNEZ() {
1541 Creature
*c
= getTargCreature();
1547 DRIV (integer) drive (integer)
1549 %pragma variants c1 c2
1550 %pragma implementation caosVM::v_DRIV_c1
1552 Returns the value for the specified drive of the target creature.
1554 void caosVM::v_DRIV_c1() {
1555 VM_PARAM_INTEGER(drive
)
1556 caos_assert(drive
< 16);
1558 oldCreature
*c
= getoldCreature(targ
.get());
1562 result
.setInt(c
->getDrive(drive
));
1566 DREA (command) max (integer)
1568 %pragma variants c1 c2
1569 %pragma implementation caosVM::c_DREA_c1
1571 Start dreaming and process (at most?) max instincts.
1573 void caosVM::c_DREA_c1() {
1574 VM_PARAM_INTEGER(max
)
1576 oldCreature
*c
= getoldCreature(targ
.get());
1583 BRED (integer) part (integer)
1586 void caosVM::v_BRED() {
1587 VM_PARAM_INTEGER(part
)
1589 result
.setInt(0); // TODO
1596 void caosVM::v_BVAR() {
1597 result
.setInt(0); // TODO
1601 EXPR (command) index (integer) ticks (integer)
1604 void caosVM::c_EXPR() {
1605 VM_PARAM_INTEGER(ticks
)
1606 VM_PARAM_INTEGER(index
)
1615 void caosVM::v_EXPR() {
1616 result
.setInt(0); // TODO
1620 TNTC (command) tintindex (integer) part (integer) commit (integer)
1623 void caosVM::c_TNTC() {
1624 VM_PARAM_INTEGER(commit
)
1625 VM_PARAM_INTEGER(part
)
1626 VM_PARAM_INTEGER(tintindex
)
1632 INJR (command) organ (integer) amount (integer)
1636 void caosVM::c_INJR() {
1637 VM_PARAM_INTEGER(amount
)
1638 VM_PARAM_INTEGER(organ
)
1645 SAY$ (command) string (string)
1649 void caosVM::c_SAY() {
1650 VM_PARAM_STRING(string
)
1657 TRIG (command) lobe (integer) cell (integer) amount (integer)
1661 void caosVM::c_TRIG() {
1662 VM_PARAM_INTEGER(amount
)
1663 VM_PARAM_INTEGER(cell
)
1664 VM_PARAM_INTEGER(lobe
)
1675 void caosVM::v_MONK() {
1676 oldCreature
*c
= getoldCreature(targ
.get());
1679 result
.setInt(0); // TODO
1685 BODY (command) set (integer) layer (integer)
1688 void caosVM::c_BODY() {
1689 VM_PARAM_INTEGER(layer
)
1690 VM_PARAM_INTEGER(set
)
1696 BODY (integer) part (integer)
1699 void caosVM::v_BODY() {
1700 VM_PARAM_INTEGER(part
)
1702 result
.setInt(-1); // TODO
1706 DYED (command) part (integer) overlay (integer) set (integer) layer (integer)
1709 void caosVM::c_DYED() {
1710 VM_PARAM_INTEGER(layer
)
1711 VM_PARAM_INTEGER(set
)
1712 VM_PARAM_INTEGER(overlay
)
1713 VM_PARAM_INTEGER(part
)
1719 HAIR (command) ruffleness (integer)
1722 void caosVM::c_HAIR() {
1723 VM_PARAM_INTEGER(ruffleness
)
1732 void caosVM::c_NUDE() {
1740 void caosVM::c_RSET() {
1748 void caosVM::c_STRE() {
1753 SWAP (command) variant (integer) part (integer) commit (integer)
1756 void caosVM::c_SWAP() {
1757 VM_PARAM_INTEGER(commit
)
1758 VM_PARAM_INTEGER(part
)
1759 VM_PARAM_INTEGER(variant
)
1765 WEAR (command) part (integer) set (integer) layer (integer)
1768 void caosVM::c_WEAR() {
1769 VM_PARAM_INTEGER(layer
)
1770 VM_PARAM_INTEGER(set
)
1771 VM_PARAM_INTEGER(part
)
1777 WEAR (integer) part (integer) layer (integer)
1780 void caosVM::v_WEAR() {
1781 VM_PARAM_INTEGER(layer
)
1782 VM_PARAM_INTEGER(part
)
1784 result
.setInt(-1); // TODO
1788 TNTO (command) tintindex (integer) part (integer) set (integer) layer (integer)
1791 void caosVM::c_TNTO() {
1792 VM_PARAM_INTEGER(layer
)
1793 VM_PARAM_INTEGER(set
)
1794 VM_PARAM_INTEGER(part
)
1795 VM_PARAM_INTEGER(tintindex
)
1800 // attachment locations
1806 void caosVM::v_DFTX() {
1807 result
.setFloat(0); // TODO
1814 void caosVM::v_DFTY() {
1815 result
.setFloat(0); // TODO
1822 void caosVM::v_UFTX() {
1823 result
.setFloat(0); // TODO
1830 void caosVM::v_UFTY() {
1831 result
.setFloat(0); // TODO
1835 HEDX (float) index (integer)
1838 void caosVM::v_HEDX() {
1839 VM_PARAM_INTEGER(index
)
1841 result
.setFloat(0); // TODO
1845 HEDY (float) index (integer)
1848 void caosVM::v_HEDY() {
1849 VM_PARAM_INTEGER(index
)
1851 result
.setFloat(0); // TODO
1858 void caosVM::v_MTHX() {
1859 result
.setFloat(0); // TODO
1866 void caosVM::v_MTHY() {
1867 result
.setFloat(0); // TODO