Free Affinity Points from Virtue Kickers (Not Free Levels)

Barathor

Emperor
Joined
May 7, 2011
Messages
1,202
Does anybody know of any mods which add affinity points to virtue synergy bonuses?

Currently, there only exists free affinity "levels" of your choice, and percent boosts to affinity points gained from techs.

If not, does anybody know how to mod this in? Any help would be greatly appreciated -- anything. I can usually take off with just a little boost or a good, similar example to work off of.

What I'm looking for exactly is a new column added to the Policies table. I'll call it, "NumFreeAffinityPoints". When a player unlocks a synergy bonus or anything with this perk, a window (similar to the free affinity level one) pops up and allows them to choose their affinity. The chosen affinity gets +X affinity points added to the total. X is defined in the row data.

Within my project, I wish to take some affinity advancement away from technology, and properly make culture a major contributor as well. I don't like the free level rewards, because they can be hard to control. A free level early on is much less points than a free level later. (I'll reveal my overhauled tech tree soon; I'm finally satisfied with my solution to this puzzle and can take off with the rest of the project.)


EDIT:

I may have used the wrong term. To avoid any confusion, I meant the synergy bonuses which run vertically to the left of all the trees. Edited the text above.

Also, I'm going to check out Machiavelli's example mod, "Policies Grant Buildings and Perks".

I'm only accustomed to working with Lua within mapscript files (oh, and for new rewards using the plot bonus system). I've never created Lua mods which hook into GameEvents before. I assume I have to do this to get this new perk to work.
 
I have some (not yet fully implemented) code that lets Virtues grant Affinity points. But it doesn't meet your full requirements because it lets players get "X Purity points" rather than "X points that they can choose to put into Harmony/Purity/Supremacy".

It also doesn't yet work on kicker Virtues but the design can be expanded to work around that.

Starrynite was interested in similar functionality in this thread. I still haven't gotten around to fully implementing my framework so he may have eaten my lunch in that respect.
 
Thanks, Mach!

Question: Where are these GameEvents functions found? I tried digging through the Table Browser within FireTuner and couldn't find many -- I didn't even see PlayerAdoptPolicy or PlayerAdoptPolicyBranch. Are we limited to just having to search through the code for any examples?

So, basically, I create my own function in Lua, and then hook it into the game by using the appropriate, existing event function using: GameEvents.*EventFunction*.Add(*MyFunction*) I'm guessing it's added at the end of all the existing processes of that function.

I'm curious where they can be found because I'm not sure if I can use PlayerAdoptPolicyBranch with the synergy bonuses.

The synergy bonuses are called depth kickers within the code: Moderate, Devoted, and Extreme.

They're listed within the Policies table with the other ones and have ID numbers, but not within PolicyBranchTypes. Instead, they're within PolicyDepthTypes with their own ID numbers. I probably can't look over at the Civ5 source code for this because it's new in BE. I guess I could try "PlayerAdoptPolicyDepth"?

OR... maybe I don't have to worry about any of that and I only need listen for when a player adopts a normal virtue? Because, for any kicker to activate, the player always has to first choose a virtue within the tree anyway. Maybe I could hook in whenever any virtue is chosen something that checks if any of the depth kickers are active using player:HasPolicy(xxx) since all these kickers are listed within the Policies table. Then I just simply copy the popup code for "choose your affinity" and then I add the appropriate points to their total. But, then I'm not sure how I stop it from counting the same unlocked kicker more than once, each time a new virtue is unlocked.
 
Where are these GameEvents functions found?
There is no perfect source but there are a few places and ways to look.

The CivFanatics ModWiki has a list of events and game events for Civ5. It doesn't have all the events and what is in Civ5 isn't exactly the same as BE but this will get you 90% of the way there.

A brief note on Events vs GameEvents. GameEvents are fine to use but you want to be skeptical of Events. Events are generally tied to UI and often won't work as you expect. They won't always fire AI players or things the players can't see.

You can also search through the Beyond Earth code for events. For example there is an event that fires when a building is created or an orbital unit is launched.

I create my own function in Lua, and then hook it into the game by using the appropriate, existing event...
Yeah, the event determines when your own code will be run and defines what input information your code will have. If there isn't an event that does what you need you're usually out of luck.

For example, PlayerAdoptPolicy will fire when a player adopts a policy (but not when a player opens a branch). It will give you the playerID and the policyID. It won't fire for the kickers but as you describe there is a way to achieve that.

Whenever a player adopts a policy, check to see if they have the kicker -- using player:IsHasPolicy(xxx). If they do, give the bonus and mark that the bonus has been given already and shouldn't be done again. You can do this marking many ways, one would be to give the player a perk which does nothing.

There is a corner case with VirtueTierSynergyRequirementDiscount (currently only used by the Bytegeist Wonder) that could let a player get a kicker Virtue without actually acquiring the bonus until they got to their next earned Virtue.
 
I have a script that gives affinity gain to virtues, I can post it here later today. It doesn't let you choose which affinity you want the virtue in though, you have to assign the affinity. I also don't know how to make a new XML table entry, so it's just an lua script, but it works.
 
