UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
g_spawn.cpp File Reference

Brings new objects into the world. More...

#include "g_spawn.h"
#include "g_ai.h"
#include "g_client.h"
#include "g_edicts.h"
#include "g_func.h"
#include "g_inventory.h"
#include "g_mission.h"
#include "g_reaction.h"
#include "g_trigger.h"
#include "g_utils.h"
#include "g_vis.h"
#include "../shared/parse.h"
#include "../shared/keyvaluepair.h"

Go to the source code of this file.

Data Structures

struct  spawn_temp_s
 this is only used to hold entity field values that can be set from the editor, but aren't actually present in Edict during gameplay More...
 
struct  spawn_s
 

Macros

#define FFL_SPAWNTEMP   1
 
#define FFL_NOSPAWN   2
 
#define G_ValidDescription(ent)   ((ent)->description && ((ent)->description[0] == '_' || strstr((ent)->description, "*msgid:") != nullptr))
 
#define MISC_MODEL_SOLID   (1 << 8)
 
#define CAMERA_ROTATE   (1 << 8)
 

Typedefs

typedef struct spawn_temp_s spawn_temp_t
 this is only used to hold entity field values that can be set from the editor, but aren't actually present in Edict during gameplay More...
 
typedef struct spawn_s spawn_t
 

Functions

static void SP_light (Edict *ent)
 light (0 1 0) (-8 -8 -8) (8 8 8) More...
 
static void SP_dummy (Edict *ent)
 a dummy to get rid of local entities More...
 
static void SP_player_start (Edict *ent)
 info_player_start (1 0 0) (-16 -16 -24) (16 16 32) Starting point for a player. "team" the number of the team for this player starting point "0" is reserved for civilians and critters (use info_civilian_start instead) More...
 
static void SP_human_start (Edict *ent)
 info_human_start (1 0 0) (-16 -16 -24) (16 16 32) Starting point for a single player human. More...
 
static void SP_alien_start (Edict *ent)
 info_alien_start (1 0 0) (-16 -16 -24) (16 16 32) Starting point for a single player alien. More...
 
static void SP_civilian_start (Edict *ent)
 info_civilian_start (0 1 1) (-16 -16 -24) (16 16 32) Starting point for a civilian. More...
 
static void SP_worldspawn (Edict *ent)
 Spawns the world entity. More...
 
static void SP_2x2_start (Edict *ent)
 info_2x2_start (1 1 0) (-32 -32 -24) (32 32 32) Starting point for a 2x2 unit. More...
 
static void SP_civilian_target (Edict *ent)
 info_civilian_start (0 1 1) (-16 -16 -24) (16 16 32) Way point for a civilian. More...
 
static void SP_misc_model (Edict *ent)
 Spawns a misc_model if there is a solid state. More...
 
static void SP_misc_item (Edict *ent)
 Spawns an item to the ground container. More...
 
static void SP_misc_mission (Edict *ent)
 Initializes the human/phalanx mission entity. More...
 
static void SP_misc_message (Edict *ent)
 
static void SP_misc_smoke (Edict *ent)
 
static void SP_misc_fire (Edict *ent)
 
static void SP_misc_camera (Edict *ent)
 
static void SP_misc_smokestun (Edict *ent)
 
static void ED_CallSpawn (Edict *ent)
 Finds the spawn function for the entity and calls it. More...
 
static char * ED_NewString (const char *string)
 Allocated memory for the given string in the level context (TAG_LEVEL) More...
 
static void ED_ParseField (const char *key, const char *value, Edict *ent)
 Takes a key/value pair and sets the binary values in an edict. More...
 
static const char * ED_ParseEdict (const char *data, Edict *ent)
 Parses an edict out of the given string, returning the new position. More...
 
static void G_FindEdictGroups (void)
 Chain together all entities with a matching team field. All but the first will have the FL_GROUPSLAVE flag set. All but the last will have the groupchain field set to the next one. More...
 
