Researching all Current Era's Techs Before Advancing to the Next Era?

Wow. So basically your "OR" prereqs set contains all of the original "AND" set, minus the inter-era prereqs? And the "AND" set is added with new prereqs to enforce the "one era after the other" rule. Smart. :)

;)

Now the first problem is that you did all of that through copy-pasting and you need a SQL. The second problem is your loading time but there is no reason we cannot fix that. When does the thing hang exactly? Could you try to insert print statements in the tech tree lua file and watch FireTuner to see which part is slow to load?

I'm not sure it's the actual LUA file that causes the long load time. I think it's the game trying to compile the tech tree itself, figuring out which techs are required to research other tech, etc. I had to raise the number of PrereqTechs in the GlobalDefines.xml file in order to do this. At any rate, my FireTuner doesn't want to load. It comes up with a "FireTuner2 has stopped working" message.

Now, to expand on this pure Lua approach, I need you to redo the tests I previously asked but without modifying the XML (I want the inter-eras prereqs to still be in the XML files). However, provided my guesses are correct, then the only thing you need to do is to prevent the UI to display those inter-era links, which is as simple as modifying line 107 and 150 as follow:
* Old: if tech and prereq then
* New: if tech and prereq and tech.Era == prereq.Era then

Well, I guess you should better start with that. Restore your XML prereqs to their original state (use the standard techs, not your custom tree for now if needed), keep the event code we used so far and make the changes I just described to techtree.lua. I guess the result will be almost good, minus a little problem that will appear if you click optics (not every tech in the ancient era will be lit up). Well, one step after the other.

EDIT: Nevermind the stroke part. Initally I assumed that civ5 was using the event for testing techs dependencies. I now understand it doesn't care at all and only deals with prereqs. And that we also have to modify them in order for API like Player.CanResearch to work. As a result I am now pretty certain that the "good way" to do it is to not change the OR prereqs set, add new prereqs to the AND set and use the display trick I detailed in this post.

Well, I tried this with the vanilla TechTree and it works. The eras are divided up into seperate trees, with the pipes missing between eras. Everything else works just as vanilla would, and load times takes 1-2 seconds.

The problem is, when I go to add all the PrereqTechs from the previous era (the techs at the "end" of a particular era tree) the game still takes 5+ minutes to load.

Some SQL code to add the missing prereqs. This is far to be optimized but since those queries are only ran once on startup, I guess this is not needed. Should I be wrong, though, there is room for improvements.

Spoiler :

Code:
/* Add new prereqs so that each tech from era N have all the techs from era <N.
*/
INSERT OR IGNORE INTO Technology_PrereqTechs
SELECT 
   TechType, PrereqType 
FROM 
        (SELECT Technologies.Type AS TechType, Eras.ID AS TechEra
         FROM Technologies INNER JOIN Eras 
         WHERE Technologies.Era = Eras.Type)
    CROSS JOIN 
        (SELECT Technologies.Type AS PrereqType, Eras.ID AS PrereqEra
         FROM Technologies INNER JOIN Eras 
         WHERE Technologies.Era = Eras.Type)
WHERE
    PrereqEra < TechEra


/* A table that contains T0 and T2 for all T0 -> T1 -> T2 dependencies 
   (T0 -> T1 is defined in S1, T1 -> T2 in S2).
   Also stores higher order cases such as T0 -> T3 since we do have T0 -> T1 (S1) and T1 -> T3 (S2). 
   Use your own unique, mod-specific, prefix rather than XYZ.
*/
CREATE TABLE XYZ_IndirectPrereqs 
AS SELECT S1.PrereqType AS PrereqType, S2.Type AS Type
FROM Technology_PrereqTechs S1
INNER JOIN Technology_PrereqTechs S2 
ON S1.Type = S2.PrereqType


/* Trims unneeded prereqs: T0 -> T2 when exists T0 -> T1 -> T2.
   Also covers higher order cases (see XYZ_IndirectPrereqs comments).
*/
DELETE S
FROM Technology_PrereqTechs S
WHERE EXISTS 
    (SELECT * FROM XYZ_IndirectPrereqs Indirect 
     WHERE S.Type = Indirect.Type AND S.PrereqType = Indirect.PrereqType)

Sorry... I'm not sure what I'm to do with this? Do I add this to a new SQL file? :confused:
 
I think it's the game trying to compile the tech tree itself, figuring out which techs are required to research other tech, etc. I had to raise the number of PrereqTechs in the GlobalDefines.xml file in order to do this. At any rate, my FireTuner doesn't want to load. It comes up with a "FireTuner2 has stopped working" message.
Well, if you're correct this could be bothersome. My solution will generate less prereqs than yours in the end so let's hope it does not cause those problems. That being said maybe we could achieve something with even less prereqs in the end, through one invisible tech at the end of each era.

Sorry... I'm not sure what I'm to do with this? Do I add this to a new SQL file? :confused:
Yes, create a new SQL file and adds it to the actions tab as you would with your XML file. And remove all changes you did to prereqs on your own (no new OR prereqs, no AND prereqs removed, etc). You can also remove the PlayerCanResearch event subscription.


@Whoward
Would your solution present any advantage over the one already set in place where I just didn't display inter-eras connectors?
 
Yes, create a new SQL file and adds it to the actions tab as you would with your XML file. And remove all changes you did to prereqs on your own (no new OR prereqs, no AND prereqs removed, etc). You can also remove the PlayerCanResearch event subscription.

Ok, I added the SQL file to the actions tab, and removed the previous LUA code that you created, and removed my CIV5Technologies.xml file (using strictly vanilla). I kept the modification to the TechTree.lua file.

I fired up a new game set in the Ancient Era to test it, and gave myself every Ancient Era tech except for one (Sailing). It doesn't seem like it did anything? I can still click on Iron Working directly via the TechTree and start researching it immediately, where as the only tech I should have been allowed to research was Sailing.

Checked the log files... nothing out of the ordinary. In fact, most were blank or had some kind of text about initializing, but that's about it.

:confused:
 
The purpose of this change is to enforce the "one era after the other" rule: if you click any classical tech, all of the ancient techs will be also selected and enqueued before. So the tech tree still behave as usual (in vanilla you can click computers even if you cannot research it yet: this enqueue the prereqs) while taking into account the new rule. Now if this does not work, check xml.log and database.log. If there is no error, look at the DB snapshot in SQLite Manager or any other tool and check iron working's prereqs.

All of that being said, if you also want to change the tech tree behavior, then this is a separate matter and you need to modify techtree.lua further (one change to prevent the click to work, another one to modify the display for those techs). But I do not think it is a good idea: you do not need this to enforce your rule, you do not need this to make sure the user understand the rule, it would just make the UI less powerful, frustrating to use and quite clumsy.
 
The purpose of this change is to enforce the "one era after the other" rule: if you click any classical tech, all of the ancient techs will be also selected and enqueued before.

It didn't do that, though. When I click on a Classical Era tech, Iron Working for example, the only ancient era tech that is enqueued is Bronze Working. I even went to the Medieval Era and clicked on Chivalry, and only those techs that would normally lead to Chivalry in a vanilla game were enqued. The techs that are not normally required to be researched were ignored. When I click on Iron Working, are all of the Ancient Era techs supposed to be enqued?

I've attached the Database.log and xml.log files, although I don't see anything that would affect what we're trying to do, but I may be wrong, too.

I'll also download SQLite Manager and see what it says.
 

Attachments

If you want to make this process as simple as possible, the original code will work but just modify PlayerCanResearch to PlayerCanEverResearch (or whatever the game event is to disable a tech).

The tech tree respects disabled techs but not canresearch techs.
 

Whoward69, I think I found a problem with your mod. It only seems to work if you use the vanilla PrereqTechs. If you delete/modify them, the mod no longer functions.

To test this, I created a CIV5Technologies.xml file, and put this in it:

Code:
<GameData>
	<Technology_PrereqTechs>
		<Delete TechType="TECH_OPTICS"/>
		<Delete TechType="TECH_PHILOSOPHY"/>
		<Delete TechType="TECH_DRAMA"/>
		<Delete TechType="TECH_HORSEBACK_RIDING"/>
		<Delete TechType="TECH_MATHEMATICS"/>
		<Delete TechType="TECH_CONSTRUCTION"/>
		<Delete TechType="TECH_IRON_WORKING"/>
	</Technology_PrereqTechs>
  </GameData>

... I can immediately research all the Classical Era technologies without having the research any Ancient Era techs.



Also, if I delete the vanilla PrereqTechs, and replace them with my own, the result is the same.

For example:

Code:
<GameData>
	<Technology_PrereqTechs>
		<Delete TechType="TECH_OPTICS"/>
		<Delete TechType="TECH_PHILOSOPHY"/>
		<Delete TechType="TECH_DRAMA"/>
		<Delete TechType="TECH_HORSEBACK_RIDING"/>
		<Delete TechType="TECH_MATHEMATICS"/>
		<Delete TechType="TECH_CONSTRUCTION"/>
		<Delete TechType="TECH_IRON_WORKING"/>
		<Row>
			<TechType>TECH_HORSEBACK_RIDING</TechType>
			<PrereqTech>TECH_WRITING</PrereqTech>
		</Row>
	</Technology_PrereqTechs>
  </GameData>

