Prerequisite Era not based upon a tech

OrionVeteran

Deity
Joined
Dec 25, 2003
Messages
2,443
Location
Newport News VA
I have 7 special buildings (National Wonders), all with different names that coincide with an era. I want to be able to build one of these buildings in each era. I do not want to give any of the the wonders a prerequisite tech. For example, any Tech in the Medieval era meets the prerequisite to build the Medieval version of this building. In SDK, how can I parse the name of a building to get an era? Once I have the building era, I can then compare it to the Player's current era to confirm "canBuild" elligibility. Here is what I have so far. I'd like to make it more efficient.

Spoiler :

Code:
	if (eBuilding == GC.getInfoTypeForString("BUILDING_ANCIENT_MYSTERIES"))
	{
		if ((EraTypes) GET_PLAYER(getOwnerINLINE()).getCurrentEra() != GC.getInfoTypeForString("ERA_ANCIENT"))
		{
			return false;
		}
		else
		{
			if (getNumRealBuilding(eBuilding) > 0)
			{
				return false;
			}
		}
	}
		
	if (eBuilding == GC.getInfoTypeForString("BUILDING_CLASSICAL_MYSTERIES"))
	{
		if ((EraTypes) GET_PLAYER(getOwnerINLINE()).getCurrentEra() != GC.getInfoTypeForString("ERA_CLASSICAL"))
		{
			return false;
		}
		else
		{
			if (getNumRealBuilding(eBuilding) > 0)
			{
				return false;
			}
		}
	}
		
	if (eBuilding == GC.getInfoTypeForString("BUILDING_MEDIEVAL_MYSTERIES"))
	{
		if ((EraTypes) GET_PLAYER(getOwnerINLINE()).getCurrentEra() != GC.getInfoTypeForString("ERA_MEDIEVAL"))
		{
			return false;
		}
		else
		{
			if (getNumRealBuilding(eBuilding) > 0)
			{
				return false;
			}
		}
	}
		
	if (eBuilding == GC.getInfoTypeForString("BUILDING_RENAISSANCE_MYSTERIES"))
	{
		if ((EraTypes) GET_PLAYER(getOwnerINLINE()).getCurrentEra() != GC.getInfoTypeForString("ERA_RENAISSANCE"))
		{
			return false;
		}
		else
		{
			if (getNumRealBuilding(eBuilding) > 0)
			{
				return false;
			}
		}
	}
		
	if (eBuilding == GC.getInfoTypeForString("BUILDING_INDUSTRIAL_MYSTERIES"))
	{
		if ((EraTypes) GET_PLAYER(getOwnerINLINE()).getCurrentEra() != GC.getInfoTypeForString("ERA_INDUSTRIAL"))
		{
			return false;
		}
		else
		{
			if (getNumRealBuilding(eBuilding) > 0)
			{
				return false;
			}
		}
	}
		
	if (eBuilding == GC.getInfoTypeForString("BUILDING_MODERN_MYSTERIES"))
	{
		if ((EraTypes) GET_PLAYER(getOwnerINLINE()).getCurrentEra() != GC.getInfoTypeForString("ERA_MODERN"))
		{
			return false;
		}
		else
		{
			if (getNumRealBuilding(eBuilding) > 0)
			{
				return false;
			}
		}
	}
		
	if (eBuilding == GC.getInfoTypeForString("BUILDING_FUTURE_MYSTERIES"))
	{
		if ((EraTypes) GET_PLAYER(getOwnerINLINE()).getCurrentEra() != GC.getInfoTypeForString("ERA_FUTURE"))
		{
			return false;
		}
		else
		{
			if (getNumRealBuilding(eBuilding) > 0)
			{
				return false;
			}
		}
	}
 
Unless you want to add in an XML tag that assigns a specific era to buildings, that's pretty much the way to do it.

You can get rid of all those getNumRealBuilding checks, though. That should already be handled if you have the buildings defined as National Wonders.

You could also replace those multiple calls to getCurrentEra with a variable instead.

Code:
EraTypes eCurrentEra = GET_PLAYER(getOwnerINLINE()).getCurrentEra();

and then use that variable for the comparison test. It wont make things any faster but it will make the code a bit cleaner and easier to read.
 
Unless you want to add in an XML tag that assigns a specific era to buildings, that's pretty much the way to do it.

You can get rid of all those getNumRealBuilding checks, though. That should already be handled if you have the buildings defined as National Wonders.

You could also replace those multiple calls to getCurrentEra with a variable instead.

Code:
EraTypes eCurrentEra = GET_PLAYER(getOwnerINLINE()).getCurrentEra();

and then use that variable for the comparison test. It wont make things any faster but it will make the code a bit cleaner and easier to read.

Thanks for the tips.
 
Top Bottom