]> icculus.org git repositories - btb/d2x.git/blob - main/editor/ehostage.c
don't use hardcoded descriptions of joystick buttons/axes
[btb/d2x.git] / main / editor / ehostage.c
1 /* $Id: ehostage.c,v 1.5 2005-01-24 21:33:28 schaffner Exp $ */
2 /*
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.
13 */
14
15 /*
16  *
17  * Routines for placing hostages, etc...
18  *
19  */
20
21 #ifdef RCS
22 static char rcsid[] = "$Id: ehostage.c,v 1.5 2005-01-24 21:33:28 schaffner Exp $";
23 #endif
24
25 #ifdef HAVE_CONFIG_H
26 #include "conf.h"
27 #endif
28
29 #if 0   // the hostage code was simplified for Descent 2
30
31 #include <stdlib.h>
32 #include <stdio.h>
33 #ifdef __MSDOS__
34 #include <conio.h>
35 #include <dos.h>
36 #include <direct.h>
37 #endif 
38 #include <string.h>
39 #include <math.h>
40
41 #include "screens.h"
42 #include "inferno.h"
43 #include "segment.h"
44 #include "editor.h"
45
46 #include "timer.h"
47 #include "objpage.h"
48 #include "fix.h"
49 #include "mono.h"
50 #include "error.h"
51 #include "kdefs.h"
52 #include        "object.h"
53 #include "polyobj.h"
54 #include "game.h"
55 #include "powerup.h"
56 #include "ai.h"
57 #include "hostage.h"
58 #include "eobject.h"
59 #include "medwall.h"
60 #include "eswitch.h"
61 #include "medrobot.h"
62 #include "key.h"
63 #include "bm.h"
64 #include "sounds.h"
65 #include "centers.h"
66 #include "piggy.h"
67
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;
77
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
81
82 void vclip_play( vclip * vc, fix frame_time )   
83 {
84         int bitmapnum;
85
86         if ( vc == NULL )
87                 return;
88
89         if ( vc != Vclip_ptr )  {
90                 // Start new vclip
91                 Vclip_ptr = vc;
92                 Vclip_animation_time = 1;
93
94                 // Calculate the frame/second of the playback
95                 Vclip_playback_speed = fixdiv(i2f(Vclip_ptr->num_frames),Vclip_ptr->play_time);
96         }
97
98         if ( Vclip_animation_time <= 0 )
99                 return;
100
101         // Find next bitmap in the vclip
102         bitmapnum = f2i(Vclip_animation_time);
103
104         // Check if vclip is done playing.
105         if (bitmapnum >= Vclip_ptr->num_frames)         {
106                 Vclip_animation_time    = 1;                                                                                    // Restart this vclip
107                 bitmapnum = 0;
108         }
109
110         PIGGY_PAGE_IN( Vclip_ptr->frames[bitmapnum] );
111         gr_bitmap(0,0,&GameBitmaps[Vclip_ptr->frames[bitmapnum].index] );
112         
113         Vclip_animation_time += fixmul(frame_time, Vclip_playback_speed );
114 }
115
116
117
118 static char HostageMessage[]  = "  ";
119
120 static fix Time;
121
122 int SelectPrevHostage() {
123         int start=0;
124
125         do      {
126                 CurrentHostageIndex--;
127                 if ( CurrentHostageIndex < 0 ) CurrentHostageIndex = MAX_HOSTAGES-1;
128                 start++;
129                 if ( start > MAX_HOSTAGES ) break;
130         } while ( !hostage_is_valid( CurrentHostageIndex ) );
131
132         if (hostage_is_valid( CurrentHostageIndex ) )   {
133                 Cur_object_index = Hostages[CurrentHostageIndex].objnum;
134         } else {
135                 CurrentHostageIndex =-1;
136         }
137         
138         return CurrentHostageIndex;
139 }
140
141
142 int SelectNextHostage() {
143         int start=0;
144
145         do      {
146                 CurrentHostageIndex++;
147                 if ( CurrentHostageIndex >= MAX_HOSTAGES ) CurrentHostageIndex = 0;
148                 start++;
149                 if ( start > MAX_HOSTAGES ) break;
150         } while ( !hostage_is_valid( CurrentHostageIndex ) );
151
152         if (hostage_is_valid( CurrentHostageIndex ) )   {
153                 Cur_object_index = Hostages[CurrentHostageIndex].objnum;
154         } else {
155                 CurrentHostageIndex =-1;
156         }
157         
158         return CurrentHostageIndex;
159 }
160
161
162 int SelectClosestHostage()      {
163         int start=0;
164
165         while ( !hostage_is_valid( CurrentHostageIndex ) )      {
166                 CurrentHostageIndex++;
167                 if ( CurrentHostageIndex >= MAX_HOSTAGES ) CurrentHostageIndex = 0;
168                 start++;
169                 if ( start > MAX_HOSTAGES ) break;
170         }
171
172         if (hostage_is_valid( CurrentHostageIndex ) )   {
173                 Cur_object_index = Hostages[CurrentHostageIndex].objnum;
174         } else {
175                 CurrentHostageIndex =-1;
176         }
177         
178         return CurrentHostageIndex;
179 }
180
181
182 int PlaceHostage()      {
183         int ctype,i;
184         vms_vector      cur_object_loc;
185
186         //update_due_to_new_segment();
187         compute_segment_center(&cur_object_loc, Cursegp);
188
189         ctype = -1;
190         for (i=0; i<Num_total_object_types; i++ )       {
191                 if (ObjType[i] == OL_HOSTAGE )  {
192                         ctype = i;      
193                         break;
194                 }
195         }
196
197         Assert( ctype != -1 );
198
199         if (place_object(Cursegp, &cur_object_loc, ctype )==0)  {
200                 Int3();         // Debug below
201                 i=place_object(Cursegp, &cur_object_loc, ctype );
202                 return 1;
203         }
204
205         if (hostage_object_is_valid( Cur_object_index ) )       {
206                 CurrentHostageIndex     = Objects[Cur_object_index].id;
207         } else {
208                 Int3();         // Get John! (Object should be valid)
209                 i=hostage_object_is_valid( Cur_object_index );  // For debugging only
210         }
211
212         return 0;
213 }
214
215 int CompressHostages()
216 {
217         hostage_compress_all();
218
219         return 0;
220 }
221
222 //@@int SelectPrevVclip()       {
223 //@@    if (!hostage_is_valid( CurrentHostageIndex ) )  
224 //@@            return 0;
225 //@@
226 //@@    if ( Hostages[CurrentHostageIndex].type == 0 )
227 //@@            Hostages[CurrentHostageIndex].type = N_hostage_types-1;
228 //@@    else
229 //@@            Hostages[CurrentHostageIndex].type--;
230 //@@    
231 //@@    if ( Hostages[CurrentHostageIndex].type >= N_hostage_types )
232 //@@            Hostages[CurrentHostageIndex].type = 0;
233 //@@    
234 //@@    return 1;
235 //@@}
236 //@@
237 //@@int SelectNextVclip()       {
238 //@@    if (!hostage_is_valid( CurrentHostageIndex ) )  
239 //@@            return 0;
240 //@@
241 //@@    Hostages[CurrentHostageIndex].type++;
242 //@@    if ( Hostages[CurrentHostageIndex].type >= N_hostage_types )
243 //@@            Hostages[CurrentHostageIndex].type = 0;
244 //@@
245 //@@    return 1;
246 //@@}
247
248 int SelectNextFace()
249 {
250         int start = Hostages[CurrentHostageIndex].vclip_num;
251         
252         if (!hostage_is_valid( CurrentHostageIndex ) )  
253                 return 0;
254
255         do {
256                 Hostages[CurrentHostageIndex].vclip_num++;
257                 if ( Hostages[CurrentHostageIndex].vclip_num >= MAX_HOSTAGES)
258                         Hostages[CurrentHostageIndex].vclip_num = 0;
259
260                 if (Hostages[CurrentHostageIndex].vclip_num == start)
261                         return 0;
262
263         } while (Hostage_face_clip[Hostages[CurrentHostageIndex].vclip_num].num_frames == 0);
264
265         return 1;
266 }
267
268 int SelectPrevFace()
269 {
270         int start = Hostages[CurrentHostageIndex].vclip_num;
271         
272         if (!hostage_is_valid( CurrentHostageIndex ) )  
273                 return 0;
274
275         do {
276                 Hostages[CurrentHostageIndex].vclip_num--;
277                 if ( Hostages[CurrentHostageIndex].vclip_num < 0)
278                         Hostages[CurrentHostageIndex].vclip_num = MAX_HOSTAGES-1;
279
280                 if (Hostages[CurrentHostageIndex].vclip_num == start)
281                         return 0;
282
283         } while (Hostage_face_clip[Hostages[CurrentHostageIndex].vclip_num].num_frames == 0);
284
285         return 1;
286 }
287
288 int PlayHostageSound()  {
289         int sound_num;
290
291         if (!hostage_is_valid( CurrentHostageIndex ) )  
292                 return 0;
293
294         sound_num = Hostage_face_clip[Hostages[CurrentHostageIndex].vclip_num].sound_num;
295
296         if ( sound_num > -1 )   {
297                 digi_play_sample( sound_num, F1_0 );
298         }
299
300         return 1;       
301 }
302
303 //@@int find_next_hostage_sound()       {
304 //@@    int start=0,n;
305 //@@
306 //@@    n = Hostages[CurrentHostageIndex].sound_num;
307 //@@    do      {
308 //@@            n++;
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;
311 //@@            start++;
312 //@@            if ( start > MAX_HOSTAGE_SOUNDS ) break;
313 //@@    } while ( Sounds[n] == NULL );
314 //@@
315 //@@    if ( Sounds[n] == NULL )
316 //@@            Hostages[CurrentHostageIndex].sound_num = -1;
317 //@@    else    {
318 //@@            Hostages[CurrentHostageIndex].sound_num = n;
319 //@@            PlayHostageSound();
320 //@@    }
321 //@@    return 1;
322 //@@}
323 //@@
324 //@@int find_prev_hostage_sound()       {
325 //@@    int start=0,n;
326 //@@
327 //@@    n = Hostages[CurrentHostageIndex].sound_num;
328 //@@    do      {
329 //@@            n--;
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;
332 //@@            start++;
333 //@@            if ( start > MAX_HOSTAGE_SOUNDS ) break;
334 //@@    } while ( Sounds[n] == NULL );
335 //@@
336 //@@    if ( Sounds[n] == NULL )
337 //@@            Hostages[CurrentHostageIndex].sound_num = -1;
338 //@@    else    {
339 //@@            Hostages[CurrentHostageIndex].sound_num = n;
340 //@@            PlayHostageSound();
341 //@@    }
342 //@@    return 1;
343 //@@}
344
345 #endif // 0
346
347 //-------------------------------------------------------------------------
348 // Called from the editor... does one instance of the hostage dialog box
349 //-------------------------------------------------------------------------
350 int do_hostage_dialog()
351 {
352 #if 0
353         int i;
354
355         // Only open 1 instance of this window...
356         if ( MainWindow != NULL ) return 0;
357         
358         // Close other windows
359         close_all_windows();
360
361         CurrentHostageIndex = 0;
362         SelectClosestHostage();
363
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 );
367
368         ui_wprintf_at( MainWindow, 10, 32,"&Message:" );
369         HostageText = ui_add_gadget_inputbox( MainWindow, 10, 50, HOSTAGE_MESSAGE_LEN, HOSTAGE_MESSAGE_LEN, HostageMessage );
370
371         // The little box the hostage vclip will play in.
372         HostageViewBox = ui_add_gadget_userbox( MainWindow,10, 90+10, 64, 64 );
373
374         // A bunch of buttons...
375         i = 90;
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;                
380
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;                
389         
390         Time = timer_get_fixed_seconds();
391
392         LastHostageIndex = -2;          // Set to some dummy value so everything works ok on the first frame.
393         
394 //      if ( CurrentHostageIndex == -1 )
395 //              SelectNextHostage();
396 #endif
397         return 1;
398
399 }
400
401 void hostage_close_window()
402 {
403 #if 0
404         if ( MainWindow!=NULL ) {
405                 ui_close_window( MainWindow );
406                 MainWindow = NULL;
407         }
408 #endif
409 }
410
411 void do_hostage_window()
412 {
413 #if 0   // redundant
414         fix DeltaTime, Temp;
415
416         if ( MainWindow == NULL ) return;
417
418         SelectClosestHostage();
419
420         //------------------------------------------------------------
421         // Call the ui code..
422         //------------------------------------------------------------
423         ui_button_any_drawn = 0;
424         ui_window_do_gadgets(MainWindow);
425
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 )   {
432
433                 if ( CurrentHostageIndex > -1 ) 
434                         strcpy( HostageText->text, Hostages[CurrentHostageIndex].text );
435                 else
436                         strcpy(HostageText->text, " " );
437
438                 HostageText->position = strlen(HostageText->text);
439                 HostageText->oldposition = HostageText->position;
440                 HostageText->status=1;
441                 HostageText->first_time = 1;
442
443         }
444
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 );
451
452         //------------------------------------------------------------
453         // A simple frame time counter for spinning the objects...
454         //------------------------------------------------------------
455         Temp = timer_get_fixed_seconds();
456         DeltaTime = Temp - Time;
457         Time = Temp;
458
459         //------------------------------------------------------------
460         // Redraw the object in the little 64x64 box
461         //------------------------------------------------------------
462         if (CurrentHostageIndex > -1 )  {
463                 int vclip_num;
464                 
465                 vclip_num = Hostages[CurrentHostageIndex].vclip_num;
466
467                 Assert(vclip_num != -1);
468
469                 gr_set_current_canvas( HostageViewBox->canvas );
470
471                 if ( vclip_num > -1 )   {
472                         vclip_play( &Hostage_face_clip[vclip_num], DeltaTime ); 
473                 } else {
474                         gr_clear_canvas( CGREY );
475                 }
476         } else {
477                 // no hostage, so just blank out
478                 gr_set_current_canvas( HostageViewBox->canvas );
479                 gr_clear_canvas( CGREY );
480         }
481
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);
491                 }       else {
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:         " );
495                 }
496                 Update_flags |= UF_WORLD_CHANGED;
497         }
498
499         if ( QuitButton->pressed || (last_keypress==KEY_ESC))   {
500                 hostage_close_window();
501                 return;
502         }               
503
504         LastHostageIndex = CurrentHostageIndex;
505 #endif
506 }
507
508
509