DayZ 1.30
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
AttachmentsOutOfReach.c
См. документацию.
2{
4
5 static bool IsAttachmentReachable(EntityAI e, string att_slot_name = "", int slot_id = -1, float range = 1.5)
6 {
7 if (!e.IgnoreOutOfReachCondition())
8 {
9 PlayerBase player = PlayerBase.Cast( g_Game.GetPlayer() );
10 if (player.IsInVehicle())
11 {
12 return false;
13 }
14 else
15 {
16 vector posAtt;
17 if (slot_id != -1)
18 {
19 att_slot_name = InventorySlots.GetSlotName(slot_id);
20 }
21 if (att_slot_name != "")
22 {
23 if (e.MemoryPointExists(att_slot_name))
24 {
25 vector mem_point = e.GetMemoryPointPos(att_slot_name);
26 posAtt = e.ModelToWorld(mem_point);
27 }
28 else
29 {
30 posAtt = e.ModelToWorld(GetAttachmentPosition(e, InventorySlots.GetSlotIdFromString(att_slot_name)));
31 }
32 }
33
34 vector posPlayer = player.GetPosition();
35 float heightDiff = posAtt[1] - posPlayer[1];
36 //float negativeTolerance = -range / 5; //TODO: maybe flat value?
37 float negativeTolerance = -1.0; //-1m tolerance to test with
38 if (heightDiff >= negativeTolerance && (Math.AbsFloat(heightDiff) < range)) //sort of 'dome' shaped detection with some negative leeway
39 {
40 posPlayer[1] = 0;
41 posAtt[1] = 0;
42 return vector.Distance(posPlayer, posAtt) <= range;
43 }
44
45 return false;
46 }
47 }
48 else
49 {
50 return true;
51 }
52 }
53
54 static vector GetAttachmentPosition(EntityAI e, int slot_id)
55 {
56 if (m_AttData == NULL)
57 {
59 }
60
61 string type_name = e.GetType();
62
63 if (!m_AttData.Contains(type_name))
64 {
66
67 m_AttData.Insert(type_name, att);
68 }
69
70 return m_AttData.Get(type_name).Get(slot_id);
71 }
72
74 {
75 map<int, vector> ret_val = new map<int, vector>();
76
77 string type_name = entity.GetType();
78 TStringArray cfg_attachments = new TStringArray;
79
80 string cfg_path;
81
82 if ( g_Game.ConfigIsExisting(CFG_VEHICLESPATH+" "+type_name) )
83 {
84 cfg_path = CFG_VEHICLESPATH+" "+type_name+" attachments";
85 }
86 else if ( g_Game.ConfigIsExisting(CFG_WEAPONSPATH+" "+type_name) )
87 {
88 cfg_path = CFG_WEAPONSPATH+" "+type_name+" attachments";
89 }
90 else if ( g_Game.ConfigIsExisting(CFG_MAGAZINESPATH+" "+type_name) )
91 {
92 cfg_path = CFG_MAGAZINESPATH+" "+type_name+" attachments";
93 }
94
95 g_Game.ConfigGetTextArray(cfg_path, cfg_attachments);
96
97 int child_count = g_Game.ConfigGetChildrenCount("CfgNonAIVehicles");
98
99 for (int x = 0; x < child_count; ++x)
100 {
101 string child_name;
102 g_Game.ConfigGetChildName("CfgNonAIVehicles",x , child_name);
103
104 string inventory_slot_name;
105 g_Game.ConfigGetText("CfgNonAIVehicles "+ child_name +" inventorySlot", inventory_slot_name);
106
107 if (cfg_attachments.Find(inventory_slot_name) > 0)
108 {
109 string model_path;
110 g_Game.ConfigGetText("CfgNonAIVehicles "+ child_name +" model", model_path);
111
112 if (model_path.Length() > 5)
113 {
114 LOD lod = entity.GetLODByName(LOD.NAME_VIEW);
115
116 if (lod)
117 {
118 model_path = model_path.Substring(0, model_path.Length() - 4);
119 model_path.ToLower();
120
121 array<Selection> selections = new array<Selection>();
122 lod.GetSelections(selections);
123
124 for (int i = 0; i < selections.Count(); ++i)
125 {
126 string selection = selections[i].GetName();
127 selection.ToLower();
128
129 if (selection.Contains(model_path))
130 {
131 ret_val.Set(InventorySlots.GetSlotIdFromString(inventory_slot_name), selections[i].GetVertexPosition(lod, 0));
132 }
133 }
134 }
135 }
136 }
137 }
138
139 return ret_val;
140 }
141}
DayZGame g_Game
Определения DayZGame.c:4074
Icon x
static ref map< string, ref map< int, vector > > m_AttData
Определения AttachmentsOutOfReach.c:3
static bool IsAttachmentReachable(EntityAI e, string att_slot_name="", int slot_id=-1, float range=1.5)
Определения AttachmentsOutOfReach.c:5
static vector GetAttachmentPosition(EntityAI e, int slot_id)
Определения AttachmentsOutOfReach.c:54
map< int, vector > CreateAttachmentPosition(EntityAI entity)
Определения AttachmentsOutOfReach.c:73
static proto native int GetSlotIdFromString(string slot_name)
converts string to slot_id
static proto native owned string GetSlotName(int id)
converts slot_id to string
provides access to slot configuration
Определения InventorySlots.c:6
static const string NAME_VIEW
Определения gameplay.c:207
proto native bool GetSelections(notnull out array< Selection > selections)
LOD class.
Определения gameplay.c:204
Определения EnMath.c:7
Определения PlayerBaseClient.c:2
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Определения Transport.c:70
static proto native float Distance(vector v1, vector v2)
Returns the distance between tips of two 3D vectors.
Определения EnConvert.c:119
class array< Class T > TStringArray
static proto float AbsFloat(float f)
Returns absolute value.
const string CFG_VEHICLESPATH
Определения 3_Game/DayZ/constants.c:228
const string CFG_WEAPONSPATH
Определения 3_Game/DayZ/constants.c:229
const string CFG_MAGAZINESPATH
Определения 3_Game/DayZ/constants.c:230
proto native int Length()
Returns length of string.
bool Contains(string sample)
Returns true if sample is substring of string.
Определения EnString.c:286
proto string Substring(int start, int len)
Substring of 'str' from 'start' position 'len' number of characters.
proto int ToLower()
Changes string to lowercase. Returns length.