本文整理汇总了C++中rng_int函数的典型用法代码示例。如果您正苦于以下问题:C++ rng_int函数的具体用法?C++ rng_int怎么用?C++ rng_int使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rng_int函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: assert
unit *addplayer(region * r, faction * f)
{
unit *u;
const char * name;
assert(r->land);
if (rpeasants(r) < PEASANT_MIN) {
rsetpeasants(r, PEASANT_MIN + rng_int() % (PEASANT_MAX - PEASANT_MIN));
}
assert(f->units == NULL);
faction_setorigin(f, 0, r->x, r->y);
u = create_unit(r, f, 1, f->race, 0, NULL, NULL);
u->thisorder = default_order(f->locale);
unit_addorder(u, copy_order(u->thisorder));
name = config_get("rules.equip_first");
if (!equip_unit(u, name ? name : "first_unit")) {
/* give every unit enough money to survive the first turn */
i_change(&u->items, get_resourcetype(R_SILVER)->itype, maintenance_cost(u));
}
u->hp = unit_max_hp(u) * u->number;
fset(u, UFL_ISNEW);
if (f->race == get_race(RC_DAEMON)) {
race_t urc;
const race *rc;
do {
urc = (race_t)(rng_int() % MAXRACES);
rc = get_race(urc);
} while (rc == NULL || urc == RC_DAEMON || !playerrace(rc));
u->irace = rc;
}
f->lastorders = 0;
return u;
}
开发者ID:eressea,项目名称:server,代码行数:34,代码来源:faction.c
示例2: scared_by_monster
static void scared_by_monster(unit * u)
{
int n;
switch (old_race(u_race(u))) {
case RC_FIREDRAGON:
n = rng_int() % 160 * u->number;
break;
case RC_DRAGON:
n = rng_int() % 400 * u->number;
break;
case RC_WYRM:
n = rng_int() % 1000 * u->number;
break;
default:
n = rng_int() % (u->number / 4 + 1);
}
if (n > 0) {
n = lovar(n);
n = _min(rpeasants(u->region), n);
if (n > 0) {
n = scareaway(u->region, n);
if (n > 0) {
ADDMSG(&u->region->msgs, msg_message("fleescared",
"amount unit", n, u));
}
}
}
}
开发者ID:hochl,项目名称:server,代码行数:30,代码来源:monster.c
示例3: main
int main() {
int i, numIn, n;
int state;
double x, y, pi;
n = 100000000;
numIn = 0;
#pragma omp parallel private(state, x, y) reduction(+:numIn)
{
state = 25234 + 17 * omp_get_thread_num();
#pragma omp for
for (i = 0; i <= n; i++) {
state = rng_int(state);
x = (double)rng_doub(1.0, state);
state = rng_int(state);
y = (double)rng_doub(1.0, state);
if (x*x + y*y <= 1) numIn++;
}
}
pi = 4.*numIn / n;
printf("asdf pi %f\n", pi);
return 0;
}
开发者ID:CCJY,项目名称:coliru,代码行数:25,代码来源:main.cpp
示例4: calloc
faction *gm_addquest(const char *email, const char *name, int radius,
unsigned int flags)
{
plane *pl;
watcher *w = calloc(sizeof(watcher), 1);
region *center;
bool invalid = false;
int minx, miny, maxx, maxy, cx, cy;
int x;
faction *f;
/* GM playfield */
do {
minx = ((rng_int() % (2 * EXTENSION)) - EXTENSION);
miny = ((rng_int() % (2 * EXTENSION)) - EXTENSION);
for (x = 0; !invalid && x <= radius * 2; ++x) {
int y;
for (y = 0; !invalid && y <= radius * 2; ++y) {
region *r = findregion(minx + x, miny + y);
if (r)
invalid = true;
}
}
} while (invalid);
maxx = minx + 2 * radius;
cx = minx + radius;
maxy = miny + 2 * radius;
cy = miny + radius;
pl = create_new_plane(rng_int(), name, minx, maxx, miny, maxy, flags);
center = new_region(cx, cy, pl, 0);
for (x = 0; x <= 2 * radius; ++x) {
int y;
for (y = 0; y <= 2 * radius; ++y) {
region *r = findregion(minx + x, miny + y);
if (!r) {
r = new_region(minx + x, miny + y, pl, 0);
}
freset(r, RF_ENCOUNTER);
if (distance(r, center) == radius) {
terraform_region(r, newterrain(T_FIREWALL));
} else if (r == center) {
terraform_region(r, newterrain(T_PLAIN));
} else {
terraform_region(r, newterrain(T_OCEAN));
}
}
}
/* watcher: */
f = gm_addfaction(email, pl, center);
w->faction = f;
w->mode = see_unit;
w->next = pl->watchers;
pl->watchers = w;
return f;
}
开发者ID:UweKopf,项目名称:server,代码行数:57,代码来源:gmcmd.c
示例5: terraform_default
static void terraform_default(struct rawmaterial *res, const region * r)
{
#define SHIFT 70
double modifier =
1.0 + ((rng_int() % (SHIFT * 2 + 1)) - SHIFT) * ((rng_int() % (SHIFT * 2 +
1)) - SHIFT) / 10000.0;
res->amount = (int)(res->amount * modifier); /* random adjustment, +/- 91% */
if (res->amount < 1)
res->amount = 1;
unused_arg(r);
}
开发者ID:Xolgrim,项目名称:server,代码行数:11,代码来源:resources.c
示例6: demon_skillchanges
/** Talente von Dämonen verschieben sich.
*/
static void demon_skillchanges(void)
{
region *r;
for (r = regions; r; r = r->next) {
unit *u;
for (u = r->units; u; u = u->next) {
if (u_race(u) == get_race(RC_DAEMON)) {
skill *sv = u->skills;
int upchance = 15;
int downchance = 10;
if (fval(u, UFL_HUNGER)) {
/* hungry demons only go down, never up in skill */
static int rule_hunger = -1;
if (rule_hunger < 0) {
rule_hunger =
get_param_int(global.parameters, "hunger.demon.skill", 0);
}
if (rule_hunger) {
upchance = 0;
downchance = 15;
}
}
while (sv != u->skills + u->skill_size) {
int roll = rng_int() % 100;
if (sv->level > 0 && roll < upchance + downchance) {
int weeks = 1 + rng_int() % 3;
if (roll < downchance) {
reduce_skill(u, sv, weeks);
if (sv->level < 1) {
/* demons should never forget below 1 */
set_level(u, sv->id, 1);
}
} else {
while (weeks--)
learn_skill(u, sv->id, 1.0);
}
if (sv->old > sv->level) {
if (verbosity >= 3) {
log_printf(stdout, "%s dropped from %u to %u:%u in %s\n",
unitname(u), sv->old, sv->level, sv->weeks, skillname(sv->id,
NULL));
}
}
}
++sv;
}
}
}
}
}
开发者ID:hochl,项目名称:server,代码行数:55,代码来源:randenc.c
示例7: godcurse
static void godcurse(void)
{
region *r;
for (r = regions; r; r = r->next) {
if (is_cursed(r->attribs, C_CURSED_BY_THE_GODS, 0)) {
unit *u;
for (u = r->units; u; u = u->next) {
skill *sv = u->skills;
while (sv != u->skills + u->skill_size) {
int weeks = 1 + rng_int() % 3;
reduce_skill(u, sv, weeks);
++sv;
}
}
if (fval(r->terrain, SEA_REGION)) {
ship *sh;
for (sh = r->ships; sh;) {
ship *shn = sh->next;
double dmg = config_get_flt("rules.ship.damage.godcurse", 0.1);
damage_ship(sh, dmg);
if (sh->damage >= sh->size * DAMAGE_SCALE) {
unit *u = ship_owner(sh);
if (u)
ADDMSG(&u->faction->msgs,
msg_message("godcurse_destroy_ship", "ship", sh));
remove_ship(&sh->region->ships, sh);
}
sh = shn;
}
}
}
}
}
开发者ID:eressea,项目名称:server,代码行数:35,代码来源:randenc.c
示例8: assert
const terrain_type *random_terrain(const terrain_type * terrains[],
int distribution[], int size)
{
int ndistribution = size;
const terrain_type *terrain;
int n;
assert(size > 0);
if (distribution) {
ndistribution = 0;
for (n = 0; n != size; ++n) {
ndistribution += distribution[n];
}
}
n = rng_int() % ndistribution;
if (distribution) {
int i;
for (i = 0; i != size; ++i) {
n -= distribution[i];
if (n < 0)
break;
}
assert(i < size);
terrain = terrains[i];
}
else {
terrain = terrains[n];
}
return terrain;
}
开发者ID:philbooth,项目名称:server,代码行数:31,代码来源:autoseed.c
示例9: malloc
static const terrain_type *chaosterrain(void)
{
static const terrain_type **types;
static int numtypes;
if (numtypes == 0) {
const terrain_type *terrain;
for (terrain = terrains(); terrain != NULL; terrain = terrain->next) {
if (fval(terrain, LAND_REGION) && terrain->herbs) {
++numtypes;
}
}
if (numtypes > 0) {
types = malloc(sizeof(terrain_type *) * numtypes);
numtypes = 0;
for (terrain = terrains(); terrain != NULL; terrain = terrain->next) {
if (fval(terrain, LAND_REGION) && terrain->herbs) {
types[numtypes++] = terrain;
}
}
}
}
if (numtypes > 0) {
return types[rng_int() % numtypes];
}
return NULL;
}
开发者ID:stm2,项目名称:server,代码行数:27,代码来源:chaos.c
示例10: encounters
void encounters(void)
{
region *r;
for (r = regions; r; r = r->next) {
if (fval(r->terrain, LAND_REGION) && fval(r, RF_ENCOUNTER)) {
int c = 0;
unit *u;
for (u = r->units; u; u = u->next) {
c += u->number;
}
if (c > 0) {
int i = 0;
int n = rng_int() % c;
for (u = r->units; u; u = u->next) {
if (i + u->number > n)
break;
i += u->number;
}
assert(u && u->number);
encounter(r, u);
}
}
}
}
开发者ID:hochl,项目名称:server,代码行数:27,代码来源:randenc.c
示例11: rng_int
static unit *random_unit(const region * r)
{
int c = 0;
int n;
unit *u;
for (u = r->units; u; u = u->next) {
if (u_race(u) != get_race(RC_SPELL)) {
c += u->number;
}
}
if (c == 0) {
return NULL;
}
n = rng_int() % c;
c = 0;
u = r->units;
while (u && c < n) {
if (u_race(u) != get_race(RC_SPELL)) {
c += u->number;
}
u = u->next;
}
return u;
}
开发者ID:hochl,项目名称:server,代码行数:28,代码来源:randenc.c
示例12: rng_int
static order *monster_learn(unit * u)
{
int c = 0;
int n;
skill *sv;
const struct locale *lang = u->faction->locale;
/* can these monsters even study? */
if (!unit_can_study(u)) {
return NULL;
}
/* Monster lernt ein zufälliges Talent aus allen, in denen es schon
* Lerntage hat. */
for (sv = u->skills; sv != u->skills + u->skill_size; ++sv) {
if (sv->level > 0)
++c;
}
if (c == 0)
return NULL;
n = rng_int() % c + 1;
c = 0;
for (sv = u->skills; sv != u->skills + u->skill_size; ++sv) {
if (sv->level > 0) {
if (++c == n) {
return create_order(K_STUDY, lang, "'%s'", skillname(sv->id, lang));
}
}
}
return NULL;
}
开发者ID:philbooth,项目名称:server,代码行数:34,代码来源:monsters.c
示例13: arena_weighted_mbind
static void arena_weighted_mbind(void *arena, size_t arena_size,
uint16_t *weights, size_t nr_weights) {
/* compute cumulative sum for weights
* cumulative sum starts at -1
* the method for determining a hit on a weight i is when the generated
* random number (modulo sum of weights) <= weights_cumsum[i]
*/
int64_t weights_cumsum[nr_weights];
weights_cumsum[0] = weights[0] - 1;
for (unsigned int i = 1; i < nr_weights; i++) {
weights_cumsum[i] = weights_cumsum[i-1] + weights[i];
}
const int32_t weight_sum = weights_cumsum[nr_weights-1]+1;
const int pagesize = getpagesize();
uint64_t mask = 0;
char *q = (char *)arena + arena_size;
rng_init(1);
for (char *p = arena; p < q; p += pagesize) {
uint32_t r = rng_int(1<<31) % weight_sum;
unsigned int node;
for (node = 0; node < nr_weights; node++) {
if (weights_cumsum[node] >= r) {
break;
}
}
mask = 1 << node;
if (mbind(p, pagesize, MPOL_BIND, &mask, nr_weights, MPOL_MF_STRICT)) {
perror("mbind");
exit(1);
}
*p = 0;
}
}
开发者ID:jichuan2k,项目名称:multichase,代码行数:34,代码来源:arena.c
示例14: scareaway
static int scareaway(region * r, int anzahl)
{
int n, p, diff = 0, emigrants[MAXDIRECTIONS];
direction_t d;
anzahl = _min(_max(1, anzahl), rpeasants(r));
/* Wandern am Ende der Woche (normal) oder wegen Monster. Die
* Wanderung wird erst am Ende von demographics () ausgefuehrt.
* emigrants[] ist local, weil r->newpeasants durch die Monster
* vielleicht schon hochgezaehlt worden ist. */
for (d = 0; d != MAXDIRECTIONS; d++)
emigrants[d] = 0;
p = rpeasants(r);
assert(p >= 0 && anzahl >= 0);
for (n = _min(p, anzahl); n; n--) {
direction_t dir = (direction_t) (rng_int() % MAXDIRECTIONS);
region *rc = rconnect(r, dir);
if (rc && fval(rc->terrain, LAND_REGION)) {
++diff;
rc->land->newpeasants++;
emigrants[dir]++;
}
}
rsetpeasants(r, p - diff);
assert(p >= diff);
return diff;
}
开发者ID:hochl,项目名称:server,代码行数:31,代码来源:monster.c
示例15: demon_skillchange
/** Talente von Daemonen verschieben sich.
*/
void demon_skillchange(unit *u)
{
skill *sv = u->skills;
int upchance = 15, downchance = 10;
static int config;
static bool rule_hunger;
static int cfgup, cfgdown;
if (config_changed(&config)) {
rule_hunger = config_get_int("hunger.demon.skills", 0) != 0;
cfgup = config_get_int("skillchange.demon.up", 15);
cfgdown = config_get_int("skillchange.demon.down", 10);
}
if (cfgup == 0) {
/* feature is disabled */
return;
}
upchance = cfgup;
downchance = cfgdown;
if (fval(u, UFL_HUNGER)) {
/* hungry demons only go down, never up in skill */
if (rule_hunger) {
downchance = upchance;
upchance = 0;
}
}
while (sv != u->skills + u->skill_size) {
int roll = rng_int() % 100;
if (sv->level > 0 && roll < upchance + downchance) {
int weeks = 1 + rng_int() % 3;
if (roll < downchance) {
reduce_skill(u, sv, weeks);
if (sv->level < 1) {
/* demons should never forget below 1 */
set_level(u, sv->id, 1);
}
}
else {
learn_skill(u, sv->id, STUDYDAYS * u->number * weeks);
}
}
++sv;
}
}
开发者ID:ennorehling,项目名称:eressea,代码行数:48,代码来源:study.c
示例16: findregion
plane *gm_addplane(int radius, unsigned int flags, const char *name)
{
region *center;
plane *pl;
bool invalid = false;
int minx, miny, maxx, maxy, cx, cy;
int x;
/* GM playfield */
do {
minx = (rng_int() % (2 * EXTENSION)) - EXTENSION;
miny = (rng_int() % (2 * EXTENSION)) - EXTENSION;
for (x = 0; !invalid && x <= radius * 2; ++x) {
int y;
for (y = 0; !invalid && y <= radius * 2; ++y) {
region *r = findregion(minx + x, miny + y);
if (r)
invalid = true;
}
}
} while (invalid);
maxx = minx + 2 * radius;
cx = minx + radius;
maxy = miny + 2 * radius;
cy = miny + radius;
pl = create_new_plane(rng_int(), name, minx, maxx, miny, maxy, flags);
center = new_region(cx, cy, pl, 0);
for (x = 0; x <= 2 * radius; ++x) {
int y;
for (y = 0; y <= 2 * radius; ++y) {
region *r = findregion(minx + x, miny + y);
if (!r)
r = new_region(minx + x, miny + y, pl, 0);
freset(r, RF_ENCOUNTER);
if (distance(r, center) == radius) {
terraform_region(r, newterrain(T_FIREWALL));
} else if (r == center) {
terraform_region(r, newterrain(T_PLAIN));
} else {
terraform_region(r, newterrain(T_OCEAN));
}
}
}
return pl;
}
开发者ID:UweKopf,项目名称:server,代码行数:45,代码来源:gmcmd.c
示例17: age_dragon
void age_dragon(unit * u)
{
if (u->number > 0 && rng_int() % 100 < age_chance(u->age, WYRMAGE, 1)) {
double q = (double)u->hp / (double)(unit_max_hp(u) * u->number);
u_setrace(u, new_race[RC_WYRM]);
u->irace = NULL;
u->hp = (int)(unit_max_hp(u) * u->number * q);
}
}
开发者ID:UweKopf,项目名称:server,代码行数:9,代码来源:dragons.c
示例18: scale_number
void scale_number(unit * u, int n)
{
skill_t sk;
const attrib *a;
int remain;
if (n == u->number)
return;
if (n && u->number > 0) {
int full;
remain = ((u->hp % u->number) * (n % u->number)) % u->number;
full = u->hp / u->number; /* wieviel kriegt jede person mindestens */
u->hp = full * n + (u->hp - full * u->number) * n / u->number;
assert(u->hp >= 0);
if ((rng_int() % u->number) < remain)
++u->hp; /* Nachkommastellen */
} else {
remain = 0;
u->hp = 0;
}
if (u->number > 0) {
for (a = a_find(u->attribs, &at_effect); a && a->type == &at_effect;
a = a->next) {
effect_data *data = (effect_data *) a->data.v;
int snew = data->value / u->number * n;
if (n) {
remain = data->value - snew / n * u->number;
snew += remain * n / u->number;
remain = (remain * n) % u->number;
if ((rng_int() % u->number) < remain)
++snew; /* Nachkommastellen */
}
data->value = snew;
}
}
if (u->number == 0 || n == 0) {
for (sk = 0; sk < MAXSKILLS; sk++) {
remove_skill(u, sk);
}
}
set_number(u, n);
}
开发者ID:UweKopf,项目名称:server,代码行数:44,代码来源:unit.c
示例19: eaten_by_monster
static void eaten_by_monster(unit * u)
{
/* adjustment for smaller worlds */
static double multi = 0.0;
int n = 0;
int horse = 0;
if (multi == 0.0) {
multi = RESOURCE_QUANTITY * newterrain(T_PLAIN)->size / 10000.0;
}
switch (old_race(u_race(u))) {
case RC_FIREDRAGON:
n = rng_int() % 80 * u->number;
horse = get_item(u, I_HORSE);
break;
case RC_DRAGON:
n = rng_int() % 200 * u->number;
horse = get_item(u, I_HORSE);
break;
case RC_WYRM:
n = rng_int() % 500 * u->number;
horse = get_item(u, I_HORSE);
break;
default:
n = rng_int() % (u->number / 20 + 1);
}
n = (int)(n * multi);
if (n > 0) {
n = lovar(n);
n = MIN(rpeasants(u->region), n);
if (n > 0) {
deathcounts(u->region, n);
rsetpeasants(u->region, rpeasants(u->region) - n);
ADDMSG(&u->region->msgs, msg_message("eatpeasants", "unit amount", u, n));
}
}
if (horse > 0) {
set_item(u, I_HORSE, 0);
ADDMSG(&u->region->msgs, msg_message("eathorse", "unit amount", u, horse));
}
}
开发者ID:UweKopf,项目名称:server,代码行数:44,代码来源:monster.c
示例20: encounter
static void encounter(region * r, unit * u)
{
if (!fval(r, RF_ENCOUNTER))
return;
freset(r, RF_ENCOUNTER);
if (rng_int() % 100 >= ENCCHANCE)
return;
switch (rng_int() % 3) {
case 0:
find_manual(r, u);
break;
case 1:
get_villagers(r, u);
break;
case 2:
get_allies(r, u);
break;
}
}
开发者ID:hochl,项目名称:server,代码行数:19,代码来源:randenc.c
注:本文中的rng_int函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论