/* * CG_ValidateItemDef * * Compares name and tag against the itemlist to make sure cgame and game lists match */ void CG_ValidateItemDef( int tag, char *name ) { gsitem_t *item; item = GS_FindItemByName( name ); if( !item ) CG_Error( "Client/Server itemlist missmatch (Game and Cgame version/mod differs). Item '%s' not found\n", name ); if( item->tag != tag ) CG_Error( "Client/Server itemlist missmatch (Game and Cgame version/mod differs).\n" ); }
/* * Cmd_Give_f * * Give items to a client */ static void Cmd_Give_f( edict_t *ent ) { char *name; gsitem_t *it; int i; bool give_all; if( !sv_cheats->integer ) { G_PrintMsg( ent, "Cheats are not enabled on this server.\n" ); return; } name = trap_Cmd_Args(); if( !Q_stricmp( name, "all" ) ) give_all = true; else give_all = false; if( give_all || !Q_stricmp( trap_Cmd_Argv( 1 ), "health" ) ) { if( trap_Cmd_Argc() == 3 ) ent->health = atoi( trap_Cmd_Argv( 2 ) ); else ent->health = ent->max_health; if( !give_all ) return; } if( give_all || !Q_stricmp( name, "weapons" ) ) { for( i = 0; i < GS_MAX_ITEM_TAGS; i++ ) { it = GS_FindItemByTag( i ); if( !it ) continue; if( !( it->flags & ITFLAG_PICKABLE ) ) continue; if( !( it->type & IT_WEAPON ) ) continue; ent->r.client->ps.inventory[i] += 1; } if( !give_all ) return; } if( give_all || !Q_stricmp( name, "ammo" ) ) { for( i = 0; i < GS_MAX_ITEM_TAGS; i++ ) { it = GS_FindItemByTag( i ); if( !it ) continue; if( !( it->flags & ITFLAG_PICKABLE ) ) continue; if( !( it->type & IT_AMMO ) ) continue; Add_Ammo( ent->r.client, it, 1000, true ); } if( !give_all ) return; } if( give_all || !Q_stricmp( name, "armor" ) ) { ent->r.client->resp.armor = GS_Armor_MaxCountForTag( ARMOR_RA ); if( !give_all ) return; } if( give_all ) { for( i = 0; i < GS_MAX_ITEM_TAGS; i++ ) { it = GS_FindItemByTag( i ); if( !it ) continue; if( !( it->flags & ITFLAG_PICKABLE ) ) continue; if( it->type & ( IT_ARMOR|IT_WEAPON|IT_AMMO ) ) continue; ent->r.client->ps.inventory[i] = 1; } return; } it = GS_FindItemByName( name ); if( !it ) { name = trap_Cmd_Argv( 1 ); it = GS_FindItemByName( name ); if( !it ) { G_PrintMsg( ent, "unknown item\n" ); return; } } if( !( it->flags & ITFLAG_PICKABLE ) ) { G_PrintMsg( ent, "non-pickup (givable) item\n" ); return; } if( it->type & IT_AMMO ) { if( trap_Cmd_Argc() == 3 ) ent->r.client->ps.inventory[it->tag] = atoi( trap_Cmd_Argv( 2 ) ); else ent->r.client->ps.inventory[it->tag] += it->quantity; } else { if( it->tag && ( it->tag > 0 ) && ( it->tag < GS_MAX_ITEM_TAGS ) ) { if( GS_FindItemByTag( it->tag ) != NULL ) ent->r.client->ps.inventory[it->tag]++; } else G_PrintMsg( ent, "non-pickup (givable) item\n" ); } }
/* * GS_Cmd_UseItem */ gsitem_t *GS_Cmd_UseItem( player_state_t *playerState, const char *string, int typeMask ) { gsitem_t *item = NULL; assert( playerState ); if( playerState->pmove.pm_type >= PM_SPECTATOR ) return NULL; if( !string || !string[0] ) return NULL; if( Q_isdigit( string ) ) { int tag = atoi( string ); item = GS_FindItemByTag( tag ); } else item = GS_FindItemByName( string ); if( !item ) return NULL; if( typeMask && !( item->type & typeMask ) ) return NULL; // we don't have this item in the inventory if( !playerState->inventory[item->tag] ) { if( gs.module == GS_MODULE_CGAME && !( item->type & IT_WEAPON ) ) module_Printf( "Item %s is not in inventory\n", item->name ); return NULL; } // see if we can use it if( !(item->flags & ITFLAG_USABLE) ) return NULL; if( item->type & IT_WEAPON ) { if( !( playerState->pmove.stats[PM_STAT_FEATURES] & PMFEAT_WEAPONSWITCH ) ) return NULL; if( item->tag == playerState->stats[STAT_PENDING_WEAPON] ) // it's already being loaded return NULL; // check for need of any kind of ammo/fuel/whatever if( item->ammo_tag != AMMO_NONE && item->weakammo_tag != AMMO_NONE ) { gs_weapon_definition_t *weapondef = GS_GetWeaponDef( item->tag ); if( weapondef ) { // do we have any of these ammos ? if( playerState->inventory[item->weakammo_tag] >= weapondef->firedef_weak.usage_count ) return item; if( playerState->inventory[item->ammo_tag] >= weapondef->firedef.usage_count ) return item; } return NULL; } return item; // one of the weapon modes doesn't require ammo to be fired } if( item->type & IT_AMMO ) return item; if( item->type & IT_HEALTH ) return item; if( item->type & IT_POWERUP ) return item; return NULL; }