Skip to content

Commit e0cca09

Browse files
committed
GetMOsAtPosition, currently-untestable CastAllMOsRay
1 parent e058c58 commit e0cca09

15 files changed

+202
-11
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
8383

8484
- New `ACraft` INI and Lua (R/W) property `CanEnterOrbit`, which determines whether a craft can enter orbit (and refund gold appropriately) or not. If false, default out-of-bounds deletion logic applies.
8585

86+
- New `MovableMan` function `GetMOsAtPosition(posX, posY, ignoreTeam, getsHitByMOsOnly)` that will return an iterator with all the `MovableObject`s that intersect that exact position with their sprite.
87+
8688
</details>
8789

8890
<details><summary><b>Changed</b></summary>

Source/Entities/MOPixel.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ void MOPixel::SetTrailLength(int trailLength) {
140140
m_Atom->SetTrailLength(trailLength);
141141
}
142142

143-
bool MOPixel::HitTestAtPixel(int pixelX, int pixelY) const {
144-
if (!GetsHitByMOs() || GetRootParent()->GetTraveling()) {
143+
bool MOPixel::HitTestAtPixel(int pixelX, int pixelY, bool validOnly) const {
144+
if (validOnly && (!GetsHitByMOs() || GetRootParent()->GetTraveling())) {
145145
return false;
146146
}
147147

Source/Entities/MOPixel.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,9 @@ namespace RTE {
125125
/// Whether a set of X, Y coordinates overlap us (in world space).
126126
/// @param pixelX The given X coordinate, in world space.
127127
/// @param pixelY The given Y coordinate, in world space.
128+
/// @param validOnly Whether to return false if this MO isn't validly owned by MovableMan or not.
128129
/// @return Whether the given coordinate overlap us.
129-
bool HitTestAtPixel(int pixelX, int pixelY) const override;
130+
bool HitTestAtPixel(int pixelX, int pixelY, bool validOnly = true) const override;
130131
#pragma endregion
131132

132133
#pragma region Virtual Override Methods

Source/Entities/MOSprite.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,8 @@ void MOSprite::Destroy(bool notInherited) {
240240
Clear();
241241
}
242242

243-
bool MOSprite::HitTestAtPixel(int pixelX, int pixelY) const {
244-
if (!GetsHitByMOs() || GetRootParent()->GetTraveling()) {
243+
bool MOSprite::HitTestAtPixel(int pixelX, int pixelY, bool validOnly) const {
244+
if (validOnly && (!GetsHitByMOs() || GetRootParent()->GetTraveling())) {
245245
return false;
246246
}
247247

Source/Entities/MOSprite.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,9 @@ namespace RTE {
127127
/// Whether a set of X, Y coordinates overlap us (in world space).
128128
/// @param pixelX The given X coordinate, in world space.
129129
/// @param pixelY The given Y coordinate, in world space.
130+
/// @param validOnly Whether to return false if this MO isn't validly owned by MovableMan or not.
130131
/// @return Whether the given coordinate overlap us.
131-
bool HitTestAtPixel(int pixelX, int pixelY) const override;
132+
bool HitTestAtPixel(int pixelX, int pixelY, bool validOnly = true) const override;
132133

133134
/// Gets the current angular velocity of this MovableObject. Positive is
134135
/// a counter-clockwise rotation.

Source/Entities/MovableObject.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,8 +588,9 @@ namespace RTE {
588588
/// Whether a set of X, Y coordinates overlap us (in world space).
589589
/// @param pixelX The given X coordinate, in world space.
590590
/// @param pixelY The given Y coordinate, in world space.
591+
/// @param validOnly Whether to return false if this MO isn't validly owned by MovableMan or not.
591592
/// @return Whether the given coordinate overlap us.
592-
virtual bool HitTestAtPixel(int pixelX, int pixelY) const { return false; }
593+
virtual bool HitTestAtPixel(int pixelX, int pixelY, bool validOnly = true) const { return false; }
593594

594595
/// Shows whether this is or carries a specifically named object in its
595596
/// inventory. Also looks through the inventories of potential passengers,

Source/Lua/LuaAdapterDefinitions.h

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -517,31 +517,43 @@ namespace RTE {
517517
/// first, g_NoMOID will be returned.
518518
/// @param start The starting position.
519519
/// @param ray The vector to trace along.
520-
/// @param ignoredMOIDs A vector of MOIDs to ignore. Any child MO's of this MOID will also be ignored. (default: g_NoMOID)
520+
/// @param ignoreMOIDs A vector of MOIDs to ignore. Any child MO's of this MOID will also be ignored. (default: g_NoMOID)
521521
/// @param ignoreTeam To enable ignoring of all MOIDs associated with an object of a specific (default: Activity::NoTeam)
522522
/// team which also has team ignoring enabled itself.
523523
/// @param ignoreMaterial A specific material ID to ignore hits with. (default: 0)
524524
/// @param ignoreAllTerrain Whether to ignore all terrain hits or not. (default: false)
525525
/// @param skip For every pixel checked along the line, how many to skip between them (default: 0)
526526
/// for optimization reasons. 0 = every pixel is checked.
527527
/// @return The MOID of the hit non-ignored MO, or g_NoMOID if terrain or no MO was hit.
528-
static MOID CastMORay1(SceneMan& sceneMan, const Vector& start, const Vector& ray, const luabind::object& ignoredMOIDs, int ignoreTeam = Activity::NoTeam, unsigned char ignoreMaterial = 0, bool ignoreAllTerrain = false, int skip = 0);
528+
static MOID CastMORay1(SceneMan& sceneMan, const Vector& start, const Vector& ray, const luabind::object& ignoreMOIDs, int ignoreTeam = Activity::NoTeam, unsigned char ignoreMaterial = 0, bool ignoreAllTerrain = false, int skip = 0);
529529

530530
/// Traces along a vector and returns MOID of the first non-ignored
531531
/// non-NoMOID MO encountered. If a non-air terrain pixel is encountered
532532
/// first, g_NoMOID will be returned.
533533
/// @param start The starting position.
534534
/// @param ray The vector to trace along.
535-
/// @param ignoredMOID An MOID to ignore. Any child MO's of this MOID will also be ignored. (default: g_NoMOID)
535+
/// @param ignoreMOID An MOID to ignore. Any child MO's of this MOID will also be ignored. (default: g_NoMOID)
536536
/// @param ignoreTeam To enable ignoring of all MOIDs associated with an object of a specific (default: Activity::NoTeam)
537537
/// team which also has team ignoring enabled itself.
538538
/// @param ignoreMaterial A specific material ID to ignore hits with. (default: 0)
539539
/// @param ignoreAllTerrain Whether to ignore all terrain hits or not. (default: false)
540540
/// @param skip For every pixel checked along the line, how many to skip between them (default: 0)
541541
/// for optimization reasons. 0 = every pixel is checked.
542542
/// @return The MOID of the hit non-ignored MO, or g_NoMOID if terrain or no MO was hit.
543-
static MOID CastMORay2(SceneMan& sceneMan, const Vector& start, const Vector& ray, MOID ignoredMOID = g_NoMOID, int ignoreTeam = Activity::NoTeam, unsigned char ignoreMaterial = 0, bool ignoreAllTerrain = false, int skip = 0);
543+
static MOID CastMORay2(SceneMan& sceneMan, const Vector& start, const Vector& ray, MOID ignoreMOID = g_NoMOID, int ignoreTeam = Activity::NoTeam, unsigned char ignoreMaterial = 0, bool ignoreAllTerrain = false, int skip = 0);
544544

545+
/// Traces along a vector and returns a vector of all MOs encountered.
546+
/// @param start The starting position.
547+
/// @param ray The vector to trace along.
548+
/// @param ignoreMOIDs A vector of MOIDs to ignore. Any child MOs of an MOID will also be ignored. (default: g_NoMOID)
549+
/// @param ignoreTeam To enable ignoring of all MOIDs associated with an object of a specific team (default: Activity::NoTeam)
550+
/// @param ignoreMaterial A specific material ID to ignore hits with. (default: 0)
551+
/// @param ignoreAllTerrain Whether to ignore all terrain hits or not. (default: false)
552+
/// @param skip For every pixel checked along the line, how many to skip between them (default: 0)
553+
/// for optimization reasons. 0 = every pixel is checked.
554+
/// @return A vector of pointers to all MovableObjects met along the ray, who aren't ignored.
555+
static const std::vector<MovableObject*>* CastAllMOsRay(SceneMan& sceneMan, const Vector& start, const Vector& ray, const luabind::object& ignoreMOIDs, int ignoreTeam = Activity::NoTeam, unsigned char ignoreMaterial = 0, bool ignoreAllTerrain = false, int skip = 0);
556+
545557
/// Traces along a vector and returns the length of how far the trace went
546558
/// without hitting any non-ignored terrain material or MOID at all.
547559
/// @param start The starting position.

Source/Lua/LuaAdapters.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,15 @@ MOID LuaAdaptersSceneMan::CastMORay2(SceneMan& sceneMan, const Vector& start, co
626626
return sceneMan.CastMORay(start, ray, ignoreMOIDs, ignoreTeam, ignoreMaterial, ignoreAllTerrain, skip);
627627
}
628628

629+
const std::vector<MovableObject*>* LuaAdaptersSceneMan::CastAllMOsRay(SceneMan& sceneMan, const Vector& start, const Vector& ray, const luabind::object& ignoreMOIDs, int ignoreTeam, unsigned char ignoreMaterial, bool ignoreAllTerrain, int skip) {
630+
std::vector<MOID*> ptrVec = ConvertLuaTableToVectorOfType<MOID*>(ignoreMOIDs);
631+
std::vector<MOID> ignoreMOIDsVec;
632+
for (auto ptr : ptrVec) {
633+
ignoreMOIDsVec.push_back(*ptr);
634+
}
635+
return sceneMan.CastAllMOsRay(start, ray, ignoreMOIDsVec, ignoreTeam, ignoreMaterial, ignoreAllTerrain, skip);
636+
}
637+
629638
float LuaAdaptersSceneMan::CastObstacleRay1(SceneMan& sceneMan, const Vector& start, const Vector& ray, Vector& obstaclePos, Vector& freePos, const luabind::object& ignoreMOIDs, int ignoreTeam, unsigned char ignoreMaterial, int skip) {
630639
std::vector<MOID*> ptrVec = ConvertLuaTableToVectorOfType<MOID*>(ignoreMOIDs);
631640
std::vector<MOID> ignoreMOIDsVec;

Source/Lua/LuaBindingsManagers.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ LuaBindingRegisterFunctionDefinitionForType(ManagerLuaBindings, MovableMan) {
168168
.def("GetMOsInRadius", (const std::vector<MovableObject*>* (MovableMan::*)(const Vector& centre, float radius) const) & MovableMan::GetMOsInRadius, luabind::adopt(luabind::return_value) + luabind::return_stl_iterator)
169169
.def("GetMOsInRadius", (const std::vector<MovableObject*>* (MovableMan::*)(const Vector& centre, float radius, int ignoreTeam) const) & MovableMan::GetMOsInRadius, luabind::adopt(luabind::return_value) + luabind::return_stl_iterator)
170170
.def("GetMOsInRadius", (const std::vector<MovableObject*>* (MovableMan::*)(const Vector& centre, float radius, int ignoreTeam, bool getsHitByMOsOnly) const) & MovableMan::GetMOsInRadius, luabind::adopt(luabind::return_value) + luabind::return_stl_iterator)
171+
.def("GetMOsAtPosition", (const std::vector<MovableObject*>* (MovableMan::*)(int pixelX, int pixelY) const) & MovableMan::GetMOsAtPosition, luabind::adopt(luabind::return_value) + luabind::return_stl_iterator)
172+
.def("GetMOsAtPosition", (const std::vector<MovableObject*>* (MovableMan::*)(int pixelX, int pixelY, int ignoreTeam) const) & MovableMan::GetMOsAtPosition, luabind::adopt(luabind::return_value) + luabind::return_stl_iterator)
173+
.def("GetMOsAtPosition", (const std::vector<MovableObject*>* (MovableMan::*)(int pixelX, int pixelY, int ignoreTeam, bool getsHitByMOsOnly) const) & MovableMan::GetMOsAtPosition, luabind::adopt(luabind::return_value) + luabind::return_stl_iterator)
171174

172175
.def("SendGlobalMessage", &LuaAdaptersMovableMan::SendGlobalMessage1)
173176
.def("SendGlobalMessage", &LuaAdaptersMovableMan::SendGlobalMessage2)

Source/Managers/MovableMan.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,12 @@ const std::vector<MovableObject*>* MovableMan::GetMOsInRadius(const Vector& cent
193193
return vectorForLua;
194194
}
195195

196+
const std::vector<MovableObject*>* MovableMan::GetMOsAtPosition(int pixelX, int pixelY, int ignoreTeam, bool getsHitByMOsOnly) const {
197+
std::vector<MovableObject*>* vectorForLua = new std::vector<MovableObject*>();
198+
*vectorForLua = std::move(g_SceneMan.GetMOIDGrid().GetMOsAtPosition(pixelX, pixelY, ignoreTeam, getsHitByMOsOnly));
199+
return vectorForLua;
200+
}
201+
196202
void MovableMan::PurgeAllMOs() {
197203
for (std::deque<Actor*>::iterator itr = m_Actors.begin(); itr != m_Actors.end(); ++itr) {
198204
(*itr)->DestroyScriptState();

0 commit comments

Comments
 (0)