Dayz Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
Loading...
Searching...
No Matches
enscript.c
Go to the documentation of this file.
1
8
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
234
253proto void Sort(void param_array[], int num);
254proto void reversearray(void param_array);
255proto void copyarray(void destArray, void srcArray);
256
287proto int ParseStringEx(inout string input, string token);
288
307proto int ParseString(string input, out string tokens[]);
308
318proto native int KillThread(Class owner, string name);
319
323proto volatile void Idle();
324
336proto owned string ThreadFunction(Class owner, string name, int backtrace, out int linenumber);
337
339string String(string s)
340{
341 return s;
342}
343
360{
361 string m_Msg;
362 void Obsolete(string msg = "")
363 {
364 m_Msg = msg;
365 }
366}
367
369void PrintString(string s)
372}
373
374class array<Class T>
375{
380 proto native int Count();
385 proto native void Clear();
389 proto void Set(int n, T value);
394 proto int Find(T value);
398
399 proto T Get(int n);
407 proto int Insert(T value);
418 proto int InsertAt(T value, int index);
449 void InsertAll(notnull array<T> from)
450 {
451 int nFrom = from.Count();
452 for ( int i = 0; i < nFrom; ++i )
453 {
454 Insert( from.Get(i) );
455 }
456 }
457
463 proto native void Remove(int index);
470 proto native void RemoveOrdered(int index);
476 proto native void Resize(int newSize);
477
482 proto native void Reserve(int newSize);
483
488 proto native void Swap(notnull array<T> other);
489
493 proto native void Sort(bool reverse = false);
498
499 proto int Copy(notnull array<T> from);
500 proto int Init(T init[]);
501
502 void RemoveItem(T value)
503 {
504 int remove_index = Find(value);
505
506 if ( remove_index >= 0 )
507 {
508 RemoveOrdered(remove_index);
509 }
510 }
511
513 {
514 int remove_index = Find(value);
515
516 if ( remove_index >= 0 )
517 {
518 Remove(remove_index);
519 }
520 }
521
522 bool IsValidIndex( int index )
523 {
524 return ( index > -1 && index < Count() );
525 }
526
527 /*
528 T GetChecked( int index )
529 {
530 if( IsValidIndex( index ) )
531 return Get( index );
532 else
533 return null;
534 }
535 */
536
548 void Debug()
549 {
550 Print(string.Format("Array count: %1", Count()));
551 for (int i = 0; i < Count(); i++)
552 {
553 T item = Get(i);
554 Print(string.Format("[%1] => %2", i, item));
555 }
556 }
557
568 {
569 if ( Count() > 0 )
570 {
571 return Math.RandomInt(0, Count());
572 }
573
574 return -1;
575 }
576
587 {
588 return Get(GetRandomIndex());
589 }
590
591 void SwapItems(int item1_index, int item2_index)
592 {
593 T item1 = Get(item1_index);
594 Set(item1_index, Get(item2_index));
595 Set(item2_index, item1);
596 }
597
599 {
600 int nOther = other.Count();
601 for (int i = 0; i < nOther; ++i)
602 {
603 T item = other.Get(i);
604 Insert(item);
605 }
606 }
607
608 void Invert()
609 {
610 int left = 0;
611 int right = Count() - 1;
612 if (right > 0)
613 {
614 while (left < right)
615 {
616 T temp = Get(left);
617 Set(left++, Get(right));
618 Set(right--, temp);
619 }
620 }
621 }
622
636 int MoveIndex(int curr_index, int move_number)
637 {
638 int count = Count();
639 int new_index = curr_index;
640
641 if ( move_number > 0 )
642 {
643 new_index = curr_index + move_number;
644 }
645
646 if ( move_number < 0 )
647 {
648 new_index = curr_index - move_number;
649
650 if ( new_index < 0 )
651 {
652 if ( new_index <= -count )
653 {
654 new_index = (new_index % count);
655 }
656
657 new_index = new_index + count;
658 }
659 }
660
661 if ( new_index >= count )
662 {
663 new_index = (new_index % count);
664 }
665
666 // move_number is 0
667 return new_index;
668 }
669
671 {
672 for (int i = 0; i < Count(); i++)
673 {
675 }
676 }
677
691 {
692 if (Count() != pOtherArray.Count())
693 {
694 ErrorEx("arrays are not the same size");
695 return -1;
696 }
697
698 int nOther = pOtherArray.Count();
699 for (int i = 0; i < nOther; ++i)
700 {
701 if (Get(i) != pOtherArray.Get(i))
702 {
703 return i;
704 }
705 }
706
707 return -1;
708 }
710
711//force these to compile so we can link C++ methods to them
721
722class set<Class T>
723{
724 proto native int Count();
725 proto native void Clear();
730 proto int Find(T value);
731 proto T Get(int n);
739 proto int Insert(T value);
750 proto int InsertAt(T value, int index);
756 proto native void Remove(int index);
757 proto int Copy(set<T> from);
758 proto native void Swap(set<T> other);
759 proto int Init(T init[]);
760
761 void InsertSet(set<T> other)
762 {
763 int count = other.Count();
764 for (int i = 0; i < count; i++)
765 {
766 T item = other[i];
767 Insert(item);
768 }
769 }
770
771 void RemoveItem(T value)
772 {
773 int remove_index = Find(value);
774 if (remove_index >= 0)
775 {
776 Remove(remove_index);
777 }
778 }
779
780 void RemoveItems(set<T> other)
781 {
782 int count = other.Count();
783 for (int i = 0; i < count; i++)
784 {
785 T item = other[i];
786 RemoveItem(item);
787 }
788 }
789
790 void Debug()
791 {
792 Print(string.Format("Set count: %1", Count()));
793 for (int i = 0; i < Count(); i++)
794 {
795 T item = Get(i);
796 Print(string.Format("[%1] => %2", i, item));
797 }
798 }
799};
800
801//force these to compile so we can link C++ methods to them
802typedef set<string> TStringSet;
803typedef set<float> TFloatSet;
804typedef set<int> TIntSet;
805typedef set<Class> TClassSet;
806typedef set<Managed> TManagedSet;
807typedef set<ref Managed> TManagedRefSet;
808typedef set<typename> TTypenameSet;
809
810typedef int MapIterator;
827class map<Class TKey,Class TValue>
828{
833 proto native int Count();
834
838 proto native void Clear();
847 proto TValue Get(TKey key);
858 proto bool Find(TKey key, out TValue val);
868 proto TValue GetElement(int index);
878 proto TKey GetKey(int i);
883 proto void Set(TKey key, TValue value);
887 proto void Remove(TKey key);
894 proto void RemoveElement(int i);
898 proto bool Contains(TKey key);
907 proto bool Insert(TKey key, TValue value);
908 proto int Copy(map<TKey,TValue> from);
909
911 {
912 array<TKey> keys = new array<TKey>();
913 for (int i = 0; i < Count(); ++i)
914 keys.Insert(GetKey(i));
915
916 return keys;
917 }
918
920 {
921 array<TValue> elements = new array<TValue>();
922 for (int i = 0; i < Count(); ++i)
923 elements.Insert(GetElement(i));
924
925 return elements;
926 }
927
928 bool ReplaceKey(TKey old_key, TKey new_key)
929 {
930 if (Contains(old_key))
931 {
932 Set(new_key, Get(old_key));
933 Remove(old_key);
934 return true;
935 }
936 return false;
937 }
938
939 TKey GetKeyByValue(TValue value)
940 {
941 TKey ret;
942 for (int i = 0; i < Count(); i++)
943 {
944 if (GetElement(i) == value)
945 {
946 ret = GetKey(i);
947 break;
948 }
949 }
950
951 return ret;
952 }
953
954 bool GetKeyByValueChecked(TValue value, out TKey key)
955 {
956 for (int i = 0; i < Count(); i++)
957 {
958 if (GetElement(i) == value)
959 {
960 key = GetKey(i);
961 return true;
962 }
963 }
964 return false;
965 }
966
967 proto native MapIterator Begin();
968 proto native MapIterator End();
969 proto native MapIterator Next(MapIterator it);
972};
973
982
991
1000
1009
1018
1027
void Remove(Object object)
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
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.
DisplayElementBase GetElement(eDisplayElements element_id)
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.
proto native void Reserve(int newSize)
Resizes the array to given size internally.
map< Managed, int > TManagedIntMap
Definition enscript.c:1011
map< Managed, Class > TManagedClassMap
Definition enscript.c:1013
proto volatile int CallFunction(Class inst, string function, out void returnVal, void parm)
dynamic call of function when inst == NULL, it's global function call, otherwise it's method of class...
void SwapItems(int item1_index, int item2_index)
Definition enscript.c:591
map< typename, float > TTypeNameFloatMap
Definition enscript.c:1001
static proto void Watch(void var, int flags)
Debug tool for watching certain variable.
proto int ParseStringEx(inout string input, string token)
Parses one token from input string.
void InsertSet(set< T > other)
Definition enscript.c:761
proto void Sort(void param_array[], int num)
Sorts static array of integers(ascendically) / floats(ascendically) / strings(alphabetically).
set< int > TIntSet
Definition enscript.c:804
array< typename > TTypenameArray
Definition enscript.c:720
TKey GetKeyByValue(TValue value)
Definition enscript.c:939
proto void Remove(TKey key)
Removes element with given key.
proto TKey GetKey(int i)
Return the i:th element key in the map.
array< float > TFloatArray
Definition enscript.c:713
proto void RemoveElement(int i)
Removes i:th element with given key.
set< Class > TClassSet
Definition enscript.c:805
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
proto int Find(T value)
Tries to find the first occurance of given value in the array.
proto void Set(int n, T value)
Sets n-th element to given value.
map< Class, vector > TClassVectorMap
Definition enscript.c:999
proto int Insert(T value)
Inserts element at the end of array.
proto int Copy(set< T > from)
void RemoveItemUnOrdered(T value)
Definition enscript.c:512
map< Class, typename > TClassTypenameMap
Definition enscript.c:998
proto native external bool IsInherited(typename type)
Returns true when instance is of the type, or inherited one.
static proto bool SafeCastType(Class type, out Class to, Class from)
This function is for internal script usage.
map< ref Managed, Managed > TManagedRefManagedMap
Definition enscript.c:1023
array< string > TStringArray
Definition enscript.c:712
static proto Class Cast(Class from)
Try to safely down-cast base class to child class.
proto native void RemoveOrdered(int index)
Removes element from array, but retain all elements ordered.
map< int, Class > TIntClassMap
Definition enscript.c:977
map< Class, float > TClassFloatMap
Definition enscript.c:992
map< string, vector > TStringVectorMap
Definition enscript.c:990
proto native int KillThread(Class owner, string name)
Kills thread.
void ~EnScript()
Definition enscript.c:169
map< int, string > TIntStringMap
Definition enscript.c:976
proto native void Swap(notnull array< T > other)
Swaps the contents of this and other arrays.
map< int, float > TIntFloatMap
Definition enscript.c:974
proto native int Count()
O(1) complexity.
proto owned string ThreadFunction(Class owner, string name, int backtrace, out int linenumber)
Debug function.
bool IsValidIndex(int index)
Definition enscript.c:522
proto int Copy(map< TKey, TValue > from)
proto native MapIterator Begin()
array< Managed > TManagedArray
Definition enscript.c:717
map< ref Managed, vector > TManagedRefVectorMap
Definition enscript.c:1026
proto native void Swap(set< T > other)
int MapIterator
Definition enscript.c:810
int DifferentAtPosition(array< T > pOtherArray)
Returns an index where 2 arrays start to differ from each other.
Definition enscript.c:690
proto static external StaticType()
Returns typename of object's reference.
map< ref Managed, float > TManagedRefFloatMap
Definition enscript.c:1019
void InsertArray(array< T > other)
Definition enscript.c:598
array< vector > TVectorArray
Definition enscript.c:719
array< ref Managed > TManagedRefArray
Definition enscript.c:718
map< ref Managed, ref Managed > TManagedRefManagedRefMap
Definition enscript.c:1024
proto TKey GetIteratorKey(MapIterator it)
void RemoveItem(T value)
Definition enscript.c:502
proto native MapIterator Next(MapIterator it)
proto int Copy(notnull array< T > from)
Copes contents of from array to this array.
array< int > TIntArray
Definition enscript.c:714
map< Class, Class > TClassClassMap
Definition enscript.c:995
proto native void Sort(bool reverse=false)
Sorts elements of array, depends on underlaying type.
proto native MapIterator End()
proto native void Release()
array< Class > TClassArray
Definition enscript.c:716
map< Class, int > TClassIntMap
Definition enscript.c:993
proto int InsertAt(T value, int index)
Inserts element at certain position and moves all elements behind this position by one.
proto void copyarray(void destArray, void srcArray)
static proto int SetVar(out void var, string value)
Sets variable value by value in string.
set< float > TFloatSet
Definition enscript.c:803
T GetRandomElement()
Returns a random element of array.
Definition enscript.c:586
static StaticGetType(typename t)
Returns typename of class even without a variable or instance.
Definition enscript.c:73
string String(string s)
Helper for passing string expression to functions with void parameter. Example: Print(String("Hello "...
Definition enscript.c:339
map< ref Managed, typename > TManagedRefTypenameMap
Definition enscript.c:1025
map< Managed, typename > TManagedTypenameMap
Definition enscript.c:1016
map< string, int > TStringIntMap
Definition enscript.c:984
proto volatile void Idle()
Yiels execution to other threads and then it continues.
set< ref Managed > TManagedRefSet
Definition enscript.c:807
proto native void Clear()
Destroyes all elements of the array and sets the Count to 0.
proto TValue Get(TKey key)
Search for an element with the given key.
string GetDebugName()
Definition enscript.c:39
proto TValue GetElement(int index)
Return the i:th element in the map.
map< typename, vector > TTypeNameVectorMap
Definition enscript.c:1008
void Obsolete(string msg="")
Definition enscript.c:362
proto native void Resize(int newSize)
Resizes the array to given size.
map< ref Managed, string > TManagedRefStringMap
Definition enscript.c:1021
map< int, typename > TIntTypenameMap
Definition enscript.c:980
map< Class, ref Managed > TClassManagedRefMap
Definition enscript.c:997
map< Managed, Managed > TManagedManagedMap
Definition enscript.c:1014
void RemoveItems(set< T > other)
Definition enscript.c:780
proto void Set(TKey key, TValue value)
Sets value of element with given key.
static proto int GetClassVar(Class inst, string varname, int index, out void result)
Dynamic read of variable value by its name.
map< typename, Managed > TTypeNameManagedMap
Definition enscript.c:1005
static proto native ScriptModule LoadScript(ScriptModule parentModule, string scriptFile, bool listing)
Do load script and create ScriptModule for it.
proto T Get(int n)
proto void reversearray(void param_array)
map< Managed, ref Managed > TManagedManagedRefMap
Definition enscript.c:1015
map< string, ref Managed > TStringManagedRefMap
Definition enscript.c:988
map< typename, ref Managed > TTypeNameManagedRefMap
Definition enscript.c:1006
map< typename, int > TTypeNameIntMap
Definition enscript.c:1002
map< string, string > TStringStringMap
Definition enscript.c:985
array< bool > TBoolArray
Definition enscript.c:715
map< Class, string > TClassStringMap
Definition enscript.c:994
map< int, int > TIntIntMap
Definition enscript.c:975
bool ReplaceKey(TKey old_key, TKey new_key)
Definition enscript.c:928
map< string, float > TStringFloatMap
Definition enscript.c:983
map< ref Managed, int > TManagedRefIntMap
Definition enscript.c:1020
proto volatile int Call(Class inst, string function, void parm)
dynamic call of function when inst == NULL, it's global function call, otherwise it's method of class...
proto native void Remove(int index)
Removes element from array.
map< typename, Class > TTypeNameClassMap
Definition enscript.c:1004
int MoveIndex(int curr_index, int move_number)
Returns a index in array moved by specific number.
Definition enscript.c:636
void ~ScriptModule()
void InsertAll(notnull array< T > from)
Inserts all elements from array.
Definition enscript.c:449
array< TValue > GetValueArray()
Definition enscript.c:919
void EnScript()
Definition enscript.c:168
map< string, Class > TStringClassMap
Definition enscript.c:986
int[] TypeID
script representation for C++ RTTI types
Definition enscript.c:127
proto native owned external string ClassName()
Returns name of class-type.
set< typename > TTypenameSet
Definition enscript.c:808
bool GetKeyByValueChecked(TValue value, out TKey key)
Definition enscript.c:954
map< typename, string > TTypeNameStringMap
Definition enscript.c:1003
map< int, Managed > TIntManagedMap
Definition enscript.c:978
proto external string ToString()
set< string > TStringSet
Definition enscript.c:802
map< string, typename > TStringTypenameMap
Definition enscript.c:989
static proto int SetClassVar(Class inst, string varname, int index, void input)
Dynamic write to variable by its name.
proto TValue GetIteratorElement(MapIterator it)
map< Managed, float > TManagedFloatMap
Definition enscript.c:1010
void Debug()
Print all elements in array.
Definition enscript.c:548
proto int Init(T init[])
proto bool Insert(TKey key, TValue value)
Insert new element into hash map.
int GetRandomIndex()
Returns a random index of array.
Definition enscript.c:567
proto bool Find(TKey key, out TValue val)
Search for an element with the given key.
string m_Msg
Definition enscript.c:361
proto native external Type()
Returns typename of object's class.
class array< Class T > PrintString
proto bool Contains(TKey key)
Returns if map contains element with given key.
map< int, vector > TIntVectorMap
Definition enscript.c:981
set< Managed > TManagedSet
Definition enscript.c:806
map< int, ref Managed > TIntManagedRefMap
Definition enscript.c:979
map< typename, typename > TTypeNameTypenameMap
Definition enscript.c:1007
map< ref Managed, Class > TManagedRefClassMap
Definition enscript.c:1022
map< Managed, string > TManagedStringMap
Definition enscript.c:1012
map< Managed, vector > TManagedVectorMap
Definition enscript.c:1017
void ShuffleArray()
Definition enscript.c:670
proto volatile int CallFunctionParams(Class inst, string function, out void returnVal, Class parms)
map< string, Managed > TStringManagedMap
Definition enscript.c:987
map< Class, Managed > TClassManagedMap
Definition enscript.c:996
static proto int RandomInt(int min, int max)
Returns a random int number between and min [inclusive] and max [exclusive].
enum MagnumStableStateID init
override float Get()
void Set(T value, string system="")