5 * Created by Alyssa Milburn on Tue May 25 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.
26 #include <boost/format.hpp>
34 OUTX (command) val (string)
37 Prints the given string on the output stream, after first quoting it and transforming
38 escapes in the string to quoted escapes.
40 void caosVM::c_OUTX() {
43 if (!outputstream
) return;
45 std::string oh
= "\"";
47 for (unsigned int i
= 0; i
< val
.size(); i
++) {
49 case '\r': oh
+= "\\r"; break;
50 case '\n': oh
+= "\\n"; break;
51 case '\t': oh
+= "\\t"; break;
52 case '\\': oh
+= "\\\\"; break;
53 case '"': oh
+= "\\\""; break;
54 case '\'': oh
+= "\\'"; break;
55 default: oh
+= val
[i
];
59 *outputstream
<< oh
<< "\"";
63 OUTS (command) val (string)
67 Prints the given string to the output stream. Does nothing when run inside a script.
69 void caosVM::c_OUTS() {
73 if (!outputstream
) return;
79 DDE: PUTS (command) val (bareword)
81 %pragma variants c1 c2
82 %pragma implementation caosVM::c_OUTS
86 OUTV (command) val (decimal)
90 Prints the given decimal value to the ouput stream. Does nothing when run inside a script.
92 void caosVM::c_OUTV() {
96 if (!outputstream
) return;
99 *outputstream
<< boost::format("%0.06f") % val
.getFloat();
100 } else if (val
.hasInt()) {
101 *outputstream
<< val
.getInt();
102 } else if (val
.hasVector()) {
103 const Vector
<float> &v
= val
.getVector();
104 *outputstream
<< boost::format("(%0.6f, %0.6f)") % v
.x
% v
.y
;
105 } else throw badParamException();
109 DDE: PUTV (command) val (integer)
111 %pragma variants c1 c2
112 %pragma implementation caosVM::c_OUTV
116 GAME (variable) name (string)
119 Returns the game variable with the given name.
121 CAOS_LVALUE(GAME
, VM_PARAM_STRING(name
),
122 world
.variables
[name
],
123 world
.variables
[name
] = newvalue
127 EAME (variable) name (anything)
130 Returns the non-persistent game variable with the given name.
132 // XXX: should this be a string argument?
133 CAOS_LVALUE(EAME
, VM_PARAM_VALUE(name
),
134 engine
.eame_variables
[name
],
135 engine
.eame_variables
[name
] = newvalue
139 DELG (command) name (string)
142 Deletes the game variable with the given name.
144 void caosVM::c_DELG() {
145 VM_PARAM_STRING(name
)
147 std::map
<std::string
, caosVar
>::iterator i
= world
.variables
.find(name
);
148 if (i
!= world
.variables
.end())
149 world
.variables
.erase(i
);
153 SCRP (command) family (integer) genus (integer) species (integer) event (integer)
155 %pragma variants c1 c2 cv c3 sm
157 Marks the beginning of a normal script applying to the agent with the given classifier
160 void caosVM::c_SCRP() {
167 %pragma variants c2 cv c3 sm
169 Marks the beginning of a removal script.
171 void caosVM::c_RSCR() {
178 %pragma variants c2 cv c3 sm
180 Marks the beginning of an installer script.
182 void caosVM::c_ISCR() {
190 %pragma variants c1 c2 cv c3 sm
192 Marks the end of a script.
194 void caosVM::c_ENDM() {
202 Restore all game variables to their saved or default values.
204 void caosVM::c_RGAM() {}
210 Returns whether the lawn was cut last Sunday or not, in theory.
211 How the C2E engine determines this, and whose lawn, exactly, and whether or not it takes into account the fact that the lawn may have been mown on Saturday or Friday, and whether it will cut you any slack if it's winter and the grass isn't growing much, is currently unknown.
213 In openc2e, currently a no-op (ie, the lawn is never, ever cut properly).
215 void caosVM::v_MOWS() {
216 result
.setInt(0); // We're too busy coding to mow the lawn.
223 Returns the minor version number of the engine.
225 void caosVM::v_VMNR() {
233 Returns the major version number of the engine.
235 void caosVM::v_VMJR() {
240 VRSN (command) required (integer)
242 %pragma variants c1 c2
244 Stop running this script unless VRSN is equal to or greater than the specified value.
246 void caosVM::c_VRSN() {
247 VM_PARAM_INTEGER(required
)
249 // TODO: is this good for c1? which version is c2?
250 int thisversion
= (engine
.version
== 1) ? 2 : 0;
252 if (thisversion
< required
) {
253 std::cout
<< "Warning: stopping script due to version requirement of " << required
<< " (we are reporting a version of " << thisversion
<< ")" << std::endl
;
261 %pragma variants c1 c2
263 Return the build version number of the engine.
265 void caosVM::v_VRSN() {
266 // TODO: is this good for c1? which version is c2?
267 int thisversion
= (engine
.version
== 1) ? 2 : 0;
269 result
.setInt(thisversion
);
273 WOLF (integer) andmask (integer) eormask (integer)
276 This returns/sets some engine settings which are useful for 'wolfing runs', among other things.
277 Set andmask for the information you want returned, and eormask for the information you want changed.
279 1 is for display rendering (turn it off to speed up the game)
280 2 is for running ticks as fast as possible, rather than according to BUZZ
281 4 is for refreshing the display (when display rendering is turned off, this will update the display at the end of the tick)
282 (note that 4 is unset by the engine when the display is refreshed)
285 void caosVM::v_WOLF() {
286 VM_PARAM_INTEGER(eormask
)
287 VM_PARAM_INTEGER(andmask
)
289 if (eormask
& 1) engine
.dorendering
= !engine
.dorendering
;
290 if (eormask
& 2) engine
.fastticks
= !engine
.fastticks
;
291 if (eormask
& 4) engine
.refreshdisplay
= !engine
.refreshdisplay
;
292 if (eormask
& 8) world
.autokill
= !world
.autokill
;
295 if (andmask
& 1 && engine
.dorendering
) r
+= 1;
296 if (andmask
& 2 && engine
.fastticks
) r
+= 2;
297 if (andmask
& 4 && engine
.refreshdisplay
) r
+= 4;
298 if (andmask
& 8 && world
.autokill
) r
+= 8;
306 void caosVM::v_LANG() {
307 result
.setString("en");
311 TOKN (integer) token (bareword)
313 %pragma variants c1 c2
315 void caosVM::v_TOKN() {
316 VM_PARAM_STRING(token
)
318 caos_assert(token
.size() == 4);
320 int *data
= (int *)token
.c_str();
321 result
.setInt(*data
);
325 GAME (variable) category (integer) variable (integer)
328 %pragma implementation caosVM::v_GAME_c2
331 VM_PARAM_INTEGER(variable
) VM_PARAM_INTEGER(category
),
335 #include <boost/filesystem/operations.hpp>
342 Returns a list of the data directories available, separated with \n. Remember that the last one is the working directory.
344 void caosVM::v_OC2E_DDIR() {
347 for (std::vector
<boost::filesystem::path
>::iterator i
= world
.data_directories
.begin(); i
!= world
.data_directories
.end(); i
++) {
348 boost::filesystem::path
&p
= *i
;
349 d
= d
+ boost::filesystem::system_complete(p
).native_file_string() + "\n";
356 SYS: CMND (command) menuid (integer)
358 %pragma variants c1 c2
360 Do something by providing a menu ID from the original Creatures 1 or Creatures 2 engines. This is obviously limited to the IDs that openc2e is aware of.
362 void caosVM::c_SYS_CMND() {
363 VM_PARAM_INTEGER(menuid
)