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