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.
21 #include "caosScript.h"
30 %pragma variants c1 c2 cv c3 sm
32 Forces the following commands to be executed in one tick, rather than scheduling them, until SLOW or the end
33 of the script is encountered.
35 void caosVM::c_INST() {
38 // TODO: do we need a state similar to locked? i commented it out because it doesn't seem right - fuzzie
45 %pragma variants c2 cv c3 sm
47 Reverses the effects of INST.
49 void caosVM::c_SLOW() {
58 %pragma variants c2 cv c3 sm
60 Prevent the script from being interrupted by another until UNLK or the end of the script is encountered.
62 void caosVM::c_LOCK() {
70 %pragma variants c2 cv c3 sm
72 Reverses the effects of LOCK.
74 void caosVM::c_UNLK() {
80 class blockUntilTime
: public blockCond
{
85 if (world
.tickcount
< end
)
90 blockUntilTime(int delta
) : end(world
.tickcount
+ delta
) {}
94 WAIT (command) ticks (integer)
96 %pragma variants c1 c2 cv c3 sm
99 Stops the script from running for the given number of ticks.
101 void caosVM::c_WAIT() {
103 VM_PARAM_INTEGER(ticks
)
105 caos_assert(ticks
>= 0); // TODO: is this right?
106 if (ticks
== 0) return;
107 if (engine
.version
< 3 && !owner
) {
108 // TODO: this message is here until someone works out what the heck ;)
109 // the C1 cloud butterfly COB and C2 nesting bluebirds COB do this, at least
110 std::cout
<< "unblockable script is trying to WAIT, ignoring" << std::endl
;
113 startBlocking(new blockUntilTime(ticks
));
119 %pragma stackdelta any
120 %pragma variants c1 c2 cv c3 sm
124 void caosVM::c_STOP() {
130 SCRX (command) family (integer) genus (integer) species (integer) event (integer)
132 %pragma variants c1 c2 cv c3 sm
134 Deletes the event script in question from the scriptoruium.
136 void caosVM::c_SCRX() {
138 VM_PARAM_INTEGER(event
)
139 caos_assert(event
>= 0);
140 caos_assert(event
<= 65535);
141 VM_PARAM_INTEGER(species
)
142 caos_assert(species
>= 0);
143 caos_assert(species
<= 65535);
144 VM_PARAM_INTEGER(genus
)
145 caos_assert(genus
>= 0);
146 caos_assert(genus
<= 255);
147 VM_PARAM_INTEGER(family
)
148 caos_assert(family
>= 0);
149 caos_assert(family
<= 255);
150 world
.scriptorium
.delScript(family
, genus
, species
, event
);
157 Returns script number running in the TARG agent. Returns -1 if target is not
158 running anything (or if it's running something that's not an event script).
160 void caosVM::v_CODE() {
163 if (targ
->vm
&& targ
->vm
->currentscript
)
164 res
= targ
->vm
->currentscript
->scrp
;
175 Returns script family running in the TARG agent. Returns -1 if target is not
176 running anything (or if it's running something that's not an event script).
178 void caosVM::v_CODF() {
181 if (targ
->vm
&& targ
->vm
->currentscript
)
182 res
= targ
->vm
->currentscript
->fmly
;
193 Returns script genus running in the target. Returns -1 if target is not
194 running anything (or if it's running something that's not an event script).
196 void caosVM::v_CODG() {
199 if (targ
->vm
&& targ
->vm
->currentscript
)
200 res
= targ
->vm
->currentscript
->gnus
;
211 Returns script species running in the target. Returns -1 if target is not
212 running anything (or if it's running something that's not an event script).
214 void caosVM::v_CODS() {
217 if (targ
->vm
&& targ
->vm
->currentscript
)
218 res
= targ
->vm
->currentscript
->spcs
;
226 JECT (command) file (string) flags (integer)
229 Inject a script from the current bootstrap. 'file' must be the full filename.
230 Flags can be 1 for remove script, 2 for event scripts and 4 for install script.
232 void caosVM::c_JECT() {
233 VM_PARAM_INTEGER(flags
)
234 VM_PARAM_STRING(file
)
240 SORQ (integer) family (integer) genus (integer) species (integer) event (integer)
243 void caosVM::v_SORQ() {
244 VM_PARAM_INTEGER(event
) caos_assert(event
>= 0 && event
<= 65535);
245 VM_PARAM_INTEGER(species
) caos_assert(event
>= 0 && event
<= 65535);
246 VM_PARAM_INTEGER(genus
) caos_assert(event
>= 0 && event
<= 255);
247 VM_PARAM_INTEGER(family
) caos_assert(event
>= 0 && event
<= 255);
249 shared_ptr
<script
> s
= world
.scriptorium
.getScript(family
, genus
, species
, event
);
250 if (s
) result
.setInt(1);
251 else result
.setInt(0);