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

Increased creature limit #3362

Merged
merged 57 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
29be66f
Rule for CREATURES_COUNT
benlp91 Jul 19, 2024
a8dc96f
fixes
benlp91 Jul 19, 2024
25c4c05
Update config_rules.c
benlp91 Jul 19, 2024
b00e914
Update rules.cfg
benlp91 Jul 19, 2024
af74c9d
name change + added rule to maps/campaigns
benlp91 Jul 26, 2024
3d6d470
Update rules.cfg
benlp91 Jul 26, 2024
7d6da39
Merge branch 'master' into increased-creature-limit
Loobinex Sep 1, 2024
ccd2049
Give it a default value
Loobinex Sep 1, 2024
1fad09f
some fixes
benlp91 Sep 1, 2024
91cffba
Merge branch 'increased-creature-limit' of https://github.com/dkfans/…
benlp91 Sep 1, 2024
4ff5954
Created the offset of 1
Loobinex Sep 1, 2024
2c319b0
Update the config
Loobinex Sep 1, 2024
243e338
made it work for SET_GAME_RULE
Loobinex Sep 1, 2024
f1b64ae
Put a lot of stuff back to CREATURES_COUNT
Loobinex Sep 2, 2024
d4521fd
Revert "made it work for SET_GAME_RULE"
Loobinex Sep 2, 2024
98aeab7
Revert "Created the offset of 1"
Loobinex Sep 2, 2024
308a5a7
handled the offset of 1 in a cleaner way
Loobinex Sep 2, 2024
eb55ff6
comments only go into main files
Loobinex Sep 2, 2024
a375ef9
Some cleanup
Loobinex Sep 2, 2024
4717bc2
some unrelated cleanup
Loobinex Sep 2, 2024
0903f78
Increased 3 more fields that were left on chars
Loobinex Sep 2, 2024
78e2f5e
Added 2 places I missed in the confusion
Loobinex Sep 3, 2024
79e6964
Revert "Added 2 places I missed in the confusion"
Loobinex Sep 3, 2024
51a0454
Reapply "Added 2 places I missed in the confusion"
Loobinex Sep 3, 2024
8051ab5
corrected tiny log mistake
Loobinex Sep 3, 2024
a5a2c64
Only stop the extra creatures, do not kill them.
Loobinex Sep 4, 2024
3f0bac8
Extra creatures just leave
Loobinex Sep 4, 2024
07e31ea
stopped creatures leaving from being snapped out of it
Loobinex Sep 4, 2024
e522ac5
raised BATTLE_COUNT
benlp91 Sep 5, 2024
894a010
battle count a bit lower
Loobinex Sep 5, 2024
9708119
Cleanup states of creatures dying from being too much
Loobinex Sep 5, 2024
72669c6
Stopped log errors and stop imps from costing money if the spell fails
Loobinex Sep 6, 2024
fb0b316
stop generating creatures beyond map limit
Loobinex Sep 8, 2024
4a95973
Merge branch 'master' into increased-creature-limit
Loobinex Sep 8, 2024
c70646a
Made a separate function for the check
Loobinex Sep 8, 2024
aa13dd1
handled vampires
Loobinex Sep 8, 2024
dac765b
handled skeletons
Loobinex Sep 8, 2024
404ce0b
handled growing up (to dragon?)
Loobinex Sep 8, 2024
8e48a24
Handled temple, prison, scavenge, torture and duplicate
Loobinex Sep 8, 2024
5532fea
Handled other special boxes and summons
Loobinex Sep 8, 2024
b6c374e
Made sure the recent commits actually build
Loobinex Sep 8, 2024
28e0cde
fixed 2 cosmetic issues
Loobinex Sep 8, 2024
9f5969f
Reverted accidental change at max creature control
Loobinex Sep 8, 2024
97d430f
Better fix for entrance
Loobinex Sep 8, 2024
2424b42
fixed errors from script command
Loobinex Sep 8, 2024
65d797b
better handle offsets
Loobinex Sep 8, 2024
7b0eee0
No error on spawning from script
Loobinex Sep 8, 2024
811fbc7
Sooner give the create creature error
Loobinex Sep 9, 2024
49b9f60
Fixed unrelated transparency_flags log error
Loobinex Sep 9, 2024
73bd759
Stops computer players from trying to cast imp at map limit
Loobinex Sep 9, 2024
033c622
convert_creature_to_ghost still kills creature when at hard limit
Loobinex Sep 9, 2024
74dcdf8
created a separate function for the setting up to leave/die
Loobinex Sep 9, 2024
63ce357
No longer use 'is being sacrificed' as workaround for leaving creatur…
Loobinex Sep 9, 2024
8bbadcc
Fixed mistake in moving of script function
Loobinex Sep 9, 2024
317cb4f
updated comment on rules.cfg
Loobinex Sep 10, 2024
97d0f98
Made sure people cannot go past 1022 creatures
Loobinex Sep 10, 2024
fb6364e
Get message back on !map.pool console command
Loobinex Sep 10, 2024
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
2 changes: 2 additions & 0 deletions config/fxdata/rules.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ AlliesShareDrop = 0
; Allied players share map vision, which is removed as soon as alliance is broken.
AlliesShareVision = 0
MaxThingsInHand = 8
; Total Amount of Creatures on the map. The absolute maximum is 1023.
MapCreatureLimit = 1000
; Global light strength and dynamic lighting (32 is full bright).
GlobalAmbientLight = 10
LightEnabled = 1
Expand Down
1 change: 1 addition & 0 deletions levels/classic_cfgs/rules.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@

