1 /* $Id: ehostage.c,v 1.4 2004-12-21 11:58:14 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...
22 static char rcsid[] = "$Id: ehostage.c,v 1.4 2004-12-21 11:58:14 btb Exp $";
66 //-------------------------------------------------------------------------
67 // Variables for this module...
68 //-------------------------------------------------------------------------
69 static UI_WINDOW *MainWindow = NULL;
70 static UI_GADGET_USERBOX *HostageViewBox;
71 static UI_GADGET_INPUTBOX *HostageText;
72 static UI_GADGET_BUTTON *QuitButton;
73 static int CurrentHostageIndex=-1;
74 static int LastHostageIndex=-1;
76 static fix Vclip_animation_time=0; // How long the rescue sequence has been playing
77 static fix Vclip_playback_speed=0; // Calculated internally. Frames/second of vclip.
78 static vclip *Vclip_ptr = NULL; // Used for the vclip on monitor
80 void vclip_play( vclip * vc, fix frame_time )
87 if ( vc != Vclip_ptr ) {
90 Vclip_animation_time = 1;
92 // Calculate the frame/second of the playback
93 Vclip_playback_speed = fixdiv(i2f(Vclip_ptr->num_frames),Vclip_ptr->play_time);
96 if ( Vclip_animation_time <= 0 )
99 // Find next bitmap in the vclip
100 bitmapnum = f2i(Vclip_animation_time);
102 // Check if vclip is done playing.
103 if (bitmapnum >= Vclip_ptr->num_frames) {
104 Vclip_animation_time = 1; // Restart this vclip
108 PIGGY_PAGE_IN( Vclip_ptr->frames[bitmapnum] );
109 gr_bitmap(0,0,&GameBitmaps[Vclip_ptr->frames[bitmapnum].index] );
111 Vclip_animation_time += fixmul(frame_time, Vclip_playback_speed );
116 static char HostageMessage[] = " ";
120 int SelectPrevHostage() {
124 CurrentHostageIndex--;
125 if ( CurrentHostageIndex < 0 ) CurrentHostageIndex = MAX_HOSTAGES-1;
127 if ( start > MAX_HOSTAGES ) break;
128 } while ( !hostage_is_valid( CurrentHostageIndex ) );
130 if (hostage_is_valid( CurrentHostageIndex ) ) {
131 Cur_object_index = Hostages[CurrentHostageIndex].objnum;
133 CurrentHostageIndex =-1;
136 return CurrentHostageIndex;
140 int SelectNextHostage() {
144 CurrentHostageIndex++;
145 if ( CurrentHostageIndex >= MAX_HOSTAGES ) CurrentHostageIndex = 0;
147 if ( start > MAX_HOSTAGES ) break;
148 } while ( !hostage_is_valid( CurrentHostageIndex ) );
150 if (hostage_is_valid( CurrentHostageIndex ) ) {
151 Cur_object_index = Hostages[CurrentHostageIndex].objnum;
153 CurrentHostageIndex =-1;
156 return CurrentHostageIndex;
160 int SelectClosestHostage() {
163 while ( !hostage_is_valid( CurrentHostageIndex ) ) {
164 CurrentHostageIndex++;
165 if ( CurrentHostageIndex >= MAX_HOSTAGES ) CurrentHostageIndex = 0;
167 if ( start > MAX_HOSTAGES ) break;
170 if (hostage_is_valid( CurrentHostageIndex ) ) {
171 Cur_object_index = Hostages[CurrentHostageIndex].objnum;
173 CurrentHostageIndex =-1;
176 return CurrentHostageIndex;
182 vms_vector cur_object_loc;
184 //update_due_to_new_segment();
185 compute_segment_center(&cur_object_loc, Cursegp);
188 for (i=0; i<Num_total_object_types; i++ ) {
189 if (ObjType[i] == OL_HOSTAGE ) {
195 Assert( ctype != -1 );
197 if (place_object(Cursegp, &cur_object_loc, ctype )==0) {
198 Int3(); // Debug below
199 i=place_object(Cursegp, &cur_object_loc, ctype );
203 if (hostage_object_is_valid( Cur_object_index ) ) {
204 CurrentHostageIndex = Objects[Cur_object_index].id;
206 Int3(); // Get John! (Object should be valid)
207 i=hostage_object_is_valid( Cur_object_index ); // For debugging only
213 int CompressHostages()
215 hostage_compress_all();
220 //@@int SelectPrevVclip() {
221 //@@ if (!hostage_is_valid( CurrentHostageIndex ) )
224 //@@ if ( Hostages[CurrentHostageIndex].type == 0 )
225 //@@ Hostages[CurrentHostageIndex].type = N_hostage_types-1;
227 //@@ Hostages[CurrentHostageIndex].type--;
229 //@@ if ( Hostages[CurrentHostageIndex].type >= N_hostage_types )
230 //@@ Hostages[CurrentHostageIndex].type = 0;
235 //@@int SelectNextVclip() {
236 //@@ if (!hostage_is_valid( CurrentHostageIndex ) )
239 //@@ Hostages[CurrentHostageIndex].type++;
240 //@@ if ( Hostages[CurrentHostageIndex].type >= N_hostage_types )
241 //@@ Hostages[CurrentHostageIndex].type = 0;
248 int start = Hostages[CurrentHostageIndex].vclip_num;
250 if (!hostage_is_valid( CurrentHostageIndex ) )
254 Hostages[CurrentHostageIndex].vclip_num++;
255 if ( Hostages[CurrentHostageIndex].vclip_num >= MAX_HOSTAGES)
256 Hostages[CurrentHostageIndex].vclip_num = 0;
258 if (Hostages[CurrentHostageIndex].vclip_num == start)
261 } while (Hostage_face_clip[Hostages[CurrentHostageIndex].vclip_num].num_frames == 0);
268 int start = Hostages[CurrentHostageIndex].vclip_num;
270 if (!hostage_is_valid( CurrentHostageIndex ) )
274 Hostages[CurrentHostageIndex].vclip_num--;
275 if ( Hostages[CurrentHostageIndex].vclip_num < 0)
276 Hostages[CurrentHostageIndex].vclip_num = MAX_HOSTAGES-1;
278 if (Hostages[CurrentHostageIndex].vclip_num == start)
281 } while (Hostage_face_clip[Hostages[CurrentHostageIndex].vclip_num].num_frames == 0);
286 int PlayHostageSound() {
289 if (!hostage_is_valid( CurrentHostageIndex ) )
292 sound_num = Hostage_face_clip[Hostages[CurrentHostageIndex].vclip_num].sound_num;
294 if ( sound_num > -1 ) {
295 digi_play_sample( sound_num, F1_0 );
301 //@@int find_next_hostage_sound() {
304 //@@ n = Hostages[CurrentHostageIndex].sound_num;
307 //@@ if ( n < SOUND_HOSTAGE_VOICES ) n = SOUND_HOSTAGE_VOICES+MAX_HOSTAGE_SOUNDS-1;
308 //@@ if ( n >= SOUND_HOSTAGE_VOICES+MAX_HOSTAGE_SOUNDS ) n = SOUND_HOSTAGE_VOICES;
310 //@@ if ( start > MAX_HOSTAGE_SOUNDS ) break;
311 //@@ } while ( Sounds[n] == NULL );
313 //@@ if ( Sounds[n] == NULL )
314 //@@ Hostages[CurrentHostageIndex].sound_num = -1;
316 //@@ Hostages[CurrentHostageIndex].sound_num = n;
317 //@@ PlayHostageSound();
322 //@@int find_prev_hostage_sound() {
325 //@@ n = Hostages[CurrentHostageIndex].sound_num;
328 //@@ if ( n < SOUND_HOSTAGE_VOICES ) n = SOUND_HOSTAGE_VOICES+MAX_HOSTAGE_SOUNDS-1;
329 //@@ if ( n >= SOUND_HOSTAGE_VOICES+MAX_HOSTAGE_SOUNDS ) n = SOUND_HOSTAGE_VOICES;
331 //@@ if ( start > MAX_HOSTAGE_SOUNDS ) break;
332 //@@ } while ( Sounds[n] == NULL );
334 //@@ if ( Sounds[n] == NULL )
335 //@@ Hostages[CurrentHostageIndex].sound_num = -1;
337 //@@ Hostages[CurrentHostageIndex].sound_num = n;
338 //@@ PlayHostageSound();
344 //-------------------------------------------------------------------------
345 // Called from the editor... does one instance of the hostage dialog box
346 //-------------------------------------------------------------------------
347 int do_hostage_dialog()
351 // Only open 1 instance of this window...
352 if ( MainWindow != NULL ) return 0;
354 // Close other windows
357 CurrentHostageIndex = 0;
358 SelectClosestHostage();
360 // Open a window with a quit button
361 MainWindow = ui_open_window( TMAPBOX_X+10, TMAPBOX_Y+20, 765-TMAPBOX_X, 545-TMAPBOX_Y, WIN_DIALOG );
362 QuitButton = ui_add_gadget_button( MainWindow, 20, 222, 48, 40, "Done", NULL );
364 ui_wprintf_at( MainWindow, 10, 32,"&Message:" );
365 HostageText = ui_add_gadget_inputbox( MainWindow, 10, 50, HOSTAGE_MESSAGE_LEN, HOSTAGE_MESSAGE_LEN, HostageMessage );
367 // The little box the hostage vclip will play in.
368 HostageViewBox = ui_add_gadget_userbox( MainWindow,10, 90+10, 64, 64 );
370 // A bunch of buttons...
372 //@@ ui_add_gadget_button( MainWindow,155,i,70, 26, "<< Type", SelectPrevVclip );
373 //@@ ui_add_gadget_button( MainWindow,155+70,i,70, 26, "Type >>", SelectNextVclip );i += 29;
374 //@@ ui_add_gadget_button( MainWindow,155,i,70, 26, "<< Sound", find_prev_hostage_sound );
375 //@@ ui_add_gadget_button( MainWindow,155+70,i,70, 26, "Sound >>", find_next_hostage_sound );i += 29;
377 ui_add_gadget_button( MainWindow,155,i,70, 26, "<< Face", SelectPrevFace );
378 ui_add_gadget_button( MainWindow,155+70,i,70, 26, "Face >>", SelectNextFace );i += 29;
379 ui_add_gadget_button( MainWindow,155,i,140, 26, "Play sound", PlayHostageSound );i += 29;
380 ui_add_gadget_button( MainWindow,155,i,140, 26, "Next Hostage", SelectNextHostage ); i += 29;
381 ui_add_gadget_button( MainWindow,155,i,140, 26, "Prev Hostage", SelectPrevHostage ); i += 29;
382 ui_add_gadget_button( MainWindow,155,i,140, 26, "Compress All", CompressHostages ); i += 29;
383 ui_add_gadget_button( MainWindow,155,i,140, 26, "Delete", ObjectDelete ); i += 29;
384 ui_add_gadget_button( MainWindow,155,i,140, 26, "Create New", PlaceHostage ); i += 29;
386 Time = timer_get_fixed_seconds();
388 LastHostageIndex = -2; // Set to some dummy value so everything works ok on the first frame.
390 // if ( CurrentHostageIndex == -1 )
391 // SelectNextHostage();
397 void hostage_close_window()
399 if ( MainWindow!=NULL ) {
400 ui_close_window( MainWindow );
405 void do_hostage_window()
409 if ( MainWindow == NULL ) return;
411 SelectClosestHostage();
413 //------------------------------------------------------------
414 // Call the ui code..
415 //------------------------------------------------------------
416 ui_button_any_drawn = 0;
417 ui_window_do_gadgets(MainWindow);
419 //------------------------------------------------------------
420 // If we change objects, we need to reset the ui code for all
421 // of the radio buttons that control the ai mode. Also makes
422 // the current AI mode button be flagged as pressed down.
423 //------------------------------------------------------------
424 if (LastHostageIndex != CurrentHostageIndex ) {
426 if ( CurrentHostageIndex > -1 )
427 strcpy( HostageText->text, Hostages[CurrentHostageIndex].text );
429 strcpy(HostageText->text, " " );
431 HostageText->position = strlen(HostageText->text);
432 HostageText->oldposition = HostageText->position;
433 HostageText->status=1;
434 HostageText->first_time = 1;
438 //------------------------------------------------------------
439 // If any of the radio buttons that control the mode are set, then
440 // update the cooresponding AI state.
441 //------------------------------------------------------------
442 if ( CurrentHostageIndex > -1 )
443 strcpy( Hostages[CurrentHostageIndex].text, HostageText->text );
445 //------------------------------------------------------------
446 // A simple frame time counter for spinning the objects...
447 //------------------------------------------------------------
448 Temp = timer_get_fixed_seconds();
449 DeltaTime = Temp - Time;
452 //------------------------------------------------------------
453 // Redraw the object in the little 64x64 box
454 //------------------------------------------------------------
455 if (CurrentHostageIndex > -1 ) {
458 vclip_num = Hostages[CurrentHostageIndex].vclip_num;
460 Assert(vclip_num != -1);
462 gr_set_current_canvas( HostageViewBox->canvas );
464 if ( vclip_num > -1 ) {
465 vclip_play( &Hostage_face_clip[vclip_num], DeltaTime );
467 gr_clear_canvas( CGREY );
470 // no hostage, so just blank out
471 gr_set_current_canvas( HostageViewBox->canvas );
472 gr_clear_canvas( CGREY );
475 //------------------------------------------------------------
476 // If anything changes in the ui system, redraw all the text that
477 // identifies this robot.
478 //------------------------------------------------------------
479 if (ui_button_any_drawn || (LastHostageIndex != CurrentHostageIndex) ) {
480 if ( CurrentHostageIndex > -1 ) {
481 ui_wprintf_at( MainWindow, 10, 15, "Hostage: %d Object: %d", CurrentHostageIndex, Hostages[CurrentHostageIndex].objnum );
482 //@@ui_wprintf_at( MainWindow, 10, 73, "Type: %d Sound: %d ", Hostages[CurrentHostageIndex].type, Hostages[CurrentHostageIndex].sound_num );
483 ui_wprintf_at( MainWindow, 10, 73, "Face: %d ", Hostages[CurrentHostageIndex].vclip_num);
485 ui_wprintf_at( MainWindow, 10, 15, "Hostage: none " );
486 //@@ui_wprintf_at( MainWindow, 10, 73, "Type: Sound: " );
487 ui_wprintf_at( MainWindow, 10, 73, "Face: " );
489 Update_flags |= UF_WORLD_CHANGED;
492 if ( QuitButton->pressed || (last_keypress==KEY_ESC)) {
493 hostage_close_window();
497 LastHostageIndex = CurrentHostageIndex;