home · contact · privacy
Fixed bug that led to endless loop in nearest_enemy_dir().
[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 #include <stdio.h> /* for FILE typedef */
11 #include <stdint.h> /* for uint8_t */
12 #include "yx_uint16.h" /* for yx_uint16 coordinates */
13
14
15
16 struct MapObj
17 {
18     struct MapObj * next;        /* pointer to next one in map object chain */
19     struct MapObj * owns;        /* chain of map objects owned / in inventory */
20     uint8_t id;                  /* individual map object's unique identifier */
21     uint8_t type;                /* ID of appropriate map object definition */
22     uint8_t lifepoints;          /* 0: object is inanimate; >0: hitpoints */
23     struct yx_uint16 pos;        /* coordinate on map */
24     uint8_t command;             /* map object's current action */
25     uint8_t arg;                 /* optional field for .command argument */
26     uint8_t progress;            /* turns already passed to realize .command */
27 };
28
29 struct MapObjDef
30 {
31     struct MapObjDef * next;
32     uint8_t id;         /* map object definition identifier / sets .type */
33     uint8_t corpse_id;  /* type to change map object into upon destruction */
34     char char_on_map;   /* map object symbol to appear on map */
35     char * name;        /* string to describe object in game log */
36     uint8_t lifepoints; /* default start value for map object's .lifepoints */
37 };
38
39
40
41 /* Initialize map object definitions chain from file at path "filename". */
42 extern void init_map_object_defs(char * filename);
43
44 /* Free map object definitions chain starting at "mod_start". */
45 extern void free_map_object_defs(struct MapObjDef * mod_start);
46
47 /* Write map objects chain to "file". */
48 extern void write_map_objects(FILE * file);
49
50 /* Read map objects chain from "file"; use "line" as char array for fgets() and
51  * expect line strings of max. "linemax" length to be read by it.
52  */
53 extern void read_map_objects(FILE * file, char * line, int linemax);
54
55 /* Add object(s) ("n": how many?) of "type" to map on random position(s). New
56  * animate objects are never placed in the same square with other animate ones.
57  */
58 extern void add_map_object(uint8_t type);
59 extern void add_map_objects(uint8_t type, uint8_t n);
60
61 /* Free map objects in map object chain starting at "mo_start. */
62 extern void free_map_objects(struct MapObj * mo_start);
63
64 /* Move object of "id" from "source" inventory to "target" inventory. */
65 extern void own_map_object(struct MapObj ** target, struct MapObj ** source,
66                            uint8_t id);
67
68 /* Get pointer to the MapObj struct that represents the player. */
69 extern struct MapObj * get_player();
70
71 /* Get pointer to the map object definition of identifier "def_id". */
72 extern struct MapObjDef * get_map_object_def(uint8_t id);
73
74 /* Move not only "mo" to "pos", but also all map objects owned by it. */
75 extern void set_object_position(struct MapObj * mo, struct yx_uint16 pos);
76
77
78
79 #endif