3UC/4UC for VP: Project Coordination Thread

Status
Not open for further replies.
We kept the bonuses to just the city to keep those from becoming major bonuses for England. We didn’t want them to figure into the strategy of the civ, just flavour boosters.

I have made all the changes to the github.

I think one other building needs to be revisited though: American Homestead.
The UB just increases a bonus already present on the UA (yields on border growth). I think this needs to be revisited.
What if instead of increasing instant yields, the homestead immediately claimed all horses/sheep/cattle/bison in workable distance of the city, even if already owned by another civ, and triggered the UA bonus for all of them?
Fair enough with the White Tower. Flavor is good, I suppose. Can always revisit this if the UW is underwhelming otherwise.

Problem with that Homestead ability is that it would cause you to be unable to build it in a city if said city is next to a civ you want to avoid diplomatic penalties with. Using America's UA is a decision, and having a "You stole their land!"-modifier with all your neighbours by Renaissance is less than ideal, usually.

Theoretically interesting gameplay that could in practice just end up being 'well poop, no Homestead in Chicago then'.
 
Theoretically interesting gameplay that could in practice just end up being 'well poop, no Homestead in Chicago then'.
I think the situation you are describing is possible, but the ingredients for such a situation seem counter to America's playstyle. Playing a polite America is playing a defanged America. It's also unlikely that a civ that settled that close to you is one that you aren't either a) pissed at for forward settling you, or b) you are purposefully trying to encroach on.

Well it's just one suggestion. My main point was that something should be done so that the UB isn't simply a copy of the UA. This is the same reason I felt the Agora had to be changed. Does anyone have a different idea?
 
Last edited:
I'm not 100% sold on the idea it really needs to be changed - it may be simple, but if it works it works. Maybe change the yields to food, culture and GAP, but remove the increase on border rate, so it's good... but far better if you actually use the UA to it's best extent?

EDIT: or an even more radical idea if we want to play with it: make the yields borderline GROSS, but give the building also a negative modifier to border growth?
 
Last edited:
Please find attached the updated 4UC pictures

Here's what I have come up with. It is a modified version of the lua used for the Ranch from Roosevelt's America Mod

claims and improves all horse, sheep, cattle, and bison with 3 tiles of the city IF NOT ALREADY OWNED

Problem: This code uses the plotiterators.lua.

@adan_eslavo got rid of plotiterators.lua in a previous version. Is there a way to do this function without using that lua?
Code:
include("PlotIterators.lua")

local improvementCampID        = GameInfoTypes.IMPROVEMENT_CAMP
local improvementPastureID    = GameInfoTypes.IMPROVEMENT_PASTURE
local resourceBisonID        = GameInfoTypes.RESOURCE_BISON
local resourceCowID            = GameInfoTypes.RESOURCE_COW
local resourceHorseID        = GameInfoTypes.RESOURCE_HORSE
local resourceSheepID        = GameInfoTypes.RESOURCE_SHEEP
local buildingRanchID         = GameInfoTypes.BUILDING_AMERICA_RANCH
local fGameSpeedModifier1     = GameInfo.GameSpeeds[ Game.GetGameSpeedType() ].ConstructPercent / 100

function RanchClaimLand(playerID, cityID, buildingID)
    local player = Players[playerID]
    if (player:GetCivilizationType() == GameInfoTypes.CIVILIZATION_AMERICA) then
        if buildingID == buildingRanchID then
            local iEraModifier = math.max(pPlayer:GetCurrentEra(), 1)
            local iYield1 = math.floor(20 * iEraModifier * fGameSpeedModifier1)
            local city = player:GetCityByID(cityID)
            local plot = Map.GetPlot(city:GetX(), city:GetY())
            for loopPlot in PlotAreaSpiralIterator(plot, 3, SECTOR_NORTH, DIRECTION_CLOCKWISE, DIRECTION_OUTWARDS, CENTRE_INCLUDE) do
                local plotX = loopPlot:GetX()
                local plotY = loopPlot:GetY()
                local plotResource = loopPlot:GetResourceType()
                if loopPlot:GetOwner() == -1 then
                    if (plotResource == resourceSheepID or plotResource == resourceHorseID or plotResource == resourceCowID)  then
                        loopPlot:SetOwner(playerID, cityID, true, true)
                        loopPlot:SetRevealed(playerTeam, true)
                        pCity:ChangeProduction(iYield1)
                        if loopPlot:GetImprovementType() == -1 then
                            loopPlot:SetImprovementType(improvementPastureID, true)
                        end
                       
                        if pPlayer:IsHuman() and pPlayer:IsTurnActive() then
                            local iCityX = pCity:GetX()
                            local iCityY = pCity:GetY()
                            local vCityPosition = PositionCalculator(iCityX, iCityY)
           
                            Events.AddPopupTextEvent(vCityPosition, "[COLOR_YIELD_PRODUCTION]+"..iYield1.." [ICON_PRODUCTION][ENDCOLOR]", 1)
                        end
                    elseif (plotResource == resourceBisonID)  then
                        loopPlot:SetOwner(playerID, cityID, true, true)
                        loopPlot:SetRevealed(playerTeam, true)
                        pCity:ChangeProduction(iYield1)
                        if loopPlot:GetImprovementType() == -1 then
                            loopPlot:SetImprovementType(improvementCampID, true)
                        end

                        if pPlayer:IsHuman() and pPlayer:IsTurnActive() then
                            local iCityX = pCity:GetX()
                            local iCityY = pCity:GetY()
                            local vCityPosition = PositionCalculator(iCityX, iCityY)

                            Events.AddPopupTextEvent(vCityPosition, "[COLOR_YIELD_PRODUCTION]+"..iYield1.." [ICON_PRODUCTION][ENDCOLOR]", 1)
                        end
                    end
                    if pPlayer:IsHuman() and pPlayer:IsTurnActive() then
                        pPlayer:AddNotification(NotificationTypes.NOTIFICATION_INSTANT_YIELD,
                        'Homestead constructed in [COLOR_POSITIVE_TEXT]'..city:GetName()..': [ENDCOLOR]+'..iYield1..' [ICON_PRODUCTION] Production',
                        'Bonus Yields in '..city:GetName(),
                        city:GetX(), city:GetY(), city:GetID())
                    end
                end
            end
        end
    end    
