[BUG & SOLUTION] Technology tree pipes not linking correctly when expanding the tree

JANorton

Chieftain
Joined
Oct 3, 2010
Messages
11
Location
Albury, Australia
Came across this bug when trying to add a new Tech to the game, basically the tech tree wouldn't connect some pipes correctly when they spanned more than 1 space along the x axis (see first screenshot).

I searched through the TechTree.lua file for the tech tree and found it was due to a typo by the original author, basically he forgot to add the xOffset to downward turning pipes when they were in conjuntion with upward or straight pipes.

To fix the pipe connection issue the following changes need to be made to the TechTree.lua file found in the Assets/InGame/UI/TechTree folder, first, find the section of the code in the below quote, its a fair way down (the file is too long to quote the entire thing) and add the changes highlighted in blue. The result of this Fix can be seen in the second screenshot.

for pipeIndex, thisPipe in pairs(techPipes) do

local tech = GameInfo.Technologies[thisPipe.techType];

local yOffset = (tech.GridY-5)*blockSpacingY + 12 + extraYOffset;

if thisPipe.rightConnectionType >= 1 then

local startPipe = g_PipeManager:GetInstance();
startPipe.TechPipeIcon:SetOffsetVal( tech.GridX*blockSpacingX + blockSizeX + 64, yOffset );
startPipe.TechPipeIcon:SetTexture(right1Texture);
startPipe.TechPipeIcon:SetSize(connectorSize);

local pipe = g_PipeManager:GetInstance();
if thisPipe.rightConnectionType == 1 then
pipe.TechPipeIcon:SetOffsetVal( (tech.GridX)*blockSpacingX + blockSizeX + 96, yOffset ); --original
pipe.TechPipeIcon:SetTexture(right1Texture);
elseif thisPipe.rightConnectionType == 2 then
pipe.TechPipeIcon:SetOffsetVal( (tech.GridX+thisPipe.xOffset)*blockSpacingX + blockSizeX + 96 - 12, yOffset - 15 );
pipe.TechPipeIcon:SetTexture(bottomRightTexture);
pipe.TechPipeIcon:SetTextureOffset(Vector2(72,72));
elseif thisPipe.rightConnectionType == 3 then
--pipe.TechPipeIcon:SetOffsetVal( (tech.GridX+thisPipe.xOffset)*blockSpacingX + blockSizeX + 96 - 6, yOffset - 15 );
--pipe.TechPipeIcon:SetTexture(right2BTexture);
--pipe.TechPipeIcon:SetTextureOffset(Vector2(36,72));
pipe.TechPipeIcon:SetOffsetVal( (tech.GridX)*blockSpacingX + blockSizeX + 96, yOffset );
pipe.TechPipeIcon:SetTexture(right1Texture);
pipe = g_PipeManager:GetInstance();
pipe.TechPipeIcon:SetOffsetVal( (tech.GridX+thisPipe.xOffset)*blockSpacingX + blockSizeX + 96 - 12, yOffset - 15 );
pipe.TechPipeIcon:SetTexture(bottomRightTexture);
pipe.TechPipeIcon:SetTextureOffset(Vector2(72,72));
elseif thisPipe.rightConnectionType == 4 then
pipe.TechPipeIcon:SetOffsetVal( (tech.GridX+thisPipe.xOffset)*blockSpacingX + blockSizeX + 96 - 12, yOffset );
pipe.TechPipeIcon:SetTexture(topRightTexture);
pipe.TechPipeIcon:SetTextureOffset(Vector2(72,0));
elseif thisPipe.rightConnectionType == 5 then
--pipe.TechPipeIcon:SetOffsetVal( (tech.GridX)*blockSpacingX + blockSizeX + 96 - 6, yOffset );
--pipe.TechPipeIcon:SetTexture(right2TTexture);
--pipe.TechPipeIcon:SetTextureOffset(Vector2(36,0));
pipe.TechPipeIcon:SetOffsetVal( (tech.GridX)*blockSpacingX + blockSizeX + 96, yOffset );
pipe.TechPipeIcon:SetTexture(right1Texture);
pipe = g_PipeManager:GetInstance();

