2025-07-18 08:56 CEST

View Issue Details Jump to Notes ]
IDProjectCategoryView StatusLast Update
0001973Spring engineLuapublic2010-07-04 15:54
ReporterRafal99 
Assigned TojK 
PrioritynormalSeveritytrivialReproducibilityalways
StatusresolvedResolutionfixed 
Product Version0.81.2.1 
Target VersionFixed in Version 
Summary0001973: [quick fix] Spring.GetUnitWeaponState (unitID, weaponNum, "reloadTime") returns wrong value
DescriptionThe value returned is rounded down to nearest integer.

I investigated this bug and here is the explanation:

CWeapon::reloadTime is integer (Weapon.h:82)
Its value means how many game frames it takes the weapon to reload.

When unit is created its weapons reloadTime is copied from weapon defs and multiplied by GAME_SPEED. (UnitLoader.cpp:442)

Now GetUnitWeaponState returns the value divided by GAME_SPEED, but still as integer so it gets rounded. (LuaSyncedRead.cpp:2908)

Needs to be changed to "(float)weapon->reloadTime / GAME_SPEED" in this line.



It is worth noting that GetUnitWeaponState uses weaponNum starting from 0, instead of starting from 1 like the rest of the Lua, but I bet it can't be changed because of backward-compatibity reasons.
Steps To ReproduceTo test it make a weapon with reloadTime = 2.6 then call GetUnitWeaponState in gadget - it will return 2.0
Note that WeaponDefs[id].reload gives the correct value, but this one is not unit-specific.
Additional InformationImho it might be worth to make reloadTime float everywhere and change the code accordingly, because with the current system the weapon firing rates may be quite inaccurate.
For example:
Weapon with reloadTime = 0.09
It gets multiplied by GAME_SPEED and rounded, you get: 0.09 * 30 = 2.7 -> 2
Now the real reload time becomes 2 / 30 = 0.066 instead of 0.09 which is quite a difference.
Sure it is only noticable with very low reload times, but still.
TagsNo tags attached.
Checked infolog.txt for Errors
Attached Files

-Relationships
+Relationships

-Notes

~0005044

Rafal99 (reporter)

Another thing is that CWeapon::reloadTime doesn't change for units with high experience,
while the real reload time is calculated (reloadTime / owner->reloadSpeed), where owner->reloadSpeed increases with unit experience, but can't be read by Lua.

Might be good to change the function to return (reloadTime / owner->reloadSpeed) instead of simply reloadTime.

~0005048

jK (developer)

http://github.com/spring/spring/commit/dc6231de29e89bb1bff28c9375f19515f6b440b8
+Notes

-Issue History
Date Modified Username Field Change
2010-07-04 12:57 Rafal99 New Issue
2010-07-04 13:26 Rafal99 Note Added: 0005044
2010-07-04 15:54 jK Note Added: 0005048
2010-07-04 15:54 jK Status new => resolved
2010-07-04 15:54 jK Resolution open => fixed
2010-07-04 15:54 jK Assigned To => jK
+Issue History