home · contact · privacy
ebda3143de670cb5e6fb73ba91798618686cc885
[plomrogue] / src / map_objects.h
1 /* map_objects.h
2  *
3  * Structs for objects on the map and their type definitions, and routines to
4  * initialize these and load and save them from/to files.
5  */
6
7 #ifndef MAP_OBJECTS_H
8 #define MAP_OBJECTS_H
9
10
11
12 #include <stdio.h> /* for FILE typedef */
13 #include "yx_uint16.h" /* for yx_uint16 coordinates */
14 struct World;
15
16
17
18 /* Player is non-standard: single and of a hard-coded type. */
19
20 struct Player
21 {
22     struct yx_uint16 pos;
23     unsigned char hitpoints;
24 };
25
26
27
28 /* Structs for standard map objects. */
29
30 struct MapObj
31 {
32     void * next;
33     char type;            /* Map object type identifier (see MapObjDef.id). */
34     struct yx_uint16 pos; /* Coordinate of object on map. */
35 };
36
37 struct Item
38 {
39     struct MapObj map_obj;
40 };
41
42 struct Monster
43 {
44     struct MapObj map_obj;
45     unsigned char hitpoints;
46 };
47
48
49
50 /* Structs for map object *type* definitions. Values common to all members of
51  * a single monster or item type are harvested from these.
52  */
53
54 struct MapObjDef
55 {
56     struct MapObjDef * next;
57     char id;      /* Unique identifier of the map object type to describe. */
58     char mapchar; /* Map object symbol to appear on map.*/
59     char * desc;  /* String describing map object in the game log. */
60 };
61
62 struct ItemDef
63 {
64     struct MapObjDef map_obj_def;
65 };
66
67 struct MonsterDef
68 {
69     struct MapObjDef map_obj_def;
70     unsigned char hitpoints_start; /* Hitpoints each monster starts with. */
71 };
72
73
74
75 /* Initialize map object type definitions from file at path "filename". */
76 extern void init_map_object_defs(struct World * world, char * filename);
77
78
79
80 /* Build into memory starting at "start" chain of "n" map objects of type
81  * "def_id", pass either "build_map_objects_itemdata" or
82  * "build_map_objects_monsterdata" as "b_typedata"() to build data specific
83  * to monsters or items (or more forms if they ever get invented).
84  *
85  * TODO: function should decide by itself what "b_typedata"() to call based
86  * on monster-or-item info in MapObjDef struct or from a table mapping type
87  * identifiers to these.
88  */
89 extern void * build_map_objects(struct World * world, void * start, char def_id,
90                                  unsigned char n, size_t size,
91                                  void (*) (struct MapObjDef *, void *));
92 extern void build_map_objects_itemdata(struct MapObjDef * map_obj_def,
93                                        void * start);
94 extern void build_map_objects_monsterdata(struct MapObjDef * map_obj_def,
95                                           void * start);
96
97
98
99 /* Write to/read from file chain of map objects starting/to start in memory at
100  * "start", use "w_typedata"()"/"r_typedata" for data specific to monsters
101  * (pass "write_map_objects_monsterdata"/"read_map_objects_itemdata") or items
102  * (currently they have no data specific only to them, so pass NULL). Use "size"
103  * in read_map_objects() to pass the size of structs of the affected map object
104  * type.
105  *
106  * TODO: the size of these structs should not need to be passed but instead be
107  * available via the type id of the affected map object type. The TODO above
108  * towards the function deciding its helper function by itself also applies.
109  */
110 extern void write_map_objects(void * start, FILE * file,
111                               void (* w_typedata) (void *, FILE *) );
112 extern void read_map_objects(void * start, FILE * file, size_t size,
113                              void (* w_typedata) (void *, FILE *) );
114 extern void write_map_objects_monsterdata(void * start, FILE * file);
115 extern void read_map_objects_monsterdata( void * start, FILE * file);
116
117
118
119 /* Get pointer to the map object definition of identifier "def_id". */
120 extern struct MapObjDef * get_map_obj_def(struct World * world, char def_id);
121
122 #endif