[vanilla] No cost when disembarking

fb2017

Chieftain
Joined
Oct 8, 2017
Messages
53
Is it possible that units pay no movement cost when embarking and disembarking? Like in civ 6?

Thanks
 
Last edited:
Assuming you're talking about movement points:
First of all, there's Denmark's trait (no movement cost when disembarking).

If you're looking for a unit-only function, or something that also works when embarking, I wrote this Lua code a while back for Pi's Newfoundland's UU. (It basically refunds movement points when embarking/disembarking)
It can easily be changed to work one-way only, or to work for all units of a civ.
Code:
-- PiNewfoundland.lua
-- Author: Troller0001
-- DateCreated: 1/19/2017 2:58:52 PM
--------------------------------------------------------------
print("PiNewfoundlandLua.lua has been loaded!");

--Defines
local iCiv = GameInfoTypes.CIVILIZATION_MYCIV

--[,,]snipped[..]

local iBluePuttee = GameInfoTypes.UNIT_ARCHER
local iPutteeEmbarkMoveCost = 1; --the movement cost of (dis)embarking with a Puttee
local tPutteeMoves = {}
local iPromotionEmbarked = GameInfoTypes.PROMOTION_PI_CHEAP_EMBARKATION_EMBARKED
local iPromotionDisembarked = GameInfoTypes.PROMOTION_PI_CHEAP_EMBARKATION_DISEMBARKED

--Modder's snippets
--===========================
--Whowards PlotIterators
include("PlotIterators");

---- whoward's IsCivInPlay
function IsCivInPlay(iCivType)
  for iSlot = 0, GameDefines.MAX_MAJOR_CIVS-1, 1 do
    local iSlotStatus = PreGame.GetSlotStatus(iSlot)
    if (iSlotStatus == SlotStatus.SS_TAKEN or iSlotStatus == SlotStatus.SS_COMPUTER) then
      if (PreGame.GetCivilization(iSlot) == iCivType) then
        return true
      end
    end
  end
 
  return false
end

--Troller's IsCSUnitGift
--Loop through all the CSs to see if they will be able to gift the UU;
function IsCSUnitGift(iUnitType)
    print("Checking if a CS can gift ("..GameInfo.Units[iUnitType].Type..")!")                       
    for i = GameDefines.MAX_MAJOR_CIVS, GameDefines.MAX_CIV_PLAYERS-1, 1 do
        local pMinor = Players[i];
        if pMinor ~= nil then
            if pMinor:IsEverAlive() then --IsEverAlive because the CS can be resurrected!
                local iTrait = pMinor:GetMinorCivTrait();
                if (iTrait == MinorCivTraitTypes.MINOR_CIV_TRAIT_MILITARISTIC) then
                    if (pMinor:IsMinorCivHasUniqueUnit()) then
                        local iUniqueUnit = pMinor:GetMinorCivUniqueUnit();
                        if iUniqueUnit == iUnitType then
                            print("A CS (ID="..i..") can gift that unit ("..GameInfo.Units[iUnitType].Type..")!")
                            return true;
                        end
                    end
                end
            end
        end
    end
    print("No CS can gift that unit ("..GameInfo.Units[iUnitType].Type..")")
    return false;
end
--===========================

--[..]snipped[..]

---------------------------------------------------------------
-------------------UU Lua---------------
--more strength when embarked -> give it the 'embarkation with defense' promotion just like the conquistador (or however you spell that)

local bReduceLag = false --reduces lag, but makes it so the UU does not function for other civs if they acquire it

function EmbarkationOnlyOneMovement(iPlayer,iUnit,iX,iY)
    local pPlayer = Players[iPlayer]
    if pPlayer:GetCivilizationType() == iCiv or (not bReduceLag) then
        local pUnit = pPlayer:GetUnitByID(iUnit)
        local pPlot = Map.GetPlot(iX,iY)
        if pUnit:GetUnitType() == iBluePuttee then
            if pUnit:IsHasPromotion(iPromotionEmbarked) and not pPlot:IsWater() then
                print("The unit was embarked and moved onto land!")
                pUnit:SetHasPromotion(iPromotionEmbarked,false)
                pUnit:SetHasPromotion(iPromotionDisembarked,true)
                SetCorrectMoves(iPlayer,iUnit)
            elseif pUnit:IsHasPromotion(iPromotionDisembarked) and pPlot:IsWater() then
                print("The unit was disembarked and moved onto the water!")
                pUnit:SetHasPromotion(iPromotionEmbarked,true)
                pUnit:SetHasPromotion(iPromotionDisembarked,false)
                SetCorrectMoves(iPlayer,iUnit)
            end
            if tPutteeMoves[iPlayer] then
                tPutteeMoves[iPlayer][iUnit] = pUnit:GetMoves()/60
                print('0) tPutteeMoves['..iPlayer..']['..iUnit..'] = '..tPutteeMoves[iPlayer][iUnit])
            end
        end
    end
