Bugfix leave_trail. Aufsplitten von move_ship

- Änderung von get_param (liefert NULL für undeklarierte params) in Vorbereitung auf "mehr config, weniger define"

Diverse indenting-anpassungen (space statt tabs)
This commit is contained in:
Enno Rehling 2004-04-10 10:43:46 +00:00
parent 77a00514ae
commit e319698a43
9 changed files with 423 additions and 398 deletions

View File

@ -112,7 +112,8 @@ static int
giverestriction(void) {
static int value = -1;
if (value<0) {
value = atoi(get_param(global.parameters, "GiveRestriction"));
const char * str = get_param(global.parameters, "GiveRestriction");
value = str?atoi(str):0;
}
return value;
}
@ -2994,9 +2995,14 @@ entertain(region * r, unit * u)
request *o;
static int entertainbase = 0;
static int entertainperlevel = 0;
if (!entertainbase) entertainbase = atoi(get_param(global.parameters, "entertain.base"));
if (!entertainperlevel) entertainperlevel = atoi(get_param(global.parameters, "entertain.perlevel"));
if (!entertainbase) {
const char * str = get_param(global.parameters, "entertain.base");
entertainbase = str?atoi(str):0;
}
if (!entertainperlevel) {
const char * str = get_param(global.parameters, "entertain.perlevel");
entertainperlevel = str?atoi(str):0;
}
if (fval(u, UFL_WERE)) {
cmistake(u, findorder(u, u->thisorder), 58, MSG_INCOME);
return;

View File

@ -108,7 +108,8 @@ static int
RemoveNMRNewbie(void) {
static int value = -1;
if (value<0) {
value = atoi(get_param(global.parameters, "nmr.removenewbie"));
const char * str = get_param(global.parameters, "nmr.removenewbie");
value = str?atoi(str):0;
}
return value;
}

View File

@ -84,8 +84,7 @@ spy(region * r, unit * u)
if (chance(spychance)) {
spy_message(spy, u, target);
} else {
add_message(&u->faction->msgs, new_message(u->faction,
"spyfail%u:spy%u:target", u, target));
ADDMSG(&u->faction->msgs, msg_message("spyfail", "spy target", u, target));
}
/* der Spion kann identifiziert werden, wenn das Opfer bessere

View File

@ -111,7 +111,8 @@ static int
MaxAge(void) {
static int value = -1;
if (value<0) {
value = atoi(get_param(global.parameters, "MaxAge"));
const char * str = get_param(global.parameters, "MaxAge");
value = str?atoi(str):0;
}
return value;
}
@ -120,7 +121,8 @@ int
LongHunger(void) {
static int value = -1;
if (value<0) {
value = atoi(get_param(global.parameters, "hunger.long"));
const char * str = get_param(global.parameters, "hunger.long");
value = str?atoi(str):0;
}
return value;
}
@ -130,7 +132,8 @@ SkillCap(skill_t sk) {
static int value = -1;
if (sk==SK_MAGIC) return 0; /* no caps on magic */
if (value<0) {
value = atoi(get_param(global.parameters, "skill.maxlevel"));
const char * str = get_param(global.parameters, "skill.maxlevel");
value = str?atoi(str):0;
}
return value;
}
@ -139,7 +142,8 @@ boolean
TradeDisabled(void) {
static int value = -1;
if (value<0) {
value = (boolean)atoi(get_param(global.parameters, "trade.disabled"));
const char * str = get_param(global.parameters, "trade.disabled");
value = str?atoi(str):0;
}
return value;
}
@ -148,7 +152,8 @@ int
NMRTimeout(void) {
static int value = -1;
if (value<0) {
value = atoi(get_param(global.parameters, "nmr.timeout"));
const char * str = get_param(global.parameters, "nmr.timeout");
value = str?atoi(str):0;
}
return value;
}
@ -378,7 +383,8 @@ allied_skillcount(const faction * f, skill_t sk)
int
allied_skilllimit(const faction * f, skill_t sk)
{
return atoi(get_param(global.parameters, "allied.skilllimit"));
const char * str = get_param(global.parameters, "allied.skilllimit");
return str?atoi(str):0;
}
#endif
@ -2186,7 +2192,7 @@ get_param(const struct param * p, const char * key)
if (strcmp(p->name, key)==0) return p->data;
p = p->next;
}
return "0";
return NULL;
}

