Ticket #599: fogging_scripted.patch

File fogging_scripted.patch, 30.5 KB (added by Itms, 10 years ago)
  • binaries/data/mods/public/gui/session/selection_details.js

     
    172172        Engine.GetGUIObjectByName("resourceCarryingText").caption = entState.foundation.numBuilders + "    ";
    173173        Engine.GetGUIObjectByName("resourceCarryingIcon").tooltip = sprintf(translate("Number of builders.\nTasking another to this foundation would speed construction up by %(numb)s%%"), { numb : Math.round((Math.pow((entState.foundation.numBuilders+1)/entState.foundation.numBuilders, 0.7) - 1.0)*100) });
    174174    }
    175     else if (entState.resourceSupply && (!entState.resourceSupply.killBeforeGather || !entState.hitpoints))
     175    else if (entState.resourceSupply && (!entState.resourceSupply.killBeforeGather || !entState.hitpoints) && !entState.mirage)
    176176    {
    177177        Engine.GetGUIObjectByName("resourceCarryingIcon").hidden = false;
    178178        Engine.GetGUIObjectByName("resourceCarryingText").hidden = false;
  • 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/Fogging.js

     
     1const VIS_HIDDEN = 0;
     2const VIS_FOGGED = 1;
     3const VIS_VISIBLE = 2;
     4
     5function Fogging() {}
     6
     7Fogging.prototype.Schema =
     8    "<a:help>Allows this entity to be replaced by mirages entities in the fog-of-war.</a:help>" +
     9    "<empty/>";
     10
     11Fogging.prototype.Init = function()
     12{
     13    this.mirages = [];
     14    this.seen = [];
     15
     16    var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
     17    for (var i = 0; i < cmpPlayerManager.GetNumPlayers(); ++i)
     18    {
     19        this.mirages.push(INVALID_ENTITY);
     20        this.seen.push(false);
     21    }
     22};
     23
     24Fogging.prototype.LoadMirage = function(player)
     25{
     26    var cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager);
     27    var templateName = "mirage|" + cmpTemplateManager.GetCurrentTemplateName(this.entity);
     28   
     29    // If this is an entity without visibility (e.g. a foundation), it should be
     30    // marked as seen for its owner
     31    var cmpParentOwnership = Engine.QueryInterface(this.entity, IID_Ownership);
     32    if (cmpParentOwnership && cmpParentOwnership.GetOwner() == player)
     33        this.seen[player] = true;
     34
     35    if (!this.seen[player] || this.mirages[player] != INVALID_ENTITY)
     36        return;
     37
     38    this.mirages[player] = Engine.AddEntity(templateName);
     39    var cmpMirage = Engine.QueryInterface(this.mirages[player], IID_Mirage);
     40    if (!cmpMirage)
     41    {
     42        error("Failed to load mirage entity for template " + templateName);
     43        this.mirages[player] = INVALID_ENTITY;
     44        return;
     45    }
     46    // Setup basic mirage properties
     47    cmpMirage.SetPlayer(player);
     48    cmpMirage.SetParent(this.entity);
     49
     50    // Copy cmpOwnership data
     51    var cmpMirageOwnership = Engine.QueryInterface(this.mirages[player], IID_Ownership);
     52    if (!cmpParentOwnership || !cmpMirageOwnership)
     53    {
     54        error("Failed to setup the ownership data of the fogged entity " + templateName);
     55        return;
     56    }
     57    cmpMirageOwnership.SetOwner(cmpParentOwnership.GetOwner());
     58
     59    // Copy cmpPosition data
     60    var cmpParentPosition = Engine.QueryInterface(this.entity, IID_Position);
     61    var cmpMiragePosition = Engine.QueryInterface(this.mirages[player], IID_Position);
     62    if (!cmpParentPosition || !cmpMiragePosition)
     63    {
     64        error("Failed to setup the position data of the fogged entity " + templateName);
     65        return;
     66    }
     67    if (!cmpParentPosition.IsInWorld())
     68        return;
     69    var pos = cmpParentPosition.GetPosition();
     70    cmpMiragePosition.JumpTo(pos.x, pos.z);
     71    var rot = cmpParentPosition.GetRotation();
     72    cmpMiragePosition.SetYRotation(rot.y);
     73    cmpMiragePosition.SetXZRotation(rot.x, rot.z);
     74
     75    // Copy cmpVisualActor data
     76    var cmpParentVisualActor = Engine.QueryInterface(this.entity, IID_Visual);
     77    var cmpMirageVisualActor = Engine.QueryInterface(this.mirages[player], IID_Visual);
     78    if (!cmpParentVisualActor || !cmpMirageVisualActor)
     79    {
     80        error("Failed to setup the visual data of the fogged entity " + templateName);
     81        return;
     82    }
     83    cmpMirageVisualActor.SetActorSeed(cmpParentVisualActor.GetActorSeed());
     84
     85    // Store valuable information into the mirage component (especially for the GUI)
     86    var cmpHealth = Engine.QueryInterface(this.entity, IID_Health);
     87    if (cmpHealth)
     88        cmpMirage.AddHealth(cmpHealth.GetMaxHitpoints(), cmpHealth.GetHitpoints());
     89
     90    var cmpResourceSupply = Engine.QueryInterface(this.entity, IID_ResourceSupply);
     91    if (cmpResourceSupply)
     92        cmpMirage.AddResourceSupply(cmpResourceSupply.GetMaxAmount(), cmpResourceSupply.GetCurrentAmount(), cmpResourceSupply.GetType());
     93};
     94
     95Fogging.prototype.IsMiraged = function(player)
     96{
     97    if (player >= this.mirages.length)
     98        return false;
     99
     100    return this.mirages[player] != INVALID_ENTITY;
     101};
     102
     103Fogging.prototype.WasSeen = function(player)
     104{
     105    if (player >= this.seen.length)
     106        return false;
     107
     108    return this.seen[player];
     109};
     110
     111Fogging.prototype.OnVisibilityChanged = function(msg)
     112{
     113    if (msg.player >= this.mirages.length)
     114        return;
     115
     116    if (msg.newVisibility == VIS_VISIBLE)
     117    {
     118        this.seen[msg.player] = true;
     119
     120        // Destroy mirages when we get back into LoS
     121        if (this.mirages[msg.player] != INVALID_ENTITY)
     122        {
     123            Engine.DestroyEntity(this.mirages[msg.player]);
     124            this.mirages[msg.player] = INVALID_ENTITY;
     125        }
     126    }
     127
     128    // Intermediate LoS state, meaning we must create a mirage
     129    if (msg.newVisibility == VIS_FOGGED)
     130        this.LoadMirage(msg.player);
     131};
     132
     133Fogging.prototype.OnDestroy = function(msg)
     134{
     135    for each (var mirage in this.mirages)
     136    {
     137        var cmpMirage = Engine.QueryInterface(mirage, IID_Mirage);
     138        if (cmpMirage)
     139            cmpMirage.SetParent(INVALID_ENTITY);
     140    }
     141};
     142
     143Engine.RegisterComponentType(IID_Fogging, "Fogging", Fogging);
  • binaries/data/mods/public/simulation/components/GuiInterface.js

     
    179179        "garrisonHolder": null,
    180180        "gate": null,
    181181        "guard": null,
     182        "mirage": null,
    182183        "pack": null,
    183184        "player": -1,
    184185        "position": null,
     
    190191        "visibility": null,
    191192    };
    192193
     194    var cmpMirage = Engine.QueryInterface(ent, IID_Mirage);
     195
    193196    var cmpIdentity = Engine.QueryInterface(ent, IID_Identity);
    194197    if (cmpIdentity)
    195198    {
     
    216219        ret.needsRepair = cmpHealth.IsRepairable() && (cmpHealth.GetHitpoints() < cmpHealth.GetMaxHitpoints());
    217220        ret.needsHeal = !cmpHealth.IsUnhealable();
    218221    }
     222    if (cmpMirage && cmpMirage.Health())
     223    {
     224        ret.hitpoints = cmpMirage.GetHitpoints();
     225        ret.maxHitpoints = cmpMirage.GetMaxHitpoints();
     226    }
    219227
    220228    var cmpBuilder = Engine.QueryInterface(ent, IID_Builder);
    221229    if (cmpBuilder)
     
    351359        "resourceSupply": null,
    352360    };
    353361
     362    var cmpMirage = Engine.QueryInterface(ent, IID_Mirage);
     363    if (cmpMirage)
     364        ret.mirage = true;
     365
    354366    var cmpIdentity = Engine.QueryInterface(ent, IID_Identity);
    355367
    356368    var cmpAttack = Engine.QueryInterface(ent, IID_Attack);
     
    445457            "gatherers": cmpResourceSupply.GetGatherers()
    446458        };
    447459    }
     460    if (cmpMirage && cmpMirage.ResourceSupply())
     461    {
     462        ret.resourceSupply = {
     463            "max": cmpMirage.GetMaxAmount(),
     464            "amount": cmpMirage.GetAmount(),
     465            "type": cmpMirage.GetType()
     466        };
     467    }
    448468
    449469    var cmpResourceGatherer = Engine.QueryInterface(ent, IID_ResourceGatherer);
    450470    if (cmpResourceGatherer)
  • binaries/data/mods/public/simulation/components/interfaces/Messages.js

     
    11/**
    22 * Broadcast message
    33 * 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
     4 * - from Foundation component when building construction is done
     5 * - from Promotion component when unit is promoted
     6 * - from Mirage component when a fogged entity is re-discovered
    67 * Data: { entity: <integer>, newentity: <integer> }
    78 */
    89Engine.RegisterMessageType("EntityRenamed");
  • binaries/data/mods/public/simulation/components/Mirage.js

     
     1const VIS_HIDDEN = 0;
     2const VIS_FOGGED = 1;
     3const VIS_VISIBLE = 2;
     4
     5function Mirage() {}
     6
     7Mirage.prototype.Schema =
     8    "<a:help>Mirage entities replace real entities in the fog-of-war.</a:help>" +
     9    "<empty/>";
     10
     11Mirage.prototype.Init = function()
     12{
     13    this.player = undefined;
     14    this.parent = INVALID_ENTITY;
     15
     16    this.health = false;
     17    this.maxHitpoints = undefined;
     18    this.hitpoints = undefined;
     19
     20    this.resourceSupply = false;
     21    this.maxAmount = undefined;
     22    this.amount = undefined;
     23    this.type = undefined;
     24};
     25
     26Mirage.prototype.SetParent = function(ent)
     27{
     28    this.parent = ent;
     29};
     30
     31Mirage.prototype.GetPlayer = function()
     32{
     33    return this.player;
     34};
     35
     36Mirage.prototype.SetPlayer = function(player)
     37{
     38    this.player = player;
     39};
     40
     41//// Parent entity data
     42
     43////
     44// Health data
     45////
     46Mirage.prototype.AddHealth = function(maxHitpoints, hitpoints)
     47{
     48    this.health = true;
     49    this.maxHitpoints = maxHitpoints;
     50    this.hitpoints = Math.ceil(hitpoints);
     51};
     52
     53Mirage.prototype.Health = function()
     54{
     55    return this.health;
     56};
     57
     58Mirage.prototype.GetMaxHitpoints = function()
     59{
     60    return this.maxHitpoints;
     61};
     62
     63Mirage.prototype.GetHitpoints = function()
     64{
     65    return this.hitpoints;
     66};
     67
     68////
     69// ResourceSupply data
     70////
     71Mirage.prototype.AddResourceSupply = function(maxAmount, amount, type)
     72{
     73    this.resourceSupply = true;
     74    this.maxAmount = maxAmount;
     75    this.amount = amount;
     76    this.type = type;
     77};
     78
     79Mirage.prototype.ResourceSupply = function()
     80{
     81    return this.resourceSupply;
     82};
     83
     84Mirage.prototype.GetMaxAmount = function()
     85{
     86    return this.maxAmount;
     87};
     88
     89Mirage.prototype.GetAmount = function()
     90{
     91    return this.amount;
     92};
     93
     94Mirage.prototype.GetType = function()
     95{
     96    return this.type;
     97};
     98
     99////
     100
     101Mirage.prototype.OnVisibilityChanged = function(msg)
     102{
     103    if (msg.player == this.player && msg.newVisibility == VIS_VISIBLE && this.parent == INVALID_ENTITY)
     104        Engine.DestroyEntity(this.entity);
     105};
     106
     107Mirage.prototype.OnDestroy = function(msg)
     108{
     109    if (this.parent == INVALID_ENTITY)
     110        return;
     111
     112    Engine.BroadcastMessage(MT_EntityRenamed, { entity: this.entity, newentity: this.parent });
     113};
     114
     115Engine.RegisterComponentType(IID_Mirage, "Mirage", Mirage);
  • binaries/data/mods/public/simulation/components/ResourceGatherer.js

     
    243243{
    244244    var cmpPlayer = QueryOwnerInterface(this.entity, IID_Player);
    245245
     246    var type;
    246247    var cmpResourceSupply = Engine.QueryInterface(target, IID_ResourceSupply);
    247     if (!cmpResourceSupply)
     248    var cmpMirage = Engine.QueryInterface(target, IID_Mirage);
     249    if (cmpResourceSupply)
     250        type = cmpResourceSupply.GetType();
     251    else if (cmpMirage && cmpMirage.ResourceSupply())
     252        type = cmpMirage.GetType();
     253    else
    248254        return 0;
    249255
    250     var type = cmpResourceSupply.GetType();
    251 
    252256    var rates = this.GetGatherRates();
    253257
    254258    var rate;
     
    261265        rate = rates[type.generic] / cmpPlayer.GetCheatTimeMultiplier();
    262266    }
    263267
     268    if (cmpMirage)
     269        return rate || 0;
     270
    264271    // Apply diminishing returns with more gatherers, for e.g. infinite farms. For most resources this has no effect. (GetDiminishingReturns will return null.)
     272    // We can assume that for resources that are miraged this is the case. (else just add the diminishing returns data to the mirage data and remove the
     273    // early return above)
    265274    // Note to people looking to change <DiminishingReturns> in a template: This is a bit complicated. Basically, the lower that number is
    266275    // the steeper diminishing returns will be. I suggest playing around with Wolfram Alpha or a graphing calculator a bit.
    267276    // In each of the following links, replace 0.65 with the gather rate of your worker for the resource with diminishing returns and
  • binaries/data/mods/public/simulation/components/UnitAI.js

     
    19871987                    // check that we can gather from the resource we're supposed to gather from.
    19881988                    var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership);
    19891989                    var cmpSupply = Engine.QueryInterface(this.gatheringTarget, IID_ResourceSupply);
    1990                     if (!cmpSupply || !cmpSupply.AddGatherer(cmpOwnership.GetOwner(), this.entity))
     1990                    var cmpMirage = Engine.QueryInterface(this.gatheringTarget, IID_Mirage);
     1991                    if ((!cmpMirage || !cmpMirage.ResourceSupply()) &&
     1992                        (!cmpSupply || !cmpSupply.AddGatherer(cmpOwnership.GetOwner(), this.entity)))
    19911993                    {
    19921994                        // Save the current order's data in case we need it later
    19931995                        var oldType = this.order.data.type;
     
    38963898    if (cmpFormation)
    38973899        return true;
    38983900
     3901    var cmpMirage = Engine.QueryInterface(ent, IID_Mirage);
     3902    if (cmpMirage)
     3903        return true;
     3904
    38993905    var cmpHealth = Engine.QueryInterface(ent, IID_Health);
    39003906    if (!cmpHealth)
    39013907        return false;
     
    43864392    if (!cmpRangeManager)
    43874393        return false;
    43884394
     4395    // Entities that are hidden and miraged are considered visible
     4396    var cmpFogging = Engine.QueryInterface(target, IID_Fogging);
     4397    if (cmpFogging && cmpFogging.IsMiraged(cmpOwnership.GetOwner()))
     4398        return true;
     4399
    43894400    if (cmpRangeManager.GetLosVisibility(target, cmpOwnership.GetOwner(), false) == "hidden")
    43904401        return false;
    43914402
     
    50075018    // Save the resource type now, so if the resource gets destroyed
    50085019    // before we process the order then we still know what resource
    50095020    // type to look for more of
     5021    var type;
    50105022    var cmpResourceSupply = Engine.QueryInterface(target, IID_ResourceSupply);
    5011     var type = cmpResourceSupply.GetType();
     5023    var cmpMirage = Engine.QueryInterface(target, IID_Mirage);
     5024    if (cmpResourceSupply)
     5025        type = cmpResourceSupply.GetType();
     5026    else if (cmpMirage && cmpMirage.ResourceSupply())
     5027        type = cmpMirage.GetType();
     5028    else
     5029        error("CanGather allowed gathering from invalid entity");
    50125030
    50135031    // Also save the target entity's template, so that if it's an animal,
    50145032    // we won't go from hunting slow safe animals to dangerous fast ones
     
    55525570{
    55535571    if (this.IsTurret())
    55545572        return false;
    5555     // The target must be a valid resource supply.
     5573    // The target must be a valid resource supply, or the mirage of one.
    55565574    var cmpResourceSupply = Engine.QueryInterface(target, IID_ResourceSupply);
    5557     if (!cmpResourceSupply)
     5575    var cmpMirage = Engine.QueryInterface(target, IID_Mirage);
     5576    if (!cmpResourceSupply && !(cmpMirage && cmpMirage.ResourceSupply()) )
    55585577        return false;
    55595578
    55605579    // Formation controllers should always respond to commands
  • binaries/data/mods/public/simulation/helpers/Commands.js

     
    980980            "queued": cmd.queued
    981981        });
    982982    }
     983   
     984    // Load a mirage for the owner of this new entity
     985    var cmpFogging = Engine.QueryInterface(ent, IID_Fogging)
     986    if (cmpFogging)
     987        cmpFogging.LoadMirage(player);
    983988
    984989    return ent;
    985990}
  • 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    {
     
    380395    }
    381396}
    382397
     398void CTemplateLoader::CopyMirageSubset(CParamNode& out, const CParamNode& in)
     399{
     400    // Currently used for mirage entities replacing real ones in fog-of-war
     401
     402    std::set<std::string> permittedComponentTypes;
     403    permittedComponentTypes.insert("Footprint");
     404    permittedComponentTypes.insert("Minimap");
     405    permittedComponentTypes.insert("Ownership");
     406    permittedComponentTypes.insert("Position");
     407    permittedComponentTypes.insert("Selectable");
     408    permittedComponentTypes.insert("VisualActor");
     409
     410    CParamNode::LoadXMLString(out, "<Entity/>");
     411    out.CopyFilteredChildrenOfChild(in, "Entity", permittedComponentTypes);
     412
     413    // Select a subset of identity data. We don't want to have, for example, a CC mirage
     414    // that has also the CC class and then prevents construction of other CCs
     415    std::set<std::string> identitySubset;
     416    identitySubset.insert("Civ");
     417    identitySubset.insert("GenericName");
     418    identitySubset.insert("SpecificName");
     419    identitySubset.insert("Tooltip");
     420    identitySubset.insert("History");
     421    identitySubset.insert("Icon");
     422    CParamNode identity;
     423    CParamNode::LoadXMLString(identity, "<Identity/>");
     424    identity.CopyFilteredChildrenOfChild(in.GetChild("Entity"), "Identity", identitySubset);
     425    CParamNode::LoadXMLString(out, ("<Entity>"+utf8_from_wstring(identity.ToXML())+"</Entity>").c_str());
     426
     427    // Set the entity as mirage entity
     428    CParamNode::LoadXMLString(out, "<Entity><Mirage/></Entity>");
     429    CParamNode::LoadXMLString(out, "<Entity><Vision><Range>0</Range><RetainInFog>true</RetainInFog><AlwaysVisible>false</AlwaysVisible></Vision></Entity>");
     430}
     431
    383432void CTemplateLoader::CopyFoundationSubset(CParamNode& out, const CParamNode& in)
    384433{
    385434    // TODO: this is all kind of yucky and hard-coded; it'd be nice to have a more generic
     
    394443    permittedComponentTypes.insert("Obstruction");
    395444    permittedComponentTypes.insert("Selectable");
    396445    permittedComponentTypes.insert("Footprint");
     446    permittedComponentTypes.insert("Fogging");
    397447    permittedComponentTypes.insert("Armour");
    398448    permittedComponentTypes.insert("Health");
    399449    permittedComponentTypes.insert("StatusBars");
  • source/ps/TemplateLoader.h

     
    7979    void CopyPreviewSubset(CParamNode& out, const CParamNode& in, bool corpse);
    8080
    8181    /**
     82     * Copy the components of an entity template necessary for a fogged "mirage"
     83     * entity (position, actor) into a new entity template
     84     */
     85    void CopyMirageSubset(CParamNode& out, const CParamNode& in);
     86
     87    /**
    8288     * Copy the components of an entity template necessary for a construction foundation
    8389     * (position, actor, armour, health, etc) into a new entity template
    8490     */
  • source/simulation2/components/CCmpRangeManager.cpp

     
    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"
     
    14101413        {
    14111414            CmpPtr<ICmpVision> cmpVision(ent);
    14121415            if (forceRetainInFog || (cmpVision && cmpVision->GetRetainInFog()))
    1413                 return VIS_FOGGED;
     1416            {
     1417                // Mirage entities are visible for one specific player
     1418                CmpPtr<ICmpMirage> cmpMirage(ent);
     1419                if (cmpMirage)
     1420                {
     1421                    if (cmpMirage->GetPlayer() == player)
     1422                        return VIS_FOGGED;
     1423                    else
     1424                        return VIS_HIDDEN;
     1425                }
     1426
     1427                // Real entities visibility depends on ownership
     1428                CmpPtr<ICmpOwnership> cmpOwnership(ent);
     1429                if (cmpOwnership)
     1430                {
     1431                    if (cmpOwnership->GetOwner() == player)
     1432                    {
     1433                        CmpPtr<ICmpFogging> cmpFogging(ent);
     1434                        if (!cmpFogging)
     1435                            return VIS_VISIBLE;
     1436                       
     1437                        // Fogged entities must not disappear while the mirage is not ready
     1438                        if (!cmpFogging->IsMiraged(player))
     1439                            return VIS_FOGGED;
     1440
     1441                        return VIS_HIDDEN;
     1442                    }
     1443                    else
     1444                    {
     1445                        // Fogged entities must not disappear while the mirage is not ready
     1446                        CmpPtr<ICmpFogging> cmpFogging(ent);
     1447                        if (cmpFogging && cmpFogging->WasSeen(player) && !cmpFogging->IsMiraged(player))
     1448                            return VIS_FOGGED;
     1449                       
     1450                        return VIS_HIDDEN;
     1451                    }
     1452                }
     1453               
     1454                return VIS_VISIBLE;
     1455            }
    14141456        }
    14151457
    14161458        // Otherwise not visible
  • 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#include "simulation2/scripting/ScriptComponent.h"
     24
     25BEGIN_INTERFACE_WRAPPER(Fogging)
     26END_INTERFACE_WRAPPER(Fogging)
     27
     28class CCmpFoggingScripted : public ICmpFogging
     29{
     30public:
     31    DEFAULT_SCRIPT_WRAPPER(FoggingScripted)
     32
     33    virtual bool WasSeen(player_id_t player)
     34    {
     35        return m_Script.Call<bool> ("WasSeen", player);
     36    }
     37
     38    virtual bool IsMiraged(player_id_t player)
     39    {
     40        return m_Script.Call<bool> ("IsMiraged", player);
     41    }
     42};
     43
     44REGISTER_COMPONENT_SCRIPT_WRAPPER(FoggingScripted)
  • 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 bool WasSeen(player_id_t player) = 0;
     35    virtual bool IsMiraged(player_id_t player) = 0;
     36    DECLARE_INTERFACE_TYPE(Fogging)
     37};
     38
     39#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#include "simulation2/scripting/ScriptComponent.h"
     24
     25BEGIN_INTERFACE_WRAPPER(Mirage)
     26END_INTERFACE_WRAPPER(Mirage)
     27
     28class CCmpMirageScripted : public ICmpMirage
     29{
     30public:
     31    DEFAULT_SCRIPT_WRAPPER(MirageScripted)
     32
     33    virtual player_id_t GetPlayer()
     34    {
     35        return m_Script.Call<player_id_t> ("GetPlayer");
     36    }
     37};
     38
     39REGISTER_COMPONENT_SCRIPT_WRAPPER(MirageScripted)
  • 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 player_id_t GetPlayer() = 0;
     33
     34    DECLARE_INTERFACE_TYPE(Mirage)
     35};
     36
     37#endif // INCLUDED_ICMPMIRAGE
  • source/simulation2/TypeList.h

     
    8181INTERFACE(Decay)
    8282COMPONENT(Decay)
    8383
     84INTERFACE(Fogging)
     85COMPONENT(FoggingScripted)
     86
    8487// Note: The VisualActor component relies on this component being initialized before itself, in order to support using
    8588// an entity's footprint shape for the selection boxes. This dependency is not strictly necessary, but it does avoid
    8689// some extra plumbing code to set up on-demand initialization. If you find yourself forced to break this dependency,
     
    97100INTERFACE(Minimap)
    98101COMPONENT(Minimap)
    99102
     103INTERFACE(Mirage)
     104COMPONENT(MirageScripted)
     105
    100106INTERFACE(Motion)
    101107COMPONENT(MotionBall)
    102108COMPONENT(MotionScripted)