src/lib/commands/fly.c

Go to the documentation of this file.
00001 /*
00002  *  Empire - A multi-player, client/server Internet based war game.
00003  *  Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
00004  *                           Ken Stevens, Steve McClure
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  *  ---
00021  *
00022  *  See files README, COPYING and CREDITS in the root of the source
00023  *  tree for related information and legal notices.  It is expected
00024  *  that future projects/authors will amend these files as needed.
00025  *
00026  *  ---
00027  *
00028  *  fly.c: fly a plane
00029  * 
00030  *  Known contributors to this file:
00031  *     Dave Pare, 1986
00032  *     Steve McClure, 2000
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 = &target;
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      * select planes within range
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      * now arm and equip the bombers, transports, whatever.
00128      */
00129     mission_flags |= P_X;       /* stealth (shhh) */
00130     mission_flags |= P_H;       /* gets turned off if not all choppers */
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 }

Generated on Fri Mar 28 11:01:12 2008 for empserver by  doxygen 1.5.2