Cars
Cars is a bit of a misnomoner, as the car system encompasses any type of vehicle - car, bike, tank, helicopter, boat, train, etc. Just as there are many types of ped, there are many types of 'car', all of which are defined by the current mod via textual car definition files and car sprite files.
Car types
Each car type has the following properties (defined as part of the cartype struct in cartypes.h):
General stats
- Display name
- Sprite set
- Bounding box size
- Monetary value (if in pristine condition)
- Vehicle type (car, boat, etc.)
- Reference count
- Starting engine health & vehicle armour values
- Flags
Doors and seating
Between the car definition file and the sprite file, the locations of every seat and door in the car are defined. In addition, seats are arranged into aisles; each aisle contains a number of seats, and up to two doors (one door at each end of the aisle). It is impossible to move between aisles when sat in a car, so if you enter using a door attached to aisle 1, you are forced to sit in a seat in aisle 1, and leave via a door attached to aisle 1. Seat number 0 is always considered to be the drivers seat.
Appearance
Just like peds, cars utilise 256 colour palettes with recolour blocks. Cars can have multiple palettes per sprite set, and each palette has two recolour blocks. This allows for both palette hacking of complex logos onto cars, and regular recolouring. Each car type also has a 'fullbright count', indicating how many of the palette entries should not be recoloured as part of the day-night cycle. This value is specified using the FULLBRIGHT attribute in the cardef file.
Ownership
This area contains information about what factions and ped types normally drive the car (or are able to drive the car at all). However this is still subject to change as the new faction system and ped/car spawning system evolves.
Turrets and trailers
Some vehicles have turrets mounted on them; this area of the definition gives the coordinate where the turret should be displayed. Likewise, some vehicles act as trailers, or can tow a trailer (or both). This section also gives the coordinates of these tow points. Some vehicles can also act as car transporters, i.e. they have another vehicle glued ontop of them. This section also gives the coordinates for that location (although currently a vehicle cannot act as a car transporter and tow a vehicle).
Handling stats
This is all a bit work-in-progress, since car physics is an evolving area of the game. (Potentially) useful physics docs: 1 2 3 4 5 6 7
This section contains the offsets of the front and rear axles, the mass of the car, the tyre grip, rolling resistance, drag, inertia, and (front) wheel turn angle.
Sounds
This contains pointers to the samples for the car engine noise, horn noise, siren noise, turret turn noise, tyre screech, as well as the radio style (ambient, music, emergency)
Car sprites
Car sprites consist of a set of 'delta' images that are overlayed ontop of a base image. This is the same technique used by GTA 1 & 2. This allows multiple areas of the car to appear damaged without having to draw individual sprites for all different combinations, or wasting memory on those extra images. For a given car in the world, a cached copy of the composite image is used; this is stored in 16bpp format ready for rendering. This can save a great deal of time during screen rendering, as each car is only likely to change appearance less than once every hundred frames. The composite image is produced by rendering deltas in the following order:
- The floor image; i.e. the chassis of the car without any bodywork
- Any pedestrians riding in the car are then rendered ontop. If no floor sprite is present, the car is assumed to have a covered roof, in which case pedestrians are only rendered if they are not fully in their seats.
- The body image; i.e. all the roof and windows.
- Any lights are rendered - flashing headlights from the car alarm going off, flashing emergency lights, etc.
- Damage zones are rendered
- Partially open doors are rendered
The source sprites make use of a 'force transparent' colour, which allows dents to be placed in the bodywork by forcing the corresponding pixel of the composite image to be transparent.
If the car has a turret, a cached image of the turret is also stored. Although the turret isn't affected by damage deltas, it is affected by recolour blocks, so storing a cached image is a lot simpler than rendering from an 8bpp palettised image every frame.
Turret and flashing light delta usage
Ordinarily the turret delta is used for a rotating turret, but it can also be placed on the car in a fixed orientation via the RECOLOUR cardef specification (Any other delta can be placed on the car in this manner also). This is useful for generating alternate versions of cars, e.g. convertibles, cars with extra armour, etc.
Several different uses of the flashing lights are available, representing each (sensible) flash pattern. E.g. just a single delta constantly on, or alternating between the two deltas, or alternating between one on and none on, etc. The behaviour of the deltas is specified in the cardef file.
TODO:
MUST-CODE: MED: Do better car physics - no climbing steep slopes
MUST-DOCS: LONG: Engine overheating, fire, etc. mechanics. Also update code to suit.
CODE: UNKNOWN: Fix movement - floating up/down slopes
DOCS: UNKNOWN: Multiped tanks? Can animate the legs using rotating sprites, but would there be any point to multipeds in a world made of giant lego blocks? Maybe they can climb 45 degree slopes?
CODE: UNKNOWN: Allow you to hear the radio of passing cars ala GTA 1? Would need generic sounds for each music type, and integration into radio system to different radio files play the correct sounds for the current station the car is tuned to
DOCS: UNKNOWN: Armoured cars - some original designs mention attaching armour/weapons to cars. This could be done by extra deltas, or by silently switching to different car type. Also, if armour is an addon, how would it work? Simple one-off armour boost, or give invulnerability to certain damage types, or modify the damage code to reduce damage by a certain percentage? If I wanted, I could make it a global thing, where you can get armour attached if the armour delta exists, and it would give similar benefits to all vehicles. The real question is how deep I want the gameplay to go - heavy car reliance/customisation (stuff like fuel tanks etc.) where your car is for life, or remain fairly arcadey where you swap cars every few minutes or so?
MUST-CODE: QUICK: Add script commands to set (and get?) which (damage?) deltas are in use
CODE: QUICK: Fix code to remove dead cars which don't have corpse sprites?
CODE: QUICK: Fix car-car collisions to apply damage deltas correctly (modified bbox_intersect that returns intersection points?)
MUST-DOCS: MED: Car bomb mechanic, code
MUST-CODE: QUICK: Redo car-wall collisions. Need to discover what direction to reflect the velocity in; i.e. check one step to the north/south and one step to the east/west for walls. Also need to perform impact damage only for the amount of force required to reflect the car (i.e. x, y, or both velocities)
MUST-DOCS: QUICK: Decide on engine overheating mechanic. Engine produces heat based around RPM or torque? Or both? This then gets added to temperature counter; radiator causes certain max amount of temperature to dissipate each second. If temperature > max, start damaging engine (and steaming?)
MUST-CODE: MED: Improve car-car collisions. Proper rigid body stuff - make it alter the rotational velocity, etc. Maybe also introduce force that helps to seperate cars which are stuck brushing against each other.
CODE: MED: Introduce multiple gun mount coordinates for cars. One set of coords per weapon, with flags to say whether on turret or base and whether single or dual.
MUST-CODE: MED: Better track deadend handling for trains. Need to derail if going past end of track too fast, need to prevent bunching of carriages when reversing.
MUST-CODE: QUICK: Add 'stiffness' attrib to cars that determines how much force is needed to trigger damage deltas
MUST-CODE: MED: Tweak car damage code so that reasonable warning is given that the car is about to explode. Leak some damage to the engine, or add onscreen armour indicators, or increase engine HP significantly, etc.
???
Profit!