Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Max fighters #3148

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/fxdata/rules.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ StunGoodEnemyChance = 100
; Amount of health below which the creature ignores its other needs.
; except hunger and immediately goes to lair to heal itself, 0..99.
CriticalHealthPercentage = 13
MaxMeeleOpponents = 4
MaxRangedOpponents = 4

[magic]
HoldAudienceTime = 500
Expand Down
2 changes: 2 additions & 0 deletions src/config_rules.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ const struct NamedField rules_creatures_named_fields[] = {
{"GAMETURNSUNCONSCIOUS", &game.conf.rules.creature.game_turns_unconscious,var_type(game.conf.rules.creature.game_turns_unconscious), 0,USHRT_MAX},
{"STUNEVILENEMYCHANCE", &game.conf.rules.creature.stun_enemy_chance_evil,var_type(game.conf.rules.creature.stun_enemy_chance_evil), 0, 100},
{"STUNGOODENEMYCHANCE", &game.conf.rules.creature.stun_enemy_chance_good,var_type(game.conf.rules.creature.stun_enemy_chance_good), 0, 100},
{"MaxMeeleOpponents", &game.conf.rules.creature.stun_enemy_chance_good,var_type(game.conf.rules.creature.stun_enemy_chance_good), 0, COMBAT_MELEE_OPPONENTS_LIMIT},
Copy link
Member

Choose a reason for hiding this comment

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

Typo and case

{"MaxRangedOpponents", &game.conf.rules.creature.stun_enemy_chance_good,var_type(game.conf.rules.creature.stun_enemy_chance_good), 0, COMBAT_RANGED_OPPONENTS_LIMIT},
{NULL,NULL,0,0,0 },
};

Expand Down
2 changes: 2 additions & 0 deletions src/config_rules.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ struct CreatureRulesConfig {
long critical_health_permil;
unsigned char stun_enemy_chance_evil;
unsigned char stun_enemy_chance_good;
unsigned char max_meele_opponents;
unsigned char max_ranged_opponents;
};

