DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
EnConvert.c
Go to the documentation of this file.
1class bool
2{
3 string ToString()
4 {
5 if (value) return "true";
6 else return "false";
7 }
8};
9
10class func
11{
13 private proto void SetInstance(Class inst);
14};
15
17{
18 NO = 0,
19 YES = 1
21
22class int
23{
24 protected const int ZERO_PAD_SIZE = 8;
25 protected static string m_ZeroPad[ZERO_PAD_SIZE] = {"", "0", "00", "000", "0000", "00000", "000000", "0000000"};
26
27 const int MAX = 2147483647;
28 const int MIN = -2147483648;
29
30 proto string ToString();
31
44 proto string AsciiToString();
45
59 string ToStringLen(int len)
60 {
61 string str = value.ToString();
62
63 int l = len - str.Length();
64
65 if (l > 0 && l < ZERO_PAD_SIZE )
66 return m_ZeroPad[l] + str;
67
68 return str;
69 }
70
84 bool InRange( int min, int max, bool inclusive_min = true, bool inclusive_max = true )
85 {
86 if( ( !inclusive_min && value <= min ) || value < min )
87 return false;
88
89 if( ( !inclusive_max && value >= max ) || value > max )
90 return false;
91
92 return true;
93 }
94};
95
96class float
97{
98 const float MIN = FLT_MIN;
99 const float MAX = FLT_MAX;
100 const float LOWEST = -FLT_MAX;
101
102 proto string ToString();
103};
104
106{
107 static const vector Up = "0 1 0";
108 static const vector Aside = "1 0 0";
109 static const vector Forward = "0 0 1";
110 static const vector Zero = "0 0 0";
111
125 proto string ToString(bool beautify = true);
126
140 proto float Normalize();
141
144
156 proto native float Length();
157
169 proto native float LengthSq();
170
183 proto static native float Distance(vector v1, vector v2);
184
197 proto static native float DistanceSq(vector v1, vector v2);
198
210 {
211 return value * vector.Up;
212 }
213
221 {
222 vector dir_vec;
223
224 dir_vec[0] = p2[0] - p1[0];
225 dir_vec[1] = p2[1] - p1[1];
226 dir_vec[2] = p2[2] - p1[2];
227
228 return dir_vec;
229 }
230
244 {
246 }
247
261 {
263 }
264
271 static float Dot(vector v1, vector v2)
272 {
273 return ((v1[0] * v2[0]) + (v1[1] * v2[1]) + (v1[2] * v2[2]));
274 }
275
287 {
288 for(int i = 0; i < 3; i++) {
289 if(value[i] > 180)
290 value[i] = value[i] - 360;
291 if(value[i] < -180)
292 value[i] = value[i] + 360;
293 }
294 return value;
295 }
296
311 proto float VectorToYaw();
312
325 proto native static vector YawToVector(float yaw);
326
341
356
370 proto void RotationMatrixFromAngles(out vector mat[3]);
371
385 proto vector Multiply4(vector mat[4]);
386
400 proto vector Multiply3(vector mat[3]);
401
416
431
440 proto static native vector Lerp(vector v1, vector v2, float t);
441
450 static vector RotateAroundZeroDeg(vector vec, vector axis, float angle)
451 {
452 return (vec * Math.Cos(angle * Math.DEG2RAD)) + ((axis * vec) * Math.Sin(angle * Math.DEG2RAD)) + (axis * vector.Dot(axis, vec)) * (1 - Math.Cos(angle * Math.DEG2RAD));
453 }
454
463 static vector RotateAroundZeroRad(vector vec, vector axis, float angle)
464 {
465 return (vec * Math.Cos(angle)) + ((axis * vec) * Math.Sin(angle)) + (axis * vector.Dot(axis, vec)) * (1 - Math.Cos(angle));
466 }
467
477 static vector RotateAroundZero(vector pos, vector axis, float cosAngle, float sinAngle)
478 {
479 return (pos * cosAngle) + ((axis * pos) * sinAngle) + (axis * vector.Dot(axis, pos)) * (1 - cosAngle);
480 }
481
491 static vector RotateAroundPoint(vector point, vector pos, vector axis, float cosAngle, float sinAngle)
492 {
493 vector offsetPos = pos - point;
494 return RotateAroundZero(offsetPos, axis, cosAngle, sinAngle) + point;
495 }
496
502 static vector ArrayToVec(float arr[])
503 {
504 return Vector(arr[0], arr[1], arr[2]);
505 }
506};
507
509{
517 proto volatile Class Spawn();
518
523 proto owned string GetModule();
524
526 proto native owned string ToString();
527
536 proto native bool IsInherited(typename baseType);
537
538 proto native int GetVariableCount();
539 proto native owned string GetVariableName(int vIdx);
540 proto native typename GetVariableType(int vIdx);
541 proto bool GetVariableValue(Class var, int vIdx, out void val);
542
550 static string EnumToString(typename e, int enumValue)
551 {
552 int cnt = e.GetVariableCount();
553 int val;
554
555 for (int i = 0; i < cnt; i++)
556 {
557 if (e.GetVariableType(i) == int && e.GetVariableValue(null, i, val) && val == enumValue)
558 {
559 return e.GetVariableName(i);
560 }
561 }
562
563 return "unknown";
564 }
565
572 static int StringToEnum(typename e, string enumName)
573 {
574 int count = e.GetVariableCount();
575 int value;
576
577 for (int i = 0; i < count; i++)
578 {
579 if (e.GetVariableType(i) == int && e.GetVariableValue(null, i, value) && e.GetVariableName(i) == enumName)
580 {
581 return value;
582 }
583 }
584
585 return -1;
586 }
587};
588
590{
591 private void EnumTools();
592 private void ~EnumTools();
593
601 static string EnumToString(typename e, int enumValue)
602 {
603 return typename.EnumToString(e, enumValue);
604 }
605
612 static int StringToEnum(typename e, string enumName)
613 {
614 return typename.StringToEnum(e, enumName);
615 }
616
623 static int GetEnumSize(typename e)
624 {
625 return e.GetVariableCount();
626 }
627
634 static int GetEnumValue(typename e, int idx)
635 {
636 int value;
637 e.GetVariableValue(null, idx, value);
638 return value;
639 }
640
647 static int GetLastEnumValue(typename e)
648 {
649 int lastValue;
650 e.GetVariableValue(null, e.GetVariableCount() - 1, lastValue);
651 return lastValue;
652 }
653}
class RecipeCacheData int
enum EBool ZERO_PAD_SIZE
const int MIN
Definition EnConvert.c:28
bool InRange(int min, int max, bool inclusive_min=true, bool inclusive_max=true)
Check whether integer falls into an inclusive range.
Definition EnConvert.c:84
static protected string m_ZeroPad[ZERO_PAD_SIZE]
Definition EnConvert.c:25
string ToStringLen(int len)
Integer to string with fixed length, padded with zeroes.
Definition EnConvert.c:59
EBool
Definition EnConvert.c:17
@ NO
Definition EnConvert.c:18
@ YES
Definition EnConvert.c:19
proto string AsciiToString()
Converts ASCII code to string.
const int MAX
Definition EnConvert.c:27
proto string ToString()
Super root of all classes in Enforce script.
Definition EnScript.c:11
static int GetLastEnumValue(typename e)
Return amount of values in enum.
Definition EnConvert.c:647
static string EnumToString(typename e, int enumValue)
Return string name of enum value.
Definition EnConvert.c:601
static int GetEnumValue(typename e, int idx)
Return the nth value in the enum.
Definition EnConvert.c:634
private void ~EnumTools()
static int GetEnumSize(typename e)
Return amount of values in enum.
Definition EnConvert.c:623
static int StringToEnum(typename e, string enumName)
Return enum value from string name.
Definition EnConvert.c:612
private void EnumTools()
Definition EnMath.c:7
string ToString()
Definition EnConvert.c:3
const float LOWEST
Definition EnConvert.c:100
const float MAX
Definition EnConvert.c:99
const float MIN
Definition EnConvert.c:98
proto string ToString()
private proto void SetInstance(Class inst)
For internal usage of VM.
proto native bool IsInherited(typename baseType)
Returns true when type is the same as 'baseType', or inherited one.
proto native owned string ToString()
Returns type name of variable as string.
static string EnumToString(typename e, int enumValue)
Return string name of enum value.
Definition EnConvert.c:550
proto native GetVariableType(int vIdx)
proto owned string GetModule()
Get the name of the module the typename belongs to.
proto native int GetVariableCount()
proto bool GetVariableValue(Class var, int vIdx, out void val)
proto native owned string GetVariableName(int vIdx)
proto volatile Class Spawn()
Dynamic variant to 'new' keyword. It creates new instance of class.
static int StringToEnum(typename e, string enumName)
Return enum value from string name.
Definition EnConvert.c:572
proto vector Normalized()
return normalized vector (keeps orginal vector untouched)
static proto native float Distance(vector v1, vector v2)
Returns the distance between tips of two 3D vectors.
static const vector Forward
Definition EnConvert.c:109
static vector RandomDir2D()
Returns randomly generated XZ unit vector with the Y(up) axis set to 0.
Definition EnConvert.c:260
static vector RotateAroundZero(vector pos, vector axis, float cosAngle, float sinAngle)
Rotate a vector around 0,0,0.
Definition EnConvert.c:477
proto float Normalize()
Normalizes vector. Returns length.
static vector RandomDir()
Returns randomly generated unit vector.
Definition EnConvert.c:243
static const vector Up
Definition EnConvert.c:107
static vector RotateAroundZeroRad(vector vec, vector axis, float angle)
Rotate a vector around 0,0,0 by an angle in radians.
Definition EnConvert.c:463
proto string ToString(bool beautify=true)
Vector to string.
proto vector InvMultiply3(vector mat[3])
Invert-transforms vector.
static const vector Zero
Definition EnConvert.c:110
proto vector AnglesToVector()
Converts spherical coordinates (yaw, pitch, roll in degrees) to unit length vector.
vector Perpend()
Returns perpendicular vector. Perpendicular vector is computed as cross product between input vector ...
Definition EnConvert.c:209
proto float VectorToYaw()
Returns yaw of vector.
static vector ArrayToVec(float arr[])
Convert static array of floats into a vector.
Definition EnConvert.c:502
proto static native vector YawToVector(float yaw)
Returns vector of yaw.
proto native float LengthSq()
Returns squared length (magnitudeSqr)
proto vector Multiply4(vector mat[4])
Transforms position.
proto vector Multiply3(vector mat[3])
Transforms vector.
proto void RotationMatrixFromAngles(out vector mat[3])
Creates rotation matrix from angles.
static const vector Aside
Definition EnConvert.c:108
static proto native vector Lerp(vector v1, vector v2, float t)
Lerp between two vectors.
proto vector InvMultiply4(vector mat[4])
Invert-transforms position.
static proto native float DistanceSq(vector v1, vector v2)
Returns the square distance between tips of two 3D vectors.
proto vector VectorToAngles()
Converts vector to spherical coordinates with radius = 1.
static vector Direction(vector p1, vector p2)
Returns direction vector from point p1 to point p2.
Definition EnConvert.c:220
static vector RotateAroundPoint(vector point, vector pos, vector axis, float cosAngle, float sinAngle)
Rotate a vector around point.
Definition EnConvert.c:491
proto native float Length()
Returns length of vector (magnitude)
static float Dot(vector v1, vector v2)
Returns Dot product of vector v1 and vector v2.
Definition EnConvert.c:271
static vector RotateAroundZeroDeg(vector vec, vector axis, float angle)
Rotate a vector around 0,0,0 by an angle in degrees.
Definition EnConvert.c:450
vector GetRelAngles()
Returns relative angles between -180 and 180, not 0 to 360.
Definition EnConvert.c:286
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
static proto float Cos(float angle)
Returns cosinus of angle in radians.
static float RandomFloatInclusive(float min, float max)
Returns a random float number between and min [inclusive] and max [inclusive].
Definition EnMath.c:86
static const float DEG2RAD
Definition EnMath.c:17
static proto float Sin(float angle)
Returns sinus of angle in radians.
static proto string ToString(void var, bool type=false, bool name=false, bool quotes=true)
Return string representation of variable.
proto native int Length()
Returns length of string.