2016-10-28 16:16:46 +02:00
|
|
|
/*
|
|
|
|
* AttackPossibility.h, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#pragma once
|
2017-07-20 06:08:49 +02:00
|
|
|
#include "../../lib/battle/CUnitState.h"
|
2016-11-01 20:53:46 +02:00
|
|
|
#include "../../CCallback.h"
|
2017-07-20 06:08:49 +02:00
|
|
|
#include "StackWithBonuses.h"
|
2016-10-28 16:16:46 +02:00
|
|
|
|
2022-04-11 08:12:41 +02:00
|
|
|
#define BATTLE_TRACE_LEVEL 0
|
|
|
|
|
2023-08-08 17:37:42 +02:00
|
|
|
class DamageCache
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
std::unordered_map<uint32_t, std::unordered_map<uint32_t, float>> damageCache;
|
2024-09-02 13:24:22 +02:00
|
|
|
std::map<BattleHex, std::unordered_map<uint32_t, int64_t>> obstacleDamage;
|
2023-08-08 17:37:42 +02:00
|
|
|
DamageCache * parent;
|
|
|
|
|
2024-09-02 13:24:22 +02:00
|
|
|
void buildObstacleDamageCache(std::shared_ptr<HypotheticBattle> hb, BattleSide side);
|
|
|
|
|
2023-08-08 17:37:42 +02:00
|
|
|
public:
|
|
|
|
DamageCache() : parent(nullptr) {}
|
|
|
|
DamageCache(DamageCache * parent) : parent(parent) {}
|
|
|
|
|
|
|
|
void cacheDamage(const battle::Unit * attacker, const battle::Unit * defender, std::shared_ptr<CBattleInfoCallback> hb);
|
|
|
|
int64_t getDamage(const battle::Unit * attacker, const battle::Unit * defender, std::shared_ptr<CBattleInfoCallback> hb);
|
2024-09-02 13:24:22 +02:00
|
|
|
int64_t getObstacleDamage(BattleHex hex, const battle::Unit * defender);
|
2023-08-08 17:37:42 +02:00
|
|
|
int64_t getOriginalDamage(const battle::Unit * attacker, const battle::Unit * defender, std::shared_ptr<CBattleInfoCallback> hb);
|
2024-08-11 22:22:35 +02:00
|
|
|
void buildDamageCache(std::shared_ptr<HypotheticBattle> hb, BattleSide side);
|
2023-08-08 17:37:42 +02:00
|
|
|
};
|
|
|
|
|
2022-10-17 18:47:16 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Evaluate attack value of one particular attack taking into account various effects like
|
|
|
|
/// retaliation, 2-hex breath, collateral damage, shooters blocked damage
|
|
|
|
/// </summary>
|
2016-10-28 16:16:46 +02:00
|
|
|
class AttackPossibility
|
|
|
|
{
|
|
|
|
public:
|
2019-06-28 20:05:25 +02:00
|
|
|
BattleHex from; //tile from which we attack
|
|
|
|
BattleHex dest; //tile which we attack
|
2016-10-28 16:16:46 +02:00
|
|
|
BattleAttackInfo attack;
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
std::shared_ptr<battle::CUnitState> attackerState;
|
|
|
|
|
|
|
|
std::vector<std::shared_ptr<battle::CUnitState>> affectedUnits;
|
|
|
|
|
2023-08-26 12:06:41 +02:00
|
|
|
float defenderDamageReduce = 0;
|
|
|
|
float attackerDamageReduce = 0; //usually by counter-attack
|
|
|
|
float collateralDamageReduce = 0; // friendly fire (usually by two-hex attacks)
|
2019-06-28 20:05:25 +02:00
|
|
|
int64_t shootersBlockedDmg = 0;
|
2024-08-04 16:50:19 +02:00
|
|
|
bool defenderDead = false;
|
2017-07-20 06:08:49 +02:00
|
|
|
|
2019-06-28 20:05:25 +02:00
|
|
|
AttackPossibility(BattleHex from, BattleHex dest, const BattleAttackInfo & attack_);
|
2016-10-28 16:16:46 +02:00
|
|
|
|
2023-08-26 12:06:41 +02:00
|
|
|
float damageDiff() const;
|
|
|
|
float attackValue() const;
|
|
|
|
float damageDiff(float positiveEffectMultiplier, float negativeEffectMultiplier) const;
|
2016-10-28 16:16:46 +02:00
|
|
|
|
2023-08-08 17:37:42 +02:00
|
|
|
static AttackPossibility evaluate(
|
|
|
|
const BattleAttackInfo & attackInfo,
|
|
|
|
BattleHex hex,
|
|
|
|
DamageCache & damageCache,
|
|
|
|
std::shared_ptr<CBattleInfoCallback> state);
|
2019-06-28 20:05:25 +02:00
|
|
|
|
2023-08-26 12:06:41 +02:00
|
|
|
static float calculateDamageReduce(
|
2022-04-11 08:12:41 +02:00
|
|
|
const battle::Unit * attacker,
|
|
|
|
const battle::Unit * defender,
|
|
|
|
uint64_t damageDealt,
|
2023-08-08 17:37:42 +02:00
|
|
|
DamageCache & damageCache,
|
|
|
|
std::shared_ptr<CBattleInfoCallback> cb);
|
2022-04-11 08:12:41 +02:00
|
|
|
|
2019-06-28 20:05:25 +02:00
|
|
|
private:
|
2023-08-08 17:37:42 +02:00
|
|
|
static int64_t evaluateBlockedShootersDmg(
|
|
|
|
const BattleAttackInfo & attackInfo,
|
|
|
|
BattleHex hex,
|
|
|
|
DamageCache & damageCache,
|
|
|
|
std::shared_ptr<CBattleInfoCallback> state);
|
2016-10-28 16:16:46 +02:00
|
|
|
};
|