1 /* $Id: ai.h,v 1.5 2003/03/27 01:23:18 btb Exp $ */ 2 /* 3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX 4 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO 5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A 6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS 7 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS 8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE 9 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE 10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS 11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. 12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. 13 */ 14 15 /* 16 * 17 * Header file for AI system. 18 * 19 * Old Log: 20 * Revision 1.3 1995/10/15 16:28:07 allender 21 * added flag to player_is_visible function 22 * 23 * Revision 1.2 1995/10/10 11:48:32 allender 24 * PC ai header 25 * 26 * Revision 1.1 1995/05/16 15:54:00 allender 27 * Initial revision 28 * 29 * Revision 2.0 1995/02/27 11:33:07 john 30 * New version 2.0, which has no anonymous unions, builds with 31 * Watcom 10.0, and doesn't require parsing BITMAPS.TBL. 32 * 33 * Revision 1.57 1995/02/04 17:28:31 mike 34 * make station guys return better. 35 * 36 * Revision 1.56 1995/02/04 10:03:23 mike 37 * Fly to exit cheat. 38 * 39 * Revision 1.55 1995/02/01 19:23:52 rob 40 * Externed a boss var. 41 * 42 * Revision 1.54 1995/01/30 13:00:58 mike 43 * Make robots fire at player other than one they are controlled by sometimes. 44 * 45 * Revision 1.53 1995/01/26 15:09:16 rob 46 * Changed robot gating to accomodate multiplayer. 47 * 48 * Revision 1.52 1995/01/26 12:23:12 rob 49 * Added new externs needed for multiplayer. 50 * 51 * Revision 1.51 1995/01/21 21:22:14 mike 52 * Kill prototype of init_boss_segments, which didn't need to be public 53 * and had changed. 54 * 55 * Revision 1.50 1995/01/16 19:24:29 mike 56 * Publicize BOSS_GATE_MATCEN_NUM and Boss_been_hit. 57 * 58 * Revision 1.49 1995/01/02 16:17:35 mike 59 * prototype some super boss function for gameseq. 60 * 61 * Revision 1.48 1994/12/19 17:08:06 mike 62 * deal with new ai_multiplayer_awareness which returns a value saying whether this object can be moved by this player. 63 * 64 * Revision 1.47 1994/12/12 17:18:04 mike 65 * make boss cloak/teleport when get hit, make quad laser 3/4 as powerful. 66 * 67 * Revision 1.46 1994/12/08 15:46:16 mike 68 * better robot behavior. 69 * 70 * Revision 1.45 1994/11/27 23:16:08 matt 71 * Made debug code go away when debugging turned off 72 * 73 * Revision 1.44 1994/11/16 23:38:41 mike 74 * new improved boss teleportation behavior. 75 * 76 * Revision 1.43 1994/11/10 17:45:11 mike 77 * debugging. 78 * 79 * Revision 1.42 1994/11/07 10:37:42 mike 80 * hooks for rob's network code. 81 * 82 * Revision 1.41 1994/11/06 15:10:50 mike 83 * prototype a debug function for dumping ai info. 84 * 85 * Revision 1.40 1994/11/02 17:57:30 rob 86 * Added extern of Believe_player_pos needed to get control centers 87 * locating people. 88 * 89 * Revision 1.39 1994/10/28 19:43:39 mike 90 * Prototype Boss_cloak_start_time, Boss_cloak_end_time. 91 * 92 * Revision 1.38 1994/10/22 14:14:42 mike 93 * Prototype ai_reset_all_paths. 94 * 95 * Revision 1.37 1994/10/21 20:42:01 mike 96 * Define MAX_PATH_LENGTH: maximum allowed length of a path. 97 * 98 * Revision 1.36 1994/10/20 09:49:18 mike 99 * Prototype something. 100 * 101 * 102 * Revision 1.35 1994/10/18 15:37:52 mike 103 * Define ROBOT_BOSS1. 104 * 105 * Revision 1.34 1994/10/13 11:12:25 mike 106 * Prototype some door functions. 107 * 108 * Revision 1.33 1994/10/12 21:28:51 mike 109 * Prototype create_n_segment_path_to_door 110 * Prototype ai_open_doors_in_segment 111 * Prototype ai_door_is_openable. 112 * 113 * Revision 1.32 1994/10/11 15:59:41 mike 114 * Prototype Robot_firing_enabled. 115 * 116 * Revision 1.31 1994/10/09 22:02:48 mike 117 * Adapt create_path_points and create_n_segment_path prototypes to use avoid_seg for player evasion. 118 * 119 * Revision 1.30 1994/09/18 18:07:44 mike 120 * Update prototypes for create_path_points and create_path_to_player. 121 * 122 * Revision 1.29 1994/09/15 16:34:08 mike 123 * Prototype do_ai_robot_hit_attack. 124 * 125 * Revision 1.28 1994/09/12 19:12:35 mike 126 * Prototype attempt_to_resume_path. 127 * 128 * Revision 1.27 1994/08/25 21:55:32 mike 129 * Add some prototypes. 130 * 131 * Revision 1.26 1994/08/10 19:53:24 mike 132 * Prototype create_path_to_player and init_robots_for_level. 133 * 134 * Revision 1.25 1994/08/04 16:32:58 mike 135 * prototype create_path_to_player. 136 * 137 * Revision 1.24 1994/08/03 15:17:20 mike 138 * Prototype make_random_vector. 139 * 140 * Revision 1.23 1994/07/31 18:10:34 mike 141 * Update prototype for create_path_points. 142 * 143 * Revision 1.22 1994/07/28 12:36:14 matt 144 * Cleaned up object bumping code 145 * 146 */ 147 148 #ifndef _AI_H 149 #define _AI_H 150 151 #include <stdio.h> 152 153 #include "object.h" 154 #include "fvi.h" 155 #include "robot.h" 156 157 #define PLAYER_AWARENESS_INITIAL_TIME (3*F1_0) 158 #define MAX_PATH_LENGTH 30 // Maximum length of path in ai path following. 159 #define MAX_DEPTH_TO_SEARCH_FOR_PLAYER 10 160 #define BOSS_GATE_MATCEN_NUM -1 161 #define MAX_BOSS_TELEPORT_SEGS 100 162 #define BOSS_ECLIP_NUM 53 163 164 #define ROBOT_BRAIN 7 165 #define ROBOT_BOSS1 17 166 167 #define ROBOT_FIRE_AGITATION 94 168 169 #define BOSS_D2 21 // Minimum D2 boss value. 170 #define BOSS_COOL 21 171 #define BOSS_WATER 22 172 #define BOSS_FIRE 23 173 #define BOSS_ICE 24 174 #define BOSS_ALIEN1 25 175 #define BOSS_ALIEN2 26 176 177 #define NUM_D2_BOSSES 8 178 179 extern ubyte Boss_teleports[NUM_D2_BOSSES]; // Set byte if this boss can teleport 180 extern ubyte Boss_spew_more[NUM_D2_BOSSES]; // Set byte if this boss can teleport 181 //extern ubyte Boss_cloaks[NUM_D2_BOSSES]; // Set byte if this boss can cloak 182 extern ubyte Boss_spews_bots_energy[NUM_D2_BOSSES]; // Set byte if boss spews bots when hit by energy weapon. 183 extern ubyte Boss_spews_bots_matter[NUM_D2_BOSSES]; // Set byte if boss spews bots when hit by matter weapon. 184 extern ubyte Boss_invulnerable_energy[NUM_D2_BOSSES]; // Set byte if boss is invulnerable to energy weapons. 185 extern ubyte Boss_invulnerable_matter[NUM_D2_BOSSES]; // Set byte if boss is invulnerable to matter weapons. 186 extern ubyte Boss_invulnerable_spot[NUM_D2_BOSSES]; // Set byte if boss is invulnerable in all but a certain spot. (Dot product fvec|vec_to_collision < BOSS_INVULNERABLE_DOT) 187 188 extern fix Boss_cloak_start_time, Boss_cloak_end_time; 189 extern int Num_boss_teleport_segs; 190 extern short Boss_teleport_segs[MAX_BOSS_TELEPORT_SEGS]; 191 extern fix Last_teleport_time; 192 extern fix Boss_cloak_duration; 193 194 extern ai_local Ai_local_info[MAX_OBJECTS]; 195 extern vms_vector Believed_player_pos; 196 extern int Believed_player_seg; 197 198 extern void move_towards_segment_center(object *objp); 199 extern int gate_in_robot(int type, int segnum); 200 extern void do_ai_movement(object *objp); 201 extern void ai_move_to_new_segment( object * obj, short newseg, int first_time ); 202 // extern void ai_follow_path( object * obj, short newseg, int first_time ); 203 extern void ai_recover_from_wall_hit(object *obj, int segnum); 204 extern void ai_move_one(object *objp); 205 extern void do_ai_frame(object *objp); 206 extern void init_ai_object(int objnum, int initial_mode, int hide_segment); 207 extern void update_player_awareness(object *objp, fix new_awareness); 208 extern void create_awareness_event(object *objp, int type); // object *objp can create awareness of player, amount based on "type" 209 extern void do_ai_frame_all(void); 210 extern void init_ai_system(void); 211 extern void reset_ai_states(object *objp); 212 extern int create_path_points(object *objp, int start_seg, int end_seg, point_seg *point_segs, short *num_points, int max_depth, int random_flag, int safety_flag, int avoid_seg); 213 extern void create_all_paths(void); 214 extern void create_path_to_station(object *objp, int max_length); 215 extern void ai_follow_path(object *objp, int player_visibility, int previous_visibility, vms_vector *vec_to_player); 216 extern void ai_turn_towards_vector(vms_vector *vec_to_player, object *obj, fix rate); 217 extern void ai_turn_towards_vel_vec(object *objp, fix rate); 218 extern void init_ai_objects(void); 219 extern void do_ai_robot_hit(object *robot, int type); 220 extern void create_n_segment_path(object *objp, int path_length, int avoid_seg); 221 extern void create_n_segment_path_to_door(object *objp, int path_length, int avoid_seg); 222 extern void make_random_vector(vms_vector *vec); 223 extern void init_robots_for_level(void); 224 extern int ai_behavior_to_mode(int behavior); 225 extern int Robot_firing_enabled; 226 extern void create_path_to_segment(object *objp, int goalseg, int max_length, int safety_flag); 227 extern int ready_to_fire(robot_info *robptr, ai_local *ailp); 228 extern int polish_path(object *objp, point_seg *psegs, int num_points); 229 extern void move_towards_player(object *objp, vms_vector *vec_to_player); 230 231 // max_length is maximum depth of path to create. 232 // If -1, use default: MAX_DEPTH_TO_SEARCH_FOR_PLAYER 233 extern void create_path_to_player(object *objp, int max_length, int safety_flag); 234 extern void attempt_to_resume_path(object *objp); 235 236 // When a robot and a player collide, some robots attack! 237 extern void do_ai_robot_hit_attack(object *robot, object *player, vms_vector *collision_point); 238 extern void ai_open_doors_in_segment(object *robot); 239 extern int ai_door_is_openable(object *objp, segment *segp, int sidenum); 240 extern int player_is_visible_from_object(object *objp, vms_vector *pos, fix field_of_view, vms_vector *vec_to_player); 241 extern void ai_reset_all_paths(void); // Reset all paths. Call at the start of a level. 242 extern int ai_multiplayer_awareness(object *objp, int awareness_level); 243 244 // In escort.c 245 extern void do_escort_frame(object *objp, fix dist_to_player, int player_visibility); 246 extern void do_snipe_frame(object *objp, fix dist_to_player, int player_visibility, vms_vector *vec_to_player); 247 extern void do_thief_frame(object *objp, fix dist_to_player, int player_visibility, vms_vector *vec_to_player); 248 249 #ifndef NDEBUG 250 extern void force_dump_ai_objects_all(char *msg); 251 #else 252 #define force_dump_ai_objects_all(msg) 253 #endif 254 255 extern void start_boss_death_sequence(object *objp); 256 extern void ai_init_boss_for_ship(void); 257 extern int Boss_been_hit; 258 extern fix AI_proc_time; 259 260 // Stuff moved from ai.c by MK on 05/25/95. 261 #define ANIM_RATE (F1_0/16) 262 #define DELTA_ANG_SCALE 16 263 264 #define OVERALL_AGITATION_MAX 100 265 #define MAX_AI_CLOAK_INFO 8 // Must be a power of 2! 266 267 typedef struct { 268 fix last_time; 269 int last_segment; 270 vms_vector last_position; 271 } ai_cloak_info; 272 273 #define BOSS_CLOAK_DURATION (F1_0*7) 274 #define BOSS_DEATH_DURATION (F1_0*6) 275 276 #define CHASE_TIME_LENGTH (F1_0*8) 277 #define DEFAULT_ROBOT_SOUND_VOLUME F1_0 278 279 extern fix Dist_to_last_fired_upon_player_pos; 280 extern vms_vector Last_fired_upon_player_pos; 281 extern int Laser_rapid_fire; 282 283 #define MAX_AWARENESS_EVENTS 64 284 typedef struct awareness_event { 285 short segnum; // segment the event occurred in 286 short type; // type of event, defines behavior 287 vms_vector pos; // absolute 3 space location of event 288 } awareness_event; 289 290 #define AIS_MAX 8 291 #define AIE_MAX 4 292 293 #define ESCORT_GOAL_UNSPECIFIED -1 294 295 #define ESCORT_GOAL_UNSPECIFIED -1 296 #define ESCORT_GOAL_BLUE_KEY 1 297 #define ESCORT_GOAL_GOLD_KEY 2 298 #define ESCORT_GOAL_RED_KEY 3 299 #define ESCORT_GOAL_CONTROLCEN 4 300 #define ESCORT_GOAL_EXIT 5 301 302 // Custom escort goals. 303 #define ESCORT_GOAL_ENERGY 6 304 #define ESCORT_GOAL_ENERGYCEN 7 305 #define ESCORT_GOAL_SHIELD 8 306 #define ESCORT_GOAL_POWERUP 9 307 #define ESCORT_GOAL_ROBOT 10 308 #define ESCORT_GOAL_HOSTAGE 11 309 #define ESCORT_GOAL_PLAYER_SPEW 12 310 #define ESCORT_GOAL_SCRAM 13 311 #define ESCORT_GOAL_EXIT2 14 312 #define ESCORT_GOAL_BOSS 15 313 #define ESCORT_GOAL_MARKER1 16 314 #define ESCORT_GOAL_MARKER2 17 315 #define ESCORT_GOAL_MARKER3 18 316 #define ESCORT_GOAL_MARKER4 19 317 #define ESCORT_GOAL_MARKER5 20 318 #define ESCORT_GOAL_MARKER6 21 319 #define ESCORT_GOAL_MARKER7 22 320 #define ESCORT_GOAL_MARKER8 23 321 #define ESCORT_GOAL_MARKER9 24 322 323 #define MAX_ESCORT_GOALS 25 324 325 #define MAX_ESCORT_DISTANCE (F1_0*80) 326 #define MIN_ESCORT_DISTANCE (F1_0*40) 327 328 #define FUELCEN_CHECK 1000 329 330 extern fix Escort_last_path_created; 331 extern int Escort_goal_object, Escort_special_goal, Escort_goal_index; 332 333 #define GOAL_WIDTH 11 334 335 #define SNIPE_RETREAT_TIME (F1_0*5) 336 #define SNIPE_ABORT_RETREAT_TIME (SNIPE_RETREAT_TIME/2) // Can abort a retreat with this amount of time left in retreat 337 #define SNIPE_ATTACK_TIME (F1_0*10) 338 #define SNIPE_WAIT_TIME (F1_0*5) 339 #define SNIPE_FIRE_TIME (F1_0*2) 340 341 #define THIEF_PROBABILITY 16384 // 50% chance of stealing an item at each attempt 342 #define MAX_STOLEN_ITEMS 10 // Maximum number kept track of, will keep stealing, causes stolen weapons to be lost! 343 344 extern int Max_escort_length; 345 extern int Escort_kill_object; 346 extern ubyte Stolen_items[MAX_STOLEN_ITEMS]; 347 extern fix Escort_last_path_created; 348 extern int Escort_goal_object, Escort_special_goal, Escort_goal_index; 349 350 extern void create_buddy_bot(void); 351 352 extern int Max_escort_length; 353 354 extern char *Escort_goal_text[MAX_ESCORT_GOALS]; 355 356 extern void ai_multi_send_robot_position(int objnum, int force); 357 358 extern int Flinch_scale; 359 extern int Attack_scale; 360 extern byte Mike_to_matt_xlate[]; 361 362 // Amount of time since the current robot was last processed for things such as movement. 363 // It is not valid to use FrameTime because robots do not get moved every frame. 364 365 extern int Num_boss_teleport_segs; 366 extern short Boss_teleport_segs[]; 367 extern int Num_boss_gate_segs; 368 extern short Boss_gate_segs[]; 369 370 371 // --------- John: These variables must be saved as part of gamesave. --------- 372 extern int Ai_initialized; 373 extern int Overall_agitation; 374 extern ai_local Ai_local_info[MAX_OBJECTS]; 375 extern point_seg Point_segs[MAX_POINT_SEGS]; 376 extern point_seg *Point_segs_free_ptr; 377 extern ai_cloak_info Ai_cloak_info[MAX_AI_CLOAK_INFO]; 378 extern fix Boss_cloak_start_time; 379 extern fix Boss_cloak_end_time; 380 extern fix Last_teleport_time; 381 extern fix Boss_teleport_interval; 382 extern fix Boss_cloak_interval; // Time between cloaks 383 extern fix Boss_cloak_duration; 384 extern fix Last_gate_time; 385 extern fix Gate_interval; 386 extern fix Boss_dying_start_time; 387 extern byte Boss_dying, Boss_dying_sound_playing; 388 extern fix Boss_hit_time; 389 // -- extern int Boss_been_hit; 390 // ------ John: End of variables which must be saved as part of gamesave. ----- 391 392 extern int ai_evaded; 393 394 extern byte Super_boss_gate_list[]; 395 #define MAX_GATE_INDEX 25 396 397 extern int Ai_info_enabled; 398 extern int Robot_firing_enabled; 399 400 401 // These globals are set by a call to find_vector_intersection, which is a slow routine, 402 // so we don't want to call it again (for this object) unless we have to. 403 extern vms_vector Hit_pos; 404 extern int Hit_type, Hit_seg; 405 extern fvi_info Hit_data; 406 407 extern int Num_awareness_events; 408 extern awareness_event Awareness_events[MAX_AWARENESS_EVENTS]; 409 410 extern vms_vector Believed_player_pos; 411 412 #ifndef NDEBUG 413 // Index into this array with ailp->mode 414 extern char *mode_text[18]; 415 416 // Index into this array with aip->behavior 417 extern char behavior_text[6][9]; 418 419 // Index into this array with aip->GOAL_STATE or aip->CURRENT_STATE 420 extern char state_text[8][5]; 421 422 extern int Do_ai_flag, Break_on_object; 423 424 extern void mprintf_animation_info(object *objp); 425 426 #endif //ifndef NDEBUG 427 428 extern int Stolen_item_index; // Used in ai.c for controlling rate of Thief flare firing. 429 430 extern void ai_frame_animation(object *objp); 431 extern int do_silly_animation(object *objp); 432 extern int openable_doors_in_segment(int segnum); 433 extern void compute_vis_and_vec(object *objp, vms_vector *pos, ai_local *ailp, vms_vector *vec_to_player, int *player_visibility, robot_info *robptr, int *flag); 434 extern void do_firing_stuff(object *obj, int player_visibility, vms_vector *vec_to_player); 435 extern int maybe_ai_do_actual_firing_stuff(object *obj, ai_static *aip); 436 extern void ai_do_actual_firing_stuff(object *obj, ai_static *aip, ai_local *ailp, robot_info *robptr, vms_vector *vec_to_player, fix dist_to_player, vms_vector *gun_point, int player_visibility, int object_animates, int gun_num); 437 extern void do_super_boss_stuff(object *objp, fix dist_to_player, int player_visibility); 438 extern void do_boss_stuff(object *objp, int player_visibility); 439 // -- unused, 08/07/95 -- extern void ai_turn_randomly(vms_vector *vec_to_player, object *obj, fix rate, int previous_visibility); 440 extern void ai_move_relative_to_player(object *objp, ai_local *ailp, fix dist_to_player, vms_vector *vec_to_player, fix circle_distance, int evade_only, int player_visibility); 441 extern void move_away_from_player(object *objp, vms_vector *vec_to_player, int attack_type); 442 extern void move_towards_vector(object *objp, vms_vector *vec_goal, int dot_based); 443 extern void init_ai_frame(void); 444 445 extern void create_bfs_list(int start_seg, short bfs_list[], int *length, int max_segs); 446 extern void init_thief_for_level(); 447 448 449 extern int Escort_goal_object; 450 451 extern int ai_save_state( FILE * fp ); 452 extern int ai_restore_state( FILE * fp, int version ); 453 454 extern int Buddy_objnum, Buddy_allowed_to_talk; 455 456 extern void start_robot_death_sequence(object *objp); 457 extern int do_any_robot_dying_frame(object *objp); 458 extern void buddy_message(char * format, ... ); 459 460 #define SPECIAL_REACTOR_ROBOT 65 461 extern void special_reactor_stuff(void); 462 463 #endif /* _AI_H */ 464