Skip to content

Commit

Permalink
Add unit->staticRadarGhost to control radar ghosts having no drift.
Browse files Browse the repository at this point in the history
  • Loading branch information
saurtron committed Jan 7, 2025
1 parent 29f3458 commit f3ea435
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 2 deletions.
22 changes: 22 additions & 0 deletions rts/Lua/LuaSyncedCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ bool LuaSyncedCtrl::PushEntries(lua_State* L)
REGISTER_LUA_CFUNC(SetUnitStealth);
REGISTER_LUA_CFUNC(SetUnitSonarStealth);
REGISTER_LUA_CFUNC(SetUnitSeismicSignature);
REGISTER_LUA_CFUNC(SetUnitStaticRadarGhost);
REGISTER_LUA_CFUNC(SetUnitAlwaysVisible);
REGISTER_LUA_CFUNC(SetUnitUseAirLos);
REGISTER_LUA_CFUNC(SetUnitMetalExtraction);
Expand Down Expand Up @@ -2684,6 +2685,27 @@ int LuaSyncedCtrl::SetUnitSeismicSignature(lua_State* L)
return 0;
}

/***
* @function Spring.SetUnitStaticRadarGhost
*
* Set the radar ghost for the unit to have no drift.
* Only for units where unitDef has leavesRadarGhost enabled.
*
* @number unitID
* @bool staticRadarGhost
* @treturn nil
*/
int LuaSyncedCtrl::SetUnitStaticRadarGhost(lua_State* L)
{
CUnit* unit = ParseUnit(L, __func__, 1);

if (unit == nullptr)
return 0;

unit->SetStaticRadarGhost(luaL_checkboolean(L, 2));
return 0;
}

/***
* @function Spring.SetUnitAlwaysVisible
* @number unitID
Expand Down
1 change: 1 addition & 0 deletions rts/Lua/LuaSyncedCtrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class LuaSyncedCtrl
static int SetUnitStealth(lua_State* L);
static int SetUnitSonarStealth(lua_State* L);
static int SetUnitSeismicSignature(lua_State* L);
static int SetUnitStaticRadarGhost(lua_State* L);
static int SetUnitAlwaysVisible(lua_State* L);
static int SetUnitUseAirLos(lua_State* L);
static int SetUnitResourcing(lua_State* L);
Expand Down
17 changes: 17 additions & 0 deletions rts/Lua/LuaSyncedRead.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(GetUnitStaticRadarGhost);
REGISTER_LUA_CFUNC(GetUnitSelfDTime);
REGISTER_LUA_CFUNC(GetUnitStockpile);
REGISTER_LUA_CFUNC(GetUnitSensorRadius);
Expand Down Expand Up @@ -3850,6 +3851,22 @@ int LuaSyncedRead::GetUnitSeismicSignature(lua_State* L)
return 1;
}

/***
*
* @function Spring.GetUnitStaticRadarGhost
* @number unitID
* @treturn nil|number
*/
int LuaSyncedRead::GetUnitStaticRadarGhost(lua_State* L)
{
const CUnit* const unit = ParseAllyUnit(L, __func__, 1);
if (unit == nullptr)
return 0;

lua_pushboolean(L, unit->staticRadarGhost);
return 1;
}

/***
*
* @function Spring.GetUnitSelfDTime
Expand Down
1 change: 1 addition & 0 deletions rts/Lua/LuaSyncedRead.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class LuaSyncedRead {
static int GetUnitIsActive(lua_State* L);
static int GetUnitIsCloaked(lua_State* L);
static int GetUnitSeismicSignature(lua_State* L);
static int GetUnitStaticRadarGhost(lua_State* L);
static int GetUnitSelfDTime(lua_State* L);
static int GetUnitStockpile(lua_State* L);
static int GetUnitSensorRadius(lua_State* L);
Expand Down
11 changes: 10 additions & 1 deletion rts/Sim/Units/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ void CUnit::PreInit(const UnitLoadParams& params)
wantCloak |= unitDef->startCloaked;
decloakDistance = unitDef->decloakDistance;

staticRadarGhost = unitDef->leavesRadarGhost;

flankingBonusMode = unitDef->flankingBonusMode;
flankingBonusDir = unitDef->flankingBonusDir;
flankingBonusMobility = unitDef->flankingBonusMobilityAdd * 1000;
Expand Down Expand Up @@ -543,6 +545,11 @@ void CUnit::ForcedMove(const float3& newPos)
}


void CUnit::SetStaticRadarGhost(bool isStatic)
{
staticRadarGhost = isStatic && unitDef->leavesRadarGhost;
}


float3 CUnit::GetErrorVector(int argAllyTeam) const
{
Expand All @@ -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->IsImmobileUnit()); // seen ghosted immobiles, no error
const int seenGhost = 4 * ((atSightMask & LOS_PREVLOS) != 0 && gameSetup->ghostedBuildings && staticRadarGhost); // seen ghosted immobiles, no error
const int isOnRadar = 8 * ((atSightMask & LOS_INRADAR) != 0 ); // current radar contact

float errorMult = 0.0f;
Expand Down Expand Up @@ -3013,6 +3020,8 @@ CR_REG_METADATA(CUnit, (
CR_MEMBER(isCloaked),
CR_MEMBER(decloakDistance),

CR_MEMBER(staticRadarGhost),

CR_MEMBER(lastTerrainType),
CR_MEMBER(curTerrainType),

Expand Down
5 changes: 4 additions & 1 deletion rts/Sim/Units/Unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ class CUnit : public CSolidObject
unsigned short CalcLosStatus(int allyTeam);
void UpdateLosStatus(int allyTeam);

void SetStaticRadarGhost(bool isStatic);

void UpdateWeapons();
void UpdateWeaponVectors();

Expand Down Expand Up @@ -548,7 +550,8 @@ class CUnit : public CSolidObject
bool isCloaked = false;
// true if the unit currently wants to be cloaked
bool wantCloak = false;

// true if unitDef leavesRadarGhost and the unit ghost will have no drift
bool staticRadarGhost = false;

// unsynced vars
bool noMinimap = false;
Expand Down

0 comments on commit f3ea435

Please sign in to comment.