2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * See files README, COPYING and CREDITS in the root of the source
23 * tree for related information and legal notices. It is expected
24 * that future projects/authors will amend these files as needed.
28 * cede.c: Give a sector to a neighbor
30 * Known contributors to this file:
45 static void cede_hdr(void);
46 static int cede_sect(struct nstr_sect *, natid);
47 static int cede_ship(struct nstr_item *, natid);
48 static void grab_sect(struct sctstr *, natid);
49 static void grab_ship(struct shpstr *, natid);
54 static int sct_or_shp[] = { EF_SECTOR, EF_SHIP, EF_BAD };
57 int is_sector = 0, is_ship = 0;
64 if ((p = getstarg(player->argp[1], "Cede what? ", buf)) == 0)
68 if (snxtitem(&ni, EF_SHIP, p))
70 if (!is_sector && !is_ship)
72 if ((n = natarg(player->argp[2], "to which country? ")) < 0)
74 if (is_sector && is_ship) {
78 getstarg(player->argp[3], "Cede sectors or ships (se, sh)? ",
83 type = ef_byname_from(p, sct_or_shp);
85 pr("Please type 'se' or 'sh'!\n");
91 if (n == player->cnum) {
92 pr("Giving something to yourself?\n");
96 if (natp->nat_stat != STAT_ACTIVE) {
97 pr("You can only give to normal countries...\n");
100 if (getrel(natp, player->cnum) < FRIENDLY) {
101 pr("You can only cede to a country that is friendly towards you...\n");
107 return cede_sect(&ns, to);
109 return cede_ship(&ni, to);
113 cede_sect(struct nstr_sect *ns, natid to)
115 struct sctstr sect, osect;
124 while (nxtsct(ns, §)) {
127 if (sect.sct_mobil == 0) {
128 pr("%s has no mobility and cannot be ceded\n",
129 xyas(sect.sct_x, sect.sct_y, player->cnum));
134 for (n = 1; n <= 6; n++) { /* Directions */
135 off_x = sect.sct_x + diroff[n][0];
136 off_y = sect.sct_y + diroff[n][1];
138 if (!getsect(off_x, off_y, &osect))
140 if ((osect.sct_own == to) && (osect.sct_mobil))
142 if ((osect.sct_own == to) &&
143 has_units_with_mob(osect.sct_x, osect.sct_y, to))
146 snxtitem_all(&ni, EF_SHIP);
147 while (nxtitem(&ni, &ship)) {
148 if ((ship.shp_own == to) &&
149 ((ship.shp_x == sect.sct_x) && (ship.shp_y == sect.sct_y)))
153 pr("%s has no sector with mobility adjacent to or ship in %s!\n",
154 cname(to), xyas(sect.sct_x, sect.sct_y, player->cnum));
161 grab_sect(§, to);
163 pr(" %s %d%% ceded\n", xyas(sect.sct_x, sect.sct_y, player->cnum),
164 (int)sect.sct_effic);
165 wu(0, (natid)to, "%s ceded to you by %s\n",
166 xyas(sect.sct_x, sect.sct_y, to), cname(player->cnum));
168 pr("%d sector%s\n", nsect, splur(nsect));
183 grab_sect(struct sctstr *sp, natid to)
193 /* Wipe all the distribution info */
194 memset(sp->sct_dist, 0, sizeof(sp->sct_dist));
195 memset(sp->sct_del, 0, sizeof(sp->sct_del));
196 sp->sct_dist_x = sp->sct_x;
197 sp->sct_dist_y = sp->sct_y;
200 snxtitem_xy(&ni, EF_PLANE, sp->sct_x, sp->sct_y);
201 while (nxtitem(&ni, pp)) {
202 if (pp->pln_own == 0)
204 if (pp->pln_ship >= 0)
206 if (pp->pln_own != player->cnum)
208 if (pp->pln_flags & PLN_LAUNCHED)
211 wu(0, to, "\t%s ceded to you by %s\n",
212 prplane(pp), cname(player->cnum));
213 makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
215 makenotlost(EF_PLANE, pp->pln_own, pp->pln_uid,
216 pp->pln_x, pp->pln_y);
219 putplane(pp->pln_uid, pp);
223 snxtitem_xy(&ni, EF_NUKE, sp->sct_x, sp->sct_y);
224 while (nxtitem(&ni, np)) {
225 if (np->nuk_own == 0)
228 wu(0, to, "\t%s ceded to you by %s\n",
229 prnuke(np), cname(player->cnum));
230 makelost(EF_NUKE, np->nuk_own, np->nuk_uid, np->nuk_x, np->nuk_y);
232 makenotlost(EF_NUKE, np->nuk_own, np->nuk_uid,
233 np->nuk_x, np->nuk_y);
238 snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y);
239 while (nxtitem(&ni, lp)) {
240 if (lp->lnd_own == 0)
242 if (lp->lnd_ship == 0)
244 if (lp->lnd_own != player->cnum)
247 wu(0, to, "\t%s ceded to you by %s\n",
248 prland(lp), cname(player->cnum));
249 makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
250 makenotlost(EF_LAND, to, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
259 if (sp->sct_oldown == to) {
260 sp->sct_che = 0; /* FIXME where do these guys go? */
261 sp->sct_che_target = 0;
265 if (sp->sct_oldown == to)
267 else /* people don't like being given away */
270 sp->sct_dist_x = sp->sct_x;
271 sp->sct_dist_y = sp->sct_y;
272 makelost(EF_SECTOR, sp->sct_own, 0, sp->sct_x, sp->sct_y);
273 makenotlost(EF_SECTOR, to, 0, sp->sct_x, sp->sct_y);
274 if (sp->sct_oldown == sp->sct_own)
281 cede_ship(struct nstr_item *ni, natid to)
286 struct nstr_item tni;
290 while (nxtitem(ni, &ship)) {
292 if (!player->owner || ship.shp_own == 0)
296 snxtitem_xy(&tni, EF_SHIP, ship.shp_x, ship.shp_y);
297 while (nxtitem(&tni, &tship) && bad)
298 if (tship.shp_own == to)
301 getsect(ship.shp_x, ship.shp_y, §);
302 if (bad && (sect.sct_own != to)) {
303 pr("%s isn't in a %s sector, and is not with a %s ship!\n",
304 prship(&ship), cname(to), cname(to));
307 grab_ship(&ship, to);
308 putship(ship.shp_uid, &ship);
310 wu(0, to, "%s ceded to you by %s\n",
311 prship(&ship), cname(player->cnum));
312 pr("%s ceded to %s\n", prship(&ship), cname(to));
314 pr(" %d ship%s\n", nships, splur(nships));
320 grab_ship(struct shpstr *sp, natid to)
329 snxtitem_xy(&ni, EF_PLANE, sp->shp_x, sp->shp_y);
330 while (nxtitem(&ni, pp)) {
331 if (pp->pln_own == 0)
333 if (pp->pln_flags & PLN_LAUNCHED)
335 if (pp->pln_ship != sp->shp_uid)
337 if (pp->pln_own != player->cnum)
340 wu(0, to, "\t%s ceded to you by %s\n",
341 prplane(pp), cname(player->cnum));
342 makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
344 makenotlost(EF_PLANE, pp->pln_own, pp->pln_uid,
345 pp->pln_x, pp->pln_y);
348 putplane(pp->pln_uid, pp);
352 snxtitem_xy(&ni, EF_LAND, sp->shp_x, sp->shp_y);
353 while (nxtitem(&ni, lp)) {
354 if (lp->lnd_own == 0)
356 if (lp->lnd_ship != sp->shp_uid)
358 if (lp->lnd_own != player->cnum)
361 wu(0, to, "\t%s ceded to you by %s\n",
362 prland(lp), cname(player->cnum));
363 makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
364 makenotlost(EF_LAND, to, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
371 makelost(EF_SHIP, sp->shp_own, sp->shp_uid, sp->shp_x, sp->shp_y);
373 makenotlost(EF_SHIP, sp->shp_own, sp->shp_uid, sp->shp_x, sp->shp_y);