home · contact · privacy
d5ef508a4aa5bd3034aa2e182d2ead9bd47265b3
[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     uint8_t * fov_map;           /* map of the thing's field of view */
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     struct ThingType * next;
32     uint8_t id;         /* thing type identifier / sets .type */
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 struct ThingAction
42 {
43     struct ThingAction * next;
44     uint8_t id;   /* identifies action in Thing.command; therefore must be >0 */
45     void (* func) (struct Thing *);    /* function called after .effort turns */
46     char * name;                       /* human-readable identifier */
47     uint8_t effort;                    /* how many turns the action takes */
48 };
49
50
51
52 /* Add thing action of "id" to world.thing_actions, with .name defaulting to
53  * s[S_CMD_WAIT], .func to actor_wait() and .effort to 1. If "id" is not >= 1
54  * and <= UINT8_MAX, use lowest unused id. Return thing action.
55  */
56 extern struct ThingAction * add_thing_action(uint8_t id);
57
58 /* Add thing type of "id" to world.thing_types, with .corpse_id defaulting to
59  * the new thing type's .id, .name to "(none)" and the remaining values to 0. If
60  * "id" is not >= 0 and <= UINT8_MAX, use lowest unused id. Return thing type.
61  */
62 extern struct ThingType * add_thing_type(int16_t id);
63
64 /* Add thing of "id" and "type" on position of "y"/x" to world.things. If "id"
65  * is not >= 0 and <= UINT8_MAX, use lowest unused id. Return thing.
66  */
67 extern struct Thing * add_thing(int16_t id, uint8_t type, uint8_t y, uint8_t x);
68
69 /* Free ThingAction/ThingType/Thing * chain starting at "ta"/"tt"/"t". */
70 extern void free_thing_actions(struct ThingAction * ta);
71 extern void free_thing_types(struct ThingType * tt);
72 extern void free_things(struct Thing * t);
73
74 /* Return pointer to ThingAction/ThingType of "id", or NULL if none found. */
75 extern struct ThingAction * get_thing_action(uint8_t id);
76 extern struct ThingType * get_thing_type(uint8_t id);
77
78 /* Return world.thing_actions ThingAction.id for "name" or 0 if none found. */
79 extern uint8_t get_thing_action_id_by_name(char * name);
80
81 /* Return thing of "id" in chain at "ptr", search inventories too if "deep".
82  * Return NULL if nothing found.
83  */
84 extern struct Thing * get_thing(struct Thing * ptr, uint8_t id, uint8_t deep);
85
86 /* Get pointer to the non-owend Thing struct that represents the player, or NULL
87  * if none found.
88  */
89 extern struct Thing * get_player();
90
91 /* Add thing(s) ("n": how many?) of "type" to map on random passable
92  * position(s). New animate things are never placed in the same square with
93  * other animate ones.
94  */
95 extern void add_things(uint8_t type, uint8_t n);
96
97 /* Move thing of "id" from "source" inventory to "target" inventory. */
98 extern void own_thing(struct Thing ** target, struct Thing ** source,
99                       uint8_t id);
100
101 /* Move not only "t" to "pos", but also all things owned by it. */
102 extern void set_thing_position(struct Thing * t, struct yx_uint8 pos);
103
104
105
106 #endif