home · contact · privacy
a56595f79aaad4c7358b092c22817fca3f66b7db
[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 <stdint.h> /* for uint8_t */
14 #include "yx_uint16.h" /* for yx_uint16 coordinates */
15 struct World;
16
17
18
19 struct MapObj
20 {
21     struct MapObj * next;        /* pointer to next one in map object chain */
22     uint8_t id;                  /* individual map object's unique identifier */
23     uint8_t type;                /* ID of appropriate map object definition */
24     uint8_t lifepoints;          /* 0: object is inanimate; >0: hitpoints */
25     struct yx_uint16 pos;        /* coordinate on map */
26 };
27
28
29
30 struct MapObjDef
31 {
32     struct MapObjDef * next;
33     uint8_t id;         /* unique identifier of map object type */
34     uint8_t corpse_id;  /* id of type to change into upon destruction */
35     char char_on_map;   /* map object symbol to appear on map */
36     char * name;        /* string to describe object in game log*/
37     uint8_t lifepoints; /* default value for map object lifepoints member */
38 };
39
40
41
42 /* Initialize map object defnitions chain from file at path "filename". */
43 extern void init_map_object_defs(struct World * world, char * filename);
44
45
46
47 /* Free map object definitions chain starting at "mod_start". */
48 extern void free_map_object_defs(struct MapObjDef * mod_start);
49
50
51
52 /* Add new object(s) ("n": how many?) of "type" to map on random position(s). */
53 extern void add_map_object(struct World * world, uint8_t type);
54 extern void add_map_objects(struct World * world, uint8_t type, uint8_t n);
55
56
57
58 /* Write map objects chain to "file". */
59 extern void write_map_objects(struct World * world, FILE * file);
60
61 /* Read from "file" map objects chain; use "line" as char array for fgets() and
62  * expect strings of max. "linemax" length.
63  */
64 extern void read_map_objects(struct World * world, FILE * file,
65                              char * line, int linemax);
66
67
68
69 /* Free map objects in map object chain starting at "mo_start. */
70 extern void free_map_objects(struct MapObj * mo_start);
71
72
73
74 /* Get pointer to the MapObj struct that represents the player. */
75 extern struct MapObj * get_player(struct World * world);
76
77
78
79 /* Get pointer to the map object definition of identifier "def_id". */
80 extern struct MapObjDef * get_map_object_def(struct World * w, uint8_t id);
81
82
83
84 #endif