2 * OpenBOR - http://www.LavaLit.com
3 * -----------------------------------------------------------------------
4 * Licensed under the BSD licence, see LICENSE in OpenBOR root for details.
6 * Copyright (c) 2004 - 2011 OpenBOR Team
9 /* This file include all script methods used by openbor engine
11 Notice: Make sure to null *pretvar when you about to return E_FAIL,
12 Or the engine might crash.
14 Notice: Every new ScriptVariant must be initialized when you first alloc it by
15 ScriptVariant_Init immediately, memset it all to zero should also work by now,
16 unless VT_EMPTY is changed.
18 If you want to reset a ScriptVariant to empty, you must use ScriptVariant_Clear instead.
19 ScriptVariant_Init or memset must be called only ONCE, later you should use ScriptVariant_Clear.
21 Besure to call ScriptVariant_Clear if you want to use free to delete those variants.
23 If you want to copy a ScriptVariant from another, use ScriptVariant_Copy instead of assignment,
24 not because it is faster, but this method is neccessary for string types.
26 If you want to change types of an ScriptVariant, use ScriptVariant_ChangeType, don't change vt directly.
31 #include "openborscript.h"
35 #include "ImportCache.h"
39 // Define macro for string mapping
40 #define MAPSTRINGS(VAR, LIST, MAXINDEX, FAILMSG) \
41 if(VAR->vt == VT_STR) { \
42 propname = (char*)StrCache_Get(VAR->strVal); \
43 prop = searchList(LIST, propname, MAXINDEX); \
45 ScriptVariant_ChangeType(VAR, VT_INTEGER); \
47 } else { printf(FAILMSG, propname); } \
50 extern int MAX_WALL_HEIGHT
;
51 extern int current_palette
;
52 extern s_player player
[4];
53 extern s_savedata savedata
;
54 extern s_savelevel savelevel
[MAX_DIFFICULTIES
];
55 extern s_savescore savescore
;
56 extern s_level
*level
;
61 extern char musicname
[128];
62 extern float musicfade
[2];
64 extern u32 musicoffset
;
65 extern int models_cached
;
67 extern unsigned char *blendings
[MAX_BLENDINGS
];
68 extern int current_palette
;
69 s_variantnode
**global_var_list
= NULL
;
70 Script
*pcurrentscript
= NULL
; //used by local script functions
72 static List scriptheap
;
73 static s_spawn_entry spawnentry
;
74 static s_drawmethod drawmethod
;
76 int max_global_var_index
= -1;
78 ScriptVariant
*indexed_var_list
= NULL
;
79 int max_global_vars
= MAX_GLOBAL_VAR
;
80 int max_indexed_vars
= 0;
81 int max_entity_vars
= 0;
82 int max_script_vars
= 0;
85 //this function should be called before all script methods, for once
86 void Script_Global_Init() {
89 if(max_global_vars
> 0) {
90 psize
= (sizeof(s_variantnode
*) * max_global_vars
);
91 csize
= psize
+ (sizeof(s_variantnode
) * max_global_vars
);
92 global_var_list
= malloc(csize
);
93 assert(global_var_list
!= NULL
);
94 memset(global_var_list
, 0, csize
);
95 for(i
= 0; i
< max_global_vars
; i
++) {
97 (s_variantnode
*) (((char *) global_var_list
) + psize
+ (i
* sizeof(s_variantnode
)));
101 for(i=0; i<max_global_vars; i++)
103 global_var_list[i] = malloc(sizeof(s_variantnode));
104 assert(global_var_list[i] != NULL);
105 memset(global_var_list[i], 0, sizeof(s_variantnode));
107 max_global_var_index
= -1;
108 memset(&spawnentry
, 0, sizeof(s_spawn_entry
)); //clear up the spawn entry
109 drawmethod
= plainmethod
;
111 if(max_indexed_vars
> 0) {
112 csize
= sizeof(ScriptVariant
) * (max_indexed_vars
+ 1);
113 indexed_var_list
= (ScriptVariant
*) malloc(csize
);
114 assert(indexed_var_list
!= NULL
);
115 memset(indexed_var_list
, 0, csize
);
117 List_Init(&theFunctionList
);
118 Script_LoadSystemFunctions();
119 List_Init(&scriptheap
);
123 //this function should only be called when the engine is shutting down
124 void Script_Global_Clear() {
126 List_Clear(&theFunctionList
);
127 // dump all un-freed variants
128 size
= List_GetSize(&scriptheap
);
130 printf("\nWarning: %d script variants are not freed, dumping...\n", size
);
131 for(i
= 0, List_Reset(&scriptheap
); i
< size
; List_GotoNext(&scriptheap
), i
++) {
132 printf("%s\n", List_GetName(&scriptheap
));
133 free(List_Retrieve(&scriptheap
));
135 List_Clear(&scriptheap
);
136 // clear the global list
137 if(global_var_list
) {
138 for(i
= 0; i
< max_global_vars
; i
++) {
139 if(global_var_list
[i
] != NULL
) {
140 ScriptVariant_Clear(&(global_var_list
[i
]->value
));
141 //free(global_var_list[i]);
143 //global_var_list[i] = NULL;
145 free(global_var_list
);
146 global_var_list
= NULL
;
148 if(indexed_var_list
) {
149 for(i
= 0; i
< max_indexed_vars
; i
++)
150 ScriptVariant_Clear(indexed_var_list
+ i
);
151 free(indexed_var_list
);
153 indexed_var_list
= NULL
;
154 max_global_var_index
= -1;
155 memset(&spawnentry
, 0, sizeof(s_spawn_entry
)); //clear up the spawn entry
161 ScriptVariant
*Script_Get_Global_Variant(char *theName
) {
164 if(!theName
|| !theName
[0])
167 for(i
= 0; i
<= max_global_var_index
; i
++) {
168 if(!global_var_list
[i
]->owner
&& strcmp(theName
, global_var_list
[i
]->key
) == 0)
169 return &(global_var_list
[i
]->value
);
176 int _set_var(char *theName
, ScriptVariant
* var
, Script
* owner
) {
178 s_variantnode
*tempnode
;
179 if(!theName
[0] || !theName
|| (owner
&& !owner
->initialized
))
182 for(i
= 0; i
<= max_global_var_index
; i
++) {
183 if(global_var_list
[i
]->owner
== owner
&& !strcmp(theName
, global_var_list
[i
]->key
)) {
184 if(var
->vt
!= VT_EMPTY
)
185 ScriptVariant_Copy(&(global_var_list
[i
]->value
), var
);
186 else // set to null, so remove this value
188 /// re-adjust bounds, swap with last node
189 if(i
!= max_global_var_index
) {
190 tempnode
= global_var_list
[i
];
191 global_var_list
[i
] = global_var_list
[max_global_var_index
];
192 global_var_list
[max_global_var_index
] = tempnode
;
194 max_global_var_index
--;
199 if(var
->vt
== VT_EMPTY
)
201 // all slots are taken
202 if(max_global_var_index
>= max_global_vars
- 1)
204 // so out of bounds, find another slot
206 ++max_global_var_index
;
207 ScriptVariant_Copy(&(global_var_list
[max_global_var_index
]->value
), var
);
208 global_var_list
[max_global_var_index
]->owner
= owner
;
209 strcpy(global_var_list
[max_global_var_index
]->key
, theName
);
214 int Script_Set_Global_Variant(char *theName
, ScriptVariant
* var
) {
215 return _set_var(theName
, var
, NULL
);
218 void Script_Local_Clear() {
220 s_variantnode
*tempnode
;
223 for(i
= 0; i
<= max_global_var_index
; i
++) {
224 if(global_var_list
[i
]->owner
== pcurrentscript
) {
225 if(i
!= max_global_var_index
) {
226 tempnode
= global_var_list
[i
];
227 global_var_list
[i
] = global_var_list
[max_global_var_index
];
228 global_var_list
[max_global_var_index
] = tempnode
;
230 max_global_var_index
--;
233 if(pcurrentscript
->vars
)
234 for(i
= 0; i
< max_script_vars
; i
++)
235 ScriptVariant_Clear(pcurrentscript
->vars
+ i
);
239 ScriptVariant
*Script_Get_Local_Variant(char *theName
) {
242 if(!pcurrentscript
|| !pcurrentscript
->initialized
|| !theName
|| !theName
[0])
245 for(i
= 0; i
<= max_global_var_index
; i
++) {
246 if(global_var_list
[i
]->owner
== pcurrentscript
&& strcmp(theName
, global_var_list
[i
]->key
) == 0)
247 return &(global_var_list
[i
]->value
);
253 int Script_Set_Local_Variant(char *theName
, ScriptVariant
* var
) {
256 return _set_var(theName
, var
, pcurrentscript
);
259 Script
*alloc_script() {
261 Script
*pscript
= (Script
*) malloc(sizeof(Script
));
262 memset(pscript
, 0, sizeof(Script
));
263 if(max_script_vars
> 0) {
264 pscript
->vars
= (ScriptVariant
*) malloc(sizeof(ScriptVariant
) * max_script_vars
);
265 for(i
= 0; i
< max_script_vars
; i
++)
266 ScriptVariant_Init(pscript
->vars
+ i
);
271 void Script_Init(Script
* pscript
, char *theName
, int first
) {
274 memset(pscript
, 0, sizeof(Script
));
275 if(max_script_vars
> 0) {
276 pscript
->vars
= (ScriptVariant
*) malloc(sizeof(ScriptVariant
) * max_script_vars
);
277 for(i
= 0; i
< max_script_vars
; i
++)
278 ScriptVariant_Init(pscript
->vars
+ i
);
281 if(!theName
|| !theName
[0])
282 return; // if no name specified, only alloc the variants
283 pcurrentscript
= pscript
; //used by local script functions
284 pscript
->pinterpreter
= (Interpreter
*) malloc(sizeof(Interpreter
));
285 Interpreter_Init(pscript
->pinterpreter
, theName
, &theFunctionList
);
286 pscript
->interpreterowner
= 1; // this is the owner, important
287 pscript
->initialized
= 1;
291 void Script_Copy(Script
* pdest
, Script
* psrc
, int localclear
) {
292 if(!psrc
->initialized
)
294 if(pdest
->initialized
)
295 Script_Clear(pdest
, localclear
);
296 pdest
->pinterpreter
= psrc
->pinterpreter
;
297 pdest
->interpreterowner
= 0; // dont own it
298 pdest
->initialized
= psrc
->initialized
; //just copy, it should be 1
301 void Script_Clear(Script
* pscript
, int localclear
) {
304 ScriptVariant
*pvars
;
305 if(localclear
== 2 && pscript
->vars
) {
306 for(i
= 0; i
< max_script_vars
; i
++) {
307 ScriptVariant_Clear(pscript
->vars
+ i
);
310 pscript
->vars
= NULL
;
312 if(!pscript
->initialized
)
314 temp
= pcurrentscript
;
315 pcurrentscript
= pscript
; //used by local script functions
316 //if it is the owner, free the interpreter
317 if(pscript
->pinterpreter
&& pscript
->interpreterowner
) {
318 Interpreter_Clear(pscript
->pinterpreter
);
319 free(pscript
->pinterpreter
);
320 pscript
->pinterpreter
= NULL
;
323 Script_Local_Clear();
324 pvars
= pscript
->vars
; // in game clear(localclear!=2) just keep this value
325 memset(pscript
, 0, sizeof(Script
));
326 pscript
->vars
= pvars
; // copy it back
327 pcurrentscript
= temp
;
330 //append part of the script
331 //Because the script might not be initialized in 1 time.
332 int Script_AppendText(Script
* pscript
, char *text
, char *path
) {
335 pcurrentscript
= pscript
; //used by local script functions
337 Interpreter_Reset(pscript
->pinterpreter
);
339 success
= SUCCEEDED(Interpreter_ParseText(pscript
->pinterpreter
, text
, 1, path
));
344 //return name of function from pointer to function
345 const char *Script_GetFunctionName(void *functionRef
) {
346 if(functionRef
== ((void *) system_isempty
))
348 else if(functionRef
== ((void *) system_NULL
))
350 else if(functionRef
== ((void *) system_rand
))
352 else if(functionRef
== ((void *) system_maxglobalvarindex
))
353 return "maxglobalvarindex";
354 else if(functionRef
== ((void *) system_getglobalvar
))
355 return "getglobalvar";
356 else if(functionRef
== ((void *) system_setglobalvar
))
357 return "setglobalvar";
358 else if(functionRef
== ((void *) system_getlocalvar
))
359 return "getlocalvar";
360 else if(functionRef
== ((void *) system_setlocalvar
))
361 return "setlocalvar";
362 else if(functionRef
== ((void *) system_clearglobalvar
))
363 return "clearglobalvar";
364 else if(functionRef
== ((void *) system_clearindexedvar
))
365 return "clearindexedvar";
366 else if(functionRef
== ((void *) system_clearlocalvar
))
367 return "clearlocalvar";
368 else if(functionRef
== ((void *) system_free
))
370 else if(functionRef
== ((void *) openbor_systemvariant
))
371 return "openborvariant";
372 else if(functionRef
== ((void *) openbor_changesystemvariant
))
373 return "changeopenborvariant";
374 else if(functionRef
== ((void *) openbor_drawstring
))
376 else if(functionRef
== ((void *) openbor_drawstringtoscreen
))
377 return "drawstringtoscreen";
378 else if(functionRef
== ((void *) openbor_log
))
380 else if(functionRef
== ((void *) openbor_drawbox
))
382 else if(functionRef
== ((void *) openbor_drawboxtoscreen
))
383 return "drawboxtoscreen";
384 else if(functionRef
== ((void *) openbor_drawline
))
386 else if(functionRef
== ((void *) openbor_drawlinetoscreen
))
387 return "drawlinetoscreen";
388 else if(functionRef
== ((void *) openbor_drawsprite
))
390 else if(functionRef
== ((void *) openbor_drawspritetoscreen
))
391 return "drawspritetoscreen";
392 else if(functionRef
== ((void *) openbor_drawdot
))
394 else if(functionRef
== ((void *) openbor_drawdottoscreen
))
395 return "drawdottoscreen";
396 else if(functionRef
== ((void *) openbor_drawscreen
))
398 else if(functionRef
== ((void *) openbor_changeplayerproperty
))
399 return "changeplayerproperty";
400 else if(functionRef
== ((void *) openbor_changeentityproperty
))
401 return "changeentityproperty";
402 else if(functionRef
== ((void *) openbor_getplayerproperty
))
403 return "getplayerproperty";
404 else if(functionRef
== ((void *) openbor_getentityproperty
))
405 return "getentityproperty";
406 else if(functionRef
== ((void *) openbor_tossentity
))
408 else if(functionRef
== ((void *) openbor_clearspawnentry
))
409 return "clearspawnentry";
410 else if(functionRef
== ((void *) openbor_setspawnentry
))
411 return "setspawnentry";
412 else if(functionRef
== ((void *) openbor_spawn
))
414 else if(functionRef
== ((void *) openbor_projectile
))
416 else if(functionRef
== ((void *) openbor_transconst
))
417 return "openborconstant";
418 else if(functionRef
== ((void *) openbor_playmusic
))
420 else if(functionRef
== ((void *) openbor_fademusic
))
422 else if(functionRef
== ((void *) openbor_setmusicvolume
))
423 return "setmusicvolume";
424 else if(functionRef
== ((void *) openbor_setmusictempo
))
425 return "setmusictempo";
426 else if(functionRef
== ((void *) openbor_pausemusic
))
428 else if(functionRef
== ((void *) openbor_playsample
))
430 else if(functionRef
== ((void *) openbor_loadsample
))
432 else if(functionRef
== ((void *) openbor_unloadsample
))
433 return "unloadsample";
434 else if(functionRef
== ((void *) openbor_fadeout
))
436 else if(functionRef
== ((void *) openbor_playerkeys
))
438 else if(functionRef
== ((void *) openbor_changepalette
))
439 return "changepalette";
440 else if(functionRef
== ((void *) openbor_damageentity
))
441 return "damageentity";
442 else if(functionRef
== ((void *) openbor_killentity
))
444 else if(functionRef
== ((void *) openbor_findtarget
))
446 else if(functionRef
== ((void *) openbor_checkrange
))
448 else if(functionRef
== ((void *) openbor_gettextobjproperty
))
449 return "gettextobjproperty";
450 else if(functionRef
== ((void *) openbor_changetextobjproperty
))
451 return "changetextobjproperty";
452 else if(functionRef
== ((void *) openbor_settextobj
))
454 else if(functionRef
== ((void *) openbor_cleartextobj
))
455 return "cleartextobj";
456 else if(functionRef
== ((void *) openbor_getbglayerproperty
))
457 return "getbglayerproperty";
458 else if(functionRef
== ((void *) openbor_changebglayerproperty
))
459 return "changebglayerproperty";
460 else if(functionRef
== ((void *) openbor_getfglayerproperty
))
461 return "getfglayerproperty";
462 else if(functionRef
== ((void *) openbor_changefglayerproperty
))
463 return "changefglayerproperty";
464 else if(functionRef
== ((void *) openbor_getlevelproperty
))
465 return "getlevelproperty";
466 else if(functionRef
== ((void *) openbor_changelevelproperty
))
467 return "changelevelproperty";
468 else if(functionRef
== ((void *) openbor_checkhole
))
470 else if(functionRef
== ((void *) openbor_checkwall
))
472 else if(functionRef
== ((void *) openbor_checkplatformbelow
))
473 return "checkplatformbelow";
474 else if(functionRef
== ((void *) openbor_openfilestream
))
475 return "openfilestream";
476 else if(functionRef
== ((void *) openbor_getfilestreamline
))
477 return "getfilestreamline";
478 else if(functionRef
== ((void *) openbor_getfilestreamargument
))
479 return "getfilestreamargument";
480 else if(functionRef
== ((void *) openbor_filestreamnextline
))
481 return "filestreamnextline";
482 else if(functionRef
== ((void *) openbor_getfilestreamposition
))
483 return "getfilestreamposition";
484 else if(functionRef
== ((void *) openbor_setfilestreamposition
))
485 return "setfilestreamposition";
486 else if(functionRef
== ((void *) openbor_filestreamappend
))
487 return "filestreamappend";
488 else if(functionRef
== ((void *) openbor_createfilestream
))
489 return "createfilestream";
490 else if(functionRef
== ((void *) openbor_savefilestream
))
491 return "savefilestream";
492 else if(functionRef
== ((void *) openbor_getindexedvar
))
493 return "getindexedvar";
494 else if(functionRef
== ((void *) openbor_setindexedvar
))
495 return "setindexedvar";
496 else if(functionRef
== ((void *) openbor_getscriptvar
))
497 return "getscriptvar";
498 else if(functionRef
== ((void *) openbor_setscriptvar
))
499 return "setscriptvar";
500 else if(functionRef
== ((void *) openbor_getentityvar
))
501 return "getentityvar";
502 else if(functionRef
== ((void *) openbor_setentityvar
))
503 return "setentityvar";
504 else if(functionRef
== ((void *) openbor_jumptobranch
))
505 return "jumptobranch";
506 else if(functionRef
== ((void *) openbor_changelight
))
507 return "changelight";
508 else if(functionRef
== ((void *) openbor_changeshadowcolor
))
509 return "changeshadowcolor";
510 else if(functionRef
== ((void *) openbor_bindentity
))
512 else if(functionRef
== ((void *) openbor_allocscreen
))
513 return "allocscreen";
514 else if(functionRef
== ((void *) openbor_clearscreen
))
515 return "clearscreen";
516 else if(functionRef
== ((void *) openbor_setdrawmethod
))
517 return "setdrawmethod";
518 else if(functionRef
== ((void *) openbor_updateframe
))
519 return "updateframe";
520 else if(functionRef
== ((void *) openbor_performattack
))
521 return "performattack";
522 else if(functionRef
== ((void *) openbor_setidle
))
524 else if(functionRef
== ((void *) openbor_getentity
))
526 else if(functionRef
== ((void *) openbor_loadmodel
))
528 else if(functionRef
== ((void *) openbor_loadsprite
))
530 else if(functionRef
== ((void *) openbor_playgif
))
532 else if(functionRef
== ((void *) openbor_strinfirst
))
534 else if(functionRef
== ((void *) openbor_strinlast
))
536 else if(functionRef
== ((void *) openbor_strleft
))
538 else if(functionRef
== ((void *) openbor_strlength
))
540 else if(functionRef
== ((void *) openbor_strright
))
542 else if(functionRef
== ((void *) openbor_getmodelproperty
))
543 return "getmodelproperty";
544 else if(functionRef
== ((void *) openbor_changemodelproperty
))
545 return "changemodelproperty";
546 else if(functionRef
== ((void *) openbor_rgbcolor
))
549 return "<unknown function>";
552 //return string mapping function corresponding to a given function
553 void *Script_GetStringMapFunction(void *functionRef
) {
554 if(functionRef
== ((void *) openbor_systemvariant
))
555 return (void *) mapstrings_systemvariant
;
556 else if(functionRef
== ((void *) openbor_changesystemvariant
))
557 return (void *) mapstrings_changesystemvariant
;
558 else if(functionRef
== ((void *) openbor_getentityproperty
))
559 return (void *) mapstrings_getentityproperty
;
560 else if(functionRef
== ((void *) openbor_changeentityproperty
))
561 return (void *) mapstrings_changeentityproperty
;
562 else if(functionRef
== ((void *) openbor_getplayerproperty
))
563 return (void *) mapstrings_getplayerproperty
;
564 else if(functionRef
== ((void *) openbor_changeplayerproperty
))
565 return (void *) mapstrings_changeplayerproperty
;
566 else if(functionRef
== ((void *) openbor_setspawnentry
))
567 return (void *) mapstrings_setspawnentry
;
568 else if(functionRef
== ((void *) openbor_transconst
))
569 return (void *) mapstrings_transconst
;
570 else if(functionRef
== ((void *) openbor_playerkeys
))
571 return (void *) mapstrings_playerkeys
;
572 else if(functionRef
== ((void *) openbor_gettextobjproperty
))
573 return (void *) mapstrings_gettextobjproperty
;
574 else if(functionRef
== ((void *) openbor_changetextobjproperty
))
575 return (void *) mapstrings_changetextobjproperty
;
576 else if(functionRef
== ((void *) openbor_getbglayerproperty
))
577 return (void *) mapstrings_getbglayerproperty
;
578 else if(functionRef
== ((void *) openbor_changebglayerproperty
))
579 return (void *) mapstrings_changebglayerproperty
;
580 else if(functionRef
== ((void *) openbor_getfglayerproperty
))
581 return (void *) mapstrings_getfglayerproperty
;
582 else if(functionRef
== ((void *) openbor_changefglayerproperty
))
583 return (void *) mapstrings_changefglayerproperty
;
588 /* Replace string constants with enum constants at compile time to speed up
590 int Script_MapStringConstants(Script
* pscript
) {
591 Interpreter
*pinterpreter
= pscript
->pinterpreter
;
592 Instruction
*pInstruction
, *pInstruction2
;
593 ScriptVariant
**params
;
594 //ScriptVariant* var;
595 void (*pMapstrings
) (ScriptVariant
**, int);
596 int i
, j
, k
, size
, paramCount
;
598 size
= pinterpreter
->theSolidListOfInstructionList
->size
;
599 for(i
= 0; i
< size
; i
++) {
600 pInstruction
= (Instruction
*) (pinterpreter
->theSolidListOfInstructionList
->solidlist
[i
]);
601 if(pInstruction
->functionRef
) {
603 pInstruction
->theSolidListOfRefList
? (ScriptVariant
**) pInstruction
->
604 theSolidListOfRefList
->solidlist
: NULL
;
605 paramCount
= (int) pInstruction
->theRef
->lVal
;
607 // Get the pointer to the correct mapstrings function, if one exists.
608 pMapstrings
= Script_GetStringMapFunction(pInstruction
->functionRef
);
610 // Call the mapstrings function.
611 pMapstrings(params
, paramCount
);
613 // Find the instruction containing each constant and update its value.
614 for(j
= 0; j
< paramCount
; j
++) {
615 for(k
= i
; k
> 0; k
--) {
617 (Instruction
*) (pinterpreter
->theSolidListOfInstructionList
->
619 if(pInstruction2
->theVal2
== params
[j
]) {
620 ScriptVariant_Copy(pInstruction2
->theVal
,
621 pInstruction2
->theVal2
);
635 // replaces the entire instruction list with a new instruction list after optimization
636 int Script_ReplaceInstructionList(Interpreter
* pInterpreter
, List
* newList
) {
637 int i
, j
, newSize
= List_GetSize(newList
);
638 Instruction
*pInstruction
, *pTarget
;
639 Instruction
**oldList
= (Instruction
**) pInterpreter
->theSolidListOfInstructionList
->solidlist
;
640 SolidList
*nl
= SolidListFromList(newList
);
644 for(i
= 0; i
< newSize
; i
++) {
645 pInstruction
= (Instruction
*) nl
->solidlist
[i
];
646 if(pInstruction
->theJumpTargetIndex
>= 0) {
647 pTarget
= (Instruction
*) oldList
[pInstruction
->theJumpTargetIndex
];
648 for(j
= 0; j
< newSize
; j
++) {
649 if(nl
->solidlist
[j
] == pTarget
) {
650 pInstruction
->theJumpTargetIndex
= j
;
654 // if the jump target isn't found, it must have been removed in an optimization - whoops!
656 Instruction_ToString(pTarget
, buf
);
657 printf("Error: jump target %i (%s) not found - overzealous optimization!\n",
658 pInstruction
->theJumpTargetIndex
, buf
);
664 // replace new list with old list
665 List_Clear(&(pInterpreter
->theInstructionList
));
666 freeSolidList(pInterpreter
->theSolidListOfInstructionList
);
667 pInterpreter
->theSolidListOfInstructionList
= nl
;
672 // prints lots of debugging stuff about optimizations that can be made
673 void Script_LowerConstants(Script
* pscript
) {
674 Interpreter
*pinterpreter
= pscript
->pinterpreter
;
675 Instruction
*pInstruction
, *pInstruction2
;
676 List
*newInstructionList
= malloc(sizeof(List
));
679 List_Init(newInstructionList
);
681 size
= pinterpreter
->theSolidListOfInstructionList
->size
;
683 for(i
= 0; i
< size
; i
++) {
684 pInstruction
= (Instruction
*) (pinterpreter
->theSolidListOfInstructionList
->solidlist
[i
]);
685 if(pInstruction
->OpCode
== DATA
) {
687 for(j
= 0; j
< size
; j
++) {
689 (Instruction
*) (pinterpreter
->theSolidListOfInstructionList
->solidlist
[j
]);
690 if(pInstruction2
->OpCode
== LOAD
&& pInstruction2
->theRef
== pInstruction
->theVal
)
693 //printf("Variable declared, %i references\n", numRefs, pInstruction->theToken->theSource);
694 //printf("DATA (theVal=0x%08X, theRef=0x%08X)\n", pInstruction->theVal, pInstruction->theRef);
696 List_InsertAfter(newInstructionList
, pInstruction
, NULL
);
698 printf("Unused variable\n");
702 List_InsertAfter(newInstructionList
, pInstruction
, NULL
);
703 #define ISCONST(x) ((x) && ((x->OpCode==CONSTINT)||(x->OpCode==CONSTSTR)||(x->OpCode==CONSTDBL)))
704 // Look for constant binary ops
705 if(pInstruction
->OpCode
== ADD
) {
706 Instruction
*pSrc1
= NULL
, *pSrc2
= NULL
;
707 char buf
[1024], buf2
[1024], buf3
[1024];
708 for(j
= 0; j
< size
; j
++) {
710 (Instruction
*) (pinterpreter
->theSolidListOfInstructionList
->solidlist
[j
]);
711 if(tmp
->theVal
== pInstruction
->theRef
|| tmp
->theVal2
== pInstruction
->theRef
)
713 if(tmp
->theVal
== pInstruction
->theRef2
|| tmp
->theVal2
== pInstruction
->theRef2
)
717 if(ISCONST(pSrc1
) && ISCONST(pSrc2
)) {
718 ScriptVariant
*sum
= ScriptVariant_Add(pSrc1
->theVal2
, pSrc2
->theVal2
);
719 ScriptVariant_ToString(pSrc1
->theVal2
, buf
);
720 ScriptVariant_ToString(pSrc2
->theVal2
, buf2
);
721 ScriptVariant_ToString(sum
, buf3
);
722 //printf("ADD 0x%08X: %s + %s = %s\n", pInstruction, buf, buf2, buf3);
725 else if(pSrc1
&& pSrc2
) {
726 Instruction_ToString(pSrc1
, buf
);
727 Instruction_ToString(pSrc2
, buf2
);
728 printf("ADD 0x%08X: %s + %s\n", pInstruction
, buf
, buf2
);
730 printf("ADD 0x%08X: Non-constant addition?\n");
736 // replace old instruction list with optimized one (TODO: enable when this function actually does optimizations)
737 //Script_ReplaceInstructionList(pinterpreter, &newInstructionList);
740 // detect unused functions in scripts (to save memory)
741 int Script_DetectUnusedFunctions(Script
* pScript
) {
742 Interpreter
*pInterpreter
= pScript
->pinterpreter
;
743 Instruction
*pInstruction
, *pInstruction2
, **instructionList
=
744 (Instruction
**) pInterpreter
->theSolidListOfInstructionList
->solidlist
;
745 List newInstructionList
;
746 int i
, size
= List_GetSize(&(pInterpreter
->theInstructionList
));
749 List_Init(&newInstructionList
);
751 for(i
= 0; i
< size
; i
++) {
752 pInstruction
= instructionList
[i
];
753 // detect function declarations (FIXME: should have an opcode for function declarations other than NOOP)
754 if(pInstruction
->OpCode
== NOOP
&& pInstruction
->theToken
755 && strlen(pInstruction
->theToken
->theSource
) > 0) {
758 // find all calls to this function
759 for(j
= 0; j
< size
; j
++) {
760 pInstruction2
= instructionList
[j
];
761 if(pInstruction2
->OpCode
== CALL
&& pInstruction2
->theJumpTargetIndex
== i
)
765 if(numCalls
== 0 && strcmp(pInstruction
->theToken
->theSource
, "main") != 0) {
766 printf("Unused function %s()\n", pInstruction
->theToken
->theSource
);
767 while(instructionList
[i
]->OpCode
!= RET
) // skip function without adding to new instruction list
769 free(instructionList
[i
++]);
771 List_Clear(&newInstructionList
);
773 } // this shouldn't happen!
775 free(instructionList
[i
]); // free the final RET instruction too
777 List_InsertAfter(&newInstructionList
, pInstruction
, NULL
);
779 List_InsertAfter(&newInstructionList
, pInstruction
, NULL
);
781 List_InsertAfter(&newInstructionList
, pInstruction
, NULL
);
783 //if(pInstruction->theToken) {free(pInstruction->theToken); pInstruction->theToken=NULL;} // TODO: move somewhere else
786 res
= Script_ReplaceInstructionList(pInterpreter
, &newInstructionList
);
787 List_Clear(&newInstructionList
);
791 //should be called only once after parsing text
792 int Script_Compile(Script
* pscript
) {
794 if(!pscript
|| !pscript
->pinterpreter
)
796 //Interpreter_OutputPCode(pscript->pinterpreter, "code");
797 result
= SUCCEEDED(Interpreter_CompileInstructions(pscript
->pinterpreter
));
799 Script_Clear(pscript
, 1);
800 shutdown(1, "Can't compile script!\n");
802 result
= Script_MapStringConstants(pscript
);
804 Script_Clear(pscript
, 1);
805 shutdown(1, "Can't compile script!\n");
807 //result = Script_DetectUnusedFunctions(pscript);
808 //if(!result) {Script_Clear(pscript, 1);shutdown(1, "Script optimization failed!\n");}
809 //Script_LowerConstants(pscript);
814 int Script_IsInitialized(Script
* pscript
) {
815 if(pscript
&& pscript
->initialized
)
816 pcurrentscript
= pscript
; //used by local script functions
817 return pscript
->initialized
;
821 int Script_Execute(Script
* pscript
) {
823 Script
*temp
= pcurrentscript
;
824 pcurrentscript
= pscript
; //used by local script functions
825 Interpreter_Reset(pscript
->pinterpreter
);
826 result
= (int) SUCCEEDED(Interpreter_EvaluateImmediate(pscript
->pinterpreter
));
827 pcurrentscript
= temp
;
829 shutdown(1, "There's an exception while executing script '%s'.\n",
830 pscript
->pinterpreter
->theSymbolTable
.name
);
834 #ifndef COMPILED_SCRIPT
835 //this method is for debug purpose
836 int Script_Call(Script
* pscript
, char *method
, ScriptVariant
* pretvar
) {
837 pcurrentscript
= pscript
; //used by local script functions
838 Interpreter_Reset(pscript
->pinterpreter
);
839 return (int) SUCCEEDED(Interpreter_Call(pscript
->pinterpreter
, method
, pretvar
));
843 //used by Script_Global_Init
844 void Script_LoadSystemFunctions() {
845 //printf("Loading system script functions....");
846 //load system functions if we need
847 List_Reset(&theFunctionList
);
849 List_InsertAfter(&theFunctionList
, (void *) system_isempty
, "isempty");
850 List_InsertAfter(&theFunctionList
, (void *) system_NULL
, "NULL");
851 List_InsertAfter(&theFunctionList
, (void *) system_rand
, "rand");
852 List_InsertAfter(&theFunctionList
, (void *) system_maxglobalvarindex
, "maxglobalvarindex");
853 List_InsertAfter(&theFunctionList
, (void *) system_getglobalvar
, "getglobalvar");
854 List_InsertAfter(&theFunctionList
, (void *) system_setglobalvar
, "setglobalvar");
855 List_InsertAfter(&theFunctionList
, (void *) system_getlocalvar
, "getlocalvar");
856 List_InsertAfter(&theFunctionList
, (void *) system_setlocalvar
, "setlocalvar");
857 List_InsertAfter(&theFunctionList
, (void *) system_clearglobalvar
, "clearglobalvar");
858 List_InsertAfter(&theFunctionList
, (void *) system_clearindexedvar
, "clearindexedvar");
859 List_InsertAfter(&theFunctionList
, (void *) system_clearlocalvar
, "clearlocalvar");
860 List_InsertAfter(&theFunctionList
, (void *) system_free
, "free");
861 List_InsertAfter(&theFunctionList
, (void *) openbor_systemvariant
, "openborvariant");
862 List_InsertAfter(&theFunctionList
, (void *) openbor_changesystemvariant
, "changeopenborvariant");
863 List_InsertAfter(&theFunctionList
, (void *) openbor_drawstring
, "drawstring");
864 List_InsertAfter(&theFunctionList
, (void *) openbor_drawstringtoscreen
, "drawstringtoscreen");
865 List_InsertAfter(&theFunctionList
, (void *) openbor_log
, "log");
866 List_InsertAfter(&theFunctionList
, (void *) openbor_drawbox
, "drawbox");
867 List_InsertAfter(&theFunctionList
, (void *) openbor_drawboxtoscreen
, "drawboxtoscreen");
868 List_InsertAfter(&theFunctionList
, (void *) openbor_drawline
, "drawline");
869 List_InsertAfter(&theFunctionList
, (void *) openbor_drawlinetoscreen
, "drawlinetoscreen");
870 List_InsertAfter(&theFunctionList
, (void *) openbor_drawsprite
, "drawsprite");
871 List_InsertAfter(&theFunctionList
, (void *) openbor_drawspritetoscreen
, "drawspritetoscreen");
872 List_InsertAfter(&theFunctionList
, (void *) openbor_drawdot
, "drawdot");
873 List_InsertAfter(&theFunctionList
, (void *) openbor_drawdottoscreen
, "drawdottoscreen");
874 List_InsertAfter(&theFunctionList
, (void *) openbor_drawscreen
, "drawscreen");
875 List_InsertAfter(&theFunctionList
, (void *) openbor_changeplayerproperty
, "changeplayerproperty");
876 List_InsertAfter(&theFunctionList
, (void *) openbor_changeentityproperty
, "changeentityproperty");
877 List_InsertAfter(&theFunctionList
, (void *) openbor_getplayerproperty
, "getplayerproperty");
878 List_InsertAfter(&theFunctionList
, (void *) openbor_getentityproperty
, "getentityproperty");
879 List_InsertAfter(&theFunctionList
, (void *) openbor_tossentity
, "tossentity");
880 List_InsertAfter(&theFunctionList
, (void *) openbor_clearspawnentry
, "clearspawnentry");
881 List_InsertAfter(&theFunctionList
, (void *) openbor_setspawnentry
, "setspawnentry");
882 List_InsertAfter(&theFunctionList
, (void *) openbor_spawn
, "spawn");
883 List_InsertAfter(&theFunctionList
, (void *) openbor_projectile
, "projectile");
884 List_InsertAfter(&theFunctionList
, (void *) openbor_transconst
, "openborconstant");
885 List_InsertAfter(&theFunctionList
, (void *) openbor_playmusic
, "playmusic");
886 List_InsertAfter(&theFunctionList
, (void *) openbor_fademusic
, "fademusic");
887 List_InsertAfter(&theFunctionList
, (void *) openbor_setmusicvolume
, "setmusicvolume");
888 List_InsertAfter(&theFunctionList
, (void *) openbor_setmusictempo
, "setmusictempo");
889 List_InsertAfter(&theFunctionList
, (void *) openbor_pausemusic
, "pausemusic");
890 List_InsertAfter(&theFunctionList
, (void *) openbor_playsample
, "playsample");
891 List_InsertAfter(&theFunctionList
, (void *) openbor_loadsample
, "loadsample");
892 List_InsertAfter(&theFunctionList
, (void *) openbor_unloadsample
, "unloadsample");
893 List_InsertAfter(&theFunctionList
, (void *) openbor_fadeout
, "fadeout");
894 List_InsertAfter(&theFunctionList
, (void *) openbor_playerkeys
, "playerkeys");
895 List_InsertAfter(&theFunctionList
, (void *) openbor_changepalette
, "changepalette");
896 List_InsertAfter(&theFunctionList
, (void *) openbor_damageentity
, "damageentity");
897 List_InsertAfter(&theFunctionList
, (void *) openbor_killentity
, "killentity");
898 List_InsertAfter(&theFunctionList
, (void *) openbor_findtarget
, "findtarget");
899 List_InsertAfter(&theFunctionList
, (void *) openbor_checkrange
, "checkrange");
900 List_InsertAfter(&theFunctionList
, (void *) openbor_gettextobjproperty
, "gettextobjproperty");
901 List_InsertAfter(&theFunctionList
, (void *) openbor_changetextobjproperty
, "changetextobjproperty");
902 List_InsertAfter(&theFunctionList
, (void *) openbor_settextobj
, "settextobj");
903 List_InsertAfter(&theFunctionList
, (void *) openbor_cleartextobj
, "cleartextobj");
904 List_InsertAfter(&theFunctionList
, (void *) openbor_getbglayerproperty
, "getbglayerproperty");
905 List_InsertAfter(&theFunctionList
, (void *) openbor_changebglayerproperty
, "changebglayerproperty");
906 List_InsertAfter(&theFunctionList
, (void *) openbor_getfglayerproperty
, "getfglayerproperty");
907 List_InsertAfter(&theFunctionList
, (void *) openbor_changefglayerproperty
, "changefglayerproperty");
908 List_InsertAfter(&theFunctionList
, (void *) openbor_getlevelproperty
, "getlevelproperty");
909 List_InsertAfter(&theFunctionList
, (void *) openbor_changelevelproperty
, "changelevelproperty");
910 List_InsertAfter(&theFunctionList
, (void *) openbor_checkhole
, "checkhole");
911 List_InsertAfter(&theFunctionList
, (void *) openbor_checkwall
, "checkwall");
912 List_InsertAfter(&theFunctionList
, (void *) openbor_checkplatformbelow
, "checkplatformbelow");
913 List_InsertAfter(&theFunctionList
, (void *) openbor_openfilestream
, "openfilestream");
914 List_InsertAfter(&theFunctionList
, (void *) openbor_getfilestreamline
, "getfilestreamline");
915 List_InsertAfter(&theFunctionList
, (void *) openbor_getfilestreamargument
, "getfilestreamargument");
916 List_InsertAfter(&theFunctionList
, (void *) openbor_filestreamnextline
, "filestreamnextline");
917 List_InsertAfter(&theFunctionList
, (void *) openbor_getfilestreamposition
, "getfilestreamposition");
918 List_InsertAfter(&theFunctionList
, (void *) openbor_setfilestreamposition
, "setfilestreamposition");
919 List_InsertAfter(&theFunctionList
, (void *) openbor_filestreamappend
, "filestreamappend");
920 List_InsertAfter(&theFunctionList
, (void *) openbor_createfilestream
, "createfilestream");
921 List_InsertAfter(&theFunctionList
, (void *) openbor_savefilestream
, "savefilestream");
922 List_InsertAfter(&theFunctionList
, (void *) openbor_getindexedvar
, "getindexedvar");
923 List_InsertAfter(&theFunctionList
, (void *) openbor_setindexedvar
, "setindexedvar");
924 List_InsertAfter(&theFunctionList
, (void *) openbor_getscriptvar
, "getscriptvar");
925 List_InsertAfter(&theFunctionList
, (void *) openbor_setscriptvar
, "setscriptvar");
926 List_InsertAfter(&theFunctionList
, (void *) openbor_getentityvar
, "getentityvar");
927 List_InsertAfter(&theFunctionList
, (void *) openbor_setentityvar
, "setentityvar");
928 List_InsertAfter(&theFunctionList
, (void *) openbor_jumptobranch
, "jumptobranch");
929 List_InsertAfter(&theFunctionList
, (void *) openbor_changelight
, "changelight");
930 List_InsertAfter(&theFunctionList
, (void *) openbor_changeshadowcolor
, "changeshadowcolor");
931 List_InsertAfter(&theFunctionList
, (void *) openbor_bindentity
, "bindentity");
932 List_InsertAfter(&theFunctionList
, (void *) openbor_allocscreen
, "allocscreen");
933 List_InsertAfter(&theFunctionList
, (void *) openbor_clearscreen
, "clearscreen");
934 List_InsertAfter(&theFunctionList
, (void *) openbor_setdrawmethod
, "setdrawmethod");
935 List_InsertAfter(&theFunctionList
, (void *) openbor_updateframe
, "updateframe");
936 List_InsertAfter(&theFunctionList
, (void *) openbor_performattack
, "performattack");
937 List_InsertAfter(&theFunctionList
, (void *) openbor_setidle
, "setidle");
938 List_InsertAfter(&theFunctionList
, (void *) openbor_getentity
, "getentity");
939 List_InsertAfter(&theFunctionList
, (void *) openbor_loadmodel
, "loadmodel");
940 List_InsertAfter(&theFunctionList
, (void *) openbor_loadsprite
, "loadsprite");
941 List_InsertAfter(&theFunctionList
, (void *) openbor_playgif
, "playgif");
942 List_InsertAfter(&theFunctionList
, (void *) openbor_strinfirst
, "strinfirst");
943 List_InsertAfter(&theFunctionList
, (void *) openbor_strinlast
, "strinlast");
944 List_InsertAfter(&theFunctionList
, (void *) openbor_strleft
, "strleft");
945 List_InsertAfter(&theFunctionList
, (void *) openbor_strlength
, "strlength");
946 List_InsertAfter(&theFunctionList
, (void *) openbor_strright
, "strright");
947 List_InsertAfter(&theFunctionList
, (void *) openbor_getmodelproperty
, "getmodelproperty");
948 List_InsertAfter(&theFunctionList
, (void *) openbor_changemodelproperty
, "changemodelproperty");
949 List_InsertAfter(&theFunctionList
, (void *) openbor_rgbcolor
, "rgbcolor");
954 //////////////////////////////////////////////////////////
955 //////////// system functions
956 //////////////////////////////////////////////////////////
958 s32
system_isempty(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
963 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
964 (*pretvar
)->lVal
= (s32
) ((varlist
[0])->vt
== VT_EMPTY
);
970 s32
system_NULL(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
971 ScriptVariant_Clear(*pretvar
);
975 s32
system_rand(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
976 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
977 (*pretvar
)->lVal
= (s32
) rand32();
981 //getglobalvar(varname);
982 s32
system_getglobalvar(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
983 ScriptVariant
*ptmpvar
;
984 if(paramCount
!= 1) {
988 if(varlist
[0]->vt
!= VT_STR
) {
989 printf("Function getglobalvar must have a string parameter.\n");
993 ptmpvar
= Script_Get_Global_Variant(StrCache_Get(varlist
[0]->strVal
));
995 ScriptVariant_Copy(*pretvar
, ptmpvar
);
997 ScriptVariant_ChangeType(*pretvar
, VT_EMPTY
);
1001 //maxglobalvarindex();
1002 s32
system_maxglobalvarindex(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
1003 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
1004 (*pretvar
)->lVal
= (s32
) max_global_var_index
;
1008 //setglobalvar(varname, value);
1009 s32
system_setglobalvar(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
1010 if(paramCount
!= 2) {
1014 if(varlist
[0]->vt
!= VT_STR
) {
1015 printf("Function setglobalvar's first parameter must be a string value.\n");
1019 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
1021 (*pretvar
)->lVal
= (s32
) Script_Set_Global_Variant(StrCache_Get(varlist
[0]->strVal
), (varlist
[1]));
1026 //getlocalvar(varname);
1027 s32
system_getlocalvar(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
1028 ScriptVariant
*ptmpvar
;
1030 if(paramCount
!= 1) {
1034 if(varlist
[0]->vt
!= VT_STR
) {
1035 printf("Function getlocalvar must have a string parameter.\n");
1039 ptmpvar
= Script_Get_Local_Variant(StrCache_Get(varlist
[0]->strVal
));
1041 ScriptVariant_Copy(*pretvar
, ptmpvar
);
1043 ScriptVariant_ChangeType(*pretvar
, VT_EMPTY
);
1047 //setlocalvar(varname, value);
1048 s32
system_setlocalvar(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
1049 if(paramCount
< 2) {
1053 if(varlist
[0]->vt
!= VT_STR
) {
1054 printf("Function setlocalvar's first parameter must be a string value.\n");
1058 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
1060 (*pretvar
)->lVal
= (s32
) Script_Set_Local_Variant(StrCache_Get(varlist
[0]->strVal
), varlist
[1]);
1066 s32
system_clearlocalvar(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
1068 Script_Local_Clear();
1073 s32
system_clearglobalvar(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
1075 max_global_var_index
= -1;
1079 //clearindexedvar();
1080 s32
system_clearindexedvar(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
1083 for(i
= 0; i
< max_indexed_vars
; i
++)
1084 ScriptVariant_Clear(indexed_var_list
+ i
);
1089 s32
system_free(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
1093 if(List_Includes(&scriptheap
, varlist
[0]->ptrVal
)) {
1094 free(List_Retrieve(&scriptheap
));
1095 List_Remove(&scriptheap
);
1101 //////////////////////////////////////////////////////////
1102 //////////// openbor functions
1103 //////////////////////////////////////////////////////////
1105 // ===== openborvariant =====
1106 void mapstrings_systemvariant(ScriptVariant
** varlist
, int paramCount
) {
1110 // This enum is replicated in getsyspropertybyindex in openbor.c. If you
1111 // change one, you must change the other as well!!!!
1112 enum systemvariant_enum
{
1119 _sv_current_palette
,
1130 _sv_in_selectscreen
,
1159 _sv_slowmotion_duration
,
1169 // arranged list, for searching
1170 static const char *proplist
[] = {
1216 "slowmotion_duration",
1225 MAPSTRINGS(varlist
[0], proplist
, _sv_the_end
, "openborvariant: System variable name not found: '%s'\n");
1228 //sample function, used for getting a system variant
1229 //openborvariant(varname);
1230 s32
openbor_systemvariant(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
1231 //used for getting the index from the enum of properties
1232 int variantindex
= -1;
1233 //the paramCount used for checking.
1234 //check it first so the engine wont crash if the list is empty
1236 goto systemvariant_error
;
1237 //call this function's mapstrings function to map string constants to enum values
1238 mapstrings_systemvariant(varlist
, paramCount
);
1239 //the variant name should be here
1240 //you can check the argument type if you like
1241 if(varlist
[0]->vt
== VT_INTEGER
)
1242 variantindex
= varlist
[0]->lVal
;
1244 goto systemvariant_error
;
1245 ///////these should be your get method, ///////
1246 ScriptVariant_Clear(*pretvar
);
1247 if(getsyspropertybyindex(*pretvar
, variantindex
)) {
1251 //////////////////////////////////////////////
1252 systemvariant_error
:
1254 // we have finshed, so return
1259 // ===== changeopenborvariant =====
1260 void mapstrings_changesystemvariant(ScriptVariant
** varlist
, int paramCount
) {
1264 // This enum is replicated in changesyspropertybyindex in openbor.c. If you
1265 // change one, you must change the other as well!!!!
1266 enum changesystemvariant_enum
{
1278 _csv_slowmotion_duration
,
1286 // arranged list, for searching
1287 static const char *proplist
[] = {
1299 "slowmotion_duration",
1306 MAPSTRINGS(varlist
[0], proplist
, _csv_the_end
, "changeopenborvariant: System variable name not found: '%s'\n");
1309 //used for changing a system variant
1310 //changeopenborvariant(varname, value);
1311 s32
openbor_changesystemvariant(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
1312 //used for getting the enum constant corresponding to the desired variable
1313 int variantindex
= 0;
1314 //reference to the arguments
1315 ScriptVariant
*arg
= NULL
;
1316 //the paramCount used for checking.
1317 //check it first so the engine wont crash if the list is empty
1319 goto changesystemvariant_error
;
1320 // map string constants to enum constants for speed
1321 mapstrings_changesystemvariant(varlist
, paramCount
);
1322 //get the 1st argument
1324 //the variant name should be here
1325 //you can check the argument type if you like
1326 if(arg
->vt
== VT_INTEGER
)
1327 variantindex
= arg
->lVal
;
1329 goto changesystemvariant_error
;
1331 if(changesyspropertybyindex(variantindex
, varlist
[1])) {
1334 changesystemvariant_error
:
1336 // we have finshed, so return
1341 // use font_printf to draw string
1342 //drawstring(x, y, font, string, z);
1343 s32
openbor_drawstring(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
1350 goto drawstring_error
;
1352 for(i
= 0; i
< 3; i
++) {
1353 if(FAILED(ScriptVariant_IntegerValue(varlist
[i
], value
+ i
)))
1354 goto drawstring_error
;
1356 if(paramCount
> 4) {
1357 if(FAILED(ScriptVariant_IntegerValue(varlist
[4], value
+ 3)))
1358 goto drawstring_error
;
1361 ScriptVariant_ToString(varlist
[3], buf
);
1362 font_printf((int) value
[0], (int) value
[1], (int) value
[2], (int) value
[3], "%s", buf
);
1367 ("First 3 values must be integer values and 4th value a string: drawstring(int x, int y, int font, value)\n");
1372 //drawstringtoscreen(screen, x, y, font, string);
1373 s32
openbor_drawstringtoscreen(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
1381 goto drawstring_error
;
1383 if(varlist
[0]->vt
!= VT_PTR
)
1384 goto drawstring_error
;
1385 scr
= (s_screen
*) varlist
[0]->ptrVal
;
1387 goto drawstring_error
;
1389 for(i
= 0; i
< 3; i
++) {
1390 if(FAILED(ScriptVariant_IntegerValue(varlist
[i
+ 1], value
+ i
)))
1391 goto drawstring_error
;
1394 ScriptVariant_ToString(varlist
[4], buf
);
1395 screen_printf(scr
, (int) value
[0], (int) value
[1], (int) value
[2], "%s", buf
);
1400 ("Function needs a valid screen handle, 3 integers and a string value: drawstringtoscreen(screen, int font, value)\n");
1406 s32
openbor_log(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
1411 goto drawstring_error
;
1413 ScriptVariant_ToString(varlist
[0], buf
);
1418 printf("Function needs 1 parameter: log(value)\n");
1422 //drawbox(x, y, width, height, z, color, lut);
1423 s32
openbor_drawbox(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
1431 for(i
= 0; i
< 6; i
++) {
1432 if(FAILED(ScriptVariant_IntegerValue(varlist
[i
], value
+ i
)))
1436 if(paramCount
> 6) {
1437 if(FAILED(ScriptVariant_IntegerValue(varlist
[6], &l
)))
1443 l
%= MAX_BLENDINGS
+ 1;
1445 spriteq_add_box((int) value
[0], (int) value
[1], (int) value
[2], (int) value
[3], (int) value
[4], (int) value
[5],
1452 ("Function requires 6 integer values: drawbox(int x, int y, int width, int height, int z, int color, int lut)\n");
1456 //drawboxtoscreen(screen, x, y, width, height, color, lut);
1457 s32
openbor_drawboxtoscreen(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
1466 s
= (s_screen
*) varlist
[0]->ptrVal
;
1471 for(i
= 1; i
< 6; i
++) {
1472 if(FAILED(ScriptVariant_IntegerValue(varlist
[i
], value
+ i
- 1)))
1476 if(paramCount
> 6) {
1477 if(FAILED(ScriptVariant_IntegerValue(varlist
[6], &l
)))
1483 l
%= MAX_BLENDINGS
+ 1;
1485 switch (s
->pixelformat
) {
1487 drawbox((int) value
[0], (int) value
[1], (int) value
[2], (int) value
[3], (int) value
[4], s
, l
);
1490 drawbox16((int) value
[0], (int) value
[1], (int) value
[2], (int) value
[3], (int) value
[4], s
, l
);
1493 drawbox32((int) value
[0], (int) value
[1], (int) value
[2], (int) value
[3], (int) value
[4], s
, l
);
1501 ("Function requires a screen handle and 5 integer values, 7th integer value is optional: drawboxtoscreen(screen, int x, int y, int width, int height, int color, int lut)\n");
1505 //drawline(x1, y1, x2, y2, z, color, lut);
1506 s32
openbor_drawline(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
1512 goto drawline_error
;
1514 for(i
= 0; i
< 6; i
++) {
1515 if(FAILED(ScriptVariant_IntegerValue(varlist
[i
], value
+ i
)))
1516 goto drawline_error
;
1519 if(paramCount
> 6) {
1520 if(FAILED(ScriptVariant_IntegerValue(varlist
[6], &l
)))
1521 goto drawline_error
;
1526 l
%= MAX_BLENDINGS
+ 1;
1528 spriteq_add_line((int) value
[0], (int) value
[1], (int) value
[2], (int) value
[3], (int) value
[4], (int) value
[5],
1535 ("Function requires 6 integer values, 7th integer value is optional: drawline(int x1, int y1, int x2, int y2, int z, int color, int lut)\n");
1539 //drawlinetoscreen(screen, x1, y1, x2, y2, color, lut);
1540 s32
openbor_drawlinetoscreen(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
1547 goto drawline_error
;
1549 s
= (s_screen
*) varlist
[0]->ptrVal
;
1552 goto drawline_error
;
1554 for(i
= 1; i
< 6; i
++) {
1555 if(FAILED(ScriptVariant_IntegerValue(varlist
[i
], value
+ i
- 1)))
1556 goto drawline_error
;
1559 if(paramCount
> 6) {
1560 if(FAILED(ScriptVariant_IntegerValue(varlist
[6], &l
)))
1561 goto drawline_error
;
1566 l
%= MAX_BLENDINGS
+ 1;
1568 switch (s
->pixelformat
) {
1570 line((int) value
[0], (int) value
[1], (int) value
[2], (int) value
[3], (int) value
[4], s
, l
);
1573 line16((int) value
[0], (int) value
[1], (int) value
[2], (int) value
[3], (int) value
[4], s
, l
);
1576 line32((int) value
[0], (int) value
[1], (int) value
[2], (int) value
[3], (int) value
[4], s
, l
);
1583 ("Function requires a screen handle and 5 integer values, 7th integer value is optional: drawlinetoscreen(screen, int x1, int y1, int x2, int y2, int color, int lut)\n");
1587 //drawsprite(sprite, x, y, z, sortid);
1588 s32
openbor_drawsprite(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
1595 goto drawsprite_error
;
1596 if(varlist
[0]->vt
!= VT_PTR
)
1597 goto drawsprite_error
;
1599 spr
= varlist
[0]->ptrVal
;
1601 goto drawsprite_error
;
1604 for(i
= 1; i
< paramCount
&& i
< 5; i
++) {
1605 if(FAILED(ScriptVariant_IntegerValue(varlist
[i
], value
+ i
- 1)))
1606 goto drawsprite_error
;
1609 spriteq_add_frame((int) value
[0], (int) value
[1], (int) value
[2], spr
, &drawmethod
, (int) value
[3]);
1615 ("Function requires a valid sprite handle 3 integer values, 5th integer value is optional: drawsprite(sprite, int x, int y, int z, int sortid)\n");
1619 //drawspritetoscreen(sprite, screen, x, y);
1620 s32
openbor_drawspritetoscreen(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
1628 goto drawsprite_error
;
1629 if(varlist
[0]->vt
!= VT_PTR
)
1630 goto drawsprite_error
;
1631 spr
= varlist
[0]->ptrVal
;
1633 goto drawsprite_error
;
1635 if(varlist
[1]->vt
!= VT_PTR
)
1636 goto drawsprite_error
;
1637 scr
= varlist
[1]->ptrVal
;
1639 goto drawsprite_error
;
1641 for(i
= 2; i
< paramCount
&& i
< 4; i
++) {
1642 if(FAILED(ScriptVariant_IntegerValue(varlist
[i
], value
+ i
- 2)))
1643 goto drawsprite_error
;
1646 putsprite((int) value
[0], (int) value
[1], spr
, scr
, &drawmethod
);
1652 ("Function requires a valid sprite handle, a valid screen handle and 2 integer values: drawspritetoscreen(sprite, screen, int x, int y)\n");
1656 //drawdot(x, y, z, color, lut);
1657 s32
openbor_drawdot(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
1665 for(i
= 0; i
< 4; i
++) {
1666 if(FAILED(ScriptVariant_IntegerValue(varlist
[i
], value
+ i
)))
1670 if(paramCount
> 4) {
1671 if(FAILED(ScriptVariant_IntegerValue(varlist
[4], &l
)))
1677 l
%= MAX_BLENDINGS
+ 1;
1679 spriteq_add_dot((int) value
[0], (int) value
[1], (int) value
[2], (int) value
[3], l
);
1685 ("Function requires 4 integer values, 5th integer value is optional: drawdot(int x, int y, int z, int color, int lut)\n");
1689 //drawdottoscreen(screen, x, y, color, lut);
1690 s32
openbor_drawdottoscreen(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
1699 s
= (s_screen
*) varlist
[0]->ptrVal
;
1704 for(i
= 1; i
< 4; i
++) {
1705 if(FAILED(ScriptVariant_IntegerValue(varlist
[i
], value
+ i
- 1)))
1709 if(paramCount
> 4) {
1710 if(FAILED(ScriptVariant_IntegerValue(varlist
[4], &l
)))
1716 l
%= MAX_BLENDINGS
+ 1;
1718 switch (s
->pixelformat
) {
1720 putpixel((int) value
[0], (int) value
[1], (int) value
[2], s
, l
);
1723 putpixel16((int) value
[0], (int) value
[1], (int) value
[2], s
, l
);
1726 putpixel32((int) value
[0], (int) value
[1], (int) value
[2], s
, l
);
1734 ("Function requires a screen handle and 3 integer values, 5th integer value is optional: dottoscreen(screen, int x, int y, int color, int lut)\n");
1739 //drawscreen(screen, x, y, z, lut);
1740 s32
openbor_drawscreen(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
1744 s_drawmethod screenmethod
;
1748 goto drawscreen_error
;
1750 s
= (s_screen
*) varlist
[0]->ptrVal
;
1753 goto drawscreen_error
;
1755 for(i
= 1; i
< 4; i
++) {
1756 if(FAILED(ScriptVariant_IntegerValue(varlist
[i
], value
+ i
- 1)))
1757 goto drawscreen_error
;
1760 if(paramCount
> 4) {
1761 if(FAILED(ScriptVariant_IntegerValue(varlist
[4], &l
)))
1762 goto drawscreen_error
;
1767 l
%= MAX_BLENDINGS
+ 1;
1770 screenmethod
= drawmethod
;
1772 screenmethod
= plainmethod
;
1773 screenmethod
.alpha
= l
;
1774 screenmethod
.transbg
= 1;
1776 spriteq_add_screen((int) value
[0], (int) value
[1], (int) value
[2], s
, &screenmethod
, 0);
1782 ("Function requires a screen handle and 3 integer values, 5th integer value is optional: drawscreen(screen, int x, int y, int z, int lut)\n");
1786 //getindexedvar(int index);
1787 s32
openbor_getindexedvar(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
1790 if(paramCount
< 1 || max_indexed_vars
<= 0) {
1795 ScriptVariant_Clear(*pretvar
);
1797 if(FAILED(ScriptVariant_IntegerValue(varlist
[0], &ind
))) {
1798 printf("Function requires 1 numberic value: getindexedvar(int index)\n");
1803 if(ind
< 0 || ind
>= max_indexed_vars
)
1806 ScriptVariant_Copy(*pretvar
, indexed_var_list
+ ind
);
1811 //setindexedvar(int index, var);
1812 s32
openbor_setindexedvar(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
1815 if(paramCount
< 2 || max_indexed_vars
<= 0) {
1820 if(FAILED(ScriptVariant_IntegerValue(varlist
[0], &ind
))) {
1821 printf("Function's 1st argument must be a numberic value: setindexedvar(int index, var)\n");
1826 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
1828 if(ind
< 0 || ind
>= max_indexed_vars
) {
1829 (*pretvar
)->lVal
= 0;
1833 ScriptVariant_Copy(indexed_var_list
+ ind
, varlist
[1]);
1834 (*pretvar
)->lVal
= 1;
1839 //getscriptvar(int index);
1840 s32
openbor_getscriptvar(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
1843 if(paramCount
< 1 || max_script_vars
<= 0 || !pcurrentscript
|| !pcurrentscript
->vars
) {
1848 if(FAILED(ScriptVariant_IntegerValue(varlist
[0], &ind
))) {
1849 printf("Function requires 1 numberic value: getscriptvar(int index)\n");
1854 ScriptVariant_Clear(*pretvar
);
1856 if(ind
< 0 || ind
>= max_script_vars
)
1859 ScriptVariant_Copy(*pretvar
, pcurrentscript
->vars
+ ind
);
1864 //setscriptvar(int index, var);
1865 s32
openbor_setscriptvar(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
1868 if(paramCount
< 2 || max_script_vars
<= 0 || !pcurrentscript
|| !pcurrentscript
->vars
) {
1873 if(FAILED(ScriptVariant_IntegerValue(varlist
[0], &ind
))) {
1874 printf("Function's 1st argument must be a numberic value: setscriptvar(int index, var)\n");
1879 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
1881 if(ind
< 0 || ind
>= max_script_vars
) {
1882 (*pretvar
)->lVal
= 0;
1886 ScriptVariant_Copy(pcurrentscript
->vars
+ ind
, varlist
[1]);
1887 (*pretvar
)->lVal
= 1;
1892 //getentityvar(entity, int index);
1893 s32
openbor_getentityvar(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
1894 ScriptVariant
*arg
= NULL
;
1898 if(paramCount
< 2 || max_entity_vars
<= 0) {
1906 ScriptVariant_Clear(*pretvar
);
1907 if(arg
->vt
== VT_EMPTY
)
1909 else if(arg
->vt
== VT_PTR
)
1910 ent
= (entity
*) arg
->ptrVal
;
1913 ("Function's 1st argument must be a valid entity handle value or empty value: getentityvar(entity, int index)\n");
1917 if(!ent
|| !ent
->entvars
)
1920 if(FAILED(ScriptVariant_IntegerValue(varlist
[1], &ind
))) {
1921 printf("Function's 2nd argument must be a numberic value: getentityvar(entity, int index)\n");
1926 if(ind
< 0 || ind
>= max_entity_vars
)
1929 ScriptVariant_Copy(*pretvar
, ent
->entvars
+ ind
);
1934 //setentityvar(int index, var);
1935 s32
openbor_setentityvar(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
1936 ScriptVariant
*arg
= NULL
;
1940 if(paramCount
< 3 || max_entity_vars
<= 0) {
1947 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
1948 (*pretvar
)->lVal
= 0;
1950 if(arg
->vt
== VT_EMPTY
)
1952 else if(arg
->vt
== VT_PTR
)
1953 ent
= (entity
*) arg
->ptrVal
;
1956 ("Function's 1st argument must be a valid entity handle value or empty value: setentityvar(entity, int index, var)\n");
1960 if(!ent
|| !ent
->entvars
)
1963 if(FAILED(ScriptVariant_IntegerValue(varlist
[1], &ind
))) {
1964 printf("Function's 2nd argument must be a numberic value: setentityvar(entity, int index, var)\n");
1969 if(ind
< 0 || ind
>= max_entity_vars
)
1972 ScriptVariant_Copy(ent
->entvars
+ ind
, varlist
[2]);
1973 (*pretvar
)->lVal
= 1;
1978 //strinfirst(char string, char search_string);
1979 s32
openbor_strinfirst(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
1980 char *tempstr
= NULL
;
1982 if(paramCount
< 2) {
1987 ScriptVariant_Clear(*pretvar
);
1989 if(varlist
[0]->vt
!= VT_STR
|| varlist
[1]->vt
!= VT_STR
) {
1991 ("\n Error, strinfirst({string}, {search string}): Strinfirst must be passed valid {string} and {search string}. \n");
1994 tempstr
= strstr((char *) StrCache_Get(varlist
[0]->strVal
), (char *) StrCache_Get(varlist
[1]->strVal
));
1996 if(tempstr
!= NULL
) {
1997 ScriptVariant_ChangeType(*pretvar
, VT_STR
);
1998 strcpy(StrCache_Get((*pretvar
)->strVal
), tempstr
);
2000 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
2001 (*pretvar
)->lVal
= -1;
2006 //strinlast(char string, char search_string);
2007 s32
openbor_strinlast(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
2008 char *tempstr
= NULL
;
2010 if(paramCount
< 2) {
2015 ScriptVariant_Clear(*pretvar
);
2017 if(varlist
[0]->vt
!= VT_STR
|| varlist
[1]->vt
!= VT_STR
) {
2019 ("\n Error, strinlast({string}, {search string}): Strinlast must be passed valid {string} and {search string}. \n");
2022 tempstr
= strrchr((char *) StrCache_Get(varlist
[0]->strVal
), varlist
[1]->strVal
);
2024 if(tempstr
!= NULL
) {
2025 ScriptVariant_ChangeType(*pretvar
, VT_STR
);
2026 strcpy(StrCache_Get((*pretvar
)->strVal
), tempstr
);
2028 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
2029 (*pretvar
)->lVal
= -1;
2034 //strleft(char string, int i);
2035 s32
openbor_strleft(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
2036 char tempstr
[66] = { 0 };
2038 if(paramCount
< 2) {
2042 if(varlist
[0]->vt
!= VT_STR
|| varlist
[1]->vt
!= VT_INTEGER
) {
2044 ("\n Error, strleft({string}, {characters}): Invalid or missing parameter. Strleft must be passed valid {string} and number of {characters}.\n");
2047 strncpy(tempstr
, (char *) StrCache_Get(varlist
[0]->strVal
), varlist
[1]->lVal
);
2048 ScriptVariant_Clear(*pretvar
);
2050 if(tempstr
!= NULL
) {
2051 ScriptVariant_ChangeType(*pretvar
, VT_STR
);
2052 strcpy(StrCache_Get((*pretvar
)->strVal
), tempstr
);
2054 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
2055 (*pretvar
)->lVal
= -1;
2061 //strlength(char string);
2062 s32
openbor_strlength(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
2063 if(paramCount
< 1) {
2068 ScriptVariant_Clear(*pretvar
);
2070 if(varlist
[0]->vt
!= VT_STR
) {
2072 ("Error, strlength({string}): Invalid or missing parameter. Strlength must be passed a valid {string}.\n");
2075 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
2076 (*pretvar
)->lVal
= strlen((char *) StrCache_Get(varlist
[0]->strVal
));
2080 //strright(char string, int i);
2081 s32
openbor_strright(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
2082 char *tempstr
= NULL
;
2084 if(paramCount
< 2) {
2089 if(varlist
[0]->vt
!= VT_STR
|| varlist
[1]->vt
!= VT_INTEGER
) {
2091 ("\n Error, strright({string}, {characters}): Invalid or missing parameter. Strright must be passed valid {string} and number of {characters}.\n");
2094 ScriptVariant_Clear(*pretvar
);
2095 tempstr
= (char *) StrCache_Get(varlist
[0]->strVal
);
2097 if(tempstr
!= NULL
|| strlen(tempstr
) > 0) {
2098 ScriptVariant_ChangeType(*pretvar
, VT_STR
);
2099 strcpy(StrCache_Get((*pretvar
)->strVal
), &tempstr
[varlist
[1]->lVal
]);
2101 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
2102 (*pretvar
)->lVal
= -1;
2108 s32
openbor_getmodelproperty(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
2111 if(paramCount
< 2) {
2116 if(varlist
[0]->vt
!= VT_INTEGER
|| varlist
[1]->vt
!= VT_INTEGER
) {
2118 ("\n Error, getmodelproperty({model}, {property}): Invalid or missing parameter. Getmodelproperty must be passed valid {model} and {property} indexes.\n");
2121 iArg
= varlist
[0]->lVal
;
2123 switch (varlist
[1]->lVal
) {
2126 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
2127 (*pretvar
)->lVal
= (s32
) model_cache
[iArg
].loadflag
;
2132 ScriptVariant_ChangeType(*pretvar
, VT_PTR
);
2133 (*pretvar
)->ptrVal
= (void*) model_cache
[iArg
].model
;
2137 ScriptVariant_ChangeType(*pretvar
, VT_STR
);
2138 strcpy(StrCache_Get((*pretvar
)->strVal
), model_cache
[iArg
].name
);
2143 ScriptVariant_ChangeType(*pretvar
, VT_STR
);
2144 strcpy(StrCache_Get((*pretvar
)->strVal
), model_cache
[iArg
].path
);
2149 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
2150 (*pretvar
)->lVal
= (s32
) model_cache
[iArg
].selectable
;
2158 s32
openbor_changemodelproperty(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
2162 if(paramCount
< 2) {
2167 if(varlist
[0]->vt
!= VT_INTEGER
|| varlist
[1]->vt
!= VT_INTEGER
) {
2169 ("\n Error, changemodelproperty({model}, {property}, {value}): Invalid or missing parameter. Changemodelproperty must be passed valid {model}, {property} and {value}.\n");
2172 iArg
= varlist
[0]->lVal
;
2174 switch (varlist
[1]->lVal
) {
2178 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist[2], <emp)))
2179 model_cache[iArg].loadflag = (int)ltemp;
2180 else (*pretvar)->lVal = (s32)0;
2187 if(varlist[2]->vt != VT_STR)
2189 printf("You must give a string value for {value}.\n");
2190 goto changeentityproperty_error;
2192 strcpy(model_cache[iArg].model, (char*)StrCache_Get(varlist[2]->strVal));
2193 (*pretvar)->lVal = (s32)1;
2200 if(varlist[2]->vt != VT_STR)
2202 printf("You must give a string value for {value}.\n");
2203 goto changeentityproperty_error;
2205 strcpy(model_cache[iArg].name, (char*)StrCache_Get(varlist[2]->strVal));
2206 (*pretvar)->lVal = (s32)1;
2213 if(varlist[2]->vt != VT_STR)
2215 printf("You must give a string value for {value}.\n");
2216 goto changeentityproperty_error;
2218 strcpy(model_cache[iArg].path, (char*)StrCache_Get(varlist[2]->strVal));
2219 (*pretvar)->lVal = (s32)1;
2225 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
)))
2226 model_cache
[iArg
].selectable
= (int) ltemp
;
2228 (*pretvar
)->lVal
= (s32
) 0;
2236 // ===== getentityproperty =====
2237 enum getentityproperty_enum
{
2267 _gep_damage_on_landing
,
2295 _gep_knockdowncount
,
2298 _gep_lifespancountdown
,
2303 _gep_maxguardpoints
,
2305 _gep_maxjugglepoints
,
2316 _gep_no_adjust_base
,
2347 _gep_subject_to_gravity
,
2348 _gep_subject_to_hole
,
2349 _gep_subject_to_maxz
,
2350 _gep_subject_to_minz
,
2351 _gep_subject_to_obstacle
,
2352 _gep_subject_to_platform
,
2353 _gep_subject_to_screen
,
2354 _gep_subject_to_wall
,
2358 _gep_throwframewait
,
2371 enum gep_edelay_enum
{
2372 _gep_edelay_cap_max
,
2373 _gep_edelay_cap_min
,
2376 _gep_edelay_range_max
,
2377 _gep_edelay_range_min
,
2378 _gep_edelay_the_end
,
2382 enum gep_aiflag_enum
{
2383 _gep_aiflag_animating
,
2384 _gep_aiflag_attacking
,
2385 _gep_aiflag_autokill
,
2387 _gep_aiflag_blocking
,
2388 _gep_aiflag_charging
,
2391 _gep_aiflag_falling
,
2392 _gep_aiflag_freezetime
,
2394 _gep_aiflag_getting
,
2397 _gep_aiflag_invincible
,
2398 _gep_aiflag_jumping
,
2399 _gep_aiflag_projectile
,
2400 _gep_aiflag_running
,
2401 _gep_aiflag_toexplode
,
2402 _gep_aiflag_turning
,
2403 _gep_aiflag_the_end
,
2406 enum _gep_defense_enum
{
2407 _gep_defense_blockpower
,
2408 _gep_defense_blockratio
,
2409 _gep_defense_blockthreshold
,
2410 _gep_defense_blocktype
,
2411 _gep_defense_factor
,
2412 _gep_defense_knockdown
,
2414 _gep_defense_the_end
,
2417 enum gep_running_enum
{
2423 _gep_running_the_end
,
2436 enum gep_attack_enum
{
2438 _gep_attack_blockflash
,
2439 _gep_attack_blocksound
,
2441 _gep_attack_counterattack
,
2442 _gep_attack_direction
,
2445 _gep_attack_dotforce
,
2446 _gep_attack_dotindex
,
2447 _gep_attack_dotrate
,
2448 _gep_attack_dottime
,
2452 _gep_attack_forcemap
,
2454 _gep_attack_freezetime
,
2456 _gep_attack_grabdistance
,
2457 _gep_attack_guardcost
,
2458 _gep_attack_hitflash
,
2459 _gep_attack_hitsound
,
2460 _gep_attack_jugglecost
,
2461 _gep_attack_maptime
,
2462 _gep_attack_noblock
,
2463 _gep_attack_noflash
,
2468 _gep_attack_sealtime
,
2469 _gep_attack_staydown
,
2472 _gep_attack_the_end
,
2475 enum gep_range_enum
{
2487 void mapstrings_getentityproperty(ScriptVariant
** varlist
, int paramCount
) {
2491 // arranged list, for searching
2492 static const char *proplist
[] = {
2522 "damage_on_landing",
2553 "lifespancountdown",
2602 "subject_to_gravity",
2606 "subject_to_obstacle",
2607 "subject_to_platform",
2608 "subject_to_screen",
2625 static const char *proplist_edelay
[] = {
2634 static const char *proplist_aiflag
[] = {
2657 static const char *proplist_defense
[] = {
2667 static const char *proplist_running
[] = {
2675 static const char *proplist_dot
[] = {
2684 static const char *proplist_attack
[] = {
2722 static const char *proplist_range
[] = {
2736 // map entity properties
2737 MAPSTRINGS(varlist
[1], proplist
, _gep_the_end
,
2738 "Property name '%s' is not supported by function getentityproperty.\n");
2743 // map subproperties of edelay property
2744 if((varlist
[1]->vt
== VT_INTEGER
) && (varlist
[1]->lVal
== _gep_edelay
)) {
2745 MAPSTRINGS(varlist
[2], proplist_edelay
, _gep_edelay_the_end
,
2746 "'%s' is not a known subproperty of 'edelay'.\n");
2748 // map subproperties of aiflag property
2749 if((varlist
[1]->vt
== VT_INTEGER
) && (varlist
[1]->lVal
== _gep_aiflag
)) {
2750 MAPSTRINGS(varlist
[2], proplist_aiflag
, _gep_aiflag_the_end
,
2751 "'%s' is not a known subproperty of 'aiflag'.\n");
2753 // map subproperties of defense property
2754 if((varlist
[1]->vt
== VT_INTEGER
) && (varlist
[1]->lVal
== _gep_defense
)) {
2755 if(paramCount
>= 4) {
2756 MAPSTRINGS(varlist
[3], proplist_defense
, _gep_defense_the_end
,
2757 "'%s' is not a known subproperty of 'defense'.\n");
2760 // map subproperties of running
2761 if((varlist
[1]->vt
== VT_INTEGER
) && (varlist
[1]->lVal
== _gep_running
)) {
2762 MAPSTRINGS(varlist
[2], proplist_running
, _gep_running_the_end
,
2763 "Property name '%s' is not a known subproperty of 'running'.\n");
2765 // map subproperties of DOT
2766 if((varlist
[1]->vt
== VT_INTEGER
) && (varlist
[1]->lVal
== _gep_dot
)) {
2767 MAPSTRINGS(varlist
[2], proplist_dot
, _gep_dot_the_end
,
2768 "Property name '%s' is not a known subproperty of 'dot'.\n");
2770 // map subproperties of Attack
2771 if((varlist
[1]->vt
== VT_INTEGER
) && (varlist
[1]->lVal
== _gep_attack
)) {
2772 MAPSTRINGS(varlist
[2], proplist_attack
, _gep_attack_the_end
,
2773 "Property name '%s' is not a known subproperty of 'attack'.\n");
2775 // map subproperties of Range
2776 if((varlist
[1]->vt
== VT_INTEGER
) && (varlist
[1]->lVal
== _gep_range
)) {
2777 MAPSTRINGS(varlist
[2], proplist_range
, _gep_range_the_end
,
2778 "Property name '%s' is not a known subproperty of 'range'.\n");
2782 //getentityproperty(pentity, propname);
2783 s32
openbor_getentityproperty(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
2785 char *tempstr
= NULL
;
2786 ScriptVariant
*arg
= NULL
;
2787 ScriptVariant
*arg1
= NULL
;
2796 if(paramCount
< 2) {
2801 ScriptVariant_Clear(*pretvar
);
2802 mapstrings_getentityproperty(varlist
, paramCount
);
2805 if(arg
->vt
!= VT_PTR
&& arg
->vt
!= VT_EMPTY
) {
2806 printf("Function getentityproperty must have a valid entity handle.\n");
2810 ent
= (entity
*) arg
->ptrVal
; //retrieve the entity
2815 if(arg
->vt
!= VT_INTEGER
) {
2816 printf("Function getentityproperty must have a string property name.\n");
2819 propind
= arg
->lVal
;
2824 ScriptVariant_ChangeType(*pretvar
, VT_STR
);
2825 strcpy(StrCache_Get((*pretvar
)->strVal
), ent
->model
->name
);
2830 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
2831 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.animal
;
2834 case _gep_spawntype
:
2836 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
2837 (*pretvar
)->lVal
= (s32
) ent
->spawntype
;
2840 case _gep_maxhealth
:
2842 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
2843 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.health
;
2848 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
2849 (*pretvar
)->lVal
= (s32
) ent
->health
;
2854 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
2855 (*pretvar
)->lVal
= (s32
) ent
->animation
->animhits
;
2860 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
2861 (*pretvar
)->lVal
= (s32
) ent
->nextanim
;
2864 case _gep_nextthink
:
2866 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
2867 (*pretvar
)->lVal
= (s32
) ent
->nextthink
;
2872 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
2873 (*pretvar
)->lVal
= (s32
) ent
->toss_time
;
2878 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
2879 (*pretvar
)->lVal
= (s32
) ent
->mp
;
2884 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
2885 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.mp
;
2888 case _gep_mpstableval
:
2890 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
2891 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.mpstableval
;
2896 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
2897 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.mpstable
;
2902 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
2903 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.mprate
;
2906 case _gep_mpdroprate
:
2908 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
2909 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.mpdroprate
;
2912 case _gep_chargerate
:
2914 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
2915 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.chargerate
;
2918 case _gep_guardpoints
:
2920 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
2921 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.guardpoints
[0];
2924 case _gep_maxguardpoints
:
2926 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
2927 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.guardpoints
[1];
2930 case _gep_jugglepoints
:
2932 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
2933 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.jugglepoints
[0];
2936 case _gep_maxjugglepoints
:
2938 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
2939 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.jugglepoints
[1];
2944 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
2945 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.alpha
;
2950 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
2951 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.height
;
2956 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
2957 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.setlayer
;
2962 ScriptVariant_ChangeType(*pretvar
, VT_DECIMAL
);
2963 (*pretvar
)->dblVal
= (double) ent
->modeldata
.speed
;
2968 ScriptVariant_ChangeType(*pretvar
, VT_PTR
);
2969 i
= ent
->animation
->sprite
[ent
->animpos
];
2970 spr
= sprite_map
[i
].sprite
;
2971 spr
->centerx
= sprite_map
[i
].centerx
;
2972 spr
->centery
= sprite_map
[i
].centery
;
2973 (*pretvar
)->ptrVal
= (void*) (spr
);
2976 case _gep_playerindex
:
2978 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
2979 (*pretvar
)->lVal
= (s32
) ent
->playerindex
;
2980 //printf("%d %s %d\n", ent->sortid, ent->name, ent->playerindex);
2983 case _gep_colourmap
:
2985 ScriptVariant_ChangeType(*pretvar
, VT_PTR
);
2986 (*pretvar
)->ptrVal
= (void*) (ent
->colourmap
);
2989 case _gep_colourtable
:
2991 ScriptVariant_ChangeType(*pretvar
, VT_PTR
);
2992 (*pretvar
)->ptrVal
= (void*) (ent
->modeldata
.colourmap
[varlist
[2]->lVal
]);
2997 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
2998 (*pretvar
)->lVal
= (s32
) 0;
2999 for(i
= 0; i
< ent
->modeldata
.maps_loaded
; i
++) {
3000 if(ent
->colourmap
== ent
->modeldata
.colourmap
[i
]) {
3001 (*pretvar
)->lVal
= (s32
) (i
+ 1);
3009 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3010 (*pretvar
)->lVal
= (s32
) (ent
->modeldata
.maps_loaded
+ 1);
3013 case _gep_mapdefault
:
3015 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3016 (*pretvar
)->lVal
= (s32
) (ent
->map
);
3021 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3022 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.hmap1
;
3027 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3028 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.hmap2
;
3036 if(arg
->vt
!= VT_INTEGER
) {
3038 ("Error, getentityproperty({ent}, 'icon', {type}): {type} parameter missing or invalid. \n {type}: \n 0 = Icon \n 1 = Icondie \n 2 = Iconget \n 3 = Iconmphigh \n 4 = Iconmphalf \n 5 = Iconmplow \n 6 = Iconpain \n 7 = Iconw \n 8 = Iconx \n 9 = Icony \n");
3042 switch (arg
->lVal
) {
3044 i
= ent
->modeldata
.icon
;
3047 i
= ent
->modeldata
.icondie
;
3050 i
= ent
->modeldata
.iconget
;
3053 i
= ent
->modeldata
.iconmp
[0];
3056 i
= ent
->modeldata
.iconmp
[1];
3059 i
= ent
->modeldata
.iconmp
[2];
3062 i
= ent
->modeldata
.iconpain
;
3065 i
= ent
->modeldata
.iconw
;
3068 i
= ent
->modeldata
.iconx
;
3071 i
= ent
->modeldata
.icony
;
3076 ScriptVariant_ChangeType(*pretvar
, VT_PTR
);
3077 spr
= sprite_map
[i
].sprite
;
3078 spr
->centerx
= sprite_map
[i
].centerx
;
3079 spr
->centery
= sprite_map
[i
].centery
;
3080 (*pretvar
)->ptrVal
= (void*) (spr
);
3082 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3083 (*pretvar
)->lVal
= -1;
3089 ScriptVariant_ChangeType(*pretvar
, VT_STR
);
3090 strcpy(StrCache_Get((*pretvar
)->strVal
), ent
->name
);
3093 case _gep_defaultname
:
3094 case _gep_defaultmodel
:
3096 ScriptVariant_ChangeType(*pretvar
, VT_STR
);
3097 strcpy(StrCache_Get((*pretvar
)->strVal
), ent
->defaultmodel
->name
);
3102 ScriptVariant_ChangeType(*pretvar
, VT_DECIMAL
);
3103 (*pretvar
)->dblVal
= (double) ent
->x
;
3108 ScriptVariant_ChangeType(*pretvar
, VT_DECIMAL
);
3109 (*pretvar
)->dblVal
= (double) ent
->z
;
3114 ScriptVariant_ChangeType(*pretvar
, VT_DECIMAL
);
3115 (*pretvar
)->dblVal
= (double) ent
->a
;
3120 ScriptVariant_ChangeType(*pretvar
, VT_DECIMAL
);
3121 (*pretvar
)->dblVal
= (double) ent
->xdir
;
3126 ScriptVariant_ChangeType(*pretvar
, VT_DECIMAL
);
3127 (*pretvar
)->dblVal
= (double) ent
->zdir
;
3132 ScriptVariant_ChangeType(*pretvar
, VT_DECIMAL
);
3133 (*pretvar
)->dblVal
= (double) ent
->tossv
;
3138 ScriptVariant_ChangeType(*pretvar
, VT_DECIMAL
);
3139 (*pretvar
)->dblVal
= (double) ent
->base
;
3142 case _gep_direction
:
3144 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3145 (*pretvar
)->lVal
= (s32
) ent
->direction
;
3150 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3151 (*pretvar
)->lVal
= (s32
) ent
->exists
;
3157 if(arg
->vt
!= VT_INTEGER
) {
3158 if(arg
->vt
!= VT_STR
)
3159 printf("You must give a string name for edelay property.\n");
3163 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3166 case _gep_edelay_mode
:
3168 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.edelay
.mode
;
3171 case _gep_edelay_factor
:
3173 (*pretvar
)->dblVal
= (float) ent
->modeldata
.edelay
.factor
;
3176 case _gep_edelay_cap_min
:
3178 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.edelay
.cap_min
;
3181 case _gep_edelay_cap_max
:
3183 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.edelay
.cap_max
;
3186 case _gep_edelay_range_min
:
3188 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.edelay
.range_min
;
3191 case _gep_edelay_range_max
:
3193 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.edelay
.range_max
;
3197 ScriptVariant_Clear(*pretvar
);
3202 case _gep_energycost
:
3204 if(paramCount
!= 4 //Validate parameter count and types.
3205 || varlist
[2]->vt
!= VT_INTEGER
|| varlist
[3]->vt
!= VT_INTEGER
) {
3207 ("\n Error, getentityproperty({ent}, 'energycost', {animation}, {argument}): Missing or invalid parameter. \n");
3211 i
= varlist
[2]->lVal
; //Animation.
3213 if(!validanim(ent
, i
)) //Bad or missing animation = instant crash, let's validate and pass user friendly error.
3216 ("\n Error, getentityproperty({ent}, 'energycost', {animation}, {argument}): {animation} argument invalid. Make sure the animation exists. \n");
3220 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3221 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.animation
[i
]->energycost
[varlist
[3]->lVal
];
3224 case _gep_dropframe
:
3227 if(paramCount
== 3) {
3229 if(FAILED(ScriptVariant_IntegerValue(arg
, <emp
)))
3232 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3233 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.animation
[ltemp
]->dropframe
;
3236 case _gep_landframe
:
3239 if(paramCount
== 3) {
3241 if(FAILED(ScriptVariant_IntegerValue(arg
, <emp
)))
3244 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3245 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.animation
[ltemp
]->landframe
[0];
3250 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3251 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.type
;
3256 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3257 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.subtype
;
3260 case _gep_throwdamage
:
3262 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3263 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.throwdamage
;
3266 case _gep_throwdist
:
3268 ScriptVariant_ChangeType(*pretvar
, VT_DECIMAL
);
3269 (*pretvar
)->dblVal
= (double) ent
->modeldata
.throwdist
;
3272 case _gep_throwframewait
:
3274 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3275 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.throwframewait
;
3278 case _gep_throwheight
:
3280 ScriptVariant_ChangeType(*pretvar
, VT_DECIMAL
);
3281 (*pretvar
)->dblVal
= (double) ent
->modeldata
.throwheight
;
3289 if(arg
->vt
!= VT_INTEGER
) {
3290 printf("You must give a string name for aiflag.\n");
3295 case _gep_aiflag_dead
:
3297 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3298 (*pretvar
)->lVal
= (s32
) ent
->dead
;
3301 case _gep_aiflag_jumping
:
3303 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3304 (*pretvar
)->lVal
= (s32
) ent
->jumping
;
3307 case _gep_aiflag_idling
:
3309 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3310 (*pretvar
)->lVal
= (s32
) ent
->idling
;
3313 case _gep_aiflag_drop
:
3315 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3316 (*pretvar
)->lVal
= (s32
) ent
->drop
;
3319 case _gep_aiflag_attacking
:
3321 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3322 (*pretvar
)->lVal
= (s32
) ent
->attacking
;
3325 case _gep_aiflag_getting
:
3327 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3328 (*pretvar
)->lVal
= (s32
) ent
->getting
;
3331 case _gep_aiflag_turning
:
3333 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3334 (*pretvar
)->lVal
= (s32
) ent
->turning
;
3337 case _gep_aiflag_charging
:
3339 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3340 (*pretvar
)->lVal
= (s32
) ent
->charging
;
3343 case _gep_aiflag_blocking
:
3345 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3346 (*pretvar
)->lVal
= (s32
) ent
->blocking
;
3349 case _gep_aiflag_falling
:
3351 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3352 (*pretvar
)->lVal
= (s32
) ent
->falling
;
3355 case _gep_aiflag_running
:
3357 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3358 (*pretvar
)->lVal
= (s32
) ent
->running
;
3361 case _gep_aiflag_inpain
:
3363 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3364 (*pretvar
)->lVal
= (s32
) ent
->inpain
;
3367 case _gep_aiflag_projectile
:
3369 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3370 (*pretvar
)->lVal
= (s32
) ent
->projectile
;
3373 case _gep_aiflag_frozen
:
3375 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3376 (*pretvar
)->lVal
= (s32
) ent
->frozen
;
3379 case _gep_aiflag_freezetime
:
3381 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3382 (*pretvar
)->lVal
= (s32
) ent
->freezetime
;
3385 case _gep_aiflag_toexplode
:
3387 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3388 (*pretvar
)->lVal
= (s32
) ent
->toexplode
;
3391 case _gep_aiflag_animating
:
3393 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3394 (*pretvar
)->lVal
= (s32
) ent
->animating
;
3397 case _gep_aiflag_blink
:
3399 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3400 (*pretvar
)->lVal
= (s32
) ent
->blink
;
3403 case _gep_aiflag_invincible
:
3405 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3406 (*pretvar
)->lVal
= (s32
) ent
->invincible
;
3409 case _gep_aiflag_autokill
:
3411 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3412 (*pretvar
)->lVal
= (s32
) ent
->autokill
;
3416 ScriptVariant_Clear(*pretvar
);
3421 case _gep_animation
:
3423 ScriptVariant_ChangeType(*pretvar
, VT_PTR
);
3424 (*pretvar
)->ptrVal
= (void*) ent
->animation
;
3428 case _gep_animationid
:
3430 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3431 (*pretvar
)->lVal
= (s32
) ent
->animnum
;
3436 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3437 (*pretvar
)->lVal
= (s32
) ent
->animpos
;
3440 case _gep_animvalid
:
3443 if(paramCount
== 3) {
3445 if(FAILED(ScriptVariant_IntegerValue(arg
, <emp
)))
3448 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3449 (*pretvar
)->lVal
= (s32
) validanim(ent
, ltemp
);
3452 case _gep_animheight
:
3454 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3455 (*pretvar
)->lVal
= (s32
) ent
->animation
->height
;
3458 case _gep_animating
:
3460 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3461 (*pretvar
)->lVal
= (s32
) ent
->animating
;
3464 case _gep_invincible
:
3466 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3467 (*pretvar
)->lVal
= (s32
) ent
->invincible
;
3470 case _gep_invinctime
:
3472 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3473 (*pretvar
)->lVal
= (s32
) ent
->invinctime
;
3476 case _gep_rush_count
:
3478 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3479 (*pretvar
)->lVal
= (s32
) ent
->rush
[0];
3482 case _gep_rush_tally
:
3484 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3485 (*pretvar
)->lVal
= (s32
) ent
->rush
[1];
3488 case _gep_rush_time
:
3490 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3491 (*pretvar
)->lVal
= (s32
) ent
->rushtime
;
3494 case _gep_knockdowncount
:
3496 ScriptVariant_ChangeType(*pretvar
, VT_DECIMAL
);
3497 (*pretvar
)->dblVal
= (double) ent
->knockdowncount
;
3505 if(arg
->vt
!= VT_INTEGER
) {
3507 ("You must provide a Komap parameter index: \n 0 = Komap \n 1 = Komap type \n");
3511 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3512 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.komap
[arg
->lVal
];
3515 case _gep_lifespancountdown
:
3517 ScriptVariant_ChangeType(*pretvar
, VT_DECIMAL
);
3518 (*pretvar
)->dblVal
= (double) ent
->lifespancountdown
;
3523 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3524 (*pretvar
)->lVal
= (s32
) ent
->blink
;
3527 case _gep_subject_to_screen
:
3529 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3530 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.subject_to_screen
;
3533 case _gep_subject_to_minz
:
3535 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3536 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.subject_to_minz
;
3539 case _gep_subject_to_maxz
:
3541 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3542 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.subject_to_maxz
;
3545 case _gep_subject_to_wall
:
3547 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3548 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.subject_to_wall
;
3551 case _gep_subject_to_hole
:
3553 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3554 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.subject_to_hole
;
3557 case _gep_subject_to_gravity
:
3559 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3560 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.subject_to_gravity
;
3563 case _gep_subject_to_obstacle
:
3565 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3566 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.subject_to_obstacle
;
3569 case _gep_subject_to_platform
:
3571 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3572 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.subject_to_platform
;
3578 if(paramCount
== 3) {
3580 if(FAILED(ScriptVariant_IntegerValue(arg
, <emp
)))
3585 if(arg
->vt
!= VT_INTEGER
) {
3586 if(arg
->vt
!= VT_STR
)
3587 printf("You must give a string name for defense property.\n");
3590 ScriptVariant_ChangeType(*pretvar
, VT_DECIMAL
);
3592 switch (arg
->lVal
) {
3593 case _gep_defense_factor
:
3595 (*pretvar
)->dblVal
=
3596 (float) ent
->modeldata
.defense_factors
[(int) ltemp
];
3599 case _gep_defense_blockpower
:
3601 (*pretvar
)->dblVal
=
3602 (double) ent
->modeldata
.defense_blockpower
[(int) ltemp
];
3605 case _gep_defense_blockratio
:
3607 (*pretvar
)->dblVal
=
3608 (double) ent
->modeldata
.defense_blockratio
[(int) ltemp
];
3611 case _gep_defense_blockthreshold
:
3613 (*pretvar
)->dblVal
=
3614 (double) ent
->modeldata
.defense_blockthreshold
[(int) ltemp
];
3617 case _gep_defense_blocktype
:
3619 (*pretvar
)->dblVal
=
3620 (double) ent
->modeldata
.defense_blocktype
[(int) ltemp
];
3623 case _gep_defense_knockdown
:
3625 (*pretvar
)->dblVal
=
3626 (double) ent
->modeldata
.defense_knockdown
[(int) ltemp
];
3629 case _gep_defense_pain
:
3631 (*pretvar
)->dblVal
=
3632 (double) ent
->modeldata
.defense_pain
[(int) ltemp
];
3640 case _gep_no_adjust_base
:
3642 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3643 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.no_adjust_base
;
3646 case _gep_noaicontrol
:
3648 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3649 (*pretvar
)->lVal
= (s32
) ent
->noaicontrol
;
3652 case _gep_nodieblink
:
3654 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3655 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.nodieblink
;
3660 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3661 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.bounce
;
3666 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3667 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.falldie
;
3672 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3673 (*pretvar
)->lVal
= (s32
) ent
->attack_id
;
3678 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3679 (*pretvar
)->lVal
= (s32
) ent
->hit_by_attack_id
;
3687 if(varlist
[2]->vt
!= VT_INTEGER
3688 || varlist
[3]->vt
!= VT_INTEGER
3689 || varlist
[4]->vt
!= VT_INTEGER
|| varlist
[5]->vt
!= VT_INTEGER
) {
3691 ("\n Error, getentityproperty({ent}, 'bbox', {index}, {animation}, {frame}, {arg}): {index}, {Animation}, {frame}, or {arg} parameter is missing or invalid. \n");
3694 //varlist[3]->lval; //bbox index (multiple bbox support).
3695 i
= varlist
[3]->lVal
; //Animation parameter.
3696 tempint
= varlist
[4]->lVal
; //Frame parameter.
3698 if(!ent
->modeldata
.animation
[i
]->bbox_coords
) {
3702 coords
= ent
->modeldata
.animation
[i
]->bbox_coords
[tempint
];
3704 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3705 (*pretvar
)->lVal
= (s32
) coords
[varlist
[5]->lVal
];
3713 if(varlist
[2]->vt
!= VT_INTEGER
|| varlist
[3]->vt
!= VT_INTEGER
) {
3715 ("\n Error, getentityproperty({ent}, 'range', {sub property}, {animation}): {Sub property} or {Animation} parameter is missing or invalid. \n");
3718 ltemp
= varlist
[2]->lVal
; //Subproperty.
3719 i
= varlist
[3]->lVal
; //Animation.
3721 if(!validanim(ent
, i
)) //Verify animation.
3727 case _gep_range_amax
:
3728 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3729 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.animation
[i
]->range
[5];
3731 case _gep_range_amin
:
3732 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3733 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.animation
[i
]->range
[4];
3735 case _gep_range_bmax
:
3736 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3737 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.animation
[i
]->range
[7];
3739 case _gep_range_bmin
:
3740 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3741 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.animation
[i
]->range
[6];
3743 case _gep_range_xmax
:
3744 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3745 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.animation
[i
]->range
[1];
3747 case _gep_range_xmin
:
3748 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3749 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.animation
[i
]->range
[0];
3751 case _gep_range_zmax
:
3752 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3753 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.animation
[i
]->range
[3];
3755 case _gep_range_zmin
:
3756 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3757 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.animation
[i
]->range
[2];
3760 ScriptVariant_Clear(*pretvar
);
3765 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3766 (*pretvar
)->lVal
= (s32
) coords
[varlist
[4]->lVal
];
3774 if(arg
->vt
!= VT_INTEGER
) {
3776 ("Error, getentityproperty({ent}, 'attack', {sub property}, {index}, {animation}, {frame}): You must give a string name for {sub property}.\n");
3781 if(varlist
[3]->vt
!= VT_INTEGER
3782 || varlist
[4]->vt
!= VT_INTEGER
|| varlist
[5]->vt
!= VT_INTEGER
) {
3784 ("\n Error, getentityproperty({ent}, 'attack', {sub property}, {index}, {animation}, {frame}): {Animation} or {frame} parameter is missing or invalid. \n");
3787 //varlist[3]->lval //Attack box index (multiple attack boxes).
3788 i
= varlist
[4]->lVal
; //Animation parameter.
3789 tempint
= varlist
[5]->lVal
; //Frame parameter.
3791 if(!validanim(ent
, i
) || !ent
->modeldata
.animation
[i
]->attacks
|| !ent
->modeldata
.animation
[i
]->attacks
[tempint
]) //Verify animation and active attack on frame.
3796 attack
= ent
->modeldata
.animation
[i
]->attacks
[tempint
]; //Get attack struct.
3799 case _gep_attack_blockflash
:
3800 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3801 (*pretvar
)->lVal
= (s32
) attack
->blockflash
;
3803 case _gep_attack_blocksound
:
3804 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3805 (*pretvar
)->lVal
= (s32
) attack
->blocksound
;
3807 case _gep_attack_coords
:
3808 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3809 (*pretvar
)->lVal
= (s32
) attack
->attack_coords
[varlist
[6]->lVal
];
3811 case _gep_attack_counterattack
:
3812 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3813 (*pretvar
)->lVal
= (s32
) attack
->counterattack
;
3815 case _gep_attack_direction
:
3816 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3817 (*pretvar
)->lVal
= (s32
) attack
->force_direction
;
3819 case _gep_attack_dol
:
3820 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3821 (*pretvar
)->lVal
= (s32
) attack
->damage_on_landing
;
3823 case _gep_attack_dot
:
3824 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3825 (*pretvar
)->lVal
= (s32
) attack
->dot
;
3827 case _gep_attack_dotforce
:
3828 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3829 (*pretvar
)->lVal
= (s32
) attack
->dot_force
;
3831 case _gep_attack_dotindex
:
3832 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3833 (*pretvar
)->lVal
= (s32
) attack
->dot_index
;
3835 case _gep_attack_dotrate
:
3836 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3837 (*pretvar
)->lVal
= (s32
) attack
->dot_rate
;
3839 case _gep_attack_dottime
:
3840 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3841 (*pretvar
)->lVal
= (s32
) attack
->dot_time
;
3843 case _gep_attack_drop
:
3844 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3845 (*pretvar
)->lVal
= (s32
) attack
->attack_drop
;
3847 case _gep_attack_dropv
:
3848 ScriptVariant_ChangeType(*pretvar
, VT_DECIMAL
);
3849 (*pretvar
)->dblVal
= (double) attack
->dropv
[varlist
[6]->lVal
];
3851 case _gep_attack_force
:
3852 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3853 (*pretvar
)->lVal
= (s32
) attack
->attack_force
;
3855 case _gep_attack_forcemap
:
3856 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3857 (*pretvar
)->lVal
= (s32
) attack
->forcemap
;
3859 case _gep_attack_freeze
:
3860 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3861 (*pretvar
)->lVal
= (s32
) attack
->freeze
;
3863 case _gep_attack_freezetime
:
3864 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3865 (*pretvar
)->lVal
= (s32
) attack
->freezetime
;
3867 case _gep_attack_grab
:
3868 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3869 (*pretvar
)->lVal
= (s32
) attack
->grab
;
3871 case _gep_attack_grabdistance
:
3872 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3873 (*pretvar
)->lVal
= (s32
) attack
->grab_distance
;
3875 case _gep_attack_guardcost
:
3876 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3877 (*pretvar
)->lVal
= (s32
) attack
->guardcost
;
3879 case _gep_attack_hitflash
:
3880 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3881 (*pretvar
)->lVal
= (s32
) attack
->hitflash
;
3883 case _gep_attack_hitsound
:
3884 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3885 (*pretvar
)->lVal
= (s32
) attack
->hitsound
;
3887 case _gep_attack_jugglecost
:
3888 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3889 (*pretvar
)->lVal
= (s32
) attack
->jugglecost
;
3891 case _gep_attack_maptime
:
3892 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3893 (*pretvar
)->lVal
= (s32
) attack
->maptime
;
3895 case _gep_attack_noblock
:
3896 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3897 (*pretvar
)->lVal
= (s32
) attack
->no_block
;
3899 case _gep_attack_noflash
:
3900 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3901 (*pretvar
)->lVal
= (s32
) attack
->no_flash
;
3903 case _gep_attack_nopain
:
3904 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3905 (*pretvar
)->lVal
= (s32
) attack
->no_pain
;
3907 case _gep_attack_otg
:
3908 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3909 (*pretvar
)->lVal
= (s32
) attack
->otg
;
3911 case _gep_attack_pause
:
3912 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3913 (*pretvar
)->lVal
= (s32
) attack
->pause_add
;
3915 case _gep_attack_seal
:
3916 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3917 (*pretvar
)->lVal
= (s32
) attack
->seal
;
3919 case _gep_attack_sealtime
:
3920 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3921 (*pretvar
)->lVal
= (s32
) attack
->sealtime
;
3923 case _gep_attack_staydown
:
3924 ScriptVariant_ChangeType(*pretvar
, VT_PTR
);
3925 (*pretvar
)->ptrVal
= (void*) attack
->staydown
;
3927 case _gep_attack_steal
:
3928 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3929 (*pretvar
)->lVal
= (s32
) attack
->steal
;
3931 case _gep_attack_type
:
3932 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3933 (*pretvar
)->lVal
= (s32
) attack
->attack_type
;
3936 ScriptVariant_Clear(*pretvar
);
3944 if(paramCount
< 3 || arg
->vt
!= VT_INTEGER
) {
3946 ("Error, getentityproperty({ent}, 'flash', {argument}): Missing or invalid parameter. \n {argument}: \n 0 = Flash \n 1 = Noatflash \n 2=bflash \n");
3950 switch (arg
->lVal
) {
3952 i
= ent
->modeldata
.flash
;
3955 i
= ent
->modeldata
.noatflash
;
3958 i
= ent
->modeldata
.bflash
;
3961 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3962 (*pretvar
)->lVal
= (s32
) i
;
3965 case _gep_freezetime
:
3967 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3968 (*pretvar
)->lVal
= (s32
) ent
->freezetime
;
3973 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3974 (*pretvar
)->lVal
= (s32
) ent
->frozen
;
3979 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3980 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.nodrop
;
3985 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3986 (*pretvar
)->lVal
= (s32
) ent
->nograb
;
3991 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
3992 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.nopain
;
3998 if(paramCount
>= 3) {
4000 if(FAILED(ScriptVariant_IntegerValue(arg
, <emp
)))
4003 ScriptVariant_ChangeType(*pretvar
, VT_DECIMAL
);
4004 (*pretvar
)->dblVal
= (double) ent
->modeldata
.offense_factors
[(int) ltemp
];
4007 case _gep_antigravity
:
4009 ScriptVariant_ChangeType(*pretvar
, VT_DECIMAL
);
4010 (*pretvar
)->dblVal
= (double) ent
->antigravity
;
4015 if(ent
->owner
) // always return an empty var if it is NULL
4017 ScriptVariant_ChangeType(*pretvar
, VT_PTR
);
4018 (*pretvar
)->ptrVal
= (void*) ent
->owner
;
4024 if(ent
->parent
) // always return an empty var if it is NULL
4026 ScriptVariant_ChangeType(*pretvar
, VT_PTR
);
4027 (*pretvar
)->ptrVal
= (void*) ent
->parent
;
4033 ScriptVariant_ChangeType(*pretvar
, VT_STR
);
4034 tempstr
= ent
->modeldata
.path
;
4036 strcpy(StrCache_Get((*pretvar
)->strVal
), tempstr
);
4039 case _gep_subentity
:
4041 if(ent
->subentity
) // always return an empty var if it is NULL
4043 ScriptVariant_ChangeType(*pretvar
, VT_PTR
);
4044 (*pretvar
)->ptrVal
= (void*) ent
->subentity
;
4050 if(ent
->opponent
) // always return an empty var if it is NULL
4052 ScriptVariant_ChangeType(*pretvar
, VT_PTR
);
4053 (*pretvar
)->ptrVal
= (void*) ent
->opponent
;
4059 if(ent
->grabbing
) // always return an empty var if it is NULL
4061 ScriptVariant_ChangeType(*pretvar
, VT_PTR
);
4062 (*pretvar
)->ptrVal
= (void*) ent
->grabbing
;
4068 if(ent
->link
) // always return an empty var if it is NULL
4070 ScriptVariant_ChangeType(*pretvar
, VT_PTR
);
4071 (*pretvar
)->ptrVal
= (void*) ent
->link
;
4077 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
4078 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.aimove
;
4081 case _gep_aggression
:
4083 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
4084 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.aggression
;
4089 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
4090 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.aiattack
;
4093 case _gep_attacking
:
4095 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
4096 (*pretvar
)->lVal
= (s32
) ent
->attacking
;
4101 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
4102 (*pretvar
)->lVal
= (s32
) ent
->autokill
;
4107 ScriptVariant_ChangeType(*pretvar
, VT_DECIMAL
);
4108 (*pretvar
)->dblVal
= (double) ent
->modeldata
.scroll
;
4111 case _gep_damage_on_landing
:
4113 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
4114 (*pretvar
)->lVal
= (s32
) ent
->damage_on_landing
;
4119 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
4120 (*pretvar
)->lVal
= (s32
) ent
->dead
;
4125 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
4126 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.stealth
[1];
4131 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
4132 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.stealth
[0];
4135 case _gep_stalltime
:
4137 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
4138 (*pretvar
)->lVal
= (s32
) ent
->stalltime
;
4148 if(arg
->vt
!= VT_INTEGER
|| arg1
->vt
!= VT_INTEGER
) {
4150 ("Incorrect parameters: getentityproperty({ent}, 'stats', {type}, {index}) \n {type}: \n 0 = Model. \n 1 = Entity. \n");
4154 ScriptVariant_ChangeType(*pretvar
, VT_DECIMAL
);
4156 switch (arg
->lVal
) {
4158 if(ent
->modeldata
.stats
[arg1
->lVal
]) {
4159 (*pretvar
)->dblVal
= (double) ent
->modeldata
.stats
[arg1
->lVal
];
4163 if(ent
->stats
[arg1
->lVal
]) {
4164 (*pretvar
)->dblVal
= (double) ent
->stats
[arg1
->lVal
];
4175 if(arg
->vt
!= VT_INTEGER
) {
4177 ("Incorrect parameters: getentityproperty({ent}, 'staydown', {type}) \n {type}: \n 0 = Staydown. \n 1 = Staydownatk. \n");
4181 ScriptVariant_ChangeType(*pretvar
, VT_DECIMAL
);
4182 (*pretvar
)->dblVal
= (double) ent
->staydown
[arg
->lVal
];
4184 case _gep_gfxshadow
:
4186 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
4187 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.gfxshadow
;
4191 case _gep_projectile
:
4193 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
4194 (*pretvar
)->lVal
= (s32
) ent
->projectile
;
4202 if(arg
->vt
!= VT_INTEGER
) {
4203 if(arg
->vt
!= VT_STR
)
4204 printf("You must give a string name for running property.\n");
4209 case _gep_running_speed
:
4211 ScriptVariant_ChangeType(*pretvar
, VT_DECIMAL
);
4212 (*pretvar
)->dblVal
= (double) ent
->modeldata
.runspeed
;
4215 case _gep_running_jumpy
:
4217 ScriptVariant_ChangeType(*pretvar
, VT_DECIMAL
);
4218 (*pretvar
)->dblVal
= (double) ent
->modeldata
.runjumpheight
;
4221 case _gep_running_jumpx
:
4223 ScriptVariant_ChangeType(*pretvar
, VT_DECIMAL
);
4224 (*pretvar
)->dblVal
= (double) ent
->modeldata
.runjumpdist
;
4227 case _gep_running_land
:
4229 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
4230 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.runhold
;
4233 case _gep_running_movez
:
4235 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
4236 (*pretvar
)->lVal
= (s32
) ent
->modeldata
.runupdown
;
4244 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
4245 (*pretvar
)->lVal
= (s32
) ent
->seal
;
4250 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
4251 (*pretvar
)->lVal
= (s32
) ent
->sealtime
;
4259 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
)))
4263 if(arg
->vt
!= VT_INTEGER
) {
4264 if(arg
->vt
!= VT_STR
)
4265 printf("You must give a string name for dot property.\n");
4268 switch (arg
->lVal
) {
4271 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
4272 (*pretvar
)->lVal
= (s32
) ent
->dot_time
[i
];
4277 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
4278 (*pretvar
)->lVal
= (s32
) ent
->dot
[i
];
4281 case _gep_dot_force
:
4284 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
4285 (*pretvar
)->lVal
= (s32
) ent
->dot_force
[i
];
4290 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
4291 (*pretvar
)->lVal
= (s32
) ent
->dot_rate
[i
];
4296 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
4297 (*pretvar
)->lVal
= (s32
) ent
->dot_atk
[i
];
4300 case _gep_dot_owner
:
4302 ScriptVariant_ChangeType(*pretvar
, VT_PTR
);
4303 (*pretvar
)->ptrVal
= (void*) ent
->dot_owner
[i
];
4309 case _gep_blockback
:
4311 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
)))
4312 ent
->modeldata
.blockback
= (int) ltemp
;
4315 case _gep_blockpain
:
4317 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
)))
4318 ent
->modeldata
.blockpain
= (int) ltemp
;
4323 ScriptVariant_ChangeType(*pretvar
, VT_PTR
);
4324 (*pretvar
)->ptrVal
= (void*) ent
->weapent
;
4328 //printf("Property name '%s' is not supported by function getentityproperty.\n", propname);
4337 // ===== changeentityproperty =====
4338 enum changeentityproperty_enum
{
4360 _cep_damage_on_landing
,
4386 _cep_lifespancountdown
,
4389 _cep_maxguardpoints
,
4391 _cep_maxjugglepoints
,
4400 _cep_no_adjust_base
,
4428 _cep_subject_to_gravity
,
4429 _cep_subject_to_hole
,
4430 _cep_subject_to_maxz
,
4431 _cep_subject_to_minz
,
4432 _cep_subject_to_obstacle
,
4433 _cep_subject_to_platform
,
4434 _cep_subject_to_screen
,
4435 _cep_subject_to_wall
,
4440 _cep_throwframewait
,
4450 enum cep_takeaction_enum
{
4451 _cep_ta_bomb_explode
,
4452 _cep_ta_common_attack_proc
,
4453 _cep_ta_common_block
,
4454 _cep_ta_common_drop
,
4455 _cep_ta_common_fall
,
4457 _cep_ta_common_grab
,
4458 _cep_ta_common_grabattack
,
4459 _cep_ta_common_grabbed
,
4460 _cep_ta_common_jump
,
4461 _cep_ta_common_land
,
4463 _cep_ta_common_pain
,
4464 _cep_ta_common_prejump
,
4465 _cep_ta_common_rise
,
4466 _cep_ta_common_spawn
,
4467 _cep_ta_common_turn
,
4468 _cep_ta_common_vault
,
4469 _cep_ta_normal_prepare
,
4471 _cep_ta_player_blink
,
4476 enum _cep_think_enum
{ // 2011_03_03, DC: Think types.
4477 _cep_th_common_think
,
4478 _cep_th_player_think
,
4479 _cep_th_steam_think
,
4480 _cep_th_steamer_think
,
4486 enum cep_hostile_candamage_enum
{
4488 _cep_hcd_type_enemy
,
4490 _cep_hcd_type_obstacle
,
4491 _cep_hcd_type_player
,
4496 enum cep_aiflag_enum
{
4497 _cep_aiflag_animating
,
4498 _cep_aiflag_attacking
,
4499 _cep_aiflag_autokill
,
4501 _cep_aiflag_blocking
,
4502 _cep_aiflag_charging
,
4505 _cep_aiflag_falling
,
4507 _cep_aiflag_getting
,
4510 _cep_aiflag_invincible
,
4511 _cep_aiflag_jumping
,
4512 _cep_aiflag_projectile
,
4513 _cep_aiflag_running
,
4514 _cep_aiflag_toexplode
,
4515 _cep_aiflag_turning
,
4516 _cep_aiflag_the_end
,
4519 void mapstrings_changeentityproperty(ScriptVariant
** varlist
, int paramCount
) {
4523 static const char *proplist
[] = {
4545 "damage_on_landing",
4571 "lifespancountdown",
4613 "subject_to_gravity",
4617 "subject_to_obstacle",
4618 "subject_to_platform",
4619 "subject_to_screen",
4634 static const char *proplist_takeaction
[] = {
4636 "common_attack_proc",
4642 "common_grabattack",
4659 static const char *proplist_think
[] = { // 2011_03_03, DC: Think types.
4668 static const char *proplist_aiflag
[] = {
4690 static const char *proplist_hostile_candamage
[] = {
4703 MAPSTRINGS(varlist
[1], proplist
, _cep_the_end
,
4704 "Property name '%s' is not supported by function changeentityproperty.\n");
4706 // action for takeaction
4707 if((varlist
[1]->vt
== VT_INTEGER
) && (varlist
[1]->lVal
== _cep_takeaction
)) {
4708 MAPSTRINGS(varlist
[2], proplist_takeaction
, _cep_ta_the_end
,
4709 "Action '%s' is not supported by 'takeaction'.\n");
4711 // 2011_03_13, DC: Think sets for think.
4712 if((varlist
[1]->vt
== VT_INTEGER
) && (varlist
[1]->lVal
== _cep_think
)) {
4713 MAPSTRINGS(varlist
[2], proplist_think
, _cep_th_the_end
, "Set '%s' is not supported by 'think'.\n");
4715 // entity type(s) for hostile, candamage, and projectilehit.
4716 if((varlist
[1]->vt
== VT_INTEGER
) &&
4717 ((varlist
[1]->lVal
== _cep_hostile
) || (varlist
[1]->lVal
== _cep_candamage
)
4718 || (varlist
[1]->lVal
== _cep_projectilehit
))) {
4719 for(i
= 2; i
< paramCount
; i
++) {
4720 MAPSTRINGS(varlist
[i
], proplist_hostile_candamage
, _cep_hcd_the_end
,
4721 "Entity type '%s' is not supported by 'hostile', 'candamage', or 'projectilehit'\n");
4724 // AI flag name for aiflag
4725 if((varlist
[1]->vt
== VT_INTEGER
) && (varlist
[1]->lVal
== _cep_aiflag
)) {
4726 MAPSTRINGS(varlist
[2], proplist_aiflag
, _cep_aiflag_the_end
,
4727 "Flag '%s' is not supported by 'aiflag'.\n");
4731 //changeentityproperty(pentity, propname, value1[ ,value2, value3, ...]);
4732 s32
openbor_changeentityproperty(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
4735 char *tempstr
= NULL
;
4740 static const void *think
[] = { // 2011_03_03, DC: Think types.
4748 static const void *actions
[] = { // for takeaction
4773 static const int entitytypes
[] = {
4774 0, // "ground"; not a real entity type
4782 if(paramCount
< 3) {
4783 printf("Function changeentityproperty must have have at least 3 parameters.");
4784 goto changeentityproperty_error
;
4787 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
4788 (*pretvar
)->lVal
= (s32
) 0;
4789 mapstrings_changeentityproperty(varlist
, paramCount
);
4791 if(varlist
[0]->vt
!= VT_PTR
&& varlist
[0]->vt
!= VT_EMPTY
) {
4792 printf("Function changeentityproperty must have a valid entity handle.");
4793 goto changeentityproperty_error
;
4795 ent
= (entity
*) varlist
[0]->ptrVal
; //retrieve the entity
4797 (*pretvar
)->lVal
= (s32
) 0;
4801 if(varlist
[1]->vt
!= VT_INTEGER
) {
4802 if(varlist
[1]->vt
!= VT_STR
)
4803 printf("Function changeentityproperty must have a string property name.\n");
4804 goto changeentityproperty_error
;
4807 propind
= varlist
[1]->lVal
;
4810 case _cep_takeaction
:
4812 if(varlist
[2]->vt
== VT_STR
) { // not a known action; if it were it would been mapped by mapstrings
4813 ent
->takeaction
= NULL
;
4815 } else if(varlist
[2]->vt
!= VT_INTEGER
) {
4816 printf("You must give a string value for action type.\n");
4817 goto changeentityproperty_error
;
4819 // otherwise, the parameter is a known action
4820 ltemp
= varlist
[2]->lVal
;
4821 if((ltemp
>= 0) && (ltemp
< _cep_ta_the_end
)) {
4822 ent
->takeaction
= actions
[(int) ltemp
];
4829 if(varlist
[2]->vt
== VT_STR
) { // not a known action; if it were it would been mapped by mapstrings
4830 //ent->think = NULL;
4832 } else if(varlist
[2]->vt
!= VT_INTEGER
) {
4833 printf("You must give a string value for think type.\n");
4834 goto changeentityproperty_error
;
4836 // otherwise, the parameter is a known action
4837 ltemp
= varlist
[2]->lVal
;
4838 if((ltemp
>= 0) && (ltemp
< _cep_th_the_end
)) {
4839 ent
->think
= think
[(int) ltemp
];
4846 if(varlist
[2]->vt
!= VT_INTEGER
) {
4847 printf("You must provide a type constant for type.\n");
4848 goto changeentityproperty_error
;
4851 ltemp
= varlist
[2]->lVal
;
4852 ent
->modeldata
.type
= (int) ltemp
;
4856 case _cep_candamage
:
4858 ent
->modeldata
.candamage
= 0;
4860 for(i
= 2; i
< paramCount
; i
++) {
4861 if(varlist
[i
]->vt
== VT_INTEGER
) // known entity type
4863 ltemp
= varlist
[i
]->lVal
;
4864 if(ltemp
== _cep_hcd_ground
) // "ground" - not needed?
4865 ent
->modeldata
.ground
= 1;
4867 ent
->modeldata
.candamage
|= entitytypes
[(int) ltemp
];
4869 printf("You must pass one or more string constants for entity type.\n");
4870 goto changeentityproperty_error
;
4878 ent
->modeldata
.hostile
= 0;
4880 for(i
= 2; i
< paramCount
; i
++) {
4881 if(varlist
[i
]->vt
== VT_INTEGER
) // known entity type
4883 ltemp
= varlist
[i
]->lVal
;
4884 ent
->modeldata
.hostile
|= entitytypes
[(int) ltemp
];
4886 printf("You must pass one or more string constants for entity type.\n");
4887 goto changeentityproperty_error
;
4893 case _cep_projectilehit
:
4896 ent
->modeldata
.projectilehit
= 0;
4898 for(i
= 2; i
< paramCount
; i
++) {
4899 if(varlist
[i
]->vt
== VT_INTEGER
) // known entity type
4901 ltemp
= varlist
[i
]->lVal
;
4902 ent
->modeldata
.projectilehit
|= entitytypes
[(int) ltemp
];
4904 printf("You must pass one or more string constants for entity type.\n");
4905 goto changeentityproperty_error
;
4914 if(varlist
[2]->vt
!= VT_STR
) {
4915 printf("You must give a string value for model name.\n");
4916 goto changeentityproperty_error
;
4918 tempstr
= (char *) StrCache_Get(varlist
[2]->strVal
);
4919 if(paramCount
> 3) {
4920 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[3], <emp
)))
4921 (*pretvar
)->lVal
= (s32
) 1;
4924 (*pretvar
)->lVal
= (s32
) 1;
4926 if((*pretvar
)->lVal
== (s32
) 1)
4927 set_model_ex(ent
, tempstr
, -1, NULL
, (int) ltemp
);
4934 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
4935 if(paramCount
> 3) {
4936 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[3], <emp2
)))
4937 (*pretvar
)->lVal
= (s32
) 1;
4940 (*pretvar
)->lVal
= (s32
) 1;
4942 set_weapon(ent
, (int) ltemp
, (int) ltemp2
);
4943 (*pretvar
)->lVal
= (s32
) 1;
4947 case _cep_maxhealth
:
4949 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
4950 (*pretvar
)->lVal
= (s32
) 1;
4951 ent
->modeldata
.health
= (int) ltemp
;
4952 if(ent
->modeldata
.health
< 0)
4953 ent
->modeldata
.health
= 0; //OK, no need to have ot below 0
4959 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
4960 ent
->health
= (int) ltemp
;
4961 if(ent
->health
> ent
->modeldata
.health
)
4962 ent
->health
= ent
->modeldata
.health
;
4963 else if(ent
->health
< 0)
4965 (*pretvar
)->lVal
= (s32
) 1;
4971 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
4972 ent
->modeldata
.mp
= (int) ltemp
;
4973 if(ent
->modeldata
.mp
< 0)
4974 ent
->modeldata
.mp
= 0; //OK, no need to have ot below 0
4975 (*pretvar
)->lVal
= (s32
) 1;
4981 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
4982 ent
->mp
= (int) ltemp
;
4983 if(ent
->mp
> ent
->modeldata
.mp
)
4984 ent
->mp
= ent
->modeldata
.mp
;
4985 else if(ent
->mp
< 0)
4987 (*pretvar
)->lVal
= (s32
) 1;
4993 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
4994 ent
->modeldata
.setlayer
= (int) ltemp
;
4995 (*pretvar
)->lVal
= (s32
) 1;
5001 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[2], &dbltemp
))) {
5002 (*pretvar
)->lVal
= (s32
) 1;
5003 ent
->modeldata
.speed
= (float) dbltemp
;
5007 case _cep_throwdamage
:
5009 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
5010 ent
->modeldata
.throwdamage
= (int) ltemp
;
5011 (*pretvar
)->lVal
= (s32
) 1;
5015 case _cep_throwdist
:
5017 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[2], &dbltemp
))) {
5018 (*pretvar
)->lVal
= (s32
) 1;
5019 ent
->modeldata
.throwdist
= (float) dbltemp
;
5023 case _cep_throwframewait
:
5025 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
5026 ent
->modeldata
.throwframewait
= (int) ltemp
;
5027 (*pretvar
)->lVal
= (s32
) 1;
5031 case _cep_throwheight
:
5033 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[2], &dbltemp
))) {
5034 (*pretvar
)->lVal
= (s32
) 1;
5035 ent
->modeldata
.throwheight
= (float) dbltemp
;
5041 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
5042 (*pretvar
)->lVal
= (s32
) 1;
5043 ent
->animation
->animhits
= (int) ltemp
;
5049 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
5050 (*pretvar
)->lVal
= (s32
) 1;
5051 ent
->modeldata
.alpha
= (int) ltemp
;
5055 case _cep_guardpoints
:
5057 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
5058 (*pretvar
)->lVal
= (s32
) 1;
5059 ent
->modeldata
.guardpoints
[0] = (int) ltemp
;
5063 case _cep_maxguardpoints
:
5065 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
5066 (*pretvar
)->lVal
= (s32
) 1;
5067 ent
->modeldata
.guardpoints
[1] = (int) ltemp
;
5071 case _cep_jugglepoints
:
5073 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
5074 (*pretvar
)->lVal
= (s32
) 1;
5075 ent
->modeldata
.jugglepoints
[0] = (int) ltemp
;
5081 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
5082 (*pretvar
)->lVal
= (s32
) 1;
5083 ent
->modeldata
.komap
[0] = (int) ltemp
;
5085 if(paramCount
>= 4 && (*pretvar
)->lVal
== (s32
) 1) {
5086 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[3], <emp
)))
5087 ent
->modeldata
.komap
[1] = (int) ltemp
;
5089 (*pretvar
)->lVal
= (s32
) 0;
5093 case _cep_maxjugglepoints
:
5095 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
5096 (*pretvar
)->lVal
= (s32
) 1;
5097 ent
->modeldata
.jugglepoints
[1] = (int) ltemp
;
5101 case _cep_antigravity
:
5103 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[2], &dbltemp
))) {
5104 (*pretvar
)->lVal
= (s32
) 1;
5105 ent
->modeldata
.antigravity
= (float) dbltemp
;
5111 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
5112 ent_set_colourmap(ent
, (int) ltemp
);
5113 (*pretvar
)->lVal
= (s32
) 1;
5119 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
5120 (*pretvar
)->lVal
= (s32
) 1;
5121 ent
->maptime
= (int) ltemp
;
5125 case _cep_colourmap
:
5127 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
5128 (*pretvar
)->lVal
= (s32
) 1;
5129 self
->colourmap
= self
->modeldata
.colourmap
[ltemp
- 1];
5135 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
)))
5136 (*pretvar
)->lVal
= (s32
) 1;
5137 self
->modeldata
.hmap1
= ltemp
;
5142 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
)))
5143 (*pretvar
)->lVal
= (s32
) 1;
5144 self
->modeldata
.hmap2
= ltemp
;
5149 if(varlist
[2]->vt
!= VT_STR
) {
5150 printf("You must give a string value for entity name.\n");
5151 goto changeentityproperty_error
;
5153 strcpy(ent
->name
, (char *) StrCache_Get(varlist
[2]->strVal
));
5154 (*pretvar
)->lVal
= (s32
) 1;
5157 case _cep_defaultname
:
5159 if(varlist
[2]->vt
!= VT_STR
) {
5160 printf("You must give a string value for entity name.\n");
5161 goto changeentityproperty_error
;
5163 tempmodel
= findmodel((char *) StrCache_Get(varlist
[2]->strVal
));
5166 ("Use must give an existing model's name for entity's default model name.\n");
5167 goto changeentityproperty_error
;
5169 ent
->defaultmodel
= tempmodel
;
5170 (*pretvar
)->lVal
= (s32
) 1;
5175 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[2], &dbltemp
))) {
5176 (*pretvar
)->lVal
= (s32
) 1;
5177 ent
->x
= (float) dbltemp
;
5179 if(paramCount
>= 4 && (*pretvar
)->lVal
== (s32
) 1) {
5180 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[3], &dbltemp
)))
5181 ent
->z
= (float) dbltemp
;
5183 (*pretvar
)->lVal
= (s32
) 0;
5185 if(paramCount
>= 5 && (*pretvar
)->lVal
== (s32
) 1) {
5186 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[4], &dbltemp
)))
5187 ent
->a
= (float) dbltemp
;
5189 (*pretvar
)->lVal
= (s32
) 0;
5195 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[2], &dbltemp
))) {
5196 ent
->base
= (float) dbltemp
;
5197 (*pretvar
)->lVal
= (s32
) 1;
5201 case _cep_direction
:
5203 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[2], &dbltemp
))) {
5204 ent
->direction
= (int) dbltemp
;
5205 (*pretvar
)->lVal
= (s32
) 1;
5211 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
5212 (*pretvar
)->lVal
= (s32
) 1;
5214 ent
->trymove
= common_trymove
;
5216 ent
->trymove
= player_trymove
;
5218 ent
->trymove
= NULL
;
5224 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
5225 (*pretvar
)->lVal
= (s32
) 1;
5226 ent
->nextanim
= (int) ltemp
;
5230 case _cep_nextthink
:
5232 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
5233 (*pretvar
)->lVal
= (s32
) 1;
5234 ent
->nextthink
= (int) ltemp
;
5240 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
5241 (*pretvar
)->lVal
= (s32
) 1;
5242 ent
->toss_time
= (int) ltemp
;
5248 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[2], &dbltemp
))) {
5249 (*pretvar
)->lVal
= (s32
) 1;
5250 ent
->xdir
= (float) dbltemp
;
5252 if(paramCount
>= 4 && (*pretvar
)->lVal
== (s32
) 1) {
5253 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[3], &dbltemp
)))
5254 ent
->zdir
= (float) dbltemp
;
5256 (*pretvar
)->lVal
= (s32
) 0;
5258 if(paramCount
>= 5 && (*pretvar
)->lVal
== (s32
) 1) {
5259 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[4], &dbltemp
)))
5260 ent
->tossv
= (float) dbltemp
;
5262 (*pretvar
)->lVal
= (s32
) 0;
5268 if(paramCount
>= 4 &&
5269 SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
)) &&
5270 ltemp
< (s32
) MAX_ATKS
&& ltemp
>= (s32
) 0) {
5271 (*pretvar
)->lVal
= (s32
) 1;
5273 if((*pretvar
)->lVal
== (s32
) 1) {
5274 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[3], &dbltemp
)))
5275 ent
->modeldata
.defense_factors
[(int) ltemp
] = (float) dbltemp
;
5277 (*pretvar
)->lVal
= (s32
) 0;
5279 if(paramCount
>= 5 && (*pretvar
)->lVal
== (s32
) 1) {
5280 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[4], &dbltemp
)))
5281 ent
->modeldata
.defense_pain
[(int) ltemp
] = (float) dbltemp
;
5283 (*pretvar
)->lVal
= (s32
) 0;
5285 if(paramCount
>= 6 && (*pretvar
)->lVal
== (s32
) 1) {
5286 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[5], &dbltemp
)))
5287 ent
->modeldata
.defense_knockdown
[(int) ltemp
] = (float) dbltemp
;
5289 (*pretvar
)->lVal
= (s32
) 0;
5291 if(paramCount
>= 7 && (*pretvar
)->lVal
== (s32
) 1) {
5292 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[6], &dbltemp
)))
5293 ent
->modeldata
.defense_blockpower
[(int) ltemp
] = (float) dbltemp
;
5295 (*pretvar
)->lVal
= (s32
) 0;
5297 if(paramCount
>= 8 && (*pretvar
)->lVal
== (s32
) 1) {
5298 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[7], &dbltemp
)))
5299 ent
->modeldata
.defense_blockthreshold
[(int) ltemp
] = (float) dbltemp
;
5301 (*pretvar
)->lVal
= (s32
) 0;
5303 if(paramCount
>= 9 && (*pretvar
)->lVal
== (s32
) 1) {
5304 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[8], &dbltemp
)))
5305 ent
->modeldata
.defense_blockratio
[(int) ltemp
] = (float) dbltemp
;
5307 (*pretvar
)->lVal
= (s32
) 0;
5309 if(paramCount
>= 10 && (*pretvar
)->lVal
== (s32
) 1) {
5310 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[9], &dbltemp
)))
5311 ent
->modeldata
.defense_blocktype
[(int) ltemp
] = (float) dbltemp
;
5313 (*pretvar
)->lVal
= (s32
) 0;
5319 if(paramCount
>= 4 &&
5320 SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
)) &&
5321 ltemp
< (s32
) MAX_ATKS
&& ltemp
>= (s32
) 0) {
5322 (*pretvar
)->lVal
= (s32
) 1;
5324 if((*pretvar
)->lVal
== (s32
) 1) {
5325 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[3], &dbltemp
)))
5326 ent
->modeldata
.offense_factors
[(int) ltemp
] = (float) dbltemp
;
5328 (*pretvar
)->lVal
= (s32
) 0;
5332 case _cep_grabforce
:
5334 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
)))
5335 ent
->model
->grabforce
= (int) ltemp
;
5340 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
)))
5341 ent
->model
->antigrab
= (int) ltemp
;
5346 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
)))
5347 ent
->modeldata
.nodrop
= (int) ltemp
;
5352 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
)))
5353 ent
->modeldata
.nopain
= (int) ltemp
;
5358 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
)))
5359 ent
->nograb
= (int) ltemp
;
5362 case _cep_no_adjust_base
:
5364 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
)))
5365 ent
->modeldata
.no_adjust_base
= (int) ltemp
;
5368 case _cep_noaicontrol
:
5370 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
)))
5371 ent
->noaicontrol
= (int) ltemp
;
5374 case _cep_nodieblink
:
5376 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
)))
5377 ent
->modeldata
.nodieblink
= (int) ltemp
;
5382 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
)))
5383 ent
->modeldata
.falldie
= (int) ltemp
;
5386 case _cep_freezetime
:
5388 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
)))
5389 ent
->freezetime
= (int) ltemp
;
5394 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
)))
5395 ent
->frozen
= (int) ltemp
;
5400 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
)))
5401 ent
->modeldata
.bounce
= (int) ltemp
;
5406 if(varlist
[2]->vt
!= VT_INTEGER
) {
5407 if(varlist
[2]->vt
!= VT_STR
)
5408 printf("You must give a string value for AI flag name.\n");
5409 goto changeentityproperty_error
;
5414 switch (varlist
[2]->lVal
) {
5415 case _cep_aiflag_dead
:
5417 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[3], <emp
)))
5418 ent
->dead
= (int) ltemp
;
5421 case _cep_aiflag_jumping
:
5423 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[3], <emp
)))
5424 ent
->jumping
= (int) ltemp
;
5427 case _cep_aiflag_idling
:
5429 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[3], <emp
)))
5430 ent
->idling
= (int) ltemp
;
5433 case _cep_aiflag_drop
:
5435 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[3], <emp
)))
5436 ent
->drop
= (int) ltemp
;
5439 case _cep_aiflag_attacking
:
5441 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[3], <emp
)))
5442 ent
->attacking
= (int) ltemp
;
5445 case _cep_aiflag_getting
:
5447 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[3], <emp
)))
5448 ent
->getting
= (int) ltemp
;
5451 case _cep_aiflag_turning
:
5453 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[3], <emp
)))
5454 ent
->turning
= (int) ltemp
;
5457 case _cep_aiflag_charging
:
5459 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[3], <emp
)))
5460 ent
->charging
= (int) ltemp
;
5463 case _cep_aiflag_blocking
:
5465 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[3], <emp
)))
5466 ent
->blocking
= (int) ltemp
;
5469 case _cep_aiflag_falling
:
5471 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[3], <emp
)))
5472 ent
->falling
= (int) ltemp
;
5475 case _cep_aiflag_running
:
5477 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[3], <emp
)))
5478 ent
->running
= (int) ltemp
;
5481 case _cep_aiflag_inpain
:
5483 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[3], <emp
)))
5484 ent
->inpain
= (int) ltemp
;
5487 case _cep_aiflag_projectile
:
5489 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[3], <emp
)))
5490 ent
->projectile
= (int) ltemp
;
5493 case _cep_aiflag_frozen
:
5495 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[3], <emp
)))
5496 ent
->frozen
= (int) ltemp
;
5499 case _cep_aiflag_toexplode
:
5501 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[3], <emp
)))
5502 ent
->toexplode
= (int) ltemp
;
5505 case _cep_aiflag_animating
:
5507 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[3], <emp
)))
5508 ent
->animating
= (int) ltemp
;
5511 case _cep_aiflag_blink
:
5513 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[3], <emp
)))
5514 ent
->blink
= (int) ltemp
;
5517 case _cep_aiflag_invincible
:
5519 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[3], <emp
)))
5520 ent
->invincible
= (int) ltemp
;
5523 case _cep_aiflag_autokill
:
5525 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[3], <emp
)))
5526 ent
->autokill
= (int) ltemp
;
5530 printf("Unknown AI flag.\n");
5531 goto changeentityproperty_error
;
5535 case _cep_animation
:
5537 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
)))
5538 (*pretvar
)->lVal
= (s32
) 1;
5539 if(paramCount
>= 4) {
5540 if(FAILED(ScriptVariant_IntegerValue(varlist
[3], <emp2
)))
5541 (*pretvar
)->lVal
= (s32
) 0;
5544 if((*pretvar
)->lVal
== (s32
) 1) {
5545 ent_set_anim(ent
, (int) ltemp
, (int) ltemp2
);
5551 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
)))
5552 ent
->animpos
= (int) ltemp
;
5555 case _cep_invincible
:
5557 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
5558 ent
->invincible
= (int) ltemp
;
5559 (*pretvar
)->lVal
= (s32
) 1;
5563 case _cep_invinctime
:
5565 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
)))
5566 ent
->invinctime
= (int) ltemp
;
5569 case _cep_rush_count
:
5571 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
5572 (*pretvar
)->lVal
= (s32
) 1;
5573 ent
->rush
[0] = (int) ltemp
;
5577 case _cep_rush_tally
:
5579 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
5580 (*pretvar
)->lVal
= (s32
) 1;
5581 ent
->rush
[1] = (int) ltemp
;
5585 case _cep_rush_time
:
5587 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
)))
5588 ent
->rushtime
= (int) ltemp
;
5591 case _cep_iconposition
:
5593 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
)))
5594 ent
->modeldata
.iconx
= (int) ltemp
;
5595 if(paramCount
> 3 && SUCCEEDED(ScriptVariant_IntegerValue(varlist
[3], <emp
)))
5596 ent
->modeldata
.icony
= (int) ltemp
;
5599 case _cep_lifeposition
:
5601 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
)))
5602 ent
->modeldata
.hpx
= (int) ltemp
;
5603 if(paramCount
> 3 && SUCCEEDED(ScriptVariant_IntegerValue(varlist
[3], <emp
)))
5604 ent
->modeldata
.hpy
= (int) ltemp
;
5607 case _cep_nameposition
:
5609 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
)))
5610 ent
->modeldata
.namex
= (int) ltemp
;
5611 if(paramCount
> 3 && SUCCEEDED(ScriptVariant_IntegerValue(varlist
[3], <emp
)))
5612 ent
->modeldata
.namey
= (int) ltemp
;
5615 case _cep_lifespancountdown
:
5617 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[2], &dbltemp
)))
5618 ent
->lifespancountdown
= (float) dbltemp
;
5623 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
5624 ent
->blink
= (int) ltemp
;
5625 (*pretvar
)->lVal
= (s32
) 1;
5629 case _cep_subject_to_screen
:
5631 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
5632 ent
->modeldata
.subject_to_screen
= (int) ltemp
;
5633 (*pretvar
)->lVal
= (s32
) 1;
5637 case _cep_subject_to_maxz
:
5639 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
5640 ent
->modeldata
.subject_to_maxz
= (int) ltemp
;
5641 (*pretvar
)->lVal
= (s32
) 1;
5645 case _cep_subject_to_minz
:
5647 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
5648 ent
->modeldata
.subject_to_minz
= (int) ltemp
;
5649 (*pretvar
)->lVal
= (s32
) 1;
5653 case _cep_subject_to_wall
:
5655 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
5656 ent
->modeldata
.subject_to_wall
= (int) ltemp
;
5657 (*pretvar
)->lVal
= (s32
) 1;
5661 case _cep_subject_to_obstacle
:
5663 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
5664 ent
->modeldata
.subject_to_obstacle
= (int) ltemp
;
5665 (*pretvar
)->lVal
= (s32
) 1;
5669 case _cep_subject_to_platform
:
5671 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
5672 ent
->modeldata
.subject_to_platform
= (int) ltemp
;
5673 (*pretvar
)->lVal
= (s32
) 1;
5677 case _cep_subject_to_gravity
:
5679 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
5680 ent
->modeldata
.subject_to_gravity
= (int) ltemp
;
5681 (*pretvar
)->lVal
= (s32
) 1;
5685 case _cep_subject_to_hole
:
5687 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
5688 ent
->modeldata
.subject_to_hole
= (int) ltemp
;
5689 (*pretvar
)->lVal
= (s32
) 1;
5695 ent
->owner
= (entity
*) varlist
[2]->ptrVal
;
5700 ent
->parent
= (entity
*) varlist
[2]->ptrVal
;
5705 ent
->opponent
= (entity
*) varlist
[2]->ptrVal
;
5708 case _cep_subentity
:
5711 ent
->subentity
->parent
= NULL
;
5712 ent
->subentity
= (entity
*) varlist
[2]->ptrVal
;
5714 ent
->subentity
->parent
= ent
;
5719 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
)))
5720 ent
->modeldata
.aimove
= (int) ltemp
;
5723 case _cep_aggression
:
5725 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
)))
5726 ent
->modeldata
.aggression
= (int) ltemp
;
5731 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
)))
5732 ent
->modeldata
.aiattack
= (int) ltemp
;
5735 case _cep_combostep
:
5737 if(paramCount
>= 4 && SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
5738 (*pretvar
)->lVal
= (s32
) 1;
5740 if((*pretvar
)->lVal
== (s32
) 1) {
5741 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[3], <emp2
)))
5742 ent
->combostep
[(int) ltemp
] = (int) ltemp2
;
5744 (*pretvar
)->lVal
= (s32
) 0;
5748 case _cep_attacking
:
5750 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
5751 ent
->attacking
= (int) ltemp
;
5752 (*pretvar
)->lVal
= (s32
) 1;
5758 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[2], &dbltemp
))) {
5759 (*pretvar
)->lVal
= (s32
) 1;
5760 ent
->modeldata
.scroll
= (float) dbltemp
;
5766 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
5767 ent
->autokill
= (int) ltemp
;
5768 (*pretvar
)->lVal
= (s32
) 1;
5772 case _cep_damage_on_landing
:
5774 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
)))
5775 ent
->damage_on_landing
= (int) ltemp
;
5780 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
)))
5781 ent
->dead
= (int) ltemp
;
5786 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
)))
5787 ent
->modeldata
.stealth
[1] = (int) ltemp
;
5790 case _cep_stalltime
:
5792 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
)))
5793 ent
->stalltime
= (int) ltemp
;
5801 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[3], <emp
))) {
5802 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[4], &dbltemp
))) {
5803 switch (varlist
[2]->lVal
) {
5805 ent
->modeldata
.stats
[(int) ltemp
] = (float) dbltemp
;
5808 ent
->stats
[(int) ltemp
] = (float) dbltemp
;
5817 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
)))
5818 ent
->attack_id
= (int) ltemp
;
5823 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
)))
5824 ent
->hit_by_attack_id
= (int) ltemp
;
5829 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
5830 (*pretvar
)->lVal
= (s32
) 1;
5831 ent
->staydown
[0] = (int) ltemp
;
5833 if(paramCount
>= 4 && (*pretvar
)->lVal
== (s32
) 1) {
5834 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[3], <emp
)))
5835 ent
->staydown
[1] = (int) ltemp
;
5840 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
)))
5841 ent
->modeldata
.stealth
[0] = (int) ltemp
;
5844 case _cep_gfxshadow
:
5846 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
)))
5847 ent
->modeldata
.gfxshadow
= (int) ltemp
;
5850 case _cep_projectile
:
5852 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
)))
5853 ent
->projectile
= (int) ltemp
;
5858 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[2], &dbltemp
))) {
5859 (*pretvar
)->lVal
= (s32
) 1;
5860 ent
->modeldata
.runspeed
= (float) dbltemp
;
5862 if(paramCount
>= 4 && (*pretvar
)->lVal
== (s32
) 1) {
5863 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[3], &dbltemp
)))
5864 ent
->modeldata
.runjumpheight
= (float) dbltemp
;
5866 if(paramCount
>= 5 && (*pretvar
)->lVal
== (s32
) 1) {
5867 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[4], &dbltemp
)))
5868 ent
->modeldata
.runjumpdist
= (float) dbltemp
;
5870 if(paramCount
>= 6 && (*pretvar
)->lVal
== (s32
) 1) {
5871 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[5], &dbltemp
)))
5872 ent
->modeldata
.runhold
= (int) dbltemp
;
5874 if(paramCount
>= 7 && (*pretvar
)->lVal
== (s32
) 1) {
5875 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[6], &dbltemp
)))
5876 ent
->modeldata
.runupdown
= (int) dbltemp
;
5883 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
)))
5884 ent
->seal
= (int) ltemp
;
5889 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
)))
5890 ent
->sealtime
= (int) ltemp
;
5895 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
5898 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[3], &dbltemp
))) {
5899 (*pretvar
)->lVal
= (s32
) 1;
5900 ent
->dot_time
[i
] = (int) dbltemp
;
5902 if(paramCount
>= 5 && (*pretvar
)->lVal
== (s32
) 1) {
5903 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[4], &dbltemp
)))
5904 ent
->dot
[i
] = (int) dbltemp
;
5906 (*pretvar
)->lVal
= (s32
) 0;
5908 if(paramCount
>= 6 && (*pretvar
)->lVal
== (s32
) 1) {
5909 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[5], &dbltemp
)))
5910 ent
->dot_force
[i
] = (int) dbltemp
;
5912 (*pretvar
)->lVal
= (s32
) 0;
5914 if(paramCount
>= 7 && (*pretvar
)->lVal
== (s32
) 1) {
5915 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[6], &dbltemp
)))
5916 ent
->dot_rate
[i
] = (int) dbltemp
;
5918 (*pretvar
)->lVal
= (s32
) 0;
5920 if(paramCount
>= 8 && (*pretvar
)->lVal
== (s32
) 1) {
5921 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[7], &dbltemp
)))
5922 ent
->dot_atk
[i
] = (int) dbltemp
;
5924 (*pretvar
)->lVal
= (s32
) 0;
5926 if(paramCount
>= 9) {
5927 ent
->dot_owner
[i
] = (entity
*) varlist
[8]->ptrVal
;
5933 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
5934 (*pretvar
)->lVal
= (s32
) 1;
5935 ent
->modeldata
.edelay
.mode
= (int) ltemp
;
5937 if(paramCount
>= 3 && (*pretvar
)->lVal
== (s32
) 1) {
5938 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[4], &dbltemp
)))
5939 ent
->modeldata
.edelay
.factor
= (float) dbltemp
;
5941 if(paramCount
>= 4 && (*pretvar
)->lVal
== (s32
) 1) {
5942 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[4], <emp
)))
5943 ent
->modeldata
.edelay
.cap_min
= (int) ltemp
;
5945 (*pretvar
)->lVal
= (s32
) 0;
5947 if(paramCount
>= 5 && (*pretvar
)->lVal
== (s32
) 1) {
5948 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[5], <emp
)))
5949 ent
->modeldata
.edelay
.cap_max
= (int) ltemp
;
5951 (*pretvar
)->lVal
= (s32
) 0;
5953 if(paramCount
>= 6 && (*pretvar
)->lVal
== (s32
) 1) {
5954 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[6], <emp
)))
5955 ent
->modeldata
.edelay
.range_min
= (int) ltemp
;
5957 (*pretvar
)->lVal
= (s32
) 0;
5959 if(paramCount
>= 7 && (*pretvar
)->lVal
== (s32
) 1) {
5960 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[7], <emp
)))
5961 ent
->modeldata
.edelay
.range_max
= (int) ltemp
;
5963 (*pretvar
)->lVal
= (s32
) 0;
5967 case _cep_energycost
:
5969 if(paramCount
!= 6) {
5971 ("\n Error, changeentityproperty({ent}, 'energycost', {animation}, {cost}, {mponly}, {disable}): Invalid or missing parameter. \n");
5972 goto changeentityproperty_error
;
5975 (*pretvar
)->lVal
= (s32
) 1;
5977 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
5981 if(!validanim(ent
, i
)) {
5983 ("\n Error, changeentityproperty({ent}, 'energycost', {animation}, {cost}, {mponly}, {disable}): {animation} parameter invalid. Make sure the animation exists. \n");
5984 goto changeentityproperty_error
;
5987 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[3], <emp
))) {
5988 ent
->modeldata
.animation
[i
]->energycost
[0] = (int) ltemp
;
5991 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[4], <emp
))) {
5992 ent
->modeldata
.animation
[i
]->energycost
[1] = (int) ltemp
;
5995 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[5], <emp
))) {
5996 ent
->modeldata
.animation
[i
]->energycost
[2] = (int) ltemp
;
6003 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[2], &dbltemp
))) {
6004 (*pretvar
)->lVal
= (s32
) 1;
6005 ent
->modeldata
.mp
= (int) dbltemp
;
6007 if(paramCount
>= 4 && (*pretvar
)->lVal
== (s32
) 1) {
6008 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[3], &dbltemp
)))
6009 ent
->modeldata
.mpstable
= (int) dbltemp
;
6011 if(paramCount
>= 5 && (*pretvar
)->lVal
== (s32
) 1) {
6012 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[4], &dbltemp
)))
6013 ent
->modeldata
.mpstableval
= (int) dbltemp
;
6015 if(paramCount
>= 6 && (*pretvar
)->lVal
== (s32
) 1) {
6016 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[5], &dbltemp
)))
6017 ent
->modeldata
.mprate
= (int) dbltemp
;
6019 if(paramCount
>= 7 && (*pretvar
)->lVal
== (s32
) 1) {
6020 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[6], &dbltemp
)))
6021 ent
->modeldata
.mpdroprate
= (int) dbltemp
;
6023 if(paramCount
>= 8 && (*pretvar
)->lVal
== (s32
) 1) {
6024 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[7], &dbltemp
)))
6025 ent
->modeldata
.chargerate
= (int) dbltemp
;
6029 case _cep_blockback
:
6031 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
)))
6032 ent
->modeldata
.blockback
= (int) ltemp
;
6035 case _cep_blockpain
:
6037 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
)))
6038 ent
->modeldata
.blockpain
= (int) ltemp
;
6042 //printf("Property name '%s' is not supported by function changeentityproperty.\n", propname);
6043 goto changeentityproperty_error
;
6048 changeentityproperty_error
:
6053 //tossentity(entity, height, speedx, speedz)
6054 s32
openbor_tossentity(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
6056 double height
= 0, speedx
= 0, speedz
= 0;
6058 if(paramCount
< 1) {
6063 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
6064 (*pretvar
)->lVal
= (s32
) 1;
6066 ent
= (entity
*) varlist
[0]->ptrVal
; //retrieve the entity
6068 (*pretvar
)->lVal
= (s32
) 0;
6073 if(paramCount
>= 2) {
6074 if(FAILED(ScriptVariant_DecimalValue(varlist
[1], &height
))) {
6075 (*pretvar
)->lVal
= (s32
) 0;
6079 if(paramCount
>= 3) {
6080 if(FAILED(ScriptVariant_DecimalValue(varlist
[2], &speedx
))) {
6081 (*pretvar
)->lVal
= (s32
) 0;
6085 if(paramCount
>= 4) {
6086 if(FAILED(ScriptVariant_DecimalValue(varlist
[3], &speedz
))) {
6087 (*pretvar
)->lVal
= (s32
) 0;
6091 ent
->xdir
= (float) speedx
;
6092 ent
->zdir
= (float) speedz
;
6093 toss(ent
, (float) height
);
6097 // ===== getplayerproperty =====
6098 enum getplayerproperty_enum
{
6111 void mapstrings_getplayerproperty(ScriptVariant
** varlist
, int paramCount
) {
6115 static const char *proplist
[] = {
6131 MAPSTRINGS(varlist
[1], proplist
, _gpp_the_end
,
6132 "Property name '%s' is not supported by function getplayerproperty.\n");
6135 //getplayerproperty(index, propname);
6136 s32
openbor_getplayerproperty(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
6141 ScriptVariant
*arg
= NULL
;
6143 if(paramCount
< 2) {
6148 mapstrings_getplayerproperty(varlist
, paramCount
);
6149 ScriptVariant_Clear(*pretvar
);
6152 if(FAILED(ScriptVariant_IntegerValue(arg
, <emp
))) {
6155 index
= (int) ltemp
;
6156 if(!(ent
= player
[index
].ent
)) //this player is not selected, so just return
6158 return S_OK
; //return S_OK, to tell the engine it is not a FATAL error
6162 if(arg
->vt
!= VT_INTEGER
) {
6163 if(arg
->vt
!= VT_STR
)
6165 ("Function call getplayerproperty has invalid propery name parameter, it must be a string value.\n");
6176 ScriptVariant_ChangeType(*pretvar
, VT_PTR
);
6177 (*pretvar
)->ptrVal
= (void*) ent
;
6182 ScriptVariant_ChangeType(*pretvar
, VT_STR
);
6183 strncpy(StrCache_Get((*pretvar
)->strVal
), (char *) player
[index
].name
, MAX_STR_VAR_LEN
);
6188 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
6189 (*pretvar
)->lVal
= (s32
) player
[index
].score
;
6194 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
6195 (*pretvar
)->lVal
= (s32
) player
[index
].lives
;
6200 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
6201 (*pretvar
)->lVal
= (s32
) player
[index
].playkeys
;
6206 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
6207 (*pretvar
)->lVal
= (s32
) player
[index
].keys
;
6212 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
6214 (*pretvar
)->lVal
= (s32
) player
[index
].credits
;
6216 (*pretvar
)->lVal
= credits
;
6221 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
6222 (*pretvar
)->lVal
= (s32
) player
[index
].weapnum
;
6225 //this property is not known
6233 // ===== changeplayerproperty =====
6234 enum changeplayerproperty_enum
{
6244 void mapstrings_changeplayerproperty(ScriptVariant
** varlist
, int paramCount
) {
6248 static const char *proplist
[] = {
6261 MAPSTRINGS(varlist
[1], proplist
, _cpp_the_end
,
6262 "Property name '%s' is not supported by function changeplayerproperty.\n");
6265 //changeplayerproperty(index, propname, value[, value2, value3,...]);
6266 s32
openbor_changeplayerproperty(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
6271 char *tempstr
= NULL
;
6272 ScriptVariant
*arg
= NULL
;
6274 if(paramCount
< 3) {
6279 mapstrings_changeplayerproperty(varlist
, paramCount
);
6280 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
6281 (*pretvar
)->lVal
= (s32
) 1;
6283 if(FAILED(ScriptVariant_IntegerValue(arg
, <emp
))) {
6286 index
= (int) ltemp
;
6288 if(!(ent
= player
[index
].ent
)) //this player is not selected, so just return
6290 return S_OK
; //return S_OK, to tell the engine it is not a FATAL error
6293 if(varlist
[1]->vt
!= VT_INTEGER
) {
6294 if(varlist
[1]->vt
!= VT_STR
)
6295 printf("You must give a string value for player property name.\n");
6298 prop
= varlist
[1]->lVal
;
6306 if(SUCCEEDED(ScriptVariant_IntegerValue(arg
, <emp
))) {
6307 if(paramCount
> 3) {
6309 if(SUCCEEDED(ScriptVariant_IntegerValue(arg
, <emp2
)))
6310 (*pretvar
)->lVal
= (s32
) 1;
6313 (*pretvar
)->lVal
= (s32
) 1;
6315 set_weapon(player
[index
].ent
, (int) ltemp
, (int) ltemp2
);
6316 (*pretvar
)->lVal
= (s32
) 1;
6318 (*pretvar
)->lVal
= (s32
) 0;
6323 if(arg
->vt
!= VT_STR
) {
6327 tempstr
= (char *) StrCache_Get(arg
->strVal
);
6328 strcpy(player
[index
].name
, tempstr
);
6329 (*pretvar
)->lVal
= (s32
) 1;
6334 if(SUCCEEDED(ScriptVariant_IntegerValue(arg
, <emp
))) {
6337 else if(ltemp
> 999999999)
6339 player
[index
].score
= (unsigned int) ltemp
;
6341 (*pretvar
)->lVal
= (s32
) 0;
6346 if(SUCCEEDED(ScriptVariant_IntegerValue(arg
, <emp
)))
6347 player
[index
].lives
= (int) ltemp
;
6349 (*pretvar
)->lVal
= (s32
) 0;
6354 if(SUCCEEDED(ScriptVariant_IntegerValue(arg
, <emp
)))
6355 player
[index
].playkeys
= (int) ltemp
;
6357 (*pretvar
)->lVal
= (s32
) 0;
6362 if(SUCCEEDED(ScriptVariant_IntegerValue(arg
, <emp
))) {
6364 player
[index
].credits
= (int) ltemp
;
6366 credits
= (int) ltemp
;
6368 (*pretvar
)->lVal
= (s32
) 0;
6371 //this property is not known, so return 0
6373 // (*pretvar)->lVal = (s32)0;
6379 //checkhole(x,z), return 1 if there's hole here
6380 s32
openbor_checkhole(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
6381 ScriptVariant
*arg
= NULL
;
6384 if(paramCount
< 2) {
6389 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
6390 (*pretvar
)->lVal
= (s32
) 0;
6393 if(FAILED(ScriptVariant_DecimalValue(arg
, &x
)))
6397 if(FAILED(ScriptVariant_DecimalValue(arg
, &z
)))
6400 (*pretvar
)->lVal
= (s32
) (checkhole((float) x
, (float) z
) && checkwall((float) x
, (float) z
) < 0);
6404 //checkwall(x,z), return wall height, or 0
6405 s32
openbor_checkwall(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
6406 ScriptVariant
*arg
= NULL
;
6410 if(paramCount
< 2) {
6415 ScriptVariant_ChangeType(*pretvar
, VT_DECIMAL
);
6416 (*pretvar
)->dblVal
= (double) 0;
6419 if(FAILED(ScriptVariant_DecimalValue(arg
, &x
)))
6423 if(FAILED(ScriptVariant_DecimalValue(arg
, &z
)))
6426 if((wall
= checkwall_below((float) x
, (float) z
, 100000)) >= 0) {
6427 (*pretvar
)->dblVal
= (double) level
->walls
[wall
].alt
;
6432 //checkplatformbelow(x,z,a), return the highest platfrom entity below
6433 s32
openbor_checkplatformbelow(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
6434 ScriptVariant
*arg
= NULL
;
6437 if(paramCount
< 3) {
6442 ScriptVariant_ChangeType(*pretvar
, VT_DECIMAL
);
6443 (*pretvar
)->dblVal
= (double) 0;
6446 if(FAILED(ScriptVariant_DecimalValue(arg
, &x
)))
6450 if(FAILED(ScriptVariant_DecimalValue(arg
, &z
)))
6454 if(FAILED(ScriptVariant_DecimalValue(arg
, &a
)))
6457 ScriptVariant_ChangeType(*pretvar
, VT_PTR
);
6458 (*pretvar
)->ptrVal
= (void*) check_platform_below((float) x
, (float) z
, (float) a
);
6462 s32
openbor_openfilestream(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
6463 char *filename
= NULL
;
6464 ScriptVariant
*arg
= NULL
;
6468 FILE *handle
= NULL
;
6469 char path
[128] = { "" };
6472 if(paramCount
< 1) {
6477 ScriptVariant_Clear(*pretvar
);
6480 if(arg
->vt
!= VT_STR
) {
6481 printf("Filename for openfilestream must be a string.\n");
6486 filename
= (char *) StrCache_Get(arg
->strVal
);
6488 if(paramCount
> 1) {
6490 if(FAILED(ScriptVariant_IntegerValue(arg
, &location
)))
6494 if(!level
->numfilestreams
)
6495 level
->numfilestreams
= 0;
6496 else if(level
->numfilestreams
== LEVEL_MAX_FILESTREAMS
) {
6497 printf("Maximum file streams exceeded.\n");
6501 // Load file from saves directory if specified
6503 getBasePath(path
, "Saves", 0);
6505 strcat(path
, filename
);
6507 if(!(fileExists(path
))) {
6508 printf("Openfilestream - file specified does not exist.\n");
6512 handle
= fopen(path
, "rb");
6515 fseek(handle
, 0, SEEK_END
);
6516 size
= ftell(handle
);
6518 level
->filestreams
[level
->numfilestreams
].buf
= (char *) malloc(sizeof(char) * size
);
6519 if(level
->filestreams
[level
->numfilestreams
].buf
== NULL
)
6521 disCcWarns
= fread(level
->filestreams
[level
->numfilestreams
].buf
, 1, size
, handle
);
6524 (filename
, &level
->filestreams
[level
->numfilestreams
].buf
,
6525 &level
->filestreams
[level
->numfilestreams
].size
) != 1) {
6526 printf("Invalid filename used in openfilestream.\n");
6531 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
6532 (*pretvar
)->lVal
= (s32
) level
->numfilestreams
;
6534 level
->filestreams
[level
->numfilestreams
].pos
= 0;
6535 level
->numfilestreams
++;
6539 s32
openbor_getfilestreamline(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
6540 char line
[MAX_STR_VAR_LEN
];
6542 ScriptVariant
*arg
= NULL
;
6543 s32 filestreamindex
;
6545 if(paramCount
< 1) {
6551 if(FAILED(ScriptVariant_IntegerValue(arg
, &filestreamindex
)))
6554 ScriptVariant_Clear(*pretvar
);
6555 ScriptVariant_ChangeType(*pretvar
, VT_STR
);
6558 strncpy(line
, "it's initialized now", MAX_STR_VAR_LEN
);
6560 while(level
->filestreams
[filestreamindex
].buf
[level
->filestreams
[filestreamindex
].pos
+ length
]
6561 && level
->filestreams
[filestreamindex
].buf
[level
->filestreams
[filestreamindex
].pos
+ length
] != '\n'
6562 && level
->filestreams
[filestreamindex
].buf
[level
->filestreams
[filestreamindex
].pos
+ length
] != '\r')
6564 if(length
>= MAX_STR_VAR_LEN
)
6565 strncpy(StrCache_Get((*pretvar
)->strVal
),
6566 (char *) (level
->filestreams
[filestreamindex
].buf
+ level
->filestreams
[filestreamindex
].pos
),
6570 (char *) (level
->filestreams
[filestreamindex
].buf
+ level
->filestreams
[filestreamindex
].pos
),
6572 line
[length
] = '\0';
6573 strncpy(StrCache_Get((*pretvar
)->strVal
), line
, MAX_STR_VAR_LEN
);
6578 s32
openbor_getfilestreamargument(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
6579 ScriptVariant
*arg
= NULL
;
6580 s32 filestreamindex
, argument
;
6581 char *argtype
= NULL
;
6583 if(paramCount
< 3) {
6589 if(FAILED(ScriptVariant_IntegerValue(arg
, &filestreamindex
)))
6593 if(FAILED(ScriptVariant_IntegerValue(arg
, &argument
)))
6595 ScriptVariant_Clear(*pretvar
);
6597 if(varlist
[2]->vt
!= VT_STR
) {
6599 ("You must give a string value specifying what kind of value you want the argument converted to.\n");
6602 argtype
= (char *) StrCache_Get(varlist
[2]->strVal
);
6604 if(stricmp(argtype
, "string") == 0) {
6605 ScriptVariant_ChangeType(*pretvar
, VT_STR
);
6606 strncpy(StrCache_Get((*pretvar
)->strVal
),
6607 (char *) findarg(level
->filestreams
[filestreamindex
].buf
+
6608 level
->filestreams
[filestreamindex
].pos
, argument
), MAX_STR_VAR_LEN
);
6609 } else if(stricmp(argtype
, "int") == 0) {
6610 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
6614 (level
->filestreams
[filestreamindex
].buf
+ level
->filestreams
[filestreamindex
].pos
, argument
));
6615 } else if(stricmp(argtype
, "float") == 0) {
6616 ScriptVariant_ChangeType(*pretvar
, VT_DECIMAL
);
6617 (*pretvar
)->dblVal
=
6620 (level
->filestreams
[filestreamindex
].buf
+ level
->filestreams
[filestreamindex
].pos
, argument
));
6622 printf("Invalid type for argument converted to (getfilestreamargument).\n");
6629 s32
openbor_filestreamnextline(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
6630 ScriptVariant
*arg
= NULL
;
6631 s32 filestreamindex
;
6633 if(paramCount
< 1) {
6639 if(FAILED(ScriptVariant_IntegerValue(arg
, &filestreamindex
)))
6641 while(level
->filestreams
[filestreamindex
].buf
[level
->filestreams
[filestreamindex
].pos
]
6642 && level
->filestreams
[filestreamindex
].buf
[level
->filestreams
[filestreamindex
].pos
] != '\n'
6643 && level
->filestreams
[filestreamindex
].buf
[level
->filestreams
[filestreamindex
].pos
] != '\r')
6644 ++level
->filestreams
[filestreamindex
].pos
;
6645 while(level
->filestreams
[filestreamindex
].buf
[level
->filestreams
[filestreamindex
].pos
] == '\n'
6646 || level
->filestreams
[filestreamindex
].buf
[level
->filestreams
[filestreamindex
].pos
] == '\r')
6647 ++level
->filestreams
[filestreamindex
].pos
;
6652 s32
openbor_getfilestreamposition(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
6653 ScriptVariant
*arg
= NULL
;
6654 s32 filestreamindex
;
6656 if(paramCount
< 1) {
6662 if(FAILED(ScriptVariant_IntegerValue(arg
, &filestreamindex
)))
6665 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
6666 (*pretvar
)->lVal
= (s32
) level
->filestreams
[filestreamindex
].pos
;
6670 s32
openbor_setfilestreamposition(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
6671 ScriptVariant
*arg
= NULL
;
6672 s32 filestreamindex
, position
;
6675 if(paramCount
< 2) {
6681 if(FAILED(ScriptVariant_IntegerValue(arg
, &filestreamindex
)))
6685 if(FAILED(ScriptVariant_IntegerValue(arg
, &position
)))
6688 level
->filestreams
[filestreamindex
].pos
= position
;
6692 s32
openbor_filestreamappend(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
6693 s32 filestreamindex
;
6694 ScriptVariant
*arg
= NULL
;
6699 char append
[MAX_STR_VAR_LEN
];
6702 if(paramCount
< 3) {
6707 ScriptVariant_Clear(*pretvar
);
6710 if(FAILED(ScriptVariant_IntegerValue(arg
, &filestreamindex
)))
6714 if(arg
->vt
== VT_STR
) {
6715 strcpy(append
, StrCache_Get(arg
->strVal
));
6716 } else if(arg
->vt
== VT_INTEGER
) {
6717 if(FAILED(ScriptVariant_IntegerValue(arg
, <emp
)))
6719 sprintf(append
, "%d", (int) ltemp
);
6720 } else if(arg
->vt
== VT_DECIMAL
) {
6721 if(FAILED(ScriptVariant_DecimalValue(arg
, &dbltemp
)))
6723 sprintf(append
, "%f", dbltemp
);
6725 printf("Filename for filestreamappend must be a string.\n");
6733 if(FAILED(ScriptVariant_IntegerValue(arg
, &appendtype
)))
6736 temp
= (char *) malloc(sizeof(char) * (strlen(level
->filestreams
[filestreamindex
].buf
) + strlen(append
) + 4));
6737 strcpy(temp
, level
->filestreams
[filestreamindex
].buf
);
6739 if(appendtype
== 0) {
6740 strcat(temp
, "\r\n");
6741 strcat(temp
, append
);
6742 temp
[strlen(level
->filestreams
[filestreamindex
].buf
) + strlen(append
) + 2] = ' ';
6743 temp
[strlen(level
->filestreams
[filestreamindex
].buf
) + strlen(append
) + 3] = '\0';
6744 } else if(appendtype
== 1) {
6745 strcat(temp
, append
);
6746 temp
[strlen(level
->filestreams
[filestreamindex
].buf
) + strlen(append
)] = ' ';
6747 temp
[strlen(level
->filestreams
[filestreamindex
].buf
) + strlen(append
) + 1] = '\0';
6749 free(level
->filestreams
[filestreamindex
].buf
);
6750 level
->filestreams
[filestreamindex
].buf
= temp
;
6755 s32
openbor_createfilestream(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
6756 ScriptVariant_Clear(*pretvar
);
6758 if(!level
->numfilestreams
)
6759 level
->numfilestreams
= 0;
6760 else if(level
->numfilestreams
== LEVEL_MAX_FILESTREAMS
) {
6761 printf("Maximum file streams exceeded.\n");
6766 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
6767 (*pretvar
)->lVal
= (s32
) level
->numfilestreams
;
6769 // Initialize the new filestream
6770 level
->filestreams
[level
->numfilestreams
].pos
= 0;
6771 level
->filestreams
[level
->numfilestreams
].buf
= (char *) malloc(sizeof(char) * 128);
6772 level
->filestreams
[level
->numfilestreams
].buf
[0] = '\0';
6773 level
->numfilestreams
++;
6777 s32
openbor_savefilestream(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
6779 s32 filestreamindex
;
6780 ScriptVariant
*arg
= NULL
;
6782 FILE *handle
= NULL
;
6783 char path
[128] = { "" };
6784 char tmpname
[128] = { "" };
6785 char mod
[256] = { "" };
6787 if(paramCount
< 1) {
6792 ScriptVariant_Clear(*pretvar
);
6795 if(FAILED(ScriptVariant_IntegerValue(arg
, &filestreamindex
)))
6799 if(arg
->vt
!= VT_STR
) {
6800 printf("Filename for savefilestream must be a string.\n");
6804 // Get the saves directory
6805 getBasePath(path
, "Saves/", 0);
6807 // get the packfile's name by chopping off the rest of the path
6808 strncpy(mod
, packfile
, strlen(packfile
) - 4);
6810 for(i
= 0; i
< (int) strlen(mod
); i
++) {
6811 if((mod
[i
] == '/') || (mod
[i
] == '\\'))
6815 for(i
= 0; i
< (int) strlen(mod
); i
++) {
6816 // For packfiles without '/'
6818 tmpname
[y
] = mod
[i
];
6821 // For packfiles with '/'
6822 if(x
!= 0 && i
> x
) {
6823 tmpname
[y
] = mod
[i
];
6828 // Make ./Saves/PAKNAME if it doesn't exist
6829 strcat(path
, tmpname
);
6834 // Add user's filename to path and write the filestream to it
6836 strcat(path
, (char *) StrCache_Get(arg
->strVal
));
6837 handle
= fopen(path
, "wb");
6841 fwrite(level
->filestreams
[filestreamindex
].buf
, 1, strlen(level
->filestreams
[filestreamindex
].buf
), handle
);
6843 // add blank line so it can be read successfully
6844 fwrite("\r\n", 1, 2, handle
);
6850 //damageentity(entity, other, force, drop, type)
6851 s32
openbor_damageentity(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
6853 entity
*other
= NULL
;
6854 entity
*temp
= NULL
;
6855 s32 force
, drop
, type
;
6858 if(paramCount
< 1) {
6863 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
6864 (*pretvar
)->lVal
= (s32
) 0;
6866 ent
= (entity
*) (varlist
[0])->ptrVal
; //retrieve the entity
6873 type
= (s32
) ATK_NORMAL
;
6875 if(paramCount
>= 2) {
6876 other
= (entity
*) (varlist
[1])->ptrVal
;
6880 if(paramCount
>= 3) {
6881 if(FAILED(ScriptVariant_IntegerValue((varlist
[2]), &force
)))
6885 if(!ent
->takedamage
) {
6886 ent
->health
-= force
;
6887 if(ent
->health
<= 0)
6889 (*pretvar
)->lVal
= (s32
) 1;
6893 if(paramCount
>= 4) {
6894 if(FAILED(ScriptVariant_IntegerValue((varlist
[3]), &drop
)))
6897 if(paramCount
>= 5) {
6898 if(FAILED(ScriptVariant_IntegerValue((varlist
[4]), &type
)))
6904 attack
= emptyattack
;
6905 attack
.attack_force
= force
;
6906 attack
.attack_drop
= drop
;
6908 attack
.dropv
[0] = (float) 3;
6909 attack
.dropv
[1] = (float) 1.2;
6910 attack
.dropv
[2] = (float) 0;
6912 attack
.attack_type
= type
;
6913 self
->takedamage(other
, &attack
);
6918 //killentity(entity)
6919 s32
openbor_killentity(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
6922 if(paramCount
< 1) {
6927 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
6929 ent
= (entity
*) (varlist
[0])->ptrVal
; //retrieve the entity
6931 (*pretvar
)->lVal
= (s32
) 0;
6935 (*pretvar
)->lVal
= (s32
) 1;
6939 //findtarget(entity, int animation);
6940 s32
openbor_findtarget(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
6942 entity
*tempself
, *target
;
6945 if(paramCount
< 1) {
6950 ScriptVariant_ChangeType(*pretvar
, VT_PTR
);
6952 ent
= (entity
*) (varlist
[0])->ptrVal
; //retrieve the entity
6954 ScriptVariant_Clear(*pretvar
);
6957 if(paramCount
> 1 && FAILED(ScriptVariant_IntegerValue(varlist
[1], &anim
)))
6961 target
= normal_find_target((int) anim
);
6963 ScriptVariant_Clear(*pretvar
);
6965 (*pretvar
)->ptrVal
= (void*) target
;
6970 //checkrange(entity, target, int ani);
6971 s32
openbor_checkrange(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
6972 entity
*ent
= NULL
, *target
= NULL
;
6976 goto checkrange_error
;
6978 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
6980 if(varlist
[0]->vt
!= VT_PTR
|| varlist
[1]->vt
!= VT_PTR
)
6981 goto checkrange_error
;
6983 ent
= (entity
*) (varlist
[0])->ptrVal
; //retrieve the entity
6984 target
= (entity
*) (varlist
[1])->ptrVal
; //retrieve the target
6987 goto checkrange_error
;
6989 if(paramCount
> 2 && FAILED(ScriptVariant_IntegerValue(varlist
[2], &ani
)))
6990 goto checkrange_error
;
6991 else if(paramCount
<= 2)
6994 if(ani
< 0 || ani
>= dyn_anim_custom_maxvalues
.max_animations
) {
6995 printf("Animation id out of range: %d / %d.\n", (int) ani
, dyn_anim_custom_maxvalues
.max_animations
);
6996 goto checkrange_error
;
6999 (*pretvar
)->lVal
= check_range(ent
, target
, ani
);
7005 ("Function needs at least 2 valid entity handles, the third parameter is optional: checkrange(entity, target, int animnum)\n");
7010 //clearspawnentry();
7011 s32
openbor_clearspawnentry(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
7013 memset(&spawnentry
, 0, sizeof(s_spawn_entry
));
7014 spawnentry
.index
= spawnentry
.itemindex
= spawnentry
.weaponindex
= -1;
7018 // ===== setspawnentry =====
7019 enum setspawnentry_enum
{
7048 void mapstrings_setspawnentry(ScriptVariant
** varlist
, int paramCount
) {
7051 static const char *proplist
[] = {
7079 MAPSTRINGS(varlist
[0], proplist
, _sse_the_end
, "Property name '%s' is not supported by setspawnentry.\n");
7082 //setspawnentry(propname, value1[, value2, value3, ...]);
7083 s32
openbor_setspawnentry(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
7088 ScriptVariant
*arg
= NULL
;
7090 if(paramCount
< 2) {
7095 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
7096 (*pretvar
)->lVal
= (s32
) 1;
7098 mapstrings_setspawnentry(varlist
, paramCount
);
7099 if(varlist
[0]->vt
!= VT_INTEGER
) {
7100 if(varlist
[0]->vt
!= VT_STR
)
7101 printf("You must give a string value for spawn entry property name.\n");
7106 prop
= varlist
[0]->lVal
;
7112 if(arg
->vt
!= VT_STR
) {
7114 ("You must use a string value for spawn entry's name property: function setspawnentry.\n");
7115 goto setspawnentry_error
;
7117 spawnentry
.model
= findmodel((char *) StrCache_Get(arg
->strVal
));
7120 if(arg
->vt
!= VT_STR
)
7121 goto setspawnentry_error
;
7122 strcpy(spawnentry
.alias
, (char *) StrCache_Get(arg
->strVal
));
7125 if(arg
->vt
!= VT_STR
)
7126 goto setspawnentry_error
;
7127 spawnentry
.itemmodel
= findmodel((char *) StrCache_Get(arg
->strVal
));
7128 spawnentry
.item
= spawnentry
.itemmodel
->name
;
7129 spawnentry
.itemindex
= get_cached_model_index(spawnentry
.item
);
7130 spawnentry
.itemplayer_count
= 0;
7133 if(arg
->vt
!= VT_STR
)
7134 goto setspawnentry_error
;
7135 tempmodel
= findmodel((char *) StrCache_Get(arg
->strVal
));
7137 spawnentry
.item
= NULL
;
7139 spawnentry
.item
= tempmodel
->name
;
7140 spawnentry
.itemplayer_count
= 1;
7143 if(arg
->vt
!= VT_STR
)
7144 goto setspawnentry_error
;
7145 spawnentry
.itemmodel
= findmodel((char *) StrCache_Get(arg
->strVal
));
7146 spawnentry
.itemplayer_count
= 2;
7149 if(arg
->vt
!= VT_STR
)
7150 goto setspawnentry_error
;
7151 spawnentry
.itemmodel
= findmodel((char *) StrCache_Get(arg
->strVal
));
7152 spawnentry
.itemplayer_count
= 3;
7155 if(SUCCEEDED(ScriptVariant_IntegerValue(arg
, <emp
)))
7156 spawnentry
.health
[0] = (int) ltemp
;
7158 (*pretvar
)->lVal
= (s32
) 0;
7160 case _sse_itemhealth
:
7161 if(SUCCEEDED(ScriptVariant_IntegerValue(arg
, <emp
)))
7162 spawnentry
.itemhealth
= (int) ltemp
;
7164 (*pretvar
)->lVal
= (s32
) 0;
7166 case _sse_itemalias
:
7167 if(arg
->vt
!= VT_STR
)
7169 strcpy(spawnentry
.itemalias
, (char *) StrCache_Get(arg
->strVal
));
7172 if(SUCCEEDED(ScriptVariant_IntegerValue(arg
, <emp
)))
7173 spawnentry
.health
[1] = (int) ltemp
;
7175 (*pretvar
)->lVal
= (s32
) 0;
7178 if(SUCCEEDED(ScriptVariant_IntegerValue(arg
, <emp
)))
7179 spawnentry
.health
[2] = (int) ltemp
;
7181 (*pretvar
)->lVal
= (s32
) 0;
7184 if(SUCCEEDED(ScriptVariant_IntegerValue(arg
, <emp
)))
7185 spawnentry
.health
[3] = (int) ltemp
;
7187 (*pretvar
)->lVal
= (s32
) 0;
7191 if(SUCCEEDED(ScriptVariant_DecimalValue(arg
, &dbltemp
)))
7192 spawnentry
.x
= (float) dbltemp
;
7195 if(paramCount
>= 3 && temp
) {
7196 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[2], &dbltemp
)))
7197 spawnentry
.z
= (float) dbltemp
;
7201 if(paramCount
>= 4 && temp
) {
7202 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[3], &dbltemp
)))
7203 spawnentry
.a
= (float) dbltemp
;
7207 (*pretvar
)->lVal
= (s32
) temp
;
7210 if(SUCCEEDED(ScriptVariant_IntegerValue(arg
, <emp
)))
7211 spawnentry
.mp
= (int) ltemp
;
7213 (*pretvar
)->lVal
= (s32
) 0;
7216 if(SUCCEEDED(ScriptVariant_IntegerValue(arg
, <emp
)))
7217 spawnentry
.colourmap
= (int) ltemp
;
7219 (*pretvar
)->lVal
= (s32
) 0;
7222 if(SUCCEEDED(ScriptVariant_IntegerValue(arg
, <emp
)))
7223 spawnentry
.itemmap
= (int) ltemp
;
7225 (*pretvar
)->lVal
= (s32
) 0;
7228 if(SUCCEEDED(ScriptVariant_IntegerValue(arg
, <emp
)))
7229 spawnentry
.alpha
= (int) ltemp
;
7231 (*pretvar
)->lVal
= (s32
) 0;
7234 if(SUCCEEDED(ScriptVariant_IntegerValue(arg
, <emp
)))
7235 spawnentry
.multiple
= (int) ltemp
;
7237 (*pretvar
)->lVal
= (s32
) 0;
7241 if(SUCCEEDED(ScriptVariant_IntegerValue(arg
, <emp
)))
7242 spawnentry
.dying
= (int) ltemp
;
7245 if(paramCount
>= 3 && temp
) {
7246 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
)))
7247 spawnentry
.per1
= (int) ltemp
;
7251 if(paramCount
>= 4 && temp
) {
7252 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[3], <emp
)))
7253 spawnentry
.per2
= (int) ltemp
;
7257 (*pretvar
)->lVal
= (s32
) temp
;
7260 if(SUCCEEDED(ScriptVariant_IntegerValue(arg
, <emp
)))
7261 spawnentry
.nolife
= (int) ltemp
;
7263 (*pretvar
)->lVal
= (s32
) 0;
7266 if(SUCCEEDED(ScriptVariant_IntegerValue(arg
, <emp
)))
7267 spawnentry
.boss
= (int) ltemp
;
7269 (*pretvar
)->lVal
= (s32
) 0;
7272 if(SUCCEEDED(ScriptVariant_IntegerValue(arg
, <emp
)))
7273 spawnentry
.flip
= (int) ltemp
;
7275 (*pretvar
)->lVal
= (s32
) 0;
7278 if(SUCCEEDED(ScriptVariant_IntegerValue(arg
, <emp
)))
7279 spawnentry
.credit
= (int) ltemp
;
7281 (*pretvar
)->lVal
= (s32
) 0;
7283 case _sse_aggression
:
7284 if(SUCCEEDED(ScriptVariant_IntegerValue(arg
, <emp
)))
7285 spawnentry
.aggression
= (int) ltemp
;
7287 (*pretvar
)->lVal
= (s32
) 0;
7290 if(arg
->vt
!= VT_STR
)
7291 goto setspawnentry_error
;
7292 spawnentry
.weaponmodel
= findmodel((char *) StrCache_Get(arg
->strVal
));
7295 //printf("Property name '%s' is not supported by setspawnentry.\n", propname);
7296 goto setspawnentry_error
;
7300 setspawnentry_error
:
7306 s32
openbor_spawn(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
7309 ent
= smartspawn(&spawnentry
);
7312 ScriptVariant_ChangeType(*pretvar
, VT_PTR
);
7313 (*pretvar
)->ptrVal
= (void*) ent
;
7315 ScriptVariant_Clear(*pretvar
);
7320 //entity * projectile(char *name, float x, float z, float a, int direction, int type, int ptype, int map);
7321 s32
openbor_projectile(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
7325 char name
[64] = { "" };
7328 goto projectile_error
;
7329 if(varlist
[0]->vt
!= VT_STR
)
7330 goto projectile_error
;
7332 ScriptVariant_Clear(*pretvar
);
7334 strncpy(name
, StrCache_Get(varlist
[0]->strVal
), MAX_STR_VAR_LEN
);
7336 for(i
= 1; i
<= 7; i
++) {
7337 if(FAILED(ScriptVariant_IntegerValue(varlist
[i
], &value
[i
- 1])))
7338 goto projectile_error
;
7341 switch ((int) value
[5]) {
7345 knife_spawn(name
, -1, (float) value
[0], (float) value
[1], (float) value
[2], (int) value
[3],
7346 (int) value
[4], (int) value
[6]);
7350 bomb_spawn(name
, -1, (float) value
[0], (float) value
[1], (float) value
[2], (int) value
[3],
7355 ScriptVariant_ChangeType(*pretvar
, VT_PTR
);
7356 (*pretvar
)->ptrVal
= (void*) ent
;
7362 ("Function requires 8 values: entity * projectile(char *name, float x, float z, float a, int direction, int type, int ptype, int map)\n");
7366 #define SAMPLE_GO samples.go
7367 #define SAMPLE_BEAT samples.beat
7368 #define SAMPLE_BLOCK samples.block
7369 #define SAMPLE_INDIRECT samples.indirect
7370 #define SAMPLE_GET samples.get
7371 #define SAMPLE_GET2 samples.get2
7372 #define SAMPLE_FALL samples.fall
7373 #define SAMPLE_JUMP samples.jump
7374 #define SAMPLE_PUNCH samples.punch
7375 #define SAMPLE_1UP samples.oneup
7376 #define SAMPLE_TIMEOVER samples.timeover
7377 #define SAMPLE_BEEP samples.beep
7378 #define SAMPLE_BEEP2 samples.beep2
7379 #define SAMPLE_BIKE samples.bike
7382 // ===== openborconstant =====
7384 #define ICMPCONST(x) \
7385 case CMD_SCRIPT_CONSTANT_ ##x: \
7387 void mapstrings_transconst(ScriptVariant
** varlist
, int paramCount
) {
7388 char *constname
= NULL
;
7389 scriptConstantsCommands cmd
;
7396 if(varlist
[0]->vt
== VT_STR
) {
7397 constname
= (char *) StrCache_Get(varlist
[0]->strVal
);
7398 cmd
= getScriptConstantsCommand(scriptConstantsCommandList
, constname
);
7399 vartype
= ScriptVariant_GetType(varlist
[0]);
7400 ScriptVariant_ChangeType(varlist
[0], VT_INTEGER
);
7402 ICMPCONST(COMPATIBLEVERSION
);
7404 ICMPCONST(PIXEL_x8
);
7405 ICMPCONST(PIXEL_16
);
7406 ICMPCONST(PIXEL_32
);
7407 ICMPCONST(CV_SAVED_GAME
);
7408 ICMPCONST(CV_HIGH_SCORE
);
7409 ICMPCONST(THINK_SPEED
);
7410 ICMPCONST(COUNTER_SPEED
);
7411 ICMPCONST(MAX_ENTS
);
7412 ICMPCONST(MAX_PANELS
);
7413 ICMPCONST(MAX_WEAPONS
);
7414 ICMPCONST(MAX_COLOUR_MAPS
);
7415 ICMPCONST(MAX_NAME_LEN
);
7416 ICMPCONST(LEVEL_MAX_SPAWNS
);
7417 ICMPCONST(LEVEL_MAX_PANELS
);
7418 ICMPCONST(LEVEL_MAX_HOLES
);
7419 ICMPCONST(LEVEL_MAX_WALLS
);
7420 ICMPCONST(MAX_LEVELS
);
7421 ICMPCONST(MAX_DIFFICULTIES
);
7422 ICMPCONST(MAX_SPECIALS
);
7423 ICMPCONST(MAX_ATCHAIN
);
7424 ICMPCONST(MAX_ATTACKS
);
7425 ICMPCONST(MAX_FOLLOWS
);
7426 ICMPCONST(MAX_PLAYERS
);
7427 ICMPCONST(MAX_ARG_LEN
);
7428 ICMPCONST(FLAG_ESC
);
7429 ICMPCONST(FLAG_START
);
7430 ICMPCONST(FLAG_MOVELEFT
);
7431 ICMPCONST(FLAG_MOVERIGHT
);
7432 ICMPCONST(FLAG_MOVEUP
);
7433 ICMPCONST(FLAG_MOVEDOWN
);
7434 ICMPCONST(FLAG_ATTACK
);
7435 ICMPCONST(FLAG_ATTACK2
);
7436 ICMPCONST(FLAG_ATTACK3
);
7437 ICMPCONST(FLAG_ATTACK4
);
7438 ICMPCONST(FLAG_JUMP
);
7439 ICMPCONST(FLAG_SPECIAL
);
7440 ICMPCONST(FLAG_SCREENSHOT
);
7441 ICMPCONST(FLAG_ANYBUTTON
);
7442 ICMPCONST(FLAG_FORWARD
);
7443 ICMPCONST(FLAG_BACKWARD
);
7444 ICMPCONST(SDID_MOVEUP
);
7445 ICMPCONST(SDID_MOVEDOWN
);
7446 ICMPCONST(SDID_MOVELEFT
);
7447 ICMPCONST(SDID_MOVERIGHT
);
7448 ICMPCONST(SDID_SPECIAL
);
7449 ICMPCONST(SDID_ATTACK
);
7450 ICMPCONST(SDID_ATTACK2
);
7451 ICMPCONST(SDID_ATTACK3
);
7452 ICMPCONST(SDID_ATTACK4
);
7453 ICMPCONST(SDID_JUMP
);
7454 ICMPCONST(SDID_START
);
7455 ICMPCONST(SDID_SCREENSHOT
);
7456 ICMPCONST(TYPE_NONE
);
7457 ICMPCONST(TYPE_PLAYER
);
7458 ICMPCONST(TYPE_ENEMY
);
7459 ICMPCONST(TYPE_ITEM
);
7460 ICMPCONST(TYPE_OBSTACLE
);
7461 ICMPCONST(TYPE_STEAMER
);
7462 ICMPCONST(TYPE_SHOT
);
7463 ICMPCONST(TYPE_TRAP
);
7464 ICMPCONST(TYPE_TEXTBOX
);
7465 ICMPCONST(TYPE_ENDLEVEL
);
7466 ICMPCONST(TYPE_NPC
);
7467 ICMPCONST(TYPE_PANEL
);
7468 ICMPCONST(SUBTYPE_NONE
);
7469 ICMPCONST(SUBTYPE_BIKER
);
7470 ICMPCONST(SUBTYPE_NOTGRAB
);
7471 ICMPCONST(SUBTYPE_ARROW
);
7472 ICMPCONST(SUBTYPE_TOUCH
);
7473 ICMPCONST(SUBTYPE_WEAPON
);
7474 ICMPCONST(SUBTYPE_NOSKIP
);
7475 ICMPCONST(SUBTYPE_FLYDIE
);
7476 ICMPCONST(SUBTYPE_BOTH
);
7477 ICMPCONST(SUBTYPE_PROJECTILE
);
7478 ICMPCONST(SUBTYPE_FOLLOW
);
7479 ICMPCONST(SUBTYPE_CHASE
);
7480 ICMPCONST(AIMOVE1_NORMAL
);
7481 ICMPCONST(AIMOVE1_CHASE
);
7482 ICMPCONST(AIMOVE1_CHASEZ
);
7483 ICMPCONST(AIMOVE1_CHASEX
);
7484 ICMPCONST(AIMOVE1_AVOID
);
7485 ICMPCONST(AIMOVE1_AVOIDZ
);
7486 ICMPCONST(AIMOVE1_AVOIDX
);
7487 ICMPCONST(AIMOVE1_WANDER
);
7488 ICMPCONST(AIMOVE1_NOMOVE
);
7489 ICMPCONST(AIMOVE1_BIKER
);
7490 ICMPCONST(AIMOVE1_STAR
);
7491 ICMPCONST(AIMOVE1_ARROW
);
7492 ICMPCONST(AIMOVE1_BOMB
);
7493 ICMPCONST(AIMOVE2_NORMAL
);
7494 ICMPCONST(AIMOVE2_IGNOREHOLES
);
7495 ICMPCONST(AIATTACK1_NORMAL
);
7496 ICMPCONST(AIATTACK1_LONG
);
7497 ICMPCONST(AIATTACK1_MELEE
);
7498 ICMPCONST(AIATTACK1_NOATTACK
);
7499 ICMPCONST(AIATTACK2_NORMAL
);
7500 ICMPCONST(AIATTACK2_DODGE
);
7501 ICMPCONST(AIATTACK2_DODGEMOVE
);
7502 ICMPCONST(FRONTPANEL_Z
);
7504 ICMPCONST(NEONPANEL_Z
);
7505 ICMPCONST(SHADOW_Z
);
7506 ICMPCONST(SCREENPANEL_Z
);
7508 ICMPCONST(MIRROR_Z
);
7509 ICMPCONST(PIT_DEPTH
);
7510 ICMPCONST(P2_STATS_DIST
);
7511 ICMPCONST(CONTACT_DIST_H
);
7512 ICMPCONST(CONTACT_DIST_V
);
7513 ICMPCONST(GRAB_DIST
);
7514 ICMPCONST(GRAB_STALL
);
7515 ICMPCONST(ATK_NORMAL
);
7516 ICMPCONST(ATK_NORMAL2
);
7517 ICMPCONST(ATK_NORMAL3
);
7518 ICMPCONST(ATK_NORMAL4
);
7519 ICMPCONST(ATK_BLAST
);
7520 ICMPCONST(ATK_BURN
);
7521 ICMPCONST(ATK_FREEZE
);
7522 ICMPCONST(ATK_SHOCK
);
7523 ICMPCONST(ATK_STEAL
);
7524 ICMPCONST(ATK_NORMAL5
);
7525 ICMPCONST(ATK_NORMAL6
);
7526 ICMPCONST(ATK_NORMAL7
);
7527 ICMPCONST(ATK_NORMAL8
);
7528 ICMPCONST(ATK_NORMAL9
);
7529 ICMPCONST(ATK_NORMAL10
);
7530 ICMPCONST(ATK_ITEM
);
7531 ICMPCONST(SCROLL_RIGHT
);
7532 ICMPCONST(SCROLL_DOWN
);
7533 ICMPCONST(SCROLL_LEFT
);
7534 ICMPCONST(SCROLL_UP
);
7535 ICMPCONST(SCROLL_BOTH
);
7536 ICMPCONST(SCROLL_LEFTRIGHT
);
7537 ICMPCONST(SCROLL_RIGHTLEFT
);
7538 ICMPCONST(SCROLL_INWARD
);
7539 ICMPCONST(SCROLL_OUTWARD
);
7540 ICMPCONST(SCROLL_INOUT
);
7541 ICMPCONST(SCROLL_OUTIN
);
7542 ICMPCONST(SCROLL_UPWARD
);
7543 ICMPCONST(SCROLL_DOWNWARD
);
7544 ICMPCONST(ANI_IDLE
);
7545 ICMPCONST(ANI_WALK
);
7546 ICMPCONST(ANI_JUMP
);
7547 ICMPCONST(ANI_LAND
);
7548 ICMPCONST(ANI_PAIN
);
7549 ICMPCONST(ANI_FALL
);
7550 ICMPCONST(ANI_RISE
);
7551 //ICMPCONST(ANI_ATTACK1);// move these below because we have some dynamic animation ids
7552 //ICMPCONST(ANI_ATTACK2);
7553 //ICMPCONST(ANI_ATTACK3);
7554 //ICMPCONST(ANI_ATTACK4);
7555 ICMPCONST(ANI_UPPER
);
7556 ICMPCONST(ANI_BLOCK
);
7557 ICMPCONST(ANI_JUMPATTACK
);
7558 ICMPCONST(ANI_JUMPATTACK2
);
7560 ICMPCONST(ANI_GRAB
);
7561 ICMPCONST(ANI_GRABATTACK
);
7562 ICMPCONST(ANI_GRABATTACK2
);
7563 ICMPCONST(ANI_THROW
);
7564 ICMPCONST(ANI_SPECIAL
);
7565 //ICMPCONST(ANI_FREESPECIAL);// move these below because we have some dynamic animation ids
7566 ICMPCONST(ANI_SPAWN
);
7568 ICMPCONST(ANI_PICK
);
7569 //ICMPCONST(ANI_FREESPECIAL2);
7570 ICMPCONST(ANI_JUMPATTACK3
);
7571 //ICMPCONST(ANI_FREESPECIAL3);
7573 ICMPCONST(ANI_DOWN
);
7574 ICMPCONST(ANI_SHOCK
);
7575 ICMPCONST(ANI_BURN
);
7577 ICMPCONST(ANI_SHOCKPAIN
);
7578 ICMPCONST(ANI_BURNPAIN
);
7579 ICMPCONST(ANI_GRABBED
);
7580 ICMPCONST(ANI_SPECIAL2
);
7582 ICMPCONST(ANI_RUNATTACK
);
7583 ICMPCONST(ANI_RUNJUMPATTACK
);
7584 ICMPCONST(ANI_ATTACKUP
);
7585 ICMPCONST(ANI_ATTACKDOWN
);
7586 ICMPCONST(ANI_ATTACKFORWARD
);
7587 ICMPCONST(ANI_ATTACKBACKWARD
);
7588 //ICMPCONST(ANI_FREESPECIAL4);
7589 //ICMPCONST(ANI_FREESPECIAL5);
7590 //ICMPCONST(ANI_FREESPECIAL6);
7591 //ICMPCONST(ANI_FREESPECIAL7);
7592 //ICMPCONST(ANI_FREESPECIAL8);
7593 ICMPCONST(ANI_RISEATTACK
);
7594 ICMPCONST(ANI_DODGE
);
7595 ICMPCONST(ANI_ATTACKBOTH
);
7596 ICMPCONST(ANI_GRABFORWARD
);
7597 ICMPCONST(ANI_GRABFORWARD2
);
7598 ICMPCONST(ANI_JUMPFORWARD
);
7599 ICMPCONST(ANI_GRABDOWN
);
7600 ICMPCONST(ANI_GRABDOWN2
);
7601 ICMPCONST(ANI_GRABUP
);
7602 ICMPCONST(ANI_GRABUP2
);
7603 ICMPCONST(ANI_SELECT
);
7604 ICMPCONST(ANI_DUCK
);
7605 ICMPCONST(ANI_FAINT
);
7606 ICMPCONST(ANI_CANT
);
7607 ICMPCONST(ANI_THROWATTACK
);
7608 ICMPCONST(ANI_CHARGEATTACK
);
7609 ICMPCONST(ANI_VAULT
);
7610 ICMPCONST(ANI_JUMPCANT
);
7611 ICMPCONST(ANI_JUMPSPECIAL
);
7612 ICMPCONST(ANI_BURNDIE
);
7613 ICMPCONST(ANI_SHOCKDIE
);
7614 ICMPCONST(ANI_PAIN2
);
7615 ICMPCONST(ANI_PAIN3
);
7616 ICMPCONST(ANI_PAIN4
);
7617 ICMPCONST(ANI_FALL2
);
7618 ICMPCONST(ANI_FALL3
);
7619 ICMPCONST(ANI_FALL4
);
7620 ICMPCONST(ANI_DIE2
);
7621 ICMPCONST(ANI_DIE3
);
7622 ICMPCONST(ANI_DIE4
);
7623 ICMPCONST(ANI_CHARGE
);
7624 ICMPCONST(ANI_BACKWALK
);
7625 ICMPCONST(ANI_SLEEP
);
7626 //ICMPCONST(ANI_FOLLOW1); // move these below because we have some dynamic animation ids
7627 //ICMPCONST(ANI_FOLLOW2);
7628 //ICMPCONST(ANI_FOLLOW3);
7629 //ICMPCONST(ANI_FOLLOW4);
7630 ICMPCONST(ANI_PAIN5
);
7631 ICMPCONST(ANI_PAIN6
);
7632 ICMPCONST(ANI_PAIN7
);
7633 ICMPCONST(ANI_PAIN8
);
7634 ICMPCONST(ANI_PAIN9
);
7635 ICMPCONST(ANI_PAIN10
);
7636 ICMPCONST(ANI_FALL5
);
7637 ICMPCONST(ANI_FALL6
);
7638 ICMPCONST(ANI_FALL7
);
7639 ICMPCONST(ANI_FALL8
);
7640 ICMPCONST(ANI_FALL9
);
7641 ICMPCONST(ANI_FALL10
);
7642 ICMPCONST(ANI_DIE5
);
7643 ICMPCONST(ANI_DIE6
);
7644 ICMPCONST(ANI_DIE7
);
7645 ICMPCONST(ANI_DIE8
);
7646 ICMPCONST(ANI_DIE9
);
7647 ICMPCONST(ANI_DIE10
);
7648 ICMPCONST(ANI_TURN
);
7649 ICMPCONST(ANI_RESPAWN
);
7650 ICMPCONST(ANI_FORWARDJUMP
);
7651 ICMPCONST(ANI_RUNJUMP
);
7652 ICMPCONST(ANI_JUMPLAND
);
7653 ICMPCONST(ANI_JUMPDELAY
);
7654 ICMPCONST(ANI_HITWALL
);
7655 ICMPCONST(ANI_GRABBACKWARD
);
7656 ICMPCONST(ANI_GRABBACKWARD2
);
7657 ICMPCONST(ANI_GRABWALK
);
7658 ICMPCONST(ANI_GRABBEDWALK
);
7659 ICMPCONST(ANI_GRABWALKUP
);
7660 ICMPCONST(ANI_GRABBEDWALKUP
);
7661 ICMPCONST(ANI_GRABWALKDOWN
);
7662 ICMPCONST(ANI_GRABBEDWALKDOWN
);
7663 ICMPCONST(ANI_GRABTURN
);
7664 ICMPCONST(ANI_GRABBEDTURN
);
7665 ICMPCONST(ANI_GRABBACKWALK
);
7666 ICMPCONST(ANI_GRABBEDBACKWALK
);
7667 ICMPCONST(ANI_SLIDE
);
7668 ICMPCONST(ANI_RUNSLIDE
);
7669 ICMPCONST(ANI_BLOCKPAIN
);
7670 ICMPCONST(ANI_DUCKATTACK
);
7671 ICMPCONST(MAX_ANIS
);
7672 ICMPCONST(PLAYER_MIN_Z
);
7673 ICMPCONST(PLAYER_MAX_Z
);
7674 ICMPCONST(BGHEIGHT
);
7675 ICMPCONST(MAX_WALL_HEIGHT
);
7676 ICMPCONST(SAMPLE_GO
);
7677 ICMPCONST(SAMPLE_BEAT
);
7678 ICMPCONST(SAMPLE_BLOCK
);
7679 ICMPCONST(SAMPLE_INDIRECT
);
7680 ICMPCONST(SAMPLE_GET
);
7681 ICMPCONST(SAMPLE_GET2
);
7682 ICMPCONST(SAMPLE_FALL
);
7683 ICMPCONST(SAMPLE_JUMP
);
7684 ICMPCONST(SAMPLE_PUNCH
);
7685 ICMPCONST(SAMPLE_1UP
);
7686 ICMPCONST(SAMPLE_TIMEOVER
);
7687 ICMPCONST(SAMPLE_BEEP
);
7688 ICMPCONST(SAMPLE_BEEP2
);
7689 ICMPCONST(SAMPLE_BIKE
);
7690 ICMPCONST(ANI_RISE2
);
7691 ICMPCONST(ANI_RISE3
);
7692 ICMPCONST(ANI_RISE4
);
7693 ICMPCONST(ANI_RISE5
);
7694 ICMPCONST(ANI_RISE6
);
7695 ICMPCONST(ANI_RISE7
);
7696 ICMPCONST(ANI_RISE8
);
7697 ICMPCONST(ANI_RISE9
);
7698 ICMPCONST(ANI_RISE10
);
7699 ICMPCONST(ANI_RISEB
);
7700 ICMPCONST(ANI_RISES
);
7701 ICMPCONST(ANI_BLOCKPAIN2
);
7702 ICMPCONST(ANI_BLOCKPAIN3
);
7703 ICMPCONST(ANI_BLOCKPAIN4
);
7704 ICMPCONST(ANI_BLOCKPAIN5
);
7705 ICMPCONST(ANI_BLOCKPAIN6
);
7706 ICMPCONST(ANI_BLOCKPAIN7
);
7707 ICMPCONST(ANI_BLOCKPAIN8
);
7708 ICMPCONST(ANI_BLOCKPAIN9
);
7709 ICMPCONST(ANI_BLOCKPAIN10
);
7710 ICMPCONST(ANI_BLOCKPAINB
);
7711 ICMPCONST(ANI_BLOCKPAINS
);
7712 ICMPCONST(ANI_CHIPDEATH
);
7713 ICMPCONST(ANI_GUARDBREAK
);
7714 ICMPCONST(ANI_RISEATTACK2
);
7715 ICMPCONST(ANI_RISEATTACK3
);
7716 ICMPCONST(ANI_RISEATTACK4
);
7717 ICMPCONST(ANI_RISEATTACK5
);
7718 ICMPCONST(ANI_RISEATTACK6
);
7719 ICMPCONST(ANI_RISEATTACK7
);
7720 ICMPCONST(ANI_RISEATTACK8
);
7721 ICMPCONST(ANI_RISEATTACK9
);
7722 ICMPCONST(ANI_RISEATTACK10
);
7723 ICMPCONST(ANI_RISEATTACKB
);
7724 ICMPCONST(ANI_RISEATTACKS
);
7726 ScriptVariant_ChangeType(varlist
[0], vartype
);
7730 varlist
[0]->lVal
= value
;
7736 static const int ani_translate
[] = {
7737 CMD_SCRIPT_CONSTANT_ANI_DOWN
,
7738 CMD_SCRIPT_CONSTANT_ANI_UP
,
7739 CMD_SCRIPT_CONSTANT_ANI_BACKWALK
,
7740 CMD_SCRIPT_CONSTANT_ANI_WALK
,
7741 CMD_SCRIPT_CONSTANT_ANI_IDLE
,
7742 CMD_SCRIPT_CONSTANT_ANI_FALL
,
7743 CMD_SCRIPT_CONSTANT_ANI_ATTACK
,
7744 CMD_SCRIPT_CONSTANT_ANI_FOLLOW
,
7745 CMD_SCRIPT_CONSTANT_ANI_RISE
,
7746 CMD_SCRIPT_CONSTANT_ANI_RISEATTACK
,
7747 CMD_SCRIPT_CONSTANT_ANI_PAIN
,
7748 CMD_SCRIPT_CONSTANT_ANI_DIE
,
7749 CMD_SCRIPT_CONSTANT_ANI_FREESPECIAL
,
7752 static int** ani_targets
[] = {
7753 &dyn_anims
.animdowns
,
7755 &dyn_anims
.animbackwalks
,
7756 &dyn_anims
.animwalks
,
7757 &dyn_anims
.animidles
,
7758 &dyn_anims
.animfalls
,
7759 &dyn_anims
.animattacks
,
7760 &dyn_anims
.animfollows
,
7761 &dyn_anims
.animrises
,
7762 &dyn_anims
.animriseattacks
,
7763 &dyn_anims
.animpains
,
7764 &dyn_anims
.animdies
,
7765 &dyn_anims
.animspecials
,
7768 #define ani_num_translations (ARRAY_SIZE(ani_targets))
7770 //openborconstant(constname);
7771 //translate a constant by string, used to retrieve a constant or macro of openbor
7772 s32
openbor_transconst(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
7773 char *constname
= NULL
;
7775 char const_name_cp
[64];
7776 unsigned got_num
= 0, l
;
7778 scriptConstantsCommands cmd
;
7781 if(paramCount
< 1) {
7786 mapstrings_transconst(varlist
, paramCount
);
7787 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
7789 if(varlist
[0]->vt
== VT_INTEGER
) // return value already determined by mapstrings
7791 (*pretvar
)->lVal
= varlist
[0]->lVal
;
7793 } else if(varlist
[0]->vt
!= VT_STR
) {
7797 // if we get to this point, it's a dynamic animation id
7798 constname
= StrCache_Get(varlist
[0]->strVal
);
7799 for(l
= 0; l
< sizeof(const_name_cp
) - 1; l
++) {
7800 switch(constname
[l
]) {
7801 case '0': case '1': case '2':
7802 case '3': case '4': case '5':
7803 case '6': case '7': case '8':
7806 const_name_cp
[l
] = constname
[l
];
7809 const_name_cp
[l
] = constname
[l
];
7812 const_name_cp
[l
] = constname
[l
];
7818 if(got_num
&& got_num
== l
- 1) {
7819 if(isdigit(constname
[got_num
-1])) got_num
--;
7820 const_name_cp
[got_num
] = 0;
7821 cmd
= getScriptConstantsCommand(scriptConstantsCommandList
, const_name_cp
);
7823 temp
= atoi(constname
+ got_num
);
7825 case CMD_SCRIPT_CONSTANT_ANI_DOWN
:
7826 case CMD_SCRIPT_CONSTANT_ANI_UP
:
7827 case CMD_SCRIPT_CONSTANT_ANI_BACKWALK
:
7828 case CMD_SCRIPT_CONSTANT_ANI_WALK
:
7829 case CMD_SCRIPT_CONSTANT_ANI_IDLE
:
7830 case CMD_SCRIPT_CONSTANT_ANI_FALL
:
7831 case CMD_SCRIPT_CONSTANT_ANI_ATTACK
:
7832 case CMD_SCRIPT_CONSTANT_ANI_FOLLOW
:
7835 case CMD_SCRIPT_CONSTANT_ANI_RISE
:
7836 case CMD_SCRIPT_CONSTANT_ANI_RISEATTACK
:
7837 case CMD_SCRIPT_CONSTANT_ANI_PAIN
:
7838 case CMD_SCRIPT_CONSTANT_ANI_DIE
:
7841 case CMD_SCRIPT_CONSTANT_ANI_FREESPECIAL
:
7848 if(check_type
>= 0) {
7849 for(l
= 0; l
< ani_num_translations
; l
++)
7850 if(ani_translate
[l
] == cmd
) {
7851 if(check_type
== 1) {
7852 if(temp
< MAX_ATKS
- STA_ATKS
+ 1)
7853 temp
= MAX_ATKS
- STA_ATKS
+ 1; // just in case
7854 } else if(check_type
== 2) {
7858 (*pretvar
)->lVal
= (s32
) ((*ani_targets
[l
])[temp
- 1]);
7864 ScriptVariant_Clear(*pretvar
);
7868 //int rgbcolor(int r, int g, int b);
7869 s32
openbor_rgbcolor(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
7873 goto rgbcolor_error
;
7874 if(FAILED(ScriptVariant_IntegerValue(varlist
[0], &r
)))
7875 goto rgbcolor_error
; // decimal/integer value for red?
7876 if(FAILED(ScriptVariant_IntegerValue(varlist
[1], &g
)))
7877 goto rgbcolor_error
; // decimal/integer value for green?
7878 if(FAILED(ScriptVariant_IntegerValue(varlist
[2], &b
)))
7879 goto rgbcolor_error
; // decimal/integer value for blue?
7881 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
7882 (*pretvar
)->lVal
= _makecolour(r
, g
, b
);
7890 // ===== playerkeys =====
7891 enum playerkeys_enum
{
7909 void mapstrings_playerkeys(ScriptVariant
** varlist
, int paramCount
) {
7910 char *propname
= NULL
;
7913 static const char *proplist
[] = // for args 2+
7931 for(i
= 2; i
< paramCount
; i
++) {
7932 MAPSTRINGS(varlist
[i
], proplist
, _pk_the_end
, "Button name '%s' is not supported by playerkeys.");
7936 //playerkeys(playerindex, newkey?, key1, key2, ...);
7937 s32
openbor_playerkeys(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
7942 ScriptVariant
*arg
= NULL
;
7944 if(paramCount
< 3) {
7949 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
7950 (*pretvar
)->lVal
= (s32
) 1;
7952 mapstrings_playerkeys(varlist
, paramCount
);
7954 if(FAILED(ScriptVariant_IntegerValue((varlist
[0]), <emp
))) {
7957 index
= (int) ltemp
;
7959 if(SUCCEEDED(ScriptVariant_IntegerValue((varlist
[1]), <emp
)))
7960 newkey
= (int) ltemp
;
7965 keys
= player
[index
].newkeys
;
7966 else if(newkey
== 2)
7967 keys
= player
[index
].releasekeys
;
7969 keys
= player
[index
].keys
;
7971 for(i
= 2; i
< paramCount
; i
++) {
7973 if(arg
->vt
== VT_INTEGER
) {
7974 switch (arg
->lVal
) {
7976 (*pretvar
)->lVal
= (s32
) (keys
& FLAG_JUMP
);
7979 (*pretvar
)->lVal
= (s32
) (keys
& FLAG_ATTACK
);
7982 (*pretvar
)->lVal
= (s32
) (keys
& FLAG_ATTACK2
);
7985 (*pretvar
)->lVal
= (s32
) (keys
& FLAG_ATTACK3
);
7988 (*pretvar
)->lVal
= (s32
) (keys
& FLAG_ATTACK4
);
7991 (*pretvar
)->lVal
= (s32
) (keys
& FLAG_SPECIAL
);
7994 (*pretvar
)->lVal
= (s32
) (keys
& FLAG_ESC
);
7997 (*pretvar
)->lVal
= (s32
) (keys
& FLAG_START
);
8000 (*pretvar
)->lVal
= (s32
) (keys
& FLAG_MOVELEFT
);
8003 (*pretvar
)->lVal
= (s32
) (keys
& FLAG_MOVERIGHT
);
8006 (*pretvar
)->lVal
= (s32
) (keys
& FLAG_MOVEUP
);
8009 (*pretvar
)->lVal
= (s32
) (keys
& FLAG_MOVEDOWN
);
8011 case _pk_screenshot
:
8012 (*pretvar
)->lVal
= (s32
) (keys
& FLAG_SCREENSHOT
);
8015 (*pretvar
)->lVal
= (s32
) (keys
& FLAG_ANYBUTTON
);
8018 (*pretvar
)->lVal
= (s32
) 0;
8021 (*pretvar
)->lVal
= (s32
) 0;
8022 if(!((*pretvar
)->lVal
))
8029 //playmusic(name, loop)
8030 s32
openbor_playmusic(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
8033 char *thename
= NULL
;
8036 if(paramCount
< 1) {
8037 sound_close_music();
8040 if(varlist
[0]->vt
!= VT_STR
) {
8044 thename
= StrCache_Get(varlist
[0]->strVal
);
8046 if(paramCount
> 1) {
8047 loop
= (int) ScriptVariant_IsTrue(varlist
[1]);
8050 if(paramCount
> 2) {
8051 if(FAILED(ScriptVariant_IntegerValue(varlist
[2], &offset
)))
8056 music(thename
, loop
, offset
);
8060 //fademusic(fade, name, loop, offset)
8061 s32
openbor_fademusic(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
8063 s32 values
[2] = { 0, 0 };
8066 goto fademusic_error
;
8067 if(FAILED(ScriptVariant_DecimalValue(varlist
[0], &value
)))
8068 goto fademusic_error
;
8069 musicfade
[0] = value
;
8070 musicfade
[1] = (float) savedata
.musicvol
;
8072 if(paramCount
== 4) {
8073 strncpy(musicname
, StrCache_Get(varlist
[1]->strVal
), 128);
8074 if(FAILED(ScriptVariant_IntegerValue(varlist
[2], &values
[0])))
8075 goto fademusic_error
;
8076 if(FAILED(ScriptVariant_IntegerValue(varlist
[3], &values
[1])))
8077 goto fademusic_error
;
8078 musicloop
= values
[0];
8079 musicoffset
= values
[1];
8085 ("Function requires 1 value, with an optional 3 for music triggering: fademusic_error(float fade, char name, int loop, unsigned long offset)\n");
8089 //setmusicvolume(left, right)
8090 s32
openbor_setmusicvolume(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
8093 if(paramCount
< 1) {
8097 if(FAILED(ScriptVariant_IntegerValue(varlist
[0], channels
)))
8098 goto setmusicvolume_error
;
8100 if(paramCount
> 1) {
8101 if(FAILED(ScriptVariant_IntegerValue(varlist
[1], channels
+ 1)))
8102 goto setmusicvolume_error
;
8104 channels
[1] = channels
[0];
8106 sound_volume_music((int) channels
[0], (int) channels
[1]);
8109 setmusicvolume_error
:
8110 printf("values must be integers: setmusicvolume(int left, (optional)int right)\n");
8114 //setmusicvolume(left, right)
8115 s32
openbor_setmusictempo(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
8118 if(paramCount
< 1) {
8122 if(FAILED(ScriptVariant_IntegerValue(varlist
[0], &new_tempo
)))
8125 sound_music_tempo(new_tempo
);
8130 s32
openbor_pausemusic(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
8132 if(paramCount
< 1) {
8136 pause
= (int) ScriptVariant_IsTrue(varlist
[0]);
8138 sound_pause_music(pause
);
8142 //playsample(id, priority, lvolume, rvolume, speed, loop)
8143 s32
openbor_playsample(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
8148 goto playsample_error
;
8151 for(i
= 0; i
< 6; i
++) {
8152 if(FAILED(ScriptVariant_IntegerValue(varlist
[i
], value
+ i
)))
8153 goto playsample_error
;
8155 if((int) value
[0] < 0) {
8156 printf("Invalid Id for playsample(id=%d, priority=%d, lvolume=%d, rvolume=%d, speed=%d, loop=%d)\n",
8157 (int) value
[0], (unsigned int) value
[1], (int) value
[2], (int) value
[3], (unsigned int) value
[4],
8162 sound_loop_sample((int) value
[0], (unsigned int) value
[1], (int) value
[2], (int) value
[3],
8163 (unsigned int) value
[4]);
8165 sound_play_sample((int) value
[0], (unsigned int) value
[1], (int) value
[2], (int) value
[3],
8166 (unsigned int) value
[4]);
8172 ("Function requires 6 integer values: playsample(int id, unsigned int priority, int lvolume, int rvolume, unsigned int speed, int loop)\n");
8176 // int loadsample(filename, log)
8177 s32
openbor_loadsample(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
8180 if(paramCount
< 1) {
8181 goto loadsample_error
;
8183 if(varlist
[0]->vt
!= VT_STR
)
8184 goto loadsample_error
;
8186 if(paramCount
> 1) {
8187 if(varlist
[1]->vt
== VT_INTEGER
) {
8188 arg
= varlist
[1]->lVal
;
8190 goto loadsample_error
;
8194 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
8195 (*pretvar
)->lVal
= (s32
) sound_load_sample(StrCache_Get(varlist
[0]->strVal
), packfile
, arg
);
8200 ("Function requires 1 string value and optional log value: loadsample(string {filename} integer {log})\n");
8205 // void unloadsample(id)
8206 s32
openbor_unloadsample(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
8210 goto unloadsample_error
;
8212 if(FAILED(ScriptVariant_IntegerValue((varlist
[0]), &id
)))
8213 goto unloadsample_error
;
8215 sound_unload_sample((int) id
);
8219 printf("Function requires 1 integer value: unloadsample(int id)\n");
8223 //fadeout(type, speed);
8224 s32
openbor_fadeout(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
8229 goto fade_out_error
;
8231 if(FAILED(ScriptVariant_IntegerValue((varlist
[0]), &type
)))
8232 goto fade_out_error
;
8233 if(FAILED(ScriptVariant_IntegerValue((varlist
[1]), &speed
)))
8235 fade_out((int) type
, (int) speed
);
8239 printf("Function requires 2 integer values: fade_out(int type, int speed)\n");
8243 //changepalette(index);
8244 s32
openbor_changepalette(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
8250 goto changepalette_error
;
8252 if(FAILED(ScriptVariant_IntegerValue((varlist
[0]), &index
)))
8253 goto changepalette_error
;
8255 change_system_palette((int) index
);
8259 changepalette_error
:
8260 printf("Function requires 1 integer value: changepalette(int index)\n");
8264 //changelight(x, z);
8265 s32
openbor_changelight(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
8267 extern int light
[2];
8268 ScriptVariant
*arg
= NULL
;
8272 goto changelight_error
;
8275 if(arg
->vt
!= VT_EMPTY
) {
8276 if(FAILED(ScriptVariant_IntegerValue(arg
, &x
)))
8277 goto changelight_error
;
8282 if(arg
->vt
!= VT_EMPTY
) {
8283 if(FAILED(ScriptVariant_IntegerValue(arg
, &z
)))
8284 goto changelight_error
;
8290 printf("Function requires 2 integer values: changepalette(int x, int z)\n");
8294 //changeshadowcolor(color, alpha);
8295 // color = 0 means no gfxshadow, -1 means don't fill the shadow with colour
8296 // alpha default to 2, <=0 means no alpha effect
8297 s32
openbor_changeshadowcolor(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
8299 extern int shadowalpha
;
8303 goto changeshadowcolor_error
;
8305 if(FAILED(ScriptVariant_IntegerValue(varlist
[0], &c
)))
8306 goto changeshadowcolor_error
;
8308 colors
.shadow
= (int) c
;
8310 if(paramCount
> 1) {
8311 if(FAILED(ScriptVariant_IntegerValue(varlist
[1], &a
)))
8312 goto changeshadowcolor_error
;
8313 shadowalpha
= (int) a
;
8317 changeshadowcolor_error
:
8319 ("Function requires at least 1 integer value, the 2nd integer parameter is optional: changepalette(int colorindex, int alpha)\n");
8323 // ===== gettextobjproperty(name, value) =====
8334 void mapstrings_gettextobjproperty(ScriptVariant
** varlist
, int paramCount
) {
8335 char *propname
= NULL
;
8338 static const char *proplist
[] = {
8349 MAPSTRINGS(varlist
[1], proplist
, _gtop_the_end
,
8350 "Property name '%s' is not supported by function gettextobjproperty.\n");
8353 s32
openbor_gettextobjproperty(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
8358 goto gettextobjproperty_error
;
8361 if(FAILED(ScriptVariant_IntegerValue(varlist
[0], &ind
))) {
8362 printf("Function's 1st argument must be a numeric value: gettextproperty(int index, \"property\")\n");
8363 goto gettextobjproperty_error
;
8366 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
8367 mapstrings_gettextobjproperty(varlist
, paramCount
);
8369 if(ind
< 0 || ind
>= LEVEL_MAX_TEXTOBJS
) {
8370 (*pretvar
)->lVal
= 0;
8374 if(varlist
[1]->vt
!= VT_INTEGER
) {
8375 if(varlist
[1]->vt
!= VT_STR
)
8376 printf("Function gettextobjproperty must have a string property name.\n");
8377 goto gettextobjproperty_error
;
8380 propind
= varlist
[1]->lVal
;
8385 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
8386 (*pretvar
)->lVal
= (s32
) level
->textobjs
[ind
].font
;
8391 ScriptVariant_ChangeType(*pretvar
, VT_STR
);
8392 strcpy(StrCache_Get((*pretvar
)->strVal
), level
->textobjs
[ind
].text
);
8397 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
8398 (*pretvar
)->lVal
= (s32
) level
->textobjs
[ind
].t
;
8403 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
8404 (*pretvar
)->lVal
= (s32
) level
->textobjs
[ind
].x
;
8409 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
8410 (*pretvar
)->lVal
= (s32
) level
->textobjs
[ind
].y
;
8415 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
8416 (*pretvar
)->lVal
= (s32
) level
->textobjs
[ind
].z
;
8420 //printf("Property name '%s' is not supported by function gettextobjproperty.\n", propname);
8421 goto gettextobjproperty_error
;
8427 gettextobjproperty_error
:
8432 // ===== changetextobjproperty(name, value) =====
8443 void mapstrings_changetextobjproperty(ScriptVariant
** varlist
, int paramCount
) {
8444 char *propname
= NULL
;
8447 static const char *proplist
[] = {
8458 MAPSTRINGS(varlist
[1], proplist
, _ctop_the_end
,
8459 "Property name '%s' is not supported by function changetextobjproperty.\n");
8462 s32
openbor_changetextobjproperty(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
8468 goto changetextobjproperty_error
;
8471 if(FAILED(ScriptVariant_IntegerValue(varlist
[0], &ind
))) {
8473 ("Function's 1st argument must be a numeric value: changetextobjproperty(int index, \"property\", value)\n");
8474 goto changetextobjproperty_error
;
8477 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
8478 mapstrings_changetextobjproperty(varlist
, paramCount
);
8480 if(ind
< 0 || ind
>= LEVEL_MAX_TEXTOBJS
) {
8481 (*pretvar
)->lVal
= 0;
8485 if(varlist
[1]->vt
!= VT_INTEGER
) {
8486 if(varlist
[1]->vt
!= VT_STR
)
8487 printf("Function changetextobjproperty must have a string property name.\n");
8488 goto changetextobjproperty_error
;
8491 propind
= varlist
[1]->lVal
;
8496 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
8497 (*pretvar
)->lVal
= (s32
) 1;
8498 level
->textobjs
[ind
].font
= (int) ltemp
;
8504 if(varlist
[2]->vt
!= VT_STR
) {
8505 printf("You must give a string value for textobj text.\n");
8506 goto changetextobjproperty_error
;
8508 if(!level
->textobjs
[ind
].text
) {
8509 level
->textobjs
[ind
].text
= (char *) malloc(MAX_STR_VAR_LEN
);
8511 strncpy(level
->textobjs
[ind
].text
, (char *) StrCache_Get(varlist
[2]->strVal
),
8513 //level->textobjs[ind].text = (char*)StrCache_Get(varlist[2]->strVal);
8514 (*pretvar
)->lVal
= (s32
) 1;
8519 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
8520 (*pretvar
)->lVal
= (s32
) 1;
8521 level
->textobjs
[ind
].t
= (int) ltemp
;
8527 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
8528 (*pretvar
)->lVal
= (s32
) 1;
8529 level
->textobjs
[ind
].x
= (int) ltemp
;
8535 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
8536 (*pretvar
)->lVal
= (s32
) 1;
8537 level
->textobjs
[ind
].y
= (int) ltemp
;
8543 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
8544 (*pretvar
)->lVal
= (s32
) 1;
8545 level
->textobjs
[ind
].z
= (int) ltemp
;
8550 //printf("Property name '%s' is not supported by function changetextobjproperty.\n", propname);
8551 goto changetextobjproperty_error
;
8557 changetextobjproperty_error
:
8562 // changelevelproperty(name, value)
8563 s32
openbor_settextobj(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
8568 goto settextobj_error
;
8570 if(FAILED(ScriptVariant_IntegerValue(varlist
[0], &ind
))) {
8572 ("Function's 1st argument must be a numeric value: settextobj(int index, int x, int y, int font, int z, char text, int time {optional})\n");
8573 goto settextobj_error
;
8576 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
8578 if(ind
< 0 || ind
>= LEVEL_MAX_TEXTOBJS
) {
8579 (*pretvar
)->lVal
= 0;
8583 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[1], <emp
))) {
8584 (*pretvar
)->lVal
= (s32
) 1;
8585 level
->textobjs
[ind
].x
= (int) ltemp
;
8588 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
8589 (*pretvar
)->lVal
= (s32
) 1;
8590 level
->textobjs
[ind
].y
= (int) ltemp
;
8593 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[3], <emp
))) {
8594 (*pretvar
)->lVal
= (s32
) 1;
8595 level
->textobjs
[ind
].font
= (int) ltemp
;
8598 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[4], <emp
))) {
8599 (*pretvar
)->lVal
= (s32
) 1;
8600 level
->textobjs
[ind
].z
= (int) ltemp
;
8603 if(varlist
[5]->vt
!= VT_STR
) {
8604 printf("You must give a string value for textobj text.\n");
8605 goto settextobj_error
;
8608 if(paramCount
>= 7) {
8609 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[6], <emp
))) {
8610 (*pretvar
)->lVal
= (s32
) 1;
8611 level
->textobjs
[ind
].t
= (int) ltemp
;
8615 if(!level
->textobjs
[ind
].text
) {
8616 level
->textobjs
[ind
].text
= (char *) malloc(MAX_STR_VAR_LEN
);
8618 strncpy(level
->textobjs
[ind
].text
, (char *) StrCache_Get(varlist
[5]->strVal
), MAX_STR_VAR_LEN
);
8619 (*pretvar
)->lVal
= (s32
) 1;
8628 s32
openbor_cleartextobj(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
8632 goto cleartextobj_error
;
8635 if(FAILED(ScriptVariant_IntegerValue(varlist
[0], &ind
))) {
8636 printf("Function's 1st argument must be a numeric value: cleartextobj(int index)\n");
8637 goto cleartextobj_error
;
8640 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
8642 if(ind
< 0 || ind
>= LEVEL_MAX_TEXTOBJS
) {
8643 (*pretvar
)->lVal
= 0;
8647 level
->textobjs
[ind
].t
= 0;
8648 level
->textobjs
[ind
].x
= 0;
8649 level
->textobjs
[ind
].y
= 0;
8650 level
->textobjs
[ind
].font
= 0;
8651 level
->textobjs
[ind
].z
= 0;
8652 if(level
->textobjs
[ind
].text
)
8653 free(level
->textobjs
[ind
].text
);
8654 level
->textobjs
[ind
].text
= NULL
;
8663 // ===== getbglayerproperty ======
8667 _gbglp_bgspeedratio
,
8669 _gbglp_transparency
,
8684 void mapstrings_getbglayerproperty(ScriptVariant
** varlist
, int paramCount
) {
8685 char *propname
= NULL
;
8688 static const char *proplist
[] = {
8709 MAPSTRINGS(varlist
[1], proplist
, _gbglp_the_end
,
8710 "Property name '%s' is not supported by function getbglayerproperty.\n");
8713 s32
openbor_getbglayerproperty(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
8718 goto getbglayerproperty_error
;
8720 if(FAILED(ScriptVariant_IntegerValue(varlist
[0], &ind
))) {
8722 ("Function's 1st argument must be a numeric value: getbglayerproperty(int index, \"property\", value)\n");
8723 goto getbglayerproperty_error
;
8726 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
8727 mapstrings_getbglayerproperty(varlist
, paramCount
);
8729 if(ind
< 0 || ind
>= level
->numbglayers
) {
8730 (*pretvar
)->lVal
= 0;
8734 if(varlist
[1]->vt
!= VT_INTEGER
) {
8735 printf("Function getbglayerproperty must have a string property name.\n");
8736 goto getbglayerproperty_error
;
8739 propind
= varlist
[1]->lVal
;
8744 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
8745 (*pretvar
)->lVal
= (s32
) level
->bglayers
[ind
].alpha
;
8748 case _gbglp_amplitude
:
8750 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
8751 (*pretvar
)->lVal
= (s32
) level
->bglayers
[ind
].amplitude
;
8754 case _gbglp_bgspeedratio
:
8756 ScriptVariant_ChangeType(*pretvar
, VT_DECIMAL
);
8757 (*pretvar
)->dblVal
= (double) level
->bglayers
[ind
].bgspeedratio
;
8760 case _gbglp_enabled
:
8762 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
8763 (*pretvar
)->lVal
= (s32
) level
->bglayers
[ind
].enabled
;
8766 case _gbglp_transparency
:
8768 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
8769 (*pretvar
)->lVal
= (s32
) level
->bglayers
[ind
].transparency
;
8772 case _gbglp_watermode
:
8774 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
8775 (*pretvar
)->lVal
= (s32
) level
->bglayers
[ind
].watermode
;
8779 case _gbglp_wavelength
:
8781 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
8782 (*pretvar
)->lVal
= (s32
) level
->bglayers
[ind
].wavelength
;
8785 case _gbglp_wavespeed
:
8787 ScriptVariant_ChangeType(*pretvar
, VT_DECIMAL
);
8788 (*pretvar
)->dblVal
= (double) level
->bglayers
[ind
].wavespeed
;
8791 case _gbglp_xoffset
:
8793 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
8794 (*pretvar
)->lVal
= (s32
) level
->bglayers
[ind
].xoffset
;
8799 ScriptVariant_ChangeType(*pretvar
, VT_DECIMAL
);
8800 (*pretvar
)->dblVal
= (double) level
->bglayers
[ind
].xratio
;
8803 case _gbglp_xrepeat
:
8805 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
8806 (*pretvar
)->lVal
= (s32
) level
->bglayers
[ind
].xrepeat
;
8809 case _gbglp_xspacing
:
8811 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
8812 (*pretvar
)->lVal
= (s32
) level
->bglayers
[ind
].xspacing
;
8815 case _gbglp_zoffset
:
8817 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
8818 (*pretvar
)->lVal
= (s32
) level
->bglayers
[ind
].zoffset
;
8823 ScriptVariant_ChangeType(*pretvar
, VT_DECIMAL
);
8824 (*pretvar
)->dblVal
= (double) level
->bglayers
[ind
].zratio
;
8827 case _gbglp_zrepeat
:
8829 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
8830 (*pretvar
)->lVal
= (s32
) level
->bglayers
[ind
].zrepeat
;
8833 case _gbglp_zspacing
:
8835 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
8836 (*pretvar
)->lVal
= (s32
) level
->bglayers
[ind
].zspacing
;
8840 //printf("Property name '%s' is not supported by function getbglayerproperty.\n", propname);
8841 goto getbglayerproperty_error
;
8847 getbglayerproperty_error
:
8852 // ===== changebglayerproperty =====
8856 _cbglp_bgspeedratio
,
8858 _cbglp_transparency
,
8873 void mapstrings_changebglayerproperty(ScriptVariant
** varlist
, int paramCount
) {
8874 char *propname
= NULL
;
8877 static const char *proplist
[] = {
8898 MAPSTRINGS(varlist
[1], proplist
, _cbglp_the_end
,
8899 "Property name '%s' is not supported by function changebglayerproperty.\n");
8902 s32
openbor_changebglayerproperty(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
8909 goto changebglayerproperty_error
;
8912 if(FAILED(ScriptVariant_IntegerValue(varlist
[0], &ind
))) {
8914 ("Function's 1st argument must be a numeric value: changebglayerproperty(int index, \"property\", value)\n");
8915 goto changebglayerproperty_error
;
8918 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
8919 mapstrings_changebglayerproperty(varlist
, paramCount
);
8921 if(ind
< 0 || ind
>= level
->numbglayers
) {
8922 (*pretvar
)->lVal
= 0;
8926 if(varlist
[1]->vt
!= VT_INTEGER
) {
8927 printf("Function changebglayerproperty must have a string property name.\n");
8928 goto changebglayerproperty_error
;
8931 propind
= varlist
[1]->lVal
;
8936 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
8937 (*pretvar
)->lVal
= (s32
) 1;
8938 level
->bglayers
[ind
].alpha
= (int) ltemp
;
8942 case _cbglp_amplitude
:
8944 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
8945 (*pretvar
)->lVal
= (s32
) 1;
8946 level
->bglayers
[ind
].amplitude
= (int) ltemp
;
8950 case _cbglp_bgspeedratio
:
8952 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[2], &dbltemp
))) {
8953 (*pretvar
)->lVal
= (s32
) 1;
8954 level
->bglayers
[ind
].bgspeedratio
= (float) dbltemp
;
8958 case _cbglp_enabled
:
8960 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
8961 (*pretvar
)->lVal
= (s32
) 1;
8962 level
->bglayers
[ind
].enabled
= (int) ltemp
;
8966 case _cbglp_transparency
:
8968 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
8969 (*pretvar
)->lVal
= (s32
) 1;
8970 level
->bglayers
[ind
].transparency
= (int) ltemp
;
8974 case _cbglp_watermode
:
8976 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
8977 (*pretvar
)->lVal
= (s32
) 1;
8978 level
->bglayers
[ind
].watermode
= (int) ltemp
;
8983 case _cbglp_wavelength
:
8985 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
8986 (*pretvar
)->lVal
= (s32
) 1;
8987 level
->bglayers
[ind
].wavelength
= (int) ltemp
;
8991 case _cbglp_wavespeed
:
8993 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[2], &dbltemp
))) {
8994 (*pretvar
)->lVal
= (s32
) 1;
8995 level
->bglayers
[ind
].wavespeed
= (float) dbltemp
;
8999 case _cbglp_xoffset
:
9001 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
9002 (*pretvar
)->lVal
= (s32
) 1;
9003 level
->bglayers
[ind
].xoffset
= (int) ltemp
;
9009 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[2], &dbltemp
))) {
9010 (*pretvar
)->lVal
= (s32
) 1;
9011 level
->bglayers
[ind
].xratio
= (float) dbltemp
;
9015 case _cbglp_xrepeat
:
9017 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
9018 (*pretvar
)->lVal
= (s32
) 1;
9019 level
->bglayers
[ind
].xrepeat
= (int) ltemp
;
9023 case _cbglp_xspacing
:
9025 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
9026 (*pretvar
)->lVal
= (s32
) 1;
9027 level
->bglayers
[ind
].xspacing
= (int) ltemp
;
9031 case _cbglp_zoffset
:
9033 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
9034 (*pretvar
)->lVal
= (s32
) 1;
9035 level
->bglayers
[ind
].zoffset
= (int) ltemp
;
9041 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[2], &dbltemp
))) {
9042 (*pretvar
)->lVal
= (s32
) 1;
9043 level
->bglayers
[ind
].zratio
= (float) dbltemp
;
9047 case _cbglp_zrepeat
:
9049 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
9050 (*pretvar
)->lVal
= (s32
) 1;
9051 level
->bglayers
[ind
].zrepeat
= (int) ltemp
;
9055 case _cbglp_zspacing
:
9057 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
9058 (*pretvar
)->lVal
= (s32
) 1;
9059 level
->bglayers
[ind
].zspacing
= (int) ltemp
;
9064 //printf("Property name '%s' is not supported by function changebglayerproperty.\n", propname);
9065 goto changebglayerproperty_error
;
9071 changebglayerproperty_error
:
9076 // ===== getfglayerproperty =====
9080 _gfglp_bgspeedratio
,
9082 _gfglp_transparency
,
9097 void mapstrings_getfglayerproperty(ScriptVariant
** varlist
, int paramCount
) {
9098 char *propname
= NULL
;
9101 static const char *proplist
[] = {
9122 MAPSTRINGS(varlist
[1], proplist
, _gfglp_the_end
,
9123 "Property name '%s' is not supported by function getfglayerproperty.\n");
9126 s32
openbor_getfglayerproperty(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
9131 goto getfglayerproperty_error
;
9134 if(FAILED(ScriptVariant_IntegerValue(varlist
[0], &ind
))) {
9136 ("Function's 1st argument must be a numeric value: getfglayerproperty(int index, \"property\", value)\n");
9137 goto getfglayerproperty_error
;
9140 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
9141 mapstrings_getfglayerproperty(varlist
, paramCount
);
9143 if(ind
< 0 || ind
>= level
->numfglayers
) {
9144 (*pretvar
)->lVal
= 0;
9148 if(varlist
[1]->vt
!= VT_INTEGER
) {
9149 printf("Function getfglayerproperty must have a string property name.\n");
9150 goto getfglayerproperty_error
;
9153 propind
= varlist
[1]->lVal
;
9158 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
9159 (*pretvar
)->lVal
= (s32
) level
->fglayers
[ind
].alpha
;
9162 case _gfglp_amplitude
:
9164 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
9165 (*pretvar
)->lVal
= (s32
) level
->fglayers
[ind
].amplitude
;
9168 case _gfglp_bgspeedratio
:
9170 ScriptVariant_ChangeType(*pretvar
, VT_DECIMAL
);
9171 (*pretvar
)->dblVal
= (double) level
->fglayers
[ind
].bgspeedratio
;
9174 case _gfglp_enabled
:
9176 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
9177 (*pretvar
)->lVal
= (s32
) level
->fglayers
[ind
].enabled
;
9180 case _gfglp_transparency
:
9182 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
9183 (*pretvar
)->lVal
= (s32
) level
->fglayers
[ind
].transparency
;
9186 case _gfglp_watermode
:
9188 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
9189 (*pretvar
)->lVal
= (s32
) level
->fglayers
[ind
].watermode
;
9193 case _gfglp_wavelength
:
9195 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
9196 (*pretvar
)->lVal
= (s32
) level
->fglayers
[ind
].wavelength
;
9199 case _gfglp_wavespeed
:
9201 ScriptVariant_ChangeType(*pretvar
, VT_DECIMAL
);
9202 (*pretvar
)->dblVal
= (double) level
->fglayers
[ind
].wavespeed
;
9205 case _gfglp_xoffset
:
9207 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
9208 (*pretvar
)->lVal
= (s32
) level
->fglayers
[ind
].xoffset
;
9213 ScriptVariant_ChangeType(*pretvar
, VT_DECIMAL
);
9214 (*pretvar
)->dblVal
= (double) level
->fglayers
[ind
].xratio
;
9217 case _gfglp_xrepeat
:
9219 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
9220 (*pretvar
)->lVal
= (s32
) level
->fglayers
[ind
].xrepeat
;
9223 case _gfglp_xspacing
:
9225 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
9226 (*pretvar
)->lVal
= (s32
) level
->fglayers
[ind
].xspacing
;
9229 case _gfglp_zoffset
:
9231 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
9232 (*pretvar
)->lVal
= (s32
) level
->fglayers
[ind
].zoffset
;
9237 ScriptVariant_ChangeType(*pretvar
, VT_DECIMAL
);
9238 (*pretvar
)->dblVal
= (double) level
->fglayers
[ind
].zratio
;
9241 case _gfglp_zrepeat
:
9243 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
9244 (*pretvar
)->lVal
= (s32
) level
->fglayers
[ind
].zrepeat
;
9247 case _gfglp_zspacing
:
9249 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
9250 (*pretvar
)->lVal
= (s32
) level
->fglayers
[ind
].zspacing
;
9254 //printf("Property name '%s' is not supported by function getfglayerproperty.\n", propname);
9255 goto getfglayerproperty_error
;
9261 getfglayerproperty_error
:
9266 // ===== changefglayerproperty =====
9270 _cfglp_bgspeedratio
,
9272 _cfglp_transparency
,
9287 void mapstrings_changefglayerproperty(ScriptVariant
** varlist
, int paramCount
) {
9288 char *propname
= NULL
;
9291 static const char *proplist
[] = {
9312 MAPSTRINGS(varlist
[1], proplist
, _cfglp_the_end
,
9313 "Property name '%s' is not supported by function changefglayerproperty.\n");
9316 s32
openbor_changefglayerproperty(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
9323 goto changefglayerproperty_error
;
9325 if(FAILED(ScriptVariant_IntegerValue(varlist
[0], &ind
))) {
9327 ("Function's 1st argument must be a numeric value: changefglayerproperty(int index, \"property\", value)\n");
9328 goto changefglayerproperty_error
;
9331 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
9332 mapstrings_changefglayerproperty(varlist
, paramCount
);
9334 if(ind
< 0 || ind
>= level
->numfglayers
) {
9335 (*pretvar
)->lVal
= 0;
9339 if(varlist
[1]->vt
!= VT_INTEGER
) {
9340 printf("Function changefglayerproperty must have a string property name.\n");
9341 goto changefglayerproperty_error
;
9344 propind
= varlist
[1]->lVal
;
9349 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
9350 (*pretvar
)->lVal
= (s32
) 1;
9351 level
->fglayers
[ind
].alpha
= (int) ltemp
;
9355 case _cfglp_amplitude
:
9357 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
9358 (*pretvar
)->lVal
= (s32
) 1;
9359 level
->fglayers
[ind
].amplitude
= (int) ltemp
;
9363 case _cfglp_bgspeedratio
:
9365 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[2], &dbltemp
))) {
9366 (*pretvar
)->lVal
= (s32
) 1;
9367 level
->fglayers
[ind
].bgspeedratio
= (float) dbltemp
;
9371 case _cfglp_enabled
:
9373 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
9374 (*pretvar
)->lVal
= (s32
) 1;
9375 level
->fglayers
[ind
].enabled
= (int) ltemp
;
9379 case _cfglp_transparency
:
9381 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
9382 (*pretvar
)->lVal
= (s32
) 1;
9383 level
->fglayers
[ind
].transparency
= (int) ltemp
;
9387 case _cfglp_watermode
:
9389 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
9390 (*pretvar
)->lVal
= (s32
) 1;
9391 level
->fglayers
[ind
].watermode
= (int) ltemp
;
9396 case _cfglp_wavelength
:
9398 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
9399 (*pretvar
)->lVal
= (s32
) 1;
9400 level
->fglayers
[ind
].wavelength
= (int) ltemp
;
9404 case _cfglp_wavespeed
:
9406 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[2], &dbltemp
))) {
9407 (*pretvar
)->lVal
= (s32
) 1;
9408 level
->fglayers
[ind
].wavespeed
= (float) dbltemp
;
9412 case _cfglp_xoffset
:
9414 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
9415 (*pretvar
)->lVal
= (s32
) 1;
9416 level
->fglayers
[ind
].xoffset
= (int) ltemp
;
9422 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[2], &dbltemp
))) {
9423 (*pretvar
)->lVal
= (s32
) 1;
9424 level
->fglayers
[ind
].xratio
= (float) dbltemp
;
9428 case _cfglp_xrepeat
:
9430 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
9431 (*pretvar
)->lVal
= (s32
) 1;
9432 level
->fglayers
[ind
].xrepeat
= (int) ltemp
;
9436 case _cfglp_xspacing
:
9438 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
9439 (*pretvar
)->lVal
= (s32
) 1;
9440 level
->fglayers
[ind
].xspacing
= (int) ltemp
;
9444 case _cfglp_zoffset
:
9446 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
9447 (*pretvar
)->lVal
= (s32
) 1;
9448 level
->fglayers
[ind
].zoffset
= (int) ltemp
;
9454 if(SUCCEEDED(ScriptVariant_DecimalValue(varlist
[2], &dbltemp
))) {
9455 (*pretvar
)->lVal
= (s32
) 1;
9456 level
->fglayers
[ind
].zratio
= (float) dbltemp
;
9460 case _cfglp_zrepeat
:
9462 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
9463 (*pretvar
)->lVal
= (s32
) 1;
9464 level
->fglayers
[ind
].zrepeat
= (int) ltemp
;
9468 case _cfglp_zspacing
:
9470 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[2], <emp
))) {
9471 (*pretvar
)->lVal
= (s32
) 1;
9472 level
->fglayers
[ind
].zspacing
= (int) ltemp
;
9477 //printf("Property name '%s' is not supported by function changefglayerproperty.\n", propname);
9478 goto changefglayerproperty_error
;
9484 changefglayerproperty_error
:
9489 s32
openbor_getlevelproperty(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
9490 char *propname
= NULL
;
9493 static const char *proplist
[] = {
9508 if(varlist
[0]->vt
!= VT_STR
) {
9509 printf("Function getlevelproperty must have a string property name.\n");
9510 goto getlevelproperty_error
;
9514 propname
= (char *) StrCache_Get(varlist
[0]->strVal
); //see what property it is
9516 propind
= searchList(proplist
, propname
, _lp_the_end
);
9521 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
9522 (*pretvar
)->lVal
= (s32
) level
->bgspeed
;
9525 case _lp_cameraxoffset
:
9527 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
9528 (*pretvar
)->lVal
= (s32
) level
->cameraxoffset
;
9531 case _lp_camerazoffset
:
9533 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
9534 (*pretvar
)->lVal
= (s32
) level
->camerazoffset
;
9538 printf("Property name '%s' is not supported by function getlevelproperty.\n", propname
);
9539 goto getlevelproperty_error
;
9545 getlevelproperty_error
:
9550 //changelevelproperty(name, value)
9551 s32
openbor_changelevelproperty(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
9552 char *propname
= NULL
;
9554 ScriptVariant
*arg
= NULL
;
9556 if(paramCount
< 2) {
9561 if(varlist
[0]->vt
!= VT_STR
) {
9566 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
9567 (*pretvar
)->lVal
= (s32
) 1;
9569 propname
= (char *) StrCache_Get(varlist
[0]->strVal
);
9573 if(strcmp(propname
, "rock") == 0) {
9574 if(SUCCEEDED(ScriptVariant_IntegerValue(arg
, <emp
)))
9575 level
->rocking
= (int) ltemp
;
9577 (*pretvar
)->lVal
= (s32
) 0;
9578 } else if(strcmp(propname
, "bgspeed") == 0) {
9579 if(SUCCEEDED(ScriptVariant_IntegerValue(arg
, <emp
)))
9580 level
->bgspeed
= (float) ltemp
;
9582 (*pretvar
)->lVal
= (s32
) 0;
9583 } else if(strcmp(propname
, "cameraxoffset") == 0) {
9584 if(SUCCEEDED(ScriptVariant_IntegerValue(arg
, <emp
)))
9585 level
->cameraxoffset
= (int) ltemp
;
9587 (*pretvar
)->lVal
= (s32
) 0;
9588 } else if(strcmp(propname
, "camerazoffset") == 0) {
9589 if(SUCCEEDED(ScriptVariant_IntegerValue(arg
, <emp
)))
9590 level
->camerazoffset
= (int) ltemp
;
9592 (*pretvar
)->lVal
= (s32
) 0;
9598 //jumptobranch(name, immediate)
9599 s32
openbor_jumptobranch(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
9601 extern char branch_name
[MAX_NAME_LEN
+ 1];
9606 goto jumptobranch_error
;
9607 if(varlist
[0]->vt
!= VT_STR
)
9608 goto jumptobranch_error
;
9610 strncpy(branch_name
, StrCache_Get(varlist
[0]->strVal
), MIN(MAX_NAME_LEN
, MAX_STR_VAR_LEN
)); // copy the string value to branch name
9612 if(paramCount
>= 2) {
9613 if(SUCCEEDED(ScriptVariant_IntegerValue(varlist
[1], <emp
))) {
9614 endgame
= (int) ltemp
;
9615 // 1 means goto that level immediately, or, wait until the level is complete
9617 goto jumptobranch_error
;
9623 ("Function requires 1 string value, the second argument is optional(int): jumptobranch(name, immediate)\n");
9627 //bindentity(entity, target, x, z, a, direction, bindanim);
9628 //bindentity(entity, NULL()); // unbind
9629 s32
openbor_bindentity(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
9631 entity
*other
= NULL
;
9632 ScriptVariant
*arg
= NULL
;
9633 void adjust_bind(entity
* e
);
9634 s32 x
= 0, z
= 0, a
= 0, dir
= 0, anim
= 0;
9637 if(paramCount
< 2) {
9641 ent
= (entity
*) (varlist
[0])->ptrVal
; //retrieve the entity
9645 other
= (entity
*) (varlist
[1])->ptrVal
;
9657 if(arg
->vt
!= VT_EMPTY
) {
9658 if(FAILED(ScriptVariant_IntegerValue(arg
, &x
)))
9661 ent
->bindoffset
[0] = (int) x
;
9667 if(arg
->vt
!= VT_EMPTY
) {
9668 if(FAILED(ScriptVariant_IntegerValue(arg
, &z
)))
9670 ent
->bindoffset
[1] = (int) z
;
9676 if(arg
->vt
!= VT_EMPTY
) {
9677 if(FAILED(ScriptVariant_IntegerValue(arg
, &a
)))
9679 ent
->bindoffset
[2] = (int) a
;
9685 if(arg
->vt
!= VT_EMPTY
) {
9686 if(FAILED(ScriptVariant_IntegerValue(arg
, &dir
)))
9688 ent
->bindoffset
[3] = (int) dir
;
9694 if(arg
->vt
!= VT_EMPTY
) {
9695 if(FAILED(ScriptVariant_IntegerValue(arg
, &anim
)))
9697 ent
->bindanim
= (int) anim
;
9706 //allocscreen(int w, int h);
9707 s32
openbor_allocscreen(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
9712 goto allocscreen_error
;
9714 if(FAILED(ScriptVariant_IntegerValue(varlist
[0], &w
)))
9715 goto allocscreen_error
;
9716 if(FAILED(ScriptVariant_IntegerValue(varlist
[1], &h
)))
9717 goto allocscreen_error
;
9720 ScriptVariant_ChangeType(*pretvar
, VT_PTR
);
9721 screen
= allocscreen((int) w
, (int) h
, screenformat
);
9723 clearscreen(screen
);
9724 (*pretvar
)->ptrVal
= (void*) screen
;
9726 if((*pretvar
)->ptrVal
== NULL
) {
9727 printf("Not enough memory: allocscreen(%d, %d)\n", (int) w
, (int) h
);
9731 List_InsertAfter(&scriptheap
, (void *) ((*pretvar
)->ptrVal
), "openbor_allocscreen");
9735 printf("Function requires 2 int values: allocscreen(int width, int height)\n");
9740 //clearscreen(s_screen* screen)
9741 s32
openbor_clearscreen(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
9746 goto clearscreen_error
;
9747 if(varlist
[0]->vt
!= VT_PTR
)
9748 goto clearscreen_error
;
9750 screen
= (s_screen
*) varlist
[0]->ptrVal
;
9752 if(screen
== NULL
) {
9753 printf("Error: NULL pointer passed to clearscreen(void screen)\n");
9757 clearscreen(screen
);
9761 printf("Function requires a screen pointer: clearscreen(void screen)\n");
9765 //setdrawmethod(entity, int flag, int scalex, int scaley, int flipx, int flipy, int shiftx, int alpha, int remap, int fillcolor, int rotate, int fliprotate, int transparencybg, void* colourmap);
9766 s32
openbor_setdrawmethod(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
9769 s_drawmethod
*pmethod
;
9774 goto setdrawmethod_error
;
9776 if(varlist
[0]->vt
== VT_EMPTY
)
9778 else if(varlist
[0]->vt
== VT_PTR
)
9779 e
= (entity
*) varlist
[0]->ptrVal
;
9781 goto setdrawmethod_error
;
9784 pmethod
= &(e
->drawmethod
);
9786 pmethod
= &(drawmethod
);
9788 memset(value
, 0, sizeof(s32
) * 12);
9789 for(i
= 1; i
< paramCount
&& i
< 13; i
++) {
9790 if(FAILED(ScriptVariant_IntegerValue(varlist
[i
], value
+ i
- 1)))
9791 goto setdrawmethod_error
;
9794 if(paramCount
>= 15 && varlist
[13]->vt
!= VT_PTR
&& varlist
[13]->vt
!= VT_EMPTY
)
9795 goto setdrawmethod_error
;
9797 pmethod
->flag
= (int) value
[0];
9798 pmethod
->scalex
= (int) value
[1];
9799 pmethod
->scaley
= (int) value
[2];
9800 pmethod
->flipx
= (int) value
[3];
9801 pmethod
->flipy
= (int) value
[4];
9802 pmethod
->shiftx
= (int) value
[5];
9803 pmethod
->alpha
= (int) value
[6];
9804 pmethod
->remap
= (int) value
[7];
9805 pmethod
->fillcolor
= (int) value
[8];
9806 pmethod
->rotate
= ((int) value
[9]) % 360;
9807 pmethod
->fliprotate
= (int) value
[10];
9808 pmethod
->transbg
= (int) value
[11];
9809 if(paramCount
>= 14)
9810 pmethod
->table
= (unsigned char *) varlist
[13]->ptrVal
;
9812 if(pmethod
->rotate
) {
9813 if(pmethod
->rotate
< 0)
9814 pmethod
->rotate
+= 360;
9818 setdrawmethod_error
:
9820 ("Function need a valid entity handle and at least 1 interger parameter, all other parameters should be integers: setdrawmethod(entity, int flag, int scalex, int scaley, int flipx, int flipy, int shiftx, int alpha, int remap, int fillcolor, int rotate, int fliprotate, int transparencybg, void* colourmap)\n");
9824 //updateframe(entity, int frame);
9825 s32
openbor_updateframe(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
9828 void update_frame(entity
* ent
, int f
);
9832 goto updateframe_error
;
9834 if(varlist
[0]->vt
== VT_EMPTY
)
9836 else if(varlist
[0]->vt
== VT_PTR
)
9837 e
= (entity
*) varlist
[0]->ptrVal
;
9839 goto updateframe_error
;
9842 goto updateframe_error
;
9844 if(FAILED(ScriptVariant_IntegerValue(varlist
[1], &f
)))
9845 goto updateframe_error
;
9847 update_frame(e
, (int) f
);
9852 printf("Function need a valid entity handle and at an interger parameter: updateframe(entity, int frame)\n");
9856 //performattack(entity, int anim, int resetable);
9857 s32
openbor_performattack(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
9858 s32 anim
, resetable
= 0;
9863 goto performattack_error
;
9865 if(varlist
[0]->vt
== VT_EMPTY
)
9867 else if(varlist
[0]->vt
== VT_PTR
)
9868 e
= (entity
*) varlist
[0]->ptrVal
;
9870 goto performattack_error
;
9873 goto performattack_error
;
9875 e
->takeaction
= common_attack_proc
;
9886 if(paramCount
> 1 && FAILED(ScriptVariant_IntegerValue(varlist
[1], &anim
)))
9887 goto performattack_error
;
9888 if(paramCount
> 2 && FAILED(ScriptVariant_IntegerValue(varlist
[2], &resetable
)))
9889 goto performattack_error
;
9890 ent_set_anim(e
, (int) anim
, (int) resetable
);
9894 performattack_error
:
9896 ("Function need a valid entity handle, the other 2 integer parameters are optional: performattack(entity, int anim, int resetable)\n");
9900 //setidle(entity, int anim, int resetable, int stalladd);
9901 s32
openbor_setidle(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
9902 s32 anim
, resetable
= 0, stalladd
;
9909 if(varlist
[0]->vt
== VT_EMPTY
)
9911 else if(varlist
[0]->vt
== VT_PTR
)
9912 e
= (entity
*) varlist
[0]->ptrVal
;
9919 e
->takeaction
= NULL
;
9931 if(paramCount
> 1 && FAILED(ScriptVariant_IntegerValue(varlist
[1], &anim
)))
9933 if(paramCount
> 2 && FAILED(ScriptVariant_IntegerValue(varlist
[2], &resetable
)))
9935 if(paramCount
> 3 && FAILED(ScriptVariant_IntegerValue(varlist
[3], &stalladd
)))
9937 ent_set_anim(e
, (int) anim
, (int) resetable
);
9940 e
->stalltime
= borTime
+ stalladd
;
9946 ("Function need a valid entity handle, the other 2 integer parameters are optional: setidle(entity, int anim, int resetable, int stalladd)\n");
9950 //getentity(int index_from_list)
9951 s32
openbor_getentity(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
9953 extern entity
*ent_list
[MAX_ENTS
];
9956 goto getentity_error
;
9958 if(FAILED(ScriptVariant_IntegerValue(varlist
[0], &ind
)))
9959 goto getentity_error
;
9961 ScriptVariant_Clear(*pretvar
);
9963 if((int) ind
< MAX_ENTS
&& (int) ind
>= 0) {
9964 ScriptVariant_ChangeType(*pretvar
, VT_PTR
);
9965 (*pretvar
)->ptrVal
= (void*) ent_list
[(int) ind
];
9967 //else, it should return an empty value
9971 printf("Function need an integer parameter: getentity(int index_in_list)\n");
9978 s32
openbor_loadmodel(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
9981 goto loadmodel_error
;
9982 if(varlist
[0]->vt
!= VT_STR
)
9983 goto loadmodel_error
;
9985 ScriptVariant_ChangeType(*pretvar
, VT_PTR
);
9987 if(FAILED(ScriptVariant_IntegerValue(varlist
[1], &unload
)))
9988 goto loadmodel_error
;
9990 (*pretvar
)->ptrVal
=
9991 (void*) load_cached_model(StrCache_Get(varlist
[0]->strVal
), "openbor_loadmodel", (char) unload
);
9992 //else, it should return an empty value
9996 printf("Function needs a string and boolean parameters: loadmodel(name, unload)\n");
9997 ScriptVariant_Clear(*pretvar
);
10002 // load a sprite which doesn't belong to the sprite_cache
10003 // loadsprite(path)
10004 s32
openbor_loadsprite(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
10005 extern s_sprite
*loadsprite2(char *filename
, int *width
, int *height
);
10006 if(paramCount
!= 1)
10007 goto loadsprite_error
;
10009 if(varlist
[0]->vt
!= VT_STR
)
10010 goto loadsprite_error
;
10012 ScriptVariant_ChangeType(*pretvar
, VT_PTR
);
10013 if(((*pretvar
)->ptrVal
= (void*) loadsprite2(StrCache_Get(varlist
[0]->strVal
), NULL
, NULL
))) {
10014 List_InsertAfter(&scriptheap
, (void *) ((*pretvar
)->ptrVal
), "openbor_loadsprite");
10016 //else, it should return an empty value
10020 printf("Function need a string parameter: loadsprite(path)\n");
10021 ScriptVariant_Clear(*pretvar
);
10026 //playgif(path, int x, int y, int noskip)
10027 s32
openbor_playgif(ScriptVariant
** varlist
, ScriptVariant
** pretvar
, int paramCount
) {
10028 s32 temp
[3] = { 0, 0, 0 }; //x,y,noskip
10030 extern unsigned char pal
[1024];
10031 extern int playgif(char *filename
, int x
, int y
, int noskip
);
10033 goto playgif_error
;
10035 if(varlist
[0]->vt
!= VT_STR
)
10036 goto playgif_error
;
10038 ScriptVariant_ChangeType(*pretvar
, VT_INTEGER
);
10039 for(i
= 0; i
< 3 && i
< paramCount
- 1; i
++) {
10040 if(FAILED(ScriptVariant_IntegerValue(varlist
[i
+ 1], temp
+ i
)))
10041 goto playgif_error
;
10044 (s32
) playgif(StrCache_Get(varlist
[0]->strVal
), (int) (temp
[0]), (int) (temp
[1]), (int) (temp
[2]));
10045 palette_set_corrected(pal
, savedata
.gamma
, savedata
.gamma
, savedata
.gamma
, savedata
.brightness
,
10046 savedata
.brightness
, savedata
.brightness
);
10051 ("Function need a string parameter, other parameters are optional: playgif(path, int x, int y, int noskip)\n");