Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion code/game/g_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ void Cmd_Give_f (gentity_t *ent)
it_ent = G_Spawn();
VectorCopy( ent->r.currentOrigin, it_ent->s.origin );
it_ent->classname = it->classname;
G_SpawnItem (it_ent, it);
G_SpawnItem (it_ent, it, qtrue);
FinishSpawningItem(it_ent );
memset( &trace, 0, sizeof( trace ) );
Touch_Item (it_ent, ent, &trace);
Expand Down
34 changes: 28 additions & 6 deletions code/game/g_items.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,15 +363,33 @@ void RespawnItem( gentity_t *ent ) {
}
master = ent->teammaster;

for (count = 0, ent = master; ent; ent = ent->teamchain, count++)
;
for (count = 0, ent = master; ent; ent = ent->teamchain) {
// Skip disabled (possibly through a disable_%s cvar) items
if ( !ent->item ) {
continue;
}

count++;
}

// No valid items to spawn
if ( count == 0 ) {
return;
}

choice = rand() % count;

for (count = 0, ent = master; ent && count < choice; ent = ent->teamchain, count++)
;
for (count = 0, ent = master; ent && count < choice; ent = ent->teamchain) {
// Skip disabled (possibly through a disable_%s cvar) items
if ( !ent->item ) {
continue;
}

count++;
}
}

// ent->item should not be nullish to this time
if (!ent) {
return;
}
Expand Down Expand Up @@ -883,14 +901,18 @@ Sets the clipping size and plants the object on the floor.

Items can't be immediately dropped to floor, because they might
be on an entity that hasn't spawned yet.

forceSpawn lets to bypass check for disabled through disable_%s
cvar items and spawn them anyway. Used for spawning items through
third party sources like give command.
============
*/
void G_SpawnItem (gentity_t *ent, gitem_t *item) {
void G_SpawnItem (gentity_t *ent, gitem_t *item, qboolean forceSpawn) {
G_SpawnFloat( "random", "0", &ent->random );
G_SpawnFloat( "wait", "0", &ent->wait );

RegisterItem( item );
if ( G_ItemDisabled(item) )
if ( !forceSpawn && G_ItemDisabled(item) )
return;

ent->item = item;
Expand Down
2 changes: 1 addition & 1 deletion code/game/g_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ void PrecacheItem (gitem_t *it);
gentity_t *Drop_Item( gentity_t *ent, gitem_t *item, float angle );
gentity_t *LaunchItem( gitem_t *item, vec3_t origin, vec3_t velocity );
void SetRespawn (gentity_t *ent, float delay);
void G_SpawnItem (gentity_t *ent, gitem_t *item);
void G_SpawnItem (gentity_t *ent, gitem_t *item, qboolean forceSpawn);
void FinishSpawningItem( gentity_t *ent );
void Think_Weapon (gentity_t *ent);
int ArmorIndex (gentity_t *ent);
Expand Down
2 changes: 1 addition & 1 deletion code/game/g_spawn.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ qboolean G_CallSpawn( gentity_t *ent ) {
// check item spawn functions
for ( item=bg_itemlist+1 ; item->classname ; item++ ) {
if ( !strcmp(item->classname, ent->classname) ) {
G_SpawnItem( ent, item );
G_SpawnItem( ent, item, qfalse );
return qtrue;
}
}
Expand Down
Loading