Ticket #599: fogging.patch

File fogging.patch, 33.3 KB (added by Itms, 10 years ago)
  • binaries/data/mods/public/simulation/components/BuildingAI.js

     
    335335
    336336    var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
    337337
     338    // Entities that are hidden and miraged are considered visible
     339    var cmpFogging = Engine.QueryInterface(target, IID_Fogging);
     340    if (cmpFogging && cmpFogging.IsMiraged(cmpOwnership.GetOwner()))
     341        return true;
     342
    338343    if (cmpRangeManager.GetLosVisibility(target, cmpOwnership.GetOwner(), false) == "hidden")
    339344        return false;
    340345
  • binaries/data/mods/public/simulation/components/BuildRestrictions.js

     
    102102        if (!cmpRangeManager || !cmpOwnership)
    103103            return result; // Fail
    104104
     105        var cmpFogging = Engine.QueryInterface(this.entity, IID_Fogging);
    105106        var explored = (cmpRangeManager.GetLosVisibility(this.entity, cmpOwnership.GetOwner(), true) != "hidden");
    106         if (!explored)
     107        if (!explored && !(cmpFogging && cmpFogging.IsMiraged(cmpOwnership.GetOwner())))
    107108        {
    108109            result.message = markForTranslation("%(name)s cannot be built in unexplored area");
    109110            return result; // Fail
  • binaries/data/mods/public/simulation/components/GuiInterface.js

     
    175175        "garrisonHolder": null,
    176176        "gate": null,
    177177        "guard": null,
     178        "mirage": null,
    178179        "pack": null,
    179180        "player": -1,
    180181        "position": null,
     
    303304        };
    304305    }
    305306
     307    var cmpMirage = Engine.QueryInterface(ent, IID_Mirage);
     308    if (cmpMirage)
     309    {
     310        ret.mirage = {
     311            "parent": cmpMirage.GetParent(),
     312        };
     313    }
     314
    306315    var cmpGate = Engine.QueryInterface(ent, IID_Gate);
    307316    if (cmpGate)
    308317    {
  • binaries/data/mods/public/simulation/components/interfaces/Messages.js

     
    1 /**
    2  * Broadcast message
    3  * sent when one entity is changed to other:
    4  * from Foundation component when building constuction is done
    5  * and from Promotion component when unit is promoted
    6  * Data: { entity: <integer>, newentity: <integer> }
    7  */
    8 Engine.RegisterMessageType("EntityRenamed");
    9 
    101Engine.RegisterMessageType("DiplomacyChanged");
  • binaries/data/mods/public/simulation/components/UnitAI.js

     
    38963896    if (cmpFormation)
    38973897        return true;
    38983898
     3899    var cmpMirage = Engine.QueryInterface(ent, IID_Mirage);
     3900    if (cmpMirage)
     3901        return true;
     3902
    38993903    var cmpHealth = Engine.QueryInterface(ent, IID_Health);
    39003904    if (!cmpHealth)
    39013905        return false;
     
    43864390    if (!cmpRangeManager)
    43874391        return false;
    43884392
     4393    // Entities that are hidden and miraged are considered visible
     4394    var cmpFogging = Engine.QueryInterface(target, IID_Fogging);
     4395    if (cmpFogging && cmpFogging.IsMiraged(cmpOwnership.GetOwner()))
     4396        return true;
     4397
    43894398    if (cmpRangeManager.GetLosVisibility(target, cmpOwnership.GetOwner(), false) == "hidden")
    43904399        return false;
    43914400
  • binaries/data/mods/public/simulation/templates/template_gaia.xml

     
    11<?xml version="1.0" encoding="utf-8"?>
    22<Entity parent="template_entity_quasi">
     3  <Fogging/>
    34  <Identity>
    45    <Civ>gaia</Civ>
    56    <GenericName>Gaia</GenericName>
  • binaries/data/mods/public/simulation/templates/template_structure.xml

     
    3737    <SinkRate>3.0</SinkRate>
    3838    <SinkAccel>9.8</SinkAccel>
    3939  </Decay>
     40  <Fogging/>
    4041  <Health>
    4142    <DeathType>corpse</DeathType>
    4243    <RegenRate>0</RegenRate>
  • source/ps/TemplateLoader.cpp

     
    8080        return true;
    8181    }
    8282
     83    // Handle special case "mirage|foo"
     84    if (templateName.find("mirage|") == 0)
     85    {
     86        // Load the base entity template, if it wasn't already loaded
     87        std::string baseName = templateName.substr(7);
     88        if (!LoadTemplateFile(baseName, depth+1))
     89        {
     90            LOGERROR(L"Failed to load entity template '%hs'", baseName.c_str());
     91            return false;
     92        }
     93        // Copy a subset to the requested template
     94        CopyMirageSubset(m_TemplateFileData[templateName], m_TemplateFileData[baseName]);
     95        return true;
     96    }
     97
    8398    // Handle special case "foundation|foo"
    8499    if (templateName.find("foundation|") == 0)
    85100    {
     
    319334    }
    320335}
    321336
     337void CTemplateLoader::CopyMirageSubset(CParamNode& out, const CParamNode& in)
     338{
     339    // Currently used for mirage entities replacing real ones in fog-of-war
     340
     341    std::set<std::string> permittedComponentTypes;
     342    permittedComponentTypes.insert("Footprint");
     343    permittedComponentTypes.insert("Health");
     344    permittedComponentTypes.insert("Minimap");
     345    permittedComponentTypes.insert("Ownership");
     346    permittedComponentTypes.insert("Position");
     347    permittedComponentTypes.insert("ResourceSupply");
     348    permittedComponentTypes.insert("Selectable");
     349    permittedComponentTypes.insert("VisualActor");
     350
     351    CParamNode::LoadXMLString(out, "<Entity/>");
     352    out.CopyFilteredChildrenOfChild(in, "Entity", permittedComponentTypes);
     353
     354    // Select a subset of identity data. We don't want to have, for example, a CC mirage
     355    // that has also the CC class and then prevents construction of other CCs
     356    std::set<std::string> identitySubset;
     357    identitySubset.insert("Civ");
     358    identitySubset.insert("GenericName");
     359    identitySubset.insert("SpecificName");
     360    identitySubset.insert("Tooltip");
     361    identitySubset.insert("History");
     362    identitySubset.insert("Icon");
     363    CParamNode identity;
     364    CParamNode::LoadXMLString(identity, "<Identity/>");
     365    identity.CopyFilteredChildrenOfChild(in.GetChild("Entity"), "Identity", identitySubset);
     366    CParamNode::LoadXMLString(out, ("<Entity>"+utf8_from_wstring(identity.ToXML())+"</Entity>").c_str());
     367
     368    // Set the entity as mirage entity
     369    CParamNode::LoadXMLString(out, "<Entity><Mirage/></Entity>");
     370    CParamNode::LoadXMLString(out, "<Entity><Vision><Range>0</Range><RetainInFog>true</RetainInFog><AlwaysVisible>false</AlwaysVisible></Vision></Entity>");
     371}
     372
    322373void CTemplateLoader::CopyFoundationSubset(CParamNode& out, const CParamNode& in)
    323374{
    324375    // TODO: this is all kind of yucky and hard-coded; it'd be nice to have a more generic
     
    333384    permittedComponentTypes.insert("Obstruction");
    334385    permittedComponentTypes.insert("Selectable");
    335386    permittedComponentTypes.insert("Footprint");
     387    permittedComponentTypes.insert("Fogging");
    336388    permittedComponentTypes.insert("Armour");
    337389    permittedComponentTypes.insert("Health");
    338390    permittedComponentTypes.insert("StatusBars");
  • source/ps/TemplateLoader.h

     
    7676    void CopyPreviewSubset(CParamNode& out, const CParamNode& in, bool corpse);
    7777
    7878    /**
     79     * Copy the components of an entity template necessary for a fogged "mirage"
     80     * entity (position, actor) into a new entity template
     81     */
     82    void CopyMirageSubset(CParamNode& out, const CParamNode& in);
     83
     84    /**
    7985     * Copy the components of an entity template necessary for a construction foundation
    8086     * (position, actor, armour, health, etc) into a new entity template
    8187     */
  • source/simulation2/components/CCmpFogging.cpp

     
     1/* Copyright (C) 2014 Wildfire Games.
     2 * This file is part of 0 A.D.
     3 *
     4 * 0 A.D. is free software: you can redistribute it and/or modify
     5 * it under the terms of the GNU General Public License as published by
     6 * the Free Software Foundation, either version 2 of the License, or
     7 * (at your option) any later version.
     8 *
     9 * 0 A.D. is distributed in the hope that it will be useful,
     10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12 * GNU General Public License for more details.
     13 *
     14 * You should have received a copy of the GNU General Public License
     15 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
     16 */
     17
     18#include "precompiled.h"
     19
     20#include "simulation2/system/Component.h"
     21#include "ICmpFogging.h"
     22
     23#include "lib/utf8.h"
     24
     25#include "ICmpOwnership.h"
     26#include "ICmpPlayerManager.h"
     27#include "ICmpRangeManager.h"
     28#include "ICmpTemplateManager.h"
     29#include "ICmpVisual.h"
     30
     31#include "ICmpMirage.h"
     32#include "ICmpPosition.h"
     33
     34class CCmpFogging : public ICmpFogging
     35{
     36public:
     37    static void ClassInit(CComponentManager& componentManager)
     38    {
     39        componentManager.SubscribeToMessageType(MT_Update);
     40        componentManager.SubscribeToMessageType(MT_Destroy);
     41    }
     42
     43    DEFAULT_COMPONENT_ALLOCATOR(Fogging)
     44
     45    static std::string GetSchema()
     46    {
     47        return "<a:help>Allows this entity to be replaced by mirages entities in the fog-of-war.</a:help>"
     48            "<empty/>";
     49    }
     50
     51    virtual void Init(const CParamNode& UNUSED(paramNode))
     52    {
     53        CmpPtr<ICmpPlayerManager> cmpPlayerManager(GetSystemEntity());
     54        size_t numPlayers = cmpPlayerManager->GetNumPlayers();
     55
     56        for (size_t i = 0; i < numPlayers; ++i)
     57        {
     58            m_Mirages.push_back(INVALID_ENTITY);
     59            m_Miraged.push_back(false);
     60        }
     61    }
     62
     63    virtual void Deinit()
     64    {
     65    }
     66
     67    virtual void Serialize(ISerializer& serialize)
     68    {
     69        serialize.NumberU32_Unbounded("num players", m_Mirages.size());
     70
     71        for (size_t i = 0; i < m_Mirages.size(); ++i)
     72        {
     73            serialize.NumberU32_Unbounded("mirage entity id", m_Mirages[i]);
     74            serialize.Bool("miraging enabled", m_Miraged[i]);
     75        }
     76    }
     77
     78    virtual void Deserialize(const CParamNode& UNUSED(paramNode), IDeserializer& deserialize)
     79    {
     80        uint32_t numPlayers;
     81        deserialize.NumberU32_Unbounded("num players", numPlayers);
     82
     83        entity_id_t ent;
     84        bool enabled;
     85        for (size_t i = 0; i < numPlayers; ++i)
     86        {
     87            deserialize.NumberU32_Unbounded("mirage entity id", ent);
     88            m_Mirages.push_back(ent);
     89           
     90            deserialize.Bool("miraging enabled", enabled);
     91            m_Miraged.push_back(enabled);
     92        }
     93    }
     94
     95    virtual void HandleMessage(const CMessage& msg, bool UNUSED(global))
     96    {
     97        switch (msg.GetType())
     98        {
     99        case MT_Update:
     100            UpdateMirages();
     101            break;
     102        case MT_Destroy:
     103            for (std::vector<entity_id_t>::iterator it = m_Mirages.begin(); it < m_Mirages.end(); ++it)
     104            {
     105                CmpPtr<ICmpMirage> cmpMirage(GetSimContext(), *it);
     106                if (cmpMirage)
     107                    cmpMirage->SetParent(INVALID_ENTITY);
     108            }
     109            break;
     110        }
     111    }
     112
     113    virtual void UpdateMirages()
     114    {
     115        CComponentManager& componentManager = GetSimContext().GetComponentManager();
     116        CmpPtr<ICmpRangeManager> cmpRangeManager(GetSystemEntity());
     117        CmpPtr<ICmpTemplateManager> cmpTemplateManager(GetSystemEntity());
     118       
     119        std::string templateName = "mirage|" + cmpTemplateManager->GetCurrentTemplateName(GetEntityId());
     120       
     121        for (size_t player = 0; player < m_Mirages.size(); ++player)
     122        {
     123            ICmpRangeManager::ELosVisibility visibility = cmpRangeManager->GetLosVisibility(GetEntityHandle(), player);
     124
     125            // Nothing to update
     126            if (visibility == ICmpRangeManager::VIS_FOGGED)
     127                continue;
     128           
     129            // Destroy mirages when we get back into LoS
     130            if (visibility == ICmpRangeManager::VIS_VISIBLE)
     131            {
     132                if (m_Mirages[player] != INVALID_ENTITY)
     133                {
     134                    componentManager.DestroyComponentsSoon(m_Mirages[player]);
     135                    m_Mirages[player] = INVALID_ENTITY;
     136                }
     137                continue;
     138            }
     139           
     140            // Else, we are hidden and we should consider miraging
     141            if (!m_Miraged[player] || m_Mirages[player] != INVALID_ENTITY)
     142                continue;
     143               
     144            m_Mirages[player] = componentManager.AllocateNewEntity();
     145            componentManager.AddEntity(wstring_from_utf8(templateName), m_Mirages[player]);
     146
     147            CmpPtr<ICmpMirage> cmpMirage(GetSimContext(), m_Mirages[player]);
     148            if (!cmpMirage)
     149            {
     150                LOGERROR(L"Failed to load mirage entity for template %hs", templateName.c_str());
     151                m_Mirages[player] = INVALID_ENTITY;
     152                continue;
     153            }
     154
     155            // Setup basic mirage properties
     156            cmpMirage->SetPlayer(player);
     157            cmpMirage->SetParent(GetEntityId());
     158
     159            // Copy cmpOwnership data
     160            CmpPtr<ICmpOwnership> cmpParentOwnership(GetEntityHandle());
     161            if (!cmpParentOwnership)
     162            {
     163                LOGERROR(L"Failed to access the ownership data of the fogged entity %hs", templateName.c_str());
     164                continue;
     165            }
     166            CmpPtr<ICmpOwnership> cmpMirageOwnership(GetSimContext(), m_Mirages[player]);
     167            if (!cmpMirageOwnership)
     168            {
     169                LOGERROR(L"No valid Ownership in template %hs", templateName.c_str());
     170                continue;
     171            }
     172            player_id_t parentOwner = cmpParentOwnership->GetOwner();
     173            cmpMirageOwnership->SetOwner(parentOwner);
     174
     175            // Copy cmpPosition data
     176            CmpPtr<ICmpPosition> cmpParentPosition(GetEntityHandle());
     177            if (!cmpParentPosition)
     178            {
     179                LOGERROR(L"Failed to access the position data of the fogged entity %hs", templateName.c_str());
     180                continue;
     181            }
     182            CmpPtr<ICmpPosition> cmpMiragePosition(GetSimContext(), m_Mirages[player]);
     183            if (!cmpMiragePosition)
     184            {
     185                LOGERROR(L"No valid Position component in template %hs", templateName.c_str());
     186                continue;
     187            }
     188            // The entity may not have been moved in-world yet, if we are e.g. placing a new building
     189            if (!cmpParentPosition->IsInWorld())
     190                continue;
     191            CFixedVector3D pos = cmpParentPosition->GetPosition();
     192            cmpMiragePosition->JumpTo(pos.X, pos.Z);
     193            CFixedVector3D rot = cmpParentPosition->GetRotation();
     194            cmpMiragePosition->SetXZRotation(rot.X, rot.Z);
     195            cmpMiragePosition->SetYRotation(rot.Y);
     196
     197            // Copy cmpVisualActor data
     198            CmpPtr<ICmpVisual> cmpParentVisualActor(GetEntityHandle());
     199            if (!cmpParentVisualActor)
     200            {
     201                LOGERROR(L"Failed to access the visual actor of the fogged entity %hs", templateName.c_str());
     202                continue;
     203            }
     204            CmpPtr<ICmpVisual> cmpMirageVisualActor(GetSimContext(), m_Mirages[player]);
     205            if (!cmpMirageVisualActor)
     206            {
     207                LOGERROR(L"No valid Visual actor in template %hs", templateName.c_str());
     208                continue;
     209            }
     210            u32 parentSeed = cmpParentVisualActor->GetActorSeed();
     211            cmpMirageVisualActor->SetActorSeed(parentSeed);
     212        }
     213    }
     214
     215    virtual bool IsMiraged(player_id_t player)
     216    {
     217        if (player > m_Miraged.size())
     218        {
     219            LOGERROR(L"Tried to query miraging info for invalid player");
     220            return false;
     221        }
     222       
     223        return m_Miraged[player];
     224    }
     225
     226    virtual void SetMiraged(player_id_t player, bool enable)
     227    {
     228        if (player > m_Miraged.size())
     229        {
     230            LOGERROR(L"Tried to enable/disable a mirage for invalid player");
     231            return;
     232        }
     233       
     234        m_Miraged[player] = enable;
     235    }
     236
     237private:
     238    /// Vector of mirages, one for each player
     239    std::vector<entity_id_t> m_Mirages;
     240
     241    /// For each player, remember if the entity must be mirage'd
     242    /// (i.e. has already been seen) or not.
     243    std::vector<bool> m_Miraged;
     244};
     245
     246REGISTER_COMPONENT_TYPE(Fogging)
  • source/simulation2/components/CCmpMirage.cpp

    Property changes on: source/simulation2/components/CCmpFogging.cpp
    ___________________________________________________________________
    Added: svn:eol-style
    ## -0,0 +1 ##
    +native
    \ No newline at end of property
     
     1/* Copyright (C) 2014 Wildfire Games.
     2 * This file is part of 0 A.D.
     3 *
     4 * 0 A.D. is free software: you can redistribute it and/or modify
     5 * it under the terms of the GNU General Public License as published by
     6 * the Free Software Foundation, either version 2 of the License, or
     7 * (at your option) any later version.
     8 *
     9 * 0 A.D. is distributed in the hope that it will be useful,
     10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12 * GNU General Public License for more details.
     13 *
     14 * You should have received a copy of the GNU General Public License
     15 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
     16 */
     17
     18#include "precompiled.h"
     19
     20#include "simulation2/system/Component.h"
     21#include "simulation2/MessageTypes.h"
     22#include "ICmpMirage.h"
     23#include "ICmpRangeManager.h"
     24
     25class CCmpMirage : public ICmpMirage
     26{
     27public:
     28    static void ClassInit(CComponentManager& componentManager)
     29    {
     30        componentManager.SubscribeToMessageType(MT_Update);
     31        componentManager.SubscribeToMessageType(MT_Destroy);
     32    }
     33
     34    DEFAULT_COMPONENT_ALLOCATOR(Mirage)
     35
     36    static std::string GetSchema()
     37    {
     38        return "<a:help>Mirage entities replace real entities in the fog-of-war.</a:help>"
     39            "<empty/>";
     40    }
     41
     42    virtual void Init(const CParamNode& UNUSED(paramNode))
     43    {
     44    }
     45
     46    virtual void Deinit()
     47    {
     48    }
     49
     50    template<typename S>
     51    void SerializeCommon(S& serialize)
     52    {
     53        serialize.NumberI32_Unbounded("player", m_Player);
     54        serialize.NumberU32_Unbounded("parent", m_Parent);
     55    }
     56
     57    virtual void Serialize(ISerializer& serialize)
     58    {
     59        SerializeCommon(serialize);
     60    }
     61
     62    virtual void Deserialize(const CParamNode& UNUSED(paramNode), IDeserializer& deserialize)
     63    {
     64        SerializeCommon(deserialize);
     65    }
     66
     67    virtual void HandleMessage(const CMessage& msg, bool UNUSED(global))
     68    {
     69        switch (msg.GetType())
     70        {
     71        case MT_Update:
     72        {
     73            CmpPtr<ICmpRangeManager> cmpRangeManager(GetSystemEntity());
     74            ICmpRangeManager::ELosVisibility visibility = cmpRangeManager->GetLosVisibility(GetEntityHandle(), m_Player);
     75            if (visibility == ICmpRangeManager::VIS_VISIBLE && m_Parent == INVALID_ENTITY)
     76                GetSimContext().GetComponentManager().DestroyComponentsSoon(GetEntityId());
     77            break;
     78        }
     79        case MT_Destroy:
     80        {
     81            if (GetParent() == INVALID_ENTITY)
     82                break;
     83               
     84            CMessageEntityRenamed msg(GetEntityId(), GetParent());
     85            GetSimContext().GetComponentManager().BroadcastMessage(msg);
     86            break;
     87        }
     88        }
     89    }
     90
     91    virtual void SetPlayer(player_id_t player)
     92    {
     93        m_Player = player;
     94    }
     95
     96    virtual player_id_t GetPlayer()
     97    {
     98        return m_Player;
     99    }
     100
     101    virtual void SetParent(entity_id_t ent)
     102    {
     103        m_Parent = ent;
     104    }
     105
     106    virtual entity_id_t GetParent()
     107    {
     108        return m_Parent;
     109    }
     110
     111private:
     112    player_id_t m_Player;
     113    entity_id_t m_Parent;
     114};
     115
     116REGISTER_COMPONENT_TYPE(Mirage)
  • source/simulation2/components/CCmpRangeManager.cpp

    Property changes on: source/simulation2/components/CCmpMirage.cpp
    ___________________________________________________________________
    Added: svn:eol-style
    ## -0,0 +1 ##
    +native
    \ No newline at end of property
     
    1 /* Copyright (C) 2013 Wildfire Games.
     1/* Copyright (C) 2014 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    2323#include "ICmpTerrain.h"
    2424#include "simulation2/system/EntityMap.h"
    2525#include "simulation2/MessageTypes.h"
     26#include "simulation2/components/ICmpFogging.h"
     27#include "simulation2/components/ICmpMirage.h"
     28#include "simulation2/components/ICmpOwnership.h"
    2629#include "simulation2/components/ICmpPosition.h"
    2730#include "simulation2/components/ICmpTerritoryManager.h"
    2831#include "simulation2/components/ICmpVision.h"
     
    13641367        CLosQuerier los(GetSharedLosMask(player), m_LosState, m_TerrainVerticesPerSide);
    13651368
    13661369        if (los.IsVisible(i, j))
     1370        {
     1371            // If we see an entity, we should mirage it as soon as it falls into fog-of-war
     1372            CmpPtr<ICmpFogging> cmpFogging(ent);
     1373            if (cmpFogging)
     1374                cmpFogging->SetMiraged(player, true);
     1375           
    13671376            return VIS_VISIBLE;
     1377        }
    13681378
    13691379        // Fogged if the 'retain in fog' flag is set, and in a non-visible explored region
    13701380        if (los.IsExplored(i, j))
     
    13711381        {
    13721382            CmpPtr<ICmpVision> cmpVision(ent);
    13731383            if (forceRetainInFog || (cmpVision && cmpVision->GetRetainInFog()))
    1374                 return VIS_FOGGED;
     1384            {
     1385                // Mirage entities are visible for one specific player
     1386                CmpPtr<ICmpMirage> cmpMirage(ent);
     1387                if (cmpMirage)
     1388                {
     1389                    if (cmpMirage->GetPlayer() == player)
     1390                        return VIS_FOGGED;
     1391                    else
     1392                        return VIS_HIDDEN;
     1393                }
     1394
     1395                // Normal entities should be visible only for their owner
     1396                CmpPtr<ICmpOwnership> cmpOwnership(ent);
     1397                if (cmpOwnership)
     1398                {
     1399                    if (cmpOwnership->GetOwner() == player)
     1400                        return VIS_FOGGED;
     1401                    else
     1402                        return VIS_HIDDEN;
     1403                }
     1404               
     1405                return VIS_VISIBLE;
     1406            }
    13751407        }
    13761408
    13771409        // Otherwise not visible
  • source/simulation2/components/CCmpUnitRenderer.cpp

     
    374374        CmpPtr<ICmpVision> cmpVision(unit.entity);
    375375        if (cmpVision && cmpVision->GetAlwaysVisible())
    376376            unit.visibility = ICmpRangeManager::VIS_VISIBLE;
     377
     378        // Uncomment the following two lines to prevent the models from popping into existence
     379        // near the LOS boundary. Is rather resource intensive.
     380        //else if (cmpVision && cmpVision->GetRetainInFog())
     381        //  unit.visibility = ICmpRangeManager::VIS_VISIBLE;
     382
    377383        else
    378384        {
    379385            CmpPtr<ICmpRangeManager> cmpRangeManager(GetSystemEntity());
    380             // Uncomment the following lines to prevent the models from popping into existence
    381             // near the LOS boundary. Is rather resource intensive.
    382             //if (cmpVision->GetRetainInFog())
    383             //  unit.visibility = ICmpRangeManager::VIS_VISIBLE;
    384             //else
    385                 unit.visibility = cmpRangeManager->GetLosVisibility(unit.entity,
    386                     GetSimContext().GetCurrentDisplayedPlayer());
     386            unit.visibility = cmpRangeManager->GetLosVisibility(unit.entity,
     387                GetSimContext().GetCurrentDisplayedPlayer());
    387388        }
    388389    }
    389390    else
  • source/simulation2/components/CCmpVisualActor.cpp

     
    532532    void ReloadActor();
    533533
    534534    void Update(fixed turnLength);
    535     void UpdateVisibility();
    536535};
    537536
    538537REGISTER_COMPONENT_TYPE(VisualActor)
  • source/simulation2/components/ICmpFogging.cpp

     
     1/* Copyright (C) 2014 Wildfire Games.
     2 * This file is part of 0 A.D.
     3 *
     4 * 0 A.D. is free software: you can redistribute it and/or modify
     5 * it under the terms of the GNU General Public License as published by
     6 * the Free Software Foundation, either version 2 of the License, or
     7 * (at your option) any later version.
     8 *
     9 * 0 A.D. is distributed in the hope that it will be useful,
     10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12 * GNU General Public License for more details.
     13 *
     14 * You should have received a copy of the GNU General Public License
     15 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
     16 */
     17
     18#include "precompiled.h"
     19
     20#include "ICmpFogging.h"
     21
     22#include "simulation2/system/InterfaceScripted.h"
     23
     24BEGIN_INTERFACE_WRAPPER(Fogging)
     25DEFINE_INTERFACE_METHOD_0("UpdateMirages", void, ICmpFogging, UpdateMirages)
     26DEFINE_INTERFACE_METHOD_1("IsMiraged", bool, ICmpFogging, IsMiraged, player_id_t)
     27DEFINE_INTERFACE_METHOD_2("SetMiraged", void, ICmpFogging, SetMiraged, player_id_t, bool)
     28END_INTERFACE_WRAPPER(Fogging)
  • source/simulation2/components/ICmpFogging.h

    Property changes on: source/simulation2/components/ICmpFogging.cpp
    ___________________________________________________________________
    Added: svn:eol-style
    ## -0,0 +1 ##
    +native
    \ No newline at end of property
     
     1/* Copyright (C) 2014 Wildfire Games.
     2 * This file is part of 0 A.D.
     3 *
     4 * 0 A.D. is free software: you can redistribute it and/or modify
     5 * it under the terms of the GNU General Public License as published by
     6 * the Free Software Foundation, either version 2 of the License, or
     7 * (at your option) any later version.
     8 *
     9 * 0 A.D. is distributed in the hope that it will be useful,
     10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12 * GNU General Public License for more details.
     13 *
     14 * You should have received a copy of the GNU General Public License
     15 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
     16 */
     17
     18#ifndef INCLUDED_ICMPFOGGING
     19#define INCLUDED_ICMPFOGGING
     20
     21#include "simulation2/system/Interface.h"
     22
     23#include "simulation2/helpers/Player.h"
     24
     25
     26/**
     27 * Handles the fogging of out-of-sight enemy entities, by creating mirage
     28 * entities.
     29 * This allows hiding changes, especially destruction status or health.
     30 */
     31class ICmpFogging : public IComponent
     32{
     33public:
     34    virtual void UpdateMirages() = 0;
     35    virtual bool IsMiraged(player_id_t player) = 0;
     36    virtual void SetMiraged(player_id_t player, bool enable) = 0;
     37    DECLARE_INTERFACE_TYPE(Fogging)
     38};
     39
     40#endif // INCLUDED_ICMPFOGGING
  • source/simulation2/components/ICmpMirage.cpp

    Property changes on: source/simulation2/components/ICmpFogging.h
    ___________________________________________________________________
    Added: svn:eol-style
    ## -0,0 +1 ##
    +native
    \ No newline at end of property
     
     1/* Copyright (C) 2014 Wildfire Games.
     2 * This file is part of 0 A.D.
     3 *
     4 * 0 A.D. is free software: you can redistribute it and/or modify
     5 * it under the terms of the GNU General Public License as published by
     6 * the Free Software Foundation, either version 2 of the License, or
     7 * (at your option) any later version.
     8 *
     9 * 0 A.D. is distributed in the hope that it will be useful,
     10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12 * GNU General Public License for more details.
     13 *
     14 * You should have received a copy of the GNU General Public License
     15 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
     16 */
     17
     18#include "precompiled.h"
     19
     20#include "ICmpMirage.h"
     21
     22#include "simulation2/system/InterfaceScripted.h"
     23
     24BEGIN_INTERFACE_WRAPPER(Mirage)
     25DEFINE_INTERFACE_METHOD_1("SetPlayer", void, ICmpMirage, SetPlayer, player_id_t)
     26DEFINE_INTERFACE_METHOD_0("GetPlayer", player_id_t, ICmpMirage, GetPlayer)
     27DEFINE_INTERFACE_METHOD_1("SetParent", void, ICmpMirage, SetParent, entity_id_t)
     28DEFINE_INTERFACE_METHOD_0("GetParent", entity_id_t, ICmpMirage, GetParent)
     29END_INTERFACE_WRAPPER(Mirage)
  • source/simulation2/components/ICmpMirage.h

    Property changes on: source/simulation2/components/ICmpMirage.cpp
    ___________________________________________________________________
    Added: svn:eol-style
    ## -0,0 +1 ##
    +native
    \ No newline at end of property
     
     1/* Copyright (C) 2014 Wildfire Games.
     2 * This file is part of 0 A.D.
     3 *
     4 * 0 A.D. is free software: you can redistribute it and/or modify
     5 * it under the terms of the GNU General Public License as published by
     6 * the Free Software Foundation, either version 2 of the License, or
     7 * (at your option) any later version.
     8 *
     9 * 0 A.D. is distributed in the hope that it will be useful,
     10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12 * GNU General Public License for more details.
     13 *
     14 * You should have received a copy of the GNU General Public License
     15 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
     16 */
     17
     18#ifndef INCLUDED_ICMPMIRAGE
     19#define INCLUDED_ICMPMIRAGE
     20
     21#include "simulation2/system/Interface.h"
     22
     23#include "simulation2/helpers/Player.h"
     24
     25/**
     26 * Component allowing mirage entities to communicate with their parent entity.
     27 * See ICmpFogging.
     28 */
     29class ICmpMirage : public IComponent
     30{
     31public:
     32    virtual void SetPlayer(player_id_t player) = 0;
     33    virtual player_id_t GetPlayer() = 0;
     34    virtual void SetParent(entity_id_t ent) = 0;
     35    virtual entity_id_t GetParent() = 0;
     36    DECLARE_INTERFACE_TYPE(Mirage)
     37};
     38
     39#endif // INCLUDED_ICMPMIRAGE
  • source/simulation2/MessageTypes.h

    Property changes on: source/simulation2/components/ICmpMirage.h
    ___________________________________________________________________
    Added: svn:eol-style
    ## -0,0 +1 ##
    +native
    \ No newline at end of property
     
    1 /* Copyright (C) 2013 Wildfire Games.
     1/* Copyright (C) 2014 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    241241    entity_id_t entity;
    242242};
    243243
     244/**
     245 * This is sent when one entity is changed to other: from Foundation component when building
     246 * constuction is done, from Promotion component, from Fogging component etc.
     247 */
     248class CMessageEntityRenamed : public CMessage
     249{
     250public:
     251    DEFAULT_MESSAGE_IMPL(EntityRenamed)
     252
     253    CMessageEntityRenamed(entity_id_t entity, entity_id_t newentity) :
     254        entity(entity), newentity(newentity)
     255    {
     256    }
     257
     258    entity_id_t entity;
     259    entity_id_t newentity;
     260};
     261
    244262class CMessageOwnershipChanged : public CMessage
    245263{
    246264public:
  • source/simulation2/scripting/MessageTypeConversions.cpp

     
    1 /* Copyright (C) 2013 Wildfire Games.
     1/* Copyright (C) 2014 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    194194
    195195////////////////////////////////
    196196
     197jsval CMessageEntityRenamed::ToJSVal(ScriptInterface& scriptInterface) const
     198{
     199    TOJSVAL_SETUP();
     200    SET_MSG_PROPERTY(entity);
     201    SET_MSG_PROPERTY(newentity);
     202    return OBJECT_TO_JSVAL(obj);
     203}
     204
     205CMessage* CMessageEntityRenamed::FromJSVal(ScriptInterface& scriptInterface, jsval val)
     206{
     207    FROMJSVAL_SETUP();
     208    GET_MSG_PROPERTY(entity_id_t, entity);
     209    GET_MSG_PROPERTY(entity_id_t, newentity);
     210    return new CMessageEntityRenamed(entity, newentity);
     211}
     212
     213////////////////////////////////
     214
    197215jsval CMessageOwnershipChanged::ToJSVal(ScriptInterface& scriptInterface) const
    198216{
    199217    TOJSVAL_SETUP();
  • source/simulation2/TypeList.h

     
    1 /* Copyright (C) 2013 Wildfire Games.
     1/* Copyright (C) 2014 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    4141MESSAGE(Deserialized) // non-deterministic (use with caution)
    4242MESSAGE(Create)
    4343MESSAGE(Destroy)
     44MESSAGE(EntityRenamed)
    4445MESSAGE(OwnershipChanged)
    4546MESSAGE(PositionChanged)
    4647MESSAGE(InterpolatedPositionChanged)
     
    8081INTERFACE(Decay)
    8182COMPONENT(Decay)
    8283
     84INTERFACE(Fogging)
     85COMPONENT(Fogging)
     86
    8387// Note: The VisualActor component relies on this component being initialized before itself, in order to support using
    8488// an entity's footprint shape for the selection boxes. This dependency is not strictly necessary, but it does avoid
    8589// some extra plumbing code to set up on-demand initialization. If you find yourself forced to break this dependency,
     
    96100INTERFACE(Minimap)
    97101COMPONENT(Minimap)
    98102
     103INTERFACE(Mirage)
     104COMPONENT(Mirage)
     105
    99106INTERFACE(Motion)
    100107COMPONENT(MotionBall)
    101108COMPONENT(MotionScripted)