]> git.pond.sub.org Git - empserver/blob - src/lib/commands/lboard.c
Update copyright notice
[empserver] / src / lib / commands / lboard.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2010, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                           Ken Stevens, Steve McClure
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  *  ---
21  *
22  *  See files README, COPYING and CREDITS in the root of the source
23  *  tree for related information and legal notices.  It is expected
24  *  that future projects/authors will amend these files as needed.
25  *
26  *  ---
27  *
28  *  lboard.c: Board an enemy land unit (heavily borrowing from boar.c)
29  *
30  *  Known contributors to this file:
31  *     Steve McClure, 1998
32  */
33
34 #include <config.h>
35
36 #include "combat.h"
37 #include "commands.h"
38 #include "land.h"
39 #include "mission.h"
40 #include "path.h"
41 #include "ship.h"
42
43 int
44 lboa(void)
45 {
46     struct combat off[1];       /* boarding sector */
47     struct combat def[1];       /* defending land unit */
48     struct emp_qelem olist;     /* boarding units */
49     struct emp_qelem dlist;     /* defending units */
50     int ototal;                 /* total boarding strength */
51     int a_engineer = 0;         /* boarder engineers are present */
52     int a_spy = 0;              /* the best boarder scout */
53     struct sctstr sect;
54     struct lndstr land;
55     char *p;
56     char buf[1024];
57
58     att_combat_init(def, EF_LAND);
59     /*
60      * Collect input from the boarder
61      */
62
63     /* What are we boarding? */
64     p = getstarg(player->argp[1], "Victim land unit #?  ", buf);
65     if (!p || (def->lnd_uid = atoi(p)) < 0)
66         return RET_SYN;
67
68     /*
69      * Ask the boarder what sector they want to board with
70      */
71
72     /* Note: if we allow land units to board other land units, we need
73      * to make sure the code will allow that */
74     if (!(p = getstarg(player->argp[2], "Boarding party from? ", buf)))
75         return RET_SYN;
76     if (issector(p)) {
77         att_combat_init(off, EF_SECTOR);
78         if (!sarg_xy(p, &off->x, &off->y))
79             return RET_SYN;
80         getsect(off->x, off->y, &sect);
81         if (sect.sct_own != player->cnum) {
82             pr("You don't own %s!\n", xyas(off->x, off->y, player->cnum));
83             return RET_SYN;
84         }
85         if (sect.sct_mobil <= 0) {
86             pr("You don't have any mobility in %s!\n",
87                xyas(off->x, off->y, player->cnum));
88             return RET_SYN;
89         }
90     } else {
91         pr("You can only board land units from a sector.\n");
92         return RET_SYN;
93     }
94     if (att_abort(A_LBOARD, off, def)) {
95         pr("Land unit boarding aborted\n");
96         return RET_OK;
97     }
98
99     /* Show what we're boarding */
100
101     if (att_show(def))
102         return RET_FAIL;
103
104     /* Ask the player what he wants to board with */
105
106     att_ask_offense(A_LBOARD, off, def, &olist, &a_spy, &a_engineer);
107     if (att_abort(A_LBOARD, off, def)) {
108         pr("Land unit boarding aborted\n");
109         att_empty_attack(A_LBOARD, 0, def);
110         return att_free_lists(&olist, NULL);
111     }
112
113     ototal = att_get_offense(A_LBOARD, off, &olist, def);
114     if (att_abort(A_LBOARD, off, def)) {
115         pr("Land unit boarding aborted\n");
116         att_empty_attack(A_LBOARD, 0, def);
117         return att_free_lists(&olist, NULL);
118     }
119
120     /*
121      * We have now got all the answers from the boarder.  From this point
122      * forward, we can assume that this battle is the _only_ thing
123      * happening in the game.
124      */
125
126     /* Get the real defense */
127
128     att_get_defense(&olist, def, &dlist, a_spy, ototal);
129
130     /*
131      * Death, carnage, and destruction.
132      */
133
134     if (!(att_fight(A_LBOARD, off, &olist, 1.0, def, &dlist, 1.0))) {
135         getland(def->lnd_uid, &land);
136         /*
137          * What about retreat on RET_BOARDED?  Well, land units can't
138          * move when the boarder is hostile, and retreating when he
139          * isn't is not useful.
140          */
141     }
142
143     return RET_OK;
144 }