/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
- * Ken Stevens, Steve McClure
+ * Copyright (C) 1986-2012, 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/>.
*
* ---
*
* Known contributors to this file:
* Ken Stevens, 1995
* Steve McClure, 1996-2000
- * Markus Armbruster, 2006-2008
+ * Markus Armbruster, 2006-2011
*/
#include <config.h>
#include <ctype.h>
#include <math.h>
#include "combat.h"
+#include "empobj.h"
#include "file.h"
#include "map.h"
#include "misc.h"
#include "mission.h"
+#include "news.h"
#include "nsc.h"
#include "optlist.h"
#include "path.h"
#include "plague.h"
#include "player.h"
#include "prototypes.h"
-#include "xy.h"
-#include "empobj.h"
#include "unit.h"
+#include "xy.h"
#define CASUALTY_LUMP 1 /* How big casualty chunks should be */
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 ulist *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 " : "",
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;
}
}
sect.sct_own = com->own;
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;
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;
}
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;
*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'))
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;
* of high-mobility sectors (mountains): for those we
* still require attack mobility.
*/
- pathcost = att_mobcost(off->own, def, lnd_mobtype(&land));
+ 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 has no offensive strength\n", prland(&land));
continue;
}
- resupply_all(&land);
- putland(land.lnd_uid, &land);
- if (!lnd_in_supply(&land)) {
+ if (!lnd_supply_all(&land)) {
pr("%s is out of supply, and cannot %s\n",
prland(&land), att_mode[combat_mode]);
continue;
memset(llp, 0, sizeof(struct ulist));
emp_insque(&llp->queue, olist);
llp->mobil = mobcost;
- if (!get_land(combat_mode, def, land.lnd_uid, llp, 0))
- continue;
+ llp->unit.land = land;
+ llp->x = llp->unit.land.lnd_x;
+ llp->y = llp->unit.land.lnd_y;
+ llp->chrp = (struct empobj_chr *)&lchr[(int)llp->unit.land.lnd_type];
+ llp->eff = llp->unit.land.lnd_effic;
if (lnd_spyval(&land) > *a_spyp)
*a_spyp = lnd_spyval(&land);
if (((struct lchrstr *)llp->chrp)->l_flags & L_ENGINEER)
}
memset(llp, 0, sizeof(struct ulist));
emp_insque(&llp->queue, list);
- resupply_all(&land);
- putland(land.lnd_uid, &land);
- llp->supplied = lnd_in_supply(&land);
- if (!get_land(A_DEFEND, def, land.lnd_uid, llp, 1))
- continue;
+ llp->supplied = lnd_supply_all(&land);
+ llp->unit.land = land;
+ llp->x = llp->unit.land.lnd_x;
+ llp->y = llp->unit.land.lnd_y;
+ llp->chrp = (struct empobj_chr *)&lchr[(int)llp->unit.land.lnd_type];
+ llp->eff = llp->unit.land.lnd_effic;
if (lnd_spyval(&land) > *d_spyp)
*d_spyp = lnd_spyval(&land);
}
for (qp = olist->q_forw; qp != olist; qp = next) {
next = qp->q_forw;
llp = (struct ulist *)qp;
- if (check && !get_land(combat_mode, 0, llp->unit.land.lnd_uid, llp, 0))
+ if (check && !get_oland(combat_mode, llp))
continue;
if (combat_mode == A_ATTACK) {
w = -1;
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_delete(llp);
continue;
}
ototal += attack_val(combat_mode, &llp->unit.land) *
for (qp = list->q_forw; qp != list; qp = next) {
next = qp->q_forw;
llp = (struct ulist *)qp;
- if (check && !get_land(A_DEFEND, def, llp->unit.land.lnd_uid, llp, 1))
+ if (check && !get_dland(def, llp))
continue;
d_unit = defense_val(&llp->unit.land);
if (!llp->supplied)
}
/*
- * 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 ulist *llp,
- int victim_land)
+get_oland(int combat_mode, struct ulist *llp)
{
struct lndstr *lp = &llp->unit.land;
char buf[512];
- getland(uid, lp);
+ getland(llp->unit.land.lnd_uid, lp);
- if (!llp->chrp) { /* first time */
- llp->x = llp->unit.land.lnd_x;
- llp->y = llp->unit.land.lnd_y;
- llp->chrp = (struct empobj_chr *)&lchr[(int)llp->unit.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_delete(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_delete(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->unit.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;
+ char buf[512];
+
+ getland(llp->unit.land.lnd_uid, lp);
+
+ if (lp->lnd_effic < LAND_MINEFF) {
+ sprintf(buf, "was destroyed and is no longer a part of the defense");
+ lnd_print(llp->unit.land.lnd_own, llp, buf);
+ lnd_delete(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_delete(llp);
+ return 0;
+ }
+
+ llp->eff = llp->unit.land.lnd_effic;
+ return 1;
+}
static void
kill_land(struct emp_qelem *list)
llp = (struct ulist *)qp;
if (llp->unit.land.lnd_ship >= 0) {
llp->unit.land.lnd_effic = 0;
- lnd_delete(llp, "cannot return to the ship, and dies!");
+ lnd_print(player->cnum, llp,
+ "cannot return to the ship, and dies!");
+ lnd_delete(llp);
}
}
}
}
}
+/*
+ * 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 ulist *llp;
emp_remque((struct emp_qelem *)llp);
free(llp);
} else
- get_land(A_ATTACK, 0, llp->unit.land.lnd_uid, llp, 0);
+ get_oland(A_ATTACK, llp);
}
}
{
struct nstr_item ni;
struct lndstr land;
- struct sctstr sect, dsect;
struct ulist *llp;
int dtotal;
double new_land = 0;
double pathcost;
int origx, origy;
double eff = att_combat_eff(def);
- char buf[1024];
if (list)
dtotal = get_dtotal(def, list, 1.0, 1);
continue;
/* Only supplied units can react */
- if (list) {
- resupply_all(&land);
- putland(land.lnd_uid, &land);
- if (!lnd_in_supply(&land))
- continue;
- } else {
- if (!lnd_could_be_supplied(&land))
- continue;
- }
+ if (list ? !lnd_supply_all(&land) : !lnd_could_be_supplied(&land))
+ continue;
if (!in_oparea((struct empobj *)&land, def->x, def->y))
continue;
- getsect(land.lnd_x, land.lnd_y, §);
- 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;
llp->y = origy;
llp->chrp = (struct empobj_chr *)&lchr[(int)land.lnd_type];
llp->unit.land = land;
+ llp->eff = land.lnd_effic;
emp_insque(&llp->queue, list);
if (lnd_spyval(&land) > *d_spyp)
*d_spyp = lnd_spyval(&land);
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) {
unit_put(dlist, 0);
/* 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))
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_delete(llp, buf);
+ lnd_print(llp->unit.land.lnd_own, llp, buf);
+ lnd_delete(llp);
}
}
}
{
int n;
int occuppied = 0;
- struct ulist *llp, *delete_me = 0;
+ struct ulist *llp, *delete_me = NULL;
char buf[1024];
struct sctstr sect;
struct shpstr ship;
if (def->type == EF_SHIP) {
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->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_delete(llp);
}
}
}
putland(land.lnd_uid, &land);
}
if (delete_me)
- lnd_delete(delete_me, buf);
+ lnd_delete(delete_me);
att_get_combat(def, 0);
return 1;
}
*answerp = 'N';
if (*answerp == 'Y')
continue;
+ if (!get_oland(A_ATTACK, llp))
+ continue;
if (*answerp != 'N') {
- if (!get_land(A_ATTACK, def, llp->unit.land.lnd_uid, llp, 0))
- continue;
sprintf(prompt, "Move in with %s (%c %d%%) [ynYNq?] ",
prland(&llp->unit.land),
llp->unit.land.lnd_army ? llp->unit.land.lnd_army : '~',
*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->unit.land.lnd_uid, llp, 0))
+ if (!get_oland(A_ATTACK, llp))
continue;
}
if (*answerp == 'y' || *answerp == 'Y')
sprintf(buf, "stays in %s",
xyas(llp->unit.land.lnd_x, llp->unit.land.lnd_y,
player->cnum));
- lnd_delete(llp, buf);
+ lnd_print(player->cnum, llp, buf);
+ lnd_delete(llp);
}
if (QEMPTY(olist))
return;
for (qp = olist->q_forw; qp != olist; qp = next) {
next = qp->q_forw;
llp = (struct ulist *)qp;
- if (!get_land(A_ATTACK, def, llp->unit.land.lnd_uid, llp, 0))
+ if (!get_oland(A_ATTACK, llp))
continue;
sprintf(buf, "stays in %s",
xyas(llp->unit.land.lnd_x, llp->unit.land.lnd_y,
player->cnum));
- lnd_delete(llp, buf);
+ lnd_print(player->cnum, llp, buf);
+ lnd_delete(llp);
}
return;
}
for (qp = olist->q_forw; qp != olist; qp = next) {
next = qp->q_forw;
llp = (struct ulist *)qp;
- if (!get_land(combat_mode, def, llp->unit.land.lnd_uid, llp, 0))
+ if (!get_oland(combat_mode, llp))
continue;
take_move_in_mob(combat_mode, llp, off, def);
llp->unit.land.lnd_x = def->x;
return;
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));
for (qp = olist->q_forw; qp != olist; qp = next) {
next = qp->q_forw;
llp = (struct ulist *)qp;
- lnd_print(llp, buf);
+ lnd_print(player->cnum, llp, buf);
}
if (QEMPTY(olist))
return;
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");
}
switch (combat_mode) {
case A_ATTACK:
mobcost = lnd_pathcost(&llp->unit.land,
- att_mobcost(off->own, def,
+ att_mobcost(llp->unit.land.lnd_own, def,
lnd_mobtype(&llp->unit.land)));
break;
case A_ASSAULT: