]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/tend.c
COPYING duplicates information from README. Remove. Move GPL from
[empserver] / src / lib / commands / tend.c
index 79d813a0e119b1be093039e9426a96f64ef72ecb..4771d1e7570c881ac9fa5fb3854e639263a86e94 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2004, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -19,9 +19,9 @@
  *
  *  ---
  *
- *  See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
- *  related information and legal notices. It is expected that any future
- *  projects/authors will amend these files as needed.
+ *  See files README, COPYING and CREDITS in the root of the source
+ *  tree for related information and legal notices.  It is expected
+ *  that future projects/authors will amend these files as needed.
  *
  *  ---
  *
@@ -33,6 +33,8 @@
  *     Steve McClure, 2000
  */
 
+#include <config.h>
+
 #include <string.h>
 #include "misc.h"
 #include "player.h"
@@ -45,7 +47,6 @@
 #include "nat.h"
 #include "land.h"
 #include "plane.h"
-#include "nuke.h"
 #include "genitem.h"
 #include "commands.h"
 
@@ -91,7 +92,7 @@ tend(void)
                  getstarg(player->argp[2], "Tender(s)? ", buf)))
        return RET_SYN;
 
-    while (nxtitem(&tenders, (s_char *)&tender)) {
+    while (nxtitem(&tenders, &tender)) {
        if (!player->owner)
            continue;
        if (type == EF_LAND) {
@@ -134,7 +135,7 @@ tend(void)
        if (!check_ship_ok(&tender))
            return RET_SYN;
        total = 0;
-       while (tend_nxtitem(&targets, (s_char *)&target)) {
+       while (nxtitem(&targets, &target)) {
            if (!player->owner &&
                (getrel(getnatp(target.shp_own), player->cnum) < FRIENDLY))
                continue;
@@ -155,8 +156,8 @@ tend(void)
                    amt = 0;
 
                /* take from target and give to tender */
-               transfer = min(ontarget, -amt);
-               transfer = min(maxtender - ontender, transfer);
+               transfer = MIN(ontarget, -amt);
+               transfer = MIN(maxtender - ontender, transfer);
                if (transfer == 0)
                    continue;
                target.shp_item[ip->i_vtype] = ontarget - transfer;
@@ -164,8 +165,8 @@ tend(void)
                total += transfer;
            } else {
                /* give to target from tender */
-               transfer = min(ontender, amt);
-               transfer = min(transfer, maxtarget - ontarget);
+               transfer = MIN(ontender, amt);
+               transfer = MIN(transfer, maxtarget - ontarget);
                if (transfer == 0)
                    continue;
                target.shp_item[ip->i_vtype] = ontarget + transfer;
@@ -182,6 +183,10 @@ tend(void)
        pr("%d total %s transferred %s %s\n",
           total, ip->i_name, (amt > 0) ? "off of" : "to",
           prship(&tender));
+       if (target.shp_own != player->cnum) {
+           wu(0, target.shp_own, "%s tended %d %s to %s\n",
+              cname(player->cnum), total, ip->i_name, prship(&target));
+       }
        tender.shp_item[ip->i_vtype] = ontender;
        tender.shp_mission = 0;
        putship(tender.shp_uid, &tender);
@@ -198,81 +203,6 @@ expose_ship(struct shpstr *s1, struct shpstr *s2)
        s1->shp_pstage = PLG_EXPOSED;
 }
 
-/*
- * tend_nxtitem.c
- *
- * get next item from list. Stolen from nxtitem to make 1 itsy-bitsy change
- *
- * Dave Pare, 1989
- */
-
-int
-tend_nxtitem(struct nstr_item *np, void *ptr)
-{
-    struct genitem *gp;
-    int selected;
-
-    if (np->sel == NS_UNDEF)
-       return 0;
-    gp = (struct genitem *)ptr;
-    do {
-       if (np->sel == NS_LIST) {
-           np->index++;
-           if (np->index >= np->size)
-               return 0;
-           np->cur = np->list[np->index];
-       } else {
-           np->cur++;
-       }
-       if (!np->read(np->type, np->cur, ptr)) {
-           /* if read fails, fatal */
-           return 0;
-       }
-       selected = 1;
-       switch (np->sel) {
-       case NS_LIST:
-           /* The change is to take the player->owner check out here */
-           break;
-       case NS_ALL:
-           /* XXX maybe combine NS_LIST and NS_ALL later */
-           break;
-       case NS_DIST:
-           if (!xyinrange(gp->x, gp->y, &np->range)) {
-               selected = 0;
-               break;
-           }
-           np->curdist = mapdist((int)gp->x, (int)gp->y,
-                                 (int)np->cx, (int)np->cy);
-           if (np->curdist > np->dist)
-               selected = 0;
-           break;
-       case NS_AREA:
-           if (!xyinrange(gp->x, gp->y, &np->range))
-               selected = 0;
-           if (gp->x == np->range.hx || gp->y == np->range.hy)
-               selected = 0;
-           break;
-       case NS_XY:
-           if (gp->x != np->cx || gp->y != np->cy)
-               selected = 0;
-           break;
-       case NS_GROUP:
-           if (np->group != gp->group)
-               selected = 0;
-           break;
-       default:
-           CANT_HAPPEN("bad np->sel");
-           return 0;
-       }
-       if (selected && np->ncond) {
-           /* nstr_exec is expensive, so we do it last */
-           if (!nstr_exec(np->cond, np->ncond, ptr))
-               selected = 0;
-       }
-    } while (!selected);
-    return 1;
-}
-
 static int
 tend_land(struct shpstr *tenderp, s_char *units)
 {
@@ -287,7 +217,7 @@ tend_land(struct shpstr *tenderp, s_char *units)
     if (!snxtitem(&lni, EF_LAND, units))
        return RET_SYN;
 
-    while (nxtitem(&lni, (s_char *)&land)) {
+    while (nxtitem(&lni, &land)) {
        if (!player->owner)
            continue;
        if (land.lnd_ship != tenderp->shp_uid) {
@@ -304,7 +234,7 @@ tend_land(struct shpstr *tenderp, s_char *units)
            break;
        if (!check_land_ok(&land))
            return RET_SYN;
-       while (tend_nxtitem(&targets, (s_char *)&target)) {
+       while (nxtitem(&targets, &target)) {
            if (!player->owner &&
                (getrel(getnatp(target.shp_own), player->cnum) < FRIENDLY))
                continue;
@@ -318,7 +248,15 @@ tend_land(struct shpstr *tenderp, s_char *units)
            count_units(&target);
            getship(target.shp_uid, &target);
 
-           if (target.shp_nland >= mchr[(int)target.shp_type].m_nland) {
+           if ((mchr[(int)target.shp_type].m_flags & M_SUB) &&
+               (lchr[(int)land.lnd_type].l_flags & L_SPY) &&
+               !mchr[(int)target.shp_type].m_nland) {
+               if (target.shp_nland > 1) {
+                   pr("%s doesn't have room for more than two spy units!\n",
+                      prship(&target));
+                   continue;
+               }
+           } else if (target.shp_nland >= mchr[(int)target.shp_type].m_nland) {
                if (mchr[(int)target.shp_type].m_nland)
                    pr("%s doesn't have room for any more land units!\n",
                       prship(&target));
@@ -348,7 +286,7 @@ tend_land(struct shpstr *tenderp, s_char *units)
            count_units(tenderp);
            putship(tenderp->shp_uid, tenderp);
            snxtitem_xy(&pni, EF_PLANE, land.lnd_x, land.lnd_y);
-           while (nxtitem(&pni, (s_char *)&plane)) {
+           while (nxtitem(&pni, &plane)) {
                if (plane.pln_flags & PLN_LAUNCHED)
                    continue;
                if (plane.pln_land != land.lnd_uid)