home · contact · privacy
ea37a81487160471b85bd8746c270380b1fc4de7
[plomrogue] / src / server / things.h
1 /* src/server/things.h
2  *
3  * Structs for things and their type and action definitions, and routines to
4  * initialize these.
5  */
6
7 #ifndef THINGS_H
8 #define THINGS_H
9
10 #include <stdint.h> /* uint8_t, int16_t */
11 #include "../common/yx_uint8.h" /* yx_uint8 structs */
12
13
14
15 struct Thing
16 {
17     struct Thing * next;
18     uint8_t id;                  /* individual thing's unique identifier */
19     struct Thing * owns;         /* chain of things owned / in inventory */
20     struct yx_uint8 pos;         /* coordinate on map */
21     char * fov_map;              /* thing's FOV map; 'v':visible, 'H':hidden */
22     char * mem_map;              /* map knowledge of thing by FOV and memory */
23     uint8_t type;                /* ID of appropriate thing definition */
24     uint8_t lifepoints;          /* 0: thing is inanimate; >0: hitpoints */
25     uint8_t command;             /* thing's current action; 0 if none */
26     uint8_t arg;                 /* optional field for .command argument */
27     uint8_t progress;            /* turns already passed to realize .command */
28 };
29
30 struct ThingType
31 {
32     struct ThingType * next;
33     uint8_t id;         /* thing type identifier / sets .type */
34     char char_on_map;   /* thing symbol to appear on map */
35     char * name;        /* string to describe thing in game log */
36     uint8_t corpse_id;  /* type to change thing into upon destruction */
37     uint8_t lifepoints; /* default start value for thing's .lifepoints */
38     uint8_t consumable; /* can be eaten if !0, for so much hitpoint win */
39     uint8_t start_n;    /* how many of these does the map start with? */
40 };
41
42 struct ThingAction
43 {
44     struct ThingAction * next;
45     uint8_t id;   /* identifies action in Thing.command; therefore must be >0 */
46     void (* func) (struct Thing *);    /* function called after .effort turns */
47     char * name;                       /* human-readable identifier */
48     uint8_t effort;                    /* how many turns the action takes */
49 };
50
51
52
53 /* Add thing action of "id" to world.thing_actions, with .name defaulting to
54  * s[S_CMD_WAIT], .func to actor_wait() and .effort to 1. If "id" is not >= 1
55  * and <= UINT8_MAX, use lowest unused id. Return thing action.
56  */
57 extern struct ThingAction * add_thing_action(uint8_t id);
58
59 /* Add thing type of "id" to world.thing_types, with .corpse_id defaulting to
60  * the new thing type's .id, .name to "(none)" and the remaining values to 0. If
61  * "id" is not >= 0 and <= UINT8_MAX, use lowest unused id. Return thing type.
62  */
63 extern struct ThingType * add_thing_type(int16_t id);
64
65 /* Add thing of "id" and "type" on position of "y"/x" to world.things. If "id"
66  * is not >= 0 and <= UINT8_MAX, use lowest unused id. Return thing.
67  */
68 extern struct Thing * add_thing(int16_t id, uint8_t type, uint8_t y, uint8_t x);
69
70 /* Free ThingAction/ThingType/Thing * chain starting at "ta"/"tt"/"t". */
71 extern void free_thing_actions(struct ThingAction * ta);
72 extern void free_thing_types(struct ThingType * tt);
73 extern void free_things(struct Thing * t);
74
75 /* Return pointer to ThingAction/ThingType of "id", or NULL if none found. */
76 extern struct ThingAction * get_thing_action(uint8_t id);
77 extern struct ThingType * get_thing_type(uint8_t id);
78
79 /* Return world.thing_actions ThingAction.id for "name" or 0 if none found. */
80 extern uint8_t get_thing_action_id_by_name(char * name);
81
82 /* Return thing of "id" in chain at "ptr", search inventories too if "deep".
83  * Return NULL if nothing found.
84  */
85 extern struct Thing * get_thing(struct Thing * ptr, uint8_t id, uint8_t deep);
86
87 /* Get pointer to the non-owend Thing struct that represents the player, or NULL
88  * if none found.
89  */
90 extern struct Thing * get_player();
91
92 /* Add thing(s) ("n": how many?) of "type" to map on random passable
93  * position(s). New animate things are never placed in the same square with
94  * other animate ones.
95  */
96 extern void add_things(uint8_t type, uint8_t n);
97
98 /* Move thing of "id" from "source" inventory to "target" inventory. */
99 extern void own_thing(struct Thing ** target, struct Thing ** source,
100                       uint8_t id);
101
102 /* Move not only "t" to "pos", but also all things owned by it. */
103 extern void set_thing_position(struct Thing * t, struct yx_uint8 pos);
104
105
106
107 #endif