18 #include "precompiled.h"
40 std::vector<std::pair<float, entity_id_t> > hits;
43 for (CSimulation2::InterfaceListUnordered::const_iterator it = ents.begin(); it != ents.end(); ++it)
49 if (!allowEditorSelectables && static_cast<ICmpSelectable*>(it->second)->IsEditorOnly())
66 if (!allowEditorSelectables)
91 CVector3D closest = origin + dir * (center - origin).Dot(dir);
94 hits.push_back(std::make_pair(dist2, ent));
98 std::sort(hits.begin(), hits.end());
101 std::vector<entity_id_t> hitEnts;
102 hitEnts.reserve(hits.size());
103 for (
size_t i = 0; i < hits.size(); ++i)
104 hitEnts.push_back(hits[i].second);
119 std::vector<entity_id_t> hitEnts;
122 for (CSimulation2::InterfaceListUnordered::const_iterator it = ents.begin(); it != ents.end(); ++it)
128 if (static_cast<ICmpSelectable*>(it->second)->IsEditorOnly() && !allowEditorSelectables)
160 if (sx0 <= ix && ix <= sx1 && sy0 <= iy && iy <= sy1)
161 hitEnts.push_back(ent);
168 const std::string& templateName,
player_id_t owner,
bool includeOffScreen,
bool matchRank,
169 bool allowEditorSelectables,
bool allowFoundations)
174 std::vector<entity_id_t> hitEnts;
177 for (CSimulation2::InterfaceListUnordered::const_iterator it = ents.begin(); it != ents.end(); ++it)
183 if (static_cast<ICmpSelectable*>(it->second)->IsEditorOnly() && !allowEditorSelectables)
190 bool matches = (curTemplateName == templateName ||
191 (allowFoundations && curTemplateName.substr(0, 11) ==
"foundation|" && curTemplateName.substr(11) == templateName));
203 if (owner !=
INVALID_PLAYER && (!cmpOwnership || cmpOwnership->GetOwner() != owner))
207 if (!includeOffScreen)
213 CVector3D position = cmpVisual->GetPosition();
225 if (!cmpIdentity || cmpIdentity->GetSelectionGroupName() != templateName)
229 hitEnts.push_back(ent);
const CSimContext & GetSimContext() const
bool RayIntersect(const CVector3D &origin, const CVector3D &dir, float &tMin, float &tMax) const
Check if a given ray intersects this box.
virtual CVector3D GetPosition()=0
Get the world-space position of the base point of the object's visual representation.
Object wrapping an entity_id_t, with a SEntityComponentCache to support fast QueryInterface() / CmpPt...
std::vector< entity_id_t > PickSimilarEntities(CSimulation2 &simulation, const CCamera &camera, const std::string &templateName, player_id_t owner, bool includeOffScreen, bool matchRank, bool allowEditorSelectables, bool allowFoundations)
Finds all entities with the given entity template name, belonging to the given player.
static void swap(UniqueRange &p1, UniqueRange &p2)
const CFrustum & GetFrustum() const
std::vector< entity_id_t > PickEntitiesAtPoint(CSimulation2 &simulation, const CCamera &camera, int screenX, int screenY, player_id_t player, bool allowEditorSelectables)
Finds all selectable entities under the given screen coordinates.
void GetCentre(CVector3D ¢re) const
CVector3D m_Center
Centroid location of the box.
bool IsPointVisible(const CVector3D &point) const
const InterfaceListUnordered & GetEntitiesWithInterfaceUnordered(int iid)
Returns a list of components implementing the given interface, and their associated entities...
virtual CBoundingBoxOriented GetSelectionBox()=0
Get the oriented world-space bounding box of the object's visual representation, clipped at the Y=0 p...
const entity_id_t SYSTEM_ENTITY
Entity ID for singleton 'system' components.
virtual ELosVisibility GetLosVisibility(CEntityHandle ent, player_id_t player, bool forceRetainInFog=false)=0
Returns the visibility status of the given entity, with respect to the given player.
Public API for simulation system.
int32_t player_id_t
valid player IDs are non-negative (see ICmpOwnership)
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
virtual player_id_t GetOwner()=0
void GetScreenCoordinates(const CVector3D &world, float &x, float &y) const
A simplified syntax for accessing entity components.
bool RayIntersect(const CVector3D &origin, const CVector3D &dir, float &tmin, float &tmax) const
Check if a given ray intersects this AABB.
void BuildCameraRay(int px, int py, CVector3D &origin, CVector3D &dir) const
virtual CBoundingBoxAligned GetBounds()=0
Get the world-space bounding box of the object's visual representation.
boost::unordered_map< entity_id_t, IComponent * > InterfaceListUnordered
static float LengthSquared(const SVec3 v)
static Handle handle(size_t idx, u64 tag)
virtual std::string GetCurrentTemplateName(entity_id_t ent)=0
Returns the name of the template most recently specified for the entity 'ent'.
u32 entity_id_t
Entity ID type.
static const player_id_t INVALID_PLAYER
Helper functions related to entity selection.
std::vector< entity_id_t > PickEntitiesInRect(CSimulation2 &simulation, const CCamera &camera, int sx0, int sy0, int sx1, int sy1, player_id_t owner, bool allowEditorSelectables)
Finds all selectable entities within the given screen coordinate rectangle, belonging to the given pl...