#include <config.h>#include "commands.h"#include "land.h"#include "lost.h"#include "nuke.h"#include "path.h"#include "plane.h"#include "ship.h"Include dependency graph for cede.c:

Go to the source code of this file.
Functions | |
| static void | cede_hdr (void) |
| static int | cede_sect (struct nstr_sect *, natid) |
| static int | cede_ship (struct nstr_item *, natid) |
| static void | grab_sect (struct sctstr *, natid) |
| static void | grab_ship (struct shpstr *, natid) |
| int | cede (void) |
| int cede | ( | void | ) |
Definition at line 52 of file cede.c.
References cede_sect(), cede_ship(), EF_BAD, ef_byname_from(), EF_SECTOR, EF_SHIP, FRIENDLY, getnatp, getrel(), getstarg(), natstr::nat_stat, natarg(), ni, pr(), RET_FAIL, RET_SYN, snxtitem(), snxtsct(), and STAT_ACTIVE.
00053 { 00054 static int sct_or_shp[] = { EF_SECTOR, EF_SHIP, EF_BAD }; 00055 natid to; 00056 int n; 00057 int is_sector = 0, is_ship = 0; 00058 char *p; 00059 struct nstr_sect ns; 00060 struct nstr_item ni; 00061 struct natstr *natp; 00062 char buf[1024]; 00063 00064 if ((p = getstarg(player->argp[1], "Cede what? ", buf)) == 0) 00065 return RET_SYN; 00066 if (snxtsct(&ns, p)) 00067 is_sector = 1; 00068 if (snxtitem(&ni, EF_SHIP, p)) 00069 is_ship = 1; 00070 if (!is_sector && !is_ship) 00071 return RET_SYN; 00072 if ((n = natarg(player->argp[2], "to which country? ")) < 0) 00073 return RET_SYN; 00074 if (is_sector && is_ship) { 00075 int type; 00076 00077 if ((p = 00078 getstarg(player->argp[3], "Cede sectors or ships (se, sh)? ", 00079 buf)) == 0) 00080 return RET_FAIL; 00081 if (strlen(p) > 4) 00082 p[2] = 0; 00083 type = ef_byname_from(p, sct_or_shp); 00084 if (type < 0) { 00085 pr("Please type 'se' or 'sh'!\n"); 00086 return RET_FAIL; 00087 } 00088 } 00089 00090 00091 if (n == player->cnum) { 00092 pr("Giving something to yourself?\n"); 00093 return RET_FAIL; 00094 } 00095 natp = getnatp(n); 00096 if (natp->nat_stat != STAT_ACTIVE) { 00097 pr("You can only give to normal countries...\n"); 00098 return RET_FAIL; 00099 } 00100 if (getrel(natp, player->cnum) < FRIENDLY) { 00101 pr("You can only cede to a country that is friendly towards you...\n"); 00102 return RET_FAIL; 00103 } 00104 to = n; 00105 00106 if (is_sector) 00107 return cede_sect(&ns, to); 00108 else 00109 return cede_ship(&ni, to); 00110 }
Here is the call graph for this function:

| static void cede_hdr | ( | void | ) | [static] |
Definition at line 113 of file cede.c.
References cede_hdr(), cname(), diroff, EF_SHIP, getsect, grab_sect(), has_units_with_mob(), ni, nxtitem(), nxtsct(), pr(), prdate(), putsect, RET_OK, sctstr::sct_effic, sctstr::sct_mobil, sctstr::sct_own, sctstr::sct_x, sctstr::sct_y, shpstr::shp_own, shpstr::shp_x, shpstr::shp_y, snxtitem_all(), splur(), wu(), and xyas().
Referenced by cede().
00114 { 00115 struct sctstr sect, osect; 00116 int nsect; 00117 int n, bad; 00118 int off_x, off_y; 00119 struct nstr_item ni; 00120 struct shpstr ship; 00121 00122 prdate(); 00123 nsect = 0; 00124 while (nxtsct(ns, §)) { 00125 if (!player->owner) 00126 continue; 00127 if (sect.sct_mobil == 0) { 00128 pr("%s has no mobility and cannot be ceded\n", 00129 xyas(sect.sct_x, sect.sct_y, player->cnum)); 00130 continue; 00131 } 00132 00133 bad = 1; 00134 for (n = 1; n <= 6; n++) { /* Directions */ 00135 off_x = sect.sct_x + diroff[n][0]; 00136 off_y = sect.sct_y + diroff[n][1]; 00137 00138 if (!getsect(off_x, off_y, &osect)) 00139 continue; 00140 if ((osect.sct_own == to) && (osect.sct_mobil)) 00141 bad = 0; 00142 if ((osect.sct_own == to) && 00143 has_units_with_mob(osect.sct_x, osect.sct_y, to)) 00144 bad = 0; 00145 } 00146 snxtitem_all(&ni, EF_SHIP); 00147 while (nxtitem(&ni, &ship)) { 00148 if ((ship.shp_own == to) && 00149 ((ship.shp_x == sect.sct_x) && (ship.shp_y == sect.sct_y))) 00150 bad = 0; 00151 } 00152 if (bad) { 00153 pr("%s has no sector with mobility adjacent to or ship in %s!\n", 00154 cname(to), xyas(sect.sct_x, sect.sct_y, player->cnum)); 00155 continue; 00156 } 00157 00158 if (nsect++ == 0) 00159 cede_hdr(); 00160 00161 grab_sect(§, to); 00162 putsect(§); 00163 pr(" %s %d%% ceded\n", xyas(sect.sct_x, sect.sct_y, player->cnum), 00164 (int)sect.sct_effic); 00165 wu(0, (natid)to, "%s ceded to you by %s\n", 00166 xyas(sect.sct_x, sect.sct_y, to), cname(player->cnum)); 00167 } 00168 pr("%d sector%s\n", nsect, splur(nsect)); 00169 return RET_OK; 00170 }
Here is the call graph for this function:

