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.
12 #include <stdio.h> /* for FILE typedef */
13 #include "yx_uint16.h" /* for yx_uint16 coordinates */
18 /* Player is non-standard: single and of a hard-coded type. */
22 unsigned char hitpoints;
27 /* Structs for standard map objects. */
32 char type; /* Map object type identifier (see MapObjDef.id). */
33 struct yx_uint16 pos; /* Coordinate of object on map. */
38 struct MapObj map_obj;
43 struct MapObj map_obj;
44 unsigned char hitpoints;
49 /* Structs for map object *type* definitions. Values common to all members of
50 * a single monster or item type are harvested from these.
55 struct MapObjDef * next;
56 char id; /* Unique identifier of the map object type to describe. */
57 char mapchar; /* Map object symbol to appear on map.*/
58 char * desc; /* String describing map object in the game log. */
63 struct MapObjDef map_obj_def;
68 struct MapObjDef map_obj_def;
69 unsigned char hitpoints_start; /* Hitpoints each monster starts with. */
74 /* Initialize map object type definitions from file at path "filename". */
75 extern void init_map_object_defs(struct World * world, char * filename);
79 /* Build into memory starting at "start" chain of "n" map objects of type
80 * "def_id", pass either "build_map_objects_itemdata" or
81 * "build_map_objects_monsterdata" as "b_typedata"() to build data specific
82 * to monsters or items (or more forms if they ever get invented).
84 * TODO: function should decide by itself what "b_typedata"() to call based
85 * on monster-or-item info in MapObjDef struct or from a table mapping type
86 * identifiers to these.
88 extern void * build_map_objects(struct World * world, void * start, char def_id,
89 unsigned char n, size_t size,
90 void (*) (struct MapObjDef *, void *));
91 extern void build_map_objects_itemdata(struct MapObjDef * map_obj_def,
93 extern void build_map_objects_monsterdata(struct MapObjDef * map_obj_def,
98 /* Write to/read from file chain of map objects starting/to start in memory at
99 * "start", use "w_typedata"()"/"r_typedata" for data specific to monsters
100 * (pass "write_map_objects_monsterdata"/"read_map_objects_itemdata") or items
101 * (currently they have no data specific only to them, so pass NULL). Use "size"
102 * in read_map_objects() to pass the size of structs of the affected map object
105 * TODO: the size of these structs should not need to be passed but instead be
106 * available via the type id of the affected map object type. The TODO above
107 * towards the function deciding its helper function by itself also applies.
109 extern void write_map_objects(void * start, FILE * file,
110 void (* w_typedata) (void *, FILE *) );
111 extern void read_map_objects(void * start, FILE * file, size_t size,
112 void (* w_typedata) (void *, FILE *) );
113 extern void write_map_objects_monsterdata(void * start, FILE * file);
114 extern void read_map_objects_monsterdata( void * start, FILE * file);
118 /* Get pointer to the map object definition of identifier "def_id". */
119 extern struct MapObjDef * get_map_obj_def(struct World * world, char def_id);