]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/mine.c
Don't permit landmine laying in foreign sectors
[empserver] / src / lib / commands / mine.c
index ec3f459ff2293ad346bb0a7ab81bf2a3a65ed737..7cdd63b6781307d5456f6a700e1d6e8708086d93 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2006, 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
  *
  *  ---
  *
- *  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.
  *
  *  ---
  *
  *  mine.c: Lay mines from ships or units
- * 
+ *
  *  Known contributors to this file:
- *     
+ *
  */
 
 #include <config.h>
 
-#include "misc.h"
-#include "player.h"
-#include "ship.h"
-#include "land.h"
-#include "sect.h"
-#include "nat.h"
-#include "xy.h"
-#include "nsc.h"
-#include "file.h"
 #include "commands.h"
+#include "land.h"
+#include "map.h"
+#include "ship.h"
 
 /*
  * format: mine <SHIPS> <NUMBER MINES>
@@ -58,10 +52,10 @@ mine(void)
     int shells;
     int mines_avail;
 
-    if (!snxtitem(&ni, EF_SHIP, player->argp[1]))
+    if (!snxtitem(&ni, EF_SHIP, player->argp[1], NULL))
        return RET_SYN;
     mines = onearg(player->argp[2],
-                  "Drop how many mines from each ship?  ");
+                  "Drop how many mines from each ship? ");
     if (mines <= 0)
        return RET_SYN;
     while (nxtitem(&ni, &ship)) {
@@ -105,9 +99,9 @@ landmine(void)
     int mines_wanted;
     int mines_laid;
     int total_mines_laid;
-    s_char prompt[128];
+    char prompt[128];
 
-    if (!snxtitem(&ni, EF_LAND, player->argp[1]))
+    if (!snxtitem(&ni, EF_LAND, player->argp[1], NULL))
        return RET_SYN;
     while (nxtitem(&ni, &land)) {
        if (!player->owner)
@@ -115,8 +109,13 @@ landmine(void)
        lp = &lchr[(int)land.lnd_type];
        if (!(lp->l_flags & L_ENGINEER))
            continue;
+       if (land.lnd_ship >= 0 || land.lnd_land >= 0) {
+           pr("%s is on a %s\n", prland(&land),
+              land. lnd_ship >= 0 ? "ship" : "land unit");
+           continue;
+       }
        if (land.lnd_mobil < 1) {
-           pr("Unit %d is out of mobility\n", land.lnd_uid);
+           pr("%s is out of mobility\n", prland(&land));
            continue;
        }
        resupply_commod(&land, I_SHELL);
@@ -124,19 +123,22 @@ landmine(void)
        if (!(shells = land.lnd_item[I_SHELL]))
            continue;
        shells = MIN(shells, land.lnd_mobil);
-       if (!getsect(land.lnd_x, land.lnd_y, &sect) ||
-           sect.sct_type == SCT_WATER || sect.sct_type == SCT_BSPAN) {
+       if (!getsect(land.lnd_x, land.lnd_y, &sect)
+           || sect.sct_type == SCT_WATER || sect.sct_type == SCT_BSPAN
+           || sect.sct_own != land.lnd_own) {
            pr("You can't lay mines there!!\n");
            continue;
        }
        if (sect.sct_own == sect.sct_oldown)
            pr("There are currently %d mines in %s\n",
               sect.sct_mines, xyas(sect.sct_x, sect.sct_y, player->cnum));
-       sprintf(prompt, "Drop how many mines from %s?  ", prland(&land));
+       sprintf(prompt, "Drop how many mines from %s? ", prland(&land));
        mines_wanted = onearg(player->argp[2], prompt);
-       if (!check_land_ok(&land))
+       if (mines_wanted < 0)
+           return RET_FAIL;
+       if (mines_wanted == 0)
            continue;
-       if (mines_wanted <= 0)
+       if (!check_land_ok(&land) || !check_sect_ok(&sect))
            continue;
        land.lnd_mission = 0;
        total_mines_laid = 0;
@@ -158,12 +160,17 @@ landmine(void)
            pr("%s laid a total of %d mines in %s",
               prland(&land), total_mines_laid,
               xyas(sect.sct_x, sect.sct_y, land.lnd_own));
-           if (!shells)
-               pr(" but is now out of supply\n");
+           if (!land.lnd_item[I_SHELL])
+               pr(" but is now out of shells\n");
            else
                pr("\n");
        } else
-           pr("%s ran out of %s before it could finish the job\nOnly %d mines were laid in %s\n", prland(&land), land.lnd_mobil > 0 ? "supply" : "mobility", total_mines_laid, xyas(sect.sct_x, sect.sct_y, land.lnd_own));
+           pr("%s ran out of %s before it could finish the job\n"
+              "Only %d mines were laid in %s\n",
+              prland(&land),
+              land.lnd_mobil > 0 ? "shells" : "mobility",
+              total_mines_laid,
+              xyas(sect.sct_x, sect.sct_y, land.lnd_own));
     }
     return RET_OK;
 }