void G_SpawnEntities (const char *mapname, bool day, const char *entities)
 Creates a server's entity / program execution context by parsing textual entity definitions out of an ent file. More...
 
EdictG_Spawn (const char *classname)
 Either finds a free edict, or allocates a new one. More...
 
static void Think_SmokeAndFire (Edict *self)
 
static void G_SpawnFieldPart (const entity_type_t fieldtype, const vec3_t vec, const char *particle, int rounds, int damage)
 
static void G_SpawnFieldGroup (const entity_type_t fieldtype, const vec3_t vec, const char *particle, int rounds, int damage, vec_t radius)
 Spawns a field that is available for some rounds. More...
 
void G_SpawnSmokeField (const vec3_t vec, const char *particle, int rounds, int damage, vec_t radius)
 Spawns a smoke field that is available for some rounds. More...
 
void G_SpawnFireField (const vec3_t vec, const char *particle, int rounds, int damage, vec_t radius)
 
void G_SpawnStunSmokeField (const vec3_t vec, const char *particle, int rounds, int damage, vec_t radius)
 
EdictG_SpawnFloor (const pos3_t pos)
 Spawns a new entity at the floor. More...
 
EdictG_SpawnParticle (const vec3_t origin, int spawnflags, const char *particle)
 
static void G_ActorSpawn (Edict *ent)
 Spawn point for a 1x1 unit. More...
 
static void G_Actor2x2Spawn (Edict *ent)
 Spawn a singleplayer 2x2 unit. More...
 
static void G_BuildForbiddenListForEntity (Edict *ent)
 Create a list of the grid positions the edict occupies and store it with the edict. More...
 
static bool Message_Use (Edict *self, Edict *activator)
 
static void G_SpawnField (Edict *ent, const char *classname, entity_type_t type, solid_t solid)
 

Variables

static spawn_temp_t spawnTemp
 
static const spawn_t spawns []
 

Detailed Description

Brings new objects into the world.

Definition in file g_spawn.cpp.

Macro Definition Documentation

#define CAMERA_ROTATE   (1 << 8)

Definition at line 981 of file g_spawn.cpp.

Referenced by SP_misc_camera().

#define FFL_NOSPAWN   2

Definition at line 45 of file g_spawn.cpp.

#define FFL_SPAWNTEMP   1

Definition at line 44 of file g_spawn.cpp.

#define G_ValidDescription (   ent)    ((ent)->description && ((ent)->description[0] == '_' || strstr((ent)->description, "*msgid:") != nullptr))

Definition at line 47 of file g_spawn.cpp.

Referenced by SP_misc_mission().

#define MISC_MODEL_SOLID   (1 << 8)

Definition at line 852 of file g_spawn.cpp.

Referenced by SP_misc_model().

Typedef Documentation

typedef struct spawn_s spawn_t
typedef struct spawn_temp_s spawn_temp_t

this is only used to hold entity field values that can be set from the editor, but aren't actually present in Edict during gameplay

Function Documentation

static void ED_CallSpawn ( Edict ent)
static

Finds the spawn function for the entity and calls it.

Definition at line 119 of file g_spawn.cpp.

References Edict::classname, Edict::inuse, spawn_t::name, and Q_streq.

Referenced by G_SpawnEntities().

static char* ED_NewString ( const char *  string)
static

Allocated memory for the given string in the level context (TAG_LEVEL)

Note
This memory is automatically freed when we close or change the level
Parameters
[in]stringThe string to copy

Definition at line 141 of file g_spawn.cpp.

References G_TagMalloc, i, and TAG_LEVEL.

Referenced by ED_ParseField().

static const char* ED_ParseEdict ( const char *  data,
Edict ent 
)
static

Parses an edict out of the given string, returning the new position.

Parameters
[in]dataThe string to parse from
[in]entshould be a properly initialized empty edict.

Definition at line 245 of file g_spawn.cpp.