... even with Writing as the PrereqTech for Horseback Riding, I still do not need all the Ancient Era techs in order to research it. All I need is Writing and Pottery (if you look at the vanilla TechTree).


Any ideas why it's doing this? :confused::confused::confused:
 
You are free to use this method to restrict eras:

Code:
GameEvents.PlayerCanEverResearch.Add(
function(iPlayer, techTypeID)
	local prereqEra = GameInfo.Technologies[techTypeID].PrereqEra

	-- does the PrereqEra match an era? (if not then do nothing)
	if prereqEra then
		local pPlayer = Players[iPlayer]
		local pTeam = Teams[pPlayer:GetTeam()];
		local pEra = GameInfo.Eras[prereqEra].ID
		
		-- Are we in that era?
		if not (pTeam:GetCurrentEra() ==  pEra)then
			return false;
		end
	end
	return true;
end)

You'd also need to put this in your SQL:
Code:
ALTER TABLE Technologies ADD COLUMN 'PrereqEra' TEXT DEFAULT NULL;

So then you'd do something like:

Code:
<Update>
 <Where Type="TECH_HORSEBACK_RIDING"/>
 <Set PrereqEra="ERA_CLASSICAL"/>
</Update>

You can't get into the Classical Era without researching all the ancient techs, so just restrict the first line of classical techs to require the classical era.
 
Whoward69, I think I found a problem with your mod. It only seems to work if you use the vanilla PrereqTechs. If you delete/modify them, the mod no longer functions.

It will depend on a) the load order of the mods and b) what your mod is actually doing.

Zip your mod and post it, it will be easier to work out what is wrong from the actual code rather than a description of what you think your code is doing
 
It will depend on a) the load order of the mods and b) what your mod is actually doing.

Zip your mod and post it, it will be easier to work out what is wrong from the actual code rather than a description of what you think your code is doing

Sure thing... here it is. Just unzip the contents of the zip file into your Firaxis Modbuddy folder.
(FYI... I have the TechTree set up so that pipes that go between Eras are invisible. Just letting you know, so that doesn't throw you off)
 

Attachments

The SQL finds the end/start techs in an era based on the relationships to those before/after them. As you are first deleting all the relationships between the Ancient and Classical eras you will need to rewrite the SQL to allow for that
 
The SQL finds the end/start techs in an era based on the relationships to those before/after them. As you are first deleting all the relationships between the Ancient and Classical eras you will need to rewrite the SQL to allow for that

Even if I use an <Update> tag, it still doesn't the exact same thing; I can update Horseback Riding's PrereqTech to Writing (instead of deleting it) and the end result is the same. I'm not very proficient with SQL; would you mind showing me how this is to be fixed? I imagine other modders will have the same problem with their custom TechTrees, as well. :sad:
 
Basic logic is

1) "start era techs" are those that have a pre-req tech in the previous era
2) "end era techs" are those that are pre-req techs for techs in the next era
3) All "start era" techs have pre-reqs added to the previous "end era techs" that they don't already have.

Your "problem" is that you are deleting the pre-req relationships between the Ancient and Classical eras so the bits of the SQL that work out 1) and 2) no longer "work" for your situation - so you'll need to fix it yourself.
 
A "problem" is still a problem, just with quotations wrapped around it.

** EDIT **

Ok, after a few hours of trial-and-error, I think I have it figured out. Although, I would suggest including a Readme with the mod explaining how some of the mechanics work, as I can easily see people getting confused on how to implement it.
 
Code that works correctly for the original situation but then breaks when applied (unaltered) to a changed situation does NOT have a problem.

If you modify your car's fuel tank to accept wood alcohol, when the engine fails the problem is not with the engine but with the modification being incomplete.

And if you've now figured it out, the civic thing to do would be to post your own solution for those that follow later
 
Code that works correctly for the original situation but then breaks when applied (unaltered) to a changed situation does NOT have a problem.

If you modify your car's fuel tank to accept wood alcohol, when the engine fails the problem is not with the engine but with the modification being incomplete.

And if you've now figured it out, the civic thing to do would be to post your own solution for those that follow later

You're being a little arrogant about this whole thing, don't you think? :rolleyes:


You wrote the code, you explain it.


Moderator Action: That is not the correct way to ask people to help you fix your mod.
 
Back
Top Bottom