11#include " Creature.h"
2+ #include < math.h>
3+ #include < locale>
4+ #include < codecvt>
5+ #include < string>
6+
7+ #include " ../msvc_bincompat.h"
8+ #include " ../cube_funcs.h"
29
310namespace cube {
11+ std::wstring Creature::GetName ()
12+ {
13+ auto len = strnlen_s (this ->name , 16 );
14+ if (len == 0 )
15+ {
16+
17+ MSVCBinCompat::wstring compat;
18+ if (this ->hostility_flags == 3 || this ->movement_flags & 0x200 )
19+ {
20+ // "Rare" creature names
21+ cube_funcs::instance ()->generate_rare_creature_name (&compat, (uint32_t )this ->GUID , this ->race );
22+ return compat;
23+ }
24+ else
25+ {
26+ // "Normal" creature names.
27+
28+ // This is AWFUL for performance because it copies out the entire map. please fix me when I implement search in MSVCBinCompat::map.
29+ auto gc = cube::GetGameController ();
30+ auto entity_localization_map = gc->world .EntityNames ->CopyToSTDMap ();
31+ auto localization_key = entity_localization_map.find (this ->race );
32+ if (localization_key == entity_localization_map.end ())
33+ {
34+ return compat;
35+ }
36+ else
37+ {
38+ MSVCBinCompat::wstring out;
39+ MSVCBinCompat::wstring key = localization_key->second ;
40+ MSVCBinCompat::wstring word_form = L" singular" ;
41+
42+ cube_funcs::instance ()->speech_get_localization_from_dict (&gc->world .speech , &out, &key, word_form);
43+
44+ return out;
45+ }
46+ }
47+ }
48+ else
49+ {
50+ std::wstring_convert<std::codecvt_utf8_utf16<wchar_t >> converter;
51+ std::wstring wide = converter.from_bytes (this ->name );
52+ return wide;
53+ }
54+ }
55+
56+ double Creature::DistanceFrom (Vector3<int64_t > point) {
57+ auto p1 = this ->position ;
58+ auto p2 = point;
59+
60+ auto x = p1.X - p2.X ;
61+ auto y = p1.Y - p2.Y ;
62+ auto z = p1.Z - p2.Z ;
63+
64+ return sqrt ((x*x) + (y*y) + (z*z));
65+ }
66+ double Creature::DistanceFrom (Creature* target) {
67+ return DistanceFrom (target->position );
68+ }
469};
0 commit comments