lemmy101
Emperor
- Joined
- Apr 10, 2006
- Messages
- 1,064
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:
you could add a new field to the technologies to allow you to set what category it is in outside of the name field:
Then to go a step further, you could do...
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:
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:
To allow the modder to do this:
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:
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.
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.
If you had a ModAction in mod buddy properties called OnCIVILIZATION_ENGLISH_DISABLE_TECHTREE_NINJA (replacing OnModActivated) that called an XML file that did:
and a ModAction called OnCIVILIZATION_ENGLISH_ENABLE_TECHTREE_NINJA with...
Finally adding the building access XML:
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)

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>
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)