mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-13 19:54:17 +02:00
AI: add army cost
This commit is contained in:
committed by
Andrii Danylchenko
parent
f44eaf8132
commit
3ffcef30f6
@@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
ChainActor::ChainActor(const CGHeroInstance * hero, uint64_t chainMask)
|
ChainActor::ChainActor(const CGHeroInstance * hero, uint64_t chainMask)
|
||||||
:hero(hero), isMovable(true), chainMask(chainMask), creatureSet(hero),
|
:hero(hero), isMovable(true), chainMask(chainMask), creatureSet(hero),
|
||||||
baseActor(this), carrierParent(nullptr), otherParent(nullptr), actorExchangeCount(1)
|
baseActor(this), carrierParent(nullptr), otherParent(nullptr), actorExchangeCount(1), armyCost()
|
||||||
{
|
{
|
||||||
initialPosition = hero->visitablePos();
|
initialPosition = hero->visitablePos();
|
||||||
layer = hero->boat ? EPathfindingLayer::SAIL : EPathfindingLayer::LAND;
|
layer = hero->boat ? EPathfindingLayer::SAIL : EPathfindingLayer::LAND;
|
||||||
@@ -31,7 +31,7 @@ ChainActor::ChainActor(const CGHeroInstance * hero, uint64_t chainMask)
|
|||||||
ChainActor::ChainActor(const ChainActor * carrier, const ChainActor * other, const CCreatureSet * heroArmy)
|
ChainActor::ChainActor(const ChainActor * carrier, const ChainActor * other, const CCreatureSet * heroArmy)
|
||||||
:hero(carrier->hero), isMovable(true), creatureSet(heroArmy), chainMask(carrier->chainMask | other->chainMask),
|
:hero(carrier->hero), isMovable(true), creatureSet(heroArmy), chainMask(carrier->chainMask | other->chainMask),
|
||||||
baseActor(this), carrierParent(carrier), otherParent(other), heroFightingStrength(carrier->heroFightingStrength),
|
baseActor(this), carrierParent(carrier), otherParent(other), heroFightingStrength(carrier->heroFightingStrength),
|
||||||
actorExchangeCount(carrier->actorExchangeCount + other->actorExchangeCount)
|
actorExchangeCount(carrier->actorExchangeCount + other->actorExchangeCount), armyCost(carrier->armyCost + other->armyCost)
|
||||||
{
|
{
|
||||||
armyValue = heroArmy->getArmyStrength();
|
armyValue = heroArmy->getArmyStrength();
|
||||||
}
|
}
|
||||||
@@ -39,7 +39,7 @@ ChainActor::ChainActor(const ChainActor * carrier, const ChainActor * other, con
|
|||||||
ChainActor::ChainActor(const CGObjectInstance * obj, const CCreatureSet * creatureSet, uint64_t chainMask, int initialTurn)
|
ChainActor::ChainActor(const CGObjectInstance * obj, const CCreatureSet * creatureSet, uint64_t chainMask, int initialTurn)
|
||||||
:hero(nullptr), isMovable(false), creatureSet(creatureSet), chainMask(chainMask),
|
:hero(nullptr), isMovable(false), creatureSet(creatureSet), chainMask(chainMask),
|
||||||
baseActor(this), carrierParent(nullptr), otherParent(nullptr), initialTurn(initialTurn), initialMovement(0),
|
baseActor(this), carrierParent(nullptr), otherParent(nullptr), initialTurn(initialTurn), initialMovement(0),
|
||||||
heroFightingStrength(0), actorExchangeCount(1)
|
heroFightingStrength(0), actorExchangeCount(1), armyCost()
|
||||||
{
|
{
|
||||||
initialPosition = obj->visitablePos();
|
initialPosition = obj->visitablePos();
|
||||||
layer = EPathfindingLayer::LAND;
|
layer = EPathfindingLayer::LAND;
|
||||||
@@ -81,6 +81,7 @@ void ChainActor::setBaseActor(HeroActor * base)
|
|||||||
creatureSet = base->creatureSet;
|
creatureSet = base->creatureSet;
|
||||||
isMovable = base->isMovable;
|
isMovable = base->isMovable;
|
||||||
heroFightingStrength = base->heroFightingStrength;
|
heroFightingStrength = base->heroFightingStrength;
|
||||||
|
armyCost = base->armyCost;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HeroActor::setupSpecialActors()
|
void HeroActor::setupSpecialActors()
|
||||||
@@ -145,6 +146,17 @@ bool HeroExchangeMap::canExchange(const ChainActor * other)
|
|||||||
|
|
||||||
if(result)
|
if(result)
|
||||||
{
|
{
|
||||||
|
if(other->armyCost.nonZero())
|
||||||
|
{
|
||||||
|
TResources resources = ai->myCb->getResourceAmount();
|
||||||
|
|
||||||
|
if(!resources.canAfford(actor->armyCost + other->armyCost))
|
||||||
|
{
|
||||||
|
result = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
uint64_t reinforcment = ai->ah->howManyReinforcementsCanGet(actor->creatureSet, other->creatureSet);
|
uint64_t reinforcment = ai->ah->howManyReinforcementsCanGet(actor->creatureSet, other->creatureSet);
|
||||||
|
|
||||||
result = reinforcment > actor->armyValue / 10 || reinforcment > 1000;
|
result = reinforcment > actor->armyValue / 10 || reinforcment > 1000;
|
||||||
@@ -208,6 +220,10 @@ DwellingActor::DwellingActor(const CGDwelling * dwelling, uint64_t chainMask, bo
|
|||||||
getInitialTurn(waitForGrowth, dayOfWeek)),
|
getInitialTurn(waitForGrowth, dayOfWeek)),
|
||||||
dwelling(dwelling)
|
dwelling(dwelling)
|
||||||
{
|
{
|
||||||
|
for(auto & slot : creatureSet->Slots())
|
||||||
|
{
|
||||||
|
armyCost += slot.second->getCreatureID().toCreature()->cost * slot.second->count;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DwellingActor::~DwellingActor()
|
DwellingActor::~DwellingActor()
|
||||||
|
@@ -46,6 +46,7 @@ public:
|
|||||||
uint64_t armyValue;
|
uint64_t armyValue;
|
||||||
float heroFightingStrength;
|
float heroFightingStrength;
|
||||||
uint8_t actorExchangeCount;
|
uint8_t actorExchangeCount;
|
||||||
|
TResources armyCost;
|
||||||
|
|
||||||
ChainActor(){}
|
ChainActor(){}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user