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 "map.h"
00038 #include "optlist.h"
00039 #include "path.h"
00040
00041 static long do_desi(struct natstr *natp, char *sects, char *deschar,
00042 long cash, int for_real);
00043
00044 int
00045 desi(void)
00046 {
00047 long cash;
00048 long cost;
00049 struct natstr *natp;
00050
00051 natp = getnatp(player->cnum);
00052 cash = natp->nat_money;
00053 if (player->argp[2]) {
00054 cost = do_desi(natp, player->argp[1], player->argp[2], cash, 0);
00055 if (cost < 0)
00056 return (int)-cost;
00057 if (chkmoney(cost, cash, player->argp[3]))
00058 return RET_SYN;
00059 }
00060 return (int)do_desi(natp, player->argp[1], player->argp[2], cash, 1);
00061 }
00062
00063 static long
00064 do_desi(struct natstr *natp, char *sects, char *deschar, long cash,
00065 int for_real)
00066 {
00067 int n;
00068 char *p;
00069 int breaksanct;
00070 int cap_x;
00071 int cap_y;
00072 int des;
00073 struct nstr_sect nstr;
00074 struct sctstr sect;
00075 struct sctstr check;
00076 char prompt[128];
00077 char buf[1024];
00078 long cost = 0;
00079 int changed = 0;
00080 int warned = 0;
00081
00082 breaksanct = 0;
00083 if (!snxtsct(&nstr, sects)) {
00084 if (for_real)
00085 return (long)RET_SYN;
00086 else
00087 return (long)-RET_SYN;
00088 }
00089 cap_x = natp->nat_xcap;
00090 cap_y = natp->nat_ycap;
00091 while (!player->aborted && nxtsct(&nstr, §)) {
00092 if (!player->owner)
00093 continue;
00094 if (!player->god && dchr[sect.sct_type].d_cost < 0)
00095 continue;
00096 sprintf(prompt, "%s %d%% %s desig? ",
00097 xyas(sect.sct_x, sect.sct_y, player->cnum),
00098 sect.sct_effic, dchr[sect.sct_type].d_name);
00099 if ((p = getstarg(deschar, prompt, buf)) == 0)
00100 continue;
00101
00102 if (!check_sect_ok(§))
00103 continue;
00104
00105 des = sct_typematch(p);
00106 if (des < 0 || (((des == SCT_BSPAN) || (des == SCT_BTOWER)) &&
00107 !player->god)) {
00108 pr("No such designation\n"
00109 "See \"info Sector-types\" for possible designations\n");
00110 if (for_real)
00111 return (long)RET_FAIL;
00112 else
00113 return (long)-RET_FAIL;
00114 }
00115 if (!player->god) {
00116 if (des == SCT_WASTE) {
00117 if (for_real)
00118 pr("Only a nuclear device (or %s) can make a %s!\n",
00119 cname(0), dchr[des].d_name);
00120 continue;
00121 }
00122 if (dchr[des].d_cost < 0) {
00123 if (for_real)
00124 pr("Only %s can make a %s!\n",
00125 cname(0), dchr[des].d_name);
00126 continue;
00127 }
00128 }
00129 if (sect.sct_type == des && sect.sct_newtype == des)
00130 continue;
00131 if (sect.sct_type == SCT_SANCT)
00132 breaksanct++;
00133 if ((des == SCT_HARBR) || (des == SCT_BHEAD)) {
00134 for (n = 1; n <= 6; n++) {
00135 getsect(nstr.x + diroff[n][0],
00136 nstr.y + diroff[n][1], &check);
00137 if (check.sct_type == SCT_WATER)
00138 break;
00139 if (check.sct_type == SCT_BSPAN)
00140 break;
00141 if (check.sct_type == SCT_BTOWER)
00142 break;
00143 }
00144 if (n > 6) {
00145 if (for_real)
00146 pr("%s does not border on water.\n",
00147 xyas(nstr.x, nstr.y, player->cnum));
00148 if (player->god) {
00149 if (for_real)
00150 pr("But if it's what you want ...\n");
00151 } else
00152 continue;
00153 }
00154 }
00155 if (sect.sct_type == SCT_SANCT && !player->god)
00156 continue;
00157 n = sect.sct_type;
00158 if ((sect.sct_newtype != des) && (sect.sct_type != des)
00159 && dchr[des].d_cost > 0) {
00160 if (for_real) {
00161 if (check_cost(!deschar, dchr[des].d_cost, cash, &warned,
00162 player->argp[3]))
00163 break;
00164 } else {
00165 cost += dchr[des].d_cost;
00166 continue;
00167 }
00168 }
00169 if (sect.sct_type != des && (sect.sct_effic < 5 || player->god)) {
00170 if (player->god)
00171 set_coastal(§, sect.sct_type, des);
00172 sect.sct_type = des;
00173 sect.sct_effic = 0;
00174 changed += map_set(player->cnum, sect.sct_x, sect.sct_y,
00175 dchr[des].d_mnem, 0);
00176 }
00177 sect.sct_newtype = des;
00178 putsect(§);
00179 if (sect.sct_x == cap_x && sect.sct_y == cap_y
00180 && des != SCT_CAPIT && des != SCT_SANCT && des != SCT_MOUNT
00181 && for_real)
00182 pr("You have redesignated your capital!\n");
00183 if (opt_EASY_BRIDGES == 0) {
00184 if (n != SCT_BHEAD)
00185 continue;
00186 bridgefall(§, 0);
00187 }
00188 }
00189 if (for_real) {
00190 if (changed)
00191 writemap(player->cnum);
00192 if (breaksanct)
00193 bsanct();
00194 return (long)RET_OK;
00195 } else {
00196 return cost;
00197 }
00198 }