]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/attsub.c
COPYING duplicates information from README. Remove. Move GPL from
[empserver] / src / lib / subs / attsub.c
index 5758c9b620968694c6d8e250488f43b501d4540e..83c2dc15196aeb3f32532b73b263e318dfdd894e 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2005, 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.
  *
  *  ---
  *
@@ -32,6 +32,8 @@
  *     Steve McClure, 1996-2000
  */
 
+#include <config.h>
+
 #include <math.h>
 #include "misc.h"
 #include "player.h"
@@ -85,7 +87,7 @@ static int take_def(int combat_mode, struct emp_qelem *list,
 static int get_land(int combat_mode, struct combat *def, int uid,
                    struct llist *llp, int victim_land);
 
-s_char *att_mode[] = {
+char *att_mode[] = {
     /* must match combat types in combat.h */
     "defend", "attack", "assault", "paradrop", "board", "lboard"
 };
@@ -133,16 +135,10 @@ pr_com(int inon, struct combat *com, natid who)
                     inon ? inon == 1 ? "in " : "into " : "",
                     xyas(com->x, com->y, who));
     } else if (com->type == EF_SHIP) {
-       if (opt_SHIPNAMES) {
-           return prbuf("%s%s %s(#%d)",
-                        inon ? inon == 1 ? "on " : "onto " : "",
-                        com->shp_mcp->m_name, com->shp_name,
-                        com->shp_uid);
-       } else {
-           return prbuf("%s%s #%d",
-                        inon ? inon == 1 ? "on " : "onto " : "",
-                        com->shp_mcp->m_name, com->shp_uid);
-       }
+       return prbuf("%s%s %s(#%d)",
+                    inon ? inon == 1 ? "on " : "onto " : "",
+                    com->shp_mcp->m_name, com->shp_name,
+                    com->shp_uid);
     } else if (com->type == EF_LAND) {
        return prbuf("%s%s #%d",
                     inon ? inon == 1 ? "on " : "onto " : "",
@@ -158,39 +154,6 @@ prcom(int inon, struct combat *com)
     return pr_com(inon, com, player->cnum);
 }
 
-/* Doing a sneak attack */
-static void
-do_sneak(struct combat *def, int success)
-{
-    struct sctstr sect;
-    struct natstr *natp = getnatp(player->cnum);
-    int issneak = getrel(natp, def->own);
-
-    if (def->type != EF_SECTOR)
-       return;
-
-    getsect(def->x, def->y, &sect);
-
-    if (issneak == AT_WAR || !def->own || sect.sct_oldown == player->cnum)
-       return;
-
-    if (success)
-       pr("Your sneak attack was successful\nBut ");
-    else
-       pr("Your sneak attack was unsuccessful\nAnd ");
-
-    pr("it will cost you $5000\n");
-    pr("War has been declared!!!!\n");
-    wu(0, def->own, "Country %s (#%d) has Sneak Attacked!!\n",
-       cname(player->cnum), player->cnum);
-    wu(0, def->own, "Country %s (#%d) has Declared WAR on you!!\n",
-       cname(player->cnum), player->cnum);
-    player->dolcost += 5000;
-    issneak = min(issneak, MOBILIZATION);
-    nreport(player->cnum, N_DECL_WAR, def->own, 1);
-    setrel(player->cnum, def->own, issneak);
-}
-
 /*
  * This is the combat object "type" based integrity check.  It basically
  * splits along three divisions: ship/sector, attacker/defender, 
@@ -227,7 +190,7 @@ att_get_combat(struct combat *com, int isdef)
        y = com->y;
        break;
     case EF_LAND:
-       if (!getland(com->lnd_uid, &land)) {
+       if (!getland(com->lnd_uid, &land) || !land.lnd_own) {
            if (isdef)
                pr("Land unit #%d is not in the same sector!\n",
                   com->lnd_uid);
@@ -266,8 +229,7 @@ att_get_combat(struct combat *com, int isdef)
            return att_combat_init(com, EF_BAD);
        }
        com->shp_mcp = &mchr[(int)ship.shp_type];
-       if (opt_SHIPNAMES)
-           strncpy(com->shp_name, ship.shp_name, MAXSHPNAMLEN);
+       strncpy(com->shp_name, ship.shp_name, MAXSHPNAMLEN);
        if (!isdef && !player->owner) {
            if (com->set)
                pr("%s was just sunk!\n", prcom(0, com));
@@ -300,7 +262,7 @@ att_get_combat(struct combat *com, int isdef)
            else if (mil == 1)
                pr("Only 1 mil %s\n", prcom(1, com));
            /* don't abandon attacking sectors or ships */
-           com->troops = max(0, mil - 1);
+           com->troops = MAX(0, mil - 1);
        }
        com->plague = pstage == PLG_INFECT;
     } else {                   /* not first time */
@@ -335,8 +297,8 @@ att_get_combat(struct combat *com, int isdef)
            }
            if (com->troops && com->troops + 1 > mil) {
                if (com->own == owner && player->cnum == owner) /* not a takeover */
-                   pr("WARNING: Your mil %s has been reduced from %d to %d!\n", prcom(1, com), com->troops, max(0, mil - 1));
-               com->troops = max(0, mil - 1);
+                   pr("WARNING: Your mil %s has been reduced from %d to %d!\n", prcom(1, com), com->troops, MAX(0, mil - 1));
+               com->troops = MAX(0, mil - 1);
            }
        }
     }
