[lua] TerrainBuilder.SetTerrainType() map actualisation problem

__jack__

Warlord
Joined
Dec 29, 2009
Messages
141
Hi,

I am running a script during OnGameTurnStarted() using TerrainBuilder.SetTerrainType() to change some of the terrain around the player.

The script change the terrain without any problem e.g. Grasslands becoming Plains except the 3D graphics are not updated (they are updated in the Strategic View).

Any function I should call to refresh the display ?

Thanks.
D.
 
saving/reloading to update the 3D display.

but is your script running in gameplay or UI context ?

I've not tried, maybe a script running in gameplay context as soon as it loads may be able to update the map before the graphic engine generate the 3D display.

OnGameTurnStarted() is called after and the change will only be visible in UI tooltips and the 2D display (A.K.A. Strategic View)

also note that after changing land from/to water you'll have to call TerrainBuilder.AnalyzeChokepoints() to prevent crashes.
 
I don't want to need a reload since it is meant to be used in MP.

It is run in a Gameplay context to rebalance the starting location but I don't want to alter AssignStartingPlot() (since I would lack the civ type information and I would need to retool it every Firaxis update)
I need to be able to run it when the units are placed to I can identify the spawn location. What are the steps before OnGameTurnStarted() I could use, but after the map and the spawn point have been allocated ?

Thanks for the tip on TerrainBuilder.AnalyzeChokepoints(); I thought AreaBuilder.Recalculate() would work but nothing.
 
just call your function at the last line of your gameplay script so it runs ASAP.

Those scripts are loaded after the map generation (including starting locations)

At this point the units are already placed IIRC, and you could use player:GetStartingPlot() anyway

But as I said I've not tested it, it may be already to late for the 3D engine, let me know, I'm curious.
 
Hum so you dump the code in initialise directly instead of OnGameTurnStarted() ok I will give it a try
 
As long as your lua gameplay script executes the Terrain alterations before LoadScreenClose (ie, as the game is loading and not triggered by a hook event) then the 3d graphics will be updated to reflect the changes in terrain. I have not however attempted this when starting a new game, but only when reloading a saved game.

From what you've reported it will also work on starting a new game as long as the code executes before LoadScreenClose ?

As you've discovered, any alterations made from an lua script after LoadScreenClose are never updated to the graphics on the normal main map view until after a save and reload. The same behavior applied in Civ5, and has to do with the way the graphics engine works.
 
Back
Top Bottom