1. We have added the ability to collapse/expand forum categories and widgets on forum home.
    Dismiss Notice
  2. All Civ avatars are brought back and available for selection in the Avatar Gallery! There are 945 avatars total.
    Dismiss Notice
  3. To make the site more secure, we have installed SSL certificates and enabled HTTPS for both the main site and forums.
    Dismiss Notice
  4. Civ6 is released! Order now! (Amazon US | Amazon UK | Amazon CA | Amazon DE | Amazon FR)
    Dismiss Notice
  5. Dismiss Notice
  6. Forum account upgrades are available for ad-free browsing.
    Dismiss Notice

Prerequisite Era not based upon a tech

Discussion in 'Civ4 - SDK/Python' started by OrionVeteran, Feb 21, 2012.

  1. OrionVeteran

    OrionVeteran Chieftain

    Joined:
    Dec 25, 2003
    Messages:
    2,405
    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;
    			}
    		}
    	}
    
     
  2. Tholal

    Tholal Chieftain

    Joined:
    May 19, 2009
    Messages:
    1,662
    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.
     
  3. OrionVeteran

    OrionVeteran Chieftain

    Joined:
    Dec 25, 2003
    Messages:
    2,405
    Location:
    Newport News VA
    Thanks for the tips.
     

Share This Page