[Lua] Are methods executive?

Irkalla

ENTP POWWWEEEEEER
Joined
Sep 25, 2012
Messages
1,009
Location
Way down around Vicksburg
For example, I'm trying to change a tile's movement cost by hooking into Plot.MovementCost and returning what I want the movement cost to be.

In this case, I'm asking the method to return 0.334 if Machinery is researched (0.334 supports units with up to 50 something moves before it starts short-changing them) and 0.501 otherwise (0.5 is a repeating decimal that gets rounded down in binary, should support units with up to 250 moves.)

I'm also returning true for Plot.IsTradeRoute() to try and make certain tiles for a trade route.

Will either of these affect gameplay, or will they just affect UI stuff that relies on that?

On a side note, I'm worried about float precision and it giving units extra moves either because of binary repeating decimals, or because they have an infinitesimal amount of moves left (such as 0.000000000000000000000000001.) Anything to ease my worries?
 
Movement costs aren't really floating point. The movement system uses the MOVE_DENOMINATOR define (60), so, for example, a 1/3 movement cost is represented internally as 20.

Some functions in the DLL use the movement value before multiplying it by the denominator, and some after doing it, which can lead to some confusion. Also, it's better not to change the denominator, when I did it I got some bad pathfinding routes.

(Due to lack of knowledge I can't answer your detailed questions about Lua, hopefully someone will do it.)
 
The Lua objects are wrappers around (several related) C++ classes. Internally the game engine uses the C++ classes, while the UI uses the Lua wrappers - so if you try to change the behaviour of the Lua methods it will only change the UI and not the actual route-finding code (which is all in CvAStar.cpp et al)
 
So will SetRouteType actually make a road improvement if I pass it on a plot with Road's ID as its argument?
 
Back
Top Bottom