-- Modified by Jeremy Norton 05/10/10
--pipe.TechPipeIcon:SetOffsetVal( (tech.GridX)*blockSpacingX + blockSizeX + 96 - 12, yOffset );
--pipe.TechPipeIcon:SetTexture(topRightTexture);
--pipe.TechPipeIcon:SetTextureOffset(Vector2(72,0));
pipe.TechPipeIcon:SetOffsetVal( (tech.GridX+thisPipe.xOffset)*blockSpacingX + blockSizeX + 96 - 12, yOffset );
pipe.TechPipeIcon:SetTexture(topRightTexture);
pipe.TechPipeIcon:SetTextureOffset(Vector2(72,0));
-- End of Changes


elseif thisPipe.rightConnectionType == 6 then
--pipe.TechPipeIcon:SetOffsetVal( (tech.GridX+thisPipe.xOffset)*blockSpacingX + blockSizeX + 96 - 12, yOffset - 6 );
--pipe.TechPipeIcon:SetTexture(right2Texture);
--pipe.TechPipeIcon:SetTextureOffset(Vector2(72,36));

-- Modified by Jeremy Norton 05/10/10
--pipe.TechPipeIcon:SetOffsetVal( (tech.GridX)*blockSpacingX + blockSizeX + 96 - 12, yOffset );
--pipe.TechPipeIcon:SetTexture(topRightTexture);
--pipe.TechPipeIcon:SetTextureOffset(Vector2(72,0));
pipe.TechPipeIcon:SetOffsetVal( (tech.GridX+thisPipe.xOffset)*blockSpacingX + blockSizeX + 96 - 12, yOffset );
pipe.TechPipeIcon:SetTexture(topRightTexture);
pipe.TechPipeIcon:SetTextureOffset(Vector2(72,0));
-- End of Changes


pipe = g_PipeManager:GetInstance();
pipe.TechPipeIcon:SetOffsetVal( (tech.GridX+thisPipe.xOffset)*blockSpacingX + blockSizeX + 96 - 12, yOffset - 15 );
pipe.TechPipeIcon:SetTexture(bottomRightTexture);
pipe.TechPipeIcon:SetTextureOffset(Vector2(72,72));
else-- thisPipe.rightConnectionType == 7 then
--pipe.TechPipeIcon:SetOffsetVal( (tech.GridX)*blockSpacingX + blockSizeX + 96 - 6, yOffset - 6 );
--pipe.TechPipeIcon:SetTexture(right3Texture);
--pipe.TechPipeIcon:SetTextureOffset(Vector2(36,36));
--pipe.TechPipeIcon:SetOffsetVal( (tech.GridX)*blockSpacingX + blockSizeX + 96, yOffset );
--pipe.TechPipeIcon:SetTexture(right1Texture);
--pipe = g_PipeManager:GetInstance();

-- Modified by Jeremy Norton 05/10/10
--pipe.TechPipeIcon:SetOffsetVal( (tech.GridX)*blockSpacingX + blockSizeX + 96 - 12, yOffset );
--pipe.TechPipeIcon:SetTexture(topRightTexture);
--pipe.TechPipeIcon:SetTextureOffset(Vector2(72,0));
pipe.TechPipeIcon:SetOffsetVal( (tech.GridX+thisPipe.xOffset)*blockSpacingX + blockSizeX + 96 - 12, yOffset );
pipe.TechPipeIcon:SetTexture(topRightTexture);
pipe.TechPipeIcon:SetTextureOffset(Vector2(72,0));
-- End of Changes


pipe = g_PipeManager:GetInstance();
pipe.TechPipeIcon:SetOffsetVal( (tech.GridX+thisPipe.xOffset)*blockSpacingX + blockSizeX + 96 - 12, yOffset - 15 );
pipe.TechPipeIcon:SetTexture(bottomRightTexture);
pipe.TechPipeIcon:SetTextureOffset(Vector2(72,72));
end
end
 

Attachments

  • techtree_bug.jpg
    techtree_bug.jpg
    218.4 KB · Views: 618
  • TechTree_Fixed.jpg
    TechTree_Fixed.jpg
    235.3 KB · Views: 491
