src/lib/commands/atta.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  *  atta.c: Attack another sector
00029  * 
00030  *  Known contributors to this file:
00031  *     Dave Pare
00032  *     Ken Stevens, 1995
00033  *     Steve McClure, 1996
00034  */
00035 
00036 #include <config.h>
00037 
00038 #include "combat.h"
00039 #include "commands.h"
00040 #include "land.h"
00041 #include "mission.h"
00042 #include "path.h"
00043 #include "ship.h"
00044 
00045 int
00046 atta(void)
00047 {
00048     struct combat off[6];       /* attacking sectors */
00049     struct combat def[1];       /* defending sector */
00050     coord newx, newy;
00051     struct sctstr sect;
00052     int fort_sup, ship_sup, land_sup, plane_sup;
00053     struct emp_qelem olist;     /* attacking units */
00054     struct emp_qelem dlist;     /* defending units */
00055     int ototal;                 /* total attacking strength */
00056     int a_engineer = 0;         /* attacker engineers are present */
00057     int a_spy = 0;              /* the best attacker scout */
00058     double osupport = 1.0;      /* attack support */
00059     double dsupport = 1.0;      /* defense support */
00060     int last, n;
00061     char *p;
00062     char buf[1024];
00063     int rel;
00064 
00065     att_combat_init(def, EF_SECTOR);
00066     /*
00067      * Collect input from the attacker
00068      */
00069 
00070     /* What are we attacking? */
00071 
00072     if (!(p = getstarg(player->argp[1], "Sector :  ", buf)))
00073         return RET_SYN;
00074     if (!sarg_xy(p, &def->x, &def->y))
00075         return RET_SYN;
00076     if (att_abort(A_ATTACK, 0, def))
00077         return RET_FAIL;
00078 
00079     /* Show what we're attacking, and check treaties */
00080 
00081     if (att_show(def))
00082         return RET_FAIL;
00083 
00084     /* Ask about offensive support */
00085 
00086     att_ask_support(2, &fort_sup, &ship_sup, &land_sup, &plane_sup);
00087     if (att_abort(A_ATTACK, 0, def)) {
00088         att_empty_attack(A_ATTACK, 0, def);
00089         return RET_OK;
00090     }
00091 
00092     /* initialize the off[] array */
00093 
00094     for (n = 0, last = -1; n < 6; ++n) {        /* Directions */
00095         newx = def->x + diroff[n + 1][0];
00096         newy = def->y + diroff[n + 1][1];
00097         getsect(newx, newy, &sect);     /* incase cross world boundary */
00098         rel = getrel(getnatp(sect.sct_own), player->cnum);
00099         if (!player->owner && rel != ALLIED)
00100             continue;
00101         att_combat_init(&off[++last], EF_SECTOR);
00102         off[last].x = sect.sct_x;
00103         off[last].y = sect.sct_y;
00104     }
00105     off->last = last;
00106 
00107     /* Ask the player what he wants to attack with */
00108 
00109     att_ask_offense(A_ATTACK, off, def, &olist, &a_spy, &a_engineer);
00110     if (att_abort(A_ATTACK, off, def)) {
00111         pr("Attack aborted\n");
00112         att_empty_attack(A_ATTACK, 0, def);
00113         return att_free_lists(&olist, 0);
00114     }
00115 
00116     ototal = att_get_offense(A_ATTACK, off, &olist, def);
00117     if (att_abort(A_ATTACK, off, def)) {
00118         pr("Attack aborted\n");
00119         att_empty_attack(A_ATTACK, 0, def);
00120         return att_free_lists(&olist, 0);
00121     }
00122 
00123     /*
00124      * We have now got all the answers from the attacker.  From this point
00125      * forward, we can assume that this battle is the _only_ thing
00126      * happening in the game.
00127      */
00128 
00129     /* Get the real defense */
00130 
00131     att_get_defense(&olist, def, &dlist, a_spy, ototal);
00132 
00133     /* Get attacker and defender support */
00134 
00135     att_get_support(A_ATTACK, fort_sup, ship_sup, land_sup, plane_sup,
00136                     &olist, off, &dlist, def, &osupport, &dsupport,
00137                     a_engineer);
00138     if (att_abort(A_ATTACK, off, def)) {
00139         pr("Attack aborted\n");
00140         att_empty_attack(A_ATTACK, 0, def);
00141         return att_free_lists(&olist, &dlist);
00142     }
00143 
00144     /*
00145      * Death, carnage, and destruction.
00146      */
00147 
00148     att_fight(A_ATTACK, off, &olist, osupport, def, &dlist, dsupport);
00149 
00150     return RET_OK;
00151 }

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