Bug - Fixed "Meat Spent" in queue miscounted if more than one is enqueued at the same time

Winterbay

Active member
"Meat Spent" in queue miscounted if more than one is enqueued at the same time

Steps to reproduce:
1) Enqueue two of something that costs meat to create (NPC store ingredient for example)
2) Look at the "Meat Spent"

In my case I chose "bat wing kabob" and the result is "80 meat", which is the cost of 1 skewer. If you enqueue them 1 at a time the result is 160 meat as expected.

A small cosmetic bug, but that is somewhat important in fist-runs where you have not very much meat.
 

slyz

Developer
I tried understanding this problem, but I couldn't find a solution. I think it all happens it Concoction.queue(), but I don't understand everything that happens in that function.

Specifically, on line 536:
PHP:
ConcoctionDatabase.queuedMeatSpent += this.price;
this.price should be multiplied by something (the amount you are going to buy), but I really don't know how to express it.
 

slyz

Developer
Just for context:
PHP:
int decrementAmount = Math.min( this.initial, amount );
int overAmount = Math.min( this.creatable, amount - decrementAmount );
int pullAmount = amount - decrementAmount - overAmount;
When this.creatable = 0, overAmount is 0 too.

I added a little bit of logging to see what this.initial and this.creatable are.

When I queue the first bat wing kabob, this is what I get:
Code:
Qeueing 1 bat wing kabob
this.initial = 0
this.creatable = 2
this.price = 0
decrementAmount = 0
overAmount = 1
pullAmount = 0

Qeueing 1 bat wing
this.initial = 2
this.creatable = 0
this.price = 0
decrementAmount = 1
overAmount = 0
pullAmount = 0

Qeueing 1 skewer
this.initial = 0
this.creatable = 0
this.price = 80
decrementAmount = 0
overAmount = 0
pullAmount = 1
I concluded that this.initial is the amount in inventory, this.creatable is the creatable amount, and apparently buying doesn't count as "creating".

So decrementAmount is the amount that will be removed from inventory, overAmount is the amount that will be created, and pullAmount is the amount that must be obtained in another way. In that case, the amount to buy should be (amount - decrementAmount - overAmount).

But when I queue the second kabob:
Code:
Qeueing 1 bat wing kabob
this.initial = 0
this.creatable = 1
this.price = 0
decrementAmount = 0
overAmount = 1
pullAmount = 0

Qeueing 1 bat wing
this.initial = 1
this.creatable = 0
this.price = 0
decrementAmount = 1
overAmount = 0
pullAmount = 0

Qeueing 1 skewer
this.initial = 0
this.creatable = -1
this.price = 80
decrementAmount = 0
overAmount = -1
pullAmount = 2
for the skewer, this.creatable is -1 which rules out multiplying by (amount - decrementAmount - overAmount).
 

Veracity

Developer
Staff member
for the skewer, this.creatable is -1.
Doesn't that seem wrong?

I don't see how it can get negative. That might be interesting for you to find out. But, looking at ConcoctionDatabase.refreshConcoctions, I see:

Code:
			int creatable = Math.max( item.creatable, 0 );
which seems intended to defensively guard against that situation. Perhaps you need:

Code:
int decrementAmount = Math.min( this.initial, amount ); 
int creatableAmount = Math.max( this.creatable, 0 );
int overAmount = Math.min( creatableAmount, amount - decrementAmount ); 
int pullAmount = amount - decrementAmount - overAmount;
 

slyz

Developer
Perhaps you need:

Code:
int decrementAmount = Math.min( this.initial, amount ); 
int creatableAmount = Math.max( this.creatable, 0 );
int overAmount = Math.min( creatableAmount, amount - decrementAmount ); 
int pullAmount = amount - decrementAmount - overAmount;
My limited testing shows that this seems to work. I haven't been able to consume, though, but I doubt it would change anything.

I'll commit and see what happens (Hola seems like a good role model).
 
Top