@@ -483,7 +445,7 @@ int
 att_abort(int combat_mode, struct combat *off, struct combat *def)
 {
     struct sctstr sect;
-    int issneak;
+    int rel;
     s_char y_or_n[512];
     struct natstr *natp;
 
@@ -562,40 +524,19 @@ att_abort(int combat_mode, struct combat *off, struct combat *def)
     }
     if (opt_SLOW_WAR && def->own != player->cnum) {
        natp = getnatp(player->cnum);
-       issneak = getrel(natp, def->own);
+       rel = getrel(natp, def->own);
 
-       if (issneak == ALLIED) {
+       if (rel == ALLIED) {
            sprintf(y_or_n, "Sector is owned by %s, your ally, %s [yn]? ",
                    cname(def->own), att_mode[combat_mode]);
            if (!confirm(y_or_n))
                return abort_attack();
 
        }
-       if (opt_SNEAK_ATTACK) {
-           getsect(def->x, def->y, &sect);
-           if ((issneak != AT_WAR) && (def->own)
-               && (def->own != player->cnum)
-               && (sect.sct_oldown != player->cnum)
-               && (issneak != SITZKRIEG) && (issneak != MOBILIZATION)) {
-               pr("You're not at war with them!\n");
-               if (!confirm("Do you really want to sneak attack (it will cost you $5000) [yn]? ")) {
-                   pr("Sneak attack cancelled!\n");
-                   return abort_attack();
-               }
-           }
-           if ((issneak != AT_WAR) && (def->own)
-               && (def->own != player->cnum)
-               && (sect.sct_oldown != player->cnum)
-               && ((issneak == MOBILIZATION) || (issneak == SITZKRIEG))) {
-               pr("You're not at war with them!\n");
-               return abort_attack();
-           }
-       } else {
-           if ((issneak != AT_WAR) && (def->own) &&
-               (sect.sct_oldown != player->cnum)) {
-               pr("You're not at war with them!\n");
-               return abort_attack();
-           }
+       if ((rel != AT_WAR) && (def->own) &&
+           (sect.sct_oldown != player->cnum)) {
+           pr("You're not at war with them!\n");
+           return abort_attack();
        }
     }
     return 0;
@@ -765,10 +706,10 @@ att_ask_support(int offset, int *fortp, int *shipp, int *landp,
     s_char *p;
     *fortp = *shipp = *landp = *planep = 1;
 
-    if (player->argp[offset] != (s_char *)0) {
-       if ((player->argp[offset + 1] == (s_char *)0) ||
-           (player->argp[offset + 2] == (s_char *)0) ||
-           (player->argp[offset + 3] == (s_char *)0)) {
+    if (player->argp[offset] != NULL) {
+       if ((player->argp[offset + 1] == NULL) ||
+           (player->argp[offset + 2] == NULL) ||
+           (player->argp[offset + 3] == NULL)) {
            pr("If any support arguments are used, all must be!\n");
            return RET_SYN;
        }
@@ -906,17 +847,17 @@ calc_mobcost(int combat_mode, struct combat *off, struct combat *def,
     switch (combat_mode) {
     case A_ATTACK:
        off->mobcost +=
-           max(1,
+           MAX(1,
                (int)(attacking_mil *
                      sector_mcost(getsectp(def->x, def->y), MOB_ROAD)));
        break;
     case A_LBOARD:
-       off->mobcost += max(1, attacking_mil / 5);
+       off->mobcost += MAX(1, attacking_mil / 5);
        break;
     case A_BOARD:
        switch (off->type) {
        case EF_SECTOR:
-           off->mobcost += max(1, attacking_mil / 5);
+           off->mobcost += MAX(1, attacking_mil / 5);
            break;
        case EF_SHIP:
            /* the 2 in the formula below is a fudge factor */
@@ -958,7 +899,7 @@ ask_off(int combat_mode, struct combat *off, struct combat *def)
     if (att_get_combat(off, 0) <= 0)
        return 0;
     if ((attacking_mil =
-        min(attacking_mil, min(mob_support, off->troops))) <= 0)
+        MIN(attacking_mil, MIN(mob_support, off->troops))) <= 0)
        return 0;
 
     calc_mobcost(combat_mode, off, def, attacking_mil);
@@ -1739,7 +1680,7 @@ get_mine_dsupport(struct combat *def, int a_engineer)
     getsect(def->x, def->y, &sect);
 
     if (sect.sct_oldown != player->cnum) {
-       mines = min(sect.sct_mines, 20);
+       mines = MIN(sect.sct_mines, 20);
        if (a_engineer)
            mines = ldround(((double)mines / 2.0), 1);
        if (mines > 0) {
@@ -1965,7 +1906,7 @@ att_fight(int combat_mode, struct combat *off, struct emp_qelem *olist,
            /* Make sure we use a positive mobility here */
            tmob = ((def->mob < 0) ? -(def->mob) : (def->mob));
            def->mobcost =
-               min(20, min(1, tmob - damage(tmob, 100 * d_cas / d_mil)));
+               MIN(20, MIN(1, tmob - damage(tmob, 100 * d_cas / d_mil)));
        }
        def->mil = def->troops;
     }
@@ -1975,12 +1916,10 @@ att_fight(int combat_mode, struct combat *off, struct emp_qelem *olist,
        if (off[n].type != EF_BAD && off[n].troops < a_troops[n]) {
            if (off[n].type == EF_SECTOR && off[n].mil)
                off[n].mobcost +=
-                   min(20,
-                       min(1,
-                           off[n].mob - damage(off[n].mob,
-                                               100 * (a_troops[n] -
-                                                      off[n].troops) /
-                                               off[n].mil)));
+                   MIN(20,
+                       off[n].mob - damage(off[n].mob,
+                                           100 * (a_troops[n] - off[n].troops)
+                                           / off[n].mil));
            off[n].mil -= a_troops[n] - off[n].troops;
        }
 
@@ -2066,10 +2005,6 @@ att_fight(int combat_mode, struct combat *off, struct emp_qelem *olist,
           action, pr_com(0, def, def->own), d_cas);
     }
 
-    if (opt_SNEAK_ATTACK) {
-       do_sneak(def, success);
-    }
-
     send_reacting_units_home(dlist);
 
     /* putland the defending land */
@@ -2520,7 +2455,7 @@ ask_move_in_off(struct combat *off, struct combat *def)
     if (off->own != player->cnum)
        return;
     d = sector_mcost(getsectp(def->x, def->y), MOB_ROAD);
-    if ((mob_support = min(off->troops, (int)(off->mob / d))) <= 0)
+    if ((mob_support = MIN(off->troops, (int)(off->mob / d))) <= 0)
        return;
     sprintf(prompt, "How many mil to move in from %s (%d max)? ",
            xyas(off->x, off->y, player->cnum), mob_support);
@@ -2535,13 +2470,13 @@ ask_move_in_off(struct combat *off, struct combat *def)
        return;
     if (att_get_combat(def, 0) < 0)
        return;
-    if ((num_mil = min(off->troops, num_mil)) <= 0) {
+    if ((num_mil = MIN(off->troops, num_mil)) <= 0) {
        pr("No mil moved in from %s\n",
           xyas(off->x, off->y, player->cnum));
        return;
     }
-    mob_support = max(1, (int)(num_mil * d));
-    off->mob -= min(off->mob, mob_support);
+    mob_support = MAX(1, (int)(num_mil * d));
+    off->mob -= MIN(off->mob, mob_support);
     off->mil -= num_mil;
     off->troops -= num_mil;
     put_combat(off);