2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2000, 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:
51 static void cede_hdr(void);
52 static int cede_sect(struct nstr_sect *, natid);
53 static int cede_ship(struct nstr_item *, natid);
54 static void grab_sect(register struct sctstr *, natid);
55 static void grab_ship(register struct shpstr *, natid);
62 int is_sector = 0, is_ship = 0;
69 if ((p = getstarg(player->argp[1], "Cede what? ", buf)) == 0)
73 if (snxtitem(&ni, EF_SHIP, p))
75 if (!is_sector && !is_ship)
77 if ((n = natarg(player->argp[2], "to which country? ")) < 0)
79 if (is_sector && is_ship) {
83 getstarg(player->argp[3], "Cede sectors or ships (se, sh)? ",
90 if (type == EF_SECTOR)
92 else if (type == EF_SHIP)
95 pr("Please type 'se' or 'sh'!\n");
101 if (n == player->cnum) {
102 pr("Giving something to yourself?\n");
106 if (natp->nat_stat & STAT_GOD) {
107 pr("You can only give to normal countries...\n");
110 if (getrel(natp, player->cnum) < FRIENDLY) {
111 pr("You can only cede to a country that is friendly towards you...\n");
117 return cede_sect(&ns, to);
119 return cede_ship(&ni, to);
123 cede_sect(struct nstr_sect *ns, natid to)
125 struct sctstr sect, osect;
134 for (n = 1; n <= 6; n++)
135 dirstr[n] = dirch[n];
140 while (nxtsct(ns, §)) {
143 if (sect.sct_mobil == 0) {
144 pr("%s has no mobility and cannot be ceded\n",
145 xyas(sect.sct_x, sect.sct_y, player->cnum));
150 for (n = 1; n <= 6; n++) { /* Directions */
151 off_x = sect.sct_x + diroff[n][0];
152 off_y = sect.sct_y + diroff[n][1];
154 if (!getsect(off_x, off_y, &osect))
156 if ((osect.sct_own == to) && (osect.sct_mobil))
158 if ((osect.sct_own == to) &&
159 has_units_with_mob(osect.sct_x, osect.sct_y, to))
162 snxtitem_all(&ni, EF_SHIP);
163 while (nxtitem(&ni, (s_char *)&ship)) {
164 if ((ship.shp_own == to) &&
165 ((ship.shp_x == sect.sct_x) && (ship.shp_y == sect.sct_y)))
169 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));
176 grab_sect(§, to);
178 pr(" %s %d%% ceded\n", xyas(sect.sct_x, sect.sct_y, player->cnum),
179 (int)sect.sct_effic);
180 wu(0, (natid)to, "%s ceded to you by %s\n",
181 xyas(sect.sct_x, sect.sct_y, to), cname(player->cnum));
183 pr("%d sector%s\n", nsect, splur(nsect));
198 grab_sect(register struct sctstr *sp, natid to)
209 /* Wipe all the distribution info */
210 memset(sp->sct_dist, 0, sizeof(sp->sct_dist));
211 memset(sp->sct_del, 0, sizeof(sp->sct_del));
212 sp->sct_dist_x = sp->sct_x;
213 sp->sct_dist_y = sp->sct_y;
216 snxtitem_xy(&ni, EF_PLANE, sp->sct_x, sp->sct_y);
217 while (nxtitem(&ni, (caddr_t)pp)) {
218 if (pp->pln_own == 0)
220 if (pp->pln_ship >= 0)
222 if (pp->pln_own != player->cnum)
224 if (pp->pln_flags & PLN_LAUNCHED)
227 wu(0, to, "\t%s ceded to you by %s\n",
228 prplane(pp), cname(player->cnum));
229 makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
231 makenotlost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x,
235 putplane(pp->pln_uid, pp);
239 snxtitem_xy(&ni, EF_NUKE, sp->sct_x, sp->sct_y);
240 while (nxtitem(&ni, (caddr_t)np)) {
241 if (np->nuk_own == 0)
244 wu(0, to, "\tnuclear stockpile #%d ceded to you by %s\n",
245 np->nuk_uid, cname(player->cnum));
246 makelost(EF_NUKE, np->nuk_own, np->nuk_uid, np->nuk_x, np->nuk_y);
248 makenotlost(EF_NUKE, np->nuk_own, np->nuk_uid, np->nuk_x,
254 snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y);
255 while (nxtitem(&ni, (caddr_t)lp)) {
256 if (lp->lnd_own == 0)
258 if (lp->lnd_ship == 0)
260 if (lp->lnd_own != player->cnum)
263 wu(0, to, "\t%s ceded to you by %s\n", prland(lp),
264 cname(player->cnum));
265 makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
266 makenotlost(EF_LAND, to, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
275 if (sp->sct_oldown == to) {
276 sp->sct_che = 0; /* FIXME where do these guys go? */
277 sp->sct_che_target = 0;
281 if (sp->sct_oldown == to)
283 else /* people don't like being given away */
286 sp->sct_dist_x = sp->sct_x;
287 sp->sct_dist_y = sp->sct_y;
288 makelost(EF_SECTOR, sp->sct_own, 0, sp->sct_x, sp->sct_y);
289 makenotlost(EF_SECTOR, to, 0, sp->sct_x, sp->sct_y);
290 if (sp->sct_oldown == sp->sct_own)
297 cede_ship(struct nstr_item *ni, natid to)
302 struct nstr_item tni;
306 while (nxtitem(ni, (s_char *)&ship)) {
308 if (!player->owner || ship.shp_own == 0)
312 snxtitem_xy(&tni, EF_SHIP, ship.shp_x, ship.shp_y);
313 while (nxtitem(&tni, (s_char *)&tship) && bad)
314 if (tship.shp_own == to)
317 getsect(ship.shp_x, ship.shp_y, §);
318 if (bad && (sect.sct_own != to)) {
319 pr("%s isn't in a %s sector, and is not with a %s ship!\n",
320 prship(&ship), cname(to), cname(to));
323 grab_ship(&ship, to);
324 putship(ship.shp_uid, &ship);
326 wu(0, to, "%s ceded to you by %s\n",
327 prship(&ship), cname(player->cnum));
328 pr("%s ceded to %s\n", prship(&ship), cname(to));
330 pr(" %d ship%s\n", nships, splur(nships));
336 grab_ship(register struct shpstr *sp, natid to)
338 register struct plnstr *pp;
339 register struct lndstr *lp;
345 snxtitem_xy(&ni, EF_PLANE, sp->shp_x, sp->shp_y);
346 while (nxtitem(&ni, (caddr_t)pp)) {
347 if (pp->pln_own == 0)
349 if (pp->pln_flags & PLN_LAUNCHED)
351 if (pp->pln_ship != sp->shp_uid)
353 if (pp->pln_own != player->cnum)
356 wu(0, to, "\t%s ceded to you by %s\n",
357 prplane(pp), cname(player->cnum));
358 makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
360 makenotlost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x,
364 putplane(pp->pln_uid, pp);
368 snxtitem_xy(&ni, EF_LAND, sp->shp_x, sp->shp_y);
369 while (nxtitem(&ni, (caddr_t)lp)) {
370 if (lp->lnd_own == 0)
372 if (lp->lnd_ship != sp->shp_uid)
374 if (lp->lnd_own != player->cnum)
377 wu(0, to, "\t%s ceded to you by %s\n",
378 prland(lp), cname(player->cnum));
379 makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
380 makenotlost(EF_LAND, to, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
387 makelost(EF_SHIP, sp->shp_own, sp->shp_uid, sp->shp_x, sp->shp_y);
389 makenotlost(EF_SHIP, sp->shp_own, sp->shp_uid, sp->shp_x, sp->shp_y);