Dayz
Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
Toggle main menu visibility
Loading...
Searching...
No Matches
mapnavigationbehaviour.c
Go to the documentation of this file.
1
enum
EMapNavigationType
2
{
3
BASIC
= 0,
4
COMPASS
= 1,
5
GPS
= 2,
6
ALL
= 4
7
}
8
9
class
MapNavigationBehaviour
10
{
11
const
int
RANDOM_DEVIATION_MIN
= 4;
12
const
int
RANDOM_DEVIATION_MAX
= 15;
13
14
static
const
int
DISPLAY_GRID_POS_MAX_CHARS_COUNT
= 3;
15
static
const
int
DISPLAY_ALT_MAX_CHARS_COUNT
= 4;
16
17
protected
static
const
string
GRID_SIZE_CFG_PATH
=
"CfgWorlds %1 Grid Zoom1 stepX"
;
18
19
protected
int
m_RandomPositionDeviationX
;
20
protected
int
m_RandomPositionDeviationZ
;
21
protected
EMapNavigationType
m_NavigationType
;
22
protected
PlayerBase
m_Player
;
23
24
protected
ref
array<EntityAI>
m_GPSInPossessionArr
;
25
protected
ref
array<EntityAI>
m_CompassInPossessionArr
;
26
27
void
MapNavigationBehaviour
(
PlayerBase
pPlayer,
EMapNavigationType
pNavigationType =
EMapNavigationType
.BASIC)
28
{
29
m_Player
= pPlayer;
30
m_NavigationType
= pNavigationType;
31
32
m_GPSInPossessionArr
=
new
array<EntityAI>
();
33
m_CompassInPossessionArr
=
new
array<EntityAI>
();
34
}
35
36
protected
void
SetNavigationType
(
EMapNavigationType
pType)
37
{
38
m_NavigationType
=
m_NavigationType
| pType;
39
}
40
41
protected
void
UnsetNavigationType
(
EMapNavigationType
pType)
42
{
43
m_NavigationType
=
m_NavigationType
& ~pType;
44
}
45
46
EMapNavigationType
GetNavigationType
()
47
{
48
return
m_NavigationType
;
49
}
50
51
void
OnItemInPlayerPossession
(
EntityAI
item)
52
{
53
if
(item.IsInherited(ItemGPS))
54
{
55
if
(
m_GPSInPossessionArr
.Find(item) ==
INDEX_NOT_FOUND
)
56
{
57
m_GPSInPossessionArr
.Insert(item);
58
SetNavigationType
(
EMapNavigationType
.GPS);
59
}
60
}
61
62
if
(item.IsInherited(ItemCompass))
63
{
64
if
(
m_CompassInPossessionArr
.Find(item) ==
INDEX_NOT_FOUND
)
65
{
66
m_CompassInPossessionArr
.Insert(item);
67
SetNavigationType
(
EMapNavigationType
.COMPASS);
68
}
69
}
70
}
71
72
void
OnItemNotInPlayerPossession
(
EntityAI
item)
73
{
74
if
(item.IsInherited(ItemGPS))
75
{
76
m_GPSInPossessionArr
.RemoveItem(item);
77
if
(
m_GPSInPossessionArr
.Count() == 0)
78
{
79
UnsetNavigationType
(
EMapNavigationType
.GPS);
80
}
81
}
82
83
if
(item.IsInherited(ItemCompass))
84
{
85
m_CompassInPossessionArr
.RemoveItem(item);
86
if
(
m_CompassInPossessionArr
.Count() == 0)
87
{
88
UnsetNavigationType
(
EMapNavigationType
.COMPASS);
89
}
90
}
91
}
92
93
void
RandomizePosition
()
94
{
95
m_RandomPositionDeviationX
=
RandomizedDeviation
();
96
m_RandomPositionDeviationZ
=
RandomizedDeviation
();
97
}
98
99
protected
float
RandomizedDeviation
()
100
{
101
Math
.
Randomize
(
GetWorldTime
() +
Math
.
RandomIntInclusive
(2, 4096));
102
if
((
Math
.
RandomIntInclusive
(0, 10) % 2) == 0)
103
{
104
return
Math
.
RandomIntInclusive
(-
RANDOM_DEVIATION_MAX
, -
RANDOM_DEVIATION_MIN
);
105
}
106
else
107
{
108
return
Math
.
RandomIntInclusive
(
RANDOM_DEVIATION_MIN
,
RANDOM_DEVIATION_MAX
);
109
}
110
}
111
112
vector
GetPositionRandomized
()
113
{
114
vector
realPosition =
m_Player
.GetPosition();
115
vector
randomizedPosition =
Vector
(realPosition[0] +
m_RandomPositionDeviationX
, realPosition[1], realPosition[2] +
m_RandomPositionDeviationZ
);
116
117
return
randomizedPosition;
118
}
119
120
vector
GetPositionReal
()
121
{
122
return
m_Player
.GetPosition();
123
}
124
125
static
array<int>
OrderedPositionNumbersFromGridCoords
(
EntityAI
pEntity)
126
{
127
float
gridSize =
g_Game
.ConfigGetFloat(
string
.Format(
GRID_SIZE_CFG_PATH
,
g_Game
.GetWorldName()));
128
int
gridX, gridZ;
129
g_Game
.GetWorld().GetGridCoords(pEntity.GetPosition(), gridSize, gridX, gridZ);
130
131
gridX =
Math
.
AbsInt
(gridX);
132
gridZ =
Math
.
AbsInt
(gridZ);
133
134
array<int>
positions =
new
array<int>
();
135
string
gridXStr = gridX.ToStringLen(
DISPLAY_GRID_POS_MAX_CHARS_COUNT
);
136
string
gridZStr = gridZ.ToStringLen(
DISPLAY_GRID_POS_MAX_CHARS_COUNT
);
137
138
int
i = 0;
139
int
gridCoordNumber;
140
for
(i = 0; i < gridXStr.
Length
(); ++i)
141
{
142
gridCoordNumber = gridXStr.
Get
(i).
ToInt
();
143
if
(
IsOutOfMap
(pEntity))
144
{
145
gridCoordNumber = -1;
146
}
147
148
positions.Insert(gridCoordNumber);
149
}
150
151
for
(i = 0; i < gridZStr.
Length
(); ++i)
152
{
153
gridCoordNumber = gridZStr.
Get
(i).
ToInt
();
154
if
(
IsOutOfMap
(pEntity))
155
{
156
gridCoordNumber = -1;
157
}
158
159
positions.Insert(gridCoordNumber);
160
}
161
162
return
positions;
163
}
164
165
static
array<int>
OrderedAltitudeNumbersPosition
(
EntityAI
pEntity)
166
{
167
array<int>
altArray =
new
array<int>
();
168
float
altF = pEntity.GetPosition()[1];
169
int
altI =
Math
.
Round
(altF);
170
string
altString = altI.ToStringLen(
DISPLAY_ALT_MAX_CHARS_COUNT
);
171
172
for
(
int
i = 0; i < altString.
Length
(); ++i)
173
{
174
altArray.Insert(altString.
Get
(i).
ToInt
());
175
}
176
177
return
altArray;
178
}
179
180
static
bool
IsOutOfMap
(
EntityAI
pEntity)
181
{
182
vector
worldPos = pEntity.GetPosition();
183
184
if
(worldPos[0] < 0 || worldPos[0] >
g_Game
.GetWorld().GetWorldSize() || worldPos[2] < 0 || worldPos[2] >
g_Game
.GetWorld().GetWorldSize())
185
{
186
return
true
;
187
}
188
189
return
false
;
190
}
191
}
m_Player
map m_Player
EntityAI
Definition
inventoryitem.c:2
Math
Definition
enmath.c:7
PlayerBase
Definition
playerbaseclient.c:2
array
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Definition
isboxcollidinggeometryproxyclasses.c:28
vector
Definition
enconvert.c:119
g_Game
DayZGame g_Game
Definition
dayzgame.c:3942
INDEX_NOT_FOUND
const int INDEX_NOT_FOUND
Definition
gameplay.c:13
ALL
@ ALL
Mask of all events.
Definition
enentity.c:110
Vector
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
Math::Randomize
static proto int Randomize(int seed)
Sets the seed for the random number generator.
Math::Round
static proto float Round(float f)
Returns mathematical round of value.
Math::RandomIntInclusive
static int RandomIntInclusive(int min, int max)
Returns a random int number between and min [inclusive] and max [inclusive].
Definition
enmath.c:54
Math::AbsInt
static proto int AbsInt(int i)
Returns absolute value.
string::ToInt
proto native int ToInt()
Converts string to integer.
string::Get
proto string Get(int index)
Gets n-th character from string.
string::Length
proto native int Length()
Returns length of string.
GetWorldTime
proto native float GetWorldTime()
GetPositionRandomized
vector GetPositionRandomized()
Definition
mapnavigationbehaviour.c:112
m_NavigationType
EMapNavigationType m_NavigationType
Definition
mapnavigationbehaviour.c:21
m_RandomPositionDeviationZ
int m_RandomPositionDeviationZ
Definition
mapnavigationbehaviour.c:20
OnItemNotInPlayerPossession
void OnItemNotInPlayerPossession(EntityAI item)
Definition
mapnavigationbehaviour.c:72
GRID_SIZE_CFG_PATH
static const string GRID_SIZE_CFG_PATH
Definition
mapnavigationbehaviour.c:17
SetNavigationType
void SetNavigationType(EMapNavigationType pType)
Definition
mapnavigationbehaviour.c:36
m_RandomPositionDeviationX
int m_RandomPositionDeviationX
Definition
mapnavigationbehaviour.c:19
RandomizedDeviation
float RandomizedDeviation()
Definition
mapnavigationbehaviour.c:99
OrderedPositionNumbersFromGridCoords
static array< int > OrderedPositionNumbersFromGridCoords(EntityAI pEntity)
Definition
mapnavigationbehaviour.c:125
RandomizePosition
void RandomizePosition()
Definition
mapnavigationbehaviour.c:93
EMapNavigationType
EMapNavigationType
Definition
mapnavigationbehaviour.c:2
BASIC
@ BASIC
Definition
mapnavigationbehaviour.c:3
GPS
@ GPS
Definition
mapnavigationbehaviour.c:5
COMPASS
@ COMPASS
Definition
mapnavigationbehaviour.c:4
UnsetNavigationType
void UnsetNavigationType(EMapNavigationType pType)
Definition
mapnavigationbehaviour.c:41
IsOutOfMap
static bool IsOutOfMap(EntityAI pEntity)
Definition
mapnavigationbehaviour.c:180
OrderedAltitudeNumbersPosition
static array< int > OrderedAltitudeNumbersPosition(EntityAI pEntity)
Definition
mapnavigationbehaviour.c:165
OnItemInPlayerPossession
void OnItemInPlayerPossession(EntityAI item)
Definition
mapnavigationbehaviour.c:51
m_GPSInPossessionArr
ref array< EntityAI > m_GPSInPossessionArr
Definition
mapnavigationbehaviour.c:24
GetPositionReal
vector GetPositionReal()
Definition
mapnavigationbehaviour.c:120
MapNavigationBehaviour
void MapNavigationBehaviour(PlayerBase pPlayer, EMapNavigationType pNavigationType=EMapNavigationType.BASIC)
Definition
mapnavigationbehaviour.c:27
DISPLAY_GRID_POS_MAX_CHARS_COUNT
static const int DISPLAY_GRID_POS_MAX_CHARS_COUNT
Definition
mapnavigationbehaviour.c:14
RANDOM_DEVIATION_MIN
enum EMapNavigationType RANDOM_DEVIATION_MIN
DISPLAY_ALT_MAX_CHARS_COUNT
static const int DISPLAY_ALT_MAX_CHARS_COUNT
Definition
mapnavigationbehaviour.c:15
RANDOM_DEVIATION_MAX
const int RANDOM_DEVIATION_MAX
Definition
mapnavigationbehaviour.c:12
GetNavigationType
EMapNavigationType GetNavigationType()
Definition
mapnavigationbehaviour.c:46
m_CompassInPossessionArr
ref array< EntityAI > m_CompassInPossessionArr
Definition
mapnavigationbehaviour.c:25
Games
Dayz
scripts
4_world
entities
itembase
mapnavigationbehaviour.c
Generated by
1.17.0