mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	Fixed #1437.
This commit is contained in:
		| @@ -3233,10 +3233,15 @@ TSubgoal CGoal::whatToDoToAchieve() | |||||||
| 				auto creature = VLC->creh->creatures[objid]; | 				auto creature = VLC->creh->creatures[objid]; | ||||||
| 				if (t->subID == creature->faction) //TODO: how to force AI to build unupgraded creatures? :O | 				if (t->subID == creature->faction) //TODO: how to force AI to build unupgraded creatures? :O | ||||||
| 				{ | 				{ | ||||||
| 					auto creatures = t->town->creatures[creature->level]; | 					auto creatures = vstd::tryAt(t->town->creatures, creature->level - 1); | ||||||
| 					int upgradeNumber = std::find(creatures.begin(), creatures.end(), creature->idNumber) - creatures.begin(); | 					if(!creatures) | ||||||
|  | 						continue;  | ||||||
|  |  | ||||||
| 					BuildingID bid(BuildingID::DWELL_FIRST + creature->level + upgradeNumber * GameConstants::CREATURES_PER_TOWN); | 					int upgradeNumber = vstd::find_pos(*creatures, creature->idNumber); | ||||||
|  | 					if(upgradeNumber < 0) | ||||||
|  | 						continue; | ||||||
|  |  | ||||||
|  | 					BuildingID bid(BuildingID::DWELL_FIRST + creature->level - 1 + upgradeNumber * GameConstants::CREATURES_PER_TOWN); | ||||||
| 					if (t->hasBuilt(bid)) //this assumes only creatures with dwellings are assigned to faction | 					if (t->hasBuilt(bid)) //this assumes only creatures with dwellings are assigned to faction | ||||||
| 					{ | 					{ | ||||||
| 						dwellings.push_back(t); | 						dwellings.push_back(t); | ||||||
|   | |||||||
							
								
								
									
										28
									
								
								Global.h
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								Global.h
									
									
									
									
									
								
							| @@ -601,6 +601,34 @@ namespace vstd | |||||||
| 			return nullptr; | 			return nullptr; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	template <typename Container, typename Index> | ||||||
|  | 	bool isValidIndex(const Container &c, Index i) | ||||||
|  | 	{ | ||||||
|  | 		return i >= 0  &&  i < c.size(); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	template <typename Container, typename Index> | ||||||
|  | 	boost::optional<typename Container::const_reference> tryAt(const Container &c, Index i) | ||||||
|  | 	{ | ||||||
|  | 		if(isValidIndex(c, i)) | ||||||
|  | 		{ | ||||||
|  | 			auto itr = c.begin(); | ||||||
|  | 			std::advance(itr, i); | ||||||
|  | 			return *itr; | ||||||
|  | 		} | ||||||
|  | 		return boost::none; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	template <typename Container, typename Pred> | ||||||
|  | 	static boost::optional<typename Container::const_reference> tryFindIf(const Container &r, const Pred &t) | ||||||
|  | 	{ | ||||||
|  | 		auto pos = range::find_if(r, t); | ||||||
|  | 		if(pos == boost::end(r)) | ||||||
|  | 			return boost::none; | ||||||
|  | 		else | ||||||
|  | 			return *pos; | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	using boost::math::round; | 	using boost::math::round; | ||||||
| } | } | ||||||
| using vstd::operator-=; | using vstd::operator-=; | ||||||
|   | |||||||
| @@ -33,7 +33,7 @@ public: | |||||||
|  |  | ||||||
| 	CreatureID idNumber; | 	CreatureID idNumber; | ||||||
| 	TFaction faction; | 	TFaction faction; | ||||||
| 	ui8 level; // 0 - unknown | 	ui8 level; // 0 - unknown; 1-7 for "usual" creatures | ||||||
|  |  | ||||||
| 	//stats that are not handled by bonus system | 	//stats that are not handled by bonus system | ||||||
| 	ui32 fightValue, AIValue, growth, hordeGrowth; | 	ui32 fightValue, AIValue, growth, hordeGrowth; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user