src/lib/commands/drop.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  *  drop.c: Air-drop commodities
00029  * 
00030  *  Known contributors to this file:
00031  *     Dave Pare, 1986
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         /* into the unknown... */
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      * select planes within range
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      * now arm and equip the bombers, transports, whatever.
00114      */
00115     mission_flags |= P_X;       /* stealth (shhh) */
00116     mission_flags |= P_H;       /* gets turned off if not all choppers */
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 }

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