This code gives you 3 purity when you adopt Industry 4, as an example.

Code:
function OnPolicyAdopted (playerID, policyID)
	local policyInfo = GameInfo.Policies["POLICY_INDUSTRY_4"]
	local virtueID = policyInfo.ID
	local bonus = 0;
	local policyBonus = 3
	local Player = Players[playerID];

	if (policyID == virtueID) then
		bonus = policyBonus;
		Affinity_ID = GameInfo.Affinity_Types["AFFINITY_TYPE_PURITY"].ID;
		if (bonus > 0) then
			Player:ChangeAffinityScore(Affinity_ID, bonus);
		end
	end
end
GameEvents.PlayerAdoptPolicy.Add(OnPolicyAdopted);
 
Thanks, guys, I really appreciate the time taken to help, especially when you have your own projects!

I think I have a solid game plan; I'm going to take a different, simpler approach that's more at my current level (baby steps... haha), for now.

I was having difficulty trying to find a good example within the code of a "choose your affinity" popup window. I assumed it would be within the Lua file of the free level plot bonus reward, but it isn't and instead is probably worked into the function that's there: ChangeNumFreeAffinityLevels.

That, plus keeping track of the tier-synergy bonuses and not counting them more than once is a little tedious too.

- - - - - - -

So, I'm going to take a more direct approach and reward smaller trickles of affinity each time a certain virtue is adopted, so I don't have to worry about keeping track of them. Also, instead of creating a popup window asking a player to choose, I'm going to use a weighted, random affinity reward that's automatic. The weights work off of a player's existing affinity point totals. I may even work in a second influence that slightly manipulates the weights based off of the virtue tree's two favored affinities (Prosperity=PH, Knowledge=HS, Industry=SP, Might=PHS), but I'm not sure and I'm going to keep it very free and flexible right now.

This has the benefit of avoiding too many annoying popups during virtue selection, and introduces a little bit of randomness that a player has to adapt their strategy to. One already has enough control on which affinity they're rewarded via tech and quests, I think letting a player also choose their affinity each time from virtues wouldn't be as enjoyable. Also, getting bonus affinity in smaller batches immediately, instead of having to complete a bunch to activate synergy bonuses, is probably a more enjoyable route as well. My revised tech tree already does this as well; all techs reward flavorful affinity types, but in smaller amounts.

Once I complete it, I'll throw it up here in case anybody else is interested or wants to tweak it for their own idea.
 
You'd need to create a new interface element to have such a popup, that's relatively advanced. ^^

About your new idea:
That's of course personal preference, but I actually dislike the idea of having semi-random Affinity gains as a main source of Affinity.

There are many things that work great as "Something random happens so you have to adapt!", but I don't see Affinity being one of them unless you make a lot of changes to the general game design. There will always be one Affinity that I want and if I get other Affinity points instead it will just go to waste or give some other passive bonus while it delays my overall affinity progress - at least I can't see anything that I would do different as a reaction to getting some of the wrong Affinity in most cases.

I personally would instead prefer just getting Points for the dominant Affinity - that way one could steer the general Affinity-Gains via technologies AND it would also reduce the amount of "semi-automatic" hybridization that we currently have and that many people seem to dislike.
 
Thanks, man, I value your feedback. When I actually release a beta of this thing, I hope it'll interest you enough to give it a spin! It'll definitely need to be fine-tuned to get the pacing just right.

Yeah, simply rewarding XP to the dominant affinity is still on the table as a possibility (perhaps even more so now), and if there's isn't a dominant it would be a chance for the top two.

Above, I was thinking of weighted system where the lowest affinity is discarded and it creates a chance for the top two. Though, it wouldn't be exactly equal to the point proportions. I was thinking of an escalating weight multiplier the more dominant an affinity is. So, the more "pure" you are, the heavier that affinity type is when rolled for.

But still, there would still be chances for that secondary affinity XP, especially with an "unlucky" streak. And as you said, when you're working towards a specific affinity, getting bits of anything else is pretty much just an annoying delay and doesn't change your play.

With certain playstyles and especially leaders (like Elodie!), culture could certainly become a large chunk of overall XP. To not have enough control over it could certainly be bad.

You also have a good point about the "semi-automatic" hybridization that's forced on players, it's already difficult to not dip into the other affinities.

For bit more perspective on things, these are the available points so far and how they're spread by tier, not counting quest XP, excavations, other bonuses, and such:

Prometheus%2BAffinity%2BDistribution.jpg


Those numbers certainly aren't final.

Affinity level cost reference:
AffinityLevelCosts.png


I'm going to get back to work on finishing the tech tree, and then I'll tackle this culture system. I have a lot of numbers that I've come up with along with theorycrafting, but in the end, I just have to see how everything plays out and paces itself.
 
Sounds like you're giving it a lot of thought! And sure, I'll give it a try. :) Don't have much free time between working on my own mod and working on my drawing skills, but a few matches will certainly fit somewhere. ^^
 
Back
Top Bottom