forked from github/server
shipspeed should be in ship.c, not in config.c
This commit is contained in:
parent
14bb27d89c
commit
4bb65873da
|
@ -54,6 +54,7 @@ attrib_type at_unitdissolve = {
|
||||||
|
|
||||||
void register_attributes(void)
|
void register_attributes(void)
|
||||||
{
|
{
|
||||||
|
at_deprecate("gm", a_readint);
|
||||||
at_register(&at_stealth);
|
at_register(&at_stealth);
|
||||||
at_register(&at_object);
|
at_register(&at_object);
|
||||||
at_register(&at_unitdissolve);
|
at_register(&at_unitdissolve);
|
||||||
|
@ -61,7 +62,6 @@ void register_attributes(void)
|
||||||
at_register(&at_raceprefix);
|
at_register(&at_raceprefix);
|
||||||
at_register(&at_iceberg);
|
at_register(&at_iceberg);
|
||||||
at_register(&at_key);
|
at_register(&at_key);
|
||||||
at_deprecate("gm", a_readint);
|
|
||||||
at_register(&at_follow);
|
at_register(&at_follow);
|
||||||
at_register(&at_targetregion);
|
at_register(&at_targetregion);
|
||||||
at_register(&at_orcification);
|
at_register(&at_orcification);
|
||||||
|
@ -69,6 +69,7 @@ void register_attributes(void)
|
||||||
at_register(&at_reduceproduction);
|
at_register(&at_reduceproduction);
|
||||||
at_register(&at_otherfaction);
|
at_register(&at_otherfaction);
|
||||||
at_register(&at_racename);
|
at_register(&at_racename);
|
||||||
|
at_register(&at_speedup);
|
||||||
at_register(&at_movement);
|
at_register(&at_movement);
|
||||||
at_register(&at_moved);
|
at_register(&at_moved);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <kernel/config.h>
|
#include <kernel/config.h>
|
||||||
#include "movement.h"
|
#include "movement.h"
|
||||||
|
|
||||||
|
#include <kernel/save.h>
|
||||||
#include <util/attrib.h>
|
#include <util/attrib.h>
|
||||||
|
|
||||||
#include <storage.h>
|
#include <storage.h>
|
||||||
|
@ -60,3 +61,20 @@ void set_movement(attrib ** alist, int type)
|
||||||
a = a_add(alist, a_new(&at_movement));
|
a = a_add(alist, a_new(&at_movement));
|
||||||
a->data.i |= type;
|
a->data.i |= type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int age_speedup(attrib * a)
|
||||||
|
{
|
||||||
|
if (a->data.sa[0] > 0) {
|
||||||
|
a->data.sa[0] = a->data.sa[0] - a->data.sa[1];
|
||||||
|
}
|
||||||
|
return (a->data.sa[0] > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
attrib_type at_speedup = {
|
||||||
|
"speedup",
|
||||||
|
NULL, NULL,
|
||||||
|
age_speedup,
|
||||||
|
a_writeint,
|
||||||
|
a_readint
|
||||||
|
};
|
||||||
|
|
||||||
|
|
|
@ -22,10 +22,11 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern bool get_movement(struct attrib *const *alist, int type);
|
bool get_movement(struct attrib *const *alist, int type);
|
||||||
extern void set_movement(struct attrib **alist, int type);
|
void set_movement(struct attrib **alist, int type);
|
||||||
|
|
||||||
extern struct attrib_type at_movement;
|
extern struct attrib_type at_movement;
|
||||||
|
extern struct attrib_type at_speedup;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <kernel/ship.h>
|
#include <kernel/ship.h>
|
||||||
#include <kernel/unit.h>
|
#include <kernel/unit.h>
|
||||||
|
|
||||||
#include <move.h>
|
#include <attributes/movement.h>
|
||||||
|
|
||||||
/* util includes */
|
/* util includes */
|
||||||
#include <util/attrib.h>
|
#include <util/attrib.h>
|
||||||
|
|
|
@ -26,10 +26,10 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include "alliance.h"
|
#include "alliance.h"
|
||||||
#include "ally.h"
|
#include "ally.h"
|
||||||
#include "alchemy.h"
|
#include "alchemy.h"
|
||||||
|
#include "curse.h"
|
||||||
#include "connection.h"
|
#include "connection.h"
|
||||||
#include "building.h"
|
#include "building.h"
|
||||||
#include "calendar.h"
|
#include "calendar.h"
|
||||||
#include "curse.h"
|
|
||||||
#include "direction.h"
|
#include "direction.h"
|
||||||
#include "faction.h"
|
#include "faction.h"
|
||||||
#include "group.h"
|
#include "group.h"
|
||||||
|
@ -442,79 +442,6 @@ int verbosity = 1;
|
||||||
|
|
||||||
FILE *debug;
|
FILE *debug;
|
||||||
|
|
||||||
static int ShipSpeedBonus(const unit * u)
|
|
||||||
{
|
|
||||||
static int level = -1;
|
|
||||||
if (level == -1) {
|
|
||||||
level =
|
|
||||||
get_param_int(global.parameters, "movement.shipspeed.skillbonus", 0);
|
|
||||||
}
|
|
||||||
if (level > 0) {
|
|
||||||
ship *sh = u->ship;
|
|
||||||
int skl = effskill(u, SK_SAILING);
|
|
||||||
int minsk = (sh->type->cptskill + 1) / 2;
|
|
||||||
return (skl - minsk) / level;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int shipspeed(const ship * sh, const unit * u)
|
|
||||||
{
|
|
||||||
double k = sh->type->range;
|
|
||||||
static const curse_type *stormwind_ct, *nodrift_ct;
|
|
||||||
static bool init;
|
|
||||||
attrib *a;
|
|
||||||
curse *c;
|
|
||||||
|
|
||||||
if (!init) {
|
|
||||||
init = true;
|
|
||||||
stormwind_ct = ct_find("stormwind");
|
|
||||||
nodrift_ct = ct_find("nodrift");
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(u->ship == sh);
|
|
||||||
assert(sh->type->construction->improvement == NULL); /* sonst ist construction::size nicht ship_type::maxsize */
|
|
||||||
if (sh->size != sh->type->construction->maxsize)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (curse_active(get_curse(sh->attribs, stormwind_ct)))
|
|
||||||
k *= 2;
|
|
||||||
if (curse_active(get_curse(sh->attribs, nodrift_ct)))
|
|
||||||
k += 1;
|
|
||||||
|
|
||||||
if (u->faction->race == u_race(u)) {
|
|
||||||
/* race bonus for this faction? */
|
|
||||||
if (fval(u_race(u), RCF_SHIPSPEED)) {
|
|
||||||
k += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
k += ShipSpeedBonus(u);
|
|
||||||
|
|
||||||
a = a_find(sh->attribs, &at_speedup);
|
|
||||||
while (a != NULL && a->type == &at_speedup) {
|
|
||||||
k += a->data.sa[0];
|
|
||||||
a = a->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
c = get_curse(sh->attribs, ct_find("shipspeedup"));
|
|
||||||
while (c) {
|
|
||||||
k += curse_geteffect(c);
|
|
||||||
c = c->nexthash;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef SHIPSPEED
|
|
||||||
k *= SHIPSPEED;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (sh->damage)
|
|
||||||
k =
|
|
||||||
(k * (sh->size * DAMAGE_SCALE - sh->damage) + sh->size * DAMAGE_SCALE -
|
|
||||||
1) / (sh->size * DAMAGE_SCALE);
|
|
||||||
|
|
||||||
return (int)k;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------- */
|
/* ----------------------------------------------------------------------- */
|
||||||
|
|
||||||
void verify_data(void)
|
void verify_data(void)
|
||||||
|
@ -1816,7 +1743,6 @@ static int read_ext(attrib * a, void *owner, struct storage *store)
|
||||||
void attrib_init(void)
|
void attrib_init(void)
|
||||||
{
|
{
|
||||||
/* Alle speicherbaren Attribute müssen hier registriert werden */
|
/* Alle speicherbaren Attribute müssen hier registriert werden */
|
||||||
at_register(&at_speedup);
|
|
||||||
at_register(&at_shiptrail);
|
at_register(&at_shiptrail);
|
||||||
at_register(&at_familiar);
|
at_register(&at_familiar);
|
||||||
at_register(&at_familiarmage);
|
at_register(&at_familiarmage);
|
||||||
|
|
|
@ -91,7 +91,6 @@ extern "C" {
|
||||||
|
|
||||||
#define want(option) (1<<option)
|
#define want(option) (1<<option)
|
||||||
/* ------------------------------------------------------------- */
|
/* ------------------------------------------------------------- */
|
||||||
int shipspeed(const struct ship *sh, const struct unit *u);
|
|
||||||
|
|
||||||
#define i2b(i) ((bool)((i)?(true):(false)))
|
#define i2b(i) ((bool)((i)?(true):(false)))
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||||
Katja Zedel <katze@felidae.kn-bremen.de
|
Katja Zedel <katze@felidae.kn-bremen.de
|
||||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||||
|
|
||||||
Permission to use, copy, modify, and/or distribute this software for any
|
Permission to use, copy, modify, and/or distribute this software for any
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
purpose with or without fee is hereby granted, provided that the above
|
||||||
|
@ -22,6 +22,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
/* kernel includes */
|
/* kernel includes */
|
||||||
#include "build.h"
|
#include "build.h"
|
||||||
|
#include "curse.h"
|
||||||
|
#include "faction.h"
|
||||||
#include "unit.h"
|
#include "unit.h"
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include "race.h"
|
#include "race.h"
|
||||||
|
@ -39,6 +41,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <quicklist.h>
|
#include <quicklist.h>
|
||||||
#include <util/xml.h>
|
#include <util/xml.h>
|
||||||
|
|
||||||
|
#include <attributes/movement.h>
|
||||||
|
|
||||||
#include <storage.h>
|
#include <storage.h>
|
||||||
|
|
||||||
/* libc includes */
|
/* libc includes */
|
||||||
|
@ -53,48 +57,48 @@ static local_names *snames;
|
||||||
|
|
||||||
const ship_type *findshiptype(const char *name, const struct locale *lang)
|
const ship_type *findshiptype(const char *name, const struct locale *lang)
|
||||||
{
|
{
|
||||||
local_names *sn = snames;
|
local_names *sn = snames;
|
||||||
variant var;
|
variant var;
|
||||||
|
|
||||||
while (sn) {
|
while (sn) {
|
||||||
if (sn->lang == lang)
|
if (sn->lang == lang)
|
||||||
break;
|
break;
|
||||||
sn = sn->next;
|
sn = sn->next;
|
||||||
}
|
|
||||||
if (!sn) {
|
|
||||||
quicklist *ql;
|
|
||||||
int qi;
|
|
||||||
|
|
||||||
sn = (local_names *) calloc(sizeof(local_names), 1);
|
|
||||||
sn->next = snames;
|
|
||||||
sn->lang = lang;
|
|
||||||
|
|
||||||
for (qi = 0, ql = shiptypes; ql; ql_advance(&ql, &qi, 1)) {
|
|
||||||
ship_type *stype = (ship_type *) ql_get(ql, qi);
|
|
||||||
variant var2;
|
|
||||||
const char *n = locale_string(lang, stype->_name);
|
|
||||||
var2.v = (void *)stype;
|
|
||||||
addtoken(&sn->names, n, var2);
|
|
||||||
}
|
}
|
||||||
snames = sn;
|
if (!sn) {
|
||||||
}
|
quicklist *ql;
|
||||||
if (findtoken(sn->names, name, &var) == E_TOK_NOMATCH)
|
int qi;
|
||||||
return NULL;
|
|
||||||
return (const ship_type *)var.v;
|
sn = (local_names *)calloc(sizeof(local_names), 1);
|
||||||
|
sn->next = snames;
|
||||||
|
sn->lang = lang;
|
||||||
|
|
||||||
|
for (qi = 0, ql = shiptypes; ql; ql_advance(&ql, &qi, 1)) {
|
||||||
|
ship_type *stype = (ship_type *)ql_get(ql, qi);
|
||||||
|
variant var2;
|
||||||
|
const char *n = locale_string(lang, stype->_name);
|
||||||
|
var2.v = (void *)stype;
|
||||||
|
addtoken(&sn->names, n, var2);
|
||||||
|
}
|
||||||
|
snames = sn;
|
||||||
|
}
|
||||||
|
if (findtoken(sn->names, name, &var) == E_TOK_NOMATCH)
|
||||||
|
return NULL;
|
||||||
|
return (const ship_type *)var.v;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ship_type *st_find_i(const char *name)
|
static ship_type *st_find_i(const char *name)
|
||||||
{
|
{
|
||||||
quicklist *ql;
|
quicklist *ql;
|
||||||
int qi;
|
int qi;
|
||||||
|
|
||||||
for (qi = 0, ql = shiptypes; ql; ql_advance(&ql, &qi, 1)) {
|
for (qi = 0, ql = shiptypes; ql; ql_advance(&ql, &qi, 1)) {
|
||||||
ship_type *stype = (ship_type *) ql_get(ql, qi);
|
ship_type *stype = (ship_type *)ql_get(ql, qi);
|
||||||
if (strcmp(stype->_name, name) == 0) {
|
if (strcmp(stype->_name, name) == 0) {
|
||||||
return stype;
|
return stype;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
return NULL;
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const ship_type *st_find(const char *name) {
|
const ship_type *st_find(const char *name) {
|
||||||
|
@ -115,60 +119,60 @@ ship_type *st_get_or_create(const char * name) {
|
||||||
ship *shiphash[MAXSHIPHASH];
|
ship *shiphash[MAXSHIPHASH];
|
||||||
void shash(ship * s)
|
void shash(ship * s)
|
||||||
{
|
{
|
||||||
ship *old = shiphash[s->no % MAXSHIPHASH];
|
ship *old = shiphash[s->no % MAXSHIPHASH];
|
||||||
|
|
||||||
shiphash[s->no % MAXSHIPHASH] = s;
|
shiphash[s->no % MAXSHIPHASH] = s;
|
||||||
s->nexthash = old;
|
s->nexthash = old;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sunhash(ship * s)
|
void sunhash(ship * s)
|
||||||
{
|
{
|
||||||
ship **show;
|
ship **show;
|
||||||
|
|
||||||
for (show = &shiphash[s->no % MAXSHIPHASH]; *show; show = &(*show)->nexthash) {
|
for (show = &shiphash[s->no % MAXSHIPHASH]; *show; show = &(*show)->nexthash) {
|
||||||
if ((*show)->no == s->no)
|
if ((*show)->no == s->no)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (*show) {
|
if (*show) {
|
||||||
assert(*show == s);
|
assert(*show == s);
|
||||||
*show = (*show)->nexthash;
|
*show = (*show)->nexthash;
|
||||||
s->nexthash = 0;
|
s->nexthash = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static ship *sfindhash(int i)
|
static ship *sfindhash(int i)
|
||||||
{
|
{
|
||||||
ship *old;
|
ship *old;
|
||||||
|
|
||||||
for (old = shiphash[i % MAXSHIPHASH]; old; old = old->nexthash)
|
for (old = shiphash[i % MAXSHIPHASH]; old; old = old->nexthash)
|
||||||
if (old->no == i)
|
if (old->no == i)
|
||||||
return old;
|
return old;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ship *findship(int i)
|
struct ship *findship(int i)
|
||||||
{
|
{
|
||||||
return sfindhash(i);
|
return sfindhash(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ship *findshipr(const region * r, int n)
|
struct ship *findshipr(const region * r, int n)
|
||||||
{
|
{
|
||||||
ship *sh;
|
ship *sh;
|
||||||
|
|
||||||
for (sh = r->ships; sh; sh = sh->next) {
|
for (sh = r->ships; sh; sh = sh->next) {
|
||||||
if (sh->no == n) {
|
if (sh->no == n) {
|
||||||
assert(sh->region == r);
|
assert(sh->region == r);
|
||||||
return sh;
|
return sh;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
return 0;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void damage_ship(ship * sh, double percent)
|
void damage_ship(ship * sh, double percent)
|
||||||
{
|
{
|
||||||
double damage =
|
double damage =
|
||||||
DAMAGE_SCALE * sh->type->damage * percent * sh->size + sh->damage;
|
DAMAGE_SCALE * sh->type->damage * percent * sh->size + sh->damage;
|
||||||
sh->damage = (int)damage;
|
sh->damage = (int)damage;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Alte Schiffstypen: */
|
/* Alte Schiffstypen: */
|
||||||
|
@ -176,62 +180,62 @@ static ship *deleted_ships;
|
||||||
|
|
||||||
ship *new_ship(const ship_type * stype, region * r, const struct locale *lang)
|
ship *new_ship(const ship_type * stype, region * r, const struct locale *lang)
|
||||||
{
|
{
|
||||||
static char buffer[32];
|
static char buffer[32];
|
||||||
ship *sh = (ship *) calloc(1, sizeof(ship));
|
ship *sh = (ship *)calloc(1, sizeof(ship));
|
||||||
const char *sname = 0;
|
const char *sname = 0;
|
||||||
|
|
||||||
assert(stype);
|
assert(stype);
|
||||||
sh->no = newcontainerid();
|
sh->no = newcontainerid();
|
||||||
sh->coast = NODIRECTION;
|
sh->coast = NODIRECTION;
|
||||||
sh->type = stype;
|
sh->type = stype;
|
||||||
sh->region = r;
|
sh->region = r;
|
||||||
|
|
||||||
sname = LOC(lang, stype->_name);
|
sname = LOC(lang, stype->_name);
|
||||||
if (!sname) {
|
|
||||||
sname = LOC(lang, parameters[P_SHIP]);
|
|
||||||
if (!sname) {
|
if (!sname) {
|
||||||
sname = parameters[P_SHIP];
|
sname = LOC(lang, parameters[P_SHIP]);
|
||||||
|
if (!sname) {
|
||||||
|
sname = parameters[P_SHIP];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
assert(sname);
|
||||||
assert(sname);
|
slprintf(buffer, sizeof(buffer), "%s %s", sname, shipid(sh));
|
||||||
slprintf(buffer, sizeof(buffer), "%s %s", sname, shipid(sh));
|
sh->name = _strdup(buffer);
|
||||||
sh->name = _strdup(buffer);
|
shash(sh);
|
||||||
shash(sh);
|
if (r) {
|
||||||
if (r) {
|
addlist(&r->ships, sh);
|
||||||
addlist(&r->ships, sh);
|
}
|
||||||
}
|
return sh;
|
||||||
return sh;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void remove_ship(ship ** slist, ship * sh)
|
void remove_ship(ship ** slist, ship * sh)
|
||||||
{
|
{
|
||||||
region *r = sh->region;
|
region *r = sh->region;
|
||||||
unit *u = r->units;
|
unit *u = r->units;
|
||||||
|
|
||||||
handle_event(sh->attribs, "destroy", sh);
|
handle_event(sh->attribs, "destroy", sh);
|
||||||
while (u) {
|
while (u) {
|
||||||
if (u->ship == sh) {
|
if (u->ship == sh) {
|
||||||
leave_ship(u);
|
leave_ship(u);
|
||||||
|
}
|
||||||
|
u = u->next;
|
||||||
}
|
}
|
||||||
u = u->next;
|
sunhash(sh);
|
||||||
}
|
while (*slist && *slist != sh)
|
||||||
sunhash(sh);
|
slist = &(*slist)->next;
|
||||||
while (*slist && *slist != sh)
|
assert(*slist);
|
||||||
slist = &(*slist)->next;
|
*slist = sh->next;
|
||||||
assert(*slist);
|
sh->next = deleted_ships;
|
||||||
*slist = sh->next;
|
deleted_ships = sh;
|
||||||
sh->next = deleted_ships;
|
sh->region = NULL;
|
||||||
deleted_ships = sh;
|
|
||||||
sh->region = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void free_ship(ship * s)
|
void free_ship(ship * s)
|
||||||
{
|
{
|
||||||
while (s->attribs)
|
while (s->attribs)
|
||||||
a_remove(&s->attribs, s->attribs);
|
a_remove(&s->attribs, s->attribs);
|
||||||
free(s->name);
|
free(s->name);
|
||||||
free(s->display);
|
free(s->display);
|
||||||
free(s);
|
free(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void free_shiptypes(void) {
|
void free_shiptypes(void) {
|
||||||
|
@ -242,121 +246,194 @@ void free_shiptypes(void) {
|
||||||
|
|
||||||
void free_ships(void)
|
void free_ships(void)
|
||||||
{
|
{
|
||||||
while (deleted_ships) {
|
while (deleted_ships) {
|
||||||
ship *s = deleted_ships;
|
ship *s = deleted_ships;
|
||||||
deleted_ships = s->next;
|
deleted_ships = s->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *write_shipname(const ship * sh, char *ibuf, size_t size)
|
const char *write_shipname(const ship * sh, char *ibuf, size_t size)
|
||||||
{
|
{
|
||||||
slprintf(ibuf, size, "%s (%s)", sh->name, itoa36(sh->no));
|
slprintf(ibuf, size, "%s (%s)", sh->name, itoa36(sh->no));
|
||||||
return ibuf;
|
return ibuf;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int ShipSpeedBonus(const unit * u)
|
||||||
|
{
|
||||||
|
static int level = -1;
|
||||||
|
if (level == -1) {
|
||||||
|
level =
|
||||||
|
get_param_int(global.parameters, "movement.shipspeed.skillbonus", 0);
|
||||||
|
}
|
||||||
|
if (level > 0) {
|
||||||
|
ship *sh = u->ship;
|
||||||
|
int skl = effskill(u, SK_SAILING);
|
||||||
|
int minsk = (sh->type->cptskill + 1) / 2;
|
||||||
|
return (skl - minsk) / level;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int shipspeed(const ship * sh, const unit * u)
|
||||||
|
{
|
||||||
|
double k = sh->type->range;
|
||||||
|
static const struct curse_type *stormwind_ct, *nodrift_ct;
|
||||||
|
static bool init;
|
||||||
|
attrib *a;
|
||||||
|
struct curse *c;
|
||||||
|
|
||||||
|
if (!init) {
|
||||||
|
init = true;
|
||||||
|
stormwind_ct = ct_find("stormwind");
|
||||||
|
nodrift_ct = ct_find("nodrift");
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(u->ship == sh);
|
||||||
|
assert(sh->type->construction->improvement == NULL); /* sonst ist construction::size nicht ship_type::maxsize */
|
||||||
|
if (sh->size != sh->type->construction->maxsize)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (curse_active(get_curse(sh->attribs, stormwind_ct)))
|
||||||
|
k *= 2;
|
||||||
|
if (curse_active(get_curse(sh->attribs, nodrift_ct)))
|
||||||
|
k += 1;
|
||||||
|
|
||||||
|
if (u->faction->race == u_race(u)) {
|
||||||
|
/* race bonus for this faction? */
|
||||||
|
if (fval(u_race(u), RCF_SHIPSPEED)) {
|
||||||
|
k += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
k += ShipSpeedBonus(u);
|
||||||
|
|
||||||
|
a = a_find(sh->attribs, &at_speedup);
|
||||||
|
while (a != NULL && a->type == &at_speedup) {
|
||||||
|
k += a->data.sa[0];
|
||||||
|
a = a->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
c = get_curse(sh->attribs, ct_find("shipspeedup"));
|
||||||
|
while (c) {
|
||||||
|
k += curse_geteffect(c);
|
||||||
|
c = c->nexthash;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef SHIPSPEED
|
||||||
|
k *= SHIPSPEED;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (sh->damage)
|
||||||
|
k =
|
||||||
|
(k * (sh->size * DAMAGE_SCALE - sh->damage) + sh->size * DAMAGE_SCALE -
|
||||||
|
1) / (sh->size * DAMAGE_SCALE);
|
||||||
|
|
||||||
|
return (int)k;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *shipname(const ship * sh)
|
const char *shipname(const ship * sh)
|
||||||
{
|
{
|
||||||
typedef char name[OBJECTIDSIZE + 1];
|
typedef char name[OBJECTIDSIZE + 1];
|
||||||
static name idbuf[8];
|
static name idbuf[8];
|
||||||
static int nextbuf = 0;
|
static int nextbuf = 0;
|
||||||
char *ibuf = idbuf[(++nextbuf) % 8];
|
char *ibuf = idbuf[(++nextbuf) % 8];
|
||||||
return write_shipname(sh, ibuf, sizeof(name));
|
return write_shipname(sh, ibuf, sizeof(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
int shipcapacity(const ship * sh)
|
int shipcapacity(const ship * sh)
|
||||||
{
|
{
|
||||||
int i = sh->type->cargo;
|
int i = sh->type->cargo;
|
||||||
|
|
||||||
/* sonst ist construction:: size nicht ship_type::maxsize */
|
/* sonst ist construction:: size nicht ship_type::maxsize */
|
||||||
assert(!sh->type->construction
|
assert(!sh->type->construction
|
||||||
|| sh->type->construction->improvement == NULL);
|
|| sh->type->construction->improvement == NULL);
|
||||||
|
|
||||||
if (sh->type->construction && sh->size != sh->type->construction->maxsize)
|
if (sh->type->construction && sh->size != sh->type->construction->maxsize)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (sh->damage) {
|
if (sh->damage) {
|
||||||
i = (int)ceil(i * (1.0 - sh->damage / sh->size / (double)DAMAGE_SCALE));
|
i = (int)ceil(i * (1.0 - sh->damage / sh->size / (double)DAMAGE_SCALE));
|
||||||
}
|
}
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
void getshipweight(const ship * sh, int *sweight, int *scabins)
|
void getshipweight(const ship * sh, int *sweight, int *scabins)
|
||||||
{
|
{
|
||||||
unit *u;
|
unit *u;
|
||||||
|
|
||||||
*sweight = 0;
|
*sweight = 0;
|
||||||
*scabins = 0;
|
*scabins = 0;
|
||||||
|
|
||||||
for (u = sh->region->units; u; u = u->next) {
|
for (u = sh->region->units; u; u = u->next) {
|
||||||
if (u->ship == sh) {
|
if (u->ship == sh) {
|
||||||
*sweight += weight(u);
|
*sweight += weight(u);
|
||||||
if (sh->type->cabins) {
|
if (sh->type->cabins) {
|
||||||
int pweight = u->number * u_race(u)->weight;
|
int pweight = u->number * u_race(u)->weight;
|
||||||
/* weight goes into number of cabins, not cargo */
|
/* weight goes into number of cabins, not cargo */
|
||||||
*scabins += pweight;
|
*scabins += pweight;
|
||||||
*sweight -= pweight;
|
*sweight -= pweight;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ship_set_owner(unit * u) {
|
void ship_set_owner(unit * u) {
|
||||||
assert(u && u->ship);
|
assert(u && u->ship);
|
||||||
u->ship->_owner = u;
|
u->ship->_owner = u;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unit * ship_owner_ex(const ship * sh, const struct faction * last_owner)
|
static unit * ship_owner_ex(const ship * sh, const struct faction * last_owner)
|
||||||
{
|
{
|
||||||
unit *u, *heir = 0;
|
unit *u, *heir = 0;
|
||||||
|
|
||||||
/* Eigentümer tot oder kein Eigentümer vorhanden. Erste lebende Einheit
|
/* Eigentümer tot oder kein Eigentümer vorhanden. Erste lebende Einheit
|
||||||
* nehmen. */
|
* nehmen. */
|
||||||
for (u = sh->region->units; u; u = u->next) {
|
for (u = sh->region->units; u; u = u->next) {
|
||||||
if (u->ship == sh) {
|
if (u->ship == sh) {
|
||||||
if (u->number > 0) {
|
if (u->number > 0) {
|
||||||
if (heir && last_owner && heir->faction!=last_owner && u->faction==last_owner) {
|
if (heir && last_owner && heir->faction != last_owner && u->faction == last_owner) {
|
||||||
heir = u;
|
heir = u;
|
||||||
break; /* we found someone from the same faction who is not dead. let's take this guy */
|
break; /* we found someone from the same faction who is not dead. let's take this guy */
|
||||||
|
}
|
||||||
|
else if (!heir) {
|
||||||
|
heir = u; /* you'll do in an emergency */
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (!heir) {
|
|
||||||
heir = u; /* you'll do in an emergency */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
return heir;
|
||||||
return heir;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ship_update_owner(ship * sh) {
|
void ship_update_owner(ship * sh) {
|
||||||
unit * owner = sh->_owner;
|
unit * owner = sh->_owner;
|
||||||
sh->_owner = ship_owner_ex(sh, owner?owner->faction:0);
|
sh->_owner = ship_owner_ex(sh, owner ? owner->faction : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
unit *ship_owner(const ship * sh)
|
unit *ship_owner(const ship * sh)
|
||||||
{
|
{
|
||||||
unit *owner = sh->_owner;
|
unit *owner = sh->_owner;
|
||||||
if (!owner || (owner->ship!=sh || owner->number<=0)) {
|
if (!owner || (owner->ship != sh || owner->number <= 0)) {
|
||||||
unit * heir = ship_owner_ex(sh, owner?owner->faction:0);
|
unit * heir = ship_owner_ex(sh, owner ? owner->faction : 0);
|
||||||
return (heir && heir->number>0) ? heir : 0;
|
return (heir && heir->number > 0) ? heir : 0;
|
||||||
}
|
}
|
||||||
return owner;
|
return owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
void write_ship_reference(const struct ship *sh, struct storage *store)
|
void write_ship_reference(const struct ship *sh, struct storage *store)
|
||||||
{
|
{
|
||||||
WRITE_INT(store, (sh && sh->region) ? sh->no : 0);
|
WRITE_INT(store, (sh && sh->region) ? sh->no : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ship_setname(ship * self, const char *name)
|
void ship_setname(ship * self, const char *name)
|
||||||
{
|
{
|
||||||
free(self->name);
|
free(self->name);
|
||||||
if (name)
|
if (name)
|
||||||
self->name = _strdup(name);
|
self->name = _strdup(name);
|
||||||
else
|
else
|
||||||
self->name = NULL;
|
self->name = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *ship_getname(const ship * self)
|
const char *ship_getname(const ship * self)
|
||||||
{
|
{
|
||||||
return self->name;
|
return self->name;
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,6 +124,7 @@ extern "C" {
|
||||||
|
|
||||||
extern const char *ship_getname(const struct ship *self);
|
extern const char *ship_getname(const struct ship *self);
|
||||||
extern void ship_setname(struct ship *self, const char *name);
|
extern void ship_setname(struct ship *self, const char *name);
|
||||||
|
int shipspeed(const struct ship *sh, const struct unit *u);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
16
src/move.c
16
src/move.c
|
@ -170,22 +170,6 @@ attrib_type at_shiptrail = {
|
||||||
shiptrail_read
|
shiptrail_read
|
||||||
};
|
};
|
||||||
|
|
||||||
static int age_speedup(attrib * a)
|
|
||||||
{
|
|
||||||
if (a->data.sa[0] > 0) {
|
|
||||||
a->data.sa[0] = a->data.sa[0] - a->data.sa[1];
|
|
||||||
}
|
|
||||||
return (a->data.sa[0] > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE;
|
|
||||||
}
|
|
||||||
|
|
||||||
attrib_type at_speedup = {
|
|
||||||
"speedup",
|
|
||||||
NULL, NULL,
|
|
||||||
age_speedup,
|
|
||||||
a_writeint,
|
|
||||||
a_readint
|
|
||||||
};
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------- */
|
/* ------------------------------------------------------------- */
|
||||||
|
|
||||||
static attrib_type at_driveweight = {
|
static attrib_type at_driveweight = {
|
||||||
|
|
|
@ -31,7 +31,6 @@ extern "C" {
|
||||||
struct ship;
|
struct ship;
|
||||||
struct building_type;
|
struct building_type;
|
||||||
|
|
||||||
extern struct attrib_type at_speedup;
|
|
||||||
extern struct attrib_type at_shiptrail;
|
extern struct attrib_type at_shiptrail;
|
||||||
|
|
||||||
/* die Zahlen sind genau äquivalent zu den race Flags */
|
/* die Zahlen sind genau äquivalent zu den race Flags */
|
||||||
|
|
Loading…
Reference in New Issue