References Com_Parse(), ED_ParseField(), gi, MAX_VAR, Edict::nativeReset(), OBJZERO, and Q_strncpyz().

Referenced by G_SpawnEntities().

static void G_BuildForbiddenListForEntity ( Edict ent)
static

Create a list of the grid positions the edict occupies and store it with the edict.

Note
This is only working for one z-level. But our models should be split for each level anyway.
Parameters
entThe edict to fill the forbidden list for

Definition at line 824 of file g_spawn.cpp.

References Edict::absBox, Edict::forbiddenListPos, Edict::forbiddenListSize, G_TagMalloc, AABB::getCenter(), i, AABB::maxs, AABB::mins, TAG_LEVEL, VecToPos, and VectorSet.

Referenced by SP_misc_model().

static void G_FindEdictGroups ( void  )
static

Chain together all entities with a matching team field. All but the first will have the FL_GROUPSLAVE flag set. All but the last will have the groupchain field set to the next one.

Definition at line 292 of file g_spawn.cpp.

References FL_GROUPSLAVE, Edict::flags, G_EdictsGetFirst(), G_EdictsGetNextInUse(), Edict::group, Edict::groupChain, Edict::groupMaster, and Q_streq.

Referenced by G_SpawnEntities().

Edict* G_Spawn ( const char *  classname)

Either finds a free edict, or allocates a new one.

Note
Try to avoid reusing an entity that was recently freed, because it can cause the player to think the entity morphed into something else instead of being removed and recreated, which can cause interpolated angles and bad trails.
See also
G_FreeEdict

Definition at line 403 of file g_spawn.cpp.

References ACTOR_SIZE_NORMAL, Edict::classname, Edict::fieldSize, G_EdictsGetNewEdict(), G_EdictsGetNumber(), gi, Edict::inuse, Edict::number, and Edict::setActive().

Referenced by G_SpawnEntities(), G_SpawnFieldPart(), G_SpawnFloor(), G_SpawnParticle(), and G_TriggerSpawn().

static void G_SpawnFieldGroup ( const entity_type_t  fieldtype,
const vec3_t  vec,
const char *  particle,
int  rounds,
int  damage,
vec_t  radius 
)
static

Spawns a field that is available for some rounds.

Parameters
[in]fieldtypeThe kind of field eg. smoke, fire, ...
[in]vecThe position in the world that is the center of the field
[in]particleThe id of the particle (see ptl_*.ufo script files in base/ufos)
[in]roundsThe number of rounds the particle will last
Todo:
Does '2 rounds' mean: created in player's turn, last through the aliens turn, vanish before the 2nd player's turn ??
Parameters
[in]damageThe damage dealt by the field
[in]radiusThe max distance of a cell from the center to get a particle

Definition at line 482 of file g_spawn.cpp.

References trace_s::contentFlags, CONTENTS_WATER, trace_s::fraction, G_SpawnFieldPart(), G_Trace(), gi, MASK_SMOKE_AND_FIRE, tr, UNIT_SIZE, VectorDist, and VectorSet.

Referenced by G_SpawnFireField(), G_SpawnSmokeField(), and G_SpawnStunSmokeField().

static void G_SpawnFieldPart ( const entity_type_t  fieldtype,
const vec3_t  vec,
const char *  particle,
int  rounds,
int  damage 
)
static
void G_SpawnFireField ( const vec3_t  vec,
const char *  particle,
int  rounds,
int  damage,
vec_t  radius 
)

Definition at line 521 of file g_spawn.cpp.

References ET_FIRE, and G_SpawnFieldGroup().

Referenced by G_ClientShoot().

Edict* G_SpawnFloor ( const pos3_t  pos)

Spawns a new entity at the floor.

Note
This is e.g. used to place dropped weapons/items at the floor

Definition at line 535 of file g_spawn.cpp.

References ACTOR_SIZE_NORMAL, Edict::calcOrigin(), ET_ITEM, Edict::fieldSize, G_Spawn(), gi, Edict::pos, Edict::type, and VectorCopy.

