cppcheck style fixes.

delete dead functions.
reactivate patzer_deathcloud.
This commit is contained in:
Enno Rehling 2017-12-08 19:59:49 +01:00
parent 4588419814
commit 9163d166ec
16 changed files with 45 additions and 312 deletions

View file

@ -10,6 +10,7 @@ require 'tests.e2.destroy'
require 'tests.e2.guard'
require 'tests.e2.stealth'
require 'tests.e2.items'
-- require 'tests.e2.ships'
require 'tests.items'
require 'tests.economy'
require 'tests.orders'

View file

@ -76,3 +76,29 @@ function test_dwarf_mining_bonus()
assert_equal(20, u:get_item('iron'))
assert_equal(84, r:get_resource('iron'))
end
function test_build_boat_low_skill()
local r = region.create(0, 0, "plain")
local f = faction.create("human", "build@example.com")
local u = unit.create(f, r, 1)
u:set_skill("shipcraft", 3) -- humans get +1
u:add_item("log", 10)
u:add_order("MACHE BOOT")
process_orders()
assert_not_equal(nil, u.ship)
assert_equal(4, u.ship.size)
assert_equal(6, u:get_item('log'))
end
function test_build_boat_high_skill()
local r = region.create(0, 0, "plain")
local f = faction.create("human", "build@example.com")
local u = unit.create(f, r, 1)
u:set_skill("shipcraft", 5) -- humans get +1
u:add_item("log", 10)
u:add_order("MACHE BOOT")
process_orders()
assert_not_equal(nil, u.ship)
assert_equal(5, u.ship.size)
assert_equal(5, u:get_item('log'))
end

View file

@ -10,10 +10,12 @@ end
function test_ship_requires_skill()
local r1 = region.create(0, 0, "ocean")
assert_not_nil(r1)
local r2 = region.create(1, 0, "ocean")
assert_not_nil(r2)
local f = faction.create("human", "fake@eressea.de", "de")
local u1 = unit.create(f, r1, 1)
u1.name = "fake"
u1.name = "fake"
u1.ship = ship.create(r1, "longboat")
u1:clear_orders()
u1:add_order("NACH O")
@ -22,21 +24,20 @@ function test_ship_requires_skill()
assert_equal(r1, u1.region)
end
function no_test_ship_happy_case()
function test_ship_happy_case()
local r1 = region.create(0, 0, "ocean")
local r2 = region.create(1, 0, "ocean")
local f = faction.create("human", "hodor@eressea.de", "de")
local u1 = unit.create(f, r1, 1)
local u2 = unit.create(f, r1, 1)
u1.ship = ship.create(r1, "longboat")
u2.ship = u1.ship
u2.ship = u1.ship
u1:clear_orders()
u1:add_order("NACH O")
u1:set_skill("sailing", 1) -- cptskill = 1
u2:set_skill("sailing", 9) -- sumskill = 10
u1:set_skill("sailing", 1) -- cptskill = 1
u2:set_skill("sailing", 9) -- sumskill = 10
process_orders()
assert_equal(r2, u1.ship.region)
assert_equal(r2, u1.region)
assert_equal(r2, u2.region)
end

View file

