ZoriaRPG

std_functions_binary.zh

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

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×