Author Topic: GetAlignment as a bitwise return  (Read 461 times)

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
GetAlignment as a bitwise return
« Reply #15 on: December 19, 2011, 08:12:29 pm »


               This is the version of it and constants I ended up going with.  The specific alignment ones weren't really needed, but they do simplify checking.

const int _ALIGNMENT_ALL            = 1;
const int _ALIGNMENT_NEUTRAL        = 2;
const int _ALIGNMENT_LAWFUL         = 4;
const int _ALIGNMENT_CHAOTIC        = 8;
const int _ALIGNMENT_GOOD           = 16;
const int _ALIGNMENT_EVIL           = 32;
const int _ALIGNMENT_LAWFUL_NEUTRAL  = 6;
const int _ALIGNMENT_CHAOTIC_NEUTRAL = 10;
const int _ALIGNMENT_NEUTRAL_GOOD    = 18;
const int _ALIGNMENT_LAWFUL_GOOD     = 20;
const int _ALIGNMENT_CHAOTIC_GOOD    = 24;
const int _ALIGNMENT_NEUTRAL_EVIL    = 34;
const int _ALIGNMENT_LAWFUL_EVIL     = 36;
const int _ALIGNMENT_CHAOTIC_EVIL    = 40;
// Code by Lightfoot8
//// Returns a bitwise value, using _ALIGNMENT_* constants.
int _GetAlignment (object oTarget = OBJECT_SELF)
{
 int nAlignment;
 nAlignment = 1 << GetAlignmentLawChaos  (oTarget);
 nAlignment |= 1 << GetAlignmentGoodEvil (oTarget);
 return nAlignment;
}


  Checking for good would simply be:
if (_GetAlignment () & _ALIGNMENT_GOOD)

Checking for !good is slightly more annoying, sice it requires another set of nested brackets:
if (!(_GetAlignment () & _ALIGNMENT_GOOD))

  Overall, it does everything I needed, and adds the versatility of checking for a specific alignment, or a general range.  Specific alignments can be checked with a standard == in addition to bit checks.
               
               

               


                     Modifié par Failed.Bard, 19 décembre 2011 - 08:12 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
GetAlignment as a bitwise return
« Reply #16 on: December 19, 2011, 09:12:14 pm »


               

Failed.Bard wrote...

Checking for !good is slightly more annoying, sice it requires another set of nested brackets:
if (!(_GetAlignment () & _ALIGNMENT_GOOD))


Inverting the Alignment bitwize before the AND should let you get rid for the extra set.

if ( ~_GetAlignment () & _ALIGNMENT_GOOD)
               
               

               
            

Legacy_wyldhunt1

  • Sr. Member
  • ****
  • Posts: 443
  • Karma: +0/-0
GetAlignment as a bitwise return
« Reply #17 on: December 19, 2011, 09:35:04 pm »


               <Bookmarks Thread>

'Twould appear that there is still a lot for me to learn about bitwise operations.
(I get what's happening in the background, but I lack a list of bitwise operands that work in Aurora)
You are a bit-flipping master, Lightfoot8. '<img'>
               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
GetAlignment as a bitwise return
« Reply #18 on: December 19, 2011, 11:22:20 pm »


               

Failed.Bard wrote...
const int _ALIGNMENT_ALL            = 1;
const int _ALIGNMENT_NEUTRAL        = 2;

  Overall, it does everything I needed, and adds the versatility of checking for a specific alignment, or a general range.  Specific alignments can be checked with a standard == in addition to bit checks.


So _ALIGNMENT_ALL | _ALIGNMENT_NEUTRAL checks the neutral cross, not neutral on a defined axis.  Not convinced that this is more functional than a 4-bit (where you can do x ^ (~ TN) to check the neutral cross)) but it definitely manages to work with undefined values well.