1 /* $Id: ehostage.c,v 1.5 2005-01-24 21:33:28 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-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
17 * Routines for placing hostages, etc...
22 static char rcsid[] = "$Id: ehostage.c,v 1.5 2005-01-24 21:33:28 schaffner Exp $";
29 #if 0 // the hostage code was simplified for Descent 2
68 //-------------------------------------------------------------------------
69 // Variables for this module...
70 //-------------------------------------------------------------------------
71 static UI_WINDOW *MainWindow = NULL;
72 static UI_GADGET_USERBOX *HostageViewBox;
73 static UI_GADGET_INPUTBOX *HostageText;
74 static UI_GADGET_BUTTON *QuitButton;
75 static int CurrentHostageIndex=-1;
76 static int LastHostageIndex=-1;
78 static fix Vclip_animation_time=0; // How long the rescue sequence has been playing
79 static fix Vclip_playback_speed=0; // Calculated internally. Frames/second of vclip.
80 static vclip *Vclip_ptr = NULL; // Used for the vclip on monitor
82 void vclip_play( vclip * vc, fix frame_time )
89 if ( vc != Vclip_ptr ) {
92 Vclip_animation_time = 1;
94 // Calculate the frame/second of the playback
95 Vclip_playback_speed = fixdiv(i2f(Vclip_ptr->num_frames),Vclip_ptr->play_time);
98 if ( Vclip_animation_time <= 0 )
101 // Find next bitmap in the vclip
102 bitmapnum = f2i(Vclip_animation_time);
104 // Check if vclip is done playing.
105 if (bitmapnum >= Vclip_ptr->num_frames) {
106 Vclip_animation_time = 1; // Restart this vclip
110 PIGGY_PAGE_IN( Vclip_ptr->frames[bitmapnum] );
111 gr_bitmap(0,0,&GameBitmaps[Vclip_ptr->frames[bitmapnum].index] );
113 Vclip_animation_time += fixmul(frame_time, Vclip_playback_speed );
118 static char HostageMessage[] = " ";
122 int SelectPrevHostage() {
126 CurrentHostageIndex--;
127 if ( CurrentHostageIndex < 0 ) CurrentHostageIndex = MAX_HOSTAGES-1;
129 if ( start > MAX_HOSTAGES ) break;
130 } while ( !hostage_is_valid( CurrentHostageIndex ) );
132 if (hostage_is_valid( CurrentHostageIndex ) ) {
133 Cur_object_index = Hostages[CurrentHostageIndex].objnum;
135 CurrentHostageIndex =-1;
138 return CurrentHostageIndex;
142 int SelectNextHostage() {
146 CurrentHostageIndex++;
147 if ( CurrentHostageIndex >= MAX_HOSTAGES ) CurrentHostageIndex = 0;
149 if ( start > MAX_HOSTAGES ) break;
150 } while ( !hostage_is_valid( CurrentHostageIndex ) );
152 if (hostage_is_valid( CurrentHostageIndex ) ) {
153 Cur_object_index = Hostages[CurrentHostageIndex].objnum;
155 CurrentHostageIndex =-1;
158 return CurrentHostageIndex;
162 int SelectClosestHostage() {
165 while ( !hostage_is_valid( CurrentHostageIndex ) ) {
166 CurrentHostageIndex++;
167 if ( CurrentHostageIndex >= MAX_HOSTAGES ) CurrentHostageIndex = 0;
169 if ( start > MAX_HOSTAGES ) break;
172 if (hostage_is_valid( CurrentHostageIndex ) ) {
173 Cur_object_index = Hostages[CurrentHostageIndex].objnum;
175 CurrentHostageIndex =-1;
178 return CurrentHostageIndex;
184 vms_vector cur_object_loc;
186 //update_due_to_new_segment();
187 compute_segment_center(&cur_object_loc, Cursegp);
190 for (i=0; i<Num_total_object_types; i++ ) {
191 if (ObjType[i] == OL_HOSTAGE ) {
197 Assert( ctype != -1 );
199 if (place_object(Cursegp, &cur_object_loc, ctype )==0) {
200 Int3(); // Debug below
201 i=place_object(Cursegp, &cur_object_loc, ctype );
205 if (hostage_object_is_valid( Cur_object_index ) ) {
206 CurrentHostageIndex = Objects[Cur_object_index].id;
208 Int3(); // Get John! (Object should be valid)
209 i=hostage_object_is_valid( Cur_object_index ); // For debugging only
215 int CompressHostages()
217 hostage_compress_all();
222 //@@int SelectPrevVclip() {
223 //@@ if (!hostage_is_valid( CurrentHostageIndex ) )
226 //@@ if ( Hostages[CurrentHostageIndex].type == 0 )
227 //@@ Hostages[CurrentHostageIndex].type = N_hostage_types-1;
229 //@@ Hostages[CurrentHostageIndex].type--;
231 //@@ if ( Hostages[CurrentHostageIndex].type >= N_hostage_types )
232 //@@ Hostages[CurrentHostageIndex].type = 0;
237 //@@int SelectNextVclip() {
238 //@@ if (!hostage_is_valid( CurrentHostageIndex ) )
241 //@@ Hostages[CurrentHostageIndex].type++;
242 //@@ if ( Hostages[CurrentHostageIndex].type >= N_hostage_types )
243 //@@ Hostages[CurrentHostageIndex].type = 0;
250 int start = Hostages[CurrentHostageIndex].vclip_num;
252 if (!hostage_is_valid( CurrentHostageIndex ) )
256 Hostages[CurrentHostageIndex].vclip_num++;
257 if ( Hostages[CurrentHostageIndex].vclip_num >= MAX_HOSTAGES)
258 Hostages[CurrentHostageIndex].vclip_num = 0;
260 if (Hostages[CurrentHostageIndex].vclip_num == start)
263 } while (Hostage_face_clip[Hostages[CurrentHostageIndex].vclip_num].num_frames == 0);
270 int start = Hostages[CurrentHostageIndex].vclip_num;
272 if (!hostage_is_valid( CurrentHostageIndex ) )
276 Hostages[CurrentHostageIndex].vclip_num--;
277 if ( Hostages[CurrentHostageIndex].vclip_num < 0)
278 Hostages[CurrentHostageIndex].vclip_num = MAX_HOSTAGES-1;
280 if (Hostages[CurrentHostageIndex].vclip_num == start)
283 } while (Hostage_face_clip[Hostages[CurrentHostageIndex].vclip_num].num_frames == 0);
288 int PlayHostageSound() {
291 if (!hostage_is_valid( CurrentHostageIndex ) )
294 sound_num = Hostage_face_clip[Hostages[CurrentHostageIndex].vclip_num].sound_num;
296 if ( sound_num > -1 ) {
297 digi_play_sample( sound_num, F1_0 );
303 //@@int find_next_hostage_sound() {
306 //@@ n = Hostages[CurrentHostageIndex].sound_num;
309 //@@ if ( n < SOUND_HOSTAGE_VOICES ) n = SOUND_HOSTAGE_VOICES+MAX_HOSTAGE_SOUNDS-1;
310 //@@ if ( n >= SOUND_HOSTAGE_VOICES+MAX_HOSTAGE_SOUNDS ) n = SOUND_HOSTAGE_VOICES;
312 //@@ if ( start > MAX_HOSTAGE_SOUNDS ) break;
313 //@@ } while ( Sounds[n] == NULL );
315 //@@ if ( Sounds[n] == NULL )
316 //@@ Hostages[CurrentHostageIndex].sound_num = -1;
318 //@@ Hostages[CurrentHostageIndex].sound_num = n;
319 //@@ PlayHostageSound();
324 //@@int find_prev_hostage_sound() {
327 //@@ n = Hostages[CurrentHostageIndex].sound_num;
330 //@@ if ( n < SOUND_HOSTAGE_VOICES ) n = SOUND_HOSTAGE_VOICES+MAX_HOSTAGE_SOUNDS-1;
331 //@@ if ( n >= SOUND_HOSTAGE_VOICES+MAX_HOSTAGE_SOUNDS ) n = SOUND_HOSTAGE_VOICES;
333 //@@ if ( start > MAX_HOSTAGE_SOUNDS ) break;
334 //@@ } while ( Sounds[n] == NULL );
336 //@@ if ( Sounds[n] == NULL )
337 //@@ Hostages[CurrentHostageIndex].sound_num = -1;
339 //@@ Hostages[CurrentHostageIndex].sound_num = n;
340 //@@ PlayHostageSound();
347 //-------------------------------------------------------------------------
348 // Called from the editor... does one instance of the hostage dialog box
349 //-------------------------------------------------------------------------
350 int do_hostage_dialog()
355 // Only open 1 instance of this window...
356 if ( MainWindow != NULL ) return 0;
358 // Close other windows
361 CurrentHostageIndex = 0;
362 SelectClosestHostage();
364 // Open a window with a quit button
365 MainWindow = ui_open_window( TMAPBOX_X+10, TMAPBOX_Y+20, 765-TMAPBOX_X, 545-TMAPBOX_Y, WIN_DIALOG );
366 QuitButton = ui_add_gadget_button( MainWindow, 20, 222, 48, 40, "Done", NULL );
368 ui_wprintf_at( MainWindow, 10, 32,"&Message:" );
369 HostageText = ui_add_gadget_inputbox( MainWindow, 10, 50, HOSTAGE_MESSAGE_LEN, HOSTAGE_MESSAGE_LEN, HostageMessage );
371 // The little box the hostage vclip will play in.
372 HostageViewBox = ui_add_gadget_userbox( MainWindow,10, 90+10, 64, 64 );
374 // A bunch of buttons...
376 //@@ ui_add_gadget_button( MainWindow,155,i,70, 26, "<< Type", SelectPrevVclip );
377 //@@ ui_add_gadget_button( MainWindow,155+70,i,70, 26, "Type >>", SelectNextVclip );i += 29;
378 //@@ ui_add_gadget_button( MainWindow,155,i,70, 26, "<< Sound", find_prev_hostage_sound );
379 //@@ ui_add_gadget_button( MainWindow,155+70,i,70, 26, "Sound >>", find_next_hostage_sound );i += 29;
381 ui_add_gadget_button( MainWindow,155,i,70, 26, "<< Face", SelectPrevFace );
382 ui_add_gadget_button( MainWindow,155+70,i,70, 26, "Face >>", SelectNextFace );i += 29;
383 ui_add_gadget_button( MainWindow,155,i,140, 26, "Play sound", PlayHostageSound );i += 29;
384 ui_add_gadget_button( MainWindow,155,i,140, 26, "Next Hostage", SelectNextHostage ); i += 29;
385 ui_add_gadget_button( MainWindow,155,i,140, 26, "Prev Hostage", SelectPrevHostage ); i += 29;
386 ui_add_gadget_button( MainWindow,155,i,140, 26, "Compress All", CompressHostages ); i += 29;
387 ui_add_gadget_button( MainWindow,155,i,140, 26, "Delete", ObjectDelete ); i += 29;
388 ui_add_gadget_button( MainWindow,155,i,140, 26, "Create New", PlaceHostage ); i += 29;
390 Time = timer_get_fixed_seconds();
392 LastHostageIndex = -2; // Set to some dummy value so everything works ok on the first frame.
394 // if ( CurrentHostageIndex == -1 )
395 // SelectNextHostage();
401 void hostage_close_window()
404 if ( MainWindow!=NULL ) {
405 ui_close_window( MainWindow );
411 void do_hostage_window()
416 if ( MainWindow == NULL ) return;
418 SelectClosestHostage();
420 //------------------------------------------------------------
421 // Call the ui code..
422 //------------------------------------------------------------
423 ui_button_any_drawn = 0;
424 ui_window_do_gadgets(MainWindow);
426 //------------------------------------------------------------
427 // If we change objects, we need to reset the ui code for all
428 // of the radio buttons that control the ai mode. Also makes
429 // the current AI mode button be flagged as pressed down.
430 //------------------------------------------------------------
431 if (LastHostageIndex != CurrentHostageIndex ) {
433 if ( CurrentHostageIndex > -1 )
434 strcpy( HostageText->text, Hostages[CurrentHostageIndex].text );
436 strcpy(HostageText->text, " " );
438 HostageText->position = strlen(HostageText->text);
439 HostageText->oldposition = HostageText->position;
440 HostageText->status=1;
441 HostageText->first_time = 1;
445 //------------------------------------------------------------
446 // If any of the radio buttons that control the mode are set, then
447 // update the cooresponding AI state.
448 //------------------------------------------------------------
449 if ( CurrentHostageIndex > -1 )
450 strcpy( Hostages[CurrentHostageIndex].text, HostageText->text );
452 //------------------------------------------------------------
453 // A simple frame time counter for spinning the objects...
454 //------------------------------------------------------------
455 Temp = timer_get_fixed_seconds();
456 DeltaTime = Temp - Time;
459 //------------------------------------------------------------
460 // Redraw the object in the little 64x64 box
461 //------------------------------------------------------------
462 if (CurrentHostageIndex > -1 ) {
465 vclip_num = Hostages[CurrentHostageIndex].vclip_num;
467 Assert(vclip_num != -1);
469 gr_set_current_canvas( HostageViewBox->canvas );
471 if ( vclip_num > -1 ) {
472 vclip_play( &Hostage_face_clip[vclip_num], DeltaTime );
474 gr_clear_canvas( CGREY );
477 // no hostage, so just blank out
478 gr_set_current_canvas( HostageViewBox->canvas );
479 gr_clear_canvas( CGREY );
482 //------------------------------------------------------------
483 // If anything changes in the ui system, redraw all the text that
484 // identifies this robot.
485 //------------------------------------------------------------
486 if (ui_button_any_drawn || (LastHostageIndex != CurrentHostageIndex) ) {
487 if ( CurrentHostageIndex > -1 ) {
488 ui_wprintf_at( MainWindow, 10, 15, "Hostage: %d Object: %d", CurrentHostageIndex, Hostages[CurrentHostageIndex].objnum );
489 //@@ui_wprintf_at( MainWindow, 10, 73, "Type: %d Sound: %d ", Hostages[CurrentHostageIndex].type, Hostages[CurrentHostageIndex].sound_num );
490 ui_wprintf_at( MainWindow, 10, 73, "Face: %d ", Hostages[CurrentHostageIndex].vclip_num);
492 ui_wprintf_at( MainWindow, 10, 15, "Hostage: none " );
493 //@@ui_wprintf_at( MainWindow, 10, 73, "Type: Sound: " );
494 ui_wprintf_at( MainWindow, 10, 73, "Face: " );
496 Update_flags |= UF_WORLD_CHANGED;
499 if ( QuitButton->pressed || (last_keypress==KEY_ESC)) {
500 hostage_close_window();
504 LastHostageIndex = CurrentHostageIndex;