* Load a city file from a given filename and (optionally) directory. * @param filename Name of the file to load. * @param dir If not \c NULL, name of the directory containing the file. * @return Load was succesfull. */
| 201 | * @return Load was succesfull. |
| 202 | */ |
| 203 | bool Micropolis::loadFileDir(const char *filename, const char *dir) |
| 204 | { |
| 205 | char *path = NULL; |
| 206 | FILE *f; |
| 207 | Quad size; |
| 208 | |
| 209 | // If needed, construct a path to the file. |
| 210 | if (dir != NULL) { |
| 211 | path = (char *)malloc(strlen(dir) + 1 + strlen(filename) + 1); |
| 212 | sprintf(path, "%s/%s", dir, filename); |
| 213 | filename = path; |
| 214 | } |
| 215 | |
| 216 | // Open the file. |
| 217 | f = fopen(filename, "rb"); |
| 218 | |
| 219 | // Before checking whether open() succeeded, first drop the path. |
| 220 | if (path != NULL) { |
| 221 | free(path); |
| 222 | } |
| 223 | |
| 224 | // open() failed; report failure. |
| 225 | if (f == NULL) { |
| 226 | return false; |
| 227 | } |
| 228 | |
| 229 | fseek(f, 0L, SEEK_END); |
| 230 | size = ftell(f); |
| 231 | fseek(f, 0L, SEEK_SET); |
| 232 | |
| 233 | bool result = |
| 234 | (size == 27120) && |
| 235 | load_short(resHist, HISTORY_LENGTH / sizeof(short), f) && |
| 236 | load_short(comHist, HISTORY_LENGTH / sizeof(short), f) && |
| 237 | load_short(indHist, HISTORY_LENGTH / sizeof(short), f) && |
| 238 | load_short(crimeHist, HISTORY_LENGTH / sizeof(short), f) && |
| 239 | load_short(pollutionHist, HISTORY_LENGTH / sizeof(short), f) && |
| 240 | load_short(moneyHist, HISTORY_LENGTH / sizeof(short), f) && |
| 241 | load_short(miscHist, MISC_HISTORY_LENGTH / sizeof(short), f) && |
| 242 | load_short(((short *)&map[0][0]), WORLD_W * WORLD_H, f); |
| 243 | |
| 244 | fclose(f); |
| 245 | |
| 246 | return result; |
| 247 | } |
| 248 | |
| 249 | /** |
| 250 | * Load a file, and initialize the game variables. |
nothing calls this directly
no test coverage detected