-
Notifications
You must be signed in to change notification settings - Fork 148
/
g_inventory.cpp
137 lines (119 loc) · 2.53 KB
/
g_inventory.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//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);
}
target->client->ps.inventory[INV_GOODIE_KEY]++;
return (qtrue);
}
qboolean INV_GoodieKeyTake( gentity_t *target )
{
if ( !target || !target->client )
{
return (qfalse);
}
if (target->client->ps.inventory[INV_GOODIE_KEY])
{
target->client->ps.inventory[INV_GOODIE_KEY]--;
return (qtrue);
}
//had no keys
return (qfalse);
}
int INV_GoodieKeyCheck( gentity_t *target )
{
if ( !target || !target->client )
{
return (qfalse);
}
if ( target->client->ps.inventory[INV_GOODIE_KEY] )
{//found a key
return (INV_GOODIE_KEY);
}
//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;
}
for ( int i = 0; i <= 4; i++ )
{
if ( target->client->ps.security_key_message[i][0] == NULL )
{//fill in the first empty slot we find with this key
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 );
return qtrue;
}
}
//couldn't find an empty slot
return qfalse;
}
void INV_SecurityKeyTake( gentity_t *target, char *keyname )
{
if ( !target || !keyname || !target->client )
{
return;
}
for ( int i = 0; i <= 4; i++ )
{
if ( target->client->ps.security_key_message[i] )
{
if ( !Q_stricmp( keyname, target->client->ps.security_key_message[i] ) )
{
target->client->ps.inventory[INV_SECURITY_KEY]--; // Take the key
target->client->ps.security_key_message[i][0] = NULL;
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);
}
for ( int i = 0; i <= 4; i++ )
{
if ( target->client->ps.inventory[INV_SECURITY_KEY] && target->client->ps.security_key_message[i] )
{
if ( !Q_stricmp( keyname, target->client->ps.security_key_message[i] ) )
{
return (qtrue);
}
}
/*
//don't do this because we could have removed one that's between 2 valid ones
else
{
break;
}
*/
}
return (qfalse);
}