end

GameEvents.CityConstructed.Add(RanchClaimLand)
 

Attachments

I think this part here can be shortened to avoid duplication:

Code:
                    if (plotResource == resourceSheepID or plotResource == resourceHorseID or plotResource == resourceCowID)  then
                        loopPlot:SetOwner(playerID, cityID, true, true)
                        loopPlot:SetRevealed(playerTeam, true)
                        pCity:ChangeProduction(iYield1)
                        if loopPlot:GetImprovementType() == -1 then
                            loopPlot:SetImprovementType(improvementPastureID, true)
                        end
                    
                        if pPlayer:IsHuman() and pPlayer:IsTurnActive() then
                            local iCityX = pCity:GetX()
                            local iCityY = pCity:GetY()
                            local vCityPosition = PositionCalculator(iCityX, iCityY)
        
                            Events.AddPopupTextEvent(vCityPosition, "[COLOR_YIELD_PRODUCTION]+"..iYield1.." [ICON_PRODUCTION][ENDCOLOR]", 1)
                        end
                    elseif (plotResource == resourceBisonID)  then
                        loopPlot:SetOwner(playerID, cityID, true, true)
                        loopPlot:SetRevealed(playerTeam, true)
                        pCity:ChangeProduction(iYield1)
                        if loopPlot:GetImprovementType() == -1 then
                            loopPlot:SetImprovementType(improvementCampID, true)
                        end

                        if pPlayer:IsHuman() and pPlayer:IsTurnActive() then
                            local iCityX = pCity:GetX()
                            local iCityY = pCity:GetY()
                            local vCityPosition = PositionCalculator(iCityX, iCityY)

                            Events.AddPopupTextEvent(vCityPosition, "[COLOR_YIELD_PRODUCTION]+"..iYield1.." [ICON_PRODUCTION][ENDCOLOR]", 1)
                        end
                    end

To this:

Code:
                    if (plotResource == resourceSheepID or plotResource == resourceHorseID or plotResource == resourceCowID or plotResource == resourceBisonID)  then
                        loopPlot:SetOwner(playerID, cityID, true, true)
                        loopPlot:SetRevealed(playerTeam, true)
                        pCity:ChangeProduction(iYield1)
                        if loopPlot:GetImprovementType() == -1 then
                            local improvementID = plotResource == resourceBisonID ? improvementCampID : improvementPastureID
                            loopPlot:SetImprovementType(improvementPastureID, true)
                        end
                    
                        if pPlayer:IsHuman() and pPlayer:IsTurnActive() then
                            local iCityX = pCity:GetX()
                            local iCityY = pCity:GetY()
                            local vCityPosition = PositionCalculator(iCityX, iCityY)
        
                            Events.AddPopupTextEvent(vCityPosition, "[COLOR_YIELD_PRODUCTION]+"..iYield1.." [ICON_PRODUCTION][ENDCOLOR]", 1)
                        end
                    end

If LUA doesn't support tertiary operators, then just make a simple if-structure, but at least there is a lot less duplicated code now.
I hope you don't mind me throwing out advice like this, but I like providing hints when I see code :p
 
Last edited:
If LUA doesn't support tertiary operators, then just make a simple if-structure, but at least there is a lot less duplicated code now.
It does not, but there’s a trick that can be used as a substitute.
Impr = ( res == bison and camp or pasture )
 
It does not, but there’s a trick that can be used as a substitute.
Impr = ( res == bison and camp or pasture )

That is not what I mean. I meant the ternary operator "?".
The code you does not pertain to that part or ?
 
It does. That is how you do ? operator in Lua.

Ah I see.

