|
1 | 1 | #include "RNG.h" |
2 | 2 |
|
| 3 | +std::uint64_t BOS_RNG::get_form_seed(const RE::TESForm* a_form) |
| 4 | +{ |
| 5 | + if (a_form->IsDynamicForm()) { |
| 6 | + return a_form->GetFormID(); |
| 7 | + } |
| 8 | + |
| 9 | + std::uint64_t result = 0; |
| 10 | + boost::hash_combine(result, a_form->GetLocalFormID()); |
| 11 | + boost::hash_combine(result, a_form->GetFile(0)->GetFilename()); |
| 12 | + return result; |
| 13 | +} |
| 14 | + |
3 | 15 | BOS_RNG::BOS_RNG(const Chance& a_chance, const RE::TESObjectREFR* a_ref) : |
4 | 16 | type(a_chance.chanceType) |
5 | 17 | { |
6 | 18 | switch (type) { |
7 | 19 | case CHANCE_TYPE::kRefHash: |
8 | | - seed = a_ref->GetFormID(); |
| 20 | + seed = get_form_seed(a_ref); |
9 | 21 | break; |
10 | 22 | case CHANCE_TYPE::kLocationHash: |
11 | 23 | { |
12 | | - auto baseID = a_ref->GetBaseObject()->GetFormID(); |
13 | | - auto location = a_ref->GetCurrentLocation(); |
| 24 | + auto base = a_ref->GetBaseObject(); |
| 25 | + auto location = a_ref->GetEditorLocation(); |
14 | 26 | auto cell = a_ref->GetSaveParentCell(); |
15 | 27 |
|
16 | 28 | if (!location && !cell) { |
17 | | - seed = a_ref->GetFormID(); |
| 29 | + seed = get_form_seed(a_ref); |
18 | 30 | } else { |
19 | | - RE::FormID locID = 0; |
| 31 | + RE::TESForm* cellOrLoc = nullptr; |
20 | 32 | if (location) { |
21 | | - locID = location->GetFormID(); |
| 33 | + cellOrLoc = location; |
22 | 34 | } else if (cell) { |
23 | | - locID = cell->GetFormID(); |
| 35 | + cellOrLoc = cell; |
24 | 36 | } |
25 | 37 | // generate hash based on location + baseID |
26 | | - seed = hash::szudzik_pair(locID, baseID); |
| 38 | + std::uint64_t result = 0; |
| 39 | + boost::hash_combine(result, get_form_seed(cellOrLoc)); |
| 40 | + boost::hash_combine(result, get_form_seed(base)); |
| 41 | + seed = result; |
27 | 42 | } |
28 | 43 | } |
29 | 44 | break; |
|
0 commit comments