1 /***************************************************************************
2 nations.h - description
3 -------------------
4 begin : Tue Mar 12 2002
5 copyright : (C) 2001 by Michael Speck
6 email : kulkanie@gmx.net
7 ***************************************************************************/
8
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21 #include "misc.h"
22 #include "shp.h"
23 #include "nations.h"
24
25 /*
26 ====================================================================
27 Externals
28 ====================================================================
29 */
30 extern char *source_path;
31 extern char *dest_path;
32 extern char target_name[128];
33
34 /*
35 ====================================================================
36 Nations.
37 ====================================================================
38 */
39 int nation_count = 24;
40 char *nations[] = {
41 "aus", "Austria", "0",
42 "bel", "Belgia", "1",
43 "bul", "Bulgaria", "2",
44 "lux", "Luxemburg", "3",
45 "den", "Denmark", "4",
46 "fin", "Finnland", "5",
47 "fra", "France", "6",
48 "ger", "Germany", "7",
49 "gre", "Greece", "8",
50 "usa", "USA", "9",
51 "hun", "Hungary", "10",
52 "tur", "Turkey", "11",
53 "it", "Italy", "12",
54 "net", "Netherlands", "13",
55 "nor", "Norway", "14",
56 "pol", "Poland", "15",
57 "por", "Portugal", "16",
58 "rum", "Rumania", "17",
59 "esp", "Spain", "18",
60 "so", "Sovjetunion", "19",
61 "swe", "Sweden", "20",
62 "swi", "Switzerland", "21",
63 "eng", "Great Britain", "22",
64 "yug", "Yugoslavia", "23"
65 };
66
67 /*
68 ====================================================================
69 Create nations database and convert graphics.
70 Only called when converting full campaign. For custom campaigns only
71 flags may differ as nation definitions are hardcoded in converter to
72 PG nations.
73 ====================================================================
74 */
nations_convert(void)75 int nations_convert( void )
76 {
77 int i, height = 0;
78 FILE *file;
79 char path[MAXPATHLEN];
80 SDL_Rect srect, drect;
81 PG_Shp *shp =0;
82 SDL_Surface *surf = 0;
83 Uint32 ckey = MAPRGB( CKEY_RED, CKEY_GREEN, CKEY_BLUE ); /* transparency key */
84
85 /* nation database */
86 printf( "Nation database...\n" );
87 snprintf( path, MAXPATHLEN, "%s/nations/%s.ndb", dest_path, target_name );
88 if ( ( file = fopen( path, "wb" ) ) == 0 ) {
89 fprintf( stderr, "%s: access denied\n", path );
90 return 0;
91 }
92 fprintf( file, "@\n" );
93 fprintf( file, "icons�%s.bmp\n", target_name );
94 fprintf( file, "icon_width�20\nicon_height�13\n" );
95 /* domain */
96 fprintf( file, "domain�pg\n" );
97 fprintf( file, "<nations\n" );
98 for ( i = 0; i < nation_count; i++ )
99 fprintf( file, "<%s\nname�%s\nicon_id�%s\n>\n", nations[i * 3], nations[i * 3 + 1], nations[i * 3 + 2] );
100 fprintf( file, ">\n" );
101 fclose( file );
102
103 /* nation graphics */
104 printf( "Nation flag graphics...\n" );
105 /* create new surface */
106 if ( ( shp = shp_load( "FLAGS.SHP" ) ) == 0 )
107 return 0;
108 for ( i = 0; i < nation_count; i++ )
109 if ( shp->headers[i].valid )
110 height += shp->headers[i].actual_height;
111 surf = SDL_CreateRGBSurface( SDL_SWSURFACE, shp->headers[0].actual_width, height, shp->surf->format->BitsPerPixel,
112 shp->surf->format->Rmask, shp->surf->format->Gmask, shp->surf->format->Bmask,
113 shp->surf->format->Amask );
114 if ( surf == 0 ) {
115 fprintf( stderr, "error creating surface: %s\n", SDL_GetError() );
116 goto failure;
117 }
118 SDL_FillRect( surf, 0, ckey );
119 /* copy flags */
120 srect.w = drect.w = shp->headers[0].actual_width;
121 srect.h = drect.h = shp->headers[0].actual_height;
122 height = 0;
123 for ( i = 0; i < nation_count; i++ ) {
124 srect.x = shp->headers[i].x1;
125 srect.y = shp->headers[i].y1 + shp->offsets[i];
126 drect.x = 0;
127 drect.y = height;
128 SDL_BlitSurface( shp->surf, &srect, surf, &drect );
129 height += shp->headers[i].actual_height;
130 }
131 snprintf( path, MAXPATHLEN, "%s/gfx/flags/%s.bmp", dest_path, target_name );
132 if ( SDL_SaveBMP( surf, path ) ) {
133 fprintf( stderr, "%s: %s\n", path, SDL_GetError() );
134 goto failure;
135 }
136 SDL_FreeSurface( surf );
137 shp_free( &shp );
138 return 1;
139 failure:
140 if ( surf ) SDL_FreeSurface( surf );
141 if ( shp ) shp_free( &shp );
142 return 0;
143 }
144