/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure
*
* This program is free software; you can redistribute it and/or modify
#include "plane.h"
#include "ship.h"
#include "trade.h"
+#include "unit.h"
/*
* format: trade
struct trdstr trade;
struct trdstr tmpt;
union empobj_storage tg;
- int plflags;
double canspend;
time_t now;
int bid;
if (!trade_getitem(&trade, &tg)) {
continue;
};
- /* fix up database if things get weird */
- /*if (trade.trd_owner != tg.gen.own) {
- trade.trd_unitid = -1;
- (void) puttrade(ni.cur, &trade);
- continue;
- } */
pr(" %3d ", ni.cur);
(void)time(&now);
tleft =
}
if (!trade_getitem(&trade, &tg)) {
pr("Can't find trade #%d!\n", trade.trd_unitid);
+ trade.trd_owner = 0;
trade.trd_unitid = -1;
if (!puttrade(lotno, &trade)) {
+ logerror("trad: can't write trade");
pr("Couldn't save after getitem failed; get help!\n");
- return RET_SYS;
+ return RET_FAIL;
}
return RET_OK;
}
}
canspend = natp->nat_money - tally;
/*
- * Find the destination sector for the plane before the trade
- * is actually made. Must be owned (except for satellites) and
- * must be a 60% airfield (except for VTOL planes).
+ * Find the destination sector for the plane before the trade is
+ * actually made, except for satellites in orbit. Must be owned
+ * and must be a 60% airfield (except for VTOL planes).
*/
- if (((trade.trd_type == EF_PLANE) || (trade.trd_type == EF_NUKE))
- && ((trade.trd_type == EF_NUKE) ||
- !(tg.plane.pln_flags & PLN_LAUNCHED))) {
- plflags = plchr[(int)tg.plane.pln_type].pl_flags;
+ if (((trade.trd_type == EF_PLANE) && !pln_is_in_orbit(&tg.plane))
+ || (trade.trd_type == EF_NUKE)) {
while (1) {
p = getstring("Destination sector: ", buf);
if (!trade_check_ok(&trade, &tg))
pr("Bad sector designation; try again!\n");
continue;
}
- if (!player->owner && !(plflags & P_O)) {
+ if (!player->owner) {
pr("You don't own that sector; try again!\n");
continue;
}
- if (!(plflags & (P_V | P_O))) {
+ if (!(plchr[tg.plane.pln_type].pl_flags & P_V)) {
if (!player->god && (sect.sct_type != SCT_AIRPT)) {
pr("Destination sector is not an airfield!\n");
continue;
check_trade(void)
{
int n;
- struct nstr_item ni;
- struct plnstr plane;
- struct lndstr land;
struct natstr *natp;
struct trdstr trade;
union empobj_storage tg;
if (!trade_getitem(&trade, &tg))
continue;
if (tg.gen.own == 0) {
+ trade.trd_owner = 0;
trade.trd_unitid = -1;
puttrade(n, &trade);
continue;
}
if (tg.gen.own != trade.trd_owner) {
logerror("Something weird, tg.gen.own != trade.trd_owner!\n");
+ trade.trd_owner = 0;
trade.trd_unitid = -1;
puttrade(n, &trade);
continue;
continue;
saveid = trade.trd_unitid;
+ trade.trd_owner = 0;
trade.trd_unitid = -1;
if (!puttrade(n, &trade)) {
logerror("Couldn't save trade after purchase; get help!\n");
case EF_NUKE:
tg.nuke.nuk_x = trade.trd_x;
tg.nuke.nuk_y = trade.trd_y;
- makelost(EF_NUKE, tg.nuke.nuk_own, tg.nuke.nuk_uid,
- tg.nuke.nuk_x, tg.nuke.nuk_y);
- tg.nuke.nuk_own = trade.trd_maxbidder;
- makenotlost(EF_NUKE, tg.nuke.nuk_own, tg.nuke.nuk_uid,
- tg.nuke.nuk_x, tg.nuke.nuk_y);
+ tg.nuke.nuk_plane = -1;
break;
case EF_PLANE:
- if ((tg.plane.pln_flags & PLN_LAUNCHED) == 0) {
+ if (!pln_is_in_orbit(&tg.plane)) {
tg.plane.pln_x = trade.trd_x;
tg.plane.pln_y = trade.trd_y;
}
- makelost(EF_PLANE, tg.plane.pln_own, tg.plane.pln_uid,
- tg.plane.pln_x, tg.plane.pln_y);
- tg.plane.pln_own = trade.trd_maxbidder;
- makenotlost(EF_PLANE, tg.plane.pln_own, tg.plane.pln_uid,
- tg.plane.pln_x, tg.plane.pln_y);
- tg.plane.pln_wing = 0;
- /* no cheap version of fly */
if (opt_MOB_ACCESS) {
tg.plane.pln_mobil = -(etu_per_update / sect_mob_neg_factor);
game_tick_to_now(&tg.plane.pln_access);
} else {
tg.plane.pln_mobil = 0;
}
- tg.plane.pln_mission = 0;
tg.plane.pln_harden = 0;
tg.plane.pln_ship = -1;
tg.plane.pln_land = -1;
break;
case EF_SHIP:
- takeover_ship(&tg.ship, trade.trd_maxbidder, 0);
+ tg.ship.shp_rflags = 0;
+ memset(tg.ship.shp_rpath, 0, sizeof(tg.ship.shp_rpath));
break;
case EF_LAND:
tg.land.lnd_x = trade.trd_x;
tg.land.lnd_y = trade.trd_y;
- if (tg.land.lnd_ship >= 0) {
- struct shpstr ship;
- getship(tg.land.lnd_ship, &ship);
- ship.shp_nland--;
- putship(ship.shp_uid, &ship);
- }
- makelost(EF_LAND, tg.land.lnd_own, tg.land.lnd_uid,
- tg.land.lnd_x, tg.land.lnd_y);
- tg.land.lnd_own = trade.trd_maxbidder;
- makenotlost(EF_LAND, tg.land.lnd_own, tg.land.lnd_uid,
- tg.land.lnd_x, tg.land.lnd_y);
- tg.land.lnd_army = 0;
- /* no cheap version of fly */
if (opt_MOB_ACCESS) {
tg.land.lnd_mobil = -(etu_per_update / sect_mob_neg_factor);
game_tick_to_now(&tg.land.lnd_access);
tg.land.lnd_mobil = 0;
}
tg.land.lnd_harden = 0;
- tg.land.lnd_mission = 0;
- /* Drop any land units this unit was carrying */
- snxtitem_xy(&ni, EF_LAND, tg.land.lnd_x, tg.land.lnd_y);
- while (nxtitem(&ni, &land)) {
- if (land.lnd_land != tg.land.lnd_uid)
- continue;
- land.lnd_land = -1;
- wu(0, land.lnd_own, "unit #%d dropped in %s\n",
- land.lnd_uid,
- xyas(land.lnd_x, land.lnd_y, land.lnd_own));
- putland(land.lnd_uid, &land);
- }
- /* Drop any planes this unit was carrying */
- snxtitem_xy(&ni, EF_PLANE, tg.land.lnd_x, tg.land.lnd_y);
- while (nxtitem(&ni, &plane)) {
- if (plane.pln_flags & PLN_LAUNCHED)
- continue;
- if (plane.pln_land != land.lnd_uid)
- continue;
- plane.pln_land = -1;
- wu(0, plane.pln_own, "plane #%d dropped in %s\n",
- plane.pln_uid,
- xyas(plane.pln_x, plane.pln_y, plane.pln_own));
- putplane(plane.pln_uid, &plane);
- }
+ unit_drop_cargo(&tg.gen, 0);
tg.land.lnd_ship = -1;
tg.land.lnd_land = -1;
break;
logerror("Bad trade type %d in trade\n", trade.trd_type);
break;
}
- if (!ef_write(trade.trd_type, saveid, &tg)) {
- logerror("Couldn't write unit to disk; seek help.\n");
- continue;
- }
+ unit_give_away(&tg.gen, trade.trd_maxbidder, 0);
+ put_empobj(trade.trd_type, saveid, &tg.gen);
+
nreport(trade.trd_owner, N_MAKE_SALE, trade.trd_maxbidder, 1);
wu(0, trade.trd_owner, "%s bought a %s #%d from you for $%.2f\n",
cname(trade.trd_maxbidder), trade_nameof(&trade, &tg),