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
00036
00037 #include <config.h>
00038
00039 #include <stdio.h>
00040 #include "commands.h"
00041 #include "nuke.h"
00042 #include "optlist.h"
00043 #include "plane.h"
00044
00045 int
00046 arm(void)
00047 {
00048 struct nchrstr *ncp;
00049 struct plchrstr *plc;
00050 struct plnstr pl;
00051 struct nukstr nuke;
00052 char *p;
00053 int nukno;
00054 struct nstr_item ni;
00055 char buf[1024];
00056 char prompt[128];
00057
00058 if (!snxtitem(&ni, EF_PLANE, player->argp[1]))
00059 return RET_SYN;
00060 while (nxtitem(&ni, &pl)) {
00061 if (!player->owner
00062 && getrel(getnatp(pl.pln_own), player->cnum) != ALLIED)
00063 continue;
00064 plc = &plchr[(int)pl.pln_type];
00065 if ((plc->pl_flags & (P_O | P_M)) == (P_O | P_M)) {
00066 pr("A %s cannot carry nuclear devices!\n", plc->pl_name);
00067 return RET_FAIL;
00068 }
00069 if (opt_MARKET) {
00070 if (ontradingblock(EF_PLANE, &pl)) {
00071 pr("You cannot arm %s while it is on the trading block!\n",
00072 prplane(&pl));
00073 return RET_FAIL;
00074 }
00075 }
00076 if (pl.pln_nuketype < 0) {
00077 sprintf(prompt, "Nuclear device for %s: ", prplane(&pl));
00078 p = getstarg(player->argp[2], prompt, buf);
00079 if (!p || !*p)
00080 return RET_SYN;
00081 if (!check_plane_ok(&pl))
00082 return RET_FAIL;
00083 nukno = atoi(p);
00084 if (!getnuke(nukno, &nuke) || !player->owner)
00085 return RET_FAIL;
00086 } else {
00087 if (nuk_on_plane(&nuke, pl.pln_uid) < 0) {
00088 CANT_REACH();
00089 continue;
00090 }
00091 }
00092 ncp = &nchr[nuke.nuk_type];
00093 if (pl.pln_load < ncp->n_weight) {
00094 pr("A %s cannot carry %s devices!\n",
00095 plc->pl_name, ncp->n_name);
00096 return RET_FAIL;
00097 }
00098 p = getstarg(player->argp[3], "Airburst [n]? ", buf);
00099
00100 if (!check_plane_ok(&pl) || !check_nuke_ok(&nuke))
00101 return RET_FAIL;
00102
00103 if (nuke.nuk_plane >= 0 && nuke.nuk_plane != pl.pln_uid) {
00104 pr("%s is already armed on plane #%d!\n",
00105 prnuke(&nuke), nuke.nuk_plane);
00106 return RET_FAIL;
00107 }
00108
00109 if (p && (*p == 'y' || *p == 'Y'))
00110 pl.pln_flags |= PLN_AIRBURST;
00111 else
00112 pl.pln_flags &= ~PLN_AIRBURST;
00113
00114 snprintf(buf, sizeof(buf), "armed on your %s in %s",
00115 prplane(&pl), xyas(pl.pln_x, pl.pln_y, pl.pln_own));
00116 gift(pl.pln_own, player->cnum, &nuke, buf);
00117 pl.pln_nuketype = nuke.nuk_type;
00118 nuke.nuk_plane = pl.pln_uid;
00119 putplane(pl.pln_uid, &pl);
00120 putnuke(nuke.nuk_uid, &nuke);
00121 pr("%s armed with %s.\n", prplane(&pl), prnuke(&nuke));
00122 pr("Warhead on %s is programmed to %s\n",
00123 prplane(&pl),
00124 pl.pln_flags & PLN_AIRBURST ? "airburst" : "groundburst");
00125 }
00126
00127 return RET_OK;
00128 }
00129
00130 int
00131 disarm(void)
00132 {
00133 struct plnstr pl;
00134 struct nukstr nuke;
00135 struct nstr_item ni;
00136 struct sctstr sect;
00137 char buf[128];
00138
00139 if (!snxtitem(&ni, EF_PLANE, player->argp[1]))
00140 return RET_SYN;
00141 while (nxtitem(&ni, &pl)) {
00142 if (!player->owner)
00143 continue;
00144 if (pl.pln_nuketype == -1)
00145 continue;
00146 if (opt_MARKET) {
00147 if (ontradingblock(EF_PLANE, &pl)) {
00148 pr("You cannot disarm %s while it is on the trading block!\n",
00149 prplane(&pl));
00150 return RET_FAIL;
00151 }
00152 }
00153 if (nuk_on_plane(&nuke, pl.pln_uid) < 0) {
00154 CANT_REACH();
00155 continue;
00156 }
00157 getsect(nuke.nuk_x, nuke.nuk_y, §);
00158 if (!player->owner
00159 && getrel(getnatp(sect.sct_own), player->cnum) != ALLIED) {
00160 pr("Disarming %s in sector %s requires an alliance!\n",
00161 prplane(&pl), xyas(sect.sct_x, sect.sct_y, player->cnum));
00162 continue;
00163 }
00164 snprintf(buf, sizeof(buf), "unloaded in your %s at %s",
00165 dchr[sect.sct_type].d_name,
00166 xyas(sect.sct_x, sect.sct_y, sect.sct_own));
00167 gift(sect.sct_own, player->cnum, &nuke, buf);
00168 nuke.nuk_plane = -1;
00169 pl.pln_nuketype = -1;
00170 pl.pln_flags &= ~PLN_AIRBURST;
00171 putplane(pl.pln_uid, &pl);
00172 putnuke(nuke.nuk_uid, &nuke);
00173 pr("%s removed from %s and added to %s\n",
00174 prnuke(&nuke), prplane(&pl),
00175 xyas(pl.pln_x, pl.pln_y, player->cnum));
00176 }
00177 return RET_OK;
00178 }