src/lib/commands/lboard.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  *  lboard.c: Board an enemy land unit (heavily borrowing from boar.c)
00029  * 
00030  *  Known contributors to this file:
00031  *     Steve McClure, 1998
00032  */
00033 
00034 #include <config.h>
00035 
00036 #include "combat.h"
00037 #include "commands.h"
00038 #include "land.h"
00039 #include "mission.h"
00040 #include "path.h"
00041 #include "ship.h"
00042 
00043 int
00044 lboa(void)
00045 {
00046     struct combat off[1];       /* boarding sector */
00047     struct combat def[1];       /* defending land unit */
00048     struct emp_qelem olist;     /* boarding units */
00049     struct emp_qelem dlist;     /* defending units */
00050     int ototal;                 /* total boarding strength */
00051     int a_engineer = 0;         /* boarder engineers are present */
00052     int a_spy = 0;              /* the best boarder scout */
00053     struct sctstr sect;
00054     struct lndstr land;
00055     char *p;
00056     char buf[1024];
00057 
00058     att_combat_init(def, EF_LAND);
00059     /*
00060      * Collect input from the boarder
00061      */
00062 
00063     /* What are we boarding? */
00064 
00065     if (!(p = getstarg(player->argp[1], "Victim land unit #?  ", buf)) ||
00066         (def->lnd_uid = atoi(p)) < 0)
00067         return RET_SYN;
00068 
00069     /*
00070      * Ask the boarder what sector they want to board with
00071      */
00072 
00073     /* Note: if we allow land units to board other land units, we need
00074      * to make sure the code will allow that */
00075     if (!(p = getstarg(player->argp[2], "Boarding party from? ", buf)))
00076         return RET_SYN;
00077     if (issector(p)) {
00078         att_combat_init(off, EF_SECTOR);
00079         if (!sarg_xy(p, &off->x, &off->y))
00080             return RET_SYN;
00081         getsect(off->x, off->y, &sect);
00082         if (sect.sct_own != player->cnum) {
00083             pr("You don't own %s!\n", xyas(off->x, off->y, player->cnum));
00084             return RET_SYN;
00085         }
00086         if (sect.sct_mobil <= 0) {
00087             pr("You don't have any mobility in %s!\n",
00088                xyas(off->x, off->y, player->cnum));
00089             return RET_SYN;
00090         }
00091     } else {
00092         pr("You can only board land units from a sector.\n");
00093         return RET_SYN;
00094     }
00095     if (att_abort(A_LBOARD, off, def)) {
00096         pr("Land unit boarding aborted\n");
00097         return RET_OK;
00098     }
00099 
00100     /* Show what we're boarding */
00101 
00102     if (att_show(def))
00103         return RET_FAIL;
00104 
00105     /* Ask the player what he wants to board with */
00106 
00107     att_ask_offense(A_LBOARD, off, def, &olist, &a_spy, &a_engineer);
00108     if (att_abort(A_LBOARD, off, def)) {
00109         pr("Land unit boarding aborted\n");
00110         att_empty_attack(A_LBOARD, 0, def);
00111         return att_free_lists(&olist, 0);
00112     }
00113 
00114     ototal = att_get_offense(A_LBOARD, off, &olist, def);
00115     if (att_abort(A_LBOARD, off, def)) {
00116         pr("Land unit boarding aborted\n");
00117         att_empty_attack(A_LBOARD, 0, def);
00118         return att_free_lists(&olist, 0);
00119     }
00120 
00121     /*
00122      * We have now got all the answers from the boarder.  From this point
00123      * forward, we can assume that this battle is the _only_ thing
00124      * happening in the game.
00125      */
00126 
00127     /* Get the real defense */
00128 
00129     att_get_defense(&olist, def, &dlist, a_spy, ototal);
00130 
00131     /*
00132      * Death, carnage, and destruction.
00133      */
00134 
00135     if (!(att_fight(A_LBOARD, off, &olist, 1.0, def, &dlist, 1.0))) {
00136         getland(def->lnd_uid, &land);
00137         /*
00138          * What about retreat on RET_BOARDED?  Well, land units can't
00139          * move when the boarder is hostile, and retreating when he
00140          * isn't is not useful.
00141          */
00142     }
00143 
00144     return RET_OK;
00145 }

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