This Trac instance is not used for development anymore!

We migrated our development workflow to git and Gitea.
To test the future redirection, replace trac by ariadne in the page URL.

Ticket #2587: team_exploration.patch

File team_exploration.patch, 9.1 KB (added by Itms, 10 years ago)
  • binaries/data/mods/public/gui/summary/summary.js

     
    787787        sumVegetarianRatio();
    788788        sumFeminisation();
    789789        sumKillDeathRatio();
    790         // TODO: probably change from simple sum to union from range manager
    791         panels.miscelanous.counters.mapExploration.teamsScores[playerState.team] += playerState.statistics.percentMapExplored;
     790        panels.miscelanous.counters.mapExploration.teamsScores[playerState.team] = playerState.statistics.teamPercentMapExplored;
    792791        panels.miscelanous.counters.mapExploration.teamsScoresCaption[playerState.team] = panels.miscelanous.counters.mapExploration.teamsScores[playerState.team] + "%";
    793792    }
    794793   
  • binaries/data/mods/public/simulation/components/AIInterface.js

     
    4040    var cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
    4141   
    4242    // Return the same game state as the GUI uses
    43     var state = cmpGuiInterface.GetExtendedSimulationState(-1);
     43    var state = cmpGuiInterface.GetSimulationState(-1);
    4444   
    4545    // Add some extra AI-specific data
    4646    // add custom events and reset them for the next turn
  • binaries/data/mods/public/simulation/components/GuiInterface.js

     
    119119    var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
    120120    ret.timeElapsed = cmpTimer.GetTime();
    121121
    122     // and the game type
     122    // Add the game type
    123123    var cmpEndGameManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_EndGameManager);
    124124    ret.gameType = cmpEndGameManager.GetGameType();
    125125
     126    // Add bartering prices
     127    var cmpBarter = Engine.QueryInterface(SYSTEM_ENTITY, IID_Barter);
     128    ret.barterPrices = cmpBarter.GetPrices();
     129
    126130    return ret;
    127131};
    128132
     133/**
     134 * Returns global information about the current game state, plus statistics.
     135 * This is used by the GUI at the end of a game, in the summary screen.
     136 * Note: Amongst statistics, the team exploration map percentage is computed from
     137 * scratch, so the extended simulation state should not be requested too often.
     138 */
    129139GuiInterface.prototype.GetExtendedSimulationState = function(player)
    130140{
    131141    // Get basic simulation info
     
    141151        ret.players[i].statistics = cmpPlayerStatisticsTracker.GetStatistics();
    142152    }
    143153
    144     // Add bartering prices
    145     var cmpBarter = Engine.QueryInterface(SYSTEM_ENTITY, IID_Barter);
    146     ret.barterPrices = cmpBarter.GetPrices();
    147 
    148154    return ret;
    149155};
    150156
  • binaries/data/mods/public/simulation/components/StatisticsTracker.js

     
    142142        "tributesReceived": this.tributesReceived,
    143143        "tradeIncome": this.tradeIncome,
    144144        "treasuresCollected": this.treasuresCollected,
    145         "percentMapExplored": this.GetPercentMapExplored()
     145        "percentMapExplored": this.GetPercentMapExplored(),
     146        "teamPercentMapExplored": this.GetTeamPercentMapExplored()
    146147    };
    147148};
    148149
     
    336337    return cmpRangeManager.GetPercentMapExplored(cmpPlayer.GetPlayerID());
    337338};
    338339
     340/**
     341 * Note: cmpRangeManager.GetUnionPercentMapExplored computes statistics from scratch!
     342 * As a consequence, this function should not be called too often.
     343 */
     344StatisticsTracker.prototype.GetTeamPercentMapExplored = function()
     345{
     346    var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
     347
     348    var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
     349    var cmpPlayer = Engine.QueryInterface(this.entity, IID_Player);
     350
     351    if (!cmpPlayer)
     352        return 0;
     353
     354    var team = cmpPlayer.GetTeam();
     355    // If teams are not locked, this statistic won't be displayed, so don't bother computing
     356    if (team == -1 || !cmpPlayer.GetLockTeams())
     357        return cmpRangeManager.GetPercentMapExplored(cmpPlayer.GetPlayerID());
     358
     359    var teamPlayers = [];
     360    for (var i = 1; i < cmpPlayerManager.GetNumPlayers(); ++i)
     361    {
     362        let cmpOtherPlayer = Engine.QueryInterface(cmpPlayerManager.GetPlayerByID(i), IID_Player);
     363        if (cmpOtherPlayer && cmpOtherPlayer.GetTeam() == team)
     364            teamPlayers.push(i);
     365    }
     366
     367    return cmpRangeManager.GetUnionPercentMapExplored(teamPlayers);
     368};
     369
    339370Engine.RegisterComponentType(IID_StatisticsTracker, "StatisticsTracker", StatisticsTracker);
  • binaries/data/mods/public/simulation/components/tests/test_GuiInterface.js

     
    117117            },
    118118            "treasuresCollected": 0,
    119119            "percentMapExplored": 10,
     120            "teamPercentMapExplored": 10
    120121        };
    121122    },
    122123    IncreaseTrainedUnitsCounter: function() { return 1; },
     
    180181            },
    181182            "treasuresCollected": 0,
    182183            "percentMapExplored": 10,
     184            "teamPercentMapExplored": 10
    183185        };
    184186    },
    185187    IncreaseTrainedUnitsCounter: function() { return 1; },
     
    254256    circularMap: false,
    255257    timeElapsed: 0,
    256258    gameType: "conquest",
     259    barterPrices: {buy: {food: 150}, sell: {food: 25}}
    257260});
    258261
    259262TS_ASSERT_UNEVAL_EQUALS(cmp.GetExtendedSimulationState(), {
     
    301304                },
    302305                treasuresCollected: 0,
    303306                percentMapExplored: 10,
     307                teamPercentMapExplored: 10
    304308            },
    305309        },
    306310        {
     
    346350                },
    347351                treasuresCollected: 0,
    348352                percentMapExplored: 10,
     353                teamPercentMapExplored: 10
    349354            },
    350355        }
    351356    ],
  • source/simulation2/components/CCmpRangeManager.cpp

     
    656656            {
    657657                for (i32 i = 0; i < m_TerrainVerticesPerSide; i++)
    658658                {
    659                     if (!LosIsOffWorld(i, j))
    660                     {
    661                         for (u8 k = 1; k < MAX_LOS_PLAYER_ID+1; ++k)
    662                             m_ExploredVertices.at(k) += ((m_LosState[j*m_TerrainVerticesPerSide + i] & (LOS_EXPLORED << (2*(k-1)))) > 0);
    663                     }
     659                    if (LosIsOffWorld(i, j))
     660                        continue;
     661
     662                    for (u8 k = 1; k < MAX_LOS_PLAYER_ID+1; ++k)
     663                        m_ExploredVertices.at(k) += ((m_LosState[j*m_TerrainVerticesPerSide + i] & (LOS_EXPLORED << (2*(k-1)))) > 0);
    664664                }
    665665            }
    666666        }
     
    20482048    {
    20492049        return m_ExploredVertices.at((u8)player) * 100 / m_TotalInworldVertices;
    20502050    }
     2051
     2052    virtual u8 GetUnionPercentMapExplored(std::vector<player_id_t> players)
     2053    {
     2054        u32 exploredVertices = 0;
     2055        std::vector<player_id_t>::iterator playerIt;
     2056
     2057        for (i32 j = 0; j < m_TerrainVerticesPerSide; j++)
     2058        {
     2059            for (i32 i = 0; i < m_TerrainVerticesPerSide; i++)
     2060            {
     2061                if (LosIsOffWorld(i, j))
     2062                    continue;
     2063
     2064                for (playerIt = players.begin(); playerIt != players.end(); ++playerIt)
     2065                {
     2066                    if ((m_LosState[j*m_TerrainVerticesPerSide + i] & (LOS_EXPLORED << (2*((*playerIt)-1)))) == 0)
     2067                        continue;
     2068
     2069                    exploredVertices += 1;
     2070                    break;
     2071                }
     2072            }
     2073        }
     2074
     2075        return exploredVertices * 100 / m_TotalInworldVertices;
     2076    }
    20512077};
    20522078
    20532079REGISTER_COMPONENT_TYPE(RangeManager)
  • source/simulation2/components/ICmpRangeManager.cpp

     
    5656DEFINE_INTERFACE_METHOD_0("GetLosCircular", bool, ICmpRangeManager, GetLosCircular)
    5757DEFINE_INTERFACE_METHOD_2("SetSharedLos", void, ICmpRangeManager, SetSharedLos, player_id_t, std::vector<player_id_t>)
    5858DEFINE_INTERFACE_METHOD_1("GetPercentMapExplored", u8, ICmpRangeManager, GetPercentMapExplored, player_id_t)
     59DEFINE_INTERFACE_METHOD_1("GetUnionPercentMapExplored", u8, ICmpRangeManager, GetUnionPercentMapExplored, std::vector<player_id_t>)
    5960END_INTERFACE_WRAPPER(RangeManager)
  • source/simulation2/components/ICmpRangeManager.h

     
    380380     */
    381381    virtual u8 GetPercentMapExplored(player_id_t player) = 0;
    382382
     383    /**
     384     * Get percent map explored statistics for specified set of players.
     385     * Note: this function computes statistics from scratch and should not be called too often.
     386     */
     387    virtual u8 GetUnionPercentMapExplored(std::vector<player_id_t> players) = 0;
    383388
     389
    384390    /**
    385391     * Perform some internal consistency checks for testing/debugging.
    386392     */