BFTTree - Multiple Page Tech Tree

Hi, this mod is great stuff by the way! :) I'll look into adding support for it in the tech editor at some point. I just wanted to drop in with an idea. I'm just going to go crazy and explain it in full. Please don't think me posting this is like some kind of diss on your awesome work, I'm always hesitant to post such things for that reason, just there may be a few SQL tricks you're not aware of that could help you out with this mod.

If you added an SQL rule at the start of your mod actions list that had something like:

Code:
ALTER TABLE Technologies ADD TechTreeType TEXT;

you could add a new field to the technologies to allow you to set what category it is in outside of the name field:

Code:
<Technologies>
     <Update>
           <Set TechTreeType="TECHTREE_MILITARY"/>
           <Where Type="TECH_BRONZE_WORKING"/>
     </Update>
     <Update>
           <Set TechTreeType="TECHTREE_MILITARY"/>
           <Where Type="TECH_IRON_WORKING"/>
     </Update>
     <Update>
           <Set TechTreeType="TECHTREE_MILITARY"/>
           <Where Type="TECH_MILITARY_SCIENCE"/>
     </Update>
</Technologies>

Then to go a step further, you could do...

Code:
CREATE TABLE TechTrees ( ID INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT NOT NULL UNIQUE, Description TEXT, PortraitIndex INTEGER, IconAtlas TEXT );

Which would create a new table to allow the modder to add tech tree categories with portraits and txt keys and whatnot in xml like this:

Code:
<TechTrees>
     <Row>
         <ID>0</ID>
         <Type>TECHTREE_MILITARY</Type>
         <Description>TXT_KEY_TECHTREE_MILITARY</Description>
         <PortraitIndex>0</PortraitIndex>
         <IconAtlas>TECHTREE_ATLAS</IconAtlas>
     </Row>
</TechTrees>

Then use a for row in DB.Query("SELECT * FROM TechTrees") do in the lua to get the list of tech trees to populate your tech tree category page:

Finally, you could also add the following table definitions:

Code:
CREATE TABLE Civilization_TechTreeAccess( CivilizationType TEXT , TechTreeType TEXT );
CREATE TABLE Technology_TechTreeAccess( TechnologyType TEXT, TechTreeType TEXT );
CREATE TABLE Building_TechTreeAccess( BuildingType TEXT, TechTreeType TEXT );

To allow the modder to do this:

Code:
<Civilization_TechTreeAccess>
    <Row>
         <CivilizationType>CIVILIZATION_AMERICA</CivilizationType>
         <TechTreeType>TECHTREE_AMERICA</TechTreeType>
    </Row> 
</Civilization_TechTreeAcces>

<Technology_TechTreeAccess>
    <Row>
        <TechnologyType>TECH_MINING</TechnologyType>
        <TechTreeType>TECHTREE_MINING</TechTreeType>
    </Row>
</Technology_TechTreeAccess>

<Building_TechTreeAccess>
    <Row>
        <BuildingType>BUILDING_BARRACKS</BuildingType>
        <TechTreeType>TECHTREE_MILITARY</TechTreeType>
    </Row>
</Building_TechTreeAccess>

Then you could do the various DB.Querys on the civilization type, the number of types of buildings the player has in their cities, and what techs the player had to determine which tech trees were locked or unlocked, which would allow the users of your mod to customize their tech trees per-civ as you have currently, and also provide building unlocked tech trees or hub techs that lead to new pages, and any other criteria you'd like to add, without having to rely on the type field. It would also mean the modder could specify their own categories.

For those DB.Querys you can do an inner join to join the results of the main techtrees table with the unlock tables, to obtain a list of TechTrees that you can test the criteria of in one single loop:

Code:
for row in DB.Query("SELECT * FROM TechTrees INNER JOIN Civilization_TechTreeAccess ON TechTrees.Type = Civilization_TechTreeAccess.TechTreeType") do
    if (row["CivilizationType"] == ThisCivsType) do
           print ("This civ has access to the "..Locale.ConvertTextKey(row["Description"]).." tech tree.");
    end
end

I've also got an idea on how to make the AI follow these tech tree rules, too.

You would add XML rows for the Civilization_DisableTech table, disabling for every civ the first root tech of each of the locked trees.

