2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
16 * Code for the control center
26 #if !defined(_WIN32) && !defined(macintosh)
35 //@@vms_vector controlcen_gun_points[MAX_CONTROLCEN_GUNS];
36 //@@vms_vector controlcen_gun_dirs[MAX_CONTROLCEN_GUNS];
38 reactor Reactors[MAX_REACTORS];
41 control_center_triggers ControlCenterTriggers;
43 int N_controlcen_guns;
44 int Control_center_been_hit;
45 int Control_center_player_been_seen;
46 int Control_center_next_fire_time;
47 int Control_center_present;
49 vms_vector Gun_pos[MAX_CONTROLCEN_GUNS], Gun_dir[MAX_CONTROLCEN_GUNS];
51 void do_countdown_frame(void);
53 // -----------------------------------------------------------------------------
54 //return the position & orientation of a gun on the control center object
55 void calc_controlcen_gun_point(vms_vector *gun_point,vms_vector *gun_dir,object *obj,int gun_num)
60 Assert(obj->type == OBJ_CNTRLCEN);
61 Assert(obj->render_type==RT_POLYOBJ);
63 reactor = &Reactors[obj->id];
65 Assert(gun_num < reactor->n_guns);
67 //instance gun position & orientation
69 vm_copy_transpose_matrix(&m,&obj->orient);
71 vm_vec_rotate(gun_point,&reactor->gun_points[gun_num],&m);
72 vm_vec_add2(gun_point,&obj->pos);
73 vm_vec_rotate(gun_dir,&reactor->gun_dirs[gun_num],&m);
76 // -----------------------------------------------------------------------------
77 // Look at control center guns, find best one to fire at *objp.
78 // Return best gun number (one whose direction dotted with vector to player is largest).
79 // If best gun has negative dot, return -1, meaning no gun is good.
80 int calc_best_gun(int num_guns, vms_vector *gun_pos, vms_vector *gun_dir, vms_vector *objpos)
89 for (i=0; i<num_guns; i++) {
93 vm_vec_sub(&gun_vec, objpos, &gun_pos[i]);
94 vm_vec_normalize_quick(&gun_vec);
95 dot = vm_vec_dot(&gun_dir[i], &gun_vec);
103 Assert(best_gun != -1); // Contact Mike. This is impossible. Or maybe you're getting an unnormalized vector somewhere.
112 extern fix Player_time_of_death; // object.c
114 int Dead_controlcen_object_num=-1;
116 //how long to blow up on insane
117 int Base_control_center_explosion_time=DEFAULT_CONTROL_CENTER_EXPLOSION_TIME;
119 int Control_center_destroyed = 0;
120 fix Countdown_timer=0;
121 int Countdown_seconds_left=0, Total_countdown_time=0; //in whole seconds
123 int Alan_pavlish_reactor_times[NDL] = {90, 60, 45, 35, 30};
125 // -----------------------------------------------------------------------------
126 // Called every frame. If control center been destroyed, then actually do something.
127 void do_controlcen_dead_frame(void)
129 if ((Dead_controlcen_object_num != -1) && (Countdown_seconds_left > 0))
130 if (d_rand() < FrameTime*4)
131 create_small_fireball_on_object(&Objects[Dead_controlcen_object_num], F1_0, 1);
133 if (Control_center_destroyed && !Endlevel_sequence)
134 do_countdown_frame();
137 #define COUNTDOWN_VOICE_TIME fl2f(12.75)
139 void do_countdown_frame()
144 if (!Control_center_destroyed) return;
146 if (!is_D2_OEM && !is_MAC_SHARE && !is_SHAREWARE) // get countdown in OEM and SHAREWARE only
148 // On last level, we don't want a countdown.
149 if (PLAYING_BUILTIN_MISSION && Current_level_num == Last_level)
151 if (!(Game_mode & GM_MULTI))
153 if (Game_mode & GM_MULTI_ROBOTS)
158 // Control center destroyed, rock the player's ship.
159 fc = Countdown_seconds_left;
163 // At Trainee, decrease rocking of ship by 4x.
165 if (Difficulty_level == 0)
168 ConsoleObject->mtype.phys_info.rotvel.x += (fixmul(d_rand() - 16384, 3*F1_0/16 + (F1_0*(16-fc))/32))/div_scale;
169 ConsoleObject->mtype.phys_info.rotvel.z += (fixmul(d_rand() - 16384, 3*F1_0/16 + (F1_0*(16-fc))/32))/div_scale;
170 // Hook in the rumble sound effect here.
172 old_time = Countdown_timer;
173 Countdown_timer -= RealFrameTime;
174 Countdown_seconds_left = f2i(Countdown_timer + F1_0*7/8);
176 if ( (old_time > COUNTDOWN_VOICE_TIME ) && (Countdown_timer <= COUNTDOWN_VOICE_TIME) ) {
177 digi_play_sample( SOUND_COUNTDOWN_13_SECS, F3_0 );
179 if ( f2i(old_time + F1_0*7/8) != Countdown_seconds_left ) {
180 if ( (Countdown_seconds_left>=0) && (Countdown_seconds_left<10) )
181 digi_play_sample( SOUND_COUNTDOWN_0_SECS+Countdown_seconds_left, F3_0 );
182 if ( Countdown_seconds_left==Total_countdown_time-1)
183 digi_play_sample( SOUND_COUNTDOWN_29_SECS, F3_0 );
186 if (Countdown_timer > 0) {
188 size = (i2f(Total_countdown_time)-Countdown_timer) / fl2f(0.65);
189 old_size = (i2f(Total_countdown_time)-old_time) / fl2f(0.65);
190 if (size != old_size && (Countdown_seconds_left < (Total_countdown_time-5) )) { // Every 2 seconds!
191 //@@if (Dead_controlcen_object_num != -1) {
192 //@@ vms_vector vp; //,v,c;
193 //@@ compute_segment_center(&vp, &Segments[Objects[Dead_controlcen_object_num].segnum]);
194 //@@ object_create_explosion( Objects[Dead_controlcen_object_num].segnum, &vp, size*10, VCLIP_SMALL_EXPLOSION);
197 digi_play_sample( SOUND_CONTROL_CENTER_WARNING_SIREN, F3_0 );
203 digi_play_sample( SOUND_MINE_BLEW_UP, F1_0 );
205 flash_value = f2i(-Countdown_timer * (64 / 4)); // 4 seconds to total whiteness
206 PALETTE_FLASH_SET(flash_value,flash_value,flash_value);
208 if (PaletteBlueAdd > 64 ) {
209 gr_set_current_canvas( NULL );
210 gr_clear_canvas(BM_XRGB(31,31,31)); //make screen all white to match palette effect
211 reset_cockpit(); //force cockpit redraw next time
212 reset_palette_add(); //restore palette for death message
213 //controlcen->MaxCapacity = Fuelcen_max_amount;
214 //gauge_message( "Control Center Reset" );
215 DoPlayerDead(); //kill_player();
220 // -----------------------------------------------------------------------------
221 // Called when control center gets destroyed.
222 // This code is common to whether control center is implicitly imbedded in a boss,
223 // or is an object of its own.
224 // if objp == NULL that means the boss was the control center and don't set Dead_controlcen_object_num
225 void do_controlcen_destroyed_stuff(object *objp)
229 if ((Game_mode & GM_MULTI_ROBOTS) && Control_center_destroyed)
230 return; // Don't allow resetting if control center and boss on same level
232 // Must toggle walls whether it is a boss or control center.
233 for (i=0;i<ControlCenterTriggers.num_links;i++)
234 wall_toggle(&Segments[ControlCenterTriggers.seg[i]], ControlCenterTriggers.side[i]);
236 // And start the countdown stuff.
237 Control_center_destroyed = 1;
239 // If a secret level, delete secret.sgc to indicate that we can't return to our secret level.
240 if (Current_level_num < 0) {
242 rval = !PHYSFS_delete(PLAYER_DIR "secret.sgc");
243 mprintf((0, "Deleting secret.sgc, return value = %i\n", rval));
246 if (Base_control_center_explosion_time != DEFAULT_CONTROL_CENTER_EXPLOSION_TIME)
247 Total_countdown_time = Base_control_center_explosion_time + Base_control_center_explosion_time * (NDL-Difficulty_level-1)/2;
249 Total_countdown_time = Alan_pavlish_reactor_times[Difficulty_level];
251 Countdown_timer = i2f(Total_countdown_time);
253 if (!Control_center_present || objp==NULL) {
254 //Assert(objp == NULL);
258 //Assert(objp != NULL);
260 Dead_controlcen_object_num = OBJECT_NUMBER(objp);
263 int Last_time_cc_vis_check = 0;
265 // -----------------------------------------------------------------------------
266 //do whatever this thing does in a frame
267 void do_controlcen_frame(object *obj)
271 // If a boss level, then Control_center_present will be 0.
272 if (!Control_center_present)
276 if (!Robot_firing_enabled || (Game_suspended & SUSP_ROBOTS))
279 if (!Robot_firing_enabled)
283 if (!(Control_center_been_hit || Control_center_player_been_seen)) {
284 if (!(FrameCount % 8)) { // Do every so often...
285 vms_vector vec_to_player;
288 segment *segp = &Segments[obj->segnum];
290 // This is a hack. Since the control center is not processed by
291 // ai_do_frame, it doesn't know to deal with cloaked dudes. It
292 // seems to work in single-player mode because it is actually using
293 // the value of Believed_player_position that was set by the last
294 // person to go through ai_do_frame. But since a no-robots game
295 // never goes through ai_do_frame, I'm making it so the control
296 // center can spot cloaked dudes.
298 if (Game_mode & GM_MULTI)
299 Believed_player_pos = Objects[Players[Player_num].objnum].pos;
301 // Hack for special control centers which are isolated and not reachable because the
302 // real control center is inside the boss.
303 for (i=0; i<MAX_SIDES_PER_SEGMENT; i++)
304 if (IS_CHILD(segp->children[i]))
306 if (i == MAX_SIDES_PER_SEGMENT)
309 vm_vec_sub(&vec_to_player, &ConsoleObject->pos, &obj->pos);
310 dist_to_player = vm_vec_normalize_quick(&vec_to_player);
311 if (dist_to_player < F1_0*200) {
312 Control_center_player_been_seen = player_is_visible_from_object(obj, &obj->pos, 0, &vec_to_player);
313 Control_center_next_fire_time = 0;
320 // Periodically, make the reactor fall asleep if player not visible.
321 if (Control_center_been_hit || Control_center_player_been_seen) {
322 if ((Last_time_cc_vis_check + F1_0*5 < GameTime) || (Last_time_cc_vis_check > GameTime)) {
323 vms_vector vec_to_player;
326 vm_vec_sub(&vec_to_player, &ConsoleObject->pos, &obj->pos);
327 dist_to_player = vm_vec_normalize_quick(&vec_to_player);
328 Last_time_cc_vis_check = GameTime;
329 if (dist_to_player < F1_0*120) {
330 Control_center_player_been_seen = player_is_visible_from_object(obj, &obj->pos, 0, &vec_to_player);
331 if (!Control_center_player_been_seen)
332 Control_center_been_hit = 0;
338 if ((Control_center_next_fire_time < 0) && !(Player_is_dead && (GameTime > Player_time_of_death+F1_0*2))) {
339 if (Players[Player_num].flags & PLAYER_FLAGS_CLOAKED)
340 best_gun_num = calc_best_gun(N_controlcen_guns, Gun_pos, Gun_dir, &Believed_player_pos);
342 best_gun_num = calc_best_gun(N_controlcen_guns, Gun_pos, Gun_dir, &ConsoleObject->pos);
344 if (best_gun_num != -1) {
345 int rand_prob, count;
346 vms_vector vec_to_goal;
350 if (Players[Player_num].flags & PLAYER_FLAGS_CLOAKED) {
351 vm_vec_sub(&vec_to_goal, &Believed_player_pos, &Gun_pos[best_gun_num]);
352 dist_to_player = vm_vec_normalize_quick(&vec_to_goal);
354 vm_vec_sub(&vec_to_goal, &ConsoleObject->pos, &Gun_pos[best_gun_num]);
355 dist_to_player = vm_vec_normalize_quick(&vec_to_goal);
358 if (dist_to_player > F1_0*300)
360 Control_center_been_hit = 0;
361 Control_center_player_been_seen = 0;
366 if (Game_mode & GM_MULTI)
367 multi_send_controlcen_fire(&vec_to_goal, best_gun_num, OBJECT_NUMBER(obj));
369 Laser_create_new_easy( &vec_to_goal, &Gun_pos[best_gun_num], OBJECT_NUMBER(obj), CONTROLCEN_WEAPON_NUM, 1 );
371 // some of time, based on level, fire another thing, not directly at player, so it might hit him if he's constantly moving.
372 rand_prob = F1_0/(abs(Current_level_num)/4+2);
374 while ((d_rand() > rand_prob) && (count < 4)) {
377 make_random_vector(&randvec);
378 vm_vec_scale_add2(&vec_to_goal, &randvec, F1_0/6);
379 vm_vec_normalize_quick(&vec_to_goal);
381 if (Game_mode & GM_MULTI)
382 multi_send_controlcen_fire(&vec_to_goal, best_gun_num, OBJECT_NUMBER(obj));
384 Laser_create_new_easy( &vec_to_goal, &Gun_pos[best_gun_num], OBJECT_NUMBER(obj), CONTROLCEN_WEAPON_NUM, 0 );
388 delta_fire_time = (NDL - Difficulty_level) * F1_0/4;
389 if (Difficulty_level == 0)
390 delta_fire_time += F1_0/2;
392 if (Game_mode & GM_MULTI) // slow down rate of fire in multi player
393 delta_fire_time *= 2;
395 Control_center_next_fire_time = delta_fire_time;
399 Control_center_next_fire_time -= FrameTime;
403 int Reactor_strength=-1; //-1 mean not set by designer
405 // -----------------------------------------------------------------------------
406 // This must be called at the start of each level.
407 // If this level contains a boss and mode != multiplayer, don't do control center stuff. (Ghost out control center object.)
408 // If this level contains a boss and mode == multiplayer, do control center stuff.
409 void init_controlcen_for_level(void)
413 int cntrlcen_objnum=-1, boss_objnum=-1;
415 for (i=0; i<=Highest_object_index; i++) {
417 if (objp->type == OBJ_CNTRLCEN)
419 if (cntrlcen_objnum != -1)
420 mprintf((1, "Warning: Two or more control centers including %i and %i\n", i, cntrlcen_objnum));
425 if ((objp->type == OBJ_ROBOT) && (Robot_info[objp->id].boss_flag)) {
426 // mprintf((0, "Found boss robot %d.\n", objp->id));
427 if (boss_objnum != -1)
428 mprintf((1, "Warning: Two or more bosses including %i and %i\n", i, boss_objnum));
435 if (cntrlcen_objnum == -1) {
436 mprintf((1, "Warning: No control center.\n"));
441 if ( (boss_objnum != -1) && !((Game_mode & GM_MULTI) && !(Game_mode & GM_MULTI_ROBOTS)) ) {
442 if (cntrlcen_objnum != -1) {
443 // mprintf((0, "Ghosting control center\n"));
444 Objects[cntrlcen_objnum].type = OBJ_GHOST;
445 Objects[cntrlcen_objnum].render_type = RT_NONE;
446 Control_center_present = 0;
449 // Compute all gun positions.
450 objp = &Objects[cntrlcen_objnum];
451 N_controlcen_guns = Reactors[objp->id].n_guns;
452 for (i=0; i<N_controlcen_guns; i++)
453 calc_controlcen_gun_point(&Gun_pos[i], &Gun_dir[i], objp, i);
454 Control_center_present = 1;
456 if (Reactor_strength == -1) { //use old defaults
457 // Boost control center strength at higher levels.
458 if (Current_level_num >= 0)
459 objp->shields = F1_0*200 + (F1_0*200/4) * Current_level_num;
461 objp->shields = F1_0*200 - Current_level_num*F1_0*150;
464 objp->shields = i2f(Reactor_strength);
469 // Say the control center has not yet been hit.
470 Control_center_been_hit = 0;
471 Control_center_player_been_seen = 0;
472 Control_center_next_fire_time = 0;
474 Dead_controlcen_object_num = -1;
477 void special_reactor_stuff(void)
479 mprintf((0, "Mucking with reactor countdown time.\n"));
480 if (Control_center_destroyed) {
481 Countdown_timer += i2f(Base_control_center_explosion_time + (NDL-1-Difficulty_level)*Base_control_center_explosion_time/(NDL-1));
482 Total_countdown_time = f2i(Countdown_timer)+2; // Will prevent "Self destruct sequence activated" message from replaying.
488 * reads n reactor structs from a CFILE
490 extern int reactor_read_n(reactor *r, int n, CFILE *fp)
494 for (i = 0; i < n; i++) {
495 r[i].model_num = cfile_read_int(fp);
496 r[i].n_guns = cfile_read_int(fp);
497 for (j = 0; j < MAX_CONTROLCEN_GUNS; j++)
498 cfile_read_vector(&(r[i].gun_points[j]), fp);
499 for (j = 0; j < MAX_CONTROLCEN_GUNS; j++)
500 cfile_read_vector(&(r[i].gun_dirs[j]), fp);
506 * reads a control_center_triggers structure from a CFILE
508 extern int control_center_triggers_read_n(control_center_triggers *cct, int n, CFILE *fp)
512 for (i = 0; i < n; i++)
514 cct->num_links = cfile_read_short(fp);
515 for (j = 0; j < MAX_CONTROLCEN_LINKS; j++)
516 cct->seg[j] = cfile_read_short(fp);
517 for (j = 0; j < MAX_CONTROLCEN_LINKS; j++)
518 cct->side[j] = cfile_read_short(fp);
524 int control_center_triggers_write(control_center_triggers *cct, PHYSFS_file *fp)
528 PHYSFS_writeSLE16(fp, cct->num_links);
529 for (j = 0; j < MAX_CONTROLCEN_LINKS; j++)
530 PHYSFS_writeSLE16(fp, cct->seg[j]);
531 for (j = 0; j < MAX_CONTROLCEN_LINKS; j++)
532 PHYSFS_writeSLE16(fp, cct->side[j]);