2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2007, 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:
43 static int explore_map(coord curx, coord cury, char *arg);
50 struct sctstr endsect;
52 struct sctstr chksect;
71 if (!(ip = whatitem(player->argp[1], "explore with what? (civ/mil) ")))
74 if ((vtype != I_CIVIL) && (vtype != I_MILIT)) {
75 pr("You can only explore with civs and mil.\n");
78 if ((p = getstarg(player->argp[2], "from sector : ", buf)) == 0)
80 if (!sarg_xy(p, &x, &y))
82 if (!getsect(x, y, §) || !player->owner) {
86 infected = sect.sct_pstage == PLG_INFECT;
87 if ((amt_src = sect.sct_item[vtype]) <= 0) {
88 pr("No %s in %s\n", ip->i_name,
89 xyas(sect.sct_x, sect.sct_y, player->cnum));
94 if (vtype == I_CIVIL && sect.sct_oldown != own) {
95 pr("You can't explore with conquered populace!\n");
99 pr("No mobility in %s\n",
100 xyas(sect.sct_x, sect.sct_y, player->cnum));
104 /* only used when moving civs; but prevent spurious compiler warnings */
105 work = sect.sct_work;
106 loyal = sect.sct_loyal;
107 if (vtype == I_CIVIL && work != 100)
108 pr("Warning: civil unrest\n");
110 sprintf(prompt, "Number of %s to explore with? (max %d) ",
111 ip->i_name, amt_src);
112 amount = onearg(player->argp[3], prompt);
113 if (!check_sect_ok(§))
115 if (amount > amt_src) {
117 pr("Only exploring with %d.\n", amount);
120 if (!want_to_abandon(§, vtype, amount, 0)) {
121 pr("Explore cancelled.\n");
125 if (!check_sect_ok(§))
130 weight = (double)amount * ip->i_lbs;
131 /* remove commodities from source sector */
132 getsect(x, y, &start);
133 amt_src = start.sct_item[vtype];
136 pr("%s in %s are gone!\n", ip->i_name,
137 xyas(start.sct_x, start.sct_y, player->cnum));
140 start.sct_item[vtype] = amt_src;
141 start.sct_flags |= MOVE_IN_PROGRESS;
144 * Now parse the path and return ending sector.
147 mcost = move_ground(§, &endsect, weight, player->argp[4],
148 explore_map, 1, &dam);
151 left = effdamage(amount, dam);
154 pr("%d of the %s you were exploring with were destroyed!\n"
155 "Only %d %s made it to %s\n",
156 amount - left, ip->i_name, left, ip->i_name,
157 xyas(endsect.sct_x, endsect.sct_y, player->cnum));
159 pr("All of the %s you were exploring with were destroyed!\n",
166 pr("Total movement cost = %d", mcost);
168 pr("No mobility used");
171 pr("\nExplore aborted");
172 getsect(start.sct_x, start.sct_y, §);
173 sect.sct_mobil = mob;
175 /* Charge mobility */
176 getsect(sect.sct_x, sect.sct_y, §);
177 n = sect.sct_mobil - mcost;
181 pr(", %d mob left in %s", sect.sct_mobil,
182 xyas(sect.sct_x, sect.sct_y, player->cnum));
184 getsect(endsect.sct_x, endsect.sct_y, §);
190 * Check for a multitude of problems
192 getsect(endsect.sct_x, endsect.sct_y, &chksect);
194 getsect(start.sct_x, start.sct_y, &start);
195 sect.sct_flags &= ~MOVE_IN_PROGRESS;
199 if (chksect.sct_type == '.') {
200 pr("Bridge disappeared!\n");
201 getsect(start.sct_x, start.sct_y, &start);
202 start.sct_flags &= ~MOVE_IN_PROGRESS;
206 if (!player->god && chksect.sct_own && chksect.sct_own != player->cnum
207 && chksect.sct_type != SCT_SANCT) {
208 pr("Somebody beat you there!\n");
209 /* Send them back home */
210 getsect(start.sct_x, start.sct_y, §);
211 if (sect.sct_own != own) {
212 pr("Someone captured the sector you started from!\n");
213 pr("Your exploring people die of disappointment!\n");
214 sect.sct_flags &= ~MOVE_IN_PROGRESS;
220 if (!player->god && !player->owner && sect.sct_type != SCT_SANCT) {
221 takeover(§, player->cnum);
223 sect.sct_oldown = own;
227 if (vtype == I_CIVIL && sect.sct_oldown != player->cnum) {
228 pr("Your civilians don't want to stay!\n");
229 getsect(start.sct_x, start.sct_y, §);
230 if (sect.sct_own != own) {
231 pr("Someone captured the sector you started from!\n");
232 pr("Your exploring people die of disappointment!\n");
233 sect.sct_flags &= ~MOVE_IN_PROGRESS;
238 amt_dst = sect.sct_item[vtype];
239 if (amount > ITEM_MAX - amt_dst) {
240 amount = ITEM_MAX - amt_dst;
241 pr("Only %d can be left there.\n", amount);
243 getsect(start.sct_x, start.sct_y, §);
245 sect.sct_item[vtype] = amount + amt_dst;
247 * Now add commodities to destination sector,
248 * along with plague that came along for the ride.
249 * Takeover unowned sectors if not deity.
251 if (!player->god && sect.sct_type != SCT_SANCT && justtook) {
252 pr("Sector %s is now yours.\n",
253 xyas(sect.sct_x, sect.sct_y, player->cnum));
254 if (opt_MOB_ACCESS) {
255 game_tick_to_now(§.sct_access);
256 sect.sct_mobil = -(etu_per_update / sect_mob_neg_factor);
261 if (infected && sect.sct_pstage == PLG_HEALTHY)
262 sect.sct_pstage = PLG_EXPOSED;
263 if (vtype == I_CIVIL) {
265 = (amt_dst * sect.sct_loyal + amount * loyal) / (amt_dst + amount);
267 = (amt_dst * sect.sct_work + amount * work) / (amt_dst + amount);
270 getsect(start.sct_x, start.sct_y, &start);
271 start.sct_flags &= ~MOVE_IN_PROGRESS;
278 explore_map(coord curx, coord cury, char *arg)
286 snxtsct_dist(&ns, curx, cury, 1);
288 while (i < 7 && nxtsct(&ns, §)) {
289 /* Nasty: this relies on the iteration order */
290 view[i] = dchr[sect.sct_type].d_mnem;
291 switch (sect.sct_type) {
299 if (sect.sct_own != player->cnum && !player->god)
303 changed += map_set(player->cnum, ns.x, ns.y, view[i], 0);
307 writemap(player->cnum);
308 if (!getsect(curx, cury, §))
310 pr(" %c %c min gold fert oil uran\n", view[0], view[1]);
311 pr(" %c %c %c %3d %4d %4d %4d %4d\n",
312 view[2], view[3], view[4],
313 sect.sct_min, sect.sct_gmin, sect.sct_fertil, sect.sct_oil,
315 pr(" %c %c\n", view[5], view[6]);