(Be warned, this text is quite long and partly quite technical. But in case you’re interested in how things work or if you are a mapper for AHL2 just read on)
There are a few bugs, which are being currently ironed out, which just cannot wait to be fixed in the next release but require another patch for v2. These are remaining rare crashes and one occasion where the gun might stay hidden, both of which are already fixed. The remaining bug is the teamspawn code not working as it should – and that’s what I’m currently working on.
Several hours of gaming on “Roy’s Happy Place” have brought up some shortcomings in the code. These are:
- Not spawning with the team, including spawning at odd places like amongst the enemy team, scattered throughout the map or even outside the map
- Spawning inside other players, no matter if friend or foe
- Spawning inside objects
- Spawning with the team and immediately somewhere else as soon as you start to move
- Teamspawn always uses the same two or three spots
The problems which lead to spawning inside other players or objects have been fixed as well a spawning with the team and then immediately somewhere else. A new server cvar has been introduced (sv_mindistancetp) which fixes the code always rotating between a small number of spots. This only leaves players not spawning with their team as the only problem. Actually this problem can be split into two separate ones, the first being that players don’t use their spot from the teamspawn grid and the second being the inability of the code to create enough spawn points for the whole team. While the former is still not solved the latter is thoroughly fixed now – as long as the available spawn points on the map aren’set up in completely stupid places.
The code first fetches an info_player_deathmatch entity from the map for the first team and uses this as the basis for each subsequent check. For all other teams every info_player_deathmatch entity on the map is checked if it is known to not being usable (more on that later), if it’s not being used by another team and if the distance is equal to or higher than the number of units set for sv_mindistancetp. If one passes the minimum distance check it is immediately chosen, if no entity matches it the, entity which is furthest away from all other teams is chosen. Starting from the base spawn point the code tries to find as many valid spawn points around it as there are players in the specific team. What qualifies a generated spawn point as valid? Well, this:
- Nothing blocks player movement from the base point to the generated one
- The space where the player would spawn is completely empty
- The player won’t fall down far enough to get hurt just when they hit the ground
- The player spawn inside and won’t fall into or through a trigger_hurt
Each valid generated spawn point serves as a base point to create additional spawn points, if necessary. If it’s not possible to create enough spawn points on the same level the code tries to stack players, by going up and down from every spawn point it found on “ground level” two times. In case it is not possible to create enough spawn points around an info_player_deathmatch entity it is added to a list of unusable spawn points for the specific team and the code tries to find another valid info_player_deathmatch entity to start the spawn point generation with as described above. As soon as a player leaves the team the list of unusable spawn points is cleared as former unusable points may be working well for a lower number of players. In-game, with some debug code enabled, it looks like this (click the images to see them full size and please note that that all of them are affected by the still not fixed “spawning at odd places” bug):

In this screenshot there have been no problems to create the grid. The yellow one is the base point and the green ones are the generated points.

This one shows a problematic spawn point. It has been possible to create three additional spawn points, but that’s it. It’s not possible to spawn in the places which are drawn in red in this picture. Therefore the base point is shown in blue here and added to the list of unusable spawn points.

In this case it has been possible to create a sufficient number of spawn points around the base point, but there are also some unusable ones as players would spawn in furniture there.

This one is a little more complex, there are many unusable points in this screenshot and the usable spawn points flow out of the small room.

This one is slightly over the top, but it shows quite well how it works. It starts at the yellow spot and tries to find usable points around it. Only the ones directly behind and in front of it are usable so the search continues with those points. The result is that the usable spawn points move down the hallway and move to the right as soon at the end of the hallway.
The code is actually quite smart and tries its very best to spawn the whole team in one place. However, in the event that it cannot find as many usable base spawn points as there are teams at least some players will spawn scattered across the map – but that’ll only happen if all of the info_player_deathmatch entities are set up in completely stupid places or if there are less spawn points than teams.