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){
79 if ((p = getstarg(player->argp[3], "Cede sectors or ships (se, sh)? ", buf)) == 0)
85 if (type == EF_SECTOR)
87 else if (type == EF_SHIP)
90 pr("Please type 'se' or 'sh'!\n");
96 if (n == player->cnum){
97 pr("Giving something to yourself?\n");
101 if (natp->nat_stat & STAT_GOD){
102 pr("You can only give to normal countries...\n");
105 if (getrel(natp, player->cnum) < FRIENDLY) {
106 pr("You can only cede to a country that is friendly towards you...\n");
112 return cede_sect(&ns,to);
114 return cede_ship(&ni,to);
118 cede_sect(struct nstr_sect *ns, natid to)
120 struct sctstr sect, osect;
129 for (n = 1; n <= 6; n++)
130 dirstr[n] = dirch[n];
135 while (nxtsct(ns, §)) {
138 if (sect.sct_mobil == 0){
139 pr("%s has no mobility and cannot be ceded\n",
140 xyas(sect.sct_x,sect.sct_y,player->cnum));
145 for (n = 1; n <= 6; n++) { /* Directions */
146 off_x = sect.sct_x + diroff[n][0];
147 off_y = sect.sct_y + diroff[n][1];
149 if (!getsect(off_x, off_y, &osect))
151 if ((osect.sct_own == to) && (osect.sct_mobil))
153 if ((osect.sct_own == to) &&
154 has_units_with_mob(osect.sct_x, osect.sct_y,to))
157 snxtitem_all(&ni,EF_SHIP);
158 while (nxtitem(&ni, (s_char *)&ship)){
159 if ((ship.shp_own == to) &&
160 ((ship.shp_x == sect.sct_x) &&
161 (ship.shp_y == sect.sct_y)))
165 pr("%s has no sector with mobility adjacent to or ship in %s!\n",
166 cname(to), xyas(sect.sct_x,sect.sct_y,player->cnum));
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",
228 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, pp->pln_y);
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, np->nuk_y);
252 snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y);
253 while (nxtitem(&ni, (caddr_t)lp)) {
254 if (lp->lnd_own == 0)
256 if (lp->lnd_ship == 0)
258 if (lp->lnd_own != player->cnum)
261 wu(0,to,"\t%s ceded to you by %s\n", prland(lp),
262 cname(player->cnum));
263 makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
264 makenotlost(EF_LAND, to, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
273 if (sp->sct_oldown == to) {
274 oldche = get_che_value(getvar(V_CHE, (s_char *)sp, EF_SECTOR));
275 set_che_value(oldche, 0);
276 set_che_cnum(oldche, 0);
277 (void) putvar(V_CHE, oldche, (s_char *)sp, EF_SECTOR);
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", prship(&ship),
320 cname(to), cname(to));
324 putship(ship.shp_uid,&ship);
326 wu(0,to,"%s ceded to you by %s\n",
328 cname(player->cnum));
329 pr("%s ceded to %s\n",
333 pr(" %d ship%s\n", nships, splur(nships));
339 grab_ship(register struct shpstr *sp, natid to)
341 register struct plnstr *pp;
342 register struct lndstr *lp;
348 snxtitem_xy(&ni, EF_PLANE, sp->shp_x, sp->shp_y);
349 while (nxtitem(&ni, (caddr_t)pp)) {
350 if (pp->pln_own == 0)
352 if (pp->pln_flags & PLN_LAUNCHED)
354 if (pp->pln_ship != sp->shp_uid)
356 if (pp->pln_own != player->cnum)
359 wu(0,to,"\t%s ceded to you by %s\n",
361 cname(player->cnum));
362 makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
364 makenotlost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
367 putplane(pp->pln_uid, pp);
371 snxtitem_xy(&ni, EF_LAND, sp->shp_x, sp->shp_y);
372 while (nxtitem(&ni, (caddr_t)lp)) {
373 if (lp->lnd_own == 0)
375 if (lp->lnd_ship != sp->shp_uid)
377 if (lp->lnd_own != player->cnum)
380 wu(0,to,"\t%s ceded to you by %s\n",
381 prland(lp), cname(player->cnum));
382 makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
383 makenotlost(EF_LAND, to, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
390 makelost(EF_SHIP, sp->shp_own, sp->shp_uid, sp->shp_x, sp->shp_y);
392 makenotlost(EF_SHIP, sp->shp_own, sp->shp_uid, sp->shp_x, sp->shp_y);