]> git.pond.sub.org Git - empserver/commitdiff
buy: Don't continue when lot changes while asking for bid
authorMarkus Armbruster <armbru@pond.sub.org>
Tue, 12 Jan 2021 20:42:42 +0000 (21:42 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Sat, 23 Jan 2021 07:39:14 +0000 (08:39 +0100)
When the lot being bid for changes while the player is at the "How
much" prompt, we report "Commodity #%d has changed!", and continue
with the changed lot.

If continuing is okay, we should keep quiet.  We did that until commit
40b11c098 "Fix buy not to wipe out concurrent updates", v4.3.27.  Okay
when only the lot's price changed.

However, the lot could have gone away, or even be reused for something
else.  Failing the command seems safest for the player, so do that.
It's how we use the check_FOO_ok() elsewhere.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
src/lib/commands/buy.c

index 3b24033e2ca91c1bf0569ca850ebf3743b9a4edd..3d7b079bf1e12291dd050a41f389db0b702c6a04 100644 (file)
@@ -30,7 +30,7 @@
  *     Dave Pare, 1986
  *     Pat Loney, 1992
  *     Steve McClure, 1996-2000
- *     Markus Armbruster, 2004-2018
+ *     Markus Armbruster, 2004-2021
  */
 
 #include <config.h>
@@ -101,6 +101,8 @@ buy(void)
     bid = atof(p);
     if (bid <= 0)
        return RET_FAIL;
+    if (!check_comm_ok(&comm))
+       return RET_FAIL;
     if (natp->nat_money < bid * comm.com_amount * buytax) {
        pr("This purchase would cost %.2f, %.2f more than you have.\n",
           bid * comm.com_amount * buytax,
@@ -126,7 +128,6 @@ buy(void)
        }
     }
     canspend = natp->nat_money - tally;
-    check_comm_ok(&comm);
     if (bid * comm.com_amount * buytax > canspend) {
        pr("You have overextended yourself in the market\n");
        pr("You can not bid on the current items at that price.\n");