Requirement for available resources?

sp00n

Prince
Joined
Jan 4, 2007
Messages
371
Is there any requirement that checks if a resource is available?

REQUIREMENT_PLAYER_HAS_RESOURCE_OWNED seems to only trigger if the resource is actually physically present within your empire (and improved), but does not include imported resources via trade deals, and probably also not resources gained via suzerainty of a city state (untested, but these resources show up as imported when querying the Lua API, so they're probably affected as well).

GameEffects.xml didn't point to anything obvious, am I out of luck here?
 
I am not sure this helps you, but I ran a database query on the Requirements table for all instances where RequirementType contained the word "Resource." None of these look like a good match to me, so we may be out of luck. Most of these seem to check on the plot level rather than the player level.

  • REQUIREMENT_PLOT_RESOURCE_CLASS_TYPE_MATCHES
  • REQUIREMENT_PLOT_RESOURCE_VISIBLE
  • REQUIREMENT_PLOT_RESOURCE_TAG_MATCHES
  • REQUIREMENT_PLOT_RESOURCE_TYPE_MATCHES
  • REQUIREMENT_PLOT_ADJACENT_RESOURCE_CLASS_TYPE_MATCHES
  • REQUIREMENT_PLAYER_HAS_RESOURCE_OWNED
  • REQUIREMENT_PLAYER_HAS_RESOURCE_VISIBILITY


I did a query of the requirement you used, REQUIREMENT_PLAYER_HAS_RESOURCE_OWNED. Interestingly, every use of REQUIREMENT_PLAYER_HAS_RESOURCE_OWNED in the game actually uses the Inverse of the condition. It seems it is mainly used in checks to see if the player is lacking access to a certain resource so the game can award some free (I believe there is a social policy that does this, and also a city state).

upload_2017-1-2_10-28-42.png


I was hoping there would be an entry in the RequirementArguments table that toggled whether to check all sources of the resources versus owning it literally from the map, but there is nothing.


As a last ditch effort, here's a list of every RequirementType used in the Requirements table. I didn't look through it to see if maybe one of these does what you need.

REQUIREMENT_ALLY
REQUIREMENT_ATTACKER_PLOT_HAS_ANY_DISTRICT
REQUIREMENT_ATTACKER_PLOT_IMPROVEMENT_TYPE_MATCHES
REQUIREMENT_CITY_CONVERTED
REQUIREMENT_CITY_FOLLOWS_PANTHEON
REQUIREMENT_CITY_FOLLOWS_RELIGION
REQUIREMENT_CITY_HAS_BUILDING
REQUIREMENT_CITY_HAS_DISTRICT
REQUIREMENT_CITY_HAS_GARRISON_UNIT
REQUIREMENT_CITY_HAS_NATIONAL_PARK
REQUIREMENT_CITY_HAS_X_SPECIALTY_DISTRICTS
REQUIREMENT_CITY_IS_OWNER_CAPITAL_CONTINENT
REQUIREMENT_CITY_LIBERATED
REQUIREMENT_CITY_OCCUPIED
REQUIREMENT_CITY_OCCUPIED_FRIEND
REQUIREMENT_CITY_RAZED
REQUIREMENT_CIVILIZATION_LEVEL
REQUIREMENT_COLLECTION_ALL_MET
REQUIREMENT_COLLECTION_COUNT_EQUALS
REQUIREMENT_COMBAT_TYPE_MATCHES
REQUIREMENT_CULTURE_BOMBED
REQUIREMENT_DECLARED_FRIEND
REQUIREMENT_DEFENSIVE_PACT
REQUIREMENT_DELEGATION
REQUIREMENT_DEMAND_RECEIVED
REQUIREMENT_DENOUNCED
REQUIREMENT_DENOUNCED_FRIEND
REQUIREMENT_DISTRICT_TYPE_MATCHES
REQUIREMENT_ESPIONAGE_DETECTED
REQUIREMENT_FOUNDED_NO_RELIGION
REQUIREMENT_GAME_TURN_MAX_REACHED
REQUIREMENT_GAME_VICTORY_ENABLED
REQUIREMENT_HAD_FRIENDLY_MEETING
REQUIREMENT_NEAR_CULTURE_BORDER
REQUIREMENT_NEAR_RELIGIOUS_CITY
REQUIREMENT_NEVER_MET
REQUIREMENT_OPEN_BORDERS
REQUIREMENT_OPPONENT_IS_BARBARIAN
REQUIREMENT_OPPONENT_IS_DISTRICT
REQUIREMENT_OPPONENT_IS_FORTIFIED
REQUIREMENT_OPPONENT_IS_MINOR_CIV
REQUIREMENT_OPPONENT_IS_OTHER_RELIGION
REQUIREMENT_OPPONENT_IS_WOUNDED
REQUIREMENT_OPPONENT_UNIT_DOMAIN_MATCHES
REQUIREMENT_OPPONENT_UNIT_PROMOTION_CLASS_MATCHES
REQUIREMENT_OPPONENT_UNIT_TAG_MATCHES
REQUIREMENT_PLAYER_ATTACKED_CONTINENT
REQUIREMENT_PLAYER_AT_WAR_AND_HAS_MET
REQUIREMENT_PLAYER_BUILT_WONDER
REQUIREMENT_PLAYER_CAN_EVER_EARN_GREAT_PERSON_CLASS
REQUIREMENT_PLAYER_CITY_STATE_PROTECTOR
REQUIREMENT_PLAYER_CIVILIZED
REQUIREMENT_PLAYER_COMPETING_MINORS
REQUIREMENT_PLAYER_CONQUERING_ALLYING_MINORS
REQUIREMENT_PLAYER_DEAL_ENACTED
REQUIREMENT_PLAYER_DECLARED_WAR
REQUIREMENT_PLAYER_DEFAULT_DEFEAT
REQUIREMENT_PLAYER_DOMINATION_VICTORY
REQUIREMENT_PLAYER_EXPLORATION_LEAD
REQUIREMENT_PLAYER_FINISHED_RESEARCH
REQUIREMENT_PLAYER_FOUNDED_OUR_RELIGION
REQUIREMENT_PLAYER_FOUNDED_RELIGION_WITH_BELIEF
REQUIREMENT_PLAYER_GOT_GREAT_PERSON
REQUIREMENT_PLAYER_HANDICAP_AT_OR_ABOVE
REQUIREMENT_PLAYER_HAPPINESS_LEAD
REQUIREMENT_PLAYER_HAS_AT_LEAST_NUM_MILITARY_UNITS
REQUIREMENT_PLAYER_HAS_COMPLETED_PROJECT
REQUIREMENT_PLAYER_HAS_DESIRED_LUXURY
REQUIREMENT_PLAYER_HAS_GIVEN_INFLUENCE_TOKENS
REQUIREMENT_PLAYER_HAS_HIGHEST_SCORE
REQUIREMENT_PLAYER_HAS_MET
REQUIREMENT_PLAYER_HAS_PANTHEON
REQUIREMENT_PLAYER_HAS_RESOURCE_OWNED
REQUIREMENT_PLAYER_HAS_RESOURCE_VISIBILITY
REQUIREMENT_PLAYER_HAS_SAME_GOVERNMENT
REQUIREMENT_PLAYER_HAS_TECHNOLOGY
REQUIREMENT_PLAYER_INCOME_LEAD
REQUIREMENT_PLAYER_IS_ATTACKING
REQUIREMENT_PLAYER_IS_AT_PEACE
REQUIREMENT_PLAYER_IS_AT_PEACE_WITH_ALL_MAJORS
REQUIREMENT_PLAYER_IS_HUMAN
REQUIREMENT_PLAYER_IS_MINOR
REQUIREMENT_PLAYER_IS_RELIGION_FOUNDER
REQUIREMENT_PLAYER_IS_SAME_RELIGION
REQUIREMENT_PLAYER_IS_SUZERAIN
REQUIREMENT_PLAYER_MAJORITY_RELIGION_IS_OWNER
REQUIREMENT_PLAYER_MET_X_TURNS_AGO
REQUIREMENT_PLAYER_MILITARY_STRENGTH_LEAD
REQUIREMENT_PLAYER_NOT_COMPETING_MINORS
REQUIREMENT_PLAYER_NOT_INVOLVED_MINORS
REQUIREMENT_PLAYER_NUKE_LOVER
REQUIREMENT_PLAYER_ON_NON_HOME_CONTINENT
REQUIREMENT_PLAYER_OWNS_OBJECT
REQUIREMENT_PLAYER_PEACEFUL_ON_CONTINENT
REQUIREMENT_PLAYER_POPULATION_LEAD
REQUIREMENT_PLAYER_RELIGION_NOT_RECEIVED
REQUIREMENT_PLAYER_RELIGION_RECEIVED
REQUIREMENT_PLAYER_SHARES_HOME_CONTINENT
REQUIREMENT_PLAYER_TURN_STARTED
REQUIREMENT_PLAYER_WITH_SHIELD_OR_ON_IT
REQUIREMENT_PLAYER_YIELD_LEAD
REQUIREMENT_PLOT_ADJACENT_DISTRICT_TYPE_MATCHES
REQUIREMENT_PLOT_ADJACENT_FEATURE_TYPE_MATCHES
REQUIREMENT_PLOT_ADJACENT_FRIENDLY_UNIT_TAG_MATCHES
REQUIREMENT_PLOT_ADJACENT_FRIENDLY_UNIT_TYPE_MATCHES
REQUIREMENT_PLOT_ADJACENT_IMPROVEMENT_TYPE_MATCHES
REQUIREMENT_PLOT_ADJACENT_RESOURCE_CLASS_TYPE_MATCHES
REQUIREMENT_PLOT_ADJACENT_TO_COAST
REQUIREMENT_PLOT_ADJACENT_TO_OWNER
REQUIREMENT_PLOT_ADJACENT_TO_OWNER_AT_WAR
REQUIREMENT_PLOT_ADJACENT_TO_RIVER
REQUIREMENT_PLOT_ADJACENT_TO_WONDER
REQUIREMENT_PLOT_DISTRICT_IS_DEFENDED
REQUIREMENT_PLOT_DISTRICT_TYPE_MATCHES
REQUIREMENT_PLOT_FEATURE_TYPE_MATCHES
REQUIREMENT_PLOT_HAS_ANY_DISTRICT
REQUIREMENT_PLOT_IMPROVEMENT_TYPE_MATCHES
REQUIREMENT_PLOT_IS_COAST
REQUIREMENT_PLOT_IS_HILLS
REQUIREMENT_PLOT_IS_LAKE
REQUIREMENT_PLOT_IS_OWNER_CAPITAL_CONTINENT
REQUIREMENT_PLOT_RESOURCE_CLASS_TYPE_MATCHES
REQUIREMENT_PLOT_RESOURCE_TAG_MATCHES
REQUIREMENT_PLOT_RESOURCE_TYPE_MATCHES
REQUIREMENT_PLOT_RESOURCE_VISIBLE
REQUIREMENT_PLOT_TERRAIN_TYPE_MATCHES
REQUIREMENT_PLOT_UNIT_TYPE_MATCHES
REQUIREMENT_REQUIREMENTSET_IS_MET
REQUIREMENT_RESIDENT_EMBASSY
REQUIREMENT_TOURISTS_EXCEED_STAYCATIONERS
REQUIREMENT_UNIT_ADJACENT_TO_OWNER_TERRITORY
REQUIREMENT_UNIT_DAMAGE_MINIMUM
REQUIREMENT_UNIT_DOMAIN_MATCHES
REQUIREMENT_UNIT_ERA_TYPE_MATCHES
REQUIREMENT_UNIT_IN_ENEMY_TERRITORY
REQUIREMENT_UNIT_IN_FORMATION
REQUIREMENT_UNIT_IN_OWNER_TERRITORY
REQUIREMENT_UNIT_IS_BARBARIAN
REQUIREMENT_UNIT_ON_COAST
REQUIREMENT_UNIT_ON_HOME_CONTINENT
REQUIREMENT_UNIT_PROMOTION_CLASS_MATCHES
REQUIREMENT_UNIT_TAG_MATCHES
REQUIREMENT_UNIT_TYPE_MATCHES

There may be some other way to check for a resource I haven't thought about yet. If anything hits me I'll share it with you.
 
Last edited:
Yeah I've checked for every type of requirement which contains RESOURCE as well, but they all seem to be dealing with other stuff. The _VISIBILITY one seems to take care of if you are actually allowed to see the resource icon yet (i.e. niter, oil, aluminium, uranium, etc) - they're already present on the map right from the beginning, just hidden. I also tried to invert the requirement condition, with a futile hope that this would somehow magically make it work... and of course it doesn't.

I've thought about adding event listeners to trade deals that check for newly imported strategic resources, and then somehow modify a tile somwhere in your territory with a hidden type of this resource (under a city center?) to make that requirement trigger, but I think this would get very messy very quickly. If it's even possible at all, I have no idea if you can modify the map right now via Lua.
 
Is there any requirement that checks if a resource is available?

REQUIREMENT_PLAYER_HAS_RESOURCE_OWNED seems to only trigger if the resource is actually physically present within your empire (and improved), but does not include imported resources via trade deals, and probably also not resources gained via suzerainty of a city state (untested, but these resources show up as imported when querying the Lua API, so they're probably affected as well).

GameEffects.xml didn't point to anything obvious, am I out of luck here?

I have been unable to find a pure XML solution to this so I had to resort to lua.

I wanted to determine when the player had gained access to all the luxury resources that spawned on the map (not great people or special city state resources), from improving the resource in their borders, or through trade or from being suzerain of a city state. An added complication I encountered was the luxury resources can change from map to map.

I have posted the code I am currently using in my victories mod that compiles a list of luxury resources that spawned on the map which I can then check using Player.GetResources():HasResource(Resource.Index) in the event you decide to use lua.

Code:
local m_MapLuxuryResources:table = {};
local m_MapLuxuryResourcesCount:number = 0;

function LoadMapLuxuryResourceData()

   if (m_MapLuxuryResourcesCount == 0) then
       local mapX, mapY = Map.GetGridSize();
      
       -- loop through the columns on the map grid
       for x = 0, mapX - 1 do
           -- now loop through the rows for each column on the map grid
           for y = 0, mapY - 1 do
               local plot:table = Map.GetPlot(x, y); -- get the plot at the x and y position
               local resource:table = GetLuxuryResourceAtPlot(plot); -- get luxury resource if one exists at plot
              
               if (resource ~= nil) then              
                   if (resource.Name ~= nil and not IsResourceInLuxuryResourcesTable(resource.Name)) then
                       -- resource does not exist in table of map resources, add it and increase the counter
                       table.insert(m_MapLuxuryResources, resource);
                       m_MapLuxuryResourcesCount = m_MapLuxuryResourcesCount + 1;
                  
                       print("LoadMapLuxuryResourceData: resource ", resource.Name);                  
                       print("LoadMapLuxuryResourceData: new resource added to m_MapLuxuryResources collection");
                       print("LoadMapLuxuryResourceData: new resources found = ", m_MapLuxuryResourcesCount);
                   end
               end
           end
       end
   end

end

function GetLuxuryResourceAtPlot(plot:table)

   local luxuryResource:table = {};

   if (plot ~= nil and plot:GetResourceCount() > 0) then
       local resourceType:number = plot:GetResourceType();
      
       if (resourceType ~= -1) then
           local resource = GameInfo.Resources[resourceType];
          
           if (resource ~= nil and resource.ResourceClassType == "RESOURCECLASS_LUXURY") then
               luxuryResource = resource;
           end
       end
   end
  
   return luxuryResource;
end

function IsResourceInLuxuryResourcesTable(resourceName:string)

   local result:boolean = false;

   if (m_MapLuxuryResources ~= nil) then
       for r, resource in ipairs(m_MapLuxuryResources) do
           if (resource.Name == resourceName) then
               result = true; -- resource already exists in table
               break;
           end
       end
   end
  
   return result;
end

I call this from the Initialise() method of the UI lua file I want to check for resources in. As you can see I was only interested in luxury resources, but it should be simple enough to change to include strategic or bonus resources too.

Once you have your m_MapLuxuryResources table populated then it is a simple matter to check what resources are available in it.

The only resources this will not pick up are the custom resources from great people or the special resources from that 1 city state that provides them (Cinnamon and Cloves I think).

Hope this is of some help.
 
Well, I already have a getImportedResources() function in my Resource Tooltip mod, so retrieving a list of the imported resources wouldn't be the problem. The connection between the lua code and the requirement modifier to trigger would be the complicated issue. I'd need to research if it's possible to add resources to the map programatically, and if it is, link them to the trade deals and keep track of them in case the tile owner changes or the trade deal runs out, etc. Not sure that's worth the effort to be honest.
sleepy.gif
 
Well, I already have a getImportedResources() function in my Resource Tooltip mod, so retrieving a list of the imported resources wouldn't be the problem. The connection between the lua code and the requirement modifier to trigger would be the complicated issue. I'd need to research if it's possible to add resources to the map programatically, and if it is, link them to the trade deals and keep track of them in case the tile owner changes or the trade deal runs out, etc. Not sure that's worth the effort to be honest.
sleepy.gif

Hopefully the SDK (with some helpful documentation) will have some functionality to allow us to create new requirement modifiers and a way of tying them into game code.
 
Back
Top Bottom