/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2005, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure
*
* This program is free software; you can redistribute it and/or modify
*
* ---
*
- * See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
- * related information and legal notices. It is expected that any future
- * projects/authors will amend these files as needed.
+ * See files README, COPYING and CREDITS in the root of the source
+ * tree for related information and legal notices. It is expected
+ * that future projects/authors will amend these files as needed.
*
* ---
*
* Steve McClure, 1996-2000
*/
+#include <config.h>
+
#include <math.h>
#include "misc.h"
#include "player.h"
static int get_land(int combat_mode, struct combat *def, int uid,
struct llist *llp, int victim_land);
-s_char *att_mode[] = {
+char *att_mode[] = {
/* must match combat types in combat.h */
"defend", "attack", "assault", "paradrop", "board", "lboard"
};
inon ? inon == 1 ? "in " : "into " : "",
xyas(com->x, com->y, who));
} else if (com->type == EF_SHIP) {
- if (opt_SHIPNAMES) {
- return prbuf("%s%s %s(#%d)",
- inon ? inon == 1 ? "on " : "onto " : "",
- com->shp_mcp->m_name, com->shp_name,
- com->shp_uid);
- } else {
- return prbuf("%s%s #%d",
- inon ? inon == 1 ? "on " : "onto " : "",
- com->shp_mcp->m_name, com->shp_uid);
- }
+ return prbuf("%s%s %s(#%d)",
+ inon ? inon == 1 ? "on " : "onto " : "",
+ 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 pr_com(inon, com, player->cnum);
}
-/* Doing a sneak attack */
-static void
-do_sneak(struct combat *def, int success)
-{
- struct sctstr sect;
- struct natstr *natp = getnatp(player->cnum);
- int issneak = getrel(natp, def->own);
-
- if (def->type != EF_SECTOR)
- return;
-
- getsect(def->x, def->y, §);
-
- if (issneak == AT_WAR || !def->own || sect.sct_oldown == player->cnum)
- return;
-
- if (success)
- pr("Your sneak attack was successful\nBut ");
- else
- pr("Your sneak attack was unsuccessful\nAnd ");
-
- pr("it will cost you $5000\n");
- pr("War has been declared!!!!\n");
- wu(0, def->own, "Country %s (#%d) has Sneak Attacked!!\n",
- cname(player->cnum), player->cnum);
- wu(0, def->own, "Country %s (#%d) has Declared WAR on you!!\n",
- cname(player->cnum), player->cnum);
- player->dolcost += 5000;
- issneak = min(issneak, MOBILIZATION);
- nreport(player->cnum, N_DECL_WAR, def->own, 1);
- setrel(player->cnum, def->own, issneak);
-}
-
/*
* This is the combat object "type" based integrity check. It basically
* splits along three divisions: ship/sector, attacker/defender,
y = com->y;
break;
case EF_LAND:
- if (!getland(com->lnd_uid, &land)) {
+ if (!getland(com->lnd_uid, &land) || !land.lnd_own) {
if (isdef)
pr("Land unit #%d is not in the same sector!\n",
com->lnd_uid);
return att_combat_init(com, EF_BAD);
}
com->shp_mcp = &mchr[(int)ship.shp_type];
- if (opt_SHIPNAMES)
- strncpy(com->shp_name, ship.shp_name, MAXSHPNAMLEN);
+ strncpy(com->shp_name, ship.shp_name, MAXSHPNAMLEN);
if (!isdef && !player->owner) {
if (com->set)
pr("%s was just sunk!\n", prcom(0, com));
else if (mil == 1)
pr("Only 1 mil %s\n", prcom(1, com));
/* don't abandon attacking sectors or ships */
- com->troops = max(0, mil - 1);
+ com->troops = MAX(0, mil - 1);
}
com->plague = pstage == PLG_INFECT;
} else { /* not first time */
}
if (com->troops && com->troops + 1 > mil) {
if (com->own == owner && player->cnum == owner) /* not a takeover */
- pr("WARNING: Your mil %s has been reduced from %d to %d!\n", prcom(1, com), com->troops, max(0, mil - 1));
- com->troops = max(0, mil - 1);
+ pr("WARNING: Your mil %s has been reduced from %d to %d!\n", prcom(1, com), com->troops, MAX(0, mil - 1));
+ com->troops = MAX(0, mil - 1);
}
}
}
att_abort(int combat_mode, struct combat *off, struct combat *def)
{
struct sctstr sect;
- int issneak;
+ int rel;
s_char y_or_n[512];
struct natstr *natp;
}
if (opt_SLOW_WAR && def->own != player->cnum) {
natp = getnatp(player->cnum);
- issneak = getrel(natp, def->own);
+ rel = getrel(natp, def->own);
- if (issneak == ALLIED) {
+ 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 (opt_SNEAK_ATTACK) {
- getsect(def->x, def->y, §);
- if ((issneak != AT_WAR) && (def->own)
- && (def->own != player->cnum)
- && (sect.sct_oldown != player->cnum)
- && (issneak != SITZKRIEG) && (issneak != MOBILIZATION)) {
- pr("You're not at war with them!\n");
- if (!confirm("Do you really want to sneak attack (it will cost you $5000) [yn]? ")) {
- pr("Sneak attack cancelled!\n");
- return abort_attack();
- }
- }
- if ((issneak != AT_WAR) && (def->own)
- && (def->own != player->cnum)
- && (sect.sct_oldown != player->cnum)
- && ((issneak == MOBILIZATION) || (issneak == SITZKRIEG))) {
- pr("You're not at war with them!\n");
- return abort_attack();
- }
- } else {
- if ((issneak != AT_WAR) && (def->own) &&
- (sect.sct_oldown != player->cnum)) {
- pr("You're not at war with them!\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;
s_char *p;
*fortp = *shipp = *landp = *planep = 1;
- if (player->argp[offset] != (s_char *)0) {
- if ((player->argp[offset + 1] == (s_char *)0) ||
- (player->argp[offset + 2] == (s_char *)0) ||
- (player->argp[offset + 3] == (s_char *)0)) {
+ if (player->argp[offset] != NULL) {
+ if ((player->argp[offset + 1] == NULL) ||
+ (player->argp[offset + 2] == NULL) ||
+ (player->argp[offset + 3] == NULL)) {
pr("If any support arguments are used, all must be!\n");
return RET_SYN;
}
switch (combat_mode) {
case A_ATTACK:
off->mobcost +=
- max(1,
+ MAX(1,
(int)(attacking_mil *
sector_mcost(getsectp(def->x, def->y), MOB_ROAD)));
break;
case A_LBOARD:
- off->mobcost += max(1, attacking_mil / 5);
+ off->mobcost += MAX(1, attacking_mil / 5);
break;
case A_BOARD:
switch (off->type) {
case EF_SECTOR:
- off->mobcost += max(1, attacking_mil / 5);
+ off->mobcost += MAX(1, attacking_mil / 5);
break;
case EF_SHIP:
/* the 2 in the formula below is a fudge factor */
if (att_get_combat(off, 0) <= 0)
return 0;
if ((attacking_mil =
- min(attacking_mil, min(mob_support, off->troops))) <= 0)
+ MIN(attacking_mil, MIN(mob_support, off->troops))) <= 0)
return 0;
calc_mobcost(combat_mode, off, def, attacking_mil);
getsect(def->x, def->y, §);
if (sect.sct_oldown != player->cnum) {
- mines = min(sect.sct_mines, 20);
+ mines = MIN(sect.sct_mines, 20);
if (a_engineer)
mines = ldround(((double)mines / 2.0), 1);
if (mines > 0) {
/* Make sure we use a positive mobility here */
tmob = ((def->mob < 0) ? -(def->mob) : (def->mob));
def->mobcost =
- min(20, min(1, tmob - damage(tmob, 100 * d_cas / d_mil)));
+ MIN(20, MIN(1, tmob - damage(tmob, 100 * d_cas / d_mil)));
}
def->mil = def->troops;
}
if (off[n].type != EF_BAD && off[n].troops < a_troops[n]) {
if (off[n].type == EF_SECTOR && off[n].mil)
off[n].mobcost +=
- min(20,
- min(1,
- off[n].mob - damage(off[n].mob,
- 100 * (a_troops[n] -
- off[n].troops) /
- off[n].mil)));
+ MIN(20,
+ off[n].mob - damage(off[n].mob,
+ 100 * (a_troops[n] - off[n].troops)
+ / off[n].mil));
off[n].mil -= a_troops[n] - off[n].troops;
}
action, pr_com(0, def, def->own), d_cas);
}
- if (opt_SNEAK_ATTACK) {
- do_sneak(def, success);
- }
-
send_reacting_units_home(dlist);
/* putland the defending land */
if (off->own != player->cnum)
return;
d = sector_mcost(getsectp(def->x, def->y), MOB_ROAD);
- if ((mob_support = min(off->troops, (int)(off->mob / d))) <= 0)
+ if ((mob_support = MIN(off->troops, (int)(off->mob / d))) <= 0)
return;
sprintf(prompt, "How many mil to move in from %s (%d max)? ",
xyas(off->x, off->y, player->cnum), mob_support);
return;
if (att_get_combat(def, 0) < 0)
return;
- if ((num_mil = min(off->troops, num_mil)) <= 0) {
+ if ((num_mil = MIN(off->troops, num_mil)) <= 0) {
pr("No mil moved in from %s\n",
xyas(off->x, off->y, player->cnum));
return;
}
- mob_support = max(1, (int)(num_mil * d));
- off->mob -= min(off->mob, mob_support);
+ mob_support = MAX(1, (int)(num_mil * d));
+ off->mob -= MIN(off->mob, mob_support);
off->mil -= num_mil;
off->troops -= num_mil;
put_combat(off);