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:
52 static void cede_hdr(void);
59 int is_sector = 0, is_ship = 0;
66 if ((p = getstarg(player->argp[1], "Cede what? ", buf)) == 0)
70 if (snxtitem(&ni, EF_SHIP, p))
72 if (!is_sector && !is_ship)
74 if ((n = natarg(player->argp[2], "to which country? ")) < 0)
76 if (is_sector && is_ship) {
80 getstarg(player->argp[3], "Cede sectors or ships (se, sh)? ",
87 if (type == EF_SECTOR)
89 else if (type == EF_SHIP)
92 pr("Please type 'se' or 'sh'!\n");
98 if (n == player->cnum) {
99 pr("Giving something to yourself?\n");
103 if (natp->nat_stat & STAT_GOD) {
104 pr("You can only give to normal countries...\n");
107 if (getrel(natp, player->cnum) < FRIENDLY) {
108 pr("You can only cede to a country that is friendly towards you...\n");
114 return cede_sect(&ns, to);
116 return cede_ship(&ni, to);
120 cede_sect(struct nstr_sect *ns, natid to)
122 struct sctstr sect, osect;
131 for (n = 1; n <= 6; n++)
132 dirstr[n] = dirch[n];
137 while (nxtsct(ns, §)) {
140 if (sect.sct_mobil == 0) {
141 pr("%s has no mobility and cannot be ceded\n",
142 xyas(sect.sct_x, sect.sct_y, player->cnum));
147 for (n = 1; n <= 6; n++) { /* Directions */
148 off_x = sect.sct_x + diroff[n][0];
149 off_y = sect.sct_y + diroff[n][1];
151 if (!getsect(off_x, off_y, &osect))
153 if ((osect.sct_own == to) && (osect.sct_mobil))
155 if ((osect.sct_own == to) &&
156 has_units_with_mob(osect.sct_x, osect.sct_y, to))
159 snxtitem_all(&ni, EF_SHIP);
160 while (nxtitem(&ni, (s_char *)&ship)) {
161 if ((ship.shp_own == to) &&
162 ((ship.shp_x == sect.sct_x) && (ship.shp_y == sect.sct_y)))
166 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));
173 grab_sect(§, to);
175 pr(" %s %d%% ceded\n", xyas(sect.sct_x, sect.sct_y, player->cnum),
176 (int)sect.sct_effic);
177 wu(0, (natid)to, "%s ceded to you by %s\n",
178 xyas(sect.sct_x, sect.sct_y, to), cname(player->cnum));
180 pr("%d sector%s\n", nsect, splur(nsect));
195 grab_sect(register struct sctstr *sp, natid to)
207 /* Wipe all the distribution info */
208 bzero((s_char *)vec, sizeof(vec));
209 putvec(VT_DIST, vec, (s_char *)sp, EF_SECTOR);
210 putvec(VT_DEL, vec, (s_char *)sp, EF_SECTOR);
211 sp->sct_dist_x = sp->sct_x;
212 sp->sct_dist_y = sp->sct_y;
215 snxtitem_xy(&ni, EF_PLANE, sp->sct_x, sp->sct_y);
216 while (nxtitem(&ni, (caddr_t)pp)) {
217 if (pp->pln_own == 0)
219 if (pp->pln_ship >= 0)
221 if (pp->pln_own != player->cnum)
223 if (pp->pln_flags & PLN_LAUNCHED)
226 wu(0, to, "\t%s ceded to you by %s\n",
227 prplane(pp), cname(player->cnum));
228 makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
230 makenotlost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x,
234 putplane(pp->pln_uid, pp);
238 snxtitem_xy(&ni, EF_NUKE, sp->sct_x, sp->sct_y);
239 while (nxtitem(&ni, (caddr_t)np)) {
240 if (np->nuk_own == 0)
243 wu(0, to, "\tnuclear stockpile #%d ceded to you by %s\n",
244 np->nuk_uid, cname(player->cnum));
245 makelost(EF_NUKE, np->nuk_own, np->nuk_uid, np->nuk_x, np->nuk_y);
247 makenotlost(EF_NUKE, np->nuk_own, np->nuk_uid, np->nuk_x,
253 snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y);
254 while (nxtitem(&ni, (caddr_t)lp)) {
255 if (lp->lnd_own == 0)
257 if (lp->lnd_ship == 0)
259 if (lp->lnd_own != player->cnum)
262 wu(0, to, "\t%s ceded to you by %s\n", prland(lp),
263 cname(player->cnum));
264 makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
265 makenotlost(EF_LAND, to, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
274 if (sp->sct_oldown == to) {
275 oldche = get_che_value(getvar(V_CHE, (s_char *)sp, EF_SECTOR));
276 set_che_value(oldche, 0);
277 set_che_cnum(oldche, 0);
278 (void)putvar(V_CHE, oldche, (s_char *)sp, EF_SECTOR);
282 if (sp->sct_oldown == to)
284 else /* people don't like being given away */
287 sp->sct_dist_x = sp->sct_x;
288 sp->sct_dist_y = sp->sct_y;
289 makelost(EF_SECTOR, sp->sct_own, 0, sp->sct_x, sp->sct_y);
290 makenotlost(EF_SECTOR, to, 0, sp->sct_x, sp->sct_y);
291 if (sp->sct_oldown == sp->sct_own)
298 cede_ship(struct nstr_item *ni, natid to)
303 struct nstr_item tni;
307 while (nxtitem(ni, (s_char *)&ship)) {
309 if (!player->owner || ship.shp_own == 0)
313 snxtitem_xy(&tni, EF_SHIP, ship.shp_x, ship.shp_y);
314 while (nxtitem(&tni, (s_char *)&tship) && bad)
315 if (tship.shp_own == to)
318 getsect(ship.shp_x, ship.shp_y, §);
319 if (bad && (sect.sct_own != to)) {
320 pr("%s isn't in a %s sector, and is not with a %s ship!\n",
321 prship(&ship), cname(to), cname(to));
324 grab_ship(&ship, to);
325 putship(ship.shp_uid, &ship);
327 wu(0, to, "%s ceded to you by %s\n",
328 prship(&ship), cname(player->cnum));
329 pr("%s ceded to %s\n", prship(&ship), cname(to));
331 pr(" %d ship%s\n", nships, splur(nships));
337 grab_ship(register struct shpstr *sp, natid to)
339 register struct plnstr *pp;
340 register struct lndstr *lp;
346 snxtitem_xy(&ni, EF_PLANE, sp->shp_x, sp->shp_y);
347 while (nxtitem(&ni, (caddr_t)pp)) {
348 if (pp->pln_own == 0)
350 if (pp->pln_flags & PLN_LAUNCHED)
352 if (pp->pln_ship != sp->shp_uid)
354 if (pp->pln_own != player->cnum)
357 wu(0, to, "\t%s ceded to you by %s\n",
358 prplane(pp), cname(player->cnum));
359 makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
361 makenotlost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x,
365 putplane(pp->pln_uid, pp);
369 snxtitem_xy(&ni, EF_LAND, sp->shp_x, sp->shp_y);
370 while (nxtitem(&ni, (caddr_t)lp)) {
371 if (lp->lnd_own == 0)
373 if (lp->lnd_ship != sp->shp_uid)
375 if (lp->lnd_own != player->cnum)
378 wu(0, to, "\t%s ceded to you by %s\n",
379 prland(lp), cname(player->cnum));
380 makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
381 makenotlost(EF_LAND, to, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
388 makelost(EF_SHIP, sp->shp_own, sp->shp_uid, sp->shp_x, sp->shp_y);
390 makenotlost(EF_SHIP, sp->shp_own, sp->shp_uid, sp->shp_x, sp->shp_y);