home · contact · privacy
All control action is moved from main() to the control library.
[plomrogue] / src / map_object_actions.c
index a4e186d28b17f0acbd0cb4333fcdb0715efbacb6..c0d43e76ba5501d2ee87486d8e2eb40c8d474db1 100644 (file)
@@ -21,8 +21,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 +75,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 +82,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 +102,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);
     }
 }
@@ -211,4 +219,3 @@ extern char is_passable (struct Map * map, struct yx_uint16 pos)
     }
     return passable;
 }
-