Difference between revisions of "Vehicles (programming)"

From Valve Developer Community
Jump to: navigation, search
m (fixed the image extending out of bound)
m
 
(One intermediate revision by the same user not shown)
Line 6: Line 6:
  
 
== In General ==
 
== In General ==
 
+
All vehicles, including the airboat, inherit from the same base classes:
All vehicles, including the airboat inherits from the same base classes:
+
{{Note|Note that abstract interfaces aren't properly represented here as separate nodes. However, classes that inherit from an interface will have it listed under its name along with every other parent class.}}
{{Note|Note that abstract interfaces aren't properly represented here as separate nodes. However classes that inherit from an interface will have it listed under its name along with every other parent classes.}}
 
 
[[File:2011April25_Source_Vehicles_Class_Diagram_ServerSide.png|920px]]
 
[[File:2011April25_Source_Vehicles_Class_Diagram_ServerSide.png|920px]]
  
Line 17: Line 16:
 
*The vehicle physics, [[CFourWheelVehiclePhysics]].
 
*The vehicle physics, [[CFourWheelVehiclePhysics]].
  
=== Prop Driveable entity ===
+
=== prop_vehicle_driveable Entity ===
 
This is the main part of the vehicle, it's the entity that has the actual name of the vehicle and inherits from [[CPropVehicleDriveable]]. Like [[CPropAirboat]].  
 
This is the main part of the vehicle, it's the entity that has the actual name of the vehicle and inherits from [[CPropVehicleDriveable]]. Like [[CPropAirboat]].  
  
Line 23: Line 22:
  
 
=== Server Vehicle ===
 
=== Server Vehicle ===
This class's primary purpose is to handle passenger entry, and sound state, along with acting as a proxy between the Driveable Vehicle, and the physic vehicle. It uses data structures named operating, control, and vehicle params, to share informations between the driveable and physics classes.  
+
This class's primary purpose is to handle passenger entry, and sound state, along with acting as a proxy between the Driveable Vehicle, and the physic vehicle. It uses data structures named operating, control, and vehicle params, to share information between the driveable and physics classes.  
 
Its other purpose is to trigger the loading of the vehicle script data on its creation, along with the creation of the physics vehicle object.
 
Its other purpose is to trigger the loading of the vehicle script data on its creation, along with the creation of the physics vehicle object.
  
 
=== Vehicle Physics ===
 
=== Vehicle Physics ===
This class isn't an entity, it's mostly a wrapper between the driveable and server vehicle entities and the vehicle physics controller([[IPhysicsVehicleController]]). It transmit data from the [[IPhysicsVehicleController]] object (that's in the physics dll) through the GetVehicleOperatingParams() method. It also transmit to the [[IPhysicsVehicleController]] the data in the control params(m_controls) structure.
+
This class isn't an entity, it's mostly a wrapper between the driveable and server vehicle entities and the vehicle physics controller ([[IPhysicsVehicleController]]). It transmits data from the [[IPhysicsVehicleController]] object (that's in the physics DLL) through the <code>GetVehicleOperatingParams()</code> method. It also transmits to the [[IPhysicsVehicleController]] the data in the control params (<code>m_controls</code>) structure.
This object is responsible for loading and parsing the physics vehicle data, through the bool ParseVehicleScript( const char *pScriptName, solid_t &solid, vehicleparams_t &vehicle ) method.
+
This object is responsible for loading and parsing the physics vehicle data, through the <code>bool ParseVehicleScript( const char *pScriptName, solid_t &solid, vehicleparams_t &vehicle )</code> method.
  
 
=== Vehicle Data Structures ===
 
=== Vehicle Data Structures ===
{{todo|Info on the data structures used to transmit physic data and controls data back and forth between the physic dll and the server dll. See ''"..\src\public\vphysics\vehicles.h"'' and ''"..\src\game\server\vehicle_sounds.h"''}}
+
{{todo|Info on the data structures used to transmit physic data and controls data back and forth between the physic DLL and the server DLL. See '''"..\src\public\vphysics\vehicles.h"''' and '''"..\src\game\server\vehicle_sounds.h"'''}}
  
==Vehicles Specifics==
+
== Vehicles Specifics ==
 
=== Vehicles types values ===
 
=== Vehicles types values ===
'' From "..\src\public\vphysics\vehicles.h" ''
+
From '''"..\src\public\vphysics\vehicles.h"'''
<syntaxhighlight lang="cpp">
+
<source lang=cpp>
 
#define VEHICLE_TYPE_CAR_WHEELS (1<<0)
 
#define VEHICLE_TYPE_CAR_WHEELS (1<<0)
 
#define VEHICLE_TYPE_CAR_RAYCAST (1<<1)
 
#define VEHICLE_TYPE_CAR_RAYCAST (1<<1)
 
#define VEHICLE_TYPE_JETSKI_RAYCAST (1<<2)
 
#define VEHICLE_TYPE_JETSKI_RAYCAST (1<<2)
#define VEHICLE_TYPE_AIRBOAT_RAYCAST         (1<<3)
+
#define VEHICLE_TYPE_AIRBOAT_RAYCAST (1<<3)
</syntaxhighlight>
+
</source>
  
 
=== The Buggy and Jalopy ===
 
=== The Buggy and Jalopy ===
 
 
[[Image:Buggy.jpg|thumb|none|100px]]
 
[[Image:Buggy.jpg|thumb|none|100px]]
 
The buggy
 
The buggy
  
{{todo|buggy and jalopy specifics.}}
+
{{todo|Buggy and Jalopy specifics.}}
  
 
=== The Airboat ===
 
=== The Airboat ===
 
[[Image:prop_vehicle_airboat.jpg|thumb|none|100px]]
 
[[Image:prop_vehicle_airboat.jpg|thumb|none|100px]]
The airboat uses the same physical entity as the buggy [[CFourWheelVehiclePhysics]]. But it change the vehicle type value to VEHICLE_TYPE_AIRBOAT_RAYCAST.
+
The airboat uses the same physical entity as the buggy [[CFourWheelVehiclePhysics]]. But it changes the vehicle type value to <code>VEHICLE_TYPE_AIRBOAT_RAYCAST</code>.
  
 
{{todo|airboat specifics.}}
 
{{todo|airboat specifics.}}
Line 60: Line 58:
 
{{todo|describe what goes on when the player uses a vehicle.}}
 
{{todo|describe what goes on when the player uses a vehicle.}}
  
 
+
== Vehicles Components ==
==Vehicles Components==
 
 
=== Interfaces ===
 
=== Interfaces ===
 
* [[IClientVehicle]] - Client Side
 
* [[IClientVehicle]] - Client Side
Line 69: Line 66:
 
* [[INPCPassengerCarrier]]
 
* [[INPCPassengerCarrier]]
 
* [[IPhysicsVehicleController]]
 
* [[IPhysicsVehicleController]]
 +
 
=== Classes ===
 
=== Classes ===
 
*Server:
 
*Server:
Line 80: Line 78:
  
 
== Additional Help ==
 
== Additional Help ==
 
 
===Source code:===
 
===Source code:===
 
==== Multi-passenger vehicles ====
 
==== Multi-passenger vehicles ====
* [[Jurassic Rage]] coding team has released multipassenger vehicle code :
+
* The [[Jurassic Rage]] coding team has released their multi-passenger vehicle code:
**[http://web.archive.org/web/20090227184301/http://www.chatbear.com/board.plm?a=viewthread&t=573,1125931904,10177&id=901881&b=4991&v=flatold Here is the forum thread] (Internet Archive link, the files weren't archived unfortunately).
+
** [https://web.archive.org/web/20090227184301/http://www.chatbear.com/board.plm?a=viewthread&t=573,1125931904,10177&id=901881&b=4991&v=flatold Here is the forum thread (archived)]
**[https://docs.google.com/file/d/0B2UEgCeQJPISdHhHN0RZSVU4Z00/edit?usp=sharing Here are the files](.7z). <!--I couldn't fin a reliable host, so I used my google drive. But ideally, would there be a way to upload this to the wiki ?-->
+
** [http://web.archive.org/web/20080325223407/http://www.users.on.net/~emlesz/Al/PassengerVehicle Here are the files (archived)] [[https://docs.google.com/file/d/0B2UEgCeQJPISdHhHN0RZSVU4Z00/edit?usp=sharing mirror #1]]
 
* [[Multipassenger Vehicle Abstract]]
 
* [[Multipassenger Vehicle Abstract]]
  
 
==== Pilotable code ====
 
==== Pilotable code ====
* [[User:TheQuartz|TheQuartz]] has released the Strider, Helicopter, and APC Source Code on his [http://www.joluis.com/archives/2005/08/strider_mod.html blog] or in [http://translate.google.com/translate?u=http%3A%2F%2Fwww.joluis.com%2Farchives%2F2005%2F08%2Fstrider_mod.html&langpair=es%7Cen&hl=en&ie=UTF-8&oe=UTF-8&prev=%2Flanguage_tools english]
+
* [[User:TheQuartz|TheQuartz]], creator of the [[Pilotable Strider Mod]], has released the "Strider, Helicopter, and APC" source code:
 +
** [https://web.archive.org/web/20090228053802/http://www.joluis.com/archives/2005/08/strider_mod.html Here is the blog post (archived)]
 +
** [https://web.archive.org/web/20051214234801/http://www.joluis.com/zips/PilotableCode.zip Here are the files (archived)]
  
 
=== Fixes: ===
 
=== Fixes: ===
Line 95: Line 94:
 
* Some information on fixing source vehicle code for use in Multiplayer can be found [[Multiplayer Vehicle Fixes|here]].
 
* Some information on fixing source vehicle code for use in Multiplayer can be found [[Multiplayer Vehicle Fixes|here]].
  
==== HL2DM Vehicle fix ====
+
==== HL2DM vehicle fix ====
 
* A partial fix to make vehicles predicted and work in HL2DM can be found [[HL2DM Vehicle Fix|here]].
 
* A partial fix to make vehicles predicted and work in HL2DM can be found [[HL2DM Vehicle Fix|here]].
  
 
== External links ==
 
== External links ==
 
* [http://www.design3.com/source-engine/coding/source-vehicle-programming Design3 Vehicle Programming Video Tutorials]
 
* [http://www.design3.com/source-engine/coding/source-vehicle-programming Design3 Vehicle Programming Video Tutorials]

Latest revision as of 21:22, 22 March 2021

Abstract Coding series Discuss your thoughts - Help us develop the articles or ideas you want

Levels & XP | Optimization | Procedural Textures | Sights & Sniperrifles | Special effects | Vehicles | Threads | Save Game Files | Night Vision | Non-offensive Weapons | Dynamic Weapon Spawns | Dynamic Weapon Spawns (Advanced)

This article is meant to give an in-depth analysis of the vehicles in Source and to provide the necessary information to create and modify source vehicles.


In General

All vehicles, including the airboat, inherit from the same base classes:

Note.png Note: Note that abstract interfaces aren't properly represented here as separate nodes. However, classes that inherit from an interface will have it listed under its name along with every other parent class.

2011April25 Source Vehicles Class Diagram ServerSide.png


At the end of the day, the typical source vehicle is made up of 3 parts:

prop_vehicle_driveable Entity

This is the main part of the vehicle, it's the entity that has the actual name of the vehicle and inherits from CPropVehicleDriveable. Like CPropAirboat.

This entity doesn't handle passengers or passengers entry, since the code the player used to ride vehicles needs a IServerVehicle. That's why there is a member pointer on a CFourWheelsServerVehicle stored in the instance.

Server Vehicle

This class's primary purpose is to handle passenger entry, and sound state, along with acting as a proxy between the Driveable Vehicle, and the physic vehicle. It uses data structures named operating, control, and vehicle params, to share information between the driveable and physics classes. Its other purpose is to trigger the loading of the vehicle script data on its creation, along with the creation of the physics vehicle object.

Vehicle Physics

This class isn't an entity, it's mostly a wrapper between the driveable and server vehicle entities and the vehicle physics controller (IPhysicsVehicleController). It transmits data from the IPhysicsVehicleController object (that's in the physics DLL) through the GetVehicleOperatingParams() method. It also transmits to the IPhysicsVehicleController the data in the control params (m_controls) structure. This object is responsible for loading and parsing the physics vehicle data, through the bool ParseVehicleScript( const char *pScriptName, solid_t &solid, vehicleparams_t &vehicle ) method.

Vehicle Data Structures

To do: Info on the data structures used to transmit physic data and controls data back and forth between the physic DLL and the server DLL. See "..\src\public\vphysics\vehicles.h" and "..\src\game\server\vehicle_sounds.h"

Vehicles Specifics

Vehicles types values

From "..\src\public\vphysics\vehicles.h"

#define VEHICLE_TYPE_CAR_WHEELS			(1<<0)
#define VEHICLE_TYPE_CAR_RAYCAST		(1<<1)
#define VEHICLE_TYPE_JETSKI_RAYCAST		(1<<2)
#define VEHICLE_TYPE_AIRBOAT_RAYCAST	(1<<3)

The Buggy and Jalopy

Buggy.jpg

The buggy

To do: Buggy and Jalopy specifics.

The Airboat

Prop vehicle airboat.jpg

The airboat uses the same physical entity as the buggy CFourWheelVehiclePhysics. But it changes the vehicle type value to VEHICLE_TYPE_AIRBOAT_RAYCAST.

To do: airboat specifics.

Player Interaction

To do: describe what goes on when the player uses a vehicle.

Vehicles Components

Interfaces

Classes

Additional Help

Source code:

Multi-passenger vehicles

Pilotable code

Fixes:

Half-Life 2 SDK vehicles

  • Some information on fixing source vehicle code for use in Multiplayer can be found here.

HL2DM vehicle fix

  • A partial fix to make vehicles predicted and work in HL2DM can be found here.

External links