/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2000, 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/>.
*
* ---
*
- * See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
- * related information and legal notices. It is expected that any future
- * projects/authors will amend these files as needed.
+ * See files README, COPYING and CREDITS in the root of the source
+ * tree for related information and legal notices. It is expected
+ * that future projects/authors will amend these files as needed.
*
* ---
*
* cede.c: Give a sector to a neighbor
- *
+ *
* Known contributors to this file:
* Dave Pare
* Thomas Ruschak
*/
-#include "misc.h"
-#include "player.h"
-#include "var.h"
-#include "xy.h"
-#include "sect.h"
-#include "nsc.h"
-#include "nat.h"
+#include <config.h>
+
+#include "commands.h"
+#include "land.h"
+#include "lost.h"
+#include "nuke.h"
#include "path.h"
-#include "file.h"
#include "plane.h"
-#include "land.h"
#include "ship.h"
-#include "nuke.h"
-#include "item.h"
-#include "commands.h"
+static int has_units_with_mob(coord, coord, natid);
static void cede_hdr(void);
static int cede_sect(struct nstr_sect *, natid);
static int cede_ship(struct nstr_item *, natid);
-static void grab_sect(register struct sctstr *, natid);
-static void grab_ship(register struct shpstr *, natid);
+static void grab_sect(struct sctstr *, natid);
+static void grab_ship(struct shpstr *, natid);
int
cede(void)
{
+ static int sct_or_shp[] = { EF_SECTOR, EF_SHIP, EF_BAD };
natid to;
int n;
int is_sector = 0, is_ship = 0;
- s_char *p;
+ char *p;
struct nstr_sect ns;
struct nstr_item ni;
struct natstr *natp;
- s_char buf[1024];
+ char buf[1024];
- if ((p = getstarg(player->argp[1], "Cede what? ", buf)) == 0)
+ p = getstarg(player->argp[1], "Cede what? ", buf);
+ if (!p || !*p)
return RET_SYN;
if (snxtsct(&ns, p))
is_sector = 1;
- if (snxtitem(&ni, EF_SHIP, p))
+ if (snxtitem(&ni, EF_SHIP, p, NULL))
is_ship = 1;
if (!is_sector && !is_ship)
return RET_SYN;
if (is_sector && is_ship) {
int type;
- if ((p =
- getstarg(player->argp[3], "Cede sectors or ships (se, sh)? ",
- buf)) == 0)
+ p = getstarg(player->argp[3], "Cede sectors or ships (se, sh)? ",
+ buf);
+ if (!p)
return RET_FAIL;
if (strlen(p) > 4)
p[2] = 0;
- type = ef_byname(p);
-
- if (type == EF_SECTOR)
- is_ship = 0;
- else if (type == EF_SHIP)
- is_sector = 0;
- else {
+ type = ef_byname_from(p, sct_or_shp);
+ if (type < 0) {
pr("Please type 'se' or 'sh'!\n");
return RET_FAIL;
}
return RET_FAIL;
}
natp = getnatp(n);
- if (natp->nat_stat & STAT_GOD) {
+ if (natp->nat_stat != STAT_ACTIVE) {
pr("You can only give to normal countries...\n");
return RET_FAIL;
}
- if (getrel(natp, player->cnum) < FRIENDLY) {
+ if (relations_with(n, player->cnum) < FRIENDLY) {
pr("You can only cede to a country that is friendly towards you...\n");
return RET_FAIL;
}
struct sctstr sect, osect;
int nsect;
int n, bad;
- s_char dirstr[20];
int off_x, off_y;
struct nstr_item ni;
struct shpstr ship;
prdate();
- for (n = 1; n <= 6; n++)
- dirstr[n] = dirch[n];
- dirstr[0] = '.';
- dirstr[7] = '$';
- dirstr[8] = '\0';
nsect = 0;
while (nxtsct(ns, §)) {
if (!player->owner)
bad = 0;
}
snxtitem_all(&ni, EF_SHIP);
- while (nxtitem(&ni, (s_char *)&ship)) {
+ while (nxtitem(&ni, &ship)) {
if ((ship.shp_own == to) &&
((ship.shp_x == sect.sct_x) && (ship.shp_y == sect.sct_y)))
bad = 0;
}
if (bad) {
- pr("%s has no sector with mobility adjacent to or ship in %s!\n", cname(to), xyas(sect.sct_x, sect.sct_y, player->cnum));
+ pr("%s has no sector with mobility adjacent to or ship in %s!\n",
+ cname(to), xyas(sect.sct_x, sect.sct_y, player->cnum));
continue;
}
putsect(§);
pr(" %s %d%% ceded\n", xyas(sect.sct_x, sect.sct_y, player->cnum),
(int)sect.sct_effic);
- wu(0, (natid)to, "%s ceded to you by %s\n",
+ wu(0, to, "%s ceded to you by %s\n",
xyas(sect.sct_x, sect.sct_y, to), cname(player->cnum));
}
pr("%d sector%s\n", nsect, splur(nsect));
return RET_OK;
}
+static int
+has_units_with_mob(coord x, coord y, natid cn)
+{
+ struct nstr_item ni;
+ struct lndstr land;
+
+ snxtitem_xy(&ni, EF_LAND, x, y);
+ while (nxtitem(&ni, &land)) {
+ if (land.lnd_own != cn)
+ continue;
+ if (land.lnd_mobil > 0)
+ return 1;
+ }
+
+ return 0;
+}
+
static void
cede_hdr(void)
{
static void
-grab_sect(register struct sctstr *sp, natid to)
+grab_sect(struct sctstr *sp, natid to)
{
struct plnstr *pp;
struct lndstr *lp;
wu(0, to, "\t%s ceded to you by %s\n",
prplane(pp), cname(player->cnum));
- makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
pp->pln_own = to;
- makenotlost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x,
- pp->pln_y);
pp->pln_mobil = 0;
pp->pln_mission = 0;
putplane(pp->pln_uid, pp);
if (np->nuk_own == 0)
continue;
- wu(0, to, "\tnuclear stockpile #%d ceded to you by %s\n",
- np->nuk_uid, cname(player->cnum));
- makelost(EF_NUKE, np->nuk_own, np->nuk_uid, np->nuk_x, np->nuk_y);
+ wu(0, to, "\t%s ceded to you by %s\n",
+ prnuke(np), cname(player->cnum));
np->nuk_own = to;
- makenotlost(EF_NUKE, np->nuk_own, np->nuk_uid, np->nuk_x,
- np->nuk_y);
putnuke(ni.cur, np);
}
if (lp->lnd_own != player->cnum)
continue;
- wu(0, to, "\t%s ceded to you by %s\n", prland(lp),
- cname(player->cnum));
- makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
- makenotlost(EF_LAND, to, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
+ wu(0, to, "\t%s ceded to you by %s\n",
+ prland(lp), cname(player->cnum));
lp->lnd_own = to;
lp->lnd_mobil = 0;
lp->lnd_mission = 0;
sp->sct_dist_x = sp->sct_x;
sp->sct_dist_y = sp->sct_y;
- makelost(EF_SECTOR, sp->sct_own, 0, sp->sct_x, sp->sct_y);
- makenotlost(EF_SECTOR, to, 0, sp->sct_x, sp->sct_y);
if (sp->sct_oldown == sp->sct_own)
sp->sct_oldown = to;
sp->sct_own = to;
int nships = 0;
int bad = 0;
- while (nxtitem(ni, (s_char *)&ship)) {
+ while (nxtitem(ni, &ship)) {
if (!player->owner || ship.shp_own == 0)
continue;
bad = 1;
snxtitem_xy(&tni, EF_SHIP, ship.shp_x, ship.shp_y);
- while (nxtitem(&tni, (s_char *)&tship) && bad)
+ while (nxtitem(&tni, &tship) && bad)
if (tship.shp_own == to)
bad = 0;
}
static void
-grab_ship(register struct shpstr *sp, natid to)
+grab_ship(struct shpstr *sp, natid to)
{
- register struct plnstr *pp;
- register struct lndstr *lp;
+ struct plnstr *pp;
+ struct lndstr *lp;
struct nstr_item ni;
struct plnstr p;
struct lndstr l;
wu(0, to, "\t%s ceded to you by %s\n",
prplane(pp), cname(player->cnum));
- makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
pp->pln_own = to;
- makenotlost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x,
- pp->pln_y);
pp->pln_mobil = 0;
pp->pln_mission = 0;
putplane(pp->pln_uid, pp);
wu(0, to, "\t%s ceded to you by %s\n",
prland(lp), cname(player->cnum));
- makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
- makenotlost(EF_LAND, to, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
lp->lnd_own = to;
lp->lnd_mobil = 0;
lp->lnd_mission = 0;
putland(ni.cur, lp);
}
- makelost(EF_SHIP, sp->shp_own, sp->shp_uid, sp->shp_x, sp->shp_y);
sp->shp_own = to;
- makenotlost(EF_SHIP, sp->shp_own, sp->shp_uid, sp->shp_x, sp->shp_y);
}