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