Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
gpsreceiver.c
Go to the documentation of this file.
1 class GPSReceiver : ItemGPS
2 {
3 
4  const string DISPLAY_TEXTURE_PATH_FORMAT = "dz\\gear\\navigation\\data\\GPS_%1_ca.paa";
5  const string ANIM_PHASE_DISPLAY_HIDE = "DisplayState";
6 
7  protected ref set<string> m_DisplayGridSelections;
8  protected ref set<string> m_DisplayAltSelections;
9  protected ref map<int, string> m_DisplayNumericSignTextureMap;
10 
12  protected ref array<int> m_OrderedPositionNumbersLast;
13  protected ref array<int> m_AltitudeNumbersLast;
14 
15  void GPSReceiver()
16  {
17  m_OrderedPositionNumbersLast = new array<int>;
18  m_AltitudeNumbersLast = new array<int>;
19 
20  int i;
21  for (i = 0; i < MapNavigationBehaviour.DISPLAY_GRID_POS_MAX_CHARS_COUNT * 2; ++i)
22  {
23  m_OrderedPositionNumbersLast.Insert(0);
24  }
25 
26  for (i = 0; i < MapNavigationBehaviour.DISPLAY_ALT_MAX_CHARS_COUNT; ++i)
27  {
28  m_AltitudeNumbersLast.Insert(0);
29  }
30 
31  m_DisplayGridSelections = new set<string>();
32  m_DisplayGridSelections.Insert("grid_1_0");
33  m_DisplayGridSelections.Insert("grid_1_1");
34  m_DisplayGridSelections.Insert("grid_1_2");
35  m_DisplayGridSelections.Insert("grid_2_0");
36  m_DisplayGridSelections.Insert("grid_2_1");
37  m_DisplayGridSelections.Insert("grid_2_2");
38 
39  m_DisplayAltSelections = new set<string>();
40  m_DisplayAltSelections.Insert("alt_0");
41  m_DisplayAltSelections.Insert("alt_1");
42  m_DisplayAltSelections.Insert("alt_2");
43  m_DisplayAltSelections.Insert("alt_3");
44 
45  m_DisplayNumericSignTextureMap = new map<int, string>();
46  for (i = -1; i < 11; i++)
47  {
48 
49  string texturePath = string.Format(DISPLAY_TEXTURE_PATH_FORMAT, i);
50 
52  if (i == -1)
53  {
54  texturePath = string.Format(DISPLAY_TEXTURE_PATH_FORMAT, "dash");
55  }
56 
57  m_DisplayNumericSignTextureMap.Insert(i, texturePath);
58  }
59  }
60 
61  protected void PositionalUpdate()
62  {
63  UpdateDisplayPosition();
64  UpdateDisplayElevation();
65  }
66 
68  override void OnMovedInsideCargo(EntityAI container);
69 
70  override void SetActions()
71  {
72  super.SetActions();
73 
76  }
77 
78  override bool IsTurnedOn()
79  {
80  return GetCompEM() && GetCompEM().IsWorking();
81  }
82 
83  //------------------------------------------------------------------------------
84  override void OnWorkStart()
85  {
86  UpdateDisplayState(true);
87 
88  if (GetHierarchyRoot())
89  {
90  PlayerBase pb = PlayerBase.Cast(GetHierarchyRoot());
91  if (pb)
92  {
93  pb.MapNavigationItemInPossession(this);
94  }
95  }
96  }
97 
98  override void OnWorkStop()
99  {
100  UpdateDisplayState(false);
101 
102  if (GetHierarchyRoot())
103  {
104  PlayerBase pb = PlayerBase.Cast(GetHierarchyRoot());
105  if (pb)
106  {
107  pb.MapNavigationItemNotInPossession(this);
108  }
109  }
110  }
111 
112  override void OnWork(float consumed_energy)
113  {
114  PositionalUpdate();
115  }
116  //------------------------------------------------------------------------------
117 
118  protected void UpdateDisplayState(bool pIsTurnedOn)
119  {
120  SetAnimationPhaseNow(ANIM_PHASE_DISPLAY_HIDE, !pIsTurnedOn);
121  }
122 
123  protected void UpdateDisplayPosition()
124  {
125  int selectionIndex;
126  string selectionName;
127  array<int> orderedPositionNumbers = MapNavigationBehaviour.OrderedPositionNumbersFromGridCoords(this);
128 
129  if (orderedPositionNumbers.DifferentAtPosition(m_OrderedPositionNumbersLast) != INDEX_NOT_FOUND)
130  {
131  for (int i = 0; i < m_DisplayGridSelections.Count(); ++i)
132  {
133  selectionName = m_DisplayGridSelections.Get(i);
134  selectionIndex = GetHiddenSelection(selectionName);
135  SetObjectTexture(selectionIndex, m_DisplayNumericSignTextureMap.Get(orderedPositionNumbers.Get(i)));
136  }
137 
138  m_OrderedPositionNumbersLast = orderedPositionNumbers;
139  }
140  }
141 
142  protected void UpdateDisplayElevation()
143  {
144  int selectionIndex;
145  string selectionName;
146  array<int> altitudeNumbers = MapNavigationBehaviour.OrderedAltitudeNumbersPosition(this);
147 
148  if (altitudeNumbers.DifferentAtPosition(m_AltitudeNumbersLast) != INDEX_NOT_FOUND)
149  {
150  for (int i = 0; i < m_DisplayAltSelections.Count(); ++i)
151  {
152  selectionName = m_DisplayAltSelections.Get(i);
153  selectionIndex = GetHiddenSelection(selectionName);
154  SetObjectTexture(selectionIndex, m_DisplayNumericSignTextureMap.Get(altitudeNumbers.Get(i)));
155  }
156 
157  m_AltitudeNumbersLast = altitudeNumbers;
158  }
159  }
160 
161  protected int GetHiddenSelection(string selection)
162  {
163  int idx = GetHiddenSelectionIndex(selection);
164 
165  if (idx != INDEX_NOT_FOUND)
166  {
167  return idx;
168  }
169  else
170  {
171  return 0;
172  }
173  }
174 
175  //================================================================
176  // DEBUG
177  //================================================================
178 
179  override void OnDebugSpawn()
180  {
181  Battery9V.Cast(GetInventory().CreateInInventory("Battery9V"));
182  }
183 }
INDEX_NOT_FOUND
const int INDEX_NOT_FOUND
Definition: gameplay.c:13
ActionTurnOnWhileInHands
Definition: actionturnonwhileinhands.c:1
Battery9V
Definition: battery9v.c:1
MapNavigationBehaviour
void MapNavigationBehaviour(PlayerBase pPlayer, EMapNavigationType pNavigationType=EMapNavigationType.BASIC)
Definition: mapnavigationbehaviour.c:27
PlayerBase
Definition: playerbaseclient.c:1
map
map
Definition: controlsxboxnew.c:3
AddAction
void AddAction(typename actionName)
Definition: advancedcommunication.c:86
ActionTurnOffWhileInHands
Definition: actionturnoffwhileinhands.c:1
array
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Definition: isboxcollidinggeometryproxyclasses.c:27
GPSReceiver
Definition: gpsreceiver.c:1
EntityAI
Definition: building.c:5