/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
- * Ken Stevens, Steve McClure
+ * Copyright (C) 1986-2021, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Ken Stevens, Steve McClure, Markus Armbruster
*
- * This program is free software; you can redistribute it and/or modify
+ * Empire is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ---
*
* ---
*
* mine.c: Lay mines from ships or units
- *
+ *
* Known contributors to this file:
- *
+ * Markus Armbruster, 2004-2010
*/
#include <config.h>
* format: mine <SHIPS> <NUMBER MINES>
*/
int
-mine(void)
+c_mine(void)
{
struct shpstr ship;
struct sctstr sect;
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? ");
continue;
mines_avail = MIN(shells, mines);
if (getsect(ship.shp_x, ship.shp_y, §) == 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;
}
* format: landmine <UNITS> <NUMBER MINES>
*/
int
-landmine(void)
+c_lmine(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;
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)
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_mobil < 1) {
- pr("Unit %d is out of mobility\n", land.lnd_uid);
+ 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;
}
- resupply_commod(&land, I_SHELL);
- putland(land.lnd_uid, &land);
- if (!(shells = land.lnd_item[I_SHELL]))
+ if (land.lnd_mobil < 1) {
+ pr("%s is out of mobility\n", prland(&land));
continue;
- shells = MIN(shells, land.lnd_mobil);
- if (!getsect(land.lnd_x, land.lnd_y, §) ||
- sect.sct_type == SCT_WATER || sect.sct_type == SCT_BSPAN) {
+ }
+ if (!getsect(land.lnd_x, land.lnd_y, §)
+ || SCT_MINES_ARE_SEAMINES(§)
+ || sect.sct_own != land.lnd_own) {
pr("You can't lay mines there!!\n");
continue;
}
sect.sct_mines, xyas(sect.sct_x, sect.sct_y, player->cnum));
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(§))
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.sct_mines = MIN(sect.sct_mines + total_mines_laid, MINES_MAX);
putsect(§);
if (total_mines_laid == mines_wanted) {
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");
+ xyas(sect.sct_x, sect.sct_y, player->cnum));
+ 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\n"
"Only %d mines were laid in %s\n",
prland(&land),
- land.lnd_mobil > 0 ? "supply" : "mobility",
+ land.lnd_mobil > 0 ? "shells" : "mobility",
total_mines_laid,
- xyas(sect.sct_x, sect.sct_y, land.lnd_own));
+ xyas(sect.sct_x, sect.sct_y, player->cnum));
}
return RET_OK;
}