1 /* $Id: ehostage.c,v 1.2 2004-12-19 14:52:48 btb 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...
23 static char rcsid[] = "$Id: ehostage.c,v 1.2 2004-12-19 14:52:48 btb Exp $";
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();
341 //-------------------------------------------------------------------------
342 // Called from the editor... does one instance of the hostage dialog box
343 //-------------------------------------------------------------------------
344 int do_hostage_dialog()
348 // Only open 1 instance of this window...
349 if ( MainWindow != NULL ) return 0;
351 // Close other windows
354 CurrentHostageIndex = 0;
355 SelectClosestHostage();
357 // Open a window with a quit button
358 MainWindow = ui_open_window( TMAPBOX_X+10, TMAPBOX_Y+20, 765-TMAPBOX_X, 545-TMAPBOX_Y, WIN_DIALOG );
359 QuitButton = ui_add_gadget_button( MainWindow, 20, 222, 48, 40, "Done", NULL );
361 ui_wprintf_at( MainWindow, 10, 32,"&Message:" );
362 HostageText = ui_add_gadget_inputbox( MainWindow, 10, 50, HOSTAGE_MESSAGE_LEN, HOSTAGE_MESSAGE_LEN, HostageMessage );
364 // The little box the hostage vclip will play in.
365 HostageViewBox = ui_add_gadget_userbox( MainWindow,10, 90+10, 64, 64 );
367 // A bunch of buttons...
369 //@@ ui_add_gadget_button( MainWindow,155,i,70, 26, "<< Type", SelectPrevVclip );
370 //@@ ui_add_gadget_button( MainWindow,155+70,i,70, 26, "Type >>", SelectNextVclip );i += 29;
371 //@@ ui_add_gadget_button( MainWindow,155,i,70, 26, "<< Sound", find_prev_hostage_sound );
372 //@@ ui_add_gadget_button( MainWindow,155+70,i,70, 26, "Sound >>", find_next_hostage_sound );i += 29;
374 ui_add_gadget_button( MainWindow,155,i,70, 26, "<< Face", SelectPrevFace );
375 ui_add_gadget_button( MainWindow,155+70,i,70, 26, "Face >>", SelectNextFace );i += 29;
376 ui_add_gadget_button( MainWindow,155,i,140, 26, "Play sound", PlayHostageSound );i += 29;
377 ui_add_gadget_button( MainWindow,155,i,140, 26, "Next Hostage", SelectNextHostage ); i += 29;
378 ui_add_gadget_button( MainWindow,155,i,140, 26, "Prev Hostage", SelectPrevHostage ); i += 29;
379 ui_add_gadget_button( MainWindow,155,i,140, 26, "Compress All", CompressHostages ); i += 29;
380 ui_add_gadget_button( MainWindow,155,i,140, 26, "Delete", ObjectDelete ); i += 29;
381 ui_add_gadget_button( MainWindow,155,i,140, 26, "Create New", PlaceHostage ); i += 29;
383 Time = timer_get_fixed_seconds();
385 LastHostageIndex = -2; // Set to some dummy value so everything works ok on the first frame.
387 // if ( CurrentHostageIndex == -1 )
388 // SelectNextHostage();
394 void hostage_close_window()
396 if ( MainWindow!=NULL ) {
397 ui_close_window( MainWindow );
402 void do_hostage_window()
406 if ( MainWindow == NULL ) return;
408 SelectClosestHostage();
410 //------------------------------------------------------------
411 // Call the ui code..
412 //------------------------------------------------------------
413 ui_button_any_drawn = 0;
414 ui_window_do_gadgets(MainWindow);
416 //------------------------------------------------------------
417 // If we change objects, we need to reset the ui code for all
418 // of the radio buttons that control the ai mode. Also makes
419 // the current AI mode button be flagged as pressed down.
420 //------------------------------------------------------------
421 if (LastHostageIndex != CurrentHostageIndex ) {
423 if ( CurrentHostageIndex > -1 )
424 strcpy( HostageText->text, Hostages[CurrentHostageIndex].text );
426 strcpy(HostageText->text, " " );
428 HostageText->position = strlen(HostageText->text);
429 HostageText->oldposition = HostageText->position;
430 HostageText->status=1;
431 HostageText->first_time = 1;
435 //------------------------------------------------------------
436 // If any of the radio buttons that control the mode are set, then
437 // update the cooresponding AI state.
438 //------------------------------------------------------------
439 if ( CurrentHostageIndex > -1 )
440 strcpy( Hostages[CurrentHostageIndex].text, HostageText->text );
442 //------------------------------------------------------------
443 // A simple frame time counter for spinning the objects...
444 //------------------------------------------------------------
445 Temp = timer_get_fixed_seconds();
446 DeltaTime = Temp - Time;
449 //------------------------------------------------------------
450 // Redraw the object in the little 64x64 box
451 //------------------------------------------------------------
452 if (CurrentHostageIndex > -1 ) {
455 vclip_num = Hostages[CurrentHostageIndex].vclip_num;
457 Assert(vclip_num != -1);
459 gr_set_current_canvas( HostageViewBox->canvas );
461 if ( vclip_num > -1 ) {
462 vclip_play( &Hostage_face_clip[vclip_num], DeltaTime );
464 gr_clear_canvas( CGREY );
467 // no hostage, so just blank out
468 gr_set_current_canvas( HostageViewBox->canvas );
469 gr_clear_canvas( CGREY );
472 //------------------------------------------------------------
473 // If anything changes in the ui system, redraw all the text that
474 // identifies this robot.
475 //------------------------------------------------------------
476 if (ui_button_any_drawn || (LastHostageIndex != CurrentHostageIndex) ) {
477 if ( CurrentHostageIndex > -1 ) {
478 ui_wprintf_at( MainWindow, 10, 15, "Hostage: %d Object: %d", CurrentHostageIndex, Hostages[CurrentHostageIndex].objnum );
479 //@@ui_wprintf_at( MainWindow, 10, 73, "Type: %d Sound: %d ", Hostages[CurrentHostageIndex].type, Hostages[CurrentHostageIndex].sound_num );
480 ui_wprintf_at( MainWindow, 10, 73, "Face: %d ", Hostages[CurrentHostageIndex].vclip_num);
482 ui_wprintf_at( MainWindow, 10, 15, "Hostage: none " );
483 //@@ui_wprintf_at( MainWindow, 10, 73, "Type: Sound: " );
484 ui_wprintf_at( MainWindow, 10, 73, "Face: " );
486 Update_flags |= UF_WORLD_CHANGED;
489 if ( QuitButton->pressed || (last_keypress==KEY_ESC)) {
490 hostage_close_window();
494 LastHostageIndex = CurrentHostageIndex;