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

Recalculate Players Digger/ctr Lists on typechange #3568

Merged
merged 4 commits into from
Oct 16, 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
1 change: 1 addition & 0 deletions src/lvl_script_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -6091,6 +6091,7 @@ static void computer_player_process(struct ScriptContext* context)
}
}
}
recalculate_player_creature_digger_lists(i);
}
}

Expand Down
77 changes: 77 additions & 0 deletions src/thing_creature.c
Original file line number Diff line number Diff line change
Expand Up @@ -3966,6 +3966,83 @@ void set_first_creature(struct Thing *creatng)
}
}

void recalculate_player_creature_digger_lists(PlayerNumber plr_idx)
{
ThingIndex previous_digger = 0;
ThingIndex previous_creature = 0;

struct Dungeon* dungeon = get_dungeon(plr_idx);
dungeon->digger_list_start = 0;
dungeon->creatr_list_start = 0;
dungeon->num_active_diggers = 0;
dungeon->num_active_creatrs = 0;


const struct StructureList* slist = get_list_for_thing_class(TCls_Creature);
long i = slist->index;
long k = 0;
while (i > 0)
{
struct Thing* creatng = thing_get(i);
if (thing_is_invalid(creatng))
break;

if(creatng->owner == plr_idx)
{
if(creature_is_for_dungeon_diggers_list(creatng))
{

if(dungeon->digger_list_start == 0)
{
dungeon->digger_list_start = i;
}
else
{
struct CreatureControl* prevcctrl = creature_control_get_from_thing(thing_get(previous_digger));
prevcctrl->players_next_creature_idx = i;
}
struct CreatureControl* cctrl = creature_control_get_from_thing(creatng);
cctrl->players_next_creature_idx = 0;
cctrl->players_prev_creature_idx = previous_digger;
if (!flag_is_set(cctrl->flgfield_2,TF2_Spectator) && !(flag_is_set(cctrl->flgfield_2, TF2_SummonedCreature)))
{
dungeon->num_active_diggers++;
}
previous_digger = i;
}
else
{

if(dungeon->creatr_list_start == 0)
{
dungeon->creatr_list_start = i;
}
else
{
struct CreatureControl* prevcctrl = creature_control_get_from_thing(thing_get(previous_creature));
prevcctrl->players_next_creature_idx = i;
}
struct CreatureControl* cctrl = creature_control_get_from_thing(creatng);
cctrl->players_next_creature_idx = 0;
cctrl->players_prev_creature_idx = previous_creature;
if (!flag_is_set(cctrl->flgfield_2,TF2_Spectator) && !(flag_is_set(cctrl->flgfield_2, TF2_SummonedCreature)))
{
dungeon->num_active_creatrs++;
}
previous_creature = i;
}
}

i = creatng->next_of_class;
k++;
if (k > slist->count)
{
ERRORLOG("Infinite loop detected when sweeping things list");
break;
}
}
}

void remove_first_creature(struct Thing *creatng)
{
struct Dungeon *dungeon;
Expand Down
1 change: 1 addition & 0 deletions src/thing_creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ TbBool creature_kind_is_for_dungeon_diggers_list(PlayerNumber plyr_idx, ThingMod
void set_first_creature(struct Thing *thing);
void remove_first_creature(struct Thing *thing);
long player_list_creature_filter_needs_to_be_placed_in_room_for_job(const struct Thing *thing, MaxTngFilterParam param, long maximizer);
void recalculate_player_creature_digger_lists(PlayerNumber plr_idx);

TbBool creature_has_lair_room(const struct Thing *creatng);
struct Room *get_creature_lair_room(const struct Thing *creatng);
Expand Down
Loading