Ticket #921: building-placement-notifications-02222013.patch
File building-placement-notifications-02222013.patch, 28.6 KB (added by , 11 years ago) |
---|
-
binaries/data/mods/public/gui/session/input.js
82 82 if (!tooltipSet) 83 83 informationTooltip.hidden = true; 84 84 85 var wallDragTooltip = getGUIObjectByName("wallDragTooltip");86 if (placementSupport. wallDragTooltip)85 var placementTooltip = getGUIObjectByName("placementTooltip"); 86 if (placementSupport.tooltipMessage) 87 87 { 88 wallDragTooltip.caption = placementSupport.wallDragTooltip;89 wallDragTooltip.hidden = false;88 placementTooltip.caption = placementSupport.tooltipMessage; 89 placementTooltip.hidden = false; 90 90 } 91 91 else 92 92 { 93 wallDragTooltip.caption = "";94 wallDragTooltip.hidden = true;93 placementTooltip.caption = ""; 94 placementTooltip.hidden = true; 95 95 } 96 96 } 97 97 … … 105 105 { 106 106 if (placementSupport.template && placementSupport.position) 107 107 { 108 returnEngine.GuiInterfaceCall("SetBuildingPlacementPreview", {108 var result = Engine.GuiInterfaceCall("SetBuildingPlacementPreview", { 109 109 "template": placementSupport.template, 110 110 "x": placementSupport.position.x, 111 111 "z": placementSupport.position.z, 112 112 "angle": placementSupport.angle, 113 113 "actorSeed": placementSupport.actorSeed 114 114 }); 115 116 // Show placement info tooltip if invalid position 117 placementSupport.tooltipMessage = result.success ? "" : result.message; 118 return result.success; 115 119 } 116 120 } 117 121 else if (placementSupport.mode === "wall") … … 862 866 863 867 if (result && result.cost) 864 868 { 865 placementSupport. wallDragTooltip= getEntityCostTooltip(result);869 placementSupport.tooltipMessage = getEntityCostTooltip(result); 866 870 var neededResources = Engine.GuiInterfaceCall("GetNeededResources", result.cost); 867 871 if (neededResources) 868 placementSupport. wallDragTooltip+= getNeededResourcesTooltip(neededResources);872 placementSupport.tooltipMessage += getNeededResourcesTooltip(neededResources); 869 873 } 870 874 871 875 break; … … 892 896 } 893 897 else 894 898 { 895 placementSupport. wallDragTooltip= "Cannot build wall here!";899 placementSupport.tooltipMessage = "Cannot build wall here!"; 896 900 } 897 901 898 902 updateBuildingPlacementPreview(); -
binaries/data/mods/public/gui/session/placement.js
13 13 this.mode = null; 14 14 this.position = null; 15 15 this.template = null; 16 this.tooltipMessage = ""; // tooltip text to show while the user is placing a building 16 17 this.wallSet = null; // maps types of wall pieces ("tower", "long", "short", ...) to template names 17 18 this.wallSnapEntities = null; // list of candidate entities to snap the starting and (!) ending positions to when building walls 18 19 this.wallEndPosition = null; 19 20 this.wallSnapEntitiesIncludeOffscreen = false; // should the next update of the snap candidate list include offscreen towers? 20 this.wallDragTooltip = null; // tooltip text while the user is draggin the wall. Used to indicate the current cost to build the wall.21 21 22 22 this.SetDefaultAngle(); 23 23 this.RandomizeActorSeed(); -
binaries/data/mods/public/gui/session/session.xml
688 688 <object name="informationTooltip" type="tooltip" independent="true" style="informationTooltip"/> 689 689 690 690 <!-- ================================ ================================ --> 691 <!-- Wall-dragging tooltip. Shows the total cost of building a wall while the player is dragging it.-->691 <!-- Building placement info tooltip --> 692 692 <!-- ================================ ================================ --> 693 <object name=" wallDragTooltip" type="tooltip" independent="true" style="informationTooltip"/>693 <object name="placementTooltip" type="tooltip" independent="true" style="informationTooltip"/> 694 694 695 695 <!-- ================================ ================================ --> 696 696 <!-- START of BOTTOM PANEL --> -
binaries/data/mods/public/simulation/components/BuildRestrictions.js
75 75 */ 76 76 BuildRestrictions.prototype.CheckPlacement = function() 77 77 { 78 // TODO: Return error code for invalid placement, which can be handled by the UI 78 var cmpIdentity = Engine.QueryInterface(this.entity, IID_Identity); 79 var name = cmpIdentity ? cmpIdentity.GetGenericName() : "Building"; 79 80 81 var result = { 82 "success": false, 83 "message": name+" cannot be built due to unknown error", 84 }; 85 86 // Check whether it's in a visible or fogged region 87 // tell GetLosVisibility to force RetainInFog because preview entities set this to false, 88 // which would show them as hidden instead of fogged 89 var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); 90 var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); 91 if (!cmpRangeManager || !cmpOwnership) 92 return result; // Fail 93 94 var explored = (cmpRangeManager.GetLosVisibility(this.entity, cmpOwnership.GetOwner(), true) != "hidden"); 95 if (!explored) 96 { 97 result.message = name+" cannot be built in unexplored area"; 98 return result; // Fail 99 } 100 80 101 // Check obstructions and terrain passability 81 102 var passClassName = ""; 82 103 switch (this.template.PlacementType) … … 91 112 } 92 113 93 114 var cmpObstruction = Engine.QueryInterface(this.entity, IID_Obstruction); 94 if (!cmpObstruction || !cmpObstruction.CheckFoundation(passClassName)) 115 if (!cmpObstruction) 116 return result; // Fail 117 118 var ret = cmpObstruction.CheckFoundation(passClassName); 119 if (ret != "success") 95 120 { 96 return false; // Fail 121 switch (ret) 122 { 123 case "fail_error": 124 case "fail_no_obstruction": 125 error("CheckPlacement: Error returned from CheckFoundation"); 126 break; 127 case "fail_obstructs_foundation": 128 result.message = name+" cannot be built on another building or resource"; 129 break; 130 case "fail_terrain_class": 131 // TODO: list valid terrain? 132 result.message = name+" cannot be built on invalid terrain"; 133 } 134 return result; // Fail 97 135 } 98 136 99 137 // Check territory restrictions 100 138 var cmpTerritoryManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TerritoryManager); 101 139 var cmpPlayer = QueryOwnerInterface(this.entity, IID_Player); 102 140 var cmpPosition = Engine.QueryInterface(this.entity, IID_Position); 103 141 if (!(cmpTerritoryManager && cmpPlayer && cmpPosition && cmpPosition.IsInWorld())) 104 { 105 return false; // Fail 106 } 107 142 return result; // Fail 143 108 144 var pos = cmpPosition.GetPosition2D(); 109 145 var tileOwner = cmpTerritoryManager.GetOwner(pos.x, pos.y); 110 146 var isOwn = (tileOwner == cmpPlayer.GetPlayerID()); … … 112 148 var isAlly = !isOwn && cmpPlayer.IsAlly(tileOwner); 113 149 // We count neutral players as enemies, so you can't build in their territory. 114 150 var isEnemy = !isNeutral && (cmpPlayer.IsEnemy(tileOwner) || cmpPlayer.IsNeutral(tileOwner)); 115 116 if ((isAlly && !this.HasTerritory("ally")) 117 || (isOwn && !this.HasTerritory("own")) 118 || (isNeutral && !this.HasTerritory("neutral")) 119 || (isEnemy && !this.HasTerritory("enemy"))) 151 152 var territoryFail = true; 153 var territoryType = ""; 154 if (isAlly && !this.HasTerritory("ally")) 155 territoryType = "ally"; 156 else if (isOwn && !this.HasTerritory("own")) 157 territoryType = "own"; 158 else if (isNeutral && !this.HasTerritory("neutral")) 159 territoryType = "neutral"; 160 else if (isEnemy && !this.HasTerritory("enemy")) 161 territoryType = "enemy"; 162 else 163 territoryFail = false 164 165 if (territoryFail) 120 166 { 121 return false; // Fail 167 result.message = name+" cannot be built in "+territoryType+" territory. Valid territories: " + this.GetTerritories().join(", "); 168 return result; // Fail 122 169 } 123 170 124 171 // Check special requirements 125 172 if (this.template.Category == "Dock") 126 173 { … … 130 177 // so it's correct even if the criteria changes for these units 131 178 var cmpFootprint = Engine.QueryInterface(this.entity, IID_Footprint); 132 179 if (!cmpFootprint) 133 { 134 return false; // Fail 135 } 136 180 return result; // Fail 181 137 182 // Get building's footprint 138 183 var shape = cmpFootprint.GetShape(); 139 184 var halfSize = 0; 140 185 if (shape.type == "square") 141 {142 186 halfSize = shape.depth/2; 143 }144 187 else if (shape.type == "circle") 145 {146 188 halfSize = shape.radius; 147 } 148 189 149 190 var cmpTerrain = Engine.QueryInterface(SYSTEM_ENTITY, IID_Terrain); 150 191 var cmpWaterManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_WaterManager); 151 192 if (!cmpTerrain || !cmpWaterManager) 152 { 153 return false; // Fail 154 } 155 193 return result; // Fail 194 156 195 var ang = cmpPosition.GetRotation().y; 157 196 var sz = halfSize * Math.sin(ang); 158 197 var cz = halfSize * Math.cos(ang); 159 198 if ((cmpWaterManager.GetWaterLevel(pos.x + sz, pos.y + cz) - cmpTerrain.GetGroundLevel(pos.x + sz, pos.y + cz)) < 1.0 // front 160 199 || (cmpWaterManager.GetWaterLevel(pos.x - sz, pos.y - cz) - cmpTerrain.GetGroundLevel(pos.x - sz, pos.y - cz)) > 2.0) // back 161 200 { 162 return false; // Fail 201 result.message = name+" must be built on a valid shoreline"; 202 return result; // Fail 163 203 } 164 204 } 165 205 166 206 // Check distance restriction 167 207 if (this.template.Distance) 168 208 { … … 189 229 } 190 230 } 191 231 } 192 193 if ((this.template.Distance.MinDistance && nearest < this.template.Distance.MinDistance) 194 || (this.template.Distance.MaxDistance && nearest > this.template.Distance.MaxDistance)) 232 233 if (this.template.Distance.MinDistance && nearest < +this.template.Distance.MinDistance) 195 234 { 196 return false; // Fail 235 result.message = name+" too close to a "+cmpBuildRestrictions.GetCategory()+", must be at least "+ +this.template.Distance.MinDistance+" meters away"; 236 return result; // Fail 197 237 } 238 else if (this.template.Distance.MaxDistance && nearest > +this.template.Distance.MaxDistance) 239 { 240 result.message = name+" too far away from a "+cmpBuildRestrictions.GetCategory()+", must be within "+ +this.template.Distance.MaxDistance+" meters"; 241 return result; // Fail 242 } 198 243 } 199 244 200 245 // Success 201 return true; 246 result.success = true; 247 result.message = ""; 248 return result; 202 249 }; 203 250 204 251 BuildRestrictions.prototype.GetCategory = function() -
binaries/data/mods/public/simulation/components/GuiInterface.js
798 798 * cmd.template is the name of the entity template, or "" to disable the preview. 799 799 * cmd.x, cmd.z, cmd.angle give the location. 800 800 * 801 * Returns true if the placement is okay (everything is valid and the entity is not obstructed by others). 801 * Returns result object: 802 * { 803 * "success": true if the placement is okay (everything is valid and the entity is not obstructed by others) 804 * "message": message to display in UI, if invalid placement 805 * } 802 806 */ 803 807 GuiInterface.prototype.SetBuildingPlacementPreview = function(player, cmd) 804 808 { 809 var result = { 810 "success": false, 811 "message": "", 812 } 813 805 814 // See if we're changing template 806 815 if (!this.placementEntity || this.placementEntity[0] != cmd.template) 807 816 { … … 832 841 pos.SetYRotation(cmd.angle); 833 842 } 834 843 835 // Check whether it's in a visible or fogged region836 // tell GetLosVisibility to force RetainInFog because preview entities set this to false,837 // which would show them as hidden instead of fogged838 var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);839 var visible = (cmpRangeManager && cmpRangeManager.GetLosVisibility(ent, player, true) != "hidden");840 844 var validPlacement = false; 841 842 845 var cmpOwnership = Engine.QueryInterface(ent, IID_Ownership); 843 846 cmpOwnership.SetOwner(player); 844 847 845 if (visible) 846 { // Check whether it's obstructed by other entities or invalid terrain 847 var cmpBuildRestrictions = Engine.QueryInterface(ent, IID_BuildRestrictions); 848 if (!cmpBuildRestrictions) 849 error("cmpBuildRestrictions not defined"); 850 851 validPlacement = (cmpBuildRestrictions && cmpBuildRestrictions.CheckPlacement()); 848 // Check whether it's obstructed by other entities or invalid terrain 849 var cmpBuildRestrictions = Engine.QueryInterface(ent, IID_BuildRestrictions); 850 if (!cmpBuildRestrictions) 851 error("cmpBuildRestrictions not defined"); 852 else 853 { 854 result = cmpBuildRestrictions.CheckPlacement(); 855 validPlacement = result.success; 852 856 } 853 857 854 var ok = (visible && validPlacement);855 856 858 // Set it to a red shade if this is an invalid location 857 859 var cmpVisual = Engine.QueryInterface(ent, IID_Visual); 858 860 if (cmpVisual) 859 861 { 860 862 if (cmd.actorSeed !== undefined) 861 863 cmpVisual.SetActorSeed(cmd.actorSeed); 862 863 if (! ok)864 865 if (!validPlacement) 864 866 cmpVisual.SetShadingColour(1.4, 0.4, 0.4, 1); 865 867 else 866 868 cmpVisual.SetShadingColour(1, 1, 1, 1); 867 869 } 868 869 return ok;870 870 } 871 871 872 return false;872 return result; 873 873 }; 874 874 875 875 /** … … 1317 1317 continue; 1318 1318 } 1319 1319 1320 validPlacement = (cmpBuildRestrictions && cmpBuildRestrictions.CheckPlacement()); 1320 // TODO: Handle results of CheckPlacement 1321 validPlacement = (cmpBuildRestrictions && cmpBuildRestrictions.CheckPlacement().success); 1321 1322 1322 1323 // If a wall piece has two control groups, it's likely a segment that spans 1323 1324 // between two existing towers. To avoid placing a duplicate wall segment, -
binaries/data/mods/public/simulation/components/Identity.js
133 133 return (this.template.SelectionGroupName || ""); 134 134 }; 135 135 136 Identity.prototype.GetGenericName = function() 137 { 138 return this.template.GenericName; 139 }; 140 136 141 Engine.RegisterComponentType(IID_Identity, "Identity", Identity); -
source/simulation2/components/CCmpFootprint.cpp
1 /* Copyright (C) 201 2Wildfire Games.1 /* Copyright (C) 2013 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 … … 186 186 CFixedVector3D pos (initialPos.X + s.Multiply(radius), fixed::Zero(), initialPos.Y + c.Multiply(radius)); 187 187 188 188 SkipTagObstructionFilter filter(spawnedTag); // ignore collisions with the spawned entity 189 if (cmpPathfinder->CheckUnitPlacement(filter, pos.X, pos.Z, spawnedRadius, spawnedPass) )189 if (cmpPathfinder->CheckUnitPlacement(filter, pos.X, pos.Z, spawnedRadius, spawnedPass) == ICmpObstruction::FOUNDATION_CHECK_SUCCESS) 190 190 return pos; // this position is okay, so return it 191 191 } 192 192 } … … 241 241 CFixedVector2D pos (center + dir*i); 242 242 243 243 SkipTagObstructionFilter filter(spawnedTag); // ignore collisions with the spawned entity 244 if (cmpPathfinder->CheckUnitPlacement(filter, pos.X, pos.Y, spawnedRadius, spawnedPass) )244 if (cmpPathfinder->CheckUnitPlacement(filter, pos.X, pos.Y, spawnedRadius, spawnedPass) == ICmpObstruction::FOUNDATION_CHECK_SUCCESS) 245 245 return CFixedVector3D(pos.X, fixed::Zero(), pos.Y); // this position is okay, so return it 246 246 } 247 247 } -
source/simulation2/components/CCmpObstruction.cpp
1 /* Copyright (C) 201 2Wildfire Games.1 /* Copyright (C) 2013 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 … … 478 478 return m_ControlPersist; 479 479 } 480 480 481 virtual boolCheckFoundation(std::string className)481 virtual EFoundationCheck CheckFoundation(std::string className) 482 482 { 483 483 CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), GetEntityId()); 484 484 if (!cmpPosition) 485 return false; // error485 return FOUNDATION_CHECK_FAIL_ERROR; // error 486 486 487 487 if (!cmpPosition->IsInWorld()) 488 return false; // no obstruction488 return FOUNDATION_CHECK_FAIL_NO_OBSTRUCTION; // no obstruction 489 489 490 490 CFixedVector2D pos = cmpPosition->GetPosition2D(); 491 491 492 492 CmpPtr<ICmpPathfinder> cmpPathfinder(GetSimContext(), SYSTEM_ENTITY); 493 493 if (!cmpPathfinder) 494 return false; // error494 return FOUNDATION_CHECK_FAIL_ERROR; // error 495 495 496 496 // required precondition to use SkipControlGroupsRequireFlagObstructionFilter 497 497 if (m_ControlGroup == INVALID_ENTITY) 498 498 { 499 499 LOGERROR(L"[CmpObstruction] Cannot test for foundation obstructions; primary control group must be valid"); 500 return false;500 return FOUNDATION_CHECK_FAIL_ERROR; 501 501 } 502 502 503 503 // Get passability class … … 509 509 SkipControlGroupsRequireFlagObstructionFilter filter(m_ControlGroup, m_ControlGroup2, 510 510 ICmpObstructionManager::FLAG_BLOCK_FOUNDATION); 511 511 512 if (m_Type == STATIC) 513 return cmpPathfinder->CheckBuildingPlacement(filter, pos.X, pos.Y, cmpPosition->GetRotation().Y, m_Size0, m_Size1, GetEntityId(), passClass); 514 else if (m_Type == UNIT) 512 if (m_Type == UNIT) 515 513 return cmpPathfinder->CheckUnitPlacement(filter, pos.X, pos.Y, m_Size0, passClass); 516 else 514 else 517 515 return cmpPathfinder->CheckBuildingPlacement(filter, pos.X, pos.Y, cmpPosition->GetRotation().Y, m_Size0, m_Size1, GetEntityId(), passClass); 518 516 } 519 517 -
source/simulation2/components/CCmpPathfinder.cpp
1 /* Copyright (C) 201 2Wildfire Games.1 /* Copyright (C) 2013 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 … … 656 656 } 657 657 } 658 658 659 boolCCmpPathfinder::CheckUnitPlacement(const IObstructionTestFilter& filter,659 ICmpObstruction::EFoundationCheck CCmpPathfinder::CheckUnitPlacement(const IObstructionTestFilter& filter, 660 660 entity_pos_t x, entity_pos_t z, entity_pos_t r, pass_class_t passClass) 661 661 { 662 662 // Check unit obstruction 663 663 CmpPtr<ICmpObstructionManager> cmpObstructionManager(GetSimContext(), SYSTEM_ENTITY); 664 664 if (!cmpObstructionManager) 665 return false;665 return ICmpObstruction::FOUNDATION_CHECK_FAIL_ERROR; 666 666 667 667 if (cmpObstructionManager->TestUnitShape(filter, x, z, r, NULL)) 668 return false;668 return ICmpObstruction::FOUNDATION_CHECK_FAIL_OBSTRUCTS_FOUNDATION; 669 669 670 670 // Test against terrain: 671 671 … … 680 680 { 681 681 if (!IS_TERRAIN_PASSABLE(m_Grid->get(i,j), passClass)) 682 682 { 683 return false;683 return ICmpObstruction::FOUNDATION_CHECK_FAIL_TERRAIN_CLASS; 684 684 } 685 685 } 686 686 } 687 return true;687 return ICmpObstruction::FOUNDATION_CHECK_SUCCESS; 688 688 } 689 689 690 boolCCmpPathfinder::CheckBuildingPlacement(const IObstructionTestFilter& filter,690 ICmpObstruction::EFoundationCheck CCmpPathfinder::CheckBuildingPlacement(const IObstructionTestFilter& filter, 691 691 entity_pos_t x, entity_pos_t z, entity_pos_t a, entity_pos_t w, 692 692 entity_pos_t h, entity_id_t id, pass_class_t passClass) 693 693 { 694 694 // Check unit obstruction 695 695 CmpPtr<ICmpObstructionManager> cmpObstructionManager(GetSimContext(), SYSTEM_ENTITY); 696 696 if (!cmpObstructionManager) 697 return false;697 return ICmpObstruction::FOUNDATION_CHECK_FAIL_ERROR; 698 698 699 699 if (cmpObstructionManager->TestStaticShape(filter, x, z, a, w, h, NULL)) 700 return false;700 return ICmpObstruction::FOUNDATION_CHECK_FAIL_OBSTRUCTS_FOUNDATION; 701 701 702 702 // Test against terrain: 703 703 704 704 UpdateGrid(); 705 705 706 ICmpObstructionManager::ObstructionSquare square; 706 707 CmpPtr<ICmpObstruction> cmpObstruction(GetSimContext(), id); 707 if (!cmpObstruction )708 return false;708 if (!cmpObstruction || !cmpObstruction->GetObstructionSquare(square)) 709 return ICmpObstruction::FOUNDATION_CHECK_FAIL_NO_OBSTRUCTION; 709 710 710 ICmpObstructionManager::ObstructionSquare square;711 if (!cmpObstruction->GetObstructionSquare(square))712 return false;713 714 711 // Expand bounds by 1/sqrt(2) tile (multiply by TERRAIN_TILE_SIZE since we want world coordinates) 715 712 entity_pos_t expand = entity_pos_t::FromInt(2).Sqrt().Multiply(entity_pos_t::FromInt(TERRAIN_TILE_SIZE / 2)); 716 713 CFixedVector2D halfSize(square.hw + expand, square.hh + expand); … … 728 725 if (Geometry::PointIsInSquare(CFixedVector2D(x - square.x, z - square.z), square.u, square.v, halfSize) 729 726 && !IS_TERRAIN_PASSABLE(m_Grid->get(i,j), passClass)) 730 727 { 731 return false;728 return ICmpObstruction::FOUNDATION_CHECK_FAIL_TERRAIN_CLASS; 732 729 } 733 730 } 734 731 } 735 732 736 return true;733 return ICmpObstruction::FOUNDATION_CHECK_SUCCESS; 737 734 } -
source/simulation2/components/CCmpPathfinder_Common.h
1 /* Copyright (C) 201 1Wildfire Games.1 /* Copyright (C) 2013 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 … … 260 260 261 261 virtual bool CheckMovement(const IObstructionTestFilter& filter, entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_t z1, entity_pos_t r, pass_class_t passClass); 262 262 263 virtual boolCheckUnitPlacement(const IObstructionTestFilter& filter, entity_pos_t x, entity_pos_t z, entity_pos_t r, pass_class_t passClass);263 virtual ICmpObstruction::EFoundationCheck CheckUnitPlacement(const IObstructionTestFilter& filter, entity_pos_t x, entity_pos_t z, entity_pos_t r, pass_class_t passClass); 264 264 265 virtual boolCheckBuildingPlacement(const IObstructionTestFilter& filter, entity_pos_t x, entity_pos_t z, entity_pos_t a, entity_pos_t w, entity_pos_t h, entity_id_t id, pass_class_t passClass);265 virtual ICmpObstruction::EFoundationCheck CheckBuildingPlacement(const IObstructionTestFilter& filter, entity_pos_t x, entity_pos_t z, entity_pos_t a, entity_pos_t w, entity_pos_t h, entity_id_t id, pass_class_t passClass); 266 266 267 267 virtual void FinishAsyncRequests(); 268 268 -
source/simulation2/components/CCmpTemplateManager.cpp
501 501 // and safe (i.e. won't do anything that affects the synchronised simulation state), so additions 502 502 // to this list should be carefully considered 503 503 std::set<std::string> permittedComponentTypes; 504 permittedComponentTypes.insert("Identity"); 504 505 permittedComponentTypes.insert("Ownership"); 505 506 permittedComponentTypes.insert("Position"); 506 507 permittedComponentTypes.insert("VisualActor"); -
source/simulation2/components/ICmpObstruction.cpp
1 /* Copyright (C) 201 2Wildfire Games.1 /* Copyright (C) 2013 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 … … 21 21 22 22 #include "simulation2/system/InterfaceScripted.h" 23 23 24 #include "simulation2/system/SimContext.h" 25 26 std::string ICmpObstruction::CheckFoundation_wrapper(std::string className) 27 { 28 EFoundationCheck check = CheckFoundation(className); 29 30 switch (check) 31 { 32 case FOUNDATION_CHECK_SUCCESS: 33 return "success"; 34 case FOUNDATION_CHECK_FAIL_ERROR: 35 return "fail_error"; 36 case FOUNDATION_CHECK_FAIL_NO_OBSTRUCTION: 37 return "fail_no_obstruction"; 38 case FOUNDATION_CHECK_FAIL_OBSTRUCTS_FOUNDATION: 39 return "fail_obstructs_foundation"; 40 case FOUNDATION_CHECK_FAIL_TERRAIN_CLASS: 41 return "fail_terrain_class"; 42 default: 43 debug_warn(L"Unexpected result from CheckFoundation"); 44 return ""; 45 } 46 } 47 24 48 BEGIN_INTERFACE_WRAPPER(Obstruction) 25 49 DEFINE_INTERFACE_METHOD_0("GetUnitRadius", entity_pos_t, ICmpObstruction, GetUnitRadius) 26 DEFINE_INTERFACE_METHOD_1("CheckFoundation", bool, ICmpObstruction, CheckFoundation, std::string)50 DEFINE_INTERFACE_METHOD_1("CheckFoundation", std::string, ICmpObstruction, CheckFoundation_wrapper, std::string) 27 51 DEFINE_INTERFACE_METHOD_0("CheckDuplicateFoundation", bool, ICmpObstruction, CheckDuplicateFoundation) 28 52 DEFINE_INTERFACE_METHOD_2("GetEntityCollisions", std::vector<entity_id_t>, ICmpObstruction, GetEntityCollisions, bool, bool) 29 53 DEFINE_INTERFACE_METHOD_1("SetActive", void, ICmpObstruction, SetActive, bool) -
source/simulation2/components/ICmpObstruction.h
1 /* Copyright (C) 201 2Wildfire Games.1 /* Copyright (C) 2013 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 { 31 31 public: 32 32 33 enum EFoundationCheck { 34 FOUNDATION_CHECK_SUCCESS, 35 FOUNDATION_CHECK_FAIL_ERROR, 36 FOUNDATION_CHECK_FAIL_NO_OBSTRUCTION, 37 FOUNDATION_CHECK_FAIL_OBSTRUCTS_FOUNDATION, 38 FOUNDATION_CHECK_FAIL_TERRAIN_CLASS 39 }; 40 33 41 virtual ICmpObstructionManager::tag_t GetObstruction() = 0; 34 42 35 43 /** … … 47 55 * Test whether this entity is colliding with any obstruction that are set to 48 56 * block the creation of foundations. 49 57 * @param ignoredEntities List of entities to ignore during the test. 50 * @return true if foundation is valid (not obstructed) 58 * @return FOUNDATION_CHECK_SUCCESS if check passes, else an EFoundationCheck 59 * value describing the type of failure. 51 60 */ 52 virtual boolCheckFoundation(std::string className) = 0;61 virtual EFoundationCheck CheckFoundation(std::string className) = 0; 53 62 54 63 /** 64 * CheckFoundation wrapper for script calls, to return friendly strings instead of an EFoundationCheck. 65 * @return "success" if check passes, else a string describing the type of failure. 66 */ 67 virtual std::string CheckFoundation_wrapper(std::string className); 68 69 /** 55 70 * Test whether this entity is colliding with any obstructions that share its 56 71 * control groups and block the creation of foundations. 57 72 * @return true if foundation is valid (not obstructed) -
source/simulation2/components/ICmpPathfinder.h
1 /* Copyright (C) 201 1Wildfire Games.1 /* Copyright (C) 2013 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 … … 20 20 21 21 #include "simulation2/system/Interface.h" 22 22 23 #include "simulation2/components/ICmpObstruction.h" 23 24 #include "simulation2/helpers/Position.h" 24 25 25 26 #include "maths/FixedVector2D.h" … … 152 153 /** 153 154 * Check whether a unit placed here is valid and doesn't hit any obstructions 154 155 * or impassable terrain. 155 * Returns true if the placement is okay. 156 * @return ICmpObstruction::FOUNDATION_CHECK_SUCCESS if the placement is okay, else 157 * a value describing the type of failure. 156 158 */ 157 virtual boolCheckUnitPlacement(const IObstructionTestFilter& filter, entity_pos_t x, entity_pos_t z, entity_pos_t r, pass_class_t passClass) = 0;159 virtual ICmpObstruction::EFoundationCheck CheckUnitPlacement(const IObstructionTestFilter& filter, entity_pos_t x, entity_pos_t z, entity_pos_t r, pass_class_t passClass) = 0; 158 160 159 161 /** 160 162 * Check whether a building placed here is valid and doesn't hit any obstructions 161 163 * or impassable terrain. 162 * Returns true if the placement is okay. 164 * @return ICmpObstruction::FOUNDATION_CHECK_SUCCESS if the placement is okay, else 165 * a value describing the type of failure. 163 166 */ 164 virtual boolCheckBuildingPlacement(const IObstructionTestFilter& filter, entity_pos_t x, entity_pos_t z, entity_pos_t a, entity_pos_t w, entity_pos_t h, entity_id_t id, pass_class_t passClass) = 0;167 virtual ICmpObstruction::EFoundationCheck CheckBuildingPlacement(const IObstructionTestFilter& filter, entity_pos_t x, entity_pos_t z, entity_pos_t a, entity_pos_t w, entity_pos_t h, entity_id_t id, pass_class_t passClass) = 0; 165 168 166 169 /** 167 170 * Toggle the storage and rendering of debug info.