home · contact · privacy
Built error checking into file reading/writing routines and calls of them.
[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 struct Player
20 {
21     struct yx_uint16 pos;
22     unsigned char hitpoints;
23 };
24
25
26
27 /* Structs for standard map objects. */
28
29 struct MapObj
30 {
31     void * next;
32     char type;            /* Map object type identifier (see MapObjDef.id). */
33     struct yx_uint16 pos; /* Coordinate of object on map. */
34 };
35
36 struct Item
37 {
38     struct MapObj map_obj;
39 };
40
41 struct Monster
42 {
43     struct MapObj map_obj;
44     unsigned char hitpoints;
45 };
46
47
48
49 /* Structs for map object *type* definitions. Values common to all members of
50  * a single monster or item type are harvested from these.
51  */
52
53 struct MapObjDef
54 {
55     struct MapObjDef * next;
56     char m_or_i;  /* Is it item or monster? "i" for items, "m" for monsters. */
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".
82  */
83 extern void * build_map_objects(struct World * world, void * start, char def_id,
84                                 unsigned char n);
85
86
87
88 /* Write to/read from file chain of map objects starting/to start in memory at
89  * "start".
90  */
91 extern uint8_t write_map_objects(struct World * world, void * start,
92                                  FILE * file);
93 extern uint8_t read_map_objects(struct World * world, void * start, FILE * file);
94
95
96
97 /* Get pointer to the map object definition of identifier "def_id". */
98 extern struct MapObjDef * get_map_obj_def(struct World * world, char def_id);
99
100
101
102 #endif