mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-25 11:26:37 +00:00 
			
		
		
		
	Simpler statistical calculation of next weather; minus before parens.
This commit is contained in:
		
							parent
							
								
									04d90b4c47
								
							
						
					
					
						commit
						f01aa8f55e
					
				
					 1 changed files with 31 additions and 37 deletions
				
			
		|  | @ -375,42 +375,36 @@ void WeatherManager::update(float duration) | ||||||
| 
 | 
 | ||||||
|                 if (region != 0) |                 if (region != 0) | ||||||
|                 { |                 { | ||||||
|                     float clear = region->mData.mClear/255.f; |                     /*
 | ||||||
|                     float cloudy = region->mData.mCloudy/255.f; |                      * All probabilities must add to 100 (responsibility of the user). | ||||||
|                     float foggy = region->mData.mFoggy/255.f; |                      * If chances A and B has values 30 and 70 then by generating | ||||||
|                     float overcast = region->mData.mOvercast/255.f; |                      * 100 numbers 1..100, 30% will be lesser or equal 30 and | ||||||
|                     float rain = region->mData.mRain/255.f; |                      * 70% will be greater than 30 (in theory). | ||||||
|                     float thunder = region->mData.mThunder/255.f; |                      */ | ||||||
|                     float ash = region->mData.mAsh/255.f; |                     const int probability[] = { | ||||||
|                     float blight = region->mData.mBlight/255.f; |                         region->mData.mClear, | ||||||
|                     float snow = region->mData.mA/255.f; |                         region->mData.mCloudy, | ||||||
|                     float blizzard = region->mData.mB/255.f; |                         region->mData.mFoggy, | ||||||
|  |                         region->mData.mOvercast, | ||||||
|  |                         region->mData.mRain, | ||||||
|  |                         region->mData.mThunder, | ||||||
|  |                         region->mData.mAsh, | ||||||
|  |                         region->mData.mBlight, | ||||||
|  |                         region->mData.mA, | ||||||
|  |                         region->mData.mB | ||||||
|  |                     }; // 10 elements
 | ||||||
| 
 | 
 | ||||||
|                     // re-scale to 100 percent
 |                     int chance = (rand() % 100) + 1; // 1..100
 | ||||||
|                     const float total = clear+cloudy+foggy+overcast+rain+thunder+ash+blight+snow+blizzard; |                     int sum = 0; | ||||||
| 
 |                     for (int i = 0; i < 10; ++i) | ||||||
|                     float random = ((rand()%100)/100.f) * total; |                     { | ||||||
| 
 |                         sum += probability[i]; | ||||||
|                     if (random >= snow+blight+ash+thunder+rain+overcast+foggy+cloudy+clear) |                         if (chance < sum) | ||||||
|                         weatherType = Weather::Type_Blizzard; |                         { | ||||||
|                     else if (random >= blight+ash+thunder+rain+overcast+foggy+cloudy+clear) |                             weatherType = (Weather::Type)i; | ||||||
|                         weatherType = Weather::Type_Snow; |                             break; | ||||||
|                     else if (random >= ash+thunder+rain+overcast+foggy+cloudy+clear) |                         } | ||||||
|                         weatherType = Weather::Type_Blight; |                     } | ||||||
|                     else if (random >= thunder+rain+overcast+foggy+cloudy+clear) |  | ||||||
|                         weatherType = Weather::Type_Ashstorm; |  | ||||||
|                     else if (random >= rain+overcast+foggy+cloudy+clear) |  | ||||||
|                         weatherType = Weather::Type_Thunderstorm; |  | ||||||
|                     else if (random >= overcast+foggy+cloudy+clear) |  | ||||||
|                         weatherType = Weather::Type_Rain; |  | ||||||
|                     else if (random >= foggy+cloudy+clear) |  | ||||||
|                         weatherType = Weather::Type_Overcast; |  | ||||||
|                     else if (random >= cloudy+clear) |  | ||||||
|                         weatherType = Weather::Type_Foggy; |  | ||||||
|                     else if (random >= clear) |  | ||||||
|                         weatherType = Weather::Type_Cloudy; |  | ||||||
|                     else |  | ||||||
|                         weatherType = Weather::Type_Clear; |  | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|  | @ -461,8 +455,8 @@ void WeatherManager::update(float duration) | ||||||
|         int facing = (mHour > 13.f) ? 1 : -1; |         int facing = (mHour > 13.f) ? 1 : -1; | ||||||
| 
 | 
 | ||||||
|         Vector3 final( |         Vector3 final( | ||||||
|             -(1 - height) * facing, |             (height - 1) * facing, | ||||||
|             -(1 - height) * facing, |             (height - 1) * facing, | ||||||
|             height); |             height); | ||||||
|         mRendering->setSunDirection(final); |         mRendering->setSunDirection(final); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue