Server Help

Bot Questions - S2C weapons packet - weapon info

Anonymous - Sun Aug 16, 2009 4:25 pm
Post subject: S2C weapons packet - weapon info
I am using two sources to get info about how S2C packets are constructed.

1) http://d1st0rt.sscentral.com/packets.html
2) ASSS 1.4.4 source


Inside the packets that send weapons info, there are conflicting constructions between my sources. ASSS has 2 bits being "shrap level", but d1st0rt's page says those 2 bits are indicate "Is Bomb" and is "EMP".
Are these saying the same thing with different wording, or are they contradictory?

Anyone mind explaining what those 2 particular bit indicate?


Code: Show/Hide
Weapon type             :5 bits
Weapon level            :2 bits
Bouncing (Boolean)      :1 bit
EMP (Boolean)           :1 bit <<---
Is bomb (Boolean)       :1 bit <<---
Shrapnel                :5 bits
Alternate (Boolean)     :1 bit
Code: Show/Hide
struct Weapons /* 2 bytes */
{
   u16 type          : 5;
   u16 level         : 2;
   u16 shrapbouncing : 1;
   u16 shraplevel    : 2; <<---
   u16 shrap         : 5;
   u16 alternate     : 1;
};


Initrd.gz - Sun Aug 16, 2009 4:28 pm
Post subject: Re: S2C weapons packet - weapon info
grazzhoppa (nopswd) wrote:

Code: Show/Hide
Weapon type             :5 bits
Weapon level            :2 bits
Bouncing (Boolean)      :1 bit
EMP (Boolean)           :1 bit <<---
Is bomb (Boolean)       :1 bit <<---
Shrapnel                :5 bits
Alternate (Boolean)     :1 bit

If emp is 1, the bomb is an EMP bomb
If Is bomb is 0 (i think) then the bomb is actually a mine, not a bomb

grazzhoppa (nopswd) wrote:
Code: Show/Hide
struct Weapons /* 2 bytes */
{
   u16 type          : 5;
   u16 level         : 2;
   u16 shrapbouncing : 1;
   u16 shraplevel    : 2; <<---
   u16 shrap         : 5;
   u16 alternate     : 1;
};


What level the shrapnel is on the bomb. Say the player firing the bomb has L2 bullets. Then shraplevel would be 2
Anonymous - Sun Aug 16, 2009 4:46 pm
Post subject:
Quote:
If emp is 1, the bomb is an EMP bomb
...What level the shrapnel is on the bomb. Say the player firing the bomb has L2 bullets. Then shraplevel would be 2

Those 2 structures are proposed for the same type of packet. So does the 9th bit indicate the EMP status of the bomb, or does it is part of the shrap level? It can't be both.

Quote:
If Is bomb is 0 (i think) then the bomb is actually a mine, not a bomb

Doesn't the "Alternate" bit indicate whether it's a mine rather than a bomb? So the bit indicating "is a bomb" would seem superfluous.
Bak - Sun Aug 16, 2009 4:47 pm
Post subject:
I think you misunderstood, those are the same struct!

here's what I got from mervbot:
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
};


The asss version is right. Bomb is a property of the weapon type, EMP is a settings property of the ship doing the firing
Anonymous - Sun Aug 16, 2009 4:52 pm
Post subject:
thank you.

Another question:
Both ASSS and mervbot use unsigned 2 byte ints for that struct. Is there a technical reason for that? Why not use unsigned 1 byte ints?
Dr Brain - Sun Aug 16, 2009 5:06 pm
Post subject:
Mostly because two bytes of information won't fit into one byte.
Anonymous - Sun Aug 16, 2009 5:16 pm
Post subject:
Quote:
Mostly because two bytes of information won't fit into one byte.

A yes/no true/false 0/1 value can fit into 1 byte. There are a few of those in that struct. The highest value in that struct is 32, so each field could fit into just 1 byte instead of 2 bytes.

Another way to ask the same question: Why not use a struct like this with unisigned 1 byte integers (uint8) rather than (uint16)?
Code: Show/Hide

struct WEAPONS_ {
    uint8_t type      : 5;
    uint8_t level     : 2;
    uint8_t shrap_bounce : 1;
    uint8_t shrap_level  : 2; /* bullet/gun level */
    uint8_t shrap     : 5;
    uint8_t alternate : 1; /* Bombs -> Mines or Bullets -> Multifire */
}

Dr Brain - Sun Aug 16, 2009 5:21 pm
Post subject:
You don't understand how bitfields work. I don't blame you, they're not seen much outside of embedded and network code. The : afterwards makes it use that many bits. Total all of the #s and you'll get 16, meaning the type needs to have two bytes.

The ENTIRE struct takes 2 bytes, not 12.
Samapico - Sun Aug 16, 2009 9:18 pm
Post subject:
Yeah, so all of the uint16 fields actually use THE SAME uint16
Anonymous - Sun Aug 16, 2009 9:44 pm
Post subject:
I see now. thanks!
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group