本文整理汇总了C++中rng函数的典型用法代码示例。如果您正苦于以下问题:C++ rng函数的具体用法?C++ rng怎么用?C++ rng使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rng函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: global_square_location
bool player::eat( item &food, bool force )
{
if( !food.is_food() ) {
return false;
}
// Check if it's rotten before eating!
food.calc_rot( global_square_location() );
const auto ret = force ? can_eat( food ) : will_eat( food, is_player() );
if( !ret.success() ) {
return false;
}
if( food.type->has_use() ) {
if( food.type->invoke( *this, food, pos() ) <= 0 ) {
return false;
}
}
// Note: the block below assumes we decided to eat it
// No coming back from here
const bool hibernate = has_active_mutation( trait_id( "HIBERNATE" ) );
const int nutr = nutrition_for( food );
const int quench = food.type->comestible->quench;
const bool spoiled = food.rotten();
// The item is solid food
const bool chew = food.type->comestible->comesttype == "FOOD" || food.has_flag( "USE_EAT_VERB" );
// This item is a drink and not a solid food (and not a thick soup)
const bool drinkable = !chew && food.type->comestible->comesttype == "DRINK";
// If neither of the above is true then it's a drug and shouldn't get mealtime penalty/bonus
if( hibernate &&
( get_hunger() > -60 && get_thirst() > -60 ) &&
( get_hunger() - nutr < -60 || get_thirst() - quench < -60 ) ) {
add_memorial_log( pgettext( "memorial_male", "Began preparing for hibernation." ),
pgettext( "memorial_female", "Began preparing for hibernation." ) );
add_msg_if_player(
_( "You've begun stockpiling calories and liquid for hibernation. You get the feeling that you should prepare for bed, just in case, but...you're hungry again, and you could eat a whole week's worth of food RIGHT NOW." ) );
}
const bool will_vomit = get_hunger() < 0 && nutr >= 5 && !has_trait( trait_id( "GOURMAND" ) ) &&
!hibernate &&
!has_trait( trait_id( "SLIMESPAWNER" ) ) && !has_trait( trait_id( "EATHEALTH" ) ) &&
rng( -200, 0 ) > get_hunger() - nutr;
const bool saprophage = has_trait( trait_id( "SAPROPHAGE" ) );
if( spoiled && !saprophage ) {
add_msg_if_player( m_bad, _( "Ick, this %s doesn't taste so good..." ), food.tname().c_str() );
if( !has_trait( trait_id( "SAPROVORE" ) ) && !has_trait( trait_id( "EATDEAD" ) ) &&
( !has_bionic( bio_digestion ) || one_in( 3 ) ) ) {
add_effect( effect_foodpoison, rng( 60, ( nutr + 1 ) * 60 ) );
}
consume_effects( food );
} else if( spoiled && saprophage ) {
add_msg_if_player( m_good, _( "Mmm, this %s tastes delicious..." ), food.tname().c_str() );
consume_effects( food );
} else {
consume_effects( food );
}
const bool amorphous = has_trait( trait_id( "AMORPHOUS" ) );
int mealtime = 250;
if( drinkable || chew ) {
// Those bonuses/penalties only apply to food
// Not to smoking weed or applying bandages!
if( has_trait( trait_id( "MOUTH_TENTACLES" ) ) || has_trait( trait_id( "MANDIBLES" ) ) ) {
mealtime /= 2;
} else if( has_trait( trait_id( "GOURMAND" ) ) ) {
// Don't stack those two - that would be 25 moves per item
mealtime -= 100;
}
if( has_trait( trait_id( "BEAK_HUM" ) ) && !drinkable ) {
mealtime += 200; // Much better than PROBOSCIS but still optimized for fluids
} else if( has_trait( trait_id( "SABER_TEETH" ) ) ) {
mealtime += 250; // They get In The Way
}
if( amorphous ) {
mealtime *= 1.1;
// Minor speed penalty for having to flow around it
// rather than just grab & munch
}
}
moves -= mealtime;
// If it's poisonous... poison us.
// TODO: Move this to a flag
if( food.poison > 0 && !has_trait( trait_id( "EATPOISON" ) ) &&
!has_trait( trait_id( "EATDEAD" ) ) ) {
if( food.poison >= rng( 2, 4 ) ) {
add_effect( effect_poison, food.poison * 100 );
}
add_effect( effect_foodpoison, food.poison * 300 );
}
if( amorphous ) {
add_msg_player_or_npc( _( "You assimilate your %s." ), _( "<npcname> assimilates a %s." ),
//.........这里部分代码省略.........
开发者ID:Caeous,项目名称:Cataclysm-DDA,代码行数:101,代码来源:consumption.cpp
示例2: x
//.........这里部分代码省略.........
dmatrix chd = choleski_decomp( (dscale*2.4/sqrt(double(nvar))) * S);
dmatrix chdinv=inv(chd);
int sgn;
dmatrix symbds(1,2,1,nvar);
initial_params::set_all_simulation_bounds(symbds);
ofstream ofs_sd1((char*)(ad_comm::adprogram_name + adstring(".mc2")));
{
long int iseed=0;
int number_sims;
if (nmcmc<=0)
{
number_sims= 100000;
}
else
{
number_sims= nmcmc;
}
//cin >> iseed;
if (iseed0<=0)
{
iseed=-36519;
}
else
{
iseed=-iseed0;
}
if (iseed>0)
{
iseed=-iseed;
}
cout << "Initial seed value " << iseed << endl;
random_number_generator rng(iseed);
rng.better_rand();
//better_rand(iseed);
double lprob=0.0;
double lpinv=0.0;
double lprob3=0.0;
// get lower and upper bounds
independent_variables y(1,nvar);
independent_variables parsave(1,nvar);
// read in the mcmc values to date
int ii=1;
dmatrix hist;
if (restart_flag)
{
int tmp=0;
if (!no_sd_mcmc) {
hist.allocate(1,ndvar,-nslots,nslots);
tmp=read_hist_data(hist,h,mean_mcmc_values,s,parsave,iseed,
size_scale);
values.allocate(1,ndvar,-nslots,nslots);
for (int i=1;i<=ndvar;i++)
{
values(i).fill_seqadd(mean_mcmc_values(i)-0.5*total_spread*s(i)
+.5*h(i),h(i));
}
}
if (iseed>0)
{
iseed=-iseed;
}
double br=rng.better_rand();
开发者ID:colemonnahan,项目名称:admb,代码行数:67,代码来源:xxmcmc2.cpp
示例3: debugmsg
void mission_start::place_npc_software(mission *miss)
{
npc* dev = g->find_npc(miss->npc_id);
if (dev == NULL) {
debugmsg("Couldn't find NPC! %d", miss->npc_id);
return;
}
g->u.i_add( item("usb_drive", 0) );
add_msg(_("%s gave you a USB drive."), dev->name.c_str());
std::string type = "house";
switch (dev->myclass) {
case NC_HACKER:
miss->item_id = "software_hacking";
break;
case NC_DOCTOR:
miss->item_id = "software_medical";
type = "s_pharm";
miss->follow_up = MISSION_GET_ZOMBIE_BLOOD_ANAL;
break;
case NC_SCIENTIST:
miss->item_id = "software_math";
break;
default:
miss->item_id = "software_useless";
}
int dist = 0;
point place;
if (type == "house") {
place = random_house_in_closest_city();
} else {
place = overmap_buffer.find_closest(dev->global_omt_location(), type, dist, false);
}
miss->target = place;
overmap_buffer.reveal(place, 6, g->get_levz());
tinymap compmap;
compmap.load(place.x * 2, place.y * 2, g->get_levz(), false);
point comppoint;
oter_id oter = overmap_buffer.ter(place.x, place.y, 0);
if( is_ot_type("house", oter) || is_ot_type("s_pharm", oter) || oter == "" ) {
std::vector<point> valid;
for (int x = 0; x < SEEX * 2; x++) {
for (int y = 0; y < SEEY * 2; y++) {
if (compmap.ter(x, y) == t_floor && compmap.furn(x, y) == f_null) {
bool okay = false;
int wall = 0;
for (int x2 = x - 1; x2 <= x + 1 && !okay; x2++) {
for (int y2 = y - 1; y2 <= y + 1 && !okay; y2++) {
if (compmap.furn(x2, y2) == f_bed || compmap.furn(x2, y2) == f_dresser) {
okay = true;
valid.push_back( point(x, y) );
}
if ( compmap.has_flag_ter("WALL", x2, y2) ) {
wall++;
}
}
}
if ( wall == 5 ) {
if ( compmap.is_last_ter_wall( true, x, y, SEEX * 2, SEEY * 2, NORTH ) &&
compmap.is_last_ter_wall( true, x, y, SEEX * 2, SEEY * 2, SOUTH ) &&
compmap.is_last_ter_wall( true, x, y, SEEX * 2, SEEY * 2, WEST ) &&
compmap.is_last_ter_wall( true, x, y, SEEX * 2, SEEY * 2, EAST ) ) {
valid.push_back( point(x, y) );
}
}
}
}
}
if (valid.empty()) {
comppoint = point( rng(6, SEEX * 2 - 7), rng(6, SEEY * 2 - 7) );
} else {
comppoint = valid[rng(0, valid.size() - 1)];
}
}
compmap.ter_set(comppoint.x, comppoint.y, t_console);
computer *tmpcomp = compmap.add_computer(comppoint.x, comppoint.y, string_format(_("%s's Terminal"), dev->name.c_str()), 0);
tmpcomp->mission_id = miss->uid;
tmpcomp->add_option(_("Download Software"), COMPACT_DOWNLOAD_SOFTWARE, 0);
compmap.save();
}
开发者ID:KA101,项目名称:Cataclysm-DDA,代码行数:85,代码来源:mission_start.cpp
示例4: digging
bool monster::move_to( const tripoint &p, bool force, const float stagger_adjustment )
{
const bool digs = digging();
const bool flies = has_flag( MF_FLIES );
const bool on_ground = !digs && !flies;
const bool climbs = has_flag( MF_CLIMBS ) && g->m.has_flag( TFLAG_NO_FLOOR, p );
// Allows climbing monsters to move on terrain with movecost <= 0
Creature *critter = g->critter_at( p, is_hallucination() );
if( g->m.has_flag( "CLIMBABLE", p ) ) {
if( g->m.impassable( p ) && critter == nullptr ) {
if( flies ) {
moves -= 100;
force = true;
if( g->u.sees( *this ) ) {
add_msg( _( "The %1$s flies over the %2$s." ), name().c_str(),
g->m.has_flag_furn( "CLIMBABLE", p ) ? g->m.furnname( p ).c_str() :
g->m.tername( p ).c_str() );
}
} else if( has_flag( MF_CLIMBS ) ) {
moves -= 150;
force = true;
if( g->u.sees( *this ) ) {
add_msg( _( "The %1$s climbs over the %2$s." ), name().c_str(),
g->m.has_flag_furn( "CLIMBABLE", p ) ? g->m.furnname( p ).c_str() :
g->m.tername( p ).c_str() );
}
}
}
}
if( critter != nullptr && !force ) {
return false;
}
// Make sure that we can move there, unless force is true.
if( !force && !can_move_to( p ) ) {
return false;
}
if( !force ) {
// This adjustment is to make it so that monster movement speed relative to the player
// is consistent even if the monster stumbles,
// and the same regardless of the distance measurement mode.
// Note: Keep this as float here or else it will cancel valid moves
const float cost = stagger_adjustment *
( float )( climbs ? calc_climb_cost( pos(), p ) :
calc_movecost( pos(), p ) );
if( cost > 0.0f ) {
moves -= ( int )ceil( cost );
} else {
return false;
}
}
//Check for moving into/out of water
bool was_water = g->m.is_divable( pos() );
bool will_be_water = on_ground && can_submerge() && g->m.is_divable( p );
if( was_water && !will_be_water && g->u.sees( p ) ) {
//Use more dramatic messages for swimming monsters
add_msg( m_warning, _( "A %1$s %2$s from the %3$s!" ), name().c_str(),
has_flag( MF_SWIMS ) || has_flag( MF_AQUATIC ) ? _( "leaps" ) : _( "emerges" ),
g->m.tername( pos() ).c_str() );
} else if( !was_water && will_be_water && g->u.sees( p ) ) {
add_msg( m_warning, _( "A %1$s %2$s into the %3$s!" ), name().c_str(),
has_flag( MF_SWIMS ) || has_flag( MF_AQUATIC ) ? _( "dives" ) : _( "sinks" ),
g->m.tername( p ).c_str() );
}
setpos( p );
footsteps( p );
underwater = will_be_water;
if( is_hallucination() ) {
//Hallucinations don't do any of the stuff after this point
return true;
}
// TODO: Make tanks stop taking damage from rubble, because it's just silly
if( type->size != MS_TINY && on_ground ) {
if( g->m.has_flag( "SHARP", pos() ) && !one_in( 4 ) ) {
apply_damage( nullptr, bp_torso, rng( 1, 10 ) );
}
if( g->m.has_flag( "ROUGH", pos() ) && one_in( 6 ) ) {
apply_damage( nullptr, bp_torso, rng( 1, 2 ) );
}
}
if( g->m.has_flag( "UNSTABLE", p ) && on_ground ) {
add_effect( effect_bouldering, 1, num_bp, true );
} else if( has_effect( effect_bouldering ) ) {
remove_effect( effect_bouldering );
}
g->m.creature_on_trap( *this );
if( !will_be_water && ( has_flag( MF_DIGS ) || has_flag( MF_CAN_DIG ) ) ) {
underwater = g->m.has_flag( "DIGGABLE", pos() );
}
// Diggers turn the dirt into dirtmound
if( digging() ) {
int factor = 0;
switch( type->size ) {
//.........这里部分代码省略.........
开发者ID:RyanMcManaman,项目名称:Cataclysm-DDA,代码行数:101,代码来源:monmove.cpp
示例5: integrator_t
//.........这里部分代码省略.........
}
else
{
if (fplog)
{
fprintf(fplog, "Will insert randomly in a sphere of radius %f around the center of the cavity\n", drmax);
}
}
ngid = groups->grps[egcENER].nr;
gid_tp = GET_CGINFO_GID(fr->cginfo[cg_tp]);
nener = 1 + ngid;
if (bDispCorr)
{
nener += 1;
}
if (bCharge)
{
nener += ngid;
if (bRFExcl)
{
nener += 1;
}
if (EEL_FULL(fr->eeltype))
{
nener += 1;
}
}
snew(sum_UgembU, nener);
/* Copy the random seed set by the user */
seed = inputrec->ld_seed;
gmx::ThreeFry2x64<16> rng(seed, gmx::RandomDomain::TestParticleInsertion); // 16 bits internal counter => 2^16 * 2 = 131072 values per stream
gmx::UniformRealDistribution<real> dist;
if (MASTER(cr))
{
fp_tpi = xvgropen(opt2fn("-tpi", nfile, fnm),
"TPI energies", "Time (ps)",
"(kJ mol\\S-1\\N) / (nm\\S3\\N)", oenv);
xvgr_subtitle(fp_tpi, "f. are averages over one frame", oenv);
snew(leg, 4+nener);
e = 0;
sprintf(str, "-kT log(<Ve\\S-\\betaU\\N>/<V>)");
leg[e++] = gmx_strdup(str);
sprintf(str, "f. -kT log<e\\S-\\betaU\\N>");
leg[e++] = gmx_strdup(str);
sprintf(str, "f. <e\\S-\\betaU\\N>");
leg[e++] = gmx_strdup(str);
sprintf(str, "f. V");
leg[e++] = gmx_strdup(str);
sprintf(str, "f. <Ue\\S-\\betaU\\N>");
leg[e++] = gmx_strdup(str);
for (i = 0; i < ngid; i++)
{
sprintf(str, "f. <U\\sVdW %s\\Ne\\S-\\betaU\\N>",
*(groups->grpname[groups->grps[egcENER].nm_ind[i]]));
leg[e++] = gmx_strdup(str);
}
if (bDispCorr)
{
sprintf(str, "f. <U\\sdisp c\\Ne\\S-\\betaU\\N>");
leg[e++] = gmx_strdup(str);
}
if (bCharge)
开发者ID:Murilogabardo,项目名称:gromacs,代码行数:67,代码来源:tpi.cpp
示例6: get_size
body_part Creature::select_body_part(Creature *source, int hit_roll)
{
// Get size difference (-1,0,1);
int szdif = source->get_size() - get_size();
if(szdif < -1) {
szdif = -1;
} else if (szdif > 1) {
szdif = 1;
}
add_msg( m_debug, "source size = %d", source->get_size() );
add_msg( m_debug, "target size = %d", get_size() );
add_msg( m_debug, "difference = %d", szdif );
std::map<body_part, double> hit_weights = default_hit_weights[szdif];
std::map<body_part, double>::iterator iter;
// If the target is on the ground, even small/tiny creatures may target eyes/head. Also increases chances of larger creatures.
// Any hit modifiers to locations should go here. (Tags, attack style, etc)
if(is_on_ground()) {
hit_weights[bp_eyes] += 10;
hit_weights[bp_head] += 20;
}
//Adjust based on hit roll: Eyes, Head & Torso get higher, while Arms and Legs get lower.
//This should eventually be replaced with targeted attacks and this being miss chances.
hit_weights[bp_eyes] = floor(hit_weights[bp_eyes] * std::pow(hit_roll, 1.15) * 10);
hit_weights[bp_head] = floor(hit_weights[bp_head] * std::pow(hit_roll, 1.15) * 10);
hit_weights[bp_torso] = floor(hit_weights[bp_torso] * std::pow(hit_roll, 1) * 10);
hit_weights[bp_arm_l] = floor(hit_weights[bp_arm_l] * std::pow(hit_roll, 0.95) * 10);
hit_weights[bp_arm_r] = floor(hit_weights[bp_arm_r] * std::pow(hit_roll, 0.95) * 10);
hit_weights[bp_leg_l] = floor(hit_weights[bp_leg_l] * std::pow(hit_roll, 0.975) * 10);
hit_weights[bp_leg_r] = floor(hit_weights[bp_leg_r] * std::pow(hit_roll, 0.975) * 10);
// Debug for seeing weights.
add_msg( m_debug, "eyes = %f", hit_weights.at( bp_eyes ) );
add_msg( m_debug, "head = %f", hit_weights.at( bp_head ) );
add_msg( m_debug, "torso = %f", hit_weights.at( bp_torso ) );
add_msg( m_debug, "arm_l = %f", hit_weights.at( bp_arm_l ) );
add_msg( m_debug, "arm_r = %f", hit_weights.at( bp_arm_r ) );
add_msg( m_debug, "leg_l = %f", hit_weights.at( bp_leg_l ) );
add_msg( m_debug, "leg_r = %f", hit_weights.at( bp_leg_r ) );
double totalWeight = 0;
std::set<std::pair<body_part, double>, weight_compare> adjusted_weights;
for(iter = hit_weights.begin(); iter != hit_weights.end(); ++iter) {
totalWeight += iter->second;
adjusted_weights.insert(*iter);
}
body_part selected_part = bp_torso;
// Blood thirsty monsters can discard body part and go to more damaged
int part_rolls = 1;
int repick_chance = 50;
if (source->has_flag(MF_BLOODTHIRSTY)) {
part_rolls += 2;
if (is_player() && g->u.has_trait("ANIMALEMPATH")) {
part_rolls -= 1;
repick_chance -= 10;
}
if (is_player() && g->u.has_trait("ANIMALDISCORD")) {
part_rolls += 1;
repick_chance += 10;
}
}
body_part last_part = selected_part;
for(int r = 0; r < part_rolls; ++r) {
double roll = rng_float(1, totalWeight);
std::set<std::pair<body_part, double>, weight_compare>::iterator adj_iter;
for(adj_iter = adjusted_weights.begin(); adj_iter != adjusted_weights.end(); ++adj_iter) {
roll -= adj_iter->second;
if(roll <= 0) {
selected_part = adj_iter->first;
break;
}
}
if (r != 0) {
hp_part hpart_cur = bodypart_to_hp_part(selected_part);
hp_part hpart_lst = bodypart_to_hp_part(last_part);
double ratio_cur = get_hp(hpart_cur) / float(get_hp_max(hpart_cur));
double ratio_lst = get_hp(hpart_lst) / float(get_hp_max(hpart_lst));
body_part cur_pick_part = selected_part;
if(ratio_cur > ratio_lst && repick_chance >= rng(1,100))
selected_part = last_part;
add_msg( m_debug, "picked %s from %s(%.2f)/%s(%.2f)",
body_part_name(selected_part).c_str(),
body_part_name(cur_pick_part).c_str(), ratio_cur,
body_part_name(last_part).c_str(), ratio_lst);
}
last_part = selected_part;
}
return selected_part;
}
开发者ID:ThatOneAnon,项目名称:Cataclysm-DDA,代码行数:97,代码来源:creature.cpp
示例7: stability_roll
bool monster::push_to( const tripoint &p, const int boost, const size_t depth )
{
if( is_hallucination() ) {
// Don't let hallucinations push, not even other hallucinations
return false;
}
if( !has_flag( MF_PUSH_MON ) || depth > 2 || has_effect( effect_pushed ) ) {
return false;
}
// TODO: Generalize this to Creature
monster *const critter = g->critter_at<monster>( p );
if( critter == nullptr || critter == this || p == pos() ) {
return false;
}
if( !can_move_to( p ) ) {
return false;
}
if( critter->is_hallucination() ) {
// Kill the hallu, but return false so that the regular move_to is uses instead
critter->die( nullptr );
return false;
}
// Stability roll of the pushed critter
const int defend = critter->stability_roll();
// Stability roll of the pushing zed
const int attack = stability_roll() + boost;
if( defend > attack ) {
return false;
}
const int movecost_from = 50 * g->m.move_cost( p );
const int movecost_attacker = std::max( movecost_from, 200 - 10 * ( attack - defend ) );
const tripoint dir = p - pos();
// Mark self as pushed to simplify recursive pushing
add_effect( effect_pushed, 1 );
for( size_t i = 0; i < 6; i++ ) {
const int dx = rng( -1, 1 );
const int dy = rng( -1, 1 );
if( dx == 0 && dy == 0 ) {
continue;
}
// Pushing forward is easier than pushing aside
const int direction_penalty = abs( dx - dir.x ) + abs( dy - dir.y );
if( direction_penalty > 2 ) {
continue;
}
tripoint dest( p.x + dx, p.y + dy, p.z );
// Pushing into cars/windows etc. is harder
const int movecost_penalty = g->m.move_cost( dest ) - 2;
if( movecost_penalty <= -2 ) {
// Can't push into unpassable terrain
continue;
}
int roll = attack - ( defend + direction_penalty + movecost_penalty );
if( roll < 0 ) {
continue;
}
Creature *critter_recur = g->critter_at( dest );
if( critter_recur == nullptr || critter_recur->is_hallucination() ) {
// Try to push recursively
monster *mon_recur = dynamic_cast< monster * >( critter_recur );
if( mon_recur == nullptr ) {
continue;
}
if( critter->push_to( dest, roll, depth + 1 ) ) {
// The tile isn't necessarily free, need to check
if( !g->critter_at( p ) ) {
move_to( p );
}
moves -= movecost_attacker;
if( movecost_from > 100 ) {
critter->add_effect( effect_downed, movecost_from / 100 + 1 );
} else {
critter->moves -= movecost_from;
}
return true;
} else {
continue;
}
}
critter_recur = g->critter_at( dest );
if( critter_recur != nullptr ) {
if( critter_recur->is_hallucination() ) {
critter_recur->die( nullptr );
//.........这里部分代码省略.........
开发者ID:RyanMcManaman,项目名称:Cataclysm-DDA,代码行数:101,代码来源:monmove.cpp
示例8: rng
void PhotonShootingTask::Run() {
// Declare local variables for _PhotonShootingTask_
MemoryArena arena;
RNG rng(31 * taskNum);
vector<Photon> localDirectPhotons, localIndirectPhotons, localCausticPhotons;
vector<RadiancePhoton> localRadiancePhotons;
u_int totalPaths = 0;
bool causticDone = (integrator->nCausticPhotonsWanted == 0);
bool indirectDone = (integrator->nIndirectPhotonsWanted == 0);
PermutedHalton halton(6, rng);
vector<Spectrum> localRpReflectances, localRpTransmittances;
while (true) {
// Follow photon paths for a block of samples
const u_int blockSize = 4096;
for (u_int i = 0; i < blockSize; ++i) {
float u[6];
halton.Sample(++totalPaths, u);
// Choose light to shoot photon from
float lightPdf;
int lightNum = lightDistribution->SampleDiscrete(u[0], &lightPdf);
const Light *light = scene->lights[lightNum];
// Generate _photonRay_ from light source and initialize _alpha_
RayDifferential photonRay;
float pdf;
LightSample ls(u[1], u[2], u[3]);
Normal Nl;
Spectrum Le = light->Sample_L(scene, ls, u[4], u[5],
&photonRay, &Nl, &pdf);
if (pdf == 0.f || Le.IsBlack()) continue;
Spectrum alpha = (AbsDot(Nl, photonRay.d) * Le) / (pdf * lightPdf);
if (!alpha.IsBlack()) {
// Follow photon path through scene and record intersections
PBRT_PHOTON_MAP_STARTED_RAY_PATH(&photonRay, &alpha);
bool specularPath = true;
Intersection photonIsect;
u_int nIntersections = 0;
while (scene->Intersect(photonRay, &photonIsect)) {
++nIntersections;
// Handle photon/surface intersection
alpha *= renderer->Transmittance(scene, photonRay, NULL, arena, &rng);
BSDF *photonBSDF = photonIsect.GetBSDF(photonRay, arena);
BxDFType specularType = BxDFType(BSDF_REFLECTION |
BSDF_TRANSMISSION | BSDF_SPECULAR);
bool hasNonSpecular = (photonBSDF->NumComponents() >
photonBSDF->NumComponents(specularType));
Vector wo = -photonRay.d;
if (hasNonSpecular) {
// Deposit photon at surface
Photon photon(photonIsect.dg.p, alpha, wo);
bool depositedPhoton = false;
if (nIntersections == 1) {
PBRT_PHOTON_MAP_DEPOSITED_DIRECT_PHOTON(&photonIsect.dg, &alpha, &wo);
depositedPhoton = true;
localDirectPhotons.push_back(photon);
}
else {
// Deposit either caustic or indirect photon
if (specularPath && !causticDone) {
PBRT_PHOTON_MAP_DEPOSITED_CAUSTIC_PHOTON(&photonIsect.dg, &alpha, &wo);
depositedPhoton = true;
localCausticPhotons.push_back(photon);
}
else if (!specularPath && !indirectDone) {
PBRT_PHOTON_MAP_DEPOSITED_INDIRECT_PHOTON(&photonIsect.dg, &alpha, &wo);
depositedPhoton = true;
localIndirectPhotons.push_back(photon);
}
}
// Possibly create radiance photon at photon intersection point
if (depositedPhoton && integrator->finalGather &&
rng.RandomFloat() < .125f) {
// Store data for radiance photon
Normal n = photonIsect.dg.nn;
n = Faceforward(n, -photonRay.d);
localRadiancePhotons.push_back(RadiancePhoton(photonIsect.dg.p, n));
// Generate random samples for computing reflectance and transmittance
const int sqrtRhoSamples = 4;
float rhoRSamples1[2*sqrtRhoSamples*sqrtRhoSamples];
float rhoRSamples2[2*sqrtRhoSamples*sqrtRhoSamples];
StratifiedSample2D(rhoRSamples1, sqrtRhoSamples, sqrtRhoSamples, rng);
StratifiedSample2D(rhoRSamples2, sqrtRhoSamples, sqrtRhoSamples, rng);
float rhoTSamples1[2*sqrtRhoSamples*sqrtRhoSamples];
float rhoTSamples2[2*sqrtRhoSamples*sqrtRhoSamples];
StratifiedSample2D(rhoTSamples1, sqrtRhoSamples, sqrtRhoSamples, rng);
StratifiedSample2D(rhoTSamples2, sqrtRhoSamples, sqrtRhoSamples, rng);
Spectrum rho_r = photonBSDF->rho(sqrtRhoSamples * sqrtRhoSamples,
rhoRSamples1, rhoRSamples2, BSDF_ALL_REFLECTION);
localRpReflectances.push_back(rho_r);
Spectrum rho_t = photonBSDF->rho(sqrtRhoSamples * sqrtRhoSamples,
rhoTSamples1, rhoTSamples2, BSDF_ALL_TRANSMISSION);
localRpTransmittances.push_back(rho_t);
}
}
if ((int)nIntersections >= integrator->maxPhotonDepth) break;
// Sample new photon ray direction
Vector wi;
//.........这里部分代码省略.........
开发者ID:sungsoo,项目名称:pbrt-v2,代码行数:101,代码来源:photonmap.cpp
示例9: switch
void event::actualize()
{
switch( type ) {
case EVENT_HELP:
debugmsg("Currently disabled while NPC and monster factions are being rewritten.");
break;
case EVENT_ROBOT_ATTACK: {
const auto u_pos = g->u.global_sm_location();
if (rl_dist(u_pos, map_point) <= 4) {
const mtype_id& robot_type = one_in( 2 ) ? mon_copbot : mon_riotbot;
g->u.add_memorial_log( pgettext("memorial_male", "Became wanted by the police!"),
pgettext("memorial_female", "Became wanted by the police!"));
int robx = (u_pos.x > map_point.x ? 0 - SEEX * 2 : SEEX * 4);
int roby = (u_pos.y > map_point.y ? 0 - SEEY * 2 : SEEY * 4);
g->summon_mon(robot_type, tripoint(robx, roby, g->u.posz()));
}
} break;
case EVENT_SPAWN_WYRMS: {
if (g->get_levz() >= 0) {
return;
}
g->u.add_memorial_log(pgettext("memorial_male", "Drew the attention of more dark wyrms!"),
pgettext("memorial_female", "Drew the attention of more dark wyrms!"));
int num_wyrms = rng(1, 4);
for (int i = 0; i < num_wyrms; i++) {
int tries = 0;
tripoint monp = g->u.pos();
do {
monp.x = rng(0, SEEX * MAPSIZE);
monp.y = rng(0, SEEY * MAPSIZE);
tries++;
} while (tries < 10 && !g->is_empty(monp) &&
rl_dist(g->u.pos(), monp) <= 2);
if (tries < 10) {
g->m.ter_set(monp, t_rock_floor);
g->summon_mon(mon_dark_wyrm, monp);
}
}
// You could drop the flag, you know.
if (g->u.has_amount("petrified_eye", 1)) {
sounds::sound(g->u.pos(), 60, "");
if (!g->u.is_deaf()) {
add_msg(_("The eye you're carrying lets out a tortured scream!"));
g->u.add_morale(MORALE_SCREAM, -15, 0, 300, 5);
}
}
if (!one_in(25)) { // They just keep coming!
g->events.add( EVENT_SPAWN_WYRMS, calendar::turn + rng( 15_turns, 25_turns ) );
}
} break;
case EVENT_AMIGARA: {
g->u.add_memorial_log(pgettext("memorial_male", "Angered a group of amigara horrors!"),
pgettext("memorial_female", "Angered a group of amigara horrors!"));
int num_horrors = rng(3, 5);
int faultx = -1, faulty = -1;
bool horizontal = false;
for (int x = 0; x < SEEX * MAPSIZE && faultx == -1; x++) {
for (int y = 0; y < SEEY * MAPSIZE && faulty == -1; y++) {
if (g->m.ter(x, y) == t_fault) {
faultx = x;
faulty = y;
horizontal = (g->m.ter(x - 1, y) == t_fault || g->m.ter(x + 1, y) == t_fault);
}
}
}
for (int i = 0; i < num_horrors; i++) {
int tries = 0;
int monx = -1, mony = -1;
do {
if (horizontal) {
monx = rng(faultx, faultx + 2 * SEEX - 8);
for (int n = -1; n <= 1; n++) {
if (g->m.ter(monx, faulty + n) == t_rock_floor) {
mony = faulty + n;
}
}
} else { // Vertical fault
mony = rng(faulty, faulty + 2 * SEEY - 8);
for (int n = -1; n <= 1; n++) {
if (g->m.ter(faultx + n, mony) == t_rock_floor) {
monx = faultx + n;
}
}
}
tries++;
} while ((monx == -1 || mony == -1 || !g->is_empty({monx, mony, g->u.posz()})) &&
tries < 10);
if (tries < 10) {
g->summon_mon(mon_amigara_horror, tripoint(monx, mony, g->u.posz()));
}
}
} break;
case EVENT_ROOTS_DIE:
g->u.add_memorial_log(pgettext("memorial_male", "Destroyed a triffid grove."),
pgettext("memorial_female", "Destroyed a triffid grove."));
//.........这里部分代码省略.........
开发者ID:Caeous,项目名称:Cataclysm-DDA,代码行数:101,代码来源:event.cpp
示例10: switch
// Why put this in a Big Switch? Why not let bionics have pointers to
// functions, much like monsters and items?
//
// Well, because like diseases, which are also in a Big Switch, bionics don't
// share functions....
void player::activate_bionic(int b, game *g)
{
bionic bio = my_bionics[b];
int power_cost = bionics[bio.id].power_cost;
if (weapon.type->id == itm_bio_claws && bio.id == bio_claws)
power_cost = 0;
if (power_level < power_cost) {
if (my_bionics[b].powered) {
g->add_msg("Your %s powers down.", bionics[bio.id].name.c_str());
my_bionics[b].powered = false;
} else
g->add_msg("You cannot power your %s", bionics[bio.id].name.c_str());
return;
}
if (my_bionics[b].powered && my_bionics[b].charge > 0) {
// Already-on units just lose a bit of charge
my_bionics[b].charge--;
} else {
// Not-on units, or those with zero charge, have to pay the power cost
if (bionics[bio.id].charge_time > 0) {
my_bionics[b].powered = true;
my_bionics[b].charge = bionics[bio.id].charge_time;
}
power_level -= power_cost;
}
std::string junk;
std::vector<point> traj;
std::vector<std::string> good;
std::vector<std::string> bad;
WINDOW* w;
int dirx, diry, t, index;
InputEvent input;
unsigned int l;
item tmp_item;
switch (bio.id) {
case bio_painkiller:
pkill += 6;
pain -= 2;
if (pkill > pain)
pkill = pain;
break;
case bio_nanobots:
healall(4);
break;
case bio_resonator:
g->sound(posx, posy, 30, "VRRRRMP!");
for (int i = posx - 1; i <= posx + 1; i++) {
for (int j = posy - 1; j <= posy + 1; j++) {
g->m.bash(i, j, 40, junk);
g->m.bash(i, j, 40, junk); // Multibash effect, so that doors &c will fall
g->m.bash(i, j, 40, junk);
if (g->m.is_destructable(i, j) && rng(1, 10) >= 4)
g->m.ter(i, j) = t_rubble;
}
}
break;
case bio_time_freeze:
moves += 100 * power_level;
power_level = 0;
g->add_msg("Your speed suddenly increases!");
if (one_in(3)) {
g->add_msg("Your muscles tear with the strain.");
hurt(g, bp_arms, 0, rng(5, 10));
hurt(g, bp_arms, 1, rng(5, 10));
hurt(g, bp_legs, 0, rng(7, 12));
hurt(g, bp_legs, 1, rng(7, 12));
hurt(g, bp_torso, 0, rng(5, 15));
}
if (one_in(5))
add_disease(DI_TELEGLOW, rng(50, 400), g);
break;
case bio_teleport:
g->teleport();
add_disease(DI_TELEGLOW, 300, g);
break;
// TODO: More stuff here (and bio_blood_filter)
case bio_blood_anal:
w = newwin(20, 40, 3, 10);
wborder(w, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX,
LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX );
if (has_disease(DI_FUNGUS))
bad.push_back("Fungal Parasite");
if (has_disease(DI_DERMATIK))
bad.push_back("Insect Parasite");
if (has_disease(DI_POISON))
bad.push_back("Poison");
if (radiation > 0)
//.........这里部分代码省略.........
开发者ID:zpmorgan,项目名称:Cataclysm-DDA,代码行数:101,代码来源:bionics.cpp
示例11: debugmsg
bool player::install_bionics(game *g, it_bionic* type)
{
if (type == NULL) {
debugmsg("Tried to install NULL bionic");
return false;
}
std::string bio_name = type->name.substr(5); // Strip off "CBM: "
WINDOW* w = newwin(25, 80, 0, 0);
int pl_skill = int_cur +
skillLevel("electronics").level() * 4 +
skillLevel("firstaid").level() * 3 +
skillLevel("mechanics").level() * 2;
int skint = int(pl_skill / 4);
int skdec = int((pl_skill * 10) / 4) % 10;
// Header text
mvwprintz(w, 0, 0, c_white, "Installing bionics:");
mvwprintz(w, 0, 20, type->color, bio_name.c_str());
// Dividing bars
for (int i = 0; i < 80; i++) {
mvwputch(w, 1, i, c_ltgray, LINE_OXOX);
mvwputch(w, 21, i, c_ltgray, LINE_OXOX);
}
// Init the list of bionics
for (int i = 1; i < type->options.size(); i++) {
bionic_id id = type->options[i];
mvwprintz(w, i + 2, 0, (has_bionic(id) ? c_ltred : c_ltblue),
bionics[id].name.c_str());
}
// Helper text
mvwprintz(w, 2, 40, c_white, "Difficulty of this module: %d",
type->difficulty);
mvwprintz(w, 3, 40, c_white, "Your installation skill: %d.%d",
skint, skdec);
mvwprintz(w, 4, 40, c_white, "Installation requires high intelligence,");
mvwprintz(w, 5, 40, c_white, "and skill in electronics, first aid, and");
mvwprintz(w, 6, 40, c_white, "mechanics (in that order of importance).");
int chance_of_success = int((100 * pl_skill) /
(pl_skill + 4 * type->difficulty));
mvwprintz(w, 8, 40, c_white, "Chance of success:");
nc_color col_suc;
if (chance_of_success >= 95)
col_suc = c_green;
else if (chance_of_success >= 80)
col_suc = c_ltgreen;
else if (chance_of_success >= 60)
col_suc = c_yellow;
else if (chance_of_success >= 35)
col_suc = c_ltred;
else
col_suc = c_red;
mvwprintz(w, 8, 59, col_suc, "%d%%%%", chance_of_success);
mvwprintz(w, 10, 40, c_white, "Failure may result in crippling damage,");
mvwprintz(w, 11, 40, c_white, "loss of existing bionics, genetic damage");
mvwprintz(w, 12, 40, c_white, "or faulty installation.");
wrefresh(w);
if (type->id == itm_bionics_battery) { // No selection list; just confirm
mvwprintz(w, 2, 0, h_ltblue, "Battery Level +%d", BATTERY_AMOUNT);
mvwprintz(w, 22, 0, c_ltblue, "\
Installing this bionic will increase your total battery capacity by %d.\n\
Batteries are necessary for most bionics to function. They also require a\n\
charge mechanism, which must be installed from another CBM.", BATTERY_AMOUNT);
InputEvent input;
wrefresh(w);
do
input = get_input();
while (input != Confirm && input != Close);
if (input == Confirm) {
practice("electronics", (100 - chance_of_success) * 1.5);
practice("firstaid", (100 - chance_of_success) * 1.0);
practice("mechanics", (100 - chance_of_success) * 0.5);
int success = chance_of_success - rng(1, 100);
if (success > 0) {
g->add_msg("Successfully installed batteries.");
max_power_level += BATTERY_AMOUNT;
} else
bionics_install_failure(g, this, success);
werase(w);
delwin(w);
g->refresh_all();
return true;
}
werase(w);
delwin(w);
g->refresh_all();
return false;
}
开发者ID:zpmorgan,项目名称:Cataclysm-DDA,代码行数:96,代码来源:bionics.cpp
示例12: CheckReproducibilityBody
CheckReproducibilityBody(std::size_t GrainSize): grainSize(GrainSize) {
//first generate seeds to check on, and make sure that sequence is reproducible
ASSERT(SingleCheck<seedsNum>()(0),"Series generated by FastRandom must be reproducible");
std::generate(seeds,seeds+seedsNum,rng(0));
}
开发者ID:yyzreal,项目名称:iHRC,代码行数:5,代码来源:test_fast_random.cpp
示例13: debugmsg
void mission_start::place_npc_software(mission *miss)
{
npc* dev = g->find_npc(miss->npc_id);
if (dev == NULL) {
debugmsg("Couldn't find NPC! %d", miss->npc_id);
return;
}
g->u.i_add( item(itypes["usb_drive"], 0) );
g->add_msg(_("%s gave you a USB drive."), dev->name.c_str());
std::string type = "house";
switch (dev->myclass) {
case NC_HACKER:
miss->item_id = "software_hacking";
break;
case NC_DOCTOR:
miss->item_id = "software_medical";
type = "s_pharm";
miss->follow_up = MISSION_GET_ZOMBIE_BLOOD_ANAL;
break;
case NC_SCIENTIST:
miss->item_id = "software_math";
break;
default:
miss->item_id = "software_useless";
}
int dist = 0;
point place;
if (type == "house") {
int city_id = g->cur_om->closest_city( g->om_location() );
place = g->cur_om->random_house_in_city(city_id);
} else {
place = g->cur_om->find_closest(g->om_location(), type, dist, false);
}
miss->target = place;
// Make it seen on our map
for (int x = place.x - 6; x <= place.x + 6; x++) {
for (int y = place.y - 6; y <= place.y + 6; y++)
g->cur_om->seen(x, y, 0) = true;
}
tinymap compmap(&(g->traps));
compmap.load(place.x * 2, place.y * 2, 0, false);
point comppoint;
oter_id oter = g->cur_om->ter(place.x, place.y, 0);
if (oter == "house_north" || oter == "house_east"
|| oter == "house_south" || oter == "house_west") {
std::vector<point> valid;
for (int x = 0; x < SEEX * 2; x++) {
for (int y = 0; y < SEEY * 2; y++) {
if (compmap.ter(x, y) == t_floor && compmap.furn(x, y) == f_null) {
bool okay = false;
for (int x2 = x - 1; x2 <= x + 1 && !okay; x2++) {
for (int y2 = y - 1; y2 <= y + 1 && !okay; y2++) {
if (compmap.furn(x2, y2) == f_bed || compmap.furn(x2, y2) == f_dresser) {
okay = true;
valid.push_back( point(x, y) );
}
}
}
}
}
}
if (valid.empty()) {
comppoint = point( rng(6, SEEX * 2 - 7), rng(6, SEEY * 2 - 7) );
} else {
comppoint = valid[rng(0, valid.size() - 1)];
}
} else if (oter == "s_pharm_north") {
bool found = false;
for (int x = SEEX * 2 - 1; x > 0 && !found; x--) {
for (int y = SEEY * 2 - 1; y > 0 && !found; y--) {
if (compmap.ter(x, y) == t_floor) {
found = true;
comppoint = point(x, y);
}
}
}
} else if (oter == "s_pharm_east") {
bool found = false;
for (int x = 0; x < SEEX * 2 && !found; x++) {
for (int y = SEEY * 2 - 1; y > 0 && !found; y--) {
if (compmap.ter(x, y) == t_floor) {
found = true;
comppoint = point(x, y);
}
}
}
} else if (oter == "s_pharm_south") {
bool found = false;
for (int x = 0; x < SEEX * 2 && !found; x++) {
for (int y = 0; y < SEEY * 2 && !found; y++) {
if (compmap.ter(x, y) == t_floor) {
found = true;
comppoint = point(x, y);
}
}
//.........这里部分代码省略.........
开发者ID:DapperDogman,项目名称:Cataclysm-DDA,代码行数:101,代码来源:mission_start.cpp
|
请发表评论