2001-01-25 10:37:55 +01:00
|
|
|
|
/* vi: set ts=2:
|
|
|
|
|
*
|
2001-12-10 01:13:39 +01:00
|
|
|
|
*
|
2003-07-29 11:48:03 +02:00
|
|
|
|
* Eressea PB(E)M host Copyright (C) 1998-2003
|
2001-01-25 10:37:55 +01:00
|
|
|
|
* Christian Schlittchen (corwin@amber.kn-bremen.de)
|
|
|
|
|
* Katja Zedel (katze@felidae.kn-bremen.de)
|
|
|
|
|
* Henning Peters (faroul@beyond.kn-bremen.de)
|
|
|
|
|
* Enno Rehling (enno@eressea-pbem.de)
|
|
|
|
|
* Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de)
|
|
|
|
|
*
|
|
|
|
|
* This program may not be used, modified or distributed without
|
|
|
|
|
* prior permission by the authors of Eressea.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#include <eressea.h>
|
|
|
|
|
#include "weapons.h"
|
|
|
|
|
|
|
|
|
|
#include <unit.h>
|
|
|
|
|
#include <build.h>
|
|
|
|
|
#include <race.h>
|
|
|
|
|
#include <item.h>
|
|
|
|
|
#include <battle.h>
|
2002-04-23 21:00:23 +02:00
|
|
|
|
#include <pool.h>
|
2001-01-25 10:37:55 +01:00
|
|
|
|
|
2001-12-10 01:13:39 +01:00
|
|
|
|
/* util includes */
|
|
|
|
|
#include <functions.h>
|
|
|
|
|
|
|
|
|
|
/* libc includes */
|
2001-01-25 10:37:55 +01:00
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
|
|
enum {
|
2006-02-12 00:18:10 +01:00
|
|
|
|
WP_NONE,
|
|
|
|
|
WP_MAX
|
2001-01-25 10:37:55 +01:00
|
|
|
|
};
|
|
|
|
|
|
2002-04-27 16:46:27 +02:00
|
|
|
|
/* damage types */
|
2001-01-25 10:37:55 +01:00
|
|
|
|
|
2002-04-27 16:46:27 +02:00
|
|
|
|
#define CUT (1<<0)
|
|
|
|
|
#define PIERCE (1<<1)
|
|
|
|
|
#define BASH (1<<2)
|
|
|
|
|
#define ARMORPIERCING (1<<3)
|
2001-01-25 10:37:55 +01:00
|
|
|
|
|
|
|
|
|
typedef struct weapondata {
|
2006-02-12 00:18:10 +01:00
|
|
|
|
double magres;
|
|
|
|
|
const char *damfoot;
|
|
|
|
|
const char *damhorse;
|
|
|
|
|
item_t item;
|
|
|
|
|
skill_t skill;
|
|
|
|
|
char attmod;
|
|
|
|
|
char defmod;
|
|
|
|
|
boolean rear;
|
|
|
|
|
boolean is_magic;
|
|
|
|
|
struct reload {
|
|
|
|
|
int type;
|
|
|
|
|
char time;
|
|
|
|
|
} reload;
|
|
|
|
|
char damage_type;
|
2001-01-25 10:37:55 +01:00
|
|
|
|
} weapondata;
|
|
|
|
|
|
|
|
|
|
static weapondata weapontable[WP_MAX + 1] =
|
|
|
|
|
/* MagRes, Schaden/Fu<46>, Schaden/Pferd, Item, Skill, OffMod, DefMod,
|
2004-06-11 21:59:02 +02:00
|
|
|
|
* missile, is_magic */
|
2001-01-25 10:37:55 +01:00
|
|
|
|
{
|
|
|
|
|
/* Unbewaffnet */
|
2006-02-11 17:11:16 +01:00
|
|
|
|
{0.00, "1d5+0", "1d6+0", MAX_ITEMS, SK_MELEE, 0, 0, false, false, { 0, 0}, BASH },
|
2001-01-25 10:37:55 +01:00
|
|
|
|
/* Dummy */
|
2006-02-11 17:11:16 +01:00
|
|
|
|
{0.00, "0d0+0", "0d0+0", MAX_ITEMS, SK_MELEE, 0, 0, false, false, { 0, 0}, 0 }
|
2001-01-25 10:37:55 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
weapon_type * oldweapontype[WP_MAX];
|
2001-12-10 01:13:39 +01:00
|
|
|
|
|
|
|
|
|
static boolean
|
2005-10-29 18:10:08 +02:00
|
|
|
|
attack_firesword(const troop * at, const struct weapon_type * wtype, int *casualties, int row)
|
2001-12-10 01:13:39 +01:00
|
|
|
|
{
|
|
|
|
|
fighter *fi = at->fighter;
|
|
|
|
|
troop dt;
|
|
|
|
|
/* Immer aus der ersten Reihe nehmen */
|
|
|
|
|
int minrow = FIGHT_ROW;
|
|
|
|
|
int maxrow = FIGHT_ROW;
|
2002-01-20 12:03:50 +01:00
|
|
|
|
int enemies = 0;
|
2001-12-10 01:13:39 +01:00
|
|
|
|
int killed = 0;
|
|
|
|
|
const char *damage = "2d8";
|
|
|
|
|
int force = 1+rand()%10;
|
|
|
|
|
|
2002-01-20 12:03:50 +01:00
|
|
|
|
if (row==FIGHT_ROW) {
|
2004-09-11 19:29:13 +02:00
|
|
|
|
enemies = count_enemies(fi->side->battle, fi->side, minrow, maxrow, true);
|
2002-01-20 12:03:50 +01:00
|
|
|
|
}
|
2001-12-10 01:13:39 +01:00
|
|
|
|
if (!enemies) {
|
|
|
|
|
if (casualties) *casualties = 0;
|
2002-01-20 12:03:50 +01:00
|
|
|
|
return true; /* if no enemy found, no use doing standarad attack */
|
2001-12-10 01:13:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fi->catmsg == -1) {
|
|
|
|
|
int i, k=0;
|
|
|
|
|
for (i=0;i<=at->index;++i) {
|
2003-09-21 09:52:23 +02:00
|
|
|
|
struct weapon * wp = fi->person[i].melee;
|
2005-10-29 18:10:08 +02:00
|
|
|
|
if (wp!=NULL && wp->type == wtype) ++k;
|
2001-12-10 01:13:39 +01:00
|
|
|
|
}
|
|
|
|
|
sprintf(buf, "%d K<>mpfer aus %s benutz%s Flammenschwert%s:", k, unitname(fi->unit),
|
|
|
|
|
(k==1)?"t sein ":"en ihre",(k==1)?"":"er");
|
|
|
|
|
battlerecord(fi->side->battle, buf);
|
|
|
|
|
fi->catmsg = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
do {
|
2004-09-11 19:29:13 +02:00
|
|
|
|
dt = select_enemy(fi->side->battle, fi, minrow, maxrow, true);
|
2001-12-10 01:13:39 +01:00
|
|
|
|
assert(dt.fighter);
|
|
|
|
|
--force;
|
|
|
|
|
killed += terminate(dt, *at, AT_SPELL, damage, 1);
|
|
|
|
|
} while (force && killed < enemies);
|
|
|
|
|
if (casualties) *casualties = killed;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2002-04-23 21:00:23 +02:00
|
|
|
|
#define CATAPULT_ATTACKS 6
|
|
|
|
|
|
2001-12-10 01:13:39 +01:00
|
|
|
|
static boolean
|
2005-10-29 18:10:08 +02:00
|
|
|
|
attack_catapult(const troop * at, const struct weapon_type * wtype, int * casualties, int row)
|
2001-12-10 01:13:39 +01:00
|
|
|
|
{
|
|
|
|
|
fighter *af = at->fighter;
|
|
|
|
|
unit *au = af->unit;
|
|
|
|
|
battle * b = af->side->battle;
|
|
|
|
|
troop dt;
|
|
|
|
|
int d = 0, n;
|
|
|
|
|
int minrow, maxrow;
|
Zu Anfang des Kampfes wählt jeder Kämpfer aus seinem Arsenal zwei Waffen
aus: Seine beste Fernampfwaffe und seine beste Nahkampfwaffe.
Welches die beste Waffe ist, ist nicht immer einleuchtend, und an dieser
Stelle macht der Server eine Vereinfachung - er wählt die Waffe, bei der der
Angriffswert plus dem Verteidigungswert am größten ist.
** Wenn eine Einheit an der Reihe ist, wird geprüft:
1. Ist die Einheit ein Magier, so zaubert sie.
2. Ist die Einheit damit beschäftigt, eine Waffe nachzuladen, so tut sie das.
3. Steht die Einheit in einer der hinteren Reihen, attackiert sie, so
vorhanden, mit der Fernkampfwaffe.
4. Steht die Einheit in der vorderen Kampfreihe, so attackiert sie mit
derjenigen Waffe von beiden, in der ihr Talent am höchsten ist.
** Wird eine Einheit angegriffen, so gilt:
1. Handelt es sich um einen Angriff durch einen Nahkämpfer, so verteidigt
sie sich mit ihrer Nahkampfwaffe oder Waffenlosem Kampf.
2. Handelt es sich um eine Attacke durch einen Fernkämpfer, so verteidigt
sie sich mit dem halben Talent ihrer besten Waffe.
2002-10-04 23:25:16 +02:00
|
|
|
|
weapon * wp = af->person[at->index].missile;
|
2005-01-30 15:30:31 +01:00
|
|
|
|
static item_type * it_catapultammo = NULL;
|
|
|
|
|
if (it_catapultammo==NULL) {
|
|
|
|
|
it_catapultammo = it_find("catapultammo");
|
|
|
|
|
}
|
2002-04-23 21:00:23 +02:00
|
|
|
|
|
2002-01-20 12:03:50 +01:00
|
|
|
|
assert(row>=FIGHT_ROW);
|
2004-10-16 02:46:38 +02:00
|
|
|
|
if (row>BEHIND_ROW) {
|
|
|
|
|
/* probiere noch weitere attacken, kann nicht schiessen */
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2005-10-29 18:10:08 +02:00
|
|
|
|
assert(wp->type==wtype);
|
2002-04-23 21:00:23 +02:00
|
|
|
|
assert(af->person[at->index].reload==0);
|
|
|
|
|
|
2005-01-30 15:30:31 +01:00
|
|
|
|
if (it_catapultammo!=NULL) {
|
2005-10-30 16:42:15 +01:00
|
|
|
|
if (get_pooled(au, it_catapultammo->rtype, GET_SLACK|GET_RESERVE|GET_POOLED_SLACK) <= 0) {
|
2005-01-30 15:30:31 +01:00
|
|
|
|
/* No ammo. Use other weapon if available. */
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-12-10 01:13:39 +01:00
|
|
|
|
|
|
|
|
|
if (af->catmsg == -1) {
|
|
|
|
|
int i, k=0;
|
|
|
|
|
for (i=0;i<=at->index;++i) {
|
Zu Anfang des Kampfes wählt jeder Kämpfer aus seinem Arsenal zwei Waffen
aus: Seine beste Fernampfwaffe und seine beste Nahkampfwaffe.
Welches die beste Waffe ist, ist nicht immer einleuchtend, und an dieser
Stelle macht der Server eine Vereinfachung - er wählt die Waffe, bei der der
Angriffswert plus dem Verteidigungswert am größten ist.
** Wenn eine Einheit an der Reihe ist, wird geprüft:
1. Ist die Einheit ein Magier, so zaubert sie.
2. Ist die Einheit damit beschäftigt, eine Waffe nachzuladen, so tut sie das.
3. Steht die Einheit in einer der hinteren Reihen, attackiert sie, so
vorhanden, mit der Fernkampfwaffe.
4. Steht die Einheit in der vorderen Kampfreihe, so attackiert sie mit
derjenigen Waffe von beiden, in der ihr Talent am höchsten ist.
** Wird eine Einheit angegriffen, so gilt:
1. Handelt es sich um einen Angriff durch einen Nahkämpfer, so verteidigt
sie sich mit ihrer Nahkampfwaffe oder Waffenlosem Kampf.
2. Handelt es sich um eine Attacke durch einen Fernkämpfer, so verteidigt
sie sich mit dem halben Talent ihrer besten Waffe.
2002-10-04 23:25:16 +02:00
|
|
|
|
if (af->person[i].reload==0 && af->person[i].missile == wp) ++k;
|
2001-12-10 01:13:39 +01:00
|
|
|
|
}
|
|
|
|
|
sprintf(buf, "%d K<>mpfer aus %s feuer%s Katapult ab:", k, unitname(au), (k==1)?"t sein":"n ihr");
|
|
|
|
|
battlerecord(b, buf);
|
|
|
|
|
af->catmsg = 0;
|
|
|
|
|
}
|
|
|
|
|
minrow = FIGHT_ROW;
|
|
|
|
|
maxrow = FIGHT_ROW;
|
2002-04-23 21:00:23 +02:00
|
|
|
|
|
2004-09-11 19:29:13 +02:00
|
|
|
|
n = min(CATAPULT_ATTACKS, count_enemies(b, af->side, minrow, maxrow, true));
|
2002-04-23 21:00:23 +02:00
|
|
|
|
|
2005-01-30 15:30:31 +01:00
|
|
|
|
if (it_catapultammo!=NULL) {
|
2005-10-30 16:42:15 +01:00
|
|
|
|
use_pooled(au, it_catapultammo->rtype, GET_SLACK|GET_RESERVE|GET_POOLED_SLACK, 1);
|
2005-01-30 15:30:31 +01:00
|
|
|
|
}
|
2001-12-10 01:13:39 +01:00
|
|
|
|
|
|
|
|
|
while (--n >= 0) {
|
|
|
|
|
/* Select defender */
|
2004-09-11 19:29:13 +02:00
|
|
|
|
dt = select_enemy(b, af, minrow, maxrow, true);
|
2001-12-10 01:13:39 +01:00
|
|
|
|
if (!dt.fighter)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
/* If battle succeeds */
|
|
|
|
|
if (hits(*at, dt, wp)) {
|
|
|
|
|
d += terminate(dt, *at, AT_STANDARD, wp->type->damage[0], true);
|
|
|
|
|
#ifdef CATAPULT_STRUCTURAL_DAMAGE
|
|
|
|
|
if (dt.fighter->unit->building && rand()%100 < 5) {
|
|
|
|
|
damage_building(b, dt.fighter->unit->building, 1);
|
|
|
|
|
} else if (dt.fighter->unit->ship && rand()%100 < 5) {
|
|
|
|
|
dt.fighter->unit->ship->damage+=DAMAGE_SCALE;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (casualties) *casualties = d;
|
2002-01-20 12:03:50 +01:00
|
|
|
|
return false; /* keine weitren attacken */
|
2001-12-10 01:13:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
2001-01-25 10:37:55 +01:00
|
|
|
|
static void
|
|
|
|
|
init_oldweapons(void)
|
|
|
|
|
{
|
|
|
|
|
int w;
|
2006-02-11 17:11:16 +01:00
|
|
|
|
for (w=0;w!=WP_MAX && weapontable[w].item!=MAX_ITEMS;++w) {
|
2001-01-25 10:37:55 +01:00
|
|
|
|
const char * damage[2];
|
|
|
|
|
item_type * itype = olditemtype[weapontable[w].item];
|
|
|
|
|
int minskill = 1, wflags = WTF_NONE;
|
2005-07-31 21:22:14 +02:00
|
|
|
|
int m;
|
2001-01-25 10:37:55 +01:00
|
|
|
|
weapon_mod * modifiers = NULL;
|
2005-10-29 18:10:08 +02:00
|
|
|
|
boolean (*attack)(const troop *, const struct weapon_type *, int *, int) = NULL;
|
2001-01-25 10:37:55 +01:00
|
|
|
|
|
|
|
|
|
assert(itype!=NULL || !"item not initialized");
|
|
|
|
|
|
|
|
|
|
if (weapontable[w].rear) wflags |= WTF_MISSILE;
|
|
|
|
|
if (weapontable[w].is_magic) wflags |= WTF_MAGICAL;
|
|
|
|
|
if (weapontable[w].damage_type & CUT) wflags |= WTF_CUT;
|
|
|
|
|
if (weapontable[w].damage_type & PIERCE) wflags |= WTF_PIERCE;
|
|
|
|
|
if (weapontable[w].damage_type & BASH) wflags |= WTF_BLUNT;
|
2002-04-27 16:46:27 +02:00
|
|
|
|
if (weapontable[w].damage_type & ARMORPIERCING) wflags |= WTF_ARMORPIERCING;
|
2001-01-25 10:37:55 +01:00
|
|
|
|
|
|
|
|
|
damage[0] = weapontable[w].damfoot;
|
|
|
|
|
damage[1] = weapontable[w].damhorse;
|
|
|
|
|
|
|
|
|
|
oldweapontype[w] = new_weapontype(itype, wflags, weapontable[w].magres, damage, weapontable[w].attmod, weapontable[w].defmod, weapontable[w].reload.time, weapontable[w].skill, minskill);
|
|
|
|
|
oldweapontype[w]->modifiers = modifiers;
|
|
|
|
|
oldweapontype[w]->attack = attack;
|
2005-07-31 21:22:14 +02:00
|
|
|
|
|
|
|
|
|
#ifdef SCORE_MODULE
|
|
|
|
|
if (itype->construction->materials==NULL) {
|
|
|
|
|
itype->score = 6000;
|
|
|
|
|
} else for (m=0;itype->construction->materials[m].number;++m) {
|
2005-10-29 13:17:21 +02:00
|
|
|
|
const resource_type * rtype = itype->construction->materials[m].rtype;
|
2005-07-31 21:22:14 +02:00
|
|
|
|
int score = rtype->itype?rtype->itype->score:5;
|
|
|
|
|
itype->score = 2*itype->construction->materials[m].number * score;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
2001-01-25 10:37:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2005-10-29 18:28:10 +02:00
|
|
|
|
register_weapons(void)
|
|
|
|
|
{
|
2005-10-31 23:34:45 +01:00
|
|
|
|
register_function((pf_generic)attack_catapult, "attack_catapult");
|
|
|
|
|
register_function((pf_generic)attack_firesword, "attack_firesword");
|
2001-01-25 10:37:55 +01:00
|
|
|
|
}
|
2002-01-09 09:20:33 +01:00
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
init_weapons(void)
|
|
|
|
|
{
|
2005-10-31 23:34:45 +01:00
|
|
|
|
init_oldweapons();
|
2002-01-09 09:20:33 +01:00
|
|
|
|
}
|