Skip to content

Commit 03b8fd7

Browse files
authored
Diggers are sorted at the top of the creature list (#3850)
So right below imps. Tunnellers or custom digging creatures a mapmaker created.
1 parent 79ab40a commit 03b8fd7

File tree

6 files changed

+42
-17
lines changed

6 files changed

+42
-17
lines changed

src/config_creature.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2203,7 +2203,7 @@ CreatureJob get_job_for_subtile(const struct Thing *creatng, MapSubtlCoord stl_x
22032203
}
22042204
if (creatng->owner == slabmap_owner(slb))
22052205
{
2206-
if (thing_is_creature_digger(creatng))
2206+
if (thing_is_creature_digger(creatng))
22072207
{
22082208
if (creature_is_for_dungeon_diggers_list(creatng))
22092209
{

src/front_input.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2805,7 +2805,7 @@ short get_gui_inputs(short gameplay_on)
28052805
gui_trap_type_highlighted = -1;
28062806
gui_creature_type_highlighted = -1;
28072807
if (gameplay_on) {
2808-
update_creatr_model_activities_list();
2808+
update_creatr_model_activities_list(0);
28092809
maintain_my_battle_list();
28102810
}
28112811
if (!lbDisplay.MLeftButton)

src/keeperfx.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ void engine(struct PlayerInfo *player, struct Camera *cam);
262262
void draw_gold_total(PlayerNumber plyr_idx, long scr_x, long scr_y, long units_per_px, long long value);
263263
void draw_mini_things_in_hand(long x, long y);
264264
TbBool screen_to_map(struct Camera *camera, long screen_x, long screen_y, struct Coord3d *mappos);
265-
void update_creatr_model_activities_list(void);
265+
void update_creatr_model_activities_list(TbBool forced);
266266
void find_map_location_coords(TbMapLocation location, long *x, long *y, int plyr_idx, const char *func_name);
267267
TbBool any_player_close_enough_to_see(const struct Coord3d *pos);
268268
void affect_nearby_stuff_with_vortex(struct Thing *thing);

src/lvl_script_commands.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7489,6 +7489,7 @@ static void swap_creature_process(struct ScriptContext* context)
74897489
SCRPTERRLOG("Error swapping creatures '%s'<->'%s'", creature_code_name(ncrt_id), creature_code_name(crtr_id));
74907490
}
74917491
recalculate_all_creature_digger_lists();
7492+
update_creatr_model_activities_list(1);
74927493
}
74937494

74947495
static void set_digger_check(const struct ScriptLine* scline)
@@ -7519,14 +7520,14 @@ static void set_digger_process(struct ScriptContext* context)
75197520
struct PlayerInfo* player = get_player(plyr_idx);
75207521

75217522
player->special_digger = context->value->shorts[0];
7522-
75237523
for (size_t i = 0; i < CREATURE_TYPES_MAX; i++)
75247524
{
75257525
if (breed_activities[i] == old_dig_model)
75267526
breed_activities[i] = new_dig_model;
75277527
else if (breed_activities[i] == new_dig_model)
75287528
breed_activities[i] = old_dig_model;
75297529
}
7530+
update_creatr_model_activities_list(1);
75307531
}
75317532
}
75327533

