Ticket #2913: conditional-fogging.patch
File conditional-fogging.patch, 14.8 KB (added by , 9 years ago) |
---|
-
binaries/data/mods/public/gui/session/selection_details.js
164 164 Engine.GetGUIObjectByName("resourceCarryingIcon").tooltip = sprintf(translate("Gain: %(amount)s"), { amount: getTradingTooltip(entState.trader.goods.amount) }); 165 165 } 166 166 // And for number of workers 167 else if (entState.foundation && !entState.mirage)167 else if (entState.foundation && entState.visibility == "visible") 168 168 { 169 169 Engine.GetGUIObjectByName("resourceCarryingIcon").hidden = false; 170 170 Engine.GetGUIObjectByName("resourceCarryingText").hidden = false; … … 172 172 Engine.GetGUIObjectByName("resourceCarryingText").caption = entState.foundation.numBuilders + " "; 173 173 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) }); 174 174 } 175 else if (entState.resourceSupply && (!entState.resourceSupply.killBeforeGather || !entState.hitpoints) && !entState.mirage)175 else if (entState.resourceSupply && (!entState.resourceSupply.killBeforeGather || !entState.hitpoints) && entState.visibility == "visible") 176 176 { 177 177 Engine.GetGUIObjectByName("resourceCarryingIcon").hidden = false; 178 178 Engine.GetGUIObjectByName("resourceCarryingText").hidden = false; -
binaries/data/mods/public/simulation/components/Fogging.js
5 5 function Fogging() {} 6 6 7 7 Fogging.prototype.Schema = 8 "<a:help>Allows this entity to be replaced by mirage sentities in the fog-of-war.</a:help>" +8 "<a:help>Allows this entity to be replaced by mirage entities in the fog-of-war.</a:help>" + 9 9 "<empty/>"; 10 10 11 11 Fogging.prototype.Init = function() 12 12 { 13 this.activated = false; 13 14 this.mirages = []; 14 15 this.miraged = []; 15 16 this.seen = []; 16 17 17 varcmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);18 for ( varplayer = 0; player < cmpPlayerManager.GetNumPlayers(); ++player)18 let cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); 19 for (let player = 0; player < cmpPlayerManager.GetNumPlayers(); ++player) 19 20 { 20 21 this.mirages.push(INVALID_ENTITY); 21 22 this.miraged.push(false); … … 23 24 } 24 25 }; 25 26 27 Fogging.prototype.Activate = function() 28 { 29 let mustUpdate = !this.activated; 30 this.activated = true; 31 32 if (mustUpdate) 33 { 34 // Load a mirage for each player who has already seen the entity 35 let cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); 36 for (let player = 0; player < cmpPlayerManager.GetNumPlayers(); ++player) 37 { 38 if (this.seen[player]) 39 this.LoadMirage(player); 40 } 41 } 42 }; 43 44 Fogging.prototype.IsActivated = function() 45 { 46 return this.activated; 47 } 48 26 49 Fogging.prototype.LoadMirage = function(player) 27 50 { 51 if (!this.activated) 52 { 53 error("LoadMirage called for an entity with fogging deactivated"); 54 return; 55 } 56 28 57 this.miraged[player] = true; 29 58 30 59 if (this.mirages[player] == INVALID_ENTITY) … … 108 137 // Notify the GUI the entity has been replaced by a mirage, in case it is selected at this moment 109 138 var cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface); 110 139 cmpGuiInterface.AddMiragedEntity(player, this.entity, this.mirages[player]); 140 141 // Notify the range manager the visibility of this entity must be updated 142 let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); 143 cmpRangeManager.RequestVisibilityUpdate(this.entity); 111 144 }; 112 145 113 146 Fogging.prototype.ForceMiraging = function(player) 114 147 { 148 if (!this.activated) 149 return; 150 115 151 this.seen[player] = true; 116 152 this.LoadMirage(player); 117 153 }; … … 140 176 return this.seen[player]; 141 177 }; 142 178 143 Fogging.prototype.OnVisibilityChanged = function(msg)144 {145 if (msg.player >= this.mirages.length)146 return;147 148 if (msg.newVisibility == VIS_VISIBLE)149 {150 this.miraged[msg.player] = false;151 this.seen[msg.player] = true;152 }153 154 if (msg.newVisibility == VIS_FOGGED)155 this.LoadMirage(msg.player);156 };157 158 179 Fogging.prototype.OnDestroy = function(msg) 159 180 { 160 181 for (var player = 0; player < this.mirages.length; ++player) … … 172 193 } 173 194 }; 174 195 196 Fogging.prototype.OnOwnershipChanged = function(msg) 197 { 198 // Always activate fogging for non-Gaia entities 199 if (msg.to > 0) 200 this.Activate(); 201 }; 202 203 Fogging.prototype.OnVisibilityChanged = function(msg) 204 { 205 if (msg.player >= this.mirages.length) 206 return; 207 208 if (msg.newVisibility == VIS_VISIBLE) 209 { 210 this.miraged[msg.player] = false; 211 this.seen[msg.player] = true; 212 } 213 214 if (msg.newVisibility == VIS_FOGGED && this.activated) 215 this.LoadMirage(msg.player); 216 }; 217 175 218 Engine.RegisterComponentType(IID_Fogging, "Fogging", Fogging); -
binaries/data/mods/public/simulation/components/Health.js
70 70 if (this.hitpoints == 0) 71 71 return; 72 72 73 // Before changing the value, activate Fogging if necessary to hide changes 74 let cmpFogging = Engine.QueryInterface(this.entity, IID_Fogging); 75 if (cmpFogging) 76 cmpFogging.Activate(); 77 73 78 var old = this.hitpoints; 74 79 this.hitpoints = Math.max(1, Math.min(this.GetMaxHitpoints(), value)); 75 80 … … 150 155 */ 151 156 Health.prototype.Reduce = function(amount) 152 157 { 158 // Before changing the value, activate Fogging if necessary to hide changes 159 let cmpFogging = Engine.QueryInterface(this.entity, IID_Fogging); 160 if (cmpFogging) 161 cmpFogging.Activate(); 162 153 163 var state = { "killed": false }; 154 164 if (amount >= 0 && this.hitpoints == this.GetMaxHitpoints()) 155 165 { … … 208 218 209 219 Health.prototype.Increase = function(amount) 210 220 { 221 // Before changing the value, activate Fogging if necessary to hide changes 222 let cmpFogging = Engine.QueryInterface(this.entity, IID_Fogging); 223 if (cmpFogging) 224 cmpFogging.Activate(); 225 211 226 if (this.hitpoints == this.GetMaxHitpoints()) 212 227 return {"old": this.hitpoints, "new":this.hitpoints}; 213 228 -
binaries/data/mods/public/simulation/components/ResourceSupply.js
97 97 98 98 ResourceSupply.prototype.TakeResources = function(rate) 99 99 { 100 // Before changing the amount, activate Fogging if necessary to hide changes 101 let cmpFogging = Engine.QueryInterface(this.entity, IID_Fogging); 102 if (cmpFogging) 103 cmpFogging.Activate(); 104 100 105 if (this.infinite) 101 106 return { "amount": rate, "exhausted": false }; 102 107 -
binaries/data/mods/public/simulation/components/StatusBars.js
101 101 yoffset -= height * 1.2; 102 102 }; 103 103 104 var cmpMirage = Engine.QueryInterface(this.entity, IID_Mirage); 105 104 106 var cmpPack = Engine.QueryInterface(this.entity, IID_Pack); 105 107 if (cmpPack && cmpPack.IsPacking()) 106 {107 108 AddBar("pack", cmpPack.GetProgress()); 108 }109 109 110 110 var cmpHealth = Engine.QueryInterface(this.entity, IID_Health); 111 111 if (cmpHealth && cmpHealth.GetHitpoints() > 0) 112 {113 112 AddBar("health", cmpHealth.GetHitpoints() / cmpHealth.GetMaxHitpoints()); 114 } 113 else if (cmpMirage && cmpMirage.Health()) 114 AddBar("health", cmpMirage.GetHitpoints() / cmpMirage.GetMaxHitpoints()); 115 115 116 116 var cmpResourceSupply = Engine.QueryInterface(this.entity, IID_ResourceSupply); 117 117 if (cmpResourceSupply) 118 {119 118 AddBar("supply", cmpResourceSupply.IsInfinite() ? 1 : cmpResourceSupply.GetCurrentAmount() / cmpResourceSupply.GetMaxAmount()); 120 } 119 else if (cmpMirage && cmpMirage.ResourceSupply()) 120 AddBar("supply", cmpMirage.IsInfinite() ? 1 : cmpMirage.GetAmount() / cmpMirage.GetMaxAmount()); 121 121 122 122 /* 123 123 // Rank icon disabled for now - see discussion around -
source/ps/TemplateLoader.cpp
433 433 permittedComponentTypes.insert("Footprint"); 434 434 permittedComponentTypes.insert("Minimap"); 435 435 permittedComponentTypes.insert("Ownership"); 436 permittedComponentTypes.insert("OverlayRenderer"); 436 437 permittedComponentTypes.insert("Position"); 437 438 permittedComponentTypes.insert("Selectable"); 439 permittedComponentTypes.insert("StatusBars"); 440 permittedComponentTypes.insert("Visibility"); 438 441 permittedComponentTypes.insert("VisualActor"); 439 442 440 443 CParamNode::LoadXMLString(out, "<Entity/>"); … … 456 459 457 460 // Set the entity as mirage entity 458 461 CParamNode::LoadXMLString(out, "<Entity><Mirage/></Entity>"); 459 CParamNode::LoadXMLString(out, "<Entity><Visibility><RetainInFog>true</RetainInFog><AlwaysVisible>false</AlwaysVisible><Preview>false</Preview></Visibility></Entity>");460 462 } 461 463 462 464 void CTemplateLoader::CopyFoundationSubset(CParamNode& out, const CParamNode& in) -
source/simulation2/components/CCmpRangeManager.cpp
1454 1454 return VIS_HIDDEN; 1455 1455 } 1456 1456 1457 // Fogged entities must not disappear while the mirage is not ready 1457 // Fogged entities are hidden in two cases: 1458 // - They were not scouted 1459 // - A mirage replaces them 1458 1460 CmpPtr<ICmpFogging> cmpFogging(ent); 1459 if (cmpFogging && cmpFogging->WasSeen(player) && !cmpFogging->IsMiraged(player)) 1460 return VIS_FOGGED; 1461 if (cmpFogging && cmpFogging->IsActivated() && 1462 (!cmpFogging->WasSeen(player) || cmpFogging->IsMiraged(player))) 1463 return VIS_HIDDEN; 1461 1464 1462 return VIS_ HIDDEN;1465 return VIS_FOGGED; 1463 1466 } 1464 1467 1465 1468 ELosVisibility ComputeLosVisibility(entity_id_t ent, player_id_t player) … … 1557 1560 1558 1561 for (std::vector<entity_id_t>::iterator it = m_ModifiedEntities.begin(); it != m_ModifiedEntities.end(); ++it) 1559 1562 { 1560 UpdateVisibility(*it); 1563 // Don't bother updating if we already did it in a global update 1564 if (!m_GlobalVisibilityUpdate) 1565 UpdateVisibility(*it); 1561 1566 } 1562 1567 m_ModifiedEntities.clear(); 1563 1568 … … 1564 1569 m_GlobalVisibilityUpdate = false; 1565 1570 } 1566 1571 1572 virtual void RequestVisibilityUpdate(entity_id_t ent) 1573 { 1574 if (std::find(m_ModifiedEntities.begin(), m_ModifiedEntities.end(), ent) == m_ModifiedEntities.end()) 1575 m_ModifiedEntities.push_back(ent); 1576 } 1577 1567 1578 void UpdateVisibility(entity_id_t ent) 1568 1579 { 1569 1580 // Warning: Code related to fogging (like posting VisibilityChanged messages) … … 1594 1605 { 1595 1606 if (oldVisibilities[player-1] == newVisibilities[player-1]) 1596 1607 continue; 1597 1598 // Another visibility update can be necessary to take in account new mirages1599 if (std::find(m_ModifiedEntities.begin(), m_ModifiedEntities.end(), ent) == m_ModifiedEntities.end())1600 m_ModifiedEntities.push_back(ent);1601 1608 1602 1609 CMessageVisibilityChanged msg(player, ent, oldVisibilities[player-1], newVisibilities[player-1]); 1603 1610 GetSimContext().GetComponentManager().PostMessage(ent, msg); -
source/simulation2/components/ICmpFogging.cpp
1 /* Copyright (C) 201 4Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 30 30 public: 31 31 DEFAULT_SCRIPT_WRAPPER(FoggingScripted) 32 32 33 virtual bool IsActivated() 34 { 35 return m_Script.Call<bool>("IsActivated"); 36 } 37 33 38 virtual bool WasSeen(player_id_t player) 34 39 { 35 40 return m_Script.Call<bool>("WasSeen", player); -
source/simulation2/components/ICmpFogging.h
1 /* Copyright (C) 201 4Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 30 30 class ICmpFogging : public IComponent 31 31 { 32 32 public: 33 virtual bool IsActivated() = 0; 33 34 virtual bool WasSeen(player_id_t player) = 0; 34 35 virtual bool IsMiraged(player_id_t player) = 0; 35 36 virtual void ForceMiraging(player_id_t player) = 0; -
source/simulation2/components/ICmpRangeManager.cpp
52 52 DEFINE_INTERFACE_METHOD_1("GetLosRevealAll", bool, ICmpRangeManager, GetLosRevealAll, player_id_t) 53 53 DEFINE_INTERFACE_METHOD_5("GetElevationAdaptedRange", entity_pos_t, ICmpRangeManager, GetElevationAdaptedRange, CFixedVector3D, CFixedVector3D, entity_pos_t, entity_pos_t, entity_pos_t) 54 54 DEFINE_INTERFACE_METHOD_2("GetLosVisibility", std::string, ICmpRangeManager, GetLosVisibility_wrapper, entity_id_t, player_id_t) 55 DEFINE_INTERFACE_METHOD_1("RequestVisibilityUpdate", void, ICmpRangeManager, RequestVisibilityUpdate, entity_id_t) 55 56 DEFINE_INTERFACE_METHOD_1("SetLosCircular", void, ICmpRangeManager, SetLosCircular, bool) 56 57 DEFINE_INTERFACE_METHOD_0("GetLosCircular", bool, ICmpRangeManager, GetLosCircular) 57 58 DEFINE_INTERFACE_METHOD_2("SetSharedLos", void, ICmpRangeManager, SetSharedLos, player_id_t, std::vector<player_id_t>) -
source/simulation2/components/ICmpRangeManager.h
323 323 virtual ELosVisibility GetLosVisibility(CEntityHandle ent, player_id_t player) = 0; 324 324 virtual ELosVisibility GetLosVisibility(entity_id_t ent, player_id_t player) = 0; 325 325 326 /** 327 * Request the update of the visibility cache of ent at next turn. 328 * Typically used for fogging. 329 */ 330 virtual void RequestVisibilityUpdate(entity_id_t ent) = 0; 326 331 332 327 333 /** 328 334 * GetLosVisibility wrapped for script calls. 329 335 * Returns "hidden", "fogged" or "visible".