/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
- * Ken Stevens, Steve McClure
+ * Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Ken Stevens, Steve McClure, Markus Armbruster
*
- * This program is free software; you can redistribute it and/or modify
+ * Empire is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ---
*
* ---
*
* tend.c: Transfer goodies from one ship to another.
- *
+ *
* Known contributors to this file:
* Dave Pare, 1986
* Thomas Ruschak, 1992
* Steve McClure, 2000
+ * Markus Armbruster, 2004-2009
*/
#include <config.h>
-#include <string.h>
-#include "misc.h"
-#include "player.h"
-#include "plague.h"
-#include "xy.h"
-#include "file.h"
-#include "ship.h"
+#include "commands.h"
#include "item.h"
-#include "nsc.h"
-#include "nat.h"
#include "land.h"
+#include "plague.h"
#include "plane.h"
-#include "genitem.h"
-#include "commands.h"
+#include "ship.h"
static void expose_ship(struct shpstr *s1, struct shpstr *s2);
-static int tend_land(struct shpstr *tenderp, s_char *units);
+static int tend_land(struct shpstr *tenderp, char *units);
int
tend(void)
int transfer;
int total;
int type;
- s_char *p;
- s_char prompt[512];
- s_char buf[1024];
+ char *p;
+ char prompt[512];
+ char buf[1024];
- if (!(p = getstarg(player->argp[1],
- "Tend what commodity (or 'land')? ", buf)) || !*p)
+ p = getstarg(player->argp[1], "Tend what commodity (or 'land')? ",
+ buf);
+ if (!p || !*p)
return RET_SYN;
if (!strncmp(p, "land", 4))
return RET_SYN;
}
- if (!snxtitem(&tenders, EF_SHIP,
- getstarg(player->argp[2], "Tender(s)? ", buf)))
+ if (!snxtitem(&tenders, EF_SHIP, player->argp[2], "Tender(s)? "))
return RET_SYN;
while (nxtitem(&tenders, &tender)) {
if (type == EF_LAND) {
sprintf(prompt, "Land unit(s) to tend from %s? ",
prship(&tender));
- if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p)
+ p = getstarg(player->argp[3], prompt, buf);
+ if (!p)
+ return RET_FAIL;
+ if (!*p)
continue;
if (!check_ship_ok(&tender))
return RET_SYN;
}
sprintf(prompt, "Number of %s to tend from %s? ",
ip->i_name, prship(&tender));
- if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p)
+ p = getstarg(player->argp[3], prompt, buf);
+ if (!p)
+ return RET_FAIL;
+ if (!*p)
continue;
if (!check_ship_ok(&tender))
return RET_SYN;
break;
}
if (!snxtitem(&targets, EF_SHIP,
- getstarg(player->argp[4], "Ships to be tended? ",
- buf)))
- break;
+ player->argp[4], "Ships to be tended? "))
+ return RET_FAIL;
if (!check_ship_ok(&tender))
return RET_SYN;
total = 0;
while (nxtitem(&targets, &target)) {
- if (!player->owner &&
- (getrel(getnatp(target.shp_own), player->cnum) < FRIENDLY))
+ if (!player->owner
+ && relations_with(target.shp_own, player->cnum) < FRIENDLY)
continue;
if (target.shp_uid == tender.shp_uid)
continue;
}
static int
-tend_land(struct shpstr *tenderp, s_char *units)
+tend_land(struct shpstr *tenderp, char *units)
{
struct nstr_item lni;
struct nstr_item targets;
struct shpstr target;
struct lndstr land;
- struct plnstr plane;
- struct nstr_item pni;
- s_char buf[1024];
+ char buf[1024];
- if (!snxtitem(&lni, EF_LAND, units))
+ if (!snxtitem(&lni, EF_LAND, units, NULL))
return RET_SYN;
while (nxtitem(&lni, &land)) {
continue;
}
if (!(lchr[(int)land.lnd_type].l_flags & L_ASSAULT)) {
- pr("%s does not have \"assault\" capability and can't be tended\n", prland(&land));
+ pr("%s does not have \"assault\" capability and can't be tended\n",
+ prland(&land));
continue;
}
if (!snxtitem(&targets, EF_SHIP,
- getstarg(player->argp[4], "Ship to be tended? ",
- buf)))
- break;
- if (!check_land_ok(&land))
+ player->argp[4], "Ship to be tended? "))
+ return RET_FAIL;
+ if (!check_ship_ok(tenderp) || !check_land_ok(&land))
return RET_SYN;
while (nxtitem(&targets, &target)) {
- if (!player->owner &&
- (getrel(getnatp(target.shp_own), player->cnum) < FRIENDLY))
+ if (!player->owner
+ && relations_with(target.shp_own, player->cnum) < FRIENDLY)
continue;
if (target.shp_uid == tenderp->shp_uid)
continue;
continue;
/* Fit unit on ship */
- count_units(&target);
getship(target.shp_uid, &target);
+ if ((!(lchr[(int)land.lnd_type].l_flags & L_LIGHT)) &&
+ (!((mchr[(int)target.shp_type].m_flags & M_SUPPLY) &&
+ (!(mchr[(int)target.shp_type].m_flags & M_SUB))))) {
+ pr("You can only load light units onto ships,\n"
+ "unless the ship is a non-sub supply ship\n"
+ "%s not tended\n", prland(&land));
+ continue;
+ }
+
if ((mchr[(int)target.shp_type].m_flags & M_SUB) &&
(lchr[(int)land.lnd_type].l_flags & L_SPY) &&
!mchr[(int)target.shp_type].m_nland) {
- if (target.shp_nland > 1) {
+ if (shp_nland(&target) > 1) {
pr("%s doesn't have room for more than two spy units!\n",
prship(&target));
continue;
}
- } else if (target.shp_nland >= mchr[(int)target.shp_type].m_nland) {
+ } else if (shp_nland(&target) >= mchr[target.shp_type].m_nland) {
if (mchr[(int)target.shp_type].m_nland)
pr("%s doesn't have room for any more land units!\n",
prship(&target));
sprintf(buf, "loaded on your %s at %s",
prship(&target), xyas(target.shp_x, target.shp_y,
target.shp_own));
- gift(target.shp_own, player->cnum, &land, EF_LAND, buf);
- makelost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x,
- land.lnd_y);
- land.lnd_own = target.shp_own;
- makenotlost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x,
- land.lnd_y);
+ gift(target.shp_own, player->cnum, &land, buf);
land.lnd_ship = target.shp_uid;
land.lnd_harden = 0;
- land.lnd_mission = 0;
- target.shp_nland++;
putland(land.lnd_uid, &land);
expose_ship(tenderp, &target);
putship(target.shp_uid, &target);
- count_units(tenderp);
putship(tenderp->shp_uid, tenderp);
- snxtitem_xy(&pni, EF_PLANE, land.lnd_x, land.lnd_y);
- while (nxtitem(&pni, &plane)) {
- if (plane.pln_flags & PLN_LAUNCHED)
- continue;
- if (plane.pln_land != land.lnd_uid)
- continue;
- sprintf(buf, "loaded on %s", prship(&target));
- gift(target.shp_own, player->cnum, &plane, EF_PLANE, buf);
- makelost(EF_PLANE, plane.pln_own, plane.pln_uid,
- plane.pln_x, plane.pln_y);
- plane.pln_own = target.shp_own;
- makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid,
- plane.pln_x, plane.pln_y);
- plane.pln_mission = 0;
- putplane(plane.pln_uid, &plane);
- }
}
}
return 0;