/* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. */ /* * * Code for the control center * */ #include #include "error.h" #include "inferno.h" #include "cntrlcen.h" #include "game.h" #include "laser.h" #include "gameseq.h" #include "ai.h" #include "multi.h" #include "fuelcen.h" #include "wall.h" #include "object.h" #include "robot.h" #include "byteswap.h" vms_vector controlcen_gun_points[MAX_CONTROLCEN_GUNS]; vms_vector controlcen_gun_dirs[MAX_CONTROLCEN_GUNS]; control_center_triggers ControlCenterTriggers; int N_controlcen_guns; int Control_center_been_hit; int Control_center_player_been_seen; int Control_center_next_fire_time; int Control_center_present; vms_vector Gun_pos[MAX_CONTROLCEN_GUNS], Gun_dir[MAX_CONTROLCEN_GUNS]; // ----------------------------------------------------------------------------- //return the position & orientation of a gun on the control center object void calc_controlcen_gun_point(vms_vector *gun_point,vms_vector *gun_dir,object *obj,int gun_num) { vms_matrix m; Assert(obj->type == OBJ_CNTRLCEN); Assert(obj->render_type==RT_POLYOBJ); Assert(gun_num < N_controlcen_guns); //instance gun position & orientation vm_copy_transpose_matrix(&m,&obj->orient); vm_vec_rotate(gun_point,&controlcen_gun_points[gun_num],&m); vm_vec_add2(gun_point,&obj->pos); vm_vec_rotate(gun_dir,&controlcen_gun_dirs[gun_num],&m); } // ----------------------------------------------------------------------------- // Look at control center guns, find best one to fire at *objp. // Return best gun number (one whose direction dotted with vector to player is largest). // If best gun has negative dot, return -1, meaning no gun is good. int calc_best_gun(int num_guns, vms_vector *gun_pos, vms_vector *gun_dir, vms_vector *objpos) { int i; fix best_dot; int best_gun; best_dot = -F1_0*2; best_gun = -1; for (i=0; i best_dot) { best_dot = dot; best_gun = i; } } Assert(best_gun != -1); // Contact Mike. This is impossible. Or maybe you're getting an unnormalized vector somewhere. if (best_dot < 0) return -1; else return best_gun; } int Dead_controlcen_object_num=-1; // ----------------------------------------------------------------------------- // Called every frame. If control center been destroyed, then actually do something. void do_controlcen_dead_frame(void) { if (!Control_center_present) return; if ((Dead_controlcen_object_num != -1) && (Countdown_seconds_left > 0)) if (d_rand() < FrameTime*4) create_small_fireball_on_object(&Objects[Dead_controlcen_object_num], F1_0*3, 1); } // ----------------------------------------------------------------------------- // Called when control center gets destroyed. // This code is common to whether control center is implicitly imbedded in a boss, // or is an object of its own. // if objp == NULL that means the boss was the control center and don't set Dead_controlcen_object_num void do_controlcen_destroyed_stuff(object *objp) { int i; // Must toggle walls whether it is a boss or control center. for (i=0;isegnum]; // This is a hack. Since the control center is not processed by // ai_do_frame, it doesn't know to deal with cloaked dudes. It // seems to work in single-player mode because it is actually using // the value of Believed_player_position that was set by the last // person to go through ai_do_frame. But since a no-robots game // never goes through ai_do_frame, I'm making it so the control // center can spot cloaked dudes. #ifdef NETWORK if (Game_mode & GM_MULTI) Believed_player_pos = Objects[Players[Player_num].objnum].pos; #endif // Hack for special control centers which are isolated and not reachable because the // real control center is inside the boss. for (i=0; ichildren[i] != -1) break; if (i == MAX_SIDES_PER_SEGMENT) return; vm_vec_sub(&vec_to_player, &ConsoleObject->pos, &obj->pos); dist_to_player = vm_vec_normalize_quick(&vec_to_player); if (dist_to_player < F1_0*200) { Control_center_player_been_seen = player_is_visible_from_object(obj, &obj->pos, 0, &vec_to_player); Control_center_next_fire_time = 0; } } return; } if (Player_is_dead) controlcen_death_silence += FrameTime; else controlcen_death_silence = 0; if ((Control_center_next_fire_time < 0) && !(controlcen_death_silence > F1_0*2)) { if (Players[Player_num].flags & PLAYER_FLAGS_CLOAKED) best_gun_num = calc_best_gun(N_controlcen_guns, Gun_pos, Gun_dir, &Believed_player_pos); else best_gun_num = calc_best_gun(N_controlcen_guns, Gun_pos, Gun_dir, &ConsoleObject->pos); if (best_gun_num != -1) { vms_vector vec_to_goal; fix dist_to_player; fix delta_fire_time; if (Players[Player_num].flags & PLAYER_FLAGS_CLOAKED) { vm_vec_sub(&vec_to_goal, &Believed_player_pos, &Gun_pos[best_gun_num]); dist_to_player = vm_vec_normalize_quick(&vec_to_goal); } else { vm_vec_sub(&vec_to_goal, &ConsoleObject->pos, &Gun_pos[best_gun_num]); dist_to_player = vm_vec_normalize_quick(&vec_to_goal); } if (dist_to_player > F1_0*300) { Control_center_been_hit = 0; Control_center_player_been_seen = 0; return; } #ifdef NETWORK if (Game_mode & GM_MULTI) multi_send_controlcen_fire(&vec_to_goal, best_gun_num, obj-Objects); #endif Laser_create_new_easy( &vec_to_goal, &Gun_pos[best_gun_num], obj-Objects, CONTROLCEN_WEAPON_NUM, 1); // 1/4 of time, fire another thing, not directly at player, so it might hit him if he's constantly moving. if (d_rand() < 32767/4) { vms_vector randvec; make_random_vector(&randvec); vm_vec_scale_add2(&vec_to_goal, &randvec, F1_0/4); vm_vec_normalize_quick(&vec_to_goal); #ifdef NETWORK if (Game_mode & GM_MULTI) multi_send_controlcen_fire(&vec_to_goal, best_gun_num, obj-Objects); #endif Laser_create_new_easy( &vec_to_goal, &Gun_pos[best_gun_num], obj-Objects, CONTROLCEN_WEAPON_NUM, 1); } delta_fire_time = (NDL - Difficulty_level) * F1_0/4; #ifdef NETWORK if (Game_mode & GM_MULTI) // slow down rate of fire in multi player delta_fire_time *= 2; #endif Control_center_next_fire_time = delta_fire_time; } } else Control_center_next_fire_time -= FrameTime; } // ----------------------------------------------------------------------------- // This must be called at the start of each level. // If this level contains a boss and mode != multiplayer, don't do control center stuff. (Ghost out control center object.) // If this level contains a boss and mode == multiplayer, do control center stuff. void init_controlcen_for_level(void) { int i; object *objp; int cntrlcen_objnum=-1, boss_objnum=-1; for (i=0; i<=Highest_object_index; i++) { objp = &Objects[i]; if (objp->type == OBJ_CNTRLCEN) { if (cntrlcen_objnum != -1) ; else cntrlcen_objnum = i; } if ((objp->type == OBJ_ROBOT) && (Robot_info[objp->id].boss_flag)) { if (boss_objnum != -1) ; else boss_objnum = i; } } #ifndef NDEBUG if (cntrlcen_objnum == -1) { return; } #endif #ifdef NETWORK if ( (boss_objnum != -1) && !((Game_mode & GM_MULTI) && !(Game_mode & GM_MULTI_ROBOTS)) ) #else if (boss_objnum != -1) #endif { if (cntrlcen_objnum != -1) { // note link to above!!! Objects[cntrlcen_objnum].type = OBJ_GHOST; Objects[cntrlcen_objnum].render_type = RT_NONE; Control_center_present = 0; } } else { // Compute all gun positions. objp = &Objects[cntrlcen_objnum]; for (i=0; i= 0) objp->shields = F1_0*200 + (F1_0*200/4) * Current_level_num; else objp->shields = F1_0*200 - Current_level_num*F1_0*100; } // Say the control center has not yet been hit. Control_center_been_hit = 0; Control_center_player_been_seen = 0; Control_center_next_fire_time = 0; Dead_controlcen_object_num = -1; } /* * reads a control_center_triggers structure from a CFILE */ extern int control_center_triggers_read_n(control_center_triggers *cct, int n, CFILE *fp) { int i, j; for (i = 0; i < n; i++) { cct->num_links = cfile_read_short(fp); for (j = 0; j < MAX_WALLS_PER_LINK; j++) cct->seg[j] = cfile_read_short(fp); for (j = 0; j < MAX_WALLS_PER_LINK; j++) cct->side[j] = cfile_read_short(fp); } return i; } void control_center_triggers_swap(control_center_triggers *cct, int swap) { int i; if (!swap) return; cct->num_links = SWAPSHORT(cct->num_links); for (i = 0; i < MAX_WALLS_PER_LINK; i++) cct->seg[i] = SWAPSHORT(cct->seg[i]); for (i = 0; i < MAX_WALLS_PER_LINK; i++) cct->side[i] = SWAPSHORT(cct->side[i]); } /* * reads n control_center_triggers structs from a CFILE and swaps if specified */ void control_center_triggers_read_n_swap(control_center_triggers *cct, int n, int swap, CFILE *fp) { int i; PHYSFS_read(fp, cct, sizeof(control_center_triggers), n); if (swap) for (i = 0; i < n; i++) control_center_triggers_swap(&cct[i], swap); } int control_center_triggers_write(control_center_triggers *cct, PHYSFS_file *fp) { int j; PHYSFS_writeSLE16(fp, cct->num_links); for (j = 0; j < MAX_CONTROLCEN_LINKS; j++) PHYSFS_writeSLE16(fp, cct->seg[j]); for (j = 0; j < MAX_CONTROLCEN_LINKS; j++) PHYSFS_writeSLE16(fp, cct->side[j]); return 1; }