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.
14 * $Source: /cvs/cvsroot/d2x/main/editor/ehostage.c,v $
17 * $Date: 2004-12-19 13:54:27 $
19 * Routines for placing hostages, etc...
21 * $Log: not supported by cvs2svn $
22 * Revision 1.1.1.1 1999/06/14 22:02:53 donut
23 * Import of d1x 1.37 source.
25 * Revision 2.0 1995/02/27 11:35:45 john
26 * Version 2.0! No anonymous unions, Watcom 10.0, with no need
29 * Revision 1.17 1995/01/14 19:18:05 john
30 * First version of object paging.
32 * Revision 1.16 1994/11/20 14:11:41 matt
33 * Show object number in hostage window
35 * Revision 1.15 1994/11/19 19:55:46 matt
36 * Added code to full support different hostage head clip & message for
40 * Revision 1.14 1994/10/28 15:03:27 john
41 * Made digi_play_sample use volume.
44 * Revision 1.13 1994/10/23 02:11:39 matt
45 * Got rid of obsolete hostage_info stuff
47 * Revision 1.12 1994/10/04 13:15:44 john
48 * Changed PLAY_SOUND to digi_play_sample.
50 * Revision 1.11 1994/08/02 14:17:28 mike
51 * Clean up dialog boxes.
53 * Revision 1.10 1994/07/22 17:19:17 yuan
54 * Working on dialog box for refuel/repair/material/control centers.
56 * Revision 1.9 1994/07/06 15:22:34 john
60 * Revision 1.8 1994/07/06 14:26:07 john
63 * Revision 1.7 1994/07/06 13:25:52 john
64 * Added compress hostages functions.
66 * Revision 1.6 1994/07/06 12:52:27 john
69 * Revision 1.5 1994/07/06 12:43:04 john
70 * Made generic messages for hostages.
72 * Revision 1.4 1994/07/06 11:49:01 john
73 * Made adding hostage update current object.
75 * Revision 1.3 1994/07/06 10:56:00 john
76 * New structures for hostages.
78 * Revision 1.2 1994/07/01 17:57:13 john
79 * First version of not-working hostage system
82 * Revision 1.1 1994/07/01 14:21:44 john
90 static char rcsid[] = "$Id: ehostage.c,v 1.1 2004-12-19 13:54:27 btb Exp $";
123 #include "medrobot.h"
130 //-------------------------------------------------------------------------
131 // Variables for this module...
132 //-------------------------------------------------------------------------
133 static UI_WINDOW *MainWindow = NULL;
134 static UI_GADGET_USERBOX *HostageViewBox;
135 static UI_GADGET_INPUTBOX *HostageText;
136 static UI_GADGET_BUTTON *QuitButton;
137 static int CurrentHostageIndex=-1;
138 static int LastHostageIndex=-1;
140 static fix Vclip_animation_time=0; // How long the rescue sequence has been playing
141 static fix Vclip_playback_speed=0; // Calculated internally. Frames/second of vclip.
142 static vclip *Vclip_ptr = NULL; // Used for the vclip on monitor
144 void vclip_play( vclip * vc, fix frame_time )
151 if ( vc != Vclip_ptr ) {
154 Vclip_animation_time = 1;
156 // Calculate the frame/second of the playback
157 Vclip_playback_speed = fixdiv(i2f(Vclip_ptr->num_frames),Vclip_ptr->play_time);
160 if ( Vclip_animation_time <= 0 )
163 // Find next bitmap in the vclip
164 bitmapnum = f2i(Vclip_animation_time);
166 // Check if vclip is done playing.
167 if (bitmapnum >= Vclip_ptr->num_frames) {
168 Vclip_animation_time = 1; // Restart this vclip
172 PIGGY_PAGE_IN( Vclip_ptr->frames[bitmapnum] );
173 gr_bitmap(0,0,&GameBitmaps[Vclip_ptr->frames[bitmapnum].index] );
175 Vclip_animation_time += fixmul(frame_time, Vclip_playback_speed );
180 static char HostageMessage[] = " ";
184 int SelectPrevHostage() {
188 CurrentHostageIndex--;
189 if ( CurrentHostageIndex < 0 ) CurrentHostageIndex = MAX_HOSTAGES-1;
191 if ( start > MAX_HOSTAGES ) break;
192 } while ( !hostage_is_valid( CurrentHostageIndex ) );
194 if (hostage_is_valid( CurrentHostageIndex ) ) {
195 Cur_object_index = Hostages[CurrentHostageIndex].objnum;
197 CurrentHostageIndex =-1;
200 return CurrentHostageIndex;
204 int SelectNextHostage() {
208 CurrentHostageIndex++;
209 if ( CurrentHostageIndex >= MAX_HOSTAGES ) CurrentHostageIndex = 0;
211 if ( start > MAX_HOSTAGES ) break;
212 } while ( !hostage_is_valid( CurrentHostageIndex ) );
214 if (hostage_is_valid( CurrentHostageIndex ) ) {
215 Cur_object_index = Hostages[CurrentHostageIndex].objnum;
217 CurrentHostageIndex =-1;
220 return CurrentHostageIndex;
224 int SelectClosestHostage() {
227 while ( !hostage_is_valid( CurrentHostageIndex ) ) {
228 CurrentHostageIndex++;
229 if ( CurrentHostageIndex >= MAX_HOSTAGES ) CurrentHostageIndex = 0;
231 if ( start > MAX_HOSTAGES ) break;
234 if (hostage_is_valid( CurrentHostageIndex ) ) {
235 Cur_object_index = Hostages[CurrentHostageIndex].objnum;
237 CurrentHostageIndex =-1;
240 return CurrentHostageIndex;
246 vms_vector cur_object_loc;
248 //update_due_to_new_segment();
249 compute_segment_center(&cur_object_loc, Cursegp);
252 for (i=0; i<Num_total_object_types; i++ ) {
253 if (ObjType[i] == OL_HOSTAGE ) {
259 Assert( ctype != -1 );
261 if (place_object(Cursegp, &cur_object_loc, ctype )==0) {
262 Int3(); // Debug below
263 i=place_object(Cursegp, &cur_object_loc, ctype );
267 if (hostage_object_is_valid( Cur_object_index ) ) {
268 CurrentHostageIndex = Objects[Cur_object_index].id;
270 Int3(); // Get John! (Object should be valid)
271 i=hostage_object_is_valid( Cur_object_index ); // For debugging only
277 int CompressHostages()
279 hostage_compress_all();
284 //@@int SelectPrevVclip() {
285 //@@ if (!hostage_is_valid( CurrentHostageIndex ) )
288 //@@ if ( Hostages[CurrentHostageIndex].type == 0 )
289 //@@ Hostages[CurrentHostageIndex].type = N_hostage_types-1;
291 //@@ Hostages[CurrentHostageIndex].type--;
293 //@@ if ( Hostages[CurrentHostageIndex].type >= N_hostage_types )
294 //@@ Hostages[CurrentHostageIndex].type = 0;
299 //@@int SelectNextVclip() {
300 //@@ if (!hostage_is_valid( CurrentHostageIndex ) )
303 //@@ Hostages[CurrentHostageIndex].type++;
304 //@@ if ( Hostages[CurrentHostageIndex].type >= N_hostage_types )
305 //@@ Hostages[CurrentHostageIndex].type = 0;
312 int start = Hostages[CurrentHostageIndex].vclip_num;
314 if (!hostage_is_valid( CurrentHostageIndex ) )
318 Hostages[CurrentHostageIndex].vclip_num++;
319 if ( Hostages[CurrentHostageIndex].vclip_num >= MAX_HOSTAGES)
320 Hostages[CurrentHostageIndex].vclip_num = 0;
322 if (Hostages[CurrentHostageIndex].vclip_num == start)
325 } while (Hostage_face_clip[Hostages[CurrentHostageIndex].vclip_num].num_frames == 0);
332 int start = Hostages[CurrentHostageIndex].vclip_num;
334 if (!hostage_is_valid( CurrentHostageIndex ) )
338 Hostages[CurrentHostageIndex].vclip_num--;
339 if ( Hostages[CurrentHostageIndex].vclip_num < 0)
340 Hostages[CurrentHostageIndex].vclip_num = MAX_HOSTAGES-1;
342 if (Hostages[CurrentHostageIndex].vclip_num == start)
345 } while (Hostage_face_clip[Hostages[CurrentHostageIndex].vclip_num].num_frames == 0);
350 int PlayHostageSound() {
353 if (!hostage_is_valid( CurrentHostageIndex ) )
356 sound_num = Hostage_face_clip[Hostages[CurrentHostageIndex].vclip_num].sound_num;
358 if ( sound_num > -1 ) {
359 digi_play_sample( sound_num, F1_0 );
365 //@@int find_next_hostage_sound() {
368 //@@ n = Hostages[CurrentHostageIndex].sound_num;
371 //@@ if ( n < SOUND_HOSTAGE_VOICES ) n = SOUND_HOSTAGE_VOICES+MAX_HOSTAGE_SOUNDS-1;
372 //@@ if ( n >= SOUND_HOSTAGE_VOICES+MAX_HOSTAGE_SOUNDS ) n = SOUND_HOSTAGE_VOICES;
374 //@@ if ( start > MAX_HOSTAGE_SOUNDS ) break;
375 //@@ } while ( Sounds[n] == NULL );
377 //@@ if ( Sounds[n] == NULL )
378 //@@ Hostages[CurrentHostageIndex].sound_num = -1;
380 //@@ Hostages[CurrentHostageIndex].sound_num = n;
381 //@@ PlayHostageSound();
386 //@@int find_prev_hostage_sound() {
389 //@@ n = Hostages[CurrentHostageIndex].sound_num;
392 //@@ if ( n < SOUND_HOSTAGE_VOICES ) n = SOUND_HOSTAGE_VOICES+MAX_HOSTAGE_SOUNDS-1;
393 //@@ if ( n >= SOUND_HOSTAGE_VOICES+MAX_HOSTAGE_SOUNDS ) n = SOUND_HOSTAGE_VOICES;
395 //@@ if ( start > MAX_HOSTAGE_SOUNDS ) break;
396 //@@ } while ( Sounds[n] == NULL );
398 //@@ if ( Sounds[n] == NULL )
399 //@@ Hostages[CurrentHostageIndex].sound_num = -1;
401 //@@ Hostages[CurrentHostageIndex].sound_num = n;
402 //@@ PlayHostageSound();
408 //-------------------------------------------------------------------------
409 // Called from the editor... does one instance of the hostage dialog box
410 //-------------------------------------------------------------------------
411 int do_hostage_dialog()
415 // Only open 1 instance of this window...
416 if ( MainWindow != NULL ) return 0;
418 // Close other windows
421 CurrentHostageIndex = 0;
422 SelectClosestHostage();
424 // Open a window with a quit button
425 MainWindow = ui_open_window( TMAPBOX_X+10, TMAPBOX_Y+20, 765-TMAPBOX_X, 545-TMAPBOX_Y, WIN_DIALOG );
426 QuitButton = ui_add_gadget_button( MainWindow, 20, 222, 48, 40, "Done", NULL );
428 ui_wprintf_at( MainWindow, 10, 32,"&Message:" );
429 HostageText = ui_add_gadget_inputbox( MainWindow, 10, 50, HOSTAGE_MESSAGE_LEN, HOSTAGE_MESSAGE_LEN, HostageMessage );
431 // The little box the hostage vclip will play in.
432 HostageViewBox = ui_add_gadget_userbox( MainWindow,10, 90+10, 64, 64 );
434 // A bunch of buttons...
436 //@@ ui_add_gadget_button( MainWindow,155,i,70, 26, "<< Type", SelectPrevVclip );
437 //@@ ui_add_gadget_button( MainWindow,155+70,i,70, 26, "Type >>", SelectNextVclip );i += 29;
438 //@@ ui_add_gadget_button( MainWindow,155,i,70, 26, "<< Sound", find_prev_hostage_sound );
439 //@@ ui_add_gadget_button( MainWindow,155+70,i,70, 26, "Sound >>", find_next_hostage_sound );i += 29;
441 ui_add_gadget_button( MainWindow,155,i,70, 26, "<< Face", SelectPrevFace );
442 ui_add_gadget_button( MainWindow,155+70,i,70, 26, "Face >>", SelectNextFace );i += 29;
443 ui_add_gadget_button( MainWindow,155,i,140, 26, "Play sound", PlayHostageSound );i += 29;
444 ui_add_gadget_button( MainWindow,155,i,140, 26, "Next Hostage", SelectNextHostage ); i += 29;
445 ui_add_gadget_button( MainWindow,155,i,140, 26, "Prev Hostage", SelectPrevHostage ); i += 29;
446 ui_add_gadget_button( MainWindow,155,i,140, 26, "Compress All", CompressHostages ); i += 29;
447 ui_add_gadget_button( MainWindow,155,i,140, 26, "Delete", ObjectDelete ); i += 29;
448 ui_add_gadget_button( MainWindow,155,i,140, 26, "Create New", PlaceHostage ); i += 29;
450 Time = timer_get_fixed_seconds();
452 LastHostageIndex = -2; // Set to some dummy value so everything works ok on the first frame.
454 // if ( CurrentHostageIndex == -1 )
455 // SelectNextHostage();
461 void hostage_close_window()
463 if ( MainWindow!=NULL ) {
464 ui_close_window( MainWindow );
469 void do_hostage_window()
473 if ( MainWindow == NULL ) return;
475 SelectClosestHostage();
477 //------------------------------------------------------------
478 // Call the ui code..
479 //------------------------------------------------------------
480 ui_button_any_drawn = 0;
481 ui_window_do_gadgets(MainWindow);
483 //------------------------------------------------------------
484 // If we change objects, we need to reset the ui code for all
485 // of the radio buttons that control the ai mode. Also makes
486 // the current AI mode button be flagged as pressed down.
487 //------------------------------------------------------------
488 if (LastHostageIndex != CurrentHostageIndex ) {
490 if ( CurrentHostageIndex > -1 )
491 strcpy( HostageText->text, Hostages[CurrentHostageIndex].text );
493 strcpy(HostageText->text, " " );
495 HostageText->position = strlen(HostageText->text);
496 HostageText->oldposition = HostageText->position;
497 HostageText->status=1;
498 HostageText->first_time = 1;
502 //------------------------------------------------------------
503 // If any of the radio buttons that control the mode are set, then
504 // update the cooresponding AI state.
505 //------------------------------------------------------------
506 if ( CurrentHostageIndex > -1 )
507 strcpy( Hostages[CurrentHostageIndex].text, HostageText->text );
509 //------------------------------------------------------------
510 // A simple frame time counter for spinning the objects...
511 //------------------------------------------------------------
512 Temp = timer_get_fixed_seconds();
513 DeltaTime = Temp - Time;
516 //------------------------------------------------------------
517 // Redraw the object in the little 64x64 box
518 //------------------------------------------------------------
519 if (CurrentHostageIndex > -1 ) {
522 vclip_num = Hostages[CurrentHostageIndex].vclip_num;
524 Assert(vclip_num != -1);
526 gr_set_current_canvas( HostageViewBox->canvas );
528 if ( vclip_num > -1 ) {
529 vclip_play( &Hostage_face_clip[vclip_num], DeltaTime );
531 gr_clear_canvas( CGREY );
534 // no hostage, so just blank out
535 gr_set_current_canvas( HostageViewBox->canvas );
536 gr_clear_canvas( CGREY );
539 //------------------------------------------------------------
540 // If anything changes in the ui system, redraw all the text that
541 // identifies this robot.
542 //------------------------------------------------------------
543 if (ui_button_any_drawn || (LastHostageIndex != CurrentHostageIndex) ) {
544 if ( CurrentHostageIndex > -1 ) {
545 ui_wprintf_at( MainWindow, 10, 15, "Hostage: %d Object: %d", CurrentHostageIndex, Hostages[CurrentHostageIndex].objnum );
546 //@@ui_wprintf_at( MainWindow, 10, 73, "Type: %d Sound: %d ", Hostages[CurrentHostageIndex].type, Hostages[CurrentHostageIndex].sound_num );
547 ui_wprintf_at( MainWindow, 10, 73, "Face: %d ", Hostages[CurrentHostageIndex].vclip_num);
549 ui_wprintf_at( MainWindow, 10, 15, "Hostage: none " );
550 //@@ui_wprintf_at( MainWindow, 10, 73, "Type: Sound: " );
551 ui_wprintf_at( MainWindow, 10, 73, "Face: " );
553 Update_flags |= UF_WORLD_CHANGED;
556 if ( QuitButton->pressed || (last_keypress==KEY_ESC)) {
557 hostage_close_window();
561 LastHostageIndex = CurrentHostageIndex;