Merge branch 'develop' of github.com:ennorehling/eressea into develop

This commit is contained in:
Enno Rehling 2017-05-04 06:51:28 +02:00
commit 138035dfda
6 changed files with 32 additions and 20 deletions

View File

@ -17,7 +17,7 @@ require 'eressea.path'
require 'tests.e2'
require 'lunit'
rng_default(0)
rng.inject(0)
rules = require('eressea.' .. config.rules)
result = lunit.main()
return result.errors + result.failed

View File

@ -17,7 +17,7 @@ require 'eressea.xmlconf'
require 'tests.e3'
require 'lunit'
rng_default(0)
rng.inject(0)
eressea.settings.set("rules.alliances", "0")
rules = require('eressea.' .. config.rules)
result = lunit.main()

View File

@ -1205,11 +1205,12 @@ terminate(troop dt, troop at, int type, const char *damage, bool missile)
if (type != AT_COMBATSPELL && type != AT_SPELL) {
if (rule_damage & DAMAGE_CRITICAL) {
double kritchance = (sk * 3 - sd) / 200.0;
int maxk = 4;
kritchance = MAX(kritchance, 0.005);
kritchance = MIN(0.9, kritchance);
while (chance(kritchance)) {
while (maxk-- && chance(kritchance)) {
da += dice_rand(damage);
}
}

View File

@ -231,7 +231,7 @@ static int tolua_setkey(lua_State * L)
return 0;
}
static int tolua_rng_int(lua_State * L)
static int tolua_random(lua_State * L)
{
lua_pushinteger(L, rng_int());
return 1;
@ -1017,6 +1017,14 @@ int tolua_bindings_open(lua_State * L, const dictionary *inifile)
tolua_module(L, NULL, 0);
tolua_beginmodule(L, NULL);
{
tolua_module(L, TOLUA_CAST "rng", 1);
tolua_beginmodule(L, TOLUA_CAST "rng");
{
tolua_function(L, TOLUA_CAST "inject", lua_rng_default);
tolua_function(L, TOLUA_CAST "random", tolua_random);
}
tolua_endmodule(L);
tolua_function(L, TOLUA_CAST "rng_int", tolua_random);
tolua_cclass(L, TOLUA_CAST "alliance", TOLUA_CAST "alliance",
TOLUA_CAST "", NULL);
tolua_beginmodule(L, TOLUA_CAST "alliance");
@ -1066,7 +1074,6 @@ int tolua_bindings_open(lua_State * L, const dictionary *inifile)
tolua_function(L, TOLUA_CAST "get_ship", tolua_get_ship);
tolua_function(L, TOLUA_CAST "get_building", tolua_get_building);
tolua_function(L, TOLUA_CAST "get_region", tolua_get_region);
tolua_function(L, TOLUA_CAST "rng_default", lua_rng_default);
tolua_function(L, TOLUA_CAST "factions", tolua_get_factions);
tolua_function(L, TOLUA_CAST "regions", tolua_get_regions);
tolua_function(L, TOLUA_CAST "read_turn", tolua_read_turn);
@ -1107,7 +1114,6 @@ int tolua_bindings_open(lua_State * L, const dictionary *inifile)
tolua_function(L, TOLUA_CAST "get_key", tolua_getkey);
tolua_function(L, TOLUA_CAST "set_key", tolua_setkey);
tolua_function(L, TOLUA_CAST "translate", &tolua_translate);
tolua_function(L, TOLUA_CAST "rng_int", tolua_rng_int);
tolua_function(L, TOLUA_CAST "spells", tolua_get_spells);
tolua_function(L, TOLUA_CAST "read_xml", tolua_read_xml);
} tolua_endmodule(L);

View File

@ -14,6 +14,7 @@
#define NO_STRDUP
#define NO_MKDIR
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma warning(disable: 4710 4820)
#pragma warning(disable: 4100) // unreferenced formal parameter
#pragma warning(disable: 4456) // declaration hides previous

View File

@ -36,23 +36,27 @@ int lovar(double xpct_x2)
return (rng_int() % n + rng_int() % n) / 1000;
}
/* NormalRand aus python, random.py geklaut, dort ist Referenz auf
* den Algorithmus. mu = Mittelwert, sigma = Standardabweichung.
* http://de.wikipedia.org/wiki/Standardabweichung#Diskrete_Gleichverteilung.2C_W.C3.BCrfel
*/
/* gaussian distribution
* taken from http://c-faq.com/lib/gaussian.html
*/
double normalvariate(double mu, double sigma)
{
static const double NV_MAGICCONST = 1.7155277699214135;
double z;
for (;;) {
double u1 = rng_double();
double u2 = rng_double();
z = NV_MAGICCONST * (u1 - 0.5) / u2;
if (z * z / 4.0 <= -log(u2)) {
break;
static double U, V;
static int phase = 0;
double Z;
if (phase == 0) {
U = (rng_int() + 1.) / (RNG_RAND_MAX + 2.);
V = rng_int() / (RNG_RAND_MAX + 1.);
Z = sqrt(-2 * log(U)) * sin(2 * M_PI * V);
}
else {
Z = sqrt(-2 * log(U)) * cos(2 * M_PI * V);
}
return mu + z * sigma;
phase = 1 - phase;
return mu + Z *sigma;
}
int ntimespprob(int n, double p, double mod)