Tire states are used by natives such as GetVehicleDamageStatus and UpdateVehicleDamageStatus.
Each tire has two states - popped and not popped. Binary digits (bits) also have two states - 0 and 1. A technique called bit masking is used to store more information in less memory. A 1 represents a popped tire, and a 0 represents a tire that isn't popped. For example, '0101' - two tires are popped, two are not.
Bitwise operators can be used to work with bit masking.
Which bit stores what?
The tyre states are grouped into a set of four bits (or a nibble), and each bit represents a single tyre. A value of 1 means the tire is popped, and a value of 0 means the tire is inflated. Here you can see how each bit is mapped to an individual tire:
- The first bit stores the state of the back-right tire for 4-wheeled vehicles, and the back tire for 2-wheeled vehicles (bikes).
- The second bit stores the state of the front-right tire for 4-wheeled vehicles, and the front tire for 2-wheeled vehicles (bikes).
- The third bit stores the state of the back-left tire for 4-wheeled vehicles. It is not used for 2-wheeled vehicles.
- The fourth bit stores the state of the front-left tire for 4-wheeled vehicles. It is not used for 2-wheeled vehicles.
Here is a visual representation of the tire states. Vehicle viewed from a top-down perspective, the top is the front of the vehicle.
o = inflated tire
x = popped tire
4 binary bits for 4-wheeled vehicles: (FL)(BL)(FR)(BR) (Front-Left, Back-Left, Front-Right and Back-Right).
o-o | | o-o
o-o | | o-x
o-x | | o-o
o-x | | o-x
o-o | | x-o
o-o | | x-x
o-x | | x-o
o-x | | x-x
x-o | | o-o
x-o | | o-x
x-x | | o-o
x-x | | o-x
x-o | | x-o
x-o | | x-x
x-x | | x-o
x-x | | x-x
After 15 the values are repeated, so 16 is 0, 17 is 1 and so on.
Bike viewed from a top-down perspective, the top is the front of the bike.
2 binary bits for 2-wheeled vehicles: (F)(B) (Front and Back)
o | o
o | x
x | o
x | x
After 3 the values are repeated, so 4 is 0, 5 is 1 and so on.
To pop the back two tires of a vehicle (with 4 wheels) while keeping the front the same state:
new Panels, Doors, Lights, Tires; GetVehicleDamageStatus(vehicleid, Panels, Doors, Lights, Tires); UpdateVehicleDamageStatus(vehicleid, Panels, Doors, Lights, (Tires | 0b0101));