2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2006, 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 * expl.c: Take over unoccupied sectors
30 * Known contributors to this file:
48 static int explore_map(s_char *what, coord curx, coord cury, s_char *arg);
55 struct sctstr endsect;
57 struct sctstr chksect;
76 if (!(ip = whatitem(player->argp[1], "explore with what? (civ/mil) ")))
79 if ((vtype != I_CIVIL) && (vtype != I_MILIT)) {
80 pr("You can only explore with civs and mil.\n");
83 if ((p = getstarg(player->argp[2], "from sector : ", buf)) == 0)
85 if (!sarg_xy(p, &x, &y))
87 if (!getsect(x, y, §) || !player->owner) {
91 infected = sect.sct_pstage == PLG_INFECT;
92 if ((amt_src = sect.sct_item[vtype]) <= 0) {
93 pr("No %s in %s\n", ip->i_name,
94 xyas(sect.sct_x, sect.sct_y, player->cnum));
98 mob = (int)sect.sct_mobil;
99 if (vtype == I_CIVIL && sect.sct_oldown != own) {
100 pr("You can't explore with conquered populace!\n");
104 pr("No mobility in %s\n",
105 xyas(sect.sct_x, sect.sct_y, player->cnum));
109 /* only used when moving civs; but prevent spurious compiler warnings */
110 work = sect.sct_work;
111 loyal = sect.sct_loyal;
112 if (vtype == I_CIVIL && work != 100)
113 pr("Warning: civil unrest\n");
115 sprintf(prompt, "Number of %s to explore with? (max %d) ",
116 ip->i_name, amt_src);
117 amount = onearg(player->argp[3], prompt);
118 if (!check_sect_ok(§))
120 if (amount > amt_src) {
122 pr("Only exploring with %d.\n", amount);
125 if (!want_to_abandon(§, vtype, amount, 0)) {
126 pr("Explore cancelled.\n");
130 if (!check_sect_ok(§))
135 weight = amount * ip->i_lbs;
136 /* remove commodities from source sector */
137 getsect(x, y, &start);
138 amt_src = start.sct_item[vtype];
141 pr("%s in %s are gone!\n", ip->i_name,
142 xyas(start.sct_x, start.sct_y, player->cnum));
145 start.sct_item[vtype] = amt_src;
146 start.sct_flags |= MOVE_IN_PROGRESS;
149 * Now parse the path and return ending sector.
152 mcost = move_ground((s_char *)ip, §, &endsect,
153 weight, player->argp[4],
154 explore_map, 1, &dam);
157 left = effdamage(amount, dam);
160 pr("%d of the %s you were exploring with were destroyed!\nOnly %d %s made it to %s\n", amount - left, ip->i_name, left, ip->i_name, xyas(endsect.sct_x, endsect.sct_y, player->cnum));
162 pr("All of the %s you were exploring with were destroyed!\n", ip->i_name);
168 pr("Total movement cost = %d", mcost);
170 pr("No mobility used");
173 pr("\nExplore aborted");
174 getsect(start.sct_x, start.sct_y, §);
175 sect.sct_mobil = (u_char)mob;
177 /* Charge mobility */
178 getsect(sect.sct_x, sect.sct_y, §);
179 n = sect.sct_mobil - mcost;
182 sect.sct_mobil = (u_char)n;
183 pr(", %d mob left in %s", sect.sct_mobil,
184 xyas(sect.sct_x, sect.sct_y, player->cnum));
186 getsect(endsect.sct_x, endsect.sct_y, §);
192 * Check for a multitude of problems
194 getsect(endsect.sct_x, endsect.sct_y, &chksect);
196 getsect(start.sct_x, start.sct_y, &start);
197 sect.sct_flags &= ~MOVE_IN_PROGRESS;
201 if (chksect.sct_type == '.') {
202 pr("Bridge disappeared!\n");
203 getsect(start.sct_x, start.sct_y, &start);
204 start.sct_flags &= ~MOVE_IN_PROGRESS;
208 if (!player->god && chksect.sct_own && chksect.sct_own != player->cnum
209 && chksect.sct_type != SCT_SANCT) {
210 pr("Somebody beat you there!\n");
211 /* Send them back home */
212 getsect(start.sct_x, start.sct_y, §);
213 if (sect.sct_own != own) {
214 pr("Someone captured the sector you started from!\n");
215 pr("Your exploring people die of disappointment!\n");
216 sect.sct_flags &= ~MOVE_IN_PROGRESS;
222 if (!player->god && !player->owner && sect.sct_type != SCT_SANCT) {
223 takeover(§, player->cnum);
225 sect.sct_oldown = own;
229 if (vtype == I_CIVIL && sect.sct_oldown != player->cnum) {
230 pr("Your civilians don't want to stay!\n");
231 getsect(start.sct_x, start.sct_y, §);
232 if (sect.sct_own != own) {
233 pr("Someone captured the sector you started from!\n");
234 pr("Your exploring people die of disappointment!\n");
235 sect.sct_flags &= ~MOVE_IN_PROGRESS;
240 amt_dst = sect.sct_item[vtype];
241 if (amount > ITEM_MAX - amt_dst) {
242 amount = ITEM_MAX - amt_dst;
243 pr("Only %d can be left there.\n", amount);
245 getsect(start.sct_x, start.sct_y, §);
247 sect.sct_item[vtype] = amount + amt_dst;
249 * Now add commodities to destination sector,
250 * along with plague that came along for the ride.
251 * Takeover unowned sectors if not deity.
253 if (!player->god && sect.sct_type != SCT_SANCT && justtook) {
254 pr("Sector %s is now yours.\n",
255 xyas(sect.sct_x, sect.sct_y, player->cnum));
256 if (opt_MOB_ACCESS) {
257 time(§.sct_access);
258 sect.sct_mobil = -(etu_per_update / sect_mob_neg_factor);
263 if (infected && sect.sct_pstage == PLG_HEALTHY)
264 sect.sct_pstage = PLG_EXPOSED;
265 if (vtype == I_CIVIL) {
267 = (amt_dst * sect.sct_loyal + amount * loyal) / (amt_dst + amount);
269 = (amt_dst * sect.sct_work + amount * work) / (amt_dst + amount);
272 getsect(start.sct_x, start.sct_y, &start);
273 start.sct_flags &= ~MOVE_IN_PROGRESS;
280 explore_map(s_char *what, coord curx, coord cury, s_char *arg)
291 np = getnatp(player->cnum);
292 rel_x = xrel(np, curx);
293 rel_y = yrel(np, cury);
294 sprintf(range, "%d:%d,%d:%d", rel_x - 2, rel_x + 2, rel_y - 1,
296 if (!snxtsct(&ns, range))
299 while (i < 7 && nxtsct(&ns, §)) {
300 view[i] = dchr[sect.sct_type].d_mnem;
301 switch (sect.sct_type) {
309 if (sect.sct_own != player->cnum && !player->god)
313 changed += map_set(player->cnum, ns.x, ns.y, view[i], 0);
317 writemap(player->cnum);
318 if (!getsect(curx, cury, §))
320 pr(" %c %c min gold fert oil uran\n", view[0], view[1]);
321 pr(" %c %c %c %3d %4d %4d %4d %4d\n",
322 view[2], view[3], view[4],
323 sect.sct_min, sect.sct_gmin, sect.sct_fertil, sect.sct_oil,
325 pr(" %c %c\n", view[5], view[6]);