浏览代码

Armycost

Added new method to retrieve the cost of an army to be used for AI-decision-making.
Xilmi 1 年之前
父节点
当前提交
aa891cb8b1
共有 2 个文件被更改,包括 16 次插入0 次删除
  1. 14 0
      lib/CCreatureSet.cpp
  2. 2 0
      lib/CCreatureSet.h

+ 14 - 0
lib/CCreatureSet.cpp

@@ -366,6 +366,14 @@ ui64 CCreatureSet::getArmyStrength() const
 	return ret;
 }
 
+ui64 CCreatureSet::getArmyCost() const
+{
+	ui64 ret = 0;
+	for (const auto& elem : stacks)
+		ret += elem.second->getCost();
+	return ret;
+}
+
 ui64 CCreatureSet::getPower(const SlotID & slot) const
 {
 	return getStack(slot).getPower();
@@ -858,6 +866,12 @@ ui64 CStackInstance::getPower() const
 	return type->getAIValue() * count;
 }
 
+ui64 CStackInstance::getCost() const
+{
+	assert(type);
+	return type->getFullRecruitCost().marketValue() * count;
+}
+
 ArtBearer::ArtBearer CStackInstance::bearerType() const
 {
 	return ArtBearer::CREATURE;

+ 2 - 0
lib/CCreatureSet.h

@@ -109,6 +109,7 @@ public:
 	FactionID getFaction() const override;
 
 	virtual ui64 getPower() const;
+	virtual ui64 getCost() const;
 	CCreature::CreatureQuantityId getQuantityID() const;
 	std::string getQuantityTXT(bool capitalized = true) const;
 	virtual int getExpRank() const;
@@ -274,6 +275,7 @@ public:
 	int stacksCount() const;
 	virtual bool needsLastStack() const; //true if last stack cannot be taken
 	ui64 getArmyStrength() const; //sum of AI values of creatures
+	ui64 getArmyCost() const; //sum of cost of creatures
 	ui64 getPower(const SlotID & slot) const; //value of specific stack
 	std::string getRoughAmount(const SlotID & slot, int mode = 0) const; //rough size of specific stack
 	std::string getArmyDescription() const;