Prevent an Improvement being built on a Feature?

whoshotdk

Chieftain
Joined
Aug 12, 2011
Messages
4
Hi,

Im now bungling my way through creating my first mod (primarily using XML), which is nothing more and nothing less than an additional worker action to 'Plant Forest'. I've got the action working nicely - the worker gets an additional button (looks same as 'Chop Forest' icon for now). When the action is performed a temporary Improvement with appropriate production values is created. Then with a bit of LUA script, the Improvement is replaced with a Forest Feature.

The only problem I'm having is being able to stop my new 'IMPROVEMENT_PLANT_FOREST' Improvement being built on existing Forest Feature tiles. Im not sure if I need to accomplish this via XML or LUA.

Attached is my single XML file; notice I've attempted to specifically define <Improvement_ValidFeatures> for the new Improvement, but alas, Civ 5 still gives me the equivalent of two fingers by refusing to stop me planting a forest thats already there.

Any ideas?

Thanks much
Dave

Spoiler :
Code:
<GameData>
	<Builds>
		<Row>
			<Type>BUILD_PLANT_FOREST</Type>
			<PrereqTech>TECH_MINING</PrereqTech>
			<Time>600</Time>
			<ImprovementType>IMPROVEMENT_PLANT_FOREST</ImprovementType>
			<Description>Plant a Forest</Description>
			<Help>Re-Forestation Baby</Help>
			<EntityEvent>ENTITY_EVENT_BUILD</EntityEvent>
			<OrderPriority>50</OrderPriority>
			<IconIndex>31</IconIndex>
			<IconAtlas>UNIT_ACTION_ATLAS</IconAtlas>
		</Row>
	</Builds>

	<Unit_Builds>
		<Row>
			<UnitType>UNIT_WORKER</UnitType>
			<BuildType>BUILD_PLANT_FOREST</BuildType>
		</Row>
	</Unit_Builds>

	<Improvements>
		<Row>
			<Type>IMPROVEMENT_PLANT_FOREST</Type>
			<Description>Forest</Description>
			<Civilopedia>Re-Forestation Baby</Civilopedia>
			<ArtDefineTag>ART_DEF_RESOURCE_COTTON</ArtDefineTag>
			<BuildableOnResources>true</BuildableOnResources>
			<OutsideBorders>true</OutsideBorders>
			<PortraitIndex>31</PortraitIndex>
			<IconAtlas>MISC_ATLAS_TERRAIN</IconAtlas>
		</Row>
	</Improvements>

	<Improvement_Flavors>
		<Row>
			<ImprovementType>IMPROVEMENT_PLANT_FOREST</ImprovementType>
			<FlavorType>FLAVOR_PRODUCTION</FlavorType>
			<Flavor>10</Flavor>
		</Row>
	</Improvement_Flavors>

	<Improvement_Yields>
		<Row>
			<ImprovementType>IMPROVEMENT_PLANT_FOREST</ImprovementType>
			<YieldType>YIELD_PRODUCTION</YieldType>
			<Yield>1</Yield>
		</Row>
	</Improvement_Yields>

	<Improvement_ValidTerrains>
		<Row>
			<ImprovementType>IMPROVEMENT_PLANT_FOREST</ImprovementType>
			<TerrainType>TERRAIN_GRASS</TerrainType>
		</Row>
		<Row>
			<ImprovementType>IMPROVEMENT_PLANT_FOREST</ImprovementType>
			<TerrainType>TERRAIN_PLAINS</TerrainType>
		</Row>
		<Row>
			<ImprovementType>IMPROVEMENT_PLANT_FOREST</ImprovementType>
			<TerrainType>TERRAIN_TUNDRA</TerrainType>
		</Row>
		<Row>
			<ImprovementType>IMPROVEMENT_PLANT_FOREST</ImprovementType>
			<TerrainType>TERRAIN_HILL</TerrainType>
		</Row>
	</Improvement_ValidTerrains>
	
	<Improvement_ValidFeatures>
		<Row>
			<ImprovementType>IMPROVEMENT_PLANT_FOREST</ImprovementType>
			<FeatureType>FEATURE_MARSH</FeatureType>
		</Row>
		<Row>
			<ImprovementType>IMPROVEMENT_PLANT_FOREST</ImprovementType>
			<FeatureType>FEATURE_FLOOD_PLAINS</FeatureType>
		</Row>
	</Improvement_ValidFeatures>
</GameData>
 
You can't.

Look, I do EXACTLY what you're trying to do in my own mod (in my sig). It's been working for about nine months now, and I've tried all sorts of methods to prevent what you're describing. The only way to prevent the recursive loop is to set the yields and flavors such that the AI doesn't see it as an improvement, and even there there's a chance it'll still do it anyway.

Also, be careful with the Lua event; you can't use SerialEventImprovementCreated for this. It has to be something like the end-of-turn events.
 
My modding experience is mostly Civ4, so what do I know, but why wouldn't this work?:

Code:
<BuildFeatures>
		<Row>
			<BuildType>BUILD_FOREST</BuildType>
			<FeatureType>FEATURE_FOREST</FeatureType>
			<PrereqTech>TECH_NEVER</PrereqTech>
			<Time>700</Time>
			<Remove>true</Remove>
		</Row>
...

TECH_NEVER being some disabled unresearchable tech of course. Might also work with future tech.
 
Thanks both of you.

Manic, I think that was truly an inspired idea - at least now the improvement cannot be built due to tech restriction.

Spatzimaus, first off: nice mod, based on the best Civ game there ever was. If only it was possibe to implement proper heightmaps :). As you really seem to know what youre talking about, I'd like to run an idea past you.

I havent given up hope on removal of the 'Plant Forest' button / ability when already on a forest - im thinking there may be a way to programmatically deny that ability when the worker unit it standing on terrain that contains a forest feature.

I wouldve thought its a matter of finding the correct event (unit selection change event maybe), then simply checking the unit type (is it a worker?), the plot type - terrain feature (does it exist? is it a forest?), then (somehow) adjusting the CanBuild or CanHaveImprovement members on the plot.

This is mostly guesswork based on several hours of Wiki perusal and Fire Tuner so it may all be complete b*ll*cks. Feel free to set me straight if all this is just wishful-thinking :)

Thanks
Dave

** Having thought about it, I'm guessing those 'CanBuild, 'CanHaveImprovement' members cant be changed? :(
But...maybe theres something in the UI library that can remove the actual 'Plant Forest' button. Theres no documentation for the UI library it seems though.
 
Back
Top Bottom