Code:
<Civilization_DisableTech>
    <Row>
         <CivilizationType>CIVILIZATION_AMERICA</CivilizationType>
         <TechType>TECH_FIRSTJAPANESETECH</TechType>
    </Row>
    <Row>
         <CivilizationType>CIVILIZATION_AMERICA</CivilizationType>
         <TechType>TECH_FIRSTENGLISHTECH</TechType>
    </Row>
</Civilization_DisableTech>

etc...

For the 'unlock during the game' types of locked tech trees, it's a little more complicated, but feasible. you would have a lua function that's called every turn:

This could go through and do those very same checks you do for the UI for each of the AI players. If they fail the checks for a tech tree, you would execute a set of mod actions (like OnModActivated) but call it say... OnAmericaMilitaryDisable or OnFranceCultureEnable which would add or remove entries to the Civilization_DisableTech table for the first root techs in those trees. It would however create a bunch of modactions to have to maintain but it would be easy to write a little tool to generate these from the XML, which I would be happy to do for you if you went down this route.

Code:
-- check all the tech trees for a player and lock / unlock them as relevant.
function CheckPlayerTechTreeUnlocks(pPlayer)

   local pTeam = Teams[pPlayer:GetTeam()];
   local pTeamTechs =  pTeam :GetTeamTechs(); // get the tech list...
   local civType = GameInfo.Civilizations[pPlayer:GetCivilizationType()].Type;

-- Check if player has technology required for each tree.
   for row in DB.Query("SELECT * FROM TechTrees, Technologies, Technology_TechTreeAccess WHERE TechTrees.Type =       Technology_TechTreeAccess.TechTreeType") do
       if (pTeamTechs:HasTech(row["Technologies.ID"])) do
            Modding.PerformActions("On"..civType.."_ENABLE_"..row["TechTrees.Type"]);                    
       else
            Modding.PerformActions("On"..civType.."_DISABLE_"..row["TechTrees.Type"]);                    
       end
   end

-- Check if player has building required for each tree.
   for row in DB.Query("SELECT * FROM TechTrees, Buildings, Building_TechTreeAccess WHERE TechTrees.Type = Building_TechTreeAccess.TechTreeType") do
    if (pPlayer:CountNumBuildings(row["Buildings.ID"]) > 0) do
            Modding.PerformActions("On"..civType.."_ENABLE_"..row["TechTrees.Type"]);                    
       else
            Modding.PerformActions("On"..civType.."_DISABLE_"..row["TechTrees.Type"]);                    
       end
   end
end

-- Check the player is valid.
function isValidPlayer(pPlayer)
	return pPlayer ~= nil and pPlayer:IsAlive() and pPlayer:GetNumCities() > 0;
end

-- Check all the players for unlocked/locked trees
function doAITechTreeChecks ()

	for iPlayerLoop = 0, GameDefines.MAX_MAJOR_CIVS-1, 1 do
		local pPlayer = Players[ iPlayerLoop ];
		
		if isValidPlayer(pPlayer) then
                    CheckPlayerTechTreeUnlocks(pPlayer);
                end
        end
end

-- Add event for start of player's turn.
Events.ActivePlayerTurnStart.Add(doAITechTreeChecks)

If you had a ModAction in mod buddy properties called OnCIVILIZATION_ENGLISH_DISABLE_TECHTREE_NINJA (replacing OnModActivated) that called an XML file that did:

Code:
<Civilization_DisableTech>
    <Row>
         <CivilizationType>CIVILIZATION_ENGLISH</CivilizationType>
         <TechType>TECH_NINJATRAINING</TechType>
    </Row>
</Civilization_DisableTech>

and a ModAction called OnCIVILIZATION_ENGLISH_ENABLE_TECHTREE_NINJA with...

Code:
<Civilization_DisableTech>
    <Delete CivilizationType="CIVILIZATION_ENGLISH" TechType="TECH_NINJATRAINING"/>     
</Civilization_DisableTech>

Finally adding the building access XML:
Code:
<Building_TechTreeAccess>
    <Row>
         <BuildingType>BUILDING_NINJATRAINING</BuildingType>
         <TechTreeType>TECHTREE_NINJA</TechTreeType>
    </Row>
</Building_TechTreeAccess>
then as soon as the English built the ninja training building in one of their cities, they would unlock the Ninja tech tree, even the AI would follow the rules. Also the tech simply wouldn't appear as an option in the popup tech chooser for the human player as it would be disabled.

