From 2c480f67b2ce76f37ed6a0c89d8633d9deaf24d7 Mon Sep 17 00:00:00 2001 From: AdamPlenty <58278560+AdamPlenty@users.noreply.github.com> Date: Thu, 7 Nov 2024 19:09:03 +0000 Subject: [PATCH 1/2] Possible fix for Imps not searching for gold hoards Possibly fixes #3642 --- src/creature_states.c | 13 ++++++------- src/creature_states_spdig.c | 6 +++--- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/creature_states.c b/src/creature_states.c index d0dcd40be5..cc01f637b0 100644 --- a/src/creature_states.c +++ b/src/creature_states.c @@ -3355,7 +3355,7 @@ long setup_head_for_empty_treasure_space(struct Thing *thing, struct Room *room) { SlabCodedCoords start_slbnum = room->slabs_list; - //Find a random slab to start out with + // Find a random slab to start out with long n = CREATURE_RANDOM(thing, room->slabs_count); for (unsigned long k = n; k > 0; k--) { @@ -3378,7 +3378,7 @@ long setup_head_for_empty_treasure_space(struct Thing *thing, struct Room *room) // If the random slab has enough space to drop all gold, go there to drop it long wealth_size_holds = game.conf.rules.game.gold_per_hoard / get_wealth_size_types_count(); GoldAmount max_hoard_size_in_room = wealth_size_holds * room->total_capacity / room->slabs_count; - if((max_hoard_size_in_room - gldtng->valuable.gold_stored) >= thing->creature.gold_carried) + if ((max_hoard_size_in_room - gldtng->valuable.gold_stored) >= thing->creature.gold_carried) { if (setup_person_move_to_position(thing, slab_subtile_center(slb_x), slab_subtile_center(slb_y), NavRtF_Default)) { @@ -3386,16 +3386,15 @@ long setup_head_for_empty_treasure_space(struct Thing *thing, struct Room *room) } } - //If not, find a slab with the lowest amount of gold - GoldAmount gold_amount = gldtng->valuable.gold_stored; - GoldAmount min_gold_amount = gldtng->valuable.gold_stored; + // If not, find a slab with the lowest amount of gold + GoldAmount min_gold_amount = max_hoard_size_in_room; SlabCodedCoords slbmin = start_slbnum; for (long i = room->slabs_count; i > 0; i--) { slb_x = slb_num_decode_x(slbnum); slb_y = slb_num_decode_y(slbnum); gldtng = find_gold_hoarde_at(slab_subtile_center(slb_x), slab_subtile_center(slb_y)); - gold_amount = gldtng->valuable.gold_stored; + GoldAmount gold_amount = gldtng->valuable.gold_stored; if (gold_amount <= 0) //Any empty slab will do { slbmin = slbnum; @@ -3414,7 +3413,7 @@ long setup_head_for_empty_treasure_space(struct Thing *thing, struct Room *room) } - //Send imp to slab with lowest amount on it + // Send imp to slab with lowest amount on it slb_x = slb_num_decode_x(slbmin); slb_y = slb_num_decode_y(slbmin); if (setup_person_move_to_position(thing, slab_subtile_center(slb_x), slab_subtile_center(slb_y), NavRtF_Default)) diff --git a/src/creature_states_spdig.c b/src/creature_states_spdig.c index f7f400d13c..a99eed231b 100644 --- a/src/creature_states_spdig.c +++ b/src/creature_states_spdig.c @@ -1285,9 +1285,9 @@ short imp_drops_gold(struct Thing *spdigtng) if (is_thing_directly_controlled_by_player(spdigtng, my_player_number)) { play_non_3d_sample(119); + internal_set_thing_state(spdigtng, state); + return 1; } - internal_set_thing_state(spdigtng, state); - return 1; } if (game.conf.rules.workers.digger_work_experience != 0) { @@ -1295,7 +1295,7 @@ short imp_drops_gold(struct Thing *spdigtng) cctrl->exp_points += digger_work_experience(spdigtng); check_experience_upgrade(spdigtng); } - if ((spdigtng->creature.gold_carried != 0) && (room->used_capacity < room->total_capacity)) + if ((spdigtng->creature.gold_carried > 0) && (room->used_capacity < room->total_capacity)) { if ((spdigtng->alloc_flags & TAlF_IsControlled) == 0) { From 6b94a4fad0b36aa20dbc9e0b2b235be3d58728e5 Mon Sep 17 00:00:00 2001 From: AdamPlenty <58278560+AdamPlenty@users.noreply.github.com> Date: Thu, 7 Nov 2024 19:21:56 +0000 Subject: [PATCH 2/2] Work XP only if gold is actually dropped --- src/creature_states_spdig.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/creature_states_spdig.c b/src/creature_states_spdig.c index a99eed231b..1508ec0de4 100644 --- a/src/creature_states_spdig.c +++ b/src/creature_states_spdig.c @@ -1279,6 +1279,12 @@ short imp_drops_gold(struct Thing *spdigtng) if ( (gold_added > 0) || (gold_created) ) { thing_play_sample(spdigtng, UNSYNC_RANDOM(3) + 32, NORMAL_PITCH, 0, 3, 0, 2, FULL_LOUDNESS); + if (game.conf.rules.workers.digger_work_experience != 0) + { + struct CreatureControl* cctrl = creature_control_get_from_thing(spdigtng); + cctrl->exp_points += digger_work_experience(spdigtng); + check_experience_upgrade(spdigtng); + } } else { @@ -1289,12 +1295,6 @@ short imp_drops_gold(struct Thing *spdigtng) return 1; } } - if (game.conf.rules.workers.digger_work_experience != 0) - { - struct CreatureControl* cctrl = creature_control_get_from_thing(spdigtng); - cctrl->exp_points += digger_work_experience(spdigtng); - check_experience_upgrade(spdigtng); - } if ((spdigtng->creature.gold_carried > 0) && (room->used_capacity < room->total_capacity)) { if ((spdigtng->alloc_flags & TAlF_IsControlled) == 0)