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