2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2021, 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 * expl.c: Take over unoccupied sectors
29 * Known contributors to this file:
42 static int explore_map(coord, coord, char *, char *);
49 struct sctstr endsect;
51 struct sctstr chksect;
70 if (!(ip = whatitem(player->argp[1], "explore with what? (civ/mil) ")))
73 if ((vtype != I_CIVIL) && (vtype != I_MILIT)) {
74 pr("You can only explore with civs and mil.\n");
77 if (!(p = getstarg(player->argp[2], "from sector : ", buf)))
79 if (!sarg_xy(p, &x, &y))
81 if (!getsect(x, y, §) || !player->owner) {
85 infected = sect.sct_pstage == PLG_INFECT;
86 if ((amt_src = sect.sct_item[vtype]) <= 0) {
87 pr("No %s in %s\n", ip->i_name,
88 xyas(sect.sct_x, sect.sct_y, player->cnum));
93 if (vtype == I_CIVIL && sect.sct_oldown != own) {
94 pr("You can't explore with conquered populace!\n");
98 pr("No mobility in %s\n",
99 xyas(sect.sct_x, sect.sct_y, player->cnum));
103 /* only used when moving civs; but prevent spurious compiler warnings */
104 work = sect.sct_work;
105 loyal = sect.sct_loyal;
106 if (vtype == I_CIVIL && work != 100)
107 pr("Warning: civil unrest\n");
109 sprintf(prompt, "Number of %s to explore with? (max %d) ",
110 ip->i_name, amt_src);
111 amount = onearg(player->argp[3], prompt);
114 if (!check_sect_ok(§))
116 if (amount > amt_src) {
118 pr("Only exploring with %d.\n", amount);
121 if (!abandon_askyn(§, vtype, amount, NULL)) {
122 pr("Explore cancelled.\n");
126 if (!check_sect_ok(§))
129 weight = (double)amount * ip->i_lbs;
130 /* remove commodities from source sector */
131 getsect(x, y, &start);
132 amt_src = start.sct_item[vtype];
135 pr("%s in %s are gone!\n", ip->i_name,
136 xyas(start.sct_x, start.sct_y, player->cnum));
139 start.sct_item[vtype] = amt_src;
140 start.sct_flags |= MOVE_IN_PROGRESS;
143 * Now parse the path and return ending sector.
146 mcost = move_ground(§, &endsect, weight, player->argp[4],
147 explore_map, 1, &dam);
150 left = effdamage(amount, dam);
153 pr("%d of the %s you were exploring with were destroyed!\n"
154 "Only %d %s made it to %s\n",
155 amount - left, ip->i_name, left, ip->i_name,
156 xyas(endsect.sct_x, endsect.sct_y, player->cnum));
158 pr("All of the %s you were exploring with were destroyed!\n",
165 pr("Total movement cost = %d", mcost);
167 pr("No mobility used");
170 pr("\nExplore aborted");
171 getsect(start.sct_x, start.sct_y, §);
172 sect.sct_mobil = mob;
174 /* Charge mobility */
175 getsect(sect.sct_x, sect.sct_y, §);
176 n = sect.sct_mobil - mcost;
180 pr(", %d mob left in %s", sect.sct_mobil,
181 xyas(sect.sct_x, sect.sct_y, player->cnum));
183 getsect(endsect.sct_x, endsect.sct_y, §);
189 * Check for a multitude of problems
191 getsect(endsect.sct_x, endsect.sct_y, &chksect);
193 getsect(start.sct_x, start.sct_y, &start);
194 sect.sct_flags &= ~MOVE_IN_PROGRESS;
198 if (chksect.sct_type == SCT_WATER) {
199 pr("Bridge disappeared!\n");
200 getsect(start.sct_x, start.sct_y, &start);
201 start.sct_flags &= ~MOVE_IN_PROGRESS;
205 if (!player->god && chksect.sct_own && chksect.sct_own != player->cnum
206 && chksect.sct_type != SCT_SANCT) {
207 pr("Somebody beat you there!\n");
208 /* Send them back home */
209 getsect(start.sct_x, start.sct_y, §);
210 if (sect.sct_own != own) {
211 pr("Someone captured the sector you started from!\n");
212 pr("Your exploring people die of disappointment!\n");
213 sect.sct_flags &= ~MOVE_IN_PROGRESS;
219 if (!player->god && !player->owner && sect.sct_type != SCT_SANCT) {
220 takeover(§, player->cnum);
222 sect.sct_oldown = own;
226 if (vtype == I_CIVIL && sect.sct_oldown != player->cnum) {
227 pr("Your civilians don't want to stay!\n");
228 getsect(start.sct_x, start.sct_y, §);
229 if (sect.sct_own != own) {
230 pr("Someone captured the sector you started from!\n");
231 pr("Your exploring people die of disappointment!\n");
232 sect.sct_flags &= ~MOVE_IN_PROGRESS;
237 amt_dst = sect.sct_item[vtype];
238 if (amount > ITEM_MAX - amt_dst) {
239 amount = ITEM_MAX - amt_dst;
240 pr("Only %d can be left there.\n", amount);
242 getsect(start.sct_x, start.sct_y, §);
244 sect.sct_item[vtype] = amount + amt_dst;
246 * Now add commodities to destination sector,
247 * along with plague that came along for the ride.
248 * Takeover unowned sectors if not deity.
250 if (!player->god && sect.sct_type != SCT_SANCT && justtook) {
251 pr("Sector %s is now yours.\n",
252 xyas(sect.sct_x, sect.sct_y, player->cnum));
253 if (opt_MOB_ACCESS) {
254 game_tick_to_now(§.sct_access);
255 sect.sct_mobil = -(etu_per_update / sect_mob_neg_factor);
260 if (infected && sect.sct_pstage == PLG_HEALTHY)
261 sect.sct_pstage = PLG_EXPOSED;
262 if (vtype == I_CIVIL) {
264 = (amt_dst * sect.sct_loyal + amount * loyal) / (amt_dst + amount);
266 = (amt_dst * sect.sct_work + amount * work) / (amt_dst + amount);
269 getsect(start.sct_x, start.sct_y, &start);
270 start.sct_flags &= ~MOVE_IN_PROGRESS;
277 explore_map(coord curx, coord cury, char *arg1, char *arg2)
285 snxtsct_dist(&ns, curx, cury, 1);
287 while (i < 7 && nxtsct(&ns, §)) {
288 /* Nasty: this relies on the iteration order */
289 view[i] = dchr[sect.sct_type].d_mnem;
290 switch (sect.sct_type) {
298 if (sect.sct_own != player->cnum && !player->god)
302 changed += map_set(player->cnum, ns.x, ns.y, view[i], 0);
306 writemap(player->cnum);
307 if (!getsect(curx, cury, §))
309 pr(" %c %c min gold fert oil uran\n", view[0], view[1]);
310 pr(" %c %c %c %3d %4d %4d %4d %4d\n",
311 view[2], view[3], view[4],
312 sect.sct_min, sect.sct_gmin, sect.sct_fertil, sect.sct_oil,
314 pr(" %c %c\n", view[5], view[6]);