Skip to content

Commit 90d87c0

Browse files
committed
convert ray ignoreMOID to vector of MOIDs, broken and bad lua adapter
1 parent 34552e8 commit 90d87c0

File tree

5 files changed

+170
-15
lines changed

5 files changed

+170
-15
lines changed

Source/Lua/LuaAdapterDefinitions.h

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,78 @@ namespace RTE {
512512

513513
#pragma region SceneMan Lua Adapters
514514
struct LuaAdaptersSceneMan {
515+
/// Traces along a vector and returns MOID of the first non-ignored
516+
/// non-NoMOID MO encountered. If a non-air terrain pixel is encountered
517+
/// first, g_NoMOID will be returned.
518+
/// @param start The starting position.
519+
/// @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)
521+
/// @param ignoreTeam To enable ignoring of all MOIDs associated with an object of a specific (default: Activity::NoTeam)
522+
/// team which also has team ignoring enabled itself.
523+
/// @param ignoreMaterial A specific material ID to ignore hits with. (default: 0)
524+
/// @param ignoreAllTerrain Whether to ignore all terrain hits or not. (default: false)
525+
/// @param skip For every pixel checked along the line, how many to skip between them (default: 0)
526+
/// for optimization reasons. 0 = every pixel is checked.
527+
/// @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);
529+
530+
/// Traces along a vector and returns MOID of the first non-ignored
531+
/// non-NoMOID MO encountered. If a non-air terrain pixel is encountered
532+
/// first, g_NoMOID will be returned.
533+
/// @param start The starting position.
534+
/// @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)
536+
/// @param ignoreTeam To enable ignoring of all MOIDs associated with an object of a specific (default: Activity::NoTeam)
537+
/// team which also has team ignoring enabled itself.
538+
/// @param ignoreMaterial A specific material ID to ignore hits with. (default: 0)
539+
/// @param ignoreAllTerrain Whether to ignore all terrain hits or not. (default: false)
540+
/// @param skip For every pixel checked along the line, how many to skip between them (default: 0)
541+
/// for optimization reasons. 0 = every pixel is checked.
542+
/// @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);
544+
545+
/// Traces along a vector and returns the length of how far the trace went
546+
/// without hitting any non-ignored terrain material or MOID at all.
547+
/// @param start The starting position.
548+
/// @param ray The vector to trace along.
549+
/// @param obstaclePos A reference to the vector screen will be filled out with the absolute
550+
/// location of the first obstacle, or the end of the ray if none was hit.
551+
/// @param freePos A reference to the vector screen will be filled out with the absolute
552+
/// location of the last free position before hitting an obstacle, or the
553+
/// end of the ray if none was hit. This is only altered if thre are any
554+
/// free pixels encountered.
555+
/// @param ignoreMOIDs A vector of MOIDs to ignore. Any child MO's of an MOID will also be ignored. (default: g_NoMOID)
556+
/// @param ignoreTeam To enable ignoring of all MOIDs associated with an object of a specific (default: Activity::NoTeam)
557+
/// team which also has team ignoring enabled itself.
558+
/// @param ignoreMaterial A specific material ID to ignore hits with. (default: 0)
559+
/// @param skip For every pixel checked along the line, how many to skip between them (default: 0)
560+
/// for optimization reasons. 0 = every pixel is checked.
561+
/// @return How far along, in pixel units, the ray the pixel of any obstacle was
562+
/// encountered. If no pixel of the right material was found, < 0 is returned.
563+
/// If an obstacle on the starting position was encountered, 0 is returned.
564+
static float CastObstacleRay1(SceneMan& sceneMan, const Vector& start, const Vector& ray, Vector& obstaclePos, Vector& freePos, const luabind::object& ignoreMOIDs, int ignoreTeam = Activity::NoTeam, unsigned char ignoreMaterial = 0, int skip = 0);
565+
566+
/// Traces along a vector and returns the length of how far the trace went
567+
/// without hitting any non-ignored terrain material or MOID at all.
568+
/// @param start The starting position.
569+
/// @param ray The vector to trace along.
570+
/// @param obstaclePos A reference to the vector screen will be filled out with the absolute
571+
/// location of the first obstacle, or the end of the ray if none was hit.
572+
/// @param freePos A reference to the vector screen will be filled out with the absolute
573+
/// location of the last free position before hitting an obstacle, or the
574+
/// end of the ray if none was hit. This is only altered if thre are any
575+
/// free pixels encountered.
576+
/// @param ignoreMOID An MOID to ignore. Any child MOs of this MOID will also be ignored. (default: g_NoMOID)
577+
/// @param ignoreTeam To enable ignoring of all MOIDs associated with an object of a specific (default: Activity::NoTeam)
578+
/// team which also has team ignoring enabled itself.
579+
/// @param ignoreMaterial A specific material ID to ignore hits with. (default: 0)
580+
/// @param skip For every pixel checked along the line, how many to skip between them (default: 0)
581+
/// for optimization reasons. 0 = every pixel is checked.
582+
/// @return How far along, in pixel units, the ray the pixel of any obstacle was
583+
/// encountered. If no pixel of the right material was found, < 0 is returned.
584+
/// If an obstacle on the starting position was encountered, 0 is returned.
585+
static float CastObstacleRay2(SceneMan& sceneMan, const Vector& start, const Vector& ray, Vector& obstaclePos, Vector& freePos, MOID ignoreMOID = g_NoMOID, int ignoreTeam = Activity::NoTeam, unsigned char ignoreMaterial = 0, int skip = 0);
586+
515587
/// Takes a Box and returns a list of Boxes that describe the Box, wrapped appropriately for the current Scene.
516588
/// @param boxToWrap The Box to wrap.
517589
/// @return A list of Boxes that make up the Box to wrap, wrapped appropriately for the current Scene.

Source/Lua/LuaAdapters.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,34 @@ std::list<Entity*>* LuaAdaptersPresetMan::GetAllEntitiesOfGroup(PresetMan& prese
612612
return entityList;
613613
}
614614

615+
MOID LuaAdaptersSceneMan::CastMORay1(SceneMan& sceneMan, const Vector& start, const Vector& ray, const luabind::object& ignoreMOIDs, int ignoreTeam, unsigned char ignoreMaterial, bool ignoreAllTerrain, int skip) {
616+
std::vector<MOID*> ptrVec = ConvertLuaTableToVectorOfType<MOID*>(ignoreMOIDs);
617+
std::vector<MOID> ignoreMOIDsVec;
618+
for (auto ptr : ptrVec) {
619+
ignoreMOIDsVec.push_back(*ptr);
620+
}
621+
return sceneMan.CastMORay(start, ray, ignoreMOIDsVec, ignoreTeam, ignoreMaterial, ignoreAllTerrain, skip);
622+
}
623+
624+
MOID LuaAdaptersSceneMan::CastMORay2(SceneMan& sceneMan, const Vector& start, const Vector& ray, MOID ignoreMOID, int ignoreTeam, unsigned char ignoreMaterial, bool ignoreAllTerrain, int skip) {
625+
std::vector<MOID> ignoreMOIDs = {ignoreMOID};
626+
return sceneMan.CastMORay(start, ray, ignoreMOIDs, ignoreTeam, ignoreMaterial, ignoreAllTerrain, skip);
627+
}
628+
629+
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) {
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.CastObstacleRay(start, ray, obstaclePos, freePos, ignoreMOIDsVec, ignoreTeam, ignoreMaterial, skip);
636+
}
637+
638+
float LuaAdaptersSceneMan::CastObstacleRay2(SceneMan& sceneMan, const Vector& start, const Vector& ray, Vector& obstaclePos, Vector& freePos, MOID ignoreMOID, int ignoreTeam, unsigned char ignoreMaterial, int skip) {
639+
std::vector<MOID> ignoreMOIDs = {ignoreMOID};
640+
return sceneMan.CastObstacleRay(start, ray, obstaclePos, freePos, ignoreMOIDs, ignoreTeam, ignoreMaterial, skip);
641+
}
642+
615643
const std::list<Box>* LuaAdaptersSceneMan::WrapBoxes(SceneMan& sceneMan, const Box& boxToWrap) {
616644
std::list<Box>* wrappedBoxes = new std::list<Box>();
617645
sceneMan.WrapBox(boxToWrap, *wrappedBoxes);

Source/Lua/LuaBindingsManagers.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,11 @@ LuaBindingRegisterFunctionDefinitionForType(ManagerLuaBindings, SceneMan) {
325325
.def("CastMaxStrengthRay", (float(SceneMan::*)(const Vector&, const Vector&, int)) & SceneMan::CastMaxStrengthRay)
326326
.def("CastStrengthRay", &SceneMan::CastStrengthRay)
327327
.def("CastWeaknessRay", &SceneMan::CastWeaknessRay)
328-
.def("CastMORay", &SceneMan::CastMORay)
328+
.def("CastMORay", &LuaAdaptersSceneMan::CastMORay1)
329+
.def("CastMORay", &LuaAdaptersSceneMan::CastMORay2)
329330
.def("CastFindMORay", &SceneMan::CastFindMORay)
330-
.def("CastObstacleRay", &SceneMan::CastObstacleRay)
331+
.def("CastObstacleRay", &LuaAdaptersSceneMan::CastObstacleRay1)
332+
.def("CastObstacleRay", &LuaAdaptersSceneMan::CastObstacleRay2)
331333
.def("CastTerrainPenetrationRay", &SceneMan::CastTerrainPenetrationRay)
332334
.def("GetLastRayHitPos", &SceneMan::GetLastRayHitPos)
333335
.def("FindAltitude", (float(SceneMan::*)(const Vector&, int, int)) & SceneMan::FindAltitude)

Source/Managers/SceneMan.cpp

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1902,7 +1902,7 @@ bool SceneMan::CastWeaknessRay(const Vector& start, const Vector& ray, float str
19021902
return foundPixel;
19031903
}
19041904

1905-
MOID SceneMan::CastMORay(const Vector& start, const Vector& ray, MOID ignoreMOID, int ignoreTeam, unsigned char ignoreMaterial, bool ignoreAllTerrain, int skip) {
1905+
MOID SceneMan::CastMORay(const Vector& start, const Vector& ray, const std::vector<MOID>& ignoreMOIDs, int ignoreTeam, unsigned char ignoreMaterial, bool ignoreAllTerrain, int skip) {
19061906
int hitCount = 0, error, dom, sub, domSteps, skipped = skip;
19071907
int intPos[2], delta[2], delta2[2], increment[2];
19081908
MOID hitMOID = g_NoMOID;
@@ -1965,7 +1965,17 @@ MOID SceneMan::CastMORay(const Vector& start, const Vector& ray, MOID ignoreMOID
19651965

19661966
// Detect MOIDs
19671967
hitMOID = GetMOIDPixel(intPos[X], intPos[Y], ignoreTeam);
1968-
if (hitMOID != g_NoMOID && hitMOID != ignoreMOID && g_MovableMan.GetRootMOID(hitMOID) != ignoreMOID) {
1968+
1969+
// Loop through ignored MOIDs to see if the one we found is ignored
1970+
bool ignoredMOIDHit = false;
1971+
for (auto ignoredMOID : ignoreMOIDs) {
1972+
if (hitMOID == ignoredMOID || g_MovableMan.GetRootMOID(hitMOID) == ignoredMOID) {
1973+
ignoredMOIDHit = true;
1974+
break;
1975+
}
1976+
}
1977+
1978+
if (hitMOID != g_NoMOID && !ignoredMOIDHit) {
19691979
// Save last ray pos
19701980
s_LastRayHitPos.SetXY(intPos[X], intPos[Y]);
19711981
return hitMOID;
@@ -2085,7 +2095,7 @@ bool SceneMan::CastFindMORay(const Vector& start, const Vector& ray, MOID target
20852095
return false;
20862096
}
20872097

2088-
float SceneMan::CastObstacleRay(const Vector& start, const Vector& ray, Vector& obstaclePos, Vector& freePos, MOID ignoreMOID, int ignoreTeam, unsigned char ignoreMaterial, int skip) {
2098+
float SceneMan::CastObstacleRay(const Vector& start, const Vector& ray, Vector& obstaclePos, Vector& freePos, const std::vector<MOID>& ignoreMOIDs, int ignoreTeam, unsigned char ignoreMaterial, int skip) {
20892099
int hitCount = 0, error, dom, sub, domSteps, skipped = skip;
20902100
int intPos[2], delta[2], delta2[2], increment[2];
20912101
bool hitObstacle = false;
@@ -2152,17 +2162,18 @@ float SceneMan::CastObstacleRay(const Vector& start, const Vector& ray, Vector&
21522162
unsigned char checkMat = GetTerrMatter(intPos[X], intPos[Y]);
21532163
MOID checkMOID = GetMOIDPixel(intPos[X], intPos[Y], ignoreTeam);
21542164

2155-
// Translate any found MOID into the root MOID of that hit MO
2156-
if (checkMOID != g_NoMOID) {
2157-
MovableObject* pHitMO = g_MovableMan.GetMOFromID(checkMOID);
2158-
if (pHitMO) {
2159-
checkMOID = pHitMO->GetRootID();
2165+
// Loop through ignored MOIDs to see if the one we found is ignored
2166+
bool ignoredMOIDHit = false;
2167+
for (auto ignoredMOID : ignoreMOIDs) {
2168+
if (checkMOID == ignoredMOID || g_MovableMan.GetRootMOID(checkMOID) == ignoredMOID) {
2169+
ignoredMOIDHit = true;
2170+
break;
21602171
}
21612172
}
21622173

21632174
// See if we found the looked-for pixel of the correct material,
21642175
// Or an MO is blocking the way
2165-
if ((checkMat != g_MaterialAir && checkMat != ignoreMaterial) || (checkMOID != g_NoMOID && checkMOID != ignoreMOID)) {
2176+
if ((checkMat != g_MaterialAir && checkMat != ignoreMaterial) || (checkMOID != g_NoMOID && !ignoredMOIDHit)) {
21662177
hitObstacle = true;
21672178
obstaclePos.SetXY(intPos[X], intPos[Y]);
21682179
// Save last ray pos

Source/Managers/SceneMan.h

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -662,16 +662,34 @@ namespace RTE {
662662
/// first, g_NoMOID will be returned.
663663
/// @param start The starting position.
664664
/// @param ray The vector to trace along.
665-
/// @param ignoreMOID An MOID to ignore. Any child MO's of this MOID will also be ignored. (default: g_NoMOID)
665+
/// @param ignoreMOIDs A vector of MOIDs to ignore. Any child MOs of an MOID will also be ignored. (default: g_NoMOID)
666666
/// @param ignoreTeam To enable ignoring of all MOIDs associated with an object of a specific (default: Activity::NoTeam)
667667
/// team which also has team ignoring enabled itself.
668668
/// @param ignoreMaterial A specific material ID to ignore hits with. (default: 0)
669669
/// @param ignoreAllTerrain Whether to ignore all terrain hits or not. (default: false)
670670
/// @param skip For every pixel checked along the line, how many to skip between them (default: 0)
671671
/// for optimization reasons. 0 = every pixel is checked.
672672
/// @return The MOID of the hit non-ignored MO, or g_NoMOID if terrain or no MO was hit.
673-
MOID CastMORay(const Vector& start, const Vector& ray, MOID ignoreMOID = g_NoMOID, int ignoreTeam = Activity::NoTeam, unsigned char ignoreMaterial = 0, bool ignoreAllTerrain = false, int skip = 0);
673+
MOID CastMORay(const Vector& start, const Vector& ray, const std::vector<MOID>& ignoreMOIDs = {g_NoMOID}, int ignoreTeam = Activity::NoTeam, unsigned char ignoreMaterial = 0, bool ignoreAllTerrain = false, int skip = 0);
674674

675+
/// Traces along a vector and returns MOID of the first non-ignored
676+
/// non-NoMOID MO encountered. If a non-air terrain pixel is encountered
677+
/// first, g_NoMOID will be returned.
678+
/// @param start The starting position.
679+
/// @param ray The vector to trace along.
680+
/// @param ignoreMOID An MOID to ignore. Any child MOs of this MOID will also be ignored. (default: g_NoMOID)
681+
/// @param ignoreTeam To enable ignoring of all MOIDs associated with an object of a specific (default: Activity::NoTeam)
682+
/// team which also has team ignoring enabled itself.
683+
/// @param ignoreMaterial A specific material ID to ignore hits with. (default: 0)
684+
/// @param ignoreAllTerrain Whether to ignore all terrain hits or not. (default: false)
685+
/// @param skip For every pixel checked along the line, how many to skip between them (default: 0)
686+
/// for optimization reasons. 0 = every pixel is checked.
687+
/// @return The MOID of the hit non-ignored MO, or g_NoMOID if terrain or no MO was hit.
688+
MOID CastMORay(const Vector& start, const Vector& ray, MOID ignoreMOID = g_NoMOID, int ignoreTeam = Activity::NoTeam, unsigned char ignoreMaterial = 0, bool ignoreAllTerrain = false, int skip = 0) {
689+
std::vector<MOID> ignoreMOIDs = {ignoreMOID};
690+
return CastMORay(start, ray, ignoreMOIDs, ignoreTeam, ignoreMaterial, ignoreAllTerrain, skip);
691+
}
692+
675693
/// Traces along a vector and shows where a specific MOID has been found.
676694
/// @param start The starting position.
677695
/// @param ray The vector to trace along.
@@ -695,7 +713,7 @@ namespace RTE {
695713
/// location of the last free position before hitting an obstacle, or the
696714
/// end of the ray if none was hit. This is only altered if thre are any
697715
/// free pixels encountered.
698-
/// @param ignoreMOID An MOID to ignore. Any child MO's of this MOID will also be ignored. (default: g_NoMOID)
716+
/// @param ignoreMOIDs A vector of MOIDs to ignore. Any child MO's of an MOID will also be ignored. (default: g_NoMOID)
699717
/// @param ignoreTeam To enable ignoring of all MOIDs associated with an object of a specific (default: Activity::NoTeam)
700718
/// team which also has team ignoring enabled itself.
701719
/// @param ignoreMaterial A specific material ID to ignore hits with. (default: 0)
@@ -704,8 +722,32 @@ namespace RTE {
704722
/// @return How far along, in pixel units, the ray the pixel of any obstacle was
705723
/// encountered. If no pixel of the right material was found, < 0 is returned.
706724
/// If an obstacle on the starting position was encountered, 0 is returned.
707-
float CastObstacleRay(const Vector& start, const Vector& ray, Vector& obstaclePos, Vector& freePos, MOID ignoreMOID = g_NoMOID, int ignoreTeam = Activity::NoTeam, unsigned char ignoreMaterial = 0, int skip = 0);
725+
float CastObstacleRay(const Vector& start, const Vector& ray, Vector& obstaclePos, Vector& freePos, const std::vector<MOID>& ignoreMOIDs = {g_NoMOID}, int ignoreTeam = Activity::NoTeam, unsigned char ignoreMaterial = 0, int skip = 0);
708726

727+
/// Traces along a vector and returns the length of how far the trace went
728+
/// without hitting any non-ignored terrain material or MOID at all.
729+
/// @param start The starting position.
730+
/// @param ray The vector to trace along.
731+
/// @param obstaclePos A reference to the vector screen will be filled out with the absolute
732+
/// location of the first obstacle, or the end of the ray if none was hit.
733+
/// @param freePos A reference to the vector screen will be filled out with the absolute
734+
/// location of the last free position before hitting an obstacle, or the
735+
/// end of the ray if none was hit. This is only altered if thre are any
736+
/// free pixels encountered.
737+
/// @param ignoreMOID An MOID to ignore. Any child MO of this MOID will also be ignored. (default: g_NoMOID)
738+
/// @param ignoreTeam To enable ignoring of all MOIDs associated with an object of a specific (default: Activity::NoTeam)
739+
/// team which also has team ignoring enabled itself.
740+
/// @param ignoreMaterial A specific material ID to ignore hits with. (default: 0)
741+
/// @param skip For every pixel checked along the line, how many to skip between them (default: 0)
742+
/// for optimization reasons. 0 = every pixel is checked.
743+
/// @return How far along, in pixel units, the ray the pixel of any obstacle was
744+
/// encountered. If no pixel of the right material was found, < 0 is returned.
745+
/// If an obstacle on the starting position was encountered, 0 is returned.
746+
float CastObstacleRay(const Vector& start, const Vector& ray, Vector& obstaclePos, Vector& freePos, MOID ignoreMOID = g_NoMOID, int ignoreTeam = Activity::NoTeam, unsigned char ignoreMaterial = 0, int skip = 0) {
747+
std::vector<MOID> ignoreMOIDs = {ignoreMOID};
748+
return CastObstacleRay(start, ray, obstaclePos, freePos, ignoreMOIDs, ignoreTeam, ignoreMaterial, skip);
749+
}
750+
709751
/// Gets the abosulte pos of where the last cast ray hit somehting.
710752
/// @return A vector with the absolute pos of where the last ray cast hit somehting.
711753
const Vector& GetLastRayHitPos();

0 commit comments

Comments
 (0)