Sfoglia il codice sorgente

Fixed desync due to uninitialized objects. Added some logging. RMG maps don't work yet, though.

DjWarmonger 11 anni fa
parent
commit
fe292dfa1d

+ 4 - 0
lib/CGameState.cpp

@@ -1849,7 +1849,10 @@ void CGameState::initMapObjects()
 	for(CGObjectInstance *obj : map->objects)
 	{
 		if(obj)
+		{
+			logGlobal->traceStream() << boost::format ("Calling Init for object %d, %d") % obj->ID % obj->subID;
 			obj->initObj();
+		}
 	}
 	for(CGObjectInstance *obj : map->objects)
 	{
@@ -3518,5 +3521,6 @@ CPathfinder::CPathfinder(CPathsInfo &_out, CGameState *_gs, const CGHeroInstance
 
 CRandomGenerator & CGameState::getRandomGenerator()
 {
+	logGlobal->traceStream() << "Fetching CGameState::rand with seed " << rand.nextInt();
 	return rand;
 }

+ 3 - 0
lib/mapObjects/CommonConstructors.cpp

@@ -271,6 +271,8 @@ BankConfig CBankInstanceConstructor::generateConfig(const JsonNode & level, CRan
 
 void CBankInstanceConstructor::configureObject(CGObjectInstance * object, CRandomGenerator & rng) const
 {
+	//logGlobal->debugStream() << "Seed used to configure bank is " << rng.nextInt();
+
 	auto bank = dynamic_cast<CBank*>(object);
 
 	bank->resetDuration = bankResetDuration;
@@ -282,6 +284,7 @@ void CBankInstanceConstructor::configureObject(CGObjectInstance * object, CRando
 	assert(totalChance != 0);
 
 	si32 selectedChance = rng.nextInt(totalChance - 1);
+	//logGlobal->debugStream() << "Selected chance for bank config is " << selectedChance;
 
 	for (auto & node : levels)
 	{

+ 5 - 0
lib/mapObjects/MiscObjects.cpp

@@ -632,6 +632,11 @@ std::string CGResource::getHoverText(PlayerColor player) const
 	return VLC->generaltexth->restypes[subID];
 }
 
+CGResource::CGResource()
+{
+	amount = 0;
+}
+
 void CGResource::initObj()
 {
 	blockVisit = true;

+ 1 - 0
lib/mapObjects/MiscObjects.h

@@ -182,6 +182,7 @@ public:
 	ui32 amount; //0 if random
 	std::string message;
 
+	CGResource();
 	void onHeroVisit(const CGHeroInstance * h) const override;
 	void initObj() override;
 	void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override;

+ 1 - 0
lib/rmg/CRmgTemplateZone.cpp

@@ -620,6 +620,7 @@ bool CRmgTemplateZone::addMonster(CMapGenerator* gen, int3 &pos, si32 strength,
 	auto guard = new CGCreature();
 	guard->ID = Obj::MONSTER;
 	guard->subID = creId;
+	guard->character = 1; //MUST be initialized or switch will diverge
 	auto  hlp = new CStackInstance(creId, amount);
 	//will be set during initialization
 	guard->putStack(SlotID(0), hlp);