DayZ 1.24
Loading...
Searching...
No Matches
EnScript.c
Go to the documentation of this file.
1
10class Class
11{
23 proto native external bool IsInherited(typename type);
24
37 proto native owned external string ClassName();
38
39 string GetDebugName() { return ClassName(); }
40
52 proto native external typename Type();
53
64 proto external static typename StaticType();
65
73 static typename StaticGetType(typename t)
74 {
75 return t;
76 }
77
78 proto external string ToString();
79
94 proto static Class Cast(Class from);
95
110 proto static bool CastTo(out Class to, Class from);
111
113 private proto static bool SafeCastType(Class type, out Class to, Class from);
114};
115
118{
119};
120
123{
124};
125
127typedef int[] TypeID;
128
131{
132 private void ~ScriptModule();
133
139 proto volatile int Call(Class inst, string function, void parm);
140
146 proto volatile int CallFunction(Class inst, string function, out void returnVal, void parm);
147 proto volatile int CallFunctionParams(Class inst, string function, out void returnVal, Class parms);
148 proto native void Release();
149
160 static proto native ScriptModule LoadScript(ScriptModule parentModule, string scriptFile, bool listing);
161};
162
163//main script module (contains script.c and this file)
164//ScriptModule g_Script;
165
167{
168 private void EnScript() {}
169 private void ~EnScript() {}
170
188 static proto int GetClassVar(Class inst, string varname, int index, out void result);
189
211 static proto int SetClassVar(Class inst, string varname, int index, void input);
212
222 static proto int SetVar(out void var, string value);
223
230 static proto void Watch(void var, int flags);
231};
232
233
252proto void Sort(void param_array[], int num);
253proto void reversearray(void param_array);
254proto void copyarray(void destArray, void srcArray);
255
286proto int ParseStringEx(inout string input, string token);
287
306proto int ParseString(string input, out string tokens[]);
307
317proto native int KillThread(Class owner, string name);
318
322proto volatile void Idle();
323
335proto owned string ThreadFunction(Class owner, string name, int backtrace, out int linenumber);
336
338string String(string s)
339{
340 return s;
341}
342
344void PrintString(string s)
345{
346 Print(s);
347}
348
349class array<Class T>
350{
355 proto native int Count();
360 proto native void Clear();
364 proto void Set(int n, T value);
369 proto int Find(T value);
374 proto T Get(int n);
382 proto int Insert(T value);
393 proto int InsertAt(T value, int index);
424 void InsertAll(notnull array<T> from)
425 {
426 for (int i = 0; i < from.Count(); i++)
427 Insert(from.Get(i));
428 }
435 proto native void Remove(int index);
442 proto native void RemoveOrdered(int index);
448 proto native void Resize(int newSize);
449
454 proto native void Reserve(int newSize);
455
460 proto native void Swap(notnull array<T> other);
461
465 proto native void Sort(bool reverse = false);
471 proto int Copy(notnull array<T> from);
472 proto int Init(T init[]);
473
474 void RemoveItem(T value)
475 {
476 int remove_index = Find(value);
477
478 if (remove_index >= 0)
479 RemoveOrdered(remove_index);
480 }
481
483 {
484 int remove_index = Find(value);
485
486 if (remove_index >= 0)
487 Remove(remove_index);
488 }
489
490 bool IsValidIndex(int index)
491 {
492 return (index > -1 && index < Count());
493 }
494
495 /*
496 T GetChecked( int index )
497 {
498 if( IsValidIndex( index ) )
499 return Get( index );
500 else
501 return null;
502 }
503 */
504
516 void Debug()
517 {
518 Print(string.Format("Array count: %1", Count()));
519 for (int i = 0; i < Count(); i++)
520 {
521 T item = Get(i);
522 Print(string.Format("[%1] => %2", i, item));
523 }
524 }
525
536 {
537 if (Count() > 0)
538 return Math.RandomInt(0, Count());
539
540 return -1;
541 }
542
553 {
554 return Get(GetRandomIndex());
555 }
556
557 void SwapItems(int item1_index, int item2_index)
558 {
559 T item1 = Get(item1_index);
560 Set(item1_index, Get(item2_index));
561 Set(item2_index, item1);
562 }
563
565 {
566 for (int i = 0; i < other.Count(); i++)
567 {
568 T item = other.Get(i);
569 Insert(item);
570 }
571 }
572
573 void Invert()
574 {
575 int left = 0;
576 int right = Count() - 1;
577 if (right > 0)
578 {
579 while (left < right)
580 {
581 T temp = Get(left);
582 Set(left++, Get(right));
583 Set(right--, temp);
584 }
585 }
586 }
587
601 int MoveIndex(int curr_index, int move_number)
602 {
603 int count = Count();
604 int new_index = curr_index;
605
606 if (move_number > 0)
607 new_index = curr_index + move_number;
608
609 if (move_number < 0)
610 {
611 new_index = curr_index - move_number;
612
613 if (new_index < 0)
614 {
615 if (new_index <= -count)
616 new_index = (new_index % count);
617
618 new_index = new_index + count;
619 }
620 }
621
622 if (new_index >= count)
623 new_index = (new_index % count);
624
625 // move_number is 0
626 return new_index;
627 }
628
630 {
631 for (int i = 0; i < Count(); i++)
632 SwapItems(i, GetRandomIndex());
633 }
634
648 {
649 if (Count() != pOtherArray.Count())
650 {
651 ErrorEx("arrays are not the same size");
652 return -1;
653 }
654
655 for (int i = 0; i < pOtherArray.Count(); ++i)
656 {
657 if (Get(i) != pOtherArray.Get(i))
658 return i;
659 }
660
661 return -1;
662 }
663};
664
665//force these to compile so we can link C++ methods to them
675
676class set<Class T>
677{
678 proto native int Count();
679 proto native void Clear();
684 proto int Find(T value);
685 proto T Get(int n);
693 proto int Insert(T value);
704 proto int InsertAt(T value, int index);
710 proto native void Remove(int index);
711 proto int Copy(set<T> from);
712 proto native void Swap(set<T> other);
713 proto int Init(T init[]);
714
715 void InsertSet(set<T> other)
716 {
717 int count = other.Count();
718 for (int i = 0; i < count; i++)
719 {
720 T item = other[i];
721 Insert(item);
722 }
723 }
724
725 void RemoveItem(T value)
726 {
727 int remove_index = Find(value);
728 if (remove_index >= 0)
729 Remove(remove_index);
730 }
731
732 void RemoveItems(set<T> other)
733 {
734 int count = other.Count();
735 for (int i = 0; i < count; i++)
736 {
737 T item = other[i];
738 RemoveItem(item);
739 }
740 }
741
742 void Debug()
743 {
744 Print(string.Format("Set count: %1", Count()));
745 for (int i = 0; i < Count(); i++)
746 {
747 T item = Get(i);
748 Print(string.Format("[%1] => %2", i, item));
749 }
750 }
751};
752
753//force these to compile so we can link C++ methods to them
754typedef set<string> TStringSet;
755typedef set<float> TFloatSet;
756typedef set<int> TIntSet;
757typedef set<Class> TClassSet;
758typedef set<Managed> TManagedSet;
759typedef set<ref Managed> TManagedRefSet;
760typedef set<typename> TTypenameSet;
761
762typedef int MapIterator;
779class map<Class TKey, Class TValue>
780{
785 proto native int Count();
786
790 proto native void Clear();
799 proto TValue Get(TKey key);
810 proto bool Find(TKey key, out TValue val);
820 proto TValue GetElement(int index);
830 proto TKey GetKey(int i);
835 proto void Set(TKey key, TValue value);
839 proto void Remove(TKey key);
846 proto void RemoveElement(int i);
850 proto bool Contains(TKey key);
859 proto bool Insert(TKey key, TValue value);
860 proto int Copy(map<TKey, TValue> from);
861
863 {
864 array<TKey> keys = new array<TKey>;
865 for (int i = 0; i < Count(); i++)
866 keys.Insert(GetKey(i));
867 return keys;
868 }
869
871 {
872 array<TValue> elements = new array<TValue>;
873 for (int i = 0; i < Count(); i++)
874 elements.Insert(GetElement(i));
875 return elements;
876 }
877
878 bool ReplaceKey(TKey old_key, TKey new_key)
879 {
880 if (Contains(old_key))
881 {
882 Set(new_key, Get(old_key));
883 Remove(old_key);
884 return true;
885 }
886 return false;
887 }
888
889 TKey GetKeyByValue(TValue value)
890 {
891 TKey ret;
892 for (int i = 0; i < Count(); i++)
893 {
894 if (GetElement(i) == value)
895 {
896 ret = GetKey(i);
897 break;
898 }
899 }
900
901 return ret;
902 }
903
904 bool GetKeyByValueChecked(TValue value, out TKey key)
905 {
906 for (int i = 0; i < Count(); i++)
907 {
908 if (GetElement(i) == value)
909 {
910 key = GetKey(i);
911 return true;
912 }
913 }
914 return false;
915 }
916
917 proto native MapIterator Begin();
918 proto native MapIterator End();
919 proto native MapIterator Next(MapIterator it);
922};
923
932
941
950
959
968
977
void Remove(Object object)
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
DisplayElementBase GetElement(eDisplayElements element_id)
enum MagnumStableStateID init
array< ref PlayerStatBase > Get()
Super root of all classes in Enforce script.
Definition EnScript.c:11
TODO doc.
Definition EnScript.c:118
Definition EnMath.c:7
TODO doc.
Definition EnScript.c:123
Module containing compiled scripts.
Definition EnScript.c:131
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
proto void Print(void var)
Prints content of variable to console/log.
enum ShapeType ErrorEx
proto int ParseString(string input, out string tokens[])
Parses string into array of tokens returns number of tokens.
map< Managed, int > TManagedIntMap
Definition EnScript.c:961
proto native void Sort(bool reverse=false)
map< Managed, Class > TManagedClassMap
Definition EnScript.c:963
map< typename, float > TTypeNameFloatMap
Definition EnScript.c:951
proto int ParseStringEx(inout string input, string token)
Parses one token from input string. Result is put into token string, and type of token is returned....
proto int Insert(T value)
static proto int SetClassVar(Class inst, string varname, int index, void input)
Dynamic write to variable by its name.
void InsertAll(notnull array< T > from)
Inserts all elements from array.
Definition EnScript.c:424
proto void Sort(void param_array[], int num)
Sorts static array of integers(ascendically) / floats(ascendically) / strings(alphabetically)
set< int > TIntSet
Definition EnScript.c:756
array< typename > TTypenameArray
Definition EnScript.c:674
static proto int SetVar(out void var, string value)
Sets variable value by value in string.
array< float > TFloatArray
Definition EnScript.c:667
proto int Init(T init[])
set< Class > TClassSet
Definition EnScript.c:757
map< Class, vector > TClassVectorMap
Definition EnScript.c:949
map< Class, typename > TClassTypenameMap
Definition EnScript.c:948
int MoveIndex(int curr_index, int move_number)
Returns a index in array moved by specific number.
Definition EnScript.c:601
proto void RemoveElement(int i)
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
proto native void Clear()
map< ref Managed, Managed > TManagedRefManagedMap
Definition EnScript.c:973
proto int Insert(T value)
array< string > TStringArray
Definition EnScript.c:666
static proto int GetClassVar(Class inst, string varname, int index, out void result)
Dynamic read of variable value by its name.
void SwapItems(int item1_index, int item2_index)
Definition EnScript.c:557
map< int, Class > TIntClassMap
Definition EnScript.c:927
proto native MapIterator End()
map< Class, float > TClassFloatMap
Definition EnScript.c:942
proto void Set(int n, T value)
map< string, vector > TStringVectorMap
Definition EnScript.c:940
proto native int KillThread(Class owner, string name)
Kills thread.
proto native owned external string ClassName()
Returns name of class-type.
map< int, string > TIntStringMap
Definition EnScript.c:926
map< int, float > TIntFloatMap
Definition EnScript.c:924
proto owned string ThreadFunction(Class owner, string name, int backtrace, out int linenumber)
Debug function. Returns current function on stack of the thread.
proto native external bool IsInherited(typename type)
Returns true when instance is of the type, or inherited one.
proto native void RemoveOrdered(int index)
proto void Remove(TKey key)
array< Managed > TManagedArray
Definition EnScript.c:671
void RemoveItem(T value)
Definition EnScript.c:725
map< ref Managed, vector > TManagedRefVectorMap
Definition EnScript.c:976
void RemoveItemUnOrdered(T value)
Definition EnScript.c:482
bool IsValidIndex(int index)
Definition EnScript.c:490
int MapIterator
Definition EnScript.c:762
proto TValue Get(TKey key)
map< ref Managed, float > TManagedRefFloatMap
Definition EnScript.c:969
array< vector > TVectorArray
Definition EnScript.c:673
proto int Find(T value)
array< ref Managed > TManagedRefArray
Definition EnScript.c:672
void PrintString(string s)
Helper for printing out string expression. Example: PrintString("Hello " + var);.
Definition EnScript.c:344
proto TKey GetIteratorKey(MapIterator it)
map< ref Managed, ref Managed > TManagedRefManagedRefMap
Definition EnScript.c:974
proto native void Swap(notnull array< T > other)
proto volatile int CallFunctionParams(Class inst, string function, out void returnVal, Class parms)
proto T Get(int n)
void ~EnScript()
Definition EnScript.c:169
array< int > TIntArray
Definition EnScript.c:668
proto int InsertAt(T value, int index)
map< Class, Class > TClassClassMap
Definition EnScript.c:945
static proto native ScriptModule LoadScript(ScriptModule parentModule, string scriptFile, bool listing)
Do load script and create ScriptModule for it.
proto int Copy(notnull array< T > from)
int GetRandomIndex()
Returns a random index of array. If Count is 0, return index is -1 .
Definition EnScript.c:535
array< Class > TClassArray
Definition EnScript.c:670
map< Class, int > TClassIntMap
Definition EnScript.c:943
proto void copyarray(void destArray, void srcArray)
proto bool Contains(TKey key)
static proto void Watch(void var, int flags)
Debug tool for watching certain variable. Invokes debugger whenever is variable used.
proto native external Type()
Returns typename of object's class.
array< TValue > GetValueArray()
Definition EnScript.c:870
proto int Find(T value)
set< float > TFloatSet
Definition EnScript.c:755
string String(string s)
Helper for passing string expression to functions with void parameter. Example: Print(String("Hello "...
Definition EnScript.c:338
TKey GetKeyByValue(TValue value)
Definition EnScript.c:889
void EnScript()
Definition EnScript.c:168
map< ref Managed, typename > TManagedRefTypenameMap
Definition EnScript.c:975
void InsertSet(set< T > other)
Definition EnScript.c:715
map< Managed, typename > TManagedTypenameMap
Definition EnScript.c:966
proto TValue GetIteratorElement(MapIterator it)
map< string, int > TStringIntMap
Definition EnScript.c:934
proto volatile void Idle()
set< ref Managed > TManagedRefSet
Definition EnScript.c:759
void InsertArray(array< T > other)
Definition EnScript.c:564
proto native int Count()
map< typename, vector > TTypeNameVectorMap
Definition EnScript.c:958
proto native void Release()
map< ref Managed, string > TManagedRefStringMap
Definition EnScript.c:971
map< int, typename > TIntTypenameMap
Definition EnScript.c:930
map< Class, ref Managed > TClassManagedRefMap
Definition EnScript.c:947
proto volatile int Call(Class inst, string function, void parm)
map< Managed, Managed > TManagedManagedMap
Definition EnScript.c:964
proto native void Reserve(int newSize)
void RemoveItem(T value)
Definition EnScript.c:474
proto native void Resize(int newSize)
map< typename, Managed > TTypeNameManagedMap
Definition EnScript.c:955
proto volatile int CallFunction(Class inst, string function, out void returnVal, void parm)
proto static external StaticType()
Returns typename of object's reference.
proto bool Insert(TKey key, TValue value)
bool ReplaceKey(TKey old_key, TKey new_key)
Definition EnScript.c:878
proto void reversearray(void param_array)
map< Managed, ref Managed > TManagedManagedRefMap
Definition EnScript.c:965
proto native MapIterator Next(MapIterator it)
void RemoveItems(set< T > other)
Definition EnScript.c:732
map< string, ref Managed > TStringManagedRefMap
Definition EnScript.c:938
proto native void Clear()
map< typename, ref Managed > TTypeNameManagedRefMap
Definition EnScript.c:956
map< typename, int > TTypeNameIntMap
Definition EnScript.c:952
proto native MapIterator Begin()
static StaticGetType(typename t)
Returns typename of class even without a variable or instance.
Definition EnScript.c:73
map< string, string > TStringStringMap
Definition EnScript.c:935
array< bool > TBoolArray
Definition EnScript.c:669
map< Class, string > TClassStringMap
Definition EnScript.c:944
map< int, int > TIntIntMap
Definition EnScript.c:925
void Debug()
Print all elements in array.
Definition EnScript.c:516
proto external string ToString()
string GetDebugName()
Definition EnScript.c:39
int DifferentAtPosition(array< T > pOtherArray)
Returns an index where 2 arrays start to differ from each other.
Definition EnScript.c:647
map< string, float > TStringFloatMap
Definition EnScript.c:933
map< ref Managed, int > TManagedRefIntMap
Definition EnScript.c:970
T GetRandomElement()
Returns a random element of array.
Definition EnScript.c:552
proto native void Remove(int index)
proto void Set(TKey key, TValue value)
map< typename, Class > TTypeNameClassMap
Definition EnScript.c:954
bool GetKeyByValueChecked(TValue value, out TKey key)
Definition EnScript.c:904
static proto Class Cast(Class from)
Try to safely down-cast base class to child class.
void ~ScriptModule()
proto int Init(T init[])
map< string, Class > TStringClassMap
Definition EnScript.c:936
int[] TypeID
script representation for C++ RTTI types
Definition EnScript.c:127
proto TValue GetElement(int index)
set< typename > TTypenameSet
Definition EnScript.c:760
proto native int Count()
map< typename, string > TTypeNameStringMap
Definition EnScript.c:953
proto int InsertAt(T value, int index)
map< int, Managed > TIntManagedMap
Definition EnScript.c:928
set< string > TStringSet
Definition EnScript.c:754
map< string, typename > TStringTypenameMap
Definition EnScript.c:939
map< Managed, float > TManagedFloatMap
Definition EnScript.c:960
proto T Get(int n)
proto int Copy(set< T > from)
proto int Copy(map< TKey, TValue > from)
proto native void Swap(set< T > other)
void ShuffleArray()
Definition EnScript.c:629
static proto bool SafeCastType(Class type, out Class to, Class from)
This function is for internal script usage.
proto bool Find(TKey key, out TValue val)
map< int, vector > TIntVectorMap
Definition EnScript.c:931
set< Managed > TManagedSet
Definition EnScript.c:758
map< int, ref Managed > TIntManagedRefMap
Definition EnScript.c:929
map< typename, typename > TTypeNameTypenameMap
Definition EnScript.c:957
map< ref Managed, Class > TManagedRefClassMap
Definition EnScript.c:972
proto native void Remove(int index)
map< Managed, string > TManagedStringMap
Definition EnScript.c:962
map< Managed, vector > TManagedVectorMap
Definition EnScript.c:967
map< string, Managed > TStringManagedMap
Definition EnScript.c:937
map< Class, Managed > TClassManagedMap
Definition EnScript.c:946
static proto int RandomInt(int min, int max)
Returns a random int number between and min [inclusive] and max [exclusive].