Referenced by G_ActorInvMove(), G_AddItemToFloor(), G_InventoryToFloor(), and G_SpawnItemOnFloor().

Edict* G_SpawnParticle ( const vec3_t  origin,
int  spawnflags,
const char *  particle 
)

This is only for particles that are spawned during a match - not for map particles.

Returns
A particle edict

Definition at line 551 of file g_spawn.cpp.

References ET_PARTICLE, G_CheckVis(), G_Spawn(), Edict::origin, Edict::particle, Edict::pos, Edict::spawnflags, Edict::type, VecToPos, and VectorCopy.

Referenced by Destroy_Breakable(), Destroy_Camera(), G_MissionThink(), G_ShootSingle(), G_SpawnField(), G_SplashDamage(), and Think_NextMapTrigger().

void G_SpawnSmokeField ( const vec3_t  vec,
const char *  particle,
int  rounds,
int  damage,
vec_t  radius 
)

Spawns a smoke field that is available for some rounds.

Parameters
[in]vecThe position in the world that is the center of the smoke field
[in]particleThe id of the particle (see ptl_*.ufo script files in base/ufos)
[in]roundsThe number of rounds the particle will last
Todo:
Does '2 rounds' mean: created in player's turn, last through the aliens turn, vanish before the 2nd player's turn ??
Parameters
[in]damageThe amount of damage this field will cause when touched by an actor.
[in]radiusThe max distance of a cell from the center to get a particle

Definition at line 516 of file g_spawn.cpp.

References ET_SMOKE, and G_SpawnFieldGroup().

Referenced by G_ClientShoot().

void G_SpawnStunSmokeField ( const vec3_t  vec,
const char *  particle,
int  rounds,
int  damage,
vec_t  radius 
)

Definition at line 526 of file g_spawn.cpp.

References ET_SMOKESTUN, and G_SpawnFieldGroup().

Referenced by G_ClientShoot().

static bool Message_Use ( Edict self,
Edict activator 
)
static

Definition at line 901 of file g_spawn.cpp.

References G_ClientPrintf(), G_FreeEdict(), G_IsActor, G_ValidMessage, Edict::getPlayer(), and PRINT_HUD.

Referenced by SP_misc_message().

static void SP_2x2_start ( Edict ent)
static

info_2x2_start (1 1 0) (-32 -32 -24) (32 32 32) Starting point for a 2x2 unit.

Definition at line 697 of file g_spawn.cpp.

References Edict::entBox, G_Actor2x2Spawn(), G_FreeEdict(), G_IsMultiPlayer, Edict::getTeam(), PLAYER_MIN, PLAYER_STAND, PLAYER_WIDTH, AABB::setMaxs(), AABB::setMins(), Edict::setTeam(), and TEAM_PHALANX.

static void SP_alien_start ( Edict ent)
static

info_alien_start (1 0 0) (-16 -16 -24) (16 16 32) Starting point for a single player alien.

Definition at line 720 of file g_spawn.cpp.

References ai_multiplayeraliens, G_ActorSpawn(), G_FreeEdict(), G_IsMultiPlayer, cvar_s::integer, Edict::setTeam(), and TEAM_ALIEN.

static void SP_civilian_start ( Edict ent)
static

info_civilian_start (0 1 1) (-16 -16 -24) (16 16 32) Starting point for a civilian.

Definition at line 737 of file g_spawn.cpp.

References ai_numcivilians, Edict::count, G_ActorSpawn(), G_FreeEdict(), G_IsMultiPlayer, cvar_s::integer, Edict::setTeam(), and TEAM_CIVILIAN.

static void SP_civilian_target ( Edict ent)
static

info_civilian_start (0 1 1) (-16 -16 -24) (16 16 32) Way point for a civilian.

See also
SP_civilian_start
Todo:
These waypoints should be placeable by the human player (e.g. spawn a special particle on the waypoint) to direct the civilians to a special location

