1 #ifndef __MISC_H 2 #define __MISC_H 3 4 #include "list.h" 5 #include <stdio.h> 6 7 /* compare strings */ 8 #define STRCMP( str1, str2 ) ( strlen( str1 ) == strlen( str2 ) && !strncmp( str1, str2, strlen( str1 ) ) ) 9 10 #define AXIS 0 11 #define ALLIES 1 12 #ifdef CMDLINE_ONLY 13 # define CLASS_COUNT 18 14 #else 15 # define CLASS_COUNT 14 16 #endif 17 #define SCEN_COUNT 38 18 19 /* unitlib entry */ 20 typedef struct { 21 char id[8]; 22 char name[24]; 23 int side; /* either axis(0) or allies(1) determined 24 from mirror index list which are the allied 25 units */ 26 int nid; /* the same as id, but stored as an integer */ 27 #ifdef CMDLINE_ONLY 28 int tgttype; 29 int class; 30 int nation; 31 int start_year, start_month; 32 int last_year; 33 #endif 34 } UnitLib_Entry; 35 36 /* reinforcement */ 37 typedef struct { 38 int pin; /* PIN to identify unit when removing */ 39 int uid; /* numerical unit id */ 40 char id[8]; /* unit id */ 41 int tid; /* numerical transport id */ 42 char trp[8]; /* transporter id */ 43 char info[128]; /* info string */ 44 int delay; 45 int str; 46 int exp; 47 int nation; /* nation id */ 48 UnitLib_Entry *entry, *trp_entry; 49 /* to reselect unit properties from reinf list */ 50 int class_id; 51 int unit_id; 52 int trp_id; 53 } Unit; 54 55 /* 56 ==================================================================== 57 Load/save reinforcement resources 58 ==================================================================== 59 */ 60 int load_reinf(); 61 int save_reinf(); 62 63 /* 64 ==================================================================== 65 Build LGC-PG reinforcements file. 66 ==================================================================== 67 */ 68 void build_reinf(); 69 70 /* 71 ==================================================================== 72 Inititate application and load resources. 73 ==================================================================== 74 */ 75 void init(); 76 77 /* 78 ==================================================================== 79 Cleanup 80 ==================================================================== 81 */ 82 void finalize(); 83 84 /* 85 ==================================================================== 86 Copy source to dest and at maximum limit chars. Terminate with 0. 87 ==================================================================== 88 */ 89 void strcpy_lt( char *dest, char *src, int limit ); 90 91 /* 92 ==================================================================== 93 Convert string to scenario id. Returns -1 if invalid. 94 ==================================================================== 95 */ 96 int to_scenario(const char *str); 97 98 /* 99 ==================================================================== 100 Convert string to side id. Returns -1 if invalid. 101 ==================================================================== 102 */ 103 int to_side(const char *str); 104 105 /* 106 ==================================================================== 107 Convert string to nation id. Returns -1 if invalid. 108 ==================================================================== 109 */ 110 int to_nation(const char *str); 111 112 /* 113 ==================================================================== 114 Convert string to unit class id. Returns -1 if invalid. 115 ==================================================================== 116 */ 117 int to_unit_class(const char *str); 118 119 /* 120 ==================================================================== 121 Convert string to target type id. Returns -1 if invalid. 122 ==================================================================== 123 */ 124 int to_target_type(const char *str); 125 126 /* 127 ==================================================================== 128 Returns the side this nation typically belongs to. 129 0 is axis, 1 is allied. 130 ==================================================================== 131 */ 132 int nation_to_side(int nation); 133 134 /* 135 ==================================================================== 136 Returns the total count of units. 137 ==================================================================== 138 */ 139 int unit_count(); 140 141 /* 142 ==================================================================== 143 Returns the unit with the given id or 0 if not found. 144 Don't call this while iterating all units by iterate_units_next() 145 ==================================================================== 146 */ 147 UnitLib_Entry *find_unit_by_id(int id); 148 149 /* 150 ==================================================================== 151 Starts iterating the unit database. 152 ==================================================================== 153 */ 154 void iterate_units_begin(void); 155 156 /* 157 ==================================================================== 158 Returns the next unit or 0 if end reached. 159 ==================================================================== 160 */ 161 UnitLib_Entry *iterate_units_next(void); 162 163 #ifndef CMDLINE_ONLY 164 /* 165 ==================================================================== 166 Update unit/transporters/reinf list 167 ==================================================================== 168 */ 169 void update_unit_list( int player, int unit_class ); 170 void update_trp_list( int player ); 171 void update_reinf_list( int scen, int player ); 172 #endif 173 174 /* 175 ==================================================================== 176 Read all lines from file. 177 ==================================================================== 178 */ 179 List* file_read_lines( FILE *file ); 180 181 /* 182 ==================================================================== 183 Build units info string. 184 ==================================================================== 185 */ 186 void build_unit_info( Unit *unit, int player ); 187 188 /* 189 ==================================================================== 190 Insert a new reinforcement unit into the reinforcements array. 191 ==================================================================== 192 */ 193 void insert_reinf_unit( Unit *unit, int player, int scenario ); 194 195 #ifdef CMDLINE_ONLY 196 /* 197 ==================================================================== 198 Return the directory the game data is installed under. 199 ==================================================================== 200 */ 201 const char *get_gamedir(void); 202 #endif 203 204 #endif 205