From 29be66f81c6f52ff7101dc309123831819ea2823 Mon Sep 17 00:00:00 2001 From: benlp91 Date: Fri, 19 Jul 2024 15:16:33 +0200 Subject: [PATCH 01/54] Rule for CREATURES_COUNT --- config/fxdata/rules.cfg | 2 ++ src/actionpt.c | 2 +- src/config_creature.c | 4 ++-- src/config_rules.c | 1 + src/config_rules.h | 1 + src/console_cmd.c | 20 +++++++++++++++++++- src/creature_battle.c | 2 +- src/creature_control.c | 12 ++++++------ src/creature_control.h | 3 +-- src/creature_groups.c | 8 ++++---- src/creature_states.c | 2 +- src/creature_states_combt.c | 12 ++++++------ src/creature_states_hero.c | 4 ++-- src/creature_states_pray.c | 6 +++--- src/creature_states_scavn.c | 2 +- src/lvl_script_commands.c | 6 +++--- src/lvl_script_commands_old.c | 4 ++-- src/magic.c | 8 ++++---- src/main.cpp | 8 ++++---- src/main_game.c | 4 ++-- src/player_compchecks.c | 4 ++-- src/player_compevents.c | 6 +++--- src/player_comptask.c | 6 +++--- src/player_computer.c | 4 ++-- src/power_specials.c | 8 ++++---- src/room_lair.c | 2 +- src/spdigger_stack.c | 4 ++-- src/thing_data.h | 2 +- 28 files changed, 84 insertions(+), 63 deletions(-) diff --git a/config/fxdata/rules.cfg b/config/fxdata/rules.cfg index 657c9cf0e5..ee44c96b00 100644 --- a/config/fxdata/rules.cfg +++ b/config/fxdata/rules.cfg @@ -59,6 +59,8 @@ EasterEggSpeechChance = 2000 EasterEggSpeechInterval = 20000 ; Possible Classic Bugs: 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 PreserveClassicBugs = +; Total Amount of Creatures on the map . +Creatures_Count = 1024 [computer] ; Maximum health percentage when creatures are considered to be put to temple to cure of disease. diff --git a/src/actionpt.c b/src/actionpt.c index d5c546b9dc..7810df244c 100644 --- a/src/actionpt.c +++ b/src/actionpt.c @@ -212,7 +212,7 @@ TbBool action_point_is_creature_from_list_within(const struct ActionPoint *apt, } // Thing list loop body ends k++; - if (k > CREATURES_COUNT) + if (k > game.conf.rules.game.creatures_count) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; diff --git a/src/config_creature.c b/src/config_creature.c index 4d20d4749a..19524e563a 100644 --- a/src/config_creature.c +++ b/src/config_creature.c @@ -1776,8 +1776,8 @@ TbBool set_creature_available(PlayerNumber plyr_idx, ThingModel crtr_model, long } if (force_avail < 0) force_avail = 0; - if (force_avail >= CREATURES_COUNT) - force_avail = CREATURES_COUNT-1; + if (force_avail >= game.conf.rules.game.creatures_count) + force_avail = game.conf.rules.game.creatures_count-1; SYNCDBG(7,"Setting %s availability for player %d to allowed=%d, forced=%d.",thing_class_and_model_name(TCls_Creature, crtr_model),(int)plyr_idx,(int)can_be_avail,(int)force_avail); dungeon->creature_allowed[crtr_model] = can_be_avail; dungeon->creature_force_enabled[crtr_model] = force_avail; diff --git a/src/config_rules.c b/src/config_rules.c index 9971572814..47ae07d99d 100644 --- a/src/config_rules.c +++ b/src/config_rules.c @@ -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}, + {"CREATURESCOUNT", &game.conf.rules.game.creatures_count, var_type(game.conf.rules.game.creatures_count ), 0,CREATURES_COUNT}, {NULL, NULL,0,0,0 }, }; diff --git a/src/config_rules.h b/src/config_rules.h index 0c073497e1..e8c8d33f19 100644 --- a/src/config_rules.h +++ b/src/config_rules.h @@ -102,6 +102,7 @@ struct GameRulesConfig { unsigned long easter_egg_speech_interval; long global_ambient_light; TbBool light_enabled; + unsigned long creatures_count; }; struct ComputerRulesConfig { diff --git a/src/console_cmd.c b/src/console_cmd.c index 9eced6a47e..d523e04eae 100644 --- a/src/console_cmd.c +++ b/src/console_cmd.c @@ -724,7 +724,25 @@ 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)) { diff --git a/src/creature_battle.c b/src/creature_battle.c index 80be797a6d..651a62ad8a 100644 --- a/src/creature_battle.c +++ b/src/creature_battle.c @@ -458,7 +458,7 @@ long setup_player_battlers(struct PlayerInfo *player, struct CreatureBattle *bat } // Per creature code ends k++; - if (k > CREATURES_COUNT) + if (k > game.conf.rules.game.creatures_count) { ERRORLOG("Infinite loop detected when sweeping battle creatures list"); break; diff --git a/src/creature_control.c b/src/creature_control.c index 0983a69caf..499dd0fe93 100644 --- a/src/creature_control.c +++ b/src/creature_control.c @@ -47,7 +47,7 @@ extern "C" { */ struct CreatureControl *creature_control_get(long cctrl_idx) { - if ((cctrl_idx < 1) || (cctrl_idx > CREATURES_COUNT)) + if ((cctrl_idx < 1) || (cctrl_idx > game.conf.rules.game.creatures_count)) return INVALID_CRTR_CONTROL; return game.persons.cctrl_lookup[cctrl_idx]; } @@ -58,7 +58,7 @@ struct CreatureControl *creature_control_get(long cctrl_idx) */ struct CreatureControl *creature_control_get_from_thing(const struct Thing *thing) { - if ((thing->ccontrol_idx < 1) || (thing->ccontrol_idx > CREATURES_COUNT)) + if ((thing->ccontrol_idx < 1) || (thing->ccontrol_idx > game.conf.rules.game.creatures_count)) return INVALID_CRTR_CONTROL; return game.persons.cctrl_lookup[thing->ccontrol_idx]; } @@ -87,7 +87,7 @@ TbBool creature_control_exists_in_thing(const struct Thing *thing) long i_can_allocate_free_control_structure(void) { - for (long i = 1; i < CREATURES_COUNT; i++) + for (long i = 1; i < game.conf.rules.game.creatures_count; i++) { struct CreatureControl* cctrl = game.persons.cctrl_lookup[i]; if (!creature_control_invalid(cctrl)) @@ -101,7 +101,7 @@ long i_can_allocate_free_control_structure(void) struct CreatureControl *allocate_free_control_structure(void) { - for (long i = 1; i < CREATURES_COUNT; i++) + for (long i = 1; i < game.conf.rules.game.creatures_count; i++) { struct CreatureControl* cctrl = game.persons.cctrl_lookup[i]; if (!creature_control_invalid(cctrl)) @@ -125,7 +125,7 @@ void delete_control_structure(struct CreatureControl *cctrl) void delete_all_control_structures(void) { - for (long i = 1; i < CREATURES_COUNT; i++) + for (long i = 1; i < game.conf.rules.game.creatures_count; i++) { struct CreatureControl* cctrl = creature_control_get(i); if (!creature_control_invalid(cctrl)) @@ -207,7 +207,7 @@ struct Thing *get_group_last_member(struct Thing *thing) ctng = thing_get(cctrl->next_in_group); cctrl = creature_control_get_from_thing(ctng); k++; - if (k > CREATURES_COUNT) + if (k > game.conf.rules.game.creatures_count) { ERRORLOG("Infinite loop detected when sweeping creatures group"); break; diff --git a/src/creature_control.h b/src/creature_control.h index f0a4b01651..6dd3ba4ffc 100644 --- a/src/creature_control.h +++ b/src/creature_control.h @@ -138,9 +138,8 @@ struct CastedSpellData { unsigned char spkind; short duration; }; - struct CreatureControl { - unsigned char index; + unsigned short index; unsigned char flgfield_1; unsigned char flgfield_2; unsigned char combat_flags; diff --git a/src/creature_groups.c b/src/creature_groups.c index 2a7e5d3813..861297c3ae 100644 --- a/src/creature_groups.c +++ b/src/creature_groups.c @@ -74,7 +74,7 @@ struct Thing *get_highest_experience_and_score_creature_in_group(struct Thing *g // Per-thing code ends i = cctrl->next_in_group; k++; - if (k > CREATURES_COUNT) + if (k > game.conf.rules.game.creatures_count) { ERRORLOG("Infinite loop detected when sweeping creatures group"); break; @@ -129,7 +129,7 @@ struct Thing *get_last_follower_creature_in_group(const struct Thing *grptng) break; i = cctrl->next_in_group; k++; - if (k > CREATURES_COUNT) + if (k > game.conf.rules.game.creatures_count) { ERRORLOG("Infinite loop detected when sweeping creatures group"); break; @@ -371,7 +371,7 @@ static short creatures_group_has_special_digger_to_lead(struct Thing* grptng) } i = cctrl->next_in_group; k++; - if (k > CREATURES_COUNT) + if (k > game.conf.rules.game.creatures_count) { ERRORLOG("Infinite loop detected when sweeping creatures group"); break; @@ -467,7 +467,7 @@ struct Thing* get_best_creature_to_lead_group(struct Thing* grptng) // Per-thing code ends i = cctrl->next_in_group; k++; - if (k > CREATURES_COUNT) + if (k > game.conf.rules.game.creatures_count) { ERRORLOG("Infinite loop detected when sweeping creatures group"); break; diff --git a/src/creature_states.c b/src/creature_states.c index 3ad63ec95c..1818ea49e7 100644 --- a/src/creature_states.c +++ b/src/creature_states.c @@ -2347,7 +2347,7 @@ struct Thing *find_random_creature_for_persuade(PlayerNumber plyr_idx, struct Co n--; // Per thing code ends k++; - if (k > CREATURES_COUNT) + if (k > game.conf.rules.game.creatures_count) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; diff --git a/src/creature_states_combt.c b/src/creature_states_combt.c index 2c97a1635e..f7718c7f8e 100644 --- a/src/creature_states_combt.c +++ b/src/creature_states_combt.c @@ -537,7 +537,7 @@ long count_creatures_really_in_combat(BattleIndex battle_id) } // Per thing code ends k++; - if (k > CREATURES_COUNT) + if (k > game.conf.rules.game.creatures_count) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; @@ -562,7 +562,7 @@ void cleanup_battle(BattleIndex battle_id) TRACE_THING(thing); remove_thing_from_battle_list(thing); k++; - if (k > CREATURES_COUNT) + if (k > game.conf.rules.game.creatures_count) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; @@ -603,7 +603,7 @@ void update_battle_events(BattleIndex battle_id) map_z = thing->mappos.z.val; // Per thing code ends k++; - if (k > CREATURES_COUNT) + if (k > game.conf.rules.game.creatures_count) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; @@ -649,7 +649,7 @@ TbBool battle_with_creature_of_player(PlayerNumber plyr_idx, BattleIndex battle_ return true; // Per thing code ends k++; - if (k > CREATURES_COUNT) + if (k > game.conf.rules.game.creatures_count) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; @@ -692,7 +692,7 @@ TbBool battle_any_of_things_in_specific_battle(const struct CreatureBattle *batt } // Per battle creature code ends k++; - if (k >= CREATURES_COUNT) { + if (k >= game.conf.rules.game.creatures_count) { ERRORLOG("Infinite loop in battle add"); break; } @@ -1265,7 +1265,7 @@ CrAttackType find_fellow_creature_to_fight_in_room(struct Thing *fightng, struct } // Thing list loop body ends k++; - if (k > CREATURES_COUNT) + if (k > game.conf.rules.game.creatures_count) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; diff --git a/src/creature_states_hero.c b/src/creature_states_hero.c index ea942352ac..d1c8dbd4bf 100644 --- a/src/creature_states_hero.c +++ b/src/creature_states_hero.c @@ -409,7 +409,7 @@ long get_wanderer_possible_targets_count_in_list(long first_thing_idx, struct Th } // Thing list loop body ends k++; - if (k > CREATURES_COUNT) + if (k > game.conf.rules.game.creatures_count) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; @@ -465,7 +465,7 @@ TbBool wander_to_specific_possible_target_in_list(long first_thing_idx, struct T break; // Thing list loop body ends k++; - if (k > CREATURES_COUNT) + if (k > game.conf.rules.game.creatures_count) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; diff --git a/src/creature_states_pray.c b/src/creature_states_pray.c index 421ea21eca..0cd6c85b60 100644 --- a/src/creature_states_pray.c +++ b/src/creature_states_pray.c @@ -223,7 +223,7 @@ TbBool add_anger_to_all_creatures_of_player(PlayerNumber plyr_idx, short percent anger_give_creatures_annoyance_percentage(thing, percentage, AngR_Other); // Thing list loop body ends k++; - if (k > CREATURES_COUNT) + if (k > game.conf.rules.game.creatures_count) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; @@ -254,7 +254,7 @@ TbBool make_all_players_creatures_angry(long plyr_idx) anger_make_creature_angry(thing, AngR_Other); // Thing list loop body ends k++; - if (k > CREATURES_COUNT) + if (k > game.conf.rules.game.creatures_count) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; @@ -326,7 +326,7 @@ void apply_spell_effect_to_players_creatures(PlayerNumber plyr_idx, ThingModel c } // Thing list loop body ends k++; - if (k > CREATURES_COUNT) + if (k > game.conf.rules.game.creatures_count) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; diff --git a/src/creature_states_scavn.c b/src/creature_states_scavn.c index da54fc6af5..9d6f2397b5 100644 --- a/src/creature_states_scavn.c +++ b/src/creature_states_scavn.c @@ -127,7 +127,7 @@ struct Thing *get_random_fellow_not_hated_creature(struct Thing *creatng) n--; // Thing list loop body ends k++; - if (k > CREATURES_COUNT) + if (k > game.conf.rules.game.creatures_count) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; diff --git a/src/lvl_script_commands.c b/src/lvl_script_commands.c index 6bbdef5a03..071931e23a 100644 --- a/src/lvl_script_commands.c +++ b/src/lvl_script_commands.c @@ -569,7 +569,7 @@ TbBool script_change_creatures_annoyance(PlayerNumber plyr_idx, ThingModel crmod } // Thing list loop body ends k++; - if (k > CREATURES_COUNT) + if (k > game.conf.rules.game.creatures_count) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; @@ -3860,7 +3860,7 @@ static void level_up_players_creatures_process(struct ScriptContext* context) } // Thing list loop body ends k++; - if (k > CREATURES_COUNT) + if (k > game.conf.rules.game.creatures_count) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; @@ -4030,7 +4030,7 @@ void cast_power_on_players_creatures(PlayerNumber plyr_idx, ThingModel crmodel, } // Thing list loop body ends k++; - if (k > CREATURES_COUNT) + if (k > game.conf.rules.game.creatures_count) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; diff --git a/src/lvl_script_commands_old.c b/src/lvl_script_commands_old.c index b1ba4db50a..200521f78e 100644 --- a/src/lvl_script_commands_old.c +++ b/src/lvl_script_commands_old.c @@ -169,7 +169,7 @@ static void command_add_creature_to_level(long plr_range_id, const char *crtr_na SCRPTERRLOG("Invalid CREATURE LEVEL parameter"); return; } - if ((ncopies <= 0) || (ncopies >= CREATURES_COUNT)) + if ((ncopies <= 0) || (ncopies >= game.conf.rules.game.creatures_count)) { SCRPTERRLOG("Invalid number of creatures to add"); return; @@ -599,7 +599,7 @@ static void command_add_creature_to_pool(const char *crtr_name, long amount) SCRPTERRLOG("Unknown creature, '%s'", crtr_name); return; } - if ((amount < 0) || (amount >= CREATURES_COUNT)) + if ((amount < 0) || (amount >= game.conf.rules.game.creatures_count)) { SCRPTERRLOG("Invalid number of '%s' creatures for pool, %d", crtr_name, amount); return; diff --git a/src/magic.c b/src/magic.c index 8654891f31..a955c091bb 100644 --- a/src/magic.c +++ b/src/magic.c @@ -1092,7 +1092,7 @@ static TbResult magic_use_power_hold_audience(PowerKind power_kind, PlayerNumber } // Thing list loop body ends k++; - if (k > CREATURES_COUNT) + if (k > game.conf.rules.game.creatures_count) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; @@ -1653,7 +1653,7 @@ long update_creatures_influenced_by_call_to_arms(PlayerNumber plyr_idx) } // Thing list loop body ends k++; - if (k > CREATURES_COUNT) + if (k > game.conf.rules.game.creatures_count) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; @@ -1789,7 +1789,7 @@ static void magic_power_hold_audience_update(PlayerNumber plyr_idx) } // Thing list loop body ends k++; - if (k > CREATURES_COUNT) + if (k > game.conf.rules.game.creatures_count) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; @@ -1853,7 +1853,7 @@ int affect_nearby_creatures_by_power_call_to_arms(PlayerNumber plyr_idx, long ra } // Thing list loop body ends k++; - if (k > CREATURES_COUNT) + if (k > game.conf.rules.game.creatures_count) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; diff --git a/src/main.cpp b/src/main.cpp index 1caaec9361..33a9114390 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -510,7 +510,7 @@ void affect_nearby_friends_with_alarm(struct Thing *traptng) } // Thing list loop body ends k++; - if (k > CREATURES_COUNT) + if (k > game.conf.rules.game.creatures_count) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; @@ -1750,7 +1750,7 @@ void clear_things_and_persons_data(void) thing->mappos.x.val = subtile_coord_center(gameadd.map_subtiles_x/2); thing->mappos.y.val = subtile_coord_center(gameadd.map_subtiles_y/2); } - for (i=0; i < CREATURES_COUNT; i++) + for (i=0; i < game.conf.rules.game.creatures_count; i++) { memset(&game.cctrl_data[i], 0, sizeof(struct CreatureControl)); } @@ -2430,7 +2430,7 @@ static void process_dungeon_devastation_effects(void) } } -void count_players_creatures_being_paid(int *creatures_count) +void count_players_creatures_being_paid(int *game.conf.rules.game.creatures_count) { unsigned long k; long i; @@ -2463,7 +2463,7 @@ void count_players_creatures_being_paid(int *creatures_count) } else { cctrl->paydays_owed++; - creatures_count[thing->owner]++; + game.conf.rules.game.creatures_count[thing->owner]++; } } } diff --git a/src/main_game.c b/src/main_game.c index 48636a0b89..ebd48e8446 100644 --- a/src/main_game.c +++ b/src/main_game.c @@ -130,11 +130,11 @@ void init_lookups(void) game.things.end = &game.things_data[THINGS_COUNT]; memset(&game.persons, 0, sizeof(struct Persons)); - for (i=0; i < CREATURES_COUNT; i++) + for (i=0; i < game.conf.rules.game.creatures_count; i++) { game.persons.cctrl_lookup[i] = &game.cctrl_data[i]; } - game.persons.cctrl_end = &game.cctrl_data[CREATURES_COUNT]; + game.persons.cctrl_end = &game.cctrl_data[game.conf.rules.game.creatures_count]; for (i=0; i < COLUMNS_COUNT; i++) { diff --git a/src/player_compchecks.c b/src/player_compchecks.c index 723dcf52a0..c3de5478f6 100644 --- a/src/player_compchecks.c +++ b/src/player_compchecks.c @@ -358,7 +358,7 @@ static TbBool any_digger_is_digging_indestructible_valuables(struct Dungeon *dun } // Thing list loop body ends k++; - if (k > CREATURES_COUNT) + if (k > game.conf.rules.game.creatures_count) { ERRORLOG("Infinite loop detected when sweeping creatures list"); return false; @@ -628,7 +628,7 @@ struct Thing * find_imp_for_pickup(struct Computer2 *comp, MapSubtlCoord stl_x, } // Thing list loop body ends k++; - if (k > CREATURES_COUNT) + if (k > game.conf.rules.game.creatures_count) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; diff --git a/src/player_compevents.c b/src/player_compevents.c index 8b2c71b125..c9fd726b2c 100644 --- a/src/player_compevents.c +++ b/src/player_compevents.c @@ -271,7 +271,7 @@ struct Thing *find_creature_in_fight_with_enemy(struct Computer2 *comp) } // Thing list loop body ends k++; - if (k > CREATURES_COUNT) + if (k > game.conf.rules.game.creatures_count) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; @@ -298,7 +298,7 @@ struct Thing *find_creature_in_fight_with_enemy(struct Computer2 *comp) } // Thing list loop body ends k++; - if (k > CREATURES_COUNT) + if (k > game.conf.rules.game.creatures_count) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; @@ -838,7 +838,7 @@ long computer_event_check_imps_in_danger(struct Computer2 *comp, struct Computer } // Thing list loop body ends k++; - if (k > CREATURES_COUNT) + if (k > game.conf.rules.game.creatures_count) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; diff --git a/src/player_comptask.c b/src/player_comptask.c index a734b7f21c..18b04a5b4a 100644 --- a/src/player_comptask.c +++ b/src/player_comptask.c @@ -2307,7 +2307,7 @@ long count_creatures_at_call_to_arms(struct Computer2 *comp) if (get_creature_state_besides_move(i) == CrSt_AlreadyAtCallToArms) num_creatures++; k++; - if (k > CREATURES_COUNT) + if (k > game.conf.rules.game.creatures_count) { ERRORLOG("Infinite loop detected when counting creatures in call to arms"); return num_creatures; @@ -2556,7 +2556,7 @@ struct Thing *find_creature_for_pickup(struct Computer2 *comp, struct Coord3d *p } // Thing list loop body ends k++; - if (k > CREATURES_COUNT) + if (k > game.conf.rules.game.creatures_count) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; @@ -2628,7 +2628,7 @@ long count_creatures_for_pickup(struct Computer2 *comp, struct Coord3d *pos, str } // Thing list loop body ends k++; - if (k > CREATURES_COUNT) + if (k > game.conf.rules.game.creatures_count) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; diff --git a/src/player_computer.c b/src/player_computer.c index 712a2ff997..d6ee905476 100644 --- a/src/player_computer.c +++ b/src/player_computer.c @@ -462,7 +462,7 @@ unsigned long count_creatures_availiable_for_fight(struct Computer2 *comp, struc } // Thing list loop body ends k++; - if (k > CREATURES_COUNT) + if (k > game.conf.rules.game.creatures_count) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; @@ -1106,7 +1106,7 @@ long count_creatures_for_defend_pickup(struct Computer2 *comp) } k++; - if (k > CREATURES_COUNT) + if (k > game.conf.rules.game.creatures_count) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; diff --git a/src/power_specials.c b/src/power_specials.c index 0e4c245b77..4b5664a177 100644 --- a/src/power_specials.c +++ b/src/power_specials.c @@ -100,7 +100,7 @@ void multiply_creatures_in_dungeon_list(struct Dungeon *dungeon, long list_start tncopy->health = thing->health; // Thing list loop body ends k++; - if (k > CREATURES_COUNT) + if (k > game.conf.rules.game.creatures_count) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; @@ -140,7 +140,7 @@ void increase_level(struct PlayerInfo *player, int count) else creature_increase_level(thing); // Thing list loop body ends k++; - if (k > CREATURES_COUNT) + if (k > game.conf.rules.game.creatures_count) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; @@ -164,7 +164,7 @@ void increase_level(struct PlayerInfo *player, int count) else creature_increase_level(thing); // Thing list loop body ends k++; - if (k > CREATURES_COUNT) + if (k > game.conf.rules.game.creatures_count) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; @@ -233,7 +233,7 @@ TbBool steal_hero(struct PlayerInfo *player, struct Coord3d *pos) } // Thing list loop body ends k++; - if (k > CREATURES_COUNT) + if (k > game.conf.rules.game.creatures_count) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; diff --git a/src/room_lair.c b/src/room_lair.c index c74bc26bef..942da86973 100644 --- a/src/room_lair.c +++ b/src/room_lair.c @@ -103,7 +103,7 @@ long calculate_free_lair_space(struct Dungeon * dungeon) } // Thing list loop body ends k++; - if (k > CREATURES_COUNT) + if (k > game.conf.rules.game.creatures_count) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; diff --git a/src/spdigger_stack.c b/src/spdigger_stack.c index 7b1514cd7d..b985a84fba 100644 --- a/src/spdigger_stack.c +++ b/src/spdigger_stack.c @@ -228,7 +228,7 @@ TbBool imp_will_soon_be_working_at_excluding(const struct Thing *creatng, MapSub } // Thing list loop body ends k++; - if (k > CREATURES_COUNT) + if (k > game.conf.rules.game.creatures_count) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; @@ -276,7 +276,7 @@ TbBool imp_will_soon_be_getting_object(PlayerNumber plyr_idx, const struct Thing } // Thing list loop body ends k++; - if (k > CREATURES_COUNT) + if (k > game.conf.rules.game.creatures_count) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; diff --git a/src/thing_data.h b/src/thing_data.h index 9aa9015a95..3211a52375 100644 --- a/src/thing_data.h +++ b/src/thing_data.h @@ -23,7 +23,7 @@ #include "bflib_basics.h" /** Max amount of creatures supported on any map. */ -#define CREATURES_COUNT 256 +#define CREATURES_COUNT 2100 #ifdef __cplusplus extern "C" { From a8dc96f6eae7e951b4534f3291639e3a5086fec4 Mon Sep 17 00:00:00 2001 From: benlp91 Date: Fri, 19 Jul 2024 15:27:47 +0200 Subject: [PATCH 02/54] fixes --- src/main.cpp | 4 ++-- src/thing_data.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 33a9114390..eb2dd9aa56 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2430,7 +2430,7 @@ static void process_dungeon_devastation_effects(void) } } -void count_players_creatures_being_paid(int *game.conf.rules.game.creatures_count) +void count_players_creatures_being_paid(int *creatures_count) { unsigned long k; long i; @@ -2463,7 +2463,7 @@ void count_players_creatures_being_paid(int *game.conf.rules.game.creatures_coun } else { cctrl->paydays_owed++; - game.conf.rules.game.creatures_count[thing->owner]++; + creatures_count[thing->owner]++; } } } diff --git a/src/thing_data.h b/src/thing_data.h index 3211a52375..d2e8f941fb 100644 --- a/src/thing_data.h +++ b/src/thing_data.h @@ -23,7 +23,7 @@ #include "bflib_basics.h" /** Max amount of creatures supported on any map. */ -#define CREATURES_COUNT 2100 +#define CREATURES_COUNT 1024 #ifdef __cplusplus extern "C" { From 25c4c05b7173d54a45201f78ce3df3b7c8980faf Mon Sep 17 00:00:00 2001 From: benlp91 Date: Fri, 19 Jul 2024 19:50:55 +0200 Subject: [PATCH 03/54] Update config_rules.c --- src/config_rules.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config_rules.c b/src/config_rules.c index 47ae07d99d..eb91b8a649 100644 --- a/src/config_rules.c +++ b/src/config_rules.c @@ -93,7 +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}, - {"CREATURESCOUNT", &game.conf.rules.game.creatures_count, var_type(game.conf.rules.game.creatures_count ), 0,CREATURES_COUNT}, + {"CREATURES_COUNT", &game.conf.rules.game.creatures_count, var_type(game.conf.rules.game.creatures_count ), 0,CREATURES_COUNT}, {NULL, NULL,0,0,0 }, }; From b00e914a66dc0b9a551d47e61003d1f877fece82 Mon Sep 17 00:00:00 2001 From: benlp91 Date: Fri, 19 Jul 2024 19:56:51 +0200 Subject: [PATCH 04/54] Update rules.cfg added a better description to the rules.cfg --- config/fxdata/rules.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/fxdata/rules.cfg b/config/fxdata/rules.cfg index ee44c96b00..c5f7345324 100644 --- a/config/fxdata/rules.cfg +++ b/config/fxdata/rules.cfg @@ -59,7 +59,7 @@ EasterEggSpeechChance = 2000 EasterEggSpeechInterval = 20000 ; Possible Classic Bugs: 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 PreserveClassicBugs = -; Total Amount of Creatures on the map . +; Total Amount of Creatures on the map .The absolute maximum is 1024. Creatures_Count = 1024 [computer] From af74c9d9e85f35156192ec6897691ea3c6db7b9c Mon Sep 17 00:00:00 2001 From: benlp91 Date: Fri, 26 Jul 2024 20:32:50 +0200 Subject: [PATCH 05/54] name change + added rule to maps/campaigns changed the name to MapCreaturesLimit and made the rules that old maps and campaigns have the old 256 creature count --- config/fxdata/rules.cfg | 2 +- levels/classic_cfgs/rules.cfg | 2 ++ levels/legacy_cfgs/rules.cfg | 2 ++ src/config_rules.c | 2 +- 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/config/fxdata/rules.cfg b/config/fxdata/rules.cfg index c5f7345324..f069f1c7d6 100644 --- a/config/fxdata/rules.cfg +++ b/config/fxdata/rules.cfg @@ -60,7 +60,7 @@ EasterEggSpeechInterval = 20000 ; Possible Classic Bugs: 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 PreserveClassicBugs = ; Total Amount of Creatures on the map .The absolute maximum is 1024. -Creatures_Count = 1024 +MapCreatureLimit = 1024 [computer] ; Maximum health percentage when creatures are considered to be put to temple to cure of disease. diff --git a/levels/classic_cfgs/rules.cfg b/levels/classic_cfgs/rules.cfg index b129109e8f..49018021ad 100644 --- a/levels/classic_cfgs/rules.cfg +++ b/levels/classic_cfgs/rules.cfg @@ -3,3 +3,5 @@ [game] DungeonHeartHealHealth = 1 +; Total Amount of Creatures on the map .The absolute maximum is 1024. +MapCreatureLimit = 256 \ No newline at end of file diff --git a/levels/legacy_cfgs/rules.cfg b/levels/legacy_cfgs/rules.cfg index 97cc68bef8..04072052a8 100644 --- a/levels/legacy_cfgs/rules.cfg +++ b/levels/legacy_cfgs/rules.cfg @@ -5,6 +5,8 @@ [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 +; Total Amount of Creatures on the map .The absolute maximum is 1024. +MapCreatureLimit = 1024 [computer] DiseaseHPTemplePercentage = 50 diff --git a/src/config_rules.c b/src/config_rules.c index eb91b8a649..9344793401 100644 --- a/src/config_rules.c +++ b/src/config_rules.c @@ -93,7 +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}, - {"CREATURES_COUNT", &game.conf.rules.game.creatures_count, var_type(game.conf.rules.game.creatures_count ), 0,CREATURES_COUNT}, + {"MAPCREATURELIMIT", &game.conf.rules.game.creatures_count, var_type(game.conf.rules.game.creatures_count ), 0,CREATURES_COUNT}, {NULL, NULL,0,0,0 }, }; From 3d6d4706106d0a74dcc811d6d18f946c9daeff49 Mon Sep 17 00:00:00 2001 From: benlp91 Date: Fri, 26 Jul 2024 22:16:23 +0200 Subject: [PATCH 06/54] Update rules.cfg --- levels/legacy_cfgs/rules.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/levels/legacy_cfgs/rules.cfg b/levels/legacy_cfgs/rules.cfg index 04072052a8..9c54cfd815 100644 --- a/levels/legacy_cfgs/rules.cfg +++ b/levels/legacy_cfgs/rules.cfg @@ -6,7 +6,7 @@ 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 ; Total Amount of Creatures on the map .The absolute maximum is 1024. -MapCreatureLimit = 1024 +MapCreatureLimit = 256 [computer] DiseaseHPTemplePercentage = 50 From ccd204924f8b7c315774c4fcee663df517210b3e Mon Sep 17 00:00:00 2001 From: Loobinex Date: Sun, 1 Sep 2024 18:18:48 +0200 Subject: [PATCH 07/54] Give it a default value --- src/config_rules.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/config_rules.c b/src/config_rules.c index 9344793401..b5c76589e9 100644 --- a/src/config_rules.c +++ b/src/config_rules.c @@ -287,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 = 256; // Creature block. game.conf.rules.creature.recovery_frequency = 10; game.conf.rules.creature.fight_max_hate = 200; From 1fad09f306738b245d619b9d755c6b7c9389845b Mon Sep 17 00:00:00 2001 From: benlp91 Date: Sun, 1 Sep 2024 18:22:25 +0200 Subject: [PATCH 08/54] some fixes --- levels/classic_cfgs/rules.cfg | 2 +- levels/legacy_cfgs/rules.cfg | 2 +- src/main.cpp | 2 +- src/main_game.c | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/levels/classic_cfgs/rules.cfg b/levels/classic_cfgs/rules.cfg index 49018021ad..8bb79632de 100644 --- a/levels/classic_cfgs/rules.cfg +++ b/levels/classic_cfgs/rules.cfg @@ -4,4 +4,4 @@ [game] DungeonHeartHealHealth = 1 ; Total Amount of Creatures on the map .The absolute maximum is 1024. -MapCreatureLimit = 256 \ No newline at end of file +MapCreatureLimit = 255 \ No newline at end of file diff --git a/levels/legacy_cfgs/rules.cfg b/levels/legacy_cfgs/rules.cfg index 9c54cfd815..46e0b9561c 100644 --- a/levels/legacy_cfgs/rules.cfg +++ b/levels/legacy_cfgs/rules.cfg @@ -6,7 +6,7 @@ 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 ; Total Amount of Creatures on the map .The absolute maximum is 1024. -MapCreatureLimit = 256 +MapCreatureLimit = 255 [computer] DiseaseHPTemplePercentage = 50 diff --git a/src/main.cpp b/src/main.cpp index eb2dd9aa56..0e6945a648 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1750,7 +1750,7 @@ void clear_things_and_persons_data(void) thing->mappos.x.val = subtile_coord_center(gameadd.map_subtiles_x/2); thing->mappos.y.val = subtile_coord_center(gameadd.map_subtiles_y/2); } - for (i=0; i < game.conf.rules.game.creatures_count; i++) + for (i=0; i < CREATURES_COUNT; i++) { memset(&game.cctrl_data[i], 0, sizeof(struct CreatureControl)); } diff --git a/src/main_game.c b/src/main_game.c index ebd48e8446..9700438d73 100644 --- a/src/main_game.c +++ b/src/main_game.c @@ -130,11 +130,11 @@ void init_lookups(void) game.things.end = &game.things_data[THINGS_COUNT]; memset(&game.persons, 0, sizeof(struct Persons)); - for (i=0; i < game.conf.rules.game.creatures_count; i++) + for (i=0; i < CREATURES_COUNT; i++) { game.persons.cctrl_lookup[i] = &game.cctrl_data[i]; } - game.persons.cctrl_end = &game.cctrl_data[game.conf.rules.game.creatures_count]; + game.persons.cctrl_end = &game.cctrl_data[CREATURES_COUNT]; for (i=0; i < COLUMNS_COUNT; i++) { From 4ff59548590da5aeed7e1df19efe3e62939f964d Mon Sep 17 00:00:00 2001 From: Loobinex Date: Sun, 1 Sep 2024 19:20:59 +0200 Subject: [PATCH 09/54] Created the offset of 1 --- src/config_rules.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/config_rules.c b/src/config_rules.c index b5c76589e9..1161f05fe8 100644 --- a/src/config_rules.c +++ b/src/config_rules.c @@ -93,13 +93,13 @@ 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}, {NULL, NULL,0,0,0 }, }; //special cases rules_game const struct NamedCommand rules_game_commands[] = { {"PRESERVECLASSICBUGS", 1}, + {"MAPCREATURELIMIT", 2}, {NULL, 0}, }; @@ -423,6 +423,17 @@ static void game_block_special_cases(int cmd_num,const char *buf,long *pos,long } } break; + case 2: + if (get_conf_parameter_single(buf, pos, len, word_buf, sizeof(word_buf)) > 0) + { + int k = atoi(word_buf); + if (k < 0) + k = 0; + if (k >= CREATURES_COUNT) + k = CREATURES_COUNT - 1; + game.conf.rules.game.creatures_count = k + 1; + } + break; } #undef COMMAND_TEXT } From 2c319b01d5e8203917025d0dc82596f9aca13fdb Mon Sep 17 00:00:00 2001 From: Loobinex Date: Sun, 1 Sep 2024 20:30:54 +0200 Subject: [PATCH 10/54] Update the config --- config/fxdata/rules.cfg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/fxdata/rules.cfg b/config/fxdata/rules.cfg index f069f1c7d6..2b4f56e9d4 100644 --- a/config/fxdata/rules.cfg +++ b/config/fxdata/rules.cfg @@ -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 1024. +MapCreatureLimit = 1000 ; Global light strength and dynamic lighting (32 is full bright). GlobalAmbientLight = 10 LightEnabled = 1 @@ -59,8 +61,6 @@ EasterEggSpeechChance = 2000 EasterEggSpeechInterval = 20000 ; Possible Classic Bugs: 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 PreserveClassicBugs = -; Total Amount of Creatures on the map .The absolute maximum is 1024. -MapCreatureLimit = 1024 [computer] ; Maximum health percentage when creatures are considered to be put to temple to cure of disease. From 243e338c6afe7bcd305185faf76bc88b46bdb211 Mon Sep 17 00:00:00 2001 From: Loobinex Date: Sun, 1 Sep 2024 20:40:06 +0200 Subject: [PATCH 11/54] made it work for SET_GAME_RULE --- src/lvl_script_commands.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/lvl_script_commands.c b/src/lvl_script_commands.c index 921aef6211..81f2cb2b05 100644 --- a/src/lvl_script_commands.c +++ b/src/lvl_script_commands.c @@ -301,6 +301,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}, }; @@ -5456,6 +5457,11 @@ 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 of the offset of 1 + SCRIPTDBG(7, "Changing Game Rule '%s' from %d to %d", rulename, game.conf.rules.game.creatures_count, rulevalue+1); + game.conf.rules.game.creatures_count = rulevalue+1; + break; default: WARNMSG("Unsupported Game Rule, command %d.", ruledesc); break; From f1b64aec7553ee1e2b1135e4f07c3f6ca4efb98e Mon Sep 17 00:00:00 2001 From: Loobinex Date: Mon, 2 Sep 2024 22:59:55 +0200 Subject: [PATCH 12/54] Put a lot of stuff back to CREATURES_COUNT --- src/actionpt.c | 2 +- src/config_creature.c | 4 ++-- src/creature_battle.c | 2 +- src/creature_control.c | 4 ++-- src/creature_groups.c | 8 ++++---- src/creature_states.c | 2 +- src/creature_states_combt.c | 12 ++++++------ src/creature_states_hero.c | 4 ++-- src/creature_states_pray.c | 6 +++--- src/creature_states_scavn.c | 2 +- src/lvl_script_commands.c | 6 +++--- src/lvl_script_commands_old.c | 2 +- src/magic.c | 8 ++++---- src/main.cpp | 2 +- src/player_compchecks.c | 4 ++-- src/player_compevents.c | 6 +++--- src/player_comptask.c | 6 +++--- src/player_computer.c | 4 ++-- src/power_specials.c | 8 ++++---- src/room_lair.c | 2 +- src/spdigger_stack.c | 4 ++-- 21 files changed, 49 insertions(+), 49 deletions(-) diff --git a/src/actionpt.c b/src/actionpt.c index 7810df244c..d5c546b9dc 100644 --- a/src/actionpt.c +++ b/src/actionpt.c @@ -212,7 +212,7 @@ TbBool action_point_is_creature_from_list_within(const struct ActionPoint *apt, } // Thing list loop body ends k++; - if (k > game.conf.rules.game.creatures_count) + if (k > CREATURES_COUNT) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; diff --git a/src/config_creature.c b/src/config_creature.c index 19524e563a..4d20d4749a 100644 --- a/src/config_creature.c +++ b/src/config_creature.c @@ -1776,8 +1776,8 @@ TbBool set_creature_available(PlayerNumber plyr_idx, ThingModel crtr_model, long } if (force_avail < 0) force_avail = 0; - if (force_avail >= game.conf.rules.game.creatures_count) - force_avail = game.conf.rules.game.creatures_count-1; + if (force_avail >= CREATURES_COUNT) + force_avail = CREATURES_COUNT-1; SYNCDBG(7,"Setting %s availability for player %d to allowed=%d, forced=%d.",thing_class_and_model_name(TCls_Creature, crtr_model),(int)plyr_idx,(int)can_be_avail,(int)force_avail); dungeon->creature_allowed[crtr_model] = can_be_avail; dungeon->creature_force_enabled[crtr_model] = force_avail; diff --git a/src/creature_battle.c b/src/creature_battle.c index 651a62ad8a..80be797a6d 100644 --- a/src/creature_battle.c +++ b/src/creature_battle.c @@ -458,7 +458,7 @@ long setup_player_battlers(struct PlayerInfo *player, struct CreatureBattle *bat } // Per creature code ends k++; - if (k > game.conf.rules.game.creatures_count) + if (k > CREATURES_COUNT) { ERRORLOG("Infinite loop detected when sweeping battle creatures list"); break; diff --git a/src/creature_control.c b/src/creature_control.c index 499dd0fe93..1acba910cf 100644 --- a/src/creature_control.c +++ b/src/creature_control.c @@ -125,7 +125,7 @@ void delete_control_structure(struct CreatureControl *cctrl) void delete_all_control_structures(void) { - for (long i = 1; i < game.conf.rules.game.creatures_count; i++) + for (long i = 1; i < CREATURES_COUNT; i++) { struct CreatureControl* cctrl = creature_control_get(i); if (!creature_control_invalid(cctrl)) @@ -207,7 +207,7 @@ struct Thing *get_group_last_member(struct Thing *thing) ctng = thing_get(cctrl->next_in_group); cctrl = creature_control_get_from_thing(ctng); k++; - if (k > game.conf.rules.game.creatures_count) + if (k > CREATURES_COUNT) { ERRORLOG("Infinite loop detected when sweeping creatures group"); break; diff --git a/src/creature_groups.c b/src/creature_groups.c index 861297c3ae..2a7e5d3813 100644 --- a/src/creature_groups.c +++ b/src/creature_groups.c @@ -74,7 +74,7 @@ struct Thing *get_highest_experience_and_score_creature_in_group(struct Thing *g // Per-thing code ends i = cctrl->next_in_group; k++; - if (k > game.conf.rules.game.creatures_count) + if (k > CREATURES_COUNT) { ERRORLOG("Infinite loop detected when sweeping creatures group"); break; @@ -129,7 +129,7 @@ struct Thing *get_last_follower_creature_in_group(const struct Thing *grptng) break; i = cctrl->next_in_group; k++; - if (k > game.conf.rules.game.creatures_count) + if (k > CREATURES_COUNT) { ERRORLOG("Infinite loop detected when sweeping creatures group"); break; @@ -371,7 +371,7 @@ static short creatures_group_has_special_digger_to_lead(struct Thing* grptng) } i = cctrl->next_in_group; k++; - if (k > game.conf.rules.game.creatures_count) + if (k > CREATURES_COUNT) { ERRORLOG("Infinite loop detected when sweeping creatures group"); break; @@ -467,7 +467,7 @@ struct Thing* get_best_creature_to_lead_group(struct Thing* grptng) // Per-thing code ends i = cctrl->next_in_group; k++; - if (k > game.conf.rules.game.creatures_count) + if (k > CREATURES_COUNT) { ERRORLOG("Infinite loop detected when sweeping creatures group"); break; diff --git a/src/creature_states.c b/src/creature_states.c index 1818ea49e7..3ad63ec95c 100644 --- a/src/creature_states.c +++ b/src/creature_states.c @@ -2347,7 +2347,7 @@ struct Thing *find_random_creature_for_persuade(PlayerNumber plyr_idx, struct Co n--; // Per thing code ends k++; - if (k > game.conf.rules.game.creatures_count) + if (k > CREATURES_COUNT) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; diff --git a/src/creature_states_combt.c b/src/creature_states_combt.c index f7718c7f8e..2c97a1635e 100644 --- a/src/creature_states_combt.c +++ b/src/creature_states_combt.c @@ -537,7 +537,7 @@ long count_creatures_really_in_combat(BattleIndex battle_id) } // Per thing code ends k++; - if (k > game.conf.rules.game.creatures_count) + if (k > CREATURES_COUNT) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; @@ -562,7 +562,7 @@ void cleanup_battle(BattleIndex battle_id) TRACE_THING(thing); remove_thing_from_battle_list(thing); k++; - if (k > game.conf.rules.game.creatures_count) + if (k > CREATURES_COUNT) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; @@ -603,7 +603,7 @@ void update_battle_events(BattleIndex battle_id) map_z = thing->mappos.z.val; // Per thing code ends k++; - if (k > game.conf.rules.game.creatures_count) + if (k > CREATURES_COUNT) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; @@ -649,7 +649,7 @@ TbBool battle_with_creature_of_player(PlayerNumber plyr_idx, BattleIndex battle_ return true; // Per thing code ends k++; - if (k > game.conf.rules.game.creatures_count) + if (k > CREATURES_COUNT) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; @@ -692,7 +692,7 @@ TbBool battle_any_of_things_in_specific_battle(const struct CreatureBattle *batt } // Per battle creature code ends k++; - if (k >= game.conf.rules.game.creatures_count) { + if (k >= CREATURES_COUNT) { ERRORLOG("Infinite loop in battle add"); break; } @@ -1265,7 +1265,7 @@ CrAttackType find_fellow_creature_to_fight_in_room(struct Thing *fightng, struct } // Thing list loop body ends k++; - if (k > game.conf.rules.game.creatures_count) + if (k > CREATURES_COUNT) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; diff --git a/src/creature_states_hero.c b/src/creature_states_hero.c index dd7f2e2404..e3095e0537 100644 --- a/src/creature_states_hero.c +++ b/src/creature_states_hero.c @@ -409,7 +409,7 @@ long get_wanderer_possible_targets_count_in_list(long first_thing_idx, struct Th } // Thing list loop body ends k++; - if (k > game.conf.rules.game.creatures_count) + if (k > CREATURES_COUNT) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; @@ -465,7 +465,7 @@ TbBool wander_to_specific_possible_target_in_list(long first_thing_idx, struct T break; // Thing list loop body ends k++; - if (k > game.conf.rules.game.creatures_count) + if (k > CREATURES_COUNT) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; diff --git a/src/creature_states_pray.c b/src/creature_states_pray.c index 0cd6c85b60..421ea21eca 100644 --- a/src/creature_states_pray.c +++ b/src/creature_states_pray.c @@ -223,7 +223,7 @@ TbBool add_anger_to_all_creatures_of_player(PlayerNumber plyr_idx, short percent anger_give_creatures_annoyance_percentage(thing, percentage, AngR_Other); // Thing list loop body ends k++; - if (k > game.conf.rules.game.creatures_count) + if (k > CREATURES_COUNT) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; @@ -254,7 +254,7 @@ TbBool make_all_players_creatures_angry(long plyr_idx) anger_make_creature_angry(thing, AngR_Other); // Thing list loop body ends k++; - if (k > game.conf.rules.game.creatures_count) + if (k > CREATURES_COUNT) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; @@ -326,7 +326,7 @@ void apply_spell_effect_to_players_creatures(PlayerNumber plyr_idx, ThingModel c } // Thing list loop body ends k++; - if (k > game.conf.rules.game.creatures_count) + if (k > CREATURES_COUNT) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; diff --git a/src/creature_states_scavn.c b/src/creature_states_scavn.c index 9d6f2397b5..da54fc6af5 100644 --- a/src/creature_states_scavn.c +++ b/src/creature_states_scavn.c @@ -127,7 +127,7 @@ struct Thing *get_random_fellow_not_hated_creature(struct Thing *creatng) n--; // Thing list loop body ends k++; - if (k > game.conf.rules.game.creatures_count) + if (k > CREATURES_COUNT) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; diff --git a/src/lvl_script_commands.c b/src/lvl_script_commands.c index 81f2cb2b05..5de7bdf9c2 100644 --- a/src/lvl_script_commands.c +++ b/src/lvl_script_commands.c @@ -580,7 +580,7 @@ TbBool script_change_creatures_annoyance(PlayerNumber plyr_idx, ThingModel crmod } // Thing list loop body ends k++; - if (k > game.conf.rules.game.creatures_count) + if (k > CREATURES_COUNT) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; @@ -3897,7 +3897,7 @@ static void level_up_players_creatures_process(struct ScriptContext* context) } // Thing list loop body ends k++; - if (k > game.conf.rules.game.creatures_count) + if (k > CREATURES_COUNT) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; @@ -4067,7 +4067,7 @@ void cast_power_on_players_creatures(PlayerNumber plyr_idx, ThingModel crmodel, } // Thing list loop body ends k++; - if (k > game.conf.rules.game.creatures_count) + if (k > CREATURES_COUNT) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; diff --git a/src/lvl_script_commands_old.c b/src/lvl_script_commands_old.c index d4ac9bfed5..f365eaa8bb 100644 --- a/src/lvl_script_commands_old.c +++ b/src/lvl_script_commands_old.c @@ -554,7 +554,7 @@ static void command_add_creature_to_pool(const char *crtr_name, long amount) SCRPTERRLOG("Unknown creature, '%s'", crtr_name); return; } - if ((amount < 0) || (amount >= game.conf.rules.game.creatures_count)) + if ((amount < 0) || (amount >= CREATURES_COUNT)) { SCRPTERRLOG("Invalid number of '%s' creatures for pool, %d", crtr_name, amount); return; diff --git a/src/magic.c b/src/magic.c index ab90e951cb..101cfbc296 100644 --- a/src/magic.c +++ b/src/magic.c @@ -1093,7 +1093,7 @@ static TbResult magic_use_power_hold_audience(PowerKind power_kind, PlayerNumber } // Thing list loop body ends k++; - if (k > game.conf.rules.game.creatures_count) + if (k > CREATURES_COUNT) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; @@ -1641,7 +1641,7 @@ long update_creatures_influenced_by_call_to_arms(PlayerNumber plyr_idx) } // Thing list loop body ends k++; - if (k > game.conf.rules.game.creatures_count) + if (k > CREATURES_COUNT) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; @@ -1777,7 +1777,7 @@ static void magic_power_hold_audience_update(PlayerNumber plyr_idx) } // Thing list loop body ends k++; - if (k > game.conf.rules.game.creatures_count) + if (k > CREATURES_COUNT) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; @@ -1841,7 +1841,7 @@ int affect_nearby_creatures_by_power_call_to_arms(PlayerNumber plyr_idx, long ra } // Thing list loop body ends k++; - if (k > game.conf.rules.game.creatures_count) + if (k > CREATURES_COUNT) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; diff --git a/src/main.cpp b/src/main.cpp index 68d2844e8b..3460dd3792 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -377,7 +377,7 @@ void affect_nearby_friends_with_alarm(struct Thing *traptng) } // Thing list loop body ends k++; - if (k > game.conf.rules.game.creatures_count) + if (k > CREATURES_COUNT) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; diff --git a/src/player_compchecks.c b/src/player_compchecks.c index 5e1b7fc236..1d747f8f98 100644 --- a/src/player_compchecks.c +++ b/src/player_compchecks.c @@ -358,7 +358,7 @@ static TbBool any_digger_is_digging_indestructible_valuables(struct Dungeon *dun } // Thing list loop body ends k++; - if (k > game.conf.rules.game.creatures_count) + if (k > CREATURES_COUNT) { ERRORLOG("Infinite loop detected when sweeping creatures list"); return false; @@ -628,7 +628,7 @@ struct Thing * find_imp_for_pickup(struct Computer2 *comp, MapSubtlCoord stl_x, } // Thing list loop body ends k++; - if (k > game.conf.rules.game.creatures_count) + if (k > CREATURES_COUNT) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; diff --git a/src/player_compevents.c b/src/player_compevents.c index c9fd726b2c..8b2c71b125 100644 --- a/src/player_compevents.c +++ b/src/player_compevents.c @@ -271,7 +271,7 @@ struct Thing *find_creature_in_fight_with_enemy(struct Computer2 *comp) } // Thing list loop body ends k++; - if (k > game.conf.rules.game.creatures_count) + if (k > CREATURES_COUNT) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; @@ -298,7 +298,7 @@ struct Thing *find_creature_in_fight_with_enemy(struct Computer2 *comp) } // Thing list loop body ends k++; - if (k > game.conf.rules.game.creatures_count) + if (k > CREATURES_COUNT) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; @@ -838,7 +838,7 @@ long computer_event_check_imps_in_danger(struct Computer2 *comp, struct Computer } // Thing list loop body ends k++; - if (k > game.conf.rules.game.creatures_count) + if (k > CREATURES_COUNT) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; diff --git a/src/player_comptask.c b/src/player_comptask.c index da8e1ce88f..6c424a02c8 100644 --- a/src/player_comptask.c +++ b/src/player_comptask.c @@ -2307,7 +2307,7 @@ long count_creatures_at_call_to_arms(struct Computer2 *comp) if (get_creature_state_besides_move(i) == CrSt_AlreadyAtCallToArms) num_creatures++; k++; - if (k > game.conf.rules.game.creatures_count) + if (k > CREATURES_COUNT) { ERRORLOG("Infinite loop detected when counting creatures in call to arms"); return num_creatures; @@ -2556,7 +2556,7 @@ struct Thing *find_creature_for_pickup(struct Computer2 *comp, struct Coord3d *p } // Thing list loop body ends k++; - if (k > game.conf.rules.game.creatures_count) + if (k > CREATURES_COUNT) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; @@ -2628,7 +2628,7 @@ long count_creatures_for_pickup(struct Computer2 *comp, struct Coord3d *pos, str } // Thing list loop body ends k++; - if (k > game.conf.rules.game.creatures_count) + if (k > CREATURES_COUNT) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; diff --git a/src/player_computer.c b/src/player_computer.c index 6f44db2ab3..38224359df 100644 --- a/src/player_computer.c +++ b/src/player_computer.c @@ -462,7 +462,7 @@ unsigned long count_creatures_availiable_for_fight(struct Computer2 *comp, struc } // Thing list loop body ends k++; - if (k > game.conf.rules.game.creatures_count) + if (k > CREATURES_COUNT) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; @@ -1106,7 +1106,7 @@ long count_creatures_for_defend_pickup(struct Computer2 *comp) } k++; - if (k > game.conf.rules.game.creatures_count) + if (k > CREATURES_COUNT) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; diff --git a/src/power_specials.c b/src/power_specials.c index 4b5664a177..0e4c245b77 100644 --- a/src/power_specials.c +++ b/src/power_specials.c @@ -100,7 +100,7 @@ void multiply_creatures_in_dungeon_list(struct Dungeon *dungeon, long list_start tncopy->health = thing->health; // Thing list loop body ends k++; - if (k > game.conf.rules.game.creatures_count) + if (k > CREATURES_COUNT) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; @@ -140,7 +140,7 @@ void increase_level(struct PlayerInfo *player, int count) else creature_increase_level(thing); // Thing list loop body ends k++; - if (k > game.conf.rules.game.creatures_count) + if (k > CREATURES_COUNT) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; @@ -164,7 +164,7 @@ void increase_level(struct PlayerInfo *player, int count) else creature_increase_level(thing); // Thing list loop body ends k++; - if (k > game.conf.rules.game.creatures_count) + if (k > CREATURES_COUNT) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; @@ -233,7 +233,7 @@ TbBool steal_hero(struct PlayerInfo *player, struct Coord3d *pos) } // Thing list loop body ends k++; - if (k > game.conf.rules.game.creatures_count) + if (k > CREATURES_COUNT) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; diff --git a/src/room_lair.c b/src/room_lair.c index 087452f054..d42c8bef54 100644 --- a/src/room_lair.c +++ b/src/room_lair.c @@ -103,7 +103,7 @@ long calculate_free_lair_space(struct Dungeon * dungeon) } // Thing list loop body ends k++; - if (k > game.conf.rules.game.creatures_count) + if (k > CREATURES_COUNT) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; diff --git a/src/spdigger_stack.c b/src/spdigger_stack.c index b985a84fba..7b1514cd7d 100644 --- a/src/spdigger_stack.c +++ b/src/spdigger_stack.c @@ -228,7 +228,7 @@ TbBool imp_will_soon_be_working_at_excluding(const struct Thing *creatng, MapSub } // Thing list loop body ends k++; - if (k > game.conf.rules.game.creatures_count) + if (k > CREATURES_COUNT) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; @@ -276,7 +276,7 @@ TbBool imp_will_soon_be_getting_object(PlayerNumber plyr_idx, const struct Thing } // Thing list loop body ends k++; - if (k > game.conf.rules.game.creatures_count) + if (k > CREATURES_COUNT) { ERRORLOG("Infinite loop detected when sweeping creatures list"); break; From d4521fde93e103bdc1575378104ea1d4b43c088d Mon Sep 17 00:00:00 2001 From: Loobinex Date: Mon, 2 Sep 2024 23:02:27 +0200 Subject: [PATCH 13/54] Revert "made it work for SET_GAME_RULE" This reverts commit 243e338c6afe7bcd305185faf76bc88b46bdb211. --- src/lvl_script_commands.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/lvl_script_commands.c b/src/lvl_script_commands.c index 5de7bdf9c2..b0065be2c3 100644 --- a/src/lvl_script_commands.c +++ b/src/lvl_script_commands.c @@ -301,7 +301,6 @@ 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}, }; @@ -5457,11 +5456,6 @@ 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 of the offset of 1 - SCRIPTDBG(7, "Changing Game Rule '%s' from %d to %d", rulename, game.conf.rules.game.creatures_count, rulevalue+1); - game.conf.rules.game.creatures_count = rulevalue+1; - break; default: WARNMSG("Unsupported Game Rule, command %d.", ruledesc); break; From 98aeab79cb20c1e8badce6d8f9b2a34789db3b99 Mon Sep 17 00:00:00 2001 From: Loobinex Date: Mon, 2 Sep 2024 23:02:41 +0200 Subject: [PATCH 14/54] Revert "Created the offset of 1" This reverts commit 4ff59548590da5aeed7e1df19efe3e62939f964d. --- src/config_rules.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/config_rules.c b/src/config_rules.c index 1161f05fe8..b5c76589e9 100644 --- a/src/config_rules.c +++ b/src/config_rules.c @@ -93,13 +93,13 @@ 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}, {NULL, NULL,0,0,0 }, }; //special cases rules_game const struct NamedCommand rules_game_commands[] = { {"PRESERVECLASSICBUGS", 1}, - {"MAPCREATURELIMIT", 2}, {NULL, 0}, }; @@ -423,17 +423,6 @@ static void game_block_special_cases(int cmd_num,const char *buf,long *pos,long } } break; - case 2: - if (get_conf_parameter_single(buf, pos, len, word_buf, sizeof(word_buf)) > 0) - { - int k = atoi(word_buf); - if (k < 0) - k = 0; - if (k >= CREATURES_COUNT) - k = CREATURES_COUNT - 1; - game.conf.rules.game.creatures_count = k + 1; - } - break; } #undef COMMAND_TEXT } From 308a5a73477872870af1e39d9af09703f952c5c4 Mon Sep 17 00:00:00 2001 From: Loobinex Date: Mon, 2 Sep 2024 19:45:07 +0200 Subject: [PATCH 15/54] handled the offset of 1 in a cleaner way --- src/config_rules.c | 2 +- src/creature_control.c | 4 ++-- src/lvl_script_commands_old.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/config_rules.c b/src/config_rules.c index b5c76589e9..42507c74af 100644 --- a/src/config_rules.c +++ b/src/config_rules.c @@ -287,7 +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 = 256; + game.conf.rules.game.creatures_count = 255; // Creature block. game.conf.rules.creature.recovery_frequency = 10; game.conf.rules.creature.fight_max_hate = 200; diff --git a/src/creature_control.c b/src/creature_control.c index 1acba910cf..31e6b28dde 100644 --- a/src/creature_control.c +++ b/src/creature_control.c @@ -87,7 +87,7 @@ TbBool creature_control_exists_in_thing(const struct Thing *thing) long i_can_allocate_free_control_structure(void) { - for (long i = 1; i < game.conf.rules.game.creatures_count; i++) + for (long i = 1; i <= game.conf.rules.game.creatures_count; i++) { struct CreatureControl* cctrl = game.persons.cctrl_lookup[i]; if (!creature_control_invalid(cctrl)) @@ -101,7 +101,7 @@ long i_can_allocate_free_control_structure(void) struct CreatureControl *allocate_free_control_structure(void) { - for (long i = 1; i < game.conf.rules.game.creatures_count; i++) + for (long i = 1; i <= game.conf.rules.game.creatures_count; i++) { struct CreatureControl* cctrl = game.persons.cctrl_lookup[i]; if (!creature_control_invalid(cctrl)) diff --git a/src/lvl_script_commands_old.c b/src/lvl_script_commands_old.c index f365eaa8bb..92c2807deb 100644 --- a/src/lvl_script_commands_old.c +++ b/src/lvl_script_commands_old.c @@ -126,7 +126,7 @@ static void command_add_creature_to_level(long plr_range_id, const char *crtr_na SCRPTERRLOG("Invalid CREATURE LEVEL parameter"); return; } - if ((ncopies <= 0) || (ncopies >= game.conf.rules.game.creatures_count)) + if ((ncopies <= 0) || (ncopies > game.conf.rules.game.creatures_count)) { SCRPTERRLOG("Invalid number of creatures to add"); return; From eb55ff6e839dca65fc29983b465dd5996fdd7c58 Mon Sep 17 00:00:00 2001 From: Loobinex Date: Mon, 2 Sep 2024 19:32:01 +0200 Subject: [PATCH 16/54] comments only go into main files --- levels/classic_cfgs/rules.cfg | 1 - levels/legacy_cfgs/rules.cfg | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/levels/classic_cfgs/rules.cfg b/levels/classic_cfgs/rules.cfg index 8bb79632de..a451f6d3fb 100644 --- a/levels/classic_cfgs/rules.cfg +++ b/levels/classic_cfgs/rules.cfg @@ -3,5 +3,4 @@ [game] DungeonHeartHealHealth = 1 -; Total Amount of Creatures on the map .The absolute maximum is 1024. MapCreatureLimit = 255 \ No newline at end of file diff --git a/levels/legacy_cfgs/rules.cfg b/levels/legacy_cfgs/rules.cfg index 46e0b9561c..bcd69d3d53 100644 --- a/levels/legacy_cfgs/rules.cfg +++ b/levels/legacy_cfgs/rules.cfg @@ -5,8 +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 -; Total Amount of Creatures on the map .The absolute maximum is 1024. -MapCreatureLimit = 255 +MapCreatureLimit = 255 [computer] DiseaseHPTemplePercentage = 50 From a375ef97cc658aa53841a88bffa99de607e0dbab Mon Sep 17 00:00:00 2001 From: Loobinex Date: Mon, 2 Sep 2024 23:13:37 +0200 Subject: [PATCH 17/54] Some cleanup --- src/creature_control.h | 1 + src/lvl_script_commands_old.c | 8 ++++++-- src/main_game.c | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/creature_control.h b/src/creature_control.h index 6dd3ba4ffc..7aa0d08234 100644 --- a/src/creature_control.h +++ b/src/creature_control.h @@ -138,6 +138,7 @@ struct CastedSpellData { unsigned char spkind; short duration; }; + struct CreatureControl { unsigned short index; unsigned char flgfield_1; diff --git a/src/lvl_script_commands_old.c b/src/lvl_script_commands_old.c index 92c2807deb..7d90a9cc1d 100644 --- a/src/lvl_script_commands_old.c +++ b/src/lvl_script_commands_old.c @@ -126,11 +126,15 @@ static void command_add_creature_to_level(long plr_range_id, const char *crtr_na SCRPTERRLOG("Invalid CREATURE LEVEL parameter"); return; } - if ((ncopies <= 0) || (ncopies > game.conf.rules.game.creatures_count)) + if ((ncopies <= 0) || (ncopies > CREATURES_COUNT)) { - SCRPTERRLOG("Invalid number of creatures to add"); + 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"); diff --git a/src/main_game.c b/src/main_game.c index 35f5d8afcf..e8d1f5d95d 100644 --- a/src/main_game.c +++ b/src/main_game.c @@ -134,7 +134,7 @@ void init_lookups(void) { game.persons.cctrl_lookup[i] = &game.cctrl_data[i]; } - game.persons.cctrl_end = &game.cctrl_data[CREATURES_COUNT]; + game.persons.cctrl_end = &game.cctrl_data[CREATURES_COUNT]; for (i=0; i < COLUMNS_COUNT; i++) { From 4717bc211e605b3a3febb2d1a5b7d9e74cd5c4a7 Mon Sep 17 00:00:00 2001 From: Loobinex Date: Mon, 2 Sep 2024 23:14:15 +0200 Subject: [PATCH 18/54] some unrelated cleanup --- src/creature_states_combt.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/creature_states_combt.c b/src/creature_states_combt.c index 2c97a1635e..135578c4e7 100644 --- a/src/creature_states_combt.c +++ b/src/creature_states_combt.c @@ -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; @@ -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; @@ -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; } From 0903f78f26e289ceee308c105ad8c4106ba72349 Mon Sep 17 00:00:00 2001 From: Loobinex Date: Tue, 3 Sep 2024 00:28:09 +0200 Subject: [PATCH 19/54] Increased 3 more fields that were left on chars --- src/dungeon_data.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/dungeon_data.h b/src/dungeon_data.h index 35bbc91485..e94cfaab9c 100644 --- a/src/dungeon_data.h +++ b/src/dungeon_data.h @@ -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; From 78e2f5ebaec7ef5245cfb29d54d1fc983a7eb3d8 Mon Sep 17 00:00:00 2001 From: Loobinex Date: Tue, 3 Sep 2024 23:09:53 +0200 Subject: [PATCH 20/54] Added 2 places I missed in the confusion --- src/creature_control.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/creature_control.c b/src/creature_control.c index 31e6b28dde..bed7a5702f 100644 --- a/src/creature_control.c +++ b/src/creature_control.c @@ -47,7 +47,7 @@ extern "C" { */ struct CreatureControl *creature_control_get(long cctrl_idx) { - if ((cctrl_idx < 1) || (cctrl_idx > game.conf.rules.game.creatures_count)) + if ((cctrl_idx < 1) || (cctrl_idx >= game.conf.rules.game.creatures_count)) return INVALID_CRTR_CONTROL; return game.persons.cctrl_lookup[cctrl_idx]; } @@ -58,7 +58,7 @@ struct CreatureControl *creature_control_get(long cctrl_idx) */ struct CreatureControl *creature_control_get_from_thing(const struct Thing *thing) { - if ((thing->ccontrol_idx < 1) || (thing->ccontrol_idx > game.conf.rules.game.creatures_count)) + if ((thing->ccontrol_idx < 1) || (thing->ccontrol_idx >= game.conf.rules.game.creatures_count)) return INVALID_CRTR_CONTROL; return game.persons.cctrl_lookup[thing->ccontrol_idx]; } From 79e6964f15db66c79d02e1c85aafad6c224bb61a Mon Sep 17 00:00:00 2001 From: Loobinex Date: Tue, 3 Sep 2024 23:43:24 +0200 Subject: [PATCH 21/54] Revert "Added 2 places I missed in the confusion" This reverts commit 78e2f5ebaec7ef5245cfb29d54d1fc983a7eb3d8. --- src/creature_control.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/creature_control.c b/src/creature_control.c index bed7a5702f..31e6b28dde 100644 --- a/src/creature_control.c +++ b/src/creature_control.c @@ -47,7 +47,7 @@ extern "C" { */ struct CreatureControl *creature_control_get(long cctrl_idx) { - if ((cctrl_idx < 1) || (cctrl_idx >= game.conf.rules.game.creatures_count)) + if ((cctrl_idx < 1) || (cctrl_idx > game.conf.rules.game.creatures_count)) return INVALID_CRTR_CONTROL; return game.persons.cctrl_lookup[cctrl_idx]; } @@ -58,7 +58,7 @@ struct CreatureControl *creature_control_get(long cctrl_idx) */ struct CreatureControl *creature_control_get_from_thing(const struct Thing *thing) { - if ((thing->ccontrol_idx < 1) || (thing->ccontrol_idx >= game.conf.rules.game.creatures_count)) + if ((thing->ccontrol_idx < 1) || (thing->ccontrol_idx > game.conf.rules.game.creatures_count)) return INVALID_CRTR_CONTROL; return game.persons.cctrl_lookup[thing->ccontrol_idx]; } From 51a0454209c7cec9c796e145581c8b712ef5a4db Mon Sep 17 00:00:00 2001 From: Loobinex Date: Wed, 4 Sep 2024 00:17:47 +0200 Subject: [PATCH 22/54] Reapply "Added 2 places I missed in the confusion" This reverts commit 79e6964f15db66c79d02e1c85aafad6c224bb61a. --- src/creature_control.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/creature_control.c b/src/creature_control.c index 31e6b28dde..bed7a5702f 100644 --- a/src/creature_control.c +++ b/src/creature_control.c @@ -47,7 +47,7 @@ extern "C" { */ struct CreatureControl *creature_control_get(long cctrl_idx) { - if ((cctrl_idx < 1) || (cctrl_idx > game.conf.rules.game.creatures_count)) + if ((cctrl_idx < 1) || (cctrl_idx >= game.conf.rules.game.creatures_count)) return INVALID_CRTR_CONTROL; return game.persons.cctrl_lookup[cctrl_idx]; } @@ -58,7 +58,7 @@ struct CreatureControl *creature_control_get(long cctrl_idx) */ struct CreatureControl *creature_control_get_from_thing(const struct Thing *thing) { - if ((thing->ccontrol_idx < 1) || (thing->ccontrol_idx > game.conf.rules.game.creatures_count)) + if ((thing->ccontrol_idx < 1) || (thing->ccontrol_idx >= game.conf.rules.game.creatures_count)) return INVALID_CRTR_CONTROL; return game.persons.cctrl_lookup[thing->ccontrol_idx]; } From 8051ab5550d950f1c7da75df8f4c2dbdcbe073ab Mon Sep 17 00:00:00 2001 From: Loobinex Date: Wed, 4 Sep 2024 00:20:24 +0200 Subject: [PATCH 23/54] corrected tiny log mistake --- src/lvl_script_commands_old.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lvl_script_commands_old.c b/src/lvl_script_commands_old.c index 7d90a9cc1d..1119636cdc 100644 --- a/src/lvl_script_commands_old.c +++ b/src/lvl_script_commands_old.c @@ -126,9 +126,9 @@ static void command_add_creature_to_level(long plr_range_id, const char *crtr_na SCRPTERRLOG("Invalid CREATURE LEVEL parameter"); return; } - if ((ncopies <= 0) || (ncopies > CREATURES_COUNT)) + if ((ncopies <= 0) || (ncopies >= CREATURES_COUNT)) { - SCRPTERRLOG("Invalid number of creatures to add, "); + SCRPTERRLOG("Invalid number of creatures to add"); return; } if (ncopies > game.conf.rules.game.creatures_count) From a5a2c6488b612ab3663362be8dd157c6cf426b36 Mon Sep 17 00:00:00 2001 From: Loobinex Date: Wed, 4 Sep 2024 23:37:10 +0200 Subject: [PATCH 24/54] Only stop the extra creatures, do not kill them. --- src/config_rules.h | 2 +- src/creature_control.c | 8 ++++---- src/thing_creature.c | 7 ++++++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/config_rules.h b/src/config_rules.h index e8c8d33f19..0fbbc69325 100644 --- a/src/config_rules.h +++ b/src/config_rules.h @@ -102,7 +102,7 @@ struct GameRulesConfig { unsigned long easter_egg_speech_interval; long global_ambient_light; TbBool light_enabled; - unsigned long creatures_count; + unsigned short creatures_count; }; struct ComputerRulesConfig { diff --git a/src/creature_control.c b/src/creature_control.c index bed7a5702f..0f9d99a2a5 100644 --- a/src/creature_control.c +++ b/src/creature_control.c @@ -47,7 +47,7 @@ extern "C" { */ struct CreatureControl *creature_control_get(long cctrl_idx) { - if ((cctrl_idx < 1) || (cctrl_idx >= game.conf.rules.game.creatures_count)) + if ((cctrl_idx < 1) || (cctrl_idx >= CREATURES_COUNT)) return INVALID_CRTR_CONTROL; return game.persons.cctrl_lookup[cctrl_idx]; } @@ -58,7 +58,7 @@ struct CreatureControl *creature_control_get(long cctrl_idx) */ struct CreatureControl *creature_control_get_from_thing(const struct Thing *thing) { - if ((thing->ccontrol_idx < 1) || (thing->ccontrol_idx >= game.conf.rules.game.creatures_count)) + if ((thing->ccontrol_idx < 1) || (thing->ccontrol_idx >= CREATURES_COUNT)) return INVALID_CRTR_CONTROL; return game.persons.cctrl_lookup[thing->ccontrol_idx]; } @@ -87,7 +87,7 @@ TbBool creature_control_exists_in_thing(const struct Thing *thing) long i_can_allocate_free_control_structure(void) { - for (long i = 1; i <= game.conf.rules.game.creatures_count; i++) + for (long i = 1; i < CREATURES_COUNT; i++) { struct CreatureControl* cctrl = game.persons.cctrl_lookup[i]; if (!creature_control_invalid(cctrl)) @@ -101,7 +101,7 @@ long i_can_allocate_free_control_structure(void) struct CreatureControl *allocate_free_control_structure(void) { - for (long i = 1; i <= game.conf.rules.game.creatures_count; i++) + for (long i = 1; i < CREATURES_COUNT; i++) { struct CreatureControl* cctrl = game.persons.cctrl_lookup[i]; if (!creature_control_invalid(cctrl)) diff --git a/src/thing_creature.c b/src/thing_creature.c index 7bbb7e7b60..f1671e3dbf 100644 --- a/src/thing_creature.c +++ b/src/thing_creature.c @@ -4013,6 +4013,11 @@ void change_creature_owner(struct Thing *creatng, PlayerNumber nowner) struct Thing *create_creature(struct Coord3d *pos, ThingModel model, PlayerNumber owner) { struct CreatureStats* crstat = creature_stats_get(model); + if (game.thing_lists[TngList_Creatures].count >= game.conf.rules.game.creatures_count) + { + SYNCDBG(6, "Cannot create %s for player %d. Map creature limit %d reached.", creature_code_name(model), (int)owner, game.conf.rules.game.creatures_count); + return INVALID_THING; + } if (!i_can_allocate_free_thing_structure(FTAF_FreeEffectIfNoSlots)) { ERRORDBG(3,"Cannot create %s for player %d. There are too many things allocated.",creature_code_name(model),(int)owner); @@ -5673,7 +5678,7 @@ TngUpdateRet update_creature(struct Thing *thing) struct CreatureControl* cctrl = creature_control_get_from_thing(thing); if (creature_control_invalid(cctrl)) { - WARNLOG("Killing %s index %d with invalid control.",thing_model_name(thing),(int)thing->index); + WARNLOG("Killing %s index %d with invalid control %d.(%d)",thing_model_name(thing),(int)thing->index, thing->ccontrol_idx, game.conf.rules.game.creatures_count); kill_creature(thing, INVALID_THING, -1, CrDed_Default); return TUFRet_Deleted; } From 3f0bac8a2108002898f78a534865800a0d63f36b Mon Sep 17 00:00:00 2001 From: Loobinex Date: Wed, 4 Sep 2024 23:59:03 +0200 Subject: [PATCH 25/54] Extra creatures just leave --- src/lvl_script_commands.c | 39 +++++++++++++++++++++++++++++++++++++++ src/thing_list.h | 1 + 2 files changed, 40 insertions(+) diff --git a/src/lvl_script_commands.c b/src/lvl_script_commands.c index b0065be2c3..d771339c74 100644 --- a/src/lvl_script_commands.c +++ b/src/lvl_script_commands.c @@ -301,6 +301,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}, }; @@ -5456,6 +5457,44 @@ 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); + 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++; + setup_creature_leave_or_die_if_possible(thing); + } + // Per-thing code ends + k++; + if (k > slist->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; diff --git a/src/thing_list.h b/src/thing_list.h index feed008797..b2a02518c3 100644 --- a/src/thing_list.h +++ b/src/thing_list.h @@ -343,6 +343,7 @@ ThingIndex get_index_of_next_creature_of_owner_and_model(struct Thing *current_c struct Thing* get_timebomb_target(struct Thing *creatng); void setup_all_player_creatures_and_diggers_leave_or_die(PlayerNumber plyr_idx); +TbBool setup_creature_leave_or_die_if_possible(struct Thing* thing); /******************************************************************************/ #ifdef __cplusplus } From 07e31ea47f790fea6d04e24f1aa6fcaab02d8682 Mon Sep 17 00:00:00 2001 From: Loobinex Date: Thu, 5 Sep 2024 00:40:52 +0200 Subject: [PATCH 26/54] stopped creatures leaving from being snapped out of it --- src/creature_states.c | 2 +- src/power_hand.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/creature_states.c b/src/creature_states.c index 3ad63ec95c..e29376b268 100644 --- a/src/creature_states.c +++ b/src/creature_states.c @@ -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)) return true; return false; } diff --git a/src/power_hand.c b/src/power_hand.c index cd0f305986..b7952253ae 100644 --- a/src/power_hand.c +++ b/src/power_hand.c @@ -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; } From e522ac51bf85e791e1d5829841e7717231e977a9 Mon Sep 17 00:00:00 2001 From: benlp91 Date: Thu, 5 Sep 2024 09:21:02 +0200 Subject: [PATCH 27/54] raised BATTLE_COUNT raised BATTLE_COUNT --- src/creature_battle.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/creature_battle.h b/src/creature_battle.h index 25552da592..59318317a7 100644 --- a/src/creature_battle.h +++ b/src/creature_battle.h @@ -27,7 +27,7 @@ extern "C" { #endif /** Max amount of battles supported on any map. */ -#define BATTLES_COUNT 48 +#define BATTLES_COUNT 512 #define MESSAGE_BATTLERS_COUNT 8 /******************************************************************************/ #pragma pack(1) From 894a0102acff117ef2be28d9b93894948e7bbf6f Mon Sep 17 00:00:00 2001 From: Loobinex Date: Thu, 5 Sep 2024 20:48:50 +0200 Subject: [PATCH 28/54] battle count a bit lower --- src/creature_battle.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/creature_battle.h b/src/creature_battle.h index 59318317a7..fdea386072 100644 --- a/src/creature_battle.h +++ b/src/creature_battle.h @@ -27,8 +27,8 @@ extern "C" { #endif /** Max amount of battles supported on any map. */ -#define BATTLES_COUNT 512 -#define MESSAGE_BATTLERS_COUNT 8 +#define BATTLES_COUNT 192 +#define MESSAGE_BATTLERS_COUNT 8 /******************************************************************************/ #pragma pack(1) From 97081194d778a160310e2b5a38c32e7825016fdc Mon Sep 17 00:00:00 2001 From: Loobinex Date: Thu, 5 Sep 2024 21:25:27 +0200 Subject: [PATCH 29/54] Cleanup states of creatures dying from being too much --- src/lvl_script_commands.c | 58 +++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 23 deletions(-) diff --git a/src/lvl_script_commands.c b/src/lvl_script_commands.c index d771339c74..ebec5b35f9 100644 --- a/src/lvl_script_commands.c +++ b/src/lvl_script_commands.c @@ -20,37 +20,39 @@ #include #include -#include "dungeon_data.h" -#include "thing_data.h" -#include "player_instances.h" -#include "keeperfx.hpp" -#include "custom_sprites.h" -#include "gui_soundmsgs.h" +#include "bflib_memory.h" +#include "bflib_sound.h" +#include "config_effects.h" #include "config_magic.h" +#include "config_players.h" +#include "config_powerhands.h" #include "config_settings.h" -#include "config_effects.h" +#include "config_spritecolors.h" #include "config_trapdoor.h" -#include "config_powerhands.h" -#include "config_players.h" -#include "frontmenu_ingame_map.h" -#include "thing_effects.h" -#include "thing_physics.h" -#include "thing_navigate.h" #include "console_cmd.h" -#include "creature_states_pray.h" -#include "creature_states_mood.h" -#include "room_util.h" #include "creature_instances.h" -#include "power_hand.h" -#include "power_specials.h" #include "creature_states.h" +#include "creature_states_mood.h" +#include "creature_states_pray.h" +#include "custom_sprites.h" +#include "dungeon_data.h" +#include "frontmenu_ingame_map.h" +#include "gui_soundmsgs.h" +#include "keeperfx.hpp" #include "map_blocks.h" -#include "bflib_memory.h" -#include "post_inc.h" #include "music_player.h" -#include "bflib_sound.h" -#include "config_spritecolors.h" +#include "player_instances.h" +#include "power_hand.h" +#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" +#include "thing_physics.h" + +#include "post_inc.h" #ifdef __cplusplus extern "C" { @@ -5480,7 +5482,17 @@ static void set_game_rule_process(struct ScriptContext* context) if (cctrl->index > game.conf.rules.game.creatures_count) { count++; - setup_creature_leave_or_die_if_possible(thing); + 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++; From 72669c60243325eb8b768832bcc60b4be2b708f3 Mon Sep 17 00:00:00 2001 From: Loobinex Date: Fri, 6 Sep 2024 20:17:24 +0200 Subject: [PATCH 30/54] Stopped log errors and stop imps from costing money if the spell fails --- src/magic.c | 5 +++++ src/thing_factory.c | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/magic.c b/src/magic.c index 101cfbc296..058f3e9d90 100644 --- a/src/magic.c +++ b/src/magic.c @@ -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 (game.thing_lists[TngList_Creatures].count >= game.conf.rules.game.creatures_count) + { + 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 diff --git a/src/thing_factory.c b/src/thing_factory.c index bdda112df6..6761b1c834 100644 --- a/src/thing_factory.c +++ b/src/thing_factory.c @@ -298,7 +298,14 @@ TbBool thing_create_thing_adv(VALUE *init_data) struct CreatureControl* cctrl = creature_control_get_from_thing(thing); if (thing_is_invalid(thing)) { - ERRORLOG("Couldn't create creature model %d (%s)", (int)model, creature_code_name(model)); + if (game.thing_lists[TngList_Creatures].count >= game.conf.rules.game.creatures_count) + { + WARNLOG("Map Creature limit reached. Couldn't create creature model %d (%s)", (int)model, creature_code_name(model)); + } + else + { + ERRORLOG("Couldn't create creature model %d (%s)", (int)model, creature_code_name(model)); + } return false; } { From fb0b316b7b09b90d11064f6276e277801bff4c2c Mon Sep 17 00:00:00 2001 From: Loobinex Date: Sun, 8 Sep 2024 12:14:45 +0200 Subject: [PATCH 31/54] stop generating creatures beyond map limit --- src/room_entrance.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/room_entrance.c b/src/room_entrance.c index 1d2d943e25..efc8454c0b 100644 --- a/src/room_entrance.c +++ b/src/room_entrance.c @@ -99,7 +99,8 @@ struct Thing *create_creature_at_entrance(struct Room * room, ThingModel crkind) */ TbBool generation_due_in_game(void) { - return ( (game.play_gameturn-game.entrance_last_generate_turn) >= game.generate_speed ); + return (( (game.play_gameturn-game.entrance_last_generate_turn) >= game.generate_speed ) && + (game.thing_lists[TngList_Creatures].count < game.conf.rules.game.creatures_count) ); } TbBool generation_due_for_dungeon(struct Dungeon * dungeon) From c70646ad19558609da2aaf58feeeb76659a62fa3 Mon Sep 17 00:00:00 2001 From: Loobinex Date: Sun, 8 Sep 2024 12:34:14 +0200 Subject: [PATCH 32/54] Made a separate function for the check --- src/magic.c | 2 +- src/room_entrance.c | 2 +- src/thing_creature.c | 17 +++++++++++++++-- src/thing_creature.h | 1 + src/thing_factory.c | 2 +- 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/magic.c b/src/magic.c index 058f3e9d90..32777e5bfa 100644 --- a/src/magic.c +++ b/src/magic.c @@ -1270,7 +1270,7 @@ static TbResult magic_use_power_imp(PowerKind power_kind, PlayerNumber plyr_idx, || !i_can_allocate_free_thing_structure(FTAF_FreeEffectIfNoSlots)) { return Lb_FAIL; } - if (game.thing_lists[TngList_Creatures].count >= game.conf.rules.game.creatures_count) + if (!creature_count_below_map_limit(0)) { SYNCLOG("Player %d attempts to create creature at map creature limit", plyr_idx); return Lb_FAIL; diff --git a/src/room_entrance.c b/src/room_entrance.c index efc8454c0b..52f10c8de6 100644 --- a/src/room_entrance.c +++ b/src/room_entrance.c @@ -100,7 +100,7 @@ struct Thing *create_creature_at_entrance(struct Room * room, ThingModel crkind) TbBool generation_due_in_game(void) { return (( (game.play_gameturn-game.entrance_last_generate_turn) >= game.generate_speed ) && - (game.thing_lists[TngList_Creatures].count < game.conf.rules.game.creatures_count) ); + (creature_count_below_map_limit(0)) ); } TbBool generation_due_for_dungeon(struct Dungeon * dungeon) diff --git a/src/thing_creature.c b/src/thing_creature.c index f1671e3dbf..c724e90fbc 100644 --- a/src/thing_creature.c +++ b/src/thing_creature.c @@ -4010,12 +4010,25 @@ void change_creature_owner(struct Thing *creatng, PlayerNumber nowner) } } +/** + * If the total creature count is low enough for a creature to be generated + * @param temp_creature when set to 1, it will still generate if it would mean going 1 over a temporary limit + * @return true if a creature may be generated, false if not. + */ +TbBool creature_count_below_map_limit(TbBool temp_creature) +{ + if (game.thing_lists[TngList_Creatures].count >= CREATURES_COUNT) + return false; + + return ((game.thing_lists[TngList_Creatures].count - temp_creature) < game.conf.rules.game.creatures_count); +} + struct Thing *create_creature(struct Coord3d *pos, ThingModel model, PlayerNumber owner) { struct CreatureStats* crstat = creature_stats_get(model); - if (game.thing_lists[TngList_Creatures].count >= game.conf.rules.game.creatures_count) + if (game.thing_lists[TngList_Creatures].count >= CREATURES_COUNT) { - SYNCDBG(6, "Cannot create %s for player %d. Map creature limit %d reached.", creature_code_name(model), (int)owner, game.conf.rules.game.creatures_count); + ERRORLOG("Cannot create %s for player %d. Creature limit %d reached.", creature_code_name(model), (int)owner, CREATURES_COUNT); return INVALID_THING; } if (!i_can_allocate_free_thing_structure(FTAF_FreeEffectIfNoSlots)) diff --git a/src/thing_creature.h b/src/thing_creature.h index 8a58b6ef6c..8fcd42d413 100644 --- a/src/thing_creature.h +++ b/src/thing_creature.h @@ -82,6 +82,7 @@ extern int creature_swap_idx[CREATURE_TYPES_COUNT]; extern unsigned long creature_create_errors; /******************************************************************************/ struct Thing *create_creature(struct Coord3d *pos, ThingModel model, PlayerNumber owner); +TbBool creature_count_below_map_limit(TbBool temp_creature); long move_creature(struct Thing *thing); struct Thing* kill_creature(struct Thing *creatng, struct Thing *killertng, PlayerNumber killer_plyr_idx, CrDeathFlags flags); diff --git a/src/thing_factory.c b/src/thing_factory.c index 6761b1c834..b8669651ac 100644 --- a/src/thing_factory.c +++ b/src/thing_factory.c @@ -298,7 +298,7 @@ TbBool thing_create_thing_adv(VALUE *init_data) struct CreatureControl* cctrl = creature_control_get_from_thing(thing); if (thing_is_invalid(thing)) { - if (game.thing_lists[TngList_Creatures].count >= game.conf.rules.game.creatures_count) + if (creature_count_below_map_limit(0)) { WARNLOG("Map Creature limit reached. Couldn't create creature model %d (%s)", (int)model, creature_code_name(model)); } From aa13dd11e908979d440f25c1a26ab8cf0ef17817 Mon Sep 17 00:00:00 2001 From: Loobinex Date: Sun, 8 Sep 2024 12:35:25 +0200 Subject: [PATCH 33/54] handled vampires --- src/thing_corpses.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/thing_corpses.c b/src/thing_corpses.c index d41130f6c7..4e6cd40184 100644 --- a/src/thing_corpses.c +++ b/src/thing_corpses.c @@ -169,9 +169,12 @@ void remove_body_from_graveyard(struct Thing *thing) struct Dungeon* dungeon = get_dungeon(room->owner); dungeon->bodies_rotten_for_vampire++; dungeon->lvstats.graveyard_bodys++; - if (dungeon->bodies_rotten_for_vampire >= game.conf.rules.rooms.bodies_for_vampire) { - dungeon->bodies_rotten_for_vampire -= game.conf.rules.rooms.bodies_for_vampire; - create_vampire_in_room(room); + if (creature_count_below_map_limit(0)) + { + if (dungeon->bodies_rotten_for_vampire >= game.conf.rules.rooms.bodies_for_vampire) { + dungeon->bodies_rotten_for_vampire -= game.conf.rules.rooms.bodies_for_vampire; + create_vampire_in_room(room); + } } } From dac765b5c3de5f13e121f31fc04c6bfb6d775f75 Mon Sep 17 00:00:00 2001 From: Loobinex Date: Sun, 8 Sep 2024 12:41:28 +0200 Subject: [PATCH 34/54] handled skeletons --- src/creature_states_prisn.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/creature_states_prisn.c b/src/creature_states_prisn.c index 6e070de32f..e09bf514de 100644 --- a/src/creature_states_prisn.c +++ b/src/creature_states_prisn.c @@ -315,23 +315,27 @@ 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++; + } } - 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) From 404ce0b2050ea1be137b277490a1a422705b5413 Mon Sep 17 00:00:00 2001 From: Loobinex Date: Sun, 8 Sep 2024 12:48:24 +0200 Subject: [PATCH 35/54] handled growing up (to dragon?) --- src/thing_creature.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/thing_creature.c b/src/thing_creature.c index c724e90fbc..9028330514 100644 --- a/src/thing_creature.c +++ b/src/thing_creature.c @@ -5623,7 +5623,11 @@ long update_creature_levels(struct Thing *thing) } } } - + if (!creature_count_below_map_limit(1)) + { + WARNLOG("Could not create creature to transform %s to due to creature limit", thing_model_name(thing)); + return 0; + } struct Thing* newtng = create_creature(&thing->mappos, model, thing->owner); if (thing_is_invalid(newtng)) { From 8e48a245d82679c40fb7c654d07a09c407109247 Mon Sep 17 00:00:00 2001 From: Loobinex Date: Sun, 8 Sep 2024 13:13:27 +0200 Subject: [PATCH 36/54] Handled temple, prison, scavenge, torture and duplicate --- src/creature_states_pray.c | 5 +++++ src/creature_states_prisn.c | 4 ++++ src/creature_states_scavn.c | 5 +++++ src/creature_states_tortr.c | 13 ++++++++++--- src/power_specials.c | 10 ++++++++-- 5 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/creature_states_pray.c b/src/creature_states_pray.c index 421ea21eca..a5b6547b35 100644 --- a/src/creature_states_pray.c +++ b/src/creature_states_pray.c @@ -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", model_name(model)); + return false; + } struct Thing* thing = create_creature(pos, model, owner); if (thing_is_invalid(thing)) { diff --git a/src/creature_states_prisn.c b/src/creature_states_prisn.c index e09bf514de..0e72b63592 100644 --- a/src/creature_states_prisn.c +++ b/src/creature_states_prisn.c @@ -332,6 +332,10 @@ TbBool prison_convert_creature_to_skeleton(struct Room *room, struct Thing *thin 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)); + } if (creature_model_bleeds(thing->model)) create_effect_around_thing(thing, TngEff_Blood5); kill_creature(thing, INVALID_THING, -1, CrDed_NoEffects); diff --git a/src/creature_states_scavn.c b/src/creature_states_scavn.c index da54fc6af5..02420c83e9 100644 --- a/src/creature_states_scavn.c +++ b/src/creature_states_scavn.c @@ -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)); diff --git a/src/creature_states_tortr.c b/src/creature_states_tortr.c index 871756675b..e9d1d64295 100644 --- a/src/creature_states_tortr.c +++ b/src/creature_states_tortr.c @@ -274,10 +274,17 @@ CrCheckRet process_kinky_function(struct Thing *thing) void convert_creature_to_ghost(struct Room *room, struct Thing *thing) { 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)) + { + struct Thing* 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 { - ERRORLOG("Couldn't create creature %s in %s room",creature_code_name(crmodel),room_code_name(room->kind)); return; } struct CreatureControl* cctrl = creature_control_get_from_thing(thing); diff --git a/src/power_specials.c b/src/power_specials.c index 0e4c245b77..d513aeae2a 100644 --- a/src/power_specials.c +++ b/src/power_specials.c @@ -90,11 +90,17 @@ void multiply_creatures_in_dungeon_list(struct Dungeon *dungeon, long list_start } i = cctrl->players_next_creature_idx; // Thing list loop body + if (!creature_count_below_map_limit(0)) + { + WARNLOG("Can't duplicate all creature because of due to map creature limit."); + break; + } struct Thing* tncopy = create_creature(&thing->mappos, thing->model, dungeon->owner); if (thing_is_invalid(tncopy)) { - WARNLOG("Can't create a copy of creature"); - break; + WARNLOG("Can't create a copy of creature %s", thing_model_name(thing)); + k++; + continue; } set_creature_level(tncopy, cctrl->explevel); tncopy->health = thing->health; From 5532feab396f4f94c8f9c3e6870d05eacb639ff3 Mon Sep 17 00:00:00 2001 From: Loobinex Date: Sun, 8 Sep 2024 14:12:33 +0200 Subject: [PATCH 37/54] Handled other special boxes and summons --- src/creature_states_tortr.c | 1 + src/power_specials.c | 23 +++++++++++++++++++---- src/thing_creature.c | 4 ++++ src/thing_traps.c | 5 +++++ 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/creature_states_tortr.c b/src/creature_states_tortr.c index e9d1d64295..4cc2ab79a4 100644 --- a/src/creature_states_tortr.c +++ b/src/creature_states_tortr.c @@ -285,6 +285,7 @@ void convert_creature_to_ghost(struct Room *room, struct Thing *thing) } } else { + WARNLOG("Could not create creature %s to transform %s to due to creature limit", thing_model_name(crmodel), thing_model_name(thing)); return; } struct CreatureControl* cctrl = creature_control_get_from_thing(thing); diff --git a/src/power_specials.c b/src/power_specials.c index d513aeae2a..1884ec01f7 100644 --- a/src/power_specials.c +++ b/src/power_specials.c @@ -92,7 +92,7 @@ void multiply_creatures_in_dungeon_list(struct Dungeon *dungeon, long list_start // Thing list loop body if (!creature_count_below_map_limit(0)) { - WARNLOG("Can't duplicate all creature because of due to map creature limit."); + WARNLOG("Can't duplicate all creature due to map creature limit."); break; } struct Thing* tncopy = create_creature(&thing->mappos, thing->model, dungeon->owner); @@ -257,6 +257,11 @@ TbBool steal_hero(struct PlayerInfo *player, struct Coord3d *pos) } else { + if (!creature_count_below_map_limit(0)) + { + SYNCDBG(7, "Failed to generate a stolen hero due to map creature limit"); + return false; + } unsigned char steal_idx = GAME_RANDOM(sizeof(prefer_steal_models)/sizeof(prefer_steal_models[0])); struct Thing* creatng = create_creature(pos, prefer_steal_models[steal_idx], player->id_number); if (thing_is_invalid(creatng)) @@ -470,9 +475,9 @@ void activate_dungeon_special(struct Thing *cratetng, struct PlayerInfo *player) case SpcKind_StealHero: if (steal_hero(player, &cratetng->mappos)) { - remove_events_thing_is_attached_to(cratetng); - used = 1; - delete_thing_structure(cratetng, 0); + remove_events_thing_is_attached_to(cratetng); + used = 1; + delete_thing_structure(cratetng, 0); } break; case SpcKind_MultplCrtr: @@ -578,6 +583,11 @@ void resurrect_creature(struct Thing *boxtng, PlayerNumber owner, ThingModel crm ERRORMSG("Invalid resurrect box object!"); return; } + if (!creature_count_below_map_limit(0)) + { + SYNCLOG("Unable to resurrect creature %s due to map creature limit", crmodel); + return; + } struct Thing* creatng = create_creature(&boxtng->mappos, crmodel, owner); if (!thing_is_invalid(creatng)) { @@ -699,6 +709,11 @@ long create_transferred_creatures_on_level(void) } struct Coord3d* pos = &(srcetng->mappos); + if (!creature_count_below_map_limit(0)) + { + WARNLOG("Can't create transferred creature %s due to map creature limit.",model_name(intralvl.transferred_creatures[p][i].model)); + continue; + } creatng = create_creature(pos, intralvl.transferred_creatures[p][i].model, plyr_idx); if (thing_is_invalid(creatng)) { diff --git a/src/thing_creature.c b/src/thing_creature.c index 9028330514..ee27391c14 100644 --- a/src/thing_creature.c +++ b/src/thing_creature.c @@ -1660,6 +1660,10 @@ void thing_summon_temporary_creature(struct Thing* creatng, ThingModel model, ch } } } + else + { + cctrl->familiar_idx[j] = 0; + } } else { diff --git a/src/thing_traps.c b/src/thing_traps.c index 6ae10aa5cb..2c8c42ca2f 100644 --- a/src/thing_traps.c +++ b/src/thing_traps.c @@ -522,6 +522,11 @@ void activate_trap_slab_change(struct Thing *traptng) struct Thing *activate_trap_spawn_creature(struct Thing *traptng, unsigned char model) { + if (!creature_count_below_map_limit(0)) + { + WARNLOG("Can't spawn creature %s due to map creature limit.", model_name(model)); + return INVALID_THING; + } struct Thing* thing; struct TrapStats* trapstat = &game.conf.trap_stats[traptng->model]; struct CreatureControl* cctrl; From b6c374eabf35ad608b93c3e8ab71923f426d5e66 Mon Sep 17 00:00:00 2001 From: Loobinex Date: Sun, 8 Sep 2024 20:19:12 +0200 Subject: [PATCH 38/54] Made sure the recent commits actually build --- src/creature_states_pray.c | 2 +- src/creature_states_tortr.c | 4 ++-- src/power_specials.c | 4 ++-- src/thing_traps.c | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/creature_states_pray.c b/src/creature_states_pray.c index a5b6547b35..ffa3f4cf3c 100644 --- a/src/creature_states_pray.c +++ b/src/creature_states_pray.c @@ -190,7 +190,7 @@ TbBool summon_creature(long model, struct Coord3d *pos, long owner, long expleve 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", model_name(model)); + 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); diff --git a/src/creature_states_tortr.c b/src/creature_states_tortr.c index 4cc2ab79a4..8ec0752310 100644 --- a/src/creature_states_tortr.c +++ b/src/creature_states_tortr.c @@ -277,7 +277,7 @@ void convert_creature_to_ghost(struct Room *room, struct Thing *thing) struct Thing* newthing = INVALID_THING; if (creature_count_below_map_limit(1)) { - struct Thing* newthing = create_creature(&thing->mappos, crmodel, room->owner); + 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)); @@ -285,7 +285,7 @@ void convert_creature_to_ghost(struct Room *room, struct Thing *thing) } } else { - WARNLOG("Could not create creature %s to transform %s to due to creature limit", thing_model_name(crmodel), thing_model_name(thing)); + 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); diff --git a/src/power_specials.c b/src/power_specials.c index 1884ec01f7..e8b5bd08e8 100644 --- a/src/power_specials.c +++ b/src/power_specials.c @@ -585,7 +585,7 @@ void resurrect_creature(struct Thing *boxtng, PlayerNumber owner, ThingModel crm } if (!creature_count_below_map_limit(0)) { - SYNCLOG("Unable to resurrect creature %s due to map creature limit", crmodel); + SYNCLOG("Unable to resurrect creature %s due to map creature limit", creature_code_name(crmodel)); return; } struct Thing* creatng = create_creature(&boxtng->mappos, crmodel, owner); @@ -711,7 +711,7 @@ long create_transferred_creatures_on_level(void) struct Coord3d* pos = &(srcetng->mappos); if (!creature_count_below_map_limit(0)) { - WARNLOG("Can't create transferred creature %s due to map creature limit.",model_name(intralvl.transferred_creatures[p][i].model)); + WARNLOG("Can't create transferred creature %s due to map creature limit.", creature_code_name(intralvl.transferred_creatures[p][i].model)); continue; } creatng = create_creature(pos, intralvl.transferred_creatures[p][i].model, plyr_idx); diff --git a/src/thing_traps.c b/src/thing_traps.c index 2c8c42ca2f..24c27c740e 100644 --- a/src/thing_traps.c +++ b/src/thing_traps.c @@ -524,7 +524,7 @@ struct Thing *activate_trap_spawn_creature(struct Thing *traptng, unsigned char { if (!creature_count_below_map_limit(0)) { - WARNLOG("Can't spawn creature %s due to map creature limit.", model_name(model)); + WARNLOG("Can't spawn creature %s due to map creature limit.", creature_code_name(model)); return INVALID_THING; } struct Thing* thing; From 28e0cde97efee138889c71cc82de61c2be1cf89e Mon Sep 17 00:00:00 2001 From: Loobinex Date: Sun, 8 Sep 2024 20:26:18 +0200 Subject: [PATCH 39/54] fixed 2 cosmetic issues --- src/console_cmd.c | 1 - src/thing_creature.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/console_cmd.c b/src/console_cmd.c index d523e04eae..5589e6eadc 100644 --- a/src/console_cmd.c +++ b/src/console_cmd.c @@ -737,7 +737,6 @@ TbBool cmd_exec(PlayerNumber plyr_idx, char *msg) targeted_message_add(MsgType_Player, 10, plyr_idx, GUI_MESSAGES_DELAY, "Pool count %s: %d",pr2str,game.pool.crtr_kind[kind]); return true; } - } else { diff --git a/src/thing_creature.c b/src/thing_creature.c index ee27391c14..a127ce9322 100644 --- a/src/thing_creature.c +++ b/src/thing_creature.c @@ -4024,7 +4024,7 @@ TbBool creature_count_below_map_limit(TbBool temp_creature) if (game.thing_lists[TngList_Creatures].count >= CREATURES_COUNT) return false; - return ((game.thing_lists[TngList_Creatures].count - temp_creature) < game.conf.rules.game.creatures_count); + return ((game.thing_lists[TngList_Creatures].count - temp_creature) < game.conf.rules.game.creatures_count); } struct Thing *create_creature(struct Coord3d *pos, ThingModel model, PlayerNumber owner) From 9f5969fc542f84e2bca59e1cfc28f247062181a6 Mon Sep 17 00:00:00 2001 From: Loobinex Date: Sun, 8 Sep 2024 20:31:21 +0200 Subject: [PATCH 40/54] Reverted accidental change at max creature control --- src/creature_control.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/creature_control.c b/src/creature_control.c index 0f9d99a2a5..0983a69caf 100644 --- a/src/creature_control.c +++ b/src/creature_control.c @@ -47,7 +47,7 @@ extern "C" { */ struct CreatureControl *creature_control_get(long cctrl_idx) { - if ((cctrl_idx < 1) || (cctrl_idx >= CREATURES_COUNT)) + if ((cctrl_idx < 1) || (cctrl_idx > CREATURES_COUNT)) return INVALID_CRTR_CONTROL; return game.persons.cctrl_lookup[cctrl_idx]; } @@ -58,7 +58,7 @@ struct CreatureControl *creature_control_get(long cctrl_idx) */ struct CreatureControl *creature_control_get_from_thing(const struct Thing *thing) { - if ((thing->ccontrol_idx < 1) || (thing->ccontrol_idx >= CREATURES_COUNT)) + if ((thing->ccontrol_idx < 1) || (thing->ccontrol_idx > CREATURES_COUNT)) return INVALID_CRTR_CONTROL; return game.persons.cctrl_lookup[thing->ccontrol_idx]; } From 97d430fb73c0feef8e9f35d3be651f6b3207f69a Mon Sep 17 00:00:00 2001 From: Loobinex Date: Sun, 8 Sep 2024 23:37:40 +0200 Subject: [PATCH 41/54] Better fix for entrance --- src/room_entrance.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/room_entrance.c b/src/room_entrance.c index 52f10c8de6..34a20a3b20 100644 --- a/src/room_entrance.c +++ b/src/room_entrance.c @@ -99,12 +99,17 @@ struct Thing *create_creature_at_entrance(struct Room * room, ThingModel crkind) */ TbBool generation_due_in_game(void) { - return (( (game.play_gameturn-game.entrance_last_generate_turn) >= game.generate_speed ) && - (creature_count_below_map_limit(0)) ); + return ((game.play_gameturn - game.entrance_last_generate_turn) >= game.generate_speed); } TbBool generation_due_for_dungeon(struct Dungeon * dungeon) { + if (!creature_count_below_map_limit(0)) + { + SYNCDBG(9, "At map limit"); + return false; + } + if ( (game.armageddon_cast_turn == 0) || (game.armageddon.count_down + game.armageddon_cast_turn > game.play_gameturn) ) { if ( (dungeon->turns_between_entrance_generation != -1) && From 2424b427b028565f08baa700675202fa78033a8f Mon Sep 17 00:00:00 2001 From: Loobinex Date: Mon, 9 Sep 2024 00:28:40 +0200 Subject: [PATCH 42/54] fixed errors from script command --- src/lvl_script_commands.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lvl_script_commands.c b/src/lvl_script_commands.c index 7f1a6d7961..5f2555262f 100644 --- a/src/lvl_script_commands.c +++ b/src/lvl_script_commands.c @@ -5495,7 +5495,7 @@ static void set_game_rule_process(struct ScriptContext* context) } // Per-thing code ends k++; - if (k > slist->count) + if (k > CREATURES_COUNT) { ERRORLOG("Infinite loop detected when sweeping things list"); break; From 65d797bf2d3a036f53f979e1529c1bb0b8493830 Mon Sep 17 00:00:00 2001 From: Loobinex Date: Mon, 9 Sep 2024 00:39:01 +0200 Subject: [PATCH 43/54] better handle offsets --- src/config_rules.c | 2 +- src/thing_creature.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/config_rules.c b/src/config_rules.c index 42507c74af..1670f8a8d4 100644 --- a/src/config_rules.c +++ b/src/config_rules.c @@ -93,7 +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}, + {"MAPCREATURELIMIT", &game.conf.rules.game.creatures_count, var_type(game.conf.rules.game.creatures_count ), 0,CREATURES_COUNT-1}, {NULL, NULL,0,0,0 }, }; diff --git a/src/thing_creature.c b/src/thing_creature.c index a127ce9322..947db3d321 100644 --- a/src/thing_creature.c +++ b/src/thing_creature.c @@ -4021,7 +4021,7 @@ void change_creature_owner(struct Thing *creatng, PlayerNumber nowner) */ TbBool creature_count_below_map_limit(TbBool temp_creature) { - if (game.thing_lists[TngList_Creatures].count >= CREATURES_COUNT) + if (game.thing_lists[TngList_Creatures].count >= CREATURES_COUNT-1) return false; return ((game.thing_lists[TngList_Creatures].count - temp_creature) < game.conf.rules.game.creatures_count); @@ -4030,7 +4030,7 @@ TbBool creature_count_below_map_limit(TbBool temp_creature) struct Thing *create_creature(struct Coord3d *pos, ThingModel model, PlayerNumber owner) { struct CreatureStats* crstat = creature_stats_get(model); - if (game.thing_lists[TngList_Creatures].count >= CREATURES_COUNT) + if (game.thing_lists[TngList_Creatures].count > CREATURES_COUNT) { ERRORLOG("Cannot create %s for player %d. Creature limit %d reached.", creature_code_name(model), (int)owner, CREATURES_COUNT); return INVALID_THING; From 7b0eee0a17091817fb6147989274ff32b5f71c2a Mon Sep 17 00:00:00 2001 From: Loobinex Date: Mon, 9 Sep 2024 00:52:27 +0200 Subject: [PATCH 44/54] No error on spawning from script --- config/fxdata/rules.cfg | 4 ++-- src/thing_creature.c | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/config/fxdata/rules.cfg b/config/fxdata/rules.cfg index 2b4f56e9d4..3299ccb0d2 100644 --- a/config/fxdata/rules.cfg +++ b/config/fxdata/rules.cfg @@ -51,8 +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 1024. -MapCreatureLimit = 1000 +; 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 diff --git a/src/thing_creature.c b/src/thing_creature.c index 947db3d321..f7c518ed91 100644 --- a/src/thing_creature.c +++ b/src/thing_creature.c @@ -6034,8 +6034,6 @@ struct Thing *script_create_creature_at_location(PlayerNumber plyr_idx, ThingMod struct Coord3d pos; TbBool fall_from_gate = false; - const unsigned char tngclass = TCls_Creature; - switch (get_map_location_type(location)) { case MLoc_ACTIONPOINT: @@ -6081,10 +6079,15 @@ struct Thing *script_create_creature_at_location(PlayerNumber plyr_idx, ThingMod return INVALID_THING; } - struct Thing* thing = create_thing_at_position_then_move_to_valid_and_add_light(&pos, tngclass, crmodel, plyr_idx); + if (!creature_count_below_map_limit(0)) + { + WARNLOG("Could not create creature %s from script to due to creature limit", creature_code_name(crmodel)); + return INVALID_THING; + } + struct Thing* thing = create_thing_at_position_then_move_to_valid_and_add_light(&pos, TCls_Creature, crmodel, plyr_idx); if (thing_is_invalid(thing)) { - ERRORLOG("Couldn't create %s at location %d",thing_class_and_model_name(tngclass, crmodel),(int)location); + ERRORLOG("Couldn't create %s at location %d", creature_code_name(crmodel), (int)location); // Error is already logged return INVALID_THING; } From 811fbc7d6acf22359a1418a2c8a3f99e7beab23a Mon Sep 17 00:00:00 2001 From: Loobinex Date: Mon, 9 Sep 2024 13:45:14 +0200 Subject: [PATCH 45/54] Sooner give the create creature error --- src/thing_creature.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/thing_creature.c b/src/thing_creature.c index f7c518ed91..adb02066bd 100644 --- a/src/thing_creature.c +++ b/src/thing_creature.c @@ -4030,7 +4030,7 @@ TbBool creature_count_below_map_limit(TbBool temp_creature) struct Thing *create_creature(struct Coord3d *pos, ThingModel model, PlayerNumber owner) { struct CreatureStats* crstat = creature_stats_get(model); - if (game.thing_lists[TngList_Creatures].count > CREATURES_COUNT) + if (game.thing_lists[TngList_Creatures].count >= CREATURES_COUNT) { ERRORLOG("Cannot create %s for player %d. Creature limit %d reached.", creature_code_name(model), (int)owner, CREATURES_COUNT); return INVALID_THING; From 49b9f60a9988398cb7c2b325eec6db679b935156 Mon Sep 17 00:00:00 2001 From: Loobinex Date: Mon, 9 Sep 2024 13:45:36 +0200 Subject: [PATCH 46/54] Fixed unrelated transparency_flags log error --- src/config_crtrmodel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config_crtrmodel.c b/src/config_crtrmodel.c index f6ad2e04ca..d31c1be2ee 100644 --- a/src/config_crtrmodel.c +++ b/src/config_crtrmodel.c @@ -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) { From 73bd759b97922a01cb2cee7a12c2a73b8ba2fe7e Mon Sep 17 00:00:00 2001 From: Loobinex Date: Mon, 9 Sep 2024 13:51:34 +0200 Subject: [PATCH 47/54] Stops computer players from trying to cast imp at map limit --- src/player_compchecks.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/player_compchecks.c b/src/player_compchecks.c index 1d747f8f98..bc64c2d7a4 100644 --- a/src/player_compchecks.c +++ b/src/player_compchecks.c @@ -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; From 033c62203cd45df459fbcb80eab9480fbfea3a72 Mon Sep 17 00:00:00 2001 From: Loobinex Date: Mon, 9 Sep 2024 15:39:29 +0200 Subject: [PATCH 48/54] convert_creature_to_ghost still kills creature when at hard limit --- src/creature_states_tortr.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/creature_states_tortr.c b/src/creature_states_tortr.c index 8ec0752310..534d004ac8 100644 --- a/src/creature_states_tortr.c +++ b/src/creature_states_tortr.c @@ -286,7 +286,6 @@ void convert_creature_to_ghost(struct Room *room, struct Thing *thing) } 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); struct CreatureControl* newcctrl = creature_control_get_from_thing(newthing); From 74dcdf80e045dee7bfe4d7837fe3b5dd24db7f15 Mon Sep 17 00:00:00 2001 From: Loobinex Date: Mon, 9 Sep 2024 17:45:01 +0200 Subject: [PATCH 49/54] created a separate function for the setting up to leave/die --- src/lvl_script_commands.c | 40 +------------------------------- src/thing_list.c | 48 +++++++++++++++++++++++++++++++++++++++ src/thing_list.h | 1 + 3 files changed, 50 insertions(+), 39 deletions(-) diff --git a/src/lvl_script_commands.c b/src/lvl_script_commands.c index 5f2555262f..99fb2279bf 100644 --- a/src/lvl_script_commands.c +++ b/src/lvl_script_commands.c @@ -5462,45 +5462,7 @@ static void set_game_rule_process(struct ScriptContext* context) //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); - 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; - } - } + short count = setup_excess_creatures_to_leave_or_die(game.conf.rules.game.creatures_count); if (count > 0) { SCRPTLOG("Map creature limit reduced, causing %d creatures to leave or die",count); diff --git a/src/thing_list.c b/src/thing_list.c index 405c34596c..9fd81fca4e 100644 --- a/src/thing_list.c +++ b/src/thing_list.c @@ -4254,6 +4254,54 @@ void setup_all_player_creatures_and_diggers_leave_or_die(PlayerNumber plyr_idx) do_to_players_all_creatures_of_model(plyr_idx, CREATURE_DIGGER, setup_creature_die_if_not_in_custody); } +unsigned short setup_excess_creatures_to_leave_or_die(short max_remain) +{ + struct CreatureControl* cctrl; + const struct StructureList* slist = get_list_for_thing_class(TCls_Creature); + unsigned long k = 0; + int i = slist->index; + short count = 0; + if (slist->count <= max_remain) + { + return count; + } + 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 > max_remain) + { + 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; + } + return count; + } +} + long count_creatures_in_dungeon_of_model_flags(const struct Dungeon *dungeon, unsigned long need_mdflags, unsigned long excl_mdflags) { long count = 0; diff --git a/src/thing_list.h b/src/thing_list.h index 0cbe5ab35e..c825d6c158 100644 --- a/src/thing_list.h +++ b/src/thing_list.h @@ -345,6 +345,7 @@ struct Thing* get_timebomb_target(struct Thing *creatng); void setup_all_player_creatures_and_diggers_leave_or_die(PlayerNumber plyr_idx); TbBool setup_creature_leave_or_die_if_possible(struct Thing* thing); +unsigned short setup_excess_creatures_to_leave_or_die(short max_remain); /******************************************************************************/ #ifdef __cplusplus } From 63ce3578b2713918448d6d5fdcd19266254c6bee Mon Sep 17 00:00:00 2001 From: Loobinex Date: Mon, 9 Sep 2024 18:24:28 +0200 Subject: [PATCH 50/54] No longer use 'is being sacrificed' as workaround for leaving creatures alone --- src/creature_states.c | 24 +++++++++++++++++++++--- src/creature_states.h | 1 + src/creature_states_combt.c | 2 +- src/creature_states_hero.c | 4 ++-- src/creature_states_mood.c | 2 +- src/creature_states_scavn.c | 2 +- src/magic.c | 8 ++++++-- src/main.cpp | 4 ++-- src/player_compchecks.c | 2 +- src/player_comptask.c | 4 ++++ src/power_hand.c | 4 ++++ src/thing_creature.c | 10 ++++++++++ src/thing_list.c | 8 ++++---- src/thing_traps.c | 2 +- 14 files changed, 59 insertions(+), 18 deletions(-) diff --git a/src/creature_states.c b/src/creature_states.c index e29376b268..cdf1516916 100644 --- a/src/creature_states.c +++ b/src/creature_states.c @@ -664,10 +664,18 @@ TbBool creature_is_being_tortured(const struct Thing *thing) return false; } -TbBool creature_is_being_sacrificed(const struct Thing *thing) +TbBool creature_is_leaving_and_cannot_be_stopped(const struct Thing *thing) { CrtrStateId i = get_creature_state_besides_interruptions(thing); - if ((i == CrSt_CreatureSacrifice) || (i == CrSt_CreatureBeingSacrificed) || (i == CrSt_LeavesBecauseOwnerLost)) + if (i == CrSt_LeavesBecauseOwnerLost) + return true; + return false; +} + +TbBool creature_is_being_sacrificed(const struct Thing* thing) +{ + CrtrStateId i = get_creature_state_besides_interruptions(thing); + if ((i == CrSt_CreatureSacrifice) || (i == CrSt_CreatureBeingSacrificed)) return true; return false; } @@ -2339,7 +2347,7 @@ struct Thing *find_random_creature_for_persuade(PlayerNumber plyr_idx, struct Co if ((n <= 0) ) { if (!thing_is_picked_up(thing) && !creature_is_kept_in_custody(thing) - && !creature_is_being_unconscious(thing) && !creature_is_dying(thing)) + && !creature_is_being_unconscious(thing) && !creature_is_dying(thing) && !creature_is_leaving_and_cannot_be_stopped(thing)) { return thing; } @@ -4100,6 +4108,9 @@ TbBool process_creature_hunger(struct Thing *thing) */ TbBool creature_will_attack_creature(const struct Thing *fightng, const struct Thing *enmtng) { + if (creature_is_leaving_and_cannot_be_stopped(fightng) || creature_is_leaving_and_cannot_be_stopped(enmtng)) { + return false; + } if (creature_is_being_unconscious(fightng) || creature_is_being_unconscious(enmtng)) { return false; } @@ -4165,6 +4176,9 @@ TbBool creature_will_attack_creature_incl_til_death(const struct Thing *fightng, if (thing_is_picked_up(fightng) || thing_is_picked_up(enmtng)) { return false; } + if (creature_is_leaving_and_cannot_be_stopped(fightng) || creature_is_leaving_and_cannot_be_stopped(enmtng)) { + return false; + } struct CreatureControl* fighctrl = creature_control_get_from_thing(fightng); struct CreatureControl* enmctrl = creature_control_get_from_thing(enmtng); @@ -5194,6 +5208,10 @@ void process_person_moods_and_needs(struct Thing *thing) // And creatures being tortured, imprisoned, etc. return; } + if (creature_is_leaving_and_cannot_be_stopped(thing)) + { + return false; + } struct CreatureStats* crstat = creature_stats_get_from_thing(thing); // Now process the needs process_creature_hunger(thing); diff --git a/src/creature_states.h b/src/creature_states.h index 6e73228c44..7990953634 100644 --- a/src/creature_states.h +++ b/src/creature_states.h @@ -372,6 +372,7 @@ TbBool creature_is_being_unconscious(const struct Thing *thing); TbBool creature_is_celebrating(const struct Thing *thing); TbBool creature_is_being_tortured(const struct Thing *thing); TbBool creature_is_being_sacrificed(const struct Thing *thing); +TbBool creature_is_leaving_and_cannot_be_stopped(const struct Thing* thing); TbBool creature_is_kept_in_prison(const struct Thing *thing); TbBool creature_is_being_summoned(const struct Thing *thing); TbBool creature_is_doing_anger_job(const struct Thing *thing); diff --git a/src/creature_states_combt.c b/src/creature_states_combt.c index 135578c4e7..421b2ed2fa 100644 --- a/src/creature_states_combt.c +++ b/src/creature_states_combt.c @@ -1249,7 +1249,7 @@ CrAttackType find_fellow_creature_to_fight_in_room(struct Thing *fightng, struct if (thing_is_creature(thing) && (thing_matches_model(thing,crmodel[j])) && (cctrl->combat_flags == 0)) { if (!thing_is_picked_up(thing) && !creature_is_kept_in_custody(thing) - && !creature_is_being_unconscious(thing) && !creature_is_dying(thing)) + && !creature_is_being_unconscious(thing) && !creature_is_dying(thing) && !creature_is_leaving_and_cannot_be_stopped(thing)) { if ((thing->index != fightng->index) && (get_room_thing_is_on(thing)->index == room->index)) { diff --git a/src/creature_states_hero.c b/src/creature_states_hero.c index e3095e0537..1176960211 100644 --- a/src/creature_states_hero.c +++ b/src/creature_states_hero.c @@ -399,7 +399,7 @@ long get_wanderer_possible_targets_count_in_list(long first_thing_idx, struct Th } i = cctrl->players_next_creature_idx; // Thing list loop body - if (!thing_is_picked_up(thing) && !creature_is_kept_in_custody_by_enemy(thing)) + if (!thing_is_picked_up(thing) && !creature_is_kept_in_custody_by_enemy(thing) && !creature_is_leaving_and_cannot_be_stopped(thing)) { // Don't check for being navigable - it's too CPU-expensive to check all creatures //if ( creature_can_navigate_to(wanderer, &thing->mappos, NavTF_Default) ) @@ -437,7 +437,7 @@ TbBool wander_to_specific_possible_target_in_list(long first_thing_idx, struct T } i = cctrl->players_next_creature_idx; // Thing list loop body - if (!thing_is_picked_up(thing) && !creature_is_kept_in_custody_by_enemy(thing)) + if (!thing_is_picked_up(thing) && !creature_is_kept_in_custody_by_enemy(thing) && !creature_is_leaving_and_cannot_be_stopped(thing)) { // If it's not the one we want, continue sweeping if (target_match > 0) diff --git a/src/creature_states_mood.c b/src/creature_states_mood.c index 65c5baf297..460c9ef16f 100644 --- a/src/creature_states_mood.c +++ b/src/creature_states_mood.c @@ -382,7 +382,7 @@ TbBool creature_will_go_postal_on_victim_during_job(const struct Thing *creatng, { if (thing_is_creature(victng) && (victng->index != creatng->index) && !creature_has_job(victng, job_kind) && !creature_is_kept_in_custody(victng) && !creature_is_being_unconscious(victng) - && !creature_is_dying(victng) && !creature_is_doing_anger_job(victng)) + && !creature_is_dying(victng) && !creature_is_doing_anger_job(victng) && !creature_is_leaving_and_cannot_be_stopped(victng)) { if (!creature_is_invisible(victng) || creature_can_see_invisible(creatng)) { return true; diff --git a/src/creature_states_scavn.c b/src/creature_states_scavn.c index 02420c83e9..a29b54dfa3 100644 --- a/src/creature_states_scavn.c +++ b/src/creature_states_scavn.c @@ -264,7 +264,7 @@ TbBool thing_is_valid_scavenge_target(const struct Thing *calltng, const struct if (thing_is_picked_up(scavtng)) { return false; } - if (is_thing_directly_controlled(scavtng) || creature_is_kept_in_custody(scavtng)) { + if (is_thing_directly_controlled(scavtng) || creature_is_kept_in_custody(scavtng) || creature_is_leaving_and_cannot_be_stopped(scavtng)) { return false; } if (is_hero_thing(scavtng) && (!game.conf.rules.rooms.scavenge_good_allowed)) { diff --git a/src/magic.c b/src/magic.c index 32777e5bfa..3dd6280d89 100644 --- a/src/magic.c +++ b/src/magic.c @@ -342,6 +342,10 @@ TbBool can_cast_power_on_thing(PlayerNumber plyr_idx, const struct Thing *thing, } if (thing_is_creature(thing)) { + if (creature_is_leaving_and_cannot_be_stopped(thing)) + { + return false; + } if (creature_is_for_dungeon_diggers_list(thing)) { if (powerst->can_cast_flags & PwCast_DiggersNot) @@ -1081,7 +1085,7 @@ static TbResult magic_use_power_hold_audience(PowerKind power_kind, PlayerNumber } i = cctrl->players_next_creature_idx; // Thing list loop body - if (!thing_is_picked_up(thing) && !creature_is_kept_in_custody(thing) && !creature_is_being_unconscious(thing)) + if (!thing_is_picked_up(thing) && !creature_is_kept_in_custody(thing) && !creature_is_being_unconscious(thing) && !creature_is_leaving_and_cannot_be_stopped(thing)) { create_effect(&thing->mappos, imp_spangle_effects[get_player_color_idx(thing->owner)], thing->owner); const struct Coord3d *pos; @@ -1838,7 +1842,7 @@ int affect_nearby_creatures_by_power_call_to_arms(PlayerNumber plyr_idx, long ra i = cctrl->players_next_creature_idx; // Thing list loop body if (!thing_is_picked_up(thing) && !creature_is_kept_in_custody(thing) && - !creature_is_being_unconscious(thing) && !creature_is_dying(thing)) + !creature_is_being_unconscious(thing) && !creature_is_dying(thing) && !creature_is_leaving_and_cannot_be_stopped(thing)) { if (affect_creature_by_power_call_to_arms(thing, range, pos)) { n++; diff --git a/src/main.cpp b/src/main.cpp index 3460dd3792..81615e4487 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -356,7 +356,7 @@ void affect_nearby_friends_with_alarm(struct Thing *traptng) // Thing list loop body if (!thing_is_picked_up(thing) && !is_thing_directly_controlled(thing) && !creature_is_being_unconscious(thing) && !creature_is_kept_in_custody(thing) && - (cctrl->combat_flags == 0) && !creature_is_dragging_something(thing) && !creature_is_dying(thing)) + (cctrl->combat_flags == 0) && !creature_is_dragging_something(thing) && !creature_is_dying(thing) && !creature_is_leaving_and_cannot_be_stopped(thing)) { struct StateInfo *stati; stati = get_thing_state_info_num(get_creature_state_besides_interruptions(thing)); @@ -2563,7 +2563,7 @@ TngUpdateRet damage_creatures_with_physical_force(struct Thing *thing, ModTngFil if (thing_is_creature(thing)) { apply_damage_to_thing_and_display_health(thing, param->num2, DmgT_Physical, param->num1); - if (thing->health >= 0) + if ((thing->health >= 0) && !creature_is_leaving_and_cannot_be_stopped(thing)) { if (((thing->alloc_flags & TAlF_IsControlled) == 0) && !creature_is_kept_in_custody(thing)) { diff --git a/src/player_compchecks.c b/src/player_compchecks.c index bc64c2d7a4..414c5362de 100644 --- a/src/player_compchecks.c +++ b/src/player_compchecks.c @@ -214,7 +214,7 @@ int calculate_number_of_creatures_to_move(struct Dungeon *dungeon, int percent_t break; } - if (!creature_is_being_unconscious(thing) && !thing_is_picked_up(thing) && !creature_is_kept_in_custody_by_enemy(thing)) + if (!creature_is_being_unconscious(thing) && !thing_is_picked_up(thing) && !creature_is_kept_in_custody_by_enemy(thing) && !creature_is_leaving_and_cannot_be_stopped(thing)) { struct CreatureStats* crstat = creature_stats_get_from_thing(thing); if ((cctrl->job_assigned == crstat->job_primary) || (cctrl->job_assigned == crstat->job_secondary) || (cctrl->job_assigned == 0)) diff --git a/src/player_comptask.c b/src/player_comptask.c index 6c424a02c8..7da02d6b4c 100644 --- a/src/player_comptask.c +++ b/src/player_comptask.c @@ -757,6 +757,10 @@ TbBool creature_could_be_placed_in_better_room(const struct Computer2 *comp, con TbBool better_job_allowed; SYNCDBG(19,"Starting for %s index %d owner %d",thing_model_name(thing),(int)thing->index,(int)thing->owner); dungeon = comp->dungeon; + if (thing_is_creature(thing) && creature_is_leaving_and_cannot_be_stopped(thing)) + { + return false; + } // Choose the room we're currently working in, and check it on the list chosen_room = get_room_creature_works_in(thing); if (!room_exists(chosen_room)) { diff --git a/src/power_hand.c b/src/power_hand.c index b7952253ae..62c6df1874 100644 --- a/src/power_hand.c +++ b/src/power_hand.c @@ -206,6 +206,10 @@ long can_thing_be_picked_up_by_player(const struct Thing *thing, PlayerNumber pl if (thing_is_creature(thing) && thing_pickup_is_blocked_by_hand_rule(thing, plyr_idx)) { return false; } + if (thing_is_creature(thing) && creature_is_leaving_and_cannot_be_stopped(thing)) + { + return false; + } // Some things can be picked not to be placed in hand, but for direct use if (thing_is_object(thing)) { diff --git a/src/thing_creature.c b/src/thing_creature.c index adb02066bd..6b1b5a9a25 100644 --- a/src/thing_creature.c +++ b/src/thing_creature.c @@ -5849,6 +5849,10 @@ TbBool creature_is_slappable(const struct Thing *thing, PlayerNumber plyr_idx) { return false; } + if (creature_is_leaving_and_cannot_be_stopped(thing)) + { + return false; + } if (thing->owner != plyr_idx) { if (creature_is_kept_in_prison(thing) || creature_is_being_tortured(thing)) @@ -5901,6 +5905,9 @@ int claim_neutral_creatures_in_sight(struct Thing *creatng, struct Coord3d *pos, { if (is_neutral_thing(thing) && line_of_sight_3d(&thing->mappos, pos)) { + if (creature_is_leaving_and_cannot_be_stopped(thing) || creature_is_leaving_and_cannot_be_stopped(creatng)) + return false; + // Unless the relevant classic bug is enabled, // neutral creatures in custody (prison/torture) can only be claimed by the player who holds it captive // and neutral creatures can not be claimed by creatures in custody. @@ -6808,6 +6815,9 @@ void query_creature(struct PlayerInfo *player, ThingIndex index, TbBool reset, T TbBool creature_can_be_queried(struct PlayerInfo *player, struct Thing *creatng) { + if (creature_is_leaving_and_cannot_be_stopped(creatng)) + return false; + switch (player->work_state) { case PSt_CreatrInfo: diff --git a/src/thing_list.c b/src/thing_list.c index 9fd81fca4e..71abd3ad26 100644 --- a/src/thing_list.c +++ b/src/thing_list.c @@ -295,7 +295,7 @@ long near_thing_pos_thing_filter_is_enemy_which_can_be_shot_by_trap(const struct if (players_are_enemies(traptng->owner, thing->owner) || is_neutral_thing(traptng)) { if (!creature_is_being_unconscious(thing) && !thing_is_dragged_or_pulled(thing) && !thing_is_picked_up(thing) - && !creature_is_kept_in_custody_by_enemy(thing) && !creature_is_dying(thing) + && !creature_is_kept_in_custody_by_enemy(thing) && !creature_is_dying(thing) && !creature_is_leaving_and_cannot_be_stopped(thing) && ((get_creature_model_flags(thing) & CMF_IsSpectator) == 0)) { MapCoordDelta distance = get_2d_distance(&thing->mappos, &traptng->mappos); @@ -423,7 +423,7 @@ long near_map_block_thing_filter_is_enemy_of_able_to_attack_and_not_specdigger(c { if ((thing->class_id == TCls_Creature) && players_are_enemies(param->plyr_idx, thing->owner)) { - if (!creature_is_being_unconscious(thing) && !thing_is_picked_up(thing) && !creature_is_kept_in_custody_by_enemy(thing)) + if (!creature_is_being_unconscious(thing) && !thing_is_picked_up(thing) && !creature_is_kept_in_custody_by_enemy(thing) && !creature_is_leaving_and_cannot_be_stopped(thing)) { if ((get_creature_model_flags(thing) & CMF_IsSpecDigger) == 0) { @@ -455,7 +455,7 @@ long near_map_block_thing_filter_is_creature_of_model_owned_and_controlled_by(co { if ((param->plyr_idx == -1) || (thing->owner == param->plyr_idx)) { - if (!creature_is_being_unconscious(thing) && !thing_is_picked_up(thing) && !creature_is_kept_in_custody_by_enemy(thing)) + if (!creature_is_being_unconscious(thing) && !thing_is_picked_up(thing) && !creature_is_kept_in_custody_by_enemy(thing) && !creature_is_leaving_and_cannot_be_stopped(thing)) { // Prepare reference Coord3d struct for distance computation struct Coord3d refpos; @@ -4197,7 +4197,7 @@ TbBool setup_creature_leave_or_die_if_possible(struct Thing *thing) { if (!is_thing_some_way_controlled(thing) && !creature_is_dying(thing)) { - if (!creature_is_kept_in_custody_by_enemy(thing) && !creature_is_being_unconscious(thing)) + if (!creature_is_kept_in_custody_by_enemy(thing) && !creature_is_being_unconscious(thing) && !creature_is_leaving_and_cannot_be_stopped(thing)) { SYNCDBG(9,"Forcing on %s index %d",thing_model_name(thing),(int)thing->index); // Drop creature if it's being dragged diff --git a/src/thing_traps.c b/src/thing_traps.c index 24c27c740e..926a1e3d16 100644 --- a/src/thing_traps.c +++ b/src/thing_traps.c @@ -200,7 +200,7 @@ TbBool thing_is_deployed_trap(const struct Thing* thing) TbBool creature_available_for_trap_trigger(struct Thing* creatng) { if (!creature_is_being_unconscious(creatng) && !thing_is_dragged_or_pulled(creatng) - && !creature_is_kept_in_custody_by_enemy(creatng) && !creature_is_dying(creatng) + && !creature_is_kept_in_custody_by_enemy(creatng) && !creature_is_dying(creatng) && !creature_is_leaving_and_cannot_be_stopped(creatng) && !creature_is_being_dropped(creatng) && !flag_is_set(get_creature_model_flags(creatng),CMF_IsSpectator)) { return true; From 8bbadcc931c2c02beeb32457e87559c5375bdff2 Mon Sep 17 00:00:00 2001 From: Loobinex Date: Mon, 9 Sep 2024 20:41:48 +0200 Subject: [PATCH 51/54] Fixed mistake in moving of script function --- src/thing_list.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/thing_list.c b/src/thing_list.c index 71abd3ad26..8636c945d2 100644 --- a/src/thing_list.c +++ b/src/thing_list.c @@ -4298,8 +4298,8 @@ unsigned short setup_excess_creatures_to_leave_or_die(short max_remain) ERRORLOG("Infinite loop detected when sweeping things list"); break; } - return count; } + return count; } long count_creatures_in_dungeon_of_model_flags(const struct Dungeon *dungeon, unsigned long need_mdflags, unsigned long excl_mdflags) From 317cb4fccd89280153c6bab28181e53035e6d972 Mon Sep 17 00:00:00 2001 From: Loobinex Date: Tue, 10 Sep 2024 15:57:08 +0200 Subject: [PATCH 52/54] updated comment on rules.cfg --- config/fxdata/rules.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/fxdata/rules.cfg b/config/fxdata/rules.cfg index 3299ccb0d2..d656c2e350 100644 --- a/config/fxdata/rules.cfg +++ b/config/fxdata/rules.cfg @@ -51,7 +51,7 @@ 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. +; Total Amount of Creatures on the map. The absolute maximum is 1023, problem free up to 1022. MapCreatureLimit = 1000 ; Global light strength and dynamic lighting (32 is full bright). GlobalAmbientLight = 10 From 97d0f98045b41fbe9fa24da118ceea12e27534bf Mon Sep 17 00:00:00 2001 From: Loobinex Date: Tue, 10 Sep 2024 17:23:14 +0200 Subject: [PATCH 53/54] Made sure people cannot go past 1022 creatures It's 1024, but creature 0 is there too and 1 creature as a buffer to grow up and transfer without problems. --- config/fxdata/rules.cfg | 2 +- src/config_rules.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/fxdata/rules.cfg b/config/fxdata/rules.cfg index d656c2e350..0f7311fa6e 100644 --- a/config/fxdata/rules.cfg +++ b/config/fxdata/rules.cfg @@ -51,7 +51,7 @@ 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, problem free up to 1022. +; Total Amount of Creatures on the map. The absolute maximum is 1022. MapCreatureLimit = 1000 ; Global light strength and dynamic lighting (32 is full bright). GlobalAmbientLight = 10 diff --git a/src/config_rules.c b/src/config_rules.c index 1670f8a8d4..447a469e7e 100644 --- a/src/config_rules.c +++ b/src/config_rules.c @@ -93,7 +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}, + {"MAPCREATURELIMIT", &game.conf.rules.game.creatures_count, var_type(game.conf.rules.game.creatures_count ), 0,CREATURES_COUNT-2}, {NULL, NULL,0,0,0 }, }; From fb6364e8149a16552167bbba7fdb62313a4d1b98 Mon Sep 17 00:00:00 2001 From: Loobinex Date: Tue, 10 Sep 2024 17:45:03 +0200 Subject: [PATCH 54/54] Get message back on !map.pool console command --- src/console_cmd.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/console_cmd.c b/src/console_cmd.c index 5589e6eadc..38548f280b 100644 --- a/src/console_cmd.c +++ b/src/console_cmd.c @@ -724,22 +724,20 @@ TbBool cmd_exec(PlayerNumber plyr_idx, char *msg) } else if ((strcasecmp(parstr, "map.pool") == 0) || (strcasecmp(parstr, "creature.pool") == 0)) { + long kind = get_id(creature_desc, pr2str); + if (kind == -1) + { + targeted_message_add(MsgType_Player, plyr_idx, plyr_idx, GUI_MESSAGES_DELAY, "Invalid creature: %s",pr2str); + return false; + } 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; - } + targeted_message_add(MsgType_Player, plyr_idx, plyr_idx, GUI_MESSAGES_DELAY, "Pool count %s: %d", pr2str,game.pool.crtr_kind[kind]); + return true; } else { + targeted_message_add(MsgType_Player, plyr_idx, plyr_idx, GUI_MESSAGES_DELAY, "Set %s pool count: %d", pr2str, atoi(pr3str)); return script_set_pool(plyr_idx, pr2str, pr3str); } }