]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/buy.c
Update copyright notice
[empserver] / src / lib / commands / buy.c
index aeed57fa1c45ba3140e39604180fbe48f8135110..3b24033e2ca91c1bf0569ca850ebf3743b9a4edd 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2012, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2021, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                Ken Stevens, Steve McClure, Markus Armbruster
  *
  *  Empire is free software: you can redistribute it and/or modify
  *     Dave Pare, 1986
  *     Pat Loney, 1992
  *     Steve McClure, 1996-2000
+ *     Markus Armbruster, 2004-2018
  */
 
 #include <config.h>
 
+#include "chance.h"
 #include "commands.h"
 #include "commodity.h"
 #include "item.h"
@@ -110,8 +112,10 @@ buy(void)
     this part up.*/
     tally = 0.0;
     for (n = 0; gettrade(n, &tmpt); n++) {
+       if (!tmpt.trd_owner)
+           continue;
        if (tmpt.trd_maxbidder == player->cnum &&
-           tmpt.trd_unitid >= 0 && tmpt.trd_owner != player->cnum) {
+           tmpt.trd_owner != player->cnum) {
            tally += tmpt.trd_price * tradetax;
        }
     }
@@ -160,16 +164,10 @@ buy(void)
        return RET_FAIL;
     if (bid > 0.04 + comm.com_price) {
        comm.com_price = bid;
-       /* Add five minutes to the time if less than 5 minutes */
        time(&now);
-       if (((MARK_DELAY - (now - comm.com_markettime)) < 300) &&
-           comm.com_maxbidder != player->cnum) {
-           comm.com_markettime += 300;
-           /* Special case - what if so much time has gone by?  Well,
-              Just reset the markettime  so that only 5 minutes are left */
-           if ((MARK_DELAY - (now - comm.com_markettime)) < 0)
-               comm.com_markettime = (now - (MARK_DELAY - 300));
-       }
+       if (comm.com_markettime + MARK_DELAY - now < minutes(5) &&
+           comm.com_maxbidder != player->cnum)
+           comm.com_markettime = now + minutes(5) - MARK_DELAY;
        comm.com_maxbidder = player->cnum;
        comm.com_x = x;
        comm.com_y = y;
@@ -195,7 +193,6 @@ check_market(void)
     int m;
     int n;
     time_t now;
-    double tleft;
     double gain;
     double price;
 
@@ -203,10 +200,7 @@ check_market(void)
        if (comm.com_maxbidder == comm.com_owner || comm.com_owner == 0)
            continue;
        (void)time(&now);
-       tleft = MARK_DELAY / 3600.0 - (now - comm.com_markettime) / 3600.0;
-       if (tleft < 0)
-           tleft = 0;
-       if (tleft > 0.0)
+       if (comm.com_markettime + MARK_DELAY > now)
            continue;
        if (CANT_HAPPEN(comm.com_type <= I_NONE || comm.com_type > I_MAX))
            continue;