View File

@ -438,57 +438,66 @@ travelthru(unit * u, region * r)
attrib *ru = a_add(&r->attribs, a_new(&at_travelunit));
ru->data.v = u;
/* the first and last region of the faction gets reset, because travelthrough
* could be in regions that are located before the [first, last] interval,
* and recalculation is needed */
u->faction->first = 0;
u->faction->last = 0;
}
static void
leave_trail(ship * sh, region **route)
{
region **ri = route;
while (*ri) {
region *r = *ri;
direction_t dir = reldirection(*ri, *rn);
attrib * a = a_find((*ri)->attribs, &at_traveldir_new);
traveldir * td = NULL;
while (a!=NULL) {
td = (traveldir *)a->data.v;
if (td->no == sh->no) break;
a = a->nexttype;
}
if (a!=NULL) {
a = a_add(&((*ri)->attribs), a_new(&at_traveldir_new));
td = (traveldir *)a->data.v;
td->no = sh->no;
}
td->dir = dir;
td->age = 2;
travelthru(u, r);
++ri;
}
}
ship *
move_ship(ship * sh, region * from, region * to, region ** route)
{
unit *u = from->units;
unit **iunit = &from->units;
unit **ulist = &to->units;
direction_t dir;
attrib *a;
boolean trail = (route==NULL);
if (from!=to) {
translist(&from->ships, &to->ships, sh);
sh->region = to;
}
while (u) {
unit *nu = u->next;
while (*iunit!=NULL) {
unit *u = *iunit;
assert(u->region==from);
if (u->ship == sh)
{
if (route) {
region **ri = route;
region **rn;
while (*ri) {
rn = ri+1;
if(*rn) {
dir = reldirection(*ri, *rn);
a = a_find((*ri)->attribs, &at_traveldir_new);
while (a) {
if(((traveldir *)(a->data.v))->no == sh->no) break;
a = a->nexttype;
}
if(!a) {
a = a_add(&((*ri)->attribs), a_new(&at_traveldir_new));
{
traveldir *t = (traveldir *)(a->data.v);
t->no = sh->no;
t->dir = dir;
t->age = 2;
}
} else {
traveldir *t = (traveldir *)(a->data.v);
t->dir = dir;
t->age = 2;
}
}
travelthru(u, *ri++);
}
if (u->ship == sh) {
if (!trail) {
leave_trail(sh, from, to, route);
trail=true;
}
if (from!=to) {
u->ship = NULL; /* damit move_unit() kein leave() macht */
@ -500,7 +509,7 @@ move_ship(ship * sh, region * from, region * to, region ** route)
produceexp(u, SK_SAILING, u->number);
}
}
u = nu;
if (*iunit==u) iunit=&u->next;
}
return sh;
}
@ -1943,9 +1952,9 @@ hunted_dir(attrib *at, int id)
{
attrib *a = a_find(at, &at_traveldir_new);
while(a) {
while (a!=NULL) {
traveldir *t = (traveldir *)(a->data.v);
if(t->no == id) return t->dir;
if (t->no == id) return t->dir;
a = a->nexttype;
}
@ -1991,7 +2000,7 @@ hunt(unit *u)
dir = hunted_dir(rc->attribs, id);
if(dir == NODIRECTION) {
if (dir == NODIRECTION) {
ship * sh = findship(id);
if (sh->region!=rc) {
cmistake(u, findorder(u, u->thisorder), 20, MSG_MOVE);
@ -2004,8 +2013,8 @@ hunt(unit *u)
moves = 1;
rc = rconnect(rc, dir);
while(moves < shipspeed(u->ship, u)
&& (dir = hunted_dir(rc->attribs, id)) != NODIRECTION) {
while (moves < shipspeed(u->ship, u) && (dir = hunted_dir(rc->attribs, id)) != NODIRECTION)
{
strcat(command, " ");
strcat(command, locale_string(u->faction->locale, directions[dir]));
moves++;
@ -2021,8 +2030,7 @@ hunt(unit *u)
/* niemand sollte auf einen kapitän direkt ein folge haben, oder? */
assert(1==0);
}
fset(u, UFL_LONGACTION); /* Von Hand setzen, um Endlosschleife zu vermeiden,
wenn Verfolgung nicht erfolgreich */
fset(u, UFL_LONGACTION); /* Von Hand setzen, um Endlosschleife zu vermeiden, wenn Verfolgung nicht erfolgreich */
return 1; /* true -> Einheitenliste von vorne durchgehen */
}

View File

@ -23,9 +23,11 @@
#include <stdlib.h>
#include <ctype.h>
/** rolls a number of n-sided dice.
* Usage: 3d6-3d4+5 = dice(3,6)-dice(3,4)+5 */
int
dice(int count, int value)
{ /* Usage: 3d6-3d4+5 = dice(3,6)-dice(3,4)+5 */
{
int d = 0, c;
if (value<=0) return 0; /* (enno) %0 geht nicht. echt wahr. */
@ -39,6 +41,10 @@ dice(int count, int value)
return d;
}
/** Parses a string of the form "2d6+8"
* Kann nur simple Strings der Form "xdy[+-]z" parsen!
* Schöner wäre eine flexibele Routine, die z.B. auch Sachen wie 2d6+3d4-1
* parsen kann. */
int
dice_rand(const char *s)
{

View File

@ -19,10 +19,6 @@
* permission from the authors.
*/
/* Kann nur simple Strings der Form "xdy[+-]z" parsen!
* Schöner wäre eine flexibele Routine, die z.B. auch Sachen wie 2d6+3d4-1
* parsen kann. */
#include <config.h>
#include "rand.h"
@ -35,12 +31,11 @@
#define drand() (((double)rand())/(double)RAND_MAX)
#define M_PIl 3.1415926535897932384626433832795029L /* pi */
static double nv_next;
static char valid_next = 0;
/* NormalRand aus python, random.py geklaut, dort ist Referenz auf
* den Algorithmus. mu = Mittelwert, sigma = Standardabweichung. */
double nv_next;
char valid_next = 0;
* den Algorithmus. mu = Mittelwert, sigma = Standardabweichung. */
double
normalvariate(double mu, double sigma)
{
@ -83,12 +78,12 @@ ntimespprob(int n, double p, double mod)
int count = 0;
int i;
for(i=0; i<n && p>0; i++)
for(i=0; i<n && p>0; i++) {
if(drand() < p) {
count++;
p += mod;
}
}
return count;
}
@ -98,4 +93,3 @@ chance(double x)
if (x>=1.0) return true;
return (boolean) (rand() % RAND_MAX < RAND_MAX * x);
}

View File

@ -18,11 +18,14 @@
extern "C" {
#endif
extern int dice_rand(const char *str);
extern int dice(int count, int value);
extern double normalvariate(double mu, double sigma);
extern int ntimespprob(int n, double p, double mod);
extern boolean chance(double x);
/* in dice.c: */
extern int dice_rand(const char *str);
extern int dice(int count, int value);
/* in rand.c: */
extern double normalvariate(double mu, double sigma);
extern int ntimespprob(int n, double p, double mod);
extern boolean chance(double x);
#ifdef __cplusplus
}

View File

@ -26,6 +26,8 @@
<param name="database.gameid" value="3"/>
<param name="hunger.long" value="0"/>
<param name="allied.skilllimit" value="15"/>
<param name="atsroi.ats" value="2"/>
<param name="atsroi.roi" value="4"/>
</game>
<xi:include href="vinyambar/wdw-strings.xml"/>