1 /* ScummVM - Graphic Adventure Engine 2 * 3 * ScummVM is the legal property of its developers, whose names 4 * are too numerous to list here. Please refer to the COPYRIGHT 5 * file distributed with this source distribution. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 */ 22 23 24 namespace Glk { 25 namespace AGT { 26 27 #ifndef global /* Don't touch this */ 28 #define global extern 29 #define global_defined_exec 30 #endif 31 32 33 34 /* This contains the decoding of the current instruction */ 35 struct op_rec { 36 integer op; 37 int arg1; 38 int arg2; 39 int optype; 40 int argcnt; /* Actual number of argument words present */ 41 const opdef *opdata; 42 const char *errmsg; 43 rbool disambig; /* Trigger disambiguation? */ 44 rbool negate; /* NOT? (cond token only) */ 45 rbool failmsg; /* Run only on failure? */ 46 rbool endor; /* End any OR blocks? (action tokens, mainly) */ 47 } ; 48 49 50 51 /* The following determines if we are doing disambiguation 52 or actually executing a verb */ 53 global uchar do_disambig; /* 0= execution 54 1= disambiguating noun 55 2= disambiguating object */ 56 57 58 /* Flags used during turn execution */ 59 global rbool beforecmd; /* Only used by 1.8x games */ 60 global rbool supress_debug; /* Causes debugging info to _not_ be printed 61 even if debugging is on; used by disambiguator 62 and to supress ANY commands */ 63 global rbool was_metaverb; /* Was the verb that just executed a metaverb? */ 64 /* Metaverbs are commands that should not take game time 65 to execute: SAVE, RESTORE, RESTART, QUIT, SCRIPT, UNSCRIPT, 66 NOTIFY, SCORE, etc. */ 67 global integer oldloc; /* Save old location for NO_BLOCK_HOSTILE purposes */ 68 69 /* This is a hack to pass the subroutine number from exec_token 70 back to scan_metacommand when a DoSubroutine is done */ 71 global integer subcall_arg; 72 73 /* This fixes a bug in the original AGT spec, causing "actor, verb ..." 74 commands to misfire if there is more than one creature of the same 75 name. */ 76 global integer *creat_fix; 77 78 79 /* -------------------------------------------------------------------- */ 80 /* Defined in EXEC.C */ 81 /* -------------------------------------------------------------------- */ 82 extern void raw_lineout(const char *s, rbool do_repl, 83 int context, const char *pword); 84 extern void msgout(int msgnum, rbool add_nl); 85 extern void sysmsg(int msgid, const char *s); 86 extern void alt_sysmsg(int msgid, const char *s, parse_rec *new_dobjrec, 87 parse_rec *new_iobjrec); 88 extern void sysmsgd(int msgid, const char *s, parse_rec *new_dobj_rec); 89 90 rbool ask_question(int qnum); 91 extern void increment_turn(void); 92 93 /* Warning: the following function rfrees <ans> */ 94 extern rbool match_answer(char *ans, int anum); 95 96 extern void look_room(void); 97 extern void runptr(int i, descr_ptr dp[], const char *msg, int msgid, 98 parse_rec *nounrec, parse_rec *objrec); 99 100 extern int normalize_time(int tnum); /* Convert hhmm so mm<60 */ 101 extern void add_time(int dt); 102 103 104 /* -------------------------------------------------------------------- */ 105 /* Defined in OBJECT.C */ 106 /* -------------------------------------------------------------------- */ 107 extern parse_rec *make_parserec(int obj, parse_rec *rec); 108 extern parse_rec *copy_parserec(parse_rec *rec); 109 extern void free_all_parserec(void); /* Freeds doj_rec, iobj_rec, and actor_rec */ 110 111 extern rbool in_scope(int item); 112 extern rbool islit(void); 113 extern rbool it_possess(int item); 114 extern rbool it_proper(int item); 115 extern rbool it_isweapon(int item); 116 extern rbool it_door(int obj, word noun); /* Is obj a door? */ 117 extern rbool is_within(integer obj1, integer obj2, rbool stop_if_closed); 118 119 extern integer it_room(int item); /* Returns the room that the item is in */ 120 121 extern int lightcheck(int parent, int roomlight, rbool active); 122 /* If active is false, we don't care if the light is actually working. */ 123 124 #define it_move(a,b) it_reposition(a,b,0) 125 #define it_destroy(item) it_move(item,0) 126 #define get_obj(dobj) it_move(dobj,1) 127 #define drop_obj(dobj) it_move(dobj,loc+first_room) 128 129 extern void it_reposition(int item, int newloc, rbool save_pos); 130 extern void goto_room(int newroom); 131 132 extern void it_describe(int dobj); 133 extern int print_contents(int obj, int ind_lev); 134 135 extern void recompute_score(void); 136 137 extern int check_fit(int obj1, int obj2); 138 139 /* And its possible return values: */ 140 141 #define FIT_OK 0 /* Fits */ 142 #define FIT_WEIGHT 1 /* Too heavy [*] */ 143 #define FIT_NETWEIGHT 2 /* With other stuff is too heavy [*] */ 144 #define FIT_SIZE 3 /* Too big */ 145 #define FIT_NETSIZE 4 /* With other stuff is too big */ 146 /* [*]-- These can only occur if obj2==1 or for ME/1.5-1.7 */ 147 148 149 extern long getprop(int obj, int prop); 150 extern void setprop(int obj, int prop, long val); 151 extern rbool getattr(int obj, int prop); 152 extern void setattr(int obj, int prop, rbool val); 153 154 extern rbool matchclass(int obj, int oclass); 155 156 /* ---------------------------------------------------------------------- */ 157 /* Define in RUNVERB.C */ 158 /* ---------------------------------------------------------------------- */ 159 160 /* Verbs actually used elsewhere in th interpreter */ 161 extern void v_inventory(void); 162 extern void v_look(void); 163 extern void v_listexit(void); 164 165 /* The routine that actually runs the current player command */ 166 extern void exec_verb(void); 167 168 169 /* ---------------------------------------------------------------------- */ 170 /* In METACOMMAND.C */ 171 /* ---------------------------------------------------------------------- */ 172 /* The main routine to search the metacommand list and run the appropriate 173 meta-commands */ 174 extern int scan_metacommand(integer m_actor, int vcode, 175 integer m_dobj, word m_prep, integer m_iobj, 176 int *redir_flag); 177 178 /* The type checking routine */ 179 rbool argvalid(int argtype, int arg); 180 181 /* ---------------------------------------------------------------------- */ 182 /* In TOKEN.C */ 183 /* ---------------------------------------------------------------------- */ 184 extern int exec_instr(op_rec *oprec); /* Execute instruction */ 185 extern long pop_expr_stack(void); /* Wrapper around routine to access TOS */ 186 187 /* ---------------------------------------------------------------------- */ 188 /* Defined in DEBUGCMD.C */ 189 /* ---------------------------------------------------------------------- */ 190 extern void get_debugcmd(void); /* Get and execute debugging commands */ 191 192 193 /* ------------------------------------------------------------------- */ 194 /* Macros for getting information about items */ 195 /* (mainly used to blackbox the difference between nouns and creatures) */ 196 /* -------------------------------------------------------------------- */ 197 198 /* A note on object codes: 199 <0 obj is a 'virtual' object, existing only as the word 200 dict[-obj], e.g. DOOR, flag nouns, global nouns 201 0 No object (or any object) 202 1 Self(i.e. the player) 203 first_room..last_room Rooms 204 first_noun..last_noun Nouns 205 first_creat..last_creat Creatures 206 1000 Being worn by the player */ 207 208 209 /* The following macro loops over the contents of an object */ 210 #define contloop(i,obj) for(i=it_contents(obj);i!=0;i=it_next(i)) 211 #define safecontloop(i,j,obj) for(i=it_contents(obj),j=it_next(i); \ 212 i!=0;i=j,j=it_next(i)) 213 214 #define cnt_val(c) ((c)==-1 ? 0 : (c)) 215 216 217 /* -------------------------------------------------------------------- */ 218 /* These are the macros that should usually be used to determine */ 219 /* information about the objects in the game, unless the object type */ 220 /* is definitely known */ 221 /* ------------------------------------------------------------------- */ 222 223 #define it_on(item) nounattr(item,on) 224 #define it_group(item) creatattr(item,groupmemb) 225 #define it_adj(item) objattr(item,adj) 226 #define it_pushable(item) nounattr(item,pushable) 227 #define it_pullable(item) nounattr(item,pullable) 228 #define it_turnable(item) nounattr(item,turnable) 229 #define it_playable(item) nounattr(item,playable) 230 #define it_plur(item) nounattr(item,plural) 231 #define it_gender(item) creatattr(item,gender) 232 233 #define it_pict(item) objattr(item,pict) 234 #define it_class(item) anyattr(item,oclass) 235 #define it_next(item) objattr(item,next) 236 #define it_isglobal(item) objattr(item,isglobal) 237 #define it_flagnum(item) objattr(item,flagnum) 238 #define it_seen(item) anyattr(item,seen) 239 240 241 #define it_name(item) objattr2(item,name,(item<0) ? -item : 0) 242 #define it_open(item) nounattr2(item,open, tcreat(item) || \ 243 (tdoor(item) && !room[loc].locked_door)) 244 245 /* This checks to make sure the object isn't unmovable. */ 246 /* (As such, all non-nouns automatically pass) */ 247 #define it_canmove(item) (!tnoun(item) || noun[(item)-first_noun].movable) 248 249 250 #ifdef IT_MACRO 251 #define it_contents(item) objattr2(item,contents,\ 252 roomattr2(item,contents,\ 253 (item==1) ? player_contents : \ 254 (item==1000) ? player_worn : 0)) 255 #define it_lockable(item) nounattr2(item,lockable, (tdoor(item) ? 1 : 0) ) 256 #define it_locked(item,name) nounattr2(item,locked,\ 257 (tdoor(item) && room[loc].locked_door ? \ 258 1 : 0)) 259 #else 260 extern int it_contents(integer obj); 261 extern rbool it_lockable(integer obj, word noun); 262 extern rbool it_locked(integer obj, word noun); 263 #endif 264 265 266 #ifdef global_defined_exec 267 #undef global 268 #undef global_defined_exec 269 #endif 270 271 } // End of namespace AGT 272 } // End of namespace Glk 273