From: Christian Heller Date: Wed, 20 Nov 2013 04:10:42 +0000 (+0100) Subject: Don't hardcode map object action id for "move" in turn_over()! X-Git-Tag: tce~926 X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/decks/%7B%7Bdb.prefix%7D%7D/static/blog?a=commitdiff_plain;h=97d23e7656f4c5e634b789fc760183edd7fd581e;p=plomrogue Don't hardcode map object action id for "move" in turn_over()! --- diff --git a/src/control.c b/src/control.c index 502f84a..ba1b505 100644 --- a/src/control.c +++ b/src/control.c @@ -11,14 +11,13 @@ */ #include "map.h" /* for map_scroll(), map_center() */ #include "main.h" /* for world global */ -#include "rexit.h" /* for exit_err() */ #include "wincontrol.h" /* for struct WinConf, scroll_pad(), toggle_window(), * growshrink_active_window(),toggle_winconfig(), * toggle_win_height_type(), toggle_win_width_type() */ #include "map_object_actions.h" /* for struct MapObjAct, actor_wait(), * actor_move(), actor_drop(), actor_pick(), - * actor_pick() + * actor_pick(), get_moa_id_by_name() */ #include "command_db.h" /* for is_command_id_shortdsc() */ #include "misc.h" /* for reload_interface_conf(), save_interface_conf(), @@ -36,9 +35,6 @@ static uint8_t try_cmd_1args(int cmd, char * match, void (* f) (char), char c); static uint8_t try_cmd_2args(int cmd, char * match, void (* f) (char, char), char c1, char c2); -/* try_player_cmd() helper, returns world.map_obj_acts action id for "name". */ -static uint8_t get_moa_id_by_name(char * name); - /* If "action" is id of command named "match", set player->arg, ->command and * call turn_over(). */ @@ -93,23 +89,6 @@ static uint8_t try_cmd_2args(int cmd, char * match, -static uint8_t get_moa_id_by_name(char * name) -{ - struct MapObjAct * moa = world.map_obj_acts; - while (NULL != moa) - { - if (0 == strcmp(moa->name, name)) - { - break; - } - moa = moa->next; - } - exit_err(NULL == moa, "get_moa_id_name() did not find map object action."); - return moa->id; -} - - - static uint8_t try_player_cmd(int action, char * match, char * command, uint8_t arg) { diff --git a/src/map_object_actions.c b/src/map_object_actions.c index 1d3139f..cdd1e97 100644 --- a/src/map_object_actions.c +++ b/src/map_object_actions.c @@ -233,6 +233,23 @@ extern void free_map_object_actions(struct MapObjAct * moa) +extern uint8_t get_moa_id_by_name(char * name) +{ + struct MapObjAct * moa = world.map_obj_acts; + while (NULL != moa) + { + if (0 == strcmp(moa->name, name)) + { + break; + } + moa = moa->next; + } + exit_err(NULL == moa, "get_moa_id_name() did not find map object action."); + return moa->id; +} + + + extern void actor_wait(struct MapObj * mo) { if (mo == get_player()) diff --git a/src/map_object_actions.h b/src/map_object_actions.h index e981228..bccd6a8 100644 --- a/src/map_object_actions.h +++ b/src/map_object_actions.h @@ -30,6 +30,9 @@ extern void init_map_object_actions(); /* Free MapObjAct * chain starting at "moa". */ extern void free_map_object_actions(struct MapObjAct * moa); +/* Return world.map_obj_acts MapObjAct.id for "name". */ +extern uint8_t get_moa_id_by_name(char * name); + /* Actor "mo" does nothing. */ extern void actor_wait(struct MapObj * mo); diff --git a/src/misc.c b/src/misc.c index 4e6527d..0e8abe9 100644 --- a/src/misc.c +++ b/src/misc.c @@ -250,7 +250,7 @@ extern void turn_over(char action) break; } char * sel = "NSEW"; - map_object->command = 1; + map_object->command = get_moa_id_by_name("move"); map_object->arg = sel[rrand() % 4]; } first_round = 0;