1 /* ---------------------------------------------------------------------- *
2  * screen.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 <math.h>
10 #include <sys/types.h>
11 #include <sys/stat.h>
12 #if defined (HAVE_UNISTD_H)
13 #include <unistd.h>
14 #endif
15 #include "lcstring.h"
16 #include "common.h"
17 #include "lctypes.h"
18 #include "lin-city.h"
19 #include "screen.h"
20 #include "engglobs.h"
21 #include "cliglobs.h"
22 #include "pixmap.h"
23 #include "lchelp.h"
24 #include "mouse.h"
25 #include "mps.h"
26 #include "lcintl.h"
27 #include "ldsvgui.h"
28 #include "pbar.h"
29 #include "dialbox.h"
30 #include "lclib.h"
31 #include "module_buttons.h"
32 #include "stats.h"
33 #include "engine.h"
34 #include "fileutil.h"
35 
36 /* ---------------------------------------------------------------------- *
37  * External Global Variables
38  * ---------------------------------------------------------------------- */
39 extern int network_game;
40 
41 /* ---------------------------------------------------------------------- *
42  * Public Global Variables
43  * ---------------------------------------------------------------------- */
44 unsigned char main_font[2048];
45 unsigned char start_font1[2048];
46 unsigned char start_font2[4096];
47 unsigned char start_font3[4096];
48 Update_Scoreboard update_scoreboard;
49 
50 int monthgraph_style = MONTHGRAPH_STYLE_MIN;
51 
52 char screen_refreshing = 0;
53 
54 /* ---------------------------------------------------------------------- *
55  * Private Global Variables
56  * ---------------------------------------------------------------------- */
57 static int monthgraph_style_timeout = 1;
58 static int mps_global_style_timeout = 1;
59 static float time_for_year;
60 
61 /* ---------------------------------------------------------------------- *
62  * Private Function Prototypes
63  * ---------------------------------------------------------------------- */
64 void draw_yellow_bezel (int x, int y, int h, int w);
65 void draw_small_yellow_bezel (int x, int y, int h, int w);
66 void print_time_for_year (void);
67 void calculate_time_for_year (void);
68 void clear_monthgraph (void);
69 void draw_ms_buttons (void);
70 static void do_monthgraph (int full_refresh);
71 static void do_history_linegraph (int draw);
72 static void do_sust_barchart (int draw);
73 static void draw_sustline (int yoffset, int count, int max, int col);
74 void monthgraph_full_refresh (void);
75 void draw_mini_pol_in_main_win ();
76 void mini_full_refresh (void);
77 void update_main_screen_normal (int full_refresh);
78 void update_main_screen_pollution (void);
79 void update_main_screen_ub40 (void);
80 void update_main_screen_starve (void);
81 void update_main_screen_power (void);
82 void update_main_screen_fire_cover (void);
83 void update_main_screen_cricket_cover (void);
84 void update_main_screen_health_cover (void);
85 void update_main_screen_coal (void);
86 
87 
88 
89 /* ---------------------------------------------------------------------- *
90  * Public Functions
91  * ---------------------------------------------------------------------- */
92 void
draw_background(void)93 draw_background (void)
94 {
95     /* XXX: we don't need to draw the whole background! */
96     /* GCS: but this routine is only called on a full refresh, so it's OK */
97 
98 #if defined (LC_X11) || defined (WIN32)
99     /* Draw border region, but don't put into pixmap */
100     draw_border ();
101     /* Draw main area */
102     Fgl_fillbox (0, 0, pixmap_width, pixmap_height, TEXT_BG_COLOUR);
103 #else /* SVGALIB */
104     Fgl_fillbox (0, 0, display.winW, display.winH, TEXT_BG_COLOUR);
105 #endif
106 }
107 
108 void
connect_transport_main_screen(void)109 connect_transport_main_screen (void)
110 {
111     Rect* b = &scr.main_win;
112 
113     connect_transport (main_screen_originx, main_screen_originy,
114 		       b->w / 16, b->h / 16);
115 }
116 
117 void
refresh_main_screen(void)118 refresh_main_screen (void)
119 {
120     connect_transport_main_screen ();
121     update_main_screen (1);
122     update_mini_screen ();
123     dialog_refresh();
124 }
125 
126 void
clip_main_window()127 clip_main_window ()
128 {
129     Rect* b = &scr.main_win;
130     Fgl_enableclipping ();
131     Fgl_setclippingwindow (b->x, b->y, b->x + b->w - 1, b->y + b->h - 1);
132 }
133 
134 void
unclip_main_window()135 unclip_main_window ()
136 {
137     Fgl_disableclipping ();
138 }
139 
140 void
rotate_main_screen(void)141 rotate_main_screen (void)
142 {
143     if (main_screen_flag == MAIN_SCREEN_NORMAL_FLAG) {
144 	main_screen_flag = MAIN_SCREEN_EQUALS_MINI;
145     } else {
146 	main_screen_flag = MAIN_SCREEN_NORMAL_FLAG;
147     }
148     refresh_main_screen ();
149 }
150 
151 void
update_main_screen(int full_refresh)152 update_main_screen (int full_refresh)
153 {
154     if (main_screen_flag == MAIN_SCREEN_NORMAL_FLAG) {
155 	update_main_screen_normal (full_refresh);
156     } else {
157 	switch (mini_screen_flags) {
158 	case MINI_SCREEN_NORMAL_FLAG:
159 	    update_main_screen_normal (full_refresh);
160 	    break;
161 	case MINI_SCREEN_POL_FLAG:
162 	    update_main_screen_pollution ();
163 	    break;
164 	case MINI_SCREEN_UB40_FLAG:
165 	    update_main_screen_ub40 ();
166 	    break;
167 	case MINI_SCREEN_STARVE_FLAG:
168 	    update_main_screen_starve ();
169 	    break;
170 	case MINI_SCREEN_POWER_FLAG:
171 	    update_main_screen_power ();
172 	    break;
173 	case MINI_SCREEN_FIRE_COVER:
174 	    update_main_screen_fire_cover ();
175 	    break;
176 	case MINI_SCREEN_CRICKET_COVER:
177 	    update_main_screen_cricket_cover ();
178 	    break;
179 	case MINI_SCREEN_HEALTH_COVER:
180 	    update_main_screen_health_cover ();
181 	    break;
182 	case MINI_SCREEN_COAL_FLAG:
183 	    if (coal_survey_done) {
184 		update_main_screen_coal ();
185 	    } else {
186 		update_main_screen_normal (full_refresh);
187 	    }
188 	    break;
189 	}
190     }
191 #if defined (WIN32)
192     /* GCS -- I have a feeling this is wrong ... */
193     if (full_refresh) {
194 	UpdateWindow (display.hWnd);
195     }
196 #else
197     if (mouse_type == MOUSE_TYPE_SQUARE)
198 	redraw_mouse ();
199 #endif
200 }
201 
202 void
update_main_screen_normal(int full_refresh)203 update_main_screen_normal (int full_refresh)
204 {
205     Rect* mw = &scr.main_win;
206     int x, y, xm, ym;
207     short typ, grp;
208 #ifdef USE_PIXMAPS
209     int sx, sy, dx, dy, x1, y1;
210 #endif
211     /*  main_screen_origin[x|y] contain the mappoint of the top left of win */
212 #ifdef DEBUG_MAIN_SCREEN
213     printf ("Updating main screen\n");
214 #endif
215     if (help_flag || load_flag || save_flag)
216 	return;
217 
218     /* GCS: I moved the code to reset the main_screen_origin to the
219        function load_city(), where I think is more appropriate. */
220 
221     xm = main_screen_originx;
222     if (xm > 3)
223 	xm = 3;
224     ym = main_screen_originy;
225     if (ym > 3)
226 	ym = 3;
227 #if !defined (WIN32)		/* For speed */
228     if (mouse_type == MOUSE_TYPE_SQUARE)
229 	hide_mouse ();
230 #endif
231     clip_main_window ();
232     for (y = main_screen_originy - ym; y < main_screen_originy
233 		 + (mw->h / 16); y++)
234 	for (x = main_screen_originx - xm; x < main_screen_originx
235 		     + (mw->w / 16); x++)
236 	{
237 	    typ = MP_TYPE(x,y);
238 	    if (typ != mappointoldtype[x][y] || full_refresh)
239 	    {
240 		mappointoldtype[x][y] = typ;
241 		if (typ == CST_USED) {
242 		    continue;
243 		}
244 		grp = get_group_of_type(typ);
245 #ifdef USE_PIXMAPS
246 		if (icon_pixmap[typ] != 0)
247 		{
248 		    x1 = y1 = 0;
249 		    if (x < main_screen_originx)
250 			x1 = (main_screen_originx - x) * 16;
251 		    if (y < main_screen_originy)
252 			y1 = (main_screen_originy - y) * 16;
253 		    sx = sy = main_groups[grp].size;
254 		    if ((sx + x) > (main_screen_originx + (mw->w / 16)))
255 			sx = (main_screen_originx + (mw->w / 16)) - x;
256 		    if ((sy + y) > (main_screen_originy + (mw->h / 16)))
257 			sy = (main_screen_originy + (mw->h / 16)) - y;
258 		    sx = (sx << 4) - x1;
259 		    sy = (sy << 4) - y1;
260 		    dx = mw->x + (x - main_screen_originx) * 16 + x1;
261 		    dy = mw->y + (y - main_screen_originy) * 16 + y1;
262 		    if (sx > 0 && sy > 0)
263 		    {
264 #if defined (LC_X11)
265 #ifdef ALLOW_PIX_DOUBLING
266 			if (pix_double)
267 			    XCopyArea (display.dpy
268 				       ,icon_pixmap[typ]
269 				       ,display.win
270 				       ,display.pixcolour_gc[0]
271 				       ,x1 * 2, y1 * 2, sx * 2, sy * 2
272 				       ,dx * 2, dy * 2);
273 			else
274 #endif /* ALLOW_PIX_DOUBLING */
275 			    XCopyArea (display.dpy
276 				       ,icon_pixmap[typ]
277 				       ,display.win
278 				       ,display.pixcolour_gc[0]
279 				       ,x1, y1, sx, sy
280 				       ,dx + borderx, dy + bordery);
281 #elif defined (WIN32)
282 			CopyPixmapToScreen (typ, x1, y1, sx, sy, dx, dy);
283 #endif /* LC_X11 or WIN32 */
284 			update_pixmap (x1, y1, sx, sy, dx, dy,
285 				       main_groups[grp].size,
286 				       main_types[typ].graphic);
287 
288 		    }
289 		}
290 		else
291 #endif /* USE_PIXMAPS */
292 		    Fgl_putbox (mw->x + (x - main_screen_originx) * 16,
293 				mw->y + (y - main_screen_originy) * 16,
294 				16 * main_groups[grp].size,
295 				16 * main_groups[grp].size,
296 				main_types[typ].graphic);
297 	    }
298 	}
299     unclip_main_window ();
300 }
301 
302 void
update_main_screen_pollution(void)303 update_main_screen_pollution (void)
304 {
305     Rect* mw = &scr.main_win;
306     int x, y, col;
307 
308     for (y = main_screen_originy;
309 	 y < main_screen_originy + (mw->h / 16); y++) {
310 	for (x = main_screen_originx;
311 	     x < main_screen_originx + (mw->w / 16); x++) {
312 	    if (MP_POL(x,y) < 4) {
313 		col = green (24);
314 	    } else if (MP_POL(x,y) < 600) {
315 		col = green (23 - (MP_POL(x,y) / 45));
316 	    } else {
317 		col = (int) sqrt ((float) (MP_POL(x,y) - 600)) / 9;
318 		if (col > 20)
319 		    col = 20;
320 		col += red (11);
321 	    }
322 	    Fgl_fillbox (mw->x + (x - main_screen_originx) * 16,
323 			 mw->y + (y - main_screen_originy) * 16,
324 			 16, 16, col);
325 	}
326     }
327 }
328 
329 void
update_main_screen_ub40(void)330 update_main_screen_ub40 (void)
331 {
332     Rect* mw = &scr.main_win;
333     int x, y, col;
334 
335     for (y = main_screen_originy;
336 	 y < main_screen_originy + (mw->h / 16); y++) {
337 	for (x = main_screen_originx;
338 	     x < main_screen_originx + (mw->w / 16); x++) {
339 	    int xx = x;
340 	    int yy = y;
341 	    if (MP_TYPE(x,y) == CST_USED) {
342 		xx = MP_INFO(x,y).int_1;
343 		yy = MP_INFO(x,y).int_2;
344 	    }
345 	    if (MP_GROUP_IS_RESIDENCE(xx,yy)) {
346 		if (MP_INFO(xx,yy).int_1 < -20)
347 		    col = red (28);
348 		else if (MP_INFO(xx,yy).int_1 < 10)
349 		    col = red (14);
350 		else
351 		    col = green (20);
352 	    } else {
353 		col = green (14);
354 	    }
355 	    Fgl_fillbox (mw->x + (x - main_screen_originx) * 16,
356 			 mw->y + (y - main_screen_originy) * 16,
357 			 16, 16, col);
358 	}
359     }
360 }
361 
362 void
update_main_screen_starve(void)363 update_main_screen_starve (void)
364 {
365     Rect* mw = &scr.main_win;
366     int x, y, col;
367 
368     for (y = main_screen_originy;
369 	 y < main_screen_originy + (mw->h / 16); y++) {
370 	for (x = main_screen_originx;
371 	     x < main_screen_originx + (mw->w / 16); x++) {
372 	    int xx = x;
373 	    int yy = y;
374 	    if (MP_TYPE(x,y) == CST_USED) {
375 		xx = MP_INFO(x,y).int_1;
376 		yy = MP_INFO(x,y).int_2;
377 	    }
378 	    if (MP_GROUP_IS_RESIDENCE(xx,yy)) {
379 		if ((total_time - MP_INFO(x,y).int_2) < 20)
380 		    col = red (28);
381 		else if ((total_time - MP_INFO(x,y).int_2) < 100)
382 		    col = red (14);
383 		else
384 		    col = green (20);
385 	    } else {
386 		col = green (14);
387 	    }
388 	    Fgl_fillbox (mw->x + (x - main_screen_originx) * 16,
389 			 mw->y + (y - main_screen_originy) * 16,
390 			 16, 16, col);
391 	}
392     }
393 }
394 
395 void
update_main_screen_power(void)396 update_main_screen_power (void)
397 {
398     Rect* mw = &scr.main_win;
399     int x, y, col;
400 
401     for (y = main_screen_originy;
402 	 y < main_screen_originy + (mw->h / 16); y++) {
403 	for (x = main_screen_originx;
404 	     x < main_screen_originx + (mw->w / 16); x++) {
405 	    int xx = x;
406 	    int yy = y;
407 	    if (MP_TYPE(x,y) == CST_USED) {
408 		xx = MP_INFO(x,y).int_1;
409 		yy = MP_INFO(x,y).int_2;
410 	    }
411 	    if (get_power (xx, yy, 1, 1) != 0) {
412 		col = green (14);
413 	    } else if (get_power (xx, yy, 1, 0) != 0) {
414 		col = green (10);
415 	    } else {
416 		// col = MP_COLOR(xx,yy);
417 		col = green (20);
418 	    }
419 	    Fgl_fillbox (mw->x + (x - main_screen_originx) * 16,
420 			 mw->y + (y - main_screen_originy) * 16,
421 			 16, 16, col);
422 	}
423     }
424 }
425 
426 void
update_main_screen_fire_cover(void)427 update_main_screen_fire_cover (void)
428 {
429     Rect* mw = &scr.main_win;
430     int x, y, col;
431 
432     for (y = main_screen_originy;
433 	 y < main_screen_originy + (mw->h / 16); y++) {
434 	for (x = main_screen_originx;
435 	     x < main_screen_originx + (mw->w / 16); x++) {
436 	    int xx = x;
437 	    int yy = y;
438 	    if (MP_TYPE(x,y) == CST_USED) {
439 		xx = MP_INFO(x,y).int_1;
440 		yy = MP_INFO(x,y).int_2;
441 	    }
442 
443 	    if ((MP_INFO(xx,yy).flags & FLAG_FIRE_COVER) == 0)
444 		// col = MP_COLOR(xx,yy);
445 		col = green (20);
446 	    else
447 		col = green (10);
448 	    Fgl_fillbox (mw->x + (x - main_screen_originx) * 16,
449 			 mw->y + (y - main_screen_originy) * 16,
450 			 16, 16, col);
451 	}
452     }
453 }
454 
455 void
update_main_screen_health_cover(void)456 update_main_screen_health_cover (void)
457 {
458     Rect* mw = &scr.main_win;
459     int x, y, col;
460 
461     for (y = main_screen_originy;
462 	 y < main_screen_originy + (mw->h / 16); y++) {
463 	for (x = main_screen_originx;
464 	     x < main_screen_originx + (mw->w / 16); x++) {
465 	    int xx = x;
466 	    int yy = y;
467 	    if (MP_TYPE(x,y) == CST_USED) {
468 		xx = MP_INFO(x,y).int_1;
469 		yy = MP_INFO(x,y).int_2;
470 	    }
471 	    if ((MP_INFO(xx,yy).flags & FLAG_HEALTH_COVER) == 0)
472 		// col = MP_COLOR(xx,yy);
473 		col = green (20);
474 	    else
475 		col = green (10);
476 	    Fgl_fillbox (mw->x + (x - main_screen_originx) * 16,
477 			 mw->y + (y - main_screen_originy) * 16,
478 			 16, 16, col);
479 	}
480     }
481 }
482 
483 void
update_main_screen_cricket_cover(void)484 update_main_screen_cricket_cover (void)
485 {
486     Rect* mw = &scr.main_win;
487     int x, y, col;
488 
489     for (y = main_screen_originy;
490 	 y < main_screen_originy + (mw->h / 16); y++) {
491 	for (x = main_screen_originx;
492 	     x < main_screen_originx + (mw->w / 16); x++) {
493 	    int xx = x;
494 	    int yy = y;
495 	    if (MP_TYPE(x,y) == CST_USED) {
496 		xx = MP_INFO(x,y).int_1;
497 		yy = MP_INFO(x,y).int_2;
498 	    }
499 	    if ((MP_INFO(xx,yy).flags & FLAG_CRICKET_COVER) == 0)
500 		// col = MP_COLOR(xx,yy);
501 		col = green (20);
502 	    else
503 		col = green (10);
504 	    Fgl_fillbox (mw->x + (x - main_screen_originx) * 16,
505 			 mw->y + (y - main_screen_originy) * 16,
506 			 16, 16, col);
507 	}
508     }
509 }
510 
511 void
update_main_screen_coal(void)512 update_main_screen_coal (void)
513 {
514     Rect* mw = &scr.main_win;
515     int x, y, col;
516 
517     for (y = main_screen_originy;
518 	 y < main_screen_originy + (mw->h / 16); y++) {
519 	for (x = main_screen_originx;
520 	     x < main_screen_originx + (mw->w / 16); x++) {
521 	    if (MP_INFO(x,y).coal_reserve == 0)
522 		col = white (4);
523 	    else if (MP_INFO(x,y).coal_reserve >= COAL_RESERVE_SIZE / 2)
524 		col = white (18);
525 	    else if (MP_INFO(x,y).coal_reserve < COAL_RESERVE_SIZE / 2)
526 		col = white (28);
527 	    Fgl_fillbox (mw->x + (x - main_screen_originx) * 16,
528 			 mw->y + (y - main_screen_originy) * 16,
529 			 16, 16, col);
530 	}
531     }
532 }
533 
534 
535 /* *******************  SCREEN SETUP  ******************* */
536 
537 /* XXX: WCK: All of the drawing should be done already in screen_full_refresh;
538    Why do it here? */
539 /* GCS: Actually, this function loads the graphics from disk */
540 /* WCK: Yes, but it used to refresh everything after doing that. */
541 void
screen_setup(void)542 screen_setup (void)
543 {
544     /* draw the graph boxes */
545     monthgraph_full_refresh ();
546     monthgraph_style_timeout = real_time + 10000;
547     mps_redraw ();
548     mps_global_style_timeout = real_time + 10000;
549 
550     /* load the pbar graphics */
551     /* XXX: WCK: pbar_setup? */
552     up_pbar1_graphic = load_graphic ("pbarup1.csi");
553     up_pbar2_graphic = load_graphic ("pbarup2.csi");
554     down_pbar1_graphic = load_graphic ("pbardown1.csi");
555     down_pbar2_graphic = load_graphic ("pbardown2.csi");
556     pop_pbar_graphic = load_graphic ("pbarpop.csi");
557     tech_pbar_graphic = load_graphic ("pbartech.csi");
558     food_pbar_graphic = load_graphic ("pbarfood.csi");
559     jobs_pbar_graphic = load_graphic ("pbarjobs.csi");
560     coal_pbar_graphic = load_graphic ("pbarcoal.csi");
561     goods_pbar_graphic = load_graphic ("pbargoods.csi");
562     ore_pbar_graphic = load_graphic ("pbarore.csi");
563     steel_pbar_graphic = load_graphic ("pbarsteel.csi");
564     money_pbar_graphic = load_graphic ("pbarmoney.csi");
565     init_pbars ();
566 
567     /* draw the box around the main window */
568     draw_main_window_box (green (8));
569     /* load the checked and unchecked box graphics */
570     checked_box_graphic = load_graphic ("checked_box.csi");
571     unchecked_box_graphic = load_graphic ("unchecked_box.csi");
572 
573     /* load minimap buttons (but don't draw) */
574     ms_normal_button_graphic = load_graphic ("ms-normal-button.csi");
575     ms_pollution_button_graphic = load_graphic ("ms-pollution-button.csi");
576     ms_fire_cover_button_graphic = load_graphic ("ms-fire-cover-button.csi");
577     ms_health_cover_button_graphic
578 	    = load_graphic ("ms-health-cover-button.csi");
579     ms_cricket_cover_button_graphic
580 	    = load_graphic ("ms-cricket-cover-button.csi");
581     ms_ub40_button_graphic = load_graphic ("ms-ub40-button.csi");
582     ms_coal_button_graphic = load_graphic ("ms-coal-button.csi");
583     ms_starve_button_graphic = load_graphic ("ms-starve-button.csi");
584     ms_power_button_graphic = load_graphic ("ms-power-button.csi");
585     ms_ocost_button_graphic = load_graphic ("ms-ocost-button.csi");
586 
587     /* draw the pause button */
588     pause_button1_off = load_graphic ("pause-offl.csi");
589     pause_button2_off = load_graphic ("pause-offr.csi");
590     pause_button1_on = load_graphic ("pause-onl.csi");
591     pause_button2_on = load_graphic ("pause-onr.csi");
592     draw_pause (0);
593 
594     /* draw the slow button */
595     slow_button1_off = load_graphic ("slow-offl.csi");
596     slow_button2_off = load_graphic ("slow-offr.csi");
597     slow_button1_on = load_graphic ("slow-onl.csi");
598     slow_button2_on = load_graphic ("slow-onr.csi");
599     draw_slow (0);
600 
601     /* draw the medium button */
602     med_button1_off = load_graphic ("norm-offl.csi");
603     med_button2_off = load_graphic ("norm-offr.csi");
604     med_button1_on = load_graphic ("norm-onl.csi");
605     med_button2_on = load_graphic ("norm-onr.csi");
606     draw_med (0);
607 
608     /* draw the fast button */
609     fast_button1_off = load_graphic ("fast-offl.csi");
610     fast_button2_off = load_graphic ("fast-offr.csi");
611     fast_button1_on = load_graphic ("fast-onl.csi");
612     fast_button2_on = load_graphic ("fast-onr.csi");
613     draw_fast (0);
614 
615     /* draw the results button */
616     results_button1 = load_graphic ("results-l.csi");
617     results_button2 = load_graphic ("results-r.csi");
618     draw_results ();
619 
620     /* draw the t-overwrite button and load 'on button' */
621 #if defined (commentout)
622     toveron_button1 = load_graphic ("tover1-on.csi");
623     toveroff_button1 = load_graphic ("tover1-off.csi");
624     toveron_button2 = load_graphic ("tover2-on.csi");
625     toveroff_button2 = load_graphic ("tover2-off.csi");
626     draw_tover (0);
627 
628 #ifdef LC_X11
629     /* draw the confine mouse button */
630     confine_button = load_graphic ("mouse-confined.csi");
631     unconfine_button = load_graphic ("mouse-free.csi");
632     draw_confine (0);
633 #endif
634 #endif
635 
636     /* Load and draw menu buttons */
637 #if defined (commentout)
638     menu_button_graphic = load_graphic ("menu-button.csi");
639 #endif
640     draw_menu ();
641     draw_help ();
642 #if defined (commentout)
643     load_button_graphic = load_graphic ("load-button.csi");
644     draw_load ();
645     save_button_graphic = load_graphic ("save-button.csi");
646     draw_save ();
647     quit_button_graphic = load_graphic ("quit-button.csi");
648     draw_quit ();
649     help_button_graphic = load_graphic ("help-button.csi");
650     draw_help ();
651 #endif
652 
653     /* GCS moved selection to here */
654     set_selected_module (CST_TRACK_LR);
655 
656 #ifdef SCREEN_SETUP_DRAWS
657     mini_full_refresh ();
658 
659     redraw_mouse ();
660 
661     update_main_screen ();
662 #endif
663 
664 }
665 
666 void
screen_full_refresh(void)667 screen_full_refresh (void)
668 {
669     screen_refreshing++;
670     draw_background ();
671 
672     monthgraph_full_refresh ();
673     mps_redraw ();
674     pbars_full_refresh ();
675     mini_full_refresh ();
676 
677     /* GCS FIX: what about during MT? */
678     if (selected_module_type == CST_GREEN)
679 	draw_main_window_box (red (8));
680     else
681 	draw_main_window_box (green (8));
682 
683     draw_menu ();
684     draw_help ();
685 #if defined (commentout)
686     draw_load ();
687     draw_save ();
688     draw_quit ();
689     draw_help ();
690 #endif
691     draw_pause (pause_flag);
692     draw_slow (slow_flag & !pause_flag);
693     draw_med (med_flag & !pause_flag);
694     draw_fast (fast_flag & !pause_flag);
695     draw_results ();
696 
697     draw_modules ();
698 
699     /* GCS:  What about resize during load/save/prefs? */
700     /* WCK:  We could just lock resize off when we enter them. */
701     if (help_flag) {
702 	refresh_help_page ();
703     }
704     refresh_main_screen ();
705 
706 /*  Text status area */
707     print_date();
708     print_time_for_year();
709     print_total_money();
710     draw_selected_module_cost();
711 
712     refresh_pbars();
713     redraw_mouse();  /* screen_setup used to do this */
714     screen_refreshing--;
715 }
716 
717 #if defined (commentout)
718 void
draw_ms_buttons(void)719 draw_ms_buttons (void)
720 {
721     draw_ms_button (&scr.ms_normal_button, ms_normal_button_graphic);
722     draw_ms_button (&scr.ms_pollution_button, ms_pollution_button_graphic);
723     draw_ms_button (&scr.ms_fire_cover_button, ms_fire_cover_button_graphic);
724     draw_ms_button (&scr.ms_health_cover_button,
725 		    ms_health_cover_button_graphic);
726     draw_ms_button (&scr.ms_cricket_cover_button,
727 		    ms_cricket_cover_button_graphic);
728     draw_ms_button (&scr.ms_ub40_button, ms_ub40_button_graphic);
729     draw_ms_button (&scr.ms_coal_button, ms_coal_button_graphic);
730     draw_ms_button (&scr.ms_starve_button, ms_starve_button_graphic);
731     draw_ms_button (&scr.ms_power_button, ms_power_button_graphic);
732     draw_ms_button (&scr.ms_ocost_button, ms_ocost_button_graphic);
733 }
734 #endif
735 
736 void
draw_main_window_box(int colour)737 draw_main_window_box (int colour)
738 {
739     Rect* b = &scr.main_win;
740     int x;
741     for (x = 0; x < 8; x++)
742     {
743 	Fgl_hline (b->x - 1 - x, b->y - 1 - x,
744 		   b->x + b->w + x, colour + x + x);
745 	Fgl_hline (b->x - 1 - x, b->y + b->h + x,
746 		   b->x + b->w + x, colour + x + x);
747 	Fgl_line (b->x - 1 - x, b->y - x, b->x - 1 - x,
748 		  b->y + b->h + x, colour + x + x);
749 	Fgl_line (b->x + b->w + x, b->y - x,
750 		  b->x + b->w + x, b->y + b->h + x,
751 		  colour + x + x);
752     }
753 }
754 
755 void
draw_yellow_bezel(int x,int y,int h,int w)756 draw_yellow_bezel (int x, int y, int h, int w)
757 {
758     int i;
759     for (i = 1; i < 8; i++) {
760 	Fgl_hline (x - 1 - i, y - 1 - i, x + w + 1 + i, yellow (16));
761 	Fgl_line (x - 1 - i, y - 1 - i, x - 1 - i, y + h + 1 + i, yellow (14));
762 	Fgl_hline (x - 1 - i, y + h + 1 + i, x + w + 1 + i, yellow (22));
763 	Fgl_line (x + w + 1 + i, y - 1 - i, x + w + 1 + i, y + h + 1 + i,
764 		  yellow (24));
765     }
766 }
767 
768 void
draw_small_yellow_bezel(int x,int y,int h,int w)769 draw_small_yellow_bezel (int x, int y, int h, int w)
770 {
771 #if defined (commentout)
772     int i;
773     for (i = 1; i < 4; i++) {
774 	Fgl_hline (x - 1 - i, y - 1 - i, x + w + 1 + i, yellow (16));
775 	Fgl_line (x - 1 - i, y - 1 - i, x - 1 - i, y + h + 1 + i, yellow (14));
776 	Fgl_hline (x - 1 - i, y + h + 1 + i, x + w + 1 + i, yellow (22));
777 	Fgl_line (x + w + 1 + i, y - 1 - i, x + w + 1 + i, y + h + 1 + i,
778 		  yellow (24));
779     }
780 #endif
781     int i;
782     for (i = 1; i < 4; i++) {
783 	Fgl_hline (x - 1 - i, y - 1 - i, x + w + i, yellow (16));
784 	Fgl_line (x - 1 - i, y - 1 - i, x - 1 - i, y + h + i, yellow (14));
785 	Fgl_hline (x - 1 - i, y + h + i, x + w + i, yellow (22));
786 	Fgl_line (x + w + i, y - 1 - i, x + w + i, y + h + i,
787 		  yellow (24));
788     }
789 }
790 
791 void
load_fonts()792 load_fonts()
793 {
794     char s[LC_PATH_MAX];
795     int i;
796     FILE *inf;
797     /* main_font */
798     if ((inf = fopen (fontfile, "r")) == 0)
799 	HandleError ("Can't open the font file", FATAL);
800     for (i = 0; i < 256 * 8; i++)
801 	main_font[i] = fgetc (inf);
802     fclose (inf);
803     /* start_font1 */
804     sprintf (s, "%s%c%s", opening_path, PATH_SLASH, "8x8thin");
805     if ((inf = fopen (s, "rb")) == NULL)
806 	do_error ("Can't open opening screen font 8x8thin");
807     for (i = 0; i < 2048; i++)
808 	start_font1[i] = fgetc (inf);
809     fclose (inf);
810     /* start_font2 */
811     sprintf (s, "%s%c%s", opening_path, PATH_SLASH, "scrawl_w.fnt");
812     if ((inf = fopen (s, "rb")) == NULL)
813 	do_error ("Can't open opening screen font scrawl_w.fnt");
814     for (i = 0; i < 4096; i++)
815 	start_font2[i] = fgetc (inf);
816     fclose (inf);
817     /* start_font3 */
818     sprintf (s, "%s%c%s", opening_path, PATH_SLASH, "scrawl_s.fnt");
819     if ((inf = fopen (s, "rb")) == NULL)
820 	do_error ("Can't open opening screen font scrawl_s.fnt");
821     for (i = 0; i < 4096; i++)
822 	start_font3[i] = fgetc (inf);
823     fclose (inf);
824 }
825 
826 void
init_fonts(void)827 init_fonts (void)
828 {
829 #if defined (WIN32)
830     init_windows_font();
831 #endif
832     load_fonts();
833 #if defined (SVGALIB)
834     gl_setwritemode (FONT_COMPRESSED);
835 #endif
836     Fgl_setfont (8, 8, main_font);
837     Fgl_setfontcolors (TEXT_BG_COLOUR, TEXT_FG_COLOUR);
838 }
839 
840 /* Miniscreen mouse handlers */
841 
842 static Mouse_Handle * mini_map_handle;
843 static Mouse_Handle * mini_aux_handle;
844 
845 void
init_mini_map_mouse(void)846 init_mini_map_mouse (void)
847 {
848     mini_map_handle = mouse_register(&scr.mini_map,&mini_map_handler);
849     mini_aux_handle = mouse_register(&scr.mini_map_aux,&mini_aux_handler);
850 }
851 
852 
853 void
mini_map_handler(int x,int y,int button)854 mini_map_handler(int x, int y, int button)
855 {
856     if (button == LC_MOUSE_RIGHTBUTTON) {
857 	mini_screen_help ();
858 	return;
859     }
860     if (mini_screen_flags == MINI_SCREEN_COAL_FLAG && !coal_survey_done) {
861 	if (yn_dial_box (_("Coal survey"),
862 			 _("This will cost you 1 million"),
863 			 _("After that it's is free to call again"),
864 			 _("Do coal survey?")) == 0)
865 	{
866 	    return;
867 	}
868 	do_coal_survey ();
869 	print_total_money ();
870 	return;
871     }
872     adjust_main_origin (x - scr.main_win.w / 32,
873 			y - scr.main_win.h / 32, 1);
874 
875     if (mini_screen_flags == MINI_SCREEN_PORT_FLAG)
876 	draw_mini_screen ();
877 }
878 
879 void
mini_aux_handler(int x,int y,int button)880 mini_aux_handler(int x, int y, int button)
881 {
882     if (button == LC_MOUSE_MIDDLEBUTTON) {
883 	rotate_main_screen ();
884 	return;
885     } else if (button == LC_MOUSE_RIGHTBUTTON) {
886 	mini_screen_help ();
887 	return;
888     }
889     rotate_mini_screen ();
890 }
891 
892 void
rotate_mini_screen(void)893 rotate_mini_screen (void)
894 {
895     switch (mini_screen_flags)
896     {
897     case MINI_SCREEN_NORMAL_FLAG:
898 	mini_screen_flags = MINI_SCREEN_POL_FLAG;
899 	break;
900     case MINI_SCREEN_POL_FLAG:
901 	mini_screen_flags = MINI_SCREEN_UB40_FLAG;
902 	break;
903     case MINI_SCREEN_UB40_FLAG:
904 	mini_screen_flags = MINI_SCREEN_STARVE_FLAG;
905 	break;
906     case MINI_SCREEN_STARVE_FLAG:
907 	mini_screen_flags = MINI_SCREEN_POWER_FLAG;
908 	break;
909 #if defined (commentout)
910     case MINI_SCREEN_PORT_FLAG:
911 	/* Not in the rotation schedule */
912 #endif
913     case MINI_SCREEN_POWER_FLAG:
914 	mini_screen_flags = MINI_SCREEN_FIRE_COVER;
915 	break;
916     case MINI_SCREEN_FIRE_COVER:
917 	mini_screen_flags = MINI_SCREEN_CRICKET_COVER;
918 	break;
919     case MINI_SCREEN_CRICKET_COVER:
920 	mini_screen_flags = MINI_SCREEN_HEALTH_COVER;
921 	break;
922     case MINI_SCREEN_HEALTH_COVER:
923 	mini_screen_flags = MINI_SCREEN_COAL_FLAG;
924 	break;
925     case MINI_SCREEN_COAL_FLAG:
926 	mini_screen_flags = MINI_SCREEN_NORMAL_FLAG;
927 	break;
928     }
929     update_mini_screen ();
930 
931     if (main_screen_flag == MAIN_SCREEN_EQUALS_MINI) {
932 	refresh_main_screen ();
933     }
934 }
935 
936 void
update_mini_screen(void)937 update_mini_screen (void)
938 {
939     switch (mini_screen_flags)
940     {
941     case MINI_SCREEN_NORMAL_FLAG:
942 	draw_mini_screen ();
943 	break;
944     case MINI_SCREEN_POL_FLAG:
945 	draw_mini_screen_pollution ();
946 	break;
947     case MINI_SCREEN_UB40_FLAG:
948 	draw_mini_screen_ub40 ();
949 	break;
950     case MINI_SCREEN_STARVE_FLAG:
951 	draw_mini_screen_starve ();
952 	break;
953 #if defined (commentout)
954     case MINI_SCREEN_PORT_FLAG:
955 	draw_mini_screen_port ();
956 	break;
957 #endif
958     case MINI_SCREEN_POWER_FLAG:
959 	draw_mini_screen_power ();
960 	break;
961     case MINI_SCREEN_FIRE_COVER:
962 	draw_mini_screen_fire_cover ();
963 	break;
964     case MINI_SCREEN_CRICKET_COVER:
965 	draw_mini_screen_cricket_cover ();
966 	break;
967     case MINI_SCREEN_HEALTH_COVER:
968 	draw_mini_screen_health_cover ();
969 	break;
970     case MINI_SCREEN_COAL_FLAG:
971 	draw_mini_screen_coal ();
972 	break;
973     }
974 }
975 
976 void
mini_screen_help(void)977 mini_screen_help (void)
978 {
979     switch (mini_screen_flags)
980     {
981     case MINI_SCREEN_NORMAL_FLAG:
982 	activate_help ("msb-normal.hlp");
983 	break;
984     case MINI_SCREEN_POL_FLAG:
985 	activate_help ("msb-pol.hlp");
986 	break;
987     case MINI_SCREEN_UB40_FLAG:
988 	activate_help ("msb-ub40.hlp");
989 	break;
990     case MINI_SCREEN_STARVE_FLAG:
991 	activate_help ("msb-starve.hlp");
992 	break;
993     case MINI_SCREEN_POWER_FLAG:
994 	activate_help ("msb-power.hlp");
995 	break;
996     case MINI_SCREEN_FIRE_COVER:
997 	activate_help ("msb-fire.hlp");
998 	break;
999     case MINI_SCREEN_CRICKET_COVER:
1000 	activate_help ("msb-cricket.hlp");
1001 	break;
1002     case MINI_SCREEN_HEALTH_COVER:
1003 	activate_help ("msb-health.hlp");
1004 	break;
1005     case MINI_SCREEN_COAL_FLAG:
1006 	activate_help ("msb-coal.hlp");
1007 	break;
1008     }
1009 }
1010 
1011 void
mini_full_refresh(void)1012 mini_full_refresh (void)
1013 {
1014     Rect* mm = &scr.mini_map;
1015     Rect* mmaux = &scr.mini_map_aux;
1016     Rect* mmarea = &scr.mini_map_area;
1017 
1018     /* draw border around mini screen */
1019     draw_small_yellow_bezel (mmarea->x, mmarea->y, mmarea->h, mmarea->w);
1020     /* draw line between mini_map and mini_map_aux */
1021     Fgl_hline (mmaux->x, mmaux->y + mmaux->h, mmaux->x + mmaux->w,
1022 	       yellow (16));
1023     Fgl_hline (mmaux->x, mmaux->y + mmaux->h + 1, mmaux->x + mmaux->w,
1024 	       yellow (16));
1025     /* Black out area l/r of mini_map w/in mini_map_area */
1026     Fgl_fillbox (mmarea->x, mm->y, mm->x - mmarea->x, mm->h,
1027 		 GRAPHS_B_COLOUR);
1028     Fgl_fillbox (mm->x + mm->w, mm->y, mmarea->x + mmarea->w - mm->x - mm->w,
1029 		 mm->h, GRAPHS_B_COLOUR);
1030 
1031     /* now draw the mini_screen contents */
1032     draw_mini_screen ();
1033 }
1034 
1035 void
draw_mini_screen(void)1036 draw_mini_screen (void)
1037 {
1038     int x, y, xx, yy;
1039     Rect* mm = &scr.mini_map;
1040 
1041     mini_screen_flags = MINI_SCREEN_NORMAL_FLAG;
1042     draw_ms_button (ms_normal_button_graphic);
1043     draw_ms_text (_("Land Use    "));
1044     for (y = 0; y < WORLD_SIDE_LEN; y++) {
1045 	for (x = 0; x < WORLD_SIDE_LEN; x++) {
1046 	    if (MP_TYPE(x,y) == CST_USED) {
1047 		xx = MP_INFO(x,y).int_1;
1048 		yy = MP_INFO(x,y).int_2;
1049 
1050 		/* WCK: I think this is what is blowing up */
1051 		if ((xx < 0 || xx > WORLD_SIDE_LEN) ||
1052 		    (yy < 0 || yy > WORLD_SIDE_LEN)) {
1053 		  printf("Argh!  mini_screen out of range on CST_USED!\n");
1054 		  printf("xx=%d,yy=%d.  Continuing\n",xx,yy);
1055 		}
1056 
1057 		Fgl_setpixel (mm->x + x, mm->y + y, main_groups[MP_GROUP(xx,yy)].colour);
1058 	    } else {
1059 		Fgl_setpixel (mm->x + x, mm->y + y,  main_groups[MP_GROUP(x,y)].colour);
1060 	    }
1061 	}
1062     }
1063     draw_mini_screen_cursor ();
1064 
1065 #if defined (WIN32)
1066     RefreshArea (mm->x, mm->y, mm->x + x, mm->y + y);
1067 #endif
1068 }
1069 
1070 void
draw_big_mini_screen(void)1071 draw_big_mini_screen (void)
1072 {
1073     Rect* b = &scr.main_win;
1074     int x, y, xx, yy;
1075     for (y = 0; y < WORLD_SIDE_LEN; y++) {
1076 	for (x = 0; x < WORLD_SIDE_LEN; x++) {
1077 	    if (MP_TYPE(x,y) == CST_USED) {
1078 		xx = MP_INFO(x,y).int_1;
1079 		yy = MP_INFO(x,y).int_2;
1080 		Fgl_fillbox (b->x + x * 4, b->y + y * 4, 4, 4
1081 			     ,main_groups[MP_GROUP(xx,yy)].colour);
1082 	    } else {
1083 		Fgl_fillbox (b->x + x * 4, b->y + y * 4, 4, 4
1084 			     ,main_groups[MP_GROUP(x,y)].colour);
1085 	    }
1086 	}
1087     }
1088 }
1089 
1090 
1091 void
draw_mini_screen_pollution(void)1092 draw_mini_screen_pollution (void)
1093 {
1094     int x, y, col;
1095     Rect* mm = &scr.mini_map;
1096 
1097     mini_screen_flags = MINI_SCREEN_POL_FLAG;
1098     draw_ms_text (_("Pollution   "));
1099     draw_ms_button (ms_pollution_button_graphic);
1100     for (y = 0; y < WORLD_SIDE_LEN; y++) {
1101 	for (x = 0; x < WORLD_SIDE_LEN; x++) {
1102 	    if (MP_POL(x,y) < 4) {
1103 		col = green (24);
1104 	    } else if (MP_POL(x,y) < 600) {
1105 		col = green (23 - (MP_POL(x,y) / 45));
1106 	    } else {
1107 		col = (int) sqrt ((float) (MP_POL(x,y) - 600)) / 9;
1108 		if (col > 20)
1109 		    col = 20;
1110 		col += red (11);
1111 	    }
1112 	    Fgl_setpixel (mm->x + x, mm->y + y, col);
1113 	}
1114     }
1115     draw_mini_screen_cursor ();
1116 #if defined (WIN32)
1117     RefreshArea (mm->x, mm->y, mm->x + x, mm->y + y);
1118 #endif
1119 }
1120 
1121 void
draw_mini_screen_fire_cover(void)1122 draw_mini_screen_fire_cover (void)
1123 {
1124     int x, y, xx, yy, col;
1125     Rect* mm = &scr.mini_map;
1126 
1127     /* GCS: This sort of works.  Might be better to return to "normal"
1128        when user clicks on mini-screen, or else draw outline box. */
1129     mini_screen_flags = MINI_SCREEN_FIRE_COVER;
1130     draw_ms_text (_("Fire cover  "));
1131     draw_ms_button (ms_fire_cover_button_graphic);
1132     for (y = 0; y < WORLD_SIDE_LEN; y++) {
1133 	for (x = 0; x < WORLD_SIDE_LEN; x++) {
1134 	    if (MP_TYPE(x,y) == CST_USED)
1135 	    {
1136 		xx = MP_INFO(x,y).int_1;
1137 		yy = MP_INFO(x,y).int_2;
1138 		if ((MP_INFO(xx,yy).flags & FLAG_FIRE_COVER) == 0)
1139 		    col = main_groups[MP_GROUP(xx,yy)].colour;
1140 		else
1141 		    col = green (10);
1142 	    }
1143 	    else
1144 	    {
1145 		if ((MP_INFO(x,y).flags & FLAG_FIRE_COVER) == 0)
1146 		    col = main_groups[MP_GROUP(x,y)].colour;
1147 		else
1148 		    col = green (10);
1149 	    }
1150 	    Fgl_setpixel (mm->x + x, mm->y + y, col);
1151 	}
1152     }
1153     draw_mini_screen_cursor ();
1154 #if defined (WIN32)
1155     RefreshArea (mm->x, mm->y, mm->x + x, mm->y + y);
1156 #endif
1157 }
1158 
1159 void
draw_mini_screen_cricket_cover(void)1160 draw_mini_screen_cricket_cover (void)
1161 {
1162     int x, y, xx, yy, col;
1163     Rect* mm = &scr.mini_map;
1164 
1165     mini_screen_flags = MINI_SCREEN_CRICKET_COVER;
1166     draw_ms_text (_("Crickt cover"));
1167     draw_ms_button (ms_cricket_cover_button_graphic);
1168     for (y = 0; y < WORLD_SIDE_LEN; y++) {
1169 	for (x = 0; x < WORLD_SIDE_LEN; x++) {
1170 	    if (MP_TYPE(x,y) == CST_USED)
1171 	    {
1172 		xx = MP_INFO(x,y).int_1;
1173 		yy = MP_INFO(x,y).int_2;
1174 		if ((MP_INFO(xx,yy).flags & FLAG_CRICKET_COVER) == 0)
1175 		    col = main_groups[MP_GROUP(xx,yy)].colour;
1176 		else
1177 		    col = green (10);
1178 	    }
1179 	    else
1180 	    {
1181 		if ((MP_INFO(x,y).flags & FLAG_CRICKET_COVER) == 0)
1182 		    col = main_groups[MP_GROUP(x,y)].colour;
1183 		else
1184 		    col = green (10);
1185 	    }
1186 	    Fgl_setpixel (mm->x + x, mm->y + y, col);
1187 	}
1188     }
1189     draw_mini_screen_cursor ();
1190 #if defined (WIN32)
1191     RefreshArea (mm->x, mm->y, mm->x + x, mm->y + y);
1192 #endif
1193 }
1194 
1195 void
draw_mini_screen_health_cover(void)1196 draw_mini_screen_health_cover (void)
1197 {
1198     int x, y, xx, yy, col;
1199     Rect* mm = &scr.mini_map;
1200 
1201     mini_screen_flags = MINI_SCREEN_HEALTH_COVER;
1202     draw_ms_text (_("Health cover"));
1203     draw_ms_button (ms_health_cover_button_graphic);
1204     for (y = 0; y < WORLD_SIDE_LEN; y++) {
1205 	for (x = 0; x < WORLD_SIDE_LEN; x++) {
1206 	    if (MP_TYPE(x,y) == CST_USED)
1207 	    {
1208 		xx = MP_INFO(x,y).int_1;
1209 		yy = MP_INFO(x,y).int_2;
1210 		if ((MP_INFO(xx,yy).flags & FLAG_HEALTH_COVER) == 0)
1211 		    col = main_groups[MP_GROUP(xx,yy)].colour;
1212 		else
1213 		    col = green (10);
1214 	    }
1215 	    else
1216 	    {
1217 		if ((MP_INFO(x,y).flags & FLAG_HEALTH_COVER) == 0)
1218 		    col = main_groups[MP_GROUP(x,y)].colour;
1219 		else
1220 		    col = green (10);
1221 	    }
1222 	    Fgl_setpixel (mm->x + x, mm->y + y, col);
1223 	}
1224     }
1225     draw_mini_screen_cursor ();
1226 #if defined (WIN32)
1227     RefreshArea (mm->x, mm->y, mm->x + x, mm->y + y);
1228 #endif
1229 }
1230 
1231 void
draw_mini_screen_ub40(void)1232 draw_mini_screen_ub40 (void)
1233 {
1234     int x, y, col;
1235     Rect* mm = &scr.mini_map;
1236 
1237     mini_screen_flags = MINI_SCREEN_UB40_FLAG;
1238     draw_ms_text (_("Unemployment"));
1239     draw_ms_button (ms_ub40_button_graphic);
1240     Fgl_fillbox (mm->x, mm->y, WORLD_SIDE_LEN, WORLD_SIDE_LEN, green (14));
1241     for (y = 0; y < WORLD_SIDE_LEN; y++) {
1242 	for (x = 0; x < WORLD_SIDE_LEN; x++) {
1243 	    if (MP_GROUP_IS_RESIDENCE(x,y)) {
1244 		if (MP_INFO(x,y).int_1 < -20)
1245 		    col = red (28);
1246 		else if (MP_INFO(x,y).int_1 < 10)
1247 		    col = red (14);
1248 		else
1249 		    col = green (20);
1250 		Fgl_fillbox (mm->x + x, mm->y + y, 3, 3, col);
1251 	    }
1252 	}
1253     }
1254     draw_mini_screen_cursor ();
1255 #if defined (WIN32)
1256     RefreshArea (mm->x, mm->y, mm->x + x, mm->y + y);
1257 #endif
1258 }
1259 
1260 void
draw_mini_screen_starve(void)1261 draw_mini_screen_starve (void)
1262 {
1263     int x, y, col;
1264     Rect* mm = &scr.mini_map;
1265 
1266     mini_screen_flags = MINI_SCREEN_STARVE_FLAG;
1267     draw_ms_text (_("Starvation  "));
1268     draw_ms_button (ms_starve_button_graphic);
1269     Fgl_fillbox (mm->x, mm->y,
1270 		 WORLD_SIDE_LEN, WORLD_SIDE_LEN, green (14));
1271     for (y = 0; y < WORLD_SIDE_LEN; y++) {
1272 	for (x = 0; x < WORLD_SIDE_LEN; x++) {
1273 	    if (MP_GROUP_IS_RESIDENCE(x,y)) {
1274 		if ((total_time - MP_INFO(x,y).int_2) < 20)
1275 		    col = red (28);
1276 		else if ((total_time - MP_INFO(x,y).int_2) < 100)
1277 		    col = red (14);
1278 		else
1279 		    col = green (20);
1280 		Fgl_fillbox (mm->x + x, mm->y + y, 3, 3, col);
1281 	    }
1282 	}
1283     }
1284     draw_mini_screen_cursor ();
1285 #if defined (WIN32)
1286     RefreshArea (mm->x, mm->y, mm->x + x, mm->y + y);
1287 #endif
1288 }
1289 
1290 void
draw_mini_screen_coal(void)1291 draw_mini_screen_coal (void)
1292 {
1293     int x, y, col;
1294     Rect* mm = &scr.mini_map;
1295 
1296     mini_screen_flags = MINI_SCREEN_COAL_FLAG;
1297     draw_ms_text (_("Coal Reserve"));
1298     draw_ms_button (ms_coal_button_graphic);
1299     if (coal_survey_done) {
1300 	for (y = 0; y < WORLD_SIDE_LEN; y++) {
1301 	    for (x = 0; x < WORLD_SIDE_LEN; x++) {
1302 		if (MP_INFO(x,y).coal_reserve == 0)
1303 		    col = white (4);
1304 		else if (MP_INFO(x,y).coal_reserve >= COAL_RESERVE_SIZE / 2)
1305 		    col = white (18);
1306 		else if (MP_INFO(x,y).coal_reserve < COAL_RESERVE_SIZE / 2)
1307 		    col = white (28);
1308 		Fgl_setpixel (mm->x + x, mm->y + y, col);
1309 	    }
1310 	}
1311 	draw_mini_screen_cursor ();
1312     } else {
1313 	Fgl_setfontcolors (white(4), white(28));
1314 	Fgl_fillbox (mm->x, mm->y, WORLD_SIDE_LEN, WORLD_SIDE_LEN, white(4));
1315 	Fgl_write (mm->x + 4, mm->y + 20, _("Click here"));
1316 	Fgl_write (mm->x + 4, mm->y + 32, _("   to do  "));
1317 	Fgl_write (mm->x + 4, mm->y + 44, _("coal survey"));
1318 	Fgl_setfontcolors (TEXT_BG_COLOUR, TEXT_FG_COLOUR);
1319     }
1320 #if defined (WIN32)
1321     RefreshArea (mm->x, mm->y, mm->x + x, mm->y + y);
1322 #endif
1323 }
1324 
1325 void
draw_mini_screen_power(void)1326 draw_mini_screen_power (void)
1327 {
1328     int x, y, xx, yy, col;
1329     int have_power = 0;
1330     Rect* mm = &scr.mini_map;
1331 
1332     mini_screen_flags = MINI_SCREEN_POWER_FLAG;
1333     draw_ms_button (ms_power_button_graphic);
1334     for (y = 0; y < WORLD_SIDE_LEN; y++) {
1335 	for (x = 0; x < WORLD_SIDE_LEN; x++) {
1336 	    short grp = MP_GROUP(x,y);
1337 	    if (grp == GROUP_USED) {
1338 		xx = MP_INFO(x,y).int_1;
1339 		yy = MP_INFO(x,y).int_2;
1340 		grp = MP_GROUP(xx,yy);
1341 	    } else {
1342 		xx = x;
1343 		yy = y;
1344 	    }
1345 	    if (get_power (xx, yy, 1, 1) != 0) {
1346 		have_power = 1;
1347 		col = green (14);
1348 	    } else if (get_power (xx, yy, 1, 0) != 0) {
1349 		have_power = 1;
1350 		col = green (10);
1351 	    } else {
1352 		col = main_groups[grp].colour;
1353 	    }
1354 	    Fgl_setpixel (mm->x + x, mm->y + y, col);
1355 	}
1356     }
1357     if (have_power) {
1358 	draw_ms_text (_("Power       "));
1359     } else {
1360 	draw_ms_text (_("Power (none)"));
1361     }
1362     draw_mini_screen_cursor ();
1363 #if defined (WIN32)
1364     RefreshArea (mm->x, mm->y, mm->x + x, mm->y + y);
1365 #endif
1366 }
1367 
1368 /* GCS -- This is obsolete, right?? */
1369 void
draw_mini_screen_ocost(void)1370 draw_mini_screen_ocost (void)
1371 {
1372     char s[100];
1373     Rect* b = &scr.mini_map;
1374     mini_screen_flags = MINI_SCREEN_NORMAL_FLAG;
1375     draw_ms_text ("Other Costs");
1376     draw_ms_button (ms_ocost_button_graphic);
1377     Fgl_fillbox (b->x, b->y,
1378 		 WORLD_SIDE_LEN, WORLD_SIDE_LEN, green (12));
1379     Fgl_setfontcolors (green (12), TEXT_FG_COLOUR);
1380     sprintf (s, "OC yr %04d", (total_time / NUMOF_DAYS_IN_YEAR) - 1);
1381     Fgl_write (b->x + 10, b->y + 2, s);
1382 
1383     if (ly_interest > 19999)
1384     {
1385 	sprintf (s, "Int %4dK", ly_interest / 1000);
1386     }
1387     else
1388 	sprintf (s, "Int %5d", ly_interest);
1389     Fgl_write (b->x + 10, b->y + 16, s);
1390 
1391     if (ly_school_cost > 19999)
1392     {
1393 	if (ly_school_cost > 1999999)
1394 	    sprintf (s, "Scl %4dM", ly_school_cost / 1000000);
1395 	else
1396 	    sprintf (s, "Scl %4dK", ly_school_cost / 1000);
1397     }
1398     else
1399 	sprintf (s, "Scl %5d", ly_school_cost);
1400     Fgl_write (b->x + 10, b->y + 24, s);
1401 
1402     if (ly_university_cost > 19999)
1403     {
1404 	if (ly_university_cost > 1999999)
1405 	    sprintf (s, "Uni %4dM", ly_university_cost / 1000000);
1406 	else
1407 	    sprintf (s, "Uni %4dK", ly_university_cost / 1000);
1408     }
1409     else
1410 	sprintf (s, "Uni %5d", ly_university_cost);
1411     Fgl_write (b->x + 10, b->y + 32, s);
1412 
1413     if (ly_deaths_cost > 19999)
1414     {
1415 	if (ly_deaths_cost > 1999999)
1416 	    sprintf (s, "UnD %4dM", ly_deaths_cost / 1000000);
1417 	else
1418 	    sprintf (s, "UnD %4dK", ly_deaths_cost / 1000);
1419     }
1420     else
1421 	sprintf (s, "UnD %5d", ly_deaths_cost);
1422     Fgl_write (b->x + 10, b->y + 40, s);
1423 
1424     if (ly_windmill_cost > 19999)
1425     {
1426 	if (ly_windmill_cost > 1999999)
1427 	    sprintf (s, "WiM %4dM", ly_windmill_cost / 1000000);
1428 	else
1429 	    sprintf (s, "WiM %4dK", ly_windmill_cost / 1000);
1430     }
1431     else
1432 	sprintf (s, "WiM %5d", ly_windmill_cost);
1433     Fgl_write (b->x + 10, b->y + 48, s);
1434 
1435     if (ly_recycle_cost > 19999)
1436     {
1437 	if (ly_recycle_cost > 1999999)
1438 	    sprintf (s, "Rcy %4dM", ly_recycle_cost / 1000000);
1439 	else
1440 	    sprintf (s, "Rcy %4dK", ly_recycle_cost / 1000);
1441     }
1442     else
1443 	sprintf (s, "Rcy %5d", ly_recycle_cost);
1444     Fgl_write (b->x + 10, b->y + 56, s);
1445 
1446     if (ly_health_cost > 19999)
1447     {
1448 	if (ly_health_cost > 1999999)
1449 	    sprintf (s, "Hth %4dM", ly_health_cost / 1000000);
1450 	else
1451 	    sprintf (s, "Hth %4dK", ly_health_cost / 1000);
1452     }
1453     else
1454 	sprintf (s, "Hth %5d", ly_health_cost);
1455     Fgl_write (b->x + 10, b->y + 64, s);
1456 
1457     if (ly_rocket_pad_cost > 19999)
1458     {
1459 	if (ly_rocket_pad_cost > 1999999)
1460 	    sprintf (s, "Rok %4dM", ly_rocket_pad_cost / 1000000);
1461 	else
1462 	    sprintf (s, "Rok %4dK", ly_rocket_pad_cost / 1000);
1463     }
1464     else
1465 	sprintf (s, "Rok %5d", ly_rocket_pad_cost);
1466     Fgl_write (b->x + 10, b->y + 72, s);
1467 
1468     if (ly_fire_cost > 19999)
1469     {
1470 	if (ly_fire_cost > 1999999)
1471 	    sprintf (s, "Fst %4dM", ly_fire_cost / 1000000);
1472 	else
1473 	    sprintf (s, "Fst %4dK", ly_fire_cost / 1000);
1474     }
1475     else
1476 	sprintf (s, "Fst %5d", ly_fire_cost);
1477     Fgl_write (b->x + 10, b->y + 80, s);
1478 
1479     if (ly_cricket_cost > 19999)
1480     {
1481 	if (ly_cricket_cost > 1999999)
1482 	    sprintf (s, "Ckt %4dM", ly_cricket_cost / 1000000);
1483 	else
1484 	    sprintf (s, "Ckt %4dK", ly_cricket_cost / 1000);
1485     }
1486     else
1487 	sprintf (s, "Ckt %5d", ly_cricket_cost);
1488     Fgl_write (b->x + 10, b->y + 88, s);
1489 
1490     Fgl_setfontcolors (TEXT_BG_COLOUR, TEXT_FG_COLOUR);
1491 }
1492 
1493 #if defined (commentout)
1494 void
draw_mini_screen_port(void)1495 draw_mini_screen_port (void)
1496 {
1497     char buy[256], sell[256], s[256];
1498     int l, i, *p1, *p2;
1499     Rect* b = &scr.mini_map;
1500     mini_screen_flags = MINI_SCREEN_PORT_FLAG;
1501 
1502     /* GCS FIX: This causes flashing on my SGI, and is really not
1503        necessary, since we will completely overwrite the numbers below. */
1504     Fgl_fillbox (b->x, b->y, WORLD_SIDE_LEN, WORLD_SIDE_LEN, green (12));
1505     Fgl_setfontcolors (green (12), TEXT_FG_COLOUR);
1506     sprintf (s, " Port %2d %2d", mini_screen_port_x, mini_screen_port_y);
1507     Fgl_write (b->x + 4, b->y + 2, s);
1508     Fgl_write (b->x + 4, b->y + 16, " F C O G S");
1509     Fgl_write (b->x + 4, b->y + 26, " Buy   Sell");
1510 
1511     p1 = &(MP_INFO(mini_screen_port_x,mini_screen_port_y + 1).int_3);
1512     p2 = &(MP_INFO(mini_screen_port_x,mini_screen_port_y + 2).int_3);
1513     for (i = 0; i < 5; i++)
1514     {
1515 	l = *(p1++) / 100;
1516 	if (l > 19999)
1517 	{
1518 	    if (l > 1999999)
1519 		sprintf (buy, "%4dM", l / 1000000);
1520 	    else
1521 		sprintf (buy, "%4dK", l / 1000);
1522 	}
1523 	else
1524 	    sprintf (buy, "%5d", l);
1525 	l = *(p2++) / 100;
1526 	if (l > 19999)
1527 	{
1528 	    if (l > 1999999)
1529 		sprintf (sell, "%4dM", l / 1000000);
1530 	    else
1531 		sprintf (sell, "%4dK", l / 1000);
1532 	}
1533 	else
1534 	    sprintf (sell, "%5d", l);
1535 	sprintf (s, "%s %s", buy, sell);
1536 	Fgl_write (b->x + 10, b->y + 40 + i * 8, s);
1537     }
1538 
1539     Fgl_setfontcolors (TEXT_BG_COLOUR, TEXT_FG_COLOUR);
1540 }
1541 #endif
1542 
1543 void
draw_mini_screen_cursor(void)1544 draw_mini_screen_cursor (void)
1545 {
1546     Rect* mini = &scr.mini_map;
1547     Rect* mw = &scr.main_win;
1548     Fgl_hline (mini->x + main_screen_originx
1549 	       ,mini->y + main_screen_originy
1550 	       ,mini->x + main_screen_originx + mw->w / 16 - 1
1551 	       ,255);
1552     Fgl_hline (mini->x + main_screen_originx
1553 	       ,mini->y + main_screen_originy + mw->h / 16 - 1
1554 	       ,mini->x + main_screen_originx + mw->w / 16 - 1
1555 	       ,255);
1556     Fgl_line (mini->x + main_screen_originx
1557 	      ,mini->y + main_screen_originy
1558 	      ,mini->x + main_screen_originx
1559 	      ,mini->y + main_screen_originy + mw->h / 16 - 1
1560 	      ,255);
1561     Fgl_line (mini->x + main_screen_originx + mw->w / 16 - 1
1562 	      ,mini->y + main_screen_originy
1563 	      ,mini->x + main_screen_originx + mw->w / 16 - 1
1564 	      ,mini->y + main_screen_originy + mw->h / 16 - 1
1565 	      ,255);
1566 
1567 }
1568 
1569 void
initialize_print_stats(void)1570 initialize_print_stats (void)
1571 {
1572 #if !defined (WIN32)
1573     hide_mouse ();
1574 #endif
1575     update_scoreboard.mps = 0;
1576     update_scoreboard.mini = 0;
1577     update_scoreboard.date = 0;
1578     update_scoreboard.money = 0;
1579     update_scoreboard.monthly = 0;
1580     update_scoreboard.yearly_1 = 0;
1581     update_scoreboard.yearly_2 = 0;
1582     update_scoreboard.message_area = 0;
1583 
1584 #if defined (STATS_WINDOW)
1585     draw_yellow_bezel (STATS_X, STATS_Y, STATS_H, STATS_W);
1586     Fgl_write (STATS_X, STATS_Y, "Population ");
1587     Fgl_write (STATS_X, STATS_Y + 8, "% Starving ");
1588     Fgl_write (STATS_X, STATS_Y + 16, "Foodstore ");
1589     Fgl_write (STATS_X, STATS_Y + 24, "% u-ployed ");
1590     Fgl_write (STATS_X + 18 * 8, STATS_Y, "Tech level   ");
1591     Fgl_write (STATS_X + 18 * 8, STATS_Y + 8, "Un-nat deaths ");
1592     Fgl_write (STATS_X + 18 * 8, STATS_Y + 16, "Rockets  ");
1593     Fgl_write (STATS_X + 18 * 8, STATS_Y + 24, "Shanty towns");
1594 #endif
1595 
1596 #if defined (FINANCE_WINDOW)
1597     draw_yellow_bezel (FINANCE_X, FINANCE_Y, FINANCE_H, FINANCE_W);
1598     Fgl_write (FINANCE_X, FINANCE_Y, "Income  Expend");
1599     Fgl_write (FINANCE_X, FINANCE_Y + 8, "IT");
1600     Fgl_write (FINANCE_X, FINANCE_Y + 16, "CT");
1601     Fgl_write (FINANCE_X, FINANCE_Y + 24, "GT");
1602     Fgl_write (FINANCE_X, FINANCE_Y + 32, "XP");
1603     Fgl_write (FINANCE_X + 64, FINANCE_Y + 8, "OC");
1604     Fgl_write (FINANCE_X + 64, FINANCE_Y + 16, "UC");
1605     Fgl_write (FINANCE_X + 64, FINANCE_Y + 24, "TC");
1606     Fgl_write (FINANCE_X + 64, FINANCE_Y + 32, "IP");
1607     Fgl_write (FINANCE_X, FINANCE_Y + 48, "Tot");
1608 #endif
1609 
1610 #if !defined (WIN32)
1611     redraw_mouse ();
1612 #endif
1613 }
1614 
1615 void
advance_monthgraph_style(void)1616 advance_monthgraph_style (void)
1617 {
1618     monthgraph_style = (monthgraph_style % 2) + 1;
1619     if (monthgraph_style == MONTHGRAPH_STYLE_ECONOMY) {
1620 	monthgraph_style_timeout = real_time + 10000;
1621     } else {
1622 	monthgraph_style_timeout = real_time + 4000;
1623     }
1624 }
1625 
1626 void
refresh_monthgraph(void)1627 refresh_monthgraph (void)
1628 {
1629     do_monthgraph (1);
1630 }
1631 
1632 void
monthgraph_full_refresh(void)1633 monthgraph_full_refresh (void)
1634 {
1635     Rect* mg = &scr.monthgraph;
1636     draw_small_yellow_bezel (mg->x, mg->y, mg->h, mg->w);
1637     do_monthgraph (1);
1638 }
1639 
1640 void
print_stats(void)1641 print_stats (void)
1642 {
1643     static int flag = 0;
1644     int monthgraph_full_update = 0;
1645 
1646     if (flag == 0) {
1647 	initialize_print_stats ();
1648 	flag = 1;
1649     }
1650 
1651 #if !defined (WIN32)
1652     hide_mouse ();
1653 #endif
1654 
1655     if (total_time % NUMOF_DAYS_IN_MONTH == (NUMOF_DAYS_IN_MONTH - 1)) {
1656 	update_scoreboard.monthly = 1;
1657     }
1658     if (total_time % NUMOF_DAYS_IN_YEAR == (NUMOF_DAYS_IN_YEAR - 1)) {
1659 	update_scoreboard.yearly_1 = 1;
1660 	update_scoreboard.money = 1;
1661     }
1662     if ((total_time % NUMOF_DAYS_IN_YEAR) == 0) {
1663 	update_scoreboard.yearly_2 = 1;
1664     }
1665     if (real_time > mappoint_stats_time) {
1666 	update_scoreboard.mps = 1;
1667 	mappoint_stats_time = real_time + 1000;
1668     }
1669     if (mini_screen_flags != MINI_SCREEN_NORMAL_FLAG
1670 	&& real_time > mini_screen_time) {
1671 	update_scoreboard.mini = 1;
1672 	mini_screen_time = real_time + 1000;
1673     }
1674     if ((total_time % NUMOF_DAYS_IN_YEAR) == 0) {
1675 	calculate_time_for_year ();
1676 	print_time_for_year ();
1677     }
1678     if (total_time % NUMOF_DAYS_IN_MONTH == 1) {
1679 	update_scoreboard.date = 1;
1680     }
1681 
1682     /* Decode and perform update requests according to scoreboard */
1683     if (update_scoreboard.mps) {
1684 	update_scoreboard.mps = 0;
1685 	/* Update the global style if timeout has occurred */
1686 	if (help_flag || load_flag || save_flag || mappoint_stats_flag) {
1687 	    mps_global_style_timeout = real_time + 6000;
1688 	}
1689 	if (real_time > mps_global_style_timeout) {
1690 	    if (time_multiplex_stats) {
1691 		mps_global_advance ();
1692 	    }
1693 	}
1694 
1695 	mps_update();
1696 
1697     }
1698 
1699     if (update_scoreboard.mini) {
1700 	update_scoreboard.mini = 0;
1701 	update_mini_screen ();
1702     }
1703 
1704     if (update_scoreboard.date) {
1705 	update_scoreboard.date = 0;
1706 	print_date ();
1707     }
1708 
1709     if (update_scoreboard.money) {
1710 	update_scoreboard.money = 0;
1711 	print_total_money ();
1712     }
1713 
1714     if (update_scoreboard.monthly) {
1715 	update_scoreboard.monthly = 0;
1716 
1717 	/* Update the global style if timeout has occurred */
1718 	if (help_flag || load_flag || save_flag) {
1719 	    if (monthgraph_style == MONTHGRAPH_STYLE_ECONOMY) {
1720 		monthgraph_style_timeout = real_time + 10000;
1721 	    } else {
1722 		monthgraph_style_timeout = real_time + 4000;
1723 	    }
1724 	}
1725 	if (real_time > monthgraph_style_timeout) {
1726 	    if (time_multiplex_stats) {
1727 		monthgraph_full_update = 1;
1728 		monthgraph_style = (monthgraph_style % 2) + 1;
1729 	    }
1730 	    if (monthgraph_style == MONTHGRAPH_STYLE_ECONOMY) {
1731 		monthgraph_style_timeout = real_time + 10000;
1732 	    } else {
1733 		monthgraph_style_timeout = real_time + 4000;
1734 	    }
1735 	}
1736 
1737 	do_monthgraph (monthgraph_full_update);
1738 
1739 #if defined (STATS_WINDOW)
1740 	sprintf (s, "%5d ", housed_population + people_pool);
1741 	Fgl_write (STATS_X + 8 * 11, STATS_Y, s);
1742 	i = ((tstarving_population / NUMOF_DAYS_IN_MONTH)
1743 	     * 1000) / ((tpopulation / NUMOF_DAYS_IN_MONTH) + 1);
1744 	sprintf (s, "%3d.%1d ", i / 10, i % 10);
1745 	Fgl_write (STATS_X + 8 * 11, STATS_Y + 8, s);
1746 	sprintf (s, "%5d ", tfood_in_markets / NUMOF_DAYS_IN_MONTH);
1747 	Fgl_write (STATS_X + 8 * 11, STATS_Y + 16, s);
1748 	i = ((tunemployed_population / NUMOF_DAYS_IN_MONTH)
1749 	     * 1000) / ((tpopulation / NUMOF_DAYS_IN_MONTH) + 1);
1750 	sprintf (s, "%3d.%1d ", i / 10, i % 10);
1751 	Fgl_write (STATS_X + 8 * 11, STATS_Y + 24, s);
1752 	sprintf (s, "%5d ", numof_shanties);
1753 	Fgl_write (STATS_X + 8 * (12 + 20), STATS_Y + 24, s);
1754 	sprintf (s, "%5.1f ", (float) tech_level * 100.0 / MAX_TECH_LEVEL);
1755 	Fgl_write (STATS_X + (20 + 12) * 8, STATS_Y, s);
1756 	sprintf (s, "%5d ", unnat_deaths);
1757 	Fgl_write (STATS_X + (20 + 12) * 8, STATS_Y + 8, s);
1758 #endif
1759 
1760 	update_pbars_monthly();
1761 
1762 	refresh_pbars();
1763 
1764 	/* GCS, May 11, 2003.  Quick hack for SVGALIB.  Basically,
1765 	 * I need to workaround the fact that a dialog box might pop
1766 	 * up, causing move_mouse() to nest hide_mouse() calls,
1767 	 * which means that the cursor will leave a trail.		*/
1768 #if !defined (WIN32)
1769         redraw_mouse ();
1770 #endif
1771 	update_avail_modules (1);
1772 #if !defined (WIN32)
1773         hide_mouse ();
1774 #endif
1775     }
1776 
1777     if (update_scoreboard.yearly_1) {
1778 	update_scoreboard.yearly_1 = 0;
1779     }
1780 
1781     if (update_scoreboard.message_area > 0
1782 	 && real_time > update_scoreboard.message_area) {
1783 	reset_status_message ();
1784     }
1785 
1786 #if defined (WIN32)
1787     UpdateWindow (display.hWnd);
1788 #else
1789     redraw_mouse ();
1790 #endif
1791 }
1792 
1793 void
print_total_money(void)1794 print_total_money (void)
1795 {
1796     Rect* b = &scr.money;
1797     char str[MONEY_W / CHAR_WIDTH + 1];
1798     size_t count;
1799 
1800     count = sprintf(str, _("Money: "));
1801     count += commify(str + count, (MONEY_W / CHAR_WIDTH) - count, total_money);
1802     count += snprintf(str + count, (MONEY_W / CHAR_WIDTH) - count,
1803 		      "                                            ");
1804     str[MONEY_W / CHAR_WIDTH] = '\0';
1805 
1806     if (total_money < 0)
1807 	Fgl_setfontcolors (TEXT_BG_COLOUR, red (30));
1808 
1809 /*     Fgl_putbox (b->x, b->y, 16, 16, money_pbar_graphic); */
1810     //Fgl_write (b->x + 16, b->y, str);
1811     Fgl_write (b->x + 32, b->y, str);
1812 
1813     if (total_money < 0)
1814 	Fgl_setfontcolors (TEXT_BG_COLOUR, TEXT_FG_COLOUR);
1815 }
1816 
1817 void
print_date(void)1818 print_date (void)
1819 {
1820     char s[50];
1821     Rect* b = &scr.date;
1822     sprintf (s, _("Date %s %04d "), current_month(total_time),
1823 	     current_year(total_time));
1824     Fgl_write (b->x, b->y, s);
1825 #if defined (WIN32)
1826     UpdateWindow (display.hWnd);
1827 #endif
1828 }
1829 
1830 void
print_population(void)1831 print_population (void)
1832 {
1833     draw_pbar (&scr.pbar_pop, pop_pbar_graphic);
1834 }
1835 
1836 void
calculate_time_for_year(void)1837 calculate_time_for_year (void)
1838 {
1839     static int time_last_year = 0;
1840 
1841     time_for_year = (float) (real_time - time_last_year) / 1000.0;
1842 
1843     time_last_year = real_time;
1844 }
1845 
1846 void
print_time_for_year(void)1847 print_time_for_year (void)
1848 {
1849     char s[100];
1850     Rect* b = &scr.time_for_year;
1851 
1852 
1853     if (time_for_year > 3600.0)
1854 	sprintf (s, _("%s%5.1f MINS/year  V %s"),
1855 		 cheat_flag ? _("TEST MODE") : "",
1856 		 time_for_year / 60.0, VERSION);
1857     else
1858 	sprintf (s, _("%s%5.1f secs/year  V %s "),
1859 		 cheat_flag ? _("TEST MODE") : "",
1860 		 time_for_year, VERSION);
1861     Fgl_write (b->x, b->y, s);
1862 }
1863 
1864 /* Write a message in the status area of the screen */
1865 void
status_message_1(char * message)1866 status_message_1 (char * message)
1867 {
1868     Rect* b = &scr.status_message_1;
1869 
1870     Fgl_fillbox(b->x, b->y, b->w, b->h, TEXT_BG_COLOUR);
1871     if (message == NULL)
1872 	return;
1873     Fgl_write (b->x, b->y, message);
1874 }
1875 
1876 void
status_message_2(char * message)1877 status_message_2 (char * message)
1878 {
1879     Rect* b = &scr.status_message_2;
1880 
1881     Fgl_fillbox(b->x, b->y, b->w, b->h, TEXT_BG_COLOUR);
1882     if (message == NULL)
1883 	return;
1884     Fgl_write (b->x, b->y, message);
1885 }
1886 
1887 void
status_message(char * m1,char * m2)1888 status_message (char* m1, char* m2)
1889 {
1890     status_message_1(m1);
1891     status_message_2(m2);
1892 #if defined (WIN32)
1893     UpdateWindow (display.hWnd);
1894 #endif
1895     update_scoreboard.message_area = real_time + 10000;
1896 }
1897 
1898 void
reset_status_message(void)1899 reset_status_message (void)
1900 {
1901     status_message_1(0);
1902     status_message_2(0);
1903 #if defined (WIN32)
1904     UpdateWindow (display.hWnd);
1905 #endif
1906     update_scoreboard.message_area = 0;
1907 }
1908 
1909 void
init_monthgraph(void)1910 init_monthgraph (void)
1911 {
1912     Rect* mg = &scr.monthgraph;
1913     Fgl_fillbox (mg->x, mg->y, mg->w + 1, mg->h + 1, GRAPHS_B_COLOUR);
1914 }
1915 
1916 void
clear_monthgraph(void)1917 clear_monthgraph (void)
1918 {
1919     Rect* mg = &scr.monthgraph;
1920     Fgl_fillbox (mg->x, mg->y, mg->w + 1, mg->h + 1, GRAPHS_B_COLOUR);
1921 }
1922 
1923 static void
do_monthgraph(int full_refresh)1924 do_monthgraph (int full_refresh)
1925 {
1926     if (full_refresh) {
1927 	clear_monthgraph();
1928     }
1929     do_history_linegraph (monthgraph_style == MONTHGRAPH_STYLE_ECONOMY);
1930     do_sust_barchart (monthgraph_style == MONTHGRAPH_STYLE_SUSTAIN);
1931 
1932 #if defined (WIN32)
1933     {
1934 	Rect* mg = &scr.monthgraph;
1935 	RefreshArea (mg->x, mg->y, mg->x + mg->w,
1936 		     mg->y + mg->h);
1937     }
1938 #endif
1939 }
1940 
1941 /* Must be called after initialize_geometry */
1942 void
initialize_monthgraph(void)1943 initialize_monthgraph (void)
1944 {
1945     int i;
1946 
1947     monthgraph_size = scr.monthgraph.w;
1948 
1949     monthgraph_pop = (int*) malloc (sizeof(int) * monthgraph_size);
1950     if (monthgraph_pop == 0) {
1951 	malloc_failure ();
1952     }
1953     monthgraph_starve = (int*) malloc (sizeof(int) * monthgraph_size);
1954     if (monthgraph_starve == 0) {
1955 	malloc_failure ();
1956     }
1957     monthgraph_nojobs = (int*) malloc (sizeof(int) * monthgraph_size);
1958     if (monthgraph_nojobs == 0) {
1959 	malloc_failure ();
1960     }
1961     monthgraph_ppool = (int*) malloc (sizeof(int) * monthgraph_size);
1962     if (monthgraph_ppool == 0) {
1963 	malloc_failure ();
1964     }
1965     for (i = 0; i < monthgraph_size; i++) {
1966 	monthgraph_pop[i] = 0;
1967 	monthgraph_starve[i] = 0;
1968 	monthgraph_nojobs[i] = 0;
1969 	monthgraph_ppool[i] = 0;
1970     }
1971 }
1972 
1973 static void
do_history_linegraph(int draw)1974 do_history_linegraph (int draw)
1975 {
1976     Rect* mg = &scr.monthgraph;
1977     int i;
1978     float f;
1979 
1980     for (i = mg->w - 1; i > 0; i--) {
1981 	if (draw) {
1982 	    Fgl_line (mg->x + mg->w - i,
1983 		      mg->y + mg->h - monthgraph_nojobs[i],
1984 		      mg->x + mg->w - i,
1985 		      mg->y + mg->h,
1986 		      GRAPHS_B_COLOUR);
1987 	    Fgl_line (mg->x + mg->w - i,
1988 		      mg->y + mg->h - monthgraph_nojobs[i-1],
1989 		      mg->x + mg->w - i,
1990 		      mg->y + mg->h,
1991 		      yellow (24));
1992 
1993 	    Fgl_line (mg->x + mg->w - i,
1994 		      mg->y + mg->h - monthgraph_starve[i],
1995 		      mg->x + mg->w - i,
1996 		      mg->y + mg->h,
1997 		      GRAPHS_B_COLOUR);
1998 	    Fgl_line (mg->x + mg->w - i,
1999 		      mg->y + mg->h - monthgraph_starve[i-1],
2000 		      mg->x + mg->w - i,
2001 		      mg->y + mg->h,
2002 		      red (24));
2003 
2004 	    Fgl_setpixel (mg->x + mg->w - i,
2005 			  mg->y + mg->h - monthgraph_pop[i],
2006 			  GRAPHS_B_COLOUR);
2007 	    Fgl_setpixel (mg->x + mg->w - i,
2008 			  mg->y + mg->h - monthgraph_pop[i-1], 7);
2009 
2010 	    Fgl_setpixel (mg->x + mg->w - i,
2011 			  mg->y + mg->h - monthgraph_ppool[i],
2012 			  GRAPHS_B_COLOUR);
2013 	    Fgl_setpixel (mg->x + mg->w - i,
2014 			  mg->y + mg->h - monthgraph_ppool[i-1],
2015 			  cyan (24));
2016 	}
2017 	monthgraph_pop[i] = monthgraph_pop[i-1];
2018 	monthgraph_ppool[i] = monthgraph_ppool[i-1];
2019 	monthgraph_nojobs[i] = monthgraph_nojobs[i-1];
2020 	monthgraph_starve[i] = monthgraph_starve[i-1];
2021     }
2022     if (tpopulation > 0)
2023     {
2024 	/* Zero out old value of leftmost pixel */
2025 	if (draw) {
2026 	    Fgl_setpixel (mg->x + mg->w,
2027 			  mg->y + mg->h - monthgraph_pop[0],
2028 			  GRAPHS_B_COLOUR);
2029 	    Fgl_setpixel (mg->x + mg->w,
2030 			  mg->y + mg->h - monthgraph_starve[0],
2031 			  GRAPHS_B_COLOUR);
2032 	    Fgl_setpixel (mg->x + mg->w,
2033 			  mg->y + mg->h - monthgraph_nojobs[0],
2034 			  GRAPHS_B_COLOUR);
2035 	    Fgl_setpixel (mg->x + mg->w,
2036 			  mg->y + mg->h - monthgraph_ppool[0],
2037 			  GRAPHS_B_COLOUR);
2038 	}
2039 	monthgraph_pop[0] = ((int) (log ((tpopulation / NUMOF_DAYS_IN_MONTH)
2040 					 + 1) * mg->h / 15)) - 5;
2041 	if (monthgraph_pop[0] < 0)
2042 	    monthgraph_pop[0] = 0;
2043 	f = ((float) tstarving_population
2044 	     / ((float) tpopulation + 1.0)) * 100.0;
2045 	if (tpopulation > 3000)	/* double the scale if pop > 3000 */
2046 	    f += f;
2047 	if (tpopulation > 6000)	/* double it AGAIN if pop > 6000 */
2048 	    f += f;
2049 	monthgraph_starve[0] = (int) f;
2050 	/* max out at 32 */
2051 	if (monthgraph_starve[0] >= mg->h)
2052 	    monthgraph_starve[0] = mg->h - 1;
2053 	f = ((float) tunemployed_population
2054 	     / ((float) tpopulation + 1.0)) * 100.0;
2055 	if (tpopulation > 3000)	/* double the scale if pop > 3000 */
2056 	    f += f;
2057 	if (tpopulation > 6000)	/* double it AGAIN if pop > 6000 */
2058 	    f += f;
2059 	monthgraph_nojobs[0] = (int) f;
2060 	/* max out at 32  */
2061 	if (monthgraph_nojobs[0] >= mg->h)
2062 	    monthgraph_nojobs[0] = mg->h - 1;
2063 	monthgraph_ppool[0] = ((int) (sqrt (people_pool + 1) * mg->h) / 35);
2064 	if (monthgraph_ppool[0] < 0)
2065 	    monthgraph_ppool[0] = 0;
2066 	if (monthgraph_ppool[0] >= mg->h)
2067 	    monthgraph_ppool[0] = mg->h - 1;
2068 	if (draw) {
2069 	    Fgl_setpixel (mg->x + mg->w,
2070 			  mg->y + mg->h - monthgraph_pop[0], 7);
2071 	    Fgl_setpixel (mg->x + mg->w,
2072 			  mg->y + mg->h - monthgraph_starve[0], red (24));
2073 	    Fgl_setpixel (mg->x + mg->w,
2074 			  mg->y + mg->h - monthgraph_nojobs[0], yellow (24));
2075 	    Fgl_setpixel (mg->x + mg->w,
2076 			  mg->y + mg->h - monthgraph_ppool[0], cyan (24));
2077 	}
2078     }
2079 }
2080 
2081 void
clicked_market_cb(int x,int y)2082 clicked_market_cb (int x, int y)
2083 {
2084     market_cb_flag = 1;
2085     mcbx = x;
2086     mcby = y;
2087 }
2088 
2089 
2090 void
draw_cb_box(int row,int col,int checked)2091 draw_cb_box (int row, int col, int checked)
2092 {
2093     int x, y;
2094     char* graphic;
2095     Rect* mcb = &scr.market_cb;
2096 
2097     y = mcb->y + 4 + (4 * 8) + (row * CB_SPACE);
2098     x = mcb->x + 12 + (col * 12) * 8;
2099     graphic = checked ? checked_box_graphic : unchecked_box_graphic;
2100     Fgl_putbox (x, y, 16, 16, graphic);
2101 }
2102 
2103 void
draw_cb_template(int is_market_cb)2104 draw_cb_template (int is_market_cb)
2105 {
2106     int x, y, flags;
2107     char s[100];
2108     Rect* mcb = &scr.market_cb;
2109 
2110     debug_printf ("In draw_cb_template...\n");
2111     debug_printf ("Coords are %d %d %d %d\n",mcb->x,mcb->y,mcb->w,mcb->h);
2112     x = mcbx;	/* x & y are the market's pos. */
2113     y = mcby;
2114     flags = MP_INFO(x,y).flags;
2115     Fgl_getbox (mcb->x, mcb->y, mcb->w, mcb->h, market_cb_gbuf);
2116     Fgl_fillbox (mcb->x, mcb->y, mcb->w, mcb->h, 28);
2117     draw_small_bezel(mcb->x+4, mcb->y+4, mcb->w-8, mcb->h-8, blue(0));
2118     Fgl_setfontcolors (28,TEXT_FG_COLOUR);
2119 #ifdef USE_EXPANDED_FONT
2120     gl_setwritemode (WRITEMODE_MASKED | FONT_EXPANDED);
2121 #endif
2122 
2123     if (is_market_cb) {
2124 	Fgl_write (mcb->x + 1 * 8, mcb->y + 8, _("Market"));
2125     } else {
2126 	Fgl_write (mcb->x + 3 * 8, mcb->y + 8, _("Port"));
2127     }
2128     sprintf (s, "%3d,%3d", x, y);
2129     Fgl_write (mcb->x + 7 * 8, mcb->y + 8, s);
2130     Fgl_hline (mcb->x + 2, mcb->y + 20, mcb->x + mcb->w - 2,
2131 	       TEXT_FG_COLOUR);
2132 
2133     Fgl_write (mcb->x +  1 * 8, mcb->y + 3 * 8, _("Buy"));
2134     Fgl_write (mcb->x + 12 * 8 + 4, mcb->y + 3 * 8 + 1, _("Sell"));
2135     if (is_market_cb) {
2136 	Fgl_write (mcb->x + 6 * 8 + 4, mcb->y + 40 +(CB_SPACE * 0), _("JOBS"));
2137     }
2138     Fgl_write (mcb->x + 6 * 8 + 4, mcb->y + 40 + (CB_SPACE * 1), _("FOOD"));
2139     Fgl_write (mcb->x + 6 * 8 + 4, mcb->y + 40 + (CB_SPACE * 2), _("COAL"));
2140     Fgl_write (mcb->x + 7 * 8, mcb->y + 40 + (CB_SPACE * 3), _("ORE"));
2141     Fgl_write (mcb->x + 6 * 8, mcb->y + 40 + (CB_SPACE * 4), _("GOODS"));
2142     Fgl_write (mcb->x + 6 * 8, mcb->y + 40 + (CB_SPACE * 5), _("STEEL"));
2143 
2144 #ifdef USE_EXPANDED_FONT
2145     gl_setwritemode (WRITEMODE_OVERWRITE | FONT_EXPANDED);
2146 #endif
2147 
2148     if (is_market_cb) {
2149 	draw_cb_box (0, 0, MP_INFO(mcbx,mcby).flags & FLAG_MB_JOBS);
2150 	draw_cb_box (0, 1, MP_INFO(mcbx,mcby).flags & FLAG_MS_JOBS);
2151     }
2152     draw_cb_box (1, 0, MP_INFO(mcbx,mcby).flags & FLAG_MB_FOOD);
2153     draw_cb_box (1, 1, MP_INFO(mcbx,mcby).flags & FLAG_MS_FOOD);
2154     draw_cb_box (2, 0, MP_INFO(mcbx,mcby).flags & FLAG_MB_COAL);
2155     draw_cb_box (2, 1, MP_INFO(mcbx,mcby).flags & FLAG_MS_COAL);
2156     draw_cb_box (3, 0, MP_INFO(mcbx,mcby).flags & FLAG_MB_ORE);
2157     draw_cb_box (3, 1, MP_INFO(mcbx,mcby).flags & FLAG_MS_ORE);
2158     draw_cb_box (4, 0, MP_INFO(mcbx,mcby).flags & FLAG_MB_GOODS);
2159     draw_cb_box (4, 1, MP_INFO(mcbx,mcby).flags & FLAG_MS_GOODS);
2160     draw_cb_box (5, 0, MP_INFO(mcbx,mcby).flags & FLAG_MB_STEEL);
2161     draw_cb_box (5, 1, MP_INFO(mcbx,mcby).flags & FLAG_MS_STEEL);
2162 }
2163 
2164 void
draw_market_cb(void)2165 draw_market_cb (void)
2166 {
2167     market_cb_drawn_flag = 1;
2168     draw_cb_template (1);
2169 }
2170 
2171 void
close_market_cb(void)2172 close_market_cb (void)
2173 {
2174     Rect* mcb = &scr.market_cb;
2175 
2176     market_cb_flag = 0;
2177     market_cb_drawn_flag = 0;
2178 
2179     Fgl_putbox (mcb->x, mcb->y, mcb->w, mcb->h
2180 		,market_cb_gbuf);
2181     Fgl_setfontcolors (TEXT_BG_COLOUR, TEXT_FG_COLOUR);
2182 
2183     /* when exiting market cb, stop the mouse repeating straight away */
2184     cs_mouse_button = LC_MOUSE_LEFTBUTTON;
2185 }
2186 
2187 void
clicked_port_cb(int x,int y)2188 clicked_port_cb (int x, int y)
2189 {
2190     port_cb_flag = 1;
2191     mcbx = x;
2192     mcby = y;
2193 }
2194 
2195 void
draw_port_cb(void)2196 draw_port_cb (void)
2197 {
2198     port_cb_drawn_flag = 1;
2199     draw_cb_template (0);
2200 }
2201 
2202 
2203 void
close_port_cb(void)2204 close_port_cb (void)
2205 {
2206     Rect* mcb = &scr.market_cb;
2207 
2208     port_cb_flag = 0;
2209     port_cb_drawn_flag = 0;
2210 
2211     Fgl_putbox (mcb->x, mcb->y, mcb->w, mcb->h, market_cb_gbuf);
2212     /* when exiting port cb, stop the mouse repeating straight away */
2213     cs_mouse_button = LC_MOUSE_LEFTBUTTON;
2214 }
2215 
2216 int
yn_dial_box(char * s1,char * s2,char * s3,char * s4)2217 yn_dial_box (char * s1, char * s2, char * s3, char *s4)
2218 {
2219     int result;
2220     result = dialog_box(red(10),7,
2221 			0,0,s1,
2222 			0,0,"",
2223 			0,0,s2,
2224 			0,0,s3,
2225 			0,0,s4,
2226 			1,'y',_("Yes"),
2227 			1,'n',_("No"));
2228 
2229     return (result == 'y') ? 1 : 0;
2230 }
2231 
2232 void
ok_dial_box(char * fn,int good_bad,char * xs)2233 ok_dial_box (char *fn, int good_bad, char *xs)
2234 {
2235     FILE *inf;
2236     struct stat statbuf;
2237     int colour;
2238     char * ss;
2239     char s[LC_PATH_MAX];
2240     int retval;
2241 
2242     if (suppress_ok_buttons != 0)
2243 	return;
2244     if (good_bad == GOOD || good_bad == RESULTS)
2245 	colour = green (14);
2246     else if (good_bad == BAD)
2247 	colour = red (12);
2248     else
2249 	colour = white (12);
2250     if (good_bad == RESULTS)
2251 	strcpy (s, fn);
2252     else
2253     {
2254 	strcpy (s, message_path);
2255 	strcat (s, fn);
2256     }
2257 
2258     if ((inf = fopen (s, "rb")) == NULL)
2259     {
2260 	printf ("Can't open message <%s> for OK dialog box\n", s);
2261 	strcpy (s, message_path);
2262 	strcat (s, "error.mes");
2263 	if ((inf = fopen (s, "rb")) == NULL)
2264 	{
2265 	    fprintf (stderr,
2266 		     "Can't open default message <%s> either\n", s);
2267 	    fprintf (stderr, " ...it was not displayed");
2268 	    return;
2269 	}
2270     }
2271     stat(s,&statbuf);
2272 
2273     ss = (char *)lcalloc(statbuf.st_size + 1);
2274     retval = fread(ss,sizeof(char),statbuf.st_size,inf);
2275     ss[statbuf.st_size] = '\0';
2276 
2277     undosify_string (ss);
2278 
2279 #if defined (commentout)
2280     if (xs != 0)
2281 	dialog_box(colour,3,
2282 		   0,0,ss,
2283 		   0,0,xs,
2284 		   2,' ',_("OK"));
2285     else
2286 	dialog_box(colour,2,
2287 		   0,0,ss,
2288 		   2,' ',_("OK"));
2289 #endif
2290     fclose(inf);
2291 
2292     display_info_message (colour, ss, xs);
2293 }
2294 
2295 void
format_status_message(char * sm1,char * sm2,int num_char,char * ss,char * xs)2296 format_status_message (char* sm1, char* sm2, int num_char, char* ss, char* xs)
2297 {
2298     char* src = ss;
2299     char* tgt = sm1;
2300     int did_xs = 0;
2301     int did_sm2 = 0;
2302     int chars_done = 0;
2303     *sm2 = *sm1 = '\0';\
2304 
2305     while (src) {
2306 	char src_c = *src++;
2307 	/* note: already undosified */
2308 	switch (src_c) {
2309 	case '\0':
2310 	    if (did_xs || !xs) {
2311 		*tgt = '\0';
2312 		return;
2313 	    } else {
2314 		src = xs;
2315 		did_xs = 1;
2316 	    }
2317 	    /* fall through */
2318 	case '\n':
2319 	    *tgt++ = ' ';
2320 	    break;
2321 	default:
2322 	    *tgt++ = src_c;
2323 	}
2324 	if (++chars_done == num_char) {
2325 	    *tgt = '\0';
2326 	    if (did_sm2) return;
2327 	    tgt = sm2;
2328 	    did_sm2 = 1;
2329 	    chars_done = 0;
2330 	}
2331     }
2332 }
2333 
2334 /* Call this routine instead of dialog_box() */
2335 void
display_info_message(int colour,char * ss,char * xs)2336 display_info_message (int colour, char* ss, char* xs)
2337 {
2338     if (suppress_popups) {
2339 	/* display in the message area */
2340         Rect* b = &scr.status_message_1;
2341 	int num_char = b->w / 9 - 1;
2342 	char *sm1, *sm2;
2343 	if ((sm1 = (char *) malloc (num_char+1)) == 0)
2344 	    malloc_failure ();
2345 	if ((sm2 = (char *) malloc (num_char+1)) == 0)
2346 	    malloc_failure ();
2347 
2348 	format_status_message (sm1,sm2,num_char,ss,xs);
2349 	status_message(sm1,sm2);
2350 	free (sm1);
2351 	free (sm2);
2352     } else {
2353 	/* display as dialog box */
2354 	if (xs) {
2355 	dialog_box(colour,3,
2356 		   0,0,ss,
2357 		   0,0,xs,
2358 		   2,' ',_("OK"));
2359 	} else {
2360 	dialog_box(colour,2,
2361 		   0,0,ss,
2362 		   2,' ',_("OK"));
2363 	}
2364     }
2365 }
2366 
2367 void
prog_box(char * title,int percent)2368 prog_box (char *title, int percent)
2369 {
2370     static int flag = 0, oldpercent = 0;
2371     char s[100];
2372     int i;
2373     if (flag == 0) {
2374 	hide_mouse ();
2375 	Fgl_getbox (PROGBOXX - 8, PROGBOXY - 8, PROGBOXW + 16,
2376 		    PROGBOXH + 16, progbox);
2377 	Fgl_fillbox (PROGBOXX, PROGBOXY,
2378 		     PROGBOXW, PROGBOXH, PROGBOX_BG_COLOUR);
2379 	for (i = 1; i < 8; i++) {
2380 	    Fgl_hline (PROGBOXX - i, PROGBOXY - i,
2381 		       PROGBOXX + PROGBOXW + i - 1,
2382 		       PROGBOX_BG_COLOUR + i + i);
2383 	    Fgl_hline (PROGBOXX - i, PROGBOXY + PROGBOXH + i - 1,
2384 		       PROGBOXX + PROGBOXW + i - 1,
2385 		       PROGBOX_BG_COLOUR + i + i);
2386 	    Fgl_line (PROGBOXX - i, PROGBOXY - i,
2387 		      PROGBOXX - i, PROGBOXY + PROGBOXH + i - 1,
2388 		      PROGBOX_BG_COLOUR + i + i);
2389 	    Fgl_line (PROGBOXX + PROGBOXW + i - 1, PROGBOXY - i,
2390 		      PROGBOXX + PROGBOXW + i - 1,
2391 		      PROGBOXY + PROGBOXH + i - 1,
2392 		      PROGBOX_BG_COLOUR + i + i);
2393 	}
2394 
2395 
2396 	Fgl_setfontcolors (PROGBOX_BG_COLOUR, TEXT_FG_COLOUR);
2397 	Fgl_write ((PROGBOXX + PROGBOXW / 2)
2398 		   - (strlen (title) * 4), PROGBOXY + 8, title);
2399 	Fgl_setfontcolors (TEXT_BG_COLOUR, TEXT_FG_COLOUR);
2400 
2401 	flag = 1;
2402     }
2403     if (percent != oldpercent)
2404     {
2405 	Fgl_fillbox (PROGBOXX + 20, PROGBOXY + 60,
2406 		     ((PROGBOXW - 40) * percent) / 100,
2407 		     20, PROGBOX_DONE_COL);
2408 	Fgl_fillbox (PROGBOXX + 20 + (((PROGBOXW - 40) * percent) / 100),
2409 		     PROGBOXY + 60,
2410 		     PROGBOXW - 40 - (((PROGBOXW - 40) * percent) / 100),
2411 		     20, PROGBOX_NOTDONE_COL);
2412 	oldpercent = percent;
2413 	Fgl_fillbox (PROGBOXX + (PROGBOXW / 2) - 20,
2414 		     PROGBOXY + 24, 40, 16, PROGBOX_BG_COLOUR);
2415 	sprintf (s, "%3d%%", percent);
2416 	Fgl_setfontcolors (PROGBOX_BG_COLOUR, TEXT_FG_COLOUR);
2417 	Fgl_write (PROGBOXX + (PROGBOXW / 2) - 20, PROGBOXY + 24, s);
2418 	Fgl_setfontcolors (TEXT_BG_COLOUR, TEXT_FG_COLOUR);
2419     }
2420 #ifdef LC_X11
2421     XSync (display.dpy, FALSE);
2422 #endif
2423     if (percent < 100)
2424     {
2425 #if defined (WIN32) /* GCS FIX:  Do I need this ????? */
2426 	/* GCS: Fgl_putbox does a refresh; no need to refresh twice */
2427 	RefreshArea (PROGBOXX - 8, PROGBOXY - 8, PROGBOXW + 16, PROGBOXH + 16);
2428 #endif
2429 	return;
2430     }
2431 
2432     Fgl_putbox (PROGBOXX - 8, PROGBOXY - 8, PROGBOXW + 16, PROGBOXH + 16, progbox);
2433     redraw_mouse ();
2434     flag = 0;
2435 }
2436 
2437 
2438 static void
do_sust_barchart(int draw)2439 do_sust_barchart (int draw)
2440 {
2441 #define SUST_BAR_H      5
2442 #define SUST_BAR_GAP_Y  5
2443   Rect* mg = &scr.monthgraph;
2444   static int flag = 0;
2445   if (flag == 0)
2446     {
2447       /*	flag = 1; */
2448       /* draw border around the sustainable screen */
2449 #if defined (commentout)
2450       draw_small_yellow_bezel (mg->x, mg->y, mg->h, mg->w);
2451 #endif
2452       if (draw) {
2453 	/* black out the inside */
2454 	Fgl_fillbox (mg->x, mg->y, mg->w, mg->h, 0);
2455 	/* write the "informative" text */
2456 	Fgl_setfontcolors (0, TEXT_FG_COLOUR);
2457 	Fgl_write (mg->x+3,
2458 		   mg->y + SUST_BAR_GAP_Y - 1,
2459 		   /* TRANSLATORS:
2460 		      MIN=Mining, PRT=Import/export from port,
2461 		      MNY=Money, POP=Population, TEC=Technology,
2462 		      FIR=Fire coverage
2463 		   */
2464 		   _("MIN"));
2465 	Fgl_write (mg->x+3,
2466 		   mg->y + SUST_BAR_GAP_Y + (SUST_BAR_H + SUST_BAR_GAP_Y) - 1,
2467 		   _("PRT"));
2468 	Fgl_write (mg->x+3,
2469 		   mg->y + SUST_BAR_GAP_Y + 2 * (SUST_BAR_H + SUST_BAR_GAP_Y) - 1,
2470 		   _("MNY"));
2471 	Fgl_write (mg->x+3,
2472 		   mg->y + SUST_BAR_GAP_Y + 3 * (SUST_BAR_H + SUST_BAR_GAP_Y) - 1,
2473 		   _("POP"));
2474 	Fgl_write (mg->x+3,
2475 		   mg->y + SUST_BAR_GAP_Y + 4 * (SUST_BAR_H + SUST_BAR_GAP_Y) - 1,
2476 		   _("TEC"));
2477 	Fgl_write (mg->x+3,
2478 		   mg->y + SUST_BAR_GAP_Y + 5 * (SUST_BAR_H + SUST_BAR_GAP_Y) - 1,
2479 		   _("FIR"));
2480 	Fgl_setfontcolors (TEXT_BG_COLOUR, TEXT_FG_COLOUR);
2481 	/* draw the starting line */
2482 	Fgl_line (mg->x + 38, mg->y, mg->x + 38, mg->y + mg->h,
2483 		  yellow (24));
2484 	/* ore coal */
2485 	Fgl_fillbox (mg->x + 36, mg->y + SUST_BAR_GAP_Y,
2486 		     3, SUST_BAR_H, SUST_ORE_COAL_COL);
2487 	/* import export */
2488 	Fgl_fillbox (mg->x + 36,
2489 		     mg->y + SUST_BAR_GAP_Y + (SUST_BAR_H + SUST_BAR_GAP_Y),
2490 		     3, SUST_BAR_H, SUST_PORT_COL);
2491 	/* money */
2492 	Fgl_fillbox (mg->x + 36,
2493 		     mg->y + SUST_BAR_GAP_Y + 2 * (SUST_BAR_H + SUST_BAR_GAP_Y),
2494 		     3, SUST_BAR_H, SUST_MONEY_COL);
2495 	/* population */
2496 	Fgl_fillbox (mg->x + 36,
2497 		     mg->y + SUST_BAR_GAP_Y + 3 * (SUST_BAR_H + SUST_BAR_GAP_Y),
2498 		     3, SUST_BAR_H, SUST_POP_COL);
2499 	/* tech */
2500 	Fgl_fillbox (mg->x + 36,
2501 		     mg->y + SUST_BAR_GAP_Y + 4 * (SUST_BAR_H + SUST_BAR_GAP_Y),
2502 		     3, SUST_BAR_H, SUST_TECH_COL);
2503 	/* fire */
2504 	Fgl_fillbox (mg->x + 36,
2505 		     mg->y + SUST_BAR_GAP_Y + 5 * (SUST_BAR_H + SUST_BAR_GAP_Y),
2506 		     3, SUST_BAR_H, SUST_FIRE_COL);
2507       }
2508     }
2509   if (sust_dig_ore_coal_count >= SUST_ORE_COAL_YEARS_NEEDED
2510       && sust_port_count >= SUST_PORT_YEARS_NEEDED
2511       && sust_old_money_count >= SUST_MONEY_YEARS_NEEDED
2512       && sust_old_population_count >= SUST_POP_YEARS_NEEDED
2513       && sust_old_tech_count >= SUST_TECH_YEARS_NEEDED
2514       && sust_fire_count >= SUST_FIRE_YEARS_NEEDED)
2515     {
2516       if (sustain_flag == 0)
2517 	ok_dial_box ("sustain.mes", GOOD, 0L);
2518       sustain_flag = 1;
2519     }
2520   else
2521     sustain_flag = 0;
2522   if (draw) {
2523     draw_sustline (0, sust_dig_ore_coal_count,
2524 		   SUST_ORE_COAL_YEARS_NEEDED, SUST_ORE_COAL_COL);
2525     draw_sustline ((SUST_BAR_H + SUST_BAR_GAP_Y),
2526 		   sust_port_count,
2527 		   SUST_PORT_YEARS_NEEDED, SUST_PORT_COL);
2528     draw_sustline (2*(SUST_BAR_H + SUST_BAR_GAP_Y),
2529 		   sust_old_money_count,
2530 		   SUST_MONEY_YEARS_NEEDED, SUST_MONEY_COL);
2531     draw_sustline (3*(SUST_BAR_H + SUST_BAR_GAP_Y),
2532 		   sust_old_population_count,
2533 		   SUST_POP_YEARS_NEEDED, SUST_POP_COL);
2534     draw_sustline (4*(SUST_BAR_H + SUST_BAR_GAP_Y),
2535 		   sust_old_tech_count,
2536 		   SUST_TECH_YEARS_NEEDED, SUST_TECH_COL);
2537     draw_sustline (5*(SUST_BAR_H + SUST_BAR_GAP_Y),
2538 		   sust_fire_count,
2539 		   SUST_FIRE_YEARS_NEEDED, SUST_FIRE_COL);
2540   }
2541 
2542 }
2543 
2544 static void
draw_sustline(int yoffset,int count,int max,int col)2545 draw_sustline (int yoffset, int count, int max, int col)
2546 {
2547   Rect* mg = &scr.monthgraph;
2548   int split;
2549   if (count >= max)
2550     split = 60;
2551   else
2552     split = 60 * count / max;
2553   Fgl_fillbox (mg->x + 38,
2554 	       mg->y + SUST_BAR_GAP_Y + yoffset, split, SUST_BAR_H, col);
2555   if (split < 60)
2556     Fgl_fillbox (mg->x + 38 + split + 1,
2557 		 mg->y + SUST_BAR_GAP_Y + yoffset, 60 - split,
2558 		 SUST_BAR_H, 0);
2559 }
2560 
2561 void
dump_screen(void)2562 dump_screen (void)
2563 {
2564 #if !defined (LC_X11) && !defined (WIN32)
2565     int x, y, r, g, b;
2566     FILE *outf;
2567     if ((outf = fopen ("screendump.raw", "wb")) == NULL)
2568 	do_error ("Can't open screendump.raw");
2569     for (y = 0; y < 480; y++)
2570 	for (x = 0; x < 640; x++)
2571 	{
2572 	    gl_getpixelrgb (x, y, &r, &g, &b);
2573 	    fputc (r, outf);
2574 	    fputc (g, outf);
2575 	    fputc (b, outf);
2576 	}
2577     fclose (outf);
2578 #endif
2579 }
2580 
2581 void
debug_writeval(int v)2582 debug_writeval (int v)
2583 {
2584     char s[100];
2585     sprintf (s, "%d  ", v);
2586     Fgl_write (280, 471, s);
2587 }
2588 
2589 int
ask_launch_rocket_click(int x,int y)2590 ask_launch_rocket_click (int x, int y)
2591 {
2592   return yn_dial_box (_("ROCKET LAUNCH"),
2593 		      _("You can launch the rocket now or wait until later."),
2594 		      _("If you wait, it costs you *only* money to keep the"),
2595 		      _("rocket ready.    Launch?"));
2596 }
2597 
2598 int
ask_launch_rocket_now(int x,int y)2599 ask_launch_rocket_now (int x, int y)
2600 {
2601     return yn_dial_box (_("Rocket ready to launch"),
2602 			_("You can launch it now or wait until later."),
2603 			_("If you wait it will continue costing you money."),
2604 			_("Launch it later by clicking on the rocket area."));
2605 }
2606 
2607 void
display_rocket_result_dialog(int result)2608 display_rocket_result_dialog (int result)
2609 {
2610     switch (result) {
2611     case ROCKET_LAUNCH_BAD:
2612 	ok_dial_box ("launch-fail.mes", BAD, 0L);
2613 	break;
2614     case ROCKET_LAUNCH_GOOD:
2615 	ok_dial_box ("launch-good.mes", GOOD, 0L);
2616 	break;
2617     case ROCKET_LAUNCH_EVAC:
2618 	ok_dial_box ("launch-evac.mes", GOOD, 0L);
2619 	break;
2620     }
2621 }
2622 
2623 void
Fgl_getrect(Rect * r,void * buffer)2624 Fgl_getrect(Rect * r, void * buffer)
2625 {
2626     Fgl_getbox(r->x,r->y,r->w,r->h,buffer);
2627 }
2628 
2629 void
Fgl_putrect(Rect * r,void * buffer)2630 Fgl_putrect(Rect *r, void * buffer)
2631 {
2632     Fgl_putbox(r->x,r->y,r->w,r->h,buffer);
2633 }
2634 
2635