jedioutcast/code/game/g_inventory.cpp

138 lines
2.7 KiB
C++
Raw Normal View History

2013-04-04 14:52:42 +00:00
//g_inventory.cpp
// leave this line at the top for all g_xxxx.cpp files...
#include "g_headers.h"
#include "g_local.h"
/*
================
Goodie Keys
================
*/
qboolean INV_GoodieKeyGive( gentity_t *target )
{
if ( !target || !target->client )
{
return (qfalse);
}
2013-04-04 18:24:26 +00:00
target->client->ps.inventory[INV_GOODIE_KEY]++;
return (qtrue);
2013-04-04 14:52:42 +00:00
}
qboolean INV_GoodieKeyTake( gentity_t *target )
{
if ( !target || !target->client )
{
return (qfalse);
}
2013-04-04 18:24:26 +00:00
if (target->client->ps.inventory[INV_GOODIE_KEY])
2013-04-04 14:52:42 +00:00
{
2013-04-04 18:24:26 +00:00
target->client->ps.inventory[INV_GOODIE_KEY]--;
return (qtrue);
2013-04-04 14:52:42 +00:00
}
2013-04-04 18:24:26 +00:00
2013-04-04 14:52:42 +00:00
//had no keys
return (qfalse);
}
int INV_GoodieKeyCheck( gentity_t *target )
{
if ( !target || !target->client )
{
return (qfalse);
}
2013-04-04 18:24:26 +00:00
if ( target->client->ps.inventory[INV_GOODIE_KEY] )
{//found a key
return (INV_GOODIE_KEY);
2013-04-04 14:52:42 +00:00
}
2013-04-04 18:24:26 +00:00
2013-04-04 14:52:42 +00:00
//no keys
return (qfalse);
}
/*
================
Security Keys
================
*/
qboolean INV_SecurityKeyGive( gentity_t *target, const char *keyname )
{
if ( target == NULL || keyname == NULL || target->client == NULL )
{
return qfalse;
}
2013-04-04 18:24:26 +00:00
for ( int i = 0; i <= 4; i++ )
2013-04-04 14:52:42 +00:00
{
2013-04-04 18:24:26 +00:00
if ( target->client->ps.security_key_message[i][0] == NULL )
2013-04-04 14:52:42 +00:00
{//fill in the first empty slot we find with this key
2013-04-04 18:24:26 +00:00
target->client->ps.inventory[INV_SECURITY_KEY]++; // He got the key
Q_strncpyz( target->client->ps.security_key_message[i], keyname, MAX_SECURITY_KEY_MESSSAGE, qtrue );
2013-04-04 14:52:42 +00:00
return qtrue;
}
}
//couldn't find an empty slot
return qfalse;
}
void INV_SecurityKeyTake( gentity_t *target, char *keyname )
{
if ( !target || !keyname || !target->client )
{
return;
}
2013-04-04 18:24:26 +00:00
for ( int i = 0; i <= 4; i++ )
2013-04-04 14:52:42 +00:00
{
2013-04-04 18:24:26 +00:00
if ( target->client->ps.security_key_message[i] )
2013-04-04 14:52:42 +00:00
{
2013-04-04 18:24:26 +00:00
if ( !Q_stricmp( keyname, target->client->ps.security_key_message[i] ) )
2013-04-04 14:52:42 +00:00
{
2013-04-04 18:24:26 +00:00
target->client->ps.inventory[INV_SECURITY_KEY]--; // Take the key
target->client->ps.security_key_message[i][0] = NULL;
2013-04-04 14:52:42 +00:00
return;
}
}
/*
//don't do this because we could have removed one that's between 2 valid ones
else
{
break;
}
*/
}
}
qboolean INV_SecurityKeyCheck( gentity_t *target, char *keyname )
{
if ( !target || !keyname || !target->client )
{
return (qfalse);
}
2013-04-04 18:24:26 +00:00
for ( int i = 0; i <= 4; i++ )
2013-04-04 14:52:42 +00:00
{
2013-04-04 18:24:26 +00:00
if ( target->client->ps.inventory[INV_SECURITY_KEY] && target->client->ps.security_key_message[i] )
2013-04-04 14:52:42 +00:00
{
2013-04-04 18:24:26 +00:00
if ( !Q_stricmp( keyname, target->client->ps.security_key_message[i] ) )
2013-04-04 14:52:42 +00:00
{
return (qtrue);
}
}
/*
//don't do this because we could have removed one that's between 2 valid ones
else
{
break;
}
*/
}
return (qfalse);
}