From: Christian Heller Date: Tue, 25 Mar 2014 15:25:43 +0000 (+0100) Subject: Server: Make objects definable as "consumable" to gain n hitpoints. X-Git-Tag: tce~808 X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/static/reset_cookie?a=commitdiff_plain;h=5ae8d71f6b87c0cfc6b3ecf974f2cfbd6a611733;p=plomrogue Server: Make objects definable as "consumable" to gain n hitpoints. This replaces the previous "MAGIC MEAT" hardcoding. --- diff --git a/README b/README index 7963f62..99edb65 100644 --- a/README +++ b/README @@ -93,10 +93,9 @@ this object decomposes to when it gets destroyed/killed, the third value is the ASCII character used to represent the object visually on the map, the fourth value is the number of hitpoints the object starts with (items are dead and start with zero hitpoints, anything else moves), the fifth is the string that -names the object in the game log. Finally, the same delimiter as for the map -object action definitions file follows. Note that the only valid item use so -far, consuming "magic meat" to gain hitpoints, is so far hard-coded (this should -change in the future). +names the object in the game log, the sixth defines if the object is consumable +(it is if it is non-zero) and how many hitpoints are gained if it is. Finally, +the same delimiter as for the map object action definitions file follows. All source files are thoroughly documented to explain more details of plomrogue's internals. The ./roguelike-server executable can be run with a -v diff --git a/TODO b/TODO index 7586040..bc87d09 100644 --- a/TODO +++ b/TODO @@ -22,6 +22,8 @@ SERVER: - for game continuation, replace re-playing of whole record files with loading game state snapshots / save files +- rename confserver/defs to confserver/map_objects + CLIENT: - enable toggling of window borders diff --git a/confserver/defs b/confserver/defs index 3eb9791..2ca0d5c 100644 --- a/confserver/defs +++ b/confserver/defs @@ -1,42 +1,49 @@ 0 5 @ -5 +105 HUMAN +0 %% 1 4 a 1 ANT +0 %% 2 5 z 3 ZOMBIE +0 %% 3 6 S 9 SHOGGOTH +0 %% 4 4 # 0 DIRT +0 %% 5 4 % 0 SKELETON +0 %% 6 4 m 0 MAGIC MEAT +5 %% diff --git a/src/server/map_object_actions.c b/src/server/map_object_actions.c index 694300d..9feab55 100644 --- a/src/server/map_object_actions.c +++ b/src/server/map_object_actions.c @@ -405,7 +405,7 @@ extern void actor_use(struct MapObj * mo) struct MapObj * selected = mo->owns; for (; i != select; i++, selected = selected->next); struct MapObjDef * mod = get_map_object_def(selected->type); - if (!strcmp("MAGIC MEAT", mod->name)) + if (mod->consumable) { wrong_object = 0; struct MapObj * next = selected->next; @@ -421,7 +421,7 @@ extern void actor_use(struct MapObj * mo) { mo->owns = next; } - mo->lifepoints++; + mo->lifepoints = mo->lifepoints + mod->consumable; } } if (mo == get_player()) diff --git a/src/server/map_object_actions.h b/src/server/map_object_actions.h index eec0087..40535a5 100644 --- a/src/server/map_object_actions.h +++ b/src/server/map_object_actions.h @@ -50,8 +50,7 @@ extern void actor_drop(struct MapObj * mo); extern void actor_pick(struct MapObj * mo); /* Actor "mo" tries to use inventory object indexed by number mo->args. - * (Currently the only valid use is consuming an item named "MAGIC MEAT", - * which increments the actors lifepoints.) + * (Currently the only valid use is consuming items defined as consumable.) */ extern void actor_use(struct MapObj * mo); diff --git a/src/server/map_objects.c b/src/server/map_objects.c index 97fbc32..f60cefe 100644 --- a/src/server/map_objects.c +++ b/src/server/map_objects.c @@ -142,6 +142,9 @@ extern void init_map_object_defs() line[strlen(line) - 1] = '\0'; mod->name = try_malloc(strlen(line) + 1, f_name); memcpy(mod->name, line, strlen(line) + 1); + err_try_fgets(line, linemax, file, context, "0nfi"); + err_line(atoi(line) > UINT8_MAX, line, context, err_toolarge); + mod->consumable = atoi(line); * last_mod_ptr_ptr = mod; last_mod_ptr_ptr = &mod->next; err_try_fgets(line, linemax, file, context, "d"); diff --git a/src/server/map_objects.h b/src/server/map_objects.h index a73aa80..f30b016 100644 --- a/src/server/map_objects.h +++ b/src/server/map_objects.h @@ -33,6 +33,7 @@ struct MapObjDef uint8_t id; /* map object definition identifier / sets .type */ uint8_t corpse_id; /* type to change map object into upon destruction */ uint8_t lifepoints; /* default start value for map object's .lifepoints */ + uint8_t consumable; /* can be eaten if !0, for so much hitpoint win */ };