MCPcopy Create free account
hub / github.com/TurningWheel/Barony / setRandomMonsterStats

Function setRandomMonsterStats

src/entity.cpp:20127–20229  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20125}
20126
20127void setRandomMonsterStats(Stat* stats, BaronyRNG& rng)
20128{
20129 if ( stats != nullptr )
20130 {
20131 //**************************************
20132 // HEALTH
20133 //**************************************
20134
20135 if ( stats->MAXHP == stats->HP )
20136 {
20137 stats->MAXHP += rng.rand() % (stats->RANDOM_MAXHP + 1);
20138
20139 if ( stats->RANDOM_MAXHP == stats->RANDOM_HP )
20140 {
20141 // if the max hp and normal hp range is the same, hp follows the roll of maxhp.
20142 stats->HP = stats->MAXHP;
20143 }
20144 else
20145 {
20146 // roll the current hp
20147 stats->HP += rng.rand() % (stats->RANDOM_HP + 1);
20148 }
20149 }
20150 else
20151 {
20152 // roll both ranges independently
20153 stats->MAXHP += rng.rand() % (stats->RANDOM_MAXHP + 1);
20154 stats->HP += rng.rand() % (stats->RANDOM_HP + 1);
20155 }
20156
20157 if ( stats->HP > stats->MAXHP )
20158 {
20159 // check if hp exceeds maximums
20160 stats->HP = stats->MAXHP;
20161 }
20162 stats->OLDHP = stats->HP;
20163
20164 //**************************************
20165 // MANA
20166 //**************************************
20167
20168 if ( stats->MAXMP == stats->MP )
20169 {
20170 stats->MAXMP += rng.rand() % (stats->RANDOM_MAXMP + 1);
20171
20172 if ( stats->RANDOM_MAXMP == stats->RANDOM_MP )
20173 {
20174 // if the max mp and normal mp range is the same, mp follows the roll of maxmp.
20175 stats->MP = stats->MAXMP;
20176 }
20177 else
20178 {
20179 // roll the current mp
20180 stats->MP += rng.rand() % (stats->RANDOM_MP + 1);
20181 }
20182 }
20183 else
20184 {

Callers 15

initMonsterSFunction · 0.85
initMonsterMFunction · 0.85
initMonsterGFunction · 0.85
initGoblinFunction · 0.85
initImpFunction · 0.85
initMinotaurFunction · 0.85
initVampireFunction · 0.85
initSentryBotFunction · 0.85
initGyroBotFunction · 0.85
initDummyBotFunction · 0.85
initScorpionFunction · 0.85
initAutomatonFunction · 0.85

Calls 1

randMethod · 0.80

Tested by

no test coverage detected