Skip to content

Commit

Permalink
add allyteam-mask arg to Spring.SetUnitPosErrorParams
Browse files Browse the repository at this point in the history
if Unit::posErrorAllyTeamMask contains a zero-bit for
allyteam (1 << N), nullify the positional error vector
when queried by allyteam N
  • Loading branch information
rtri committed Nov 18, 2019
1 parent 525b136 commit 09ea507
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
10 changes: 8 additions & 2 deletions rts/Lua/LuaSyncedCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2538,9 +2538,15 @@ int LuaSyncedCtrl::SetUnitPosErrorParams(lua_State* L)
if (unit == nullptr)
return 0;

unit->posErrorVector = float3(luaL_checkfloat(L, 2), luaL_checkfloat(L, 3), luaL_checkfloat(L, 4));
unit->posErrorDelta = float3(luaL_checkfloat(L, 5), luaL_checkfloat(L, 6), luaL_checkfloat(L, 7));
unit->posErrorVector.x = luaL_optfloat(L, 2, unit->posErrorVector.x);
unit->posErrorVector.y = luaL_optfloat(L, 3, unit->posErrorVector.y);
unit->posErrorVector.z = luaL_optfloat(L, 4, unit->posErrorVector.z);
unit->posErrorDelta.x = luaL_optfloat(L, 5, unit->posErrorDelta.x);
unit->posErrorDelta.y = luaL_optfloat(L, 6, unit->posErrorDelta.y);
unit->posErrorDelta.z = luaL_optfloat(L, 7, unit->posErrorDelta.z);

unit->nextPosErrorUpdate = luaL_optint(L, 8, unit->nextPosErrorUpdate);
unit->posErrorAllyTeamMask = luaL_optint(L, 9, unit->posErrorAllyTeamMask);
return 0;
}

Expand Down
26 changes: 16 additions & 10 deletions rts/Sim/Units/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,21 +521,25 @@ void CUnit::ForcedMove(const float3& newPos)

float3 CUnit::GetErrorVector(int argAllyTeam) const
{
const int tstAllyTeam = argAllyTeam * (argAllyTeam >= 0) * (argAllyTeam < teamHandler.ActiveAllyTeams());
const int tstAllyTeam = argAllyTeam * teamHandler.IsValidAllyTeam(argAllyTeam);
const int atErrorMask = posErrorAllyTeamMask & (1 << tstAllyTeam);
const int atSightMask = losStatus[tstAllyTeam];

const bool limitRead = (1 ) && (tstAllyTeam != argAllyTeam); // LuaHandle without full read access
const bool isVisible = (1 - limitRead) && ((losStatus[tstAllyTeam] & LOS_INLOS ) != 0 || teamHandler.Ally(tstAllyTeam, allyteam)); // in LOS or allied, no error
const bool seenGhost = (1 - limitRead) && ((losStatus[tstAllyTeam] & LOS_PREVLOS) != 0 && gameSetup->ghostedBuildings && unitDef->IsBuildingUnit()); // seen ghosted building, no error
const bool isOnRadar = (1 - limitRead) && ((losStatus[tstAllyTeam] & LOS_INRADAR) != 0); // current radar contact
const bool limitRead = (1 ) && (tstAllyTeam != argAllyTeam); // indicates LuaHandle without full read access
const bool isVisible = (1 - limitRead) && ((atSightMask & LOS_INLOS ) != 0 || teamHandler.Ally(tstAllyTeam, allyteam)); // in LOS or allied, no error
const bool seenGhost = (1 - limitRead) && ((atSightMask & LOS_PREVLOS) != 0 && gameSetup->ghostedBuildings && unitDef->IsBuildingUnit()); // seen ghosted building, no error
const bool isOnRadar = (1 - limitRead) && ((atSightMask & LOS_INRADAR) != 0); // current radar contact

float errorMult = 0.0f;

switch ((limitRead * 1) + (isVisible * 2) + (seenGhost * 4) + (isOnRadar * 8)) {
case 0: { return (posErrorVector * losHandler->GetBaseRadarErrorSize() * 2.0f); } break; // !limitRead && !isVisible && !seenGhost && !isOnRadar
case 1: { return (posErrorVector * losHandler->GetBaseRadarErrorSize() * 2.0f); } break; // limitRead
case 8: { return (posErrorVector * losHandler->GetAllyTeamRadarErrorSize(tstAllyTeam)); } break; // !limitRead && !isVisible && !seenGhost && isOnRadar
default: { } break; // !limitRead && ( isVisible || seenGhost) && !isOnRadar
case 0: { errorMult = losHandler->GetBaseRadarErrorSize() * 2.0f; } break; // !limitRead && !isVisible && !seenGhost && !isOnRadar
case 1: { errorMult = losHandler->GetBaseRadarErrorSize() * 2.0f; } break; // limitRead (allyteam < 0 || allyteam >= #activeallyteams)
case 8: { errorMult = losHandler->GetAllyTeamRadarErrorSize(tstAllyTeam); } break; // !limitRead && !isVisible && !seenGhost && isOnRadar
default: { } break; // !limitRead && ( isVisible || seenGhost) && !isOnRadar
}

return ZeroVector;
return (posErrorVector * errorMult * ((atErrorMask + limitRead) != 0));
}

void CUnit::UpdatePosErrorParams(bool updateError, bool updateDelta)
Expand Down Expand Up @@ -2897,7 +2901,9 @@ CR_REG_METADATA(CUnit, (

CR_MEMBER(posErrorVector),
CR_MEMBER(posErrorDelta),

CR_MEMBER(nextPosErrorUpdate),
CR_MEMBER(posErrorAllyTeamMask),

CR_MEMBER(wantCloak),
CR_MEMBER(isCloaked),
Expand Down
2 changes: 2 additions & 0 deletions rts/Sim/Units/Unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,8 @@ class CUnit : public CSolidObject
float curArmorMultiple = 1.0f;

int nextPosErrorUpdate = 1;
// bit-mask indicating which allyteams see this unit with positional error
int posErrorAllyTeamMask = 0xFFFFFFFF;


int lastTerrainType = -1;
Expand Down

0 comments on commit 09ea507

Please sign in to comment.