Swarm C++ Code Overview: Difference between revisions
Jump to navigation
Jump to search
Note:See Swarm SDK Create a Mod for instructions on compiling the Alien Swarm source code and setting up Visual Studio.
(Created page with '== Compiling the source code == See Swarm SDK Create a Mod for instructions on compiling the Alien Swarm source code and setting up Visual Studio. == Alien Swarm classes =…') |
m (Nesciuse moved page Swarm C++ Code Overview/en to Swarm C++ Code Overview without leaving a redirect: Move en subpage to basepage) |
||
(10 intermediate revisions by 7 users not shown) | |||
Line 1: | Line 1: | ||
{{LanguageBar}} | |||
{{ASW topicon}}{{source topicon}} | |||
See [[Swarm SDK Create a Mod]] for instructions on compiling the Alien Swarm source code and setting up Visual Studio. | {{note|See [[Swarm SDK Create a Mod]] for instructions on compiling the Alien Swarm source code and setting up Visual Studio. }} | ||
== Alien Swarm | == Alien Swarm Classes == | ||
Here is an overview of the major C++ classes in Alien Swarm. Most of the Alien Swarm <code>.cpp/.h</code> files begin with <code>asw_</code>. The class names begin with <code>CASW_</code> for server classes and <code>C_ASW_</code> for networked client classes. | |||
Here is an overview of the major C++ classes in Alien Swarm. Most of the Alien Swarm .cpp/.h files begin with | ;<code>CASW_Player</code> | ||
:This is the Alien Swarm player class. Unlike most {{Source|2}} engine games, the player in Alien Swarm is an invisible commander entity. It does not move. If the player is currently controlling a marine, then calling the <code>GetMarine()</code> method on the player will return it. | |||
;CASW_Player | ;<code>CASW_Marine</code> | ||
:This is the Alien Swarm player class. Unlike most Source engine games, the player in Alien Swarm is an invisible commander entity. It does not move. If the player is currently controlling a marine, then calling the GetMarine() method on the player will return it. | :This entity is the actual marine you see running around the levels and shooting aliens. It is derived from the <code>CAI_BaseNPC</code> class. When a marine is inhabited it means he is being directly controlled by a <code>CASW_Player</code>. When a marine is under direct control, his AI is disabled, he becomes a predicted entity and the player's input will drive the marine around. | ||
;CASW_Marine | |||
:This entity is the actual marine you see running around the levels and shooting aliens. It is derived from the CAI_BaseNPC class. When a marine is inhabited it means he is being directly controlled by a CASW_Player. When a marine is under direct control, his AI is disabled, he becomes a predicted entity and the player's input will drive the marine around. | |||
::Useful methods: | ::Useful methods: | ||
:::GetCommander() - returns the CASW_Player who owns this marine. | :::<code>GetCommander()</code> - returns the <code>CASW_Player</code> who owns this marine. | ||
:::GetMarineResource() - returns the associated CASW_Marine_Resource. | :::<code>GetMarineResource()</code> - returns the associated <code>CASW_Marine_Resource</code>. | ||
:::GetASWWeapon( nSlot ) - returns the weapon equipped in that slot (where the inventory slot is either ASW_INVENTORY_SLOT_PRIMARY, ASW_INVENTORY_SLOT_SECONDARY or ASW_INVENTORY_SLOT_EXTRA). | :::<code>GetASWWeapon( nSlot )</code> - returns the weapon equipped in that slot (where the inventory slot is either <code>ASW_INVENTORY_SLOT_PRIMARY</code>, <code>ASW_INVENTORY_SLOT_SECONDARY</code>, or <code>ASW_INVENTORY_SLOT_EXTRA</code>). | ||
:::GetMarineProfile() - returns the profile for this marine. | :::<code>GetMarineProfile()</code> - returns the profile for this marine. | ||
:::IsInhabited() - returns true if a player is controlling the marine, false if it's under AI control. | :::<code>IsInhabited()</code> - returns true if a player is controlling the marine, false if it's under AI control. | ||
;<code>CASW_Marine_Resource</code>:This class holds some networked data about each marine (similar to a player resource in other Source engine games). There is one of these for every selected marine in the game. The marine resource exists as soon as the marine is selected in the briefing (before the <code>asw_marine</code> entity is created). The marine resource also stays around after the marine is killed and the marine entity is deleted. | |||
;CASW_Marine_Resource | |||
:This class holds some networked data about each marine (similar to a player resource in other Source engine games). There is one of these for every selected marine in the game. The marine resource exists as soon as the marine is selected in the briefing (before the asw_marine entity is created). The marine resource also stays around after the marine is killed and the marine entity is deleted. | |||
::Useful methods: | ::Useful methods: | ||
:::GetMarineEntity() - if there is a live spawned marine entity for this resource, this will return it. | :::<code>GetMarineEntity()</code> - if there is a live spawned marine entity for this resource, this will return it. | ||
:::IsInhabited() - returns true if a player is controlling the marine, false if it's under AI control. | :::<code>IsInhabited()</code> - returns true if a player is controlling the marine, false if it's under AI control. | ||
:::GetCommander() - returns the CASW_Player who owns this marine. | :::<code>GetCommander()</code> - returns the <code>CASW_Player</code> who owns this marine. | ||
:::GetProfile() - returns the profile for this marine. | :::<code>GetProfile()</code> - returns the profile for this marine. | ||
;<code>CASW_Marine_Profile</code>:This represents the static data associated with each of the characters in the game. There is a profile for Sarge, Jæger, Wildcat, etc. From this class you can access their name, portrait images and skill set. | |||
;CASW_Marine_Profile | ;<code>CASW_Game_Resource</code>:This holds an array of marine resources, objectives and other networked game state. You can get to this object with the global accessor <code>ASWGameResource()</code>. | ||
:This represents the static data associated with each of the characters in the game. There is a profile for Sarge, | ::Use <code>GetMaxMarineResources()</code> and <code>GetMarineResource( i )</code> to iterate over all the marine resources. if you want to iterate over all the marines, you can call <code>GetMarineEntity()</code> on each marine resource. | ||
::Use <code>ASW_MAX_OBJECTIVES</code> and <code>GetObjective( i )</code> to iterate over each objective. | |||
;CASW_Game_Resource | ;<code>CAlienSwarm</code>:This is the gamerules object for Alien Swarm. It controls overall game state, selecting marines, selecting equipment, spawning marines, completing the mission, players connecting, etc. You can get to this object with the global accessor <code>ASWGameRules()</code>. | ||
:This holds an array of marine resources, objectives and other networked game state. You can get to this object with the global accessor ASWGameResource(). | |||
::Use GetMaxMarineResources() and GetMarineResource( i ) to iterate over all the marine resources. if you want to iterate over all the marines, you can call GetMarineEntity() on each marine resource. | |||
::Use ASW_MAX_OBJECTIVES and GetObjective( i ) to iterate over each objective. | |||
;CAlienSwarm | |||
:This is the gamerules object for Alien Swarm. It controls overall game state, selecting marines, selecting equipment, spawning marines, completing the mission, players connecting, etc. You can get to this object with the global accessor ASWGameRules(). | |||
::Useful methods: | ::Useful methods: | ||
:::GetSkillLevel() - returns 1, 2, 3 or 4 (for easy, normal, hard, insane) | :::<code>GetSkillLevel()</code> - returns 1, 2, 3 or 4 (for easy, normal, hard, insane) | ||
:::GetGameState() - returns the current game state. See the ASW_GameState enum for possible states. | :::<code>GetGameState()</code> - returns the current game state. See the <code>ASW_GameState</code> enum for possible states. | ||
:::StartMission() - this gets called when all players have selected their marines and the leader presses the Start Mission button. | :::<code>StartMission()</code> - this gets called when all players have selected their marines and the leader presses the Start Mission button. | ||
:::MissionComplete( bool bSuccess ) - this gets called when the mission ends. | :::<code>MissionComplete( bool bSuccess )</code> - this gets called when the mission ends. | ||
;<code>CASW_Weapon</code>:This is the base weapon class for all Alien Swarm weapons. | |||
;CASW_Weapon | ;<code>CASW_WeaponInfo</code>:This holds the static data associated with each weapon type, read from the weapon script files in swarm/scripts. | ||
:This is the base weapon class for all Alien Swarm weapons. | ;<code>CASW_Objective</code>:This is the base class for each objective. Objectives receive events from the <code>CASW_Mission_Manager</code> and will mark themselves as complete/incomplete and potentially complete the mission. | ||
;CASW_WeaponInfo | |||
:This holds the static data associated with each weapon type, read from the weapon script files in swarm/scripts. | |||
;CASW_Objective | |||
:This is the base class for each objective. Objectives receive events from the CASW_Mission_Manager and will mark themselves as complete/incomplete and potentially complete the mission. | |||
::Useful methods: | ::Useful methods: | ||
:::IsObjectiveComplete() | :::<code>IsObjectiveComplete()</code> | ||
:::IsObjectiveHidden() | :::<code>IsObjectiveHidden()</code> | ||
:::GetObjectiveProgress() | :::<code>GetObjectiveProgress()</code> | ||
;<code>CASW_Alien</code>:This is the base class for most aliens in Alien Swarm (all except the <code>CASW_Buzzer</code> and <code>CASW_Grub</code>). | |||
;CASW_Alien | ;<code>CASW_Egg</code>:The alien egg that hatches parasites. | ||
:This is the base class for most aliens in Alien Swarm (all except the CASW_Buzzer and CASW_Grub). | ;<code>CASW_Door</code>:The class used for doors. Doors can auto-open, be welded shut, get damaged and fall down. Has an associated <code>CASW_Door_Area trigger</code> for triggering auto-open and knowing when the marine is within weld range. | ||
;<code>CASW_Button_Area</code>:This trigger volume represents an interactive button panel. It can be locked and the player will have to complete a wire puzzle to open it. | |||
;CASW_Egg | ;<code>CASW_Computer_Area</code>:Similar to a button area, but for an interactive computer, typically used for a download objective. If locked, it will spawn a tumbler hack minigame. | ||
:The alien egg that hatches parasites. | ;<code>CASW_Marine_Skills</code>:This class will return skill based values for each marine in the game. It can be used to find damage bonuses, move speed bonuses, etc. for each marine, based on their profile and the number of skill points each marine has. The number of skill points each marine has is networked to all players via the <code>CASW_Game_Resource</code>. | ||
;<code>CASW_Spawner</code>:This entity is used to spawn aliens in the level. It is placed by the level designer and has many keyfields and inputs for controlling spawn rate, max aliens spawned, and unburrow animations for the alien. | |||
;CASW_Door | ;<code>CASW_Campaign_Save</code>:When playing ''Alien Swarm'' through the main menu, the game is always in campaign mode. This means there is an active <code>CASW_Campaign_Save</code> object, which holds information on the current campaign you are playing, which missions are complete, how many retries you've had on each mission and which marines each player selected previously (and the skill points of each marine, if you're playing with custom skill points turned on). | ||
:The class used for doors. Doors can auto-open, be welded shut, get damaged and fall down. Has an associated CASW_Door_Area trigger for triggering auto-open and knowing when the marine is within weld range. | ::You can get the current campaign save by doing <code>ASWGameRules()->GetCampaignSave()</code>. | ||
;<code>CASW_Campaign_Info</code>:This describes the static data for a campaign. Each campaign has a name, textures and an array of <code>Campaign_Mission_t</code>s, which describe each mission and how they link together. | |||
;CASW_Button_Area | |||
:This trigger volume represents an interactive button panel. It can be locked and the player will have to complete a wire puzzle to open it. | |||
;CASW_Computer_Area | |||
:Similar to a button area, but for an interactive computer, typically used for a download objective. If locked, it will spawn a tumbler hack minigame. | |||
;CASW_Marine_Skills | |||
:This class will return skill based values for each marine in the game. It can be used to find damage bonuses, move speed bonuses, etc. for each marine, based on their profile and the number of skill points each marine has. The number of skill points each marine has is networked to all players via the CASW_Game_Resource. | |||
;CASW_Spawner | |||
:This entity is used to spawn aliens in the level. It is placed by the level designer and has many keyfields and inputs for controlling spawn rate, max aliens spawned, unburrow animations for the alien. | |||
;CASW_Campaign_Save | |||
:When playing Alien Swarm through the main menu, the game is always in campaign mode. This means there is an active CASW_Campaign_Save object, which holds information on the current campaign you are playing, which missions are complete, how many retries you've had on each mission and which marines each player selected previously (and the skill points of each marine, if you're playing with custom skill points turned on). | |||
::You can get the current campaign save by doing | |||
;CASW_Campaign_Info | |||
:This describes the static data for a campaign. Each campaign has a name, textures and an array of Campaign_Mission_t | |||
::Useful methods: | ::Useful methods: | ||
:::GetNumMissions() | :::<code>GetNumMissions()</code> | ||
:::GetMission( i ) | :::<code>GetMission( i )</code> | ||
;<code>CASW_Melee_System</code>:This class handles predicted melee attacks (the animation, anim events and animation driven movement are predicted and synchronized between client and server, the same way normal player movement is). The <code>CASW_Melee_Attack</code> class describes each attack's animation, damage, area of effect and if it combos from another attack. | |||
;CASW_Melee_System | |||
:This class handles predicted melee attacks (the animation, anim events and animation driven movement are predicted and synchronized between client and server, the same way normal player movement is). The CASW_Melee_Attack class describes each attack's animation, damage, area of effect and if it combos from another attack | |||
;asw_input.cpp, asw_in_main.cpp, asw_in_mouse.cpp | == Other Files of Interest == | ||
:These files read keyboard/mouse input and turn it into the CUserCmd that will drive the marine around, aim the cursor and shoot. They also handle | ;<code>asw_shareddefs.cpp/.h</code>:This lists various Alien Swarm defines, collision groups, classifies, etc. | ||
;<code>clientmode_asw.cpp/.h</code>:Exists on the client and receives function calls on level init, on shutdown, and per frame. | |||
;<code>asw_playeranimstate.cpp/.h</code>:This is responsible for animating the marines. It looks at the entity's movement, angles and anim events to decide which animations to play. | |||
;<code>asw_marine_gamemovement.cpp/.h</code>:This processes movement commands and drives the marine around. | |||
;<code>asw_input.cpp</code>, <code>asw_in_main.cpp</code>, <code>asw_in_mouse.cpp</code>:These files read keyboard/mouse input and turn it into the <code>CUserCmd</code> that will drive the marine around, aim the cursor and shoot. They also handle client-side vertical autoaim and turning the mouse position into a world location. | |||
[[Category: | == More Information == | ||
* Be sure to join the hlcoders [http://list.valvesoftware.com/mailman/listinfo/hlcoders mailing list] and [irc://irc.gamesurge.net/hlcoders IRC channel] | |||
* For questions regarding Alien Swarm code specifically, you can email [mailto:jonathan@valvesoftware.com?subject=Alien%20Swarm%20code jonathan@valvesoftware.com]. | |||
[[Category:Alien Swarm]][[Category:Programming]] |
Latest revision as of 11:21, 12 July 2024

Alien Swarm Classes
Here is an overview of the major C++ classes in Alien Swarm. Most of the Alien Swarm .cpp/.h
files begin with asw_
. The class names begin with CASW_
for server classes and C_ASW_
for networked client classes.
CASW_Player
- This is the Alien Swarm player class. Unlike most
Source engine games, the player in Alien Swarm is an invisible commander entity. It does not move. If the player is currently controlling a marine, then calling the
GetMarine()
method on the player will return it. CASW_Marine
- This entity is the actual marine you see running around the levels and shooting aliens. It is derived from the
CAI_BaseNPC
class. When a marine is inhabited it means he is being directly controlled by aCASW_Player
. When a marine is under direct control, his AI is disabled, he becomes a predicted entity and the player's input will drive the marine around.- Useful methods:
GetCommander()
- returns theCASW_Player
who owns this marine.GetMarineResource()
- returns the associatedCASW_Marine_Resource
.GetASWWeapon( nSlot )
- returns the weapon equipped in that slot (where the inventory slot is eitherASW_INVENTORY_SLOT_PRIMARY
,ASW_INVENTORY_SLOT_SECONDARY
, orASW_INVENTORY_SLOT_EXTRA
).GetMarineProfile()
- returns the profile for this marine.IsInhabited()
- returns true if a player is controlling the marine, false if it's under AI control.
- Useful methods:
CASW_Marine_Resource
- This class holds some networked data about each marine (similar to a player resource in other Source engine games). There is one of these for every selected marine in the game. The marine resource exists as soon as the marine is selected in the briefing (before the
asw_marine
entity is created). The marine resource also stays around after the marine is killed and the marine entity is deleted.- Useful methods:
GetMarineEntity()
- if there is a live spawned marine entity for this resource, this will return it.IsInhabited()
- returns true if a player is controlling the marine, false if it's under AI control.GetCommander()
- returns theCASW_Player
who owns this marine.GetProfile()
- returns the profile for this marine.
- Useful methods:
CASW_Marine_Profile
- This represents the static data associated with each of the characters in the game. There is a profile for Sarge, Jæger, Wildcat, etc. From this class you can access their name, portrait images and skill set.
CASW_Game_Resource
- This holds an array of marine resources, objectives and other networked game state. You can get to this object with the global accessor
ASWGameResource()
.- Use
GetMaxMarineResources()
andGetMarineResource( i )
to iterate over all the marine resources. if you want to iterate over all the marines, you can callGetMarineEntity()
on each marine resource. - Use
ASW_MAX_OBJECTIVES
andGetObjective( i )
to iterate over each objective.
- Use
CAlienSwarm
- This is the gamerules object for Alien Swarm. It controls overall game state, selecting marines, selecting equipment, spawning marines, completing the mission, players connecting, etc. You can get to this object with the global accessor
ASWGameRules()
.- Useful methods:
GetSkillLevel()
- returns 1, 2, 3 or 4 (for easy, normal, hard, insane)GetGameState()
- returns the current game state. See theASW_GameState
enum for possible states.StartMission()
- this gets called when all players have selected their marines and the leader presses the Start Mission button.MissionComplete( bool bSuccess )
- this gets called when the mission ends.
- Useful methods:
CASW_Weapon
- This is the base weapon class for all Alien Swarm weapons.
CASW_WeaponInfo
- This holds the static data associated with each weapon type, read from the weapon script files in swarm/scripts.
CASW_Objective
- This is the base class for each objective. Objectives receive events from the
CASW_Mission_Manager
and will mark themselves as complete/incomplete and potentially complete the mission.- Useful methods:
IsObjectiveComplete()
IsObjectiveHidden()
GetObjectiveProgress()
- Useful methods:
CASW_Alien
- This is the base class for most aliens in Alien Swarm (all except the
CASW_Buzzer
andCASW_Grub
). CASW_Egg
- The alien egg that hatches parasites.
CASW_Door
- The class used for doors. Doors can auto-open, be welded shut, get damaged and fall down. Has an associated
CASW_Door_Area trigger
for triggering auto-open and knowing when the marine is within weld range. CASW_Button_Area
- This trigger volume represents an interactive button panel. It can be locked and the player will have to complete a wire puzzle to open it.
CASW_Computer_Area
- Similar to a button area, but for an interactive computer, typically used for a download objective. If locked, it will spawn a tumbler hack minigame.
CASW_Marine_Skills
- This class will return skill based values for each marine in the game. It can be used to find damage bonuses, move speed bonuses, etc. for each marine, based on their profile and the number of skill points each marine has. The number of skill points each marine has is networked to all players via the
CASW_Game_Resource
. CASW_Spawner
- This entity is used to spawn aliens in the level. It is placed by the level designer and has many keyfields and inputs for controlling spawn rate, max aliens spawned, and unburrow animations for the alien.
CASW_Campaign_Save
- When playing Alien Swarm through the main menu, the game is always in campaign mode. This means there is an active
CASW_Campaign_Save
object, which holds information on the current campaign you are playing, which missions are complete, how many retries you've had on each mission and which marines each player selected previously (and the skill points of each marine, if you're playing with custom skill points turned on).- You can get the current campaign save by doing
ASWGameRules()->GetCampaignSave()
.
- You can get the current campaign save by doing
CASW_Campaign_Info
- This describes the static data for a campaign. Each campaign has a name, textures and an array of
Campaign_Mission_t
s, which describe each mission and how they link together.- Useful methods:
GetNumMissions()
GetMission( i )
- Useful methods:
CASW_Melee_System
- This class handles predicted melee attacks (the animation, anim events and animation driven movement are predicted and synchronized between client and server, the same way normal player movement is). The
CASW_Melee_Attack
class describes each attack's animation, damage, area of effect and if it combos from another attack.
Other Files of Interest
asw_shareddefs.cpp/.h
- This lists various Alien Swarm defines, collision groups, classifies, etc.
clientmode_asw.cpp/.h
- Exists on the client and receives function calls on level init, on shutdown, and per frame.
asw_playeranimstate.cpp/.h
- This is responsible for animating the marines. It looks at the entity's movement, angles and anim events to decide which animations to play.
asw_marine_gamemovement.cpp/.h
- This processes movement commands and drives the marine around.
asw_input.cpp
,asw_in_main.cpp
,asw_in_mouse.cpp
- These files read keyboard/mouse input and turn it into the
CUserCmd
that will drive the marine around, aim the cursor and shoot. They also handle client-side vertical autoaim and turning the mouse position into a world location.
More Information
- Be sure to join the hlcoders mailing list and IRC channel
- For questions regarding Alien Swarm code specifically, you can email jonathan@valvesoftware.com.