Hi all,
I have fixed the Lua code that renders the tech tree incorrectly when two or more techs with different X coordinates all rely on the same prerequisite tech.
This was brought to my attention when I posted my concerns in this thread:
http://forums.civfanatics.com/showthread.php?t=420270
I modified the following file directly: Assets -> UI -> InGame -> TechTree -> TechTree.lua
I haven't thought about how to include it in a mod for now (am quite tired and need to post my magic design tonight for my own mod before I sleep lol).
The fix will work fine though if directly applied to this file (feel free to report any bugs to me ofc )
The fix is as follows:
Remove the block of code shown below:
-- add the pipes
local techPipes = {};
for row in GameInfo.Technologies() do
techPipes[row.Type] =
{
leftConnectionUp = false;
leftConnectionDown = false;
leftConnectionCenter = false;
leftConnectionType = 0;
rightConnectionUp = false;
rightConnectionDown = false;
rightConnectionCenter = false;
rightConnectionType = 0;
xOffset = 0;
techType = row.Type;
};
end
local cnxCenter = 1
local cnxUp = 2
local cnxDown = 4
-- Figure out which left and right adapters we need
for row in GameInfo.Technology_PrereqTechs() do
local prereq = GameInfo.Technologies[row.PrereqTech];
local tech = GameInfo.Technologies[row.TechType];
if tech and prereq then
if tech.GridY < prereq.GridY then
techPipes[tech.Type].leftConnectionDown = true;
techPipes[prereq.Type].rightConnectionUp = true;
elseif tech.GridY > prereq.GridY then
techPipes[tech.Type].leftConnectionUp = true;
techPipes[prereq.Type].rightConnectionDown = true;
else -- tech.GridY == prereq.GridY
techPipes[tech.Type].leftConnectionCenter = true;
techPipes[prereq.Type].rightConnectionCenter = true;
end
local xOffset = (tech.GridX - prereq.GridX) - 1;
if xOffset > techPipes[prereq.Type].xOffset then
techPipes[prereq.Type].xOffset = xOffset;
end
end
end
and replace it with the following code
-- add the pipes
local techPipes = {};
local i = 0;
for row in GameInfo.Technology_PrereqTechs() do
local tech = GameInfo.Technologies[row.TechType];
local prereq = GameInfo.Technologies[row.PrereqTech];
if tech and prereq then
local bTechLeftConnUp = false;
local bTechLeftConnDown = false;
local bTechLeftConnCentre = false;
local bPrereqRightConnUp = false;
local bPrereqRightConnDown = false;
local bPrereqRightConnCentre = false;
local nPrereqXOffset = (tech.GridX - prereq.GridX) - 1;
local nTechXOffset = -nPrereqXOffset;
if tech.GridY < prereq.GridY then
bTechLeftConnDown = true;
bPrereqRightConnUp = true;
elseif tech.GridY > prereq.GridY then
bTechLeftConnUp = true;
bPrereqRightConnDown = true;
else -- tech.GridY == prereq.GridY
bTechLeftConnCentre = true;
bPrereqRightConnCentre = true;
end
techPipes =
{
leftConnectionUp = bTechLeftConnUp;
leftConnectionDown = bTechLeftConnDown;
leftConnectionCenter = bTechLeftConnCentre;
leftConnectionType = 0;
rightConnectionUp = false;
rightConnectionDown = false;
rightConnectionCenter = false;
rightConnectionType = 0;
xOffset = nTechXOffset;
techType = tech.Type;
};
i = i + 1;
techPipes =
{
leftConnectionUp = false;
leftConnectionDown = false;
leftConnectionCenter = false;
leftConnectionType = 0;
rightConnectionUp = bPrereqRightConnUp;
rightConnectionDown = bPrereqRightConnDown;
rightConnectionCenter = bPrereqRightConnCentre;
rightConnectionType = 0;
xOffset = nPrereqXOffset;
techType = prereq.Type;
};
i = i + 1;
end
end
local cnxCenter = 1
local cnxUp = 2
local cnxDown = 4
The new code is logically less efficient (as it draws each pipe individually), but there appears to be no significant effect on performance
Attached is a picture showing the fix in action (note that both Faith and Calendar both require Writing and have different X coordinates. The branches are now drawn correctly)
Hope you all enjoy!
Let me know if there are any problems
Al
I have fixed the Lua code that renders the tech tree incorrectly when two or more techs with different X coordinates all rely on the same prerequisite tech.
This was brought to my attention when I posted my concerns in this thread:
http://forums.civfanatics.com/showthread.php?t=420270
I modified the following file directly: Assets -> UI -> InGame -> TechTree -> TechTree.lua
I haven't thought about how to include it in a mod for now (am quite tired and need to post my magic design tonight for my own mod before I sleep lol).
The fix will work fine though if directly applied to this file (feel free to report any bugs to me ofc )
The fix is as follows:
Remove the block of code shown below:
Spoiler Old Code To Remove :
-- add the pipes
local techPipes = {};
for row in GameInfo.Technologies() do
techPipes[row.Type] =
{
leftConnectionUp = false;
leftConnectionDown = false;
leftConnectionCenter = false;
leftConnectionType = 0;
rightConnectionUp = false;
rightConnectionDown = false;
rightConnectionCenter = false;
rightConnectionType = 0;
xOffset = 0;
techType = row.Type;
};
end
local cnxCenter = 1
local cnxUp = 2
local cnxDown = 4
-- Figure out which left and right adapters we need
for row in GameInfo.Technology_PrereqTechs() do
local prereq = GameInfo.Technologies[row.PrereqTech];
local tech = GameInfo.Technologies[row.TechType];
if tech and prereq then
if tech.GridY < prereq.GridY then
techPipes[tech.Type].leftConnectionDown = true;
techPipes[prereq.Type].rightConnectionUp = true;
elseif tech.GridY > prereq.GridY then
techPipes[tech.Type].leftConnectionUp = true;
techPipes[prereq.Type].rightConnectionDown = true;
else -- tech.GridY == prereq.GridY
techPipes[tech.Type].leftConnectionCenter = true;
techPipes[prereq.Type].rightConnectionCenter = true;
end
local xOffset = (tech.GridX - prereq.GridX) - 1;
if xOffset > techPipes[prereq.Type].xOffset then
techPipes[prereq.Type].xOffset = xOffset;
end
end
end
and replace it with the following code
Spoiler New Code :
-- add the pipes
local techPipes = {};
local i = 0;
for row in GameInfo.Technology_PrereqTechs() do
local tech = GameInfo.Technologies[row.TechType];
local prereq = GameInfo.Technologies[row.PrereqTech];
if tech and prereq then
local bTechLeftConnUp = false;
local bTechLeftConnDown = false;
local bTechLeftConnCentre = false;
local bPrereqRightConnUp = false;
local bPrereqRightConnDown = false;
local bPrereqRightConnCentre = false;
local nPrereqXOffset = (tech.GridX - prereq.GridX) - 1;
local nTechXOffset = -nPrereqXOffset;
if tech.GridY < prereq.GridY then
bTechLeftConnDown = true;
bPrereqRightConnUp = true;
elseif tech.GridY > prereq.GridY then
bTechLeftConnUp = true;
bPrereqRightConnDown = true;
else -- tech.GridY == prereq.GridY
bTechLeftConnCentre = true;
bPrereqRightConnCentre = true;
end
techPipes =
{
leftConnectionUp = bTechLeftConnUp;
leftConnectionDown = bTechLeftConnDown;
leftConnectionCenter = bTechLeftConnCentre;
leftConnectionType = 0;
rightConnectionUp = false;
rightConnectionDown = false;
rightConnectionCenter = false;
rightConnectionType = 0;
xOffset = nTechXOffset;
techType = tech.Type;
};
i = i + 1;
techPipes =
{
leftConnectionUp = false;
leftConnectionDown = false;
leftConnectionCenter = false;
leftConnectionType = 0;
rightConnectionUp = bPrereqRightConnUp;
rightConnectionDown = bPrereqRightConnDown;
rightConnectionCenter = bPrereqRightConnCentre;
rightConnectionType = 0;
xOffset = nPrereqXOffset;
techType = prereq.Type;
};
i = i + 1;
end
end
local cnxCenter = 1
local cnxUp = 2
local cnxDown = 4
The new code is logically less efficient (as it draws each pipe individually), but there appears to be no significant effect on performance
Attached is a picture showing the fix in action (note that both Faith and Calendar both require Writing and have different X coordinates. The branches are now drawn correctly)
Hope you all enjoy!
Let me know if there are any problems
Al