]> 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-2014, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                Ken Stevens, Steve McClure, Markus Armbruster
5  *
6  *  Empire 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 3 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, see <http://www.gnu.org/licenses/>.
18  *
19  *  ---
20  *
21  *  See files README, COPYING and CREDITS in the root of the source
22  *  tree for related information and legal notices.  It is expected
23  *  that future projects/authors will amend these files as needed.
24  *
25  *  ---
26  *
27  *  lboard.c: Board an enemy land unit (heavily borrowing from boar.c)
28  *
29  *  Known contributors to this file:
30  *     Steve McClure, 1998
31  */
32
33 #include <config.h>
34
35 #include "combat.h"
36 #include "commands.h"
37 #include "land.h"
38 #include "ship.h"
39
40 int
41 lboa(void)
42 {
43     struct combat off[1];       /* boarding sector */
44     struct combat def[1];       /* defending land unit */
45     struct emp_qelem olist;     /* boarding units */
46     struct emp_qelem dlist;     /* defending units */
47     int ototal;                 /* total boarding strength */
48     int a_engineer = 0;         /* boarder engineers are present */
49     int a_spy = 0;              /* the best boarder scout */
50     struct sctstr sect;
51     struct lndstr land;
52     char *p;
53     char buf[1024];
54
55     att_combat_init(def, EF_LAND);
56     /*
57      * Collect input from the boarder
58      */
59
60     /* What are we boarding? */
61     p = getstarg(player->argp[1], "Victim land unit #?  ", buf);
62     if (!p || (def->lnd_uid = atoi(p)) < 0)
63         return RET_SYN;
64
65     /*
66      * Ask the boarder what sector they want to board with
67      */
68
69     /* Note: if we allow land units to board other land units, we need
70      * to make sure the code will allow that */
71     if (!(p = getstarg(player->argp[2], "Boarding party from? ", buf)))
72         return RET_SYN;
73     if (issector(p)) {
74         att_combat_init(off, EF_SECTOR);
75         if (!sarg_xy(p, &off->x, &off->y))
76             return RET_SYN;
77         getsect(off->x, off->y, &sect);
78         if (sect.sct_own != player->cnum) {
79             pr("You don't own %s!\n", xyas(off->x, off->y, player->cnum));
80             return RET_SYN;
81         }
82         if (sect.sct_mobil <= 0) {
83             pr("You don't have any mobility in %s!\n",
84                xyas(off->x, off->y, player->cnum));
85             return RET_SYN;
86         }
87     } else {
88         pr("You can only board land units from a sector.\n");
89         return RET_SYN;
90     }
91     if (att_abort(A_LBOARD, off, def)) {
92         pr("Land unit boarding aborted\n");
93         return RET_OK;
94     }
95
96     /* Show what we're boarding */
97
98     if (att_show(def))
99         return RET_FAIL;
100
101     /* Ask the player what he wants to board with */
102
103     att_ask_offense(A_LBOARD, off, def, &olist, &a_spy, &a_engineer);
104     if (att_abort(A_LBOARD, off, def)) {
105         pr("Land unit boarding aborted\n");
106         att_empty_attack(A_LBOARD, 0, def);
107         return att_free_lists(&olist, NULL);
108     }
109
110     ototal = att_get_offense(A_LBOARD, off, &olist, def);
111     if (att_abort(A_LBOARD, off, def)) {
112         pr("Land unit boarding aborted\n");
113         att_empty_attack(A_LBOARD, 0, def);
114         return att_free_lists(&olist, NULL);
115     }
116
117     /*
118      * We have now got all the answers from the boarder.  From this point
119      * forward, we can assume that this battle is the _only_ thing
120      * happening in the game.
121      */
122
123     /* Get the real defense */
124
125     att_get_defense(&olist, def, &dlist, a_spy, ototal);
126
127     /*
128      * Death, carnage, and destruction.
129      */
130
131     if (!(att_fight(A_LBOARD, off, &olist, 1.0, def, &dlist, 1.0))) {
132         getland(def->lnd_uid, &land);
133         /*
134          * What about retreat on RET_BOARDED?  Well, land units can't
135          * move when the boarder is hostile, and retreating when he
136          * isn't is not useful.
137          */
138     }
139
140     return RET_OK;
141 }