home · contact · privacy
Load last world state from save file, not from re-stepping record file.
[plomrogue] / src / server / things.h
1 /* src/server/things.h
2  *
3  * Structs for things and their type definitions, and routines to initialize
4  * these and load and save them from/to files.
5  */
6
7 #ifndef THINGS_H
8 #define THINGS_H
9
10 #include <stdint.h> /* uint8_t */
11 #include "../common/yx_uint8.h" /* yx_uint8 structs */
12
13
14
15 struct Thing
16 {
17     struct Thing * next;         /* pointer to next one in things chain */
18     struct Thing * owns;         /* chain of things owned / in inventory */
19     struct yx_uint8 pos;         /* coordinate on map */
20     uint8_t * fov_map;           /* map of the thing's field of view */
21     uint8_t id;                  /* individual thing's unique identifier */
22     uint8_t type;                /* ID of appropriate thing definition */
23     uint8_t lifepoints;          /* 0: thing is inanimate; >0: hitpoints */
24     uint8_t command;             /* thing's current action; 0 if none */
25     uint8_t arg;                 /* optional field for .command argument */
26     uint8_t progress;            /* turns already passed to realize .command */
27 };
28
29 struct ThingType
30 {
31     uint8_t id;         /* thing type identifier / sets .type */
32     struct ThingType * next;
33     char char_on_map;   /* thing symbol to appear on map */
34     char * name;        /* string to describe thing in game log */
35     uint8_t corpse_id;  /* type to change thing into upon destruction */
36     uint8_t lifepoints; /* default start value for thing's .lifepoints */
37     uint8_t consumable; /* can be eaten if !0, for so much hitpoint win */
38     uint8_t start_n;    /* how many of these does the map start with? */
39 };
40
41
42
43 /* Return thing of "id" in chain at "ptr", search inventories too if "deep". */
44 extern struct Thing * get_thing(struct Thing * ptr, uint8_t id, uint8_t deep);
45
46 /* Free thing types chain starting at "tt_start". */
47 extern void free_thing_types(struct ThingType * tt_start);
48
49 /* Add thing of "id" and "type" to map on random passable position (positions
50  * which contain an actor are not deemed passable) if "find_pos", else on y=0,
51  * x=0. If "id" is >= 0 and <= UINT8_MAX, use lowest unused id. Return thing.
52  */
53 extern struct Thing * add_thing(int16_t id, uint8_t type, uint8_t find_pos);
54
55 /* Add thing(s) ("n": how many?) of "type" to map on random position(s). New
56  * animate things are never placed in the same square with other animate ones.
57  */
58 extern void add_things(uint8_t type, uint8_t n);
59
60 /* Free things in things chain starting at "t_start. */
61 extern void free_things(struct Thing * t_start);
62
63 /* Move thing of "id" from "source" inventory to "target" inventory. */
64 extern void own_thing(struct Thing ** target, struct Thing ** source,
65                       uint8_t id);
66
67 /* Get pointer to the Thing struct that represents the player. */
68 extern struct Thing * get_player();
69
70 /* Get pointer to the thing type of identifier "def_id". */
71 extern struct ThingType * get_thing_type(uint8_t id);
72
73 /* Move not only "t" to "pos", but also all things owned by it. */
74 extern void set_thing_position(struct Thing * t, struct yx_uint8 pos);
75
76
77
78 #endif