Голод в бою (−50%) и правило усталости (−20%, вместе 40%)

План от 27.10.2026, раздел «Армии и восстановление»:
- BattleCondition (флаги Famine, Fatigue); BattleRequest.AttackerConditions / DefenderConditions
- голод −50%, усталость −20%, применяются последовательно: вместе 40% силы
- порядок: контры и осадные → бонусы → состояния → случайность
- числа в BattleConfig (famineStrengthPercent, fatigueStrengthPercent) и BattleRules, версия правил 2
- BattleOutcome.AttackerConditionPercent / DefenderConditionPercent

Мир:
- голод проверяется на момент боя: WorldSimulation.AttackerConditions спрашивает MarchManager,
  тот берёт IPopulation.IsStarving
- бой в офлайне получает голод на момент входа в игру (истории голода у Населения нет) — записано в Battle.md

Интерфейс карты:
- окно атаки: «Голод: войско слабее, сила 50%. Накормите город до боя», прогноз учитывает голод
- окно итога боя: «голод: сила 50%»

Усталость пока никто не выставляет: не утверждено, как смешивать свежие и уставшие войска.

Тесты: штрафы и их сложение, голод переворачивает бой у нападающего и у защитника, прогноз с голодом,
голод в момент боя у похода. Все 39 тестов ModuleTests проходят вне Unity.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alexander
2026-10-28 19:16:25 +01:00
co-authored by Claude Opus 5.5
parent 2e87b10a58
commit 5581b4d2c9
13 changed files with 164 additions and 14 deletions
+19 -4
View File
@@ -76,9 +76,11 @@ public sealed class BattleSystem : IBattleSystem
int[] att = Units(request.AttackerUnits, request.Attackers);
int[] def = Units(request.DefenderUnits, request.Defenders);
long attPower = SidePower(att, def, attacking: true, request.DefenderFortified, request.AttackerBonusPercent, attLuckPermille);
int attCondition = ConditionPercent(request.AttackerConditions);
int defCondition = ConditionPercent(request.DefenderConditions);
long attPower = SidePower(att, def, attacking: true, request.DefenderFortified, request.AttackerBonusPercent, attCondition, attLuckPermille);
long defPower = SidePower(def, att, attacking: false, request.DefenderFortified,
request.DefenderBonusPercent + (request.DefenderFortified ? rules.WallsPercent : 0), defLuckPermille);
request.DefenderBonusPercent + (request.DefenderFortified ? rules.WallsPercent : 0), defCondition, defLuckPermille);
bool victory = attPower > defPower; // ничья -- в пользу защитника
@@ -114,6 +116,8 @@ public sealed class BattleSystem : IBattleSystem
DefenderPower = defPower,
AttackerLuckPermille = attLuckPermille,
DefenderLuckPermille = defLuckPermille,
AttackerConditionPercent = attCondition,
DefenderConditionPercent = defCondition,
AttackerUnitsBefore = att,
DefenderUnitsBefore = def,
AttackerSurvivorUnits = attAlive,
@@ -126,9 +130,19 @@ public sealed class BattleSystem : IBattleSystem
};
}
// Сколько силы оставляют состояния стороны, в процентах. Штрафы -- последовательно: голод и усталость -- 40%
public int ConditionPercent(BattleCondition conditions)
{
int percent = 100;
if ((conditions & BattleCondition.Famine) != 0) percent = percent * rules.FamineStrengthPercent / 100;
if ((conditions & BattleCondition.Fatigue) != 0) percent = percent * rules.FatigueStrengthPercent / 100;
return Math.Max(0, percent);
}
// Сила стороны в сотых долях (x100), чтобы проценты считались в целых числах.
// Порядок: контры и осадные -> бонусы стороны -> случайность (порядок -- открытый вопрос плана).
long SidePower(int[] units, int[] enemy, bool attacking, bool fortified, int bonusPercent, int luckPermille)
// Порядок: контры и осадные -> бонусы стороны -> состояния (голод, усталость) -> случайность
// (порядок бонусов и случайности -- открытый вопрос плана).
long SidePower(int[] units, int[] enemy, bool attacking, bool fortified, int bonusPercent, int conditionPercent, int luckPermille)
{
int enemyTotal = Sum(enemy);
long total = 0;
@@ -146,6 +160,7 @@ public sealed class BattleSystem : IBattleSystem
total += (long)units[i] * power[i] * (100 + counterPercent + siegePercent);
}
total = Math.Max(0, total * (100 + bonusPercent) / 100);
total = total * conditionPercent / 100;
return total * (1000 + luckPermille) / 1000;
}