mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	- Fixed custom main hero handling (map options)
- Refactoring
This commit is contained in:
		| @@ -174,21 +174,13 @@ void updateStartInfo(std::string filename, StartInfo & sInfo, const CMapHeader * | ||||
| 		pset.castle = pinfo.defaultCastle(); | ||||
| 		pset.hero = pinfo.defaultHero(); | ||||
|  | ||||
|  | ||||
| 		if(pinfo.customHeroID >= 0) | ||||
| 		if(pset.hero != PlayerSettings::RANDOM && pinfo.hasCustomMainHero()) | ||||
| 		{ | ||||
| 			pset.hero = pinfo.customHeroID; | ||||
|  | ||||
| 			if (!pinfo.mainHeroName.empty()) | ||||
| 				pset.heroName = pinfo.mainHeroName; | ||||
| 			else | ||||
| 				pset.heroName = CGI->heroh->heroes[pinfo.customHeroID]->name; | ||||
|  | ||||
| 			if (pinfo.mainHeroPortrait >= 0) | ||||
| 				pset.heroPortrait = pinfo.mainHeroPortrait; | ||||
| 			else | ||||
| 				pset.heroPortrait = pinfo.customHeroID; | ||||
| 			pset.hero = pinfo.mainCustomHeroId; | ||||
| 			pset.heroName = pinfo.mainCustomHeroName; | ||||
| 			pset.heroPortrait = pinfo.mainCustomHeroPortrait; | ||||
| 		} | ||||
|  | ||||
| 		pset.handicap = PlayerSettings::NO_HANDICAP; | ||||
| 	} | ||||
| } | ||||
| @@ -2299,7 +2291,7 @@ void OptionsTab::nextCastle( PlayerColor player, int dir ) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	if(s.hero >= 0 && SEL->current->mapHeader->players[s.color.getNum()].customHeroID < 0) // remove hero unless it set to fixed one in map editor | ||||
| 	if(s.hero >= 0 && !SEL->current->mapHeader->players[s.color.getNum()].hasCustomMainHero()) // remove hero unless it set to fixed one in map editor | ||||
| 		s.hero =  PlayerSettings::RANDOM; | ||||
| 	if(cur < 0  &&  s.bonus == PlayerSettings::RESOURCE) | ||||
| 		s.bonus = PlayerSettings::RANDOM; | ||||
| @@ -2938,7 +2930,7 @@ void OptionsTab::SelectedBox::clickRight( tribool down, bool previousState ) | ||||
| 		// cases when we do not need to display a message | ||||
| 		if (settings.castle == -2 && CPlayerSettingsHelper::type == TOWN ) | ||||
| 			return; | ||||
| 		if (settings.hero == -2 && SEL->current->mapHeader->players[settings.color.getNum()].customHeroID == -1 && CPlayerSettingsHelper::type == HERO) | ||||
| 		if (settings.hero == -2 && !SEL->current->mapHeader->players[settings.color.getNum()].hasCustomMainHero() && CPlayerSettingsHelper::type == HERO) | ||||
| 			return; | ||||
|  | ||||
| 		GH.pushInt(new CPregameTooltipBox(*this)); | ||||
|   | ||||
| @@ -265,7 +265,6 @@ void CConnection::prepareForSendingHeroes() | ||||
| 	savedPointers.clear(); | ||||
| 	disableSmartVectorMemberSerialization(); | ||||
| 	enableSmartPointerSerializatoin(); | ||||
| 	//disableSmartPointerSerializatoin(); | ||||
| 	disableStackSendingByID(); | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -15,8 +15,8 @@ SHeroName::SHeroName() : heroId(-1) | ||||
| } | ||||
|  | ||||
| PlayerInfo::PlayerInfo(): canHumanPlay(false), canComputerPlay(false), | ||||
| 	aiTactic(EAiTactic::RANDOM), isFactionRandom(false), mainHeroPortrait(-1), hasMainTown(false), | ||||
| 	generateHeroAtMainTown(false), team(255), generateHero(false), p7(0), hasHero(false), customHeroID(-1), powerPlaceholders(-1) | ||||
| 	aiTactic(EAiTactic::RANDOM), isFactionRandom(false), mainCustomHeroPortrait(-1), mainCustomHeroId(-1), hasMainTown(false), | ||||
| 	generateHeroAtMainTown(false), team(255), hasRandomHero(false), /* following are unused */ generateHero(false), p7(0), powerPlaceholders(-1) | ||||
| { | ||||
| 	auto allowed = VLC->townh->getDefaultAllowed(); | ||||
| 	for (size_t i=0; i<allowed.size(); i++) | ||||
| @@ -40,7 +40,7 @@ si8 PlayerInfo::defaultCastle() const | ||||
| si8 PlayerInfo::defaultHero() const | ||||
| { | ||||
| 	// we will generate hero in front of main town | ||||
| 	if((generateHeroAtMainTown && hasMainTown) || hasHero) | ||||
| 	if((generateHeroAtMainTown && hasMainTown) || hasRandomHero) | ||||
| 	{ | ||||
| 		//random hero | ||||
| 		return -1; | ||||
| @@ -54,6 +54,11 @@ bool PlayerInfo::canAnyonePlay() const | ||||
| 	return canHumanPlay || canComputerPlay; | ||||
| } | ||||
|  | ||||
| bool PlayerInfo::hasCustomMainHero() const | ||||
| { | ||||
| 	return !mainCustomHeroName.empty() && mainCustomHeroPortrait != -1; | ||||
| } | ||||
|  | ||||
| LossCondition::LossCondition() : typeOfLossCon(ELossConditionType::LOSSSTANDARD), | ||||
| 	pos(int3(-1, -1, -1)), timeLimit(-1), obj(nullptr) | ||||
| { | ||||
|   | ||||
| @@ -68,24 +68,28 @@ struct DLL_LINKAGE PlayerInfo | ||||
| 	/// Gets the default hero id or -1 for a random hero. | ||||
| 	si8 defaultHero() const; | ||||
| 	bool canAnyonePlay() const; | ||||
| 	bool hasCustomMainHero() const; | ||||
|  | ||||
| 	bool canHumanPlay; | ||||
| 	bool canComputerPlay; | ||||
| 	EAiTactic::EAiTactic aiTactic; /// The default value is EAiTactic::RANDOM. | ||||
|  | ||||
| 	std::set<TFaction> allowedFactions; | ||||
| 	bool isFactionRandom; | ||||
| 	si32 mainHeroPortrait; /// The default value is -1. | ||||
| 	std::string mainHeroName; | ||||
| 	std::vector<SHeroName> heroesNames; /// List of renamed heroes. | ||||
|  | ||||
| 	si32 mainCustomHeroPortrait; /// The default value is -1. | ||||
| 	std::string mainCustomHeroName; | ||||
| 	si32 mainCustomHeroId; /// ID of custom hero (only if portrait and hero name are set, otherwise unpredicted value), -1 if none (not always -1) | ||||
|  | ||||
| 	std::vector<SHeroName> heroesNames; /// list of placed heroes on the map | ||||
| 	bool hasMainTown; /// The default value is false. | ||||
| 	bool generateHeroAtMainTown; /// The default value is false. | ||||
| 	int3 posOfMainTown; | ||||
| 	TeamID team; /// The default value is 255 representing that the player belongs to no team. | ||||
| 	bool hasRandomHero; /// Player has a random hero | ||||
|  | ||||
| 	bool generateHero; /// Unused. | ||||
| 	si32 p7; /// Unknown and unused. | ||||
| 	bool hasHero; /// Player has a (custom?) hero | ||||
| 	si32 customHeroID; /// ID of custom hero, -1 if none | ||||
| 	/// Unused. Count of hero placeholders containing hero type. | ||||
| 	/// WARNING: powerPlaceholders sometimes gives false 0 (eg. even if there is one placeholder), maybe different meaning ??? | ||||
| 	ui8 powerPlaceholders; | ||||
| @@ -93,8 +97,8 @@ struct DLL_LINKAGE PlayerInfo | ||||
| 	template <typename Handler> | ||||
| 	void serialize(Handler & h, const int version) | ||||
| 	{ | ||||
| 		h & p7 & hasHero & customHeroID & canHumanPlay & canComputerPlay & aiTactic & allowedFactions & isFactionRandom & | ||||
| 				mainHeroPortrait & mainHeroName & heroesNames & hasMainTown & generateHeroAtMainTown & | ||||
| 		h & p7 & hasRandomHero & mainCustomHeroId & canHumanPlay & canComputerPlay & aiTactic & allowedFactions & isFactionRandom & | ||||
| 				mainCustomHeroPortrait & mainCustomHeroName & heroesNames & hasMainTown & generateHeroAtMainTown & | ||||
| 				posOfMainTown & team & generateHero; | ||||
| 	} | ||||
| }; | ||||
| @@ -374,13 +378,13 @@ public: | ||||
| 	std::vector< ConstTransitivePtr<CGHeroInstance> > allHeroes; //indexed by [hero_type_id]; on map, disposed, prisons, etc. | ||||
|  | ||||
| 	//Helper lists | ||||
| 	std::vector< ConstTransitivePtr<CGHeroInstance> > heroesOnMap; | ||||
|  | ||||
| 	/// associative list to identify which hero/creature id belongs to which object id(index for objects) | ||||
| 	std::map<si32, ObjectInstanceID> questIdentifierToId; | ||||
|  | ||||
| 	unique_ptr<CMapEditManager> editManager; | ||||
|  | ||||
| 	std::vector< ConstTransitivePtr<CGHeroInstance> > heroesOnMap; | ||||
|  | ||||
| 	/// associative list to identify which hero/creature id belongs to which object id(index for objects) | ||||
| 	std::map<si32, ObjectInstanceID> questIdentifierToId; | ||||
|  | ||||
| 	unique_ptr<CMapEditManager> editManager; | ||||
|  | ||||
| private: | ||||
| 	/// a 3-dimensional array of terrain tiles, access is as follows: x, y, level. where level=1 is underground | ||||
| 	TerrainTile*** terrain; | ||||
|   | ||||
| @@ -250,19 +250,19 @@ void CMapLoaderH3M::readPlayerInfo() | ||||
| 			mapHeader->players[i].posOfMainTown = readInt3(); | ||||
| 		} | ||||
|  | ||||
| 		mapHeader->players[i].hasHero = reader.readBool(); | ||||
| 		mapHeader->players[i].customHeroID = reader.readUInt8(); | ||||
| 		mapHeader->players[i].hasRandomHero = reader.readBool(); | ||||
| 		mapHeader->players[i].mainCustomHeroId = reader.readUInt8(); | ||||
|  | ||||
| 		if(mapHeader->players[i].customHeroID != 0xff) | ||||
| 		if(mapHeader->players[i].mainCustomHeroId != 0xff) | ||||
| 		{ | ||||
| 			mapHeader->players[i].mainHeroPortrait = reader.readUInt8(); | ||||
| 			if (mapHeader->players[i].mainHeroPortrait == 0xff) | ||||
| 				mapHeader->players[i].mainHeroPortrait = -1; //correct 1-byte -1 (0xff) into 4-byte -1 | ||||
| 			mapHeader->players[i].mainCustomHeroPortrait = reader.readUInt8(); | ||||
| 			if (mapHeader->players[i].mainCustomHeroPortrait == 0xff) | ||||
| 				mapHeader->players[i].mainCustomHeroPortrait = -1; //correct 1-byte -1 (0xff) into 4-byte -1 | ||||
|  | ||||
| 			mapHeader->players[i].mainHeroName = reader.readString(); | ||||
| 			mapHeader->players[i].mainCustomHeroName = reader.readString(); | ||||
| 		} | ||||
| 		else | ||||
| 			mapHeader->players[i].customHeroID = -1; //correct 1-byte -1 (0xff) into 4-byte -1 | ||||
| 			mapHeader->players[i].mainCustomHeroId = -1; //correct 1-byte -1 (0xff) into 4-byte -1 | ||||
|  | ||||
| 		if(mapHeader->version != EMapFormat::ROE) | ||||
| 		{ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user