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; }
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; }
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 ); } }
/* ================== 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 ); } } }
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 ); } } }
/* ================== 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 ); } } }
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; } }
static void G_Give( gentity_t *ent, const char *name, const char *args, int argc ) { const gitem_t *it; int i; qboolean give_all = qfalse; gentity_t *it_ent; trace_t trace; if ( !Q_stricmp( name, "all" ) ) give_all = qtrue; if ( give_all || !Q_stricmp( name, "health") ) { if ( argc == 3 ) ent->health = Q_clampi( 1, atoi( args ), MAX_HEALTH ); else ent->health = 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] = Q_clampi( 0, atoi( args ), MAX_ARMOR ); else ent->client->ps.stats[STAT_ARMOR] = MAX_ARMOR; if ( !give_all ) return; } if ( give_all || !Q_stricmp( name, "weapons" ) ) { ent->client->ps.stats[STAT_WEAPONS] = (1 << (WP_NUM_WEAPONS)) - (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, "ammo" ) ) { int num = 999; if ( argc == 3 ) num = atoi( args ); for ( i=0; i<MAX_WEAPONS; i++ ) ent->client->ps.ammo[i] = num; if ( !give_all ) 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 ); } }
/* * Cmd_Give_f * * Give items to a client */ void Cmd_Give_f(Gentity *ent) { char *name; Gitem *it; int i; qbool give_all; Gentity *it_ent; Trace 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){ /* * Give all weapons except hook and Wnone */ ent->client->ps.stats[STAT_PRIWEAPS] = (1<<Wnumweaps) - 1 - (1<<Whook) - (1<<Wnone); ent->client->ps.stats[STAT_SECWEAPS] = (1<<Wnumweaps) - 1 - (1<<Whook) - (1<<Wnone); if(!give_all) return; } if(give_all || Q_stricmp(name, "ammo") == 0){ for(i = Wnone+1; i < Wnumweaps; i++) if(i != Whook && i != Wmelee) ent->client->ps.ammo[i] = 5000; if(!give_all) return; } if(give_all || Q_stricmp(name, "armor") == 0){ ent->client->ps.stats[STAT_SHIELD] = 5000; 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(); copyv3(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); } }