From: Christian Heller Date: Sun, 1 Dec 2013 03:22:27 +0000 (+0100) Subject: Some refactoring in map_object_actions library. X-Git-Tag: tce~900 X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/decks/%7B%7Bdeck_id%7D%7D?a=commitdiff_plain;h=ea9dd0ae82153bf07b6c0fe2927548afea57e833;p=plomrogue Some refactoring in map_object_actions library. --- diff --git a/src/map_object_actions.c b/src/map_object_actions.c index 7059863..5ba99c0 100644 --- a/src/map_object_actions.c +++ b/src/map_object_actions.c @@ -1,7 +1,7 @@ /* map_object_actions.c */ #include "map_object_actions.h" -#include /* for uint8_t */ +#include /* for uint8_t, uint16_t */ #include /* for strlen(), strcmp() */ #include "yx_uint16.h" /* for yx_uint16 struct, mv_yx_in_dir(), * yx_uint16_cmp() @@ -78,14 +78,12 @@ static void actor_hits_actor(struct MapObj * hitter, struct MapObj * hitted) if (player == hitted) { update_log(" You die."); + return; } - else + update_log(" It dies."); + if (player == hitter) { - update_log(" It dies."); - if (player == hitter) - { - world.score = world.score + mod_hitted->lifepoints; - } + world.score = world.score + mod_hitted->lifepoints; } } } @@ -131,15 +129,10 @@ static void playerbonus_drop(uint8_t owns_none) if (0 != owns_none) { update_log("\nYou try to drop an object, but you own none."); + return; } - else - { - update_log("\nYou drop an object."); - if (0 < world.inventory_sel) - { - world.inventory_sel--; - } - } + update_log("\nYou drop an object."); + world.inventory_sel = world.inventory_sel - (0 < world.inventory_sel); } @@ -149,11 +142,9 @@ static void playerbonus_pick(uint8_t picked) if (picked) { update_log("\nYou pick up an object."); + return; } - else - { - update_log("\nYou try to pick up an object, but there is none."); - } + update_log("\nYou try to pick up an object, but there is none."); } @@ -163,19 +154,15 @@ static void playerbonus_use(uint8_t no_object, uint8_t wrong_object) if (no_object) { update_log("\nYou try to use an object, but you own none."); + return; } else if (wrong_object) { update_log("\nYou try to use this object, but fail."); + return; } - else - { - update_log("\nYou consume MAGIC MEAT."); - if (0 < world.inventory_sel) - { - world.inventory_sel--; - } - } + update_log("\nYou consume MAGIC MEAT."); + world.inventory_sel = world.inventory_sel - (0 < world.inventory_sel); } @@ -183,12 +170,10 @@ static void playerbonus_use(uint8_t no_object, uint8_t wrong_object) extern void init_map_object_actions() { char * f_name = "init_map_object_actions()"; - char * path = "config/map_object_actions"; FILE * file = try_fopen(path, "r", f_name); uint16_t linemax = textfile_sizes(file, NULL); char line[linemax + 1]; - struct MapObjAct ** moa_ptr_ptr = &world.map_obj_acts; char * delim = " "; while (fgets(line, linemax + 1, file)) @@ -351,9 +336,8 @@ extern void actor_use(struct MapObj * mo) if (0 < select) { select--; - for (i = 0, selected = mo->owns; - i != select; - i++, selected = selected->next); + selected = mo->owns; + for (i = 0; i != select; i++, selected = selected->next); selected->next = next; } else diff --git a/src/map_object_actions.h b/src/map_object_actions.h index bccd6a8..0d594d3 100644 --- a/src/map_object_actions.h +++ b/src/map_object_actions.h @@ -18,7 +18,7 @@ struct MapObjAct struct MapObjAct * next; uint8_t id; /* unique id of map object action */ char * name; /* human-readable identifier */ - uint8_t effort; /* how many turn the action takes */ + uint8_t effort; /* how many turns the action takes */ void (* func) (struct MapObj *); /* function called after .effort turns */ }; @@ -50,7 +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 "MAGIC MEAT". + * (Currently the only valid use is consuming "MAGIC MEAT".) */ extern void actor_use(struct MapObj * mo); diff --git a/src/map_objects.c b/src/map_objects.c index a60395c..1fb4e68 100644 --- a/src/map_objects.c +++ b/src/map_objects.c @@ -282,4 +282,3 @@ extern void set_object_position(struct MapObj * mo, struct yx_uint16 pos) struct MapObj * owned = mo->owns; for (; owned != NULL; set_object_position(owned, pos), owned = owned->next); } -