Swarm C++ Code Overview

== 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 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 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: 
:::GetCommander() - returns the CASW_Player who owns this marine. 
:::GetMarineResource() - returns the associated CASW_Marine_Resource. 
:::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). 
:::GetMarineProfile() - returns the profile for this marine.
:::IsInhabited() - returns true if a player is controlling the marine, false if it's under AI control. 
;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 the CASW_Player who owns this marine. 
:::GetProfile() - returns the profile for this marine.
;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() 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: 
:::GetSkillLevel() - 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. 
:::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.
;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()
;CASW_Alien:This is the base class for most aliens in Alien Swarm (all except the CASW_Buzzer and CASW_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().
;CASW_Campaign_Info:This describes the static data for a campaign. Each campaign has a name, textures and an array of Campaign_Mission_ts, which describe each mission and how they link together. 
::Useful methods: 
:::GetNumMissions()
:::GetMission( i )
;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.
Category:Alien SwarmCategory:Programming