Definition at line 756 of file g_spawn.cpp.

References ACTOR_SIZE_NORMAL, Edict::calcOrigin(), Edict::classname, ET_CIVILIANTARGET, Edict::fieldSize, G_AddToWayPointList(), gi, PATHFINDING_HEIGHT, Edict::pos, Edict::setTeam(), TEAM_CIVILIAN, and Edict::type.

static void SP_dummy ( Edict ent)
static

a dummy to get rid of local entities

Definition at line 998 of file g_spawn.cpp.

References G_FreeEdict().

static void SP_human_start ( Edict ent)
static

info_human_start (1 0 0) (-16 -16 -24) (16 16 32) Starting point for a single player human.

Definition at line 680 of file g_spawn.cpp.

References G_ActorSpawn(), G_FreeEdict(), G_IsMultiPlayer, Edict::setTeam(), and TEAM_PHALANX.

static void SP_light ( Edict ent)
static

light (0 1 0) (-8 -8 -8) (8 8 8)

Definition at line 647 of file g_spawn.cpp.

References G_FreeEdict().

static void SP_misc_camera ( Edict ent)
static
static void SP_misc_fire ( Edict ent)
static
static void SP_misc_item ( Edict ent)
static

Spawns an item to the ground container.

Definition at line 887 of file g_spawn.cpp.

References G_AddItemToFloor(), G_FreeEdict(), gi, Edict::item, and Edict::pos.

static void SP_misc_message ( Edict ent)
static
static void SP_misc_model ( Edict ent)
static

Spawns a misc_model if there is a solid state.

Todo:
is fieldsize and forbidden list update really needed here?

Definition at line 856 of file g_spawn.cpp.

References ACTOR_SIZE_NORMAL, Edict::classname, Edict::entBox, ET_SOLID, Edict::fieldSize, Edict::frame, G_BuildForbiddenListForEntity(), G_FreeEdict(), gi, MISC_MODEL_SOLID, Edict::model, AABB::set(), Edict::solid, SOLID_BBOX, Edict::spawnflags, and Edict::type.

static void SP_misc_smoke ( Edict ent)
static
static void SP_misc_smokestun ( Edict ent)
static
static void SP_player_start ( Edict ent)
static

info_player_start (1 0 0) (-16 -16 -24) (16 16 32) Starting point for a player. "team" the number of the team for this player starting point "0" is reserved for civilians and critters (use info_civilian_start instead)

Todo:
Wrong place here

Definition at line 660 of file g_spawn.cpp.

References G_ActorSpawn(), G_FreeEdict(), G_IsSinglePlayer, Edict::getTeam(), cvar_s::integer, level, level_locals_s::num_spawnpoints, and sv_maxsoldiersperteam.

static void SP_worldspawn ( Edict ent)
static

Spawns the world entity.

Only used for the world. "sounds" music cd track number "maxlevel" max. level to use in the map "maxteams" max team amount for multiplayergames for the current map

Definition at line 1013 of file g_spawn.cpp.

References Edict::classname, CS_ENABLEMORALE, CS_MAXCLIENTS, CS_MAXSOLDIERSPERPLAYER, CS_MAXSOLDIERSPERTEAM, CS_MAXTEAMS, G_IsMultiPlayer, gi, cvar_s::integer, Edict::inuse, level, spawn_temp_s::noEquipment, level_locals_s::noEquipment, spawn_temp_s::noRandomSpawn, level_locals_s::noRandomSpawn, Edict::solid, SOLID_BSP, cvar_s::string, sv_enablemorale, sv_maxclients, sv_maxsoldiersperplayer, sv_maxsoldiersperteam, and sv_maxteams.

static void Think_SmokeAndFire ( Edict self)
static

Variable Documentation

const spawn_t spawns[]
static

Definition at line 84 of file g_spawn.cpp.

spawn_temp_t spawnTemp
static

Definition at line 59 of file g_spawn.cpp.