3 * Structs for things and their type and action definitions, and routines to
10 #include <stdint.h> /* uint8_t, int16_t */
11 #include "../common/yx_uint8.h" /* yx_uint8 structs */
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 * 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 */
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? */
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 */
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.
57 extern struct ThingAction * add_thing_action(uint8_t id);
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.
63 extern struct ThingType * add_thing_type(int16_t id);
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.
68 extern struct Thing * add_thing(int16_t id, uint8_t type, uint8_t y, uint8_t x);
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);
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);
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);
82 /* Return thing of "id" in chain at "ptr", search inventories too if "deep".
83 * Return NULL if nothing found.
85 extern struct Thing * get_thing(struct Thing * ptr, uint8_t id, uint8_t deep);
87 /* Get pointer to the non-owend Thing struct that represents the player, or NULL
90 extern struct Thing * get_player();
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
96 extern void add_things(uint8_t type, uint8_t n);
98 /* Move thing of "id" from "source" inventory to "target" inventory. */
99 extern void own_thing(struct Thing ** target, struct Thing ** source,
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);