From 0d9977af5f0d42bd94c1213b9f98bc717c495789 Mon Sep 17 00:00:00 2001 From: Martin Read Date: Mon, 10 Mar 2014 16:18:21 +0000 Subject: [PATCH] Snapshotting monsters.cc --- monsters.cc | 163 +++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 90 insertions(+), 73 deletions(-) diff --git a/monsters.cc b/monsters.cc index d643081..04f8a59 100644 --- a/monsters.cc +++ b/monsters.cc @@ -162,85 +162,102 @@ Mon_handle create_mon(int pm_idx, Coord c) return NO_MON; } -void death_drop(Mon_handle mon) +/* The rules: + * A monster gets eight entries. + */ + +struct Death_drop_entry { - Mon *mptr = mon_snapv(mon); - int pm = mptr->pm_ref; - Coord c = mptr->pos; - Offset delta; - int tryct = 0; - while (((lvl.obj_at(c) != NO_OBJ) || (lvl.terrain_at(c) != FLOOR)) && - (tryct < 100)) + int pm_ref; + void (*func)(Coord c); +}; + +void goblin_death_drop(Coord c) +{ + if (!zero_die(4)) { - delta = random_step(); - tryct++; - c += delta; + create_obj_near(PO_DAGGER, 1, c); } - if (tryct >= 100) +} + +void thug_death_drop(Coord c) +{ + if (!zero_die(4)) { - return; + create_obj_near(PO_MACE, 1, c); } - switch (pm) + else if (!zero_die(3)) { - case PM_GOBLIN: - if (!zero_die(4)) - { - create_obj_near(PO_DAGGER, 1, c); - } - break; - case PM_THUG: - case PM_GOON: - if (!zero_die(4)) - { - create_obj_near(PO_MACE, 1, c); - } - else if (!zero_die(3)) - { - create_obj_near(PO_LEATHER_ARMOUR, 1, c); - } - break; - case PM_HUNTER: - if (!zero_die(6)) - { - create_obj_near(PO_BOW, 1, c); - } - break; - case PM_DUELLIST: - if (!zero_die(6)) - { - create_obj_near(PO_LONG_SWORD, 1, c); - } - break; - case PM_WIZARD: - if (!zero_die(4)) - { - create_obj_class_near(POCLASS_SCROLL, 1, false, c); - } - else if (!zero_die(3)) - { - create_obj_class_near(POCLASS_POTION, 1, false, c); - } - break; - case PM_WARLORD: - if (!zero_die(3)) - { - create_obj_near(PO_RUNESWORD, 1, c); - } - break; - case PM_DEMON: - if (!zero_die(100)) - { - create_obj_near(PO_DEVIL_SPLEEN, 1, c); - } - break; - case PM_DEFILER: - if (!zero_die(50)) - { - create_obj_near(PO_DEVIL_SPLEEN, 1, c); - } - break; - default: - break; + create_obj_near(PO_LEATHER_ARMOUR, 1, c); + } +} + +void hunter_death_drop(Coord c) +{ + if (!zero_die(6)) + { + create_obj_near(PO_BOW, 1, c); + } +} + +void duellist_death_drop(Coord c) +{ + if (!zero_die(6)) + { + create_obj_near(PO_LONG_SWORD, 1, c); + } +} + +void wizard_death_drop(Coord c) +{ + if (!zero_die(4)) + { + create_obj_class_near(POCLASS_SCROLL, 1, false, c); + } + else if (!zero_die(3)) + { + create_obj_class_near(POCLASS_POTION, 1, false, c); + } +} + +void warlord_death_drop(Coord c) +{ + if (!zero_die(3)) + { + create_obj_near(PO_RUNESWORD, 1, c); + } +} + +void demon_death_drop(Coord c) +{ + if (!zero_die(100)) + { + create_obj_near(PO_DEVIL_SPLEEN, 1, c); + } +} + +Death_drop_entry death_drops[] = +{ + { PM_GOBLIN, goblin_death_drop }, + { PM_THUG, thug_death_drop }, + { PM_GOON, thug_death_drop }, + { PM_HUNTER, hunter_death_drop }, + { PM_DUELLIST, duellist_death_drop }, + { PM_WIZARD, wizard_death_drop }, + { PM_WARLORD, warlord_death_drop }, + { PM_DEMON, demon_death_drop }, + { NO_PMON, nullptr } +}; + +void death_drop(Mon_handle mon) +{ + Mon const *mptr = mon_snap(mon); + for (int i = 0; death_drops[i].func != nullptr; ++i) + { + if (death_drops[i].pm_ref == mptr->pm_ref) + { + death_drops[i].func(mptr->pos); + } } } -- 2.11.0