/*  mapC interpreter interface file

  This file declares the basic constructs and operators of the mapC
  language, as well as the interface between the interpreter and
  the bytecode.
*/

#mapinfo
	"interface_version" "0.75"


#operators   // in order of precedence
! NOT	// NOT is identical to !  (logical negation)
~ 		// binary negation  (flips all the bits)
%
^		// ^ is higher precedence than it's other bitwise friends
/		// because it gets used as a unary operator as well
*
+ -
& | IN	// IN is identical to &
== != >= <= > <
OR AND					// ||, && have been replaced by OR, AND
= 						// assignment operator
+= -= &= |= *= /= 		// self-inclusive operators

// note that period . is a reserved operator, and is non-configurable 

#operator_map
int = int = int
int + int = int
int - int = int		
int * int = int
int / int = int  // integer division (the result is rounded down)
int % int = int  // modulo  (returns the remainder from division of the ints)
int | int = int  // OR
int & int = int  // AND
int IN int = int // AND
int ^ int = int  // XOR  (when would you ever need this?)
int AND int = int
int OR int = int
int == int = int
int != int = int
int > int = int
int < int = int
int <= int = int
int >= int = int
- int = int
! int = int
NOT int = int
~ int = int

int += int = int
int -= int = int
int &= int = int	
int |= int = int
int *= int = int
int /= int = int

vector = vector = vector  
vector + vector = vector
vector - vector = vector
vector * vector = int    	// dot product
vector % vector = vector 	// cross product
vector == vector = int
vector != vector = int
vector * int = vector
vector / int = vector
- vector = vector
^ vector = vector		// unit vector 
% vector = int			// the length of the vector (%(^vec) == 1)
// tbd: self-inclusive operators for vectors

string = string = string	// copies the string 
string + string = string	// returns a reference to string 0
string == string = int
string != string = int
% string = int			// the length of the string
string += string = string  // concatonate

entity = entity = entity
entity == entity = int
entity != entity = int
entity IN entlist = int    // is the entity part of the list? 

entlist = entlist = entlist	// copies the entlist 
entlist += entlist = entlist  // concatonates entlists
entlist -= entlist = entlist
entlist += entity = entlist
entlist -= entity = entlist

entlist + entlist = entlist  // union
entlist - entlist = entlist	// set subtraction 
entlist % entlist = entlist	// set intersection
entlist + entity = entlist    // adds the entity to the end of the entlist
entlist - entity = entlist	// removes the entity from the entlist
entlist == entlist = int      // returns true if the lists are identical
entlist != entlist = int      // returns true if the lists are not identical 
entlist > entlist = int	// returns true if list2 is a true subset of list1
entlist < entlist = int	
entlist >= entlist = int	// returns true if list2 is a subset of list1
entlist <= entlist = int    // returns true if list1 is a subset of list2
^ entlist = entity		// pops the first entity off the entlist 
% entlist = int		// the length of the entlist

var = var = var
var == var = int
var != var = int

////////////////////////////////////////////////////////////////

#interface_vars
       
// global variables
readonly int time;  // time in tenths of seconds (600 = 60seconds)
readonly entity worldspawn;
readonly entlist player_list;
int     number_of_teams;

// global functions
string  int_to_str(int number);

entlist get_players(var var_to_check, string match);
entlist get_players(var var_to_check, int match);

entity  find_ent(entity ent, var var_to_check, string match);
entity  find_ent(entity ent, var var_to_check, int match);
entity  find_player(entity ent, var var_to_check, string match);
find_player(entity ent, var var_to_check, int match);

void    error(string cstring);

// Message Printing
void    dprint(int cint);
void    dprint(string cstring);
void    dprint(string cstring, string cstring2);
void    dprint(string cstring, string cstring2, string cstring3);
void    dprint(vector vec);
void    cprint(entity ent, int cint);
void    cprint(entity ent, string cstring);
void    cprint(entity ent, string cstring, string cstring2);
void    cprint(entity ent, string cstring, string cstring2, string cstring3);
void    tprint(int team_no, entity ignore, int cint);
void    tprint(int team_no, entity ignore, string cstring);
void    tprint(int team_no, entity ignore, string cstring, string cstring2);
void    tprint(int team_no, entity ignore, string cstring, string cstring2, string cstring3);
void    lprint(entlist players, int cint);
void    lprint(entlist players, string cstring);
void    lprint(entlist players, string cstring, string cstring2);
void    lprint(entlist players, string cstring, string cstring2, string cstring3);
void    update_status(entity ent, string cstring, int priority, string wav_file);

void    droptofloor(entity ent);
void    throw_object(entity ent, vector org);

// Remove  of specified item from client.  of 0 removes all.
void    remove_item(entity ent, string item_name, int quantity);
// Give  of specified item to client
void    add_item(entity ent, string item_name, int quantity);
// Returns the  of the specified item being carried by the client
int     get_num_items(entity ent, string item_name);

// Play sound to all players within hearing
void    play_sound(entity ent, string wav_file, int channel, int attenuation);
// Play sound to only one client
void    play_clientsound(entity ent, string wav_file, int channel, int attenuation);

