Exemplo n.º 1
0
/**
 * @brief Finds the spawn function for the entity and calls it.
 */
static _Bool G_SpawnEntity(g_entity_t *ent) {

	if (!ent->class_name) {
		gi.Debug("NULL classname\n");
		return false;
	}

	// check item spawn functions
	for (int32_t i = 0; i < g_num_items; i++) {

		const g_item_t *item = G_ItemByIndex(i);

		if (!item->class_name) {
			continue;
		}

		if (!g_strcmp0(item->class_name, ent->class_name)) { // found it
			G_SpawnItem(ent, item);
			return true;
		}
	}

	// check normal spawn functions
	for (g_entity_spawn_t *s = g_entity_spawns; s->name; s++) {
		if (!g_strcmp0(s->name, ent->class_name)) { // found it
			s->Spawn(ent);
			return true;
		}
	}

	gi.Warn("%s doesn't have a spawn function\n", ent->class_name);
	return false;
}
Exemplo n.º 2
0
void SP_gametype_item ( gentity_t* ent )
{
	gitem_t *item = NULL;
	char *value;
	int team = -1;

	G_SpawnString("teamfilter", "", &value);

	G_SetOrigin( ent, ent->s.origin );

	// If a team filter is set then override any team settings for the spawns
	if ( level.mTeamFilter[0] )
	{
		if ( Q_stricmp ( level.mTeamFilter, "red") == 0 )
		{
			team = TEAM_RED;
		}
		else if ( Q_stricmp ( level.mTeamFilter, "blue") == 0 )
		{
			team = TEAM_BLUE;
		}
	}

	if (ent->targetname && ent->targetname[0])
	{
		if (team != -1)
		{
			if (strstr(ent->targetname, "flag"))
			{
				if (team == TEAM_RED)
				{
					item = BG_FindItem("team_CTF_redflag");
				}
				else
				{ //blue
					item = BG_FindItem("team_CTF_blueflag");
				}
			}
		}
		else if (strstr(ent->targetname, "red_flag"))
		{
			item = BG_FindItem("team_CTF_redflag");
		}
		else if (strstr(ent->targetname, "blue_flag"))
		{
			item = BG_FindItem("team_CTF_blueflag");
		}
		else
		{
			item = NULL;
		}

		if (item)
		{
			ent->targetname = NULL;
			ent->classname = item->classname;
			G_SpawnItem( ent, item );
		}
	}
}
Exemplo n.º 3
0
/*
===============
G_CallSpawn

Finds the spawn function for the entity and calls it,
returning qfalse if not found
===============
*/
qboolean G_CallSpawn( gentity_t *ent ) {
	spawn_t	*s;
	gitem_t	*item;

	if ( !ent->classname ) {
		G_Printf ("G_CallSpawn: NULL classname\n");
		return qfalse;
	}

	// check item spawn functions
	for ( item=bg_itemlist+1 ; item->classname ; item++ ) {
		if ( !strcmp(item->classname, ent->classname) ) {
			G_SpawnItem( ent, item );
			return qtrue;
		}
	}

	// check normal spawn functions
	for ( s=spawns ; s->name ; s++ ) {
		if ( !strcmp(s->name, ent->classname) ) {
			// found it
			if (ent->healingsound && ent->healingsound[0])
			{ //yeah...this can be used for anything, so.. precache it if it's there
				G_SoundIndex(ent->healingsound);
			}
			s->spawn(ent);
			return qtrue;
		}
	}
	G_Printf ("%s doesn't have a spawn function\n", ent->classname);
	return qfalse;
}
Exemplo n.º 4
0
/*
 * @brief Finds the spawn function for the entity and calls it.
 */