end

function SetCorrectMoves(iPlayer,iUnit)
    local pPlayer = Players[iPlayer]
    local pUnit = pPlayer:GetUnitByID(iUnit)
    if tPutteeMoves[iPlayer] then
        local iMovesPreEmbark = tPutteeMoves[iPlayer][iUnit]
        if iMovesPreEmbark and iMovesPreEmbark > 0 then
            pUnit:SetMoves(60*(iMovesPreEmbark-iPutteeEmbarkMoveCost))
        else
            tPutteeMoves[iPlayer][iUnit] = pUnit:MaxMoves()/60
            print('1) tPutteeMoves['..iPlayer..']['..iUnit..'] = '..tPutteeMoves[iPlayer][iUnit])
            pUnit:SetMoves(math.max(pUnit:MaxMoves()-60*iPutteeEmbarkMoveCost,0))
        end
    end
end

--resets the table per turn. if tPutteeMoves[iPlayer][iUnit] = nil, then the amount of moves is the maximum amount of moves
function ResetTablePerTurn(iPlayer)
    tPutteeMoves[iPlayer]={}
end

--Initializes the moves-table, which contains the number of moves of every Blue Puttee
function InitialMovesTableLoad()
    for i=1,GameDefines.MAX_CIV_PLAYERS-1 do
        local pPlayer = Players[i]
        if pPlayer:GetCivilizationType() == iCiv or (not bReduceLag) then
            for pUnit in pPlayer:Units() do
                if pUnit:GetUnitType() == iBluePuttee then
                    if tPutteeMoves[i] == nil then
                        print('tPutteeMoves['..i..'] = {}')
                        tPutteeMoves[i] = {}
                    end
                    print('tPutteeMoves['..i..']['..pUnit:GetID()..'] = '..pUnit:GetMoves())
                    tPutteeMoves[i][pUnit:GetID()] = pUnit:GetMoves()
                end
            end
        end
    end
end

if IsCivInPlay(iCiv) or ((not bReduceLag) and IsCSUnitGift(iBluePuttee)) then
    InitialMovesTableLoad()
    GameEvents.PlayerDoTurn.Add(ResetTablePerTurn)
    GameEvents.UnitSetXY.Add(EmbarkationOnlyOneMovement)
end
 
Assuming you're talking about movement points:
First of all, there's Denmark's trait (no movement cost when disembarking).

If you're looking for a unit-only function, or something that also works when embarking, I wrote this Lua code a while back for Pi's Newfoundland's UU. (It basically refunds movement points when embarking/disembarking)
It can easily be changed to work one-way only, or to work for all units of a civ.
Code:
-- PiNewfoundland.lua
-- Author: Troller0001
-- DateCreated: 1/19/2017 2:58:52 PM
--------------------------------------------------------------
print("PiNewfoundlandLua.lua has been loaded!");

--Defines
local iCiv = GameInfoTypes.CIVILIZATION_MYCIV

--[,,]snipped[..]

local iBluePuttee = GameInfoTypes.UNIT_ARCHER
local iPutteeEmbarkMoveCost = 1; --the movement cost of (dis)embarking with a Puttee
local tPutteeMoves = {}
local iPromotionEmbarked = GameInfoTypes.PROMOTION_PI_CHEAP_EMBARKATION_EMBARKED
local iPromotionDisembarked = GameInfoTypes.PROMOTION_PI_CHEAP_EMBARKATION_DISEMBARKED

--Modder's snippets
--===========================
--Whowards PlotIterators
include("PlotIterators");

---- whoward's IsCivInPlay
function IsCivInPlay(iCivType)
  for iSlot = 0, GameDefines.MAX_MAJOR_CIVS-1, 1 do
    local iSlotStatus = PreGame.GetSlotStatus(iSlot)
    if (iSlotStatus == SlotStatus.SS_TAKEN or iSlotStatus == SlotStatus.SS_COMPUTER) then
      if (PreGame.GetCivilization(iSlot) == iCivType) then
        return true
      end
    end
  end
 
  return false
end

