2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2005, 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 the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23 * related information and legal notices. It is expected that any future
24 * projects/authors will amend these files as needed.
28 * cede.c: Give a sector to a neighbor
30 * Known contributors to this file:
49 static void cede_hdr(void);
50 static int cede_sect(struct nstr_sect *, natid);
51 static int cede_ship(struct nstr_item *, natid);
52 static void grab_sect(struct sctstr *, natid);
53 static void grab_ship(struct shpstr *, natid);
60 int is_sector = 0, is_ship = 0;
67 if ((p = getstarg(player->argp[1], "Cede what? ", buf)) == 0)
71 if (snxtitem(&ni, EF_SHIP, p))
73 if (!is_sector && !is_ship)
75 if ((n = natarg(player->argp[2], "to which country? ")) < 0)
77 if (is_sector && is_ship) {
81 getstarg(player->argp[3], "Cede sectors or ships (se, sh)? ",
88 if (type == EF_SECTOR)
90 else if (type == EF_SHIP)
93 pr("Please type 'se' or 'sh'!\n");
99 if (n == player->cnum) {
100 pr("Giving something to yourself?\n");
104 if (natp->nat_stat & STAT_GOD) {
105 pr("You can only give to normal countries...\n");
108 if (getrel(natp, player->cnum) < FRIENDLY) {
109 pr("You can only cede to a country that is friendly towards you...\n");
115 return cede_sect(&ns, to);
117 return cede_ship(&ni, to);
121 cede_sect(struct nstr_sect *ns, natid to)
123 struct sctstr sect, osect;
132 for (n = 1; n <= 6; n++)
133 dirstr[n] = dirch[n];
138 while (nxtsct(ns, §)) {
141 if (sect.sct_mobil == 0) {
142 pr("%s has no mobility and cannot be ceded\n",
143 xyas(sect.sct_x, sect.sct_y, player->cnum));
148 for (n = 1; n <= 6; n++) { /* Directions */
149 off_x = sect.sct_x + diroff[n][0];
150 off_y = sect.sct_y + diroff[n][1];
152 if (!getsect(off_x, off_y, &osect))
154 if ((osect.sct_own == to) && (osect.sct_mobil))
156 if ((osect.sct_own == to) &&
157 has_units_with_mob(osect.sct_x, osect.sct_y, to))
160 snxtitem_all(&ni, EF_SHIP);
161 while (nxtitem(&ni, (s_char *)&ship)) {
162 if ((ship.shp_own == to) &&
163 ((ship.shp_x == sect.sct_x) && (ship.shp_y == sect.sct_y)))
167 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));
174 grab_sect(§, to);
176 pr(" %s %d%% ceded\n", xyas(sect.sct_x, sect.sct_y, player->cnum),
177 (int)sect.sct_effic);
178 wu(0, (natid)to, "%s ceded to you by %s\n",
179 xyas(sect.sct_x, sect.sct_y, to), cname(player->cnum));
181 pr("%d sector%s\n", nsect, splur(nsect));
196 grab_sect(struct sctstr *sp, natid to)
206 /* Wipe all the distribution info */
207 memset(sp->sct_dist, 0, sizeof(sp->sct_dist));
208 memset(sp->sct_del, 0, sizeof(sp->sct_del));
209 sp->sct_dist_x = sp->sct_x;
210 sp->sct_dist_y = sp->sct_y;
213 snxtitem_xy(&ni, EF_PLANE, sp->sct_x, sp->sct_y);
214 while (nxtitem(&ni, pp)) {
215 if (pp->pln_own == 0)
217 if (pp->pln_ship >= 0)
219 if (pp->pln_own != player->cnum)
221 if (pp->pln_flags & PLN_LAUNCHED)
224 wu(0, to, "\t%s ceded to you by %s\n",
225 prplane(pp), cname(player->cnum));
226 makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
228 makenotlost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x,
232 putplane(pp->pln_uid, pp);
236 snxtitem_xy(&ni, EF_NUKE, sp->sct_x, sp->sct_y);
237 while (nxtitem(&ni, np)) {
238 if (np->nuk_own == 0)
241 wu(0, to, "\tnuclear stockpile #%d ceded to you by %s\n",
242 np->nuk_uid, cname(player->cnum));
243 makelost(EF_NUKE, np->nuk_own, np->nuk_uid, np->nuk_x, np->nuk_y);
245 makenotlost(EF_NUKE, np->nuk_own, np->nuk_uid, np->nuk_x,
251 snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y);
252 while (nxtitem(&ni, lp)) {
253 if (lp->lnd_own == 0)
255 if (lp->lnd_ship == 0)
257 if (lp->lnd_own != player->cnum)
260 wu(0, to, "\t%s ceded to you by %s\n", prland(lp),
261 cname(player->cnum));
262 makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
263 makenotlost(EF_LAND, to, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
272 if (sp->sct_oldown == to) {
273 sp->sct_che = 0; /* FIXME where do these guys go? */
274 sp->sct_che_target = 0;
278 if (sp->sct_oldown == to)
280 else /* people don't like being given away */
283 sp->sct_dist_x = sp->sct_x;
284 sp->sct_dist_y = sp->sct_y;
285 makelost(EF_SECTOR, sp->sct_own, 0, sp->sct_x, sp->sct_y);
286 makenotlost(EF_SECTOR, to, 0, sp->sct_x, sp->sct_y);
287 if (sp->sct_oldown == sp->sct_own)
294 cede_ship(struct nstr_item *ni, natid to)
299 struct nstr_item tni;
303 while (nxtitem(ni, (s_char *)&ship)) {
305 if (!player->owner || ship.shp_own == 0)
309 snxtitem_xy(&tni, EF_SHIP, ship.shp_x, ship.shp_y);
310 while (nxtitem(&tni, (s_char *)&tship) && bad)
311 if (tship.shp_own == to)
314 getsect(ship.shp_x, ship.shp_y, §);
315 if (bad && (sect.sct_own != to)) {
316 pr("%s isn't in a %s sector, and is not with a %s ship!\n",
317 prship(&ship), cname(to), cname(to));
320 grab_ship(&ship, to);
321 putship(ship.shp_uid, &ship);
323 wu(0, to, "%s ceded to you by %s\n",
324 prship(&ship), cname(player->cnum));
325 pr("%s ceded to %s\n", prship(&ship), cname(to));
327 pr(" %d ship%s\n", nships, splur(nships));
333 grab_ship(struct shpstr *sp, natid to)
342 snxtitem_xy(&ni, EF_PLANE, sp->shp_x, sp->shp_y);
343 while (nxtitem(&ni, pp)) {
344 if (pp->pln_own == 0)
346 if (pp->pln_flags & PLN_LAUNCHED)
348 if (pp->pln_ship != sp->shp_uid)
350 if (pp->pln_own != player->cnum)
353 wu(0, to, "\t%s ceded to you by %s\n",
354 prplane(pp), cname(player->cnum));
355 makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
357 makenotlost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x,
361 putplane(pp->pln_uid, pp);
365 snxtitem_xy(&ni, EF_LAND, sp->shp_x, sp->shp_y);
366 while (nxtitem(&ni, lp)) {
367 if (lp->lnd_own == 0)
369 if (lp->lnd_ship != sp->shp_uid)
371 if (lp->lnd_own != player->cnum)
374 wu(0, to, "\t%s ceded to you by %s\n",
375 prland(lp), cname(player->cnum));
376 makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
377 makenotlost(EF_LAND, to, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
384 makelost(EF_SHIP, sp->shp_own, sp->shp_uid, sp->shp_x, sp->shp_y);
386 makenotlost(EF_SHIP, sp->shp_own, sp->shp_uid, sp->shp_x, sp->shp_y);