/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
- * Ken Stevens, Steve McClure
+ * Copyright (C) 1986-2021, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Ken Stevens, Steve McClure, Markus Armbruster
*
- * This program is free software; you can redistribute it and/or modify
+ * Empire is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ---
*
* ---
*
* attsub.c: Attack subroutines
- *
+ *
* Known contributors to this file:
* Ken Stevens, 1995
* Steve McClure, 1996-2000
+ * Markus Armbruster, 2006-2016
*/
#include <config.h>
+#include <ctype.h>
#include <math.h>
+#include "chance.h"
+#include "combat.h"
+#include "empobj.h"
+#include "map.h"
#include "misc.h"
-#include "player.h"
-#include "file.h"
-#include "plague.h"
-#include "sect.h"
-#include "ship.h"
-#include "path.h"
+#include "mission.h"
#include "news.h"
-#include "treaty.h"
-#include "nat.h"
-#include "xy.h"
-#include "land.h"
#include "nsc.h"
-#include "mission.h"
-#include "combat.h"
-#include "item.h"
#include "optlist.h"
+#include "path.h"
+#include "plague.h"
+#include "player.h"
#include "prototypes.h"
+#include "unit.h"
+#include "xy.h"
#define CASUALTY_LUMP 1 /* How big casualty chunks should be */
static void ask_olist(int combat_mode, struct combat *off,
struct combat *def, struct emp_qelem *olist,
char *land_answer, int *a_spyp, int *a_engineerp);
-static void take_move_in_mob(int combat_mode, struct llist *llp,
+static void take_move_in_mob(int combat_mode, struct ulist *llp,
struct combat *off, struct combat *def);
static void move_in_land(int combat_mode, struct combat *off,
struct emp_qelem *olist, struct combat *def);
static int land_board_abort(struct combat *off, struct combat *def);
static int ask_off(int combat_mode, struct combat *off,
struct combat *def);
-static void get_dlist(struct combat *def, struct emp_qelem *list, int a_spy,
+static void get_dlist(struct combat *def, struct emp_qelem *, int a_spy,
int *d_spyp);
static int get_ototal(int combat_mode, struct combat *off,
struct emp_qelem *olist, double osupport, int check);
static int take_def(int combat_mode, struct emp_qelem *list,
struct combat *off, struct combat *def);
-static int get_land(int combat_mode, struct combat *def, int uid,
- struct llist *llp, int victim_land);
+static int get_oland(int, struct ulist *);
+static int get_dland(struct combat *, struct ulist *);
char *att_mode[] = {
/* must match combat types in combat.h */
} else if (com->type == EF_SHIP) {
return prbuf("%s%s %s(#%d)",
inon ? inon == 1 ? "on " : "onto " : "",
- com->shp_mcp->m_name, com->shp_name,
- com->shp_uid);
+ com->shp_mcp->m_name, com->shp_name, com->shp_uid);
} else if (com->type == EF_LAND) {
return prbuf("%s%s #%d",
inon ? inon == 1 ? "on " : "onto " : "",
/*
* This is the combat object "type" based integrity check. It basically
- * splits along three divisions: ship/sector, attacker/defender,
+ * splits along three divisions: ship/sector, attacker/defender,
* first time/not first time.
*/
y = com->y;
break;
case EF_LAND:
- if (!getland(com->lnd_uid, &land) || !land.lnd_own) {
+ if (!getland(com->lnd_uid, &land) || !land.lnd_own
+ || land.lnd_ship >= 0 || land.lnd_land >= 0) {
if (isdef)
pr("Land unit #%d is not in the same sector!\n",
com->lnd_uid);
return att_combat_init(com, EF_BAD);
}
if (opt_MARKET) {
- if (isdef && player->owner &&
- ontradingblock(EF_SHIP, &ship)) {
+ if (isdef && player->owner && ontradingblock(EF_SHIP, &ship)) {
pr("%s is on the trading block.\n", prcom(0, com));
return att_combat_init(com, EF_BAD);
}
mil);
com->troops = mil;
} else { /* attacker */
- if (owner != player->cnum && getrel(getnatp(owner), player->cnum) != ALLIED) {
+ if (owner != com->own && owner != player->cnum) {
/* must be EF_SECTOR */
- if (com->mil)
+ if (com->troops)
pr("WARNING: Your %d mil in %s were destroyed because %s just took the sector!\n",
com->mil, xyas(com->x, com->y, player->cnum),
cname(owner));
else
- pr("You no longer own %s\n",
- xyas(com->x, com->y, player->cnum));
+ pr("%s just took %s!\n",
+ cname(owner), xyas(com->x, com->y, player->cnum));
return att_combat_init(com, EF_BAD);
}
if (com->troops && com->troops + 1 > mil) {
if ((com->mob - com->mobcost) < -127)
sect.sct_mobil = -127;
else
- sect.sct_mobil = (short)(com->mob - com->mobcost);
+ sect.sct_mobil = com->mob - com->mobcost;
} else {
if ((com->mob - com->mobcost) < 0)
sect.sct_mobil = 0;
else
- sect.sct_mobil = (short)(com->mob - com->mobcost);
+ sect.sct_mobil = com->mob - com->mobcost;
}
}
- makelost(EF_SECTOR, sect.sct_own, 0, sect.sct_x, sect.sct_y);
- makenotlost(EF_SECTOR, com->own, 0, sect.sct_x, sect.sct_y);
sect.sct_own = com->own;
if (com->plague) {
if (sect.sct_pstage == PLG_HEALTHY)
else
land.lnd_mobil = (signed char)(com->mob - com->mobcost);
}
- makelost(EF_LAND, land.lnd_own, land.lnd_uid,
- land.lnd_x, land.lnd_y);
land.lnd_own = com->own;
- makenotlost(EF_LAND, land.lnd_own, land.lnd_uid,
- land.lnd_x, land.lnd_y);
if (com->plague) {
if (land.lnd_pstage == PLG_HEALTHY)
land.lnd_pstage = PLG_EXPOSED;
}
if (!(com->lnd_lcp->l_flags & L_SPY))
land.lnd_item[I_MILIT] = com->mil;
- lnd_count_units(&land);
if (com->own == player->cnum) {
land.lnd_mission = 0;
land.lnd_rflags = 0;
else
ship.shp_mobil = (signed char)(com->mob - com->mobcost);
}
- makelost(EF_SHIP, ship.shp_own, ship.shp_uid,
- ship.shp_x, ship.shp_y);
ship.shp_own = com->own;
- makenotlost(EF_SHIP, ship.shp_own, ship.shp_uid,
- ship.shp_x, ship.shp_y);
if (com->plague) {
if (ship.shp_pstage == PLG_HEALTHY)
ship.shp_pstage = PLG_EXPOSED;
}
ship.shp_item[I_MILIT] = com->mil;
- count_units(&ship);
if (com->own == player->cnum) {
ship.shp_mission = 0;
ship.shp_rflags = 0;
putship(com->shp_uid, &ship);
}
com->mobcost = 0;
+ /*
+ * FIXME if we just sank the ship, att_get_combat() will report
+ * "not in the same sector", and proceed to clobber *com. See
+ * also the workaround in boar().
+ */
att_get_combat(com, com->own != player->cnum);
}
att_abort(int combat_mode, struct combat *off, struct combat *def)
{
struct sctstr sect;
- int rel;
- char y_or_n[512];
- struct natstr *natp;
if (player->aborted)
return 1;
if (att_get_combat(off, 0) < 0)
return abort_attack();
if (off->type == EF_SHIP &&
+ !(off->x == def->x && off->y == def->y) &&
(!getsect(off->x, off->y, §) ||
sect.sct_type != SCT_WATER)) {
pr("%s can not %s from that far inland!\n",
return land_board_abort(off, def);
}
- if (off && def->sct_dcp->d_mcst <= 0) {
+ if (off && def->sct_dcp->d_mob0 < 0) {
pr("You can't %s a %s sector!\n",
att_mode[combat_mode], def->sct_dcp->d_name);
return abort_attack();
setcont(player->cnum, def->own, FOUND_SPY);
setcont(def->own, player->cnum, FOUND_SPY);
}
- if (opt_SLOW_WAR && def->own != player->cnum) {
- natp = getnatp(player->cnum);
- rel = getrel(natp, def->own);
- if (rel == ALLIED) {
- sprintf(y_or_n, "Sector is owned by %s, your ally, %s [yn]? ",
- cname(def->own), att_mode[combat_mode]);
- if (!confirm(y_or_n))
- return abort_attack();
-
- }
- if ((rel != AT_WAR) && (def->own) &&
- (sect.sct_oldown != player->cnum)) {
- pr("You're not at war with them!\n");
- return abort_attack();
- }
- }
return 0;
}
}
getship(off->shp_uid, &aship);
getship(def->shp_uid, &dship);
- if (techfact(aship.shp_tech, 1.0) * aship.shp_speed * off->eff
- <= techfact(dship.shp_tech, 1.0) * dship.shp_speed * def->eff) {
+ if (techfact(aship.shp_tech, shp_speed(&aship)) * off->eff
+ <= techfact(dship.shp_tech, shp_speed(&dship)) * def->eff) {
pr("Victim ship moves faster than you do!\n");
if (def->own)
wu(0, def->own,
- "%s (#%d) %s failed to catch %s\n",
- cname(aship.shp_own), aship.shp_own,
+ "%s %s failed to catch %s\n",
+ prnatid(aship.shp_own),
pr_com(0, off, def->own), pr_com(0, def, def->own));
return abort_attack();
}
}
if (off->type == EF_SECTOR) {
getsect(off->x, off->y, §);
- sectdamage(§, dam, 0);
+ sectdamage(§, dam);
putsect(§);
pr("Enemy fleet at %s does %d damage to %s\n",
xyas(def->x, def->y, player->cnum), dam, prcom(0, off));
/* The attack is valid. Tell the attacker about what they're going to hit */
-int
+void
att_show(struct combat *def)
{
- /* Note that we tell the player about the treaty BEFORE we tell them
- about the item. If we didn't, then they gain free information */
if (def->type == EF_SECTOR) {
- if (!trechk(player->cnum, def->own, LANATT))
- return abort_attack();
pr("%s is a %d%% %s %s with approximately %d military.\n",
xyas(def->x, def->y, player->cnum),
roundintby((int)def->eff, 10),
if (map_set(player->cnum, def->x, def->y, def->sct_dcp->d_mnem, 0))
writemap(player->cnum);
} else if (def->type == EF_SHIP || def->type == EF_LAND) {
- if (def->type == EF_SHIP) {
- if (!trechk(player->cnum, def->own, SEAATT))
- return abort_attack();
- } else {
- if (!trechk(player->cnum, def->own, LNDATT))
- return abort_attack();
- }
- pr("%s is about %d%% efficient and has approximately %d mil on board.\n", prcom(0, def), roundintby((int)def->eff, 10), roundintby(def->troops, 10));
+ pr("%s is about %d%% efficient and has approximately %d mil on board.\n",
+ prcom(0, def), roundintby((int)def->eff, 10),
+ roundintby(def->troops, 10));
}
- /* Ok, everything is fine */
- return 0;
}
/* Attack and assault ask the user which kind of support they want */
*fortp = *shipp = 0;
*landp = *planep = 0;
- if (!(p = getstarg(player->argp[offset], "Use fort support? ",
- buf)))
+ p = getstarg(player->argp[offset], "Use fort support? ", buf);
+ if (!p)
return RET_SYN;
if ((*p == 'y') || (*p == 'Y'))
*fortp = 1;
- if (!(p = getstarg(player->argp[offset + 1], "Use ship support? ",
- buf)))
+ p = getstarg(player->argp[offset + 1], "Use ship support? ", buf);
+ if (!p)
return RET_SYN;
if ((*p == 'y') || (*p == 'Y'))
*shipp = 1;
- if (!(p = getstarg(player->argp[offset + 2], "Use land support? ",
- buf)))
+ p = getstarg(player->argp[offset + 2], "Use land support? ", buf);
+ if (!p)
return RET_SYN;
if ((*p == 'y') || (*p == 'Y'))
*landp = 1;
- if (!(p = getstarg(player->argp[offset + 3], "Use plane support? ",
- buf)))
+ p = getstarg(player->argp[offset + 3], "Use plane support? ", buf);
+ if (!p)
return RET_SYN;
if ((*p == 'y') || (*p == 'Y'))
}
/*
- * Return path cost for ATTACKER to enter sector given by DEF.
- * MOBTYPE is a mobility type accepted by sector_mcost().
+ * Return path cost for @attacker to enter sector given by @def.
+ * @mobtype is a mobility type accepted by sector_mcost().
*/
static double
att_mobcost(natid attacker, struct combat *def, int mobtype)
case EF_SHIP:
/* the 2 in the formula below is a fudge factor */
getship(def->shp_uid, &ship);
- off->mobcost += (def->eff / 100) * (ship.shp_speed / 2);
+ off->mobcost += shp_speed(&ship) / 2 * def->eff / 100;
}
}
}
sprintf(prompt, "Number of mil from %s (max %d) : ",
prcom(0, off), mob_support);
}
- if ((attacking_mil = onearg(0, prompt)) < 0)
+ if ((attacking_mil = onearg(NULL, prompt)) < 0)
abort_attack();
if (att_abort(combat_mode, off, def))
return 0;
army = '~';
for (;;) {
p = getstring(prompt, buf);
- if (player->aborted || (p && *p == 'q')) {
+ if (!p || *p == 'q') {
abort_attack();
return 'N';
}
- if (!p || !*p)
+ if (!*p)
return 'n';
if (tolower(*p) == 'y' || tolower(*p) == 'n')
return *p;
{
struct nstr_item ni;
struct lndstr land;
- double mobcost;
- struct llist *llp;
+ double pathcost, mobcost;
+ int reqmob;
+ struct ulist *llp;
struct lchrstr *lcp;
double att_val;
int count = 0;
while (nxtitem(&ni, &land)) {
if (land.lnd_own != player->cnum)
continue;
- if (land.lnd_effic < LAND_MINEFF)
+ if (!land.lnd_own)
continue;
if (land_answer[(int)land.lnd_army] == 'N')
continue;
pr("Land units are not able to board this kind of ship\n");
return;
}
+ if (def->type == EF_SHIP
+ && (def->shp_mcp->m_flags & (M_SUPPLY | M_SUB)) != M_SUPPLY
+ && !(lcp->l_flags & L_LIGHT)) {
+ pr("Only light land units can board this kind of ship\n");
+ continue;
+ }
if (land.lnd_mobil <= 0) {
pr("%s is out of mobility, and cannot %s\n",
prland(&land), att_mode[combat_mode]);
}
switch (combat_mode) {
case A_ATTACK:
- mobcost = lnd_pathcost(&land,
- att_mobcost(off->own, def,
- lnd_mobtype(&land)));
- if (land.lnd_mobil < mobcost) {
- pr("%s does not have enough mobility (%d needed)\n",
- prland(&land), (int)ceil(mobcost));
- continue;
+ /*
+ * We used to let land units attack only if they have the
+ * mobility consumed by the attack, not counting combat
+ * and moving in to occupy. Making sure your land units
+ * reach attack positions with enough mobility left is a
+ * pain in the neck. We now require positive mobility,
+ * just like for marching. Except we don't allow rushing
+ * of high-mobility sectors (mountains): for those we
+ * still require attack mobility.
+ */
+ pathcost = att_mobcost(land.lnd_own, def, lnd_mobtype(&land));
+ mobcost = lnd_pathcost(&land, pathcost);
+ if (pathcost < 1.0) {
+ if (land.lnd_mobil <= 0) {
+ pr("%s is out of mobility\n", prland(&land));
+ continue;
+ }
+ } else {
+ reqmob = MIN(land_mob_max, (int)ceil(mobcost));
+ if (land.lnd_mobil < reqmob) {
+ pr("%s does not have enough mobility (%d needed)\n",
+ prland(&land), reqmob);
+ continue;
+ }
}
break;
case A_ASSAULT:
return;
}
att_val = attack_val(combat_mode, &land);
- if (att_val < 1.0) {
+ /*
+ * We need to let spies assault even though they have no
+ * offensive strength, because assault is how they sneak
+ * ashore. If this assault turns out to be a fight, they'll
+ * be removed by get_ototal().
+ */
+ if (att_val < 1.0
+ && !(combat_mode == A_ASSAULT && (lcp->l_flags & L_SPY))) {
pr("%s has no offensive strength\n", prland(&land));
continue;
}
- resupply_all(&land);
- putland(land.lnd_uid, &land);
- if (!has_supply(&land)) {
+ if (!lnd_supply_all(&land)) {
pr("%s is out of supply, and cannot %s\n",
prland(&land), att_mode[combat_mode]);
continue;
land_answer[(int)land.lnd_army] != 'Y')
continue;
}
- if (!(llp = malloc(sizeof(struct llist)))) {
- logerror("Malloc failed in attack!\n");
- abort_attack();
- return;
- }
- memset(llp, 0, sizeof(struct llist));
- emp_insque(&llp->queue, olist);
+ llp = lnd_insque(&land, olist);
+ llp->supplied = 1;
llp->mobil = mobcost;
- if (!get_land(combat_mode, def, land.lnd_uid, llp, 0))
- continue;
+ llp->x = llp->unit.land.lnd_x;
+ llp->y = llp->unit.land.lnd_y;
+ llp->eff = llp->unit.land.lnd_effic;
if (lnd_spyval(&land) > *a_spyp)
*a_spyp = lnd_spyval(&land);
- if (llp->lcp->l_flags & L_ENGINEER)
+ if (lchr[land.lnd_type].l_flags & L_ENGINEER)
++*a_engineerp;
if (def->type == EF_SHIP && ++count >= maxland)
break;
eff = com->eff / 100.0;
if (com->own == player->cnum) {
str = com->sct_dcp->d_ostr;
- eff = 1.0 + ((str - 1.0) * eff);
+ eff = 1.0 + (str - 1.0) * eff;
} else
eff = sector_strength(getsectp(com->x, com->y));
} else if (com->type == EF_SHIP && com->own != player->cnum) {
getship(com->shp_uid, &ship);
- eff = 1.0 + ship.shp_armor / 100.0;
+ eff = 1.0 + shp_armor(&ship) / 100.0;
}
return eff;
}
{
int d_spy = 0;
struct emp_qelem *qp;
- struct llist *llp;
+ struct ulist *llp;
int dtotal;
int old_dtotal;
att_reacting_units(def, dlist, a_spy, &d_spy, ototal);
for (qp = olist->q_forw; qp != olist; qp = qp->q_forw) {
- llp = (struct llist *)qp;
- intelligence_report(def->own, &llp->land, d_spy,
+ llp = (struct ulist *)qp;
+ intelligence_report(def->own, &llp->unit.land, d_spy,
"Scouts report attacking unit:");
}
int *d_spyp)
{
struct nstr_item ni;
- struct llist *llp;
+ struct ulist *llp;
struct lndstr land;
/* In here is where you need to take out spies and trains from the defending
continue;
if (def->type == EF_SECTOR && land.lnd_land >= 0)
continue;
+ if (def->type == EF_SECTOR && (lchr[land.lnd_type].l_flags & L_SPY))
+ continue;
if (def->type == EF_SHIP && land.lnd_ship != def->shp_uid)
continue;
if (def->type == EF_LAND && land.lnd_land != def->lnd_uid)
continue;
- if (!list) { /* Just estimating the enemy strength */
- intelligence_report(player->cnum, &land, a_spy,
- "Scouts report defending unit:");
- continue;
- }
- if (!(llp = malloc(sizeof(struct llist)))) {
- logerror("Malloc failed in attack!\n");
- abort_attack();
- return;
- }
- memset(llp, 0, sizeof(struct llist));
- emp_insque(&llp->queue, list);
- llp->supplied = has_supply(&land);
- if (!get_land(A_DEFEND, def, land.lnd_uid, llp, 1))
- continue;
+ intelligence_report(player->cnum, &land, a_spy,
+ "Scouts report defending unit:");
+ llp = lnd_insque(&land, list);
+ llp->supplied = lnd_supply_all(&land);
+ llp->mobil = 0.0;
+ llp->x = llp->unit.land.lnd_x;
+ llp->y = llp->unit.land.lnd_y;
+ llp->eff = llp->unit.land.lnd_effic;
if (lnd_spyval(&land) > *d_spyp)
*d_spyp = lnd_spyval(&land);
}
{
double ototal = 0.0;
struct emp_qelem *qp, *next;
- struct llist *llp;
+ struct ulist *llp;
int n, w;
+ double att_val;
/*
* first, total the attacking mil
for (qp = olist->q_forw; qp != olist; qp = next) {
next = qp->q_forw;
- llp = (struct llist *)qp;
- if (check && !get_land(combat_mode, 0, llp->land.lnd_uid, llp, 0))
+ llp = (struct ulist *)qp;
+ if (check && !get_oland(combat_mode, llp))
+ continue;
+ att_val = attack_val(combat_mode, &llp->unit.land);
+ if (check && att_val < 1.0) {
+ /*
+ * No offensive strength, and fighting hasn't even begun.
+ * Since ask_olist() doesn't offer such land units, except
+ * for spies sometimes, it's either a spy, or the strength
+ * must have been destroyed since then. Leave it behind.
+ */
+ lnd_print(player->cnum, llp, "has no offensive strength");
+ lnd_put_one(llp);
continue;
+ }
if (combat_mode == A_ATTACK) {
w = -1;
for (n = 0; n <= off->last; ++n) {
if (off[n].type == EF_BAD)
continue;
- if ((off[n].x == llp->land.lnd_x) &&
- (off[n].y == llp->land.lnd_y))
+ if ((off[n].x == llp->unit.land.lnd_x) &&
+ (off[n].y == llp->unit.land.lnd_y))
w = n;
}
if (w < 0) {
- lnd_delete(llp, "is in a sector not owned by you");
+ lnd_print(player->cnum, llp,
+ "can't attack from this sector now");
+ lnd_put_one(llp);
continue;
}
- ototal += attack_val(combat_mode, &llp->land) *
- att_combat_eff(off + w);
- } else {
- ototal += attack_val(combat_mode, &llp->land);
+ att_val *= att_combat_eff(off + w);
}
+ ototal += att_val;
}
ototal *= osupport;
{
double dtotal = 0.0, eff = 1.0, d_unit;
struct emp_qelem *qp, *next;
- struct llist *llp;
+ struct ulist *llp;
if (check && att_get_combat(def, 1) < 0)
return 0;
for (qp = list->q_forw; qp != list; qp = next) {
next = qp->q_forw;
- llp = (struct llist *)qp;
- if (check && !get_land(A_DEFEND, def, llp->land.lnd_uid, llp, 1))
+ llp = (struct ulist *)qp;
+ if (check && !get_dland(def, llp))
continue;
- d_unit = defense_val(&llp->land);
+ d_unit = defense_val(&llp->unit.land);
if (!llp->supplied)
d_unit /= 2.0;
dtotal += d_unit * eff;
}
/*
- * This is the land unit integrity check. Note that we don't print
- * warnings about victim land units because the attacker may not have seen them
+ * This is the land unit integrity check.
*/
static int
-get_land(int combat_mode, struct combat *def, int uid, struct llist *llp,
- int victim_land)
+get_oland(int combat_mode, struct ulist *llp)
{
- struct lndstr *lp = &llp->land;
+ struct lndstr *lp = &llp->unit.land;
char buf[512];
- getland(uid, lp);
+ getland(llp->unit.land.lnd_uid, lp);
- if (!llp->lcp) { /* first time */
- llp->x = llp->land.lnd_x;
- llp->y = llp->land.lnd_y;
- llp->lcp = &lchr[(int)llp->land.lnd_type];
- } else { /* not first time */
- if (lp->lnd_effic < LAND_MINEFF) {
- sprintf(buf, "was destroyed and is no longer a part of the %s",
- att_mode[combat_mode]);
- lnd_delete(llp, buf);
- return 0;
- }
- if (victim_land) {
- if (lp->lnd_x != def->x || lp->lnd_y != def->y) {
- lnd_delete(llp,
- "left to go fight another battle and is no longer a part of the defense");
- return 0;
- }
- } else {
- if (lp->lnd_own != player->cnum) {
- sprintf(buf,
- "was destroyed and is no longer a part of the %s",
- att_mode[combat_mode]);
- lnd_delete(llp, buf);
- return 0;
- }
- if (lp->lnd_x != llp->x || lp->lnd_y != llp->y) {
- sprintf(buf,
- "left to fight another battle and is no longer a part of the %s",
- att_mode[combat_mode]);
- lnd_delete(llp, buf);
- return 0;
- }
- if (lp->lnd_effic < llp->eff) {
- sprintf(buf, "damaged from %d%% to %d%%",
- llp->eff, lp->lnd_effic);
- lnd_print(llp, buf);
- }
- }
+ if (lp->lnd_own != player->cnum) {
+ sprintf(buf, "was destroyed and is no longer a part of the %s",
+ att_mode[combat_mode]);
+ lnd_print(player->cnum, llp, buf);
+ lnd_put_one(llp);
+ return 0;
+ }
+ if (lp->lnd_x != llp->x || lp->lnd_y != llp->y) {
+ sprintf(buf,
+ "left to fight another battle and is no longer a part of the %s",
+ att_mode[combat_mode]);
+ lnd_print(player->cnum, llp, buf);
+ lnd_put_one(llp);
+ return 0;
+ }
+ if (lp->lnd_effic < llp->eff) {
+ sprintf(buf, "damaged from %d%% to %d%%",
+ llp->eff, lp->lnd_effic);
+ lnd_print(player->cnum, llp, buf);
}
- llp->eff = llp->land.lnd_effic;
+ llp->eff = llp->unit.land.lnd_effic;
return 1;
}
-/*
- * Put the land unit on the disk. If there was some mobility cost, then
- * subtract it from the units mobility. Note that this works the same way
- * as sectors & ships in that no mobility is actually taken until the attacker
- * has committed to attacking.
- */
+static int
+get_dland(struct combat *def, struct ulist *llp)
+{
+ struct lndstr *lp = &llp->unit.land;
+
+ getland(llp->unit.land.lnd_uid, lp);
+
+ if (lp->lnd_own != def->own) {
+ lnd_print(llp->unit.land.lnd_own, llp,
+ "was destroyed and is no longer a part of the defense");
+ lnd_put_one(llp);
+ return 0;
+ }
+ if (lp->lnd_x != def->x || lp->lnd_y != def->y) {
+ lnd_print(llp->unit.land.lnd_own, llp,
+ "left to go fight another battle and is no longer a part of the defense");
+ lnd_put_one(llp);
+ return 0;
+ }
+
+ llp->eff = llp->unit.land.lnd_effic;
+ return 1;
+}
static void
kill_land(struct emp_qelem *list)
{
struct emp_qelem *qp, *next;
- struct llist *llp;
+ struct ulist *llp;
for (qp = list->q_forw; qp != list; qp = next) {
next = qp->q_forw;
- llp = (struct llist *)qp;
- if (llp->land.lnd_ship >= 0) {
- llp->land.lnd_effic = 0;
- lnd_delete(llp, "cannot return to the ship, and dies!");
+ llp = (struct ulist *)qp;
+ if (llp->unit.land.lnd_ship >= 0) {
+ llp->unit.land.lnd_effic = 0;
+ lnd_print(player->cnum, llp,
+ "cannot return to the ship, and dies!");
+ lnd_put_one(llp);
}
}
}
att_infect_units(struct emp_qelem *list, int plague)
{
struct emp_qelem *qp, *next;
- struct llist *llp;
+ struct ulist *llp;
if (!plague)
return;
for (qp = list->q_forw; qp != list; qp = next) {
next = qp->q_forw;
- llp = (struct llist *)qp;
- if (llp->land.lnd_pstage == PLG_HEALTHY)
- llp->land.lnd_pstage = PLG_EXPOSED;
+ llp = (struct ulist *)qp;
+ if (llp->unit.land.lnd_pstage == PLG_HEALTHY)
+ llp->unit.land.lnd_pstage = PLG_EXPOSED;
}
}
+/*
+ * Put the land unit on the disk. If there was some mobility cost, then
+ * subtract it from the units mobility. Note that this works the same way
+ * as sectors & ships in that no mobility is actually taken until the attacker
+ * has committed to attacking.
+ */
+
static void
-put_land(struct emp_qelem *list)
+put_oland(struct emp_qelem *list)
{
struct emp_qelem *qp, *next;
- struct llist *llp;
+ struct ulist *llp;
for (qp = list->q_forw; qp != list; qp = next) {
next = qp->q_forw;
- llp = (struct llist *)qp;
- llp->land.lnd_mission = 0;
- llp->land.lnd_harden = 0;
- llp->land.lnd_mobil -= (int)llp->mobil;
+ llp = (struct ulist *)qp;
+ llp->unit.land.lnd_mission = 0;
+ llp->unit.land.lnd_harden = 0;
+ llp->unit.land.lnd_mobil -= (int)llp->mobil;
llp->mobil = 0.0;
- putland(llp->land.lnd_uid, &llp->land);
- if (llp->land.lnd_own != player->cnum) {
- emp_remque((struct emp_qelem *)llp);
+ putland(llp->unit.land.lnd_uid, &llp->unit.land);
+ if (llp->unit.land.lnd_own != player->cnum) {
+ emp_remque(&llp->queue);
free(llp);
} else
- get_land(A_ATTACK, 0, llp->land.lnd_uid, llp, 0);
+ get_oland(A_ATTACK, llp);
}
}
{
struct nstr_item ni;
struct lndstr land;
- struct sctstr sect, dsect;
- struct llist *llp;
+ struct ulist *llp;
int dtotal;
double new_land = 0;
double mobcost;
double pathcost;
- int dist;
- int radius;
int origx, origy;
double eff = att_combat_eff(def);
- char buf[1024];
if (list)
dtotal = get_dtotal(def, list, 1.0, 1);
while (nxtitem(&ni, &land) && dtotal + new_land * eff < 1.2 * ototal) {
if (!land.lnd_own)
continue;
- if (!land.lnd_rad_max)
+ if (land.lnd_mission != MI_RESERVE)
continue;
if ((land.lnd_x == def->x) && (land.lnd_y == def->y))
continue;
continue;
/* Only supplied units can react */
- if (!has_supply(&land))
+ if (list ? !lnd_supply_all(&land) : !lnd_could_be_supplied(&land))
continue;
- dist = mapdist(land.lnd_x, land.lnd_y, def->x, def->y);
-
- getsect(land.lnd_x, land.lnd_y, §);
- /* Units on efficient headquarters can react 1 farther */
- if ((sect.sct_type == SCT_HEADQ) && (sect.sct_effic >= 60))
- radius = land.lnd_rad_max + 1;
- else
- radius = land.lnd_rad_max;
-
- if (land.lnd_mission == MI_RESERVE)
- radius += 2;
-
- if (dist > radius)
+ if (!in_oparea((struct empobj *)&land, def->x, def->y))
continue;
- getsect(def->x, def->y, &dsect);
- if (!BestLandPath(buf, §, &dsect, &pathcost,
- lnd_mobtype(&land)))
+ pathcost = path_find(land.lnd_x, land.lnd_y, def->x, def->y,
+ def->own, lnd_mobtype(&land));
+ if (pathcost < 0)
continue;
-
mobcost = lnd_pathcost(&land, pathcost);
if (land.lnd_mobil < mobcost)
continue;
wu(0, land.lnd_own, "%s reacts to %s.\n",
prland(&land), xyas(land.lnd_x, land.lnd_y, land.lnd_own));
- llp = malloc(sizeof(struct llist));
-
- memset(llp, 0, sizeof(struct llist));
+ llp = lnd_insque(&land, list);
llp->supplied = 1;
+ llp->mobil = 0.0;
llp->x = origx;
llp->y = origy;
- llp->lcp = &lchr[(int)land.lnd_type];
- llp->land = land;
- emp_insque(&llp->queue, list);
+ llp->eff = land.lnd_effic;
if (lnd_spyval(&land) > *d_spyp)
*d_spyp = lnd_spyval(&land);
ap = dam / 100.0;
osupport += ap;
}
- sprintf(outs, "attacker\t%1.2f\t%1.2f\t%1.2f\t%1.2f\n", af, as, au,
- ap);
+ sprintf(outs, "attacker\t%1.2f\t%1.2f\t%1.2f\t%1.2f", af, as, au, ap);
return osupport;
}
if (good)
*outs = '\0';
else
- sprintf(outs, "defender\t%1.2f\t%1.2f\t%1.2f\t%1.2f\n\n", df, ds,
- du, dp);
+ sprintf(outs, "defender\t%1.2f\t%1.2f\t%1.2f\t%1.2f",
+ df, ds, du, dp);
if (def->own) {
if (good < 0)
wu(0, def->own,
getsect(def->x, def->y, §);
if (sect.sct_oldown != player->cnum) {
- mines = MIN(sect.sct_mines, 20);
+ mines = SCT_LANDMINES(§);
+ mines = MIN(mines, 20);
if (a_engineer)
mines = ldround(mines / 2.0, 1);
if (mines > 0) {
/*
* I need to put a 1 at the end of the next four total_stren calls
- * becauase units & mil may have been damaged by collateral damage or
- * neclear warheads from the offensive & defensive support.
+ * because units & mil may have been damaged by collateral damage or
+ * nuclear warheads from the offensive & defensive support.
*/
ototal = get_ototal(combat_mode, off, olist, *osupportp, 1);
pr("\n\t\tsupport values\n");
pr("\t\tforts\tships\tunits\tplanes\n");
if (*osupportp != 1.0)
- pr("%s", osupports);
+ pr("%s\n", osupports);
if (*dsupportp != 1.0)
- pr("%s", dsupports);
+ pr("%s\n", dsupports);
+ pr("\n");
if (def->own) {
wu(0, def->own, "\n\t\tsupport values\n");
wu(0, def->own, "\t\tforts\tships\tunits\tplanes\n");
if (*osupportp != 1.0)
- wu(0, def->own, "%s", osupports);
+ wu(0, def->own, "%s\n", osupports);
if (*dsupportp != 1.0)
- wu(0, def->own, "%s", dsupports);
+ wu(0, def->own, "%s\n", dsupports);
+ wu(0, def->own, "\n");
}
}
int n;
int bodies = 0;
struct emp_qelem *qp;
- struct llist *llp;
+ struct ulist *llp;
for (n = 0; n <= off->last; ++n)
bodies += off[n].troops;
for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
- llp = (struct llist *)qp;
- bodies += llp->land.lnd_item[I_MILIT];
+ llp = (struct ulist *)qp;
+ bodies += llp->unit.land.lnd_item[I_MILIT];
}
return bodies;
}
att_infect_units(dlist, def->plague);
/*
- * Fighting is slightly random. There is always that last little
+ * Fighting is slightly random. There is always that last little
* effort you see people put in. Or the stray bullet that takes out
* an officer and the rest go into chaos. Things like that.
* Thus, we have added a very slight random factor that will sometimes
* since a single dead guy normally wouldn't cause a commander to
* rethink his strategies, but 50 dead guys might.
*/
- odds += (random() % 11 - 5) / 100.0;
+ odds += (roll(11) - 6) / 100.0;
if (odds < 0.0)
odds = 0.1;
if (odds > 1.0)
odds = 1.0;
- recalctime = 8 + (random() % 43);
+ recalctime = 7 + roll(43);
while (!success && ototal) {
if (chance(odds)) {
pr("!");
if (((a_cas + d_cas) % 70) == 69)
pr("\n");
if (recalctime-- <= 0) {
- recalctime = 8 + (random() % 43);
+ recalctime = 7 + roll(43);
odds = att_calcodds(ototal, dtotal);
- odds += (random() % 11 - 5) / 100.0;
+ odds += (roll(11) - 6) / 100.0;
if (odds < 0.0)
odds = 0.1;
if (odds > 1.0)
pr("- Casualties -\n Yours: %d\n", a_cas);
pr(" Theirs: %d\n", d_cas);
- pr("Papershuffling ... %.1f B.T.U\n", (d_cas + a_cas) * 0.15);
+ pr("Paper-shuffling ... %.1f BTU\n", (d_cas + a_cas) * 0.15);
player->btused += (int)((d_cas + a_cas) * 0.015 + 0.5);
if (success) {
nreport(player->cnum, news_item, def->own, 1);
if (def->own) {
wu(0, def->own,
- "%s (#%d) lost %d troops %s %s\nWe lost %d troops defending\n",
- cname(player->cnum), player->cnum, a_cas,
+ "%s lost %d troops %s %s\nWe lost %d troops defending\n",
+ prnatid(player->cnum), a_cas,
action, pr_com(0, def, def->own), d_cas);
}
send_reacting_units_home(dlist);
/* putland the defending land */
- lnd_put(dlist, 0);
+ lnd_put(dlist);
/* putland the attacking land */
- put_land(olist);
+ put_oland(olist);
/* put the victim sector/ship/land */
if (!success || !take_def(combat_mode, olist, off, def))
int to_take = CASUALTY_LUMP;
int biggest_troops = 0, index = -1;
int n, tot_troops = 0, biggest_mil, cas;
- struct emp_qelem *qp, *biggest;
- struct llist *llp;
+ struct emp_qelem *qp;
+ struct ulist *llp, *biggest;
for (n = 0; n <= off->last; ++n) {
if (off[n].type != EF_BAD) {
biggest = NULL;
biggest_mil = -1;
for (qp = olist->q_forw; qp != olist; qp = qp->q_forw) {
- llp = (struct llist *)qp;
+ llp = (struct ulist *)qp;
- if (llp->land.lnd_item[I_MILIT] > biggest_mil) {
- biggest_mil = llp->land.lnd_item[I_MILIT];
- biggest = qp;
+ if (llp->unit.land.lnd_item[I_MILIT] > biggest_mil) {
+ biggest_mil = llp->unit.land.lnd_item[I_MILIT];
+ biggest = llp;
}
}
if (biggest == NULL)
return CASUALTY_LUMP - to_take;
- llp = (struct llist *)biggest;
- cas = lnd_take_casualty(combat_mode, llp, to_take);
+ cas = lnd_take_casualty(combat_mode, biggest, to_take);
return CASUALTY_LUMP - (to_take - cas);
}
send_reacting_units_home(struct emp_qelem *list)
{
struct emp_qelem *qp, *next;
- struct llist *llp;
+ struct ulist *llp;
char buf[1024];
for (qp = list->q_forw; qp != list; qp = next) {
next = qp->q_forw;
- llp = (struct llist *)qp;
- if ((llp->land.lnd_x != llp->x) || (llp->land.lnd_y != llp->y)) {
+ llp = (struct ulist *)qp;
+ if ((llp->unit.land.lnd_x != llp->x) ||
+ (llp->unit.land.lnd_y != llp->y)) {
sprintf(buf, "returns to %s",
- xyas(llp->x, llp->y, llp->land.lnd_own));
- llp->land.lnd_x = llp->x;
- llp->land.lnd_y = llp->y;
- lnd_delete(llp, buf);
+ xyas(llp->x, llp->y, llp->unit.land.lnd_own));
+ llp->unit.land.lnd_x = llp->x;
+ llp->unit.land.lnd_y = llp->y;
+ lnd_print(llp->unit.land.lnd_own, llp, buf);
+ lnd_put_one(llp);
}
}
}
if (ototal <= 0) {
if (def->own && player->cnum != def->own) {
wu(0, def->own,
- "%s (#%d) considered %sing you @%s\n",
- cname(player->cnum), player->cnum,
+ "%s considered %sing you @%s\n",
+ prnatid(player->cnum),
att_mode[combat_mode], xyas(def->x, def->y, def->own));
}
pr("No troops for %s...\n", att_mode[combat_mode]);
{
int n;
int occuppied = 0;
- struct llist *llp, *delete_me = 0;
+ struct ulist *llp, *delete_me = NULL;
char buf[1024];
struct sctstr sect;
struct shpstr ship;
pr_com(2, def, def->own));
return 0;
} else {
- llp = (struct llist *)list->q_forw;
- llp->land.lnd_x = def->x;
- llp->land.lnd_y = def->y;
+ llp = (struct ulist *)list->q_forw;
+ llp->unit.land.lnd_x = def->x;
+ llp->unit.land.lnd_y = def->y;
take_move_in_mob(combat_mode, llp, off, def);
if (def->type == EF_SHIP) {
- llp->land.lnd_ship = def->shp_uid;
+ llp->unit.land.lnd_ship = def->shp_uid;
sprintf(buf, "boards %s", prcom(0, def));
+ lnd_print(player->cnum, llp, buf);
delete_me = llp;
} else {
- llp->land.lnd_ship = -1;
+ llp->unit.land.lnd_ship = -1;
sprintf(buf, "moves in to occupy %s",
xyas(def->x, def->y, player->cnum));
- lnd_delete(llp, buf);
+ lnd_print(player->cnum, llp, buf);
+ lnd_put_one(llp);
}
}
}
putsect(§);
} else if (def->type == EF_SHIP) {
getship(def->shp_uid, &ship);
- takeover_ship(&ship, player->cnum, 1);
+ takeover_ship(&ship, player->cnum);
putship(ship.shp_uid, &ship);
} else if (def->type == EF_LAND) {
getland(def->lnd_uid, &land);
- takeover_land(&land, player->cnum, 1);
+ takeover_land(&land, player->cnum);
putland(land.lnd_uid, &land);
}
if (delete_me)
- lnd_delete(delete_me, buf);
+ lnd_put_one(delete_me);
att_get_combat(def, 0);
return 1;
}
{
int n;
struct emp_qelem *qp, *next;
- struct llist *llp;
+ struct ulist *llp;
char buf[512];
char prompt[512];
char land_answer[256];
memset(land_answer, 0, sizeof(land_answer));
for (qp = olist->q_forw; qp != olist; qp = next) {
next = qp->q_forw;
- llp = (struct llist *)qp;
- answerp = &land_answer[(int)llp->land.lnd_army];
+ llp = (struct ulist *)qp;
+ answerp = &land_answer[(int)llp->unit.land.lnd_army];
if (player->aborted || att_get_combat(def, 0) < 0)
*answerp = 'N';
if (*answerp == 'Y')
continue;
+ if (!get_oland(A_ATTACK, llp))
+ continue;
if (*answerp != 'N') {
- if (!get_land(A_ATTACK, def, llp->land.lnd_uid, llp, 0))
- continue;
sprintf(prompt, "Move in with %s (%c %d%%) [ynYNq?] ",
- prland(&llp->land),
- llp->land.lnd_army ? llp->land.lnd_army : '~',
- llp->land.lnd_effic);
- *answerp = att_prompt(prompt, llp->land.lnd_army);
+ prland(&llp->unit.land),
+ llp->unit.land.lnd_army ? llp->unit.land.lnd_army : '~',
+ llp->unit.land.lnd_effic);
+ *answerp = att_prompt(prompt, llp->unit.land.lnd_army);
if (player->aborted || att_get_combat(def, 0) < 0)
*answerp = 'N';
- if (!get_land(A_ATTACK, def, llp->land.lnd_uid, llp, 0))
+ if (!get_oland(A_ATTACK, llp))
continue;
}
if (*answerp == 'y' || *answerp == 'Y')
continue;
sprintf(buf, "stays in %s",
- xyas(llp->land.lnd_x, llp->land.lnd_y, player->cnum));
- lnd_delete(llp, buf);
+ xyas(llp->unit.land.lnd_x, llp->unit.land.lnd_y,
+ player->cnum));
+ lnd_print(player->cnum, llp, buf);
+ lnd_put_one(llp);
}
if (QEMPTY(olist))
return;
if (att_get_combat(def, 0) < 0) {
for (qp = olist->q_forw; qp != olist; qp = next) {
next = qp->q_forw;
- llp = (struct llist *)qp;
- if (!get_land(A_ATTACK, def, llp->land.lnd_uid, llp, 0))
+ llp = (struct ulist *)qp;
+ if (!get_oland(A_ATTACK, llp))
continue;
sprintf(buf, "stays in %s",
- xyas(llp->land.lnd_x, llp->land.lnd_y, player->cnum));
- lnd_delete(llp, buf);
+ xyas(llp->unit.land.lnd_x, llp->unit.land.lnd_y,
+ player->cnum));
+ lnd_print(player->cnum, llp, buf);
+ lnd_put_one(llp);
}
return;
}
move_in_land(A_ATTACK, off, olist, def);
}
-/* Move offensive land units to the conquered sector or ship */
-
-static void
-move_in_land(int combat_mode, struct combat *off, struct emp_qelem *olist,
- struct combat *def)
+void
+att_move_land(int combat_mode, struct combat *off, struct emp_qelem *olist,
+ struct combat *def)
{
struct emp_qelem *qp, *next;
- struct llist *llp;
- char buf[512];
+ struct ulist *llp;
- if (QEMPTY(olist))
- return;
for (qp = olist->q_forw; qp != olist; qp = next) {
next = qp->q_forw;
- llp = (struct llist *)qp;
- if (!get_land(combat_mode, def, llp->land.lnd_uid, llp, 0))
+ llp = (struct ulist *)qp;
+ if (!get_oland(combat_mode, llp))
continue;
take_move_in_mob(combat_mode, llp, off, def);
- llp->land.lnd_x = def->x;
- llp->land.lnd_y = def->y;
+ llp->unit.land.lnd_x = def->x;
+ llp->unit.land.lnd_y = def->y;
if (def->type == EF_SHIP)
- llp->land.lnd_ship = def->shp_uid;
+ llp->unit.land.lnd_ship = def->shp_uid;
else
- llp->land.lnd_ship = -1;
+ llp->unit.land.lnd_ship = -1;
}
- if (QEMPTY(olist))
- return;
+}
+
+/* Move offensive land units to the conquered sector or ship */
+
+static void
+move_in_land(int combat_mode, struct combat *off, struct emp_qelem *olist,
+ struct combat *def)
+{
+ struct emp_qelem *qp, *next;
+ struct ulist *llp;
+ char buf[512];
+
+ att_move_land(combat_mode, off, olist, def);
+
if (def->type == EF_SECTOR) {
if (opt_INTERDICT_ATT) {
- lnd_sweep(olist, 0, 0, def->own);
+ lnd_sweep(olist, 0, 0, player->cnum);
lnd_check_mines(olist);
}
sprintf(buf, "now occupies %s", prcom(0, def));
} else {
sprintf(buf, "boards %s", prcom(0, def));
}
- if (QEMPTY(olist))
- return;
+
for (qp = olist->q_forw; qp != olist; qp = next) {
next = qp->q_forw;
- llp = (struct llist *)qp;
- lnd_print(llp, buf);
+ llp = (struct ulist *)qp;
+ lnd_print(player->cnum, llp, buf);
}
- if (QEMPTY(olist))
- return;
- lnd_put(olist, 0);
+
+ lnd_put(olist);
}
/*
return;
sprintf(prompt, "How many mil to move in from %s (%d max)? ",
xyas(off->x, off->y, player->cnum), mob_support);
- if (!(p = getstring(prompt, buf)) || !*p || (num_mil = atoi(p)) <= 0)
+ p = getstring(prompt, buf);
+ if (!p || !*p || (num_mil = atoi(p)) <= 0)
return;
/* Make sure we don't move in more than we can support mobility-wise */
if (num_mil > mob_support)
left = commdamage(num_mil, dam, I_MILIT);
if (left < num_mil) {
if (left) {
- pr("%d of the mil you were moving were destroyed!\nOnly %d mil made it to %s\n", num_mil - left, left, xyas(def->x, def->y, player->cnum));
+ pr("%d of the mil you were moving were destroyed!\n"
+ "Only %d mil made it to %s\n",
+ num_mil - left, left,
+ xyas(def->x, def->y, player->cnum));
} else {
pr("All of the mil you were moving were destroyed!\n");
}
/* Charge land units for moving into a sector or onto a ship */
static void
-take_move_in_mob(int combat_mode, struct llist *llp, struct combat *off,
+take_move_in_mob(int combat_mode, struct ulist *llp, struct combat *off,
struct combat *def)
{
- int mobcost;
- int new;
+ double mob = llp->unit.land.lnd_mobil;
+ double gain = etu_per_update * land_mob_scale;
+ double mobcost, moblim;
switch (combat_mode) {
case A_ATTACK:
- mobcost = lnd_pathcost(&llp->land,
- att_mobcost(off->own, def,
- lnd_mobtype(&llp->land)));
- new = llp->land.lnd_mobil - mobcost;
- if (new < -127)
- new = -127;
- llp->land.lnd_mobil = new;
+ mobcost = lnd_pathcost(&llp->unit.land,
+ att_mobcost(llp->unit.land.lnd_own, def,
+ lnd_mobtype(&llp->unit.land)));
break;
case A_ASSAULT:
- if (off->shp_mcp->m_flags & M_LAND) {
- if (llp->lcp->l_flags & L_MARINE)
- llp->land.lnd_mobil -=
- (float)etu_per_update * land_mob_scale * 0.5;
- else
- llp->land.lnd_mobil -= (float)etu_per_update * land_mob_scale;
+ /*
+ * Set mobcost to basic assault cost, moblim to maximum
+ * mobility to keep when assaulting from non-landing ship
+ */
+ if (lchr[llp->unit.land.lnd_type].l_flags & L_MARINE) {
+ mobcost = gain / 2.0;
+ moblim = 0;
} else {
- if (llp->lcp->l_flags & L_MARINE)
- llp->land.lnd_mobil = 0;
- else
- llp->land.lnd_mobil = -(float)etu_per_update * land_mob_scale;
+ mobcost = gain;
+ moblim = -gain;
}
+ if (!(off->shp_mcp->m_flags & M_LAND))
+ /* Not a landing ship, ensure we go to or below moblim */
+ mobcost = MAX(mobcost, mob - moblim);
break;
case A_BOARD:
- /* I arbitrarily chose the numbers 10 and 40 below -KHS */
- if (llp->lcp->l_flags & L_MARINE)
- llp->land.lnd_mobil -= 10;
+ if (lchr[llp->unit.land.lnd_type].l_flags & L_MARINE)
+ mobcost = 10;
else
- llp->land.lnd_mobil -= 40;
+ mobcost = 40;
break;
+ default:
+ CANT_REACH();
+ mobcost = 0;
}
- llp->land.lnd_harden = 0;
+
+ mob -= mobcost;
+ if (mob < -127.0)
+ mob = -127.0;
+ llp->unit.land.lnd_mobil = (signed char)mob;
+ llp->unit.land.lnd_harden = 0;
}
static void
/*
* sector_strength - Everyone starts at 1. You can get up to a max
* of d_dstr, depending on how much you build up the
- * defenses of the sector.
+ * defenses of the sector.
*/
double
double base = sp->sct_type == SCT_MOUNT ? 2.0 : 1.0;
double d = base + (dchr[sp->sct_type].d_dstr - base) * def;
- if (CANT_HAPPEN(d > dchr[sp->sct_type].d_dstr))
- d = dchr[sp->sct_type].d_dstr;
- if (CANT_HAPPEN(d < base))
- d = base;
- return d;
+ return LIMIT_TO(d, base, dchr[sp->sct_type].d_dstr);
}