Player specific building type

How to get a player specific building type?
E.g. Temple for Endland but Burial Tomb for Egypt?
Are you asking how in lua to get which building from within the BuildingClass is correct for Egypt, England, JFD_Civ_Something_Or_Other ?

  • I wrote these a while back for my own use. I've used and confirmed the Units one works correctly but I haven't ever had occasion to check that the buildings one is structured correctly.
  • You send the player "object" data (ie, Players[0] or Players[iPlayer] etc.) and the default BuildingID# from within the class to the function for the Buildings, and it returns the correct BuildingID# for that player. Similar for the Units except that you send the player data and the default unit ID#.
  • It wouldn't be terribly hard to re-write so that regardless of which unit or building from within a class is sent to the functions they will return the correct unit or building ID# (default from within the class or unique to the player, as appropriate). (Currently as written the two functions depend on you sending the default within the class to the functions).
Code:
function GetCivSpecificUnitForDefaultUnit(pPlayer, iDefaultUnit)
	local sUnitClass = GameInfo.Units[iDefaultUnit].Class
	local sCivilizationName = GameInfo.Civilizations[pPlayer:GetCivilizationType()].Type
	for row in GameInfo.Civilization_UnitClassOverrides("CivilizationType='" .. sCivilizationName .. "'") do
		if row.UnitClassType == sUnitClass then
			if row.UnitType ~= "NULL" and row.UnitType ~= "null" and row.UnitType ~= "NONE" and row.UnitType ~= -1 and row.UnitType ~= nil then
				return GameInfoTypes[row.UnitType]
			end
		end
	end
	return iDefaultUnit
end
function GetCivSpecificBuildingForDefaultBuilding(pPlayer, iDefaultBuilding)
	local sBuildingClass = GameInfo.Buildings[iDefaultBuilding].BuildingClass
	local sCivilizationName = GameInfo.Civilizations[pPlayer:GetCivilizationType()].Type
	for row in GameInfo.Civilization_BuildingClassOverrides("CivilizationType='" .. sCivilizationName .. "'") do
		if row.BuildingClassType == sBuildingClass then
			if row.BuildingType ~= "NULL" and row.BuildingType ~= "null" and row.BuildingType ~= "NONE" and row.BuildingType ~= -1 and row.BuildingType ~= nil then
				return GameInfoTypes[row.BuildingType]
			end
		end
	end
	return iDefaultBuilding
end
 
Back
Top Bottom