What can you apply strategic resources to?

AW Arcaeca

Deus Vult
Joined
Mar 10, 2013
Messages
2,984
Location
Operation Padlock ground zero
For a distant civ I've planned - which will be food-based - I've been struggling to come up with a UA and second unique. But I think I may have figured it out: A UI that gives lots more food than a regular farm (and maybe a little gold too). But to prevent it from being too much like the polder/terrace farm, and to prevent it from being overpowered, I'd like to have it require a unique Strategic Resource, 2 of which are provided by each city the civ founds.

The problem is: Is that possible? Units can require SRs, so can buildings, but what about improvements? No idea. Is there something coded in the DLL or whatnot that limits SRs to units and buildings? And if not, how would you create a resource dependency for an improvement?
 
Improvements use only:
<Improvement_ValidTerrains>
<Improvement_ValidFeatures>
<Improvement_ResourceTypes>

Meaning the only way to make an improvement "valid" is based on the terrain, features, and resources present on the tile. There is no way to directly demand a resource be present within an empire in order to build an improvement.

You could make it so the improvement is only able to be built by a unique civilian, then have that civilian require a copy of the unique resource to be built (like a swordsman with iron).

Although I've never done it, I think you could easily set him up to perform like a Great Person, so he disappears after building the improvement. If you give him a high enough cost, you could make the trade-off of producing him vs. the power of the improvement balanced.
 
Sorry to resurrect this thread (...from 4 days ago, but nonetheless), but could it potentially be done with lua?

Code:
GameEvents.PlayerDoTurn.Add(
function(playerID)
	local pPlayer = Players[playerID]
	local resource = GameInfoTypes.RESOURCE.NEW_RESOURCE
	local improvement = GameInfoTypes.IMPROVEMENT_UNIQUE_IMPROVEMENT
	if (pPlayer:IsAlive()) then
		-- Get number of strategic resources
		local res_total = pPlayer:GetNumResourceTotal(resource, 1)
		local res_used = pPlayer:GetNumResourceTotal(resource)
		local res_available = (math.floor(res_total - res_used))
		if (res_available >= 1) then
			-- ???
		end
	end
end)
Theoretically - because if history is my guide I probably made a dozen errors - the code should retrieve the number of available resources for this specific type. Maybe.

The problem is - I couldn't find any kind of Player.SetCanBuild() or whatnot function for improvements. Does anyone know of any, or perhaps a better way to do this with lua?
 
Some Improvements can only be built after researching a specific tech, you could make a dummy tech and give/remove accordingly.
I could, yeah, but the specification is more that the improvement would require a unique strategic resource. Unless I'm not really understanding what you're saying...
 
The problem is - I couldn't find any kind of Player.SetCanBuild() or whatnot function for improvements. Does anyone know of any, or perhaps a better way to do this with lua?
From this, specially mentioning the SetCanBuild thing and the code provided, it is logical to infer that you want it to be buildable when you have the Resource connected in the Empire, is that correct?

If so, you use a check to see if the Resource is present and give the Tech to the player; if he ever loses it, remove the tech.

If you were talking about only building an Improvement on a resource - which I believe is not the case - the XML has the tables for that.

If none of the above are true, I have no idea what you're asking then. :D
 
Let me see if I can figure out an ugly, ugly way to do this, since that's what I do.

I think the easiest way is the way in which you build a special unit -- let's call it a "Nutmegmancer," who requires "Nutmeg" and can be expended to build "Nutmegaries."

Otherwise, I can see it becoming a pain to manually destroy your resource as needed.

That said, you are passing your custom resource using Lua. It's not like it is every on the map. Sooooo....

1) Create a secret tech. Call the secret tech whatever your resource is called, so that if your player mouses over a disabled button, it will read "Requires Nutmeg" or something.
2) Each time a unit changes XY (this is important to prevent players from queuing up 12 Nutmegaries while the going's good, even though they only have 2 Nutmeg) do some math: 2x the number of cities, minus the number of Nutmegaries. If that is less than 1, take away the secret tech.
3) If you can/want, put the running tally of whatever the math from step 2 was up on top of the screen.
4) Every time a city is founded, run that check from step 2 again. This way you stay on top of things.

i.e., your special resource doesn't have to exist as a resource. It can just be math. You just need to pretend it exists.
(Except for if you plan to trade it with the locals. Who can't use it. Which would be sneaky and evil.)
 
Let me see if I can figure out an ugly, ugly way to do this, since that's what I do.

I think the easiest way is the way in which you build a special unit -- let's call it a "Nutmegmancer," who requires "Nutmeg" and can be expended to build "Nutmegaries."

Otherwise, I can see it becoming a pain to manually destroy your resource as needed.

That said, you are passing your custom resource using Lua. It's not like it is every on the map. Sooooo....

1) Create a secret tech. Call the secret tech whatever your resource is called, so that if your player mouses over a disabled button, it will read "Requires Nutmeg" or something.
2) Each time a unit changes XY (this is important to prevent players from queuing up 12 Nutmegaries while the going's good, even though they only have 2 Nutmeg) do some math: 2x the number of cities, minus the number of Nutmegaries. If that is less than 1, take away the secret tech.
3) If you can/want, put the running tally of whatever the math from step 2 was up on top of the screen.
4) Every time a city is founded, run that check from step 2 again. This way you stay on top of things.

i.e., your special resource doesn't have to exist as a resource. It can just be math. You just need to pretend it exists.
(Except for if you plan to trade it with the locals. Who can't use it. Which would be sneaky and evil.)
I see... The only problem I can see with this plan - actually, I guess it would be 2 problems:

1) I actually would like the number of "Nutmeg" (that's not actually what the resource is, but it's relevant enough for the discussion I guess) to display on the top of the screen, like strategic resources do, to give the false illusion of it being an actual resource, and so players can track their number of nutmeg left. If I'm not mistaken, that requires editing the already in-game TopPanel.lua file, correct? Never done that before. Do you know how to make that display up there, and only for the civ that has this "unique strategic resource"?

2) Is it possible to do this without a unique unit? Or is it not possible to do have just a normal worker build the new UI?

EDIT: So this is pretty much what I have so far:
Code:
GameEvents.PlayerDoTurn.Add(
function(playerID)
	local pPlayer = Players[playerID]
	local newTech = GameInfoTypes.TECH_NEWRESOURCE
	if (pPlayer:GetCivilizationType() == GameInfoTypes.CIVILIZATION_NEWCIV) then
		if (Teams[pPlayer:GetTeam]:IsHasTech(newTech)) then

		
			local nCities = pPlayer.GetNumCities()
			local res_basenum = (math.floor(nCities * 2))

			local improvement = GameInfoTypes.IMPROVEMENT_NEWIMPROVEMENT
			local improve_num = pPlayer:GetImprovementCount(improvement)
		
			local res_remaining = (math.floor(res_basenum - improve_num)
			
			if (res_remaining <= 0 ) then
				Teams[pPlayer:GetTeam]:SetHasTech(newTech, false)
			end

		end
	end
end)
 
alright, I've revised the code:
Code:
GameEvents.DoPlayerTurn.Add(
function(playerID)
	local pPlayer = Players[playerID]
	local pTeam = pPlayer:GetTeam()
	
	local newTech = GameInfoTypes.TECH_NEWRESOURCE
	local prereqTech = GameInfoTypes.TECH_PREREQ
	local newRes = GameInfoTypes.RESOURCE_NEWRESOURCE
	
	if (pPlayer:GetCivilizationType() == GameInfoTypes.CIVILIZATION_NEWCIV) then
		
		local res_total = pPlayer:GetNumResourceTotal(newRes, true)
		local res_used = pPlayer:GetNumResourceUsed(newRes)
		local res_remaining = (math.floor(res_total - res_used))

		local improvement = GameInfoTypes.IMPROVEMENT_NEWIMPROVEMENT

		if (res_remaining >= 1) then
			if (pTeam:IsHasTech(prereqTech) then
				
				pTeam:SetHasTech(newTech, false)
			end
		end
	end
end)

Basically, what it should do now is track the number of resources you have from the beginning. If that number dips below 1 (in other words, when you have no "Nutmeg" left), the game removes the improvement's "Nutmeg" prereq tech. Nutmeg itself has the actual prereq tech of the improvement (haven't decided yet, but just for the sake of this argument I'll say it's fertilizer) as a prereq, and is given automatically as soon as you gain Fertilizer and you have at least 1 "Nutmeg". Does that sound like it should work?

I think this should work better than the old code; the problem I forsee is that since technically the improvement's prereq is not Fertilizer, but in fact Nutmeg, it won't appear on the tech tree as an effect of researching Fertilizer.

On the plus side, as long as we don't add Nutmeg to the tech tree it won't show up.
 
It sounds like that should work. Let me know if it does :)

Also, let me know about the symbol on top of the screen. I have no idea about that, but it sounds like bane_ is on to something.

I'm curious because I'm interested in what can be done with Strategic Resources that don't really exist.
 
To show in the Top Panel, the resource must have a ResourceUsageTypes of RESOURCEUSAGE_STRATEGIC and the player must either know the tech to reveal them or have units/buildings that are using the resource
 
Top Bottom