View Issue Details

IDProjectCategoryView StatusLast Update
0004927Spring engineGeneralpublic2015-11-29 09:00
Reportersilentwings Assigned TojK  
PrioritynormalSeveritymajorReproducibilityalways
Status resolvedResolutionfixed 
Product Version100.0 
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}
end

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)
    end
end
TagsNo tags attached.
Checked infolog.txt for Errors

Activities

silentwings

2015-08-07 18:04

reporter   ~0015052

Last edited: 2015-08-07 18:05

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

jK

2015-08-09 15:38

developer   ~0015058

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

2015-08-09 17:45

reporter   ~0015059

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

2015-08-09 20:00

developer   ~0015060

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

2015-08-10 15:32

reporter   ~0015061

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

2015-11-29 09:00

developer   ~0015350

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
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