// Precache functions
void    precache_sound(string wav_file);
void    precache_model(string mdl_file);

// Utility functions
int     random(int upper, int lower);

// Entity Creation/Destruction functions
entity  create_entity();
void    remove_entity(entity ent);

// Team Handling
void    team_set_name(int team_number, string team_name);
string  team_get_name(int team_number);
void    team_set_skin(int team_number, string skin_directory);
void    team_set_score(int team_number, int score);
void    team_set_frags(int team_number, int frags);
void    team_add_ally(int team_number, int ally_team_number);
void    team_remove_ally(int team_number, int ally_team_number);

////////////////////////////////////
// entity data
entity	entity::owner;

string  entity::classname;
int     entity::playerclass;
string  entity::model;

vector  entity::velocity;
vector  entity::avelocity;

vector  entity::origin;
int     entity::team_no;
int     entity::owned_by_team;
int     entity::flags;
int     entity::item_flags;
int     entity::svflags;
int     entity::solid;
string  entity::name;
int     entity::health;
int     entity::count;

int     entity::nextthink;

string  entity::command_str;
void()  entity::command_func;

// entity function ptrs.
void()      entity::think;
//void()	entity::use;
//void()	entity::touch;
//void()	entity::blocked;

// entity functions


///////////////////////////////////
// misc. types

// even the vector components are declared here
// because of the way the compiler handles in-line variables,
// the components of a vector are accessed as quickly as any
// normal int.
readonly int vector::ref; // the first DWORD of any vector is a reference to self. DO NOT USE.
int vector::x;
int vector::y;
int vector::z;

// constant values
const int FALSE = 0;
const int TRUE  = 1;

// maybe should add in a bitfield type?
const int LIGHT_INF	    = 1;
const int MEDIUM_INF    = 2;
const int HEAVY_INF	    = 4;
const int ROCKET_INF 	= 8;
const int SNIPER	    = 16;
const int COMMANDO	    = 32;
const int MEDIC 	    = 64;
const int ENGINEER	    = 128;
const int SPY           = 256;

// ent->svflags
const int SVF_NOCLIENT      = 1;
const int SVF_DEADMONSTER   = 2;
const int SVR_MONSTER       = 4;
// ent->flags
const int SOLID_NOT         = 0;        // no interaction with other objects
const int SOLID_TRIGGER     = 1;        // only touch when inside, after moving
const int SOLID_BBOX        = 2;        // touch on edge
const int SOLID_BSP         = 3;        // bsp clip, touch on edge
// ent->item_flags
const int IT_WEAPON 	    =	1;		// DO NOT TOUCH
const int IT_AMMO		    =	2;      // DO NOT TOUCH
const int IT_ARMOR		    =	4;      // DO NOT TOUCH
const int IT_GRENADE	    =	8;	    // DO NOT TOUCH
const int IT_DROPPABLE	    =   16;	    // can be dropped or left on bodies
const int IT_RESPAWN_KEEP	=   32;	    // kept even over a respawn
const int IT_NOT_VISIBLE	=   64;	    // invisible to the player
const int IT_INTRINSIC	    =   128;    // DO NOT TOUCH
const int IT_COMMAND		=   256;    // DO NOT TOUCH
const int IT_SILENCED		=   512;	// DO NOT TOUCH
const int IT_CUSTOM		    =   1024;   // DO NOT TOUCH


//////////////////////////////////////////////////////////////
// definitions for parameters passed thru to game functions
// play_sound & play_clientsound:   channel
const int CHAN_AUTO         =   0;
const int CHAN_WEAPON       =   1;
const int CHAN_VOICE        =   2;
const int CHAN_ITEM         =   3;
const int CHAN_BODY         =   4;
const int CHAN_NO_PHS_ADD	=   8;	// send to all clients, not just ones in PHS (ATTN 0 will also do this)
const int CHAN_RELIABLE		=   16;	// send by reliable message, not datagram
// play_sound & play_clientsound:   attenuation
const int ATTN_NONE         =   0;	// full volume the entire level
const int ATTN_NORM         =   1;
const int ATTN_IDLE         =   2;
const int ATTN_STATIC       =   3;	// diminish very rapidly with distance
// update_status                :   wav_file
const string WAV_ERROR      =   "misc/tf_error.wav";
// update_status                :   priority
const int PRINT_LOW			=   0;		// pickup messages
const int PRINT_MEDIUM		=   1;		// death messages
const int PRINT_HIGH		=	2;		// critical messages


//////////////////////////////////////////////////////////////
// script flag defines, mirrored in s_int.h

// script_dropitem
const int SF_DI_PLAYER_DEATH	=   1;
const int SF_DI_PLAYER_DROP	    =   2;
const int SF_DI_PLAYER_TRADE    =   4;


//////////////////////////////////////////////////////////////
// Team defines
const int TEAM1                 =   1;
const int TEAM2                 =   2;
const int TEAM3                 =   4;
const int TEAM4                 =   8;

#end	// this signifies the end of a section
		// unneeded here because it's the end of the file anyway