Advertisement
ZoriaRPG

ZScript: BinaryFlags.zh

Nov 27th, 2016
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.75 KB | None | 0 0
  1. //BinaryFlags.zh
  2.  
  3.  
  4. //Set or Get binary flags for any pointer type.
  5.  
  6. //NPC->Misc
  7. //These set or get a flag from an npc's ->Misc array.
  8. //Call as: SetFlag(npc_pointer, misc_index, flag, true/false)
  9.  
  10. //Example:
  11. ////npc goblin = Screen->LoadNPC(4);
  12. // const int MY_FLAG = 0100b;
  13. // SetFlag(goblin, 6, MY_FLAG, true)
  14. void SetFlag(npc n, int index, int flag, bool state){
  15.     if ( state ) n->Misc[index] |= flag;
  16.     else n->Misc[index] &= ~flag;
  17. }
  18.  
  19. //This returns the flag from the misc index of an npc
  20. //Call as getFlag(npc_pointer, index, flag)
  21. //Example:
  22. ////npc goblin = Screen->LoadNPC(4);
  23. // const int MY_FLAG = 0100b;
  24. // if ( GetFlag(goblin, 6, MY_FLAG ) //The flag is true, do something.
  25. bool GetFlag(npc n, int index, int flag) {
  26.     return ( n->Misc[index] & flag ) != 0;
  27. }
  28.  
  29. //The same, for lweapons
  30. void SetFlag(lweapon n, int index, int flag, bool state){
  31.     if ( state ) n->Misc[index] |= flag;
  32.     else n->Misc[index] &= ~flag;
  33. }
  34.  
  35. bool GetFlag(lweapon n, int index, int flag) {
  36.     return ( n->Misc[index] & flag ) != 0;
  37. }
  38.  
  39. //The same, for eweapons
  40. void SetFlag(eweapon n, int index, int flag, bool state){
  41.     if ( state ) n->Misc[index] |= flag;
  42.     else n->Misc[index] &= ~flag;
  43. }
  44.  
  45. bool GetFlag(eweapon n, int index, int flag) {
  46.     return ( n->Misc[index] & flag ) != 0;
  47. }
  48.  
  49. //The same, for items
  50. void SetFlag(item n, int index, int flag, bool state){
  51.     if ( state ) n->Misc[index] |= flag;
  52.     else n->Misc[index] &= ~flag;
  53. }
  54.  
  55. bool GetFlag(item n, int index, int flag) {
  56.     return ( n->Misc[index] & flag ) != 0;
  57. }
  58.  
  59. //The same, for ffcs
  60. void SetFlag(ffc n, int index, int flag, bool state){
  61.     if ( state ) n->Misc[index] |= flag;
  62.     else n->Misc[index] &= ~flag;
  63. }
  64.  
  65. bool GetFlag(ffc n, int index, int flag) {
  66.     return ( n->Misc[index] & flag ) != 0;
  67. }
  68.  
  69. //This will set a binary flag in any array index.
  70. //Specify the array identifier, index of the array, flag, and state
  71. //Example:
  72. // int arr[24];
  73. // const int MY_FLAG = 0100b;
  74. // SetFlag(arr, 12, MY_FLAG, true)
  75. void SetFlag(int n, int index, int flag, bool state){
  76.     if ( state ) n[index] |= flag;
  77.     else n[index] &= ~flag;
  78. }
  79.  
  80. bool GetFlag(int n, int index, int flag) {
  81.     return ( n[index] & flag ) != 0;
  82. }
  83.  
  84. //This will set a binary flag in a Screen->D array index.
  85. //Example:
  86. // const int MY_FLAG = 0100b;
  87. // SetScreenDFlag(5, MY_FLAG, true) ; //Sets Screen->D[6] with a binary flag
  88. void SetScreenDFlag(int index, int flag, bool state){
  89.     if ( state ) Screen->D[index] |= flag;
  90.     else Screen->D[index] &= ~flag;
  91. }
  92.  
  93. //Gets the binary flag from a Screen->D index
  94. // Example:
  95. // if ( GetScreenDFlag(6, MY_FLAG) ) // Evaluates true if this flag is set for Screen->D[6]
  96. bool GetScreenDFlag(int index, int flag) {
  97.     return ( Screen->D[index] & flag ) != 0;
  98. }
  99.  
  100. //! We need DMAPScreenD
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement