| 1 |
/** |
| 2 |
* DinkC script engine |
| 3 |
|
| 4 |
* Copyright (C) 2008, 2009 Sylvain Beucler |
| 5 |
|
| 6 |
* This file is part of GNU FreeDink |
| 7 |
|
| 8 |
* GNU FreeDink is free software; you can redistribute it and/or |
| 9 |
* modify it under the terms of the GNU General Public License as |
| 10 |
* published by the Free Software Foundation; either version 3 of the |
| 11 |
* License, or (at your option) any later version. |
| 12 |
|
| 13 |
* GNU FreeDink is distributed in the hope that it will be useful, but |
| 14 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 |
* General Public License for more details. |
| 17 |
|
| 18 |
* You should have received a copy of the GNU General Public License |
| 19 |
* along with this program. If not, see |
| 20 |
* <http://www.gnu.org/licenses/>. |
| 21 |
*/ |
| 22 |
|
| 23 |
#ifndef _DINKC_H |
| 24 |
#define _DINKC_H |
| 25 |
|
| 26 |
#include <stdio.h> |
| 27 |
#include "io_util.h" |
| 28 |
|
| 29 |
/* Gnulib */ |
| 30 |
extern "C" { |
| 31 |
#include "hash.h" |
| 32 |
} |
| 33 |
|
| 34 |
#define MAX_SCRIPTS 200 |
| 35 |
#define MAX_VARS 250 |
| 36 |
|
| 37 |
/* Part of the savegame data dump, beware of size change! */ |
| 38 |
struct varman |
| 39 |
{ |
| 40 |
int var; |
| 41 |
char name[19+1]; |
| 42 |
int scope; /* script number holding the local variable */ |
| 43 |
BOOL_1BYTE active; |
| 44 |
}; |
| 45 |
/* Named index for varman.scope */ |
| 46 |
#define DINKC_GLOBAL_SCOPE 0 |
| 47 |
|
| 48 |
// global functions (v1.08) |
| 49 |
struct global_function |
| 50 |
{ |
| 51 |
char file[9+1]; |
| 52 |
char func[19+1]; |
| 53 |
}; |
| 54 |
|
| 55 |
struct refinfo |
| 56 |
{ |
| 57 |
char* name; |
| 58 |
long location; |
| 59 |
long current; // current offset |
| 60 |
int cur_line; // current line |
| 61 |
int cur_col; // current column (position within ligne) |
| 62 |
int debug_line; // last parsed line (whereas cur_line == next-to-be-read) |
| 63 |
int level; // nested level |
| 64 |
long end; // size of the text, == strlen(rbuf[i]) |
| 65 |
int sprite; //if more than 0, it was spawned and is owned by a sprite, if 1000 doesn't die |
| 66 |
/*bool*/int skipnext; |
| 67 |
int onlevel; |
| 68 |
int proc_return; |
| 69 |
/* v1.08 arguments for user-defined functions */ |
| 70 |
int arg1; |
| 71 |
int arg2; |
| 72 |
int arg3; |
| 73 |
int arg4; |
| 74 |
int arg5; |
| 75 |
int arg6; |
| 76 |
int arg7; |
| 77 |
int arg8; |
| 78 |
int arg9; |
| 79 |
}; |
| 80 |
extern struct refinfo *rinfo[]; |
| 81 |
|
| 82 |
enum dinkc_parser_state { |
| 83 |
DCPS_GOTO_NEXTLINE = 0, |
| 84 |
DCPS_CONTINUE = 1, |
| 85 |
DCPS_YIELD = 2, |
| 86 |
DCPS_DOELSE_ONCE = 4, |
| 87 |
}; |
| 88 |
|
| 89 |
|
| 90 |
/* Map DinkC function with C function */ |
| 91 |
struct binding |
| 92 |
{ |
| 93 |
char* funcname; /* name of the function, as string */ |
| 94 |
void* func; /* pointer to the C function */ |
| 95 |
int params[10]; /* DinkC specification of params e.g. {2,1,1,0,0,0,0,0,0,0} */ |
| 96 |
enum dinkc_parser_state badparams_dcps; /* if the DinkC script has bad arguments, skip line or yield? */ |
| 97 |
int badparams_returnint_p; /* overwrite returnint if bad arguments? */ |
| 98 |
int badparams_returnint; /* value for returnint if badparams_returnint_p is 1 */ |
| 99 |
}; |
| 100 |
|
| 101 |
extern Hash_table* bindings; |
| 102 |
|
| 103 |
|
| 104 |
extern char* cur_funcname; |
| 105 |
|
| 106 |
extern int weapon_script; |
| 107 |
extern int magic_script; |
| 108 |
|
| 109 |
extern void dinkc_init(); |
| 110 |
extern void dinkc_quit(); |
| 111 |
extern int load_script(char* filename, int sprite); |
| 112 |
extern int dinkc_execute_one_liner(char* line); |
| 113 |
extern void strip_beginning_spaces(char *str); |
| 114 |
extern /*bool*/int locate(int script, char* proc_lookup); |
| 115 |
extern /*bool*/int locate_goto(char* expr, int script); |
| 116 |
extern long decipher(char* variable, int script); |
| 117 |
extern void decipher_string(char** line_p, int script); |
| 118 |
extern int add_callback(char name[20], int n1, int n2, int script); |
| 119 |
extern void kill_callback(int cb); |
| 120 |
extern void kill_callbacks_owned_by_script(int script); |
| 121 |
extern void kill_script(int k); |
| 122 |
extern void kill_scripts_with_inactive_sprites(); |
| 123 |
extern void kill_all_scripts_for_real(void); |
| 124 |
extern char* read_next_line(int script); |
| 125 |
extern void process_callbacks(Uint32 now); |
| 126 |
extern int lookup_var(char* variable, int scope); |
| 127 |
extern void make_int(char* name, int value, int scope, int script); |
| 128 |
extern void var_equals(char name[20], char newname[20], char math, int script, char rest[200]); |
| 129 |
extern int var_figure(char h[200], int script); |
| 130 |
extern void kill_scripts_owned_by(int sprite); |
| 131 |
extern void kill_returning_stuff(int script); |
| 132 |
extern void run_script(int script); |
| 133 |
extern void attach(void); |
| 134 |
extern void int_prepare(char line[100], int script); |
| 135 |
extern void make_function(char file[10], char func[20]); |
| 136 |
extern void kill_all_vars(); |
| 137 |
|
| 138 |
/* Used by draw_screen_game only */ |
| 139 |
extern void kill_all_scripts(void); |
| 140 |
|
| 141 |
extern void dinkc_bindings_add(Hash_table* hash, struct binding* pbd); |
| 142 |
extern struct binding* dinkc_bindings_lookup(Hash_table* hash, char* funcname); |
| 143 |
|
| 144 |
extern int returnint; |
| 145 |
extern int bKeepReturnInt; /* v1.08 */ |
| 146 |
extern char returnstring[]; |
| 147 |
extern unsigned short decipher_savegame; |
| 148 |
|
| 149 |
/* Test suite */ |
| 150 |
extern int ts_lookup_var_local_global(char* variable, int scope); |
| 151 |
extern int ts_script_init(const char* name, char* code); |
| 152 |
#endif |