Help with determining how many Followers of a Religion are in another Civilization

Harkodos

Warlord
Joined
Feb 9, 2016
Messages
195
So I've yet another problem: I'm trying to determine how many Followers of a Religion exist, and then displaying that on the TopPanel. I can get that just fine for any Followers in the player's Cities, but when it come to other players, I'm at a bit of a snag.

Here's what I've got for the Peace Loving belief:
Code:
        local iNumFollowersPerHappiness = 0; -- Happiness
        local iPeacefulReligionFollowers = 0;
        local iNumPeacefulFollowers = 0;
        local iGlobalHappinessFromFollowers = 0; -- Happiness
        local iNumCivs = (bCountMinors and (GameDefines.MAX_PLAYERS - 2) or (GameDefines.MAX_MAJOR_CIVS - 1));

        for rPlayer=0, GameDefines.MAX_MAJOR_CIVS-1 do
            local rPlayer = Players[rPlayer];
            if (pPlayer == rPlayer) then
                if (rPlayer:GetReligionCreatedByPlayer() >= 1) then
                    local rReligion = rPlayer:GetReligionCreatedByPlayer();
                    for i,v in ipairs(Game.GetBeliefsInReligion(rReligion)) do
                        local belief = GameInfo.Beliefs[v];
                        if (belief ~= nil) then

                            -- Global Happiness from number of Followers in Peaceful Foreign Cities (Global)
                            if (belief.HappinessPerXPeacefulForeignFollowers ~= 0) then
                                iNumFollowersPerHappiness = belief.HappinessPerXPeacefulForeignFollowers; -- Happiness

                                -- Determine the number of Peaceful Followers in the City
                                for iOtherPlayer = 0, iNumCivs do
                                    local pOtherPlayer = Players[iOtherPlayer];
                                    local iOtherTeam = pOtherPlayer:GetTeam();
                                    local pOtherTeam = Teams[iOtherTeam];

                                    if (pOtherPlayer ~= pPlayer and pOtherPlayer:IsAlive()) then
                                        if not (pTeam:IsAtWar(iOtherTeam)) then
                                            for pCity in pOtherPlayer:Cities() do
                                                local iCityOwner = pCity:GetOwner();
                                                local pCityOwner = Players[iCityOwner];

                                                if (pCityOwner ~= nil) and (pCityOwner ~= pPlayer) then
                                                    local iOtherTeam = pCityOwner:GetTeam();
                                                    local pOtherTeam = Teams[iOtherTeam];

                                                    if not (pTeam:IsAtWar(pOtherTeam)) then
                                                        iPeacefulReligionFollowers = pCity:GetNumFollowers(rReligion);
                                                    else
                                                        iPeacefulReligionFollowers = iPeacefulReligionFollowers;
                                                    end
                                                end
                                            end
                                            break;
                                        end
                                    end
                                end
                            end
                        end
                    end
                end
            end
        end

And a second check to determine a conversion for the display:
Code:
        for iOtherPlayer = 0, iNumCivs do
            local pOtherPlayer = Players[iOtherPlayer];
            local iOtherTeam = pOtherPlayer:GetTeam();
            local pOtherTeam = Teams[iOtherTeam];

            if (pOtherPlayer ~= pPlayer and pOtherPlayer:IsAlive()) then
                if not (pTeam:IsAtWar(iOtherTeam)) then
                    for pCity in pOtherPlayer:Cities() do
                        if (pCity:GetNumFollowers() >= 1) then

                            -- Number of total Peaceful Followers
                            if (iPeacefulReligionFollowers > 0) then
                                iNumPeacefulFollowers = iNumPeacefulFollowers + iPeacefulReligionFollowers;
                                iGlobalHappinessFromFollowers = (math.floor(iNumPeacefulFollowers / iNumFollowersPerHappiness)); -- Happiness
                            end
                        end
                    end
                end
            end
        end
The first code section seems to work (somewhat), but the second keeps returning with "0" values. After tinkering/rewriting/remaking this code for 5+ hours, I'm at wit's end getting it to display anything but a "0", "1", or "3" (all of which appeared to be static values which wouldn't update properly, or were far off from what should have displayed.

If someone could help me with this, it would be very much appreciated (and would help me with additional troubles down the road).
 
Update: I've solved the problem.

I was able to create a working bit of code by referencing the Tourism section of the WhosWinningPopup.lua and combining that with a few tidbits from above. I've also solved another issue related to this that I hadn't gone into (it regarded an oversight with a code that did something similar).

Anyways, thanks to anyone who at least looked the code over.
 
Top Bottom