2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2017, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure, Markus Armbruster
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.
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.
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/>.
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.
27 * atta.c: Attack another sector
29 * Known contributors to this file:
45 struct combat off[6]; /* attacking sectors */
46 struct combat def[1]; /* defending sector */
49 int fort_sup, ship_sup, land_sup, plane_sup;
50 struct emp_qelem olist; /* attacking units */
51 struct emp_qelem dlist; /* defending units */
52 int ototal; /* total attacking strength */
53 int a_engineer = 0; /* attacker engineers are present */
54 int a_spy = 0; /* the best attacker scout */
55 double osupport = 1.0; /* attack support */
56 double dsupport = 1.0; /* defense support */
61 att_combat_init(def, EF_SECTOR);
63 * Collect input from the attacker
66 /* What are we attacking? */
68 if (!(p = getstarg(player->argp[1], "Sector : ", buf)))
70 if (!sarg_xy(p, &def->x, &def->y))
72 if (att_abort(A_ATTACK, NULL, def))
75 /* Show what we're attacking */
78 /* Ask about offensive support */
80 att_ask_support(2, &fort_sup, &ship_sup, &land_sup, &plane_sup);
81 if (att_abort(A_ATTACK, NULL, def)) {
82 att_empty_attack(A_ATTACK, 0, def);
86 /* initialize the off[] array */
88 for (n = 0, last = -1; n < 6; ++n) { /* Directions */
89 newx = def->x + diroff[n + 1][0];
90 newy = def->y + diroff[n + 1][1];
91 getsect(newx, newy, §); /* incase cross world boundary */
93 && relations_with(sect.sct_own, player->cnum) != ALLIED)
95 att_combat_init(&off[++last], EF_SECTOR);
96 off[last].x = sect.sct_x;
97 off[last].y = sect.sct_y;
101 /* Ask the player what he wants to attack with */
103 att_ask_offense(A_ATTACK, off, def, &olist, &a_spy, &a_engineer);
104 if (att_abort(A_ATTACK, off, def)) {
105 pr("Attack aborted\n");
106 att_empty_attack(A_ATTACK, 0, def);
107 return att_free_lists(&olist, NULL);
110 ototal = att_get_offense(A_ATTACK, off, &olist, def);
111 if (att_abort(A_ATTACK, off, def)) {
112 pr("Attack aborted\n");
113 att_empty_attack(A_ATTACK, 0, def);
114 return att_free_lists(&olist, NULL);
118 * We have now got all the answers from the attacker. From this point
119 * forward, we can assume that this battle is the _only_ thing
120 * happening in the game.
123 /* Get the real defense */
125 att_get_defense(&olist, def, &dlist, a_spy, ototal);
127 /* Get attacker and defender support */
129 att_get_support(A_ATTACK, fort_sup, ship_sup, land_sup, plane_sup,
130 &olist, off, &dlist, def, &osupport, &dsupport,
132 if (att_abort(A_ATTACK, off, def)) {
133 pr("Attack aborted\n");
134 att_empty_attack(A_ATTACK, 0, def);
135 return att_free_lists(&olist, &dlist);
139 * Death, carnage, and destruction.
142 att_fight(A_ATTACK, off, &olist, osupport, def, &dlist, dsupport);