mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	Move away subgoal collection logic for GetObj
This commit is contained in:
		| @@ -512,11 +512,15 @@ std::string GetObj::completeMessage() const | |||||||
| 	return "hero " + hero.get()->name + " captured Object ID = " + boost::lexical_cast<std::string>(objid); | 	return "hero " + hero.get()->name + " captured Object ID = " + boost::lexical_cast<std::string>(objid); | ||||||
| } | } | ||||||
|  |  | ||||||
| TSubgoal GetObj::whatToDoToAchieve() | TGoalVec GetObj::getAllPossibleSubgoals() | ||||||
| { | { | ||||||
|  | 	TGoalVec goalList; | ||||||
| 	const CGObjectInstance * obj = cb->getObj(ObjectInstanceID(objid)); | 	const CGObjectInstance * obj = cb->getObj(ObjectInstanceID(objid)); | ||||||
| 	if(!obj) | 	if(!obj) | ||||||
| 		return sptr(Goals::Explore()); | 	{ | ||||||
|  | 		goalList.push_back(sptr(Goals::Explore())); | ||||||
|  | 		return goalList; | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	int3 pos = obj->visitablePos(); | 	int3 pos = obj->visitablePos(); | ||||||
| 	if(hero) | 	if(hero) | ||||||
| @@ -524,31 +528,43 @@ TSubgoal GetObj::whatToDoToAchieve() | |||||||
| 		if(ai->isAccessibleForHero(pos, hero)) | 		if(ai->isAccessibleForHero(pos, hero)) | ||||||
| 		{ | 		{ | ||||||
| 			if(isSafeToVisit(hero, pos)) | 			if(isSafeToVisit(hero, pos)) | ||||||
| 				return sptr(Goals::GetObj(obj->id.getNum()).sethero(hero).setisElementar(true)); | 				goalList.push_back(sptr(Goals::GetObj(obj->id.getNum()).sethero(hero))); | ||||||
| 			else | 			else | ||||||
| 				return sptr(Goals::GatherArmy(evaluateDanger(pos, hero.h) * SAFE_ATTACK_CONSTANT).sethero(hero).setisAbstract(true)); | 				goalList.push_back(sptr(Goals::GatherArmy(evaluateDanger(pos, hero.h) * SAFE_ATTACK_CONSTANT).sethero(hero).setisAbstract(true))); | ||||||
|  |  | ||||||
|  | 			return goalList; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	else | 	else | ||||||
| 	{ | 	{ | ||||||
| 		TGoalVec goalVersionsWithAllPossibleHeroes; |  | ||||||
| 		for(auto h : cb->getHeroesInfo()) | 		for(auto h : cb->getHeroesInfo()) | ||||||
| 		{ | 		{ | ||||||
| 			if(ai->isAccessibleForHero(pos, h)) | 			if(ai->isAccessibleForHero(pos, h)) | ||||||
| 			{ | 			{ | ||||||
| 				if(isSafeToVisit(hero, pos)) | 				if(isSafeToVisit(hero, pos)) | ||||||
| 					goalVersionsWithAllPossibleHeroes.push_back(sptr(Goals::GetObj(obj->id.getNum()).sethero(h))); | 					goalList.push_back(sptr(Goals::GetObj(obj->id.getNum()).sethero(h))); | ||||||
| 				else | 				else | ||||||
| 					return sptr(Goals::GatherArmy(evaluateDanger(pos, h) * SAFE_ATTACK_CONSTANT).sethero(hero).setisAbstract(true)); | 					goalList.push_back(sptr(Goals::GatherArmy(evaluateDanger(pos, h) * SAFE_ATTACK_CONSTANT).sethero(hero).setisAbstract(true))); | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 		if(!goalVersionsWithAllPossibleHeroes.empty()) | 		if(!goalList.empty()) | ||||||
| 		{ | 		{ | ||||||
| 			auto bestCandidate = fh->chooseSolution(goalVersionsWithAllPossibleHeroes); | 			return goalList; | ||||||
| 			return bestCandidate; |  | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	return sptr(Goals::ClearWayTo(pos).sethero(hero)); |  | ||||||
|  | 	goalList.push_back(sptr(Goals::ClearWayTo(pos).sethero(hero))); | ||||||
|  | 	return goalList; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | TSubgoal GetObj::whatToDoToAchieve() | ||||||
|  | { | ||||||
|  | 	auto bestGoal = fh->chooseSolution(getAllPossibleSubgoals()); | ||||||
|  |  | ||||||
|  | 	if(bestGoal->goalType == Goals::GET_OBJ && bestGoal->hero) | ||||||
|  | 		bestGoal->setisElementar(true); | ||||||
|  |  | ||||||
|  | 	return bestGoal; | ||||||
| } | } | ||||||
|  |  | ||||||
| bool Goals::GetObj::operator==(AbstractGoal & g) | bool Goals::GetObj::operator==(AbstractGoal & g) | ||||||
|   | |||||||
| @@ -472,10 +472,7 @@ public: | |||||||
| 		objid = Objid; | 		objid = Objid; | ||||||
| 		priority = 3; | 		priority = 3; | ||||||
| 	} | 	} | ||||||
| 	TGoalVec getAllPossibleSubgoals() override | 	TGoalVec getAllPossibleSubgoals() override; | ||||||
| 	{ |  | ||||||
| 		return TGoalVec(); |  | ||||||
| 	} |  | ||||||
| 	TSubgoal whatToDoToAchieve() override; | 	TSubgoal whatToDoToAchieve() override; | ||||||
| 	bool operator==(AbstractGoal & g) override; | 	bool operator==(AbstractGoal & g) override; | ||||||
| 	bool fulfillsMe(TSubgoal goal) override; | 	bool fulfillsMe(TSubgoal goal) override; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user