2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
6 * This program 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 2 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, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * See files README, COPYING and CREDITS in the root of the source
23 * tree for related information and legal notices. It is expected
24 * that future projects/authors will amend these files as needed.
28 * mine.c: Lay mines from ships or units
30 * Known contributors to this file:
31 * Markus Armbruster, 2004-2009
42 * format: mine <SHIPS> <NUMBER MINES>
55 if (!snxtitem(&ni, EF_SHIP, player->argp[1], NULL))
57 mines = onearg(player->argp[2],
58 "Drop how many mines from each ship? ");
61 while (nxtitem(&ni, &ship)) {
64 mp = &mchr[(int)ship.shp_type];
65 if ((mp->m_flags & M_MINE) == 0)
67 if ((shells = ship.shp_item[I_SHELL]) == 0)
69 mines_avail = MIN(shells, mines);
70 if (getsect(ship.shp_x, ship.shp_y, §) == 0 ||
71 sect.sct_type != SCT_WATER) {
72 pr("You can't lay mines there!!\n");
75 sect.sct_mines = MIN(sect.sct_mines + mines_avail, MINES_MAX);
76 ship.shp_item[I_SHELL] = shells - mines_avail;
79 putship(ship.shp_uid, &ship);
80 pr("Laying %d mines from %s\n", mines_avail, prship(&ship));
82 map_set(player->cnum, sect.sct_x, sect.sct_y, 'X', 0))
83 writemap(player->cnum);
89 * format: landmine <UNITS> <NUMBER MINES>
100 int total_mines_laid;
103 if (!snxtitem(&ni, EF_LAND, player->argp[1], NULL))
105 while (nxtitem(&ni, &land)) {
108 if (!(lchr[land.lnd_type].l_flags & L_ENGINEER))
110 if (land.lnd_ship >= 0 || land.lnd_land >= 0) {
111 pr("%s is on a %s\n", prland(&land),
112 land. lnd_ship >= 0 ? "ship" : "land unit");
115 if (land.lnd_mobil < 1) {
116 pr("%s is out of mobility\n", prland(&land));
119 if (!getsect(land.lnd_x, land.lnd_y, §)
120 || SCT_MINES_ARE_SEAMINES(§)
121 || sect.sct_own != land.lnd_own) {
122 pr("You can't lay mines there!!\n");
125 if (sect.sct_own == sect.sct_oldown)
126 pr("There are currently %d mines in %s\n",
127 sect.sct_mines, xyas(sect.sct_x, sect.sct_y, player->cnum));
128 sprintf(prompt, "Drop how many mines from %s? ", prland(&land));
129 mines_wanted = onearg(player->argp[2], prompt);
130 if (mines_wanted < 0)
132 if (mines_wanted == 0)
134 if (!check_land_ok(&land) || !check_sect_ok(§))
136 land.lnd_mission = 0;
137 todo = MIN(mines_wanted, land.lnd_mobil);
138 total_mines_laid = 0;
140 lnd_supply(&land, I_SHELL, todo);
141 mines_laid = MIN(todo, land.lnd_item[I_SHELL]);
142 land.lnd_item[I_SHELL] -= mines_laid;
143 land.lnd_mobil -= mines_laid;
144 putland(land.lnd_uid, &land);
145 total_mines_laid += mines_laid;
147 } while (todo && mines_laid);
148 lnd_supply_all(&land);
149 getsect(sect.sct_x, sect.sct_y, §);
150 sect.sct_mines = MIN(sect.sct_mines + total_mines_laid, MINES_MAX);
152 if (total_mines_laid == mines_wanted) {
153 pr("%s laid a total of %d mines in %s",
154 prland(&land), total_mines_laid,
155 xyas(sect.sct_x, sect.sct_y, land.lnd_own));
156 if (!land.lnd_item[I_SHELL])
157 pr(" but is now out of shells\n");
161 pr("%s ran out of %s before it could finish the job\n"
162 "Only %d mines were laid in %s\n",
164 land.lnd_mobil > 0 ? "shells" : "mobility",
166 xyas(sect.sct_x, sect.sct_y, land.lnd_own));