Count number of DoF's, get bonus from DoF, etc.

Danmacsch

Geheimekabinetsminister
Joined
Jan 14, 2014
Messages
1,316
Location
Copenhagen, Denmark
Hi,

I'm trying to come up with a bunch of functions for a project of mine.
I have a lot of different questions and requests for help, and all advice is very welcome :D

In the following I've listed some of the functions I'm having trouble with. I have tried to write the code myself of course, and I will post my attempts once I'm home (sometime tonight).


1) A function to detect the number of DoF's you currently have with other major civilisations.

2) A function that gives the player a percentage of the gold and culture generated by civilisations with whom you have a DoF.

3) A function to detect when a worker has chopped down a forest somewhere on the map

4) probably a little more complicated. Letting a unit build an improvement on city-state territory and having two possible outcomes: a) instant decrease in influence and b) puppet city-state.

That's it for now. I really hope someone can help me.
 

JFD

Kathigitarkh
Joined
Oct 19, 2010
Messages
9,131
Location
The Kingdom of New Zealand
1 + 2 See my Switzerland civ. But I can write up the code for you.
3 Detecting a chop forest should be easy (if you don't mind a chopped Jungle as well). Will write up the code for you, to.
4 You can restrict the improvement to CS territory with some tag used by the Portuguese Feitoria. Then I suppose you'll need a new UI element to pop up once that's completed. I can do this for you too.
 

JFD

Kathigitarkh
Joined
Oct 19, 2010
Messages
9,131
Location
The Kingdom of New Zealand
Function for 1:

Code:
function JFD_GetNumDoF(playerID)
	local player = Players[playerID]
	local numDoF = 0
	for iPlayer = 0, GameDefines.MAX_MAJOR_CIVS-1, 1 do
		local otherPlayer = Players[iPlayer]
		if otherPlayer:IsAlive() and iPlayer ~= playerID then
			if Teams[player:GetTeam()]:IsHasMet(otherPlayer:GetTeam()) then
				if not (otherPlayer:IsDoF(playerID)) and not (otherPlayer:IsDenouncedPlayer(playerID)) and not (otherPlayer:IsDenouncingPlayer(playerID)) and not (Teams[otherPlayer:GetTeam()]:IsAtWar(player:GetTeam())) then
					numDoF = numDoF + 1
				end
			end
		end
	end

	return numDoF
end

Function for 2 (invoke with a yield and a percentage, e.g. JFD_GetYieldFromDoFPartners(playerID, "YIELD_GOLD", 50)

Code:
function JFD_GetYieldFromDoFPartners(playerID, yieldType, percentage)
	local player = Players[playerID]
	local yield = 0
	for iPlayer = 0, GameDefines.MAX_MAJOR_CIVS-1, 1 do
		local otherPlayer = Players[iPlayer]
		if otherPlayer:IsAlive() and iPlayer ~= playerID then
			if Teams[player:GetTeam()]:IsHasMet(otherPlayer:GetTeam()) then
				if not (otherPlayer:IsDoF(playerID)) and not (otherPlayer:IsDenouncedPlayer(playerID)) and not (otherPlayer:IsDenouncingPlayer(playerID)) and not (Teams[otherPlayer:GetTeam()]:IsAtWar(player:GetTeam())) then
					if yieldType == "YIELD_GOLD" then
						local otherPlayerGold = otherPlayer:CalculateGoldRate()
						yield = yield + (otherPlayerGold * percentage / 100)
					end

					if yieldType == "YIELD_CULTURE" then
						local othePlayerCulture = otherPlayer:GetTotalJONSCulturePerTurn()
						yield = yield + (othePlayerCulture * percentage / 100)
					end
					
					if yieldType == "YIELD_FAITH" then
						local othePlayerFaith = otherPlayer:GetTotalFaithPerTurn()
						yield = yield + (othePlayerFaith * percentage / 100)
					end

					if yieldType == "YIELD_SCIENCE" then
						local othePlayerScience = otherPlayer:GetScience()
						yield = yield + (othePlayerScience * percentage / 100)
					end
				end
			end
		end
	end

	return yield
end

Unfortunately, I don't think number 3 will be possible, though maybe there's a serial event that could be used.
 

whoward69

DLL Minion
Joined
May 30, 2011
Messages
8,604
Location
Near Portsmouth, UK
though maybe there's a serial event that could be used.
If there is (and I can't remember if the events for completing/destroying an improvement fire for the "remove" builds), it will only work for the human player (and not the AI), as they only fire if the tile the forest was chopped on is visible to the player.
 

DonStamos

Mobster Inc©
Joined
Sep 21, 2002
Messages
820
Location
United States
If I'm correct on this, could I use the number from Function 1 (numDoF) to give a Civilization extra WC delegates equal to that number (and would I call it back to "numDoF" in the function that grants the delegates)?
 

Danmacsch

Geheimekabinetsminister
Joined
Jan 14, 2014
Messages
1,316
Location
Copenhagen, Denmark
I don't know how to grant WC delegates, but guess it's pretty straightforward.
The function 1 returns the number of declarations of friendship, so calling numDoF from the WC delegates function should do the trick.

You can just post the code in this thread if you run into any problems.

Can I ask what it's for? Saw that you are working on adding E&D support for DJSHenninger's civs. Is it for that?
 

DonStamos

Mobster Inc©
Joined
Sep 21, 2002
Messages
820
Location
United States
I don't know how to grant WC delegates, but guess it's pretty straightforward.
The function 1 returns the number of declarations of friendship, so calling numDoF from the WC delegates function should do the trick.

You can just post the code in this thread if you run into any problems.

Can I ask what it's for? Saw that you are working on adding E&D support for DJSHenninger's civs. Is it for that?

Yeah, it's for a decision about the Non-Aligned Movement. I'm hoping to avoid dummy buildings if possible, but if they're the best way to do it, I'll use them. Thanks for the tip, Bane :)
 

DonStamos

Mobster Inc©
Joined
Sep 21, 2002
Messages
820
Location
United States
You just saved me a headache! :)

I'll have to find the tutorial on adding dummy buildings I saw last night.
 

DonStamos

Mobster Inc©
Joined
Sep 21, 2002
Messages
820
Location
United States
^^^That is indeed a great guide!

Two questions about the lua side, though:

1. How would I add a dummy building for each DOF? For example, let's say the when the decision in question is enacted, the civ currently has 3 DOFs with other Civs. The code above would give 1 building (hence 1 WC delegate). How would I have it give more than one if numDOF is more than 1?

city:SetNumRealBuilding(buildingDelegateID, 1)

This is from JFD's Arminius civ. Could I just replace the 1 with numDOF?

2. How would I take away dummy buildings if a DOF runs out? I know I use the save(pPlayer) tag to ensure that it remembers the decision was taken, but how would I have it check the number of DOFs each turn?
 

DonStamos

Mobster Inc©
Joined
Sep 21, 2002
Messages
820
Location
United States
I think it's on an on-turn basis. I know the load check is to see if the decision has already been enacted or not.

Hm. So I don't just stick "numDoF" in there? I need to make it send the number itself to that spot? (sorry if I seem a bit dense here)
 

bane_

Howardianism High-Priest
Joined
Nov 27, 2013
Messages
1,559
No problem.
I said 'yes' as an answer to your question: "Could I just replace the 1 with numDOF?"

I don't know how Sukricat's Decision works. My point is, every time the code runs, the variable will correctly reference the number of DoF.
At least that is what I can assume, since I haven't read your code.
 

LeeS

Imperator
Joined
Jul 23, 2013
Messages
7,241
Location
Illinois, USA
If the number of declaration-of-friendships* decreases, I'm sure JFD's numDOF will reflect that, since I haven't hardly ever seen him oopsie on a lua-code he's passed along to other folks. What I am not sure of is if the <Buildings> column <ExtraLeagueVotes> "stacks" for multiple copies of the same building added to the same city. That is something I haven't had a chance to verify one way or the other for my most-recently offered reference/tutorial/guidance on issues related to dummy buildings and building-class structuring.

Nor have I experimented with whether or not <ExtraLeagueVotes> is truly 'adaptive' in the sense that going from 4 dummy buildings in a city to 3 dummy buildings in a city will decrease the number of votes. That itself should be easy enough to verify, though, by simply adding and taking away the Forbidden Palace from a city to see if the extra votes disappear, once a situation is created in a test-game where the World Congress has started to convene.

[edit]merry-jingle-happy-feliz to uno and all, and to all a good mod, er, Knight, or something :xmastree:

* = *sigh*, typos. I wrote delegates first time around, which really would ought to have confused the issue right proper. *sigh*
 

LeeS

Imperator
Joined
Jul 23, 2013
Messages
7,241
Location
Illinois, USA
I can attest to that, as my Crane Civ uses dummy buildings with that column.
Both "stacks" and is "adaptive" ?

And I can see I may have to add a column in that newer ref/tut for whether a column is "adaptive" :)
 
Top Bottom