-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix static ghost behaviours #1831
base: master
Are you sure you want to change the base?
Changes from all commits
6da976c
9dc230f
29f3458
f3ea435
fa85dd5
7197698
fcbb300
7e905e0
e15c580
d3120da
a8a0c80
493cba2
0ec0141
afd9a07
f046206
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
#include "Rendering/Env/GrassDrawer.h" | ||
#include "Rendering/Env/IGroundDecalDrawer.h" | ||
#include "Rendering/Models/IModelParser.h" | ||
#include "Rendering/Units/UnitDrawer.h" | ||
#include "Sim/Features/Feature.h" | ||
#include "Sim/Features/FeatureDef.h" | ||
#include "Sim/Features/FeatureDefHandler.h" | ||
|
@@ -181,6 +182,7 @@ bool LuaSyncedCtrl::PushEntries(lua_State* L) | |
REGISTER_LUA_CFUNC(SetUnitStealth); | ||
REGISTER_LUA_CFUNC(SetUnitSonarStealth); | ||
REGISTER_LUA_CFUNC(SetUnitSeismicSignature); | ||
REGISTER_LUA_CFUNC(SetUnitLeavesGhost); | ||
REGISTER_LUA_CFUNC(SetUnitAlwaysVisible); | ||
REGISTER_LUA_CFUNC(SetUnitUseAirLos); | ||
REGISTER_LUA_CFUNC(SetUnitMetalExtraction); | ||
|
@@ -2684,6 +2686,35 @@ int LuaSyncedCtrl::SetUnitSeismicSignature(lua_State* L) | |
return 0; | ||
} | ||
|
||
/*** | ||
* @function Spring.SetUnitLeavesGhost | ||
* | ||
* Change the unit leavesGhost attribute. | ||
* | ||
* Controls unit having static radar ghosts. | ||
* | ||
* @number unitID | ||
* @bool leavesGhost | ||
* @bool[opt] leaveDeadGhost leave a dead ghost behind if disabling and the unit had a live static ghost. | ||
* @treturn nil | ||
*/ | ||
int LuaSyncedCtrl::SetUnitLeavesGhost(lua_State* L) | ||
{ | ||
if (!gameSetup->ghostedBuildings) | ||
return 0; | ||
|
||
CUnit* unit = ParseUnit(L, __func__, 1); | ||
|
||
if (unit == nullptr) | ||
return 0; | ||
|
||
bool prevValue = unit->leavesGhost; | ||
unit->SetLeavesGhost(luaL_checkboolean(L, 2)); | ||
if (prevValue != unit->leavesGhost) | ||
unitDrawer->UnitLeavesGhostChanged(unit, luaL_optboolean(L, 3, false)); | ||
Comment on lines
+2713
to
+2714
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These two lines should probably be part of |
||
return 0; | ||
} | ||
|
||
/*** | ||
* @function Spring.SetUnitAlwaysVisible | ||
* @number unitID | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -215,6 +215,7 @@ bool LuaSyncedRead::PushEntries(lua_State* L) | |
REGISTER_LUA_CFUNC(GetUnitArmored); | ||
REGISTER_LUA_CFUNC(GetUnitIsActive); | ||
REGISTER_LUA_CFUNC(GetUnitIsCloaked); | ||
REGISTER_LUA_CFUNC(GetUnitLeavesGhost); | ||
REGISTER_LUA_CFUNC(GetUnitSelfDTime); | ||
REGISTER_LUA_CFUNC(GetUnitStockpile); | ||
REGISTER_LUA_CFUNC(GetUnitSensorRadius); | ||
|
@@ -3850,6 +3851,22 @@ int LuaSyncedRead::GetUnitSeismicSignature(lua_State* L) | |
return 1; | ||
} | ||
|
||
/*** | ||
* | ||
* @function Spring.GetUnitLeavesGhost | ||
* @number unitID | ||
* @treturn nil|number | ||
*/ | ||
int LuaSyncedRead::GetUnitLeavesGhost(lua_State* L) | ||
{ | ||
const CUnit* const unit = ParseAllyUnit(L, __func__, 1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should probably be allowed for enemy units too, since that is whose ghosts you're interested in. |
||
if (unit == nullptr) | ||
return 0; | ||
|
||
lua_pushboolean(L, unit->leavesGhost); | ||
return 1; | ||
} | ||
|
||
/*** | ||
* | ||
* @function Spring.GetUnitSelfDTime | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -295,6 +295,8 @@ void CUnit::PreInit(const UnitLoadParams& params) | |||||
wantCloak |= unitDef->startCloaked; | ||||||
decloakDistance = unitDef->decloakDistance; | ||||||
|
||||||
leavesGhost = gameSetup->ghostedBuildings && unitDef->leavesGhost; | ||||||
|
||||||
flankingBonusMode = unitDef->flankingBonusMode; | ||||||
flankingBonusDir = unitDef->flankingBonusDir; | ||||||
flankingBonusMobility = unitDef->flankingBonusMobilityAdd * 1000; | ||||||
|
@@ -543,6 +545,11 @@ void CUnit::ForcedMove(const float3& newPos) | |||||
} | ||||||
|
||||||
|
||||||
void CUnit::SetLeavesGhost(bool newLeavesGhost) | ||||||
{ | ||||||
leavesGhost = newLeavesGhost; | ||||||
} | ||||||
|
||||||
|
||||||
float3 CUnit::GetErrorVector(int argAllyTeam) const | ||||||
{ | ||||||
|
@@ -555,7 +562,7 @@ float3 CUnit::GetErrorVector(int argAllyTeam) const | |||||
const int atSightMask = losStatus[argAllyTeam]; | ||||||
|
||||||
const int isVisible = 2 * ((atSightMask & LOS_INLOS ) != 0 || teamHandler.Ally(argAllyTeam, allyteam)); // in LOS or allied, no error | ||||||
const int seenGhost = 4 * ((atSightMask & LOS_PREVLOS) != 0 && gameSetup->ghostedBuildings && unitDef->IsBuildingUnit()); // seen ghosted building, no error | ||||||
const int seenGhost = 4 * ((atSightMask & LOS_PREVLOS) != 0 && leavesGhost); // seen ghosted immobiles, no error | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ghosts are no longer tied to being an immobile.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unsure about this, since this is just for ghosts of "generally immobile" units. At least I don't see how this kind of ghosts could have a meaning in the game unless the unit has some kind of "generally immobile" assumption, even if it can sometimes be broken, like when a building is moved with some exception like being transported. Mobile ones have a different kind of ghost. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you point to the different kind of ghost for mobiles? Maybe handling for the two could be combined somehow. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually, looks like the mobile ones don't get drawn by engine itself, for bar it looks like it goes through unit_ghostradar_gl4. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I suspect they could use the same path liveGhostBuildings are using tho, they probably doing it for nothing |
||||||
const int isOnRadar = 8 * ((atSightMask & LOS_INRADAR) != 0 ); // current radar contact | ||||||
|
||||||
float errorMult = 0.0f; | ||||||
|
@@ -3013,6 +3020,8 @@ CR_REG_METADATA(CUnit, ( | |||||
CR_MEMBER(isCloaked), | ||||||
CR_MEMBER(decloakDistance), | ||||||
|
||||||
CR_MEMBER(leavesGhost), | ||||||
|
||||||
CR_MEMBER(lastTerrainType), | ||||||
CR_MEMBER(curTerrainType), | ||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good if leaving a dead ghost was a standalone function. That way
SetUnitLeavesGhost
is atomic and you can leave dead ghosts around in other circumstances at will.