try to make build portable: remove SDL_mixer dependency, remove -f from cp command...
[openc2e.git] / caosVM_scripts.cpp
blob0cd016012989ef45eb9f59b452b6672a9fc945e5
1 /*
2 * caosVM_scripts.cpp
3 * openc2e
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.
20 #include "caosVM.h"
21 #include "caosScript.h"
22 #include "World.h"
23 #include "Engine.h"
24 #include <iostream>
25 using std::cerr;
27 /**
28 INST (command)
29 %status maybe
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() {
36 VM_VERIFY_SIZE(0)
37 inst = true;
38 // TODO: do we need a state similar to locked? i commented it out because it doesn't seem right - fuzzie
39 //locked = true;
42 /**
43 SLOW (command)
44 %status maybe
45 %pragma variants c2 cv c3 sm
47 Reverses the effects of INST.
49 void caosVM::c_SLOW() {
50 VM_VERIFY_SIZE(0)
52 inst = false;
55 /**
56 LOCK (command)
57 %status maybe
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() {
63 VM_VERIFY_SIZE(0)
64 lock = true;
67 /**
68 UNLK (command)
69 %status maybe
70 %pragma variants c2 cv c3 sm
72 Reverses the effects of LOCK.
74 void caosVM::c_UNLK() {
75 VM_VERIFY_SIZE(0)
77 lock = false;
80 class blockUntilTime : public blockCond {
81 protected:
82 unsigned int end;
83 public:
84 bool operator()() {
85 if (world.tickcount < end)
86 return true;
87 return false;
90 blockUntilTime(int delta) : end(world.tickcount + delta) {}
93 /**
94 WAIT (command) ticks (integer)
95 %status maybe
96 %pragma variants c1 c2 cv c3 sm
97 %cost c1,c2 0
99 Stops the script from running for the given number of ticks.
101 void caosVM::c_WAIT() {
102 VM_VERIFY_SIZE(1)
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;
111 return;
113 startBlocking(new blockUntilTime(ticks));
117 STOP (command)
118 %status maybe
119 %pragma stackdelta any
120 %pragma variants c1 c2 cv c3 sm
122 Aborts the script.
124 void caosVM::c_STOP() {
125 VM_VERIFY_SIZE(0)
126 stop();
130 SCRX (command) family (integer) genus (integer) species (integer) event (integer)
131 %status maybe
132 %pragma variants c1 c2 cv c3 sm
134 Deletes the event script in question from the scriptoruium.
136 void caosVM::c_SCRX() {
137 VM_VERIFY_SIZE(4)
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);
154 CODE (integer)
155 %status maybe
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() {
161 valid_agent(targ);
162 int res;
163 if (targ->vm && targ->vm->currentscript)
164 res = targ->vm->currentscript->scrp;
165 else
166 res = -1;
168 result.setInt(res);
172 CODF (integer)
173 %status maybe
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() {
179 valid_agent(targ);
180 int res;
181 if (targ->vm && targ->vm->currentscript)
182 res = targ->vm->currentscript->fmly;
183 else
184 res = -1;
186 result.setInt(res);
190 CODG (integer)
191 %status maybe
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() {
197 valid_agent(targ);
198 int res;
199 if (targ->vm && targ->vm->currentscript)
200 res = targ->vm->currentscript->gnus;
201 else
202 res = -1;
204 result.setInt(res);
208 CODS (integer)
209 %status maybe
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() {
215 valid_agent(targ);
216 int res;
217 if (targ->vm && targ->vm->currentscript)
218 res = targ->vm->currentscript->spcs;
219 else
220 res = -1;
222 result.setInt(res);
226 JECT (command) file (string) flags (integer)
227 %status stub
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)
236 // TODO
240 SORQ (integer) family (integer) genus (integer) species (integer) event (integer)
241 %status maybe
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);
254 /* vim: set noet: */