So the entire thing would look like this:
Code:
                    if (plotResource == resourceSheepID or plotResource == resourceHorseID or plotResource == resourceCowID or plotResource == resourceBisonID)  then
                        loopPlot:SetOwner(playerID, cityID, true, true)
                        loopPlot:SetRevealed(playerTeam, true)
                        pCity:ChangeProduction(iYield1)
                        if loopPlot:GetImprovementType() == -1 then
                            local improvementID = plotResource == resourceBisonID and improvementCampID or improvementPastureID
                            loopPlot:SetImprovementType(improvementPastureID, true)
                        end
                    
                        if pPlayer:IsHuman() and pPlayer:IsTurnActive() then
                            local iCityX = pCity:GetX()
                            local iCityY = pCity:GetY()
                            local vCityPosition = PositionCalculator(iCityX, iCityY)
        
                            Events.AddPopupTextEvent(vCityPosition, "[COLOR_YIELD_PRODUCTION]+"..iYield1.." [ICON_PRODUCTION][ENDCOLOR]", 1)
                        end
                    end
 
Would this work as well ?
No. You cannot use statement keywords (then) in an expression.
And/or are operators. The trick is that Lua, in case of logical operators, treats any value as true (only false and nil are actually false). Also, stops evaluating them once the result is known.
So, the expression ( cond and exp1 or exp2 ) means that if cond is true, then exp1 is evaluated. If cond is false, then exp1 is not evaluated (no need, 'and' is always false in this case), so exp2 must be evaluated because there's 'or'.
Yeah... Lua is full of such "features". Very flexible but tracking errors is nightmare sometimes.
 
No. You cannot use statement keywords (then) in an expression.
And/or are operators. The trick is that Lua, in case of logical operators, treats any value as true (only false and nil are actually false). Also, stops evaluating them once the result is known.
So, the expression ( cond and exp1 or exp2 ) means that if cond is true, then exp1 is evaluated. If cond is false, then exp1 is not evaluated (no need, 'and' is always false in this case), so exp2 must be evaluated because there's 'or'.
Yeah... Lua is full of such "features". Very flexible but tracking errors is nightmare sometimes.

But isn't this code correct then ?
local improvementID = plotResource == resourceBisonID and improvementCampID or improvementPastureID
or am I missing something ?

Btw. I edited the post above, so you might have responded to the old post which contained some other code.
 
Sounds like @De_Genius wants a job :D

Would one of your two simply prefer to take over this? I certainly won't say no
 
Hehe. Still don't have the time. I just enjoy optimizing code, and in this case it was a juicy one :D
Well, I hope you'll reconsider. Sounds like you have a pretty good idea for what needs to be done.

If someone who isn't me wants to take this idea to completion then by all means. I spent 2 weeks beating my head against a wall for a relatively simple change to the Agora, only to have @Infixo complete it. I never could do it myself, even with his patient tutelage. There's just too much I don't know or understand about lua and coding in general.

I think a change to Ranch would improve the mod, but I should just admit when I'm beat. Me doing lua isn't a good use of anyone's time.
 
Well, I hope you'll reconsider. Sounds like you have a pretty good idea for what needs to be done.

If someone who isn't me wants to take this idea to completion then by all means. I spent 2 weeks beating my head against a wall for a relatively simple change to the Agora, only to have @Infixo complete it. I never could do it myself, even with his patient tutelage. There's just too much I don't know or understand about lua and coding in general.

I think a change to Ranch would improve the mod, but I should just admit when I'm beat. Me doing lua isn't a good use of anyone's time.

Although I don't have much time for contributing directly, I would be happy to help out with the actual code. I have spent the last 10 years developing small casual games in Java and HTML5/JS, so I often have a good idea how to put together code. It is mostly the stuff surrounding that takes up most of the time when making the UCs, at least for me.

pineappledan, if you want to, we would work together through PM or similar regarding your problems.
 
You can do it without PlotIterators. You need to use two loops -3..3 for x and y and PlotDistance function.

How would one go about performing this without plotIterators ?
If you could post the code here or point us towards a file using it, that would be excellent.
 
How would one go about performing this without plotIterators ?
If you could post the code here or point us towards a file using it, that would be excellent.
I just said that. You need 2 loops and PlotDistance function (maybe it’s called different, I cannot check now).
The issue here is not changing the function into non-PlotIterators, which is easy. The issue here is that this change has not been agreed. So, there is no need to change anything, at least not yet.
 
I just said that. You need 2 loops and PlotDistance function (maybe it’s called different, I cannot check now).
The issue here is not changing the function into non-PlotIterators, which is easy. The issue here is that this change has not been agreed. So, there is no need to change anything, at least not yet.

Ok, so we will use the PlotIterator for now then. I am fairly curious to know how it would be possible with 2 loops, since it does not seem possible for me to do in a hexagonal world. In a square pre Civ5 world yes, but things are a lot more complex with the hexes.

If you could provide a concrete example or point me/us towards a place in VP where it is used, please do so, when it is possible for you.
 
Status
Not open for further replies.
Back
Top Bottom