1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

Fixing Quests

Discussion in 'CivBE - Mod Development' started by Ryoga, Nov 4, 2014.

  1. Ryoga

    Ryoga King

    Oct 12, 2010
    -Updated to winter patch 2015

    This is a project that fixes several bugs and addresses several problems concerning the affinity quests of Civ BE. The December 2014 patch solved some problems, didn't solve several others and in quite a few cases it created even more issues than before.

    Here is a brief list of what was changed\fixed:

    -Familiar Exotics Chapter 2 (Reverted to my pre-patch fixed version, because Firaxis' solution makes it way too easy, and it still doesn't fix the illogical rewards)
    -An Elemental Fate (Xenomass now respawns at the end of the Harmony path)
    -Cultural Burden (Firaxis' solution was too radical. With this mod it works like the new version when all the 8 sponsors are present and it works like the old version when there are 7 or less)
    -Point of not Return Null (Fixed two critical bugs, because Firaxis solved the issue and broke the script at the same time)
    -Acclimation (Fixed the "city must be near canyon" check)
    -Pure Advantage (Reverted to its original version, because Firaxis managed to put a critical bug in a quest that was fine as it was)

    AffinityQuestManager.lua Fixed a line that causes the code to check quest eligibility in the wrong place. Fixed a critical issue, from the patch, that prevents quests from being assigned to human players.

    If you want to know more:

    Spoiler Detailed Explanations :

    I changed just a line here. The major bug was fixed, but somehow the check for canyons near cities to determine eligibility was not. This is odd because the quest "Ancillary Adams" and its related objective, which use a similar routine, were fixed exactly like I did. Anyway this is a very minor issue.

    An Elemental Fate:
    Firaxis fixed this quest as much as I did with the previous version of this mod. This time I simply made a change in response to a request. Since this quest entails the destruction not only of an alien nest but also of the precious Xenomass below it, the Harmony "reward" is a bit underwhelming when you consider that you lose a precious resource, especially if it is one of the rare spots with 8 or more units.
    Now with this fix when you complete the Harmony path the Xenomass pool will return exactly as it was before.

    Cultural Burden:
    Firaxis solved the issue with a very drastic measure by cutting away several parts of the code and changing several texts of all the languages available.
    Rather than picking a random sponsor among those that aren't in the game the quest now just have zero randomness and always "chooses" "Cestus Group" as the involved sponsor.
    Personally I liked the idea of the original quest, it was fun to see how the rival of a previous game died in space in the next one, and I think this drastic change is completely unnecessary, especially considering that I had already fixed it in a similar way but without removing the cool part.
    So this time I endeavored to revert the quest as it was before after my bugfix. This wasn't an easy task because I had to retrieve all the texts that were changed and I did so for all the available languages.
    I changed my "Unity Expedition" as the fallback sponsor for when all the 8 official ones are present to "Cestus Group" which is what Firaxis picked for their fix.

    Familiar Exotics Chapter 2
    Here again Firaxis chose a drastic and somehow unsatisfying solution. It replaced "Biofuel plant" with "Vivarium" for the purity building and "Petrochemical Plant" with "Alien Preserve" for the supremacy building.
    I really think that the way I had fixed it, by simply removing the specific city requirement, was a lot better. There is absolutely nothing in the text that suggests that a specific city must be selected (such as in "Point of no return null") so why not simply removing that? Of course with my method the quest might still be impossible to complete in some unfortunate circumstances (no petroleum in any nearby area or no algae because it is an all land map), but it think it is reasonable enough. The main issue I have with Firaxis' solution is the fact that the Harmony path still requires a Xeno Sanctuary, which is a very advanced building. The gap is too big and unfair for the Harmony factions.

    Point of no Return Null and Pure Advantage
    I'll explain these two at the same time because Firaxis changed them both in the very same way and made the same horrible mistake in both.
    From one side I feel like praising their effort for creating a brand new API (I think it's new) to check if a city has a workable resource of a certain kind in its borders. They basically decided to solve the issue of non completable quests because of non completable buildings by checking for eligible cities before assigning those quests. So basically their idea was "if there isn't a city with a workable firaxite nearby then simply the player won't get the quest 'Pont of no Return Null'".
    And that's fine, nothing wrong with that.
    But this, this makes me cringe:

    local firaxiteType = GameInfo.Resources[RESOURCE_FIRAXITE].ID;
    Because that "RESOURCE_FIRAXITE" needs to be enclosed by quotation marks or the code simply doesn't work and the whole script crashes.
    So what happened is that they tried to fix a quest that in many cases couldn't be completed and made it impossible to complete in ANY cases.

    NOTE: This particular error was fixed in the 2015 winter patch, However...

    That isn't even the only problem. Instead of making sure that the selected city has a workable resource of Firaxite, the code makes sure it doesn't!

    What's even worse is that they repeated the very same mistake with "Pure Advantage". In this case the quest requires a building that requires workable resilin.
    But this quest doesn't even have a specific city requirement! You can build the building in any city, you can even found another city near resilin or conquer one if you are in a pinch.

    So well... I simply reverted it as it was before. As for "Point of no Return Null" I simply added those quotation marks and adjusted the check.

    I could say a lot about this one, but... let's just not. Suffice to say that the mess that the new code created makes any previous issue related to affinity quests pale in comparison. It practically killed the whole system! The only reason it didn't completely kill it, it's because, comically... or tragically, the old bug wasn't fixed. Somehow the old bug reduced the damages of the even worse new bug.

    I chose quite an unorthodox method to "fix" this mess. Well first I fixed the lines that I fixed in the old version so all the checks are done in the right places.
    Then, since the new code wants AI to get the same amount of affinity quests that the players get, I created one specifically for them, and they always get that every time.

    Now the question is whether AI are supposed to get affinity quests or not. I decided to let YOU decide which is the answer. By default in this mod, AI keep getting the new quest, but then the quests aren't processed and therefore they won't complete them and they won't get any reward.
    However by simply changing a line in the XML file "Quest_Fix.xml", "<IgnoredByAI>true</IgnoredByAI>" to "<IgnoredByAI>false</IgnoredByAI>", AI will automatically complete the quests after a certain amount of turns. More of that later.

    With this system the issue is solved in whichever way you might prefer.

    This is an optional feature. By default AI cannot get affinity quests, and even if they get them, they can't complete them. And when I say that they can't complete them, I mean that there is a specific code that prevents them from doing so.
    Now whoever changed the file "AffinityQuestManager.lua" in the December 2014 patch obviously thinks that it's unfair for a player to get more affinity quests than the others. It's unclear if he only meant that for human players and forgot to prevent the check from considering AI or if he didn't notice that AI aren't supposed to get ANY affinity quests.
    At any rate the result is that as long as there is even ONE AI in the game, human players will only get a few basic quests before turn 100 (normal speed) and then NOTHING for the rest of the game.
    Without this mod 18 quests are made completely unavailable. And this was from a patch that was supposed to fix everything.

    Now by default this mod assigns to AI a custom quest that I created called "Quest For Special Kids Only". However the quest will never be completed. If you think that AI should be allowed to complete it, then you need to change the value of the tag "IgnoredByAI" from "true" to "false". You can see a detailed explanation on how to do that by looking at the picture attached.

    The "Quest For Special Kids Only" is an affinity quest specifically designed for AI and their "differently smart" behavior. Basically AI will be rewarded for the praiseworthy achievement of not getting themselves killed before a certain amount of turns. The amount of turns is equal to the value "AFFINITY_QUEST_MIN_TURNS_BETWEEN_QUESTS" (modified by game speed) which can be found in the "GlobalDefines.xml". So AI will always complete their quest before they get another one.

    Upon completion AI will be rewarded with affinity points (same as the human player) plus one among many different yields (science, culture, energy, food, production, etc) which mirror the same rewards that the human player normally gets.
    Moreover once AI reach level 4 or more in their dominant affinity, the quest will reward them by spawning a related affinity resource with 6 units near their capital (regular quests for the human player may give something like that so it's fair), and if they don't have titanium, they get 4 units for free.

    AI can receive this quest a virtually infinite amount of times, but they may have only one special resource reward near their Capital (they may get a second if their capital is forcibly relocated to some other city).

    I have no clear idea how letting AI get and complete affinity quests will affect the game balance, certainly I expect them to gain affinity points faster (duh), so difficulty will probably increase.

    For detailed explanations of my work on fixing affinity quests before the patch:

    Spoiler Old Log :

    I have started with the infamous "Familiar Exotics".
    I started with the idea of simply removing the City requirement for the buildings, so that the quest could be completed by building them anywhere.

    Little did I know of the unspeakable mess that I would find...

    First off The script is filled with vestigial codes. There are several mentions of vivariums, growlabs and pharmalabs. This suggests that the code was changed and tampered with several times, with the buildings being changed probably during the balancing phase. Even so they still managed, as you know, to choose the wrong buildings in the end, as they have very strict requirements which in one case makes the quest impossible to complete and in the rest it makes it extremely unlikely to be completed before the end of the game.

    Because of that there are obvious cases of variables being assigned to the wrong places. For example the quest log clearly states that the Purity path will give food while the Supremacy path will give energy, this is written everywhere in the code too, but guess what? The reward is set so that Purity doesn't give any food while Supremacy does.
    The rewards are clearly inverted.

    Finally there's the worst bug of all. Perhaps you are among those fortunate few that actually managed to get workable oil in the capital. So you built that petrochemical plant you got your Supremacy affinity points and you thought it was all right.
    Well it wasn't.
    Because you are also supposed to get a reward screen and the quest should be marked as completed. But nothing of that happens because the next line is wrong and it crashes the script.

    So in the end the fixed file:

    1) Removes the specific city requirement. The quest will be completed upon building the "biofuel plant" or "petrochemical plant" regardless of the city.
    2) Swaps Supremacy's food reward with Purity's reward. (Purity still gets the science reward as it is hinted by the quest log).
    3) Fixes the bug that caused the script to crash.


    Fixed "Cultural Burden quest". The script is included in the attachments.

    This one was easy but the error is absolutely ridiculous.
    The code has a subroutine that checks all the factions and picks one that isn't present in the game. That faction name is then used in the quest logs.

    Somehow the programmers didn't think that this subroutine could give no results... such as in any games where all the factions are presents.

    How could they not imagine that is beyond me.

    Anyway I had to come up with a fallback name in case the subroutine returns nothing. I opted for "Project Unity" which refers to the colonization project from Alpha Centauri.


    It turns out that "Dogmatic Engineering" is fine, or so it seems, the real issue comes from an error in Affinity quest manager, a bug that I reported here.
    It was a single variable but it causes the quest "Dogmatic Engineering" (among others) to be assigned to AI (even though it's set on "ingoredbyAI") which causes stations to pop unnecessarily.

    Fixed a critical error in the Supremacy Path of "An Elemental Fate".
    This is actually one of the coolest quests of the game with some unconventional reward.
    The Supremacy path would cause the script to crash because of not one but several bugs, moreover it incorrectly told you that by making an expedition the quest would fail.
    Everything was fixed.

    Fixed "Point of No Return Null" quest.
    The quest itself doesn't have any bugs, as far as I could tell, but in spite of a check for eligible cities, it doesn't check if a city can ever build the required NeuroLab.
    Though it is still technically possible to complete the quest through a high level satellite, the likelihood of that happening before the end of the game is very slim.

    I reworked the quest in a way that instead of starting when selected it gets flagged and queued (as a few other quests already do).
    The quest then starts as soon as an eligible city can build a Neurolab and it picks that precise city instead of a random one without firaxite.


    Today I've been looking into the "Acclimation" quest which was reported to have a bug.

    I was able to replicate the error and I found out that this is a particular case where both the first and second objective require to complete a building. This caused the script to enter in an infinite loop in case the second building was completed first.

    I have simply moved a check before the cycle can enter into the loop and my tests showed that everything was working correctly.

    Though the system is so complex that I can't be 100% sure that moving the check into that position will not cause yet another bug.

    My tests say it doesn't, but... who knows...

    Besides I've found another bug in the same script.
    There is a routine that checks if the player has a city near a canyon. The conditions were incorrect and it caused to miss certain hexes from the checks. So the script was not considering eligible cities which had the right requisites.

    Because the routine is the same as in the "Ancillary Adams" quest, I realized that there was an error there too and in its related questObjective script as well.

    Those are just minor fixes and the quest can be completed anyway, but since the point of the quest is to remove any forests around your cities, then you should remove all of them and not all of them excluding those that were ignored because of a bug.

    Besides there is an inherent problem in the check, since apparently there isn't any event controller for clearing forests, the script makes the check every time an improvement is completed instead. Close enough I guess and it should happen fairly often.


    Finally I addressed a bug that was reported here.
    This turned out to be the very similar issue to the one that affects the "Acclimation" quest.

    I can explain the problem better now that I have a better understanding of how the quest system works.

    Basically the whole system stands on the constant danger of entering into an infinite loop. To prevent that from happening, every block of a quest flowchart starts with a check, if that particular part of the quest was completed it skips to the next part.
    Without this check every single quest would enter into an infinite loop.

    In the case of "Written in Stone" the issue is not that it enters in an infinite loop, but that the check prevents some part of the script from being executed as they are supposed to.

    That happens whenever the second objective of the quest is already completed when the first is, exactly like in the "Acclimation" quest.

    Simply moving before the potential looping point the part of the script that gets left out solved the issue.

    Due to the increased complexity of this mod, manual installation by replacing files is no longer available. This is no longer a mere fix, it's a mod and it must be installed and used as a mod.
    Simply download the file attached and put it in your Civ BE mods directory.

    There is a known bug that prevents modded quests to be loaded successfully in the game if your windows username contains non standard characters. Should you encounter this problem, you can create a different account to play the civBE (easy but unsatisfactory solution) or you can follow the guide posted by Makshow here.

    In case you still find bugs:
    Bugs are an inevitability, whatever program you create, if sufficiently big, there will be bugs, it's an universal law. The only thing you can do is swat them when you find them.
    If you still find bugs, please report them adding as many details as you can.
    Best you can do is providing a saved file of a turn (or some turns) prior to the occurrence of the bug, I'll try to address the problems and fix those as well.

    Attached Files:

  2. terraslayer

    terraslayer Chieftain

    Sep 13, 2010

    Dude, you rock!
  3. solinda

    solinda Chieftain

    Oct 26, 2014
    If I had the power to hire you as a Test Engineer, I would. Good job with this.

    I hope you did test it though :p

    I am giving it a try now and will report any bugs I find.
  4. Ryoga

    Ryoga King

    Oct 12, 2010
    All right...

    From one side Firaxis makes things "modular" with modders in mind, from the other side they completely forget that mods are supposed to go into their own directory. So they had this wonderful idea of making the code check for files inside the game path!

    Luckily Vice Virtuoso already saw to that and fixed the issue.
    Or rather a part of the issue.

    The single quests and objectives work fine, but now I need to struggle on how to implement the modified "AffinityQuestManager.lua".

    Simply uploading it into the mod and making it override the existing one won't do, of course. Because then its path is the mod path and then when it calls for other functions everything is messed up because they assume the file is inside the game directory.

    And all it needs to do is fix a single line!!!
  5. Lanth

    Lanth Warlord

    Sep 16, 2007
    These bugs, more than anything else, are testament that the game was rushed out the door with a lack of care. If it were just 1 or 2 bugs, or only affected rare quests (some of the ones listed here, I've not seen) that'd be one thing. But some of these quests turn up (nearly?) every game and are obviously broken.

    Good job anyway.
  6. Vicevirtuoso

    Vicevirtuoso The Modetta Man

    May 14, 2013
    The Wreckage, Brother
    From what I can gather, AffinityQuestManager is added in through a regular include() in QuestSystem rather than the dofile() function used for scripts, so it shouldn't be path-dependent. Adding it to your mod with VFS = true doesn't work?
  7. Ryoga

    Ryoga King

    Oct 12, 2010
    Forget everything I said, I'm an idiot, it was an error on my side.

    Yeah it works fine now:lol:

    BTW thanks for your modular script.

    Okay all done, the mod is completed.
  8. darkedone02

    darkedone02 The Suggestor

    Mar 9, 2006
    Louisville, Kentucky
    See if you can add this up on the steam workshop as well.
  9. Ryoga

    Ryoga King

    Oct 12, 2010
    Already done


    Hopefully this is going to become unnecessary very soon. Once the patch will be released I'm going to recheck all the errors that I found to see if they actually fixed them all.
  10. Ryoga

    Ryoga King

    Oct 12, 2010
    All right the patch has come and I promptly checked whether Firaxis really fixed all the bugs and problems that I found.

    Here I'm going to report what I could surmise from the changed files. Note that I haven't tested anything, but the changes in the code should be proof enough that they fixed the problems, I mean they can't possibly have made changes without checking if they fixed the issue right?


    Familiar Exotics (Chapter 2)
    Firaxis here went for a very radical solution and completely changed the required buildings.
    Now a Vivarium is needed instead of a Biofuel plant (vestigial code suggests this was the original idea)
    An Alien Preserve is now needed in place of a Petrochemical Plant

    The bug that caused the script to crash on completing the Supremacy Path has been fixed. However the illogical reward system has not. You get food and population for the Supremacy Path and Energy for the Purity path even though the text suggests otherwise... oh well...

    The check that failed and caused the script to enter into a loop has been completely changed. This presumably means that it is now fixed.
    The Canyon check However hasn't changed (more of that on the next quest).

    Ancillary Adams
    The Forest check both in the "quest" file and the related "objective" file has been fixed in the very same way I fixed (which is the only logical way).

    Now note that this is the exact check system that is used in the Acclimation quest, however no change was made there. I can only think that it slipped through their "to do" list.
    That being said it is a very minor issue and you will never notice any problem, it just makes it less likely that you will get "Acclimation" as your affinity quest, because it requires a Canyon near one of your cities, and the check is messed up. (It will still work for the most part).

    Elemental Fate
    The bug that caused the script to crash on the Supremacy Path has been fixed.

    Cultural Burden
    Here, again, Firaxis opted for a very drastic solution. Instead of checking for a missing faction and use that as "the faction that never reached the planet", they put by default a never mentioned before "Cestus Group" (Who?)
    Honestly I think this was unnecessary. I did basically the same thing by creating a fallback faction called "Unity Expedition", but whenever one of the main factions was actually missing, the code worked as intended and picked one of them.
    It's kind of sad that you'll never ever see a quest telling you that the Arc or Brazilia died in space before reaching the planet.

    Point of no Return Null
    Now the script has more strict rules for eligibility. There must not only be a non capital city that has yet to build a Neurolab, it must also have a workable Firaxite in the vicinity, which effectively solves the problem.

    Written in stone
    This was fixed in the exact same way I fixed it, by simply moving a part of the code.

    There have been major changes in this script, and I haven't really checked what exactly they entail.
    The only certain thing is that now the affinity quest assignment works under different rules.

    However it still baffles me that the line that I found wrong wasn't changed, and as far as logic goes, it should still be wrong.
    I have no idea what to think about this.
  11. Ryoga

    Ryoga King

    Oct 12, 2010
    Quest Fix updated

    It is even more voluminous than it was before patch.
  12. TLHeart

    TLHeart King

    Oct 15, 2005
    Thank you for correcting the broken fixes.
  13. Paszczak

    Paszczak Warlord

    Dec 23, 2013
    Back in my day modders added new stuff to games :old:

    Now they're busy fixing bugs :(
  14. player1 fanatic

    player1 fanatic Fanatic

    Mar 19, 2002
    Belgrade, Serbia
    Back in the day I was also making bug-fixer mods for Neverwinter Nights 2 and Rome Total War.

    There was always need for fixing bugs with moding.

    Usually the more open game is for moding the greater chance is have bug fixing mods, since modders can then actually see bugged code, unlike some other games.
  15. Gritf

    Gritf Chieftain

    Jan 13, 2015
    I Ryoga, I'm a big fan of your mod, exactly what I was looking for since I first played the game. After some fiddling and reading your threads and those of ViceVirtuoso I came up for a solution to the bug of some people no receiving any quest from the start of the match... sorta.

    In the lua.log, there was this error message that the game couln't locate you custom lua file from the mod, since it was looking at C:/users/"username"/Documents etc. Since my user name is Adrián with an accent, the whole procces didn't occur since it can't read foreign characters, the lua wouldn't load when the game started.

    I'm not a modder myself, just barely code macros for work, so I just created an additional account on my Windows just to play with your mod, one whose username doesn't use accents and it worked. Maybe you and other modders could work on a more general solution.

    I'll try to come back tomorrow with a copy of the log, since it is 2 a.m. and have to reproduce the error again. From now on I'll enjoy your awesome work and post other bugs I might find. Thank you
  16. Ryoga

    Ryoga King

    Oct 12, 2010
    Oh man... I totally didn't expect an issue of this kind...
    Yes if what you say is true than I can totally see how that can cause problems, but again this is an overlook from Firaxis.

    I'm glad you told me about this, I had no idea, however here the issue lies with the system used in QuestSystem.lua. The "affinity quest fix" mod doesn't even use a modified version of that it simply makes use of the one updated with the latest patch which was supposed to guarantee total mod compatibility.

    Anyway fixing "QuestSystem.lua" is something that ViceVirtuoso's mod is supposed to do.


    Alright I was able to confirm that the system to load modded quests fails if the Windows user name contains non standard characters.
    Unfortunately this is also true for the current version of Vice Virtuoso's mod. The problem lies in the "dofile" function, which I don't quite know where it is located. If it's in the C++ code, then we are simply screwed.

    I'll relay this information to Vice Virtuoso, maybe he can think of something, but I don't have many hopes for this...
  17. Gritf

    Gritf Chieftain

    Jan 13, 2015
    Hi, here's my log, winrar'ed since the forum doesn't allow for *.log files. After switching to a windows account without weird characters the game and your mod works wonders (except for occasional freezes between turns but that was always been happening for many people wether modded or not).

    I noticed a few minor instances when I suddenly got extra levels of affinity for apparently no source and once I got an autocomplete in a single mission which I can't remember right now. I'll keep playing and write down if it happens again.

    Thank you again and sorry for my engrish.

    Attached Files:

    • Lua.rar
      File size:
      6.6 KB
  18. Ryoga

    Ryoga King

    Oct 12, 2010
    Thanx Gritf. If you encounter again a problem the thing that will help me the most is a saved file one or few more turns prior to its occurrence.

    You can use the autosave function for that and then send the files explaining the problem.
  19. Gritf

    Gritf Chieftain

    Jan 13, 2015
    Hi again. I checked again my games, and it turned out it was ok, since some quests like "Leadfoot soldier" are ment to autocomplete.

    However, I think I saw a minor oversight. The quest "Point of No Return Null" still requires a firaxite source in a specific city, regardlees if there is the source or not. At least is just something else to add to the list and not a source of headaches XD.

    Maybe it was meant as a way to ask for the orbital fabricator.
  20. Ryoga

    Ryoga King

    Oct 12, 2010
    Firaxis created a specific code that is supposed to check if a city has a workable Firaxite in its borders. I have no way to determine if it is 100% flawless, but as long as I don't have evidence of the contrary I'm going to assume it is.

    If you can provide evidence of that, by all means send me a saved file. That way I can try to figure out why it failed.

Share This Page