Definition at line 281 of file cede.c.
References cname(), EF_SHIP, getsect, grab_ship(), ni, nxtitem(), pr(), prship(), putship, RET_OK, sctstr::sct_own, shpstr::shp_own, shpstr::shp_uid, shpstr::shp_x, shpstr::shp_y, snxtitem_xy(), splur(), and wu().
Referenced by cede().
00282 { 00283 struct shpstr ship; 00284 struct shpstr tship; 00285 struct sctstr sect; 00286 struct nstr_item tni; 00287 int nships = 0; 00288 int bad = 0; 00289 00290 while (nxtitem(ni, &ship)) { 00291 00292 if (!player->owner || ship.shp_own == 0) 00293 continue; 00294 00295 bad = 1; 00296 snxtitem_xy(&tni, EF_SHIP, ship.shp_x, ship.shp_y); 00297 while (nxtitem(&tni, &tship) && bad) 00298 if (tship.shp_own == to) 00299 bad = 0; 00300 00301 getsect(ship.shp_x, ship.shp_y, §); 00302 if (bad && (sect.sct_own != to)) { 00303 pr("%s isn't in a %s sector, and is not with a %s ship!\n", 00304 prship(&ship), cname(to), cname(to)); 00305 continue; 00306 } 00307 grab_ship(&ship, to); 00308 putship(ship.shp_uid, &ship); 00309 nships++; 00310 wu(0, to, "%s ceded to you by %s\n", 00311 prship(&ship), cname(player->cnum)); 00312 pr("%s ceded to %s\n", prship(&ship), cname(to)); 00313 } 00314 pr(" %d ship%s\n", nships, splur(nships)); 00315 00316 return RET_OK; 00317 }
Here is the call graph for this function:

Definition at line 183 of file cede.c.
References cname(), EF_LAND, EF_NUKE, EF_PLANE, EF_SECTOR, lndstr::lnd_mission, lndstr::lnd_mobil, lndstr::lnd_own, lndstr::lnd_ship, lndstr::lnd_uid, lndstr::lnd_x, lndstr::lnd_y, makelost(), makenotlost(), ni, nukstr::nuk_own, nukstr::nuk_uid, nukstr::nuk_x, nukstr::nuk_y, nxtitem(), plnstr::pln_flags, PLN_LAUNCHED, plnstr::pln_mission, plnstr::pln_mobil, plnstr::pln_own, plnstr::pln_ship, plnstr::pln_uid, plnstr::pln_x, plnstr::pln_y, prland(), prnuke(), prplane(), putland, putnuke, putplane, snxtitem_xy(), sp, and wu().
Referenced by cede_sect().
00184 { 00185 struct plnstr *pp; 00186 struct lndstr *lp; 00187 struct nukstr *np; 00188 struct nstr_item ni; 00189 struct plnstr p; 00190 struct lndstr l; 00191 struct nukstr nuk; 00192 00193 /* Wipe all the distribution info */ 00194 memset(sp->sct_dist, 0, sizeof(sp->sct_dist)); 00195 memset(sp->sct_del, 0, sizeof(sp->sct_del)); 00196 sp->sct_dist_x = sp->sct_x; 00197 sp->sct_dist_y = sp->sct_y; 00198 00199 pp = &p; 00200 snxtitem_xy(&ni, EF_PLANE, sp->sct_x, sp->sct_y); 00201 while (nxtitem(&ni, pp)) { 00202 if (pp->pln_own == 0) 00203 continue; 00204 if (pp->pln_ship >= 0) 00205 continue; 00206 if (pp->pln_own != player->cnum) 00207 continue; 00208 if (pp->pln_flags & PLN_LAUNCHED) 00209 continue; 00210 00211 wu(0, to, "\t%s ceded to you by %s\n", 00212 prplane(pp), cname(player->cnum)); 00213 makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y); 00214 pp->pln_own = to; 00215 makenotlost(EF_PLANE, pp->pln_own, pp->pln_uid, 00216 pp->pln_x, pp->pln_y); 00217 pp->pln_mobil = 0; 00218 pp->pln_mission = 0; 00219 putplane(pp->pln_uid, pp); 00220 } 00221 00222 np = &nuk; 00223 snxtitem_xy(&ni, EF_NUKE, sp->sct_x, sp->sct_y); 00224 while (nxtitem(&ni, np)) { 00225 if (np->nuk_own == 0) 00226 continue; 00227 00228 wu(0, to, "\t%s ceded to you by %s\n", 00229 prnuke(np), cname(player->cnum)); 00230 makelost(EF_NUKE, np->nuk_own, np->nuk_uid, np->nuk_x, np->nuk_y); 00231 np->nuk_own = to; 00232 makenotlost(EF_NUKE, np->nuk_own, np->nuk_uid, 00233 np->nuk_x, np->nuk_y); 00234 putnuke(ni.cur, np); 00235 } 00236 00237 lp = &l; 00238 snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y); 00239 while (nxtitem(&ni, lp)) { 00240 if (lp->lnd_own == 0) 00241 continue; 00242 if (lp->lnd_ship == 0) 00243 continue; 00244 if (lp->lnd_own != player->cnum) 00245 continue; 00246 00247 wu(0, to, "\t%s ceded to you by %s\n", 00248 prland(lp), cname(player->cnum)); 00249 makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y); 00250 makenotlost(EF_LAND, to, lp->lnd_uid, lp->lnd_x, lp->lnd_y); 00251 lp->lnd_own = to; 00252 lp->lnd_mobil = 0; 00253 lp->lnd_mission = 0; 00254 putland(ni.cur, lp); 00255 } 00256 00257 sp->sct_avail = 0; 00258 00259 if (sp->sct_oldown == to) { 00260 sp->sct_che = 0; /* FIXME where do these guys go? */ 00261 sp->sct_che_target = 0; 00262 sp->sct_loyal = 0; 00263 } 00264 00265 if (sp->sct_oldown == to) 00266 sp->sct_loyal = 0; 00267 else /* people don't like being given away */ 00268 sp->sct_loyal = 50; 00269 00270 sp->sct_dist_x = sp->sct_x; 00271 sp->sct_dist_y = sp->sct_y; 00272 makelost(EF_SECTOR, sp->sct_own, 0, sp->sct_x, sp->sct_y); 00273 makenotlost(EF_SECTOR, to, 0, sp->sct_x, sp->sct_y); 00274 if (sp->sct_oldown == sp->sct_own) 00275 sp->sct_oldown = to; 00276 sp->sct_own = to; 00277 sp->sct_mobil = 0; 00278 }
Here is the call graph for this function:

