mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	Misc improvements & tests.
This commit is contained in:
		| @@ -110,4 +110,14 @@ namespace RandomGeneratorUtil | ||||
| 		assert(!container.empty()); | ||||
| 		return std::next(container.begin(), rand.nextInt(container.size() - 1)); | ||||
| 	} | ||||
|  | ||||
| 	template<typename T> | ||||
| 	void randomShuffle(std::vector<T>& container, CRandomGenerator & rand) | ||||
| 	{ | ||||
| 		int n = (container.end() - container.begin()); | ||||
| 		for (int i = n-1; i>0; --i) | ||||
| 		{ | ||||
| 			std::swap (container.begin()[i],container.begin()[rand.nextInt(i+1)]); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|   | ||||
| @@ -234,15 +234,7 @@ void CMapGenerator::createConnections() | ||||
| 		//rearrange tiles in random order | ||||
| 		auto tilesCopy = zoneA->getTileInfo(); | ||||
| 		std::vector<int3> tiles(tilesCopy.begin(), tilesCopy.end()); | ||||
| 		//TODO: hwo to use std::shuffle with our generator? | ||||
| 		//std::random_shuffle (tiles.begin(), tiles.end(), &gen->rand.nextInt); | ||||
|  | ||||
| 		int i, n; | ||||
| 		n = (tiles.end() - tiles.begin()); | ||||
| 		for (i=n-1; i>0; --i) | ||||
| 		{ | ||||
| 			std::swap (tiles.begin()[i],tiles.begin()[rand.nextInt(i+1)]); | ||||
| 		} | ||||
| 		RandomGeneratorUtil::randomShuffle(tiles, rand); | ||||
|  | ||||
| 		int3 guardPos(-1,-1,-1); | ||||
|  | ||||
|   | ||||
| @@ -517,6 +517,11 @@ bool CRmgTemplateZone::createTreasurePile (CMapGenerator* gen, int3 &pos) | ||||
|  | ||||
| 		//now find place for next object | ||||
| 		int3 placeFound(-1,-1,-1); | ||||
|  | ||||
| 		//FIXME: find out why teh following code causes crashes | ||||
| 		//std::vector<int3> boundaryVec(boundary.begin(), boundary.end()); | ||||
| 		//RandomGeneratorUtil::randomShuffle(boundaryVec, gen->rand); | ||||
| 		//for (auto tile : boundaryVec) | ||||
| 		for (auto tile : boundary) | ||||
| 		{ | ||||
| 			if (gen->isPossible(tile)) //we can place new treasure only on possible tile | ||||
| @@ -541,7 +546,7 @@ bool CRmgTemplateZone::createTreasurePile (CMapGenerator* gen, int3 &pos) | ||||
| 	{ | ||||
| 		for (auto treasure : treasures) | ||||
| 		{ | ||||
| 			placeObject(gen, treasure.second, treasure.first); | ||||
| 			placeObject(gen, treasure.second, treasure.first - treasure.second->getVisitableOffset()); | ||||
| 		} | ||||
|  | ||||
| 		std::vector<int3> accessibleTiles; //we can't place guard in dead-end of zone, make sure that at least one neightbouring tile is possible and not blocked | ||||
| @@ -913,6 +918,8 @@ ObjectInfo CRmgTemplateZone::getRandomObject (CMapGenerator* gen, ui32 value) | ||||
| 	{ | ||||
| 		if (oi.value >= minValue && oi.value <= value) | ||||
| 		{ | ||||
| 			//TODO: check place for non-removable object | ||||
| 			//problem: we need at least template for the object that does not yet exist | ||||
| 			total += oi.probability; | ||||
| 			tresholds.push_back (std::make_pair (total, oi)); | ||||
| 		} | ||||
| @@ -1085,4 +1092,39 @@ void CRmgTemplateZone::addAllPossibleObjects (CMapGenerator* gen) | ||||
| 		oi.probability = 30; | ||||
| 		possibleObjects.push_back (oi); | ||||
| 	} | ||||
|  | ||||
| 	//non-removable object for test | ||||
| 	oi.generateObject = [gen]() -> CGObjectInstance * | ||||
| 	{ | ||||
| 		auto obj = new CGMagicWell(); | ||||
| 		obj->ID = Obj::MAGIC_WELL; | ||||
| 		obj->subID = 0; | ||||
| 		return obj; | ||||
| 	}; | ||||
| 	oi.value = 250; | ||||
| 	oi.probability = 100; | ||||
| 	possibleObjects.push_back (oi); | ||||
|  | ||||
| 	oi.generateObject = [gen]() -> CGObjectInstance * | ||||
| 	{ | ||||
| 		auto obj = new CGObelisk(); | ||||
| 		obj->ID = Obj::OBELISK; | ||||
| 		obj->subID = 0; | ||||
| 		return obj; | ||||
| 	}; | ||||
| 	oi.value = 3500; | ||||
| 	oi.probability = 200; | ||||
| 	possibleObjects.push_back (oi); | ||||
|  | ||||
| 	oi.generateObject = [gen]() -> CGObjectInstance * | ||||
| 	{ | ||||
| 		auto obj = new CBank(); | ||||
| 		obj->ID = Obj::CREATURE_BANK; | ||||
| 		obj->subID = 5; //naga bank | ||||
| 		return obj; | ||||
| 	}; | ||||
| 	oi.value = 3000; | ||||
| 	oi.probability = 100; | ||||
| 	possibleObjects.push_back (oi); | ||||
| 	 | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user