@ -2285,21 +2285,6 @@ void do_attack(fighter * af)
}
}
void do_regenerate(fighter * af)
{
troop ta;
unit *au = af->unit;
ta.fighter = af;
ta.index = af->fighting;
while (ta.index--) {
struct person *p = af->person + ta.index;
p->hp += effskill(au, SK_STAMINA, 0);
p->hp = MIN(unit_max_hp(au), p->hp);
}
}
static void add_tactics(tactics * ta, fighter * fig, int value)
{
if (value == 0 || value < ta->value)

View file

@ -430,46 +430,6 @@ const char *alliancename(const alliance * al)
return ibuf;
}
void alliancevictory(void)
{
const struct building_type *btype = bt_find("stronghold");
region *r = regions;
alliance *al = alliances;
if (btype == NULL)
return;
while (r != NULL) {
building *b = r->buildings;
while (b != NULL) {
if (b->type == btype) {
unit *u = building_owner(b);
if (u) {
fset(u->faction->alliance, FFL_MARK);
}
}
b = b->next;
}
r = r->next;
}
while (al != NULL) {
if (!fval(al, FFL_MARK)) {
faction **fp;
for (fp = &factions; *fp; ) {
faction *f = *fp;
if (f->alliance == al) {
ADDMSG(&f->msgs, msg_message("alliance::lost", "alliance", al));
destroyfaction(fp);
} else {
fp = &f->next;
}
}
}
else {
freset(al, FFL_MARK);
}
al = al->next;
}
}
void alliance_setname(alliance * self, const char *name)
{
free(self->name);

View file

@ -774,22 +774,11 @@ int cmp_wage(const struct building *b, const building * a)
return -1;
}
bool is_owner_building(const struct building * b)
{
region *r = b->region;
if (b->type->taxes && r->land && r->land->ownership) {
unit *u = building_owner(b);
return u && u->faction == r->land->ownership->owner;
}
return false;
}
int building_taxes(const building *b) {
assert(b);
return b->type->taxes;
}
int cmp_taxes(const building * b, const building * a)
{
faction *f = region_get_owner(b->region);

View file

@ -260,15 +260,6 @@ param_t getparam(const struct locale * lang)
return s ? findparam(s, lang) : NOPARAM;
}
unit *getnewunit(const region * r, const faction * f)
{
int n;
n = getid();
return findnewunit(r, f, n);
}
/* -- Erschaffung neuer Einheiten ------------------------------ */
static const char *forbidden[] = { "t", "te", "tem", "temp", NULL };

View file

@ -631,27 +631,6 @@ int set_item(unit * u, const item_type *itype, int value)
return value;
}
/* t_item::flags */
#define FL_ITEM_CURSED (1<<0)
#define FL_ITEM_NOTLOST (1<<1)
#define FL_ITEM_NOTINBAG (1<<2) /* nicht im Bag Of Holding */
#define FL_ITEM_ANIMAL (1<<3) /* ist ein Tier */
#define FL_ITEM_MOUNT ((1<<4) | FL_ITEM_ANIMAL) /* ist ein Reittier */
typedef struct t_item {
const char *name;
/* [0]: Einzahl fuer eigene; [1]: Mehrzahl fuer eigene;
* [2]: Einzahl fuer Fremde; [3]: Mehrzahl fuer Fremde */
bool is_resource;
skill_t skill;
int minskill;
int gewicht;
int preis;
unsigned int flags;
void(*benutze_funktion) (struct region *, struct unit *, int amount,
struct order *);
} t_item;
#include "move.h"
static int

View file

