00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00023
00024 #include "crogue.h"
00025
00037 typedef struct aux_function
00038 {
00040 void *func;
00041
00044 void (*helper_func) (void *func, long *params, return_info_t *ret);
00045 } aux_function;
00046
00047
00048 static sint tile_is_passable(sint x, sint y)
00049 {
00050
00051
00052 if(x<=0 || y<=0 || x>=MAPSIZE_X-1 || y>=MAPSIZE_Y-1)
00053 return 0;
00054 return TILEDESC(w->t[y][x]).passable;
00055 }
00056
00057
00058 static sint tile_is_transparent(sint x, sint y)
00059 {
00060
00061
00062 if(x<=0 || y<=0 || x>=MAPSIZE_X-1 || y>=MAPSIZE_Y-1)
00063 return 0;
00064 return TILEDESC(w->t[y][x]).transparent;
00065 }
00066
00067
00068 static sint tile_is_occupied(sint x, sint y)
00069 {
00070 return w->t[y][x].flags & TFLAG_OCCUPIED;
00071 }
00072
00073
00074 static void *get_plr(void)
00075 {
00076 return &w->plr;
00077 }
00078
00079
00080 static void *get_w(void)
00081 {
00082 return w;
00083 }
00084
00085
00086 static sint fstrcmp(char *one, char *two)
00087 {
00088 return strcmp(one, two);
00089 }
00090
00091
00092
00093 static void void_helper_void(void *func, long *params, return_info_t *ret)
00094 {
00095 ((void (*)(void))func)();
00096 }
00097
00098
00099 static void void_helper_pointer(void *func, long *params, return_info_t *ret)
00100 {
00101 ((void (*)(char *))func)((void*)params[0]);
00102 }
00103
00104
00105 static void void_helper_pointer_pointer(void *func, long *params, return_info_t *ret)
00106 {
00107 ((void (*)(char *, char*))func)((void*)params[0], (void*)params[1]);
00108 }
00109
00110
00111 static void pointer_helper_short(void *func, long *params, return_info_t *ret)
00112 {
00113 ret->returns = 1;
00114 ret->retval = (long)(( long*(*)(ushort) )func)(params[0]);
00115 }
00116
00117
00118 static void int_helper_short(void *func, long *params, return_info_t *ret)
00119 {
00120 ret->returns = 1;
00121 ret->retval = ((sint (*)(ushort))func)(params[0]);
00122 }
00123
00124
00125 static void int_helper_short_short(void *func, long *params, return_info_t *ret)
00126 {
00127 ret->returns = 1;
00128 ret->retval = ((sint (*)(ushort,ushort))func)(params[0], params[1]);
00129 }
00130
00131
00132 static void int_helper_short_short_short(void *func, long *params, return_info_t *ret)
00133 {
00134 ret->returns = 1;
00135 ret->retval = ((sint (*)(ushort,ushort,ushort))func)(params[0], params[1], params[2]);
00136 }
00137
00138
00139 static void void_helper_short(void *func, long *params, return_info_t *ret)
00140 {
00141 ((void (*)(ushort))func)(params[0]);
00142 }
00143
00144
00145 static void void_helper_short_short(void *func, long *params, return_info_t *ret)
00146 {
00147 ((void (*)(ushort,ushort))func)(params[0], params[1]);
00148 }
00149
00150
00151 static void void_helper_short_short_short(void *func, long *params, return_info_t *ret)
00152 {
00153 ((void (*)(ushort,ushort,ushort))func)(params[0], params[1], params[2]);
00154 }
00155
00156
00157 static void int_helper_pointer(void *func, long *params, return_info_t *ret)
00158 {
00159 ret->returns = 1;
00160 ret->retval = ((ushort (*)(char *))func)((void*)params[0]);
00161 }
00162
00163
00164 static void int_helper_pointer_pointer(void *func, long *params, return_info_t *ret)
00165 {
00166 ret->returns = 1;
00167 ret->retval = ((ushort (*)(char*, char*))func)((void*)params[0], (void*)params[1]);
00168 }
00169
00170
00171 static void int_helper_pointer_short(void *func, long *params, return_info_t *ret)
00172 {
00173 ret->returns = 1;
00174 ret->retval = ((ushort (*)(char *,ushort))func)((void*)params[0], (ushort)params[1]);
00175 }
00176
00177
00178 static void int_helper_void(void *func, long *params, return_info_t *ret)
00179 {
00180 ret->returns = 1;
00181 ret->retval = ((ushort (*)(void))func)();
00182 }
00183
00184
00185 static void int_helper_short_short_pointer_pointer_short(void *func, long *params, return_info_t *ret)
00186 {
00187 ret->returns = 1;
00188 ret->retval =
00189 ((ushort (*)(ushort,ushort,char*,char*,ushort))func)(params[0], params[1], (void*)params[2], (void*)params[3], params[4]);
00190 }
00191
00192
00193 static void void_helper_pointer_vararg(void *func, long *params, return_info_t *ret)
00194 {
00195 ((void (*)(char *, va_list))func)((void*)params[0], (va_list)(params+1));
00196 }
00197
00198
00199 static void pointer_helper_pointer_vararg(void *func, long *params, return_info_t *ret)
00200 {
00201 ret->returns = 1;
00202 ret->retval = (long)((char* (*)(char *, va_list))func)
00203 ((void*)params[0], (va_list)(params+1));
00204 }
00205
00206
00207 static void int_helper_short_short_vararg(void *func, long *params, return_info_t *ret)
00208 {
00209 ret->returns = 1;
00210 ret->retval = (long)((sint (*)(ushort, ushort, va_list))func)((int)params[0], (int)params[1], (va_list)(params+2));
00211 }
00212
00213
00214 static void pointer_helper_void(void *func, long *params, return_info_t *ret)
00215 {
00216 ret->returns = 1;
00217 ret->retval = (long)((void* (*)(void))func)();
00218 }
00219
00220
00221 static void pointer_helper_long(void *func, long *params, return_info_t *ret)
00222 {
00223 ret->returns = 1;
00224 ret->retval = (long)((void* (*)(long))func)(params[0]);
00225 }
00226
00227
00228 static void pointer_helper_pointer(void *func, long *params, return_info_t *ret)
00229 {
00230 ret->returns = 1;
00231 ret->retval = (long)((void* (*)(char*))func)((char*)params[0]);
00232 }
00233
00234
00235 static void void_helper_short_pointer(void *func, long *params, return_info_t *ret)
00236 {
00237 ((void (*)(ushort, char*))func)(params[0], (void*)params[1]);
00238 }
00239
00240
00241 static void long_helper_void(void *func, long *params, return_info_t *ret)
00242 {
00243 ret->returns = 1;
00244 ret->retval = ((ulong (*)(void))func)();
00245 }
00246
00247
00248 static void void_helper_long(void *func, long *params, return_info_t *ret)
00249 {
00250 ((void (*)(ulong))func)(params[0]);
00251 }
00252
00253
00254 static void void_helper_pointer_short_short(void *func, long *params, return_info_t *ret)
00255 {
00256 ((void (*)(char *, ushort, ushort))func)((void*)params[0], params[1], params[2]);
00257 }
00258
00259
00260
00261
00262
00263 static aux_function aux_functions[] =
00264 {
00265 { vmessage, void_helper_pointer_vararg },
00266 { nrandom, int_helper_short_short },
00267 { plr_mod_stat, void_helper_short_short },
00268 { base_coat, void_helper_void },
00269 { place_room, int_helper_pointer },
00270 { place_hole, void_helper_void },
00271 { place_corridors, int_helper_void },
00272 { place_doors, void_helper_void },
00273 { fill_room, void_helper_pointer },
00274 { UI_Dialog_Default, void_helper_pointer },
00275 { make_connections, void_helper_void },
00276 { place_items, void_helper_void },
00277 { make_noise, void_helper_short_short },
00278 { cave_generation, void_helper_short_short },
00279 { prompt, int_helper_pointer },
00280 { prompt_dir, void_helper_pointer_pointer },
00281 { illuminate, void_helper_short_short_short },
00282 { calc_light, void_helper_void },
00283 { attack_tile, int_helper_short_short_pointer_pointer_short },
00284 { delay, void_helper_void },
00285 { UI_TF_DrawEffect, void_helper_short_short_short },
00286 { UI_TF_ClearEffects, void_helper_void },
00287 { monstbytile, int_helper_short_short },
00288 { tile_is_passable, int_helper_short_short },
00289 { tile_is_transparent,int_helper_short_short },
00290 { tile_is_occupied, int_helper_short_short },
00291 { get_plr, pointer_helper_void },
00292 { plr_restore_stat, int_helper_short_short },
00293 { get_w, pointer_helper_void },
00294 { plr_takedamage, void_helper_short_pointer },
00295 { player_gold, long_helper_void },
00296 { debit_gold, void_helper_long },
00297 { deref_file_ptr, pointer_helper_long },
00298 { place_item, void_helper_pointer_short_short },
00299 { scare_monster, void_helper_short },
00300 { update_player, void_helper_void },
00301 { identify, int_helper_void },
00302 { UI_Menu_Set_Persist, void_helper_short },
00303 { draw_tile, void_helper_short_short },
00304 { entangle, void_helper_short },
00305 { UI_MF_wait, void_helper_void },
00306 { study_book, int_helper_short_short_vararg },
00307 { plr_moveto, void_helper_short_short_short },
00308 { give_item, int_helper_pointer_short},
00309 { confuse, void_helper_short },
00310 { hallucinate, void_helper_short },
00311 { timepass, void_helper_short },
00312 { identify_type, void_helper_short },
00313 { addmonster_ptr, void_helper_pointer_short_short },
00314 { end_game, void_helper_pointer },
00315 { die, void_helper_pointer },
00316 { fix_rust, int_helper_void },
00317 { monstname, pointer_helper_short },
00318 { fstrcmp, int_helper_pointer_pointer },
00319 { monst_heal, void_helper_short_short },
00320 { numb, void_helper_short },
00321 { detect_invisible, void_helper_short },
00322 { place_player_randomly, void_helper_void },
00323 { removecurses, void_helper_void },
00324 { enchant_item, int_helper_void },
00325 { n_itemname, pointer_helper_long },
00326 { monstmoveto, void_helper_short_short_short },
00327 { webspinner_build, void_helper_short_short_short },
00328 { webspinner_cower, void_helper_short_short_short },
00329 { monst_battle_pet, int_helper_short },
00330 { monst_detect_player, int_helper_short },
00331 { monst_can_attack_player, int_helper_short },
00332 { monstmovetowardsplayer, void_helper_short },
00333 { monst_chat, void_helper_short },
00334 { vretprintf, pointer_helper_pointer_vararg },
00335 { indefinite_article, pointer_helper_pointer },
00336 { paralyze, void_helper_short },
00337 { rust_inventory, void_helper_short },
00338 { monst_remove, void_helper_short },
00339 { monst_facing, int_helper_short },
00340 { player_can_see, int_helper_short },
00341 { monst_takedamage, void_helper_short_short_short },
00342 { monstcanmove, int_helper_short_short_short },
00343 { engulf_in_darkness, void_helper_short },
00344 { top_item, int_helper_short_short },
00345 { mkmap_big_front, int_helper_void },
00346 { cave_partial_gen, void_helper_short_short }
00347 };
00348
00349 return_info_t interpret_call(int which_func, long *params)
00350 {
00351 return_info_t ret;
00352 ret.returns = 0;
00353
00354 aux_functions[which_func].helper_func( aux_functions[which_func].func, params, &ret );
00355
00356 return ret;
00357 }
00358