Quake-III-Arena

Quake III Arena GPL Source Release
Log | Files | Refs

ai_main.h (13999B)


      1 /*
      2 ===========================================================================
      3 Copyright (C) 1999-2005 Id Software, Inc.
      4 
      5 This file is part of Quake III Arena source code.
      6 
      7 Quake III Arena source code is free software; you can redistribute it
      8 and/or modify it under the terms of the GNU General Public License as
      9 published by the Free Software Foundation; either version 2 of the License,
     10 or (at your option) any later version.
     11 
     12 Quake III Arena source code is distributed in the hope that it will be
     13 useful, 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 Foobar; if not, write to the Free Software
     19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
     20 ===========================================================================
     21 */
     22 //
     23 
     24 /*****************************************************************************
     25  * name:		ai_main.h
     26  *
     27  * desc:		Quake3 bot AI
     28  *
     29  * $Archive: /source/code/botai/ai_chat.c $
     30  *
     31  *****************************************************************************/
     32 
     33 //#define DEBUG
     34 #define CTF
     35 
     36 #define MAX_ITEMS					256
     37 //bot flags
     38 #define BFL_STRAFERIGHT				1	//strafe to the right
     39 #define BFL_ATTACKED				2	//bot has attacked last ai frame
     40 #define BFL_ATTACKJUMPED			4	//bot jumped during attack last frame
     41 #define BFL_AIMATENEMY				8	//bot aimed at the enemy this frame
     42 #define BFL_AVOIDRIGHT				16	//avoid obstacles by going to the right
     43 #define BFL_IDEALVIEWSET			32	//bot has ideal view angles set
     44 #define BFL_FIGHTSUICIDAL			64	//bot is in a suicidal fight
     45 //long term goal types
     46 #define LTG_TEAMHELP				1	//help a team mate
     47 #define LTG_TEAMACCOMPANY			2	//accompany a team mate
     48 #define LTG_DEFENDKEYAREA			3	//defend a key area
     49 #define LTG_GETFLAG					4	//get the enemy flag
     50 #define LTG_RUSHBASE				5	//rush to the base
     51 #define LTG_RETURNFLAG				6	//return the flag
     52 #define LTG_CAMP					7	//camp somewhere
     53 #define LTG_CAMPORDER				8	//ordered to camp somewhere
     54 #define LTG_PATROL					9	//patrol
     55 #define LTG_GETITEM					10	//get an item
     56 #define LTG_KILL					11	//kill someone
     57 #define LTG_HARVEST					12	//harvest skulls
     58 #define LTG_ATTACKENEMYBASE			13	//attack the enemy base
     59 #define LTG_MAKELOVE_UNDER			14
     60 #define LTG_MAKELOVE_ONTOP			15
     61 //some goal dedication times
     62 #define TEAM_HELP_TIME				60	//1 minute teamplay help time
     63 #define TEAM_ACCOMPANY_TIME			600	//10 minutes teamplay accompany time
     64 #define TEAM_DEFENDKEYAREA_TIME		600	//10 minutes ctf defend base time
     65 #define TEAM_CAMP_TIME				600	//10 minutes camping time
     66 #define TEAM_PATROL_TIME			600	//10 minutes patrolling time
     67 #define TEAM_LEAD_TIME				600	//10 minutes taking the lead
     68 #define TEAM_GETITEM_TIME			60	//1 minute
     69 #define	TEAM_KILL_SOMEONE			180	//3 minute to kill someone
     70 #define TEAM_ATTACKENEMYBASE_TIME	600	//10 minutes
     71 #define TEAM_HARVEST_TIME			120	//2 minutes
     72 #define CTF_GETFLAG_TIME			600	//10 minutes ctf get flag time
     73 #define CTF_RUSHBASE_TIME			120	//2 minutes ctf rush base time
     74 #define CTF_RETURNFLAG_TIME			180	//3 minutes to return the flag
     75 #define CTF_ROAM_TIME				60	//1 minute ctf roam time
     76 //patrol flags
     77 #define PATROL_LOOP					1
     78 #define PATROL_REVERSE				2
     79 #define PATROL_BACK					4
     80 //teamplay task preference
     81 #define TEAMTP_DEFENDER				1
     82 #define TEAMTP_ATTACKER				2
     83 //CTF strategy
     84 #define CTFS_AGRESSIVE				1
     85 //copied from the aas file header
     86 #define PRESENCE_NONE				1
     87 #define PRESENCE_NORMAL				2
     88 #define PRESENCE_CROUCH				4
     89 //
     90 #define MAX_PROXMINES				64
     91 
     92 //check points
     93 typedef struct bot_waypoint_s
     94 {
     95 	int			inuse;
     96 	char		name[32];
     97 	bot_goal_t	goal;
     98 	struct		bot_waypoint_s *next, *prev;
     99 } bot_waypoint_t;
    100 
    101 #define MAX_ACTIVATESTACK		8
    102 #define MAX_ACTIVATEAREAS		32
    103 
    104 typedef struct bot_activategoal_s
    105 {
    106 	int inuse;
    107 	bot_goal_t goal;						//goal to activate (buttons etc.)
    108 	float time;								//time to activate something
    109 	float start_time;						//time starting to activate something
    110 	float justused_time;					//time the goal was used
    111 	int shoot;								//true if bot has to shoot to activate
    112 	int weapon;								//weapon to be used for activation
    113 	vec3_t target;							//target to shoot at to activate something
    114 	vec3_t origin;							//origin of the blocking entity to activate
    115 	int areas[MAX_ACTIVATEAREAS];			//routing areas disabled by blocking entity
    116 	int numareas;							//number of disabled routing areas
    117 	int areasdisabled;						//true if the areas are disabled for the routing
    118 	struct bot_activategoal_s *next;		//next activate goal on stack
    119 } bot_activategoal_t;
    120 
    121 //bot state
    122 typedef struct bot_state_s
    123 {
    124 	int inuse;										//true if this state is used by a bot client
    125 	int botthink_residual;							//residual for the bot thinks
    126 	int client;										//client number of the bot
    127 	int entitynum;									//entity number of the bot
    128 	playerState_t cur_ps;							//current player state
    129 	int last_eFlags;								//last ps flags
    130 	usercmd_t lastucmd;								//usercmd from last frame
    131 	int entityeventTime[1024];						//last entity event time
    132 	//
    133 	bot_settings_t settings;						//several bot settings
    134 	int (*ainode)(struct bot_state_s *bs);			//current AI node
    135 	float thinktime;								//time the bot thinks this frame
    136 	vec3_t origin;									//origin of the bot
    137 	vec3_t velocity;								//velocity of the bot
    138 	int presencetype;								//presence type of the bot
    139 	vec3_t eye;										//eye coordinates of the bot
    140 	int areanum;									//the number of the area the bot is in
    141 	int inventory[MAX_ITEMS];						//string with items amounts the bot has
    142 	int tfl;										//the travel flags the bot uses
    143 	int flags;										//several flags
    144 	int respawn_wait;								//wait until respawned
    145 	int lasthealth;									//health value previous frame
    146 	int lastkilledplayer;							//last killed player
    147 	int lastkilledby;								//player that last killed this bot
    148 	int botdeathtype;								//the death type of the bot
    149 	int enemydeathtype;								//the death type of the enemy
    150 	int botsuicide;									//true when the bot suicides
    151 	int enemysuicide;								//true when the enemy of the bot suicides
    152 	int setupcount;									//true when the bot has just been setup
    153 	int map_restart;									//true when the map is being restarted
    154 	int entergamechat;								//true when the bot used an enter game chat
    155 	int num_deaths;									//number of time this bot died
    156 	int num_kills;									//number of kills of this bot
    157 	int revenge_enemy;								//the revenge enemy
    158 	int revenge_kills;								//number of kills the enemy made
    159 	int lastframe_health;							//health value the last frame
    160 	int lasthitcount;								//number of hits last frame
    161 	int chatto;										//chat to all or team
    162 	float walker;									//walker charactertic
    163 	float ltime;									//local bot time
    164 	float entergame_time;							//time the bot entered the game
    165 	float ltg_time;									//long term goal time
    166 	float nbg_time;									//nearby goal time
    167 	float respawn_time;								//time the bot takes to respawn
    168 	float respawnchat_time;							//time the bot started a chat during respawn
    169 	float chase_time;								//time the bot will chase the enemy
    170 	float enemyvisible_time;						//time the enemy was last visible
    171 	float check_time;								//time to check for nearby items
    172 	float stand_time;								//time the bot is standing still
    173 	float lastchat_time;							//time the bot last selected a chat
    174 	float kamikaze_time;							//time to check for kamikaze usage
    175 	float invulnerability_time;						//time to check for invulnerability usage
    176 	float standfindenemy_time;						//time to find enemy while standing
    177 	float attackstrafe_time;						//time the bot is strafing in one dir
    178 	float attackcrouch_time;						//time the bot will stop crouching
    179 	float attackchase_time;							//time the bot chases during actual attack
    180 	float attackjump_time;							//time the bot jumped during attack
    181 	float enemysight_time;							//time before reacting to enemy
    182 	float enemydeath_time;							//time the enemy died
    183 	float enemyposition_time;						//time the position and velocity of the enemy were stored
    184 	float defendaway_time;							//time away while defending
    185 	float defendaway_range;							//max travel time away from defend area
    186 	float rushbaseaway_time;						//time away from rushing to the base
    187 	float attackaway_time;							//time away from attacking the enemy base
    188 	float harvestaway_time;							//time away from harvesting
    189 	float ctfroam_time;								//time the bot is roaming in ctf
    190 	float killedenemy_time;							//time the bot killed the enemy
    191 	float arrive_time;								//time arrived (at companion)
    192 	float lastair_time;								//last time the bot had air
    193 	float teleport_time;							//last time the bot teleported
    194 	float camp_time;								//last time camped
    195 	float camp_range;								//camp range
    196 	float weaponchange_time;						//time the bot started changing weapons
    197 	float firethrottlewait_time;					//amount of time to wait
    198 	float firethrottleshoot_time;					//amount of time to shoot
    199 	float notblocked_time;							//last time the bot was not blocked
    200 	float blockedbyavoidspot_time;					//time blocked by an avoid spot
    201 	float predictobstacles_time;					//last time the bot predicted obstacles
    202 	int predictobstacles_goalareanum;				//last goal areanum the bot predicted obstacles for
    203 	vec3_t aimtarget;
    204 	vec3_t enemyvelocity;							//enemy velocity 0.5 secs ago during battle
    205 	vec3_t enemyorigin;								//enemy origin 0.5 secs ago during battle
    206 	//
    207 	int kamikazebody;								//kamikaze body
    208 	int proxmines[MAX_PROXMINES];
    209 	int numproxmines;
    210 	//
    211 	int character;									//the bot character
    212 	int ms;											//move state of the bot
    213 	int gs;											//goal state of the bot
    214 	int cs;											//chat state of the bot
    215 	int ws;											//weapon state of the bot
    216 	//
    217 	int enemy;										//enemy entity number
    218 	int lastenemyareanum;							//last reachability area the enemy was in
    219 	vec3_t lastenemyorigin;							//last origin of the enemy in the reachability area
    220 	int weaponnum;									//current weapon number
    221 	vec3_t viewangles;								//current view angles
    222 	vec3_t ideal_viewangles;						//ideal view angles
    223 	vec3_t viewanglespeed;
    224 	//
    225 	int ltgtype;									//long term goal type
    226 	// team goals
    227 	int teammate;									//team mate involved in this team goal
    228 	int decisionmaker;								//player who decided to go for this goal
    229 	int ordered;									//true if ordered to do something
    230 	float order_time;								//time ordered to do something
    231 	int owndecision_time;							//time the bot made it's own decision
    232 	bot_goal_t teamgoal;							//the team goal
    233 	bot_goal_t altroutegoal;						//alternative route goal
    234 	float reachedaltroutegoal_time;					//time the bot reached the alt route goal
    235 	float teammessage_time;							//time to message team mates what the bot is doing
    236 	float teamgoal_time;							//time to stop helping team mate
    237 	float teammatevisible_time;						//last time the team mate was NOT visible
    238 	int teamtaskpreference;							//team task preference
    239 	// last ordered team goal
    240 	int lastgoal_decisionmaker;
    241 	int lastgoal_ltgtype;
    242 	int lastgoal_teammate;
    243 	bot_goal_t lastgoal_teamgoal;
    244 	// for leading team mates
    245 	int lead_teammate;								//team mate the bot is leading
    246 	bot_goal_t lead_teamgoal;						//team goal while leading
    247 	float lead_time;								//time leading someone
    248 	float leadvisible_time;							//last time the team mate was visible
    249 	float leadmessage_time;							//last time a messaged was sent to the team mate
    250 	float leadbackup_time;							//time backing up towards team mate
    251 	//
    252 	char teamleader[32];							//netname of the team leader
    253 	float askteamleader_time;						//time asked for team leader
    254 	float becometeamleader_time;					//time the bot will become the team leader
    255 	float teamgiveorders_time;						//time to give team orders
    256 	float lastflagcapture_time;						//last time a flag was captured
    257 	int numteammates;								//number of team mates
    258 	int redflagstatus;								//0 = at base, 1 = not at base
    259 	int blueflagstatus;								//0 = at base, 1 = not at base
    260 	int neutralflagstatus;							//0 = at base, 1 = our team has flag, 2 = enemy team has flag, 3 = enemy team dropped the flag
    261 	int flagstatuschanged;							//flag status changed
    262 	int forceorders;								//true if forced to give orders
    263 	int flagcarrier;								//team mate carrying the enemy flag
    264 	int ctfstrategy;								//ctf strategy
    265 	char subteam[32];								//sub team name
    266 	float formation_dist;							//formation team mate intervening space
    267 	char formation_teammate[16];					//netname of the team mate the bot uses for relative positioning
    268 	float formation_angle;							//angle relative to the formation team mate
    269 	vec3_t formation_dir;							//the direction the formation is moving in
    270 	vec3_t formation_origin;						//origin the bot uses for relative positioning
    271 	bot_goal_t formation_goal;						//formation goal
    272 
    273 	bot_activategoal_t *activatestack;				//first activate goal on the stack
    274 	bot_activategoal_t activategoalheap[MAX_ACTIVATESTACK];	//activate goal heap
    275 
    276 	bot_waypoint_t *checkpoints;					//check points
    277 	bot_waypoint_t *patrolpoints;					//patrol points
    278 	bot_waypoint_t *curpatrolpoint;					//current patrol point the bot is going for
    279 	int patrolflags;								//patrol flags
    280 } bot_state_t;
    281 
    282 //resets the whole bot state
    283 void BotResetState(bot_state_t *bs);
    284 //returns the number of bots in the game
    285 int NumBots(void);
    286 //returns info about the entity
    287 void BotEntityInfo(int entnum, aas_entityinfo_t *info);
    288 
    289 extern float floattime;
    290 #define FloatTime() floattime
    291 
    292 // from the game source
    293 void	QDECL BotAI_Print(int type, char *fmt, ...);
    294 void	QDECL QDECL BotAI_BotInitialChat( bot_state_t *bs, char *type, ... );
    295 void	BotAI_Trace(bsp_trace_t *bsptrace, vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, int passent, int contentmask);
    296 int		BotAI_GetClientState( int clientNum, playerState_t *state );
    297 int		BotAI_GetEntityState( int entityNum, entityState_t *state );
    298 int		BotAI_GetSnapshotEntity( int clientNum, int sequence, entityState_t *state );
    299 int		BotTeamLeader(bot_state_t *bs);