Skip to content

Commit 2530a6a

Browse files
authored
Merge pull request #53 from cortex-command-community/mopixelcolorchange
Exposed MOPixel Color to Lua, made DislodgePixel return MOPixels
2 parents c6b8047 + a8d423c commit 2530a6a

File tree

6 files changed

+54
-38
lines changed

6 files changed

+54
-38
lines changed

CHANGELOG.md

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

161161
- New `SceneMan` Lua function `CastTerrainPenetrationRay(Vector start, Vector ray, Vector endPos, int strengthLimit, int skip)`, which adds up the material strength of the terrain pixels encountered along the way, and stops when the accumulated value meets or exceeds `strengthLimit`. `endPos` is filled out with the ending position of the ray, returns `true` or `false` depending on whether the ray was stopped early or not.
162162

163+
- New `MOPixel` Lua functions `GetColorIndex()` and `SetColorIndex(int newColorIndex)`, which allow you to get and set the index of the pixel's color.
164+
163165
- Three new Browncoat items have been added: a shield with reactive explosive armor, a revolver, and a close-range incendiary battle rifle.
164166

165167
- AI idle aim timer (the time the AI stops after aiming fully up or fully down in sentry mode) is now customizable using a custom number value for ACrabs. Use it to make your turrets less spastic.
@@ -208,6 +210,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
208210

209211
- `SceneMan` Lua function `DislodgePixel()` now optionally accepts a third boolean argument to delete the found pixel immediately. Format is `DislodgePixel(int posX, int posY, bool deletePixel)`. `DislodgePixel()` now also automatically accounts for scene wrapping.
210212

213+
- `SceneMan` Lua function `DislodgePixel()` and all of its derivatives now return `MOPixels` instead of `MovableObjects`.
214+
211215
- MuzzleSmoke.lua now uses the new ParticleUtility directional smoke function for a more interesting effect.
212216

213217
</details>

Source/Entities/MOPixel.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,18 @@ namespace RTE {
8686
/// @return A Color object describing the color.
8787
Color GetColor() const { return m_Color; }
8888

89+
/// Gets the index of the color of this MOPixel.
90+
/// @return An int that is the index of the Color object.
91+
int GetColorIndex() const { return m_Color.GetIndex(); }
92+
8993
/// Sets the color value of this MOPixel.
9094
/// @param newColor A Color object specifying the new color index value.
9195
void SetColor(Color newColor) { m_Color = newColor; }
9296

97+
/// Sets the color value of this MOPixel via index.
98+
/// @param newColor An int specifying the new color index value.
99+
void SetColorIndex(int newColorIndex) { m_Color.SetRGBWithIndex(newColorIndex); }
100+
93101
/// Travel distance until the bullet start to lose lethality.
94102
/// @return The factor that modifies the base value.
95103
float GetMaxLethalRangeFactor() const { return m_MaxLethalRange; }

Source/Lua/LuaBindingsEntities.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,10 @@ LuaBindingRegisterFunctionDefinitionForType(EntityLuaBindings, MOPixel) {
763763
return ConcreteTypeLuaClassDefinition(MOPixel, MovableObject)
764764

765765
.property("TrailLength", &MOPixel::GetTrailLength, &MOPixel::SetTrailLength)
766-
.property("Staininess", &MOPixel::GetStaininess, &MOPixel::SetStaininess);
766+
.property("Staininess", &MOPixel::GetStaininess, &MOPixel::SetStaininess)
767+
768+
.def("GetColorIndex", &MOPixel::GetColorIndex)
769+
.def("SetColorIndex", &MOPixel::SetColorIndex);
767770
}
768771

769772
LuaBindingRegisterFunctionDefinitionForType(EntityLuaBindings, MOSParticle) {

Source/Lua/LuaBindingsManagers.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -333,14 +333,14 @@ LuaBindingRegisterFunctionDefinitionForType(ManagerLuaBindings, SceneMan) {
333333
.def("CheckAndRemoveOrphans", (int(SceneMan::*)(int, int, int, int, bool)) & SceneMan::RemoveOrphans)
334334
.def("DislodgePixel", &SceneMan::DislodgePixel)
335335
.def("DislodgePixel", &SceneMan::DislodgePixelBool)
336-
.def("DislodgePixelLine", (const std::vector<MovableObject*>* (SceneMan::*)(const Vector& start, const Vector& ray, int skip, bool deletePixels) const) & SceneMan::DislodgePixelLine, luabind::adopt(luabind::return_value) + luabind::return_stl_iterator)
337-
.def("DislodgePixelLine", (const std::vector<MovableObject*>* (SceneMan::*)(const Vector& start, const Vector& ray, int skip) const) & SceneMan::DislodgePixelLineNoBool, luabind::adopt(luabind::return_value) + luabind::return_stl_iterator)
338-
.def("DislodgePixelCircle", (const std::vector<MovableObject*>* (SceneMan::*)(const Vector& centre, float radius, bool deletePixels) const) & SceneMan::DislodgePixelCircle, luabind::adopt(luabind::return_value) + luabind::return_stl_iterator)
339-
.def("DislodgePixelCircle", (const std::vector<MovableObject*>* (SceneMan::*)(const Vector& centre, float radius) const) & SceneMan::DislodgePixelCircleNoBool, luabind::adopt(luabind::return_value) + luabind::return_stl_iterator)
340-
.def("DislodgePixelBox", (const std::vector<MovableObject*>* (SceneMan::*)(const Vector& upperLeftCorner, const Vector& lowerRightCorner, bool deletePixels) const) & SceneMan::DislodgePixelBox, luabind::adopt(luabind::return_value) + luabind::return_stl_iterator)
341-
.def("DislodgePixelBox", (const std::vector<MovableObject*>* (SceneMan::*)(const Vector& upperLeftCorner, const Vector& lowerRightCorner) const) & SceneMan::DislodgePixelBoxNoBool, luabind::adopt(luabind::return_value) + luabind::return_stl_iterator)
342-
.def("DislodgePixelRing", (const std::vector<MovableObject*>* (SceneMan::*)(const Vector& centre, float innerRadius, float outerRadius, bool deletePixels) const) & SceneMan::DislodgePixelRing, luabind::adopt(luabind::return_value) + luabind::return_stl_iterator)
343-
.def("DislodgePixelRing", (const std::vector<MovableObject*>* (SceneMan::*)(const Vector& centre, float innerRadius, float outerRadius) const) & SceneMan::DislodgePixelRingNoBool, luabind::adopt(luabind::return_value) + luabind::return_stl_iterator);
336+
.def("DislodgePixelLine", (const std::vector<MOPixel*>* (SceneMan::*)(const Vector& start, const Vector& ray, int skip, bool deletePixels) const) & SceneMan::DislodgePixelLine, luabind::adopt(luabind::return_value) + luabind::return_stl_iterator)
337+
.def("DislodgePixelLine", (const std::vector<MOPixel*>* (SceneMan::*)(const Vector& start, const Vector& ray, int skip) const) & SceneMan::DislodgePixelLineNoBool, luabind::adopt(luabind::return_value) + luabind::return_stl_iterator)
338+
.def("DislodgePixelCircle", (const std::vector<MOPixel*>* (SceneMan::*)(const Vector& centre, float radius, bool deletePixels) const) & SceneMan::DislodgePixelCircle, luabind::adopt(luabind::return_value) + luabind::return_stl_iterator)
339+
.def("DislodgePixelCircle", (const std::vector<MOPixel*>* (SceneMan::*)(const Vector& centre, float radius) const) & SceneMan::DislodgePixelCircleNoBool, luabind::adopt(luabind::return_value) + luabind::return_stl_iterator)
340+
.def("DislodgePixelBox", (const std::vector<MOPixel*>* (SceneMan::*)(const Vector& upperLeftCorner, const Vector& lowerRightCorner, bool deletePixels) const) & SceneMan::DislodgePixelBox, luabind::adopt(luabind::return_value) + luabind::return_stl_iterator)
341+
.def("DislodgePixelBox", (const std::vector<MOPixel*>* (SceneMan::*)(const Vector& upperLeftCorner, const Vector& lowerRightCorner) const) & SceneMan::DislodgePixelBoxNoBool, luabind::adopt(luabind::return_value) + luabind::return_stl_iterator)
342+
.def("DislodgePixelRing", (const std::vector<MOPixel*>* (SceneMan::*)(const Vector& centre, float innerRadius, float outerRadius, bool deletePixels) const) & SceneMan::DislodgePixelRing, luabind::adopt(luabind::return_value) + luabind::return_stl_iterator)
343+
.def("DislodgePixelRing", (const std::vector<MOPixel*>* (SceneMan::*)(const Vector& centre, float innerRadius, float outerRadius) const) & SceneMan::DislodgePixelRingNoBool, luabind::adopt(luabind::return_value) + luabind::return_stl_iterator);
344344
}
345345

346346
LuaBindingRegisterFunctionDefinitionForType(ManagerLuaBindings, CameraMan) {

Source/Managers/SceneMan.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ bool SceneMan::TryPenetrate(int posX,
892892
return false;
893893
}
894894

895-
MovableObject* SceneMan::DislodgePixel(int posX, int posY) {
895+
MOPixel* SceneMan::DislodgePixel(int posX, int posY) {
896896
WrapPosition(posX, posY);
897897
int materialID = getpixel(m_pCurrentScene->GetTerrain()->GetMaterialBitmap(), posX, posY);
898898
if (materialID <= MaterialColorKeys::g_MaterialAir) {
@@ -924,16 +924,16 @@ MovableObject* SceneMan::DislodgePixel(int posX, int posY) {
924924
}
925925

926926
// Bool variant to avoid changing the original
927-
MovableObject* SceneMan::DislodgePixelBool(int posX, int posY, bool deletePixel) {
928-
MovableObject* pixelMO = DislodgePixel(posX, posY);
927+
MOPixel* SceneMan::DislodgePixelBool(int posX, int posY, bool deletePixel) {
928+
MOPixel* pixelMO = DislodgePixel(posX, posY);
929929
if (pixelMO) {
930930
pixelMO->SetToDelete(deletePixel);
931931
}
932932
return pixelMO;
933933
}
934934

935-
std::vector<MovableObject*>* SceneMan::DislodgePixelCircle(const Vector& centre, float radius, bool deletePixels) {
936-
std::vector<MovableObject*>* pixelList = new std::vector<MovableObject*>();
935+
std::vector<MOPixel*>* SceneMan::DislodgePixelCircle(const Vector& centre, float radius, bool deletePixels) {
936+
std::vector<MOPixel*>* pixelList = new std::vector<MOPixel*>();
937937
int limit = static_cast<int>(radius) * 2;
938938
for (int x = 0; x <= limit; x++) {
939939
for (int y = 0; y <= limit; y++) {
@@ -945,7 +945,7 @@ std::vector<MovableObject*>* SceneMan::DislodgePixelCircle(const Vector& centre,
945945
}
946946

947947
if (!distance.MagnitudeIsGreaterThan(radius)) {
948-
MovableObject* px = DislodgePixelBool(checkPos.m_X, checkPos.m_Y, deletePixels);
948+
MOPixel* px = DislodgePixelBool(checkPos.m_X, checkPos.m_Y, deletePixels);
949949
if (px) {
950950
pixelList->push_back(px);
951951
}
@@ -956,17 +956,17 @@ std::vector<MovableObject*>* SceneMan::DislodgePixelCircle(const Vector& centre,
956956
return pixelList;
957957
}
958958

959-
std::vector<MovableObject*>* SceneMan::DislodgePixelCircleNoBool(const Vector& centre, float radius) {
959+
std::vector<MOPixel*>* SceneMan::DislodgePixelCircleNoBool(const Vector& centre, float radius) {
960960
return DislodgePixelCircle(centre, radius, false);
961961
}
962962

963-
std::vector<MovableObject*>* SceneMan::DislodgePixelRing(const Vector& centre, float innerRadius, float outerRadius, bool deletePixels) {
963+
std::vector<MOPixel*>* SceneMan::DislodgePixelRing(const Vector& centre, float innerRadius, float outerRadius, bool deletePixels) {
964964
// Account for users inputting radii in the wrong order
965965
if (outerRadius < innerRadius) {
966966
std::swap(outerRadius, innerRadius);
967967
}
968968

969-
std::vector<MovableObject*>* pixelList = new std::vector<MovableObject*>();
969+
std::vector<MOPixel*>* pixelList = new std::vector<MOPixel*>();
970970
int limit = static_cast<int>(outerRadius) * 2;
971971
for (int x = 0; x <= limit; x++) {
972972
for (int y = 0; y <= limit; y++) {
@@ -983,7 +983,7 @@ std::vector<MovableObject*>* SceneMan::DislodgePixelRing(const Vector& centre, f
983983
}
984984

985985
if (!distance.MagnitudeIsGreaterThan(outerRadius) && !distance.MagnitudeIsLessThan(innerRadius)) {
986-
MovableObject* px = DislodgePixelBool(checkPos.m_X, checkPos.m_Y, deletePixels);
986+
MOPixel* px = DislodgePixelBool(checkPos.m_X, checkPos.m_Y, deletePixels);
987987
if (px) {
988988
pixelList->push_back(px);
989989
}
@@ -994,12 +994,12 @@ std::vector<MovableObject*>* SceneMan::DislodgePixelRing(const Vector& centre, f
994994
return pixelList;
995995
}
996996

997-
std::vector<MovableObject*>* SceneMan::DislodgePixelRingNoBool(const Vector& centre, float innerRadius, float outerRadius) {
997+
std::vector<MOPixel*>* SceneMan::DislodgePixelRingNoBool(const Vector& centre, float innerRadius, float outerRadius) {
998998
return DislodgePixelRing(centre, innerRadius, outerRadius, false);
999999
}
10001000

1001-
std::vector<MovableObject*>* SceneMan::DislodgePixelBox(const Vector& upperLeftCorner, const Vector& lowerRightCorner, bool deletePixels) {
1002-
std::vector<MovableObject*>* pixelList = new std::vector<MovableObject*>();
1001+
std::vector<MOPixel*>* SceneMan::DislodgePixelBox(const Vector& upperLeftCorner, const Vector& lowerRightCorner, bool deletePixels) {
1002+
std::vector<MOPixel*>* pixelList = new std::vector<MOPixel*>();
10031003

10041004
// Make sure it works even if people input corners in the wrong order
10051005
Vector start = Vector(std::min(upperLeftCorner.m_X, lowerRightCorner.m_X), std::min(upperLeftCorner.m_Y, lowerRightCorner.m_Y));
@@ -1010,7 +1010,7 @@ std::vector<MovableObject*>* SceneMan::DislodgePixelBox(const Vector& upperLeftC
10101010
for (int x = 0; x <= static_cast<int>(width) * 2; x++) {
10111011
for (int y = 0; y <= static_cast<int>(height) * 2; y++) {
10121012
Vector checkPos = start + Vector(static_cast<float>(x), static_cast<float>(y));
1013-
MovableObject* px = DislodgePixelBool(checkPos.m_X, checkPos.m_Y, deletePixels);
1013+
MOPixel* px = DislodgePixelBool(checkPos.m_X, checkPos.m_Y, deletePixels);
10141014
if (px) {
10151015
pixelList->push_back(px);
10161016
}
@@ -1020,12 +1020,12 @@ std::vector<MovableObject*>* SceneMan::DislodgePixelBox(const Vector& upperLeftC
10201020
return pixelList;
10211021
}
10221022

1023-
std::vector<MovableObject*>* SceneMan::DislodgePixelBoxNoBool(const Vector& upperLeftCorner, const Vector& lowerRightCorner) {
1023+
std::vector<MOPixel*>* SceneMan::DislodgePixelBoxNoBool(const Vector& upperLeftCorner, const Vector& lowerRightCorner) {
10241024
return DislodgePixelBox(upperLeftCorner, lowerRightCorner, false);
10251025
}
10261026

1027-
std::vector<MovableObject*>* SceneMan::DislodgePixelLine(const Vector& start, const Vector& ray, int skip, bool deletePixels) {
1028-
std::vector<MovableObject*>* pixelList = new std::vector<MovableObject*>();
1027+
std::vector<MOPixel*>* SceneMan::DislodgePixelLine(const Vector& start, const Vector& ray, int skip, bool deletePixels) {
1028+
std::vector<MOPixel*>* pixelList = new std::vector<MOPixel*>();
10291029
int error, dom, sub, domSteps, skipped = skip;
10301030
int intPos[2], delta[2], delta2[2], increment[2];
10311031

@@ -1080,7 +1080,7 @@ std::vector<MovableObject*>* SceneMan::DislodgePixelLine(const Vector& start, co
10801080
// Scene wrapping
10811081
g_SceneMan.WrapPosition(intPos[X], intPos[Y]);
10821082

1083-
MovableObject* px = DislodgePixelBool(intPos[X], intPos[Y], deletePixels);
1083+
MOPixel* px = DislodgePixelBool(intPos[X], intPos[Y], deletePixels);
10841084
if (px) {
10851085
pixelList->push_back(px);
10861086
}
@@ -1093,7 +1093,7 @@ std::vector<MovableObject*>* SceneMan::DislodgePixelLine(const Vector& start, co
10931093
return pixelList;
10941094
}
10951095

1096-
std::vector<MovableObject*>* SceneMan::DislodgePixelLineNoBool(const Vector& start, const Vector& ray, int skip) {
1096+
std::vector<MOPixel*>* SceneMan::DislodgePixelLineNoBool(const Vector& start, const Vector& ray, int skip) {
10971097
return DislodgePixelLine(start, ray, skip, false);
10981098
}
10991099

Source/Managers/SceneMan.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ namespace RTE {
3131
class SceneObject;
3232
class TerrainObject;
3333
class MovableObject;
34+
class MOPixel;
3435
class Material;
3536
class SoundContainer;
3637
struct PostEffect;
@@ -401,70 +402,70 @@ namespace RTE {
401402
/// @param posX The X coordinate of the terrain pixel.
402403
/// @param posX The Y coordinate of the terrain pixel.
403404
/// @return The newly dislodged pixel, if one was found.
404-
MovableObject* DislodgePixel(int posX, int posY);
405+
MOPixel* DislodgePixel(int posX, int posY);
405406

406407
/// Removes a pixel from the terrain and adds it to MovableMan.
407408
/// @param posX The X coordinate of the terrain pixel.
408409
/// @param posX The Y coordinate of the terrain pixel.
409410
/// @param deletePixel Whether or not to immediately mark the pixel for deletion.
410411
/// @return The newly dislodged pixel, if one was found.
411-
MovableObject* DislodgePixelBool(int posX, int posY, bool deletePixel);
412+
MOPixel* DislodgePixelBool(int posX, int posY, bool deletePixel);
412413

413414
/// Removes a circle of pixels from the terrain and adds them to MovableMan.
414415
/// @param centre The vector position of the centre of the circle.
415416
/// @param radius The radius of the circle of pixels to remove.
416417
/// @param deletePixels Whether or not to immediately mark all found pixels for deletion.
417418
/// @return A list of the removed pixels, if any.
418-
std::vector<MovableObject*>* DislodgePixelCircle(const Vector& centre, float radius, bool deletePixels);
419+
std::vector<MOPixel*>* DislodgePixelCircle(const Vector& centre, float radius, bool deletePixels);
419420

420421
/// Removes a circle of pixels from the terrain and adds them to MovableMan.
421422
/// @param centre The vector position of the centre of the circle.
422423
/// @param radius The radius of the circle of pixels to remove.
423424
/// @return A list of the removed pixels, if any.
424-
std::vector<MovableObject*>* DislodgePixelCircleNoBool(const Vector& centre, float radius);
425+
std::vector<MOPixel*>* DislodgePixelCircleNoBool(const Vector& centre, float radius);
425426

426427
/// Removes a ring of pixels from the terrain and adds them to MovableMan.
427428
/// @param centre The vector position of the centre of the ring.
428429
/// @param innerRadius The inner radius of the ring of pixels to remove.
429430
/// @param outerRadius The outer radius of the ring of pixels to remove.
430431
/// @param deletePixels Whether or not to immediately mark all found pixels for deletion.
431432
/// @return A list of the removed pixels, if any.
432-
std::vector<MovableObject*>* DislodgePixelRing(const Vector& centre, float innerRadius, float outerRadius, bool deletePixels);
433+
std::vector<MOPixel*>* DislodgePixelRing(const Vector& centre, float innerRadius, float outerRadius, bool deletePixels);
433434

434435
/// Removes a ring of pixels from the terrain and adds them to MovableMan.
435436
/// @param centre The vector position of the centre of the ring.
436437
/// @param innerRadius The inner radius of the ring of pixels to remove.
437438
/// @param outerRadius The outer radius of the ring of pixels to remove.
438439
/// @return A list of the removed pixels, if any.
439-
std::vector<MovableObject*>* DislodgePixelRingNoBool(const Vector& centre, float innerRadius, float outerRadius);
440+
std::vector<MOPixel*>* DislodgePixelRingNoBool(const Vector& centre, float innerRadius, float outerRadius);
440441

441442
/// Removes a box of pixels from the terrain and adds them to MovableMan.
442443
/// @param upperLeftCorner The vector position of the upper left corner of the box.
443444
/// @param lowerRightCorner The vector position of the lower right corner of the box.
444445
/// @param deletePixels Whether or not to immediately mark all found pixels for deletion.
445446
/// @return A list of the removed pixels, if any.
446-
std::vector<MovableObject*>* DislodgePixelBox(const Vector& upperLeftCorner, const Vector& lowerRightCorner, bool deletePixels);
447+
std::vector<MOPixel*>* DislodgePixelBox(const Vector& upperLeftCorner, const Vector& lowerRightCorner, bool deletePixels);
447448

448449
/// Removes a box of pixels from the terrain and adds them to MovableMan.
449450
/// @param upperLeftCorner The vector position of the upper left corner of the box.
450451
/// @param lowerRightCorner The vector position of the lower right corner of the box.
451452
/// @return A list of the removed pixels, if any.
452-
std::vector<MovableObject*>* DislodgePixelBoxNoBool(const Vector& upperLeftCorner, const Vector& lowerRightCorner);
453+
std::vector<MOPixel*>* DislodgePixelBoxNoBool(const Vector& upperLeftCorner, const Vector& lowerRightCorner);
453454

454455
/// Removes a line of pixels from the terrain and adds them to MovableMan.
455456
/// @param start The starting position.
456457
/// @param ray The vector to trace along.
457458
/// @param skip For every pixel checked along the line, how many to skip between them.
458459
/// @param deletePixels Whether or not to immediately mark all found pixels for deletion.
459460
/// @return A list of the removed pixels, if any.
460-
std::vector<MovableObject*>* DislodgePixelLine(const Vector& start, const Vector& ray, int skip, bool deletePixels);
461+
std::vector<MOPixel*>* DislodgePixelLine(const Vector& start, const Vector& ray, int skip, bool deletePixels);
461462

462463
/// Removes a line of pixels from the terrain and adds them to MovableMan.
463464
/// @param start The starting position.
464465
/// @param ray The vector to trace along.
465466
/// @param skip For every pixel checked along the line, how many to skip between them.
466467
/// @return A list of the removed pixels, if any.
467-
std::vector<MovableObject*>* DislodgePixelLineNoBool(const Vector& start, const Vector& ray, int skip);
468+
std::vector<MOPixel*>* DislodgePixelLineNoBool(const Vector& start, const Vector& ray, int skip);
468469

469470
/// Sets one team's view of the scene to be unseen, using a generated map
470471
/// of a specific resolution chunkiness.

0 commit comments

Comments
 (0)