Can someone please help out with my UA?

Discussion in 'Civ5 - Creation & Customization' started by Scissor_fingers, Jul 31, 2016.

  1. Scissor_fingers

    Scissor_fingers Chieftain

    Joined:
    Jul 31, 2016
    Messages:
    10
    Location:
    Texas
    So I'm making a civ based around Chinese pirates and I have come to a stumbling block with my UA.

    I really like it but I dont know exactly how to code it. This is my first mod so I'm a bit new so please forgive my stupidity. I'd really appreciate it if some one explained what I need to do. I've been messing around in XML and stuff but I don't know if this is enough. Thanks!

    Heres the UA
    San T'iao - Naval Units built in a city with a GA stationed in it gain the Prize Ships promotion. Cities with water trade routes in them produce additional culture equivalent to 50% of gold intake
     
  2. Enginseer

    Enginseer Salientia of the Community Patch Supporter

    Joined:
    Nov 7, 2012
    Messages:
    3,229
    Gender:
    Male
    Location:
    Somewhere in California
    You can only do it in Lua.

    The first part seems impossible because of how hard it is for the AI to use this UA, but.... I'll do it(maybe detect if there is a great admiral alive then grant the prize ship promotion regardless where he or she is?).

    For the second part of your UA, however it's impossible to do water trade routes unless someone proves me otherwise...
    Code:
    local iAdmiral = GameInfoTypes.UNITCLASS_GREAT_ADMIRAL
    local ChinesePirateCiv = GameInfoTypes.CIVILIZATION_WHATEVERITIS
    local iDomainWater = GameInfoTypes.DOMAIN_SEA
    local iPrizePromotion = GameInfoTypes.PROMOTION_PRIZE_SHIPS
    
    --As you can see your first part of the UA is very intensive compared to the second part because of how much the game has to do to detect the correct civilization, if unit has promotion already, check if unit is on a plot that is on a city while containing a great admiral!
    function ChinesePrizeShips(playerID, unitID, hexVec, unitType, cultureType, civID, primaryColor, secondaryColor, unitFlagIndex, fogState, selected, military, notInvisible)
    	local pPlayer = Players[playerID]
    	if pPlayer == nil then return end
    	if (pPlayer:GetCivilizationType() == ChinesePirateCiv) then
    		local pUnit = pPlayer:GetUnitByID(unitID)
    		if (pUnit == nil or pUnit:IsDead() or pUnit:IsHasPromotion(iPrizePromotion)) then return end
    		if pUnit:GetDomainType() == iDomainWater then
    			local pPlot = pUnit:GetPlot()
    			if pPlot:IsCity() then
    				local pAdmiral = nil
    				for i = 0, pPlot:GetNumUnits() do
    					local pAdmiralSearch = pPlot:GetUnit(i)
    					if pAdmiralSearch then
    						if (pAdmiralSearch:GetUnitClassType() == iAdmiral) and (pAdmiralSearch:GetOwner() == playerID) then
    							pAdmiralSearch = pAdmiral
    						end
    					end
    				end
    				if pAdmiral then 
    					pUnit:SetHasPromotion(iPrizePromotion, true)
    				end
    			end
    		end
    	end
    end
    
    function ChinesePirate(iPlayer)
    	local pPlayer = Players[iPlayer]
    	if (pPlayer:GetCivilizationType() == ChinesePirateCiv) then 
    		local iTradeGoldIncome = (pPlayer:GetGoldFromCitiesTimes100()-pPlayer:GetGoldFromCitiesMinusTradeRoutesTimes100())/200
    		--For non-math people, dividing by 200 instead of 100 will give me the value equivalent to 50% of the gold per turn.
    		pPlayer:ChangeJONSCulture(iTradeGoldIncome)
    	end
    end
    
    Events.SerialEventUnitCreated.Add(ChinesePrizeShips)
    GameEvents.PlayerDoTurn.Add(ChinesePirate)
    
    Note I haven't tested it and has just written this by scratch. If there are any errors, just a safety precautions so I can easily fix it...

    Edit: And for future purposes later that I think you might encounter a problem into when trying to put Lua inside your ModBuddy.
     

Share This Page