src/lvl_script_value.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@ void script_process_value(unsigned long var_index, unsigned long plr_range_id, l
580580
clear_flag(crconf->model_flags,CMF_IsSpecDigger);
581581
}
582582
recalculate_all_creature_digger_lists();
583+
update_creatr_model_activities_list(1);
583584
break;
584585
case 11: // ARACHNID
585586
if (val4 >= 1)
@@ -818,6 +819,7 @@ void script_process_value(unsigned long var_index, unsigned long plr_range_id, l
818819
{
819820
clear_flag(crconf->model_flags, CMF_IsDiggingCreature);
820821
}
822+
update_creatr_model_activities_list(1);
821823
break;
822824
default:
823825
SCRPTERRLOG("Unknown creature property '%ld'", val3);

src/main.cpp

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,48 +1296,51 @@ TbBool screen_to_map(struct Camera *camera, long screen_x, long screen_y, struct
12961296
return result;
12971297
}
12981298

1299-
void update_creatr_model_activities_list(void)
1299+
void update_creatr_model_activities_list(TbBool forced)
13001300
{
1301-
struct Dungeon *dungeon;
1302-
dungeon = get_my_dungeon();
1301+
struct Dungeon *dungeon = get_my_dungeon();
13031302
ThingModel crmodel;
1304-
int num_breeds;
1305-
num_breeds = no_of_breeds_owned;
1303+
int num_breeds = no_of_breeds_owned;
1304+
TbBool changed = false;
1305+
13061306
// Add to breed activities
1307-
for (crmodel=1; crmodel < game.conf.crtr_conf.model_count; crmodel++)
1307+
for (crmodel = 1; crmodel < game.conf.crtr_conf.model_count; crmodel++)
13081308
{
13091309
if ((dungeon->owned_creatures_of_model[crmodel] > 0)
13101310
&& (crmodel != get_players_spectator_model(my_player_number)))
13111311
{
1312-
int i;
1313-
for (i=0; i < num_breeds; i++)
1312+
TbBool found = false;
1313+
for (int i = 0; i < num_breeds; i++)
13141314
{
13151315
if (breed_activities[i] == crmodel)
13161316
{
1317+
found = true;
13171318
break;
13181319
}
13191320
}
1320-
if (num_breeds == i)
1321+
if (!found)
13211322
{
1322-
breed_activities[i] = crmodel;
1323+
changed = true;
1324+
breed_activities[num_breeds] = crmodel;
13231325
num_breeds++;
13241326
}
13251327
}
13261328
}
1329+
13271330
// Remove from breed activities
1328-
for (crmodel=1; crmodel < game.conf.crtr_conf.model_count; crmodel++)
1331+
for (crmodel = 1; crmodel < game.conf.crtr_conf.model_count; crmodel++)
13291332
{
13301333
if ((dungeon->owned_creatures_of_model[crmodel] <= 0)
13311334
&& (crmodel != get_players_special_digger_model(my_player_number)))
13321335
{
1333-
int i;
1334-
for (i=0; i < num_breeds; i++)
1336+
for (int i = 0; i < num_breeds; i++)
13351337
{
13361338
if (breed_activities[i] == crmodel)
13371339
{
13381340
for (; i < num_breeds-1; i++) {
13391341
breed_activities[i] = breed_activities[i+1];
13401342
}
1343+
changed = true;
13411344
num_breeds--;
13421345
breed_activities[i] = 0;
13431346
break;
@@ -1346,6 +1349,25 @@ void update_creatr_model_activities_list(void)
13461349
}
13471350
no_of_breeds_owned = num_breeds;
13481351
}
1352+
1353+
// Reorder breed activities to ensure diggers are correctly positioned
1354+
if (changed || forced)
1355+
{
1356+
struct CreatureModelConfig* crconf;
1357+
ThingModel temp;
1358+
int write_idx = 1;
1359+
for (int i = 1; i < num_breeds; i++)
1360+
{
1361+
crconf = &game.conf.crtr_conf.model[breed_activities[i]];
1362+
if (any_flag_is_set(crconf->model_flags, (CMF_IsDiggingCreature | CMF_IsSpecDigger)))
1363+
{
1364+
temp = breed_activities[i];
1365+
memmove(&breed_activities[write_idx + 1], &breed_activities[write_idx], (i - write_idx) * sizeof(ThingModel));
1366+
breed_activities[write_idx] = temp;
1367+
write_idx++;
1368+
}
1369+
}
1370+
}
13491371
}
13501372

13511373
void toggle_hero_health_flowers(void)

0 commit comments

Comments
 (0)