]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/mine.c
Update copyright notice
[empserver] / src / lib / commands / mine.c
index 3e8601c17a708470e3e45e70410add294f382453..bef2f4ffbf6a350fcdee45dd959edf2eae0d4254 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2009, 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
@@ -28,7 +28,7 @@
  *  mine.c: Lay mines from ships or units
  *
  *  Known contributors to this file:
- *
+ *     Markus Armbruster, 2004-2009
  */
 
 #include <config.h>
@@ -68,7 +68,7 @@ mine(void)
            continue;
        mines_avail = MIN(shells, mines);
        if (getsect(ship.shp_x, ship.shp_y, &sect) == 0 ||
-           (sect.sct_type != SCT_WATER && sect.sct_type != SCT_BSPAN)) {
+           sect.sct_type != SCT_WATER) {
            pr("You can't lay mines there!!\n");
            continue;
        }
@@ -93,9 +93,8 @@ landmine(void)
 {
     struct lndstr land;
     struct sctstr sect;
-    struct lchrstr *lp;
     struct nstr_item ni;
-    int shells;
+    int todo;
     int mines_wanted;
     int mines_laid;
     int total_mines_laid;
@@ -106,8 +105,7 @@ landmine(void)
     while (nxtitem(&ni, &land)) {
        if (!player->owner)
            continue;
-       lp = &lchr[(int)land.lnd_type];
-       if (!(lp->l_flags & L_ENGINEER))
+       if (!(lchr[land.lnd_type].l_flags & L_ENGINEER))
            continue;
        if (land.lnd_ship >= 0 || land.lnd_land >= 0) {
            pr("%s is on a %s\n", prland(&land),
@@ -118,13 +116,9 @@ landmine(void)
            pr("%s is out of mobility\n", prland(&land));
            continue;
        }
-       resupply_commod(&land, I_SHELL);
-       putland(land.lnd_uid, &land);
-       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)
+           || SCT_MINES_ARE_SEAMINES(&sect)
+           || sect.sct_own != land.lnd_own) {
            pr("You can't lay mines there!!\n");
            continue;
        }
@@ -140,18 +134,18 @@ landmine(void)
        if (!check_land_ok(&land) || !check_sect_ok(&sect))
            continue;
        land.lnd_mission = 0;
+       todo = MIN(mines_wanted, land.lnd_mobil);
        total_mines_laid = 0;
-       while (shells > 0 && total_mines_laid < mines_wanted) {
-           mines_laid = MIN(shells, mines_wanted - total_mines_laid);
-           land.lnd_item[I_SHELL] = shells - mines_laid;
+       do {
+           lnd_supply(&land, I_SHELL, todo);
+           mines_laid = MIN(todo, land.lnd_item[I_SHELL]);
+           land.lnd_item[I_SHELL] -= mines_laid;
            land.lnd_mobil -= mines_laid;
            putland(land.lnd_uid, &land);
-           resupply_commod(&land, I_SHELL);    /* Get more shells */
-           putland(land.lnd_uid, &land);
            total_mines_laid += mines_laid;
-           shells = land.lnd_item[I_SHELL];
-           shells = MIN(shells, land.lnd_mobil);
-       }
+           todo -= mines_laid;
+       } while (todo && mines_laid);
+       lnd_supply_all(&land);
        getsect(sect.sct_x, sect.sct_y, &sect);
        sect.sct_mines = MIN(sect.sct_mines + total_mines_laid, MINES_MAX);
        putsect(&sect);