X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=src%2Fmap_object_actions.c;h=97f33d6e4eb947074f8c60ff30ce308c72303a3e;hb=f8325a4ea617b15315183d7a8027c0b913c91034;hp=a4e186d28b17f0acbd0cb4333fcdb0715efbacb6;hpb=e43611d44a32c92274d08dcc42e2541cf1ecdc72;p=plomrogue diff --git a/src/map_object_actions.c b/src/map_object_actions.c index a4e186d..97f33d6 100644 --- a/src/map_object_actions.c +++ b/src/map_object_actions.c @@ -9,6 +9,7 @@ #include "main.h" /* for World struct */ #include "map_objects.h" /* for map object (definition) structs */ #include "rrand.h" /* for rrand() */ +#include "command_db.h" /* for get_command_id() */ @@ -21,8 +22,9 @@ static void monster_bumps_monster(struct World * world, char * dsc_monster1, */ static void monster_hits_player(struct World * world, char * dsc_monster); -/* Decrement HP of "monster" hit by player, kill it if its HP hit zero; log the - * whole action. +/* Decrement HP of "monster" hit by player, kill it if its HP hit zero, create a + * corpse and increment player's score by the amount of hitpoints the monster + * started with; log the whole action. */ static void player_hits_monster(struct World * world, struct Monster * monster); @@ -74,7 +76,6 @@ static void player_hits_monster(struct World * world, struct Monster * monster) update_log(world, msg); free(msg); monster->hitpoints--; - if (0 == monster->hitpoints) { hit_dsc = "You kill the "; @@ -82,6 +83,12 @@ static void player_hits_monster(struct World * world, struct Monster * monster) sprintf(msg, "\n%s%s.", hit_dsc, monster_dsc); update_log(world, msg); free(msg); + struct MonsterDef * md = (struct MonsterDef * ) mod; + struct Item * corpse = malloc(sizeof(struct Item)); + corpse->map_obj.type = md->corpse_id; + corpse->map_obj.pos = monster->map_obj.pos; + corpse->map_obj.next = world->item; + world->item = corpse; if (world->monster == monster) { world->monster = world->monster->map_obj.next; @@ -96,6 +103,8 @@ static void player_hits_monster(struct World * world, struct Monster * monster) m_prev->map_obj.next = monster->map_obj.next; } } + uint8_t score = md->hitpoints_start; + world->score = world->score + score; free(monster); } } @@ -172,6 +181,28 @@ extern void move_monster(struct World * world, struct Monster * monster) extern void move_player(struct World * world, enum dir d) { + char * action_dsc_prototype = "player_"; + uint8_t len = strlen(action_dsc_prototype); + char * action_dsc = malloc(len + 2); + memcpy(action_dsc, action_dsc_prototype, len); + if (NORTH == d) + { + action_dsc[len] = 'u'; + } + else if (SOUTH == d) + { + action_dsc[len] = 'd'; + } + else if (WEST == d) + { + action_dsc[len] = 'l'; + } + else if (EAST == d) + { + action_dsc[len] = 'r'; + } + action_dsc[len + 1] = '\0'; + uint8_t action_id = get_command_id(world, action_dsc); struct yx_uint16 t = mv_yx_in_dir(d, world->player->pos); struct Monster * monster; for (monster = world->monster; @@ -181,12 +212,12 @@ extern void move_player(struct World * world, enum dir d) if (yx_uint16_cmp(&t, &monster->map_obj.pos)) { player_hits_monster(world, monster); - turn_over(world, d); + turn_over(world, action_id); return; } } try_player_move(world, d, t); - turn_over(world, d); + turn_over(world, action_id); } @@ -194,7 +225,7 @@ extern void move_player(struct World * world, enum dir d) extern void player_wait (struct World * world) { update_log(world, "\nYou wait."); - turn_over(world, 0); + turn_over(world, get_command_id(world, "wait")); } @@ -211,4 +242,3 @@ extern char is_passable (struct Map * map, struct yx_uint16 pos) } return passable; } -