--Troller's IsCSUnitGift
--Loop through all the CSs to see if they will be able to gift the UU;
function IsCSUnitGift(iUnitType)
    print("Checking if a CS can gift ("..GameInfo.Units[iUnitType].Type..")!")                      
    for i = GameDefines.MAX_MAJOR_CIVS, GameDefines.MAX_CIV_PLAYERS-1, 1 do
        local pMinor = Players[i];
        if pMinor ~= nil then
            if pMinor:IsEverAlive() then --IsEverAlive because the CS can be resurrected!
                local iTrait = pMinor:GetMinorCivTrait();
                if (iTrait == MinorCivTraitTypes.MINOR_CIV_TRAIT_MILITARISTIC) then
                    if (pMinor:IsMinorCivHasUniqueUnit()) then
                        local iUniqueUnit = pMinor:GetMinorCivUniqueUnit();
                        if iUniqueUnit == iUnitType then
                            print("A CS (ID="..i..") can gift that unit ("..GameInfo.Units[iUnitType].Type..")!")
                            return true;
                        end
                    end
                end
            end
        end
    end
    print("No CS can gift that unit ("..GameInfo.Units[iUnitType].Type..")")
    return false;
end
--===========================

--[..]snipped[..]

---------------------------------------------------------------
-------------------UU Lua---------------
--more strength when embarked -> give it the 'embarkation with defense' promotion just like the conquistador (or however you spell that)

local bReduceLag = false --reduces lag, but makes it so the UU does not function for other civs if they acquire it

function EmbarkationOnlyOneMovement(iPlayer,iUnit,iX,iY)
    local pPlayer = Players[iPlayer]
    if pPlayer:GetCivilizationType() == iCiv or (not bReduceLag) then
        local pUnit = pPlayer:GetUnitByID(iUnit)
        local pPlot = Map.GetPlot(iX,iY)
        if pUnit:GetUnitType() == iBluePuttee then
            if pUnit:IsHasPromotion(iPromotionEmbarked) and not pPlot:IsWater() then
                print("The unit was embarked and moved onto land!")
                pUnit:SetHasPromotion(iPromotionEmbarked,false)
                pUnit:SetHasPromotion(iPromotionDisembarked,true)
                SetCorrectMoves(iPlayer,iUnit)
            elseif pUnit:IsHasPromotion(iPromotionDisembarked) and pPlot:IsWater() then
                print("The unit was disembarked and moved onto the water!")
                pUnit:SetHasPromotion(iPromotionEmbarked,true)
                pUnit:SetHasPromotion(iPromotionDisembarked,false)
                SetCorrectMoves(iPlayer,iUnit)
            end
            if tPutteeMoves[iPlayer] then
                tPutteeMoves[iPlayer][iUnit] = pUnit:GetMoves()/60
                print('0) tPutteeMoves['..iPlayer..']['..iUnit..'] = '..tPutteeMoves[iPlayer][iUnit])
            end
        end
    end
end

function SetCorrectMoves(iPlayer,iUnit)
    local pPlayer = Players[iPlayer]
    local pUnit = pPlayer:GetUnitByID(iUnit)
    if tPutteeMoves[iPlayer] then
        local iMovesPreEmbark = tPutteeMoves[iPlayer][iUnit]
        if iMovesPreEmbark and iMovesPreEmbark > 0 then
            pUnit:SetMoves(60*(iMovesPreEmbark-iPutteeEmbarkMoveCost))
        else
            tPutteeMoves[iPlayer][iUnit] = pUnit:MaxMoves()/60
            print('1) tPutteeMoves['..iPlayer..']['..iUnit..'] = '..tPutteeMoves[iPlayer][iUnit])
            pUnit:SetMoves(math.max(pUnit:MaxMoves()-60*iPutteeEmbarkMoveCost,0))
        end
    end
end

--resets the table per turn. if tPutteeMoves[iPlayer][iUnit] = nil, then the amount of moves is the maximum amount of moves
function ResetTablePerTurn(iPlayer)
    tPutteeMoves[iPlayer]={}
end

--Initializes the moves-table, which contains the number of moves of every Blue Puttee
function InitialMovesTableLoad()
    for i=1,GameDefines.MAX_CIV_PLAYERS-1 do
        local pPlayer = Players[i]
        if pPlayer:GetCivilizationType() == iCiv or (not bReduceLag) then
            for pUnit in pPlayer:Units() do
                if pUnit:GetUnitType() == iBluePuttee then
                    if tPutteeMoves[i] == nil then
                        print('tPutteeMoves['..i..'] = {}')
                        tPutteeMoves[i] = {}
                    end
                    print('tPutteeMoves['..i..']['..pUnit:GetID()..'] = '..pUnit:GetMoves())
                    tPutteeMoves[i][pUnit:GetID()] = pUnit:GetMoves()
                end
            end
        end
    end
end

if IsCivInPlay(iCiv) or ((not bReduceLag) and IsCSUnitGift(iBluePuttee)) then
    InitialMovesTableLoad()
    GameEvents.PlayerDoTurn.Add(ResetTablePerTurn)
    GameEvents.UnitSetXY.Add(EmbarkationOnlyOneMovement)
end
Yeah, I was talking about movement cost! Thanks for the answer!
 
Top Bottom