subs: Factor common military counting out of shoo() and conv()
Put the new function security_strength() next to military_control(), because that one does a similar count. Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
parent
602f15f52d
commit
ffd6651f86
4 changed files with 33 additions and 39 deletions
|
@ -399,6 +399,7 @@ extern int check_trade_ok(struct trdstr *);
|
||||||
/* coastal.c */
|
/* coastal.c */
|
||||||
extern void set_coastal(struct sctstr *, int, int);
|
extern void set_coastal(struct sctstr *, int, int);
|
||||||
/* control.c */
|
/* control.c */
|
||||||
|
extern int security_strength(struct sctstr *, int *);
|
||||||
extern int military_control(struct sctstr *);
|
extern int military_control(struct sctstr *);
|
||||||
extern int abandon_askyn(struct sctstr *, i_type, int, struct ulist *);
|
extern int abandon_askyn(struct sctstr *, i_type, int, struct ulist *);
|
||||||
extern int would_abandon(struct sctstr *, i_type, int, struct ulist *);
|
extern int would_abandon(struct sctstr *, i_type, int, struct ulist *);
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
*
|
*
|
||||||
* Known contributors to this file:
|
* Known contributors to this file:
|
||||||
* Dave Pare, 1986
|
* Dave Pare, 1986
|
||||||
* Markus Armbruster, 2004-2015
|
* Markus Armbruster, 2004-2016
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -48,10 +48,8 @@ conv(void)
|
||||||
struct sctstr sect;
|
struct sctstr sect;
|
||||||
struct nstr_sect nstr;
|
struct nstr_sect nstr;
|
||||||
int uwtoconvert, newuw, totaluw, uw;
|
int uwtoconvert, newuw, totaluw, uw;
|
||||||
int maxpop, civ, mil, adj_mob, mob;
|
int maxpop, civ, mil, nsec, adj_mob, mob;
|
||||||
double security_extra = 1.0;
|
double security_extra = 1.0;
|
||||||
struct lndstr land;
|
|
||||||
struct nstr_item ni;
|
|
||||||
|
|
||||||
if (!snxtsct(&nstr, player->argp[1]))
|
if (!snxtsct(&nstr, player->argp[1]))
|
||||||
return RET_SYN;
|
return RET_SYN;
|
||||||
|
@ -68,27 +66,7 @@ conv(void)
|
||||||
natp = getnatp(sect.sct_own);
|
natp = getnatp(sect.sct_own);
|
||||||
maxpop = max_pop(natp->nat_level[NAT_RLEV], §);
|
maxpop = max_pop(natp->nat_level[NAT_RLEV], §);
|
||||||
civ = sect.sct_item[I_CIVIL];
|
civ = sect.sct_item[I_CIVIL];
|
||||||
mil = sect.sct_item[I_MILIT];
|
mil = security_strength(§, &nsec);
|
||||||
|
|
||||||
/*
|
|
||||||
* Military units count according to the number of
|
|
||||||
* mil in them. (i.e. attack/defense modifier don't
|
|
||||||
* count.
|
|
||||||
*/
|
|
||||||
snxtitem_xy(&ni, EF_LAND, sect.sct_x, sect.sct_y);
|
|
||||||
while (nxtitem(&ni, &land)) {
|
|
||||||
mil += land.lnd_item[I_MILIT];
|
|
||||||
|
|
||||||
/* Anti-terrorist units count double */
|
|
||||||
if (lchr[(int)land.lnd_type].l_flags & L_SECURITY) {
|
|
||||||
/*
|
|
||||||
* They also increase the efficiency of
|
|
||||||
* the conversion process by 10% each.
|
|
||||||
*/
|
|
||||||
security_extra += .1;
|
|
||||||
mil += land.lnd_item[I_MILIT];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/*
|
/*
|
||||||
* Must have military control to convert captured civs.
|
* Must have military control to convert captured civs.
|
||||||
*/
|
*/
|
||||||
|
@ -110,6 +88,7 @@ conv(void)
|
||||||
mob = sect.sct_mobil * 5;
|
mob = sect.sct_mobil * 5;
|
||||||
|
|
||||||
/* security troops make conversion more effective */
|
/* security troops make conversion more effective */
|
||||||
|
security_extra = 1.0 + nsec / 10.0;
|
||||||
adj_mob = ldround(((double)mob * security_extra), 1);
|
adj_mob = ldround(((double)mob * security_extra), 1);
|
||||||
|
|
||||||
if (adj_mob < newuw)
|
if (adj_mob < newuw)
|
||||||
|
|
|
@ -43,12 +43,10 @@ shoo(void)
|
||||||
{
|
{
|
||||||
struct sctstr sect;
|
struct sctstr sect;
|
||||||
struct nstr_sect nstr;
|
struct nstr_sect nstr;
|
||||||
struct nstr_item ni;
|
|
||||||
int nshot;
|
int nshot;
|
||||||
double m;
|
double m;
|
||||||
i_type item;
|
i_type item;
|
||||||
struct ichrstr *ip;
|
struct ichrstr *ip;
|
||||||
struct lndstr land;
|
|
||||||
int targets;
|
int targets;
|
||||||
char *p;
|
char *p;
|
||||||
int mil, nsec;
|
int mil, nsec;
|
||||||
|
@ -68,18 +66,7 @@ shoo(void)
|
||||||
while (nxtsct(&nstr, §)) {
|
while (nxtsct(&nstr, §)) {
|
||||||
if (!player->owner)
|
if (!player->owner)
|
||||||
continue;
|
continue;
|
||||||
mil = sect.sct_item[I_MILIT];
|
mil = security_strength(§, &nsec);
|
||||||
nsec = 0;
|
|
||||||
snxtitem_xy(&ni, EF_LAND, sect.sct_x, sect.sct_y);
|
|
||||||
while (nxtitem(&ni, &land)) {
|
|
||||||
mil += land.lnd_item[I_MILIT];
|
|
||||||
|
|
||||||
if (lchr[(int)land.lnd_type].l_flags & L_SECURITY) {
|
|
||||||
mil += land.lnd_item[I_MILIT];
|
|
||||||
nsec++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sect.sct_item[item] == 0 || sect.sct_item[I_CIVIL] > mil * 10)
|
if (sect.sct_item[item] == 0 || sect.sct_item[I_CIVIL] > mil * 10)
|
||||||
continue;
|
continue;
|
||||||
nshot = sect.sct_item[item] > targets ? targets : sect.sct_item[item];
|
nshot = sect.sct_item[item] > targets ? targets : sect.sct_item[item];
|
||||||
|
|
|
@ -40,6 +40,33 @@
|
||||||
#include "sect.h"
|
#include "sect.h"
|
||||||
#include "unit.h"
|
#include "unit.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return strength of security detail in @sp.
|
||||||
|
* Store number of land units with security capability in @nsecurity.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
security_strength(struct sctstr *sp, int *nsecurity)
|
||||||
|
{
|
||||||
|
int strength;
|
||||||
|
int nsec;
|
||||||
|
struct nstr_item ni;
|
||||||
|
struct lndstr land;
|
||||||
|
|
||||||
|
strength = sp->sct_item[I_MILIT];
|
||||||
|
nsec = 0;
|
||||||
|
snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y);
|
||||||
|
while (nxtitem(&ni, &land)) {
|
||||||
|
strength += land.lnd_item[I_MILIT];
|
||||||
|
if (lchr[land.lnd_type].l_flags & L_SECURITY) {
|
||||||
|
strength += land.lnd_item[I_MILIT];
|
||||||
|
nsec++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*nsecurity = nsec;
|
||||||
|
return strength;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Does the player->owner have military control of this sector?
|
* Does the player->owner have military control of this sector?
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue