2019-12-07 07:40 CET

View Issue Details Jump to Notes ]
IDProjectCategoryView StatusLast Update
0004927Spring engineGeneralpublic2015-11-29 09:00
Assigned TojK 
Product Version100.0 
Target VersionFixed in Version 
Summary0004927: unitDef.losRange returns the wrong value
DescriptionThe value returned by UnitDefs[uDID].losRange is incorrect.
The value returned by Spring.GetUnitSensorRadius(test[n][1], 'los') is correct, and always about (not but exactly) 31.5 times that returned by UnitDefs[uDID].losRange.
Steps To ReproduceUse widget code below, and give a unit.
Additional Informationlocal test = {}

function widget:UnitCreated(unitID, unitDefID, unitTeam, builderID)
    local f = Spring.GetGameFrame()
    test[f+1] = {unitID, unitDefID}

function widget:GameFrame(n)
    if test[n] then
        local ud_los = UnitDefs[test[n][2]].losRadius
        local lua_los = Spring.GetUnitSensorRadius(test[n][1], 'los')
        Spring.Echo(ud_los, lua_los, lua_los/ud_los)
TagsNo tags attached.
Checked infolog.txt for Errors
Attached Files




silentwings (reporter)

Last edited: 2015-08-07 18:05

View 2 revisions

Ops, meant to write losRadius (code is correct, subject is not)
Also, test[n][1]==unitID


jK (developer)

it is not wrong the UnitDefs table is
1. not the things you put in in defs.lua stage
2. not in always in the units you expect it to be
3. it is the _raw_ data the engine uses itself


silentwings (reporter)

Then, obviously, how to convert between the two?

Also, afaik every other tag listed on https://springrts.com/wiki/Gamedev:UnitDefs returned distances in elmos unless otherwise specified, so this is imo inconsistent/confusing.


Kloot (developer)

UnitDefs[i].losRadius is

    (sightDistance * modInfo.losMul) / K

GetUnitSensorRadius("los") is

    UnitDefs[i].losRadius * K == sightDistance * modInfo.losMul

the constant K is

    SQUARE_SIZE * (1 << modInfo.losMipLevel)

and it might also be helpful to keep the following snippet around

    local modRules = VFS.Include("gamedata/modrules.lua")
    local losResMult = modRules["sensors"]["los"]["losMul" ]
    local losMipLevel = modRules["sensors"]["los"]["losMipLevel"]
    local losSqSize = Game.squareSize * math.pow(2, losMipLevel)
    local losToElmos = losSqSize / losResMult

    -- in elmos
    local udefBaseSightDist = unitDef.losRadius * losToElmos

    -- assuming you have not called Spring.SetUnitSensorRadius
    assert(Spring.GetUnitSensorRadius(123, "los") / losSqSize == unitDef.losRadius)
    assert(Spring.GetUnitSensorRadius(123, "los") == unitDef.losRadius * losSqSize)

(feel free to put this in the wiki)


silentwings (reporter)

Ok, thanks very much, I'll add to the wiki.

Fwiw, literally all other los/sensor radius tags are in elmos, in both unit def files and the lua table, so imo it would be better if this one was too.


jK (developer)

with the next release the returned values are in elmos

-Issue History
Date Modified Username Field Change
2015-08-07 18:02 silentwings New Issue
2015-08-07 18:04 silentwings Note Added: 0015052
2015-08-07 18:05 silentwings Note Edited: 0015052 View Revisions
2015-08-09 15:38 jK Note Added: 0015058
2015-08-09 15:38 jK Status new => closed
2015-08-09 15:38 jK Assigned To => jK
2015-08-09 15:38 jK Resolution open => no change required
2015-08-09 17:45 silentwings Note Added: 0015059
2015-08-09 17:45 silentwings Status closed => feedback
2015-08-09 17:45 silentwings Resolution no change required => reopened
2015-08-09 20:00 Kloot Note Added: 0015060
2015-08-10 15:32 silentwings Note Added: 0015061
2015-08-10 15:32 silentwings Status feedback => assigned
2015-11-29 09:00 jK Note Added: 0015350
2015-11-29 09:00 jK Status assigned => resolved
2015-11-29 09:00 jK Resolution reopened => fixed
+Issue History