Nice catch. I've encountered a similar bug. In my case, the pipes are going too far, instead of not far enough. Unfortunately, I don't think the solution for this one is going to be quite so pretty. I'm completely new to this Lua malarkey, so I may be wrong (in fact I hope I am), but it seems to me that each tech can only have one xOffset value. This in turn means that a given tech can only lead to other techs that have the same GridX values as each other.

Curiously enough, there is one tech in the default techtree, Combustion, that does not conform to this rule. And, less curiously, the pipe that leads from said tech is one of the downward-hooked ones, of exactly the kind that your fix applies to. So it seems the bug is no mere typo by a forgetful author, it is in fact a dirty hack to stop the default techtree from breaking. (In fact I have just taken a look at the default techtree with this fix enabled, and Combustion does indeed break.) I have no idea why they didn't just shuffle a few of the techs along one column.

Anyway, I'm slightly digressing from my point. As you can see from my screenshot, my techtree has techs that lead to multiple different columns. Quite a few, in fact, and it'd be a right pain to try to reshuffle all of them all over the place. As I said, I'm new to Lua, so I've been scratching my head for a while, and I can't see any kind of elegant solution that would allow for techs to be arranged in this manner. I thought I'd ask to see if you, or anyone else, had any ideas.
 

Attachments

  • Civ5Screen0000.jpg
    Civ5Screen0000.jpg
    217.5 KB · Views: 294
Nice catch. I've encountered a similar bug. In my case, the pipes are going too far, instead of not far enough. Unfortunately, I don't think the solution for this one is going to be quite so pretty. I'm completely new to this Lua malarkey, so I may be wrong (in fact I hope I am), but it seems to me that each tech can only have one xOffset value. This in turn means that a given tech can only lead to other techs that have the same GridX values as each other.

Curiously enough, there is one tech in the default techtree, Combustion, that does not conform to this rule. And, less curiously, the pipe that leads from said tech is one of the downward-hooked ones, of exactly the kind that your fix applies to. So it seems the bug is no mere typo by a forgetful author, it is in fact a dirty hack to stop the default techtree from breaking. (In fact I have just taken a look at the default techtree with this fix enabled, and Combustion does indeed break.) I have no idea why they didn't just shuffle a few of the techs along one column.

Anyway, I'm slightly digressing from my point. As you can see from my screenshot, my techtree has techs that lead to multiple different columns. Quite a few, in fact, and it'd be a right pain to try to reshuffle all of them all over the place. As I said, I'm new to Lua, so I've been scratching my head for a while, and I can't see any kind of elegant solution that would allow for techs to be arranged in this manner. I thought I'd ask to see if you, or anyone else, had any ideas.

You are absolutely right, there is only 1 xOffset attribute per pipe connection to and from each tech, which means a fair amount of re-coding would be required to solve your problem. Something along the lines of individualising and displaying each prereq -> tech connection rather than trying to do all the outbound pipes from just each tech in one go. Like you, i'm also new to lua and am only able to make small changes by looking at the code, figuring out what it does and then limited to just adjusting or copying code. So if anyone with sufficient lua experience would like to have a go at solving this it would be greatly appreciated.

For the mean time you could move all the techs above and above and to the right of the red square in your thumbnail to the right one tech spacing, this should at least make all the pipes connect correctly.

Hopefully firaxis addresses these tech tree pipe connection issues in a soon to come patch, if not I can see them becoming a stumbling block for modders trying to do more advanced things with the tech tree.
 
Thanks....needed that, kept having the same problems but I was too lazy to break down the code.
You're the man!!!
 
Hi JANorton,

Anychance you can upload a copy of the TechTree.Lua with your changes already in it? I have tried to add in your changes, but I do not get any changed results.

or do I have to add an action for it to fire the new TechTree.Lua?
 
Hi JANorton,

Anychance you can upload a copy of the TechTree.Lua with your changes already in it? I have tried to add in your changes, but I do not get any changed results.

or do I have to add an action for it to fire the new TechTree.Lua?

No action required just simply have it included in your mods folder structure, see attached for the modified file.
 

Attachments

  • TechTree.zip
    5.3 KB · Views: 145
Top Bottom