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

View File

@ -108,7 +108,8 @@ static int
RemoveNMRNewbie(void) { RemoveNMRNewbie(void) {
static int value = -1; static int value = -1;
if (value<0) { 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; return value;
} }

View File

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

View File

@ -111,7 +111,8 @@ static int
MaxAge(void) { MaxAge(void) {
static int value = -1; static int value = -1;
if (value<0) { 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; return value;
} }
@ -120,7 +121,8 @@ int
LongHunger(void) { LongHunger(void) {
static int value = -1; static int value = -1;
if (value<0) { 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; return value;
} }
@ -130,7 +132,8 @@ SkillCap(skill_t sk) {
static int value = -1; static int value = -1;
if (sk==SK_MAGIC) return 0; /* no caps on magic */ if (sk==SK_MAGIC) return 0; /* no caps on magic */
if (value<0) { 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; return value;
} }
@ -139,7 +142,8 @@ boolean
TradeDisabled(void) { TradeDisabled(void) {
static int value = -1; static int value = -1;
if (value<0) { 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; return value;
} }
@ -148,7 +152,8 @@ int
NMRTimeout(void) { NMRTimeout(void) {
static int value = -1; static int value = -1;
if (value<0) { 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; return value;
} }
@ -378,7 +383,8 @@ allied_skillcount(const faction * f, skill_t sk)
int int
allied_skilllimit(const faction * f, skill_t sk) 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 #endif
@ -2186,7 +2192,7 @@ get_param(const struct param * p, const char * key)
if (strcmp(p->name, key)==0) return p->data; if (strcmp(p->name, key)==0) return p->data;
p = p->next; 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)); attrib *ru = a_add(&r->attribs, a_new(&at_travelunit));
ru->data.v = u; 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->first = 0;
u->faction->last = 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 * ship *
move_ship(ship * sh, region * from, region * to, region ** route) move_ship(ship * sh, region * from, region * to, region ** route)
{ {
unit *u = from->units; unit **iunit = &from->units;
unit **ulist = &to->units; unit **ulist = &to->units;
direction_t dir; direction_t dir;
attrib *a; attrib *a;
boolean trail = (route==NULL);
if (from!=to) { if (from!=to) {
translist(&from->ships, &to->ships, sh); translist(&from->ships, &to->ships, sh);
sh->region = to; sh->region = to;
} }
while (u) { while (*iunit!=NULL) {
unit *nu = u->next; unit *u = *iunit;
assert(u->region==from);
if (u->ship == sh) if (u->ship == sh) {
{ if (!trail) {
if (route) { leave_trail(sh, from, to, route);
region **ri = route; trail=true;
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 (from!=to) { if (from!=to) {
u->ship = NULL; /* damit move_unit() kein leave() macht */ 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); produceexp(u, SK_SAILING, u->number);
} }
} }
u = nu; if (*iunit==u) iunit=&u->next;
} }
return sh; return sh;
} }
@ -1943,9 +1952,9 @@ hunted_dir(attrib *at, int id)
{ {
attrib *a = a_find(at, &at_traveldir_new); attrib *a = a_find(at, &at_traveldir_new);
while(a) { while (a!=NULL) {
traveldir *t = (traveldir *)(a->data.v); traveldir *t = (traveldir *)(a->data.v);
if(t->no == id) return t->dir; if (t->no == id) return t->dir;
a = a->nexttype; a = a->nexttype;
} }
@ -1991,7 +2000,7 @@ hunt(unit *u)
dir = hunted_dir(rc->attribs, id); dir = hunted_dir(rc->attribs, id);
if(dir == NODIRECTION) { if (dir == NODIRECTION) {
ship * sh = findship(id); ship * sh = findship(id);
if (sh->region!=rc) { if (sh->region!=rc) {
cmistake(u, findorder(u, u->thisorder), 20, MSG_MOVE); cmistake(u, findorder(u, u->thisorder), 20, MSG_MOVE);
@ -2004,8 +2013,8 @@ hunt(unit *u)
moves = 1; moves = 1;
rc = rconnect(rc, dir); rc = rconnect(rc, dir);
while(moves < shipspeed(u->ship, u) while (moves < shipspeed(u->ship, u) && (dir = hunted_dir(rc->attribs, id)) != NODIRECTION)
&& (dir = hunted_dir(rc->attribs, id)) != NODIRECTION) { {
strcat(command, " "); strcat(command, " ");
strcat(command, locale_string(u->faction->locale, directions[dir])); strcat(command, locale_string(u->faction->locale, directions[dir]));
moves++; moves++;
@ -2021,8 +2030,7 @@ hunt(unit *u)
/* niemand sollte auf einen kapitän direkt ein folge haben, oder? */ /* niemand sollte auf einen kapitän direkt ein folge haben, oder? */
assert(1==0); assert(1==0);
} }
fset(u, UFL_LONGACTION); /* Von Hand setzen, um Endlosschleife zu vermeiden, fset(u, UFL_LONGACTION); /* Von Hand setzen, um Endlosschleife zu vermeiden, wenn Verfolgung nicht erfolgreich */
wenn Verfolgung nicht erfolgreich */
return 1; /* true -> Einheitenliste von vorne durchgehen */ return 1; /* true -> Einheitenliste von vorne durchgehen */
} }

View File

@ -23,9 +23,11 @@
#include <stdlib.h> #include <stdlib.h>
#include <ctype.h> #include <ctype.h>
/** rolls a number of n-sided dice.
* Usage: 3d6-3d4+5 = dice(3,6)-dice(3,4)+5 */
int int
dice(int count, int value) dice(int count, int value)
{ /* Usage: 3d6-3d4+5 = dice(3,6)-dice(3,4)+5 */ {
int d = 0, c; int d = 0, c;
if (value<=0) return 0; /* (enno) %0 geht nicht. echt wahr. */ if (value<=0) return 0; /* (enno) %0 geht nicht. echt wahr. */
@ -39,6 +41,10 @@ dice(int count, int value)
return d; 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 int
dice_rand(const char *s) dice_rand(const char *s)
{ {

View File

@ -19,10 +19,6 @@
* permission from the authors. * 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 <config.h>
#include "rand.h" #include "rand.h"
@ -35,12 +31,11 @@
#define drand() (((double)rand())/(double)RAND_MAX) #define drand() (((double)rand())/(double)RAND_MAX)
#define M_PIl 3.1415926535897932384626433832795029L /* pi */ #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 /* NormalRand aus python, random.py geklaut, dort ist Referenz auf
* den Algorithmus. mu = Mittelwert, sigma = Standardabweichung. */ * den Algorithmus. mu = Mittelwert, sigma = Standardabweichung. */
double nv_next;
char valid_next = 0;
double double
normalvariate(double mu, double sigma) normalvariate(double mu, double sigma)
{ {
@ -83,12 +78,12 @@ ntimespprob(int n, double p, double mod)
int count = 0; int count = 0;
int i; int i;
for(i=0; i<n && p>0; i++) for(i=0; i<n && p>0; i++) {
if(drand() < p) { if(drand() < p) {
count++; count++;
p += mod; p += mod;
} }
}
return count; return count;
} }
@ -98,4 +93,3 @@ chance(double x)
if (x>=1.0) return true; if (x>=1.0) return true;
return (boolean) (rand() % RAND_MAX < RAND_MAX * x); return (boolean) (rand() % RAND_MAX < RAND_MAX * x);
} }

View File

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

View File

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