1 /** |
1 /** |
2 * Data structure for defining a map. Note that most maps also depend on the |
2 * Data structure for defining a map. This contains the whole recipe to |
3 * random seed passed to the engine, if you store that in addition to the |
3 * exactly recreate a particular map. For named maps, you also need the |
4 * flib_map structure you have the whole recipe to exactly recreate a particular |
4 * corresponding files. |
5 * map. For named maps, you also need the corresponding files. |
5 * |
|
6 * The required fields depend on the map generator, see the comments |
|
7 * at the struct for details. |
6 */ |
8 */ |
7 |
9 |
8 #ifndef MODEL_MAP_H_ |
10 #ifndef MODEL_MAP_H_ |
9 #define MODEL_MAP_H_ |
11 #define MODEL_MAP_H_ |
10 |
12 |
11 #include <stdint.h> |
13 #include <stdint.h> |
|
14 #include <stdbool.h> |
12 |
15 |
13 #define MAPGEN_REGULAR 0 |
16 #define MAPGEN_REGULAR 0 |
14 #define MAPGEN_MAZE 1 |
17 #define MAPGEN_MAZE 1 |
15 #define MAPGEN_DRAWN 2 |
18 #define MAPGEN_DRAWN 2 |
16 #define MAPGEN_NAMED 3 |
19 #define MAPGEN_NAMED 3 |
30 #define MAZE_SIZE_LARGE_ISLANDS 5 |
33 #define MAZE_SIZE_LARGE_ISLANDS 5 |
31 |
34 |
32 typedef struct { |
35 typedef struct { |
33 int _referenceCount; |
36 int _referenceCount; |
34 int mapgen; // Always one of the MAPGEN_ constants |
37 int mapgen; // Always one of the MAPGEN_ constants |
|
38 char *name; // The name of the map for MAPGEN_NAMED, otherwise one of "+rnd+", "+maze+" or "+drawn+". |
|
39 char *seed; // Used for all maps |
35 char *theme; // Used for all except MAPGEN_NAMED |
40 char *theme; // Used for all except MAPGEN_NAMED |
36 char *name; // Used for MAPGEN_NAMED |
|
37 uint8_t *drawData; // Used for MAPGEN_DRAWN |
41 uint8_t *drawData; // Used for MAPGEN_DRAWN |
38 int drawDataSize; // Used for MAPGEN_DRAWN |
42 int drawDataSize; // Used for MAPGEN_DRAWN |
39 int templateFilter; // Used for MAPGEN_REGULAR |
43 int templateFilter; // Used for MAPGEN_REGULAR |
40 int mazeSize; // Used for MAPGEN_MAZE |
44 int mazeSize; // Used for MAPGEN_MAZE |
41 } flib_map; |
45 } flib_map; |
47 * passing it to the engine. |
51 * passing it to the engine. |
48 * |
52 * |
49 * Use flib_map_destroy to free the returned object. |
53 * Use flib_map_destroy to free the returned object. |
50 * No NULL parameters allowed, returns NULL on failure. |
54 * No NULL parameters allowed, returns NULL on failure. |
51 */ |
55 */ |
52 flib_map *flib_map_create_regular(const char *theme, int templateFilter); |
56 flib_map *flib_map_create_regular(const char *seed, const char *theme, int templateFilter); |
53 |
57 |
54 /** |
58 /** |
55 * Create a generated maze-type map. theme should be the name of a |
59 * Create a generated maze-type map. theme should be the name of a |
56 * directory in "Themes" and mazeSize should be one of the |
60 * directory in "Themes" and mazeSize should be one of the |
57 * MAZE_SIZE_* constants, but this is not checked before |
61 * MAZE_SIZE_* constants, but this is not checked before |
58 * passing it to the engine. |
62 * passing it to the engine. |
59 * |
63 * |
60 * Use flib_map_destroy to free the returned object. |
64 * Use flib_map_destroy to free the returned object. |
61 * No NULL parameters allowed, returns NULL on failure. |
65 * No NULL parameters allowed, returns NULL on failure. |
62 */ |
66 */ |
63 flib_map *flib_map_create_maze(const char *theme, int mazeSize); |
67 flib_map *flib_map_create_maze(const char *seed, const char *theme, int mazeSize); |
64 |
68 |
65 /** |
69 /** |
66 * Create a map from the Maps-Directory. name should be the name of a |
70 * Create a map from the Maps-Directory. name should be the name of a |
67 * directory in "Maps", but this is not checked before |
71 * directory in "Maps", but this is not checked before |
68 * passing it to the engine. If this is a mission, the corresponding |
72 * passing it to the engine. If this is a mission, the corresponding |
69 * script is used automatically. |
73 * script is used automatically. |
70 * |
74 * |
71 * Use flib_map_destroy to free the returned object. |
75 * Use flib_map_destroy to free the returned object. |
72 * No NULL parameters allowed, returns NULL on failure. |
76 * No NULL parameters allowed, returns NULL on failure. |
73 */ |
77 */ |
74 flib_map *flib_map_create_named(const char *name); |
78 flib_map *flib_map_create_named(const char *seed, const char *name); |
75 |
79 |
76 /** |
80 /** |
77 * Create a hand-drawn map. Use flib_map_destroy to free the returned object. |
81 * Create a hand-drawn map. Use flib_map_destroy to free the returned object. |
78 * No NULL parameters allowed, returns NULL on failure. |
82 * No NULL parameters allowed, returns NULL on failure. |
79 */ |
83 */ |
80 flib_map *flib_map_create_drawn(const char *theme, const uint8_t *drawData, int drawDataSize); |
84 flib_map *flib_map_create_drawn(const char *seed, const char *theme, const uint8_t *drawData, int drawDataSize); |
|
85 |
|
86 /** |
|
87 * Create a deep copy of the map. Returns NULL on failure or if NULL was passed. |
|
88 */ |
|
89 flib_map *flib_map_copy(const flib_map *map); |
81 |
90 |
82 /** |
91 /** |
83 * Increase the reference count of the object. Call this if you store a pointer to it somewhere. |
92 * Increase the reference count of the object. Call this if you store a pointer to it somewhere. |
84 * Returns the parameter. |
93 * Returns the parameter. |
85 */ |
94 */ |