Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
arrowmanagerplayer.c
Go to the documentation of this file.
2 {
3  private static ref map<int,typename> m_TypeHashTable;
4 
5  void ArrowManagerPlayer(PlayerBase player)
6  {
7  if (!m_TypeHashTable)
8  {
9  InitializeHash();
10  }
11  }
12 
13  private static void InitializeHash()
14  {
15  m_TypeHashTable = new map<int,typename>();
16 
17  AddArrowTypeToHash("Ammo_HuntingBolt");
18  AddArrowTypeToHash("Ammo_ImprovisedBolt_1");
19  AddArrowTypeToHash("Ammo_ImprovisedBolt_2");
20  AddArrowTypeToHash("Ammo_ImprovisedBolt_3");
21  }
22 
23  private static void AddArrowTypeToHash(string ArrowType)
24  {
25  m_TypeHashTable.Insert(ArrowType.Hash(), ArrowType.ToType());
26  }
27 
28  private static typename GetArrowTypeFromHash(int hash)
29  {
30  return m_TypeHashTable.Get(hash);
31  }
32 
33  bool Save(ParamsWriteContext ctx)
34  {
35  ctx.Write(VERSION);
36  int count = m_Arrows.Count();
37  int i;
38  //TODO MW Delete after find why sometimes arrow missing - most likely Life span
39  for (i = count - 1; i >= 0; i--)
40  {
41  if (!m_Arrows.Get(i))
42  {
43  m_Arrows.Remove(i);
44  }
45  }
46  count = m_Arrows.Count();
47 
48  ctx.Write(count);
49 
50  for (i = 0; i < count; i++)
51  {
52  EntityAI arrow = m_Arrows.Get(i);
53 
54  string type = arrow.GetType();
55  ctx.Write(type.Hash());
56 
57  vector angle = arrow.GetLocalYawPitchRoll();
58  vector pos = arrow.GetLocalPosition();
59 
60  ctx.Write(angle[0]);
61  ctx.Write(angle[1]);
62  ctx.Write(angle[2]);
63  ctx.Write(pos[0]);
64  ctx.Write(pos[1]);
65  ctx.Write(pos[2]);
66 
67  int pivot = arrow.GetHierarchyPivot();
68  ctx.Write(pivot);
69  }
70 
71  return true;
72  }
73 
74 
75  bool Load(ParamsReadContext ctx)
76  {
77  int version;
78  if (!ctx.Read(version))
79  {
80  return false;
81  }
82 
83  int count;
84  if (!ctx.Read(count))
85  {
86  return false;
87  }
88 
89  for (int i = 0; i < count; i++)
90  {
91 
92  if (version >= 1)
93  {
94  int hash;
95  if (!ctx.Read(hash))
96  {
97  return false;
98  }
99 
100  float angleF[3];
101  float posF[3];
102  float value;
103 
104  if (!ctx.Read(value))
105  {
106  return false;
107  }
108  angleF[0] = value;
109 
110  if (!ctx.Read(value))
111  {
112  return false;
113  }
114  angleF[1] = value;
115 
116  if (!ctx.Read(value))
117  {
118  return false;
119  }
120  angleF[2] = value;
121 
122  if (!ctx.Read(value))
123  {
124  return false;
125  }
126  posF[0] = value;
127 
128  if (!ctx.Read(value))
129  {
130  return false;
131  }
132  posF[1] = value;
133 
134  if (!ctx.Read(value))
135  {
136  return false;
137  }
138  posF[2] = value;
139 
140  vector angle = "0 0 0";
141  vector pos = "0 0 0";
142 
143  angle = vector.ArrayToVec(angleF);
144  pos = vector.ArrayToVec(posF);
145 
146  int pivot;
147  if (!ctx.Read(pivot))
148  {
149  return false;
150  }
151 
152  if (version >= 2)
153  {
154  #ifdef SERVER
155  int spawnFlags = ECE_KEEPHEIGHT|ECE_DYNAMIC_PERSISTENCY;
156  #else
158  #endif
159 
160  typename arrowType = GetArrowTypeFromHash(hash);
161  EntityAI arrow = EntityAI.Cast(GetGame().CreateObjectEx(arrowType.ToString(), pos, spawnFlags));
162  if (arrow)
163  {
164  arrow.SetQuantityToMinimum();
165  arrow.SetYawPitchRoll(angle);
166  m_Owner.AddChild(arrow, pivot);
167  }
168  }
169  }
170 
171  }
172 
173  return true;
174  }
175 }
GetGame
proto native CGame GetGame()
ECE_KEEPHEIGHT
const int ECE_KEEPHEIGHT
Definition: centraleconomy.c:27
Serializer
Serialization general interface. Serializer API works with:
Definition: serializer.c:55
PlayerBase
Definition: playerbaseclient.c:1
map
map
Definition: controlsxboxnew.c:3
vector
Definition: enconvert.c:105
ArrowManagerPlayer
Definition: arrowmanagerplayer.c:1
m_Owner
enum ProcessDirectDamageFlags m_Owner
ECE_DYNAMIC_PERSISTENCY
const int ECE_DYNAMIC_PERSISTENCY
Definition: centraleconomy.c:32
ECE_LOCAL
const int ECE_LOCAL
Definition: centraleconomy.c:24
ArrowManagerBase
Definition: arrowmanagerbase.c:1
EntityAI
Definition: building.c:5