]> icculus.org git repositories - btb/d2x.git/blob - main/movie.c
more movie improvements
[btb/d2x.git] / main / movie.c
1 /* $Id: movie.c,v 1.12 2002-09-01 02:49:06 btb 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-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
13 */
14
15 #ifdef HAVE_CONFIG_H
16 #include <conf.h>
17 #endif
18
19 #ifdef RCS
20 static char rcsid[] = "$Id: movie.c,v 1.12 2002-09-01 02:49:06 btb Exp $";
21 #endif
22
23 #define DEBUG_LEVEL CON_NORMAL
24
25 #include <string.h>
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 #include <fcntl.h>
29 #include <unistd.h>
30 #include <ctype.h>
31
32 #include "movie.h"
33 #include "console.h"
34 #include "args.h"
35 #include "key.h"
36 #include "digi.h"
37 #include "songs.h"
38 #include "inferno.h"
39 #include "palette.h"
40 #include "strutil.h"
41 #include "error.h"
42 #include "u_mem.h"
43 #include "byteswap.h"
44 #include "gr.h"
45 #include "gamefont.h"
46 #include "cfile.h"
47 #include "menu.h"
48 #include "mvelib.h"
49 #include "text.h"
50 #include "fileutil.h"
51 #include "mveplay.h"
52
53 extern int MenuHiresAvailable;
54 extern char CDROM_dir[];
55
56 #define VID_PLAY 0
57 #define VID_PAUSE 1
58
59 int Vid_State;
60
61
62 // Subtitle data
63 typedef struct {
64         short first_frame,last_frame;
65         char *msg;
66 } subtitle;
67
68 #define MAX_SUBTITLES 500
69 #define MAX_ACTIVE_SUBTITLES 3
70 subtitle Subtitles[MAX_SUBTITLES];
71 int Num_subtitles;
72
73
74 typedef struct {
75         char name[FILENAME_LEN];
76         int offset,len;
77 } ml_entry;
78
79 #define MLF_ON_CD    1
80 #define MAX_MOVIES_PER_LIB    50    //determines size of malloc
81
82
83 typedef struct {
84         char     name[100]; //[FILENAME_LEN];
85         int      n_movies;
86         ubyte    flags,pad[3];
87         ml_entry *movies;
88 } movielib;
89
90 #ifdef D2_OEM
91 char movielib_files[][FILENAME_LEN] = {"intro-l.mvl","other-l.mvl","robots-l.mvl","oem-l.mvl"};
92 #else
93 char movielib_files[][FILENAME_LEN] = {"intro-l.mvl","other-l.mvl","robots-l.mvl"};
94 #endif
95
96 #define N_BUILTIN_MOVIE_LIBS (sizeof(movielib_files)/sizeof(*movielib_files))
97 #define N_MOVIE_LIBS (N_BUILTIN_MOVIE_LIBS+1)
98 #define EXTRA_ROBOT_LIB N_BUILTIN_MOVIE_LIBS
99 movielib *movie_libs[N_MOVIE_LIBS];
100
101 int MVEPaletteCalls = 0;
102
103 //do we have the robot movies available
104 int robot_movies = 0; //0 means none, 1 means lowres, 2 means hires
105
106 int MovieHires = 0;   //default for now is lores
107
108 int RoboFile = 0;
109 off_t Robo_filepos;
110 MVESTREAM *Robo_mve;
111 grs_bitmap *Robo_bitmap;
112
113
114 //      Function Prototypes
115 int RunMovie(char *filename, int highres_flag, int allow_abort,int dx,int dy);
116
117 int open_movie_file(char *filename,int must_have);
118
119 void change_filename_ext( char *dest, char *src, char *ext );
120 void decode_text_line(char *p);
121 void draw_subtitles(int frame_num);
122
123
124 //filename will actually get modified to be either low-res or high-res
125 //returns status.  see values in movie.h
126 int PlayMovie(const char *filename, int must_have)
127 {
128         char name[FILENAME_LEN],*p;
129         int c, ret;
130 #if 0
131         int save_sample_rate;
132 #endif
133
134 #ifndef RELEASE
135         if (FindArg("-nomovies"))
136                 return MOVIE_NOT_PLAYED;
137 #endif
138
139         strcpy(name,filename);
140
141         if ((p=strchr(name,'.')) == NULL)               //add extension, if missing
142                 strcat(name,".mve");
143
144         //check for escape already pressed & abort if so
145         while ((c=key_inkey()) != 0)
146                 if (c == KEY_ESC)
147                         return MOVIE_ABORTED;
148
149         // Stop all digital sounds currently playing.
150         digi_stop_all();
151
152         // Stop all songs
153         songs_stop_all();
154
155 #if 0
156         save_sample_rate = digi_sample_rate;
157         digi_sample_rate = SAMPLE_RATE_22K;             //always 22K for movies
158         digi_reset(); digi_reset();
159 #else
160         digi_close();
161 #endif
162
163         ret = RunMovie(name,MovieHires,must_have,-1,-1);
164
165 #if 0
166         gr_palette_clear();             //clear out palette in case movie aborted
167 #endif
168
169 #if 0
170         digi_sample_rate = save_sample_rate;            //restore rate for game
171         digi_reset(); digi_reset();
172 #else
173         digi_init();
174 #endif
175
176         Screen_mode = -1;               //force screen reset
177
178         return ret;
179 }
180
181 #if 0
182 typedef struct bkg {
183         short x, y, w, h;           // The location of the menu.
184         grs_bitmap * bmp;               // The background under the menu.
185 } bkg;
186
187 bkg movie_bg = {0,0,0,0,NULL};
188 #endif
189
190 #define BOX_BORDER (MenuHires?40:20)
191
192 void show_pause_message(char *msg)
193 {
194         int w,h,aw;
195         int x,y;
196
197         gr_set_current_canvas(NULL);
198         gr_set_curfont( SMALL_FONT );
199
200         gr_get_string_size(msg,&w,&h,&aw);
201
202         x = (grd_curscreen->sc_w-w)/2;
203         y = (grd_curscreen->sc_h-h)/2;
204
205 #if 0
206         if (movie_bg.bmp) {
207                 gr_free_bitmap(movie_bg.bmp);
208                 movie_bg.bmp = NULL;
209         }
210
211         // Save the background of the display
212         movie_bg.x=x; movie_bg.y=y; movie_bg.w=w; movie_bg.h=h;
213
214         movie_bg.bmp = gr_create_bitmap( w+BOX_BORDER, h+BOX_BORDER );
215
216         gr_bm_ubitblt(w+BOX_BORDER, h+BOX_BORDER, 0, 0, x-BOX_BORDER/2, y-BOX_BORDER/2, &(grd_curcanv->cv_bitmap), movie_bg.bmp );
217 #endif
218
219         gr_setcolor(0);
220         gr_rect(x-BOX_BORDER/2,y-BOX_BORDER/2,x+w+BOX_BORDER/2-1,y+h+BOX_BORDER/2-1);
221
222         gr_set_fontcolor( 255, -1 );
223
224         gr_ustring( 0x8000, y, msg );
225
226         gr_update();
227 }
228
229 void clear_pause_message()
230 {
231 #if 0
232         if (movie_bg.bmp) {
233
234                 gr_bitmap(movie_bg.x-BOX_BORDER/2, movie_bg.y-BOX_BORDER/2, movie_bg.bmp);
235
236                 gr_free_bitmap(movie_bg.bmp);
237                 movie_bg.bmp = NULL;
238         }
239 #endif
240 }
241
242 //returns status.  see movie.h
243 int RunMovie(char *filename, int hires_flag, int must_have,int dx,int dy)
244 {
245         int filehndl;
246         int result=1,aborted=0;
247         int frame_num;
248         MVESTREAM *mve;
249         grs_bitmap *mve_bitmap;
250         int key;
251         int x, y, w, h;
252
253         result=1;
254
255         // Open Movie file.  If it doesn't exist, no movie, just return.
256
257         filehndl = open_movie_file(filename,must_have);
258
259         if (filehndl == -1) {
260 #ifndef EDITOR
261                 if (must_have)
262                         Warning("movie: RunMovie: Cannot open movie <%s>\n",filename);
263 #endif
264                 return MOVIE_NOT_PLAYED;
265         }
266
267         if (hires_flag) {
268                 gr_set_mode(SM(640,480));
269                 x = 24;
270                 y = 84;
271                 w = 592;
272                 h = 312;
273         } else {
274                 gr_set_mode(SM(320,200));
275                 x = 0;
276                 y = 32;
277                 w = 320;
278                 h = 136;
279         }
280
281         frame_num = 0;
282
283         FontHires = FontHiresAvailable && hires_flag;
284
285     mve = mve_open(filehndl);
286
287         mve_bitmap = gr_create_bitmap(w, h); // w, h must match the mve exactly!
288
289         mveplay_initializeMovie(mve, mve_bitmap);
290
291         while((result = mveplay_stepMovie(mve))) {
292
293                 gr_bitmap(x, y, mve_bitmap);
294
295                 draw_subtitles(frame_num);
296
297                 key = key_inkey();
298
299                 // If ESCAPE pressed, then quit movie.
300                 if (key == KEY_ESC) {
301                         result = 0;
302                         aborted = 1;
303                         break;
304                 }
305
306                 // If PAUSE pressed, then pause movie
307                 if (key == KEY_PAUSE) {
308                         show_pause_message(TXT_PAUSE);
309                         while (!key_inkey()) ;
310                         mveplay_restartTimer(mve);
311                         clear_pause_message();
312                 }
313
314                 frame_num++;
315         }
316
317         Assert(aborted || !result);      ///movie should be over
318
319     mveplay_shutdownMovie(mve);
320
321         gr_free_bitmap(mve_bitmap);
322
323     mve_close(mve);
324
325         close(filehndl);                           // Close Movie File
326
327         // Restore old graphic state
328
329         Screen_mode=-1;  //force reset of screen mode
330
331         return (aborted?MOVIE_ABORTED:MOVIE_PLAYED_FULL);
332 }
333
334
335 int InitMovieBriefing()
336 {
337         if (MenuHires)
338                 gr_set_mode(SM(640,480));
339         else
340                 gr_set_mode(SM(320,200));
341
342         return 1;
343 }
344
345
346 //returns 1 if frame updated ok
347 int RotateRobot()
348 {
349         int ret;
350
351         ret = mveplay_stepMovie(Robo_mve);
352         gr_bitmap(MenuHires?280:140, MenuHires?200:80, Robo_bitmap);
353
354         if (!ret) {
355                 mveplay_shutdownMovie(Robo_mve);
356                 mve_close(Robo_mve);
357                 lseek(RoboFile, Robo_filepos, SEEK_SET);
358                 Robo_mve = mve_open(RoboFile);
359                 mveplay_initializeMovie(Robo_mve, Robo_bitmap);
360         }
361
362         return 1;
363 }
364
365
366 void DeInitRobotMovie(void)
367 {
368         mveplay_shutdownMovie(Robo_mve);
369         mve_close(Robo_mve);
370
371         gr_free_bitmap(Robo_bitmap);
372
373         close(RoboFile);
374 }
375
376
377 int InitRobotMovie(char *filename)
378 {
379         RoboFile = open_movie_file(filename, 1);
380
381         if (RoboFile == -1) {
382                 Warning("movie: InitRobotMovie: Cannot open movie file <%s>",filename);
383                 return MOVIE_NOT_PLAYED;
384         }
385
386         Robo_filepos = lseek(RoboFile, 0, SEEK_CUR);
387
388         Robo_mve = mve_open(RoboFile);
389
390         Robo_bitmap = gr_create_bitmap(MenuHires?320:160, MenuHires?200:88);
391
392         mveplay_initializeMovie(Robo_mve, Robo_bitmap);
393
394         return 1;
395 }
396
397
398 /*
399  *              Subtitle system code
400  */
401
402 ubyte *subtitle_raw_data;
403
404
405 //search for next field following whitespace 
406 ubyte *next_field(ubyte *p)
407 {
408         while (*p && !isspace(*p))
409                 p++;
410
411         if (!*p)
412                 return NULL;
413
414         while (*p && isspace(*p))
415                 p++;
416
417         if (!*p)
418                 return NULL;
419
420         return p;
421 }
422
423
424 int init_subtitles(char *filename)
425 {
426         CFILE *ifile;
427         int size,read_count;
428         ubyte *p;
429         int have_binary = 0;
430
431         Num_subtitles = 0;
432
433         if (! FindArg("-subtitles"))
434                 return 0;
435
436         ifile = cfopen(filename,"rb");          //try text version
437
438         if (!ifile) {                                                           //no text version, try binary version
439                 char filename2[FILENAME_LEN];
440                 change_filename_ext(filename2,filename,".TXB");
441                 ifile = cfopen(filename2,"rb");
442                 if (!ifile)
443                         return 0;
444                 have_binary = 1;
445         }
446
447         size = cfilelength(ifile);
448    
449         MALLOC (subtitle_raw_data, ubyte, size+1);
450
451         read_count = cfread(subtitle_raw_data, 1, size, ifile);
452
453         cfclose(ifile);
454
455         subtitle_raw_data[size] = 0;
456
457         if (read_count != size) {
458                 d_free(subtitle_raw_data);
459                 return 0;
460         }
461
462         p = subtitle_raw_data;
463
464         while (p && p < subtitle_raw_data+size) {
465                 char *endp;
466
467                 endp = strchr(p,'\n'); 
468                 if (endp) {
469                         if (endp[-1] == '\r')
470                                 endp[-1] = 0;           //handle 0d0a pair
471                         *endp = 0;                      //string termintor
472                 }
473
474                 if (have_binary)
475                         decode_text_line(p);
476
477                 if (*p != ';') {
478                         Subtitles[Num_subtitles].first_frame = atoi(p);
479                         p = next_field(p); if (!p) continue;
480                         Subtitles[Num_subtitles].last_frame = atoi(p);
481                         p = next_field(p); if (!p) continue;
482                         Subtitles[Num_subtitles].msg = p;
483
484                         Assert(Num_subtitles==0 || Subtitles[Num_subtitles].first_frame >= Subtitles[Num_subtitles-1].first_frame);
485                         Assert(Subtitles[Num_subtitles].last_frame >= Subtitles[Num_subtitles].first_frame);
486
487                         Num_subtitles++;
488                 }
489
490                 p = endp+1;
491
492         }
493
494         return 1;
495 }
496
497
498 void close_subtitles()
499 {
500         if (subtitle_raw_data)
501                 d_free(subtitle_raw_data);
502         subtitle_raw_data = NULL;
503         Num_subtitles = 0;
504 }
505
506
507 //draw the subtitles for this frame
508 void draw_subtitles(int frame_num)
509 {
510         static int active_subtitles[MAX_ACTIVE_SUBTITLES];
511         static int num_active_subtitles,next_subtitle,line_spacing;
512         int t,y;
513         int must_erase=0;
514
515         if (frame_num == 0) {
516                 num_active_subtitles = 0;
517                 next_subtitle = 0;
518                 gr_set_curfont( GAME_FONT );
519                 line_spacing = grd_curcanv->cv_font->ft_h + (grd_curcanv->cv_font->ft_h >> 2);
520                 gr_set_fontcolor(255,-1);
521         }
522
523         //get rid of any subtitles that have expired
524         for (t=0;t<num_active_subtitles;)
525                 if (frame_num > Subtitles[active_subtitles[t]].last_frame) {
526                         int t2;
527                         for (t2=t;t2<num_active_subtitles-1;t2++)
528                                 active_subtitles[t2] = active_subtitles[t2+1];
529                         num_active_subtitles--;
530                         must_erase = 1;
531                 }
532                 else
533                         t++;
534
535         //get any subtitles new for this frame 
536         while (next_subtitle < Num_subtitles && frame_num >= Subtitles[next_subtitle].first_frame) {
537                 if (num_active_subtitles >= MAX_ACTIVE_SUBTITLES)
538                         Error("Too many active subtitles!");
539                 active_subtitles[num_active_subtitles++] = next_subtitle;
540                 next_subtitle++;
541         }
542
543         //find y coordinate for first line of subtitles
544         y = grd_curcanv->cv_bitmap.bm_h-((line_spacing+1)*MAX_ACTIVE_SUBTITLES+2);
545
546         //erase old subtitles if necessary
547         if (must_erase) {
548                 gr_setcolor(0);
549                 gr_rect(0,y,grd_curcanv->cv_bitmap.bm_w-1,grd_curcanv->cv_bitmap.bm_h-1);
550         }
551
552         //now draw the current subtitles
553         for (t=0;t<num_active_subtitles;t++)
554                 if (active_subtitles[t] != -1) {
555                         gr_string(0x8000,y,Subtitles[active_subtitles[t]].msg);
556                         y += line_spacing+1;
557                 }
558
559         gr_update();
560 }
561
562
563 int request_cd(void)
564 {
565         con_printf(DEBUG_LEVEL, "STUB: movie: request_cd\n");
566         return 0;
567 }
568
569
570 movielib *init_new_movie_lib(char *filename,FILE *fp)
571 {
572         int nfiles,offset;
573         int i,n;
574         movielib *table;
575
576         //read movie file header
577
578         nfiles = file_read_int(fp);             //get number of files
579
580         //table = d_malloc(sizeof(*table) + sizeof(ml_entry)*nfiles);
581         MALLOC(table, movielib, 1);
582         MALLOC(table->movies, ml_entry, nfiles);
583
584         strcpy(table->name,filename);
585         table->n_movies = nfiles;
586
587         offset = 4+4+nfiles*(13+4);     //id + nfiles + nfiles * (filename + size)
588
589         for (i=0;i<nfiles;i++) {
590                 int len;
591
592                 n = fread( table->movies[i].name, 13, 1, fp );
593                 if ( n != 1 )
594                         break;          //end of file (probably)
595
596                 len = file_read_int(fp);
597
598                 table->movies[i].len = len;
599                 table->movies[i].offset = offset;
600
601                 offset += table->movies[i].len;
602
603         }
604
605         fclose(fp);
606
607         table->flags = 0;
608
609         return table;
610
611 }
612
613
614 movielib *init_old_movie_lib(char *filename,FILE *fp)
615 {
616         int nfiles,size;
617         int i;
618         movielib *table,*table2;
619
620         nfiles = 0;
621
622         //allocate big table
623         table = d_malloc(sizeof(*table) + sizeof(ml_entry)*MAX_MOVIES_PER_LIB);
624
625         while( 1 ) {
626                 int len;
627
628                 i = fread( table->movies[nfiles].name, 13, 1, fp );
629                 if ( i != 1 )
630                         break;          //end of file (probably)
631
632                 i = fread( &len, 4, 1, fp );
633                 if ( i != 1 )
634                         Error("error reading movie library <%s>",filename);
635
636                 table->movies[nfiles].len = INTEL_INT(len);
637                 table->movies[nfiles].offset = ftell( fp );
638
639                 fseek( fp, INTEL_INT(len), SEEK_CUR );          //skip data
640
641                 nfiles++;
642         }
643
644         //allocate correct-sized table
645         size = sizeof(*table) + sizeof(ml_entry)*nfiles;
646         table2 = d_malloc(size);
647         memcpy(table2,table,size);
648         d_free(table);
649         table = table2;
650
651         strcpy(table->name,filename);
652
653         table->n_movies = nfiles;
654
655         fclose(fp);
656
657         table->flags = 0;
658
659         return table;
660
661 }
662
663
664 //find the specified movie library, and read in list of movies in it
665 movielib *init_movie_lib(char *filename)
666 {
667         //note: this based on cfile_init_hogfile()
668
669         char id[4];
670         FILE * fp;
671
672         fp = fopen( filename, "rb" );
673
674         if ((fp == NULL) && (AltHogdir_initialized)) {
675                 char temp[128];
676                 strcpy(temp, AltHogDir);
677                 strcat(temp, "/");
678                 strcat(temp, filename);
679                 fp = fopen(temp, "rb");
680         }
681
682         if ( fp == NULL )
683                 return NULL;
684
685         fread( id, 4, 1, fp );
686         if ( !strncmp( id, "DMVL", 4 ) )
687                 return init_new_movie_lib(filename,fp);
688         else if ( !strncmp( id, "DHF", 3 ) ) {
689                 fseek(fp,-1,SEEK_CUR);          //old file had 3 char id
690                 return init_old_movie_lib(filename,fp);
691         }
692         else {
693                 fclose(fp);
694                 return NULL;
695         }
696 }
697
698
699 void close_movie(int i)
700 {
701         if (movie_libs[i]) {
702                 d_free(movie_libs[i]->movies);
703                 d_free(movie_libs[i]);
704         }
705 }
706
707
708 void close_movies()
709 {
710         int i;
711
712         for (i=0;i<N_MOVIE_LIBS;i++)
713                 close_movie(i);
714 }
715
716
717 void init_movie(char *filename,int libnum,int is_robots,int required)
718 {
719         int high_res;
720         int try = 0;
721
722 #ifndef RELEASE
723         if (FindArg("-nomovies")) {
724                 movie_libs[libnum] = NULL;
725                 return;
726         }
727 #endif
728
729         //for robots, load highres versions if highres menus set
730         if (is_robots)
731                 high_res = MenuHiresAvailable;
732         else
733                 high_res = MovieHires;
734
735         if (high_res)
736                 strchr(filename,'.')[-1] = 'h';
737
738 try_again:;
739
740         if ((movie_libs[libnum] = init_movie_lib(filename)) == NULL) {
741                 char name2[100];
742
743                 strcpy(name2,CDROM_dir);
744                 strcat(name2,filename);
745                 movie_libs[libnum] = init_movie_lib(name2);
746
747                 if (movie_libs[libnum] != NULL)
748                         movie_libs[libnum]->flags |= MLF_ON_CD;
749                 else {
750                         if (required) {
751                                 Warning("Cannot open movie file <%s>\n",filename);
752                         }
753
754                         if (!try) {                                         // first try
755                                 if (strchr(filename, '.')[-1] == 'h') {         // try again with lowres
756                                         strchr(filename, '.')[-1] = 'l';
757                                         Warning("Trying to open movie file <%s> instead\n", filename);
758                                         try++;
759                                         goto try_again;
760                                 } else if (strchr(filename, '.')[-1] == 'l') {  // try again with highres
761                                         strchr(filename, '.')[-1] = 'h';
762                                         Warning("Trying to open movie file <%s> instead\n", filename);
763                                         try++;
764                                         goto try_again;
765                                 }
766                         }
767                 }
768         }
769
770         if (is_robots && movie_libs[libnum]!=NULL)
771                 robot_movies = high_res?2:1;
772 }
773
774
775 //find and initialize the movie libraries
776 void init_movies()
777 {
778         int i;
779         int is_robots;
780
781         for (i=0;i<N_BUILTIN_MOVIE_LIBS;i++) {
782
783                 if (!strnicmp(movielib_files[i],"robot",5))
784                         is_robots = 1;
785                 else
786                         is_robots = 0;
787
788                 init_movie(movielib_files[i],i,is_robots,1);
789         }
790
791         movie_libs[EXTRA_ROBOT_LIB] = NULL;
792
793         atexit(close_movies);
794 }
795
796
797 void init_extra_robot_movie(char *filename)
798 {
799         close_movie(EXTRA_ROBOT_LIB);
800         init_movie(filename,EXTRA_ROBOT_LIB,1,0);
801 }
802
803
804 //looks through a movie library for a movie file
805 //returns filehandle, with fileposition at movie, or -1 if can't find
806 int search_movie_lib(movielib *lib,char *filename,int must_have)
807 {
808         int i;
809         int filehandle;
810
811         if (lib == NULL)
812                 return -1;
813
814         for (i=0;i<lib->n_movies;i++)
815                 if (!stricmp(filename,lib->movies[i].name)) {   //found the movie in a library 
816                         int from_cd;
817
818                         from_cd = (lib->flags & MLF_ON_CD);
819
820                         if (from_cd)
821                                 songs_stop_redbook();           //ready to read from CD
822
823                         do {            //keep trying until we get the file handle
824
825                                 /* movie_handle = */ filehandle = open(lib->name, O_RDONLY);
826
827                                 if ((filehandle == -1) && (AltHogdir_initialized)) {
828                                         char temp[128];
829                                         strcpy(temp, AltHogDir);
830                                         strcat(temp, "/");
831                                         strcat(temp, lib->name);
832                                         filehandle = open(temp, O_RDONLY);
833                                 }
834
835                                 if (must_have && from_cd && filehandle == -1) {         //didn't get file!
836
837                                         if (request_cd() == -1)         //ESC from requester
838                                                 break;                                          //bail from here. will get error later
839                                 }
840
841                         } while (must_have && from_cd && filehandle == -1);
842
843                         if (filehandle != -1)
844                                 lseek(filehandle,(/* movie_start = */ lib->movies[i].offset),SEEK_SET);
845
846                         return filehandle;
847                 }
848
849         return -1;
850 }
851
852
853 //returns file handle
854 int open_movie_file(char *filename,int must_have)
855 {
856         int filehandle,i;
857
858         for (i=0;i<N_MOVIE_LIBS;i++) {
859                 if ((filehandle = search_movie_lib(movie_libs[i],filename,must_have)) != -1)
860                         return filehandle;
861         }
862
863         return -1;              //couldn't find it
864 }
865
866