A single player game absolutely requires some type of AI controlled characters (also known as Non-Player Characters or NPCs) in order to have any kind of gameplay. Quake 3 has AI controlled Bots for its team games but these work poorly in a single player game. In this section I will show how to add the AI controlled characters from the Dark Conjunction mod to our single player game code to correct this deficit.
The Dark Conjunction NPCs consist of the following seven types :
- Ank - an orange fireball hurling creature
- Bat - a flying and walking creature
- Hulk - a blue four armed monster with an earthquake attack
- Metlar - a frog jumping demon
- Pilot - human friendlies armed with a pistol
- Sealoard - large immobile monster with a fireball like attack
- Soldier - human friendly armed with a pistol
In our implementation of these NPCs we must add the weapons and attack types used by the NPCs, as well as adding the NPCs themselves. Included with the NPCs is an NPC path entity that is used to make the NPCs walk a path when they are not fighting. The NPCs will also use the map AAS information for navigation.
Source Files
The code changes required for implementing NPCs are made to both the Game module and the Cgame module. The files which must be added to these modules are included as part of the Single Player Source Package on the Downloads page. For the Game module these files are g_npc.c, g_npcmove.c and g_npcthink.c. They are placed in the code/game folder and are added to the game project. For the Cgame module the file is named cg_npc.c and it is placed in the code\cgame folder and is added to the cgame project.
Entity Definitions
To use the NPCs in your levels they must be added to the map using your level editor. This requires adding their definitions to the editor's entity definition file. Add the following definitions to implement NPC usage in your level editor :
/*QUAKED npcpath (0.2 0.5 0.5) (-8 -8 -8) (8 8 8)
*/
/*QUAKED npc_ank (0.2 0.5 0) (-16 -16 -40) (16 16 8) suspended disabled deaf first_taunt
"shot_factor" likeness of NPC to fire (far weapon), 1.0 means always fire, 0 means never fire,
only chase, default is 0.5
*/
/*QUAKED npc_bat (0.2 0.5 0) (-16 -16 -40) (16 16 8) suspended disabled deaf first_taunt
"shot_factor" likeness of NPC to fire (far weapon), 1.0 means always fire,
0 means never fire, only chase, default is 0.5
"flying_alt" altitude that de NPC will try to mantain, default is 100
*/
/*QUAKED npc_hulk (0.2 0.5 0) (-16 -16 -40) (16 16 8) suspended disabled deaf first_taunt
"shot_factor" likeness of NPC to fire (far weapon), 1.0 means always fire,
0 means never fire, only chase, default is 0.5
*/
/*QUAKED npc_metlar (0.2 0.5 0) (-16 -16 -40) (16 16 8) suspended disabled deaf first_taunt
"shot_factor" likeness of NPC to fire (far weapon), 1.0 means always fire,
0 means never fire, only chase, default is 0.5
*/
/*QUAKED npc_pilot (0.2 0.5 0) (-16 -16 -40) (16 16 8) suspended disabled deaf first_taunt
"shot_factor" likeness of NPC to fire (far weapon), 1.0 means always fire,
0 means never fire, only chase, default is 0.5
*/
/*QUAKED npc_sealord (0.2 0.5 0) (-16 -16 -40) (16 16 8) suspended disabled deaf first_taunt
"shot_factor" likeness of NPC to fire (far weapon), 1.0 means always fire,
0 means never fire, only chase, default is 0.5
*/
/*QUAKED npc_soldier1 (0.2 0.5 0) (-16 -16 -40) (16 16 8) suspended disabled deaf first_taunt
"shot_factor" likeness of NPC to fire (far weapon), 1.0 means always fire,
0 means never fire, only chase, default is 0.5
*/
/*QUAKED npc_soldier2 (0.2 0.5 0) (-16 -16 -40) (16 16 8) suspended disabled deaf first_taunt
"shot_factor" likeness of NPC to fire (far weapon), 1.0 means always fire,
0 means never fire, only chase, default is 0.5
*/
Using the NPC Entities
The following is taken from the Dark Conjunction Entity Manual and describes how to use the NPC entities in your levels :
NPCs in general:
Keys
shot_factor: Values are between 0 and 1. This controls the likeness a NPC will fire a projectile and how much it uses backpedal. An NPC that has shot_factor set to 0 will not shoot at all and will never backpedal. An NPC with shot_factor set to 1 will always shoot and won't move. The higher the value the more the NPC will shoot and the more it will backpedal (unless set to 1 where it won't move). The default value is 0.5.
targetname: This is used for the "disabled" check box option. When triggered the NPC is enabled (see disabled under Check Boxes/Spawnflags)
target: This is used to trigger an event once the NPC is killed. It can also be used to make the NPC walk through a specified route using the npcpath entity (see npcpath for more info).
angle: The angle in which the NPC is spawned.
Check Boxes/Spawnflags
suspended: When enabled the NPC starts suspended in the air when spawned into the map. This has not been checked so we don't know if it works.
disabled: The NPC is hidden until it is triggered. When triggered it will appear in the specified location.
deaf: This doesn't work in Demo 1.0. NPCs are still always deaf...
first_taunt: If enabled, when the NPC "sees" you for the first time it will perform the taunt animation.
npc_ank
Design tips: This is the orange fireball hurling monster. It is the most commonly used monster. Fireballs are sometimes homing at far distances. If shot_factor is set to 0 it will attack the player only with the melee attack. If shot_factor is set to 1 it can be used as a "sniper".
npc_bat
Design tips: The bat demon is one of the most special NPCs of all, since it has a flying mode and a land mode. Bat demons have a specific key no other NPC has. The key "flying_alt" determines the standard height the bat demon will try to fly at. Default is 100. Bat demons do not fall off ledges and they enter in a flying mode if they do so. A bat demon on the land can jump to flight, but they do this only sometimes. These NPCs are recommended to use in open spaces with a lot of sky.
npc_hulk
Design tips: This is the four arm blue monster. It is very important that this monster is used in open spaces. The problem is that the aas routines are calculated for a player size and the monster, which is much larger than a player, uses these routines. Because of the aas it thinks it can enter any area a player can access. If you are not careful it will get stuck easily. The ground shaking attack does not affect the player if the player is jumping. Shot_factor has not been tested with this NPC and it shouldn't have any use.
npc_metlar
Design tips: Metlar demons are the frog jumping demons from TDC. They should be used in not too complex open spaces, since they are rather large and don't work well in closed areas due to the nature of their movement. Remember that aas routines are calculated for a player size and these monster use those routines, which means they will think they can get past areas they do not fit. Shot_factor has not been tested with this NPC.
npc_pilot
Design tips: Pilots do not attack the player unless the player attacks them. They attack monsters on sight. Shot_factor has not been tested with this NPC. When killed drops a weapon_gun entity that does not respawn. Slightly weaker than soldiers.
npc_sealord
Design tips: This monster can only be used under very specific conditions! The monster must face south (angle 270). We haven't confirmed north (angle 90), but it may work. The monster moves only from side to side (strafing) and has a maximum strafing distance of about 120 game units. The monster will not exceed that distance. The other thing is that the monster's bounding box only covers it's chest area. If you do not stop the player from reaching the NPC you will have clipping problems. If the player manages to get behind the monster it will not turn! We used a clip brush to avoid the player from reaching the monster. Shot_factor has not been tested with this NPC.
npc_soldier1
Design tips: Soldiers do not attack the player unless the player attacks them. They attack monsters on sight. Shot_factor has not been tested with this NPC. When killed drops a weapon_gun entity that does not respawn.
npcpath
Design tips: You can use this entity to make an NPC walk a specific path as long as it is inactive (not fighting). The complete path doesn't have to be laid out because the NPC will use the aas to reach one npcpath box to another. You can make the NPC go back and forth if you connect the boxes in a circular pattern.
Keys
targetname: The target name that links a npcpath with the another npcpath or the NPC itself. An NPC must be targeted to one of the paths to use it.
target: The target destination npcpath the NPC should walk.
Notes: This entity is to use only with NPCs that can walk. The bat demon, the hulk demon and the sea lord do not walk.
Media for NPCs
To make it easier to implement the AI controlled characters, the required models and sounds are avalible on the Downloads page.