00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include <config.h>
00035
00036 #include "commands.h"
00037 #include "game.h"
00038 #include "item.h"
00039 #include "map.h"
00040 #include "optlist.h"
00041 #include "plague.h"
00042
00043 static int explore_map(coord curx, coord cury, char *arg);
00044
00045 int
00046 explore(void)
00047 {
00048 int amount;
00049 struct sctstr sect;
00050 struct sctstr endsect;
00051 struct sctstr start;
00052 struct sctstr chksect;
00053 double weight;
00054 int mcost, dam;
00055 int infected;
00056 i_type vtype;
00057 int amt_src;
00058 int amt_dst;
00059 struct ichrstr *ip;
00060 int work;
00061 int loyal;
00062 int own, mob;
00063 int justtook;
00064 coord x, y;
00065 char *p;
00066 int n;
00067 int left;
00068 char buf[1024];
00069 char prompt[128];
00070
00071 if (!(ip = whatitem(player->argp[1], "explore with what? (civ/mil) ")))
00072 return RET_SYN;
00073 vtype = ip->i_uid;
00074 if ((vtype != I_CIVIL) && (vtype != I_MILIT)) {
00075 pr("You can only explore with civs and mil.\n");
00076 return RET_FAIL;
00077 }
00078 if ((p = getstarg(player->argp[2], "from sector : ", buf)) == 0)
00079 return RET_SYN;
00080 if (!sarg_xy(p, &x, &y))
00081 return RET_SYN;
00082 if (!getsect(x, y, §) || !player->owner) {
00083 pr("Not yours\n");
00084 return RET_FAIL;
00085 }
00086 infected = sect.sct_pstage == PLG_INFECT;
00087 if ((amt_src = sect.sct_item[vtype]) <= 0) {
00088 pr("No %s in %s\n", ip->i_name,
00089 xyas(sect.sct_x, sect.sct_y, player->cnum));
00090 return RET_SYN;
00091 }
00092 own = sect.sct_own;
00093 mob = sect.sct_mobil;
00094 if (vtype == I_CIVIL && sect.sct_oldown != own) {
00095 pr("You can't explore with conquered populace!\n");
00096 return RET_SYN;
00097 }
00098 if (mob <= 0) {
00099 pr("No mobility in %s\n",
00100 xyas(sect.sct_x, sect.sct_y, player->cnum));
00101 return RET_SYN;
00102 }
00103
00104
00105 work = sect.sct_work;
00106 loyal = sect.sct_loyal;
00107 if (vtype == I_CIVIL && work != 100)
00108 pr("Warning: civil unrest\n");
00109
00110 sprintf(prompt, "Number of %s to explore with? (max %d) ",
00111 ip->i_name, amt_src);
00112 amount = onearg(player->argp[3], prompt);
00113 if (!check_sect_ok(§))
00114 return RET_FAIL;
00115 if (amount > amt_src) {
00116 amount = amt_src;
00117 pr("Only exploring with %d.\n", amount);
00118 }
00119
00120 if (!want_to_abandon(§, vtype, amount, 0)) {
00121 pr("Explore cancelled.\n");
00122 return RET_FAIL;
00123 }
00124
00125 if (!check_sect_ok(§))
00126 return RET_FAIL;
00127
00128 if (amount <= 0)
00129 return RET_SYN;
00130 weight = (double)amount * ip->i_lbs;
00131
00132 getsect(x, y, &start);
00133 amt_src = start.sct_item[vtype];
00134 amt_src -= amount;
00135 if (amt_src < 0) {
00136 pr("%s in %s are gone!\n", ip->i_name,
00137 xyas(start.sct_x, start.sct_y, player->cnum));
00138 return RET_OK;
00139 }
00140 start.sct_item[vtype] = amt_src;
00141 start.sct_flags |= MOVE_IN_PROGRESS;
00142 putsect(&start);
00143
00144
00145
00146 dam = 1;
00147 mcost = move_ground(§, &endsect, weight, player->argp[4],
00148 explore_map, 1, &dam);
00149
00150 if (dam) {
00151 left = effdamage(amount, dam);
00152 if (left < amount) {
00153 if (left) {
00154 pr("%d of the %s you were exploring with were destroyed!\n"
00155 "Only %d %s made it to %s\n",
00156 amount - left, ip->i_name, left, ip->i_name,
00157 xyas(endsect.sct_x, endsect.sct_y, player->cnum));
00158 } else {
00159 pr("All of the %s you were exploring with were destroyed!\n",
00160 ip->i_name);
00161 }
00162 amount = left;
00163 }
00164 }
00165 if (mcost > 0)
00166 pr("Total movement cost = %d", mcost);
00167 else
00168 pr("No mobility used");
00169
00170 if (mcost < 0) {
00171 pr("\nExplore aborted");
00172 getsect(start.sct_x, start.sct_y, §);
00173 sect.sct_mobil = mob;
00174 } else {
00175
00176 getsect(sect.sct_x, sect.sct_y, §);
00177 n = sect.sct_mobil - mcost;
00178 if (n < 0)
00179 n = 0;
00180 sect.sct_mobil = n;
00181 pr(", %d mob left in %s", sect.sct_mobil,
00182 xyas(sect.sct_x, sect.sct_y, player->cnum));
00183 putsect(§);
00184 getsect(endsect.sct_x, endsect.sct_y, §);
00185 }
00186 pr("\n");
00187 justtook = 0;
00188
00189
00190
00191
00192 getsect(endsect.sct_x, endsect.sct_y, &chksect);
00193 if (amount <= 0) {
00194 getsect(start.sct_x, start.sct_y, &start);
00195 sect.sct_flags &= ~MOVE_IN_PROGRESS;
00196 putsect(§);
00197 return RET_FAIL;
00198 }
00199 if (chksect.sct_type == '.') {
00200 pr("Bridge disappeared!\n");
00201 getsect(start.sct_x, start.sct_y, &start);
00202 start.sct_flags &= ~MOVE_IN_PROGRESS;
00203 putsect(&start);
00204 return RET_FAIL;
00205 }
00206 if (!player->god && chksect.sct_own && chksect.sct_own != player->cnum
00207 && chksect.sct_type != SCT_SANCT) {
00208 pr("Somebody beat you there!\n");
00209
00210 getsect(start.sct_x, start.sct_y, §);
00211 if (sect.sct_own != own) {
00212 pr("Someone captured the sector you started from!\n");
00213 pr("Your exploring people die of disappointment!\n");
00214 sect.sct_flags &= ~MOVE_IN_PROGRESS;
00215 putsect(§);
00216 return RET_FAIL;
00217 }
00218 }
00219
00220 if (!player->god && !player->owner && sect.sct_type != SCT_SANCT) {
00221 takeover(§, player->cnum);
00222 justtook = 1;
00223 sect.sct_oldown = own;
00224 sect.sct_work = 100;
00225 sect.sct_loyal = 0;
00226 }
00227 if (vtype == I_CIVIL && sect.sct_oldown != player->cnum) {
00228 pr("Your civilians don't want to stay!\n");
00229 getsect(start.sct_x, start.sct_y, §);
00230 if (sect.sct_own != own) {
00231 pr("Someone captured the sector you started from!\n");
00232 pr("Your exploring people die of disappointment!\n");
00233 sect.sct_flags &= ~MOVE_IN_PROGRESS;
00234 putsect(§);
00235 return RET_FAIL;
00236 }
00237 }
00238 amt_dst = sect.sct_item[vtype];
00239 if (amount > ITEM_MAX - amt_dst) {
00240 amount = ITEM_MAX - amt_dst;
00241 pr("Only %d can be left there.\n", amount);
00242 if (amount <= 0)
00243 getsect(start.sct_x, start.sct_y, §);
00244 }
00245 sect.sct_item[vtype] = amount + amt_dst;
00246
00247
00248
00249
00250
00251 if (!player->god && sect.sct_type != SCT_SANCT && justtook) {
00252 pr("Sector %s is now yours.\n",
00253 xyas(sect.sct_x, sect.sct_y, player->cnum));
00254 if (opt_MOB_ACCESS) {
00255 game_tick_to_now(§.sct_access);
00256 sect.sct_mobil = -(etu_per_update / sect_mob_neg_factor);
00257 } else {
00258 sect.sct_mobil = 0;
00259 }
00260 }
00261 if (infected && sect.sct_pstage == PLG_HEALTHY)
00262 sect.sct_pstage = PLG_EXPOSED;
00263 if (vtype == I_CIVIL) {
00264 sect.sct_loyal
00265 = (amt_dst * sect.sct_loyal + amount * loyal) / (amt_dst + amount);
00266 sect.sct_work
00267 = (amt_dst * sect.sct_work + amount * work) / (amt_dst + amount);
00268 }
00269 putsect(§);
00270 getsect(start.sct_x, start.sct_y, &start);
00271 start.sct_flags &= ~MOVE_IN_PROGRESS;
00272 putsect(&start);
00273 return RET_OK;
00274 }
00275
00276
00277 static int
00278 explore_map(coord curx, coord cury, char *arg)
00279 {
00280 struct nstr_sect ns;
00281 struct sctstr sect;
00282 char view[7];
00283 int i;
00284 int changed = 0;
00285
00286 snxtsct_dist(&ns, curx, cury, 1);
00287 i = 0;
00288 while (i < 7 && nxtsct(&ns, §)) {
00289
00290 view[i] = dchr[sect.sct_type].d_mnem;
00291 switch (sect.sct_type) {
00292 case SCT_WATER:
00293 case SCT_RURAL:
00294 case SCT_MOUNT:
00295 case SCT_WASTE:
00296 case SCT_PLAINS:
00297 break;
00298 default:
00299 if (sect.sct_own != player->cnum && !player->god)
00300 view[i] = '?';
00301 break;
00302 }
00303 changed += map_set(player->cnum, ns.x, ns.y, view[i], 0);
00304 i++;
00305 }
00306 if (changed)
00307 writemap(player->cnum);
00308 if (!getsect(curx, cury, §))
00309 return RET_FAIL;
00310 pr(" %c %c min gold fert oil uran\n", view[0], view[1]);
00311 pr(" %c %c %c %3d %4d %4d %4d %4d\n",
00312 view[2], view[3], view[4],
00313 sect.sct_min, sect.sct_gmin, sect.sct_fertil, sect.sct_oil,
00314 sect.sct_uran);
00315 pr(" %c %c\n", view[5], view[6]);
00316 return RET_OK;
00317 }