[game]
DungeonHeartHealHealth = 1
MapCreatureLimit = 255
1 change: 1 addition & 0 deletions levels/legacy_cfgs/rules.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[game]
DungeonHeartHealHealth = 1
PreserveClassicBugs = RESURRECT_FOREVER OVERFLOW_8BIT CLAIM_ROOM_ALL_THINGS RESURRECT_REMOVED NO_HAND_PURGE_ON_DEFEAT MUST_OBEY_KEEPS_NOT_DO_JOBS BREAK_NEUTRAL_WALLS ALWAYS_TUNNEL_TO_RED FULLY_HAPPY_WITH_GOLD FAINTED_IMMUNE_TO_BOULDER REBIRTH_KEEPS_SPELLS STUN_FRIENDLY_UNITS PASSIVE_NEUTRALS NEUTRAL_TORTURE_CONVERTS
MapCreatureLimit = 255

[computer]
DiseaseHPTemplePercentage = 50
Expand Down
2 changes: 1 addition & 1 deletion src/config_crtrmodel.c
Original file line number Diff line number Diff line change
Expand Up @@ -1706,8 +1706,8 @@ TbBool parse_creaturemodel_appearance_blocks(long crtr_model,char *buf,long len,
if (k > 0)
{
crstat->transparency_flags = k<<4; // Bitshift to get the transparancy bit in the render flag
n++;
}
n++;
}
if (n < 1)
{
Expand Down
2 changes: 2 additions & 0 deletions src/config_rules.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ const struct NamedField rules_game_named_fields[] = {
{"EASTEREGGSPEECHINTERVAL", &game.conf.rules.game.easter_egg_speech_interval, var_type(game.conf.rules.game.easter_egg_speech_interval), 0,LONG_MAX},
{"GLOBALAMBIENTLIGHT", &game.conf.rules.game.global_ambient_light, var_type(game.conf.rules.game.global_ambient_light ),LONG_MIN,LONG_MAX},
{"LIGHTENABLED", &game.conf.rules.game.light_enabled, var_type(game.conf.rules.game.light_enabled ), 0, 1},
{"MAPCREATURELIMIT", &game.conf.rules.game.creatures_count, var_type(game.conf.rules.game.creatures_count ), 0,CREATURES_COUNT-1},
{NULL, NULL,0,0,0 },
};

Expand Down Expand Up @@ -286,6 +287,7 @@ static void set_defaults()
game.conf.rules.game.torture_payday = 50;
game.conf.rules.game.torture_training_cost = 100;
game.conf.rules.game.torture_scavenging_cost = 100;
game.conf.rules.game.creatures_count = 255;
// Creature block.
game.conf.rules.creature.recovery_frequency = 10;
game.conf.rules.creature.fight_max_hate = 200;
Expand Down
1 change: 1 addition & 0 deletions src/config_rules.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ struct GameRulesConfig {
unsigned long easter_egg_speech_interval;
long global_ambient_light;
TbBool light_enabled;
unsigned short creatures_count;
};

struct ComputerRulesConfig {
Expand Down
19 changes: 18 additions & 1 deletion src/console_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,24 @@ TbBool cmd_exec(PlayerNumber plyr_idx, char *msg)
}
else if ((strcasecmp(parstr, "map.pool") == 0) || (strcasecmp(parstr, "creature.pool") == 0))
{
return script_set_pool(plyr_idx, pr2str, pr3str);
if (pr3str == NULL)
{
long kind = get_id(creature_desc, pr2str);
if (kind == -1)
{
targeted_message_add(MsgType_Player, 10, plyr_idx, GUI_MESSAGES_DELAY, "Invalid creature");
return false;
}
else
{
targeted_message_add(MsgType_Player, 10, plyr_idx, GUI_MESSAGES_DELAY, "Pool count %s: %d",pr2str,game.pool.crtr_kind[kind]);
return true;
}
}
else
{
return script_set_pool(plyr_idx, pr2str, pr3str);
}
}
else if ((strcasecmp(parstr, "gold.create") == 0) || (strcasecmp(parstr, "create.gold") == 0))
{
Expand Down
4 changes: 2 additions & 2 deletions src/creature_battle.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ extern "C" {
#endif

/** Max amount of battles supported on any map. */
#define BATTLES_COUNT 48
#define MESSAGE_BATTLERS_COUNT 8
#define BATTLES_COUNT 192
#define MESSAGE_BATTLERS_COUNT 8
/******************************************************************************/
#pragma pack(1)

Expand Down
2 changes: 1 addition & 1 deletion src/creature_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ struct CastedSpellData {
};

struct CreatureControl {
unsigned char index;
unsigned short index;
unsigned char flgfield_1;
unsigned char flgfield_2;
unsigned char combat_flags;
Expand Down
2 changes: 1 addition & 1 deletion src/creature_states.c
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ TbBool creature_is_being_tortured(const struct Thing *thing)
TbBool creature_is_being_sacrificed(const struct Thing *thing)
{
CrtrStateId i = get_creature_state_besides_interruptions(thing);
if ((i == CrSt_CreatureSacrifice) || (i == CrSt_CreatureBeingSacrificed))
if ((i == CrSt_CreatureSacrifice) || (i == CrSt_CreatureBeingSacrificed) || (i == CrSt_LeavesBecauseOwnerLost))
Loobinex marked this conversation as resolved.
Show resolved Hide resolved
return true;
return false;
}
Expand Down
11 changes: 6 additions & 5 deletions src/creature_states_combt.c
Original file line number Diff line number Diff line change
Expand Up @@ -639,8 +639,8 @@ TbBool battle_with_creature_of_player(PlayerNumber plyr_idx, BattleIndex battle_
TRACE_THING(thing);
if (thing_is_invalid(thing))
{
ERRORLOG("Jump to invalid thing detected");
break;
ERRORLOG("Jump to invalid thing detected");
break;
}
struct CreatureControl* cctrl = creature_control_get_from_thing(thing);
i = cctrl->battle_prev_creatr;
Expand All @@ -651,8 +651,8 @@ TbBool battle_with_creature_of_player(PlayerNumber plyr_idx, BattleIndex battle_
k++;
if (k > CREATURES_COUNT)
{
ERRORLOG("Infinite loop detected when sweeping creatures list");
break;
ERRORLOG("Infinite loop detected when sweeping creatures list");
break;
}
}
return false;
Expand Down Expand Up @@ -692,7 +692,8 @@ TbBool battle_any_of_things_in_specific_battle(const struct CreatureBattle *batt
}
// Per battle creature code ends
k++;
if (k >= CREATURES_COUNT) {
if (k >= CREATURES_COUNT)
{
ERRORLOG("Infinite loop in battle add");
break;
}
Expand Down
5 changes: 5 additions & 0 deletions src/creature_states_pray.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ short state_cleanup_in_temple(struct Thing *creatng)
TbBool summon_creature(long model, struct Coord3d *pos, long owner, long explevel)
{
SYNCDBG(4,"Creating model %ld for player %ld",model,owner);
if (!creature_count_below_map_limit(0))
{
SYNCLOG("Summon creature %s failed to due to map creature limit", creature_code_name(model));
return false;
}
struct Thing* thing = create_creature(pos, model, owner);
if (thing_is_invalid(thing))
{
Expand Down
30 changes: 19 additions & 11 deletions src/creature_states_prisn.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,23 +315,31 @@ CrStateRet creature_in_prison(struct Thing *thing)
TbBool prison_convert_creature_to_skeleton(struct Room *room, struct Thing *thing)
{
struct CreatureControl* cctrl = creature_control_get_from_thing(thing);
struct Thing* crthing = INVALID_THING;
long crmodel = get_room_create_creature_model(room->kind); // That normally returns skeleton breed
struct Thing* crthing = create_creature(&thing->mappos, crmodel, room->owner);
if (thing_is_invalid(crthing))
if (creature_count_below_map_limit(1))
{
ERRORLOG("Couldn't create creature %s in prison", creature_code_name(crmodel));
return false;
crthing = create_creature(&thing->mappos, crmodel, room->owner);
if (thing_is_invalid(crthing))
{
ERRORLOG("Couldn't create creature %s in prison", creature_code_name(crmodel));
return false;
}
init_creature_level(crthing, cctrl->explevel);
set_start_state(crthing);
struct Dungeon* dungeon = get_dungeon(room->owner);
if (!dungeon_invalid(dungeon)) {
dungeon->lvstats.skeletons_raised++;
}
}
else
{
WARNLOG("Could not create creature %s to transform %s to due to creature limit", thing_model_name(crmodel),thing_model_name(thing));
}
init_creature_level(crthing, cctrl->explevel);
set_start_state(crthing);
if (creature_model_bleeds(thing->model))
create_effect_around_thing(thing, TngEff_Blood5);
kill_creature(thing, INVALID_THING, -1, CrDed_NoEffects);
struct Dungeon* dungeon = get_dungeon(room->owner);
if (!dungeon_invalid(dungeon)) {
dungeon->lvstats.skeletons_raised++;
}
return true;
return !thing_is_invalid(crthing);
}

TbBool process_prisoner_skelification(struct Thing *thing, struct Room *room)
Expand Down
5 changes: 5 additions & 0 deletions src/creature_states_scavn.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,11 @@ TbBool creature_scavenge_from_creature_pool(struct Thing *calltng)
ERRORLOG("Could not find valid position in %s for %s to be generated",room_code_name(room->kind),creature_code_name(calltng->model));
return false;
}
if (!creature_count_below_map_limit(0))
{
SYNCDBG(7,"Scavenge creature %s from portal failed to due to map creature limit", thing_model_name(calltng));
return false;
}
struct Thing* scavtng = create_creature(&pos, calltng->model, calltng->owner);
if (thing_is_invalid(scavtng)) {
ERRORLOG("Tried to generate %s but creation failed",thing_model_name(calltng));
Expand Down
14 changes: 11 additions & 3 deletions src/creature_states_tortr.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,18 @@ CrCheckRet process_kinky_function(struct Thing *thing)
void convert_creature_to_ghost(struct Room *room, struct Thing *thing)
Loobinex marked this conversation as resolved.
Show resolved Hide resolved
{
int crmodel = get_room_create_creature_model(room->kind);
struct Thing* newthing = create_creature(&thing->mappos, crmodel, room->owner);
if (thing_is_invalid(newthing))
struct Thing* newthing = INVALID_THING;
if (creature_count_below_map_limit(1))
{
ERRORLOG("Couldn't create creature %s in %s room",creature_code_name(crmodel),room_code_name(room->kind));
newthing = create_creature(&thing->mappos, crmodel, room->owner);
if (thing_is_invalid(newthing))
{
ERRORLOG("Couldn't create creature %s in %s room",creature_code_name(crmodel),room_code_name(room->kind));
return;
}
} else
{
WARNLOG("Could not create creature %s to transform %s to due to creature limit", creature_code_name(crmodel), thing_model_name(thing));
return;
}
struct CreatureControl* cctrl = creature_control_get_from_thing(thing);
Expand Down
6 changes: 3 additions & 3 deletions src/dungeon_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ struct Dungeon {
unsigned char gold_piles_sacrificed;
unsigned char creature_sacrifice[CREATURE_TYPES_MAX];
unsigned char creature_sacrifice_exp[CREATURE_TYPES_MAX];
unsigned char num_active_diggers;
unsigned char num_active_creatrs;
unsigned char owned_creatures_of_model[CREATURE_TYPES_MAX];
unsigned short num_active_diggers;
unsigned short num_active_creatrs;
unsigned short owned_creatures_of_model[CREATURE_TYPES_MAX];
/** Total amount of rooms in possession of a player. Rooms which can never be built are not counted. */
unsigned char total_rooms;
unsigned short total_doors;
Expand Down
50 changes: 50 additions & 0 deletions src/lvl_script_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "power_specials.h"
#include "room_util.h"
#include "sounds.h"
#include "spdigger_stack.h"
#include "thing_data.h"
#include "thing_effects.h"
#include "thing_navigate.h"
Expand Down Expand Up @@ -301,6 +302,7 @@ rules_creatures_named_fields,rules_computer_named_fields,rules_workers_named_fie
static const struct NamedCommand game_rule_desc[] = {
{"PreserveClassicBugs", 1},
{"AlliesShareVision", 2},
{"MapCreatureLimit", 3},
{NULL, 0},
};

Expand Down Expand Up @@ -5456,6 +5458,54 @@ static void set_game_rule_process(struct ScriptContext* context)
game.conf.rules.game.allies_share_vision = (TbBool)rulevalue;
panel_map_update(0, 0, gameadd.map_subtiles_x + 1, gameadd.map_subtiles_y + 1);
break;
case 3: //MapCreatureLimit
//this one is a special case because it needs to kill of additional creatures
SCRIPTDBG(7, "Changing Game Rule '%s' from %d to %d", rulename, game.conf.rules.game.creatures_count, rulevalue);
game.conf.rules.game.creatures_count = rulevalue;
struct CreatureControl* cctrl;
const struct StructureList* slist = get_list_for_thing_class(TCls_Creature);
Loobinex marked this conversation as resolved.
Show resolved Hide resolved
unsigned long k = 0;
int i = slist->index;
short count = 0;
while (i != 0)
{
struct Thing* thing = thing_get(i);
if (thing_is_invalid(thing))
{
ERRORLOG("Jump to invalid thing detected");
break;
}
i = thing->next_of_class;
// Per-thing code
cctrl = creature_control_get_from_thing(thing);
if (cctrl->index > game.conf.rules.game.creatures_count)
{
count++;
cleanup_creature_state_and_interactions(thing);
force_any_creature_dragging_thing_to_drop_it(thing);

if (is_thing_some_way_controlled(thing) || thing_is_picked_up(thing))
{
kill_creature(thing, INVALID_THING, -1, CrDed_Default);
}
else
{
setup_creature_leaves_or_dies(thing);
}
}
// Per-thing code ends
k++;
if (k > CREATURES_COUNT)
{
ERRORLOG("Infinite loop detected when sweeping things list");
break;
}
}
if (count > 0)
{
SCRPTLOG("Map creature limit reduced, causing %d creatures to leave or die",count);
}
break;
default:
WARNMSG("Unsupported Game Rule, command %d.", ruledesc);
break;
Expand Down
4 changes: 4 additions & 0 deletions src/lvl_script_commands_old.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ static void command_add_creature_to_level(long plr_range_id, const char *crtr_na
SCRPTERRLOG("Invalid number of creatures to add");
return;
}
if (ncopies > game.conf.rules.game.creatures_count)
{
SCRPTWRNLOG("Trying to add %d creatures which is over map limit %d", ncopies, game.conf.rules.game.creatures_count);
}
if (gameadd.script.party_triggers_num >= PARTY_TRIGGERS_COUNT)
{
SCRPTERRLOG("Too many ADD_CREATURE commands in script");
Expand Down
5 changes: 5 additions & 0 deletions src/magic.c
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,11 @@ static TbResult magic_use_power_imp(PowerKind power_kind, PlayerNumber plyr_idx,
|| !i_can_allocate_free_thing_structure(FTAF_FreeEffectIfNoSlots)) {
return Lb_FAIL;
}
if (!creature_count_below_map_limit(0))
{
SYNCLOG("Player %d attempts to create creature at map creature limit", plyr_idx);
return Lb_FAIL;
}
if ((mod_flags & PwMod_CastForFree) == 0)
{
// If we can't afford the spell, fail
Expand Down
5 changes: 5 additions & 0 deletions src/player_compchecks.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,11 @@ long computer_check_no_imps(struct Computer2 *comp, struct ComputerCheck * check
SYNCDBG(7,"Computer players %d dungeon in invalid or has no heart",(int)dungeon->owner);
return CTaskRet_Unk4;
}
if (!creature_count_below_map_limit(0))
{
SYNCDBG(7, "Computer player %d can't create imps due to map limit", (int)dungeon->owner);
return CTaskRet_Unk4;
}
long controlled_diggers = dungeon->num_active_diggers - count_player_diggers_not_counting_to_total(dungeon->owner);
int preferred_imps;
int minimal_imps;
Expand Down
4 changes: 2 additions & 2 deletions src/power_hand.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ TbBool can_thing_be_picked_up2_by_player(const struct Thing *thing, PlayerNumber
state = thing->active_state;
}

if ( (state == CrSt_CreatureSacrifice)
|| (state == CrSt_CreatureBeingSacrificed) || (state == CrSt_CreatureBeingSummoned))
if ( (state == CrSt_CreatureSacrifice) || (state == CrSt_CreatureBeingSacrificed)
|| (state == CrSt_CreatureBeingSummoned) || (state == CrSt_LeavesBecauseOwnerLost))
{
return false;
}
Expand Down
Loading