shipspeed should be in ship.c, not in config.c

This commit is contained in:
Enno Rehling 2014-12-25 18:16:24 +01:00
parent 14bb27d89c
commit 4bb65873da
10 changed files with 277 additions and 271 deletions

View File

@ -54,6 +54,7 @@ attrib_type at_unitdissolve = {
void register_attributes(void)
{
at_deprecate("gm", a_readint);
at_register(&at_stealth);
at_register(&at_object);
at_register(&at_unitdissolve);
@ -61,7 +62,6 @@ void register_attributes(void)
at_register(&at_raceprefix);
at_register(&at_iceberg);
at_register(&at_key);
at_deprecate("gm", a_readint);
at_register(&at_follow);
at_register(&at_targetregion);
at_register(&at_orcification);
@ -69,6 +69,7 @@ void register_attributes(void)
at_register(&at_reduceproduction);
at_register(&at_otherfaction);
at_register(&at_racename);
at_register(&at_speedup);
at_register(&at_movement);
at_register(&at_moved);
}

View File

@ -20,6 +20,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/config.h>
#include "movement.h"
#include <kernel/save.h>
#include <util/attrib.h>
#include <storage.h>
@ -60,3 +61,20 @@ void set_movement(attrib ** alist, int type)
a = a_add(alist, a_new(&at_movement));
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
};

View File

@ -22,10 +22,11 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
extern "C" {
#endif
extern bool get_movement(struct attrib *const *alist, int type);
extern void set_movement(struct attrib **alist, int type);
bool get_movement(struct attrib *const *alist, int type);
void set_movement(struct attrib **alist, int type);
extern struct attrib_type at_movement;
extern struct attrib_type at_speedup;
#ifdef __cplusplus
}

View File

@ -29,7 +29,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/ship.h>
#include <kernel/unit.h>
#include <move.h>
#include <attributes/movement.h>
/* util includes */
#include <util/attrib.h>

View File

@ -26,10 +26,10 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "alliance.h"
#include "ally.h"
#include "alchemy.h"
#include "curse.h"
#include "connection.h"
#include "building.h"
#include "calendar.h"
#include "curse.h"
#include "direction.h"
#include "faction.h"
#include "group.h"
@ -442,79 +442,6 @@ int verbosity = 1;
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)
@ -1816,7 +1743,6 @@ static int read_ext(attrib * a, void *owner, struct storage *store)
void attrib_init(void)
{
/* Alle speicherbaren Attribute müssen hier registriert werden */
at_register(&at_speedup);
at_register(&at_shiptrail);
at_register(&at_familiar);
at_register(&at_familiarmage);

View File

@ -91,7 +91,6 @@ extern "C" {
#define want(option) (1<<option)
/* ------------------------------------------------------------- */
int shipspeed(const struct ship *sh, const struct unit *u);
#define i2b(i) ((bool)((i)?(true):(false)))

View File

@ -22,6 +22,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* kernel includes */
#include "build.h"
#include "curse.h"
#include "faction.h"
#include "unit.h"
#include "item.h"
#include "race.h"
@ -39,6 +41,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <quicklist.h>
#include <util/xml.h>
#include <attributes/movement.h>
#include <storage.h>
/* libc includes */
@ -254,6 +258,79 @@ const char *write_shipname(const ship * sh, char *ibuf, size_t size)
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)
{
typedef char name[OBJECTIDSIZE + 1];

View File

@ -124,6 +124,7 @@ extern "C" {
extern const char *ship_getname(const struct ship *self);
extern void ship_setname(struct ship *self, const char *name);
int shipspeed(const struct ship *sh, const struct unit *u);
#ifdef __cplusplus
}

View File

@ -170,22 +170,6 @@ attrib_type at_shiptrail = {
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 = {

View File

@ -31,7 +31,6 @@ extern "C" {
struct ship;
struct building_type;
extern struct attrib_type at_speedup;
extern struct attrib_type at_shiptrail;
/* die Zahlen sind genau äquivalent zu den race Flags */