extra yield if no yield

AW Arcaeca

Deus Vult
Joined
Mar 10, 2013
Messages
3,019
Location
Operation Padlock ground zero
Basically for a new civ I'm planning to give all tiles within their territory that generate no base yield (snow and desert, basically) +1 culture. Right now the code only calls for the plot to not generate food, gold or production but I might change that later on.

TBH I have no idea how to call all plots owned by a certain civ, so I kind of guessed on that... But with that in mind, how close is this coding to being able to do that?

Code:
GameEvents.PlayerDoTurn.Add(
function(playerID)
	local pPlayer = Players[playerID]
	if (pPlayer:IsAlive()) then
		if (pPlayer:GetCivilizationType() == GameInfoTypes.CIVILIZATION_NEWCIV) then

		local pPlot = Game.Plots([Plot.GetOwner(pPlayer)])
		local food = GameInfoTypes.YIELD_FOOD
		local gold = GameInfoTypes.YIELD_GOLD
		local production = GameInfoTypes.YIELD_PRODUCTION
		local culture = GameInfoTypes.YIELD_CULTURE

		if (pPlot:GetYield(food) == 0)
		and (pPlot:GetYield(gold) == 0)
		and (pPlot:GetYield(production) == 0) then
			x = pPlot:GetX()
			y = pPlot:GetY()
			Game.SetPlotExtraYield(x, y, culture, 1)
		end
	end
end)
 
Code:
for iCity in pPlayer:Cities() do
	for i = 0, iCity:GetNumCityPlots() -1 do
		if iCity:GetCityIndexPlot(i) ~= nil then
			local iPlot = iCity:GetCityIndexPlot(i);
			if iPlot:GetOwner() == playerID then
				--you have all workable plots of pPlayer
			end
		end
	end
end
 
The code above is going to give you redundant calls on the same plot if you have any cities < 6 plots apart. The problem is that GetNumCityPlots() and GetCityIndexPlot(i) don't refer to plots owned by a city (what you would think), but rather all plots out to 3 radius (regardless of ownership or overlap between cities). Redundant calls may or may not be a problem for you. If it is, there are several ways to deal with it. One would be to keep track of plots already looped. Another would be to check which specific city owns the plot. There is a function that (despite its name) actually does this: plot:GetCityPurchaseID().

Also... For Heaven's sake, don't use iPlot and iCity for the game objects! Any coder expects an integer when they see those variable names. If you are going to use Hungarian notation, then don't use it to indicate exactly what the variable isn't. It's iCity = pCity:GetID(). A lot of us use a sort of bastardized Hungarian where some variables are prefixed but others not. Personally, I use "i" prefix for game instance indexes (iPlayer, iCity), "ID" suffix for database row IDs (improvementID, resourceID), and nothing for objects (player, plot, city, etc). But in any case, if you saw bSomething or iSomething in my code, you would know with 100% certainty that these were a boolean and an integer, respectively. To the extent that you use this naming system, use it to say what a variable is rather than what it isn't.

Code:
local pPlayer = Players[iPlayer]
for pCity in pPlayer:Cities() do
	for i = 0, pCity:GetNumCityPlots() - 1 do
		local pPlot = pCity:GetCityIndexPlot(i)
		if pPlot and pPlot:GetOwner() == iPlayer then
			local iCity = pCity:GetID()
			if pPlot:GetCityPurchaseID() == iCity then

				--non-redundant owned plots within 3 radius of city

			end
		end
	end
end
--used strict Hungarian above, which is not what I normally do; but at least
--I'm not using "deceptive Hungarian".

Note: this won't get you owned plots that are >3 radius from any city. But yield on these doesn't matter. I'm not sure what happens if a city owns plots beyond 3 radius and then another city is settled near one of those plots. I think the new city takes ownership of the plot so that my code above would work, but I'm not sure. (If not, then you would have to iterate over all plots I guess.)


[Edit: What's annoying about Hungarian, at least how it's used by some, is that it doesn't give you the info you need. Self-consistency is more important. x, y, hexX, hexY would always be integers in my code, but the first two would indicate rectangular coordinates and the second two hex coordinates. iX, iY is silly here because I already know these are integers; what I want to know is what grid system. iUnit would always be the instance index in my mod, but unitID (or more likely unitTypeID) would refer to the database row ID. Again, both are integers but using iUnit in both cases would be uninformative and lead to confusion and mistakes.]
 
We have a badass programmist here. I understand your outrage, because I met this before from my friends, who belongs to your race.

Too bad I am not a coder and I use iPrefix when I iterate anything. Dunno about AgressiveWimp, but I except nobody to read my code.

Anyway, iterating one plot several times isn't worser than iterating all plots.
 
Not a badass programmer. Not professional and I'm only just learning C++. :) If my hackles get up at all it is because Firaxis coders (some new, obviously) sometimes go off the rails and do this sort of thing. Then it takes me many hours to mod the code because I can't understand it.

Anyway, iterating one plot several times isn't worser than iterating all plots.

Depends. Iterating out to 3 radius from all cities and allowing redundancy could be OK or fatal, depending on what you do with it. SetPlotExtraYield is probably OK, since setting the same value redundantly shouldn't hurt (though it doesn't help). But if it were ChangeSomething or count something then that would be bad. Iterating all plots would be slower, but that's not necessary here with the specific city ownership test.
 
Newly found city may claim the ownership of adjacent plots (1 range), but if the city A gain B-plot in 4 range and then u settle a city C in 2-3 range from B-plot then city A remains the owner (too lazy to test it, but from my hours played and cities conquered it seems the case).
What is more, I am sure that conquered cities would not "steal" the ownership of your B-plot.
Since I am too lazy to test it, I would go without checking cityID.

In case of counting or change, I would go with help table to check if plot wasn't already done.
 
Sorry to bump the thread, but if my code won't work and neither will LastSword's, what about Pazyryk's code? Granted I'll have to fill in the empty space, but will his code make a good outline at least?

Which brings me to my next question: My code uses the function Game.SetPlotExtraYield(), but apparently my code won't work. So is it because of that function or because of the condition that triggers it? I'm guessing the latter, and if it is, couldn't the same function be used to set the tile yield once plugged into Pazyryk's code?

EDIT: Nevermind, I think this can be done with xml
 
Back
Top Bottom