This commit is contained in:
Richard
2026-03-26 18:43:01 +01:00
commit 9616a8236b
25 changed files with 2773 additions and 0 deletions

26
farm/maps.c Normal file
View File

@@ -0,0 +1,26 @@
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
#include "maps.h"
struct Maps* load_maps(char* filename) {
FILE* f = fopen(filename, "r");
if (f == NULL) {
return NULL;
}
int num_maps;
int num_read = fread(&num_maps, 4, 1, f);
if (num_read != 1 || num_maps > 10000) {
return NULL;
}
int mapfile_size = sizeof(struct Map) * num_maps;
struct Maps *maps = (struct Maps *)malloc(mapfile_size + 4);
maps->num_maps = num_maps;
num_read = fread(&maps->maps, 1, mapfile_size, f);
if (num_read != mapfile_size) {
return NULL;
}
fclose(f);
return maps;
}