Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
attachmentsoutofreach.c
Go to the documentation of this file.
2 {
3  protected static ref map<string, ref map<int, vector>> m_AttData;
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( GetGame().GetPlayer() );
10  if( player.IsInVehicle() )
11  {
12  return false;
13  }
14  else
15  {
16 
17  vector pos_att;
18  if ( slot_id != -1 )
19  {
20  att_slot_name = InventorySlots.GetSlotName(slot_id);
21  }
22  if( att_slot_name != "" )
23  {
24  if( e.MemoryPointExists(att_slot_name) )
25  {
26  vector mem_point = e.GetMemoryPointPos(att_slot_name);
27  pos_att = e.ModelToWorld(mem_point);
28  }
29  else
30  {
31  pos_att = e.ModelToWorld(GetAttachmentPosition(e, InventorySlots.GetSlotIdFromString( att_slot_name ) ));
32  }
33 
34  }
35 
36  vector pos_player = player.GetPosition();
37 
38  float height_diff = Math.AbsFloat( pos_player[1] - pos_att[1] );
39  if( height_diff < range )
40  {
41  pos_player[1] = 0;
42  pos_att[1] = 0;
43  if ( vector.Distance(pos_player, pos_att) <= range )
44  {
45  return true;
46  }
47  return false;
48  }
49  else
50  {
51  return false;
52  }
53  }
54  }
55  else
56  {
57  return true;
58  }
59  }
60 
61  static vector GetAttachmentPosition(EntityAI e, int slot_id)
62  {
63  if ( m_AttData == NULL )
64  {
65  m_AttData = new map<string, ref map<int, vector>>();
66  }
67 
68  string type_name = e.GetType();
69 
70  if ( !m_AttData.Contains( type_name ) )
71  {
72  map<int, vector> att = CreateAttachmentPosition( e );
73 
74  m_AttData.Insert( type_name, att );
75  }
76 
77  return m_AttData.Get( type_name ).Get( slot_id );
78  }
79 
80  static protected map<int, vector> CreateAttachmentPosition( EntityAI entity )
81  {
82  map<int, vector> ret_val = new map<int, vector>();
83 
84  string type_name = entity.GetType();
85  TStringArray cfg_attachments = new TStringArray;
86 
87  string cfg_path;
88 
89  if ( GetGame().ConfigIsExisting(CFG_VEHICLESPATH+" "+type_name) )
90  {
91  cfg_path = CFG_VEHICLESPATH+" "+type_name+" attachments";
92  }
93  else if ( GetGame().ConfigIsExisting(CFG_WEAPONSPATH+" "+type_name) )
94  {
95  cfg_path = CFG_WEAPONSPATH+" "+type_name+" attachments";
96  }
97  else if ( GetGame().ConfigIsExisting(CFG_MAGAZINESPATH+" "+type_name) )
98  {
99  cfg_path = CFG_MAGAZINESPATH+" "+type_name+" attachments";
100  }
101 
102  GetGame().ConfigGetTextArray(cfg_path, cfg_attachments);
103 
104  int child_count = GetGame().ConfigGetChildrenCount("CfgNonAIVehicles");
105 
106  for ( int x = 0; x < child_count; ++x )
107  {
108  string child_name;
109  GetGame().ConfigGetChildName("CfgNonAIVehicles",x , child_name);
110 
111  string inventory_slot_name;
112  GetGame().ConfigGetText("CfgNonAIVehicles "+ child_name +" inventorySlot", inventory_slot_name);
113 
114  if ( cfg_attachments.Find( inventory_slot_name ) > 0 )
115  {
116  string model_path;
117  GetGame().ConfigGetText("CfgNonAIVehicles "+ child_name +" model", model_path);
118 
119  if ( model_path.Length() > 5 )
120  {
121  LOD lod = entity.GetLODByName(LOD.NAME_VIEW);
122 
123  if ( lod )
124  {
125  model_path = model_path.Substring(0, model_path.Length() - 4);
126  model_path.ToLower();
127 
128  array<Selection> selections = new array<Selection>();
129  lod.GetSelections(selections);
130 
131  for ( int i = 0; i < selections.Count(); ++i )
132  {
133  string selection = selections[i].GetName();
134  selection.ToLower();
135 
136  if ( selection.Contains(model_path) )
137  {
138  ret_val.Set(InventorySlots.GetSlotIdFromString( inventory_slot_name ), selections[i].GetVertexPosition(lod, 0));
139  }
140  }
141  }
142  }
143  }
144  }
145 
146  return ret_val;
147  }
148 }
GetGame
proto native CGame GetGame()
InventorySlots
provides access to slot configuration
Definition: inventoryslots.c:5
TStringArray
array< string > TStringArray
Definition: enscript.c:685
AttachmentsOutOfReach
Definition: attachmentsoutofreach.c:1
LOD
LOD class.
Definition: gameplay.c:202
PlayerBase
Definition: playerbaseclient.c:1
map
map
Definition: controlsxboxnew.c:3
vector
Definition: enconvert.c:105
CFG_VEHICLESPATH
const string CFG_VEHICLESPATH
Definition: constants.c:209
CFG_MAGAZINESPATH
const string CFG_MAGAZINESPATH
Definition: constants.c:211
CFG_WEAPONSPATH
const string CFG_WEAPONSPATH
Definition: constants.c:210
array< string >
x
Icon x
GetPlayer
protected void GetPlayer()
Definition: crosshairselector.c:127
Math
Definition: enmath.c:6
EntityAI
Definition: building.c:5