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 * expl.c: Take over unoccupied sectors
30 * Known contributors to this file:
46 static int explore_map(s_char *what, coord curx, coord cury, s_char *arg);
53 struct sctstr endsect;
55 struct sctstr chksect;
75 whatitem(player->argp[1], "explore with what? (civ/mil) ")) == 0)
78 if ((vtype != V_CIVIL) && (vtype != V_MILIT)) {
79 pr("You can only explore with civs and mil.\n");
82 if ((p = getstarg(player->argp[2], "from sector : ", buf)) == 0)
84 if (!sarg_xy(p, &x, &y))
86 if (!getsect(x, y, §) || !player->owner) {
90 infected = sect.sct_pstage == PLG_INFECT;
91 if ((amt_src = sect.sct_item[vtype]) <= 0) {
92 pr("No %s in %s\n", ip->i_name,
93 xyas(sect.sct_x, sect.sct_y, player->cnum));
97 mob = (int)sect.sct_mobil;
98 if (vtype == V_CIVIL && sect.sct_oldown != own) {
99 pr("You can't explore with conquered populace!\n");
103 pr("No mobility in %s\n",
104 xyas(sect.sct_x, sect.sct_y, player->cnum));
107 if (vtype == V_CIVIL) {
108 work = sect.sct_work;
110 pr("Warning: civil unrest\n");
111 loyal = sect.sct_loyal;
112 } else if (vtype == V_MILIT) {
116 sprintf(prompt, "Number of %s to explore with? (max %d) ",
117 ip->i_name, amt_src);
118 amount = onearg(player->argp[3], prompt);
119 if (!check_sect_ok(§))
121 if (amount > amt_src) {
123 pr("Only exploring with %d.\n", amount);
126 if (!want_to_abandon(§, vtype, amount, 0)) {
127 pr("Explore cancelled.\n");
131 if (!check_sect_ok(§))
136 weight = amount * ip->i_lbs;
137 /* remove commodities from source sector */
138 getsect(x, y, &start);
139 amt_src = start.sct_item[vtype];
142 pr("%s in %s are gone!\n", ip->i_name,
143 xyas(start.sct_x, start.sct_y, player->cnum));
146 start.sct_item[vtype] = amt_src;
147 start.sct_flags |= MOVE_IN_PROGRESS;
150 * Now parse the path and return ending sector.
153 mcost = move_ground((s_char *)ip, §, &endsect,
154 weight, player->argp[4],
155 explore_map, 1, &dam);
158 left = effdamage(amount, dam);
161 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));
163 pr("All of the %s you were exploring with were destroyed!\n", ip->i_name);
169 pr("Total movement cost = %d", mcost);
171 pr("No mobility used");
174 pr("\nExplore aborted");
175 getsect(start.sct_x, start.sct_y, §);
176 sect.sct_mobil = (u_char)mob;
178 /* Charge mobility */
179 getsect(sect.sct_x, sect.sct_y, §);
180 n = sect.sct_mobil - mcost;
183 sect.sct_mobil = (u_char)n;
184 pr(", %d mob left in %s", sect.sct_mobil,
185 xyas(sect.sct_x, sect.sct_y, player->cnum));
187 getsect(endsect.sct_x, endsect.sct_y, §);
193 * Check for a multitude of problems
195 getsect(endsect.sct_x, endsect.sct_y, &chksect);
196 if (chksect.sct_type == '.') {
197 pr("Bridge disappeared!\n");
198 getsect(start.sct_x, start.sct_y, &start);
199 start.sct_flags &= ~MOVE_IN_PROGRESS;
203 if (!player->god && chksect.sct_own && chksect.sct_own != player->cnum
204 && chksect.sct_type != SCT_SANCT) {
205 pr("Somebody beat you there!\n");
206 /* Send them back home */
207 getsect(start.sct_x, start.sct_y, §);
208 if (sect.sct_own != own) {
209 pr("Someone captured the sector you started from!\n");
210 pr("Your exploring people die of disappointment!\n");
211 sect.sct_flags &= ~MOVE_IN_PROGRESS;
217 if (!player->god && !player->owner && sect.sct_type != SCT_SANCT) {
218 takeover(§, player->cnum);
220 sect.sct_oldown = own;
221 sect.sct_work = work;
222 sect.sct_loyal = loyal;
224 if (vtype == V_CIVIL && sect.sct_oldown != player->cnum) {
225 pr("Your civilians don't want to stay!\n");
226 getsect(start.sct_x, start.sct_y, §);
227 if (sect.sct_own != own) {
228 pr("Someone captured the sector you started from!\n");
229 pr("Your exploring people die of disappointment!\n");
230 sect.sct_flags &= ~MOVE_IN_PROGRESS;
235 getsect(start.sct_x, start.sct_y, &start);
236 start.sct_flags &= ~MOVE_IN_PROGRESS;
238 amt_dst = sect.sct_item[vtype];
239 if (32767 - amt_dst < amount) {
240 amount = 32767 - 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 time(§.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 == V_CIVIL) {
265 sect.sct_loyal = ((amt_dst * sect.sct_loyal) +
266 (amount * loyal)) / (amt_dst + amount);
267 sect.sct_work = ((amt_dst * sect.sct_work) +
268 (amount * work)) / (amt_dst + amount);
269 } else { /* ! NEW_WORK */
271 /* It only takes one bad apple... */
272 if (sect.sct_loyal < loyal)
273 sect.sct_loyal = loyal;
274 if (sect.sct_work > work)
275 sect.sct_work = work;
284 explore_map(s_char *what, coord curx, coord cury, s_char *arg)
295 np = getnatp(player->cnum);
296 rel_x = xrel(np, curx);
297 rel_y = yrel(np, cury);
298 sprintf(range, "%d:%d,%d:%d", rel_x - 2, rel_x + 2, rel_y - 1,
300 if (!snxtsct(&ns, range))
303 while (i < 7 && nxtsct(&ns, §)) {
304 view[i] = dchr[sect.sct_type].d_mnem;
305 switch (sect.sct_type) {
313 if (sect.sct_own != player->cnum && !player->god)
317 changed += map_set(player->cnum, ns.x, ns.y, view[i], 0);
321 writemap(player->cnum);
322 if (!getsect(curx, cury, §))
324 pr(" %c %c min gold fert oil uran\n", view[0], view[1]);
325 pr(" %c %c %c %3d %4d %4d %4d %4d\n",
326 view[2], view[3], view[4],
327 sect.sct_min, sect.sct_gmin, sect.sct_fertil, sect.sct_oil,
329 pr(" %c %c\n", view[5], view[6]);