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:
47 static int explore_map(s_char *what, coord curx, coord cury, s_char *arg);
49 extern int etu_per_update;
50 extern int sect_mob_neg_factor;
56 struct sctstr orig, sect;
57 struct sctstr endsect;
59 struct sctstr chksect;
79 whatitem(player->argp[1], "explore with what? (civ/mil) ")) == 0)
82 if ((vtype != V_CIVIL) && (vtype != V_MILIT)) {
83 pr("You can only explore with civs and mil.\n");
86 if ((p = getstarg(player->argp[2], "from sector : ", buf)) == 0)
88 if (!sarg_xy(p, &x, &y))
90 if (!getsect(x, y, §) || !player->owner) {
94 bcopy((s_char *)§, (s_char *)&orig, sizeof(struct sctstr));
95 infected = getvar(V_PSTAGE, (s_char *)§, EF_SECTOR) == PLG_INFECT;
96 if ((amt_src = getvar(vtype, (s_char *)§, EF_SECTOR)) <= 0) {
97 pr("No %s in %s\n", ip->i_name,
98 xyas(sect.sct_x, sect.sct_y, player->cnum));
102 mob = (int)sect.sct_mobil;
103 if (vtype == V_CIVIL && sect.sct_oldown != own) {
104 pr("You can't explore with conquered populace!\n");
108 pr("No mobility in %s\n",
109 xyas(sect.sct_x, sect.sct_y, player->cnum));
112 if (vtype == V_CIVIL) {
113 work = sect.sct_work;
115 pr("Warning: civil unrest\n");
116 loyal = sect.sct_loyal;
117 } else if (vtype == V_MILIT) {
121 sprintf(prompt, "Number of %s to explore with? (max %d) ",
122 ip->i_name, amt_src);
123 amount = onearg(player->argp[3], prompt);
124 if (!check_sect_ok(§))
126 if (amount > amt_src) {
128 pr("Only exploring with %d.\n", amount);
131 if (!want_to_abandon(§, vtype, amount, 0)) {
132 pr("Explore cancelled.\n");
136 if (!check_sect_ok(§))
141 weight = amount * ip->i_lbs;
142 /* remove commodities from source sector */
143 getsect(x, y, &start);
144 amt_src = getvar(vtype, (s_char *)&start, EF_SECTOR);
147 pr("%s in %s are gone!\n", ip->i_name,
148 xyas(start.sct_x, start.sct_y, player->cnum));
151 putvar(vtype, amt_src, (s_char *)&start, EF_SECTOR);
152 start.sct_flags |= MOVE_IN_PROGRESS;
155 * Now parse the path and return ending sector.
158 mcost = move_ground((s_char *)ip, §, &endsect,
159 (double)sect.sct_mobil, weight, player->argp[4],
160 explore_map, 1, &dam);
163 left = effdamage(amount, dam);
166 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));
168 pr("All of the %s you were exploring with were destroyed!\n", ip->i_name);
174 pr("Total movement cost = %d", mcost);
176 pr("No mobility used");
179 pr("\nExplore aborted");
180 getsect(start.sct_x, start.sct_y, §);
181 sect.sct_mobil = (u_char)mob;
183 /* Charge mobility */
184 getsect(sect.sct_x, sect.sct_y, §);
185 n = sect.sct_mobil - mcost;
188 sect.sct_mobil = (u_char)n;
189 pr(", %d mob left in %s", sect.sct_mobil,
190 xyas(sect.sct_x, sect.sct_y, player->cnum));
192 getsect(endsect.sct_x, endsect.sct_y, §);
198 * Check for a multitude of problems
200 getsect(endsect.sct_x, endsect.sct_y, &chksect);
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 xback 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 (void)takeover(§, player->cnum);
225 sect.sct_oldown = own;
226 sect.sct_work = work;
227 sect.sct_loyal = loyal;
229 if (vtype == V_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 getsect(start.sct_x, start.sct_y, &start);
241 start.sct_flags &= ~MOVE_IN_PROGRESS;
243 amt_dst = getvar(vtype, (s_char *)§, EF_SECTOR);
244 if (32767 - amt_dst < amount) {
245 amount = 32767 - amt_dst;
246 pr("Only %d can be left there.\n", amount);
248 getsect(start.sct_x, start.sct_y, §);
250 if (putvar(vtype, amount + amt_dst, (s_char *)§, EF_SECTOR) < 0) {
251 pr("No more room in %s.\n",
252 xyas(sect.sct_x, sect.sct_y, player->cnum));
256 * Now add commodities to destination sector,
257 * along with plague that came along for the ride.
258 * Takeover unowned sectors if not deity.
260 if (!player->god && sect.sct_type != SCT_SANCT && justtook) {
261 pr("Sector %s is now yours.\n",
262 xyas(sect.sct_x, sect.sct_y, player->cnum));
263 if (opt_MOB_ACCESS) {
264 time(§.sct_access);
265 sect.sct_mobil = -(etu_per_update / sect_mob_neg_factor);
270 if (infected && getvar(V_PSTAGE, (s_char *)§, EF_SECTOR) == 0)
271 putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)§, EF_SECTOR);
272 if (vtype == V_CIVIL) {
274 sect.sct_loyal = ((amt_dst * sect.sct_loyal) +
275 (amount * loyal)) / (amt_dst + amount);
276 sect.sct_work = ((amt_dst * sect.sct_work) +
277 (amount * work)) / (amt_dst + amount);
278 } else { /* ! NEW_WORK */
280 /* It only takes one bad apple... */
281 if (sect.sct_loyal < loyal)
282 sect.sct_loyal = loyal;
283 if (sect.sct_work > work)
284 sect.sct_work = work;
293 explore_map(s_char *what, coord curx, coord cury, s_char *arg)
304 np = getnatp(player->cnum);
305 rel_x = xrel(np, curx);
306 rel_y = yrel(np, cury);
307 sprintf(range, "%d:%d,%d:%d", rel_x - 2, rel_x + 2, rel_y - 1,
309 if (!snxtsct(&ns, range))
312 while (i < 7 && nxtsct(&ns, §)) {
313 view[i] = dchr[sect.sct_type].d_mnem;
314 switch (sect.sct_type) {
322 if (sect.sct_own != player->cnum && !player->god)
326 changed += map_set(player->cnum, ns.x, ns.y, view[i], 0);
330 writemap(player->cnum);
331 if (!getsect(curx, cury, §))
333 pr(" %c %c min gold fert oil uran\n", view[0], view[1]);
334 pr(" %c %c %c %3d %4d %4d %4d %4d\n",
335 view[2], view[3], view[4],
336 sect.sct_min, sect.sct_gmin, sect.sct_fertil, sect.sct_oil,
338 pr(" %c %c\n", view[5], view[6]);