@ -123,50 +123,9 @@ char *rns(FILE * f, char *c, size_t size)
return c;
}
/* ------------------------------------------------------------- */
/* #define INNER_WORLD */
/* fürs debuggen nur den inneren Teil der Welt laden */
/* -9;-27;-1;-19;Sumpfloch */
int inner_world(region * r)
{
static int xy[2] = { 18, -45 };
static int size[2] = { 27, 27 };
if (r->x >= xy[0] && r->x < xy[0] + size[0] && r->y >= xy[1]
&& r->y < xy[1] + size[1])
return 2;
if (r->x >= xy[0] - 9 && r->x < xy[0] + size[0] + 9 && r->y >= xy[1] - 9
&& r->y < xy[1] + size[1] + 9)
return 1;
return 0;
}
int maxregions = -1;
int loadplane = 0;
enum {
U_MAN,
U_UNDEAD,
U_ILLUSION,
U_FIREDRAGON,
U_DRAGON,
U_WYRM,
U_SPELL,
U_TAVERNE,
U_MONSTER,
U_BIRTHDAYDRAGON,
U_TREEMAN,
MAXTYPES
};
race_t typus2race(unsigned char typus)
{
if (typus > 0 && typus <= 11)
return (race_t)(typus - 1);
return NORACE;
}
static void read_alliances(gamedata *data)
{
storage *store = data->store;

View file

@ -1929,10 +1929,6 @@ int read_unitid(const faction * f, const region * r)
char token[16];
const char *s = gettoken(token, sizeof(token));
/* Da s nun nur einen string enthaelt, suchen wir ihn direkt in der
* paramliste. machen wir das nicht, dann wird getnewunit in s nach der
* nummer suchen, doch dort steht bei temp-units nur "temp" drinnen! */
if (!s || *s == 0 || !isalnum(*s)) {
return -1;
}

View file

@ -2323,22 +2323,6 @@ int follow_ship(unit * u, order * ord)
return 1; /* true -> Einheitenliste von vorne durchgehen */
}
void destroy_damaged_ships(void)
{
region *r;
ship *sh, *shn;
for (r = regions; r; r = r->next) {
for (sh = r->ships; sh;) {
shn = sh->next;
if (sh->damage >= sh->size * DAMAGE_SCALE) {
remove_ship(&sh->region->ships, sh);
}
sh = shn;
}
}
}
/* Bewegung, Verfolgung, Piraterie */
/** ships that folow other ships

View file

@ -2358,7 +2358,6 @@ static int sp_earthquake(castorder * co)
/* ------------------------------------------------------------- */
void patzer_peasantmob(const castorder * co)
{
int anteil = 6, n;
unit *u;
attrib *a;
region *r;
@ -2370,8 +2369,9 @@ void patzer_peasantmob(const castorder * co)
faction *f = get_monsters();
const struct locale *lang = f->locale;
message *msg;
int anteil, n;
anteil += rng_int() % 4;
anteil = 6 + rng_int() % 4;
n = rpeasants(r) * anteil / 10;
rsetpeasants(r, rpeasants(r) - n);
assert(rpeasants(r) >= 0);
@ -2966,12 +2966,12 @@ static int sp_deathcloud(castorder * co)
return co->level;
}
void patzer_deathcloud(castorder * co)
static void patzer_deathcloud(const castorder * co)
{
unit *mage = co->magician.u;
int hp = (mage->hp - 2);
change_hitpoints(mage, -rng_int() % hp);
change_hitpoints(mage, -(rng_int() % hp));
ADDMSG(&mage->faction->msgs, msg_message("magic_fumble",
"unit region command", mage, mage->region, co->order));
@ -6144,89 +6144,6 @@ int sp_speed2(castorder * co)
return MAX(1, used);
}
/* ------------------------------------------------------------- */
/* Name: Magiefresser
* Stufe: 7
* Kosten: SPC_LEVEL
*
* Wirkung:
* Kann eine bestimmte Verzauberung angreifen und aufloesen. Die Staerke
* des Zaubers muss staerker sein als die der Verzauberung.
* Syntax:
* ZAUBERE \"Magiefresser\" REGION
* ZAUBERE \"Magiefresser\" EINHEIT <Einheit-Nr>
* ZAUBERE \"Magiefresser\" GEBAEUDE <Gebaeude-Nr>
* ZAUBERE \"Magiefresser\" SCHIFF <Schiff-Nr>
*
* "kc?c"
* Flags:
* (FARCASTING | SPELLLEVEL | ONSHIPCAST | TESTCANSEE)
*/
/* Jeder gebrochene Zauber verbraucht c->vigour an Zauberkraft
* (force) */
int sp_q_antimagie(castorder * co)
{
attrib **ap;
int obj;
curse *c = NULL;
int succ;
region *r = co_get_region(co);
unit *mage = co->magician.u;
int cast_level = co->level;
double force = co->force;
spellparameter *pa = co->par;
const char *ts = NULL;
obj = pa->param[0]->typ;
switch (obj) {
case SPP_REGION:
ap = &r->attribs;
ts = regionname(r, mage->faction);
break;
case SPP_TEMP:
case SPP_UNIT:
{
unit *u = pa->param[0]->data.u;
ap = &u->attribs;
ts = itoa36(u->no);
break;
}
case SPP_BUILDING:
{
building *b = pa->param[0]->data.b;
ap = &b->attribs;
ts = itoa36(b->no);
break;
}
case SPP_SHIP:
{
ship *sh = pa->param[0]->data.sh;
ap = &sh->attribs;
ts = itoa36(sh->no);
break;
}
default:
/* Das Zielobjekt wurde vergessen */
cmistake(mage, co->order, 203, MSG_MAGIC);
return 0;
}
succ = break_curse(ap, cast_level, force, c);
if (succ) {
ADDMSG(&mage->faction->msgs, msg_message("destroy_magic_effect",
"unit region command succ target", mage, mage->region, co->order, succ,
ts));
}
else {
ADDMSG(&mage->faction->msgs, msg_message("destroy_magic_noeffect",
"unit region command", mage, mage->region, co->order));
}
return MAX(succ, 1);
}
/* ------------------------------------------------------------- */
/* Name: Fluch brechen
* Stufe: 7
@ -6541,7 +6458,7 @@ static spelldata spell_functions[] = {
{ "forestfire", sp_forest_fire, patzer_peasantmob },
{ "draigdestroymagic", sp_destroy_magic, 0 },
{ "unholypower", sp_unholypower, 0 },
{ "deathcloud", sp_deathcloud, patzer_peasantmob },
{ "deathcloud", sp_deathcloud, patzer_deathcloud },
{ "summondragon", sp_summondragon, patzer_peasantmob },
{ "summonshadowlords", sp_summonshadowlords, patzer_peasantmob },
{ "chaossuction", sp_chaossuction, patzer_peasantmob },

View file

@ -622,7 +622,6 @@ int sp_dragonodem(struct castorder * co)
troop dt;
troop at;
int force, enemies;
int killed = 0;
const char *damage;
/* 11-26 HP */
@ -641,6 +640,7 @@ int sp_dragonodem(struct castorder * co)
}
else {
struct message *m;
int killed = 0;
at.fighter = fi;
at.index = 0;
@ -717,53 +717,6 @@ int sp_immolation(struct castorder * co)
return level;
}
int sp_drainodem(fighter * fi, int level, double power, spell * sp)
{
battle *b = fi->side->battle;
troop dt;
troop at;
int force, enemies;
int drained = 0;
int killed = 0;
const char *damage;
message *m;
/* 11-26 HP */
damage = spell_damage(4);
/* Jungdrache 3->54, Drache 6->216, Wyrm 12->864 Treffer */
force = lovar(get_force(power, 6));
enemies = count_enemies(b, fi, FIGHT_ROW, BEHIND_ROW - 1, SELECT_ADVANCE);
if (!enemies) {
m = msg_message("spell_out_of_range", "mage spell", fi->unit, sp);
message_all(b, m);
msg_release(m);
return 0;
}
at.fighter = fi;
at.index = 0;
while (force && drained < enemies) {
dt = select_enemy(fi, FIGHT_ROW, BEHIND_ROW - 1, SELECT_ADVANCE);
assert(dt.fighter);
if (hits(at, dt, NULL)) {
drain_exp(dt.fighter->unit, 90);
++drained;
killed += terminate(dt, at, AT_COMBATSPELL, damage, false);
}
--force;
}
m =
msg_message("cast_drainlife_effect", "mage spell amount", fi->unit, sp,
drained);
message_all(b, m);
msg_release(m);
return level;
}
/* ------------------------------------------------------------- */
/* PRECOMBAT */

View file

@ -12,17 +12,6 @@
#include <string.h>
#include <stdlib.h>
faction *get_faction_by_id(int uid)
{
faction *f;
for (f = factions; f; f = f->next) {
if (f->subscription == uid) {
return f;
}
}
return NULL;
}
typedef struct db_faction {
int uid;
int no;

View file

@ -57,13 +57,14 @@ const char *itoab(int i, int base)
static char sstr[80];
char *s, *dst;
static int index = 0; /* STATIC_XCALL: used across calls */
int neg = 0;
s = sstr + (index * 20);
index = (index + 1) & 3; /* quick for % 4 */
dst = s + 19;
(*dst--) = 0;
if (i != 0) {
int neg = 0;
if (i < 0) {
i = -i;
neg = 1;

View file

@ -60,7 +60,7 @@ arg_type *find_argtype(const char *name)
message_type *mt_new(const char *name, const char *args[])
{
int i, nparameters = 0;
int nparameters = 0;
message_type *mtype;
assert(name != NULL);
@ -85,6 +85,8 @@ message_type *mt_new(const char *name, const char *args[])
mtype->types = NULL;
}
if (args != NULL) {
int i;
for (i = 0; args[i]; ++i) {
const char *x = args[i];
const char *spos = strchr(x, ':');