assault: Factor only_spies(), sneak_ashore() out of assa()
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
parent
33800fc732
commit
f15f0cc687
1 changed files with 74 additions and 55 deletions
|
@ -29,6 +29,7 @@
|
||||||
* Known contributors to this file:
|
* Known contributors to this file:
|
||||||
* Ken Stevens, 1995
|
* Ken Stevens, 1995
|
||||||
* Steve McClure, 1997
|
* Steve McClure, 1997
|
||||||
|
* Markus Armbruster, 2009-2016
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
@ -39,6 +40,9 @@
|
||||||
#include "empobj.h"
|
#include "empobj.h"
|
||||||
#include "unit.h"
|
#include "unit.h"
|
||||||
|
|
||||||
|
static int only_spies(struct combat[], struct emp_qelem *);
|
||||||
|
static void sneak_ashore(struct emp_qelem *, struct combat *);
|
||||||
|
|
||||||
int
|
int
|
||||||
assa(void)
|
assa(void)
|
||||||
{
|
{
|
||||||
|
@ -54,11 +58,6 @@ assa(void)
|
||||||
double dsupport = 1.0; /* defense support */
|
double dsupport = 1.0; /* defense support */
|
||||||
char *p;
|
char *p;
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
int n;
|
|
||||||
int ourtotal;
|
|
||||||
struct emp_qelem *qp, *next;
|
|
||||||
struct ulist *llp;
|
|
||||||
int rel;
|
|
||||||
|
|
||||||
att_combat_init(off, EF_SHIP);
|
att_combat_init(off, EF_SHIP);
|
||||||
att_combat_init(def, EF_SECTOR);
|
att_combat_init(def, EF_SECTOR);
|
||||||
|
@ -137,13 +136,52 @@ assa(void)
|
||||||
* make it, the defenders don't see a thing. If they fail, well,
|
* make it, the defenders don't see a thing. If they fail, well,
|
||||||
* the spies die, and the defenders see them. */
|
* the spies die, and the defenders see them. */
|
||||||
|
|
||||||
|
/* If no attacking forces (i.e. we got here with only spies)
|
||||||
|
* then try to sneak on-land. */
|
||||||
|
if (only_spies(off, &olist)) {
|
||||||
|
sneak_ashore(&olist, def);
|
||||||
|
return RET_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get the real defense */
|
||||||
|
|
||||||
|
att_get_defense(&olist, def, &dlist, a_spy, ototal);
|
||||||
|
|
||||||
|
/* Get assaulter and defender support */
|
||||||
|
|
||||||
|
att_get_support(A_ASSAULT, fort_sup, ship_sup, land_sup, plane_sup,
|
||||||
|
&olist, off, &dlist, def, &osupport, &dsupport,
|
||||||
|
a_engineer);
|
||||||
|
if (att_abort(A_ASSAULT, off, def)) {
|
||||||
|
pr("Assault aborted\n");
|
||||||
|
att_empty_attack(A_ASSAULT, 0, def);
|
||||||
|
return att_free_lists(&olist, &dlist);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Death, carnage, and destruction.
|
||||||
|
*/
|
||||||
|
|
||||||
|
att_fight(A_ASSAULT, off, &olist, osupport, def, &dlist, dsupport);
|
||||||
|
|
||||||
|
return RET_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
only_spies(struct combat off[], struct emp_qelem *olist)
|
||||||
|
{
|
||||||
|
int ourtotal;
|
||||||
|
int n;
|
||||||
|
struct emp_qelem *qp, *next;
|
||||||
|
struct ulist *llp;
|
||||||
|
|
||||||
ourtotal = 0;
|
ourtotal = 0;
|
||||||
for (n = 0; n <= off->last; n++) {
|
for (n = 0; n <= off->last; n++) {
|
||||||
if (off[n].type == EF_BAD)
|
if (off[n].type == EF_BAD)
|
||||||
continue;
|
continue;
|
||||||
ourtotal += off[n].troops * att_combat_eff(off + n);
|
ourtotal += off[n].troops * att_combat_eff(off + n);
|
||||||
}
|
}
|
||||||
for (qp = olist.q_forw; qp != &olist; qp = next) {
|
for (qp = olist->q_forw; qp != olist; qp = next) {
|
||||||
next = qp->q_forw;
|
next = qp->q_forw;
|
||||||
llp = (struct ulist *)qp;
|
llp = (struct ulist *)qp;
|
||||||
if (lchr[(int)llp->unit.land.lnd_type].l_flags & L_SPY)
|
if (lchr[(int)llp->unit.land.lnd_type].l_flags & L_SPY)
|
||||||
|
@ -151,13 +189,19 @@ assa(void)
|
||||||
ourtotal++;
|
ourtotal++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If no attacking forces (i.e. we got here with only spies)
|
return ourtotal == 0;
|
||||||
* then try to sneak on-land. */
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sneak_ashore(struct emp_qelem *olist, struct combat *def)
|
||||||
|
{
|
||||||
|
struct emp_qelem *qp, *next;
|
||||||
|
struct ulist *llp;
|
||||||
|
int rel;
|
||||||
|
|
||||||
if (!ourtotal) {
|
|
||||||
pr("Trying to sneak on shore...\n");
|
pr("Trying to sneak on shore...\n");
|
||||||
|
|
||||||
for (qp = olist.q_forw; qp != &olist; qp = next) {
|
for (qp = olist->q_forw; qp != olist; qp = next) {
|
||||||
next = qp->q_forw;
|
next = qp->q_forw;
|
||||||
llp = (struct ulist *)qp;
|
llp = (struct ulist *)qp;
|
||||||
rel = relations_with(def->own, player->cnum);
|
rel = relations_with(def->own, player->cnum);
|
||||||
|
@ -189,29 +233,4 @@ assa(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return RET_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Get the real defense */
|
|
||||||
|
|
||||||
att_get_defense(&olist, def, &dlist, a_spy, ototal);
|
|
||||||
|
|
||||||
/* Get assaulter and defender support */
|
|
||||||
|
|
||||||
att_get_support(A_ASSAULT, fort_sup, ship_sup, land_sup, plane_sup,
|
|
||||||
&olist, off, &dlist, def, &osupport, &dsupport,
|
|
||||||
a_engineer);
|
|
||||||
if (att_abort(A_ASSAULT, off, def)) {
|
|
||||||
pr("Assault aborted\n");
|
|
||||||
att_empty_attack(A_ASSAULT, 0, def);
|
|
||||||
return att_free_lists(&olist, &dlist);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Death, carnage, and destruction.
|
|
||||||
*/
|
|
||||||
|
|
||||||
att_fight(A_ASSAULT, off, &olist, osupport, def, &dlist, dsupport);
|
|
||||||
|
|
||||||
return RET_OK;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue