/*  exec.h-- Header file for verb execution routines      */
/* Copyright 1996,97    Robert Masenten                   */
/*                                                        */
/* This is part of the source for AGiliTy: the (Mostly) Universal  */
/*       AGT Interpreter                                           */


#ifndef global    /* Don't touch this */
#define global extern
#define global_defined_exec
#endif



/* The following determines if we are doing disambiguation
   or actually executing a verb */
global uchar do_disambig;  /* 0= execution
		       	      1= disambiguating noun
		              2= disambiguating object */


/* Flags used during turn execution */
global bool ignore_grammer; /* Used, e.g. in redirection */
global bool beforecmd;     /* Only used by 1.8x games */
global bool supress_debug; /* Causes debugging info to _not_ be printed
			      even if debugging is on; used by disambiguator
			      and to supress ANY commands */
global bool was_metaverb; /* Was the verb that just executed a metaverb? */
          /* Metaverbs are commands that should not take game time 
	     to execute: SAVE, RESTORE, RESTART, QUIT, SCRIPT, UNSCRIPT,
	     NOTIFY, SCORE, etc. */
global integer oldloc;  /* Save old location for NO_BLOCK_HOSTILE purposes */


/* --------------------------------------------------------------------	*/
/* Defined in EXEC.C 							*/
/* -------------------------------------------------------------------- */
void msgout(int msgnum,bool add_nl);
void sysmsgd(int msgid,char *s,parse_rec *new_dobj_rec);
void sysmsgi(int msgid,char *s,parse_rec *new_iobj_rec);
bool ask_question(int qnum);

void look_room(void);
void runptr(int i, descr_ptr dp[], char *msg, int msgid);

int normalize_time(int tnum); /* Convert hhmm so mm<60 */
void add_time(int dt);


/* --------------------------------------------------------------------	*/
/* Defined in OBJECT.C 							*/
/* --------------------------------------------------------------------	*/
bool in_scope(int item);
bool islit(void);
bool it_possess(int item);

#define it_move(a,b) it_reposition(a,b,0)
#define it_destroy(item) it_move(item,0)
#define get_obj(dobj) it_move(dobj,1)
#define drop_obj(dobj) it_move(dobj,loc+first_room)

void it_reposition(int item,int newloc,bool save_pos);
void goto_room(int newroom);

void it_describe(int dobj);
int /*@alt void@*/ print_contents(int obj,int ind_lev);

void recompute_score(void);



/* ---------------------------------------------------------------------- */
/* Define in RUNVERB.C                                                    */
/* ---------------------------------------------------------------------- */

/* Verbs actually used elsewhere in th interpreter */
void v_inventory(void);
void v_look(void);
void v_listexit(void);

/* The routine that actually runs the current player command */
void exec_verb(void); 


/* ---------------------------------------------------------------------- */
/* In METACOMMAND.C 							  */
/* ---------------------------------------------------------------------- */
/* The main routine to search the metacommand list and run the appropriate
   meta-commands */
int scan_metacommand(integer m_actor,int vcode,word m_noun,
		     word m_prep,word m_obj, 
		     word m_nounadj, word m_objadj);


/* ---------------------------------------------------------------------- */
/* In TOKEN.C 								  */
/* ---------------------------------------------------------------------- */
int exec_token(int ip,int op, int arg1, int arg2, int optype);


/* ---------------------------------------------------------------------- */ 
/* Defined in DEBUGCMD.C 						  */
/* ---------------------------------------------------------------------- */
void get_debugcmd(void);  /* Get and execute debugging commands */


/* ------------------------------------------------------------------- 	*/
/* Macros for getting information about items 				*/
/* (mainly used to blackbox the difference between nouns and creatures) */
/* --------------------------------------------------------------------	*/

/* A note on object codes:
       <0                 obj is a 'virtual' object, existing only as the word
                           dict[-obj], e.g. DOOR, flag nouns, global nouns
       0                  No object (or any object) 
       1                  Self(i.e. the player)
   first_room..last_room  Rooms
   first_noun..last_noun  Nouns
   first_creat..last_creat Creatures
      1000                Being worn by the player			*/


/* The following macro loops over the contents of an object */
#define contloop(i,obj)   for(i=it_contents(obj);i!=0;i=it_next(i))
#define safecontloop(i,j,obj) for(i=it_contents(obj),j=it_next(i); \
				  i!=0;i=j,j=it_next(i))

#define cnt_val(c) ((c)==-1 ? 0 : (c))


/* ------------------------------------------------------------------- 	*/
/* The following are intended as building blocks to construct macros  	*/
/*  to extract information about general objects, regardless of whether	*/
/*  they are nouns, creatures, or virtual nouns with no associated	*/
/*  data structure. 							*/
/* ------------------------------------------------------------------- 	*/
#define creatattr2(item,attr,op3) (tcreat(item)? \
				   creature[item-first_creat].attr:\
				   (op3))
#define creatattr(item,attr) creatattr2(item,attr,0)
#define nounattr2(item,attr,alt) (tnoun(item)?noun[item-first_noun].attr:(alt))
#define nounattr(item,attr) nounattr2(item,attr,0)
#define objattr(item,attr) nounattr2(item,attr,creatattr(item,attr))
#define objattr2(item,attr,op3) nounattr2(item,attr,creatattr2(item,attr,op3))
#define roomattr2(item,attr,op3) (troom(item)?room[item-first_room].attr:(op3))


/* --------------------------------------------------------------------	*/
/* These are the macros that should usually be used to determine 	*/
/*  information about the objects in the game, unless the object type   */
/*  is definitely known  						*/
/* ------------------------------------------------------------------- 	*/

#define it_name(item) objattr2(item,name,(item<0) ? -item : 0)
#define it_lockable(item)  nounattr2(item,lockable, (tdoor(item) ? 1 : 0) )
#define it_locked(item) nounattr2(item,locked,\
				  (tdoor(item) && room[loc].locked_door ? \
				   1 : 0))
#define it_on(item) nounattr(item,on)
#define it_group(item) creatattr(item,groupmemb)
#define it_adj(item) objattr(item,adj)
#define it_pushable(item) nounattr(item,pushable)
#define it_pullable(item) nounattr(item,pullable)
#define it_turnable(item) nounattr(item,turnable)
#define it_playable(item) nounattr(item,playable) 
#define it_plur(item) nounattr(item,sing_plur)
#define it_gender(item) creatattr(item,gender)

#define it_loc(item) objattr2(item,location,\
			      (tdoor(item)) ? loc+first_room : 0)
#define it_open(item) nounattr2(item,open, tcreat(item) || \
				(tdoor(item) && !room[loc].locked_door))
#define it_next(item) objattr(item,next)
#define it_contents(item) objattr2(item,contents,\
				   roomattr2(item,contents,\
					     (item==1) ? player_contents : \
					     (item==1000) ? player_worn : 0))


#ifdef global_defined_exec
#undef global
#undef global_defined_exec
#endif


