I want to give a specific number of affility points

Joined
Jun 27, 2007
Messages
2,248
Location
Hamilton, Ontario
Looking at QuestRewards.lua it seems like affinity rewards are always equal to whatever the next level requires. However I want to give less than what a level up would require. Specifically if I had a quest that occurred so early that giving a full level would be unbalanced, I would want to give 10 points which isn't even enough for get to level 1.
So is there a way to give a specific amount and not an amount adjusted for level? A better way would to get the requirement for level 1 and then subtract 1 so it would work the same if someone changed level one requirements, but I'll take what I can get.
 
TopPanel.lua (or in this case the included InfoTooltipInclude.lua) file is your friend.

Mouse over the affinity icons and the tooltip at the bottom tells you how far you are towards the next level and what that level occurs at, so you just need to find that code

Code:
local iAffinityType = GameInfoTypes.AFFINITY_TYPE_HARMONY

-- What are the current values for this affinity
local iCurrentScore = pPlayer:GetAffinityScoreTowards NextLevel(iAffinityType)
local iNeededScore = pPlayer:CalculateAffinityScore NeededForNextLevel(iAffinityType)

-- Take them to one shy of the next level
pPlayer:ChangeAffinityScore(iAffinityType, iNeededScore - iCurrentScore -1)
 
Actually I was looking for how to do one less that the first level i.e. going from 0 to 1. I should probably just enter it manually. If someone else wants to do the same thing they're probably better than me and would have no trouble changing it themselves.
However going to the interface lua gives me a lot more code to look at for hints.

Anyway, I'm not sure what I want to do is even possible. Putting affinity gains on building choice quests. BuildingChoiceTemplateQuest.lua looks like this:

Code:
BUILDING_CHOICES_TABLE[GameInfo.Buildings["BUILDING_RELIC"].ID] = hmake BuildingQuestStruct {
	TitleTextKey = "TXT_KEY_QUEST_BUILDING_RELIC",
	BodyTextKey = "TXT_KEY_QUEST_BUILDING_RELIC_BODY",
	SummaryTextKey = "TXT_KEY_QUEST_BUILDING_RELIC_SUMMARY",
	ChoiceA = hmake BuildingChoiceStruct {
		ID = 1,
		Text = "TXT_KEY_QUEST_BUILDING_RELIC_CHOICE_A",
		Epilogue = "TXT_KEY_QUEST_BUILDING_RELIC_CHOICE_EPILOGUE_A";
		Flavor = GameInfo.Flavors["FLAVOR_ENERGY"].ID,
		RewardPerkType = "PLAYERPERK_RELICS_FREE_MAINTENANCE";
	},
	ChoiceB = hmake BuildingChoiceStruct {
		ID = 2,
		Text = "TXT_KEY_QUEST_BUILDING_RELIC_CHOICE_B",
		Epilogue = "TXT_KEY_QUEST_BUILDING_RELIC_CHOICE_EPILOGUE_B";
		Flavor = GameInfo.Flavors["FLAVOR_CULTURE"].ID,
		RewardPerkType = "PLAYERPERK_RELICS_CULTURE_FLAT";
	}
}

RewardPerkType is looking at an xml field, not code from lua and there is nothing in the CBEPlayerPerks xml for adding affinity exp. It doesn't look like it would accept code in RewardPerkType. Looking in SteelSynapseQuest.lua it looks like this line is where affinity points are actually applied:
Code:
local function AddRewards(quest)

	local rewards = {
		Affinity = QuestRewards.Supremacy(),
		Yield = QuestRewards.Science()
	}

	MergeTable(rewards, quest.PersistentData.Rewards);
	quest.PersistentData.Rewards = rewards;
	rewards = {}
end
Although I could be wrong and I don't think I can just copy and paste that in after RewardPerkType and have it work.
 
Actually I was looking for how to do one less than the first level i.e. going from 0 to 1.

The absolute value is

Code:
GameInfo.Affinity_Levels[1].AffinityValueNeededAsDominant - 1

If you want to take into account any points the player already has towards a particular affinity, the code posted above still works
 
I don't think I can just copy and paste that in after RewardPerkType and have it work.

No you couldn't. You'd need to change a lot more of the core code, such that a reward from a building is either a PlayerPerk or the outcome of a function call. Not hard but requires Lua knowledge (and a basic understating of the Quest system).

I've already butchered the BuildingChoiceTemplateQuest.lua file to put all the quest details into the database (see "Utils - Tabulated Building Quests" in my pick-n-mix mods thread) - if I find time I'll take a look and see if the rewards can be extended to calling a LuaEvent to get the reward
 
Thanks. I'd think this could.be done via the source code too but we don't have that yet. Also it would be better to keep quests modular and easy for other people to incorporate into their own mods.
The patch notes said something about making modding of quests easier but I'll probably work on something simpler until more information is available.
 
Also it would be better to keep quests modular and easy for other people to incorporate into their own mods.

"Utils - Tabulated Building Quests" is a modular system (much like Utilities - Modular Script Loading)

V2 now supports dynamic (Lua based) granting of rewards, see the "Quests - Headquarters Affinity" example in the same thread
 
Is it possible to add more definitions into BuildingChoiceStruct? (Sorry if this not the correct name for this, I am no programmer) I wanted to achieve the same thing by adding two definitions into it: AffinityType and Points. After writing the necessary code, I get a Syntax error, which tells me, that BuildingChoiceStruct already has a different definition and points me to line 14 (which would be end). Here's what I meant:
Code:
local QuestScript = hmake CvQuestScript{};

----------------------------------------------------
-- Definitions
---------------------------------------------------- 
hstructure BuildingChoiceStruct
	ID : number
	Text : string
	Epilogue : string
	Flavor : number
	RewardPerkType : string
	AffinityType : string -- NewHorizons --
	Points : number -- NewHorizons --
end
 
BuildingChoiceStruct is almost certainly a C++ data structure that is being exposed to Lua, so it won't be possible to add new members to it (without access to the DLL C++ source code)
 
BuildingChoiceStruct is almost certainly a C++ data structure that is being exposed to Lua, so it won't be possible to add new members to it (without access to the DLL C++ source code)
Well drats ;) I already thought so, but you never know... Thanks alot for the answer!
 
Back
Top Bottom