122 - Incorrect calculation of possible number of items that can be produced
AWST Calculates the number of items that can be produced by considering reagents in bags/bank/alts and considering merchants. However in some cases this figures are incorrect.
Steps to reproduce:
Consider Woolen Cape of Tailoring. It is produced by 1 Bold of Woolen Cloth and 1 Fine Thread. Each Bolt of Woolen Cloth is produced by 3 Wool Clothes. Assume you have 13 Wool Clothes in your bag. AWST correctly displays the number of Woolen Capes to be produced as (0/4) (Not 4/4, since you need to buy Fine Thread to craft them).
Now queue 1 Woolen Cape. 1 Bolt of Woolen Cloth is queued as well. The number of Woolen Capes to be produced is updated, but incorrectly. We should see (0/3) as the number of Woolen Capes to be produced, but we see (0/2).
This incorrect behavior occurs for professions where gathered items (clothes in tailoring, pigments for inscription) are converted to another item (bolts of clothes for tailoring, inks for inscription) and real trade items are crafted from these intermediate items.
Technically, the reason behind this error is incorrect calculation of existing items due to miscalculation of awst_queueditemlist table.
Consider above case. After we queue 1 Woolen Cape, AWST recalculates the numbers. It correctly determines we can create 1 Woolen Cape, or 2 Woolen Capes. It proceeds to examine whether we can create 3 Woolen Capes. 3 Woolen Capes require 3 Bolts of Woolen Clothes. Normally AWST should proceed to examine whether we can create 3 Bolt of Woolen Clothes. However it thinks that we have -1 Bolts of Woolen Clothes, so it proceeds to examine whether we can create 4 Bolts of Woolen Clothes, which fails.
This negative -1 number is produced since awst_queueditemlist table tells that we need 1 Bolt of Woolen Cloth queued as reagent. This table (theoretically) contains the number of reagents required for the items in the queue. The calculations are correct for simpler cases, such as leatherworking where leathers are used directly to produce items. However for tailoring and inscription intermediate items (bolts of clothes, inks) also exist in this queue, which is unintentional I believe. Correct behavior should add the reagents of queued items to this list, however also remove them when the reagents are also produced in the queue.
For the above case, 1 Woolen Cape in the queue adds 1 Bolt of Woolen Cloth to the table. However, 1 Bolt of Woolen Cloth to be produced in the queue should also be removed, thus we should have 0 Bolt of Woolen Cloth in awst_queueditemlist. (This is semantically correct too. Processing the queue does not change the number of Bolt of Woolen Clothes, since all to be produced will be consumed.)
Since awst_queueditemlist only serves a single purpose I took the liberty of modifying the code to correct the behavior. Only modification will be at method ATSWInv_UpdateQueuedItemList(). As far as I can tell, with the modification the numbers are calculated correctly and nothing else breaks down.
function ATSWInv_UpdateQueuedItemList()
atsw_queueditemlist={};
for i=1,table.getn(atsw_queue),1 do
-- Modification starts
if(atsw_queueditemlist[atsw_queue[i].name]) then
atsw_queueditemlist[atsw_queue[i].name]=atsw_queueditemlist[atsw_queue[i].name]-atsw_queue[i].count;
else
atsw_queueditemlist[atsw_queue[i].name]=-atsw_queue[i].count;
end
-- Modification ends
for j=1,table.getn(atsw_tradeskilllist),1 do
if(atsw_tradeskilllist[j].name==atsw_queue[i].name) then
for k=1,table.getn(atsw_tradeskilllist[j].reagents),1 do
if(atsw_tradeskilllist[j].reagents[k]) then
if(atsw_queueditemlist[atsw_tradeskilllist[j].reagents[k].name]) then
atsw_queueditemlist[atsw_tradeskilllist[j].reagents[k].name]=atsw_queueditemlist[atsw_tradeskilllist[j].reagents[k].name]+atsw_tradeskilllist[j].reagents[k].count*atsw_queue[i].count;
else
atsw_queueditemlist[atsw_tradeskilllist[j].reagents[k].name]=atsw_tradeskilllist[j].reagents[k].count*atsw_queue[i].count;
--table.setn(atsw_queueditemlist,table.getn(atsw_queueditemlist)+1);
end
end
end
end
end
end
end
| User | When | Change |
|---|---|---|
| utkuerd | Jan 15, 2012 at 01:13 UTC | Create |
- 1 comment
- 1 comment
Facts
- Reported
- Jan 15, 2012
- Status
- New - Issue has not had initial review yet.
- Type
- Patch - Source code patch for review
- Priority
- Medium - Normal priority.
- Votes
- 0
- Reply
- #1
utkuerd Feb 28, 2012 at 21:17 UTC - 0 likesStill exists in 0.9. Same modification part can be inserted at the same spot in the modified function.