2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2012, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure, Markus Armbruster
6 * Empire is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * See files README, COPYING and CREDITS in the root of the source
22 * tree for related information and legal notices. It is expected
23 * that future projects/authors will amend these files as needed.
27 * mine.c: Lay mines from ships or units
29 * Known contributors to this file:
30 * Markus Armbruster, 2004-2010
41 * format: mine <SHIPS> <NUMBER MINES>
54 if (!snxtitem(&ni, EF_SHIP, player->argp[1], NULL))
56 mines = onearg(player->argp[2],
57 "Drop how many mines from each ship? ");
60 while (nxtitem(&ni, &ship)) {
63 mp = &mchr[(int)ship.shp_type];
64 if ((mp->m_flags & M_MINE) == 0)
66 if ((shells = ship.shp_item[I_SHELL]) == 0)
68 mines_avail = MIN(shells, mines);
69 if (getsect(ship.shp_x, ship.shp_y, §) == 0 ||
70 sect.sct_type != SCT_WATER) {
71 pr("You can't lay mines there!!\n");
74 sect.sct_mines = MIN(sect.sct_mines + mines_avail, MINES_MAX);
75 ship.shp_item[I_SHELL] = shells - mines_avail;
78 putship(ship.shp_uid, &ship);
79 pr("Laying %d mines from %s\n", mines_avail, prship(&ship));
81 map_set(player->cnum, sect.sct_x, sect.sct_y, 'X', 0))
82 writemap(player->cnum);
88 * format: landmine <UNITS> <NUMBER MINES>
102 if (!snxtitem(&ni, EF_LAND, player->argp[1], NULL))
104 while (nxtitem(&ni, &land)) {
107 if (!(lchr[land.lnd_type].l_flags & L_ENGINEER))
109 if (land.lnd_ship >= 0 || land.lnd_land >= 0) {
110 pr("%s is on a %s\n", prland(&land),
111 land.lnd_ship >= 0 ? "ship" : "land unit");
114 if (land.lnd_mobil < 1) {
115 pr("%s is out of mobility\n", prland(&land));
118 if (!getsect(land.lnd_x, land.lnd_y, §)
119 || SCT_MINES_ARE_SEAMINES(§)
120 || sect.sct_own != land.lnd_own) {
121 pr("You can't lay mines there!!\n");
124 if (sect.sct_own == sect.sct_oldown)
125 pr("There are currently %d mines in %s\n",
126 sect.sct_mines, xyas(sect.sct_x, sect.sct_y, player->cnum));
127 sprintf(prompt, "Drop how many mines from %s? ", prland(&land));
128 mines_wanted = onearg(player->argp[2], prompt);
129 if (mines_wanted < 0)
131 if (mines_wanted == 0)
133 if (!check_land_ok(&land) || !check_sect_ok(§))
135 land.lnd_mission = 0;
136 todo = MIN(mines_wanted, land.lnd_mobil);
137 total_mines_laid = 0;
139 lnd_supply(&land, I_SHELL, todo);
140 mines_laid = MIN(todo, land.lnd_item[I_SHELL]);
141 land.lnd_item[I_SHELL] -= mines_laid;
142 land.lnd_mobil -= mines_laid;
143 putland(land.lnd_uid, &land);
144 total_mines_laid += mines_laid;
146 } while (todo && mines_laid);
147 lnd_supply_all(&land);
148 getsect(sect.sct_x, sect.sct_y, §);
149 sect.sct_mines = MIN(sect.sct_mines + total_mines_laid, MINES_MAX);
151 if (total_mines_laid == mines_wanted) {
152 pr("%s laid a total of %d mines in %s",
153 prland(&land), total_mines_laid,
154 xyas(sect.sct_x, sect.sct_y, player->cnum));
155 if (!land.lnd_item[I_SHELL])
156 pr(" but is now out of shells\n");
160 pr("%s ran out of %s before it could finish the job\n"
161 "Only %d mines were laid in %s\n",
163 land.lnd_mobil > 0 ? "shells" : "mobility",
165 xyas(sect.sct_x, sect.sct_y, player->cnum));