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;
78 if ((ip = whatitem(player->argp[1], "explore with what? (civ/mil) ")) == 0)
81 if ((vtype != V_CIVIL) && (vtype != V_MILIT)) {
82 pr("You can only explore with civs and mil.\n");
85 if ((p = getstarg(player->argp[2], "from sector : ", buf)) == 0)
87 if (!sarg_xy(p, &x, &y))
89 if (!getsect(x, y, §) || !player->owner) {
93 bcopy((s_char *)§,(s_char *)&orig,sizeof(struct sctstr));
94 infected = getvar(V_PSTAGE, (s_char *)§, EF_SECTOR) == PLG_INFECT;
95 if ((amt_src = getvar(vtype, (s_char *)§, EF_SECTOR)) <= 0) {
96 pr("No %s in %s\n", ip->i_name,
97 xyas(sect.sct_x, sect.sct_y, player->cnum));
101 mob = (int)sect.sct_mobil;
102 if (vtype == V_CIVIL && sect.sct_oldown != own) {
103 pr("You can't explore with conquered populace!\n");
107 pr("No mobility in %s\n",
108 xyas(sect.sct_x, sect.sct_y, player->cnum));
111 if (vtype == V_CIVIL) {
112 work = sect.sct_work;
114 pr("Warning: civil unrest\n");
115 loyal = sect.sct_loyal;
116 } else if (vtype == V_MILIT) {
120 sprintf(prompt, "Number of %s to explore with? (max %d) ",
121 ip->i_name, amt_src);
122 amount = onearg(player->argp[3], prompt);
123 if (!check_sect_ok(§))
125 if (amount > amt_src) {
127 pr("Only exploring with %d.\n", amount);
130 if (!want_to_abandon(§, vtype, amount, 0)) {
131 pr("Explore cancelled.\n");
135 if (!check_sect_ok(§))
140 weight = amount * ip->i_lbs;
141 /* remove commodities from source sector */
142 getsect(x, y, &start);
143 amt_src = getvar(vtype, (s_char *)&start, EF_SECTOR);
146 pr("%s in %s are gone!\n", ip->i_name,
147 xyas(start.sct_x, start.sct_y, player->cnum));
150 putvar(vtype, amt_src, (s_char *)&start, EF_SECTOR);
151 start.sct_flags |= MOVE_IN_PROGRESS;
154 * Now parse the path and return ending sector.
157 mcost = move_ground((s_char *)ip, §, &endsect,
158 (double)sect.sct_mobil, weight, player->argp[4],
159 explore_map, 1, &dam);
162 left = effdamage(amount, dam);
165 pr("%d of the %s you were exploring with were destroyed!\nOnly %d %s made it to %s\n",
170 xyas(endsect.sct_x, endsect.sct_y, player->cnum));
172 pr("All of the %s you were exploring with were destroyed!\n",ip->i_name);
178 pr("Total movement cost = %d",mcost);
180 pr("No mobility used");
183 pr("\nExplore aborted");
184 getsect(start.sct_x,start.sct_y,§);
185 sect.sct_mobil = (u_char)mob;
187 /* Charge mobility */
188 getsect(sect.sct_x, sect.sct_y, §);
189 n = sect.sct_mobil - mcost;
192 sect.sct_mobil = (u_char)n;
193 pr(", %d mob left in %s", sect.sct_mobil,
194 xyas(sect.sct_x,sect.sct_y,player->cnum));
196 getsect(endsect.sct_x, endsect.sct_y, §);
202 * Check for a multitude of problems
204 getsect(endsect.sct_x, endsect.sct_y, &chksect);
205 if(chksect.sct_type == '.') {
206 pr("Bridge disappeared!\n");
207 getsect(start.sct_x,start.sct_y,&start);
208 start.sct_flags &= ~MOVE_IN_PROGRESS;
212 if(!player->god && chksect.sct_own && chksect.sct_own != player->cnum
213 && chksect.sct_type != SCT_SANCT) {
214 pr("Somebody beat you there!\n");
215 /* Send them xback home */
216 getsect(start.sct_x,start.sct_y,§);
217 if (sect.sct_own != own) {
218 pr("Someone captured the sector you started from!\n");
219 pr("Your exploring people die of disappointment!\n");
220 sect.sct_flags &= ~MOVE_IN_PROGRESS;
226 if (!player->god && !player->owner && sect.sct_type != SCT_SANCT) {
227 (void) takeover(§, player->cnum);
229 sect.sct_oldown = own;
230 sect.sct_work = work;
231 sect.sct_loyal = loyal;
233 if (vtype == V_CIVIL && sect.sct_oldown != player->cnum) {
234 pr("Your civilians don't want to stay!\n");
235 getsect(start.sct_x,start.sct_y,§);
236 if (sect.sct_own != own) {
237 pr("Someone captured the sector you started from!\n");
238 pr("Your exploring people die of disappointment!\n");
239 sect.sct_flags &= ~MOVE_IN_PROGRESS;
244 getsect(start.sct_x,start.sct_y,&start);
245 start.sct_flags &= ~MOVE_IN_PROGRESS;
247 amt_dst = getvar(vtype, (s_char *)§, EF_SECTOR);
248 if (32767 - amt_dst < amount) {
249 amount = 32767 - amt_dst;
250 pr("Only %d can be left there.\n", amount);
252 getsect(start.sct_x,start.sct_y,§);
254 if (putvar(vtype, amount + amt_dst, (s_char *)§, EF_SECTOR) < 0) {
255 pr("No more room in %s.\n",
256 xyas(sect.sct_x, sect.sct_y, player->cnum));
260 * Now add commodities to destination sector,
261 * along with plague that came along for the ride.
262 * Takeover unowned sectors if not deity.
264 if (!player->god && sect.sct_type != SCT_SANCT && justtook) {
265 pr("Sector %s is now yours.\n",
266 xyas(sect.sct_x, sect.sct_y, player->cnum));
267 if (opt_MOB_ACCESS) {
268 time(§.sct_access);
269 sect.sct_mobil = -(etu_per_update / sect_mob_neg_factor);
274 if (infected && getvar(V_PSTAGE, (s_char *)§, EF_SECTOR) == 0)
275 putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)§, EF_SECTOR);
276 if (vtype == V_CIVIL) {
278 sect.sct_loyal =( (amt_dst * sect.sct_loyal) +
279 (amount * loyal) ) / (amt_dst+amount);
280 sect.sct_work =( (amt_dst * sect.sct_work) +
281 (amount * work) ) / (amt_dst+amount);
282 } else { /* ! NEW_WORK */
284 /* It only takes one bad apple... */
285 if (sect.sct_loyal < loyal)
286 sect.sct_loyal = loyal;
287 if (sect.sct_work > work)
288 sect.sct_work = work;
297 explore_map(s_char *what, coord curx, coord cury, s_char *arg)
308 np = getnatp(player->cnum);
309 rel_x = xrel(np, curx);
310 rel_y = yrel(np, cury);
311 sprintf(range, "%d:%d,%d:%d", rel_x-2, rel_x+2, rel_y-1, rel_y+1);
312 if (!snxtsct(&ns, range))
315 while (i < 7 && nxtsct(&ns, §)) {
316 view[i] = dchr[sect.sct_type].d_mnem;
317 switch (sect.sct_type) {
325 if (sect.sct_own != player->cnum && !player->god)
329 changed += map_set(player->cnum, ns.x, ns.y, view[i], 0);
333 writemap(player->cnum);
334 if (!getsect(curx, cury, §))
336 pr(" %c %c min gold fert oil uran\n", view[0], view[1]);
337 pr(" %c %c %c %3d %4d %4d %4d %4d\n",
338 view[2], view[3], view[4],
339 sect.sct_min, sect.sct_gmin, sect.sct_fertil, sect.sct_oil,
341 pr(" %c %c\n", view[5], view[6]);