Can You Add a Feature During Gameplay with Lua?

isau

Deity
Joined
Jan 15, 2007
Messages
3,071
I've been thinking about how to improve the Great Wall improvement and it seems to me an easy way to do it would be to have it behave more like a Feature than an Improvement. Features can slow units down, prevent line of fire, and so on.

I don't think it's possible for Builders to place Features (altho they can plant Forests, which are Features). My thought is I could insert a dummy Feature on the tile when a player places the Great Wall improvement. Then it would just be a matter of making sure to remove it when the player pillages or removes the tile.

Is it even possible to add Features during gameplay though? I know it can be done during map generation and using Firetuner.
 
You should still be able to use the WorldBuilder manager during the game, though I don't know what functions it has. I assume if you can add a feature at the beginning of the game you can do it mid-game using this method, though I don't know if the WorldBuilder will recognize a dummy feature you design.
 
Extracted from the map gen files shortly after the game was released
Code:
TerrainBuilder.SetTerrainType(pPlot, g_TERRAIN_TYPE_DESERT)
TerrainBuilder.SetTerrainType(plot, g_TerrainPlacement.AddType)

TerrainBuilder.GetRandomNumber(3, "Random Rainfall - Lua")
TerrainBuilder.SetFeatureType(plot, g_FEATURE_FLOODPLAINS)
TerrainBuilder.SetFeatureType(pPlot, eFeatureType);
TerrainBuilder.SetFeatureType(plot, -1)
TerrainBuilder.GetAdjacentFeatureCount(plot, g_FEATURE_MARSH)

	--unclear from context what the third boolean argument does
TerrainBuilder.CanHaveFeature(plot, g_FEATURE_FOREST)
TerrainBuilder.CanHaveFeature(pPlot, eFeatureType)
TerrainBuilder.CanHaveFeature(pWPlot, eFeatureType, true)
The SetTerrainType method worked in a GamePlay Script (I did not test the Features ones) but for terrain-changing as in Civ5 the main map did not graphically update until the save was re-loaded. May or may not have similar problems with features, or with specific features.
 
Extracted from the map gen files shortly after the game was released
Code:
TerrainBuilder.SetTerrainType(pPlot, g_TERRAIN_TYPE_DESERT)
TerrainBuilder.SetTerrainType(plot, g_TerrainPlacement.AddType)

TerrainBuilder.GetRandomNumber(3, "Random Rainfall - Lua")
TerrainBuilder.SetFeatureType(plot, g_FEATURE_FLOODPLAINS)
TerrainBuilder.SetFeatureType(pPlot, eFeatureType);
TerrainBuilder.SetFeatureType(plot, -1)
TerrainBuilder.GetAdjacentFeatureCount(plot, g_FEATURE_MARSH)

    --unclear from context what the third boolean argument does
TerrainBuilder.CanHaveFeature(plot, g_FEATURE_FOREST)
TerrainBuilder.CanHaveFeature(pPlot, eFeatureType)
TerrainBuilder.CanHaveFeature(pWPlot, eFeatureType, true)
The SetTerrainType method worked in a GamePlay Script (I did not test the Features ones) but for terrain-changing as in Civ5 the main map did not graphically update until the save was re-loaded. May or may not have similar problems with features, or with specific features.


Interesting, thanks. The good news is here we wouldn't need a graphical update. The Improvement provides the graphic, and the Feature would be an invisible object dropped underneath it that supplies characteristics similar to a Forest (slows movement and blocks line of sight). I have tried this out with dummy Improvements before, adding them to the map without a visual, and that seems to work, so maybe this will as well.

The remaining problem would be making sure to clear the Feature if the Improvement is removed (as when the city is captured). I may just make the wall tile unpillagible to avoid the headache of addding/removing it when the wall is pillaged or restored.
 
I wanted to do similar in my mod, but first I wanted to make the Great Wall act as a road. So far no luck. So if your method works, maybe you could also make that feature give road movement? I'd love you forever if I could use it =D
 
How's this project going? I never managed to get the road part working... :(
 
Top Bottom