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-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
16 * Routines for placing hostages, etc...
24 #if 0 // the hostage code was simplified for Descent 2
63 //-------------------------------------------------------------------------
64 // Variables for this module...
65 //-------------------------------------------------------------------------
66 static UI_WINDOW *MainWindow = NULL;
67 static UI_GADGET_USERBOX *HostageViewBox;
68 static UI_GADGET_INPUTBOX *HostageText;
69 static UI_GADGET_BUTTON *QuitButton;
70 static int CurrentHostageIndex=-1;
71 static int LastHostageIndex=-1;
73 static fix Vclip_animation_time=0; // How long the rescue sequence has been playing
74 static fix Vclip_playback_speed=0; // Calculated internally. Frames/second of vclip.
75 static vclip *Vclip_ptr = NULL; // Used for the vclip on monitor
77 void vclip_play( vclip * vc, fix frame_time )
84 if ( vc != Vclip_ptr ) {
87 Vclip_animation_time = 1;
89 // Calculate the frame/second of the playback
90 Vclip_playback_speed = fixdiv(i2f(Vclip_ptr->num_frames),Vclip_ptr->play_time);
93 if ( Vclip_animation_time <= 0 )
96 // Find next bitmap in the vclip
97 bitmapnum = f2i(Vclip_animation_time);
99 // Check if vclip is done playing.
100 if (bitmapnum >= Vclip_ptr->num_frames) {
101 Vclip_animation_time = 1; // Restart this vclip
105 PIGGY_PAGE_IN( Vclip_ptr->frames[bitmapnum] );
106 gr_bitmap(0,0,&GameBitmaps[Vclip_ptr->frames[bitmapnum].index] );
108 Vclip_animation_time += fixmul(frame_time, Vclip_playback_speed );
113 static char HostageMessage[] = " ";
117 int SelectPrevHostage() {
121 CurrentHostageIndex--;
122 if ( CurrentHostageIndex < 0 ) CurrentHostageIndex = MAX_HOSTAGES-1;
124 if ( start > MAX_HOSTAGES ) break;
125 } while ( !hostage_is_valid( CurrentHostageIndex ) );
127 if (hostage_is_valid( CurrentHostageIndex ) ) {
128 Cur_object_index = Hostages[CurrentHostageIndex].objnum;
130 CurrentHostageIndex =-1;
133 return CurrentHostageIndex;
137 int SelectNextHostage() {
141 CurrentHostageIndex++;
142 if ( CurrentHostageIndex >= MAX_HOSTAGES ) CurrentHostageIndex = 0;
144 if ( start > MAX_HOSTAGES ) break;
145 } while ( !hostage_is_valid( CurrentHostageIndex ) );
147 if (hostage_is_valid( CurrentHostageIndex ) ) {
148 Cur_object_index = Hostages[CurrentHostageIndex].objnum;
150 CurrentHostageIndex =-1;
153 return CurrentHostageIndex;
157 int SelectClosestHostage() {
160 while ( !hostage_is_valid( CurrentHostageIndex ) ) {
161 CurrentHostageIndex++;
162 if ( CurrentHostageIndex >= MAX_HOSTAGES ) CurrentHostageIndex = 0;
164 if ( start > MAX_HOSTAGES ) break;
167 if (hostage_is_valid( CurrentHostageIndex ) ) {
168 Cur_object_index = Hostages[CurrentHostageIndex].objnum;
170 CurrentHostageIndex =-1;
173 return CurrentHostageIndex;
179 vms_vector cur_object_loc;
181 //update_due_to_new_segment();
182 compute_segment_center(&cur_object_loc, Cursegp);
185 for (i=0; i<Num_total_object_types; i++ ) {
186 if (ObjType[i] == OL_HOSTAGE ) {
192 Assert( ctype != -1 );
194 if (place_object(Cursegp, &cur_object_loc, ctype )==0) {
195 Int3(); // Debug below
196 i=place_object(Cursegp, &cur_object_loc, ctype );
200 if (hostage_object_is_valid( Cur_object_index ) ) {
201 CurrentHostageIndex = Objects[Cur_object_index].id;
203 Int3(); // Get John! (Object should be valid)
204 i=hostage_object_is_valid( Cur_object_index ); // For debugging only
210 int CompressHostages()
212 hostage_compress_all();
217 //@@int SelectPrevVclip() {
218 //@@ if (!hostage_is_valid( CurrentHostageIndex ) )
221 //@@ if ( Hostages[CurrentHostageIndex].type == 0 )
222 //@@ Hostages[CurrentHostageIndex].type = N_hostage_types-1;
224 //@@ Hostages[CurrentHostageIndex].type--;
226 //@@ if ( Hostages[CurrentHostageIndex].type >= N_hostage_types )
227 //@@ Hostages[CurrentHostageIndex].type = 0;
232 //@@int SelectNextVclip() {
233 //@@ if (!hostage_is_valid( CurrentHostageIndex ) )
236 //@@ Hostages[CurrentHostageIndex].type++;
237 //@@ if ( Hostages[CurrentHostageIndex].type >= N_hostage_types )
238 //@@ Hostages[CurrentHostageIndex].type = 0;
245 int start = Hostages[CurrentHostageIndex].vclip_num;
247 if (!hostage_is_valid( CurrentHostageIndex ) )
251 Hostages[CurrentHostageIndex].vclip_num++;
252 if ( Hostages[CurrentHostageIndex].vclip_num >= MAX_HOSTAGES)
253 Hostages[CurrentHostageIndex].vclip_num = 0;
255 if (Hostages[CurrentHostageIndex].vclip_num == start)
258 } while (Hostage_face_clip[Hostages[CurrentHostageIndex].vclip_num].num_frames == 0);
265 int start = Hostages[CurrentHostageIndex].vclip_num;
267 if (!hostage_is_valid( CurrentHostageIndex ) )
271 Hostages[CurrentHostageIndex].vclip_num--;
272 if ( Hostages[CurrentHostageIndex].vclip_num < 0)
273 Hostages[CurrentHostageIndex].vclip_num = MAX_HOSTAGES-1;
275 if (Hostages[CurrentHostageIndex].vclip_num == start)
278 } while (Hostage_face_clip[Hostages[CurrentHostageIndex].vclip_num].num_frames == 0);
283 int PlayHostageSound() {
286 if (!hostage_is_valid( CurrentHostageIndex ) )
289 sound_num = Hostage_face_clip[Hostages[CurrentHostageIndex].vclip_num].sound_num;
291 if ( sound_num > -1 ) {
292 digi_play_sample( sound_num, F1_0 );
298 //@@int find_next_hostage_sound() {
301 //@@ n = Hostages[CurrentHostageIndex].sound_num;
304 //@@ if ( n < SOUND_HOSTAGE_VOICES ) n = SOUND_HOSTAGE_VOICES+MAX_HOSTAGE_SOUNDS-1;
305 //@@ if ( n >= SOUND_HOSTAGE_VOICES+MAX_HOSTAGE_SOUNDS ) n = SOUND_HOSTAGE_VOICES;
307 //@@ if ( start > MAX_HOSTAGE_SOUNDS ) break;
308 //@@ } while ( Sounds[n] == NULL );
310 //@@ if ( Sounds[n] == NULL )
311 //@@ Hostages[CurrentHostageIndex].sound_num = -1;
313 //@@ Hostages[CurrentHostageIndex].sound_num = n;
314 //@@ PlayHostageSound();
319 //@@int find_prev_hostage_sound() {
322 //@@ n = Hostages[CurrentHostageIndex].sound_num;
325 //@@ if ( n < SOUND_HOSTAGE_VOICES ) n = SOUND_HOSTAGE_VOICES+MAX_HOSTAGE_SOUNDS-1;
326 //@@ if ( n >= SOUND_HOSTAGE_VOICES+MAX_HOSTAGE_SOUNDS ) n = SOUND_HOSTAGE_VOICES;
328 //@@ if ( start > MAX_HOSTAGE_SOUNDS ) break;
329 //@@ } while ( Sounds[n] == NULL );
331 //@@ if ( Sounds[n] == NULL )
332 //@@ Hostages[CurrentHostageIndex].sound_num = -1;
334 //@@ Hostages[CurrentHostageIndex].sound_num = n;
335 //@@ PlayHostageSound();
342 //-------------------------------------------------------------------------
343 // Called from the editor... does one instance of the hostage dialog box
344 //-------------------------------------------------------------------------
345 int do_hostage_dialog()
350 // Only open 1 instance of this window...
351 if ( MainWindow != NULL ) return 0;
353 // Close other windows
356 CurrentHostageIndex = 0;
357 SelectClosestHostage();
359 // Open a window with a quit button
360 MainWindow = ui_open_window( TMAPBOX_X+10, TMAPBOX_Y+20, 765-TMAPBOX_X, 545-TMAPBOX_Y, WIN_DIALOG );
361 QuitButton = ui_add_gadget_button( MainWindow, 20, 222, 48, 40, "Done", NULL );
363 ui_wprintf_at( MainWindow, 10, 32,"&Message:" );
364 HostageText = ui_add_gadget_inputbox( MainWindow, 10, 50, HOSTAGE_MESSAGE_LEN, HOSTAGE_MESSAGE_LEN, HostageMessage );
366 // The little box the hostage vclip will play in.
367 HostageViewBox = ui_add_gadget_userbox( MainWindow,10, 90+10, 64, 64 );
369 // A bunch of buttons...
371 //@@ ui_add_gadget_button( MainWindow,155,i,70, 26, "<< Type", SelectPrevVclip );
372 //@@ ui_add_gadget_button( MainWindow,155+70,i,70, 26, "Type >>", SelectNextVclip );i += 29;
373 //@@ ui_add_gadget_button( MainWindow,155,i,70, 26, "<< Sound", find_prev_hostage_sound );
374 //@@ ui_add_gadget_button( MainWindow,155+70,i,70, 26, "Sound >>", find_next_hostage_sound );i += 29;
376 ui_add_gadget_button( MainWindow,155,i,70, 26, "<< Face", SelectPrevFace );
377 ui_add_gadget_button( MainWindow,155+70,i,70, 26, "Face >>", SelectNextFace );i += 29;
378 ui_add_gadget_button( MainWindow,155,i,140, 26, "Play sound", PlayHostageSound );i += 29;
379 ui_add_gadget_button( MainWindow,155,i,140, 26, "Next Hostage", SelectNextHostage ); i += 29;
380 ui_add_gadget_button( MainWindow,155,i,140, 26, "Prev Hostage", SelectPrevHostage ); i += 29;
381 ui_add_gadget_button( MainWindow,155,i,140, 26, "Compress All", CompressHostages ); i += 29;
382 ui_add_gadget_button( MainWindow,155,i,140, 26, "Delete", ObjectDelete ); i += 29;
383 ui_add_gadget_button( MainWindow,155,i,140, 26, "Create New", PlaceHostage ); i += 29;
385 Time = timer_get_fixed_seconds();
387 LastHostageIndex = -2; // Set to some dummy value so everything works ok on the first frame.
389 // if ( CurrentHostageIndex == -1 )
390 // SelectNextHostage();
396 void hostage_close_window()
399 if ( MainWindow!=NULL ) {
400 ui_close_window( MainWindow );
406 void do_hostage_window()
411 if ( MainWindow == NULL ) return;
413 SelectClosestHostage();
415 //------------------------------------------------------------
416 // Call the ui code..
417 //------------------------------------------------------------
418 ui_button_any_drawn = 0;
419 ui_window_do_gadgets(MainWindow);
421 //------------------------------------------------------------
422 // If we change objects, we need to reset the ui code for all
423 // of the radio buttons that control the ai mode. Also makes
424 // the current AI mode button be flagged as pressed down.
425 //------------------------------------------------------------
426 if (LastHostageIndex != CurrentHostageIndex ) {
428 if ( CurrentHostageIndex > -1 )
429 strcpy( HostageText->text, Hostages[CurrentHostageIndex].text );
431 strcpy(HostageText->text, " " );
433 HostageText->position = strlen(HostageText->text);
434 HostageText->oldposition = HostageText->position;
435 HostageText->status=1;
436 HostageText->first_time = 1;
440 //------------------------------------------------------------
441 // If any of the radio buttons that control the mode are set, then
442 // update the cooresponding AI state.
443 //------------------------------------------------------------
444 if ( CurrentHostageIndex > -1 )
445 strcpy( Hostages[CurrentHostageIndex].text, HostageText->text );
447 //------------------------------------------------------------
448 // A simple frame time counter for spinning the objects...
449 //------------------------------------------------------------
450 Temp = timer_get_fixed_seconds();
451 DeltaTime = Temp - Time;
454 //------------------------------------------------------------
455 // Redraw the object in the little 64x64 box
456 //------------------------------------------------------------
457 if (CurrentHostageIndex > -1 ) {
460 vclip_num = Hostages[CurrentHostageIndex].vclip_num;
462 Assert(vclip_num != -1);
464 gr_set_current_canvas( HostageViewBox->canvas );
466 if ( vclip_num > -1 ) {
467 vclip_play( &Hostage_face_clip[vclip_num], DeltaTime );
469 gr_clear_canvas( CGREY );
472 // no hostage, so just blank out
473 gr_set_current_canvas( HostageViewBox->canvas );
474 gr_clear_canvas( CGREY );
477 //------------------------------------------------------------
478 // If anything changes in the ui system, redraw all the text that
479 // identifies this robot.
480 //------------------------------------------------------------
481 if (ui_button_any_drawn || (LastHostageIndex != CurrentHostageIndex) ) {
482 if ( CurrentHostageIndex > -1 ) {
483 ui_wprintf_at( MainWindow, 10, 15, "Hostage: %d Object: %d", CurrentHostageIndex, Hostages[CurrentHostageIndex].objnum );
484 //@@ui_wprintf_at( MainWindow, 10, 73, "Type: %d Sound: %d ", Hostages[CurrentHostageIndex].type, Hostages[CurrentHostageIndex].sound_num );
485 ui_wprintf_at( MainWindow, 10, 73, "Face: %d ", Hostages[CurrentHostageIndex].vclip_num);
487 ui_wprintf_at( MainWindow, 10, 15, "Hostage: none " );
488 //@@ui_wprintf_at( MainWindow, 10, 73, "Type: Sound: " );
489 ui_wprintf_at( MainWindow, 10, 73, "Face: " );
491 Update_flags |= UF_WORLD_CHANGED;
494 if ( QuitButton->pressed || (last_keypress==KEY_ESC)) {
495 hostage_close_window();
499 LastHostageIndex = CurrentHostageIndex;