mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	Remove a few more usages of thread shared ai and cb
This commit is contained in:
		| @@ -194,12 +194,6 @@ bool CDistanceSorter::operator()(const CGObjectInstance * lhs, const CGObjectIns | ||||
| 	return ln->cost < rn->cost; | ||||
| } | ||||
|  | ||||
|  | ||||
| bool compareDanger(const CGObjectInstance * lhs, const CGObjectInstance * rhs) | ||||
| { | ||||
| 	return fh->evaluateDanger(lhs) < fh->evaluateDanger(rhs); | ||||
| } | ||||
|  | ||||
| bool isSafeToVisit(HeroPtr h, crint3 tile) | ||||
| { | ||||
| 	return isSafeToVisit(h, fh->evaluateDanger(tile, h.get())); | ||||
|   | ||||
| @@ -207,11 +207,12 @@ void FuzzyHelper::setPriority(Goals::TSubgoal & g) //calls evaluate - Visitor pa | ||||
|  | ||||
| ui64 FuzzyHelper::evaluateDanger(crint3 tile, const CGHeroInstance * visitor) | ||||
| { | ||||
| 	return evaluateDanger(tile, visitor, cb.get()); | ||||
| 	return evaluateDanger(tile, visitor, ai.get()); | ||||
| } | ||||
|  | ||||
| ui64 FuzzyHelper::evaluateDanger(crint3 tile, const CGHeroInstance * visitor, const CPlayerSpecificInfoCallback * cb) | ||||
| ui64 FuzzyHelper::evaluateDanger(crint3 tile, const CGHeroInstance * visitor, const VCAI * ai) | ||||
| { | ||||
| 	auto cb = ai->myCb; | ||||
| 	const TerrainTile * t = cb->getTile(tile, false); | ||||
| 	if(!t) //we can know about guard but can't check its tile (the edge of fow) | ||||
| 		return 190000000; //MUCH | ||||
| @@ -231,7 +232,7 @@ ui64 FuzzyHelper::evaluateDanger(crint3 tile, const CGHeroInstance * visitor, co | ||||
|  | ||||
| 	if(const CGObjectInstance * dangerousObject = vstd::backOrNull(visitableObjects)) | ||||
| 	{ | ||||
| 		objectDanger = evaluateDanger(dangerousObject); //unguarded objects can also be dangerous or unhandled | ||||
| 		objectDanger = evaluateDanger(dangerousObject, ai); //unguarded objects can also be dangerous or unhandled | ||||
| 		if(objectDanger) | ||||
| 		{ | ||||
| 			//TODO: don't downcast objects AI shouldn't know about! | ||||
| @@ -251,7 +252,9 @@ ui64 FuzzyHelper::evaluateDanger(crint3 tile, const CGHeroInstance * visitor, co | ||||
| 				auto guards = cb->getGuardingCreatures(it->second->visitablePos()); | ||||
| 				for(auto cre : guards) | ||||
| 				{ | ||||
| 					vstd::amax(guardDanger, evaluateDanger(cre) * tacticalAdvantageEngine.getTacticalAdvantage(visitor, dynamic_cast<const CArmedInstance *>(cre))); | ||||
| 					float tacticalAdvantage = tacticalAdvantageEngine.getTacticalAdvantage(visitor, dynamic_cast<const CArmedInstance *>(cre)); | ||||
|  | ||||
| 					vstd::amax(guardDanger, evaluateDanger(cre, ai) * tacticalAdvantage); | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| @@ -260,15 +263,19 @@ ui64 FuzzyHelper::evaluateDanger(crint3 tile, const CGHeroInstance * visitor, co | ||||
| 	auto guards = cb->getGuardingCreatures(tile); | ||||
| 	for(auto cre : guards) | ||||
| 	{ | ||||
| 		vstd::amax(guardDanger, evaluateDanger(cre) * tacticalAdvantageEngine.getTacticalAdvantage(visitor, dynamic_cast<const CArmedInstance *>(cre))); //we are interested in strongest monster around | ||||
| 		float tacticalAdvantage = tacticalAdvantageEngine.getTacticalAdvantage(visitor, dynamic_cast<const CArmedInstance *>(cre)); | ||||
|  | ||||
| 		vstd::amax(guardDanger, evaluateDanger(cre, ai) * tacticalAdvantage); //we are interested in strongest monster around | ||||
| 	} | ||||
|  | ||||
| 	//TODO mozna odwiedzic blockvis nie ruszajac straznika | ||||
| 	return std::max(objectDanger, guardDanger); | ||||
| } | ||||
|  | ||||
| ui64 FuzzyHelper::evaluateDanger(const CGObjectInstance * obj) | ||||
| ui64 FuzzyHelper::evaluateDanger(const CGObjectInstance * obj, const VCAI * ai) | ||||
| { | ||||
| 	auto cb = ai->myCb; | ||||
|  | ||||
| 	if(obj->tempOwner < PlayerColor::PLAYER_LIMIT && cb->getPlayerRelations(obj->tempOwner, ai->playerID) != PlayerRelations::ENEMIES) //owned or allied objects don't pose any threat | ||||
| 		return 0; | ||||
|  | ||||
|   | ||||
| @@ -43,7 +43,7 @@ public: | ||||
| 	Goals::TSubgoal chooseSolution(Goals::TGoalVec vec); | ||||
| 	//std::shared_ptr<AbstractGoal> chooseSolution (std::vector<std::shared_ptr<AbstractGoal>> & vec); | ||||
|  | ||||
| 	ui64 evaluateDanger(const CGObjectInstance * obj); | ||||
| 	ui64 evaluateDanger(crint3 tile, const CGHeroInstance * visitor, const CPlayerSpecificInfoCallback * cb); | ||||
| 	ui64 evaluateDanger(const CGObjectInstance * obj, const VCAI * ai); | ||||
| 	ui64 evaluateDanger(crint3 tile, const CGHeroInstance * visitor, const VCAI * ai); | ||||
| 	ui64 evaluateDanger(crint3 tile, const CGHeroInstance * visitor); | ||||
| }; | ||||
|   | ||||
| @@ -45,7 +45,7 @@ TSubgoal VisitHero::whatToDoToAchieve() | ||||
|  | ||||
| 	if(hero && ai->isAccessibleForHero(pos, hero, true) && isSafeToVisit(hero, pos)) //enemy heroes can get reinforcements | ||||
| 	{ | ||||
| 		if(hero->pos == pos) | ||||
| 		if(hero->visitablePos() == pos) | ||||
| 			logAi->error("Hero %s tries to visit himself.", hero.name); | ||||
| 		else | ||||
| 		{ | ||||
|   | ||||
| @@ -185,10 +185,11 @@ std::vector<CGPathNode *> AINodeStorage::calculateNeighbours( | ||||
| 	return neighbours; | ||||
| } | ||||
|  | ||||
| void AINodeStorage::setHero(HeroPtr heroPtr, const CPlayerSpecificInfoCallback * _cb) | ||||
| void AINodeStorage::setHero(HeroPtr heroPtr, const VCAI * _ai) | ||||
| { | ||||
| 	hero = heroPtr.get(); | ||||
| 	cb = _cb; | ||||
| 	cb = _ai->myCb.get(); | ||||
| 	ai = _ai; | ||||
| } | ||||
|  | ||||
| std::vector<CGPathNode *> AINodeStorage::calculateTeleportations( | ||||
|   | ||||
| @@ -62,6 +62,7 @@ private: | ||||
| 	/// 1-3 - position on map, 4 - layer (air, water, land), 5 - chain (normal, battle, spellcast and combinations) | ||||
| 	boost::multi_array<AIPathNode, 5> nodes; | ||||
| 	const CPlayerSpecificInfoCallback * cb; | ||||
| 	const VCAI * ai; | ||||
| 	const CGHeroInstance * hero; | ||||
| 	std::unique_ptr<FuzzyHelper> dangerEvaluator; | ||||
|  | ||||
| @@ -106,7 +107,7 @@ public: | ||||
| 	std::vector<AIPath> getChainInfo(const int3 & pos, bool isOnLand) const; | ||||
| 	bool isTileAccessible(const int3 & pos, const EPathfindingLayer layer) const; | ||||
|  | ||||
| 	void setHero(HeroPtr heroPtr, const CPlayerSpecificInfoCallback * cb); | ||||
| 	void setHero(HeroPtr heroPtr, const VCAI * ai); | ||||
|  | ||||
| 	const CGHeroInstance * getHero() const | ||||
| 	{ | ||||
| @@ -115,7 +116,7 @@ public: | ||||
|  | ||||
| 	uint64_t evaluateDanger(const int3 &  tile) const | ||||
| 	{ | ||||
| 		return dangerEvaluator->evaluateDanger(tile, hero, cb); | ||||
| 		return dangerEvaluator->evaluateDanger(tile, hero, ai); | ||||
| 	} | ||||
|  | ||||
| private: | ||||
|   | ||||
| @@ -62,7 +62,6 @@ void AIPathfinder::updatePaths(std::vector<HeroPtr> heroes) | ||||
|  | ||||
| 	std::vector<Task> calculationTasks; | ||||
|  | ||||
| 	// TODO: go parallel? | ||||
| 	for(HeroPtr hero : heroes) | ||||
| 	{ | ||||
| 		std::shared_ptr<AINodeStorage> nodeStorage; | ||||
| @@ -78,7 +77,7 @@ void AIPathfinder::updatePaths(std::vector<HeroPtr> heroes) | ||||
| 		} | ||||
|  | ||||
| 		storageMap[hero] = nodeStorage; | ||||
| 		nodeStorage->setHero(hero, cb); | ||||
| 		nodeStorage->setHero(hero, ai); | ||||
|  | ||||
| 		auto config = std::make_shared<AIPathfinding::AIPathfinderConfig>(cb, ai, nodeStorage); | ||||
|  | ||||
| @@ -121,7 +120,7 @@ void AIPathfinder::updatePaths(const HeroPtr & hero) | ||||
| 		} | ||||
|  | ||||
| 		storageMap[hero] = nodeStorage; | ||||
| 		nodeStorage->setHero(hero, cb); | ||||
| 		nodeStorage->setHero(hero, ai); | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user