1 /* $Id: gameseq.c,v 1.38 2004-10-24 12:46:49 schaffner Exp $ */
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.
17 * Routines for EndGame, EndLevel, etc.
27 char gameseq_rcsid[] = "$Id: gameseq.c,v 1.38 2004-10-24 12:46:49 schaffner Exp $";
38 #if !defined(_MSC_VER) && !defined(macintosh)
47 #include "pa_enabl.h" //$$POLY_ACC
101 #include "fireball.h"
106 #include "cntrlcen.h"
111 #include "texmerge.h"
118 #include "controls.h"
120 #include "gamemine.h"
122 #if defined(POLY_ACC)
123 #include "poly_acc.h"
125 #if defined (TACTILE)
130 #include "editor/editor.h"
136 void StartNewLevelSecret(int level_num, int page_in_textures);
137 void InitPlayerPosition(int random_flag);
139 void returning_to_level_message(void);
140 void advancing_to_level_message(void);
141 void DoEndGame(void);
142 void AdvanceLevel(int secret_flag);
143 void filter_objects_from_level();
145 // From allender -- you'll find these defines in state.c and cntrlcen.c
146 // since I couldn't think of a good place to put them and i wanted to
147 // fix this stuff fast! Sorry about that...
150 #define SECRETB_FILENAME "secret.sgb"
151 #define SECRETC_FILENAME "secret.sgc"
153 #define SECRETB_FILENAME ":Players:secret.sgb"
154 #define SECRETC_FILENAME ":Players:secret.sgc"
157 //Current_level_num starts at 1 for the first level
158 //-1,-2,-3 are secret levels
159 //0 means not a real level loaded
160 int Current_level_num=0,Next_level_num;
161 char Current_level_name[LEVEL_NAME_LEN];
163 // Global variables describing the player
164 int N_players=1; // Number of players ( >1 means a net game, eh?)
165 int Player_num=0; // The player number who is on the console.
166 player Players[MAX_PLAYERS+4]; // Misc player info
167 obj_position Player_init[MAX_PLAYERS];
169 // Global variables telling what sort of game we have
170 int MaxNumNetPlayers = -1;
171 int NumNetPlayerPositions = -1;
173 extern fix ThisLevelTime;
175 // Extern from game.c to fix a bug in the cockpit!
177 extern int last_drawn_cockpit[2];
178 extern int Last_level_path_created;
180 // HUD_clear_messages external, declared in gauges.h
182 extern void HUD_clear_messages(); // From hud.c
185 // Extra prototypes declared for the sake of LINT
186 void init_player_stats_new_ship(void);
187 void copy_defaults_to_robot_all(void);
189 int Do_appearance_effect=0;
191 extern int Rear_view;
193 int First_secret_visit = 1;
195 extern int descent_critical_error;
197 extern int Last_msg_ycrd;
199 //--------------------------------------------------------------------
200 void verify_console_object()
202 Assert( Player_num > -1 );
203 Assert( Players[Player_num].objnum > -1 );
204 ConsoleObject = &Objects[Players[Player_num].objnum];
205 Assert( ConsoleObject->type==OBJ_PLAYER );
206 Assert( ConsoleObject->id==Player_num );
209 int count_number_of_robots()
215 for (i=0;i<=Highest_object_index;i++) {
216 if (Objects[i].type == OBJ_ROBOT)
224 int count_number_of_hostages()
230 for (i=0;i<=Highest_object_index;i++) {
231 if (Objects[i].type == OBJ_HOSTAGE)
238 //added 10/12/95: delete buddy bot if coop game. Probably doesn't really belong here. -MT
240 gameseq_init_network_players()
244 // Initialize network player start locations and object numbers
246 ConsoleObject = &Objects[0];
249 for (i=0;i<=Highest_object_index;i++) {
251 if (( Objects[i].type==OBJ_PLAYER ) || (Objects[i].type == OBJ_GHOST) || (Objects[i].type == OBJ_COOP))
253 if ( (!(Game_mode & GM_MULTI_COOP) && ((Objects[i].type == OBJ_PLAYER)||(Objects[i].type==OBJ_GHOST))) ||
254 ((Game_mode & GM_MULTI_COOP) && ((j == 0) || ( Objects[i].type==OBJ_COOP ))) )
256 // -- mprintf((0, "Created Cooperative multiplayer object\n"));
257 Objects[i].type=OBJ_PLAYER;
258 // -- mprintf((0, "Player init %d is ship %d.\n", k, j));
259 Player_init[k].pos = Objects[i].pos;
260 Player_init[k].orient = Objects[i].orient;
261 Player_init[k].segnum = Objects[i].segnum;
262 Players[k].objnum = i;
271 if ((Objects[i].type==OBJ_ROBOT) && (Robot_info[Objects[i].id].companion) && (Game_mode & GM_MULTI))
272 obj_delete(i); //kill the buddy in netgames
275 NumNetPlayerPositions = k;
278 if ( ((Game_mode & GM_MULTI_COOP) && (NumNetPlayerPositions != 4)) ||
279 (!(Game_mode & GM_MULTI_COOP) && (NumNetPlayerPositions != 8)) )
281 mprintf((1, "--NOT ENOUGH MULTIPLAYER POSITIONS IN THIS MINE!--\n"));
282 //Int3(); // Not enough positions!!
286 if (is_D2_OEM && (Game_mode & GM_MULTI) && PLAYING_BUILTIN_MISSION && Current_level_num==8)
288 for (i=0;i<N_players;i++)
289 if (Players[i].connected && !(NetPlayers.players[i].version_minor & 0xF0))
291 nm_messagebox ("Warning!",1,TXT_OK,"This special version of Descent II\nwill disconnect after this level.\nPlease purchase the full version\nto experience all the levels!");
296 if (is_MAC_SHARE && (Game_mode & GM_MULTI) && PLAYING_BUILTIN_MISSION && Current_level_num == 4)
298 for (i = 0; i < N_players; i++)
299 if (Players[i].connected && !(NetPlayers.players[i].version_minor & 0xF0))
301 nm_messagebox ("Warning!", 1 ,TXT_OK, "This shareware version of Descent II\nwill disconnect after this level.\nPlease purchase the full version\nto experience all the levels!");
308 void gameseq_remove_unused_players()
312 // 'Remove' the unused players
315 if (Game_mode & GM_MULTI)
317 for (i=0; i < NumNetPlayerPositions; i++)
319 if ((!Players[i].connected) || (i >= N_players))
322 // mprintf((0, "Ghosting player ship %d.\n", i+1));
324 multi_make_player_ghost(i);
330 { // Note link to above if!!!
332 // -- mprintf((0, "Removing player objects numbered %d-%d.\n", 1, NumNetPlayerPositions));
334 for (i=1; i < NumNetPlayerPositions; i++)
336 obj_delete(Players[i].objnum);
341 fix StartingShields=INITIAL_SHIELDS;
343 // Setup player for new game
344 void init_player_stats_game()
346 Players[Player_num].score = 0;
347 Players[Player_num].last_score = 0;
348 Players[Player_num].lives = INITIAL_LIVES;
349 Players[Player_num].level = 1;
351 Players[Player_num].time_level = 0;
352 Players[Player_num].time_total = 0;
353 Players[Player_num].hours_level = 0;
354 Players[Player_num].hours_total = 0;
356 Players[Player_num].energy = INITIAL_ENERGY;
357 Players[Player_num].shields = StartingShields;
358 Players[Player_num].killer_objnum = -1;
360 Players[Player_num].net_killed_total = 0;
361 Players[Player_num].net_kills_total = 0;
363 Players[Player_num].num_kills_level = 0;
364 Players[Player_num].num_kills_total = 0;
365 Players[Player_num].num_robots_level = 0;
366 Players[Player_num].num_robots_total = 0;
367 Players[Player_num].KillGoalCount = 0;
369 Players[Player_num].hostages_rescued_total = 0;
370 Players[Player_num].hostages_level = 0;
371 Players[Player_num].hostages_total = 0;
373 Players[Player_num].laser_level = 0;
374 Players[Player_num].flags = 0;
376 init_player_stats_new_ship();
378 First_secret_visit = 1;
381 void init_ammo_and_energy(void)
383 if (Players[Player_num].energy < INITIAL_ENERGY)
384 Players[Player_num].energy = INITIAL_ENERGY;
385 if (Players[Player_num].shields < StartingShields)
386 Players[Player_num].shields = StartingShields;
388 // for (i=0; i<MAX_PRIMARY_WEAPONS; i++)
389 // if (Players[Player_num].primary_ammo[i] < Default_primary_ammo_level[i])
390 // Players[Player_num].primary_ammo[i] = Default_primary_ammo_level[i];
392 // for (i=0; i<MAX_SECONDARY_WEAPONS; i++)
393 // if (Players[Player_num].secondary_ammo[i] < Default_secondary_ammo_level[i])
394 // Players[Player_num].secondary_ammo[i] = Default_secondary_ammo_level[i];
395 if (Players[Player_num].secondary_ammo[0] < 2 + NDL - Difficulty_level)
396 Players[Player_num].secondary_ammo[0] = 2 + NDL - Difficulty_level;
399 extern ubyte Last_afterburner_state;
401 // Setup player for new level (After completion of previous level)
402 void init_player_stats_level(int secret_flag)
406 Players[Player_num].last_score = Players[Player_num].score;
408 Players[Player_num].level = Current_level_num;
411 if (!Network_rejoined) {
413 Players[Player_num].time_level = 0;
414 Players[Player_num].hours_level = 0;
419 Players[Player_num].killer_objnum = -1;
421 Players[Player_num].num_kills_level = 0;
422 Players[Player_num].num_robots_level = count_number_of_robots();
423 Players[Player_num].num_robots_total += Players[Player_num].num_robots_level;
425 Players[Player_num].hostages_level = count_number_of_hostages();
426 Players[Player_num].hostages_total += Players[Player_num].hostages_level;
427 Players[Player_num].hostages_on_board = 0;
430 init_ammo_and_energy();
432 Players[Player_num].flags &= (~KEY_BLUE);
433 Players[Player_num].flags &= (~KEY_RED);
434 Players[Player_num].flags &= (~KEY_GOLD);
436 Players[Player_num].flags &= ~(PLAYER_FLAGS_INVULNERABLE |
437 PLAYER_FLAGS_CLOAKED |
438 PLAYER_FLAGS_MAP_ALL);
440 Players[Player_num].cloak_time = 0;
441 Players[Player_num].invulnerable_time = 0;
443 if ((Game_mode & GM_MULTI) && !(Game_mode & GM_MULTI_COOP))
444 Players[Player_num].flags |= (KEY_BLUE | KEY_RED | KEY_GOLD);
447 Player_is_dead = 0; // Added by RH
448 Players[Player_num].homing_object_dist = -F1_0; // Added by RH
450 Last_laser_fired_time = Next_laser_fire_time = GameTime; // added by RH, solved demo playback bug
452 Controls.afterburner_state = 0;
453 Last_afterburner_state = 0;
455 digi_kill_sound_linked_to_object(Players[Player_num].objnum);
461 tactile_set_button_jolt();
464 Missile_viewer = NULL;
467 extern void init_ai_for_ship(void);
469 // Setup player for a brand-new ship
470 void init_player_stats_new_ship()
474 if (Newdemo_state == ND_STATE_RECORDING) {
475 newdemo_record_laser_level(Players[Player_num].laser_level, 0);
476 newdemo_record_player_weapon(0, 0);
477 newdemo_record_player_weapon(1, 0);
480 Players[Player_num].energy = INITIAL_ENERGY;
481 Players[Player_num].shields = StartingShields;
482 Players[Player_num].laser_level = 0;
483 Players[Player_num].killer_objnum = -1;
484 Players[Player_num].hostages_on_board = 0;
486 Afterburner_charge = 0;
488 for (i=0; i<MAX_PRIMARY_WEAPONS; i++) {
489 Players[Player_num].primary_ammo[i] = 0;
490 Primary_last_was_super[i] = 0;
493 for (i=1; i<MAX_SECONDARY_WEAPONS; i++) {
494 Players[Player_num].secondary_ammo[i] = 0;
495 Secondary_last_was_super[i] = 0;
497 Players[Player_num].secondary_ammo[0] = 2 + NDL - Difficulty_level;
499 Players[Player_num].primary_weapon_flags = HAS_LASER_FLAG;
500 Players[Player_num].secondary_weapon_flags = HAS_CONCUSSION_FLAG;
503 Secondary_weapon = 0;
505 Players[Player_num].flags &= ~( PLAYER_FLAGS_QUAD_LASERS |
506 PLAYER_FLAGS_AFTERBURNER |
507 PLAYER_FLAGS_CLOAKED |
508 PLAYER_FLAGS_INVULNERABLE |
509 PLAYER_FLAGS_MAP_ALL |
510 PLAYER_FLAGS_CONVERTER |
511 PLAYER_FLAGS_AMMO_RACK |
512 PLAYER_FLAGS_HEADLIGHT |
513 PLAYER_FLAGS_HEADLIGHT_ON |
516 Players[Player_num].cloak_time = 0;
517 Players[Player_num].invulnerable_time = 0;
519 Player_is_dead = 0; //player no longer dead
521 Players[Player_num].homing_object_dist = -F1_0; // Added by RH
523 Controls.afterburner_state = 0;
524 Last_afterburner_state = 0;
526 digi_kill_sound_linked_to_object(Players[Player_num].objnum);
528 Missile_viewer=NULL; ///reset missile camera if out there
533 tactile_set_button_jolt();
541 extern void init_stuck_objects(void);
545 extern int Slide_segs_computed;
547 //reset stuff so game is semi-normal when playing from editor
548 void editor_reset_stuff_on_level()
550 gameseq_init_network_players();
551 init_player_stats_level(0);
552 Viewer = ConsoleObject;
553 ConsoleObject = Viewer = &Objects[Players[Player_num].objnum];
554 ConsoleObject->id=Player_num;
555 ConsoleObject->control_type = CT_FLYING;
556 ConsoleObject->movement_type = MT_PHYSICS;
558 verify_console_object();
559 Control_center_destroyed = 0;
560 if (Newdemo_state != ND_STATE_PLAYBACK)
561 gameseq_remove_unused_players();
563 init_robots_for_level();
567 init_player_stats_new_ship();
568 init_controlcen_for_level();
569 automap_clear_visited();
570 init_stuck_objects();
571 init_thief_for_level();
573 Slide_segs_computed = 0;
577 //do whatever needs to be done when a player dies in multiplayer
581 // nm_messagebox( TXT_GAME_OVER, 1, TXT_OK, "" );
583 if (PLAYING_BUILTIN_MISSION)
584 scores_maybe_add_player(0);
586 Function_mode = FMODE_MENU;
587 Game_mode = GM_GAME_OVER;
588 longjmp( LeaveGame, 0 ); // Exit out of game loop
592 extern void do_save_game_menu();
594 //update various information about the player
595 void update_player_stats()
597 Players[Player_num].time_level += FrameTime; //the never-ending march of time...
598 if ( Players[Player_num].time_level > i2f(3600) ) {
599 Players[Player_num].time_level -= i2f(3600);
600 Players[Player_num].hours_level++;
603 Players[Player_num].time_total += FrameTime; //the never-ending march of time...
604 if ( Players[Player_num].time_total > i2f(3600) ) {
605 Players[Player_num].time_total -= i2f(3600);
606 Players[Player_num].hours_total++;
610 //hack to not start object when loading level
611 extern int Dont_start_sound_objects;
613 //go through this level and start any eclip sounds
614 void set_sound_sources()
619 digi_init_sounds(); //clear old sounds
621 Dont_start_sound_objects = 1;
623 for (seg=&Segments[0],segnum=0;segnum<=Highest_segment_index;seg++,segnum++)
624 for (sidenum=0;sidenum<MAX_SIDES_PER_SEGMENT;sidenum++) {
627 if (WALL_IS_DOORWAY(seg,sidenum) & WID_RENDER_FLAG)
628 if ((((tm=seg->sides[sidenum].tmap_num2) != 0) && ((ec=TmapInfo[tm&0x3fff].eclip_num)!=-1)) || ((ec=TmapInfo[seg->sides[sidenum].tmap_num].eclip_num)!=-1))
629 if ((sn=Effects[ec].sound_num)!=-1) {
631 int csegnum = seg->children[sidenum];
633 //check for sound on other side of wall. Don't add on
634 //both walls if sound travels through wall. If sound
635 //does travel through wall, add sound for lower-numbered
638 if (IS_CHILD(csegnum) && csegnum < segnum) {
639 if (WALL_IS_DOORWAY(seg, sidenum) & (WID_FLY_FLAG+WID_RENDPAST_FLAG)) {
643 csegp = &Segments[seg->children[sidenum]];
644 csidenum = find_connect_side(seg, csegp);
646 if (csegp->sides[csidenum].tmap_num2 == seg->sides[sidenum].tmap_num2)
647 continue; //skip this one
651 compute_center_point_on_side(&pnt,seg,sidenum);
652 digi_link_sound_to_pos(sn,segnum,sidenum,&pnt,1, F1_0/2);
656 Dont_start_sound_objects = 0;
661 //fix flash_dist=i2f(1);
662 fix flash_dist=fl2f(.9);
664 //create flash for player appearance
665 void create_player_appearance_effect(object *player_obj)
672 int objnum = player_obj-Objects;
673 if ( (objnum < 0) || (objnum > Highest_object_index) )
674 Int3(); // See Rob, trying to track down weird network bug
678 if (player_obj == Viewer)
679 vm_vec_scale_add(&pos, &player_obj->pos, &player_obj->orient.fvec, fixmul(player_obj->size,flash_dist));
681 pos = player_obj->pos;
683 effect_obj = object_create_explosion(player_obj->segnum, &pos, player_obj->size, VCLIP_PLAYER_APPEARANCE );
686 effect_obj->orient = player_obj->orient;
688 if ( Vclip[VCLIP_PLAYER_APPEARANCE].sound_num > -1 )
689 digi_link_sound_to_object( Vclip[VCLIP_PLAYER_APPEARANCE].sound_num, effect_obj-Objects, 0, F1_0);
694 // New Game sequencing functions
697 //pairs of chars describing ranges
698 char playername_allowed_chars[] = "azAZ09__--";
700 int MakeNewPlayerFile(int allow_abort)
705 char text[CALLSIGN_LEN+1]="";
710 strncpy(text, Players[Player_num].callsign,CALLSIGN_LEN);
713 m.type=NM_TYPE_INPUT; m.text_len = 8; m.text = text;
715 Newmenu_allowed_chars = playername_allowed_chars;
716 x = newmenu_do( NULL, TXT_ENTER_PILOT_NAME, 1, &m, NULL );
717 Newmenu_allowed_chars = NULL;
720 if ( allow_abort ) return 0;
724 if (text[0]==0) //null string
726 sprintf( filename, "%s.plr", text );
729 fp = fopen( filename, "rb" );
732 //if the callsign is the name of a tty device, prepend a char
733 if (fp && isatty(fileno(fp))) {
735 sprintf(filename,"$%.7s.plr",text);
736 fp = fopen(filename,"rb");
741 nm_messagebox(NULL, 1, TXT_OK, "%s '%s' %s", TXT_PLAYER, text, TXT_ALREADY_EXISTS );
746 if (cfexist(filename))
748 nm_messagebox(NULL, 1, TXT_OK, "%s '%s' %s", TXT_PLAYER, text, TXT_ALREADY_EXISTS );
753 if ( !new_player_config() )
754 goto try_again; // They hit Esc during New player config
756 strncpy(Players[Player_num].callsign, text, CALLSIGN_LEN);
764 #undef TXT_SELECT_PILOT
765 #define TXT_SELECT_PILOT "Select pilot\n<Ctrl-D> or Right-click\nto delete"
768 //Inputs the player's name, without putting up the background screen
773 int allow_abort_flag = 1;
775 if ( Players[Player_num].callsign[0] == 0 ) {
776 //---------------------------------------------------------------------
777 // Set default config options in case there is no config file
778 // kc_keyboard, kc_joystick, kc_mouse are statically defined.
779 Config_joystick_sensitivity = 8;
780 Config_control_type =CONTROL_NONE;
781 for (i=0; i<CONTROL_MAX_TYPES; i++ )
782 for (j=0; j<MAX_CONTROLS; j++ )
783 kconfig_settings[i][j] = default_kconfig_settings[i][j];
785 //----------------------------------------------------------------
787 // Read the last player's name from config file, not lastplr.txt
788 strncpy( Players[Player_num].callsign, config_last_player, CALLSIGN_LEN );
790 if (config_last_player[0]==0)
791 allow_abort_flag = 0;
798 if (!newmenu_get_filename( TXT_SELECT_PILOT, "*.plr", filename, allow_abort_flag )) {
799 goto do_menu_again; //return 0; // They hit Esc in file selector
803 if (!newmenu_get_filename( TXT_SELECT_PILOT, ".\\Players\\*.plr", filename, allow_abort_flag )) {
804 goto do_menu_again; // They hit Esc in file selector
807 newmenu_get_filename( "Select Pilot", ".\\Players\\*.plr", filename, 0 ); // no abort allowed ever -- and change title of menubox
811 if ( filename[0] == '<' ) {
812 // They selected 'create new pilot'
813 if (!MakeNewPlayerFile(allow_abort_flag))
814 //return 0; // They hit Esc during enter name stage
817 strncpy(Players[Player_num].callsign,filename, CALLSIGN_LEN);
820 if (read_player_file() != EZERO)
823 Auto_leveling_on = Default_leveling_on;
825 set_display_mode(Default_display_mode);
827 WriteConfigFile(); // Update lastplr
833 void load_robot_replacements(char *level_name);
835 extern int Robot_replacements_loaded;
837 //load a level off disk. level numbers start at 1. Secret levels are -1,-2,-3
838 void LoadLevel(int level_num,int page_in_textures)
844 save_player = Players[Player_num];
846 Assert(level_num <= Last_level && level_num >= Last_secret_level && level_num != 0);
848 if (level_num<0) //secret level
849 level_name = Secret_level_names[-level_num-1];
851 level_name = Level_names[level_num-1];
854 dd_gr_set_current_canvas(NULL);
855 dd_gr_clear_canvas(BM_XRGB(0,0,0));
857 gr_set_current_canvas(NULL);
858 gr_clear_canvas(BM_XRGB(0, 0, 0)); //so palette switching is less obvious
861 Last_msg_ycrd = -1; //so we don't restore backgound under msg
863 // WIN(LoadCursorWin(MOUSE_WAIT_CURSOR));
864 // WIN(ShowCursorW());
866 #if 1 //defined(POLY_ACC) || defined(OGL)
867 gr_palette_load(gr_palette);
868 show_boxed_message(TXT_LOADING);
870 show_boxed_message(TXT_LOADING);
871 gr_palette_load(gr_palette);
874 load_ret = load_level(level_name); //actually load the data from disk!
877 Error("Couldn't load level file <%s>, error = %d",level_name,load_ret);
879 Current_level_num=level_num;
881 // load_palette_pig(Current_level_palette); //load just the pig
883 load_palette(Current_level_palette,1,1); //don't change screen
885 load_endlevel_data(level_num);
887 if ( page_in_textures )
888 piggy_load_level_data();
891 load_d1_bitmap_replacements();
893 load_bitmap_replacements(level_name);
895 if (Robot_replacements_loaded) {
896 read_hamfile(); //load original data
897 Robot_replacements_loaded = 0;
899 load_robot_replacements(level_name);
902 my_segments_checksum = netmisc_calc_checksum(Segments, sizeof(segment)*(Highest_segment_index+1));
904 reset_network_objects();
907 Players[Player_num] = save_player;
911 songs_play_level_song( Current_level_num );
913 clear_boxed_message(); //remove message before new palette loaded
915 gr_palette_load(gr_palette); //actually load the palette
917 // WIN(HideCursorW());
920 //sets up Player_num & ConsoleObject
921 void InitPlayerObject()
923 Assert(Player_num>=0 && Player_num<MAX_PLAYERS);
925 if (Player_num != 0 ) {
926 Players[0] = Players[Player_num];
930 Players[Player_num].objnum = 0;
932 ConsoleObject = &Objects[Players[Player_num].objnum];
934 ConsoleObject->type = OBJ_PLAYER;
935 ConsoleObject->id = Player_num;
936 ConsoleObject->control_type = CT_FLYING;
937 ConsoleObject->movement_type = MT_PHYSICS;
940 extern void game_disable_cheats();
941 extern void turn_cheats_off();
942 extern void init_seismic_disturbances(void);
944 //starts a new game on the given level
945 void StartNewGame(int start_level)
947 Game_mode = GM_NORMAL;
948 Function_mode = FMODE_GAME;
952 InitPlayerObject(); //make sure player's object set up
954 init_player_stats_game(); //clear all stats
958 Network_new_game = 0;
962 StartNewLevelSecret(start_level, 0);
964 StartNewLevel(start_level, 0);
966 Players[Player_num].starting_level = start_level; // Mark where they started
968 game_disable_cheats();
970 init_seismic_disturbances();
973 //@@//starts a resumed game loaded from disk
974 //@@void ResumeSavedGame(int start_level)
976 //@@ Game_mode = GM_NORMAL;
977 //@@ Function_mode = FMODE_GAME;
980 //@@ Network_new_game = 0;
982 //@@ InitPlayerObject(); //make sure player's object set up
984 //@@ StartNewLevel(start_level, 0);
986 //@@ game_disable_cheats();
990 extern int network_endlevel_poll2( int nitems, newmenu_item * menus, int * key, int citem ); // network.c
993 #define STARS_BACKGROUND ((MenuHires && cfexist("starsb.pcx"))?"starsb.pcx":cfexist("stars.pcx")?"stars.pcx":"starsb.pcx")
995 // -----------------------------------------------------------------------------
996 // Does the bonus scoring.
997 // Call with dead_flag = 1 if player died, but deserves some portion of bonus (only skill points), anyway.
998 void DoEndLevelScoreGlitz(int network)
1000 int level_points, skill_points, energy_points, shield_points, hostage_points;
1001 int all_hostage_points;
1003 char all_hostage_text[64];
1004 char endgame_text[64];
1005 #define N_GLITZITEMS 11
1006 char m_str[N_GLITZITEMS][30];
1007 newmenu_item m[N_GLITZITEMS+1];
1013 set_screen_mode(SCREEN_MENU); //go into menu mode
1020 mprintf((0,"DoEndLevelScoreGlitz\n"));
1022 // Compute level player is on, deal with secret levels (negative numbers)
1023 mine_level = Players[Player_num].level;
1025 mine_level *= -(Last_level/N_secret_levels);
1027 level_points = Players[Player_num].score-Players[Player_num].last_score;
1029 if (!Cheats_enabled) {
1030 if (Difficulty_level > 1) {
1031 skill_points = level_points*(Difficulty_level)/4;
1032 skill_points -= skill_points % 100;
1036 shield_points = f2i(Players[Player_num].shields) * 5 * mine_level;
1037 energy_points = f2i(Players[Player_num].energy) * 2 * mine_level;
1038 hostage_points = Players[Player_num].hostages_on_board * 500 * (Difficulty_level+1);
1040 shield_points -= shield_points % 50;
1041 energy_points -= energy_points % 50;
1049 all_hostage_text[0] = 0;
1050 endgame_text[0] = 0;
1052 if (!Cheats_enabled && (Players[Player_num].hostages_on_board == Players[Player_num].hostages_level)) {
1053 all_hostage_points = Players[Player_num].hostages_on_board * 1000 * (Difficulty_level+1);
1054 sprintf(all_hostage_text, "%s%i\n", TXT_FULL_RESCUE_BONUS, all_hostage_points);
1056 all_hostage_points = 0;
1058 if (!Cheats_enabled && !(Game_mode & GM_MULTI) && (Players[Player_num].lives) && (Current_level_num == Last_level)) { //player has finished the game!
1059 endgame_points = Players[Player_num].lives * 10000;
1060 sprintf(endgame_text, "%s%i\n", TXT_SHIP_BONUS, endgame_points);
1063 endgame_points = is_last_level = 0;
1065 mprintf((0,"adding bonus points\n"));
1066 add_bonus_points_to_score(skill_points + energy_points + shield_points + hostage_points + all_hostage_points + endgame_points);
1069 sprintf(m_str[c++], "%s%i", TXT_SHIELD_BONUS, shield_points); // Return at start to lower menu...
1070 sprintf(m_str[c++], "%s%i", TXT_ENERGY_BONUS, energy_points);
1071 sprintf(m_str[c++], "%s%i", TXT_HOSTAGE_BONUS, hostage_points);
1072 sprintf(m_str[c++], "%s%i", TXT_SKILL_BONUS, skill_points);
1074 sprintf(m_str[c++], "%s", all_hostage_text);
1075 if (!(Game_mode & GM_MULTI) && (Players[Player_num].lives) && (Current_level_num == Last_level))
1076 sprintf(m_str[c++], "%s", endgame_text);
1078 sprintf(m_str[c++], "%s%i\n", TXT_TOTAL_BONUS, shield_points+energy_points+hostage_points+skill_points+all_hostage_points+endgame_points);
1079 sprintf(m_str[c++], "%s%i", TXT_TOTAL_SCORE, Players[Player_num].score);
1082 sprintf(m_str[c++], "");
1083 sprintf(m_str[c++], " Done");
1086 for (i=0; i<c; i++) {
1087 m[i].type = NM_TYPE_TEXT;
1088 m[i].text = m_str[i];
1092 m[c-1].type = NM_TYPE_MENU;
1095 // m[c].type = NM_TYPE_MENU; m[c++].text = "Ok";
1097 if (Current_level_num < 0)
1098 sprintf(title,"%s%s %d %s\n %s %s",is_last_level?"\n\n\n":"\n",TXT_SECRET_LEVEL, -Current_level_num, TXT_COMPLETE, Current_level_name, TXT_DESTROYED);
1100 sprintf(title,"%s%s %d %s\n%s %s",is_last_level?"\n\n\n":"\n",TXT_LEVEL, Current_level_num, TXT_COMPLETE, Current_level_name, TXT_DESTROYED);
1102 Assert(c <= N_GLITZITEMS);
1104 gr_palette_fade_out(gr_palette, 32, 0);
1106 mprintf((0,"doing menu\n"));
1108 PA_DFX (pa_alpha_always());
1111 if ( network && (Game_mode & GM_NETWORK) )
1112 newmenu_do2(NULL, title, c, m, (void (*))network_endlevel_poll2, 0, STARS_BACKGROUND);
1115 // NOTE LINK TO ABOVE!!!
1116 newmenu_do2(NULL, title, c, m, NULL, 0, STARS_BACKGROUND);
1118 mprintf((0,"done DoEndLevelScoreGlitz\n"));
1121 //give the player the opportunity to save his game
1122 void DoEndlevelMenu()
1124 //No between level saves......!!! state_save_all(1);
1127 // -----------------------------------------------------------------------------------------------------
1128 //called when the player is starting a level (new game or new ship)
1129 void StartSecretLevel()
1131 Assert(!Player_is_dead);
1133 InitPlayerPosition(0);
1135 verify_console_object();
1137 ConsoleObject->control_type = CT_FLYING;
1138 ConsoleObject->movement_type = MT_PHYSICS;
1140 // -- WHY? -- disable_matcens();
1141 clear_transient_objects(0); //0 means leave proximity bombs
1143 // create_player_appearance_effect(ConsoleObject);
1144 Do_appearance_effect = 1;
1146 ai_reset_all_paths();
1147 // -- NO? -- reset_time();
1150 Auto_fire_fusion_cannon_time = 0;
1153 Robot_firing_enabled = 1;
1156 extern void set_pos_from_return_segment(void);
1158 // Returns true if secret level has been destroyed.
1159 int p_secret_level_destroyed(void)
1161 if (First_secret_visit) {
1162 return 0; // Never been there, can't have been destroyed.
1164 if (cfexist(SECRETC_FILENAME))
1173 // -----------------------------------------------------------------------------------------------------
1174 void do_secret_message(char *msg)
1180 #if defined(POLY_ACC)
1182 pa_update_clut(gr_palette, 0, 256, 0);
1185 old_fmode = Function_mode;
1186 Function_mode = FMODE_MENU;
1187 nm_messagebox(NULL, 1, TXT_OK, msg);
1188 Function_mode = old_fmode;
1190 #if defined(POLY_ACC)
1194 WIN(DEFINE_SCREEN(NULL));
1197 // -----------------------------------------------------------------------------------------------------
1198 // called when the player is starting a new level for normal game mode and restore state
1199 // Need to deal with whether this is the first time coming to this level or not. If not the
1200 // first time, instead of initializing various things, need to do a game restore for all the
1201 // robots, powerups, walls, doors, etc.
1202 void StartNewLevelSecret(int level_num, int page_in_textures)
1209 m[0].type = NM_TYPE_TEXT;
1212 last_drawn_cockpit[0] = -1;
1213 last_drawn_cockpit[1] = -1;
1215 if (Newdemo_state == ND_STATE_PAUSED)
1216 Newdemo_state = ND_STATE_RECORDING;
1218 if (Newdemo_state == ND_STATE_RECORDING) {
1219 newdemo_set_new_level(level_num);
1220 newdemo_record_start_frame(FrameCount, FrameTime );
1221 } else if (Newdemo_state != ND_STATE_PLAYBACK) {
1223 gr_palette_fade_out(gr_palette, 32, 0);
1225 set_screen_mode(SCREEN_MENU); //go into menu mode
1227 if (First_secret_visit) {
1228 do_secret_message(TXT_SECRET_EXIT);
1230 if (cfexist(SECRETC_FILENAME))
1232 do_secret_message(TXT_SECRET_EXIT);
1236 sprintf(text_str, "Secret level already destroyed.\nAdvancing to level %i.", Current_level_num+1);
1237 do_secret_message(text_str);
1242 LoadLevel(level_num,page_in_textures);
1244 Assert(Current_level_num == level_num); //make sure level set right
1246 Assert(Function_mode == FMODE_GAME);
1248 gameseq_init_network_players(); // Initialize the Players array for
1251 HUD_clear_messages();
1253 automap_clear_visited();
1255 // -- init_player_stats_level();
1257 Viewer = &Objects[Players[Player_num].objnum];
1259 gameseq_remove_unused_players();
1263 Control_center_destroyed = 0;
1266 reset_palette_add();
1268 if (First_secret_visit || (Newdemo_state == ND_STATE_PLAYBACK)) {
1269 init_robots_for_level();
1271 init_smega_detonates();
1274 reset_special_effects();
1277 if (cfexist(SECRETC_FILENAME))
1279 int pw_save, sw_save;
1281 pw_save = Primary_weapon;
1282 sw_save = Secondary_weapon;
1283 state_restore_all(1, 1, SECRETC_FILENAME);
1284 Primary_weapon = pw_save;
1285 Secondary_weapon = sw_save;
1286 reset_special_effects();
1288 // -- No: This is only for returning to base level: set_pos_from_return_segment();
1292 sprintf(text_str, "Secret level already destroyed.\nAdvancing to level %i.", Current_level_num+1);
1293 do_secret_message(text_str);
1296 // -- // If file doesn't exist, it's because reactor was destroyed.
1297 // -- mprintf((0, "secret.sgc doesn't exist. Advancing to next level.\n"));
1298 // -- // -- StartNewLevel(Secret_level_table[-Current_level_num-1]+1, 0);
1299 // -- StartNewLevel(Secret_level_table[-Current_level_num-1]+1, 0);
1304 if (First_secret_visit) {
1305 copy_defaults_to_robot_all();
1310 init_controlcen_for_level();
1312 // Say player can use FLASH cheat to mark path to exit.
1313 Last_level_path_created = -1;
1315 First_secret_visit = 0;
1318 int Entered_from_level;
1320 // ---------------------------------------------------------------------------------------------------------------
1321 // Called from switch.c when player is on a secret level and hits exit to return to base level.
1322 void ExitSecretLevel(void)
1324 if (Newdemo_state == ND_STATE_PLAYBACK)
1327 if (!Control_center_destroyed) {
1328 state_save_all(0, 2, SECRETC_FILENAME);
1331 if (cfexist(SECRETB_FILENAME))
1333 int pw_save, sw_save;
1335 returning_to_level_message();
1336 pw_save = Primary_weapon;
1337 sw_save = Secondary_weapon;
1338 state_restore_all(1, 1, SECRETB_FILENAME);
1339 Primary_weapon = pw_save;
1340 Secondary_weapon = sw_save;
1342 // File doesn't exist, so can't return to base level. Advance to next one.
1343 if (Entered_from_level == Last_level)
1346 advancing_to_level_message();
1347 StartNewLevel(Entered_from_level+1, 0);
1352 // ---------------------------------------------------------------------------------------------------------------
1353 // Set invulnerable_time and cloak_time in player struct to preserve amount of time left to
1354 // be invulnerable or cloaked.
1355 void do_cloak_invul_secret_stuff(fix old_gametime)
1357 if (Players[Player_num].flags & PLAYER_FLAGS_INVULNERABLE) {
1360 time_used = old_gametime - Players[Player_num].invulnerable_time;
1361 Players[Player_num].invulnerable_time = GameTime - time_used;
1364 if (Players[Player_num].flags & PLAYER_FLAGS_CLOAKED) {
1367 time_used = old_gametime - Players[Player_num].cloak_time;
1368 Players[Player_num].cloak_time = GameTime - time_used;
1372 // ---------------------------------------------------------------------------------------------------------------
1373 // Called from switch.c when player passes through secret exit. That means he was on a non-secret level and he
1374 // is passing to the secret level.
1376 void EnterSecretLevel(void)
1381 Assert(! (Game_mode & GM_MULTI) );
1383 Entered_from_level = Current_level_num;
1385 if (Control_center_destroyed)
1386 DoEndLevelScoreGlitz(0);
1388 if (Newdemo_state != ND_STATE_PLAYBACK)
1389 state_save_all(0, 1, NULL); // Not between levels (ie, save all), IS a secret level, NO filename override
1391 // Find secret level number to go to, stuff in Next_level_num.
1392 for (i=0; i<-Last_secret_level; i++)
1393 if (Secret_level_table[i]==Current_level_num) {
1394 Next_level_num = -(i+1);
1396 } else if (Secret_level_table[i] > Current_level_num) { // Allows multiple exits in same group.
1397 Next_level_num = -i;
1401 if (! (i<-Last_secret_level)) //didn't find level, so must be last
1402 Next_level_num = Last_secret_level;
1404 old_gametime = GameTime;
1406 StartNewLevelSecret(Next_level_num, 1);
1408 // do_cloak_invul_stuff();
1411 //called when the player has finished a level
1412 void PlayerFinishedLevel(int secret_flag)
1414 Assert(!secret_flag);
1416 //credit the player for hostages
1417 Players[Player_num].hostages_rescued_total += Players[Player_num].hostages_on_board;
1419 if (Game_mode & GM_NETWORK)
1420 Players[Player_num].connected = 2; // Finished but did not die
1422 last_drawn_cockpit[0] = -1;
1423 last_drawn_cockpit[1] = -1;
1425 AdvanceLevel(secret_flag); //now go on to the next one (if one)
1428 #if defined(D2_OEM) || defined(COMPILATION)
1429 #define MOVIE_REQUIRED 0
1431 #define MOVIE_REQUIRED 1
1435 #define ENDMOVIE "endo"
1437 #define ENDMOVIE "end"
1440 void show_order_form();
1441 extern void com_hangup(void);
1443 //called when the player has finished the last level
1444 void DoEndGame(void)
1446 mprintf((0,"DoEndGame\n"));
1448 Function_mode = FMODE_MENU;
1449 if ((Newdemo_state == ND_STATE_RECORDING) || (Newdemo_state == ND_STATE_PAUSED))
1450 newdemo_stop_recording();
1452 set_screen_mode( SCREEN_MENU );
1455 dd_gr_set_current_canvas(NULL),
1456 gr_set_current_canvas(NULL)
1461 if (PLAYING_BUILTIN_MISSION && !(Game_mode & GM_MULTI))
1462 { //only built-in mission, & not multi
1463 int played=MOVIE_NOT_PLAYED; //default is not played
1465 init_subtitles(ENDMOVIE ".tex"); //ingore errors
1466 played = PlayMovie(ENDMOVIE,MOVIE_REQUIRED);
1471 songs_play_song( SONG_TITLE, 0 );
1472 do_briefing_screens("end2oem.tex",1);
1476 songs_play_song( SONG_ENDGAME, 0 );
1477 mprintf((0,"doing briefing\n"));
1478 do_briefing_screens("ending2.tex",1);
1479 mprintf((0,"briefing done\n"));
1482 } else if (!(Game_mode & GM_MULTI)) { //not multi
1483 char tname[FILENAME_LEN];
1484 sprintf(tname,"%s.tex",Current_mission_filename);
1485 do_briefing_screens (tname,Last_level+1); //level past last is endgame breifing
1487 //try doing special credits
1488 sprintf(tname,"%s.ctb",Current_mission_filename);
1489 credits_show(tname);
1499 if (Game_mode & GM_MULTI)
1500 multi_endlevel_score();
1503 // NOTE LINK TO ABOVE
1504 DoEndLevelScoreGlitz(0);
1506 if (PLAYING_BUILTIN_MISSION && !((Game_mode & GM_MULTI) && !(Game_mode & GM_MULTI_COOP))) {
1508 dd_gr_set_current_canvas(NULL),
1509 gr_set_current_canvas( NULL )
1512 dd_gr_clear_canvas(BM_XRGB(0,0,0)),
1513 gr_clear_canvas(BM_XRGB(0,0,0))
1516 load_palette(DEFAULT_PALETTE,0,1);
1517 scores_maybe_add_player(0);
1520 Function_mode = FMODE_MENU;
1522 if ((Game_mode & GM_SERIAL) || (Game_mode & GM_MODEM))
1523 Game_mode |= GM_GAME_OVER; //preserve modem setting so go back into modem menu
1525 Game_mode = GM_GAME_OVER;
1528 longjmp( LeaveGame, 0 ); // Exit out of game loop
1531 //called to go to the next level (if there is one)
1532 //if secret_flag is true, advance to secret level, else next normal one
1533 // Return true if game over.
1534 void AdvanceLevel(int secret_flag)
1540 mprintf((0,"AdvanceLevel\n"));
1542 Assert(!secret_flag);
1544 if (Current_level_num != Last_level) {
1546 if (Game_mode & GM_MULTI)
1547 multi_endlevel_score();
1550 // NOTE LINK TO ABOVE!!!
1551 DoEndLevelScoreGlitz(0); //give bonuses
1554 Control_center_destroyed = 0;
1557 if (Current_level_num == 0)
1558 return; //not a real level
1562 if (Game_mode & GM_MULTI) {
1563 result = multi_endlevel(&secret_flag); // Wait for other players to reach this point
1564 if (result) // failed to sync
1566 if (Current_level_num == Last_level) //player has finished the game!
1567 longjmp( LeaveGame, 0 ); // Exit out of game loop
1574 if (Current_level_num == Last_level) { //player has finished the game!
1576 mprintf((0,"Finished last level!\n"));
1582 Next_level_num = Current_level_num+1; //assume go to next normal level
1584 if (!(Game_mode & GM_MULTI))
1585 DoEndlevelMenu(); // Let use save their game
1587 StartNewLevel(Next_level_num, 0);
1592 #ifdef MACINTOSH // horrible hack of a routine to load just the palette from the stars.pcx file
1594 extern char last_palette_loaded[];
1596 void load_stars_palette()
1601 pcx_error = pcx_read_bitmap_palette(STARS_BACKGROUND,pal);
1602 Assert(pcx_error == PCX_ERROR_NONE);
1604 //@@gr_remap_bitmap_good( bmp, pal, -1, -1 );
1607 { //remap stuff. this code is kindof a hack
1609 //now, before we bring up the menu, we need to
1610 //do some stuff to make sure the palette is ok. First, we need to
1611 //get our current palette into the 2d's array, so the remapping will
1612 //work. Second, we need to remap the fonts. Third, we need to fill
1613 //in part of the fade tables so the darkening of the menu edges works
1615 gr_copy_palette(gr_palette, pal, sizeof(gr_palette));
1616 remap_fonts_and_menus(1);
1620 strcpy(last_palette_loaded,""); //force palette load next time
1624 void nm_draw_background1(char * filename);
1629 //@@ ubyte pal[256*3];
1631 //@@ pcx_error = pcx_read_bitmap("STARS.PCX",&grd_curcanv->cv_bitmap,grd_curcanv->cv_bitmap.bm_type,pal);
1632 //@@ Assert(pcx_error == PCX_ERROR_NONE);
1634 //@@ gr_remap_bitmap_good( &grd_curcanv->cv_bitmap, pal, -1, -1 );
1636 WIN(DEFINE_SCREEN(STARS_BACKGROUND));
1638 nm_draw_background1(STARS_BACKGROUND);
1644 died_in_mine_message(void)
1646 // Tell the player he died in the mine, explain why
1649 if (Game_mode & GM_MULTI)
1652 gr_palette_fade_out(gr_palette, 32, 0);
1654 set_screen_mode(SCREEN_MENU); //go into menu mode
1657 dd_gr_set_current_canvas(NULL),
1658 gr_set_current_canvas(NULL)
1663 #if defined(POLY_ACC)
1665 pa_update_clut(gr_palette, 0, 256, 0);
1668 old_fmode = Function_mode;
1669 Function_mode = FMODE_MENU;
1670 nm_messagebox(NULL, 1, TXT_OK, TXT_DIED_IN_MINE);
1671 Function_mode = old_fmode;
1673 #if defined(POLY_ACC)
1677 WIN(DEFINE_SCREEN(NULL));
1680 // Called when player dies on secret level.
1681 void returning_to_level_message(void)
1687 if (Game_mode & GM_MULTI)
1690 gr_palette_fade_out(gr_palette, 32, 0);
1692 set_screen_mode(SCREEN_MENU); //go into menu mode
1694 gr_set_current_canvas(NULL);
1698 #if defined(POLY_ACC)
1700 pa_update_clut(gr_palette, 0, 256, 0);
1703 old_fmode = Function_mode;
1704 Function_mode = FMODE_MENU;
1705 sprintf(msg, "Returning to level %i", Entered_from_level);
1706 nm_messagebox(NULL, 1, TXT_OK, msg);
1707 Function_mode = old_fmode;
1709 #if defined(POLY_ACC)
1713 WIN(DEFINE_SCREEN(NULL));
1716 // Called when player dies on secret level.
1717 void advancing_to_level_message(void)
1723 // Only supposed to come here from a secret level.
1724 Assert(Current_level_num < 0);
1726 if (Game_mode & GM_MULTI)
1729 gr_palette_fade_out(gr_palette, 32, 0);
1731 set_screen_mode(SCREEN_MENU); //go into menu mode
1733 gr_set_current_canvas(NULL);
1737 #if defined(POLY_ACC)
1739 pa_update_clut(gr_palette, 0, 256, 0);
1742 old_fmode = Function_mode;
1743 Function_mode = FMODE_MENU;
1744 sprintf(msg, "Base level destroyed.\nAdvancing to level %i", Entered_from_level+1);
1745 nm_messagebox(NULL, 1, TXT_OK, msg);
1746 Function_mode = old_fmode;
1748 #if defined(POLY_ACC)
1752 WIN(DEFINE_SCREEN(NULL));
1755 void digi_stop_digi_sounds();
1759 reset_palette_add();
1761 gr_palette_load (gr_palette);
1763 // digi_pause_digi_sounds(); //kill any continuing sounds (eg. forcefield hum)
1764 digi_stop_digi_sounds(); //kill any continuing sounds (eg. forcefield hum)
1766 dead_player_end(); //terminate death sequence (if playing)
1769 if (Game_mode == GM_EDITOR) { //test mine, not real level
1770 object * playerobj = &Objects[Players[Player_num].objnum];
1771 //nm_messagebox( "You're Dead!", 1, "Continue", "Not a real game, though." );
1772 load_level("gamesave.lvl");
1773 init_player_stats_new_ship();
1774 playerobj->flags &= ~OF_SHOULD_BE_DEAD;
1781 if ( Game_mode&GM_MULTI )
1783 multi_do_death(Players[Player_num].objnum);
1787 { //Note link to above else!
1788 Players[Player_num].lives--;
1789 if (Players[Player_num].lives == 0)
1796 if ( Control_center_destroyed ) {
1798 //clear out stuff so no bonus
1799 Players[Player_num].hostages_on_board = 0;
1800 Players[Player_num].energy = 0;
1801 Players[Player_num].shields = 0;
1802 Players[Player_num].connected = 3;
1804 died_in_mine_message(); // Give them some indication of what happened
1806 if (Current_level_num < 0) {
1807 if (cfexist(SECRETB_FILENAME))
1809 returning_to_level_message();
1810 state_restore_all(1, 2, SECRETB_FILENAME); // 2 means you died
1811 set_pos_from_return_segment();
1812 Players[Player_num].lives--; // re-lose the life, Players[Player_num].lives got written over in restore.
1814 advancing_to_level_message();
1815 StartNewLevel(Entered_from_level+1, 0);
1816 init_player_stats_new_ship(); // New, MK, 05/29/96!, fix bug with dying in secret level, advance to next level, keep powerups!
1820 AdvanceLevel(0); //if finished, go on to next level
1822 init_player_stats_new_ship();
1823 last_drawn_cockpit[0] = -1;
1824 last_drawn_cockpit[1] = -1;
1827 } else if (Current_level_num < 0) {
1828 if (cfexist(SECRETB_FILENAME))
1830 returning_to_level_message();
1831 if (!Control_center_destroyed)
1832 state_save_all(0, 2, SECRETC_FILENAME);
1833 state_restore_all(1, 2, SECRETB_FILENAME);
1834 set_pos_from_return_segment();
1835 Players[Player_num].lives--; // re-lose the life, Players[Player_num].lives got written over in restore.
1837 died_in_mine_message(); // Give them some indication of what happened
1838 advancing_to_level_message();
1839 StartNewLevel(Entered_from_level+1, 0);
1840 init_player_stats_new_ship();
1843 init_player_stats_new_ship();
1850 extern int BigWindowSwitch;
1852 //called when the player is starting a new level for normal game mode and restore state
1853 // secret_flag set if came from a secret level
1854 void StartNewLevelSub(int level_num, int page_in_textures, int secret_flag)
1856 if (!(Game_mode & GM_MULTI)) {
1857 last_drawn_cockpit[0] = -1;
1858 last_drawn_cockpit[1] = -1;
1863 if (Newdemo_state == ND_STATE_PAUSED)
1864 Newdemo_state = ND_STATE_RECORDING;
1866 if (Newdemo_state == ND_STATE_RECORDING) {
1867 newdemo_set_new_level(level_num);
1868 newdemo_record_start_frame(FrameCount, FrameTime );
1871 if (Game_mode & GM_MULTI)
1872 Function_mode = FMODE_MENU; // Cheap fix to prevent problems with errror dialogs in loadlevel.
1874 LoadLevel(level_num,page_in_textures);
1876 Assert(Current_level_num == level_num); //make sure level set right
1878 gameseq_init_network_players(); // Initialize the Players array for
1881 Viewer = &Objects[Players[Player_num].objnum];
1883 Assert(N_players <= NumNetPlayerPositions);
1884 //If this assert fails, there's not enough start positions
1887 if (Game_mode & GM_NETWORK)
1889 if(network_level_sync()) // After calling this, Player_num is set
1892 if ((Game_mode & GM_SERIAL) || (Game_mode & GM_MODEM))
1894 if(com_level_sync())
1899 Assert(Function_mode == FMODE_GAME);
1902 //-- mprintf((0, "Player_num = %d, N_players = %d.\n", Player_num, N_players)); // DEBUG
1905 HUD_clear_messages();
1907 automap_clear_visited();
1910 if (Network_new_game == 1)
1912 Network_new_game = 0;
1913 init_player_stats_new_ship();
1916 init_player_stats_level(secret_flag);
1919 if ((Game_mode & GM_MULTI_COOP) && Network_rejoined)
1922 for (i = 0; i < N_players; i++)
1923 Players[i].flags |= Netgame.player_flags[i];
1926 if (Game_mode & GM_MULTI)
1928 multi_prep_level(); // Removes robots from level if necessary
1932 gameseq_remove_unused_players();
1936 Control_center_destroyed = 0;
1938 set_screen_mode(SCREEN_GAME);
1940 init_robots_for_level();
1942 init_smega_detonates();
1945 reset_palette_add();
1946 init_thief_for_level();
1947 init_stuck_objects();
1948 game_flush_inputs(); // clear out the keyboard
1949 if (!(Game_mode & GM_MULTI))
1950 filter_objects_from_level();
1954 if (!(Game_mode & GM_MULTI) && !Cheats_enabled)
1955 set_highest_level(Current_level_num);
1957 read_player_file(); //get window sizes
1959 reset_special_effects();
1962 gr_remap_mono_fonts();
1963 ogl_cache_level_textures();
1968 if (Network_rejoined == 1)
1971 mprintf((0, "Restarting - joining in random location.\n"));
1973 Network_rejoined = 0;
1978 StartLevel(0); // Note link to above if!
1980 copy_defaults_to_robot_all();
1981 init_controlcen_for_level();
1983 // Say player can use FLASH cheat to mark path to exit.
1984 Last_level_path_created = -1;
1988 extern char PowerupsInMine[MAX_POWERUP_TYPES], MaxPowerupsAllowed[MAX_POWERUP_TYPES];
1990 void bash_to_shield (int i,char *s)
1993 int type=Objects[i].id;
1996 mprintf((0, "Bashing %s object #%i to shield.\n",s, i));
1999 PowerupsInMine[type]=MaxPowerupsAllowed[type]=0;
2002 Objects[i].id = POW_SHIELD_BOOST;
2003 Objects[i].rtype.vclip_info.vclip_num = Powerup_info[Objects[i].id].vclip_num;
2004 Objects[i].rtype.vclip_info.frametime = Vclip[Objects[i].rtype.vclip_info.vclip_num].frame_time;
2008 void filter_objects_from_level()
2012 mprintf ((0,"Highest object index=%d\n",Highest_object_index));
2014 for (i=0;i<=Highest_object_index;i++)
2016 if (Objects[i].type==OBJ_POWERUP)
2017 if (Objects[i].id==POW_FLAG_RED || Objects[i].id==POW_FLAG_BLUE)
2018 bash_to_shield (i,"Flag!!!!");
2025 char movie_name[FILENAME_LEN];
2026 } intro_movie[] = { { 1,"pla"},
2034 #define NUM_INTRO_MOVIES (sizeof(intro_movie) / sizeof(*intro_movie))
2036 extern int MenuHiresAvailable;
2037 extern int robot_movies; //0 means none, 1 means lowres, 2 means hires
2038 extern int intro_played; //true if big intro movie played
2040 void ShowLevelIntro(int level_num)
2042 //if shareware, show a briefing?
2044 if (!(Game_mode & GM_MULTI)) {
2047 ubyte save_pal[sizeof(gr_palette)];
2049 memcpy(save_pal,gr_palette,sizeof(gr_palette));
2051 if (PLAYING_BUILTIN_MISSION) {
2057 do_briefing_screens ("brief2.tex", 1);
2061 if (level_num == 1 && !intro_played)
2062 do_briefing_screens("brief2o.tex", 1);
2064 else // full version
2066 for (i=0;i<NUM_INTRO_MOVIES;i++)
2068 if (intro_movie[i].level_num == level_num)
2071 PlayMovie(intro_movie[i].movie_name,MOVIE_REQUIRED);
2078 if (!movie) { //must go before briefing
2079 dd_gr_init_screen();
2086 int hires_save=MenuHiresAvailable;
2088 if (robot_movies == 1) //lowres only
2090 MenuHiresAvailable = 0; //pretend we can't do highres
2092 if (hires_save != MenuHiresAvailable)
2093 Screen_mode = -1; //force reset
2096 do_briefing_screens ("robot.tex",level_num);
2097 MenuHiresAvailable = hires_save;
2102 else { //not the built-in mission. check for add-on briefing
2104 do_briefing_screens(Briefing_text_filename, level_num);
2106 char tname[FILENAME_LEN];
2107 sprintf(tname, "%s.tex", Current_mission_filename);
2108 do_briefing_screens(tname, level_num);
2113 memcpy(gr_palette,save_pal,sizeof(gr_palette));
2117 // ---------------------------------------------------------------------------
2118 // If starting a level which appears in the Secret_level_table, then set First_secret_visit.
2119 // Reason: On this level, if player goes to a secret level, he will be going to a different
2120 // secret level than he's ever been to before.
2121 // Sets the global First_secret_visit if necessary. Otherwise leaves it unchanged.
2122 void maybe_set_first_secret_visit(int level_num)
2126 for (i=0; i<N_secret_levels; i++) {
2127 if (Secret_level_table[i] == level_num) {
2128 First_secret_visit = 1;
2129 mprintf((0, "Bashing First_secret_visit to 1 because entering level %i.\n", level_num));
2134 //called when the player is starting a new level for normal game model
2135 // secret_flag if came from a secret level
2136 void StartNewLevel(int level_num, int secret_flag)
2140 if ((level_num > 0) && (!secret_flag)) {
2141 maybe_set_first_secret_visit(level_num);
2144 ShowLevelIntro(level_num);
2146 WIN(DEFINE_SCREEN(NULL)); // ALT-TAB: no restore of background.
2148 StartNewLevelSub(level_num, 1, secret_flag );
2152 //initialize the player object position & orientation (at start of game, or new ship)
2153 void InitPlayerPosition(int random_flag)
2158 if (! ((Game_mode & GM_MULTI) && !(Game_mode&GM_MULTI_COOP)) ) // If not deathmatch
2160 NewPlayer = Player_num;
2162 else if (random_flag == 1)
2164 int i, closest = -1, trys=0;
2165 fix closest_dist = 0x7ffffff, dist;
2170 if (NumNetPlayerPositions != MAX_NUM_NET_PLAYERS)
2172 mprintf((1, "WARNING: There are only %d start positions!\n"));
2180 mprintf((0, "Can't start in location %d because its too close to player %d\n", NewPlayer, closest ));
2184 NewPlayer = d_rand() % NumNetPlayerPositions;
2187 closest_dist = 0x7fffffff;
2189 for (i=0; i<N_players; i++ ) {
2190 if ( (i!=Player_num) && (Objects[Players[i].objnum].type == OBJ_PLAYER) ) {
2191 dist = find_connected_distance(&Objects[Players[i].objnum].pos, Objects[Players[i].objnum].segnum, &Player_init[NewPlayer].pos, Player_init[NewPlayer].segnum, 10, WID_FLY_FLAG ); // Used to be 5, search up to 10 segments
2192 // -- mprintf((0, "Distance from start location %d to player %d is %f.\n", NewPlayer, i, f2fl(dist)));
2193 if ( (dist < closest_dist) && (dist >= 0) ) {
2194 closest_dist = dist;
2200 // -- mprintf((0, "Closest from pos %d is %f to plr %d.\n", NewPlayer, f2fl(closest_dist), closest));
2201 } while ( (closest_dist<i2f(15*20)) && (trys<MAX_NUM_NET_PLAYERS*2) );
2204 mprintf((0, "Starting position is not being changed.\n"));
2205 goto done; // If deathmatch and not random, positions were already determined by sync packet
2207 Assert(NewPlayer >= 0);
2208 Assert(NewPlayer < NumNetPlayerPositions);
2211 ConsoleObject->pos = Player_init[NewPlayer].pos;
2212 ConsoleObject->orient = Player_init[NewPlayer].orient;
2213 // -- mprintf((0, "Pos set to %8x %8x %8x\n", ConsoleObject->pos.x, ConsoleObject->pos.y, ConsoleObject->pos.z));
2215 // -- mprintf((0, "Re-starting in location %d of %d.\n", NewPlayer+1, NumNetPlayerPositions));
2217 obj_relink(ConsoleObject-Objects,Player_init[NewPlayer].segnum);
2222 reset_player_object();
2226 // -----------------------------------------------------------------------------------------------------
2227 // Initialize default parameters for one robot, copying from Robot_info to *objp.
2228 // What about setting size!? Where does that come from?
2229 void copy_defaults_to_robot(object *objp)
2234 Assert(objp->type == OBJ_ROBOT);
2236 Assert(objid < N_robot_types);
2238 robptr = &Robot_info[objid];
2240 // Boost shield for Thief and Buddy based on level.
2241 objp->shields = robptr->strength;
2243 if ((robptr->thief) || (robptr->companion)) {
2244 objp->shields = (objp->shields * (abs(Current_level_num)+7))/8;
2246 if (robptr->companion) {
2247 // Now, scale guide-bot hits by skill level
2248 switch (Difficulty_level) {
2249 case 0: objp->shields = i2f(20000); break; // Trainee, basically unkillable
2250 case 1: objp->shields *= 3; break; // Rookie, pretty dang hard
2251 case 2: objp->shields *= 2; break; // Hotshot, a bit tough
2255 } else if (robptr->boss_flag) // MK, 01/16/95, make boss shields lower on lower diff levels.
2256 objp->shields = objp->shields/(NDL+3) * (Difficulty_level+4);
2258 // Additional wimpification of bosses at Trainee
2259 if ((robptr->boss_flag) && (Difficulty_level == 0))
2263 // -----------------------------------------------------------------------------------------------------
2264 // Copy all values from the robot info structure to all instances of robots.
2265 // This allows us to change bitmaps.tbl and have these changes manifested in existing robots.
2266 // This function should be called at level load time.
2267 void copy_defaults_to_robot_all()
2271 for (i=0; i<=Highest_object_index; i++)
2272 if (Objects[i].type == OBJ_ROBOT)
2273 copy_defaults_to_robot(&Objects[i]);
2277 extern void clear_stuck_objects(void);
2279 // -----------------------------------------------------------------------------------------------------
2280 //called when the player is starting a level (new game or new ship)
2281 void StartLevel(int random_flag)
2283 Assert(!Player_is_dead);
2285 InitPlayerPosition(random_flag);
2287 verify_console_object();
2289 ConsoleObject->control_type = CT_FLYING;
2290 ConsoleObject->movement_type = MT_PHYSICS;
2294 clear_transient_objects(0); //0 means leave proximity bombs
2296 // create_player_appearance_effect(ConsoleObject);
2297 Do_appearance_effect = 1;
2300 if (Game_mode & GM_MULTI)
2302 if (Game_mode & GM_MULTI_COOP)
2304 multi_send_position(Players[Player_num].objnum);
2305 multi_send_reappear();
2308 if (Game_mode & GM_NETWORK)
2309 network_do_frame(1, 1);
2312 ai_reset_all_paths();
2313 ai_init_boss_for_ship();
2314 clear_stuck_objects();
2317 // Note, this is only done if editor builtin. Calling this from here
2318 // will cause it to be called after the player dies, resetting the
2319 // hits for the buddy and thief. This is ok, since it will work ok
2320 // in a shipped version.
2327 Auto_fire_fusion_cannon_time = 0;
2330 Robot_firing_enabled = 1;