View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0001973 | Spring engine | Lua | public | 2010-07-04 12:57 | 2010-07-04 15:54 |
| Reporter | Rafal99 | Assigned To | jK | ||
| Priority | normal | Severity | trivial | Reproducibility | always |
| Status | resolved | Resolution | fixed | ||
| Product Version | 0.81.2.1 | ||||
| Summary | 0001973: [quick fix] Spring.GetUnitWeaponState (unitID, weaponNum, "reloadTime") returns wrong value | ||||
| Description | The 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 Reproduce | To 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 Information | Imho 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. | ||||
| Tags | No tags attached. | ||||
| Checked infolog.txt for Errors | |||||
|
|
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. |
|
|
http://github.com/spring/spring/commit/dc6231de29e89bb1bff28c9375f19515f6b440b8 |