2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2000, 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 the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23 * related information and legal notices. It is expected that any future
24 * projects/authors will amend these files as needed.
28 * mine.c: Lay mines from ships or units
30 * Known contributors to this file:
47 * format: mine <SHIPS> <NUMBER MINES>
61 if (!snxtitem(&ni, EF_SHIP, player->argp[1]))
64 onearg(player->argp[2], "Drop how many mines from each ship? ");
67 while (nxtitem(&ni, (s_char *)&ship)) {
70 mp = &mchr[(int)ship.shp_type];
71 if ((mp->m_flags & M_MINE) == 0)
73 if ((shells = getvar(V_SHELL, (s_char *)&ship, EF_SHIP)) == 0)
75 mines_avail = min(shells, mines);
76 if (getsect(ship.shp_x, ship.shp_y, §) == 0 ||
77 (sect.sct_type != SCT_WATER && sect.sct_type != SCT_BSPAN)) {
78 pr("You can't lay mines there!!\n");
81 mines_there = getvar(V_MINE, (s_char *)§, EF_SECTOR);
82 putvar(V_SHELL, shells - mines_avail, (s_char *)&ship, EF_SHIP);
83 putvar(V_MINE, mines_avail + mines_there, (s_char *)§,
87 putship(ship.shp_uid, &ship);
88 pr("Laying %d mines from %s\n", mines_avail, prship(&ship));
90 map_set(player->cnum, sect.sct_x, sect.sct_y, 'X', 0))
91 writemap(player->cnum);
97 * format: landmine <UNITS> <NUMBER MINES>
110 int total_mines_laid;
113 if (!snxtitem(&ni, EF_LAND, player->argp[1]))
115 while (nxtitem(&ni, (s_char *)&land)) {
118 lp = &lchr[(int)land.lnd_type];
119 if (!(lp->l_flags & L_ENGINEER))
121 if (land.lnd_mobil < 1) {
122 pr("Unit %d is out of mobility\n", land.lnd_uid);
125 resupply_commod(&land, I_SHELL);
126 if (!(shells = getvar(V_SHELL, (s_char *)&land, EF_LAND)))
128 shells = min(shells, land.lnd_mobil);
129 if (!getsect(land.lnd_x, land.lnd_y, §) ||
130 sect.sct_type == SCT_WATER || sect.sct_type == SCT_BSPAN) {
131 pr("You can't lay mines there!!\n");
134 mines_there = getvar(V_MINE, (s_char *)§, EF_SECTOR);
135 if (sect.sct_own == sect.sct_oldown)
136 pr("There are currently %d mines in %s\n",
137 mines_there, xyas(sect.sct_x, sect.sct_y, player->cnum));
138 sprintf(prompt, "Drop how many mines from %s? ", prland(&land));
139 mines_wanted = onearg(player->argp[2], prompt);
140 if (!check_land_ok(&land))
142 if (mines_wanted <= 0)
144 land.lnd_mission = 0;
145 total_mines_laid = 0;
146 while (shells > 0 && total_mines_laid < mines_wanted) {
147 mines_laid = min(shells, mines_wanted - total_mines_laid);
148 putvar(V_SHELL, shells - mines_laid, (s_char *)&land, EF_LAND);
149 land.lnd_mobil -= mines_laid;
150 putland(land.lnd_uid, &land);
151 resupply_commod(&land, I_SHELL);
152 putland(land.lnd_uid, &land);
153 total_mines_laid += mines_laid;
154 shells = getvar(V_SHELL, (s_char *)&land, EF_LAND);
155 shells = min(shells, land.lnd_mobil);
157 getsect(sect.sct_x, sect.sct_y, §);
158 putvar(V_MINE, total_mines_laid + mines_there, (s_char *)§,
162 pr("%s laid a total of %d mines in %s\n",
163 prland(&land), total_mines_laid,
164 xyas(sect.sct_x, sect.sct_y, land.lnd_own));
166 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));