/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2013, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Copyright (C) 1986-2014, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure, Markus Armbruster
*
* Empire is free software: you can redistribute it and/or modify
* Known contributors to this file:
* Ken Stevens, 1995
* Steve McClure, 1996-2000
- * Markus Armbruster, 2006-2011
+ * Markus Armbruster, 2006-2014
*/
#include <config.h>
#include <ctype.h>
#include <math.h>
+#include "chance.h"
#include "combat.h"
#include "empobj.h"
#include "file.h"
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();
}
/* 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));
}
- /* Ok, everything is fine */
- return 0;
}
/* Attack and assault ask the user which kind of support they want */
land_answer[(int)land.lnd_army] != 'Y')
continue;
}
- if (!(llp = malloc(sizeof(struct ulist)))) {
- logerror("Malloc failed in attack!\n");
- abort_attack();
- return;
- }
- memset(llp, 0, sizeof(struct ulist));
- emp_insque(&llp->queue, olist);
+ llp = lnd_insque(&land, olist);
+ llp->supplied = 1;
llp->mobil = mobcost;
- 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);
continue;
intelligence_report(player->cnum, &land, a_spy,
"Scouts report defending unit:");
- if (!(llp = malloc(sizeof(struct ulist)))) {
- logerror("Malloc failed in attack!\n");
- abort_attack();
- return;
- }
- memset(llp, 0, sizeof(struct ulist));
- emp_insque(&llp->queue, list);
+ llp = lnd_insque(&land, list);
llp->supplied = lnd_supply_all(&land);
- llp->unit.land = land;
+ llp->mobil = 0.0;
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);
llp->mobil = 0.0;
putland(llp->unit.land.lnd_uid, &llp->unit.land);
if (llp->unit.land.lnd_own != player->cnum) {
- emp_remque((struct emp_qelem *)llp);
+ emp_remque(&llp->queue);
free(llp);
} else
get_oland(A_ATTACK, llp);
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 ulist));
-
- memset(llp, 0, sizeof(struct ulist));
+ llp = lnd_insque(&land, list);
llp->supplied = 1;
+ llp->mobil = 0.0;
llp->x = origx;
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);
* 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)
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);
}
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 ulist *llp;
+ struct emp_qelem *qp;
+ struct ulist *llp, *biggest;
for (n = 0; n <= off->last; ++n) {
if (off[n].type != EF_BAD) {
if (llp->unit.land.lnd_item[I_MILIT] > biggest_mil) {
biggest_mil = llp->unit.land.lnd_item[I_MILIT];
- biggest = qp;
+ biggest = llp;
}
}
if (biggest == NULL)
return CASUALTY_LUMP - to_take;
- llp = (struct ulist *)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);
}
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]);
double base = sp->sct_type == SCT_MOUNT ? 2.0 : 1.0;
double d = base + (dchr[sp->sct_type].d_dstr - base) * def;
- if (d > dchr[sp->sct_type].d_dstr)
- d = dchr[sp->sct_type].d_dstr;
- if (d < base)
- d = base;
- return d;
+ return LIMIT_TO(d, base, dchr[sp->sct_type].d_dstr);
}