static void G_SpawnEntity(g_edict_t *ent) {
	spawn_t *s;
	int32_t i;

	if (!ent->class_name) {
		gi.Debug("NULL classname\n");
		return;
	}

	// check item spawn functions
	const g_item_t *item = g_items;
	for (i = 0; i < g_num_items; i++, item++) {

		if (!item->class_name)
			continue;

		if (!g_strcmp0(item->class_name, ent->class_name)) { // found it
			G_SpawnItem(ent, item);
			return;
		}
	}

	// check normal spawn functions
	for (s = g_spawns; s->name; s++) {
		if (!g_strcmp0(s->name, ent->class_name)) { // found it
			s->spawn(ent);
			return;
		}
	}

	gi.Debug("%s doesn't have a spawn function\n", ent->class_name);
}
Exemplo n.º 5
0
/*
===============
G_CallSpawn

Finds the spawn function for the entity and calls it,
returning qfalse if not found
===============
*/
qboolean G_CallSpawn(gentity_t *ent)
{
	spawn_t *s;
	gitem_t *item;

	if (!ent->classname)
	{
		G_Printf("G_CallSpawn: NULL classname\n");
		return qfalse;
	}

	// check item spawn functions
	for (item = bg_itemlist + 1 ; item->classname ; item++)
	{
		if (!strcmp(item->classname, ent->classname))
		{
			// found it
			if (g_gametype.integer != GT_WOLF_LMS)     // lets not have items in last man standing for the moment
			{
				G_SpawnItem(ent, item);

				G_Script_ScriptParse(ent);
				G_Script_ScriptEvent(ent, "spawn", "");
			}
			else
			{
				return qfalse;
			}
			return qtrue;
		}
	}

	// check normal spawn functions
	for (s = spawns ; s->name ; s++)
	{
		if (!strcmp(s->name, ent->classname))
		{
			// found it
			s->spawn(ent);

			// entity scripting
			if (/*ent->s.number >= MAX_CLIENTS &&*/ ent->scriptName)
			{
				G_Script_ScriptParse(ent);
				G_Script_ScriptEvent(ent, "spawn", "");
			}

			return qtrue;
		}
	}

	// hack: this avoids spammy prints on start, bsp uses obsolete classnames!
	// bot_sniper_spot (railgun)
	if (Q_stricmp(ent->classname, "bot_sniper_spot"))
	{
		G_Printf("%s doesn't have a spawn function\n", ent->classname);
	}

	return qfalse;
}
Exemplo n.º 6
0
qboolean G_CallSpawn( gentity_t *ent ) {
	spawn_t	*s;
	gitem_t	*item;

	if ( !ent->classname ) {
		G_Printf( "G_CallSpawn: NULL classname\n" );
		return qfalse;
	}

	// check item spawn functions
	//TODO: cant reorder items because compat so....?
	for ( item=bg_itemlist+1 ; item->classname ; item++ ) {
		if ( !strcmp(item->classname, ent->classname) ) {
			G_SpawnItem( ent, item );
			return qtrue;
		}
	}

	// check normal spawn functions
	s = (spawn_t *)bsearch( ent->classname, spawns, ARRAY_LEN( spawns ), sizeof( spawn_t ), spawncmp );
	if ( s )
	{// found it
		if ( VALIDSTRING( ent->healingsound ) )
			G_SoundIndex( ent->healingsound );

		s->spawn( ent );
		return qtrue;
	}

	G_Printf( "%s doesn't have a spawn function\n", ent->classname );
	return qfalse;
}
Exemplo n.º 7
0
/*
===============
G_CallSpawn

Finds the spawn function for the entity and calls it,
returning qfalse if not found
===============
*/
qbool G_CallSpawn( gentity_t *ent ) {
	spawn_t	*s;
	gitem_t	*item;

	if ( !ent->classname ) {
		G_Printf ("G_CallSpawn: NULL classname\n");
		return qfalse;
	}

	// check item spawn functions
	for(item=&bg_itemlist[1]; ITEM_INDEX(item) < IT_NUM_ITEMS; item++){
		if ( !strcmp(item->classname, ent->classname) ) {

			if(g_gametype.integer != GT_BR && !Q_stricmp(item->classname, "item_money"))
				return qfalse;

			if(g_gametype.integer >= GT_RTP && !Q_stricmp(item->classname, "pickup_money"))
				return qfalse;

			G_SpawnItem( ent, item );
			return qtrue;
		}
	}

	// check normal spawn functions
	for ( s=spawns ; s->name ; s++ ) {
		if ( !strcmp(s->name, ent->classname) ) {
			// found it
			s->spawn(ent);
			return qtrue;
		}
	}
	G_Printf ("%s doesn't have a spawn function\n", ent->classname);
	return qfalse;
}
Exemplo n.º 8
0
/*
===============
G_CallSpawn

Finds the spawn function for the entity and calls it,
returning qfalse if not found
===============
*/
qboolean G_CallSpawn( gentity_t *ent ) {
	spawn_t	*s;
	gitem_t	*item;

	if ( !ent->classname ) {
		G_Printf ("G_CallSpawn: NULL classname\n");
		return qfalse;
	}

	// check item spawn functions
	for ( item=bg_itemlist+1 ; item->classname ; item++ ) {
		if ( !strcmp(item->classname, ent->classname) ) {
			G_SpawnItem( ent, item );
			return qtrue;
		}
	}

	// check normal spawn functions
	for ( s=spawns ; s->name ; s++ ) {
		if ( !strcmp(s->name, ent->classname) ) {
			// found it
			s->spawn(ent);
			return qtrue;
		}
	}
	G_Printf ("%s doesn't have a spawn function\n", ent->classname);
	return qfalse;
}
Exemplo n.º 9
0
/*
===============
G_CallSpawn

Finds the spawn function for the entity and calls it,
returning qfalse if not found
===============
*/
qboolean G_CallSpawn( gentity_t *ent ) {
	spawn_t	*s;
	gitem_t	*item;
	int		i;

	if ( !ent->classname ) {
		G_Printf ("G_CallSpawn: NULL classname\n");
		return qfalse;
	}

	// check item spawn functions
	for ( i = 1; i < BG_NumItems(); i++ ) {
		item = BG_ItemForItemNum( i );
		if ( !item->classname || !*item->classname ) {
			continue;
		}
		if ( !strcmp(item->classname, ent->classname) ) {
			G_SpawnItem( ent, item );
			return qtrue;
		}
	}

	// check normal spawn functions
	for ( s=spawns ; s->name ; s++ ) {
		if ( !strcmp(s->name, ent->classname) ) {
			// found it
			s->spawn(ent);
			return qtrue;
		}
	}
	G_Printf ("%s doesn't have a spawn function\n", ent->classname);
	return qfalse;
}
Exemplo n.º 10
0
static gentity_t* G_RealSpawnGametypeItem ( gentity_t* ent, bool dropped )
{
	gentity_t* it_ent;

	it_ent = G_Spawn();

	it_ent->flags |= FL_DROPPED_ITEM;
	it_ent->item = ent->item;

	VectorCopy( ent->r.currentOrigin, it_ent->s.origin );
	VectorCopy ( ent->s.angles, it_ent->s.apos.trBase );
	it_ent->classname = ent->item->classname;
	G_SpawnItem ( it_ent, it_ent->item );
	FinishSpawningItem(it_ent);	
	
	VectorSet( it_ent->r.mins, -ITEM_RADIUS * 4 / 3, -ITEM_RADIUS * 4 / 3, -ITEM_RADIUS );
	VectorSet( it_ent->r.maxs, ITEM_RADIUS * 4 / 3, ITEM_RADIUS * 4 / 3, ITEM_RADIUS );

	// Red team only
	if ( ent->s.eFlags & EF_REDTEAM )
	{
		it_ent->s.eFlags |= EF_REDTEAM;
	}
	
	if ( ent->s.eFlags & EF_BLUETEAM )
	{
		it_ent->s.eFlags |= EF_BLUETEAM;
	}

	return it_ent;
}
Exemplo n.º 11
0
/*
===============
G_CallSpawn

Finds the spawn function for the entity and calls it,
returning qfalse if not found
===============
*/
qboolean G_CallSpawn( gentity_t *ent ) {
	spawn_t *s;
	gitem_t *item;
	int hash;

	if ( !ent->classname ) {
		G_Printf( "G_CallSpawn: NULL classname\n" );
		return qfalse;
	}

	if ( g_deathmatch.integer ) {
		if ( !strcmp( "func_explosive", ent->classname ) ) {
			return qfalse;
		}

		if ( !strcmp( "trigger_hurt", ent->classname ) ) {
			return qfalse;
		}

		// don't spawn the flags in cp
		if ( g_gametype.integer == 7 && !strcmp( "team_WOLF_checkpoint", ent->classname ) ) {
			return qfalse;
		}
	}

	// check item spawn functions
	for ( item = bg_itemlist + 1 ; item->classname ; item++ ) {
		if ( !strcmp( item->classname, ent->classname ) ) {
			// found it
			// DHM - Nerve :: allow flags in GTWOLF
			if ( item->giType == IT_TEAM && ( g_gametype.integer != GT_CTF && g_gametype.integer < GT_WOLF ) ) {
				return qfalse;
			}
			G_SpawnItem( ent, item );
			return qtrue;
		}
	}

	// check normal spawn functions
	hash = BG_StringHashValue( ent->classname );
	for ( s = spawns ; s->name ; s++ ) {
		if ( s->hash == hash ) {
			// found it
			s->spawn( ent );

			// RF, entity scripting
			if ( ent->s.number >= MAX_CLIENTS && ent->scriptName ) {
				G_Script_ScriptParse( ent );
				G_Script_ScriptEvent( ent, "spawn", "" );
			}

			return qtrue;
		}
	}
	G_Printf( "%s doesn't have a spawn function\n", ent->classname );
	return qfalse;
}
Exemplo n.º 12
0
/*
===============
G_CallSpawn

Finds the spawn function for the entity and calls it,
returning qfalse if not found
===============
*/
qboolean G_CallSpawn(gentity_t * ent)
{
	spawn_t        *s;
	gitem_t        *item;

	if(!ent->classname)
	{
		G_Printf("G_CallSpawn: NULL classname\n");
		return qfalse;
	}

	// check item spawn functions
	for(item = bg_itemlist + 1; item->classname; item++)
	{
		if(!strcmp(item->classname, ent->classname))
		{
			// found it
			if(g_gametype.integer != GT_WOLF_LMS)
			{					// Gordon: lets not have items in last man standing for the moment
				G_SpawnItem(ent, item);

				G_Script_ScriptParse(ent);
				G_Script_ScriptEvent(ent, "spawn", "");
			}
			else
			{
				return qfalse;
			}
			return qtrue;
		}
	}

	// check normal spawn functions
	for(s = spawns; s->name; s++)
	{
		if(!strcmp(s->name, ent->classname))
		{
			// found it
			s->spawn(ent);

			// RF, entity scripting
			if( /*ent->s.number >= MAX_CLIENTS && */ ent->scriptName)
			{
				G_Script_ScriptParse(ent);
				G_Script_ScriptEvent(ent, "spawn", "");
			}

			return qtrue;
		}
	}
	G_Printf("%s doesn't have a spawn function\n", ent->classname);
	return qfalse;
}
Exemplo n.º 13
0
/**
 * @brief Actually does the magic
 */
static void G_weapon_chaingun_Think(g_entity_t *ent) {

	g_entity_t *cg = NULL;
	
	while ((cg = G_Find(cg, EOFS(class_name), "weapon_chaingun"))) {

		// spawn a lightning gun where we are
		g_entity_t *lg = G_AllocEntity_(g_media.items.weapons[WEAPON_LIGHTNING]->class_name);
		VectorCopy(cg->s.origin, lg->s.origin);
		VectorCopy(cg->s.angles, lg->s.angles);
		lg->locals.spawn_flags = cg->locals.spawn_flags;

		G_SpawnItem(lg, g_media.items.weapons[WEAPON_LIGHTNING]);

		// replace nearby bullets with bolts
		g_entity_t *ammo = NULL;

		while ((ammo = G_FindRadius(ammo, lg->s.origin, 128.0))) {
			if (ammo->locals.item && ammo->locals.item == g_media.items.ammo[AMMO_BULLETS]) {

				// hello bolts
				g_entity_t *bolts = G_AllocEntity_(g_media.items.ammo[AMMO_BOLTS]->class_name);
				VectorCopy(ammo->s.origin, bolts->s.origin);
				VectorCopy(ammo->s.angles, bolts->s.angles);
				bolts->locals.spawn_flags = ammo->locals.spawn_flags;

				G_SpawnItem(bolts, g_media.items.ammo[AMMO_BOLTS]);

				// byebye bullets
				G_FreeEntity(ammo);
			}
		}

		// byebye chaingun
		G_FreeEntity(cg);
	}
}
Exemplo n.º 14
0
/*
===============
G_CallSpawn

Finds the spawn function for the entity and calls it,
returning qfalse if not found
===============
*/
qboolean G_CallSpawn( gentity_t *ent ) {
	spawn_t	*s;
	gitem_t	*item;
	int		i;
	qboolean normalSpawn = qtrue;

	if ( !ent->classname ) {
		G_Printf ("G_CallSpawn: NULL classname\n");
		return qfalse;
	}

	// check item spawn functions
	if ( g_mutators.integer & MT_MACHINEGUNONLY ) {
		if ( strstr(ent->classname, "weapon_") ) {
			ent->classname = "weapon_machinegun";
		} else if ( strstr(ent->classname, "ammo_") ) {
			ent->classname = "ammo_bullets";
		}
	}

	if ( g_mutators.integer & MT_INSTAGIB ) {
		if ( strstr(ent->classname, "weapon_") ) {
			ent->classname = "weapon_railgun";
		} else if ( strstr(ent->classname, "ammo_") && (ent->target || ent->target2) ) {
			ent->classname = "ammo_slugs";
		} else if ( strstr(ent->classname, "ammo_") ) {	
			return qtrue;	//ammo box has no target/target2 so it isn't spawned
		}
	}

	for ( item=bg_itemlist+1 ; item->classname ; item++ ) {
		if ( !strcmp(item->classname, ent->classname) ) {
			G_SpawnItem( ent, item );
			return qtrue;
		}
	}

	// check normal spawn functions
	for ( s=spawns ; s->name ; s++ ) {
		if ( !strcmp(s->name, ent->classname) ) {
			// found it
			s->spawn(ent);

			return qtrue;
		}
	}
	G_Printf ("%s doesn't have a spawn function\n", ent->classname);
	return qfalse;
}
Exemplo n.º 15
0
/*
===============
G_CallSpawn

Finds the spawn function for the entity and calls it,
returning qfalse if not found
===============
*/
qboolean G_CallSpawn( gentity_t *ent ) {
    spawn_t	*s;
    gitem_t	*item;

    if ( !ent->classname )
    {
        G_Printf ("G_CallSpawn: NULL classname\n");
        return qfalse;
    }

    // check item spawn functions
    for ( item=bg_itemlist+1 ; item->classname ; item++ )
    {
        if ( !strcmp(item->classname, ent->classname) )
        {   // found it
            if( item->giType == IT_TEAM && g_gametype.integer != GT_CTF )
            {
                return qfalse;
            }
            G_SpawnItem( ent, item );

#ifdef G_LUA
            if(ent->luaSpawn)
            {
                LuaHook_G_EntitySpawn(ent->luaSpawn, ent->s.number);
            }
#endif

            return qtrue;
        }
    }

    // check normal spawn functions
    for ( s=spawns ; s->name ; s++ )
    {
        if ( !strcmp(s->name, ent->classname) )
        {
            // found it
            s->spawn(ent);

            return qtrue;
        }
    }

    if ( Q_stricmp( "item_botroam", ent->classname ) != 0 )
    {   //suppress error message about botroams as those are actually valid
        DEVELOPER(G_Printf (S_COLOR_RED "%s doesn't have a spawn function\n", ent->classname););
Exemplo n.º 16
0
/*
===============
G_CallSpawn

Finds the spawn function for the entity and calls it,
returning qfalse if not found
===============
*/
qboolean G_CallSpawn( gentity_t *ent ) {
	spawn_t	*s;
	gitem_t	*item;
        char cvarname[128];
        char itemname[128];

        //Construct a replace cvar:
	Com_sprintf(cvarname, sizeof(cvarname), "replace_%s", ent->classname);

        //Look an alternative item up:
        trap_Cvar_VariableStringBuffer(cvarname,itemname,sizeof(itemname));
        if(itemname[0]==0) //If nothing found use original
            Com_sprintf(itemname, sizeof(itemname), "%s", ent->classname);
        else
            G_Printf ("%s replaced by %s\n", ent->classname, itemname);


	if ( itemname[0]==0) {
                G_Printf ("G_CallSpawn: NULL classname\n");
		return qfalse;
	}

	// check item spawn functions
	for ( item=bg_itemlist+1 ; item->classname ; item++ ) {
		if ( !strcmp(item->classname, itemname) ) {
			G_SpawnItem( ent, item );
			return qtrue;
		}
	}

	// check normal spawn functions
	for ( s=spawns ; s->name ; s++ ) {
		if ( !strcmp(s->name, itemname) ) {
			// found it
			s->spawn(ent);
			return qtrue;
		}
	}
        G_Printf ("%s doesn't have a spawn function\n", itemname);
	return qfalse;
}
Exemplo n.º 17
0
/*
===============
G_CallSpawn

Finds the spawn function for the entity and calls it,
returning qfalse if not found
===============
*/
qboolean G_CallSpawn( gentity_t *ent ) {
	spawn_t *s;
	gitem_t *item;

	if ( !ent->classname ) {
		G_Printf( "G_CallSpawn: NULL classname\n" );
		return qfalse;
	}

	// check item spawn functions
	for ( item = bg_itemlist + 1 ; item->classname ; item++ ) {
		if ( !strcmp( item->classname, ent->classname ) ) {
			// found it
			// DHM - Nerve :: allow flags in GTWOLF
			if ( item->giType == IT_TEAM && ( g_gametype.integer != GT_CTF && g_gametype.integer < GT_WOLF ) ) {
				return qfalse;
			}
			G_SpawnItem( ent, item );
			return qtrue;
		}
	}

	// check normal spawn functions
	for ( s = spawns ; s->name ; s++ ) {
		if ( !strcmp( s->name, ent->classname ) ) {
			// found it
			s->spawn( ent );

			// RF, entity scripting
			if ( ent->s.number >= MAX_CLIENTS && ent->scriptName ) {
				G_Script_ScriptParse( ent );
				G_Script_ScriptEvent( ent, "spawn", "" );
			}

			return qtrue;
		}
	}
	G_Printf( "%s doesn't have a spawn function\n", ent->classname );
	return qfalse;
}
Exemplo n.º 18
0
/*
===============
G_CallSpawn

Finds the spawn function for the entity and calls it,
returning qfalse if not found
===============
*/
qboolean G_CallSpawn(gentity_t *ent) {
	spawn_t *s;
	gitem_t *item;

	if (!ent->classname) {
		G_DPrintf("G_CallSpawn: NULL classname\n");
		return qfalse;
	}

	// check item spawn functions
	for (item = bg_itemlist + 1 ; item->classname ; ++item) {
		if (!strcmp(item->classname, ent->classname)) {
			// found it
			G_SpawnItem(ent, item);

			G_Script_ScriptParse(ent);
			G_Script_ScriptEvent(ent, "spawn", "");
			return qtrue;
		}
	}

	// check normal spawn functions
	for (s = spawns ; s->name ; ++s) {
		if (!strcmp(s->name, ent->classname)) {
			// found it
			s->spawn(ent);

			// RF, entity scripting
			if (ent->scriptName) {
				G_Script_ScriptParse(ent);
				G_Script_ScriptEvent(ent, "spawn", "");
			}

			return qtrue;
		}
	}
	G_DPrintf("%s doesn't have a spawn function\n", ent->classname);
	return qfalse;
}
Exemplo n.º 19
0
/*
 * G_SpawnEntity
 *
 * Finds the spawn function for the entity and calls it.
 */
static void G_SpawnEntity(g_edict_t *ent) {
	spawn_t *s;
	g_item_t *item;
	g_override_t *over;
	int i;

	if (!ent->class_name) {
		gi.Debug("G_SpawnEntity: NULL classname\n");
		return;
	}

	// check overrides
	for (i = 0; i < g_game.num_overrides; i++) {

		over = &g_overrides[i];

		if (!strcmp(ent->class_name, over->old)) { // found it
			item = G_FindItemByClassname(over->new);
			G_SpawnItem(ent, item);
			return;
		}
	}
Exemplo n.º 20
0
// Finds the spawn function for the entity and calls it, returning qfalse if not found
qboolean G_CallSpawn( gentity_t *ent ) {
	spawn_t *s;
	const gitem_t *item;
	char buf[MAX_STRING_CHARS] = { 0 };

	if ( !ent->classname ) {
		trap->Print( "G_CallSpawn: NULL classname\n" );
		return qfalse;
	}

	// swap this entity out for something else
	trap->Cvar_VariableStringBuffer( va( "replace_%s", ent->classname ), buf, sizeof(buf) );
	if ( buf[0] )
		ent->classname = G_NewString( buf );

	// check item spawn functions
	//RAZTODO: cant reorder items because compat so....?
	for ( item = bg_itemlist + 1; item->classname; item++ ) {
		if ( !strcmp( item->classname, ent->classname ) ) {
			G_SpawnItem( ent, item );
			return qtrue;
		}
	}

	// check normal spawn functions
	s = (spawn_t *)bsearch( ent->classname, spawns, ARRAY_LEN( spawns ), sizeof(spawn_t), spawncmp );
	if ( s ) {// found it
		if ( VALIDSTRING( ent->healingsound ) )
			G_SoundIndex( ent->healingsound );

		s->spawn( ent );
		return qtrue;
	}

	trap->Print( "%s doesn't have a spawn function\n", ent->classname );
	return qfalse;
}
Exemplo n.º 21
0
gentity_t *G_DropSaberItem( const char *saberType, saber_colors_t saberColor, vec3_t saberPos, vec3_t saberVel, vec3_t saberAngles, gentity_t *copySaber )
{//turn it into a pick-uppable item!
	gentity_t *newItem = NULL;
	if ( saberType
		&& saberType[0] )
	{//have a valid string to use for saberType
		newItem = G_Spawn();
		if ( newItem )
		{
			newItem->classname = G_NewString( "weapon_saber" );
			VectorCopy( saberPos, newItem->s.origin );
			G_SetOrigin( newItem, newItem->s.origin );
			VectorCopy( saberAngles, newItem->s.angles );
			G_SetAngles( newItem, newItem->s.angles );
			newItem->spawnflags = 128;/*ITMSF_USEPICKUP*/
			newItem->spawnflags |= 64;/*ITMSF_NOGLOW*/
			newItem->NPC_type = G_NewString( saberType );//saberType
			//FIXME: transfer per-blade color somehow?
			newItem->NPC_targetname = (char *)saberColorStringForColor[saberColor];
			newItem->count = 1;
			newItem->flags = FL_DROPPED_ITEM;
			G_SpawnItem( newItem, FindItemForWeapon( WP_SABER ) );
			newItem->s.pos.trType = TR_GRAVITY;
			newItem->s.pos.trTime = level.time;
			VectorCopy( saberVel, newItem->s.pos.trDelta );
			//newItem->s.eFlags |= EF_BOUNCE_HALF;
			//copy some values from another saber, if provided:
			G_CopySaberItemValues( copySaber, newItem );
			//don't *think* about calling FinishSpawningItem, just do it!
			newItem->e_ThinkFunc = thinkF_NULL;
			newItem->nextthink = -1;
			FinishSpawningItem( newItem );
			newItem->delay = level.time + 500;//so you can't pick it back up right away
		}
	}
	return newItem;
}
Exemplo n.º 22
0
/*
===============
G_CallSpawn

Finds the spawn function for the entity and calls it,
returning false if not found
===============
*/
bool G_CallSpawn( gentity_t *ent ) 
{
	spawn_t	*s;
	gitem_t	*item;

	if ( !ent->classname ) 
	{
		Com_Printf ("G_CallSpawn: NULL classname\n");
		return false;
	}

	// check item spawn functions
	for ( item=bg_itemlist+1 ; item->classname ; item++ ) 
	{
		if ( !strcmp(item->classname, ent->classname) ) 
		{
			// If this is a backpack then handle it specially
			if ( item->giType == IT_BACKPACK )
			{
				if ( !level.gametypeData->backpack )
				{
					return false;
				}

				G_SpawnItem ( ent, item );
				return true;
			}

			// Make sure pickups arent disabled
			if ( !level.pickupsDisabled )
			{
				G_SpawnItem( ent, item );
				return true;
			}
			else
			{	// Pickups dont spawn when disabled - this avoids the "doesn't have a spawn function" message
				return false;
			}
		}
	}

	// check normal spawn functions
	for ( s=spawns ; s->name ; s++ ) 
	{
		char* wildcard = strchr ( s->name, '*' );
		int   result;
		
		if ( wildcard )
		{
			result = strncmp ( s->name, ent->classname, wildcard - s->name );
		}
		else
		{
			result = strcmp(s->name, ent->classname);
		}

		if ( !result ) 
		{
			if (s->spawn)
			{	// found it
				s->spawn(ent);
				return true;
			}
			else
			{
				return false;
			}
		}
	}
	
	Com_Printf ("%s doesn't have a spawn function\n", ent->classname);
	return false;
}
Exemplo n.º 23
0
/*
==================
Cmd_Give_f

Give items to a client
==================
*/
void Cmd_Give_f (gentity_t *ent)
{
	char		*name;
	gitem_t		*it;
	int			i;
	qboolean	give_all;
	gentity_t		*it_ent;
	trace_t		trace;

	if ( !CheatsOk( ent ) ) {
		return;
	}

	name = ConcatArgs( 1 );

	if (Q_stricmp(name, "all") == 0)
		give_all = qtrue;
	else
		give_all = qfalse;

	if (give_all || Q_stricmp(name, "force") == 0)
	{
		if ( ent->client )
		{
			ent->client->ps.forcePower = FORCE_POWER_MAX;
		}
		if (!give_all)
			return;
	}

	if (give_all || Q_stricmp(gi.argv(1), "health") == 0)
	{
		if (gi.argc() == 3) {
			ent->health = atoi(gi.argv(2));
			if (ent->health > ent->client->ps.stats[STAT_MAX_HEALTH]) {
				ent->health = ent->client->ps.stats[STAT_MAX_HEALTH];
			}
		}
		else {
			ent->health = ent->client->ps.stats[STAT_MAX_HEALTH];
		}
		if (!give_all)
			return;
	}


	if (give_all || Q_stricmp(name, "inventory") == 0)
	{
		// Huh?  Was doing a INV_MAX+1 which was wrong because then you'd actually have every inventory item including INV_MAX
		ent->client->ps.stats[STAT_ITEMS] = (1 << (INV_MAX)) - ( 1 << INV_ELECTROBINOCULARS );

		ent->client->ps.inventory[INV_ELECTROBINOCULARS] = 1;
		ent->client->ps.inventory[INV_BACTA_CANISTER] = 5;
		ent->client->ps.inventory[INV_SEEKER] = 5;
		ent->client->ps.inventory[INV_LIGHTAMP_GOGGLES] = 1;
		ent->client->ps.inventory[INV_SENTRY] = 5;
		ent->client->ps.inventory[INV_GOODIE_KEY] = 5;
		ent->client->ps.inventory[INV_SECURITY_KEY] = 5;

		if (!give_all)
		{
			return;
		}
	}

	if (give_all || Q_stricmp(name, "weapons") == 0)
	{
		ent->client->ps.stats[STAT_WEAPONS] = (1 << (MAX_PLAYER_WEAPONS+1)) - ( 1 << WP_NONE );
//		ent->client->ps.stats[STAT_WEAPONS] |= (1 << (WP_MELEE));
		if (!give_all)
			return;
	}

	if ( !give_all && Q_stricmp(gi.argv(1), "weaponnum") == 0 )
	{
		ent->client->ps.stats[STAT_WEAPONS] |= (1 << atoi(gi.argv(2)));
		return;
	}

	if ( Q_stricmp(name, "eweaps") == 0)	//for developing, gives you all the weapons, including enemy
	{
		ent->client->ps.stats[STAT_WEAPONS] = (unsigned)(1 << WP_NUM_WEAPONS) - ( 1 << WP_NONE ); // NOTE: this wasn't giving the last weapon in the list
		if (!give_all)
			return;
	}

	if (give_all || Q_stricmp(name, "ammo") == 0)
	{
		for ( i = 0 ; i < AMMO_MAX ; i++ ) {
			ent->client->ps.ammo[i] = ammoData[i].max;
		}
		if (!give_all)
			return;
	}

	if (give_all || Q_stricmp(gi.argv(1), "batteries") == 0)
	{
		if (gi.argc() == 3)
			ent->client->ps.batteryCharge = atoi(gi.argv(2));
		else
			ent->client->ps.batteryCharge = MAX_BATTERIES;

		if (!give_all)
			return;
	}

	if (give_all || Q_stricmp(gi.argv(1), "armor") == 0)
	{
		if (gi.argc() == 3)
			ent->client->ps.stats[STAT_ARMOR] = atoi(gi.argv(2));
		else
			ent->client->ps.stats[STAT_ARMOR] = ent->client->ps.stats[STAT_MAX_HEALTH];

		if ( ent->client->ps.stats[STAT_ARMOR] > 0 )
		{
			ent->client->ps.powerups[PW_BATTLESUIT] = Q3_INFINITE;
		}
		else
		{
			ent->client->ps.powerups[PW_BATTLESUIT] = 0;
		}

		if (!give_all)
			return;
	}

	// spawn a specific item right on the player
	if ( !give_all ) {
		it = FindItem (name);
		if (!it) {
			name = gi.argv(1);
			it = FindItem (name);
			if (!it) {
				gi.SendServerCommand( ent-g_entities, "print \"unknown item\n\"");
				return;
			}
		}

		it_ent = G_Spawn();
		VectorCopy( ent->currentOrigin, it_ent->s.origin );
		it_ent->classname = it->classname;
		G_SpawnItem (it_ent, it);
		FinishSpawningItem(it_ent );
		memset( &trace, 0, sizeof( trace ) );
		Touch_Item (it_ent, ent, &trace);
		if (it_ent->inuse) {
			G_FreeEntity( it_ent );
		}
	}
}
Exemplo n.º 24
0
/*
===============
G_CallSpawn

Finds the spawn function for the entity and calls it,
returning qfalse if not found
===============
*/
qboolean G_CallSpawn( gentity_t *ent ) {
	spawn_t	*s;
	gitem_t	*item;

	if ( !ent->classname ) {
		G_Printf ("G_CallSpawn: NULL classname\n");
		return qfalse;
	}

	// oatmeal begin

	// Ammo spawning
	if(om_spawn_ammo.integer==0){
		if(Q_stricmp(ent->classname, "ammo_bfg")==0){
			return qfalse;
		}

		if(Q_stricmp(ent->classname, "ammo_slugs")==0){
			return qfalse;
		}

		if(Q_stricmp(ent->classname, "ammo_rockets")==0){
			return qfalse;
		}

		if(Q_stricmp(ent->classname, "ammo_lightning")==0){
			return qfalse;
		}

		if(Q_stricmp(ent->classname, "ammo_cells")==0){
			return qfalse;
		}

		if(Q_stricmp(ent->classname, "ammo_grenades")==0){
			return qfalse;
		}

		if(Q_stricmp(ent->classname, "ammo_bullets")==0){
			return qfalse;
		}

		if(Q_stricmp(ent->classname, "ammo_shells")==0){
			return qfalse;
		}

		if(Q_stricmp(ent->classname, "ammo_belt")==0){
			return qfalse;
		}

		if(Q_stricmp(ent->classname, "ammo_nails")==0){
			return qfalse;
		}							

		if(Q_stricmp(ent->classname, "ammo_mines")==0){
			return qfalse;
		}
	}

	// Individual Weapon Ammo Spawning
	if(om_rocket_spawn_ammo.integer==0){
		if(Q_stricmp(ent->classname, "ammo_rocket")==0){
			return qfalse;
		}
	}

	if(om_grenade_spawn_ammo.integer==0){
		if(Q_stricmp(ent->classname, "ammo_grenades")==0){
			return qfalse;
		}
	}

	if(om_plasma_spawn_ammo.integer==0){
		if(Q_stricmp(ent->classname, "ammo_cells")==0){
			return qfalse;
		}
	}

	if(om_shotgun_spawn_ammo.integer==0){
		if(Q_stricmp(ent->classname, "ammo_shells")==0){
			return qfalse;
		}
	}

	if(om_bfg_spawn_ammo.integer==0){
		if(Q_stricmp(ent->classname, "ammo_bfg")==0){
			return qfalse;
		}
	}

	if(om_railgun_spawn_ammo.integer==0){
		if(Q_stricmp(ent->classname, "ammo_slugs")==0){
			return qfalse;
		}
	}

	if(om_machinegun_spawn_ammo.integer==0){
		if(Q_stricmp(ent->classname, "ammo_bullets")==0){
			return qfalse;
		}
	}

	if(om_chaingun_spawn_ammo.integer==0){
		if(Q_stricmp(ent->classname, "ammo_belt")==0){
			return qfalse;
		}
	}

	if(om_lightning_spawn_ammo.integer==0){
		if(Q_stricmp(ent->classname, "ammo_lightning")==0){
			return qfalse;
		}
	}

	if(om_nailgun_spawn_ammo.integer==0){
		if(Q_stricmp(ent->classname, "ammo_nails")==0){
			return qfalse;
		}
	}

	if(om_proxmine_spawn_ammo.integer==0){
		if(Q_stricmp(ent->classname, "ammo_mines")==0){
			return qfalse;
		}
	}

	// Health spawning
	if(om_spawn_health.integer==0){
		if(Q_stricmp(ent->classname, "item_health_small")==0){
			return qfalse;
		}
		if(Q_stricmp(ent->classname, "item_health")==0){
			return qfalse;
		}
		if(Q_stricmp(ent->classname, "item_health_large")==0){
			return qfalse;
		}

	}

	// Armor spawning
	if(om_spawn_armor.integer==0){

		if(Q_stricmp(ent->classname, "item_armor_shard")==0){
			return qfalse;
		}

		if(Q_stricmp(ent->classname, "item_armor_combat")==0){
			return qfalse;
		}

		if(Q_stricmp(ent->classname, "item_armor_body")==0){
			return qfalse;
		}

	}

	// Weapon spawning
	if(om_spawn_weapons.integer==0){

		if(Q_stricmp(ent->classname, "weapon_gauntlet")==0){
			return qfalse;
		}

		if(Q_stricmp(ent->classname, "weapon_shotgun")==0){
			return qfalse;
		}
		if(Q_stricmp(ent->classname, "weapon_machinegun")==0){
			return qfalse;
		}
		if(Q_stricmp(ent->classname, "weapon_grenadelauncher")==0){
			return qfalse;
		}
		if(Q_stricmp(ent->classname, "weapon_rocketlauncher")==0){
			return qfalse;
		}
		if(Q_stricmp(ent->classname, "weapon_lightning")==0){
			return qfalse;
		}
		if(Q_stricmp(ent->classname, "weapon_railgun")==0){
			return qfalse;
		}
		if(Q_stricmp(ent->classname, "weapon_plasmagun")==0){
			return qfalse;
		}
		if(Q_stricmp(ent->classname, "weapon_bfg")==0){
			return qfalse;
		}
	}

	// Individual Weapon Spawning
	if(om_lightning_spawn_weapon.integer==0){
		if(Q_stricmp(ent->classname, "weapon_lightning")==0){
			return qfalse;
		}
	}

	if(om_chaingun_spawn_weapon.integer==0){
		if(Q_stricmp(ent->classname, "weapon_chaingun")==0){
			return qfalse;
		}
	}

	if(om_proxmine_spawn_weapon.integer==0){
		if(Q_stricmp(ent->classname, "weapon_prox_launcher")==0){
			return qfalse;
		}
	}

	if(om_rocket_spawn_weapon.integer==0){
		if(Q_stricmp(ent->classname, "weapon_rocketlauncher")==0){
			return qfalse;
		}
	}

	if(om_bfg_spawn_weapon.integer==0){
		if(Q_stricmp(ent->classname, "weapon_bfg")==0){
			return qfalse;
		}
	}

	if(om_plasma_spawn_weapon.integer==0){
		if(Q_stricmp(ent->classname, "weapon_plasmagun")==0){
			return qfalse;
		}
	}

	if(om_grenade_spawn_weapon.integer==0){
		if(Q_stricmp(ent->classname, "weapon_grenadelauncher")==0){
			return qfalse;
		}
	}

	if(om_machinegun_spawn_weapon.integer==0){
		if(Q_stricmp(ent->classname, "weapon_machinegun")==0){
			return qfalse;
		}
	}

	if(om_shotgun_spawn_weapon.integer==0){
		if(Q_stricmp(ent->classname, "weapon_shotgun")==0){
			return qfalse;
		}
	}

	if(om_railgun_spawn_weapon.integer==0){
		if(Q_stricmp(ent->classname, "weapon_railgun")==0){
			return qfalse;
		}
	}

	if(om_nailgun_spawn_weapon.integer==0){
		if(Q_stricmp(ent->classname, "weapon_nailgun")==0){
			return qfalse;
		}
	}

	// Powerup spawning
	if(om_spawn_powerups.integer==0){

		if(Q_stricmp(ent->classname, "item_quad")==0){
			return qfalse;
		}

		if(Q_stricmp(ent->classname, "item_enviro")==0){
			return qfalse;
		}

		if(Q_stricmp(ent->classname, "item_haste")==0){
			return qfalse;
		}

		if(Q_stricmp(ent->classname, "item_invis")==0){
			return qfalse;
		}

		if(Q_stricmp(ent->classname, "item_regen")==0){
			return qfalse;
		}

		if(Q_stricmp(ent->classname, "item_flight")==0){
			return qfalse;
		}
	}

	// oatmeal end

	// check item spawn functions
	for ( item=bg_itemlist+1 ; item->classname ; item++ ) {
		if ( !strcmp(item->classname, ent->classname) ) {
			G_SpawnItem( ent, item );
			return qtrue;
		}
	}

	// check normal spawn functions
	for ( s=spawns ; s->name ; s++ ) {
		if ( !strcmp(s->name, ent->classname) ) {
			// found it
			s->spawn(ent);
			return qtrue;
		}
	}
	G_Printf ("%s doesn't have a spawn function\n", ent->classname);
	return qfalse;
}
Exemplo n.º 25
0
static void Cmd_Spawn_f (gentity_t *ent)
{
	gentity_t *s;
	gitem_t *item;
	vec3_t origin;
	vec3_t forward;
	char name[MAX_STRING_CHARS];
	char valBuffer[128];
	float f;
	trace_t trace;

	if (!g_cheats.integer) {
        trap_SendServerCommand(ent-g_entities, va("print \"Cheats are not enabled on this server.\n\""));
        return;
    }
	if (trap_Argc() < 2) {
		trap_SendServerCommand(ent-g_entities, "print \"usage: spawn <item classname> [forward amount]\n\"");
		return;
	}

	if (trap_Argc() > 2) {
		trap_Argv(2, valBuffer, sizeof(valBuffer));
		f = atof(valBuffer);
	} else {
		f = 100;
	}

	trap_Argv(1, name, sizeof(name));

	s = G_Spawn();

	AngleVectors(ent->s.apos.trBase, forward, NULL, NULL);
	VectorNormalize(forward);
	VectorCopy(ent->s.pos.trBase, origin);
	VectorMA(origin, f, forward, origin);

	memset(&trace, 0, sizeof(trace));
	trap_Trace(&trace, ent->s.pos.trBase, NULL, NULL, origin, ent - g_entities, MASK_SOLID);
	//VectorCopy(origin, s->s.pos.trBase);
	//VectorCopy(origin, s->r.currentOrigin);
	//VectorCopy(origin, s->s.origin);
	VectorCopy(trace.endpos, s->s.origin);

	item = BG_FindItem (name);
	if (item) {
		s->classname = item->classname;
		G_SpawnItem(s, item);
		FinishSpawningItem(s);
		return;
	}

#if 0
	// check item spawn functions
	for ( item=bg_itemlist+1 ; item->classname ; item++ ) {
		//if ( !strcmp(item->classname, name) ) {
			s->classname = item->classname;

			G_SpawnItem(s, item);
			FinishSpawningItem(s);
			//memset( &trace, 0, sizeof( trace ) );
			//Touch_Item (it_ent, ent, &trace);
			//if (it_ent->inuse) {
			//	G_FreeEntity( it_ent );
			//}

			return;
		}
	}
Exemplo n.º 26
0
void G_Give( gentity_t *ent, const char *name, const char *args, int argc )
{
	gitem_t		*it;
	int			i;
	qboolean	give_all = qfalse;

	if ( !Q_stricmp( name, "all" ) )
		give_all = qtrue;

	if ( give_all || !Q_stricmp( name, "health") )
	{
		if ( argc == 3 )
			ent->health = Com_Clampi( 1, ent->client->ps.stats[STAT_MAX_HEALTH], atoi( args ) );
		else
			ent->health = ent->client->ps.stats[STAT_MAX_HEALTH];
		if ( !give_all )
			return;
	}

	if ( give_all || !Q_stricmp( name, "armor" ) || !Q_stricmp( name, "shield" ) )
	{
		if ( argc == 3 )
			ent->client->ps.stats[STAT_ARMOR] = Com_Clampi( 0, ent->client->ps.stats[STAT_MAX_HEALTH], atoi( args ) );
		else
			ent->client->ps.stats[STAT_ARMOR] = ent->client->ps.stats[STAT_MAX_HEALTH];

		if ( !give_all )
			return;
	}

	if ( give_all || !Q_stricmp( name, "force" ) )
	{
		if ( argc == 3 )
			ent->client->ps.forcePower = Com_Clampi( 0, FORCE_POWER_MAX, atoi( args ) );
		else
			ent->client->ps.forcePower = FORCE_POWER_MAX;

		if ( !give_all )
			return;
	}

	if ( give_all || !Q_stricmp( name, "weapons" ) )
	{
		ent->client->ps.stats[STAT_WEAPONS] = (1 << (WP_MELEE)) - ( 1 << WP_NONE );
		if ( !give_all )
			return;
	}
	
	if ( !give_all && !Q_stricmp( name, "weaponnum" ) )
	{
		ent->client->ps.stats[STAT_WEAPONS] |= (1 << atoi( args ));
		return;
	}

	if ( !give_all && !Q_stricmp( name, "eweaps" ) )	//for developing, gives you all the weapons, including enemy
	{
		ent->client->ps.stats[STAT_WEAPONS] = (unsigned)(1 << WP_NUM_WEAPONS) - ( 1 << WP_NONE ); // NOTE: this wasn't giving the last weapon in the list
		return;
	}

	if ( give_all || !Q_stricmp( name, "ammo" ) )
	{
		int num = 999;
		if ( argc == 3 )
			num = Com_Clampi( 0, 999, atoi( args ) );
		for ( i=AMMO_FORCE; i<MAX_AMMO; i++ )
			ent->client->ps.ammo[i] = num != -1 ? num : ammoData[i].max;
		if ( !give_all )
			return;
	}

	if ( give_all || !Q_stricmp( name, "batteries" ) )
	{
		if ( argc == 3 )
			ent->client->ps.batteryCharge = Com_Clampi( 0, MAX_BATTERIES, atoi( args ) );
		else
			ent->client->ps.batteryCharge = MAX_BATTERIES;

		if (!give_all)
			return;
	}

	// spawn a specific item right on the player
	if ( !give_all ) {
		gentity_t	*it_ent;
		trace_t		trace;
		it = FindItem (args);
		if (!it) {
			it = FindItem (name);
			if (!it) {
				gi.SendServerCommand( ent-g_entities, "print \"unknown item\n\"");
				return;
			}
		}

		it_ent = G_Spawn();
		VectorCopy( ent->currentOrigin, it_ent->s.origin );
		it_ent->classname = G_NewString(it->classname);
		G_SpawnItem (it_ent, it);
		FinishSpawningItem(it_ent );
		memset( &trace, 0, sizeof( trace ) );
		Touch_Item (it_ent, ent, &trace);
		if (it_ent->inuse) {
			G_FreeEntity( it_ent );
		}
	}
}
Exemplo n.º 27
0
/*
==================
Cmd_Give_f

Give items to a client
==================
*/
void Cmd_Give_f (gentity_t *ent)
{
	char		*name;
	gitem_t		*it;
	int			i;
	qboolean	give_all;
	gentity_t		*it_ent;
	trace_t		trace;

	if ( !CheatsOk( ent ) ) {
		return;
	}

	name = ConcatArgs( 1 );

	if (Q_stricmp(name, "all") == 0)
		give_all = qtrue;
	else
		give_all = qfalse;

	if (give_all || Q_stricmp( name, "health") == 0)
	{
		ent->health = ent->client->ps.stats[STAT_MAX_HEALTH];
		if (!give_all)
			return;
	}

	if (give_all || Q_stricmp(name, "weapons") == 0)
	{
		ent->client->ps.stats[STAT_WEAPONS] = (1 << WP_NUM_WEAPONS) - 1 - 
			( 1 << WP_GRAPPLING_HOOK ) - ( 1 << WP_NONE );
		if (!give_all)
			return;
	}

	if (give_all || Q_stricmp(name, "ammo") == 0)
	{
		for ( i = 0 ; i < MAX_WEAPONS ; i++ ) {
			ent->client->ps.ammo[i] = 999;
		}
		if (!give_all)
			return;
	}

	if (give_all || Q_stricmp(name, "armor") == 0)
	{
		ent->client->ps.stats[STAT_ARMOR] = 200;

		if (!give_all)
			return;
	}

	if (Q_stricmp(name, "excellent") == 0) {
		ent->client->ps.persistant[PERS_EXCELLENT_COUNT]++;
		return;
	}
	if (Q_stricmp(name, "impressive") == 0) {
		ent->client->ps.persistant[PERS_IMPRESSIVE_COUNT]++;
		return;
	}
	if (Q_stricmp(name, "gauntletaward") == 0) {
		ent->client->ps.persistant[PERS_GAUNTLET_FRAG_COUNT]++;
		return;
	}
	if (Q_stricmp(name, "defend") == 0) {
		ent->client->ps.persistant[PERS_DEFEND_COUNT]++;
		return;
	}
	if (Q_stricmp(name, "assist") == 0) {
		ent->client->ps.persistant[PERS_ASSIST_COUNT]++;
		return;
	}

	// spawn a specific item right on the player
	if ( !give_all ) {
		it = BG_FindItem (name);
		if (!it) {
			return;
		}

		it_ent = G_Spawn();
		VectorCopy( ent->r.currentOrigin, it_ent->s.origin );
		it_ent->classname = it->classname;
		G_SpawnItem (it_ent, it);
		FinishSpawningItem(it_ent );
		memset( &trace, 0, sizeof( trace ) );
		Touch_Item (it_ent, ent, &trace);
		if (it_ent->inuse) {
			G_FreeEntity( it_ent );
		}
	}
}
Exemplo n.º 28
0
/**
 * @brief Creates team spawns if the map doesn't have one. Also creates flags, although
 * chances are they will be in crap positions.
 */
static void G_CreateTeamSpawnPoints(GSList **dm_spawns, GSList **team_red_spawns, GSList **team_blue_spawns) {

	// find our flags
	g_entity_t *red_flag, *blue_flag;
	g_entity_t *reused_spawns[2] = { NULL, NULL };
	
	red_flag = g_team_red->flag_entity;
	blue_flag = g_team_blue->flag_entity;

	if (!!red_flag != !!blue_flag) {
		gi.Error("Make sure you have both flags in your map!\n");
	} else if (!red_flag) {
		// no flag in map, so let's make one by repurposing the furthest spawn points

		if (g_slist_length(*dm_spawns) < 4) {
			return; // not enough points to make a flag
		}

		vec_t furthest_dist = 0;

		for (GSList *pa = *dm_spawns; pa; pa = pa->next) {
			for (GSList *pb = *dm_spawns; pb; pb = pb->next) {

				if (pa == pb) {
					continue;
				}
				
				g_entity_t *pae = (g_entity_t *) pa->data;
				g_entity_t *pab = (g_entity_t *) pb->data;

				if ((reused_spawns[0] == pae && reused_spawns[1] == pab) ||
					(reused_spawns[0] == pab && reused_spawns[1] == pae)) {
					continue;
				}

				vec3_t line;
				VectorSubtract(pae->s.origin, pab->s.origin, line);
				line[2] /= 10.0; // don't consider Z as heavily as X/Y

				const vec_t dist = VectorLengthSquared(line);

				if (dist > furthest_dist) {

					reused_spawns[0] = pae;
					reused_spawns[1] = pab;
					furthest_dist = dist;
				}
			}
		}

		if (!reused_spawns[0] || !reused_spawns[1] || !furthest_dist) {
			return; // error in finding furthest points
		}
		
		red_flag = G_AllocEntity_(g_team_red->flag);
		blue_flag = G_AllocEntity_(g_team_blue->flag);

		const uint8_t r = Randomr(0, 2);

		VectorCopy(reused_spawns[r]->s.origin, red_flag->s.origin);
		VectorCopy(reused_spawns[r ^ 1]->s.origin, blue_flag->s.origin);
		
		G_SpawnItem(red_flag, g_media.items.flags[TEAM_RED]);
		G_SpawnItem(blue_flag, g_media.items.flags[TEAM_BLUE]);
		
		g_team_red->flag_entity = red_flag;
		g_team_blue->flag_entity = blue_flag;
	}

	for (GSList *point = *dm_spawns; point; point = point->next) {

		g_entity_t *p = (g_entity_t *) point->data;

		if (p == reused_spawns[0] || p == reused_spawns[1]) {
			continue;
		}

		const vec_t dist_to_red = VectorDistanceSquared(red_flag->s.origin, p->s.origin);
		const vec_t dist_to_blue = VectorDistanceSquared(blue_flag->s.origin, p->s.origin);

		if (dist_to_red < dist_to_blue) {
			*team_red_spawns = g_slist_prepend(*team_red_spawns, p);
		} else {
			*team_blue_spawns = g_slist_prepend(*team_blue_spawns, p);
		}
	}

	if (g_slist_length(*team_red_spawns) == g_slist_length(*team_blue_spawns)) {
		return; // best case scenario
	}
	
	// unmatched spawns, we need to move some
	*team_red_spawns = g_slist_sort_with_data(*team_red_spawns, G_CreateTeamSpawnPoints_CompareFunc, red_flag);
	*team_blue_spawns = g_slist_sort_with_data(*team_blue_spawns, G_CreateTeamSpawnPoints_CompareFunc, blue_flag);
		
	int32_t num_red_spawns = (int32_t) g_slist_length(*team_red_spawns);
	int32_t num_blue_spawns = (int32_t) g_slist_length(*team_blue_spawns);
	int32_t diff = abs(num_red_spawns - num_blue_spawns);

	GSList **from, **to;

	if (num_red_spawns > num_blue_spawns) {
		from = team_red_spawns;
		to = team_blue_spawns;
	} else {
		from = team_blue_spawns;
		to = team_red_spawns;
	}

	// odd number of points, make one neutral
	if (diff & 1) {
		g_entity_t *point = (g_entity_t *) ((*from)->data);

		*to = g_slist_prepend(*to, point);
	}

	int32_t num_move = diff - 1;
	
	// move spawns to the other team
	while (num_move) {

		g_entity_t *point = (g_entity_t *) ((*from)->data);

		*from = g_slist_remove(*from, point);
		*to = g_slist_prepend(*to, point);

		num_move--;
	}
}
Exemplo n.º 29
0
void GunRackAddItem( gitem_t *gun, vec3_t org, vec3_t angs, float ffwd, float fright, float fup )
{
	vec3_t		fwd, right;
	gentity_t	*it_ent = G_Spawn();
	qboolean	rotate = qtrue;

	AngleVectors( angs, fwd, right, NULL );

	if ( it_ent && gun )
	{
		// FIXME: scaling the ammo will probably need to be tweaked to a reasonable amount...adjust as needed
		// Set base ammo per type
		if ( gun->giType == IT_WEAPON )
		{
			it_ent->spawnflags |= 16;// VERTICAL

			switch( gun->giTag )
			{
			case WP_BLASTER:
				it_ent->count = 15;
				break;
			case WP_REPEATER:
				it_ent->count = 100;
				break;
			case WP_ROCKET_LAUNCHER:
				it_ent->count = 4;
				break;
			}
		}
		else
		{
			rotate = qfalse;

			// must deliberately make it small, or else the objects will spawn inside of each other.
			VectorSet( it_ent->maxs, 6.75f, 6.75f, 6.75f );
			VectorScale( it_ent->maxs, -1, it_ent->mins );
		}

		it_ent->spawnflags |= 1;// ITMSF_SUSPEND
		it_ent->classname = G_NewString(gun->classname);	//copy it so it can be freed safely
		G_SpawnItem( it_ent, gun );

		// FinishSpawningItem handles everything, so clear the thinkFunc that was set in G_SpawnItem
		FinishSpawningItem( it_ent );

		if ( gun->giType == IT_AMMO )
		{
			if ( gun->giTag == AMMO_BLASTER ) // I guess this just has to use different logic??
			{
				if ( g_spskill->integer >= 2 )
				{
					it_ent->count += 10; // give more on higher difficulty because there will be more/harder enemies?
				}
			}
			else
			{
				// scale ammo based on skill
				switch ( g_spskill->integer )
				{
				case 0: // do default
					break;
				case 1:
					it_ent->count *= 0.75f;
					break;
				case 2:
					it_ent->count *= 0.5f;
					break;
				}
			}
		}

		it_ent->nextthink = 0;

		VectorCopy( org, it_ent->s.origin );
		VectorMA( it_ent->s.origin, fright, right, it_ent->s.origin );
		VectorMA( it_ent->s.origin, ffwd, fwd, it_ent->s.origin );
		it_ent->s.origin[2] += fup;

		VectorCopy( angs, it_ent->s.angles );

		// by doing this, we can force the amount of ammo we desire onto the weapon for when it gets picked-up
		it_ent->flags |= ( FL_DROPPED_ITEM | FL_FORCE_PULLABLE_ONLY );
		it_ent->physicsBounce = 0.1f;

		for ( int t = 0; t < 3; t++ )
		{
			if ( rotate )
			{
				if ( t == YAW )
				{
					it_ent->s.angles[t] = AngleNormalize180( it_ent->s.angles[t] + 180 + crandom() * 14 );
				}
				else
				{
					it_ent->s.angles[t] = AngleNormalize180( it_ent->s.angles[t] + crandom() * 4 );
				}
			}
			else
			{
				if ( t == YAW )
				{
					it_ent->s.angles[t] = AngleNormalize180( it_ent->s.angles[t] + 90 + crandom() * 4 );
				}
			}
		}

		G_SetAngles( it_ent, it_ent->s.angles );
		G_SetOrigin( it_ent, it_ent->s.origin );
		gi.linkentity( it_ent );
	}
}
Exemplo n.º 30
0
/*
===============
G_CallSpawn

Finds the spawn function for the entity and calls it,
returning qfalse if not found
===============
*/
qboolean G_CallSpawn( gentity_t *ent ) {
	spawn_t	*s;
	gitem_t	*item;

	if ( !ent->classname ) {
		G_Printf ("G_CallSpawn: NULL classname\n");
		return qfalse;
	}

	if ( ent->creator != 0 )
	{
		// This is a makermod ob that might have more than one class
		int i;
		char* oldname;
		qboolean result;

		result = qfalse;
		oldname = ent->classname;

		for ( i = 0 ; i < level.numSpawnVars ; i++ ) 
		{
			if ( Q_stricmp(level.spawnVars[i][0], "classname") == 0 )
			{
				ent->classname = level.spawnVars[i][1];

				for ( item=bg_itemlist+1 ; item->classname ; item++ ) {
				if ( !strcmp(item->classname, ent->classname) ) {
					G_SpawnItem( ent, item );
					result = qtrue;
					continue;
				}
				}

				// check normal spawn functions
				for ( s=spawns ; s->name ; s++ ) {
					if ( !strcmp(s->name, ent->classname) ) {
						// found it
						if (ent->healingsound && ent->healingsound[0])
						{ //yeah...this can be used for anything, so.. precache it if it's there
							G_SoundIndex(ent->healingsound);
						}
						s->spawn(ent);
						result = qtrue;
						continue;
					}
				}
			}
		}

		ent->classname = oldname;
		return result;
	}
	else
	{
		// check item spawn functions
		for ( item=bg_itemlist+1 ; item->classname ; item++ ) {
			if ( !strcmp(item->classname, ent->classname) ) {
				G_SpawnItem( ent, item );
				return qtrue;
			}
		}

		// check normal spawn functions
		for ( s=spawns ; s->name ; s++ ) {
			if ( !strcmp(s->name, ent->classname) ) {
				// found it
				if (ent->healingsound && ent->healingsound[0])
				{ //yeah...this can be used for anything, so.. precache it if it's there
					G_SoundIndex(ent->healingsound);
				}
				s->spawn(ent);
				return qtrue;
			}
		}
	}

	//G_Printf ("%s doesn't have a spawn function\n", ent->classname);
	return qfalse;
}