struct MagicRulesConfig {
Expand Down
4 changes: 2 additions & 2 deletions src/creature_battle.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ TbBool has_melee_combat_attackers(struct Thing *victim)
TbBool can_add_melee_combat_attacker(struct Thing *victim)
{
struct CreatureControl* vicctrl = creature_control_get_from_thing(victim);
return (vicctrl->opponents_melee_count < COMBAT_MELEE_OPPONENTS_LIMIT);
return (vicctrl->opponents_melee_count < game.conf.rules.creature.max_meele_opponents);
}

TbBool has_ranged_combat_attackers(const struct Thing *victim)
Expand Down Expand Up @@ -139,7 +139,7 @@ BattleIndex find_last_battle_of_mine(PlayerNumber plyr_idx)
TbBool can_add_ranged_combat_attacker(const struct Thing *victim)
{
struct CreatureControl* vicctrl = creature_control_get_from_thing(victim);
return (vicctrl->opponents_ranged_count < COMBAT_RANGED_OPPONENTS_LIMIT);
return (vicctrl->opponents_ranged_count < game.conf.rules.creature.max_ranged_opponents);
}

long get_flee_position(struct Thing *creatng, struct Coord3d *pos)
Expand Down
8 changes: 4 additions & 4 deletions src/creature_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ extern "C" {
#define CREATURE_MAX_SPELLS_CASTED_AT 5
/** Max amount of creatures supported on any map. */
#define CREATURES_COUNT 256
/** Number of possible melee combat opponents. */
#define COMBAT_MELEE_OPPONENTS_LIMIT 4
/** Number of possible range combat opponents. */
#define COMBAT_RANGED_OPPONENTS_LIMIT 4
/** absolute max number of possible melee combat opponents. actual max is game.conf.rules.creature.max_meele_opponents */
#define COMBAT_MELEE_OPPONENTS_LIMIT 32
/** absolute max number of possible range combat opponents. actual max is game.conf.rules.creature.max_ranged_opponents */
#define COMBAT_RANGED_OPPONENTS_LIMIT 32
/** Amount of instances. */
/** Max amount of rooms needed for a creature to be attracted to a dungeon. */
#define ENTRANCE_ROOMS_COUNT 3
Expand Down
50 changes: 25 additions & 25 deletions src/creature_states_combt.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ TbBool creature_is_being_attacked_by_enemy_player(struct Thing *fightng)
TRACE_THING(fightng);
struct CreatureControl* figctrl = creature_control_get_from_thing(fightng);
// Check any enemy creature is in melee opponents list
for (oppn_idx = 0; oppn_idx < COMBAT_MELEE_OPPONENTS_LIMIT; oppn_idx++)
for (oppn_idx = 0; oppn_idx < game.conf.rules.creature.max_meele_opponents; oppn_idx++)
{
struct Thing* enmtng = thing_get(figctrl->opponents_melee[oppn_idx]);
if (!thing_is_invalid(enmtng))
Expand All @@ -108,7 +108,7 @@ TbBool creature_is_being_attacked_by_enemy_player(struct Thing *fightng)
}
}
// Check any enemy creature is in ranged opponents list
for (oppn_idx = 0; oppn_idx < COMBAT_RANGED_OPPONENTS_LIMIT; oppn_idx++)
for (oppn_idx = 0; oppn_idx < game.conf.rules.creature.max_ranged_opponents; oppn_idx++)
{
struct Thing* enmtng = thing_get(figctrl->opponents_ranged[oppn_idx]);
if (!thing_is_invalid(enmtng))
Expand All @@ -127,7 +127,7 @@ TbBool creature_is_being_attacked_by_enemy_creature_not_digger(struct Thing *fig
TRACE_THING(fightng);
struct CreatureControl* figctrl = creature_control_get_from_thing(fightng);
// Check any enemy creature is in melee opponents list
for (oppn_idx = 0; oppn_idx < COMBAT_MELEE_OPPONENTS_LIMIT; oppn_idx++)
for (oppn_idx = 0; oppn_idx < game.conf.rules.creature.max_meele_opponents; oppn_idx++)
{
struct Thing* enmtng = thing_get(figctrl->opponents_melee[oppn_idx]);
if (!thing_is_invalid(enmtng) && !thing_is_creature_special_digger(enmtng))
Expand All @@ -138,7 +138,7 @@ TbBool creature_is_being_attacked_by_enemy_creature_not_digger(struct Thing *fig
}
}
// Check any enemy creature is in ranged opponents list
for (oppn_idx = 0; oppn_idx < COMBAT_RANGED_OPPONENTS_LIMIT; oppn_idx++)
for (oppn_idx = 0; oppn_idx < game.conf.rules.creature.max_ranged_opponents; oppn_idx++)
{
struct Thing* enmtng = thing_get(figctrl->opponents_ranged[oppn_idx]);
if (!thing_is_invalid(enmtng) && !thing_is_creature_special_digger(enmtng))
Expand Down Expand Up @@ -201,7 +201,7 @@ TbBool creature_has_other_attackers(const struct Thing *fightng, ThingModel enmo
TRACE_THING(fightng);
struct CreatureControl* figctrl = creature_control_get_from_thing(fightng);
// Check any enemy creature is in melee opponents list
for (oppn_idx = 0; oppn_idx < COMBAT_MELEE_OPPONENTS_LIMIT; oppn_idx++)
for (oppn_idx = 0; oppn_idx < game.conf.rules.creature.max_meele_opponents; oppn_idx++)
{
struct Thing* enmtng = thing_get(figctrl->opponents_melee[oppn_idx]);
if (!thing_is_invalid(enmtng))
Expand All @@ -212,7 +212,7 @@ TbBool creature_has_other_attackers(const struct Thing *fightng, ThingModel enmo
}
}
// Check any enemy creature is in ranged opponents list
for (oppn_idx = 0; oppn_idx < COMBAT_RANGED_OPPONENTS_LIMIT; oppn_idx++)
for (oppn_idx = 0; oppn_idx < game.conf.rules.creature.max_ranged_opponents; oppn_idx++)
{
struct Thing* enmtng = thing_get(figctrl->opponents_ranged[oppn_idx]);
if (!thing_is_invalid(enmtng))
Expand Down Expand Up @@ -798,21 +798,21 @@ TbBool add_ranged_combat_attacker(struct Thing *enmtng, unsigned short fighter_i
TRACE_THING(enmtng);
struct CreatureControl* enmctrl = creature_control_get_from_thing(enmtng);
// Check if the fighter is already in opponents list
for (oppn_idx = 0; oppn_idx < COMBAT_RANGED_OPPONENTS_LIMIT; oppn_idx++)
for (oppn_idx = 0; oppn_idx < game.conf.rules.creature.max_ranged_opponents; oppn_idx++)
{
if (enmctrl->opponents_ranged[oppn_idx] == fighter_idx) {
WARNLOG("Fighter %s index %d already in opponents list",thing_model_name(enmtng),(int)enmtng->index);
return true;
}
}
// Find empty opponent slot
for (oppn_idx = 0; oppn_idx < COMBAT_RANGED_OPPONENTS_LIMIT; oppn_idx++)
for (oppn_idx = 0; oppn_idx < game.conf.rules.creature.max_ranged_opponents; oppn_idx++)
{
if (enmctrl->opponents_ranged[oppn_idx] == 0)
break;
}
SYNCDBG(7,"Adding to %s index %d attacker %d index %d",thing_model_name(enmtng),(int)enmtng->index,(int)oppn_idx,(int)fighter_idx);
if (oppn_idx >= COMBAT_RANGED_OPPONENTS_LIMIT)
if (oppn_idx >= game.conf.rules.creature.max_ranged_opponents)
return false;
// Add the opponent
enmctrl->opponents_ranged_count++;
Expand All @@ -825,13 +825,13 @@ TbBool remove_ranged_combat_attacker(struct Thing *enmtng, unsigned short fighte
long oppn_idx;
TRACE_THING(enmtng);
struct CreatureControl* enmctrl = creature_control_get_from_thing(enmtng);
for (oppn_idx = 0; oppn_idx < COMBAT_RANGED_OPPONENTS_LIMIT; oppn_idx++)
for (oppn_idx = 0; oppn_idx < game.conf.rules.creature.max_ranged_opponents; oppn_idx++)
{
if (enmctrl->opponents_ranged[oppn_idx] == fighter_idx)
break;
}
SYNCDBG(7,"Removing from %s index %d attacker %d index %d",thing_model_name(enmtng),(int)enmtng->index,(int)oppn_idx,(int)fighter_idx);
if (oppn_idx >= COMBAT_RANGED_OPPONENTS_LIMIT)
if (oppn_idx >= game.conf.rules.creature.max_ranged_opponents)
return false;
enmctrl->opponents_ranged_count--;
enmctrl->opponents_ranged[oppn_idx] = 0;
Expand All @@ -844,20 +844,20 @@ TbBool add_melee_combat_attacker(struct Thing *enmtng, unsigned short fighter_id
TRACE_THING(enmtng);
struct CreatureControl* enmctrl = creature_control_get_from_thing(enmtng);
// Check if the fighter is already in opponents list
for (oppn_idx = 0; oppn_idx < COMBAT_MELEE_OPPONENTS_LIMIT; oppn_idx++)
for (oppn_idx = 0; oppn_idx < game.conf.rules.creature.max_meele_opponents; oppn_idx++)
{
if (enmctrl->opponents_melee[oppn_idx] == fighter_idx) {
WARNLOG("Fighter %s index %d already in opponents list",thing_model_name(enmtng),(int)enmtng->index);
return true;
}
}
// Find empty opponent slot
for (oppn_idx = 0; oppn_idx < COMBAT_MELEE_OPPONENTS_LIMIT; oppn_idx++)
for (oppn_idx = 0; oppn_idx < game.conf.rules.creature.max_meele_opponents; oppn_idx++)
{
if (enmctrl->opponents_melee[oppn_idx] == 0)
break;
}
if (oppn_idx >= COMBAT_MELEE_OPPONENTS_LIMIT)
if (oppn_idx >= game.conf.rules.creature.max_meele_opponents)
return false;
// Add the opponent
enmctrl->opponents_melee_count++;
Expand All @@ -870,12 +870,12 @@ TbBool remove_melee_combat_attacker(struct Thing *enmtng, unsigned short fighter
long oppn_idx;
TRACE_THING(enmtng);
struct CreatureControl* enmctrl = creature_control_get_from_thing(enmtng);
for (oppn_idx = 0; oppn_idx < COMBAT_MELEE_OPPONENTS_LIMIT; oppn_idx++)
for (oppn_idx = 0; oppn_idx < game.conf.rules.creature.max_meele_opponents; oppn_idx++)
{
if (enmctrl->opponents_melee[oppn_idx] == fighter_idx)
break;
}
if (oppn_idx >= COMBAT_MELEE_OPPONENTS_LIMIT)
if (oppn_idx >= game.conf.rules.creature.max_meele_opponents)
return false;
enmctrl->opponents_melee_count--;
enmctrl->opponents_melee[oppn_idx] = 0;
Expand Down Expand Up @@ -965,7 +965,7 @@ long remove_all_melee_combat_attackers(struct Thing *victmtng)
TRACE_THING(victmtng);
long num = 0;
struct CreatureControl* vicctrl = creature_control_get_from_thing(victmtng);
for (long oppn_idx = 0; oppn_idx < COMBAT_MELEE_OPPONENTS_LIMIT; oppn_idx++)
for (long oppn_idx = 0; oppn_idx < game.conf.rules.creature.max_meele_opponents; oppn_idx++)
{
long fighter_idx = vicctrl->opponents_melee[oppn_idx];
if (fighter_idx > 0) {
Expand All @@ -989,7 +989,7 @@ long remove_all_ranged_combat_attackers(struct Thing *victmtng)
TRACE_THING(victmtng);
long num = 0;
struct CreatureControl* vicctrl = creature_control_get_from_thing(victmtng);
for (long oppn_idx = 0; oppn_idx < COMBAT_RANGED_OPPONENTS_LIMIT; oppn_idx++)
for (long oppn_idx = 0; oppn_idx < game.conf.rules.creature.max_ranged_opponents; oppn_idx++)
{
long fighter_idx = vicctrl->opponents_ranged[oppn_idx];
if (fighter_idx > 0) {
Expand Down Expand Up @@ -1490,7 +1490,7 @@ CrAttackType check_for_possible_melee_combat_with_attacker_within_distance(struc
struct CreatureControl* figctrl = creature_control_get_from_thing(fightng);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not 100% certain but check those lines 1455 / 1460 / 1464 / 1471 / 1476 / 1480.

I think the magic number 4 refer to the limit that is hardcoded, so maybe it should no longer be 4 but the actual limit set in config now?

score_base = 258 * (4 - enmctrl->opponents_ranged_count) + score_extra;

would become:

score_base = 258 * (COMBAT_RANGED_OPPONENTS_LIMIT - enmctrl->opponents_ranged_count) + score_extra;

if that makes senses to you? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

aight makes sense, I'll try and figure out all of the magic numbers in the function, but those 4's being the max opponents makes sense

CrAttackType best = AttckT_Unset;
// Check scores of melee opponents
for (long oppn_idx = 0; oppn_idx < COMBAT_MELEE_OPPONENTS_LIMIT; oppn_idx++)
for (long oppn_idx = 0; oppn_idx < game.conf.rules.creature.max_meele_opponents; oppn_idx++)
{
long thing_idx = figctrl->opponents_melee[oppn_idx];
struct Thing* thing;
Expand Down Expand Up @@ -1526,7 +1526,7 @@ CrAttackType check_for_possible_ranged_combat_with_attacker_within_distance(stru
struct CreatureControl* figctrl = creature_control_get_from_thing(fightng);
CrAttackType best = AttckT_Unset;
// Check scores of ranged opponents
for (long oppn_idx = 0; oppn_idx < COMBAT_RANGED_OPPONENTS_LIMIT; oppn_idx++)
for (long oppn_idx = 0; oppn_idx < game.conf.rules.creature.max_ranged_opponents; oppn_idx++)
{
long thing_idx = figctrl->opponents_ranged[oppn_idx];
struct Thing* thing;
Expand Down Expand Up @@ -2464,7 +2464,7 @@ long creature_has_spare_slot_for_combat(struct Thing *fighter, struct Thing *ene
struct CreatureControl* enmctrl = creature_control_get_from_thing(enemy);
if (attack_type == AttckT_Ranged)
{
if (enmctrl->opponents_ranged_count < COMBAT_RANGED_OPPONENTS_LIMIT)
if (enmctrl->opponents_ranged_count < game.conf.rules.creature.max_ranged_opponents)
return true;
return false;
}
Expand All @@ -2474,11 +2474,11 @@ long creature_has_spare_slot_for_combat(struct Thing *fighter, struct Thing *ene
{
if (creature_has_ranged_weapon(fighter))
{
if (enmctrl->opponents_ranged_count < COMBAT_RANGED_OPPONENTS_LIMIT)
if (enmctrl->opponents_ranged_count < game.conf.rules.creature.max_ranged_opponents)
return true;
}
}
if (enmctrl->opponents_melee_count < COMBAT_MELEE_OPPONENTS_LIMIT)
if (enmctrl->opponents_melee_count < game.conf.rules.creature.max_meele_opponents)
return true;
return false;
}
Expand All @@ -2498,7 +2498,7 @@ long change_creature_with_existing_attacker(struct Thing *fighter, struct Thing
if (cctrl->opponents_ranged_count <= 0) {
ERRORLOG("No ranged attackers - serious");
}
for (i = 0; i < COMBAT_RANGED_OPPONENTS_LIMIT; i++)
for (i = 0; i < game.conf.rules.creature.max_ranged_opponents; i++)
{
if (cctrl->opponents_ranged[i] > 0)
{
Expand All @@ -2520,7 +2520,7 @@ long change_creature_with_existing_attacker(struct Thing *fighter, struct Thing
if (cctrl->opponents_melee_count <= 0) {
ERRORLOG("No melee attackers - serious");
}
for (i = 0; i < COMBAT_MELEE_OPPONENTS_LIMIT; i++)
for (i = 0; i < game.conf.rules.creature.max_meele_opponents; i++)
{
if (cctrl->opponents_melee[i] > 0)
{
Expand Down