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
00035 #include <config.h>
00036
00037 #include "commands.h"
00038 #include "land.h"
00039 #include "nuke.h"
00040 #include "plane.h"
00041 #include "ship.h"
00042
00043 static int tran_pmap(coord curx, coord cury, char *arg);
00044 static int tran_nmap(coord curx, coord cury, char *arg);
00045 static int tran_nuke(void);
00046 static int tran_plane(void);
00047
00048 int
00049 tran(void)
00050 {
00051 char *what;
00052 char buf[1024];
00053
00054 what = getstarg(player->argp[1], "transport what (nuke or plane): ",
00055 buf);
00056 if (what == 0)
00057 return RET_SYN;
00058 if (*what == 'n')
00059 return tran_nuke();
00060 else if (*what == 'p')
00061 return tran_plane();
00062 return RET_SYN;
00063 }
00064
00065 static int
00066 tran_nuke(void)
00067 {
00068 coord srcx, srcy;
00069 coord dstx, dsty;
00070 int mcost;
00071 int weight, count;
00072 int type, dam;
00073 struct nstr_item nstr;
00074 struct nukstr nuke;
00075 struct sctstr sect;
00076 struct sctstr endsect;
00077
00078 weight = 0;
00079 count = 0;
00080 if (!snxtitem(&nstr, EF_NUKE, player->argp[2]))
00081 return RET_SYN;
00082 while (nxtitem(&nstr, &nuke)) {
00083 if (!player->owner)
00084 continue;
00085 type = nuke.nuk_type;
00086 if (nuke.nuk_plane >= 0) {
00087 pr("%s is armed and can't be transported\n", prnuke(&nuke));
00088 return RET_FAIL;
00089 }
00090 if (count == 0) {
00091 srcx = nuke.nuk_x;
00092 srcy = nuke.nuk_y;
00093 } else {
00094 if (nuke.nuk_x != srcx || nuke.nuk_y != srcy) {
00095 pr("All nukes must be in the same sector.\n");
00096 return RET_FAIL;
00097 }
00098 }
00099 weight += nchr[type].n_weight;
00100 ++count;
00101 }
00102 if (count == 0) {
00103 pr("No nukes\n");
00104 return RET_FAIL;
00105 }
00106 if (!getsect(srcx, srcy, §) || !player->owner) {
00107 pr("You don't own %s\n", xyas(srcx, srcy, player->cnum));
00108 return RET_FAIL;
00109 }
00110 if (!military_control(§)) {
00111 pr("Military control required to move nukes.\n");
00112 return RET_FAIL;
00113 }
00114 dam = 0;
00115 mcost = move_ground(§, &endsect, weight,
00116 player->argp[3], tran_nmap, 0, &dam);
00117 if (mcost < 0)
00118 return 0;
00119
00120 dstx = endsect.sct_x;
00121 dsty = endsect.sct_y;
00122 snxtitem_rewind(&nstr);
00123 while (nxtitem(&nstr, &nuke)) {
00124 if (!player->owner)
00125 continue;
00126
00127 nuke.nuk_x = dstx;
00128 nuke.nuk_y = dsty;
00129 nuke.nuk_mission = 0;
00130 putnuke(nuke.nuk_uid, &nuke);
00131 }
00132 if (mcost > 0)
00133 pr("Total movement cost = %d\n", mcost);
00134 else
00135 pr("No mobility used\n");
00136 getsect(srcx, srcy, §);
00137 sect.sct_mobil -= mcost;
00138 if (sect.sct_mobil < 0)
00139 sect.sct_mobil = 0;
00140 putsect(§);
00141 return RET_OK;
00142 }
00143
00144 static int
00145 tran_plane(void)
00146 {
00147 coord srcx, srcy;
00148 coord dstx, dsty;
00149 int mcost;
00150 int weight, count;
00151 int type, dam;
00152 struct nstr_item nstr;
00153 struct plnstr plane;
00154 struct sctstr sect;
00155 struct sctstr endsect;
00156
00157 weight = 0;
00158 count = 0;
00159 if (!snxtitem(&nstr, EF_PLANE, player->argp[2]))
00160 return RET_SYN;
00161
00162
00163
00164
00165
00166
00167 while (nxtitem(&nstr, &plane)) {
00168 if (!player->owner)
00169 continue;
00170 type = plane.pln_type;
00171 if (plane.pln_ship >= 0) {
00172 pr("%s is at sea and can't be transported\n", prplane(&plane));
00173 return RET_FAIL;
00174 } else if (plane.pln_harden != 0) {
00175 pr("%s has been hardened and can't be transported\n",
00176 prplane(&plane));
00177 return RET_FAIL;
00178 } else if ((plane.pln_flags & PLN_LAUNCHED) &&
00179 (plchr[type].pl_flags & P_O)) {
00180 pr("%s is in space and can't be transported\n",
00181 prplane(&plane));
00182 return RET_FAIL;
00183 }
00184 if (count == 0) {
00185 srcx = plane.pln_x;
00186 srcy = plane.pln_y;
00187 } else {
00188 if (plane.pln_x != srcx || plane.pln_y != srcy) {
00189 pr("All planes must be in the same sector.\n");
00190 return RET_FAIL;
00191 }
00192 }
00193 weight += plchr[type].pl_lcm + (plchr[type].pl_hcm * 2);
00194 ++count;
00195 }
00196 if (count == 0) {
00197 pr("No planes\n");
00198 return RET_FAIL;
00199 }
00200 if (!getsect(srcx, srcy, §) || !player->owner) {
00201 pr("You don't own %s\n", xyas(srcx, srcy, player->cnum));
00202 return RET_FAIL;
00203 }
00204 if (!military_control(§)) {
00205 pr("Military control required to move planes.\n");
00206 return RET_FAIL;
00207 }
00208 dam = 1;
00209 mcost = move_ground(§, &endsect, weight,
00210 player->argp[3], tran_pmap, 0, &dam);
00211 dam /= count;
00212 if (mcost < 0)
00213 return 0;
00214
00215 dstx = endsect.sct_x;
00216 dsty = endsect.sct_y;
00217 snxtitem_rewind(&nstr);
00218 while (nxtitem(&nstr, &plane)) {
00219 if (!player->owner)
00220 continue;
00221 if (dam)
00222 planedamage(&plane, dam);
00223 plane.pln_x = dstx;
00224 plane.pln_y = dsty;
00225 plane.pln_mission = 0;
00226 putplane(plane.pln_uid, &plane);
00227 }
00228 if (mcost > 0)
00229 pr("Total movement cost = %d\n", mcost);
00230 else
00231 pr("No mobility used\n");
00232 getsect(srcx, srcy, §);
00233 sect.sct_mobil -= mcost;
00234 if (sect.sct_mobil < 0)
00235 sect.sct_mobil = 0;
00236 putsect(§);
00237 return RET_OK;
00238 }
00239
00240
00241
00242
00243
00244
00245
00246 static int
00247 tran_pmap(coord curx, coord cury, char *arg)
00248 {
00249 return display_region_map(0, EF_PLANE, curx, cury, arg);
00250 }
00251
00252 static int
00253 tran_nmap(coord curx, coord cury, char *arg)
00254 {
00255 return display_region_map(0, EF_NUKE, curx, cury, arg);
00256 }
00257