View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0002914 | FSSCP | scripting | public | 2013-08-28 14:42 | 2013-08-29 15:39 |
| Reporter | Axem | Assigned To | m_m | ||
| Priority | normal | Severity | minor | Reproducibility | always |
| Status | resolved | Resolution | fixed | ||
| Summary | 0002914: Using AmmoLeft and AmmoMax returns bizzare results | ||||
| Description | Using Primary/SecondaryBankp[i].AmmoLeft or AmmoMax seems to return numbers that are obviously not correct. See below for code snippet and debug output. Talked to m|m about it and he'll take this thrilling case. | ||||
| Steps To Reproduce | CODE: if player.SecondaryBanks:isValid() then for i = 1, #player.SecondaryBanks do ba.print("Secondary Bank " .. i .. ": Ammo Left: " .. player.SecondaryBanks[i].AmmoLeft .. " - Ammo Max: " .. player.SecondaryBanks[i].AmmoMax .. " Trying to increase by: " .. player.SecondaryBanks[i].AmmoMax * amount .. "\n" ) if player.SecondaryBanks[i].AmmoLeft + math.ceil(player.SecondaryBanks[i].AmmoMax * amount) < player.SecondaryBanks[i].AmmoMax then player.SecondaryBanks[i].AmmoLeft = player.SecondaryBanks[i].AmmoLeft + math.ceil(player.SecondaryBanks[i].AmmoMax * amount) else player.SecondaryBanks[i].AmmoLeft = player.SecondaryBanks[i].AmmoMax end end end PRINT OUTPUT: Secondary Bank 1: Ammo Left: 140 - Ammo Max: 8 Trying to increase by: 0.8 Secondary Bank 2: Ammo Left: 1 - Ammo Max: 700 Trying to increase by: 70 GAME STATUS: Player's ship secondary caps are 70, 70 Bank 1 has a weapon with cargo size 0.5 (140 max) Bank 2 has a weapon with cargo size 12 (5 max) | ||||
| Tags | No tags attached. | ||||
|
|
The issue seems to be caused by an incorrect usage of ship_weapons::primary_bank_start_ammo/secondary_bank_start_ammo in the scripting function. The correct way would be to use "get_max_ammo_count_for_primary_bank" or "get_max_ammo_count_for_bank". |
|
|
Added path which fixes the reported problem. |
|
|
mantis2914.patch (2,279 bytes)
Index: code/parse/lua.cpp
===================================================================
--- code/parse/lua.cpp (revision 9749)
+++ code/parse/lua.cpp (working copy)
@@ -6554,7 +6554,8 @@
return ade_set_error(L, "i", 0);
}
-ADE_VIRTVAR(AmmoMax, l_WeaponBank, "number", "Maximum ammo for the current bank", "number", "Ammo capacity, or 0 if handle is invalid")
+ADE_VIRTVAR(AmmoMax, l_WeaponBank, "number", "Maximum ammo for the current bank<br>"
+ "<b>Note:</b> Setting this value actually sets the <i>capacity</i> of the weapon bank. To set the actual maximum ammunition use <tt>AmmoMax = <amount> * class.CargoSize</tt>", "number", "Ammo capacity, or 0 if handle is invalid")
{
ship_bank_h *bh = NULL;
int ammomax;
@@ -6567,23 +6568,35 @@
switch(bh->type)
{
case SWH_PRIMARY:
- if(ADE_SETTING_VAR && ammomax > -1) {
- bh->sw->primary_bank_start_ammo[bh->bank] = ammomax;
+ {
+ if(ADE_SETTING_VAR && ammomax > -1) {
+ bh->sw->primary_bank_capacity[bh->bank] = ammomax;
+ }
+
+ int weapon_class = bh->sw->primary_bank_weapons[bh->bank];
+
+ Assert(bh->objp->type == OBJ_SHIP);
+
+ return ade_set_args(L, "i", get_max_ammo_count_for_primary_bank(Ships[bh->objp->instance].ship_info_index, bh->bank, weapon_class));
}
+ case SWH_SECONDARY:
+ {
+ if(ADE_SETTING_VAR && ammomax > -1) {
+ bh->sw->secondary_bank_capacity[bh->bank] = ammomax;
+ }
- return ade_set_args(L, "i", bh->sw->primary_bank_start_ammo[bh->bank]);
- case SWH_SECONDARY:
- if(ADE_SETTING_VAR && ammomax > -1) {
- bh->sw->secondary_bank_start_ammo[bh->bank] = ammomax;
+ int weapon_class = bh->sw->secondary_bank_weapons[bh->bank];
+
+ Assert(bh->objp->type == OBJ_SHIP);
+
+ return ade_set_args(L, "i", get_max_ammo_count_for_bank(Ships[bh->objp->instance].ship_info_index, bh->bank, weapon_class));
}
-
- return ade_set_args(L, "i", bh->sw->secondary_bank_start_ammo[bh->bank]);
case SWH_TERTIARY:
if(ADE_SETTING_VAR && ammomax > -1) {
- bh->sw->tertiary_bank_ammo = ammomax;
+ bh->sw->tertiary_bank_capacity = ammomax;
}
- return ade_set_args(L, "i", bh->sw->tertiary_bank_start_ammo);
+ return ade_set_args(L, "i", bh->sw->tertiary_bank_capacity);
}
return ade_set_error(L, "i", 0);
|
|
|
Fix committed to trunk@9752. |
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 2013-08-28 14:42 | Axem | New Issue | |
| 2013-08-28 14:43 | m_m | Assigned To | => m_m |
| 2013-08-28 14:43 | m_m | Status | new => assigned |
| 2013-08-28 14:45 | m_m | Note Added: 0015244 | |
| 2013-08-28 15:15 | m_m | Note Added: 0015245 | |
| 2013-08-28 15:15 | m_m | Status | assigned => code review |
| 2013-08-28 15:15 | m_m | File Added: mantis2914.patch | |
| 2013-08-29 15:39 | The_E | Changeset attached | => fs2open trunk r9752 |
| 2013-08-29 15:39 | The_E | Note Added: 0015251 | |
| 2013-08-29 15:39 | The_E | Status | code review => resolved |
| 2013-08-29 15:39 | The_E | Resolution | open => fixed |