Dayz Explorer 1.29.162510
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
20}
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
82 proto string ToHex();
83
97 bool InRange( int min, int max, bool inclusive_min = true, bool inclusive_max = true )
98 {
99 if( ( !inclusive_min && value <= min ) || value < min )
100 return false;
101
102 if( ( !inclusive_max && value >= max ) || value > max )
103 return false;
104
105 return true;
106 }
107};
108
109class float
110{
111 const float MIN = FLT_MIN;
112 const float MAX = FLT_MAX;
113 const float LOWEST = -FLT_MAX;
114
115 proto string ToString(bool simple = true);
116};
117
119{
120 static const vector Up = "0 1 0";
121 static const vector Aside = "1 0 0";
122 static const vector Forward = "0 0 1";
123 static const vector Zero = "0 0 0";
124
138 proto string ToString(bool beautify = true);
139
153 proto float Normalize();
154
156 proto vector Normalized();
157
169 proto native float Length();
170
182 proto native float LengthSq();
183
196 proto static native float Distance(vector v1, vector v2);
197
210 proto static native float DistanceSq(vector v1, vector v2);
211
222 vector Perpend()
223 {
224 return value * vector.Up;
225 }
226
233 static vector Direction(vector p1, vector p2)
234 {
235 vector dir_vec;
236
237 dir_vec[0] = p2[0] - p1[0];
238 dir_vec[1] = p2[1] - p1[1];
239 dir_vec[2] = p2[2] - p1[2];
240
241 return dir_vec;
242 }
243
256 static vector RandomDir()
257 {
258 return Vector(Math.RandomFloatInclusive(-1,1),Math.RandomFloatInclusive(-1,1),Math.RandomFloatInclusive(-1,1)).Normalized();
259 }
260
273 static vector RandomDir2D()
274 {
275 return Vector(Math.RandomFloatInclusive(-1,1),0,Math.RandomFloatInclusive(-1,1)).Normalized();
276 }
277
284 static float Dot(vector v1, vector v2)
285 {
286 return ((v1[0] * v2[0]) + (v1[1] * v2[1]) + (v1[2] * v2[2]));
287 }
288
299 vector GetRelAngles()
300 {
301 for(int i = 0; i < 3; i++) {
302 if(value[i] > 180)
303 value[i] = value[i] - 360;
304 if(value[i] < -180)
305 value[i] = value[i] + 360;
306 }
307 return value;
308 }
309
324 proto float VectorToYaw();
325
338 proto native static vector YawToVector(float yaw);
339
353 proto vector VectorToAngles();
354
368 proto vector AnglesToVector();
369
383 proto void RotationMatrixFromAngles(out vector mat[3]);
384
398 proto vector Multiply4(vector mat[4]);
399
413 proto vector Multiply3(vector mat[3]);
414
428 proto vector InvMultiply4(vector mat[4]);
429
443 proto vector InvMultiply3(vector mat[3]);
444
453 proto static native vector Lerp(vector v1, vector v2, float t);
454
462
463 static vector RotateAroundZeroDeg(vector vec, vector axis, float angle)
464 {
465 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));
466 }
467
475
476 static vector RotateAroundZeroRad(vector vec, vector axis, float angle)
477 {
478 return (vec * Math.Cos(angle)) + ((axis * vec) * Math.Sin(angle)) + (axis * vector.Dot(axis, vec)) * (1 - Math.Cos(angle));
479 }
480
489
490 static vector RotateAroundZero(vector pos, vector axis, float cosAngle, float sinAngle)
491 {
492 return (pos * cosAngle) + ((axis * pos) * sinAngle) + (axis * vector.Dot(axis, pos)) * (1 - cosAngle);
493 }
494
504 static vector RotateAroundPoint(vector point, vector pos, vector axis, float cosAngle, float sinAngle)
505 {
506 vector offsetPos = pos - point;
507 return RotateAroundZero(offsetPos, axis, cosAngle, sinAngle) + point;
508 }
509
515 static vector ArrayToVec(float arr[])
516 {
517 return Vector(arr[0], arr[1], arr[2]);
518 }
519};
520
522{
530 proto volatile Class Spawn();
531
536 proto owned string GetModule();
537
539 proto native owned string ToString();
540
549 proto native bool IsInherited(typename baseType);
550
551 proto native int GetVariableCount();
552 proto native owned string GetVariableName(int vIdx);
553 proto native typename GetVariableType(int vIdx);
554 proto bool GetVariableValue(Class var, int vIdx, out void val);
555
563 static string EnumToString(typename e, int enumValue)
564 {
565 int cnt = e.GetVariableCount();
566 int val;
567
568 for (int i = 0; i < cnt; i++)
569 {
570 if (e.GetVariableType(i) == int && e.GetVariableValue(null, i, val) && val == enumValue)
571 {
572 return e.GetVariableName(i);
573 }
574 }
575
576 return "unknown";
577 }
578
585 static int StringToEnum(typename e, string enumName)
586 {
587 int count = e.GetVariableCount();
588 int value;
589
590 for (int i = 0; i < count; i++)
591 {
592 if (e.GetVariableType(i) == int && e.GetVariableValue(null, i, value) && e.GetVariableName(i) == enumName)
593 {
594 return value;
595 }
596 }
597
598 return -1;
599 }
600};
601
602class EnumTools
603{
604 private void EnumTools();
605 private void ~EnumTools();
606
614 static string EnumToString(typename e, int enumValue)
615 {
616 return typename.EnumToString(e, enumValue);
617 }
618
625 static int StringToEnum(typename e, string enumName)
626 {
627 return typename.StringToEnum(e, enumName);
628 }
629
636 static int GetEnumSize(typename e)
637 {
638 return e.GetVariableCount();
639 }
640
647 static int GetEnumValue(typename e, int idx)
648 {
649 int value;
650 e.GetVariableValue(null, idx, value);
651 return value;
652 }
653
660 static int GetLastEnumValue(typename e)
661 {
662 int lastValue;
663 e.GetVariableValue(null, e.GetVariableCount() - 1, lastValue);
664 return lastValue;
665 }
666}
Param3 int
Direction
Definition inventory.c:19
void Spawn()
spawn damage trigger
Super root of all classes in Enforce script.
Definition enscript.c:11
Definition enmath.c:7
enum EBool ZERO_PAD_SIZE
const int MIN
Definition enconvert.c:28
proto string ToHex()
Integer to hex (as string).
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:97
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()
proto native vector Vector(float x, float y, float z)
Vector constructor from components.