buy set trade: Fix taking lots off the market
To find out whether a lot is in use, some places check for zero
trd_owner, others for negative trd_unitid. The former is reliable,
the latter is not: set() fails to change trd_unitid when it takes a
lot off the market. The next trade-related command then runs
check_trade(), which logs "Something weird" and cleans up the mess.
Broken in commit e16e38dfab
(v4.2.18).
Replace the unreliable checks by reliable ones.
Clean up set() not to implictly rely on unused lots having negative
trd_unitid.
The trd_unitid = -1 are unnecessary now, so drop them.
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
parent
5f0ddfd950
commit
6bcd72e241
3 changed files with 13 additions and 18 deletions
|
@ -30,7 +30,7 @@
|
||||||
* Dave Pare, 1986
|
* Dave Pare, 1986
|
||||||
* Pat Loney, 1992
|
* Pat Loney, 1992
|
||||||
* Steve McClure, 1996-2000
|
* Steve McClure, 1996-2000
|
||||||
* Markus Armbruster, 2004-2013
|
* Markus Armbruster, 2004-2018
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
@ -112,8 +112,10 @@ buy(void)
|
||||||
this part up.*/
|
this part up.*/
|
||||||
tally = 0.0;
|
tally = 0.0;
|
||||||
for (n = 0; gettrade(n, &tmpt); n++) {
|
for (n = 0; gettrade(n, &tmpt); n++) {
|
||||||
|
if (!tmpt.trd_owner)
|
||||||
|
continue;
|
||||||
if (tmpt.trd_maxbidder == player->cnum &&
|
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;
|
tally += tmpt.trd_price * tradetax;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,6 +105,7 @@ set(void)
|
||||||
if (!trade.trd_owner) {
|
if (!trade.trd_owner) {
|
||||||
if (freeslot < 0)
|
if (freeslot < 0)
|
||||||
freeslot = ni_trade.cur;
|
freeslot = ni_trade.cur;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
if (trade.trd_unitid == ni.cur && trade.trd_type == type) {
|
if (trade.trd_unitid == ni.cur && trade.trd_type == type) {
|
||||||
foundslot = ni_trade.cur;
|
foundslot = ni_trade.cur;
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
* Dave Pare, 1986
|
* Dave Pare, 1986
|
||||||
* Pat Loney, 1992
|
* Pat Loney, 1992
|
||||||
* Steve McClure, 1996-2000
|
* Steve McClure, 1996-2000
|
||||||
* Markus Armbruster, 2004-2013
|
* Markus Armbruster, 2004-2018
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
@ -123,18 +123,13 @@ trad(void)
|
||||||
pr("Bad lot number\n");
|
pr("Bad lot number\n");
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
if (!gettrade(lotno, &trade)) {
|
if (!gettrade(lotno, &trade) || !trade.trd_owner) {
|
||||||
pr("No such lot number\n");
|
pr("No such lot number\n");
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
if (trade.trd_unitid < 0) {
|
|
||||||
pr("Invalid lot number.\n");
|
|
||||||
return RET_OK;
|
|
||||||
}
|
|
||||||
if (!trade_getitem(&trade, &tg)) {
|
if (!trade_getitem(&trade, &tg)) {
|
||||||
pr("Can't find trade #%d!\n", trade.trd_unitid);
|
pr("Can't find trade #%d!\n", trade.trd_unitid);
|
||||||
trade.trd_owner = 0;
|
trade.trd_owner = 0;
|
||||||
trade.trd_unitid = -1;
|
|
||||||
if (!puttrade(lotno, &trade)) {
|
if (!puttrade(lotno, &trade)) {
|
||||||
logerror("trad: can't write trade");
|
logerror("trad: can't write trade");
|
||||||
pr("Couldn't save after getitem failed; get help!\n");
|
pr("Couldn't save after getitem failed; get help!\n");
|
||||||
|
@ -164,8 +159,10 @@ trad(void)
|
||||||
}
|
}
|
||||||
tally = 0.0;
|
tally = 0.0;
|
||||||
for (i = 0; gettrade(i, &tmpt); i++) {
|
for (i = 0; gettrade(i, &tmpt); i++) {
|
||||||
|
if (!tmpt.trd_owner)
|
||||||
|
continue;
|
||||||
if (tmpt.trd_maxbidder == player->cnum &&
|
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;
|
tally += tmpt.trd_price * tradetax;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -282,20 +279,18 @@ check_trade(void)
|
||||||
natid seller;
|
natid seller;
|
||||||
|
|
||||||
for (n = 0; gettrade(n, &trade); n++) {
|
for (n = 0; gettrade(n, &trade); n++) {
|
||||||
if (trade.trd_unitid < 0)
|
if (!trade.trd_owner)
|
||||||
continue;
|
continue;
|
||||||
if (!trade_getitem(&trade, &tg))
|
if (!trade_getitem(&trade, &tg))
|
||||||
continue;
|
continue;
|
||||||
if (tg.gen.own == 0) {
|
if (tg.gen.own == 0) {
|
||||||
trade.trd_owner = 0;
|
trade.trd_owner = 0;
|
||||||
trade.trd_unitid = -1;
|
|
||||||
puttrade(n, &trade);
|
puttrade(n, &trade);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (tg.gen.own != trade.trd_owner) {
|
if (tg.gen.own != trade.trd_owner) {
|
||||||
logerror("Something weird, tg.gen.own != trade.trd_owner!\n");
|
logerror("Something weird, tg.gen.own != trade.trd_owner!\n");
|
||||||
trade.trd_owner = 0;
|
trade.trd_owner = 0;
|
||||||
trade.trd_unitid = -1;
|
|
||||||
puttrade(n, &trade);
|
puttrade(n, &trade);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -310,7 +305,6 @@ check_trade(void)
|
||||||
saveid = trade.trd_unitid;
|
saveid = trade.trd_unitid;
|
||||||
seller = trade.trd_owner;
|
seller = trade.trd_owner;
|
||||||
trade.trd_owner = 0;
|
trade.trd_owner = 0;
|
||||||
trade.trd_unitid = -1;
|
|
||||||
if (!puttrade(n, &trade)) {
|
if (!puttrade(n, &trade)) {
|
||||||
logerror("Couldn't save trade after purchase; get help!\n");
|
logerror("Couldn't save trade after purchase; get help!\n");
|
||||||
continue;
|
continue;
|
||||||
|
@ -408,7 +402,7 @@ ontradingblock(int type, void *ptr)
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
for (n = 0; gettrade(n, &trade); n++) {
|
for (n = 0; gettrade(n, &trade); n++) {
|
||||||
if (trade.trd_unitid < 0)
|
if (!trade.trd_owner)
|
||||||
continue;
|
continue;
|
||||||
if (!trade_getitem(&trade, &tg))
|
if (!trade_getitem(&trade, &tg))
|
||||||
continue;
|
continue;
|
||||||
|
@ -428,7 +422,7 @@ trdswitchown(int type, struct empobj *obj, int newown)
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
for (n = 0; gettrade(n, &trade); n++) {
|
for (n = 0; gettrade(n, &trade); n++) {
|
||||||
if (trade.trd_unitid < 0)
|
if (!trade.trd_owner)
|
||||||
continue;
|
continue;
|
||||||
if (!trade_getitem(&trade, &tg))
|
if (!trade_getitem(&trade, &tg))
|
||||||
continue;
|
continue;
|
||||||
|
@ -439,8 +433,6 @@ trdswitchown(int type, struct empobj *obj, int newown)
|
||||||
if (trade.trd_owner == trade.trd_maxbidder)
|
if (trade.trd_owner == trade.trd_maxbidder)
|
||||||
trade.trd_maxbidder = newown;
|
trade.trd_maxbidder = newown;
|
||||||
trade.trd_owner = newown;
|
trade.trd_owner = newown;
|
||||||
if (newown == 0)
|
|
||||||
trade.trd_unitid = -1;
|
|
||||||
puttrade(n, &trade);
|
puttrade(n, &trade);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue