2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
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.
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, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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.
28 * atta.c: Attack another sector
30 * Known contributors to this file:
57 struct combat off[6]; /* attacking sectors */
58 struct combat def[1]; /* defending sector */
61 int fort_sup, ship_sup, land_sup, plane_sup;
62 struct emp_qelem olist; /* attacking units */
63 struct emp_qelem dlist; /* defending units */
64 int ototal; /* total attacking strength */
65 int a_engineer = 0; /* attacker engineers are present */
66 int a_spy = 0; /* the best attacker scout */
67 double osupport = 1.0; /* attack support */
68 double dsupport = 1.0; /* defense support */
74 att_combat_init(def, EF_SECTOR);
76 * Collect input from the attacker
79 /* What are we attacking? */
81 if (!(p = getstarg(player->argp[1], "Sector : ", buf)))
83 if (!sarg_xy(p, &def->x, &def->y))
85 if (att_abort(A_ATTACK, 0, def))
88 /* Show what we're attacking, and check treaties */
93 /* Ask about offensive support */
95 att_ask_support(2, &fort_sup, &ship_sup, &land_sup, &plane_sup);
96 if (att_abort(A_ATTACK, 0, def)) {
97 att_empty_attack(A_ATTACK, 0, def);
101 /* initialize the off[] array */
103 for (n = 0, last = -1; n < 6; ++n) { /* Directions */
104 newx = def->x + diroff[n + 1][0];
105 newy = def->y + diroff[n + 1][1];
106 getsect(newx, newy, §); /* incase cross world boundary */
107 rel = getrel(getnatp(sect.sct_own), player->cnum);
108 if (!player->owner && rel != ALLIED)
110 att_combat_init(&off[++last], EF_SECTOR);
111 off[last].x = sect.sct_x;
112 off[last].y = sect.sct_y;
116 /* Ask the player what he wants to attack with */
118 att_ask_offense(A_ATTACK, off, def, &olist, &a_spy, &a_engineer);
119 if (att_abort(A_ATTACK, off, def)) {
120 pr("Attack aborted\n");
121 att_empty_attack(A_ATTACK, 0, def);
122 return att_free_lists(&olist, 0);
126 * Estimate the defense strength and give the player a chance to abort
129 ototal = att_estimate_defense(A_ATTACK, off, &olist, def, a_spy);
130 if (att_abort(A_ATTACK, off, def)) {
131 pr("Attack aborted\n");
132 att_empty_attack(A_ATTACK, 0, def);
133 return att_free_lists(&olist, 0);
137 * We have now got all the answers from the attacker. From this point
138 * forward, we can assume that this battle is the _only_ thing
139 * happening in the game.
142 /* Get the real defense */
144 att_get_defense(&olist, def, &dlist, a_spy, ototal);
146 /* Get attacker and defender support */
148 att_get_support(A_ATTACK, fort_sup, ship_sup, land_sup, plane_sup,
149 &olist, off, &dlist, def, &osupport, &dsupport,
151 if (att_abort(A_ATTACK, off, def)) {
152 pr("Attack aborted\n");
153 att_empty_attack(A_ATTACK, 0, def);
154 return att_free_lists(&olist, &dlist);
158 * Death, carnage, and destruction.
161 att_fight(A_ATTACK, off, &olist, osupport, def, &dlist, dsupport);