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.

Changeset 10034 for ps


Ignore:
Timestamp:
08/18/11 22:28:53 (13 years ago)
Author:
philip
Message:

# Health decay for buildings not in a civ center's territory.

Location:
ps/trunk
Files:
2 added
30 edited

Legend:

Unmodified
Added
Removed
  • ps/trunk/binaries/data/mods/public/shaders/overlayline.fp

    r9929 r10034  
    1616
    1717// Use alpha from base texture
    18 MOV result.color.a, base.a;
     18MUL result.color.a, objectColor.a, base.a;
    1919
    2020END
  • ps/trunk/binaries/data/mods/public/simulation/components/Timer.js

    r8678 r10034  
    8383        var cmp = Engine.QueryInterface(t[0], t[1]);
    8484        if (!cmp)
    85             continue; // the entity was probably destroyed
     85        {
     86            // The entity was probably destroyed; clean up the timer
     87            delete this.timers[id];
     88            continue;
     89        }
    8690
    8791        try {
  • ps/trunk/binaries/data/mods/public/simulation/templates/other/hellenic_propylaea.xml

    r9963 r10034  
    4545  </Obstruction>
    4646  <TerritoryInfluence>
     47    <Root>false</Root>
    4748    <Radius>40</Radius>
    4849    <Weight>65536</Weight>
  • ps/trunk/binaries/data/mods/public/simulation/templates/other/hellenic_royal_stoa.xml

    r9963 r10034  
    4545  </Obstruction>
    4646  <TerritoryInfluence>
     47    <Root>false</Root>
    4748    <Radius>40</Radius>
    4849    <Weight>65536</Weight>
  • ps/trunk/binaries/data/mods/public/simulation/templates/other/hellenic_stoa.xml

    r9963 r10034  
    4545  </Obstruction>
    4646  <TerritoryInfluence>
     47    <Root>false</Root>
    4748    <Radius>36</Radius>
    4849    <Weight>65536</Weight>
  • ps/trunk/binaries/data/mods/public/simulation/templates/special/territory_block.xml

    r9936 r10034  
    2525  <TerritoryInfluence>
    2626    <OverrideCost>64</OverrideCost>
     27    <Root>false</Root>
    2728    <Weight>0</Weight>
    2829    <Radius>0</Radius>
  • ps/trunk/binaries/data/mods/public/simulation/templates/special/territory_pull.xml

    r9936 r10034  
    2525  <TerritoryInfluence>
    2626    <OverrideCost>0</OverrideCost>
     27    <Root>false</Root>
    2728    <Weight>0</Weight>
    2829    <Radius>0</Radius>
  • ps/trunk/binaries/data/mods/public/simulation/templates/template_structure.xml

    r9970 r10034  
    6767    <HeightOffset>12.0</HeightOffset>
    6868  </StatusBars>
     69  <TerritoryDecay>
     70    <HealthDecayRate>20</HealthDecayRate>
     71  </TerritoryDecay>
    6972  <Vision>
    7073    <Range>40</Range>
  • ps/trunk/binaries/data/mods/public/simulation/templates/template_structure_civic_civil_centre.xml

    r9994 r10034  
    7777  </Sound>
    7878  <TerritoryInfluence>
     79    <Root>true</Root>
    7980    <Radius>180</Radius>
    8081    <Weight>65536</Weight>
  • ps/trunk/binaries/data/mods/public/simulation/templates/template_structure_civic_house.xml

    r9995 r10034  
    4646  </StatusBars>
    4747  <TerritoryInfluence>
     48    <Root>false</Root>
    4849    <Radius>20</Radius>
    4950    <Weight>65536</Weight>
  • ps/trunk/binaries/data/mods/public/simulation/templates/template_structure_civic_temple.xml

    r9956 r10034  
    5252  </Sound>
    5353  <TerritoryInfluence>
     54    <Root>false</Root>
    5455    <Radius>40</Radius>
    5556    <Weight>65536</Weight>
  • ps/trunk/binaries/data/mods/public/simulation/templates/template_structure_defense_scout_tower.xml

    r9956 r10034  
    6767  </StatusBars>
    6868  <TerritoryInfluence>
     69    <Root>false</Root>
    6970    <Radius>32</Radius>
    7071    <Weight>65536</Weight>
  • ps/trunk/binaries/data/mods/public/simulation/templates/template_structure_economic_farmstead.xml

    r9956 r10034  
    4343  </Sound>
    4444  <TerritoryInfluence>
     45    <Root>false</Root>
    4546    <Radius>20</Radius>
    4647    <Weight>65536</Weight>
  • ps/trunk/binaries/data/mods/public/simulation/templates/template_structure_economic_market.xml

    r9956 r10034  
    3939  </Sound>
    4040  <TerritoryInfluence>
     41    <Root>false</Root>
    4142    <Radius>40</Radius>
    4243    <Weight>65536</Weight>
  • ps/trunk/binaries/data/mods/public/simulation/templates/template_structure_economic_mill.xml

    r9970 r10034  
    4343  </Sound>
    4444  <TerritoryInfluence>
     45    <Root>false</Root>
    4546    <Radius>20</Radius>
    4647    <Weight>65536</Weight>
  • ps/trunk/binaries/data/mods/public/simulation/templates/template_structure_military_barracks.xml

    r9956 r10034  
    4747  </Sound>
    4848  <TerritoryInfluence>
     49    <Root>false</Root>
    4950    <Radius>60</Radius>
    5051    <Weight>65536</Weight>
  • ps/trunk/binaries/data/mods/public/simulation/templates/template_structure_military_fortress.xml

    r9994 r10034  
    6363  </Sound>
    6464  <TerritoryInfluence>
     65    <Root>false</Root>
    6566    <Radius>100</Radius>
    6667    <Weight>65536</Weight>
  • ps/trunk/binaries/data/mods/public/simulation/templates/template_structure_special.xml

    r9942 r10034  
    2121  </Obstruction>
    2222  <TerritoryInfluence>
     23    <Root>false</Root>
    2324    <Radius>40</Radius>
    2425    <Weight>65536</Weight>
  • ps/trunk/source/graphics/TerritoryTexture.cpp

    r10019 r10034  
    193193        for (ssize_t i = 0; i < w; ++i)
    194194        {
    195             u8 val = territories.get(i, j);
     195            u8 val = territories.get(i, j) & ICmpTerritoryManager::TERRITORY_PLAYER_MASK;
    196196
    197197            CColor color(1, 0, 1, 1);
     
    203203            *p++ = (int)(color.r*255.f);
    204204
    205             if ((i > 0 && territories.get(i-1, j) != val)
    206              || (i < w-1 && territories.get(i+1, j) != val)
    207              || (j > 0 && territories.get(i, j-1) != val)
    208              || (j < h-1 && territories.get(i, j+1) != val)
    209 //           || (i > 0 && j > 0 && territories.get(i-1, j-1) != val)
    210 //           || (i < w-1 && j > 0 && territories.get(i+1, j-1) != val)
    211 //           || (i > 0 && j > h-1 && territories.get(i-1, j+1) != val)
    212 //           || (i < w-1 && j < h-1 && territories.get(i+1, j+1) != val)
     205            if ((i > 0 && (territories.get(i-1, j) & ICmpTerritoryManager::TERRITORY_PLAYER_MASK) != val)
     206             || (i < w-1 && (territories.get(i+1, j) & ICmpTerritoryManager::TERRITORY_PLAYER_MASK) != val)
     207             || (j > 0 && (territories.get(i, j-1) & ICmpTerritoryManager::TERRITORY_PLAYER_MASK) != val)
     208             || (j < h-1 && (territories.get(i, j+1) & ICmpTerritoryManager::TERRITORY_PLAYER_MASK) != val)
    213209            )
    214210            {
  • ps/trunk/source/simulation2/MessageTypes.h

    r9951 r10034  
    288288
    289289/**
     290 * Sent when territory assignments have changed.
     291 */
     292class CMessageTerritoriesChanged : public CMessage
     293{
     294public:
     295    DEFAULT_MESSAGE_IMPL(TerritoriesChanged)
     296
     297    CMessageTerritoriesChanged()
     298    {
     299    }
     300};
     301
     302/**
    290303 * Sent by CCmpRangeManager at most once per turn, when an active range query
    291304 * has had matching units enter/leave the range since the last RangeUpdate.
  • ps/trunk/source/simulation2/TypeList.h

    r9889 r10034  
    4646MESSAGE(RangeUpdate)
    4747MESSAGE(TerrainChanged)
     48MESSAGE(TerritoriesChanged)
    4849MESSAGE(PathResult)
    4950
  • ps/trunk/source/simulation2/components/CCmpRangeManager.cpp

    r10017 r10034  
    917917            for (u16 i = 0; i < grid.m_W; ++i)
    918918            {
    919                 u8 p = grid.get(i, j);
     919                u8 p = grid.get(i, j) & ICmpTerritoryManager::TERRITORY_PLAYER_MASK;
    920920                if (p > 0 && p <= MAX_LOS_PLAYER_ID)
    921921                {
  • ps/trunk/source/simulation2/components/CCmpTerrain.cpp

    r10017 r10034  
    5959    {
    6060        Init(paramNode);
     61    }
     62
     63    virtual bool IsLoaded()
     64    {
     65        return m_Terrain->GetVerticesPerSide() != 0;
    6166    }
    6267
  • ps/trunk/source/simulation2/components/CCmpTerritoryInfluence.cpp

    r10017 r10034  
    3131
    3232    i32 m_Cost;
     33    bool m_Root;
    3334    u32 m_Weight;
    3435    u32 m_Radius;
     
    4445                "</element>"
    4546            "</optional>"
     47            "<element name='Root'>"
     48                "<data type='boolean'/>"
     49            "</element>"
    4650            "<element name='Weight'>"
    4751                "<data type='nonNegativeInteger'/>"
     
    5963            m_Cost = -1;
    6064
     65        m_Root = paramNode.GetChild("Root").ToBool();
    6166        m_Weight = paramNode.GetChild("Weight").ToInt();
    6267        m_Radius = paramNode.GetChild("Radius").ToInt();
     
    8186    }
    8287
     88    virtual bool IsRoot()
     89    {
     90        return m_Root;
     91    }
     92
    8393    virtual u32 GetWeight()
    8494    {
  • ps/trunk/source/simulation2/components/CCmpTerritoryManager.cpp

    r10017 r10034  
    6767        componentManager.SubscribeGloballyToMessageType(MT_PositionChanged);
    6868        componentManager.SubscribeToMessageType(MT_TerrainChanged);
     69        componentManager.SubscribeToMessageType(MT_Update);
     70        componentManager.SubscribeToMessageType(MT_Interpolate);
    6971        componentManager.SubscribeToMessageType(MT_RenderSubmit);
    7072    }
     
    8183    float m_BorderSeparation;
    8284
     85    // Player ID in lower 7 bits; connected flag in high bit
    8386    Grid<u8>* m_Territories;
     87
     88    // Set to true when territories change; will send a TerritoriesChanged message
     89    // during the Update phase
     90    bool m_TriggerEvent;
     91
     92    struct SBoundaryLine
     93    {
     94        bool connected;
     95        CColor color;
     96        SOverlayTexturedLine overlay;
     97    };
     98
     99    std::vector<SBoundaryLine> m_BoundaryLines;
     100    bool m_BoundaryLinesDirty;
     101
     102    double m_AnimTime; // time since start of rendering, in seconds
     103
    84104    TerritoryOverlay* m_DebugOverlay;
    85     std::vector<SOverlayTexturedLine> m_BoundaryLines;
    86     bool m_BoundaryLinesDirty;
    87105
    88106    virtual void Init(const CParamNode& UNUSED(paramNode))
     
    92110//      m_DebugOverlay = new TerritoryOverlay(*this);
    93111        m_BoundaryLinesDirty = true;
     112        m_TriggerEvent = true;
    94113
    95114        m_DirtyID = 1;
     115
     116        m_AnimTime = 0.0;
    96117
    97118        CParamNode externalParamNode;
     
    142163            break;
    143164        }
     165        case MT_Update:
     166        {
     167            if (m_TriggerEvent)
     168            {
     169                m_TriggerEvent = false;
     170                CMessageTerritoriesChanged msg;
     171                GetSimContext().GetComponentManager().BroadcastMessage(msg);
     172            }
     173            break;
     174        }
     175        case MT_Interpolate:
     176        {
     177            const CMessageInterpolate& msgData = static_cast<const CMessageInterpolate&> (msg);
     178            Interpolate(msgData.frameTime, msgData.offset);
     179            break;
     180        }
    144181        case MT_RenderSubmit:
    145182        {
     
    167204    {
    168205        CalculateTerritories();
     206        ENSURE(m_Territories);
    169207        return *m_Territories;
    170208    }
    171209
    172     virtual int32_t GetOwner(entity_pos_t x, entity_pos_t z);
     210    virtual player_id_t GetOwner(entity_pos_t x, entity_pos_t z);
     211    virtual bool IsConnected(entity_pos_t x, entity_pos_t z);
    173212
    174213    // To support lazy updates of territory render data,
     
    183222        ++m_DirtyID;
    184223        m_BoundaryLinesDirty = true;
     224        m_TriggerEvent = true;
    185225    }
    186226
     
    206246    struct TerritoryBoundary
    207247    {
     248        bool connected;
    208249        player_id_t owner;
    209250        std::vector<CVector2D> points;
     
    213254
    214255    void UpdateBoundaryLines();
     256
     257    void Interpolate(float frameTime, float frameOffset);
    215258
    216259    void RenderSubmit(SceneCollector& collector);
     
    251294static void FloodFill(Grid<u32>& grid, Grid<u8>& costGrid, OpenQueue& openTiles, u32 falloff)
    252295{
    253     u32 tilesW = grid.m_W;
    254     u32 tilesH = grid.m_H;
     296    u16 tilesW = grid.m_W;
     297    u16 tilesH = grid.m_H;
    255298
    256299    while (!openTiles.empty())
     
    282325void CCmpTerritoryManager::CalculateTerritories()
    283326{
    284     PROFILE("CalculateTerritories");
    285 
    286327    if (m_Territories)
    287328        return;
    288329
     330    PROFILE("CalculateTerritories");
     331
    289332    CmpPtr<ICmpTerrain> cmpTerrain(GetSimContext(), SYSTEM_ENTITY);
     333
     334    // If the terrain hasn't been loaded (e.g. this is called during map initialisation),
     335    // abort the computation (and assume callers can cope with m_Territories == NULL)
     336    if (!cmpTerrain->IsLoaded())
     337        return;
     338
    290339    u16 tilesW = cmpTerrain->GetTilesPerSide();
    291340    u16 tilesH = cmpTerrain->GetTilesPerSide();
    292341
    293     SAFE_DELETE(m_Territories);
    294342    m_Territories = new Grid<u8>(tilesW, tilesH);
    295343
     
    325373    // Split influence entities into per-player lists, ignoring any with invalid properties
    326374    std::map<player_id_t, std::vector<entity_id_t> > influenceEntities;
     375    std::vector<entity_id_t> rootInfluenceEntities;
    327376    for (CComponentManager::InterfaceList::iterator it = influences.begin(); it != influences.end(); ++it)
    328377    {
     
    341390            continue;
    342391
     392        // We only have 7 bits to store tile ownership, so ignore unrepresentable players
     393        if (owner > TERRITORY_PLAYER_MASK)
     394            continue;
     395
    343396        // Ignore if invalid position
    344397        CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), it->first);
     
    347400
    348401        influenceEntities[owner].push_back(it->first);
     402
     403        if (cmpTerritoryInfluence->IsRoot())
     404            rootInfluenceEntities.push_back(it->first);
    349405    }
    350406
     
    414470        }
    415471    }
     472
     473    // Detect territories connected to a 'root' influence (typically a civ center)
     474    // belonging to their player, and mark them with the connected flag
     475    for (std::vector<entity_id_t>::iterator it = rootInfluenceEntities.begin(); it != rootInfluenceEntities.end(); ++it)
     476    {
     477        // (These components must be valid else the entities wouldn't be added to this list)
     478        CmpPtr<ICmpOwnership> cmpOwnership(GetSimContext(), *it);
     479        CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), *it);
     480
     481        CFixedVector2D pos = cmpPosition->GetPosition2D();
     482        u16 i = (u16)clamp((pos.X / (int)CELL_SIZE).ToInt_RoundToNegInfinity(), 0, tilesW-1);
     483        u16 j = (u16)clamp((pos.Y / (int)CELL_SIZE).ToInt_RoundToNegInfinity(), 0, tilesH-1);
     484
     485        u8 owner = (u8)cmpOwnership->GetOwner();
     486
     487        if (m_Territories->get(i, j) != owner)
     488            continue;
     489
     490        // TODO: would be nice to refactor some of the many flood fill
     491        // algorithms in this component
     492
     493        Grid<u8>& grid = *m_Territories;
     494
     495        u16 maxi = (u16)(grid.m_W-1);
     496        u16 maxj = (u16)(grid.m_H-1);
     497
     498        std::vector<std::pair<u16, u16> > tileStack;
     499
     500#define MARK_AND_PUSH(i, j) STMT(grid.set(i, j, owner | TERRITORY_CONNECTED_MASK); tileStack.push_back(std::make_pair(i, j)); )
     501
     502        MARK_AND_PUSH(i, j);
     503        while (!tileStack.empty())
     504        {
     505            int ti = tileStack.back().first;
     506            int tj = tileStack.back().second;
     507            tileStack.pop_back();
     508
     509            if (ti > 0 && grid.get(ti-1, tj) == owner)
     510                MARK_AND_PUSH(ti-1, tj);
     511            if (ti < maxi && grid.get(ti+1, tj) == owner)
     512                MARK_AND_PUSH(ti+1, tj);
     513            if (tj > 0 && grid.get(ti, tj-1) == owner)
     514                MARK_AND_PUSH(ti, tj-1);
     515            if (tj < maxj && grid.get(ti, tj+1) == owner)
     516                MARK_AND_PUSH(ti, tj+1);
     517
     518            if (ti > 0 && tj > 0 && grid.get(ti-1, tj-1) == owner)
     519                MARK_AND_PUSH(ti-1, tj-1);
     520            if (ti > 0 && tj < maxj && grid.get(ti-1, tj+1) == owner)
     521                MARK_AND_PUSH(ti-1, tj+1);
     522            if (ti < maxi && tj > 0 && grid.get(ti+1, tj-1) == owner)
     523                MARK_AND_PUSH(ti+1, tj-1);
     524            if (ti < maxi && tj < maxj && grid.get(ti+1, tj+1) == owner)
     525                MARK_AND_PUSH(ti+1, tj+1);
     526        }
     527
     528#undef MARK_AND_PUSH
     529    }
    416530}
    417531
     
    482596
    483597    CalculateTerritories();
     598    ENSURE(m_Territories);
    484599
    485600    // Copy the territories grid so we can mess with it
     
    507622
    508623                boundaries.push_back(TerritoryBoundary());
    509                 boundaries.back().owner = owner;
     624                boundaries.back().connected = (owner & TERRITORY_CONNECTED_MASK);
     625                boundaries.back().owner = (owner & TERRITORY_PLAYER_MASK);
    510626                std::vector<CVector2D>& points = boundaries.back().points;
    511627
     
    586702                std::vector<std::pair<u16, u16> > tileStack;
    587703
    588 #define ZERO_AND_PUSH(i, j) STMT(grid.set(i, j, 0); tileStack.push_back(std::make_pair(i, j)); )
    589 
    590                 ZERO_AND_PUSH(i, j);
     704#define MARK_AND_PUSH(i, j) STMT(grid.set(i, j, 0); tileStack.push_back(std::make_pair(i, j)); )
     705
     706                MARK_AND_PUSH(i, j);
    591707                while (!tileStack.empty())
    592708                {
     
    596712
    597713                    if (ti > 0 && grid.get(ti-1, tj) == owner)
    598                         ZERO_AND_PUSH(ti-1, tj);
     714                        MARK_AND_PUSH(ti-1, tj);
    599715                    if (ti < maxi && grid.get(ti+1, tj) == owner)
    600                         ZERO_AND_PUSH(ti+1, tj);
     716                        MARK_AND_PUSH(ti+1, tj);
    601717                    if (tj > 0 && grid.get(ti, tj-1) == owner)
    602                         ZERO_AND_PUSH(ti, tj-1);
     718                        MARK_AND_PUSH(ti, tj-1);
    603719                    if (tj < maxj && grid.get(ti, tj+1) == owner)
    604                         ZERO_AND_PUSH(ti, tj+1);
     720                        MARK_AND_PUSH(ti, tj+1);
    605721
    606722                    if (ti > 0 && tj > 0 && grid.get(ti-1, tj-1) == owner)
    607                         ZERO_AND_PUSH(ti-1, tj-1);
     723                        MARK_AND_PUSH(ti-1, tj-1);
    608724                    if (ti > 0 && tj < maxj && grid.get(ti-1, tj+1) == owner)
    609                         ZERO_AND_PUSH(ti-1, tj+1);
     725                        MARK_AND_PUSH(ti-1, tj+1);
    610726                    if (ti < maxi && tj > 0 && grid.get(ti+1, tj-1) == owner)
    611                         ZERO_AND_PUSH(ti+1, tj-1);
     727                        MARK_AND_PUSH(ti+1, tj-1);
    612728                    if (ti < maxi && tj < maxj && grid.get(ti+1, tj+1) == owner)
    613                         ZERO_AND_PUSH(ti+1, tj+1);
     729                        MARK_AND_PUSH(ti+1, tj+1);
    614730                }
    615731
    616 #undef ZERO_AND_PUSH
     732#undef MARK_AND_PUSH
    617733            }
    618734        }
     
    659775            color = cmpPlayer->GetColour();
    660776
    661         m_BoundaryLines.push_back(SOverlayTexturedLine());
    662         m_BoundaryLines.back().m_Terrain = terrain;
    663         m_BoundaryLines.back().m_TextureBase = textureBase;
    664         m_BoundaryLines.back().m_TextureMask = textureMask;
    665         m_BoundaryLines.back().m_Color = color;
    666         m_BoundaryLines.back().m_Thickness = m_BorderThickness;
     777        m_BoundaryLines.push_back(SBoundaryLine());
     778        m_BoundaryLines.back().connected = boundaries[i].connected;
     779        m_BoundaryLines.back().color = color;
     780
     781        m_BoundaryLines.back().overlay.m_Terrain = terrain;
     782        m_BoundaryLines.back().overlay.m_TextureBase = textureBase;
     783        m_BoundaryLines.back().overlay.m_TextureMask = textureMask;
     784        m_BoundaryLines.back().overlay.m_Color = color;
     785        m_BoundaryLines.back().overlay.m_Thickness = m_BorderThickness;
    667786
    668787        SimRender::SmoothPointsAverage(boundaries[i].points, true);
     
    670789        SimRender::InterpolatePointsRNS(boundaries[i].points, true, m_BorderSeparation);
    671790
    672         std::vector<float>& points = m_BoundaryLines.back().m_Coords;
     791        std::vector<float>& points = m_BoundaryLines.back().overlay.m_Coords;
    673792        for (size_t j = 0; j < boundaries[i].points.size(); ++j)
    674793        {
     
    679798}
    680799
    681 void CCmpTerritoryManager::RenderSubmit(SceneCollector& collector)
    682 {
     800void CCmpTerritoryManager::Interpolate(float frameTime, float UNUSED(frameOffset))
     801{
     802    m_AnimTime += frameTime;
     803
    683804    if (m_BoundaryLinesDirty)
    684805    {
     
    688809
    689810    for (size_t i = 0; i < m_BoundaryLines.size(); ++i)
    690         collector.Submit(&m_BoundaryLines[i]);
    691 }
    692 
    693 int32_t CCmpTerritoryManager::GetOwner(entity_pos_t x, entity_pos_t z)
     811    {
     812        if (!m_BoundaryLines[i].connected)
     813        {
     814            CColor c = m_BoundaryLines[i].color;
     815            c.a *= 0.2f + 0.8f * fabsf((float)cos(m_AnimTime * M_PI)); // TODO: should let artists tweak this
     816            m_BoundaryLines[i].overlay.m_Color = c;
     817        }
     818    }
     819}
     820
     821void CCmpTerritoryManager::RenderSubmit(SceneCollector& collector)
     822{
     823    for (size_t i = 0; i < m_BoundaryLines.size(); ++i)
     824        collector.Submit(&m_BoundaryLines[i].overlay);
     825}
     826
     827player_id_t CCmpTerritoryManager::GetOwner(entity_pos_t x, entity_pos_t z)
    694828{
    695829    u16 i, j;
    696830    CalculateTerritories();
     831    if (!m_Territories)
     832        return 0;
     833
    697834    NearestTile(x, z, i, j, m_Territories->m_W, m_Territories->m_H);
    698     return m_Territories->get(i, j);
     835    return m_Territories->get(i, j) & TERRITORY_PLAYER_MASK;
     836}
     837
     838bool CCmpTerritoryManager::IsConnected(entity_pos_t x, entity_pos_t z)
     839{
     840    u16 i, j;
     841    CalculateTerritories();
     842    if (!m_Territories)
     843        return false;
     844
     845    NearestTile(x, z, i, j, m_Territories->m_W, m_Territories->m_H);
     846    return m_Territories->get(i, j) & TERRITORY_CONNECTED_MASK;
    699847}
    700848
  • ps/trunk/source/simulation2/components/ICmpTerrain.h

    r10017 r10034  
    3030{
    3131public:
     32    virtual bool IsLoaded() = 0;
     33
    3234    virtual CFixedVector3D CalcNormal(entity_pos_t x, entity_pos_t z) = 0;
    3335
  • ps/trunk/source/simulation2/components/ICmpTerritoryInfluence.h

    r10017 r10034  
    3131    virtual i32 GetCost() = 0;
    3232
     33    virtual bool IsRoot() = 0;
     34
    3335    virtual u32 GetWeight() = 0;
    3436
  • ps/trunk/source/simulation2/components/ICmpTerritoryManager.cpp

    r9970 r10034  
    2323
    2424BEGIN_INTERFACE_WRAPPER(TerritoryManager)
    25 DEFINE_INTERFACE_METHOD_2("GetOwner", int32_t, ICmpTerritoryManager, GetOwner, entity_pos_t, entity_pos_t)
     25DEFINE_INTERFACE_METHOD_2("GetOwner", player_id_t, ICmpTerritoryManager, GetOwner, entity_pos_t, entity_pos_t)
     26DEFINE_INTERFACE_METHOD_2("IsConnected", bool, ICmpTerritoryManager, IsConnected, entity_pos_t, entity_pos_t)
    2627END_INTERFACE_WRAPPER(TerritoryManager)
  • ps/trunk/source/simulation2/components/ICmpTerritoryManager.h

    r9970 r10034  
    1919#define INCLUDED_ICMPTERRITORYMANAGER
    2020
     21#include "simulation2/system/Interface.h"
     22
    2123#include "simulation2/helpers/Grid.h"
    22 #include "simulation2/system/Interface.h"
     24#include "simulation2/helpers/Player.h"
    2325#include "simulation2/components/ICmpPosition.h"
    2426
     
    2830    virtual bool NeedUpdate(size_t* dirtyID) = 0;
    2931
     32    static const int TERRITORY_PLAYER_MASK = 0x7F;
     33    static const int TERRITORY_CONNECTED_MASK = 0x80;
     34
     35    /**
     36     * For each tile, the TERRITORY_PLAYER_MASK bits are player ID;
     37     * TERRITORY_CONNECTED_MASK is set if the tile is connected to a root object
     38     * (civ center etc).
     39     */
    3040    virtual const Grid<u8>& GetTerritoryGrid() = 0;
    3141
    3242    /**
    33      * Get owner of territory at given position
    34      *
     43     * Get owner of territory at given position.
    3544     * @return player ID of owner; 0 if neutral territory
    3645     */
    37     virtual int32_t GetOwner(entity_pos_t x, entity_pos_t z) = 0;
     46    virtual player_id_t GetOwner(entity_pos_t x, entity_pos_t z) = 0;
     47
     48    /**
     49     * Get whether territory at given position is connected to a root object
     50     * (civ center etc) owned by that territory's player.
     51     */
     52    virtual bool IsConnected(entity_pos_t x, entity_pos_t z) = 0;
    3853
    3954    DECLARE_INTERFACE_TYPE(TerritoryManager)
  • ps/trunk/source/simulation2/scripting/MessageTypeConversions.cpp

    r9950 r10034  
    1 /* Copyright (C) 2010 Wildfire Games.
     1/* Copyright (C) 2011 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
     
    2727    JSObject* obj = JS_NewObject(scriptInterface.GetContext(), NULL, NULL, NULL); \
    2828    if (! obj) \
    29         return JSVAL_VOID
     29        return JSVAL_VOID;
    3030
    3131#define SET_MSG_PROPERTY(name) \
     
    3434        if (! JS_SetProperty(scriptInterface.GetContext(), obj, #name, &prop)) \
    3535            return JSVAL_VOID; \
    36     } while (0)
     36    } while (0);
    3737
    3838#define FROMJSVAL_SETUP() \
    3939    if (! JSVAL_IS_OBJECT(val)) \
    4040        return NULL; \
    41     JSObject* obj = JSVAL_TO_OBJECT(val)
    42 jsval prop;
     41    JSObject* obj = JSVAL_TO_OBJECT(val); \
     42    jsval prop;
    4343
    4444#define GET_MSG_PROPERTY(type, name) \
     
    5959////////////////////////////////
    6060
    61 jsval CMessageTurnStart::ToJSVal(ScriptInterface& UNUSED(scriptInterface)) const
    62 {
    63     LOGWARNING(L"CMessageTurnStart::ToJSVal not implemented");
    64     return JSVAL_VOID;
     61jsval CMessageTurnStart::ToJSVal(ScriptInterface& scriptInterface) const
     62{
     63    TOJSVAL_SETUP();
     64    return OBJECT_TO_JSVAL(obj);
    6565}
    6666
     
    255255////////////////////////////////
    256256
     257jsval CMessageTerritoriesChanged::ToJSVal(ScriptInterface& scriptInterface) const
     258{
     259    TOJSVAL_SETUP();
     260    return OBJECT_TO_JSVAL(obj);
     261}
     262
     263CMessage* CMessageTerritoriesChanged::FromJSVal(ScriptInterface& UNUSED(scriptInterface), jsval UNUSED(val))
     264{
     265    return new CMessageTerritoriesChanged();
     266}
     267
     268////////////////////////////////
     269
    257270jsval CMessageRangeUpdate::ToJSVal(ScriptInterface& scriptInterface) const
    258271{
Note: See TracChangeset for help on using the changeset viewer.