Skip to content

Commit

Permalink
use unsynced rng for unit traits
Browse files Browse the repository at this point in the history
this has 2 reasons:
1) In the 'unit::unit(const unit_type& u_type ..' ctor the facting is
usually overwritten after the unit is constructed (at least the normal
unit recruit code does that) so calling the synced rng there has no
other effect than blocking undoing (in case that the unit has no traits,
otherwise undoing would already be imposible because of trait
generation)

2) in the 'unit::unit(const config& cfg ...' ctor it might make sense to
use the synced rng, but since iirc the facing attribute is already
unsynced since it changed by the drawing code (which might be skipped if
animations are disabled) we also use the unsyced rng here to not block
undoing (in that rare case).
  • Loading branch information
gfgtdf authored and GregoryLundberg committed Nov 30, 2017
1 parent b57048d commit b5b0b11
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/units/unit.cpp
Expand Up @@ -437,7 +437,7 @@ unit::unit(const config& cfg, bool use_traits, const vconfig* vcfg)

random_traits_ = cfg["random_traits"].to_bool(true);
facing_ = map_location::parse_direction(cfg["facing"]);
if(facing_ == map_location::NDIRECTIONS) facing_ = static_cast<map_location::DIRECTION>(randomness::generator->get_random_int(0, map_location::NDIRECTIONS-1));
if(facing_ == map_location::NDIRECTIONS) facing_ = static_cast<map_location::DIRECTION>(randomness::rng::default_instance().get_random_int(0, map_location::NDIRECTIONS-1));

if(const config& mods = cfg.child("modifications")) {
modifications_ = mods;
Expand Down Expand Up @@ -668,7 +668,7 @@ unit::unit(const unit_type& u_type, int side, bool real_unit, unit_race::GENDER
, overlays_()
, role_()
, attacks_()
, facing_(static_cast<map_location::DIRECTION>(randomness::generator->get_random_int(0, map_location::NDIRECTIONS-1)))
, facing_(static_cast<map_location::DIRECTION>(randomness::rng::default_instance().get_random_int(0, map_location::NDIRECTIONS-1)))
, trait_names_()
, trait_descriptions_()
, unit_value_()
Expand Down

0 comments on commit b5b0b11

Please sign in to comment.