MCPcopy Create free account
hub / github.com/WolfireGames/overgrowth / Check

Method Check

Source/Objects/movementobject.cpp:4874–4931  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4872}
4873
4874float AttackHistory::Check(const std::string& str) {
4875 if (entries.empty()) {
4876 return 0.5f;
4877 }
4878 float cur_time = game_timer.game_time;
4879 AttackScriptGetter attack_script_getter;
4880 attack_script_getter.Load(str);
4881 AttackHeight attack_height;
4882 AttackDirection attack_direction;
4883 std::string name;
4884 GetAttackInfo(attack_script_getter, &attack_height, &attack_direction, &name);
4885
4886 const AttackHistoryEntry& entry = entries.back();
4887 const AttackScriptGetter& old_attack_script_getter = entry.attack_script_getter;
4888 AttackHeight old_attack_height;
4889 AttackDirection old_attack_direction;
4890 std::string old_name;
4891 GetAttackInfo(old_attack_script_getter, &old_attack_height, &old_attack_direction, &old_name);
4892
4893 float similarity = 0.5f;
4894 if (old_attack_height == attack_height) {
4895 similarity += 0.15f;
4896 } else if ((old_attack_height == _low && attack_height == _high) ||
4897 (old_attack_height == _high && attack_height == _low)) {
4898 similarity -= 0.15f;
4899 }
4900 if (old_attack_direction == attack_direction) {
4901 similarity += 0.15f;
4902 } else if ((old_attack_direction == _left && attack_direction == _right) ||
4903 (old_attack_direction == _right && attack_direction == _left)) {
4904 similarity -= 0.15f;
4905 }
4906 if (old_name == name) {
4907 similarity += 0.15f;
4908 } else {
4909 similarity -= 0.15f;
4910 }
4911
4912 unsigned long hash = djb2_string_hash(old_name.c_str());
4913 const InnerTransitionMap& itm = transitions[hash];
4914 InnerTransitionMap::const_iterator iter = itm.find(attack_script_getter.attack_ref());
4915 float transition_probability = 0.0f;
4916 if (entry.time > cur_time - kAttackTransitionTime) {
4917 float num = 0.0f;
4918 if (iter != itm.end()) {
4919 num = iter->second;
4920 }
4921 if (num != 0) {
4922 float total = 0;
4923 for (const auto& iter : itm) {
4924 total += iter.second;
4925 }
4926 transition_probability = num / total;
4927 }
4928 }
4929 similarity += (1.0f - similarity) * transition_probability;
4930 return similarity;
4931}

Callers 1

CheckAttackHistoryMethod · 0.45

Calls 8

GetAttackInfoFunction · 0.85
djb2_string_hashFunction · 0.85
emptyMethod · 0.45
LoadMethod · 0.45
backMethod · 0.45
c_strMethod · 0.45
findMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected