Where are the .lua strategic and luxury resource files located?

KennyTG

Chieftain
Joined
May 26, 2014
Messages
45
Hi,
I'm working on a mod that would allow players to plant a luxury or strategic (only ones like wheat or deer) once they have access to that resource. Bear in mind that I have a c/c++ and javascript background, but I'm thinking that I could create new improvements in xml that would mock the behavior of these luxury and strategic resources and then add an event in lua that would unlock these improvements once a player has built an improvements on one of these resources. Can I do something like this? Would there be a way to avoid the xml mock improvements? Where are these resources defined in the games lua files?

Thanks.
 
Most of the game is written in C++; there isn't any Lua for what you're talking about. However, there are Lua methods for the kinds of things you'd like to accomplish.

I'd imagine you'd still want to add fake improvements to the database, then use Lua to swap out the improvement for the resource. You'd determine when the improvement was completed by using the hook Events.SerialEventImprovementCreated, then remove the improvement with Plot.SetImprovementType and replace it using Plot.SetResourceType.

You'd need to hook GameEvents.TeamSetHasTech and apply Player.CanBuild to allow your workers to build the improvement when reaching the appropriate technology.

EDIT: Note your players would potentially destroy resources that they cannot actually see yet.
 
Thanks Nutty,
I've done some coding and everything seems to work up until the point where the improvement isn't being removed... What value do I need to put in pPlot:SetImprovementType() to remove the improvement?

I've tried nil, 0, -1, different improvement types, and none of these seem to work...

Thanks.
 
Ok. I think I see where I went wrong. I use an if statement to check if the improvement that was built is the dummy improvement. Currently I am using pPlot:GetImprovementType() . What exactly is the value it returns? I'm pretty sure that I'm comparing incompatible types (right now I'm comparing the variable I assign it to to GameInfo.Improvements.IMPROVEMENT_INSERTNAME) .
 
You should compare to GameInfoTypes.IMPROVEMENT_INSERTNAME (or, if you want a more complicated version, to GameInfo.Improvements.IMPROVEMENT_INSERTNAME.ID)
 
Ok. This is entirely out of curiosity, but can I hook a single function to multiple game events?
 
Ok, everything is working except the game lets me place my improvements on top of features if I set the underlying terrain as a valid terrain type. How do I require the building of these improvements to clear a feature such as a forest, jungle, or marsh(this would be in xml)?
 
You can use the BuildFeatures table for this. This is the code the game uses for the farm, you can add something similar for your improvement.
Code:
	<BuildFeatures>
		<Row>
			<BuildType>BUILD_FARM</BuildType>
			<FeatureType>FEATURE_JUNGLE</FeatureType>
			<PrereqTech>TECH_BRONZE_WORKING</PrereqTech>
			<Time>700</Time>
			<Remove>true</Remove>
		</Row>
		<Row>
			<BuildType>BUILD_FARM</BuildType>
			<FeatureType>FEATURE_FOREST</FeatureType>
			<PrereqTech>TECH_MINING</PrereqTech>
			<Time>400</Time>
			<Production>20</Production>
			<Remove>true</Remove>
		</Row>
		<Row>
			<BuildType>BUILD_FARM</BuildType>
			<FeatureType>FEATURE_MARSH</FeatureType>
			<PrereqTech>TECH_MASONRY</PrereqTech>
			<Time>600</Time>
			<Remove>true</Remove>
		</Row>
	</BuildFeatures>
 
Top Bottom