]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/laun.c
commands: Rename the command functions
[empserver] / src / lib / commands / laun.c
index a2fa234d83d5497bc579cb11c49e75f8d0f95f71..9e1466b5cb282d0f0d7db4de2d68e115f4af1b8d 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2021, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                Ken Stevens, Steve McClure, Markus Armbruster
  *
  *  Empire is free software: you can redistribute it and/or modify
  *     Dave Pare, 1986
  *     Ken Stevens, 1995
  *     Steve McClure, 1998-2000
- *     Markus Armbruster, 2005-2009
+ *     Markus Armbruster, 2005-2021
  */
 
 #include <config.h>
 
+#include "chance.h"
 #include "commands.h"
 #include "damage.h"
 #include "mission.h"
@@ -42,6 +43,7 @@
 #include "nuke.h"
 #include "optlist.h"
 #include "path.h"
+#include "plague.h"
 #include "plane.h"
 #include "ship.h"
 
@@ -54,7 +56,7 @@ static int msl_equip(struct plnstr *, char);
  * laun <PLANES>
  */
 int
-laun(void)
+c_launch(void)
 {
     struct nstr_item nstr;
     struct plnstr plane;
@@ -86,7 +88,7 @@ laun(void)
        }
        if (opt_MARKET) {
            if (ontradingblock(EF_PLANE, &plane)) {
-               pr("plane #%d inelligible - it's for sale.\n",
+               pr("plane #%d ineligible - it's for sale.\n",
                   plane.pln_uid);
                continue;
            }
@@ -122,7 +124,7 @@ laun(void)
 }
 
 /*
- * Launch anti-sat weapon PP.
+ * Launch anti-sat weapon @pp.
  * Return RET_OK if launched (even when missile explodes),
  * else RET_SYN or RET_FAIL.
  */
@@ -133,15 +135,15 @@ launch_as(struct plnstr *pp)
     struct plnstr plane;
 
     cp = getstarg(player->argp[2], "Target satellite? ", buf);
-    if (!check_plane_ok(pp))
-       return RET_FAIL;
     if (!cp || !*cp)
        return RET_SYN;
+    if (!check_plane_ok(pp))
+       return RET_FAIL;
     if (!getplane(atoi(cp), &plane) || !plane.pln_own
        || !pln_is_in_orbit(&plane)) {
        pr("No such satellite exists!\n");
        return RET_FAIL;
-       /* Can be abused to find satellite ids.  Tolerable.  */
+       /* Can be abused to find satellite IDs.  Tolerable. */
     }
 
     if (mapdist(pp->pln_x, pp->pln_y, plane.pln_x, plane.pln_y)
@@ -149,7 +151,7 @@ launch_as(struct plnstr *pp)
        pr("Range too great!\n");
        return RET_FAIL;
     }
-    if (msl_equip(pp, 'i') < 0)
+    if (msl_equip(pp, 0) < 0)
        return RET_FAIL;
     if (msl_launch(pp, EF_PLANE, prplane(&plane),
                   plane.pln_x, plane.pln_y, plane.pln_own, NULL) < 0)
@@ -167,7 +169,7 @@ launch_as(struct plnstr *pp)
 }
 
 /*
- * Launch missile PP.
+ * Launch missile @pp.
  * Return RET_OK if launched (even when missile explodes),
  * else RET_SYN or RET_FAIL.
  */
@@ -237,7 +239,7 @@ launch_missile(struct plnstr *pp)
        if (getnuke(nuk_on_plane(pp), &nuke))
            detonate(&nuke, sx, sy, pp->pln_flags & PLN_AIRBURST);
        else {
-           dam = pln_damage(pp, 's', 1);
+           dam = pln_damage(pp, 's', "");
            pr("did %d damage in %s\n", PERCENT_DAMAGE(dam),
               xyas(sx, sy, player->cnum));
            if (sect.sct_own != 0) {
@@ -266,22 +268,23 @@ launch_missile(struct plnstr *pp)
                     N_SHP_MISS, N_SHP_SMISS, sublaunch,
                     target_ship.shp_own)) {
            pr("splash\n");
-           dam = pln_damage(pp, 'p', 0);
+           dam = pln_damage(pp, 'p', NULL);
            collateral_damage(target_ship.shp_x, target_ship.shp_y, dam);
            return RET_OK;
        }
-       dam = pln_damage(pp, 'p', 1);
-       check_retreat_and_do_shipdamage(&target_ship, dam);
-       putship(target_ship.shp_uid, &target_ship);
-       getship(target_ship.shp_uid, &target_ship);
-       if (!target_ship.shp_own)
+       dam = pln_damage(pp, 'p', "");
+       shipdamage(&target_ship, dam);
+       if (target_ship.shp_effic < SHIP_MINEFF)
            pr("%s sunk!\n", prship(&target_ship));
+       if (dam && (target_ship.shp_rflags & RET_INJURED))
+           retreat_ship(&target_ship, target_ship.shp_own);
+       putship(target_ship.shp_uid, &target_ship);
     }
     return RET_OK;
 }
 
 /*
- * Launch a satellite.
+ * Launch satellite @pp.
  * Return RET_OK if launched (even when satellite fails),
  * else RET_SYN or RET_FAIL.
  */
@@ -298,10 +301,10 @@ launch_sat(struct plnstr *pp)
 
     pr("\n");
     cp = getstarg(player->argp[2], "Target sector? ", buf);
-    if (!check_plane_ok(pp))
-       return RET_FAIL;
     if (!cp || !*cp)
        return RET_SYN;
+    if (!check_plane_ok(pp))
+       return RET_FAIL;
     if (!sarg_xy(cp, &sx, &sy)) {
        pr("Bad sector designation!\n");
        return RET_SYN;
@@ -329,7 +332,7 @@ launch_sat(struct plnstr *pp)
     }
     i = pp->pln_tech + pp->pln_effic;
     if (chance(1.0 - (i / (i + 50.0)))) {
-       dir = (random() % 6) + 1;
+       dir = DIR_FIRST + roll0(6);
        sx = xnorm(sx + diroff[dir][0]);
        sy = ynorm(sy + diroff[dir][1]);
        pr("Your trajectory was a little off.\n");
@@ -342,6 +345,7 @@ launch_sat(struct plnstr *pp)
     CANT_HAPPEN(pp->pln_flags & PLN_LAUNCHED);
     pp->pln_flags |= PLN_LAUNCHED;
     pp->pln_mobil = pp->pln_mobil > dist ? pp->pln_mobil - dist : 0;
+    pp->pln_ship = pp->pln_land = -1;
     putplane(pp->pln_uid, pp);
     pr("%s positioned over %s, will be ready for use in %d time units\n",
        prplane(pp), xyas(sx, sy, player->cnum),
@@ -354,8 +358,10 @@ msl_equip(struct plnstr *pp, char mission)
 {
     struct plist pl;
 
-    memset(&pl, 0, sizeof(struct plist));
+    pl.load = 0;
+    pl.pstage = PLG_HEALTHY;
     pl.pcp = plchr + pp->pln_type;
     pl.plane = *pp;
+    emp_initque(&pl.queue);
     return pln_equip(&pl, NULL, mission);
 }