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. */
23 unsigned char hitpoints;
28 /* Structs for standard map objects. */
33 char type; /* Map object type identifier (see MapObjDef.id). */
34 struct yx_uint16 pos; /* Coordinate of object on map. */
39 struct MapObj map_obj;
44 struct MapObj map_obj;
45 unsigned char hitpoints;
50 /* Structs for map object *type* definitions. Values common to all members of
51 * a single monster or item type are harvested from these.
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. */
64 struct MapObjDef map_obj_def;
69 struct MapObjDef map_obj_def;
70 unsigned char hitpoints_start; /* Hitpoints each monster starts with. */
75 /* Initialize map object type definitions from file at path "filename". */
76 extern void init_map_object_defs(struct World * world, char * filename);
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).
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.
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,
94 extern void build_map_objects_monsterdata(struct MapObjDef * map_obj_def,
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
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.
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);
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);