1. We have added the ability to collapse/expand forum categories and widgets on forum home.
    Dismiss Notice
  2. All Civ avatars are brought back and available for selection in the Avatar Gallery! There are 945 avatars total.
    Dismiss Notice
  3. To make the site more secure, we have installed SSL certificates and enabled HTTPS for both the main site and forums.
    Dismiss Notice
  4. Civ6 is released! Order now! (Amazon US | Amazon UK | Amazon CA | Amazon DE | Amazon FR)
    Dismiss Notice
  5. Dismiss Notice
  6. Forum account upgrades are available for ad-free browsing.
    Dismiss Notice

Fix for Civics Tree Display Issues

Discussion in 'Civ6 - Utilities, Code Snippets & Art Assets' started by PlotinusRedux, Jan 7, 2017.

  1. PlotinusRedux

    PlotinusRedux Chieftain

    Joined:
    Jul 11, 2013
    Messages:
    196
    The rules for Civics are:

    For each era, every civic with the same UITreeRow should be related to each other in the same prereq chain, with only 1 per UITreeRow having no prereqs in the same era.

    However, even following that rule, you can end up with civics overlapping each other on the display due to a Firaxis bug in a sort routine, especially if you end up with 4+ columns in any given era.

    To fix this: copy Base/Assets/UI/Screens/CivicsTree.lua to your mod's folder and add it to the <ImportFiles> section of your .modinfo. Then beginning at line 278 replace:
    Code:
       -- Manually sort based on prereqs, 2(N log N)
        for eraType,grid in pairs(eraGrids) do     
            local numEraItems:number = table.count(grid.sortRow.columns);
            if numEraItems > 1 then         
                for pass=1,2,1 do                    -- Make 2 passes so the first swapped item is checked.
                    for a=1,numEraItems do
                        for b=a,numEraItems do
                            if a ~= b then
                                for _,prereq in ipairs(m_kItemDefaults[grid.sortRow.columns[a] ].Prereqs) do
                                    if prereq == grid.sortRow.columns[b] then
                                        grid.sortRow.columns[a], grid.sortRow.columns[b] = grid.sortRow.columns[b], grid.sortRow.columns[a];    -- swap LUA style
                                    end
                                end                 
                            end
                        end
                    end
                end
            end
        end
    with:
    Code:
       -- Manually sort based on prereqs
        for eraType,grid in pairs(eraGrids) do     
            local numEraItems:number = table.count(grid.sortRow.columns);
            if numEraItems > 1 then
                local a : number = 1;
                while ( a < numEraItems ) do
                    local found = false;
                    for b = numEraItems, a + 1, -1 do
                        for _,prereq in ipairs(m_kItemDefaults[grid.sortRow.columns[a]].Prereqs) do
                            if prereq == grid.sortRow.columns[b] then
                                found = true;
                                table.insert(grid.sortRow.columns, b, table.remove(grid.sortRow.columns, a));
                                break;
                            end
                        end
                        if found then
                            break;
                        end;
                    end;
    
                    if ( not found ) then
                        a = a + 1;
                    end
                end
            end
        end
    In the tech tree view they didn't even try to sort by prereqs, they just set the column directly based on the tech's cost, so just make sure you don't have any techs with the same cost and UITreeRow.
     
    raen and Lynnes like this.

Share This Page

Ebates: Get Paid to Shop