Anyway just to say again this is a wonderful mod, I just thought this info might provide you with another approach to the backend that would allow for more flexibility. :)

(just to point out, all this code is typed directly into the page, so there may be syntax issues/errors but I believe it's right)
 
Fires,

Lemmy posted this over here for you after a couple people brought up your mod and urged him to post over here... And at least myself had mentioned being hesitant about using your mod because it didn't seem modular enough yet...

Don't get me wrong, I really, REALLY love the idea of multi-tech tree's, with categories, but as I'm getting ready to dive into a TC, I didn't want to have extraneous views, or have to do a ton of editing on something to make it work and look all 'purdy like'... which was part of the conv and people urging Lemmy to post...

So if it made ya mad he did, then be mad at me. I can take it, I have my big boy undies on. :p
 
Oh god yeah, I really don't want to annoy you by telling you how to suck eggs or something, as I say it's an awesome mod, very well executed and I wasn't going to post any of this because I always feel really iffy about doing this, especially after the fact, and tend to avoid it.

but I was told you were looking into doing a policy tree version, so figured it was best to dispense this suggestion now rather than sit on it. :) if nothing else it's some insights into SQL that some people may not be aware of, that would be useful for all manner of mods.
 
Thanks for the input, there is a lot of good stuff here for me to work on.

This is the kind of input I like so don’t worry about it, the more people comment and discuss the better I can make this and the policy tree so keep it up.

I have been very busy recently but will be back working on this mod and the policy tree mod a lot over the next few weeks so it’s a very good time for these types comments.
 
So it looks like that would allow the core to be more modular for general XML modders? IE we wouldn't have to bug you for page additions, or would that still be required for the UI lua portion?

What is the real difference between that and the current system? SQL vs a lua solution? I am not really versed in either, just curious.
 
Ok i have been using what lemmy suggested and it works really good gets around so many problems, including the adding of new categories, that the current system has, so thanks a lot lemmy :goodjob:

This will mean a change to how it all works, so expect a few changes with a new how-to for anyone who has already been creating stuff with bfttree :eek:

Hopefully i can get a new version out by middle of next week :)
 
Nice! Hopefully when I come back from vacation in a few weeks(if I can leave this week that is) I will be able to begin full speed on new techs. :)

Might work on it a bit while I am home, but only if my laptop can handle it heh.
 
A quick update, sorry for the long delay but i discovered an issue with the pipes while reworking the trees into one .lua file. When i get this sorted then the next version will be out.

Update: Think those pipes should be fixed now, just doing some last checks here and there

The turning off and on of tech trees depending upon era, tech discovered etc wont be in this version but should be in the next :)
 
Awesome! As soon as I get home I will begin work on implementing this for my next version. :)

Will the main tree techs need any tinkering with to make them compatible with the categories? IE will we need to add the <TechCat> line to main tree techs to declare them as being in the main tree?
 
Awesome! As soon as I get home I will begin work on implementing this for my next version. :)

Will the main tree techs need any tinkering with to make them compatible with the categories? IE will we need to add the <TechCat> line to main tree techs to declare them as being in the main tree?

You do not have to do anything to the main game techs, they will find their way into the correct tech tree :)

Yay! looking awesome will look into editor support soon!

I am sure this would make quite a few people happy :D
 
I've been working on something similar to this, but much simpler, as a sort of proof-of-concept for a feature I'd like to have for a mod I've been thinking about for some time. I already have the things I want working, but not exactly looking all that great. It's pretty likely that there's code in this mod that's really close to what I need, but I don't need everything in this mod. Would you be ok if I were to, well, "borrow" some code? With credit given where appropriate, of course.
 
I've been working on something similar to this, but much simpler, as a sort of proof-of-concept for a feature I'd like to have for a mod I've been thinking about for some time. I already have the things I want working, but not exactly looking all that great. It's pretty likely that there's code in this mod that's really close to what I need, but I don't need everything in this mod. Would you be ok if I were to, well, "borrow" some code? With credit given where appropriate, of course.

If there is some code that helps your mod then i don't mind you using it, thanks for asking.
 
In light of some of the other mods that were wrecked by the patch, have there been any issues with the multiple pages mod?

I finally reached the point where I can begin implementation of this(vacation, other priorities, etc), but if it doesn't work it would be a lot of headache trying to figure out whether any problems are linked to me, or the patch.
 
Back
Top Bottom