Skip to content

Commit

Permalink
Imps search correct spot for gold in treasure room again (#3649)
Browse files Browse the repository at this point in the history
Fixes #3642
  • Loading branch information
AdamPlenty authored Nov 9, 2024
1 parent f4f9efb commit f88db4a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
13 changes: 6 additions & 7 deletions src/creature_states.c
Original file line number Diff line number Diff line change
Expand Up @@ -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--)
{
Expand All @@ -3378,24 +3378,23 @@ 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))
{
return 1;
}
}

//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;
Expand All @@ -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))
Expand Down
18 changes: 9 additions & 9 deletions src/creature_states_spdig.c
Original file line number Diff line number Diff line change
Expand Up @@ -1279,23 +1279,23 @@ 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
{
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)
{
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->creature.gold_carried > 0) && (room->used_capacity < room->total_capacity))
{
if ((spdigtng->alloc_flags & TAlF_IsControlled) == 0)
{
Expand Down

0 comments on commit f88db4a

Please sign in to comment.