What triggers quests?

kingsbury

Warlord
Joined
Oct 26, 2014
Messages
174
I have yet to find any good information on how to trigger quests. I know the building quests are in some way triggered by building the building, but beyond that is it just a random time afterwords?

The civlopedia is lacking on this type of information unfortunately and when I google it all I get is reviews since the game has only been out for a few days.
 
Building quests seem to have a random chance to trigger after the building is built. Unsure if there's a minimum time before it triggers, but there doesn't seem to be a maximum, either. I guess I don't have preserve random seed (I'm using whatever the default is), and sometimes I find that when I reload a previous auto-save, I'll get a building quest upon loading that I hadn't had when I played through the first time.
 
I can say with near certainty that you have a 5% chance of triggering any available building quest each turn. If you go to assets\Gameplay\Lua\BuildingChoiceTemplateQuest.lua and open it with something like Notepad++, you can find this field: local TRIGGER_CHANCE = 5;. I changed the value from 5 to 100, saved, and reloaded the game; after completing a Clinic and Old Earth Relic, both of them gave quests immediately on the turn they were finished. Changing it to 0, I never received quests for any buildings.
 
I think you can only get 1 building quest per turn, though.

Would be nice if they had a maximum time length on them.
 
I can say with near certainty that you have a 5% chance of triggering any available building quest each turn. If you go to assets\Gameplay\Lua\BuildingChoiceTemplateQuest.lua and open it with something like Notepad++, you can find this field: local TRIGGER_CHANCE = 5;. I changed the value from 5 to 100, saved, and reloaded the game; after completing a Clinic and Old Earth Relic, both of them gave quests immediately on the turn they were finished. Changing it to 0, I never received quests for any buildings.

Thanks for this info. I think I am going to give up on the institute building quest as an essential part of any strategy if it really is a 5% chance of triggering every turn.

*edit* does anyone have any info on what triggers the alien nest quest?
 
Sorry for the late response, I've been out.

*edit* does anyone have any info on what triggers the alien nest quest?

This is the Occupational Hazard quest, right? You choose to either Domesticate or Eradicate wildlife, and if you choose to eradicate, you must destroy two nests for Purity points. In that case:

Code:
	-- Calculate the probability we will start a quest this turn
	local probabilityPerTurn : number = 100 / (maxTurns - minTurns + 1);
	local probabilityThisTurn : number = probabilityPerTurn * (turnsSinceLastQuest - minTurns + 1);

	-- Roll to see if we start a quest
	local roll : number = Game.Rand(100, "Choosing to do an affinity quest player " .. playerType);
	if (roll < probabilityThisTurn) then
		return true;
	end

	return false;

	--return roll < probabilityThisTurn;

It later redirects to a few entries in GlobalDefines.xml

Code:
<Row Name="AFFINITY_QUEST_MIN_TURNS_BEFORE_INITIAL_QUEST">
<Value>8</Value>
</Row>
<Row Name="AFFINITY_QUEST_MAX_TURNS_BEFORE_INITIAL_QUEST">
<Value>12</Value>
</Row>
<Row Name="AFFINITY_QUEST_MIN_TURNS_BETWEEN_QUESTS">
<Value>40</Value>
</Row>
<Row Name="AFFINITY_QUEST_MAX_TURNS_BETWEEN_QUESTS">
<Value>60</Value>

So this tells us that your first affinity quest can not come before turn 8 or after turn 12. It then uses the formula above to roll a random number between 1 and 100; if it rolls under the Probability value for that turn, you will receive the quest that turn. After you receive (complete?) that quest, you must wait at least 40 turns for the next one. It mentions that this does change depending on speed, but I don't know exactly how much (it uses the name gameSpeedQuestFrequencyModifier, which leads me to believe it's not quite the same as the other modifiers).

As for this quest itself, it seems to be random which Affinity quest the game chooses in most cases. I can't find any specific trigger in the LUA for it, while triggers do exist for some others.

tl;dr: I'm pretty sure it's random, with some conditions on which turns the quest can occur in.
 
Thanks for this info. I think I am going to give up on the institute building quest as an essential part of any strategy if it really is a 5% chance of triggering every turn.