Definition at line 320 of file cede.c.
References cname(), EF_LAND, EF_PLANE, EF_SHIP, lndstr::lnd_mission, lndstr::lnd_mobil, lndstr::lnd_own, lndstr::lnd_ship, lndstr::lnd_uid, lndstr::lnd_x, lndstr::lnd_y, makelost(), makenotlost(), ni, nxtitem(), PLN_LAUNCHED, prland(), prplane(), putland, putplane, snxtitem_xy(), sp, and wu().
Referenced by cede_ship().
00321 { 00322 struct plnstr *pp; 00323 struct lndstr *lp; 00324 struct nstr_item ni; 00325 struct plnstr p; 00326 struct lndstr l; 00327 00328 pp = &p; 00329 snxtitem_xy(&ni, EF_PLANE, sp->shp_x, sp->shp_y); 00330 while (nxtitem(&ni, pp)) { 00331 if (pp->pln_own == 0) 00332 continue; 00333 if (pp->pln_flags & PLN_LAUNCHED) 00334 continue; 00335 if (pp->pln_ship != sp->shp_uid) 00336 continue; 00337 if (pp->pln_own != player->cnum) 00338 continue; 00339 00340 wu(0, to, "\t%s ceded to you by %s\n", 00341 prplane(pp), cname(player->cnum)); 00342 makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y); 00343 pp->pln_own = to; 00344 makenotlost(EF_PLANE, pp->pln_own, pp->pln_uid, 00345 pp->pln_x, pp->pln_y); 00346 pp->pln_mobil = 0; 00347 pp->pln_mission = 0; 00348 putplane(pp->pln_uid, pp); 00349 } 00350 00351 lp = &l; 00352 snxtitem_xy(&ni, EF_LAND, sp->shp_x, sp->shp_y); 00353 while (nxtitem(&ni, lp)) { 00354 if (lp->lnd_own == 0) 00355 continue; 00356 if (lp->lnd_ship != sp->shp_uid) 00357 continue; 00358 if (lp->lnd_own != player->cnum) 00359 continue; 00360 00361 wu(0, to, "\t%s ceded to you by %s\n", 00362 prland(lp), cname(player->cnum)); 00363 makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y); 00364 makenotlost(EF_LAND, to, lp->lnd_uid, lp->lnd_x, lp->lnd_y); 00365 lp->lnd_own = to; 00366 lp->lnd_mobil = 0; 00367 lp->lnd_mission = 0; 00368 putland(ni.cur, lp); 00369 } 00370 00371 makelost(EF_SHIP, sp->shp_own, sp->shp_uid, sp->shp_x, sp->shp_y); 00372 sp->shp_own = to; 00373 makenotlost(EF_SHIP, sp->shp_own, sp->shp_uid, sp->shp_x, sp->shp_y); 00374 }
Here is the call graph for this function:

1.5.2