]> 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-2005, 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 the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23  *  related information and legal notices. It is expected that any future
24  *  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 "misc.h"
35 #include "player.h"
36 #include "file.h"
37 #include "sect.h"
38 #include "path.h"
39 #include "nat.h"
40 #include "xy.h"
41 #include "land.h"
42 #include "nsc.h"
43 #include "mission.h"
44 #include "ship.h"
45 #include "combat.h"
46 #include "commands.h"
47
48 int
49 lboa(void)
50 {
51     struct combat off[1];       /* boarding sector */
52     struct combat def[1];       /* defending land unit */
53     struct emp_qelem olist;     /* boarding units */
54     struct emp_qelem dlist;     /* defending units */
55     int ototal;                 /* total boarding strength */
56     int a_engineer = 0;         /* boarder engineers are present */
57     int a_spy = 0;              /* the best boarder scout */
58     struct sctstr sect;
59     struct lndstr land;
60     s_char *p;
61     s_char buf[1024];
62
63     att_combat_init(def, EF_LAND);
64     /*
65      * Collect input from the boarder
66      */
67
68     /* What are we boarding? */
69
70     if (!(p = getstarg(player->argp[1], "Victim land unit #?  ", buf)) ||
71         (def->lnd_uid = atoi(p)) < 0)
72         return RET_SYN;
73
74     /*
75      * Ask the boarder what sector they want to board with
76      */
77
78     /* Note: if we allow land units to board other land units, we need
79      * to make sure the code will allow that */
80     if (!(p = getstarg(player->argp[2], "Boarding party from? ", buf)))
81         return RET_SYN;
82     if (issector(p)) {
83         att_combat_init(off, EF_SECTOR);
84         if (!sarg_xy(p, &off->x, &off->y))
85             return RET_SYN;
86         getsect(off->x, off->y, &sect);
87         if (sect.sct_own != player->cnum) {
88             pr("You don't own %s!\n", xyas(off->x, off->y, player->cnum));
89             return RET_SYN;
90         }
91         if (sect.sct_mobil <= 0) {
92             pr("You don't have any mobility in %s!\n",
93                xyas(off->x, off->y, player->cnum));
94             return RET_SYN;
95         }
96     } else {
97         pr("You can only board land units from a sector.\n");
98         return RET_SYN;
99     }
100     if (att_abort(A_LBOARD, off, def)) {
101         pr("Land unit boarding aborted\n");
102         return RET_OK;
103     }
104
105     /* Show what we're boarding */
106
107     if (att_show(def))
108         return RET_FAIL;
109
110     /* Ask the player what he wants to board with */
111
112     att_ask_offense(A_LBOARD, off, def, &olist, &a_spy, &a_engineer);
113     if (att_abort(A_LBOARD, off, def)) {
114         pr("Land unit boarding aborted\n");
115         att_empty_attack(A_LBOARD, 0, def);
116         return att_free_lists(&olist, 0);
117     }
118
119     /*
120      * Estimate the defense strength and give the player a chance to abort
121      */
122
123     ototal = att_estimate_defense(A_LBOARD, off, &olist, def, a_spy);
124     if (att_abort(A_LBOARD, off, def)) {
125         pr("Land unit boarding aborted\n");
126         att_empty_attack(A_LBOARD, 0, def);
127         return att_free_lists(&olist, 0);
128     }
129
130     /*
131      * We have now got all the answers from the boarder.  From this point
132      * forward, we can assume that this battle is the _only_ thing
133      * happening in the game.
134      */
135
136     /* Get the real defense */
137
138     att_get_defense(&olist, def, &dlist, a_spy, ototal);
139
140     /*
141      * Death, carnage, and destruction.
142      */
143
144     if (!(att_fight(A_LBOARD, off, &olist, 1.0, def, &dlist, 1.0))) {
145         getland(def->lnd_uid, &land);
146         /*
147          * What about retreat on RET_BOARDED?  Well, land units can't
148          * move when the boarder is hostile, and retreating when he
149          * isn't is not useful.
150          */
151     }
152
153     return RET_OK;
154 }