1 /* ---------------------------------------------------------------------- *
2  * splash.c
3  * This file is part of lincity.
4  * Lincity is copyright (c) I J Peters 1995-1997, (c) Greg Sharp 1997-2001.
5  * ---------------------------------------------------------------------- */
6 #include "lcconfig.h"
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <ctype.h>
10 #include "lcstring.h"
11 
12 #if defined (WIN32)
13 #include <winsock.h>
14 #include <io.h>
15 #include <direct.h>
16 #include <process.h>
17 #endif
18 
19 #include "common.h"
20 #ifdef LC_X11
21 #include <X11/cursorfont.h>
22 #endif
23 #include "lctypes.h"
24 #include "lin-city.h"
25 #include "cliglobs.h"
26 #include "engglobs.h"
27 #include "screen.h"
28 #include "fileutil.h"
29 
30 #define SI_BLACK 252
31 #define SI_RED 253
32 #define SI_GREEN 254
33 #define SI_YELLOW 255
34 
35 /* ---------------------------------------------------------------------- *
36  * Private Fn Prototypes
37  * ---------------------------------------------------------------------- */
38 
39 
40 /* ---------------------------------------------------------------------- *
41  * Private Global Variables
42  * ---------------------------------------------------------------------- */
43 
44 
45 /* ---------------------------------------------------------------------- *
46  * Public Functions
47  * ---------------------------------------------------------------------- */
48 void
load_start_image(void)49 load_start_image (void)
50 {
51 #ifdef LC_X11
52   XColor pal[256];
53   XEvent xev;
54 #endif
55   long x, y, l, r, g, b;
56   FILE *fp;
57 
58   fp = fopen_read_gzipped (opening_pic);
59   if (fp == NULL) {
60       return;
61   }
62 
63   for (x = 0; x < 7; x++)
64     l = fgetc (fp);
65   l &= 0xff;
66   if (l == 0)
67     l = 256;
68   for (x = 0; x < l; x++)
69     {
70       r = fgetc (fp);
71       g = fgetc (fp);
72       b = fgetc (fp);
73 #ifdef LC_X11
74       pal[x].red = r;
75       pal[x].green = g;
76       pal[x].blue = b;
77       pal[x].flags = DoRed | DoGreen | DoBlue;
78 #else
79       gl_setpalettecolor (x, r, g, b);
80 #endif
81     }
82   /* use last 4 colours for text */
83 #ifdef LC_X11
84   pal[SI_BLACK].red = 0;
85   pal[SI_BLACK].green = 0;
86   pal[SI_BLACK].blue = 0;
87   pal[SI_BLACK].flags = DoRed | DoGreen | DoBlue;
88   pal[SI_RED].red = 60;
89   pal[SI_RED].green = 0;
90   pal[SI_RED].blue = 0;
91   pal[SI_RED].flags = DoRed | DoGreen | DoBlue;
92   pal[SI_GREEN].red = 0;
93   pal[SI_GREEN].green = 60;
94   pal[SI_GREEN].blue = 0;
95   pal[SI_GREEN].flags = DoRed | DoGreen | DoBlue;
96   pal[SI_YELLOW].red = 60;
97   pal[SI_YELLOW].green = 60;
98   pal[SI_YELLOW].blue = 0;
99   pal[SI_YELLOW].flags = DoRed | DoGreen | DoBlue;
100   open_setcustompalette (pal);
101   suppress_next_expose = 1;
102   do
103     {
104       while (XPending (display.dpy) == 0);
105       XNextEvent (display.dpy, &xev);
106       HandleEvent (&xev);
107     }
108   while (xev.type != MapNotify);
109 
110 #else
111   gl_setpalettecolor (SI_BLACK, 0, 0, 0);
112   gl_setpalettecolor (SI_RED, 60, 0, 0);
113   gl_setpalettecolor (SI_GREEN, 0, 60, 0);
114   gl_setpalettecolor (SI_YELLOW, 60, 60, 0);
115 #endif
116 #if defined (WIN32)
117   UpdatePalette ();
118 #endif
119   for (y = 0; y < 480; y++)
120     for (x = 0; x < 640; x++)
121       {
122 	l = fgetc (fp);
123 	/*
124 	   //      printf("l=%d x=%d y=%d ",l,x,y);
125 	   // octree doesn't seem to want to generate images with 252 colours!
126 	   // So the next best thing (well the easyest) is to just map the pixels
127 	   // coloured as the last 4 colours to the 4 before that.
128 	   // If it looks OK, leave it.
129 	 */
130 	if (l == SI_BLACK)
131 	  l = SI_BLACK - 4;
132 	if (l == SI_RED)
133 	  l = SI_RED - 4;
134 	if (l == SI_GREEN)
135 	  l = SI_GREEN - 4;
136 	if (l == SI_YELLOW)
137 	  l = SI_YELLOW - 4;
138 	Fgl_setpixel (x, y, l);
139       }
140 
141   fclose_read_gzipped (fp);
142 
143 #if defined (WIN32)
144   RefreshScreen ();
145 #endif
146   start_image_text ();
147 }
148 
149 void
start_image_text(void)150 start_image_text (void)
151 {
152 #if defined (SVGALIB)
153   gl_setwritemode (FONT_COMPRESSED);
154 #endif
155   Fgl_setfont (8, 8, start_font1);
156 #if defined (SVGALIB)
157   gl_setwritemode (FONT_COMPRESSED);
158 #endif
159   Fgl_setfontcolors (SI_BLACK, SI_RED);
160   si_scroll_text ();
161 }
162 
163 void
si_scroll_text(void)164 si_scroll_text (void)
165 {
166   char s[LC_PATH_MAX], line1[100], line2[100], line3[100], c;
167   int i, t, l1c = 0, l2c = 0, l3c = 0;
168   FILE *inf1, *inf2, *inf3;
169 #ifdef LC_X11
170   XEvent xev;
171 #endif
172   Fgl_enableclipping ();
173   sprintf (s, "%s%c%s", opening_path, PATH_SLASH, "text1");
174   if ((inf1 = fopen (s, "rb")) == NULL)
175     do_error ("Can't open opening/text1");
176   for (i = 0; i < 52; i++)
177     line1[i] = si_next_char (inf1);
178   line1[52] = 0;
179   sprintf (s, "%s%c%s", opening_path, PATH_SLASH, "text2");
180   if ((inf2 = fopen (s, "rb")) == NULL)
181     do_error ("Can't open opening/text2");
182   for (i = 0; i < 52; i++)
183     line2[i] = si_next_char (inf2);
184   line2[52] = 0;
185   sprintf (s, "%s%c%s", opening_path, PATH_SLASH, "text3");
186   if ((inf3 = fopen (s, "rb")) == NULL)
187     do_error ("Can't open opening/text3");
188   for (i = 0; i < 52; i++)
189     line3[i] = si_next_char (inf3);
190   line3[52] = 0;
191   do
192     {
193       get_real_time ();
194       t = real_time + SPLASH_SCROLL_DELAY;
195 #ifdef LC_X11
196       if (XPending (display.dpy))
197 
198 	{
199 	  XNextEvent (display.dpy, &xev);
200 	  HandleEvent (&xev);
201 	}
202 
203       c = x_key_value;
204 #elif defined (WIN32)
205       c = GetKeystroke ();
206 #else
207       c = vga_getkey ();
208 #endif
209       if (l1c >= 8)
210 	{
211 	  for (i = 0; i < 51; i++)
212 	    line1[i] = line1[i + 1];
213 	  line1[51] = si_next_char (inf1);
214 	  l1c = 0;
215 	}
216       Fgl_setfont (8, 8, start_font1);
217       Fgl_setclippingwindow (120, 30, 520, 40);
218       Fgl_setfontcolors (SI_BLACK, SI_RED);
219 #if defined (LC_X11) || defined (WIN32)
220       open_write (120 - l1c, 31, line1);
221 #else
222       Fgl_write (120 - l1c, 31, line1);
223 #endif
224       l1c++;
225 
226       if (l2c >= 8)
227 	{
228 	  for (i = 0; i < 51; i++)
229 	    line2[i] = line2[i + 1];
230 	  line2[51] = si_next_char (inf2);
231 	  l2c = 0;
232 	}
233       Fgl_setfont (8, 16, start_font2);
234       Fgl_setclippingwindow (120, 55, 520, 73);
235       Fgl_setfontcolors (SI_BLACK, SI_GREEN);
236 #if defined (LC_X11) || defined (WIN32)
237       open_write (120 - l2c, 57, line2);
238 #else
239       Fgl_write (120 - l2c, 57, line2);
240 #endif
241       l2c += 2;
242 
243       if (l3c >= 8)
244 	{
245 	  for (i = 0; i < 51; i++)
246 	    line3[i] = line3[i + 1];
247 	  line3[51] = si_next_char (inf3);
248 	  l3c = 0;
249 	}
250       Fgl_setfont (8, 16, start_font3);
251       Fgl_setclippingwindow (120, 88, 520, 106);
252       Fgl_setfontcolors (SI_BLACK, SI_YELLOW);
253 #if defined (LC_X11) || defined (WIN32)
254       open_write (120 - l3c, 90, line3);
255 #else
256       Fgl_write (120 - l3c, 90, line3);
257 #endif
258       l3c += 2;
259 #if defined (WIN32)		/* Scroll a little faster for WIN32 */
260       if (pix_double)
261 	{
262 	  l1c += 10;
263 	  l2c += 10;
264 	  l3c += 10;
265 	}
266       else
267 	{
268 	  l1c += 2;
269 	  l2c += 4;
270 	  l3c += 4;
271 	}
272 #endif
273       while (real_time < t)
274 	{
275 	  lc_usleep (1);
276 	  get_real_time ();
277 	}
278     }
279   while (c == 0);
280   fclose (inf1);
281   fclose (inf2);
282   fclose (inf3);
283   Fgl_disableclipping ();
284 }
285 
286 char
si_next_char(FILE * inf)287 si_next_char (FILE * inf)
288 {
289   char c;
290   if (feof (inf) != 0)
291     fseek (inf, 0L, SEEK_SET);
292   c = fgetc (inf);
293   if (c == 0xa || c == 0xd)
294     c = ' ';
295   return (c);
296 }
297 
298