]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/cede.c
Update copyright notice
[empserver] / src / lib / commands / cede.c
index 0ba9623f983dd7b9dfa77b61f2fd5c6e6581f93a..bb35322fb896eb1ee7cfea470b15b847d0b8ccbe 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -26,7 +26,7 @@
  *  ---
  *
  *  cede.c: Give a sector to a neighbor
- * 
+ *
  *  Known contributors to this file:
  *     Dave Pare
  *     Thomas Ruschak
 
 #include <config.h>
 
-#include "misc.h"
-#include "player.h"
-#include "xy.h"
-#include "sect.h"
-#include "nsc.h"
-#include "nat.h"
+#include "commands.h"
+#include "land.h"
+#include "lost.h"
+#include "nuke.h"
 #include "path.h"
-#include "file.h"
 #include "plane.h"
-#include "land.h"
 #include "ship.h"
-#include "nuke.h"
-#include "commands.h"
 
+static int has_units_with_mob(coord, coord, natid);
 static void cede_hdr(void);
 static int cede_sect(struct nstr_sect *, natid);
 static int cede_ship(struct nstr_item *, natid);
@@ -67,11 +62,12 @@ cede(void)
     struct natstr *natp;
     char buf[1024];
 
-    if ((p = getstarg(player->argp[1], "Cede what? ", buf)) == 0)
+    p = getstarg(player->argp[1], "Cede what? ", buf);
+    if (!p || !*p)
        return RET_SYN;
     if (snxtsct(&ns, p))
        is_sector = 1;
-    if (snxtitem(&ni, EF_SHIP, p))
+    if (snxtitem(&ni, EF_SHIP, p, NULL))
        is_ship = 1;
     if (!is_sector && !is_ship)
        return RET_SYN;
@@ -175,6 +171,23 @@ cede_sect(struct nstr_sect *ns, natid to)
     return RET_OK;
 }
 
+static int
+has_units_with_mob(coord x, coord y, natid cn)
+{
+    struct nstr_item ni;
+    struct lndstr land;
+
+    snxtitem_xy(&ni, EF_LAND, x, y);
+    while (nxtitem(&ni, &land)) {
+       if (land.lnd_own != cn)
+           continue;
+       if (land.lnd_mobil > 0)
+           return 1;
+    }
+
+    return 0;
+}
+
 static void
 cede_hdr(void)
 {
@@ -216,10 +229,7 @@ grab_sect(struct sctstr *sp, natid to)
 
        wu(0, to, "\t%s ceded to you by %s\n",
           prplane(pp), cname(player->cnum));
-       makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
        pp->pln_own = to;
-       makenotlost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x,
-                   pp->pln_y);
        pp->pln_mobil = 0;
        pp->pln_mission = 0;
        putplane(pp->pln_uid, pp);
@@ -231,12 +241,9 @@ grab_sect(struct sctstr *sp, natid to)
        if (np->nuk_own == 0)
            continue;
 
-       wu(0, to, "\tnuclear stockpile #%d ceded to you by %s\n",
-          np->nuk_uid, cname(player->cnum));
-       makelost(EF_NUKE, np->nuk_own, np->nuk_uid, np->nuk_x, np->nuk_y);
+       wu(0, to, "\t%s ceded to you by %s\n",
+          prnuke(np), cname(player->cnum));
        np->nuk_own = to;
-       makenotlost(EF_NUKE, np->nuk_own, np->nuk_uid, np->nuk_x,
-                   np->nuk_y);
        putnuke(ni.cur, np);
     }
 
@@ -250,10 +257,8 @@ grab_sect(struct sctstr *sp, natid to)
        if (lp->lnd_own != player->cnum)
            continue;
 
-       wu(0, to, "\t%s ceded to you by %s\n", prland(lp),
-          cname(player->cnum));
-       makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
-       makenotlost(EF_LAND, to, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
+       wu(0, to, "\t%s ceded to you by %s\n",
+          prland(lp), cname(player->cnum));
        lp->lnd_own = to;
        lp->lnd_mobil = 0;
        lp->lnd_mission = 0;
@@ -275,8 +280,6 @@ grab_sect(struct sctstr *sp, natid to)
 
     sp->sct_dist_x = sp->sct_x;
     sp->sct_dist_y = sp->sct_y;
-    makelost(EF_SECTOR, sp->sct_own, 0, sp->sct_x, sp->sct_y);
-    makenotlost(EF_SECTOR, to, 0, sp->sct_x, sp->sct_y);
     if (sp->sct_oldown == sp->sct_own)
        sp->sct_oldown = to;
     sp->sct_own = to;
@@ -345,10 +348,7 @@ grab_ship(struct shpstr *sp, natid to)
 
        wu(0, to, "\t%s ceded to you by %s\n",
           prplane(pp), cname(player->cnum));
-       makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
        pp->pln_own = to;
-       makenotlost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x,
-                   pp->pln_y);
        pp->pln_mobil = 0;
        pp->pln_mission = 0;
        putplane(pp->pln_uid, pp);
@@ -366,15 +366,11 @@ grab_ship(struct shpstr *sp, natid to)
 
        wu(0, to, "\t%s ceded to you by %s\n",
           prland(lp), cname(player->cnum));
-       makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
-       makenotlost(EF_LAND, to, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
        lp->lnd_own = to;
        lp->lnd_mobil = 0;
        lp->lnd_mission = 0;
        putland(ni.cur, lp);
     }
 
-    makelost(EF_SHIP, sp->shp_own, sp->shp_uid, sp->shp_x, sp->shp_y);
     sp->shp_own = to;
-    makenotlost(EF_SHIP, sp->shp_own, sp->shp_uid, sp->shp_x, sp->shp_y);
 }