making the old eressea binary run on x64:

- normalvariate fix.
- familiars again
- invalid assert
- forgot init_reports
This commit is contained in:
Enno Rehling 2006-02-09 22:20:28 +00:00
parent e02a7afb78
commit 589b1b036a
5 changed files with 27 additions and 40 deletions

View File

@ -1436,8 +1436,13 @@ randomevents(void)
int n = itm->number; int n = itm->number;
double k = n*rot_chance/100.0; double k = n*rot_chance/100.0;
if (fval(itm->type, ITF_HERB)) { if (fval(itm->type, ITF_HERB)) {
n = (int)(min(n, normalvariate(k, k/4))); double nv = normalvariate(k, k/4);
i_change(itmp, itm->type, -n); int inv = (int)nv;
int delta = min(n, inv);
if (inv<0) {
nv = normalvariate(k, k/4);
}
i_change(itmp, itm->type, -delta);
} }
if (itm==*itmp) itmp=&itm->next; if (itm==*itmp) itmp=&itm->next;
} }

View File

@ -148,10 +148,10 @@ register_bordertype(border_type * type)
border_type * border_type *
find_bordertype(const char * name) find_bordertype(const char * name)
{ {
border_type * bt = bordertypes; border_type * bt = bordertypes;
while (bt && strcmp(bt->__name, name)) bt = bt->next; while (bt && strcmp(bt->__name, name)) bt = bt->next;
return bt; return bt;
} }
void void
@ -176,7 +176,6 @@ b_read(border * b, FILE *f)
void void
b_write(const border * b, FILE *f) b_write(const border * b, FILE *f)
{ {
assert(sizeof(int)==sizeof(b->data));
switch (b->type->datatype) { switch (b->type->datatype) {
case VAR_NONE: case VAR_NONE:
case VAR_INT: case VAR_INT:

View File

@ -535,8 +535,7 @@ select_familiar(const race * magerace, magic_t magiegebiet)
retval = magerace->familiars[magiegebiet]; retval = magerace->familiars[magiegebiet];
} }
assert (retval!=NULL); if (retval!=NULL && retval->init_familiar!=NULL) {
if (retval->init_familiar!=NULL) {
return NULL; return NULL;
} }
return retval; return retval;

View File

@ -26,9 +26,10 @@
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#include <math.h> #include <math.h>
#include <float.h>
#include <ctype.h> #include <ctype.h>
#define drand() (((double)rand())/(double)RAND_MAX) #define drand() ((rand()%RAND_MAX)/(double)RAND_MAX)
#define M_PIl 3.1415926535897932384626433832795029L /* pi */ #define M_PIl 3.1415926535897932384626433832795029L /* pi */
static double nv_next; static double nv_next;
@ -39,37 +40,17 @@ static char valid_next = 0;
double double
normalvariate(double mu, double sigma) normalvariate(double mu, double sigma)
{ {
double x2pi, g2rad, z; static double NV_MAGICCONST = 1.7155277699214135;
double t1, t2; double z;
double fac=1; for (;;) {
static double mu_alt, sigma_alt; double u1 = drand();
double u2 = 1.0 - drand();
if(mu < 10) { z = NV_MAGICCONST*(u1-0.5)/u2;
fac=0.01; if (z*z/4.0 <= -log(u2)) {
mu*=100; break;
sigma*=100; }
} }
return mu+z*sigma;
if(mu_alt!=mu || sigma_alt!= sigma)
valid_next=0;
mu_alt=mu;
sigma_alt=sigma;
if (valid_next == 0) {
x2pi = drand() * 2.0L * M_PIl;
t1 = drand();
t1 = 1.0 - t1;
t2 = log(t1);
g2rad = sqrt(-2.0 * t2);
z = cos(x2pi) * g2rad;
nv_next = sin(x2pi) * g2rad;
valid_next = 1;
} else {
z = nv_next;
valid_next = 0;
}
return (fac*(mu + z*sigma)); /* mu thorin */
} }
int int

View File

@ -271,7 +271,10 @@ processturn(char *filename)
} }
score(); score();
update_guards(); update_guards();
if (!noreports) reports(); if (!noreports) {
init_reports();
reports();
}
free_units(); free_units();
puts(" - Beseitige leere Parteien"); puts(" - Beseitige leere Parteien");
remove_empty_factions(true); remove_empty_factions(true);