Ticket #958: territory_fow_building-09122011.patch
File territory_fow_building-09122011.patch, 7.5 KB (added by , 13 years ago) |
---|
-
binaries/data/mods/public/simulation/components/BuildRestrictions.js
118 118 return false; // Fail 119 119 } 120 120 121 // Check whether it's in a visible region or explored but inside player's territory 122 var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); 123 if (!cmpRangeManager) 124 { 125 return false; // Fail 126 } 127 var losState = cmpRangeManager.GetLosState(this.entity, player); 128 if (losState != "visible" && !(losState == "explored" && isOwn)) 129 { 130 return false; // Fail 131 } 132 121 133 // Check special requirements 122 134 if (this.template.Category == "Dock") 123 135 { -
binaries/data/mods/public/simulation/components/GuiInterface.js
471 471 pos.SetYRotation(cmd.angle); 472 472 } 473 473 474 // Check whether it's in a visible region475 var cmp RangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);476 var visible = (cmpRangeManager && cmpRangeManager.GetLosVisibility(ent, player) == "visible");477 var validPlacement = false;474 // Check whether it's obstructed by other entities or invalid terrain 475 var cmpBuildRestrictions = Engine.QueryInterface(ent, IID_BuildRestrictions); 476 if (!cmpBuildRestrictions) 477 error("cmpBuildRestrictions not defined"); 478 478 479 if (visible) 480 { // Check whether it's obstructed by other entities or invalid terrain 481 var cmpBuildRestrictions = Engine.QueryInterface(ent, IID_BuildRestrictions); 482 if (!cmpBuildRestrictions) 483 error("cmpBuildRestrictions not defined"); 484 485 validPlacement = (cmpBuildRestrictions && cmpBuildRestrictions.CheckPlacement(player)); 486 } 487 488 var ok = (visible && validPlacement); 479 var validPlacement = (cmpBuildRestrictions && cmpBuildRestrictions.CheckPlacement(player)); 489 480 490 481 // Set it to a red shade if this is an invalid location 491 482 var cmpVisual = Engine.QueryInterface(ent, IID_Visual); 492 483 if (cmpVisual) 493 484 { 494 if (! ok)485 if (!validPlacement) 495 486 cmpVisual.SetShadingColour(1.4, 0.4, 0.4, 1); 496 487 else 497 488 cmpVisual.SetShadingColour(1, 1, 1, 1); 498 489 } 499 490 500 return ok;491 return validPlacement; 501 492 } 502 493 503 494 return false; -
binaries/data/mods/public/simulation/helpers/Commands.js
168 168 Engine.DestroyEntity(ent); 169 169 break; 170 170 } 171 172 // Check whether it's in a visible region173 var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);174 var visible = (cmpRangeManager.GetLosVisibility(ent, player) == "visible");175 if (!visible)176 {177 // TODO: report error to player (the building site was not visible)178 print("Building site was not visible\n");179 180 Engine.DestroyEntity(ent);181 break;182 }183 171 } 184 172 185 173 var cmpCost = Engine.QueryInterface(ent, IID_Cost); -
source/simulation2/components/CCmpRangeManager.cpp
866 866 return VIS_HIDDEN; 867 867 } 868 868 869 virtual ELosState GetLosState(entity_id_t ent, player_id_t player) 870 { 871 // (We can't use m_EntityData since this needs to handle LOCAL entities too) 872 873 // Entities not with positions in the world are never visible 874 CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), ent); 875 if (cmpPosition.null() || !cmpPosition->IsInWorld()) 876 return LOS_UNEXPLORED; 877 878 CFixedVector2D pos = cmpPosition->GetPosition2D(); 879 880 int i = (pos.X / (int)CELL_SIZE).ToInt_RoundToNearest(); 881 int j = (pos.Y / (int)CELL_SIZE).ToInt_RoundToNearest(); 882 883 // Reveal flag makes all positioned entities visible 884 if (GetLosRevealAll(player)) 885 { 886 if (LosIsOffWorld(i, j)) 887 return LOS_UNEXPLORED; 888 else 889 return LOS_VISIBLE; 890 } 891 892 CLosQuerier los(player, m_LosState, m_TerrainVerticesPerSide); 893 894 if (los.IsVisible(i, j)) 895 return LOS_VISIBLE; 896 else if (los.IsExplored(i, j)) 897 return LOS_EXPLORED; 898 899 // Otherwise unexplored 900 return LOS_UNEXPLORED; 901 } 902 869 903 virtual void SetLosRevealAll(player_id_t player, bool enabled) 870 904 { 871 905 m_LosRevealAll[player] = enabled; -
source/simulation2/components/ICmpRangeManager.cpp
33 33 } 34 34 } 35 35 36 std::string ICmpRangeManager::GetLosState_wrapper(entity_id_t ent, int player) 37 { 38 ELosState state = GetLosState(ent, player); 39 switch (state) 40 { 41 case LOS_UNEXPLORED: return "unexplored"; 42 case LOS_EXPLORED: return "explored"; 43 case LOS_VISIBLE: return "visible"; 44 default: return "error"; // should never happen 45 } 46 } 47 36 48 BEGIN_INTERFACE_WRAPPER(RangeManager) 37 49 DEFINE_INTERFACE_METHOD_5("ExecuteQuery", std::vector<entity_id_t>, ICmpRangeManager, ExecuteQuery, entity_id_t, entity_pos_t, entity_pos_t, std::vector<int>, int) 38 50 DEFINE_INTERFACE_METHOD_5("CreateActiveQuery", ICmpRangeManager::tag_t, ICmpRangeManager, CreateActiveQuery, entity_id_t, entity_pos_t, entity_pos_t, std::vector<int>, int) … … 44 56 DEFINE_INTERFACE_METHOD_1("SetDebugOverlay", void, ICmpRangeManager, SetDebugOverlay, bool) 45 57 DEFINE_INTERFACE_METHOD_2("SetLosRevealAll", void, ICmpRangeManager, SetLosRevealAll, player_id_t, bool) 46 58 DEFINE_INTERFACE_METHOD_2("GetLosVisibility", std::string, ICmpRangeManager, GetLosVisibility_wrapper, entity_id_t, player_id_t) 59 DEFINE_INTERFACE_METHOD_2("GetLosState", std::string, ICmpRangeManager, GetLosState_wrapper, entity_id_t, player_id_t) 47 60 DEFINE_INTERFACE_METHOD_1("SetLosCircular", void, ICmpRangeManager, SetLosCircular, bool) 48 61 DEFINE_INTERFACE_METHOD_0("GetLosCircular", bool, ICmpRangeManager, GetLosCircular) 49 62 DEFINE_INTERFACE_METHOD_1("GetPercentMapExplored", i32, ICmpRangeManager, GetPercentMapExplored, player_id_t) -
source/simulation2/components/ICmpRangeManager.h
270 270 std::string GetLosVisibility_wrapper(entity_id_t ent, player_id_t player); 271 271 272 272 /** 273 * Returns the LOS state of the given entity, with respect to the given player. 274 * Returns LOS_UNEXPLORED if the entity doesn't exist or is not in the world. 275 * This respects the GetLosRevealAll flag. 276 * (Note this is subtly different than GetLosVisibility, which considers rendering concepts). 277 */ 278 virtual ELosState GetLosState(entity_id_t ent, player_id_t player) = 0; 279 280 /** 281 * GetLosState wrapped for script calls. 282 * Returns "unexplored", "explored" or "visible". 283 */ 284 std::string GetLosState_wrapper(entity_id_t ent, player_id_t player); 285 286 /** 273 287 * Set whether the whole map should be made visible to the given player. 274 288 * If player is -1, the map will be made visible to all players. 275 289 */