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 "item.h"
00038 #include "path.h"
00039 #include "plane.h"
00040 #include "ship.h"
00041
00042 int
00043 drop(void)
00044 {
00045 int mission_flags;
00046 coord tx, ty;
00047 coord ax, ay;
00048 int ap_to_target;
00049 struct ichrstr *ip;
00050 char flightpath[MAX_PATH_LEN];
00051 struct nstr_item ni_bomb;
00052 struct nstr_item ni_esc;
00053 struct sctstr target;
00054 struct emp_qelem bomb_list;
00055 struct emp_qelem esc_list;
00056 int wantflags;
00057 struct sctstr ap_sect;
00058 char buf[1024];
00059
00060 wantflags = 0;
00061 if (!snxtitem(&ni_bomb, EF_PLANE, player->argp[1]))
00062 return RET_SYN;
00063 if (!snxtitem(&ni_esc, EF_PLANE,
00064 getstarg(player->argp[2], "escort(s)? ", buf)))
00065 pr("No escorts...\n");
00066 if (!get_assembly_point(player->argp[3], &ap_sect, buf))
00067 return RET_SYN;
00068 ax = ap_sect.sct_x;
00069 ay = ap_sect.sct_y;
00070 if (getpath(flightpath, player->argp[4], ax, ay, 0, 0, P_FLYING) == 0
00071 || *flightpath == 0)
00072 return RET_SYN;
00073 tx = ax;
00074 ty = ay;
00075 (void)pathtoxy(flightpath, &tx, &ty, fcost);
00076 pr("target is %s\n", xyas(tx, ty, player->cnum));
00077 if ((ip = whatitem(player->argp[5], "Drop off what? ")) == 0)
00078 return RET_SYN;
00079 getsect(tx, ty, &target);
00080
00081 if (target.sct_own == player->cnum
00082 || getrel(getnatp(target.sct_own), player->cnum) == ALLIED) {
00083 if (ip->i_uid == I_CIVIL && target.sct_own != target.sct_oldown) {
00084 pr("Can't drop civilians into occupied sectors.\n");
00085 return RET_FAIL;
00086 }
00087 } else {
00088
00089 if (ip->i_uid != I_SHELL) {
00090 pr("You don't own %s!\n", xyas(tx, ty, player->cnum));
00091 return RET_FAIL;
00092 }
00093 wantflags = P_MINE;
00094 }
00095
00096 ap_to_target = strlen(flightpath);
00097 if (flightpath[ap_to_target - 1] == 'h')
00098 ap_to_target--;
00099 pr("range to target is %d\n", ap_to_target);
00100
00101
00102
00103 mission_flags = 0;
00104 pln_sel(&ni_bomb, &bomb_list, &ap_sect, ap_to_target,
00105 2, wantflags, P_M | P_O);
00106 if (QEMPTY(&bomb_list)) {
00107 pr("No planes could be equipped for the mission.\n");
00108 return RET_FAIL;
00109 }
00110 pln_sel(&ni_esc, &esc_list, &ap_sect, ap_to_target,
00111 2, P_ESC | P_F, P_M | P_O);
00112
00113
00114
00115 mission_flags |= P_X;
00116 mission_flags |= P_H;
00117 mission_flags |= P_MINE;
00118 mission_flags = pln_arm(&bomb_list, 2 * ap_to_target,
00119 wantflags & P_MINE ? 'm' : 'd',
00120 ip, 0, mission_flags);
00121 if (QEMPTY(&bomb_list)) {
00122 pr("No planes could be equipped for the mission.\n");
00123 return RET_FAIL;
00124 }
00125 mission_flags = pln_arm(&esc_list, 2 * ap_to_target, 'd',
00126 ip, P_ESC | P_F, mission_flags);
00127 ac_encounter(&bomb_list, &esc_list, ax, ay, flightpath, mission_flags,
00128 0, 0, 0);
00129 if (QEMPTY(&bomb_list)) {
00130 pr("No planes got through fighter defenses\n");
00131 } else {
00132 getsect(tx, ty, &target);
00133 if (wantflags & P_MINE)
00134 pln_mine(&bomb_list, &target);
00135 else
00136 pln_dropoff(&bomb_list, ip, tx, ty, &target, EF_SECTOR);
00137 }
00138 pln_put(&bomb_list);
00139 pln_put(&esc_list);
00140 return RET_OK;
00141 }