Angband.oook.cz
Angband.oook.cz
AboutVariantsLadderForumCompetitionComicScreenshotsFunniesLinks

Go Back   Angband Forums > Angband > Vanilla

Reply
 
Thread Tools Display Modes
Old January 30, 2008, 00:15   #1
Dragonboneman
Adept
 
Join Date: Aug 2007
Posts: 182
Dragonboneman is on a distinguished road
V3.0.9 Negative gold?

http://angband.oook.cz/ladder-show.php?id=7454

Just spent all my gold on a staff of Teleportation, or so I thought, but it turns out I spent more than all of it. That's never happened to me before. Any ideas why this happened?
Dragonboneman is offline   Reply With Quote
Old January 30, 2008, 02:09   #2
takkaria
Veteran
 
takkaria's Avatar
 
Join Date: Apr 2007
Posts: 1,936
Donated: $40
takkaria is on a distinguished road
Quote:
Originally Posted by Dragonboneman View Post
http://angband.oook.cz/ladder-show.php?id=7454

Just spent all my gold on a staff of Teleportation, or so I thought, but it turns out I spent more than all of it. That's never happened to me before. Any ideas why this happened?
Hmm. I'm going to put my head on the line and say perhaps it was a bug. Other than that, don't think I've seen it myself.
takkaria is offline   Reply With Quote
Old January 30, 2008, 09:53   #3
Dragonboneman
Adept
 
Join Date: Aug 2007
Posts: 182
Dragonboneman is on a distinguished road
I'm no programmer but I'd come to a similar conclusion.
Guess I can consider it reported. Once I picked up some more gold everything returned to normal.
Dragonboneman is offline   Reply With Quote
Old January 30, 2008, 19:57   #4
EricDerKonig
Rookie
 
Join Date: Jan 2008
Posts: 9
EricDerKonig is on a distinguished road
Better be on your guard now.

A Bill Collector suddenly appears!
The Creditor summons Repo Men!
The Repo Man hits you!
Your possessions were stolen!
The Repo Man hits you!
Your house was repossessed!
The Bill Collector hits you!
Your Credit Rating {average} was destroyed!
EricDerKonig is offline   Reply With Quote
Old February 2, 2008, 01:21   #5
Zero
Apprentice
 
Join Date: Jan 2008
Posts: 83
Zero is on a distinguished road
This happened to me also. I believe it is because the price listed in the store display is an average for the stack. When you buy a staff, the number of charges you get is ceiling(stack_charges / stack_size), and the price you pay is not the price of an average staff, but the price for the specific staff you are buying. If the number of charges divided by the number of items in the stack does not equal an integer, then you'll pay more than the listed average.

... I think, anyway.

Or maybe the shopkeeper just decided to cut you a break and accept an I.O.U.
Zero is offline   Reply With Quote
Old February 2, 2008, 12:22   #6
Dragonboneman
Adept
 
Join Date: Aug 2007
Posts: 182
Dragonboneman is on a distinguished road
Takkaria - Would you mind if I update that dump at some point?
Eric -
Zero - that makes sense to me, just about.
Dragonboneman is offline   Reply With Quote
Old February 2, 2008, 12:32   #7
takkaria
Veteran
 
takkaria's Avatar
 
Join Date: Apr 2007
Posts: 1,936
Donated: $40
takkaria is on a distinguished road
Quote:
Originally Posted by Dragonboneman View Post
Takkaria - Would you mind if I update that dump at some point?
Oh, sure. I believed you anyway, though.
takkaria is offline   Reply With Quote
Old February 2, 2008, 15:10   #8
roustk
Adept
 
Join Date: Dec 2007
Posts: 167
roustk is on a distinguished road
Quote:
Originally Posted by Zero View Post
This happened to me also. I believe it is because the price listed in the store display is an average for the stack. When you buy a staff, the number of charges you get is ceiling(stack_charges / stack_size), and the price you pay is not the price of an average staff, but the price for the specific staff you are buying. If the number of charges divided by the number of items in the stack does not equal an integer, then you'll pay more than the listed average.
That is *exactly* it. From 3.0.9 store.c, around line 1830, you select the item you want to purchase:
Code:
                /* Price of one */
                price = price_item(o_ptr, FALSE);

                /* Check if the player can afford any at all */
                if ((u32b)p_ptr->au < (u32b)price)
                {
                        /* Tell the user */
                        msg_print("You do not have enough gold for this item.");
                        store_flags |= STORE_KEEP_PROMPT;

                        /* Abort now */
                        return FALSE;
                }
Then you select the quantity and, at line 1865, charges are allocated to the wand/staff you are actually buying:
Code:
        /*
         * XXX Stacking
         * If a rod or wand, allocate total maximum timeouts or charges
         * between those purchased and left on the shelf.
         */
        reduce_charges(i_ptr, i_ptr->number - amt);
(reduce_charges() is in object2.c and uses integer division to calculate the number of charges to take away, so you always buy above-average charges and below-average charges are destroyed in combat.)

Finally, at about line 1888, the price is re-calculated and deducted, without a sanity check.
Code:
                /* Extract the price for the entire stack */
                price = price_item(i_ptr, FALSE) * i_ptr->number;
...
                /* Spend the money */
                p_ptr->au -= price;
Now that we know what is going wrong, we can debate the correct way to correct it. Because this is a special case, and the error is small, I'd recommend letting the purchase happen while simply forcing p_ptr->au to be non-negative for appearances. That is, after "p_ptr->au -= price;" add something like "if (p_ptr->au < 0) p_ptr->au = 0L;"

If we add another sanity check at this point, we would have to either (1) tell the player that we lied about the quantity he could afford or (2) we would have to (silently?) sell below-average items so that he could afford them.

I don't know what has happened to store.c since 3.0.9, but takkaria can find this code by looking for the store_purchase() function.

Kevin
roustk is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
FuryBand 5.0/Gold Released!!! The GP Fury Variants 7 July 27, 2008 21:37
FuryBand Gold Beta Release The GP Fury Variants 15 November 26, 2007 23:31


All times are GMT +1. The time now is 02:11.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.