Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible fix for Imps not searching for space in Treasure Room #3649

Merged
merged 4 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would we set a state to a creature when it is possessed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To keep it under possession, if I recall correctly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not sound correct to me. Possession overwrites states, the states are used to direct creature behavior.
I think it was there (but outside of this if) to get imps to get back to mining when they fail to drop off gold anywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may need to test again, but if I remember correctly, if the Imp is under possession, he'll do his own thing even though he's under possession, unless his state is reset. We do not want possessed Imps to be set to the last work state.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But you are setting possessed imps to last_work_state here right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. Possessed Imps are set to the null 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