src/lib/commands/para.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  *  para.c: Drop paratroopers onto a sector
00029  * 
00030  *  Known contributors to this file:
00031  *     Dave Pare, 1986
00032  *     Ken Stevens, 1995
00033  */
00034 
00035 #include <config.h>
00036 
00037 #include "combat.h"
00038 #include "commands.h"
00039 #include "item.h"
00040 #include "land.h"
00041 #include "mission.h"
00042 #include "path.h"
00043 #include "plane.h"
00044 #include "ship.h"
00045 
00046 static int paradrop(struct emp_qelem *list, coord x, coord y);
00047 
00048 int
00049 para(void)
00050 {
00051     int mission_flags;
00052     coord tx, ty;
00053     coord ax, ay;
00054     int ap_to_target;
00055     char flightpath[MAX_PATH_LEN];
00056     struct nstr_item ni_bomb;
00057     struct nstr_item ni_esc;
00058     struct sctstr target;
00059     struct emp_qelem bomb_list;
00060     struct emp_qelem esc_list;
00061     int wantflags;
00062     struct sctstr ap_sect;
00063     char buf[1024];
00064 
00065     wantflags = P_P;
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     getsect(tx, ty, &target);
00082     pr("LZ is %s\n", xyas(tx, ty, player->cnum));
00083     ap_to_target = strlen(flightpath);
00084     if (flightpath[ap_to_target - 1] == 'h')
00085         ap_to_target--;
00086     pr("range to target is %d\n", ap_to_target);
00087     /*
00088      * select planes within range
00089      */
00090     pln_sel(&ni_bomb, &bomb_list, &ap_sect, ap_to_target,
00091             2, P_C | wantflags, P_M | P_O);
00092     pln_sel(&ni_esc, &esc_list, &ap_sect, ap_to_target,
00093             2, P_ESC | P_F, P_M | P_O);
00094     /*
00095      * now arm and equip the bombers, transports, whatever.
00096      */
00097     mission_flags = 0;
00098     mission_flags |= P_X;       /* stealth (shhh) */
00099     mission_flags |= P_H;       /* gets turned off if not all choppers */
00100     mission_flags = pln_arm(&bomb_list, 2 * ap_to_target, 'a',
00101                             &ichr[I_MILIT], 0, mission_flags);
00102     if (QEMPTY(&bomb_list)) {
00103         pr("No planes could be equipped for the mission.\n");
00104         return RET_FAIL;
00105     }
00106     mission_flags = pln_arm(&esc_list, 2 * ap_to_target, 'a',
00107                             &ichr[I_MILIT], P_ESC | P_F, mission_flags);
00108     ac_encounter(&bomb_list, &esc_list, ax, ay, flightpath, mission_flags,
00109                  0, 0, 0);
00110     if (QEMPTY(&bomb_list)) {
00111         pr("No planes got through fighter defenses\n");
00112     } else {
00113         getsect(tx, ty, &target);
00114         paradrop(&bomb_list, tx, ty);
00115     }
00116     pln_put(&bomb_list);
00117     pln_put(&esc_list);
00118     return RET_OK;
00119 }
00120 
00121 static int
00122 paradrop(struct emp_qelem *list, coord x, coord y)
00123 {
00124     struct combat off[1];       /* assaulting ship or sector */
00125     struct combat def[1];       /* defending ship */
00126     struct emp_qelem olist;     /* assaulting units */
00127     struct emp_qelem dlist;     /* defending units */
00128     int ototal;                 /* total assaulting strength */
00129     int a_engineer = 0;         /* assaulter engineers are present */
00130     int a_spy = 0;              /* the best assaulter scout */
00131     double osupport = 1.0;      /* assault support */
00132     double dsupport = 1.0;      /* defense support */
00133     struct plist *plp;
00134     struct emp_qelem *qp;
00135 
00136     /* Check for valid attack */
00137 
00138     att_combat_init(def, EF_SECTOR);
00139     def->x = x;
00140     def->y = y;
00141     if (att_abort(A_PARA, 0, def))
00142         return RET_FAIL;
00143 
00144     /* Show what we're air-assaulting, and check treaties */
00145 
00146     if (att_show(def))
00147         return RET_FAIL;
00148 
00149     /* set what we're air-assaulting with */
00150 
00151     emp_initque(&olist);
00152     att_combat_init(off, EF_PLANE);
00153     for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
00154         plp = (struct plist *)qp;
00155         if (plp->pcp->pl_flags & (P_V | P_C))
00156             off->troops += plp->misc;
00157     }
00158     off->mil = off->troops;
00159     if (att_abort(A_PARA, off, def)) {
00160         pr("Air-Assault aborted\n");
00161         return RET_OK;
00162     }
00163 
00164     ototal = att_get_offense(A_PARA, off, &olist, def);
00165     if (att_abort(A_PARA, off, def)) {
00166         pr("Air-assault aborted\n");
00167         return RET_OK;
00168     }
00169 
00170     /* Get the defense */
00171 
00172     att_get_defense(&olist, def, &dlist, a_spy, ototal);
00173 
00174     /* Get defender support */
00175 
00176     att_get_support(A_PARA, 0, 0, 0, 0,
00177                     &olist, off, &dlist, def, &osupport, &dsupport,
00178                     a_engineer);
00179 
00180     if (att_abort(A_PARA, off, def)) {
00181         pr("Air-assault aborted\n");
00182         return RET_OK;
00183     }
00184     /*
00185      * Death, carnage, and destruction.
00186      */
00187 
00188     att_fight(A_PARA, off, &olist, osupport, def, &dlist, dsupport);
00189 
00190     return RET_OK;
00191 }

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