Ticket #2285: damage.diff
File damage.diff, 7.6 KB (added by , 10 years ago) |
---|
-
binaries/data/mods/public/simulation/helpers/Damage.js
99 99 // If there is insufficient data return an empty array. 100 100 if (!origin || !radius) 101 101 return []; 102 // Create/recycle the dummy entity used for range calculations.103 if (!Damage.dummyTargetEntity || dummyPath != Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager).GetCurrentTemplateName(Damage.dummyTargetEntity))104 Damage.dummyTargetEntity = Engine.AddEntity(dummyPath);105 // Move the dummy entity to the origin of the query.106 var cmpDummyPosition = Engine.QueryInterface(Damage.dummyTargetEntity, IID_Position);107 if (!cmpDummyPosition)108 return [];109 cmpDummyPosition.JumpTo(origin.x, origin.z);110 102 111 103 // If the players parameter is not specified use all players. 112 104 if (!players) … … 119 111 120 112 // Call RangeManager with dummy entity and return the result. 121 113 var rangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); 122 var rangeQuery = rangeManager.ExecuteQuery (Damage.dummyTargetEntity, 0, radius, players, IID_DamageReceiver);114 var rangeQuery = rangeManager.ExecuteQueryAroundPos({"x": origin.x, "y": origin.z}, 0, radius, players, IID_DamageReceiver); 123 115 return rangeQuery; 124 116 }; 125 117 -
source/simulation2/components/CCmpRangeManager.cpp
33 33 #include "graphics/Overlay.h" 34 34 #include "graphics/Terrain.h" 35 35 #include "lib/timer.h" 36 #include "maths/FixedVector2D.h"37 36 #include "ps/CLogger.h" 38 37 #include "ps/Overlay.h" 39 38 #include "ps/Profile.h" … … 729 728 q.enabled = false; 730 729 } 731 730 731 virtual std::vector<entity_id_t> ExecuteQueryAroundPos(CFixedVector2D pos, 732 entity_pos_t minRange, entity_pos_t maxRange, 733 std::vector<int> owners, int requiredInterface) 734 { 735 Query q = ConstructQuery(INVALID_ENTITY, minRange, maxRange, owners, requiredInterface, GetEntityFlagMask("normal")); 736 std::vector<entity_id_t> r; 737 PerformQuery(q, r, pos); 738 739 // Return the list sorted by distance from the entity 740 std::stable_sort(r.begin(), r.end(), EntityDistanceOrdering(m_EntityData, pos)); 741 742 return r; 743 } 744 732 745 virtual std::vector<entity_id_t> ExecuteQuery(entity_id_t source, 733 746 entity_pos_t minRange, entity_pos_t maxRange, 734 747 std::vector<int> owners, int requiredInterface) … … 746 759 return r; 747 760 } 748 761 749 PerformQuery(q, r); 762 CFixedVector2D pos = cmpSourcePosition->GetPosition2D(); 763 PerformQuery(q, r, pos); 750 764 751 765 // Return the list sorted by distance from the entity 752 CFixedVector2D pos = cmpSourcePosition->GetPosition2D();753 766 std::stable_sort(r.begin(), r.end(), EntityDistanceOrdering(m_EntityData, pos)); 754 767 755 768 return r; … … 779 792 return r; 780 793 } 781 794 782 PerformQuery(q, r); 795 CFixedVector2D pos = cmpSourcePosition->GetPosition2D(); 796 PerformQuery(q, r, pos); 783 797 784 798 q.lastMatch = r; 785 799 786 800 // Return the list sorted by distance from the entity 787 CFixedVector2D pos = cmpSourcePosition->GetPosition2D();788 801 std::stable_sort(r.begin(), r.end(), EntityDistanceOrdering(m_EntityData, pos)); 789 802 790 803 return r; … … 841 854 842 855 results.clear(); 843 856 results.reserve(query.lastMatch.size()); 844 PerformQuery(query, results); 857 CFixedVector2D pos = cmpSourcePosition->GetPosition2D(); 858 PerformQuery(query, results, pos); 845 859 846 860 // Compute the changes vs the last match 847 861 added.clear(); … … 902 916 /** 903 917 * Returns a list of distinct entity IDs that match the given query, sorted by ID. 904 918 */ 905 void PerformQuery(const Query& q, std::vector<entity_id_t>& r )919 void PerformQuery(const Query& q, std::vector<entity_id_t>& r, CFixedVector2D pos) 906 920 { 907 CmpPtr<ICmpPosition> cmpSourcePosition(q.source);908 if (!cmpSourcePosition || !cmpSourcePosition->IsInWorld())909 return;910 CFixedVector2D pos = cmpSourcePosition->GetPosition2D();911 921 912 922 // Special case: range -1.0 means check all entities ignoring distance 913 923 if (q.maxRange == entity_pos_t::FromInt(-1)) … … 924 934 else if (q.parabolic) 925 935 { 926 936 // elevationBonus is part of the 3D position, as the source is really that much heigher 937 CmpPtr<ICmpPosition> cmpSourcePosition(q.source); 927 938 CFixedVector3D pos3d = cmpSourcePosition->GetPosition()+ 928 939 CFixedVector3D(entity_pos_t::Zero(), q.elevationBonus, entity_pos_t::Zero()) ; 929 940 // Get a quick list of entities that are potentially in range, with a cutoff of 2*maxRange … … 992 1003 } 993 1004 } 994 1005 995 996 1006 virtual entity_pos_t GetElevationAdaptedRange(CFixedVector3D pos, CFixedVector3D rot, entity_pos_t range, entity_pos_t elevationBonus, entity_pos_t angle) 997 1007 { 998 1008 entity_pos_t r = entity_pos_t::Zero() ; -
source/simulation2/components/ICmpRangeManager.cpp
35 35 36 36 BEGIN_INTERFACE_WRAPPER(RangeManager) 37 37 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 DEFINE_INTERFACE_METHOD_5("ExecuteQueryAroundPos", std::vector<entity_id_t>, ICmpRangeManager, ExecuteQueryAroundPos, CFixedVector2D, entity_pos_t, entity_pos_t, std::vector<int>, int) 38 39 DEFINE_INTERFACE_METHOD_6("CreateActiveQuery", ICmpRangeManager::tag_t, ICmpRangeManager, CreateActiveQuery, entity_id_t, entity_pos_t, entity_pos_t, std::vector<int>, int, u8) 39 40 DEFINE_INTERFACE_METHOD_7("CreateActiveParabolicQuery", ICmpRangeManager::tag_t, ICmpRangeManager, CreateActiveParabolicQuery, entity_id_t, entity_pos_t, entity_pos_t, entity_pos_t, std::vector<int>, int, u8) 40 41 DEFINE_INTERFACE_METHOD_1("DestroyActiveQuery", void, ICmpRangeManager, DestroyActiveQuery, ICmpRangeManager::tag_t) -
source/simulation2/components/ICmpRangeManager.h
19 19 #define INCLUDED_ICMPRANGEMANAGER 20 20 21 21 #include "maths/FixedVector3D.h" 22 #include "maths/FixedVector2D.h" 22 23 23 24 #include "simulation2/system/Interface.h" 24 25 #include "simulation2/helpers/Position.h" … … 92 93 entity_pos_t minRange, entity_pos_t maxRange, std::vector<int> owners, int requiredInterface) = 0; 93 94 94 95 /** 96 * Execute a passive query. 97 * @param pos the position around which the range will be computed. 98 * @param minRange non-negative minimum distance in metres (inclusive). 99 * @param maxRange non-negative maximum distance in metres (inclusive); or -1.0 to ignore distance. 100 * @param owners list of player IDs that matching entities may have; -1 matches entities with no owner. 101 * @param requiredInterface if non-zero, an interface ID that matching entities must implement. 102 * @return list of entities matching the query, ordered by increasing distance from the source entity. 103 */ 104 virtual std::vector<entity_id_t> ExecuteQueryAroundPos(CFixedVector2D pos, 105 entity_pos_t minRange, entity_pos_t maxRange, std::vector<int> owners, int requiredInterface) = 0; 106 107 /** 95 108 * Construct an active query. The query will be disabled by default. 96 109 * @param source the entity around which the range will be computed. 97 110 * @param minRange non-negative minimum distance in metres (inclusive).