+1 Movement for the AI?

Is should be

Code:
unit:SetMoves(unit:GetMoves() + GameDefines.MOVE_DENOMINATOR)

Edit: Or just
Code:
unit:ChangeMoves(GameDefines.MOVE_DENOMINATOR)
 
OK, so a just no barbs version would be:
Code:
GameEvents.PlayerDoTurn.Add(
function(iPlayer)
    local player = Players[iPlayer]
    if player:IsAlive() and not player:IsBarbarian() then
        for unit in player:Units() do
            unit:SetMoves(unit:GetMoves() + 1)
        end
    end
end)
I thought you said using GameEvents.PlayerDoTurn would make movement points per turn stack?

I get the feeling Marshall Thomas here has one or both of two problems:
  • He hasn't given the lua an InGameUIAddin Entry.
  • The code hits an error very early on.
 
Code:
unit:ChangeMoves(GameDefines.MOVE_DENOMINATOR)
Oh yeah, moves aren't just simple integers. It seems a little odd to divide them into 60th's, though...

I thought you said using GameEvents.PlayerDoTurn would make movement points per turn stack?
It would have stacked had I not changed the code to use the playerID parameter instead of the "for" loop in posts #1 and #4...


@Marshall Thomas:
OK, so I finally got around to testing it, and adding 60 instead of 1 does the trick for either PlayerDoTurn() or ActivePlayerTurnStart(), so pick your favorite.

This one runs before each player takes their turn:
Spoiler :
Code:
GameEvents.PlayerDoTurn.Add(
function(iPlayer)
    local player = Players[iPlayer]
    if player:IsAlive() and not player:IsHuman() and not player:IsBarbarian() then
        for unit in player:Units() do
            unit:ChangeMoves(GameDefines.MOVE_DENOMINATOR)
        end
    end
end)
Note that when I switched to PlayerDoTurn() I originally forgot to actually make sure it does not apply it to the human player! :blush:

[Removed ActivePlayerTurnStart() since it won't work in hotseat without a rewrite]
 
Note that when I switched to PlayerDoTurn() I originally forgot to actually make sure it does not apply it to the human player! :blush:

And the ActivePlayerTurnStart version only works for single-player, not hot-seat games
 
And the ActivePlayerTurnStart version only works for single-player, not hot-seat games
:rolleyes: Oh, pish posh.

EDIT: Do you mean because it doesn't do an IsHuman() check, or does the ActivePlayerTurnStart event behave differently in multiplayer?
 
Not multi-player, hot-seat (very different beasts)

Two or more people taking turns at the same computer, so there'll be active player 0, active player 1, etc

So, ActivePlayerTurnStart will fire multiple times for the AI players between their turns (basically you'll be adding "plus number of hot-seat players" to the AI moves, not +1) and you'll also be adding to the moves of all the hot-seat players except the first (because of the loop starting at 1 and not "number of hot-seat players -1")
 
Oh yeah, moves aren't just simple integers. It seems a little odd to divide them into 60th's, though...


It would have stacked had I not changed the code to use the playerID parameter instead of the "for" loop in posts #1 and #4...


@Marshall Thomas:
OK, so I finally got around to testing it, and adding 60 instead of 1 does the trick for either PlayerDoTurn() or ActivePlayerTurnStart(), so pick your favorite.

This one runs before each player takes their turn:
Spoiler :
Code:
GameEvents.PlayerDoTurn.Add(
function(iPlayer)
    local player = Players[iPlayer]
    if player:IsAlive() and not player:IsHuman() and not player:IsBarbarian() then
        for unit in player:Units() do
            unit:ChangeMoves(GameDefines.MOVE_DENOMINATOR)
        end
    end
end)
Note that when I switched to PlayerDoTurn() I originally forgot to actually make sure it does not apply it to the human player! :blush:

[Removed ActivePlayerTurnStart() since it won't work in hotseat without a rewrite]
Thanks! Going to go try it now.

and thanks again to everyone who posted here.
 
Not multi-player, hot-seat (very different beasts)

Two or more people taking turns at the same computer, so there'll be active player 0, active player 1, etc

So, ActivePlayerTurnStart will fire multiple times for the AI players between their turns (basically you'll be adding "plus number of hot-seat players" to the AI moves, not +1) and you'll also be adding to the moves of all the hot-seat players except the first (because of the loop starting at 1 and not "number of hot-seat players -1")
For singleplayer, is one of these faster than the other? Or would there be no noticeable difference?

This type of modding (anything other than simple xml file modding) is totally new to me.

Thanks in advance.
 
Speed at this level is pretty much irrelevant. Both sets of code do the same amount of provessing - give or take a few gnat-milli-micro-ticks here or there. However, one is storing up problems for the future, one isn't.
 
@Marshall Thomas:
OK, so I finally got around to testing it, and adding 60 instead of 1 does the trick for either PlayerDoTurn() or ActivePlayerTurnStart(), so pick your favorite.

This one runs before each player takes their turn:
Spoiler :
Code:
GameEvents.PlayerDoTurn.Add(
function(iPlayer)
    local player = Players[iPlayer]
    if player:IsAlive() and not player:IsHuman() and not player:IsBarbarian() then
        for unit in player:Units() do
            unit:ChangeMoves(GameDefines.MOVE_DENOMINATOR)
        end
    end
end)
Note that when I switched to PlayerDoTurn() I originally forgot to actually make sure it does not apply it to the human player! :blush:

[Removed ActivePlayerTurnStart() since it won't work in hotseat without a rewrite]
When I hover over an enemy unit to attack it, it still says that they have 2 movement points. I don't know for sure that this means it isn't working. Maybe the way in which this mod gives AI units an additional movement is such that it wouldn't show when I hover over enemy units.

How can I test this mod to see if it is giving the AI an additional movement point? Thanks again for your help.
 
Back
Top Bottom