| 1 | /* agility.h-- Header for all AGiliTy files. */ |
| 2 | /* Copyright (C) 1996-99,2001 Robert Masenten */ |
| 3 | /* |
| 4 | This program is free software; you can redistribute it and/or modify |
| 5 | it under the terms of version 2 of the GNU General Public License |
| 6 | as published by the Free Software Foundation. |
| 7 | |
| 8 | This program is distributed in the hope that it will be useful, |
| 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | GNU General Public License for more details. |
| 12 | |
| 13 | You should have received a copy of the GNU General Public License |
| 14 | along with this program; if not, write to the Free Software |
| 15 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
| 16 | USA |
| 17 | */ |
| 18 | /* */ |
| 19 | /* This is part of the source for both AGiliTy: the (Mostly) Universal */ |
| 20 | /* AGT Interpreter and for the Magx adventure game compiler. */ |
| 21 | |
| 22 | /* This indicates the AGiliTy version code for the current version. */ |
| 23 | /* 0=0.8.7 and the numbers are assigned sequentially from there. |
| 24 | 1=0.8.8 |
| 25 | 2=1.0 |
| 26 | (pre-0.8.7 versions of AGiliTy don't have version codes) */ |
| 27 | /* Don't touch this unless you know exactly what you're doing. */ |
| 28 | #define AGIL_VERID 3 |
| 29 | |
| 30 | /* |
| 31 | This is the master header file for all of the AGT stuff. |
| 32 | It includes the global variables, the data types, etc. |
| 33 | (everything that is read in from the game file). |
| 34 | Variables not read in from the game file but used internally |
| 35 | by the AGiliTy interpreter are declared in interp.h. |
| 36 | Magx specific things are in comp.h. |
| 37 | */ |
| 38 | |
| 39 | /* Headers used by by all of the modules or by this header file */ |
| 40 | #include <stdlib.h> |
| 41 | #include <stdio.h> |
| 42 | #include <string.h> |
| 43 | |
| 44 | /* For strcasecmp() and strncasecemp(). */ |
| 45 | #include <strings.h> |
| 46 | |
| 47 | /* Platform-specific configuration info */ |
| 48 | #include "config.h" |
| 49 | |
| 50 | /* ------------------------------------------------------------------- */ |
| 51 | /* This is a preprocessor trick to ensure that space is only allocated |
| 52 | for global variables once. 'global' should only be defined in one |
| 53 | source file; for all of the other modules, it will be converted to |
| 54 | extern by the following lines */ |
| 55 | /* ------------------------------------------------------------------- */ |
| 56 | #ifndef global /* Don't touch this */ |
| 57 | #define global extern |
| 58 | #define global_defined_agtread |
| 59 | #endif |
| 60 | |
| 61 | |
| 62 | /* ------------------------------------------------------------------- */ |
| 63 | /* DEFINITIONS OF SPECIAL DATA TYPES */ |
| 64 | /* These should by platform-independent. */ |
| 65 | /* ------------------------------------------------------------------- */ |
| 66 | |
| 67 | #ifdef force16 /* This is for debugging purposes */ |
| 68 | #define int short int |
| 69 | #endif |
| 70 | |
| 71 | /* General data types */ |
| 72 | typedef unsigned char uchar; |
| 73 | typedef signed char schar; |
| 74 | typedef short integer; /* Should be a 16+-bit signed numeric type */ |
| 75 | /* For technical reasons, it must be big enough to |
| 76 | hold a value of type word (see below) */ |
| 77 | typedef unsigned long int32; /* Should be a 32+-bit unsigned numeric type */ |
| 78 | typedef unsigned long uint32; |
| 79 | typedef uchar rbool; |
| 80 | |
| 81 | #define WORD_LENG 25 |
| 82 | |
| 83 | /* Game-specific data type */ |
| 84 | typedef char tline[81]; /* Both of these must include terminating null */ |
| 85 | typedef char words[WORD_LENG]; /* ...23 in classic, 16 in master's */ |
| 86 | typedef short word; /* A pointer into the dictionary */ |
| 87 | typedef short slist; /* Index into synlist marking beginning of this |
| 88 | synonym list. [SYNCNT] |
| 89 | list of word pointers -- eg synonyms */ |
| 90 | typedef char *descr_line; /* This is the type used to return descriptions. |
| 91 | They are actually returned as an array of |
| 92 | pointers to char, one for each line. |
| 93 | It is NULL terminated. */ |
| 94 | typedef char *filename; /* Datatype used for picture, sound, etc. names*/ |
| 95 | |
| 96 | |
| 97 | typedef enum {fNONE, |
| 98 | fDA1,fDA2,fDA3,fDA4,fDA5,fDA6,fDSS, |
| 99 | fHNT,fOPT,fTTL, |
| 100 | fSAV,fSCR,fLOG, |
| 101 | fAGX,fINS,fVOC,fCFG, |
| 102 | fAGT,fDAT,fMSG,fCMD,fSTD,fAGT_STD} filetype; |
| 103 | |
| 104 | |
| 105 | /* ------------------------------------------------------------------- */ |
| 106 | /* GLOBAL FLAGS */ |
| 107 | /* Many of the following should be made into command line options */ |
| 108 | /* ------------------------------------------------------------------- */ |
| 109 | |
| 110 | /* #define AGT_16BIT */ /* Force interpreter to use 16-bit quantities */ |
| 111 | /* #define DUMP_VLIST */ /* Dump out the verb list info */ |
| 112 | /* #define USE_CMD_INDEX */ /* Read in metacommand index data for objects */ |
| 113 | |
| 114 | |
| 115 | #define SS_GRAIN 1024 /* Granularity of size request for static string |
| 116 | array (to avoid calling rrealloc too often) */ |
| 117 | #define SYN_GRAIN 32 /* Granularity of requests for synonym array; this |
| 118 | is in units of sizeof(word) */ |
| 119 | #define MAX_BADTOK 10 /* How many bad tokens to report before giving |
| 120 | up */ |
| 121 | |
| 122 | |
| 123 | |
| 124 | /* The following are defaults that can be overridden from the command line */ |
| 125 | /* The real variable has the name without the "def_" */ |
| 126 | |
| 127 | #define def_DIAG 0 /* Print out diagnostic data? */ |
| 128 | #define def_interp_arg 1 /* Decipher arguments to opcodes? */ |
| 129 | #define def_debug_da1 0 /* used to analyse .DA1 files */ |
| 130 | #define def_RAW_CMD_OUT 0 /*Print CMDs out raw, undecoded; sometimes useful |
| 131 | when trying to understand new gamefile version */ |
| 132 | #define def_ERR_LEVEL 2 /* Level of error reporting. */ |
| 133 | /* 0== almost none */ |
| 134 | /* 1== Report possibly serious conditions */ |
| 135 | /* 2== Report any fall from perfection */ |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | /* ------------------------------------------------------------------- */ |
| 144 | /* DEFINES OF GLOBAL PARAMETERS */ |
| 145 | /* ------------------------------------------------------------------- */ |
| 146 | |
| 147 | #define FORMAT_CODE 0xFF /* Character used for special formatting codes: |
| 148 | --in 1.8x games, it designates bold |
| 149 | --in AGX+ games, it will prefix format codes |
| 150 | --otherwise it designates black (replacing |
| 151 | 0, which has obvious problems) */ |
| 152 | #define LAST_TEXTCODE 8 /* Last ascii code to be used for text attributes */ |
| 153 | |
| 154 | |
| 155 | |
| 156 | #define MAX_PIX 31 |
| 157 | #define MAX_FLAG_NOUN 31 |
| 158 | |
| 159 | |
| 160 | |
| 161 | #define OLD_VERB 59 /* Number of built in verbs in original interpreters-- |
| 162 | this number includes ANY, which is verb 0. */ |
| 163 | #define DIR_ADDR_CODE (OLD_VERB+17) /* Verb ID used for direct address */ |
| 164 | #define AUX_VERB 18 /* Additional verbs supported by the interpreter */ |
| 165 | #define BASE_VERB (OLD_VERB+AUX_VERB) /* Total number of built-in verbs */ |
| 166 | #define DUMB_VERB (DVERB+MAX_SUB) /* Number of dummy verbs and subroutines */ |
| 167 | #define TOTAL_VERB (BASE_VERB+DUMB_VERB) /* Total count of verbs */ |
| 168 | |
| 169 | |
| 170 | /* The following numbers refer to the ideal code we are translating into, |
| 171 | not the parameters for the actual data file we're reading. */ |
| 172 | #define MAX_COND 143 /* Last condition token id */ |
| 173 | #define START_ACT 1000 /* First action code */ |
| 174 | #define PREWIN_ACT 1161 /* Last action code before WinGame */ |
| 175 | #define WIN_ACT 2000 /* Value of WinGame opcode */ |
| 176 | #define END_ACT (WIN_ACT+2) /* Lowest command-terminating action code */ |
| 177 | #define MAX_ACT (WIN_ACT+4) /* Highest action code */ |
| 178 | |
| 179 | /* Note: the following values are used by Magx internally: |
| 180 | 3000-- Used to mark 'no entry' in the opcode hash table. |
| 181 | 8000-- Used for NEXT |
| 182 | 8001-- Used for PREV |
| 183 | */ |
| 184 | |
| 185 | #define MAX_TOKEN_ID 250 /* Upper limit on legal (raw) token values |
| 186 | read from AGT files. Doesn't need to be exact. */ |
| 187 | |
| 188 | /* Number of built in properties and attributes. */ |
| 189 | #define NUM_PROP 14 |
| 190 | #define NUM_ATTR 26 |
| 191 | |
| 192 | |
| 193 | /* |
| 194 | None of these are used any more, but I leave them here for reference |
| 195 | #define MAX_ROOM 300 |
| 196 | #define MAX_NOUN 300 |
| 197 | #define MAX_CREAT 200 |
| 198 | #define MAX_CMD 1500 |
| 199 | #define MAX_QUEST 100 |
| 200 | #define MAX_MSG 1000 |
| 201 | #define MAX_PICT 250 |
| 202 | #define ABS_MAX_REC_CMD 34 |
| 203 | #define MAX_OBJ (MAX_ROOM+MAX_NOUN+MAX_CREAT) |
| 204 | #define SYNCNT 15 |
| 205 | */ |
| 206 | |
| 207 | |
| 208 | |
| 209 | /* --------------------------------------------------------------------- */ |
| 210 | /* DATA STRUCTURE DEFINITIONS */ |
| 211 | /* */ |
| 212 | /* All of the internal data structures used to store the contents of the */ |
| 213 | /* game file */ |
| 214 | /* --------------------------------------------------------------------- */ |
| 215 | |
| 216 | /* First, pointers to game descriptions */ |
| 217 | /* start and size may be measured in units of characters or in units */ |
| 218 | /* of tline */ |
| 219 | typedef struct { |
| 220 | long start; |
| 221 | long size; |
| 222 | } descr_ptr; |
| 223 | |
| 224 | |
| 225 | /* Entries in the opcode tables: the name of the opcode, the number of |
| 226 | arguments, and the types of those arguments */ |
| 227 | typedef struct { |
| 228 | char *opcode; |
| 229 | integer argnum; |
| 230 | integer arg1,arg2; |
| 231 | } opdef; /* Opcode table entry */ |
| 232 | |
| 233 | |
| 234 | |
| 235 | /* This is the data type for opcode correction entries */ |
| 236 | /* These are used to translate the opcodes from the various versions */ |
| 237 | /* to a uniform internal format. */ |
| 238 | /* The actual translation tables built with this are in agtdata.c */ |
| 239 | typedef struct { |
| 240 | integer told,tnew; /* Old and new values. */ |
| 241 | } cmd_fix_rec; |
| 242 | |
| 243 | typedef const cmd_fix_rec *fix_array; |
| 244 | |
| 245 | |
| 246 | /* ROOMS */ |
| 247 | typedef struct { |
| 248 | const char *name; /* [31] */ |
| 249 | int32 flag_noun_bits,PIX_bits; /* Master's Ed. only */ |
| 250 | slist replacing_word; /* List of words to be replaced */ |
| 251 | word replace_word; /* Word that does replacing */ |
| 252 | word autoverb; /* Verb automatically executed on entry to room */ |
| 253 | integer path[13]; |
| 254 | integer key; |
| 255 | integer contents; /* Used internally by the interpreter; not read in |
| 256 | from the game file */ |
| 257 | integer points; |
| 258 | integer light; /* Object that lights room; 0=none needed, 1=any */ |
| 259 | integer pict,initdesc; |
| 260 | integer oclass; |
| 261 | rbool seen, locked_door; |
| 262 | rbool end, win, killplayer; |
| 263 | rbool unused; /* True if this room entry is unused */ |
| 264 | } room_rec; |
| 265 | |
| 266 | |
| 267 | /* NOUNS */ |
| 268 | typedef struct { |
| 269 | const char *shortdesc; /* tline */ |
| 270 | const char *position; |
| 271 | /* 23 characters in position for classic ed, 31 for ME */ |
| 272 | const char *initpos; /*Starting value of position;used for RESTART/RESTORE*/ |
| 273 | int scratch; /* Scratch space for use by various parser routines. */ |
| 274 | slist syns; /* List of synonyms */ |
| 275 | word name, adj; |
| 276 | word related_name; /* Word that should appear on menu when this noun |
| 277 | is in scope */ |
| 278 | word pos_prep, pos_name; /* Used internally by the interpreter */ |
| 279 | /* pos_prep==-1 means use noun.position */ |
| 280 | integer nearby_noun; /* Noun this noun is behind */ |
| 281 | integer num_shots; |
| 282 | integer points; |
| 283 | integer weight, size; |
| 284 | integer key; |
| 285 | integer initdesc,pict; |
| 286 | integer location; /* 1=carried, 1000=worn */ |
| 287 | integer contents, next; /* Used internally by the interpreter; not read in |
| 288 | from the game file */ |
| 289 | integer oclass; |
| 290 | integer flagnum; /* Number of associated flag + 1. 0=no flag. */ |
| 291 | rbool scope; /* Used internally by the interpreter */ |
| 292 | rbool isglobal; /* True if global object */ |
| 293 | uchar plural; |
| 294 | rbool something_pos_near_noun; /* Anybody behind us? */ |
| 295 | rbool has_syns; |
| 296 | rbool pushable, pullable, turnable, playable, readable; |
| 297 | rbool on, closable, open, lockable, locked, edible, wearable; |
| 298 | rbool drinkable, poisonous, movable, light; |
| 299 | rbool shootable; |
| 300 | rbool win; |
| 301 | rbool unused; /* True if this noun entry is unused */ |
| 302 | rbool seen; /* True if this noun has been seen by the player */ |
| 303 | rbool proper; /* True if noun's name is to be treated as proper noun. */ |
| 304 | } noun_rec; |
| 305 | |
| 306 | |
| 307 | /* CREATURES */ |
| 308 | typedef struct { |
| 309 | const char *shortdesc; /* tline */ |
| 310 | int scratch; /* Scratch space for use by various parser routines. */ |
| 311 | slist syns; |
| 312 | word name; |
| 313 | word adj; |
| 314 | integer location; |
| 315 | integer contents, next; /* Used internally by the interpreter; not read in |
| 316 | from the game file */ |
| 317 | integer weapon; /* Killed by this */ |
| 318 | integer points; |
| 319 | integer counter; /* How many times has player been nasty to it? */ |
| 320 | integer threshold, timethresh, timecounter; |
| 321 | integer pict,initdesc; |
| 322 | integer oclass; |
| 323 | integer flagnum; /* Number of associated flag + 1. 0=no flag. */ |
| 324 | rbool scope; /* Used internally by the interpreter */ |
| 325 | rbool isglobal; /* True if global object */ |
| 326 | rbool has_syns; |
| 327 | rbool groupmemb; |
| 328 | rbool hostile; |
| 329 | uchar gender; |
| 330 | rbool unused; /* True if this creature entry is unused */ |
| 331 | rbool seen; /* True if this creature has been seen by the player */ |
| 332 | rbool proper; /* True if this creature's name is to be treated as a proper |
| 333 | noun (i.e. not prepended with "the") */ |
| 334 | } creat_rec; |
| 335 | |
| 336 | /* These records are used to hold reference information for |
| 337 | user-defined flags and properties */ |
| 338 | /* These give the base index offset in objflag/objprop of each flag/prop |
| 339 | for rooms, nouns, and creatures. The flag record also contains the |
| 340 | bit offset in the given byte. */ |
| 341 | /* This approach allows for a single property to be located in different |
| 342 | places for each of the three types of objects. */ |
| 343 | /* A value of -1 for any of the three fields indicates that this |
| 344 | property doesn't exist for the given type of object. */ |
| 345 | |
| 346 | typedef struct { |
| 347 | long r,n,c; |
| 348 | long str_cnt; /* values from 0..(str_cnt-1) have assoc strings */ |
| 349 | long str_list; /* Index into propstr[] array */ |
| 350 | } propdef_rec; |
| 351 | |
| 352 | typedef struct { |
| 353 | long r,n,c; |
| 354 | char rbit,nbit,cbit; |
| 355 | const char *ystr, *nstr; /* Yes and no strings */ |
| 356 | } attrdef_rec; |
| 357 | |
| 358 | typedef struct { |
| 359 | long str_cnt; |
| 360 | long str_list; |
| 361 | } vardef_rec; |
| 362 | |
| 363 | |
| 364 | typedef struct { |
| 365 | const char *ystr, *nstr; |
| 366 | } flagdef_rec; |
| 367 | |
| 368 | /* Metacommand headers and a pointer to the actual sequence of tokens |
| 369 | to execute if the metacommand is run. */ |
| 370 | typedef struct { |
| 371 | integer actor; /* Contains the actor object number; |
| 372 | 1==self(no explicit actor) 2=anybody |
| 373 | It is multiplied by negative one for redirected |
| 374 | commands */ |
| 375 | /* 0 in any of the following word variables denotes ANY; |
| 376 | -1 denotes <*none*> and will only occur in Magx-generated files. |
| 377 | (verbcmd cannot be equal to -1). Support for -1 is still experimental */ |
| 378 | word verbcmd, nouncmd, objcmd, prep; /* prep only in ME games */ |
| 379 | word noun_adj, obj_adj; /* Adjectives for noun and obj; not |
| 380 | supported in original AGT games */ |
| 381 | integer noun_obj, obj_obj; /* Actual object numbers, |
| 382 | or 0 if none specified */ |
| 383 | integer *data; /* MaxSizeCommand */ |
| 384 | integer cmdsize; /* Number of commands */ |
| 385 | /* integer ptr; */ /* In ME games-- see below for replacement */ |
| 386 | } cmd_rec; |
| 387 | |
| 388 | |
| 389 | /* FRS=file record size; these are the sizes to be allocated to the buffer |
| 390 | used to read in the various records from the files; they should be at |
| 391 | least as big as the worst case scenario. */ |
| 392 | #define FRS_ROOM 220 |
| 393 | #define FRS_NOUN 310 |
| 394 | #define FRS_CREAT 240 |
| 395 | #define FRS_CMD 150 |
| 396 | |
| 397 | |
| 398 | /* This is the record used to hold menu information for verbs */ |
| 399 | typedef struct { /*verb menu entry */ |
| 400 | word verb; /* Verb word */ |
| 401 | word prep; /* Associated preposition */ |
| 402 | short objnum; /* Number of objects */ |
| 403 | } verbentry_rec; |
| 404 | |
| 405 | |
| 406 | /* This is the datatype that will be used (tenatively) for hint info */ |
| 407 | /* This isn't implemented yet. */ |
| 408 | typedef struct { |
| 409 | integer dtype; /* The hint element type */ |
| 410 | integer child; /* The hint element value */ |
| 411 | char *name; /* The hint element name */ |
| 412 | } hint_rec; |
| 413 | |
| 414 | |
| 415 | /* This is the data type used to hold information about |
| 416 | built-in attributes and properties */ |
| 417 | typedef struct { |
| 418 | char *name; /* Property name. */ |
| 419 | int room,noun,creature; /* Offsets for the various object types. */ |
| 420 | } prop_struct; |
| 421 | |
| 422 | |
| 423 | /* The following data structure is used to store info on fields of a struct |
| 424 | that may need to be read from/written to a file. */ |
| 425 | /* They are used by both the AGX and the Savefile routines */ |
| 426 | /* They should be organized in ftype==0 terminated arrays, |
| 427 | in the order they occur in the file (the file is assumed to have |
| 428 | no padding, so we don't need file offsets: they can be computed) */ |
| 429 | /* The following is used for both global variables and fields in |
| 430 | structures. For global variables, ptr is set to point at the variable |
| 431 | and offset is 0. For fields, offset is set to the offset of the field |
| 432 | in the structure and ptr is set internally */ |
| 433 | typedef struct { |
| 434 | int ftype; /* Type in file */ |
| 435 | int dtype; /* Data type of field in memory; often ignored */ |
| 436 | void *ptr; /* Pointer to variable */ |
| 437 | size_t offset; /* Offset of field in structure */ |
| 438 | } file_info; |
| 439 | |
| 440 | |
| 441 | |
| 442 | /* This contains all of the information needed to find files. */ |
| 443 | #ifndef REPLACE_FC |
| 444 | typedef struct { |
| 445 | char *gamename; /* Name as entered by user */ |
| 446 | char *path; /* The path */ |
| 447 | char *shortname; /* The filename w/o directory information */ |
| 448 | char *ext; /* The preexisting extension/prefix */ |
| 449 | filetype ft; /* The filetype corresponding to ext */ |
| 450 | int special; /* Used to mark special files, such as UNIX pipes */ |
| 451 | } file_context_rec; |
| 452 | |
| 453 | typedef file_context_rec *fc_type; |
| 454 | |
| 455 | #endif |
| 456 | |
| 457 | |
| 458 | /* ------------------------------------------------------------------- */ |
| 459 | /* GLOBAL VARIABLES */ |
| 460 | /* ------------------------------------------------------------------- */ |
| 461 | |
| 462 | /* ------------------------------------------------------------------- */ |
| 463 | /* Flags used internally by the interpreter and reading routines */ |
| 464 | |
| 465 | global uchar DIAG, interp_arg, debug_da1, RAW_CMD_OUT; |
| 466 | global int ERR_LEVEL; |
| 467 | |
| 468 | global rbool agx_file; /* Are we reading an AGX file? */ |
| 469 | global rbool have_opt; /* Do we have an OPT file? */ |
| 470 | global rbool skip_descr; /* Causes read_filerec() to skip over description |
| 471 | pointers without actually reading them in. |
| 472 | Used to support RESTORE for multi-part games |
| 473 | such as Klaustrophobia */ |
| 474 | global rbool no_auxsyn; /* Prevents building of auxsyn and preplist |
| 475 | synonym lists; used by agt2agx. */ |
| 476 | |
| 477 | |
| 478 | global rbool BATCH_MODE, make_test; |
| 479 | /* These indicates we are in testing mode: |
| 480 | -- The random number generator should be set to a standard state. |
| 481 | -- Automatically send output to <gamename>.scr |
| 482 | -- Automatically read/write input from <gamename>.log |
| 483 | (depending on whether we are in BATCH_MODE or make_test mode, |
| 484 | respectivly). |
| 485 | */ |
| 486 | |
| 487 | |
| 488 | /* ------------------------------------------------------------------- */ |
| 489 | /* Flags reflecting game version and configuration */ |
| 490 | |
| 491 | global rbool have_meta; /* Do we have any metacommands? */ |
| 492 | global rbool debug_mode, freeze_mode, milltime_mode, bold_mode; |
| 493 | global uchar score_mode, statusmode; |
| 494 | global rbool intro_first; |
| 495 | global rbool box_title; |
| 496 | global rbool mars_fix; |
| 497 | global rbool fix_ascii_flag; /* Translate IBM characters? |
| 498 | Defaults to fix_ascii #define'd above */ |
| 499 | global rbool dbg_nomsg; /* Causes printing of <msg> arguments by |
| 500 | debug disassembler to be supressed */ |
| 501 | |
| 502 | global rbool irun_mode; /* If true, all messages will be in 1st person */ |
| 503 | global rbool verboseflag; |
| 504 | |
| 505 | global int font_status; /* 0=unknown; 1=force fixed font, |
| 506 | 2=allow proportional font. */ |
| 507 | |
| 508 | |
| 509 | /* The following are AGT 'purity' flags; they turn off features of */ |
| 510 | /* my interpreter that are not fully consistent with the original AGT. */ |
| 511 | /* They are defined in auxfile.c (see also interp.h and agil.c for */ |
| 512 | /* interpreter-specific flags) */ |
| 513 | /* Anything added here should also be correctly initialized in agt2agx */ |
| 514 | |
| 515 | extern rbool PURE_ANSWER, PURE_TIME, PURE_ROOMTITLE; |
| 516 | extern rbool PURE_AND, PURE_METAVERB, PURE_ERROR; |
| 517 | extern rbool PURE_SYN, PURE_NOUN, PURE_ADJ, PURE_SIZE; |
| 518 | extern rbool PURE_DUMMY, PURE_SUBNAME, PURE_PROSUB; |
| 519 | extern rbool PURE_HOSTILE, PURE_GETHOSTILE; |
| 520 | extern rbool PURE_DISAMBIG, PURE_ALL, PURE_OBJ_DESC; |
| 521 | extern rbool PURE_GRAMMAR, PURE_SYSMSG, PURE_AFTER; |
| 522 | extern rbool PURE_PROPER; |
| 523 | |
| 524 | extern rbool TWO_CYCLE, FORCE_VERSION; |
| 525 | extern rbool MASTERS_OR; |
| 526 | |
| 527 | /* ------------------------------------------------------------------- */ |
| 528 | /* Variables containing limits and counts of objects */ |
| 529 | |
| 530 | global integer FLAG_NUM, CNT_NUM, VAR_NUM; /* (255, 50, 50) */ |
| 531 | global integer MAX_USTR; /* Maximum number of user strings (25) */ |
| 532 | global integer MAX_SUB; /* Number of subroutines (15) */ |
| 533 | global integer DVERB; /* Number of real dummy_verbs (50) */ |
| 534 | global integer NUM_ERR; /* For ME is 185 */ |
| 535 | |
| 536 | /* Number of objflags and objprops for each type of object */ |
| 537 | /* The flag counts are for groups of 8 flags. */ |
| 538 | global integer num_rflags, num_nflags, num_cflags; |
| 539 | global integer num_rprops, num_nprops, num_cprops; |
| 540 | global integer oprop_cnt, oflag_cnt; /* Size of flag and property tables */ |
| 541 | |
| 542 | global integer maxroom, maxnoun, maxcreat; |
| 543 | global long MaxQuestion; |
| 544 | global integer first_room, first_noun, first_creat, last_obj; |
| 545 | global long last_message, last_cmd; |
| 546 | global long numglobal; /* Number of global nouns */ |
| 547 | global long maxpict, maxpix, maxfont, maxsong; |
| 548 | global long num_prep; /* Number of user-defined prepositions */ |
| 549 | global int num_auxcomb; |
| 550 | global int num_comb; |
| 551 | |
| 552 | global integer exitmsg_base; /* Number added to messages used as |
| 553 | "illegal direction" messages */ |
| 554 | |
| 555 | |
| 556 | /* ------------------------------------------------------------------- */ |
| 557 | /* Miscellaneous other variables read in from the game file */ |
| 558 | |
| 559 | global integer start_room, treas_room, resurrect_room, max_lives; |
| 560 | global long max_score; |
| 561 | global integer start_time, delta_time; |
| 562 | |
| 563 | /* ver contains the size of the game, aver indicates its version */ |
| 564 | /* See the #define's below for details */ |
| 565 | global int ver,aver; /* ver: 0=unknown, 1=small, 2=big, 4=masters1.5 */ |
| 566 | global long game_sig; /* 2-byte quantity used to identify game files */ |
| 567 | /* (It's declared long to avoid overflow problems when |
| 568 | computing it) */ |
| 569 | global int vm_size; /* Size of verb menu */ |
| 570 | |
| 571 | global int min_ver; /* Lowest version of AGiliTy this will run on. */ |
| 572 | |
| 573 | /* ------------------------------------------------------------------- */ |
| 574 | /* Miscellaneous Game Data Structures */ |
| 575 | |
| 576 | /* All of the following are allocated dynamically */ |
| 577 | global room_rec *room; /* [MAX_ROOM]; */ |
| 578 | global creat_rec *creature; /* [MAX_CREAT]; */ |
| 579 | global noun_rec *noun; /* [MAX_NOUN]; */ |
| 580 | global cmd_rec *command; |
| 581 | |
| 582 | global unsigned char *objflag; |
| 583 | global long *objprop; |
| 584 | |
| 585 | /* Next we have tables linking abstract flag/property values to |
| 586 | the indices with the objflag/objprop arrays. */ |
| 587 | global attrdef_rec *attrtable; |
| 588 | global propdef_rec *proptable; |
| 589 | global vardef_rec *vartable; /* For itemized variables */ |
| 590 | global flagdef_rec *flagtable; |
| 591 | |
| 592 | /* Output strings associated with various property values. */ |
| 593 | /* See propdef_rec */ |
| 594 | global char **propstr; |
| 595 | global long propstr_size; |
| 596 | |
| 597 | global tline *userstr; /*[MAX_USTR];*/ |
| 598 | global word *sub_name; /* [MAX_SUB] Dictionary id's of all subroutines */ |
| 599 | |
| 600 | /* Verb information */ |
| 601 | global verbentry_rec *verbinfo; /* Verb information */ |
| 602 | global short *verbptr,*verbend; /* [TOTAL_VERB] */ |
| 603 | global slist *synlist; /* [MAX_VERBS+1];*/ |
| 604 | global slist *comblist; /* Global combination list */ |
| 605 | global word *old_agt_verb; /* List of non-canonical verb synonyms in the |
| 606 | original AGT; these are not allowed to be |
| 607 | expanded as dummy verbs. */ |
| 608 | |
| 609 | |
| 610 | global slist *userprep; /* Array of user-defined prepostions */ |
| 611 | |
| 612 | global word flag_noun[MAX_FLAG_NOUN],*globalnoun; |
| 613 | global word pix_name[MAX_PIX]; |
| 614 | global filename *pictlist,*pixlist,*fontlist,*songlist; |
| 615 | |
| 616 | global uchar opt_data[14]; /* Contents of OPT file. For the format of this |
| 617 | block, see the comments to read_opt() in |
| 618 | agtread.c */ |
| 619 | |
| 620 | /* These are built by reinit_dict */ |
| 621 | |
| 622 | global slist *auxsyn; /* [TOTAL_VERB] Built-in synonym list */ |
| 623 | global slist *preplist; /* [TOTAL_VERB] */ |
| 624 | global uchar *verbflag; /* [TOTAL_VERB] Verb flags; see below */ |
| 625 | global slist *auxcomb; /* Built-in combination lists (for multi-word |
| 626 | verbs) */ |
| 627 | |
| 628 | #ifdef PATH_SEP |
| 629 | global char **gamepath; |
| 630 | #endif |
| 631 | |
| 632 | /* ------------------------------------------------------------------- */ |
| 633 | /* Description Pointers */ |
| 634 | |
| 635 | |
| 636 | global descr_ptr intro_ptr; |
| 637 | global descr_ptr title_ptr, ins_ptr; /* Only defined if agx_file is true */ |
| 638 | global descr_ptr *err_ptr; /* [NUM_ERR];*/ |
| 639 | |
| 640 | global descr_ptr *msg_ptr; /* [MAX_MSG];*/ |
| 641 | global descr_ptr *help_ptr, *room_ptr, *special_ptr; /*[ROOM] */ |
| 642 | global descr_ptr *noun_ptr, *text_ptr, *turn_ptr, /* [NOUN] */ |
| 643 | *push_ptr, *pull_ptr, *play_ptr; |
| 644 | global descr_ptr *talk_ptr, *ask_ptr, *creat_ptr; /* [CREAT] */ |
| 645 | |
| 646 | global descr_ptr *quest_ptr, *ans_ptr; /* [MAX_QUEST] */ |
| 647 | global tline *question, *answer; /* [MAX_QUEST] */ |
| 648 | |
| 649 | |
| 650 | |
| 651 | /* ------------------------------------------------------------------------ */ |
| 652 | /* Dynamically allocated data blocks (which are pointed to from elsewhere) */ |
| 653 | |
| 654 | global char **dict; /* dict[n] points to the nth dictionary word */ |
| 655 | global long dp; /* Dictionary pointer: number of words in dict */ |
| 656 | |
| 657 | #define DICT_INIT 12*1024 /* Starting size of dictstr */ |
| 658 | #define DICT_GRAN 1024 /* Granularity of dictstr size requests |
| 659 | must be at least 4. */ |
| 660 | global char *dictstr; /* Pointer to memory block containing dict words */ |
| 661 | global long dictstrptr, dictstrsize; |
| 662 | /* dictstrptr points to the first unused byte in dictstr. |
| 663 | dictstrsize points to the end of the space currently allocated for |
| 664 | dictstr. |
| 665 | */ |
| 666 | |
| 667 | global char *static_str; /*Static string space */ |
| 668 | global long ss_end; /* Pointer to end of used space in above */ |
| 669 | global long ss_size; /* Current size of static string space */ |
| 670 | |
| 671 | global word *syntbl; /* Synonym list space */ |
| 672 | global slist synptr; /* Points to end of used space */ |
| 673 | global long syntbl_size; /* Long so we can catch overflows */ |
| 674 | |
| 675 | global long descr_maxmem; |
| 676 | global char *mem_descr; /* Copy of descriptor in memory */ |
| 677 | |
| 678 | |
| 679 | |
| 680 | /* ------------------------------------------------------------------------ */ |
| 681 | /* Data structures used internally by agtread.c */ |
| 682 | |
| 683 | /*The following are all set to NULL after agtread finishes. */ |
| 684 | global long *cmd_ptr; /* ME only;Points to cmd start locs in gamefile.*/ |
| 685 | global long *room_name,*noun_sdesc,*noun_pos,*creat_sdesc; |
| 686 | global long *t_pictlist, *t_pixlist, *t_songlist, *t_fontlist; |
| 687 | |
| 688 | /* These are only used by agtout (to allow the AGT reading routines to |
| 689 | pass back the count of nouns inside the given object) */ |
| 690 | global integer *room_inside, *noun_inside, *creat_inside; |
| 691 | |
| 692 | /* This is used to translate ASCII codes */ |
| 693 | global uchar fixchar[256]; |
| 694 | |
| 695 | global rbool text_file; /* Set if we are currently opening a binary file. */ |
| 696 | #ifdef OPEN_AS_TEXT |
| 697 | global rbool open_as_binary; /* Open text files as binary, anyhow. */ |
| 698 | #endif |
| 699 | |
| 700 | |
| 701 | /* ------------------------------------------------------------------ */ |
| 702 | /* SYMBOLIC CONSTANTS: VERSION CODES */ |
| 703 | /* These are the values stored in the variable 'aver'. */ |
| 704 | /* ------------------------------------------------------------------ */ |
| 705 | |
| 706 | #define AGT10 1 /* SPA */ |
| 707 | #define AGT118 2 /* TAMORET, PORK II */ |
| 708 | #define AGT12 3 /* SOS,... */ |
| 709 | #define AGTCOS 4 /* COSMOS and SOGGY: enhanced versions of 1.3x */ |
| 710 | #define AGT135 5 /* By far the most common version; includes practically |
| 711 | every version of Classic AGT from 1.19 to 1.7 */ |
| 712 | #define AGT182 6 |
| 713 | #define AGT183 7 |
| 714 | #define AGT15 8 /* HOTEL */ |
| 715 | #define AGT15F 9 /* MDTHIEF */ |
| 716 | #define AGT16 10 /* PORK */ |
| 717 | #define AGTME10 11 /* CLIFF2, ELF20 */ |
| 718 | #define AGTME10A 12 /* HURRY */ |
| 719 | #define AGTME15 13 /* WOK */ |
| 720 | #define AGTME155 14 /* TJA */ |
| 721 | #define AGTME16 15 /* also includes v1.56 and 1.7 */ |
| 722 | #define AGX00 16 /* Tenative */ |
| 723 | |
| 724 | #define AGTMAST AGTME16 |
| 725 | #define AGTCLASS AGT16 /* Dividing line between master's ed and classic */ |
| 726 | #define AGT18 AGT182 /* Defines lowest 1.8x version */ |
| 727 | #define AGT18MAX AGT183 /* Defines the highest 1.8x version */ |
| 728 | #define AGTSTD AGT135 /* "Default" version of AGT */ |
| 729 | |
| 730 | |
| 731 | |
| 732 | /* ------------------------------------------------------------------ */ |
| 733 | /* SYMBOLIC CONSTANTS: ARGUMENT TYPES */ |
| 734 | /* These are used to encode the argument types of metacommands for */ |
| 735 | /* opcode tables. */ |
| 736 | /* ------------------------------------------------------------------ */ |
| 737 | |
| 738 | #define AGT_UNK 0 /* Unknown argument type */ |
| 739 | |
| 740 | /* The following can all mix and match in various ways and so are |
| 741 | put together as powers of two. */ |
| 742 | #define AGT_NONE 1 /* 0 is allowed */ |
| 743 | #define AGT_SELF 2 /* 1 is allowed */ |
| 744 | #define AGT_WORN 4 /* 1000 is allowed */ |
| 745 | #define AGT_ROOM 8 /* A room # is allowed */ |
| 746 | #define AGT_ITEM 16 /* An item # is allowed */ |
| 747 | #define AGT_CREAT 32 /* A creature # is allowed */ |
| 748 | |
| 749 | /* AGT_VAR is special, since it is always combined with another type-- |
| 750 | the type that the variable is expected to be */ |
| 751 | #define AGT_VAR 64 |
| 752 | |
| 753 | /* The rest of the values are always distinct; they never mix and so |
| 754 | they can be given simple consecutive indices */ |
| 755 | #define AGT_NUM 128 |
| 756 | #define AGT_FLAG 129 |
| 757 | #define AGT_QUEST 130 /* Question */ |
| 758 | #define AGT_MSG 131 /* Message */ |
| 759 | #define AGT_STR 132 /* String */ |
| 760 | #define AGT_CNT 133 /* Counter */ |
| 761 | #define AGT_DIR 134 /* Direction */ |
| 762 | #define AGT_SUB 135 /* Subroutine */ |
| 763 | #define AGT_PIC 136 /* Picture */ |
| 764 | #define AGT_PIX 137 /* Room picture */ |
| 765 | #define AGT_FONT 138 |
| 766 | #define AGT_SONG 139 |
| 767 | #define AGT_ROOMFLAG 140 |
| 768 | #define AGT_TIME 141 |
| 769 | #define AGT_ERR 142 |
| 770 | #define AGT_OBJFLAG 143 /* User defined object flags */ |
| 771 | #define AGT_OBJPROP 144 /* User defined object properties */ |
| 772 | #define AGT_ATTR 145 /* Built-in attribute */ |
| 773 | #define AGT_PROP 146 /* Built-in property */ |
| 774 | |
| 775 | |
| 776 | /* These next three may not occur as operand types */ |
| 777 | #define AGT_EXIT 147 /* Valid values for an exit: room, msg+msgbase, 0 */ |
| 778 | #define AGT_GENFLAG 148 /* PIX or Room Flag; used internally by compiler */ |
| 779 | #define AGT_GENPROP 149 /* ObjProp/Property */ |
| 780 | |
| 781 | /* certain restrictions. Used internally |
| 782 | by the compiler in the parsing |
| 783 | of "[obj].[prop].[prop].[flag]" |
| 784 | constructions. */ |
| 785 | |
| 786 | #define AGT_LVAL 150 /* Used by the compiler in certain psuedo-ops */ |
| 787 | |
| 788 | |
| 789 | #define AGT_DEFINE 256 |
| 790 | |
| 791 | |
| 792 | |
| 793 | /* ------------------------------------------------------------------ */ |
| 794 | /* Verb flags for verbflag[]; these should be powers of 2 */ |
| 795 | |
| 796 | #define VERB_TAKEOBJ 1 |
| 797 | #define VERB_META 2 |
| 798 | #define VERB_MULTI 4 /* Can the verb take mulitple objects? */ |
| 799 | #define VERB_GLOBAL 8 /* Does the verb have global scope? */ |
| 800 | |
| 801 | /* ------------------------------------------------------------------ */ |
| 802 | /* SYMBOLIC CONSTANTS: FILE DATA TYPES */ |
| 803 | /* Data type specifiers for file i/o routines */ |
| 804 | /* The FT_* constants specify file data types */ |
| 805 | /* The DT_* constants specify internal data types */ |
| 806 | /* ------------------------------------------------------------------ */ |
| 807 | |
| 808 | #define FT_COUNT 17 /* Number of file data types */ |
| 809 | |
| 810 | #define FT_END 0 /* End of list of fields/variables in file */ |
| 811 | #define FT_INT16 1 /* DT_SHORT */ |
| 812 | #define FT_UINT16 2 /* DT_LONG */ |
| 813 | #define FT_INT32 3 /* DT_LONG */ |
| 814 | #define FT_UINT32 4 |
| 815 | #define FT_BYTE 5 /* aka uchar; DT_UCHAR */ |
| 816 | #define FT_VERSION 6 /* Game version */ |
| 817 | #define FT_BOOL 7 /* DT_BOOL. Adjacent rbooleans are packed */ |
| 818 | #define FT_DESCPTR 8 /* DT_DESCPTR */ |
| 819 | #define FT_STR 9 /* Integer pointer into static string array */ |
| 820 | #define FT_SLIST 10 /* Synonym list index */ |
| 821 | #define FT_WORD FT_INT16 /* Index into dictionary */ |
| 822 | #define FT_PATHARRAY 11 /* 13 integers in an array of directions */ |
| 823 | #define FT_CMDPTR 12 /* Pointer into command block */ |
| 824 | #define FT_DICTPTR 13 /* Pointer into dictionary text */ |
| 825 | #define FT_TLINE 14 /* TextLine */ |
| 826 | #define FT_CHAR 15 /* Characters. */ |
| 827 | #define FT_CFG 16 /* Configuration byte; 0=false, 1=true, |
| 828 | 2=none (don't change) */ |
| 829 | |
| 830 | #define DT_DEFAULT 0 /* Default internal type for <ftype> */ |
| 831 | #define DT_LONG 1 |
| 832 | #define DT_DESCPTR 2 /* Description pointer, which are treated specially */ |
| 833 | #define DT_CMDPTR 3 /* Command block pointer, also treated specially */ |
| 834 | |
| 835 | /* This is the end marker for the file definitions used by the file I/O |
| 836 | routines */ |
| 837 | #define endrec {FT_END,0,NULL,0} |
| 838 | |
| 839 | |
| 840 | /* ------------------------------------------------------------------- */ |
| 841 | /* Date type macros */ |
| 842 | /* ------------------------------------------------------------------- */ |
| 843 | #define troom(x) ((x)>=first_room && (x)<=maxroom) |
| 844 | #define tnoun(x) ((x)>=first_noun && (x)<=maxnoun) |
| 845 | #define tcreat(x) ((x)>=first_creat && (x)<=maxcreat) |
| 846 | |
| 847 | |
| 848 | /* ------------------------------------------------------------------- */ |
| 849 | /* FUNCTION PROTOTYPES AND INITIALIZED TABLES */ |
| 850 | /* ------------------------------------------------------------------- */ |
| 851 | |
| 852 | /* This is intended for removing whitespace in AGT data files. */ |
| 853 | #define rspace(c) ((c)==' ' || (c)=='\t') |
| 854 | |
| 855 | /* ------------------------------------------------------------------- */ |
| 856 | /* In GAMEDATA.C */ |
| 857 | /* This module contains the major initialized data structures and */ |
| 858 | /* routines to manipulate game data structures, in particular the */ |
| 859 | /* game's dictionary */ |
| 860 | /* ------------------------------------------------------------------- */ |
| 861 | |
| 862 | void init_dict(void); /* 1=set of verblist, 0=don't */ |
| 863 | void build_verblist(void); /* Creates verblist */ |
| 864 | void reinit_dict(void); |
| 865 | void free_dict(void); |
| 866 | word search_dict(const char*); |
| 867 | word add_dict(const char*); |
| 868 | const char *gdict(word w); /* Almost equivalent to dict[w], but with |
| 869 | some error checking and handling for |
| 870 | the w==-1 case. */ |
| 871 | |
| 872 | int verb_code(word); |
| 873 | int verb_builtin(word); |
| 874 | int verb_authorsyn(word); |
| 875 | void addsyn(word); |
| 876 | slist add_multi_word(word); |
| 877 | |
| 878 | /* Commands to manipulate object flags */ |
| 879 | long objextsize(char op); |
| 880 | long op_objprop(int op, int obj, int propid, long val); |
| 881 | rbool op_objflag(int op, integer obj, int flagid); |
| 882 | long lookup_objflag(int id, int t, char *ofs); |
| 883 | long lookup_objprop(int id, int t); |
| 884 | rbool have_objattr(rbool prop,integer obj,int id); |
| 885 | int num_oattrs(int t, rbool isflag); |
| 886 | rbool op_simpflag(uchar *flag, char ofs, int op); |
| 887 | /* op: 0=clear, 1=set, 2=nop, 3=toggle two bits: <ab> */ |
| 888 | const char *get_objattr_str(int dtype,int id,long val); |
| 889 | |
| 890 | |
| 891 | const opdef *get_opdef(integer op); |
| 892 | char *objname(int); |
| 893 | void sort_cmd(void); |
| 894 | void cmds_syns_canon(void); |
| 895 | |
| 896 | void agtwarn(const char*,int elev); |
| 897 | void agtnwarn(const char*,int,int elev); |
| 898 | |
| 899 | void init_flags(void); |
| 900 | |
| 901 | #ifdef ZIP |
| 902 | #define fatal agil_fatal |
| 903 | #endif |
| 904 | void fatal(const char*); |
| 905 | |
| 906 | long new_str(char *buff,int max_leng,rbool pasc); |
| 907 | |
| 908 | descr_line *read_descr(long start,long size); |
| 909 | void free_descr(descr_line *p); |
| 910 | |
| 911 | extern const char trans_ibm[]; |
| 912 | extern const char nonestr[]; |
| 913 | |
| 914 | /* Tables of opcodes */ |
| 915 | extern const opdef cond_def[], act_def[], end_def[], illegal_def; |
| 916 | |
| 917 | /* Table of built in properties and attributes */ |
| 918 | extern const prop_struct proplist[NUM_PROP]; |
| 919 | extern const prop_struct attrlist[NUM_ATTR]; |
| 920 | |
| 921 | global words *verblist; /* List of prexisting words, intialized by init_dict */ |
| 922 | extern const fix_array FIX_LIST[]; |
| 923 | extern const char *exitname[13]; |
| 924 | extern const char *verstr[], *averstr[]; |
| 925 | extern const char *version_str,*portstr; |
| 926 | |
| 927 | |
| 928 | /* ------------------------------------------------------------------- */ |
| 929 | /* In AGTREAD.C */ |
| 930 | /* Routines to read in AGT data files */ |
| 931 | /* ------------------------------------------------------------------- */ |
| 932 | |
| 933 | void open_descr(fc_type fc); |
| 934 | void close_descr(void); |
| 935 | descr_line *agt_read_descr(long start,long len); |
| 936 | rbool readagt(fc_type fc, rbool diag); |
| 937 | void free_all_agtread(void); /* Cleans up everything allocated in agtread |
| 938 | should only be called at the very end of |
| 939 | the program */ |
| 940 | void free_ttl(descr_line *title); |
| 941 | |
| 942 | |
| 943 | /* ------------------------------------------------------------------- */ |
| 944 | /* In AGXFILE.C */ |
| 945 | /* Routines to read and write AGX files */ |
| 946 | /* ------------------------------------------------------------------- */ |
| 947 | |
| 948 | int read_agx(fc_type fc, rbool diag); |
| 949 | descr_line *agx_read_descr(long start,long size); |
| 950 | void agx_close_descr(void); |
| 951 | |
| 952 | /* The following are in the order they should be called */ |
| 953 | void agx_create(fc_type fc); |
| 954 | void write_descr(descr_ptr *dp,descr_line *txt); |
| 955 | void agx_write(void); |
| 956 | void agx_wclose(void); |
| 957 | void agx_wabort(void); |
| 958 | |
| 959 | /* ------------------------------------------------------------------- */ |
| 960 | /* In AUXFILE.C */ |
| 961 | /* Routines to read VOC, OPT, CFG, TTL, INS, etc. files */ |
| 962 | /* ------------------------------------------------------------------- */ |
| 963 | void read_opt(fc_type fc); |
| 964 | void read_config(genfile cfgfile, rbool lastpass); |
| 965 | rbool parse_config_line(char *s, rbool lastpass); |
| 966 | |
| 967 | descr_line *read_ttl(fc_type fc); /* This returns the title. The return string |
| 968 | must be freed with free_ttl() and not |
| 969 | with free_descr */ |
| 970 | void free_ttl(descr_line *title); |
| 971 | |
| 972 | void read_voc(fc_type fc); |
| 973 | void init_verbrec(void); |
| 974 | void add_verbrec(char *verbline,rbool addnew); /* addnew should be 0 */ |
| 975 | void finish_verbrec(void); |
| 976 | |
| 977 | descr_line *read_ins(fc_type fc); |
| 978 | void free_ins(descr_line *instr); |
| 979 | rbool open_ins_file(fc_type fc, rbool report_error); |
| 980 | char *read_ins_line(void); /* Reuses buffer, so return value should be copied |
| 981 | if it needs to be used past the next call to |
| 982 | read_ins_line or close_ins_file */ |
| 983 | void close_ins_file(void); |
| 984 | |
| 985 | void build_fixchar(void); |
| 986 | |
| 987 | /* ------------------------------------------------------------------- */ |
| 988 | /* In or used by DISASSEMBLE.C */ |
| 989 | /* Routines to disassemble metacommands (used by the interpreter for */ |
| 990 | /* tracing and by agtout to produce the metacommand output). */ |
| 991 | /* ------------------------------------------------------------------- */ |
| 992 | |
| 993 | global rbool *dbgflagptr; |
| 994 | global long *dbgvarptr; |
| 995 | global short *dbgcntptr; |
| 996 | |
| 997 | void dbgprintf(const char *fmt,...); |
| 998 | void debugout(const char *s); |
| 999 | int argout(int dtype, int dval, int optype); |
| 1000 | |
| 1001 | /* ------------------------------------------------------------------- */ |
| 1002 | /* In INTERFACE.C, AGIL.C and/or AGILSTUB.C */ |
| 1003 | /* agilstub.c provides minimal versions of these routines for use by */ |
| 1004 | /* programs other than the interpreter */ |
| 1005 | /* ------------------------------------------------------------------- */ |
| 1006 | |
| 1007 | void writeln(const char *s); |
| 1008 | void writestr(const char *s); |
| 1009 | void agil_option(int optnum,char *optstr[], rbool setflag, rbool lastpass); |
| 1010 | void close_interface(void); |
| 1011 | |
| 1012 | void print_tos(void); /* Called by the disassembler; in either TOKEN.C |
| 1013 | or AGTOUT.C */ |
| 1014 | |
| 1015 | |
| 1016 | /* ------------------------------------------------------------------- */ |
| 1017 | /* In UTIL.C */ |
| 1018 | /* Low-level utilites, including memory allocation, string manip., */ |
| 1019 | /* and buffered file I/O. */ |
| 1020 | /* ------------------------------------------------------------------- */ |
| 1021 | |
| 1022 | global uchar trans_ascii[256]; /* Table to translate ascii values read |
| 1023 | in from file */ |
| 1024 | |
| 1025 | void build_trans_ascii(void); /* Set up the above table. */ |
| 1026 | |
| 1027 | void rprintf(const char *fmt, ...); /* General output routine, mainly used |
| 1028 | for diagnostics. There can be a newline |
| 1029 | at the end, but there shouldn't be |
| 1030 | one in the middle of the string */ |
| 1031 | |
| 1032 | |
| 1033 | |
| 1034 | /* Memory management variables and routines */ |
| 1035 | |
| 1036 | extern rbool rm_trap; /* Trap memory allocation failures? */ |
| 1037 | global rbool rm_acct; /* Turn on rmem accounting, to locate memory leaks */ |
| 1038 | global long rfree_cnt, ralloc_cnt; /* # of allocs/frees since acct turned on */ |
| 1039 | global long rm_size, rm_freesize; /* These hold worst case values */ |
| 1040 | |
| 1041 | long get_rm_size(void); /* These get the current values */ |
| 1042 | long get_rm_freesize(void); |
| 1043 | void *rmalloc(long size); |
| 1044 | void r_free(void *p); |
| 1045 | #define rfree(p) (r_free(p),p=NULL) /* Traps errors & catch memory leaks */ |
| 1046 | void *rrealloc(void *p,long size); |
| 1047 | char *rstrdup(const char *s); |
| 1048 | |
| 1049 | |
| 1050 | /* String utilities */ |
| 1051 | |
| 1052 | char *concdup(const char *s1,const char *s2); /* Concacate and duplicate */ |
| 1053 | char *rstrncpy(char *dest,const char *src,int max); |
| 1054 | /* Copy at most max-1 characters */ |
| 1055 | rbool match_str(const char **pstr,const char *match); |
| 1056 | |
| 1057 | #ifdef NEED_STR_CMP |
| 1058 | int strcasecmp(const char *s1,const char *s2); |
| 1059 | #endif |
| 1060 | #ifdef NEED_STRN_CMP |
| 1061 | int strncasecmp(const char *s1,const char *s2,size_t n); |
| 1062 | #endif |
| 1063 | |
| 1064 | |
| 1065 | /* The fixsign.. routines put together unsigned bytes to form signed ints */ |
| 1066 | |
| 1067 | #ifndef FAST_FIXSIGN |
| 1068 | short fixsign16(uchar n1,uchar n2); |
| 1069 | long fixsign32(uchar n1,uchar n2,uchar n3,uchar n4); |
| 1070 | #else |
| 1071 | #define fixsign16(u1,u2) ( (u1) | ((u2)<<8) ) |
| 1072 | #define fixsign32(u1,u2,u3,u4) ( ((long)u1) | (((long)u2)<<8) | \ |
| 1073 | (((long)u3)<<16) | (((long)u4)<<24) ) |
| 1074 | #endif |
| 1075 | |
| 1076 | |
| 1077 | /* Miscellaneous */ |
| 1078 | long rangefix(long n); |
| 1079 | |
| 1080 | /* File routines */ |
| 1081 | genfile openfile(fc_type fc,filetype ext,char *err,rbool ferr); |
| 1082 | genfile openbin(fc_type fc,filetype ext,char *err,rbool ferr); |
| 1083 | |
| 1084 | char *readln(genfile f, char *buff, int n); |
| 1085 | /* Read a line from a 'text' file */ |
| 1086 | |
| 1087 | /* (None of the following routines are at all reentrant) */ |
| 1088 | long buffopen(fc_type fc, filetype ext, |
| 1089 | long minbuffsize,char *rectype,long recnum); |
| 1090 | /* Open file for our buffered routines and make it our current file; |
| 1091 | returns the record size. Prints out error message on failure |
| 1092 | rectype="noun","room",etc.; recnum=expected # of objects in file */ |
| 1093 | uchar *buffread(long index); |
| 1094 | /* seek to index*recsize, read buff_rsize bytes, return pointer to a |
| 1095 | buffer with them. */ |
| 1096 | void buffclose(void); /* Close the current file */ |
| 1097 | |
| 1098 | void bw_open(fc_type fc,filetype ext); /* Open buffered file for writing */ |
| 1099 | void bw_close(void); /* Close buffered file */ |
| 1100 | void bw_abort(void); /* Close and delete buffered file */ |
| 1101 | |
| 1102 | /* "Universal" file routines */ |
| 1103 | extern const size_t ft_leng[FT_COUNT]; /* File lengths of the data types */ |
| 1104 | long compute_recsize(file_info *recinfo); |
| 1105 | void *read_recblock(void *base,int ftype,long numrec, long offset, |
| 1106 | long blocksize); |
| 1107 | /* Only works for FT_BYTE, FT_SLIST, FT_WORD, FT_DICTTEXT, FT_INT16 */ |
| 1108 | void *read_recarray(void *base, long eltsize, long numelts, |
| 1109 | file_info *field_info, char *rectype, |
| 1110 | long file_offset,long file_blocksize); |
| 1111 | void read_globalrec(file_info *global_info, char *rectype, |
| 1112 | long file_offset, long file_blocksize); |
| 1113 | |
| 1114 | long write_recarray(void *base, long eltsize, long numelts, |
| 1115 | file_info *field_info, long file_offset); |
| 1116 | long write_globalrec(file_info *global_info, long file_offset); |
| 1117 | long write_recblock(void *base,int ftype,long numrec, long offset); |
| 1118 | |
| 1119 | void set_internal_buffer(void *p); |
| 1120 | /* Causes all of the above routines to write to the block of memory pointed |
| 1121 | at by p instead of to a file */ |
| 1122 | |
| 1123 | #ifdef PROFILE_SUPPORT |
| 1124 | /* These are functions to do quick-and-dirty timing of routines; |
| 1125 | I added them to check the performance of the AGX code. |
| 1126 | They aren't likely to work on anything other than a *nix box */ |
| 1127 | void resetwatch(void); |
| 1128 | void startwatch(void); |
| 1129 | char *stopwatch(void); |
| 1130 | char *timestring(void); |
| 1131 | #define runwatch(cmd) do{resetwatch();cmd;printf("%s\n",stopwatch());}while(0) |
| 1132 | #else |
| 1133 | #define runwatch(cmd) cmd |
| 1134 | #endif |
| 1135 | |
| 1136 | |
| 1137 | |
| 1138 | /* ------------------------------------------------------------------- */ |
| 1139 | /* In FILENAME.C */ |
| 1140 | /* The low-level file routines */ |
| 1141 | /* ------------------------------------------------------------------- */ |
| 1142 | |
| 1143 | fc_type init_file_context(const char *game_name, filetype ft); |
| 1144 | /* This sets up the filename system, based around a game with name |
| 1145 | "gamename". Must be called before any of the following are called |
| 1146 | with relative filetypes (all filetypes that depend on the game's |
| 1147 | name and location-- everything but the global config file.) */ |
| 1148 | /* ft indicates the file type class. At the moment, it can be |
| 1149 | fAGX, fSAV, fSCR, fLOG |
| 1150 | */ |
| 1151 | void fix_file_context(fc_type fc, filetype ft); |
| 1152 | fc_type convert_file_context(fc_type fc,filetype ft, const char *name); |
| 1153 | void release_file_context(fc_type *pfc); |
| 1154 | |
| 1155 | |
| 1156 | char *formal_name(fc_type fc, filetype ft); /* Used for messages */ |
| 1157 | genfile badfile(filetype ft); /* Bad file of type ft */ |
| 1158 | rbool fileexist(fc_type fc, filetype ft); |
| 1159 | |
| 1160 | genfile readopen(fc_type fc, filetype ft, char **errstr); |
| 1161 | genfile writeopen(fc_type fc, filetype ft, |
| 1162 | file_id_type *pfileid, char **errstr); |
| 1163 | rbool filevalid(genfile f, filetype ft); |
| 1164 | void readclose(genfile f); |
| 1165 | void writeclose(genfile f, file_id_type fileid); |
| 1166 | |
| 1167 | void binremove(genfile f, file_id_type fileid); |
| 1168 | void binseek(genfile f, long offset); |
| 1169 | rbool binread(genfile f, void *buff, long recsize, long recnum, char **errstr); |
| 1170 | long varread(genfile f, void *buff, long recsize, long recnum, char **errstr); |
| 1171 | rbool binwrite(genfile f, void *buff, long recsize, long recnum, rbool ferr); |
| 1172 | long binsize(genfile f); /* Size of an open binary file */ |
| 1173 | |
| 1174 | rbool textrewind(genfile f); |
| 1175 | |
| 1176 | char *assemble_filename(const char *path, const char *root, |
| 1177 | const char *ext); |
| 1178 | |
| 1179 | |
| 1180 | #ifdef global_defined_agtread |
| 1181 | #undef global |
| 1182 | #undef global_defined_agtread |
| 1183 | #endif |
| 1184 | |
| 1185 | |
| 1186 |