]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/mfir.c
Factor feels_like_helping() out of quiet_bigdef(), sd(), dd()
[empserver] / src / lib / commands / mfir.c
index 787aee04b04ff3323d970e1f7e165e125b759477..1d8925ff176527e3b73ac89dbead62480c1f9002 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2010, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
  *  ---
  *
  *  multifire.c: Fire at other sectors/ships
- * 
+ *
  *  Known contributors to this file:
  *     Steve McClure, 2000
- *     Markus Armbruster, 2004-2008
+ *     Markus Armbruster, 2004-2009
  */
 
 #include <config.h>
@@ -46,7 +46,7 @@ enum targ_type {
 struct flist {
     struct emp_qelem queue;    /* list of fired things */
     short type;                        /* EF_SECTOR, EF_SHIP or EF_LAND */
-    short uid;
+    int uid;
     coord x, y;
     int defdam;                        /* damage defenders did */
     natid victim;
@@ -72,7 +72,6 @@ multifire(void)
     coord fy;
     coord x;
     coord y;
-    int mil;
     int dam;
     int totaldefdam = 0;
     int vshipno;
@@ -83,8 +82,6 @@ multifire(void)
     struct shpstr vship;
     struct sctstr vsect;
     enum targ_type target;
-    int rel;
-    struct natstr *natp;
     struct nstr_item nbst;
     int type;
     struct empobj *attgp;
@@ -98,9 +95,9 @@ multifire(void)
 
     emp_initque(&fired);
     emp_initque(&defended);
-    if (!(p = getstarg(player->argp[1],
-                      "Firing from ship(s), sect(s), or land unit(s)? ",
-                      buf)))
+    p = getstarg(player->argp[1],
+                "Firing from ship(s), sect(s), or land unit(s)? ", buf);
+    if (!p)
        return RET_SYN;
     type = ef_byname_from(p, ef_with_guns);
     if (opt_NO_FORT_FIRE && type == EF_SECTOR) {
@@ -111,17 +108,9 @@ multifire(void)
        pr("Ships, land units or sectors only!\n");
        return RET_SYN;
     }
-    if ((ptr = getstarg(player->argp[2], "Firing from? ", buf)) == 0
-       || *ptr == '\0')
-       return RET_SYN;
-
-    if (!snxtitem(&nbst, type, ptr))
+    if (!snxtitem(&nbst, type, player->argp[2], "Firing from? "))
        return RET_SYN;
 
-    if (player->aborted) {
-       pr("Fire aborted.\n");
-       return RET_OK;
-    }
     while (nxtitem(&nbst, &item)) {
        if (type == EF_LAND) {
            if (!getland(item.land.lnd_uid, &fland))
@@ -220,13 +209,11 @@ multifire(void)
            fy = fsect.sct_y;
        }
 
-       if ((ptr = getstarg(player->argp[3], "Firing at? ", buf)) == 0
-           || *ptr == '\0')
-           continue;
-       if (player->aborted) {
-           pr("Fire aborted.\n");
+       ptr = getstarg(player->argp[3], "Firing at? ", buf);
+       if (!ptr)
+           return RET_FAIL;
+       if (!*ptr)
            continue;
-       }
        if (!issector(ptr)) {
            vshipno = atoi(ptr);
            if (vshipno < 0 || !getship(vshipno, &vship) ||
@@ -275,7 +262,7 @@ multifire(void)
                    continue;
                }
            }
-           if ((mil = fship.shp_item[I_MILIT]) < 1) {
+           if (fship.shp_item[I_MILIT] < 1) {
                pr("Not enough military for firing crew.\n");
                continue;
            }
@@ -427,17 +414,6 @@ multifire(void)
            break;
        }
 
-       if (opt_SLOW_WAR) {
-           if (target == targ_land) {
-               natp = getnatp(player->cnum);
-               rel = getrel(natp, vict);
-               if ((rel != AT_WAR) && (player->cnum != vict) &&
-                   (vict) && (vsect.sct_oldown != player->cnum)) {
-                   pr("You're not at war with them!\n");
-                   continue;
-               }
-           }
-       }
        nfiring++;
        switch (target) {
        case targ_sub:
@@ -503,9 +479,10 @@ multifire(void)
            putship(vship.shp_uid, &vship);
            break;
        }
-       if ((totaldefdam == 0) && (target == targ_ship))
-           if (vship.shp_rflags & RET_HELPLESS)
-               retreat_ship(&vship, 'h');
+       if (totaldefdam == 0 && target == targ_ship
+           && (vship.shp_rflags & RET_HELPLESS)
+           && !(vship.shp_rflags & RET_INJURED))
+           retreat_ship(&vship, 'h');
        switch (attgp->ef_type) {
        case EF_SECTOR:
            putsect(&fsect);
@@ -611,7 +588,7 @@ quiet_bigdef(int type, struct emp_qelem *list, natid own, natid aown,
     struct shpstr ship;
     struct lndstr land;
     struct nstr_item ni;
-    int dam, dam2, rel, rel2;
+    int dam, dam2;
     struct sctstr firing;
     struct nstr_sect ns;
     struct flist *fp;
@@ -621,19 +598,12 @@ quiet_bigdef(int type, struct emp_qelem *list, natid own, natid aown,
     dam = 0;
     snxtitem_dist(&ni, EF_SHIP, ax, ay, 8);
     while (nxtitem(&ni, &ship)) {
-       if (ship.shp_own == 0)
+       if (!feels_like_helping(ship.shp_own, own, aown))
            continue;
 
        if ((mchr[ship.shp_type].m_flags & M_SUB) && type != EF_SHIP)
            continue;
 
-       rel = getrel(getnatp(ship.shp_own), own);
-       rel2 = getrel(getnatp(ship.shp_own), aown);
-       if ((ship.shp_own != own) && ((rel != ALLIED) || (rel2 != AT_WAR)))
-           continue;
-       /* Don't shoot yourself */
-       if (ship.shp_own == aown)
-           continue;
        if (mchr[(int)ship.shp_type].m_flags & M_SUB) {
            erange = torprange(&ship);
            if (roundrange(erange) < ni.curdist)
@@ -673,16 +643,7 @@ quiet_bigdef(int type, struct emp_qelem *list, natid own, natid aown,
     }
     snxtitem_dist(&ni, EF_LAND, ax, ay, 8);
     while (nxtitem(&ni, &land)) {
-       if (land.lnd_own == 0)
-           continue;
-       /* Don't shoot yourself */
-       if (land.lnd_own == aown)
-           continue;
-
-       rel = getrel(getnatp(land.lnd_own), own);
-       rel2 = getrel(getnatp(land.lnd_own), aown);
-
-       if ((land.lnd_own != own) && ((rel != ALLIED) || (rel2 != AT_WAR)))
+       if (!feels_like_helping(land.lnd_own, own, aown))
            continue;
 
        erange = lnd_fire_range(&land);
@@ -720,17 +681,9 @@ quiet_bigdef(int type, struct emp_qelem *list, natid own, natid aown,
     if (!opt_NO_FORT_FIRE) {
        snxtsct_dist(&ns, ax, ay, 8);
        while (nxtsct(&ns, &firing)) {
-           if (firing.sct_own == 0)
+           if (!feels_like_helping(firing.sct_own, own, aown))
                continue;
-           rel = getrel(getnatp(firing.sct_own), own);
-           rel2 = getrel(getnatp(firing.sct_own), aown);
 
-           if ((firing.sct_own != own) &&
-               ((rel != ALLIED) || (rel2 != AT_WAR)))
-               continue;
-           /* Don't shoot yourself */
-           if (firing.sct_own == aown)
-               continue;
            erange = fortrange(&firing);
            if (roundrange(erange) < ns.curdist)
                continue;