]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/mission.c
Limit nukes to strategic missions
[empserver] / src / lib / subs / mission.c
index 473e012dd5ce021822c435541ac58a5ead90e510..cab8182b0b5c73c0f24f00d695eb0cdb5d02c855 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-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -30,6 +30,7 @@
  *  Known contributors to this file:
  *     Ken Stevens, 1995
  *     Steve McClure, 1996-2000
+ *     Markus Armbruster, 2003-2009
  */
 
 #include <config.h>
@@ -70,7 +71,7 @@ static void divide(struct emp_qelem *, struct emp_qelem *, coord, coord);
 static int dosupport(struct genlist *, coord, coord, natid, natid);
 static int find_airport(struct emp_qelem *, coord, coord);
 static void mission_pln_arm(struct emp_qelem *, coord, coord, int,
-                           int, struct ichrstr *, int);
+                           int, struct ichrstr *);
 static void mission_pln_sel(struct emp_qelem *, int, int, int);
 static int perform_mission(coord, coord, natid, struct emp_qelem *, int,
                           char *, int);
@@ -550,7 +551,7 @@ perform_mission(coord x, coord y, natid victim, struct emp_qelem *list,
        /* I arbitrarily chose 100 mindam -KHS */
        dam +=
            msl_launch_mindam(&missiles, x, y, hardtarget, EF_SECTOR, 100,
-                             "sector", victim, mission);
+                             "sector", victim);
        qp = missiles.q_forw;
        while (qp != (&missiles)) {
            newqp = qp->q_forw;
@@ -609,12 +610,12 @@ perform_mission(coord x, coord y, natid victim, struct emp_qelem *list,
        /* Split off the escorts at this base into e */
        divide(&escorts, &e, air->x, air->y);
 
-       mission_pln_arm(&b, air->x, air->y, 2 * md, 'p', 0, 0);
+       mission_pln_arm(&b, air->x, air->y, 2 * md, 'p', NULL);
 
        if (QEMPTY(&b))
            continue;
 
-       mission_pln_arm(&e, air->x, air->y, 2 * md, 'p', 0, P_F | P_ESC);
+       mission_pln_arm(&e, air->x, air->y, 2 * md, 'e', NULL);
 
        pp = BestAirPath(buf, air->x, air->y, x, y);
        if (CANT_HAPPEN(!pp))
@@ -839,7 +840,7 @@ mission_pln_sel(struct emp_qelem *list, int wantflags, int nowantflags,
  */
 static void
 mission_pln_arm(struct emp_qelem *list, coord x, coord y, int dist,
-               int mission, struct ichrstr *ip, int flags)
+               int mission, struct ichrstr *ip)
 {
     struct emp_qelem *qp;
     struct emp_qelem *next;
@@ -857,21 +858,20 @@ mission_pln_arm(struct emp_qelem *list, coord x, coord y, int dist,
            continue;
 
        if (CANT_HAPPEN(pp->pln_flags & PLN_LAUNCHED)
-           || mission_pln_equip(plp, ip, flags, mission) < 0) {
+           || mission_pln_equip(plp, ip, mission) < 0) {
            emp_remque(qp);
            free(qp);
            continue;
        }
 
        pp->pln_flags |= PLN_LAUNCHED;
-       pp->pln_mobil -= pln_mobcost(dist, pp, flags);
+       pp->pln_mobil -= pln_mobcost(dist, pp, mission);
        putplane(pp->pln_uid, pp);
     }
 }
 
 int
-mission_pln_equip(struct plist *plp, struct ichrstr *ip, int flags,
-                 char mission)
+mission_pln_equip(struct plist *plp, struct ichrstr *ip, char mission)
 {
     struct plchrstr *pcp;
     struct plnstr *pp;
@@ -898,61 +898,45 @@ mission_pln_equip(struct plist *plp, struct ichrstr *ip, int flags,
        return -1;
     }
     item[I_PETROL] -= pcp->pl_fuel;
-    if (!(flags & P_F)) {
-       load = pln_load(pp);
-       itype = I_NONE;
-       needed = 0;
-       switch (mission) {
-       case 's':               /* strategic bomb */
-       case 'p':               /* pinpoint bomb */
-           if (nuk_on_plane(pp) < 0) {
-               itype = I_SHELL;
-               needed = load;
-           }
-           break;
-       case 't':               /* transport */
-       case 'd':               /* drop */
-           if ((pcp->pl_flags & P_C) == 0 || ip == 0)
-               break;
-           itype = ip->i_uid;
-           needed = (load * 2) / ip->i_lbs;
-           break;
-       case 'a':               /* paradrop */
-           if ((pcp->pl_flags & (P_V | P_C)) == 0)
-               break;
-           itype = I_MILIT;
-           needed = load / ip->i_lbs;
-           break;
-       case 'i':               /* missile interception */
-           if (load) {
-               itype = I_SHELL;
-               needed = load;
-           }
-           break;
-       case 'r':               /* reconnaissance */
-       case 0:                 /* plane interception */
-           break;
-       default:
-           CANT_REACH();
-           break;
-       }
-       if (itype != I_NONE && needed <= 0)
+    load = pln_load(pp);
+    itype = I_NONE;
+    switch (mission) {
+    case 'p':          /* pinpoint bomb */
+       itype = I_SHELL;
+       break;
+    case 'i':          /* missile interception */
+       if (load)
+           itype = I_SHELL;
+       break;
+    case 'e':          /* escort */
+    case 0:            /* plane interception */
+       load = 0;
+       break;
+    default:
+       CANT_REACH();
+       load = 0;
+    }
+
+    if (itype != I_NONE) {
+       needed = load / ichr[itype].i_lbs;
+       if (needed <= 0)
+           return -1;
+       if (CANT_HAPPEN(nuk_on_plane(pp) >= 0))
            return -1;
-       if (itype != I_NONE) {
-           if (itype == I_SHELL && item[itype] < needed)
-               item[itype] += supply_commod(plp->plane.pln_own,
-                                            plp->plane.pln_x,
-                                            plp->plane.pln_y,
-                                            I_SHELL, needed);
-           if (item[itype] < needed)
-               return -1;
-           item[itype] -= needed;
+       if (itype == I_SHELL && item[itype] < needed) {
+           if (pp->pln_ship >= 0)
+               shp_supply(&ship, I_SHELL, needed);
+           else if (pp->pln_land >= 0)
+               lnd_supply(&land, I_SHELL, needed);
+           else
+               sct_supply(&sect, I_SHELL, needed);
        }
-       if (itype == I_SHELL && (mission == 's' || mission == 'p'))
-           plp->bombs = needed;
-       else
-           plp->misc = needed;
+       if (item[itype] < needed)
+           return -1;
+       item[itype] -= needed;
+       plp->load = needed;
     }
+
     if (pp->pln_ship >= 0)
        putship(ship.shp_uid, &ship);
     else if (pp->pln_land >= 0)
@@ -1030,7 +1014,6 @@ air_damage(struct emp_qelem *bombers, coord x, coord y, int mission,
     struct plnstr *pp;
     int newdam, dam = 0;
     int hitchance;
-    int nukedam;
 
     for (qp = bombers->q_forw; qp != bombers; qp = qp->q_forw) {
        plp = (struct plist *)qp;
@@ -1039,7 +1022,7 @@ air_damage(struct emp_qelem *bombers, coord x, coord y, int mission,
        if ((mission == MI_SINTERDICT) && !(plp->pcp->pl_flags & P_A))
            continue;
 
-       if (!plp->bombs)
+       if (!plp->load)
            continue;
 
        newdam = 0;
@@ -1069,24 +1052,14 @@ air_damage(struct emp_qelem *bombers, coord x, coord y, int mission,
            hitchance = 100;
        else if (hardtarget != SECT_HARDTARGET)
            wu(0, pp->pln_own, "\t\t%d%% hitchance...", hitchance);
-       /* Always calculate damage */
        if (roll(100) <= hitchance) {
-           newdam = pln_damage(&plp->plane, x, y, 'p', &nukedam, 1);
-           if (nukedam) {
-               if (mission == MI_INTERDICT) {
-                   wu(0, pp->pln_own,
-                      "\t\tnuclear warhead on plane %s does %d damage to %s %s\n",
-                      prplane(pp), nukedam, cname(victim), s);
-                   dam += nukedam;
-               }
-           } else {
-               wu(0, pp->pln_own,
-                  "\t\thit %s %s for %d damage\n",
-                  cname(victim), s, newdam);
-               dam += newdam;
-           }
+           newdam = pln_damage(&plp->plane, 'p', 1);
+           wu(0, pp->pln_own,
+              "\t\thit %s %s for %d damage\n",
+              cname(victim), s, newdam);
+           dam += newdam;
        } else {
-           newdam = pln_damage(&plp->plane, x, y, 'p', &nukedam, 0);
+           newdam = pln_damage(&plp->plane, 'p', 0);
            wu(0, pp->pln_own, "missed\n");
            if (mission == MI_SINTERDICT) {
                mpr(victim,