Ya, I ran into this problem in my recent game. I built the institute atleast 30-40 turns ago and have yet to get my free tech quest...:(
 
tl;dr: I'm pretty sure it's random, with some conditions on which turns the quest can occur in.

I could be wrong, but I'm wondering if a more surefire way to get the building quest from the institute is to not build any buildings but the institute because there looks like there is some check of whether or not you have previously been given a quest.

*edit* I just made a game where I didn't build any buildings but the institute and it triggered the quest on turn 61.

*edit 2* something is really screwy with the code or something because now when I load the game on autosave to turn 51 it keeps giving me the institute quest as soon as it loads

*edit 3* now when I load the game on autosave on turn 41 gave me a quest on turn 51, but it was an affinity quest and not the institute quest. I loaded again and got the same thing. Still as confused as ever about the mechanics of quests.
 
Is it 5% per instance of the building, or just 5% globally? Would be nice if the probability increased as you built more of the building, then I could at least speed up that autoplant free TR
 
Tx for this info! The two most important ones (the free traderoute and the trade transports are immune to aliens) sometimes take so long! I'm probably not alone in the fact that the fence is one of the 1st buildings i build, just because the quest reward is so insanely OP!
 
I could be wrong, but I'm wondering if a more surefire way to get the building quest from the institute is to not build any buildings but the institute because there looks like there is some check of whether or not you have previously been given a quest.

The turnsSinceLastQuest check only applies for affinity quests, not building quests.

*edit 3* now when I load the game on autosave on turn 41 gave me a quest on turn 51, but it was an affinity quest and not the institute quest. I loaded again and got the same thing. Still as confused as ever about the mechanics of quests.

Pretty much all you need to know is that building quests are completely random (the probability is checked per-turn, rather than when the building is made), an affinity quest must spawn early, and you can't have affinity quests too close or far away from each other.


Is it 5% per instance of the building, or just 5% globally? Would be nice if the probability increased as you built more of the building, then I could at least speed up that autoplant free TR

I'm not sure on this one. I really feel like it's 5% per building, considering how often quests appear once you get some routes to your capital. You won't get two quests in one turn though.
 
No data other than personal xp, which admittedly could be luck of the dice going my way consistently so far.

The guy that found the 5% line seems pretty solid since he said tested it with 0 and 100 values to prove the impact of that variable.

But ill side with the .02 cents on it being 5% per building per turn. Maybe luck like I said but seems I get my alien fence and autoplant reward faster when I concurrently build more than one of them.

Knock on wood but in about 10 games total played, I've never waited more than 5-6 turns for either reverse polarity or +1 route rewards, frequently only 1-3 turns after my buildings are up.

Again, want to stress this is my provisional pov thoughts only. A mere ten games in first week of release is too small sample size for hard conclusions.
 
Pretty much all you need to know is that building quests are completely random (the probability is checked per-turn, rather than when the building is made)

Code:
-- Building Processed
function QuestScript.OnBuildingProcessed(playerID, buildingID, cityID, buildingAdded)
	
	if QuestScript.PersistentData.PlayerTriggerTables[playerID] ~= nil then
		local buildTableData = nil;
		for buildingTableID, buildingTableRow in ipairs(QuestScript.PersistentData.PlayerTriggerTables[playerID]) do
			if(buildingTableRow.BuildingID == buildingID) then
				buildTableData = buildingTableRow;
				break;
			end
		end

		if buildTableData ~= nil then
			-- data already exists, increment or decrement depending on whether the building is being added or removed
			if buildingAdded then
				buildTableData.TriggerChance = buildTableData.TriggerChance + TRIGGER_CHANCE;
			else
				buildTableData.TriggerChance = buildTableData.TriggerChance - TRIGGER_CHANCE;
			end
		else
			-- first building of its class, set base table data
			local newTableData = {};
			newTableData.TriggerChance = TRIGGER_CHANCE;
			newTableData.QuestStarted = false;
			newTableData.BuildingID= buildingID;
			table.insert(QuestScript.PersistentData.PlayerTriggerTables[playerID], newTableData);
		end
	else
		-- no player table for some reason
		error(string.format("No table for player %s in PlayerTriggerTables", playerID));
	end
end
GameEvents.BuildingProcessed.Add(QuestScript.OnBuildingProcessed);

-- Active Player Turn Start
function QuestScript.OnPlayerDoTurn(playerID)

	--print("QuestScript.OnPlayerDoTurn player " .. playerID);

	if QuestScript.PersistentData.PlayerTriggerTables[playerID] ~= nil then
		for i, buildingTable in ipairs(QuestScript.PersistentData.PlayerTriggerTables[playerID]) do

			-- Only check buildings that have entries in the BUILDING_CHOICES_TABLE
			if BUILDING_CHOICES_TABLE[buildingTable.BuildingID] ~= nil then

				if buildingTable.QuestStarted == false and buildingTable.TriggerChance > 0 then

					print("Rolling to start quest for Building: " .. tostring(GameInfo.Buildings[buildingTable.BuildingID].Type));
					local roll = Game.Rand(100, "Building Quest Trigger: player " .. playerID .. " BuildID " .. buildingTable.BuildingID);
					if (roll <= buildingTable.TriggerChance) then
						buildingTable.QuestStarted = true;	
						StartQuest(playerID, QuestScript.Info.ID, buildingTable.BuildingID);
						return;
					end
				end
			end
		end
	end
end
GameEvents.PlayerDoTurn.Add(QuestScript.OnPlayerDoTurn);

Basically, at the beginning of each turn, you have a (5 * number of buildings) percent chance* of triggering the quest. Curiously, I'm not seeing anything that would prevent two building quests from triggering on the same turn, though I've never seen it happen in-game.

*This is assuming that Game.Rand is 0-exclusive, max-inclusive, which is peculiar (programming convention is that random numbers are 0-inclusive, max-exclusive, meaning 'a random number, max 100' would mean '0-99'). I couldn't confirm whether this is the case, though; if it isn't, the chance would be 1% + 5% per building, but only if there is at least one building.
 
Building quests should always come up exactly 03 turns after producing/buying it for the first time [or in the 4th turn if you begin with said building, like African Union with OER or anyone with Clinic cargo]. At the very least there should be such option, so both those who like certainty [like me] and those who like randomness can be satisfied.

What does NOT satisfy me is loading tens of times for each building, in hopes of getting the quest asap [it works, but save-loading can become a grind when lady luck is not around]. I even give the game three turns before I start doing it, but sure as hell I won't leave it to chance and wait 30 turns for dat ultrasonic fence quest.

edit: omg, sorry for necroing this one, only now I notice what I did... :blush:
 
Top Bottom