Code: Show/Hide #define WPN_NONE 0x00
#define WPN_BULLET 0x01 #define WPN_BOUNCINGBULLET 0x02 #define WPN_BOMB 0x03 #define WPN_PROXBOMB 0x04 #define WPN_REPEL 0x05 #define WPN_DECOY 0x06 #define WPN_BURST 0x07 #define WPN_THOR 0x08 typedef struct WPN_ { WORD type : 5; WORD level : 2; WORD shrapbounce : 1; WORD shraplevel : 2; WORD shrap : 5; WORD multimine : 1; } WPN; |
Code: Show/Hide public WeaponFired( ByteArray array ){
super( array ); short wepinfo = getWeaponInfo(); m_weaponType = wepinfo & 0x001f; m_weaponLevel = ((wepinfo & 0x0060)>>5) + 1; m_weaponBouncyShrap = ((wepinfo & 0x0080)>>7)==1; m_weaponShrapLevel = ((wepinfo & 0x0300)>>8) + 1; m_weaponShrapCount = (wepinfo & 0x7c00)>>10; m_weaponAlternative = (wepinfo & 0x8000)>>15==1; } |
Code: Show/Hide public static int getBitFragment(byte b, int startIndex, int endIndex)
{ b &= (int)Math.pow(2,8 - startIndex); return (b >> (8 - endIndex)); } |
Code: Show/Hide union weaponInfo { struct { Uint16 type : 5; // enum Projectile_Types Uint16 level : 2; // Only for bombs/bullets Uint16 shrapBounce : 1; // Bouncing shrapnel? Uint16 shrapLevel : 2; // Shrapnel level 0..3 Uint16 shrapCount : 5; // 0-31 Uint16 fireType : 1; // Bombs -> Mines, Bullets -> Multifire }; Uint16 n; }; // Weapon types for weaponInfo.type enum Projectile_Types { // Seen "in the wild" PROJ_None, PROJ_Bullet, PROJ_BBullet, PROJ_Bomb, PROJ_PBomb, PROJ_Repel, PROJ_Decoy, PROJ_Burst, PROJ_Thor, // Internal to the bot PROJ_InactiveBullet, PROJ_Shrapnel }; // Weapon levels for weaponInfo.level enum Weapon_Levels { LVL_One, LVL_Two, LVL_Three, LVL_Four }; |
Code: Show/Hide /**
* get the bit fragment from startIndex to endIndex * @param extractFrom the byte to extract from * @param startIndex the inclusive leftbound index: 1234 5678 * @param endIndex the inclusive rightbound index 1234 5678 and > startIndex * @return the int extracted from the requested bits */ public static int getBitFragment(byte extractFrom, int startIndex, int endIndex) { int shift = 8 - endIndex; int numBits = endIndex - startIndex + 1; byte mask = (byte)((0x01 << numBits) - 1); return (extractFrom >> shift) & mask; } |