X-Git-Url: https://plomlompom.com/repos/feed.xml?a=blobdiff_plain;f=src%2Fmap_object_actions.c;h=9d1721e936fab21bd8e6c3634812f409e9adb6e9;hb=42f6cd9789e06f0257a078a33fa13aaea0714fce;hp=44e02638ef2a71353c35dc5eab0456eab5466c0e;hpb=7290dec4219eaa2325aa00ef6139f715743dba3a;p=plomrogue diff --git a/src/map_object_actions.c b/src/map_object_actions.c index 44e0263..9d1721e 100644 --- a/src/map_object_actions.c +++ b/src/map_object_actions.c @@ -64,7 +64,7 @@ static void actor_hits_actor(struct MapObj * hitter, struct MapObj * hitted) -extern uint8_t move_actor(struct MapObj * actor, enum dir d) +extern uint8_t move_actor(struct MapObj * actor, char d) { struct yx_uint16 target = mv_yx_in_dir(d, actor->pos); struct MapObj * other_actor; @@ -92,29 +92,29 @@ extern uint8_t move_actor(struct MapObj * actor, enum dir d) -extern void move_player(enum dir d) +extern void move_player(char d) { char * dsc_dir; char * action_dsc_prototype = "player_"; uint8_t len_action_dsc_prototype = strlen(action_dsc_prototype); char action_dsc[len_action_dsc_prototype + 2]; memcpy(action_dsc, action_dsc_prototype, len_action_dsc_prototype); - if (NORTH == d) + if ('N' == d) { dsc_dir = "north"; action_dsc[len_action_dsc_prototype] = 'u'; } - else if (EAST == d) + else if ('E' == d) { dsc_dir = "east" ; action_dsc[len_action_dsc_prototype] = 'r'; } - else if (SOUTH == d) + else if ('S' == d) { dsc_dir = "south"; action_dsc[len_action_dsc_prototype] = 'd'; } - else if (WEST == d) + else if ('W' == d) { dsc_dir = "west" ; action_dsc[len_action_dsc_prototype] = 'l'; @@ -206,3 +206,47 @@ extern void player_pick() } turn_over(get_command_id("pick")); } + + + +extern void player_use() +{ + struct MapObj * player = get_player(); + if (NULL == player->owns) + { + update_log("\nYou try to use an object, but you own none."); + world.old_inventory_select = 0; + } + else + { + uint8_t i = 0; + struct MapObj * selected = player->owns; + for (; i != world.inventory_select; i++, selected = selected->next); + struct MapObjDef * mod = get_map_object_def(selected->type); + if (!strcmp("MAGIC MEAT", mod->name)) + { + struct MapObj * next = selected->next; + free(selected); + if (0 < world.inventory_select) + { + world.old_inventory_select = world.inventory_select; + world.inventory_select--; + for (i = 0, selected = player->owns; + i != world.inventory_select; + i++, selected = selected->next); + selected->next = next; + } + else + { + player->owns = next; + } + player->lifepoints++; + update_log("\nYou consume MAGIC MEAT."); + } + else + { + update_log("\nYou try to use this object, but fail."); + } + } + turn_over(get_command_id("use")); +}