UFO: Alien Invasion
Toggle main menu visibility
Loading...
Searching...
No Matches
cp_rank.cpp
Go to the documentation of this file.
1
4
5
/*
6
Copyright (C) 2002-2025 UFO: Alien Invasion.
7
8
This program is free software; you can redistribute it and/or
9
modify it under the terms of the GNU General Public License
10
as published by the Free Software Foundation; either version 2
11
of the License, or (at your option) any later version.
12
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
17
See the GNU General Public License for more details.
18
19
You should have received a copy of the GNU General Public License
20
along with this program; if not, write to the Free Software
21
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
*/
23
24
#include "
../../cl_shared.h
"
25
#include "
../../../shared/parse.h
"
26
#include "
cp_rank.h
"
27
#include "
cp_campaign.h
"
28
34
int
CL_GetRankIdx
(
const
char
* rankID)
35
{
36
for
(
int
i
= 0;
i
<
ccs
.numRanks;
i
++) {
37
if
(
Q_streq
(
ccs
.ranks[
i
].id, rankID))
38
return
i
;
39
}
40
41
return
-1;
42
}
43
50
rank_t
*
CL_GetRankByIdx
(
const
int
index
)
51
{
52
if
(
index < 0 || index >
=
ccs
.numRanks)
53
return
nullptr
;
54
55
return
&
ccs
.ranks[
index
];
56
}
57
58
static
const
value_t
rankValues
[] = {
59
{
"name"
,
V_TRANSLATION_STRING
, offsetof(
rank_t
,
name
), 0},
60
{
"shortname"
,
V_TRANSLATION_STRING
, offsetof(
rank_t
, shortname), 0},
61
{
"image"
,
V_HUNK_STRING
, offsetof(
rank_t
, image), 0},
62
{
"mind"
,
V_INT
, offsetof(
rank_t
, mind),
MEMBER_SIZEOF
(
rank_t
, mind)},
63
{
"killed_enemies"
,
V_INT
, offsetof(
rank_t
, killedEnemies),
MEMBER_SIZEOF
(
rank_t
, killedEnemies)},
64
{
"killed_others"
,
V_INT
, offsetof(
rank_t
, killedOthers),
MEMBER_SIZEOF
(
rank_t
, killedOthers)},
65
{
"factor"
,
V_FLOAT
, offsetof(
rank_t
, factor),
MEMBER_SIZEOF
(
rank_t
, factor)},
66
{
"level"
,
V_INT
, offsetof(
rank_t
,
level
),
MEMBER_SIZEOF
(
rank_t
,
level
)},
67
{
nullptr
,
V_NULL
, 0, 0}
68
};
69
74
void
CL_ParseRanks
(
const
char
*
name
,
const
char
** text)
75
{
76
rank_t
* rank;
77
const
char
* errhead =
"CL_ParseRanks: unexpected end of file (medal/rank "
;
78
const
char
* token;
79
80
/* get name list body body */
81
token =
Com_Parse
(text);
82
83
if
(!*text || *token !=
'{'
) {
84
cgi
->Com_Printf(
"CL_ParseRanks: rank/medal \"%s\" without body ignored\n"
,
name
);
85
return
;
86
}
87
88
for
(
int
i
= 0;
i
<
ccs
.numRanks;
i
++) {
89
if
(
Q_streq
(
name
,
ccs
.ranks[
i
].name)) {
90
cgi
->Com_Printf(
"CL_ParseRanks: Rank with same name '%s' already loaded.\n"
,
name
);
91
return
;
92
}
93
}
94
/* parse ranks */
95
if
(
ccs
.numRanks >=
MAX_RANKS
) {
96
cgi
->Com_Printf(
"CL_ParseRanks: Too many rank descriptions, '%s' ignored.\n"
,
name
);
97
ccs
.numRanks =
MAX_RANKS
;
98
return
;
99
}
100
101
rank = &
ccs
.ranks[
ccs
.numRanks++];
102
OBJZERO
(*rank);
103
rank->
id
=
cgi
->PoolStrDup(
name
,
cp_campaignPool
, 0);
104
rank->
level
= -1;
105
106
do
{
107
/* get the name type */
108
token =
cgi
->Com_EParse(text, errhead,
name
);
109
if
(!*text)
110
break
;
111
if
(*token ==
'}'
)
112
break
;
113
114
if
(
cgi
->Com_ParseBlockToken(
name
, text, rank,
rankValues
,
cp_campaignPool
, token)) {
115
continue
;
116
}
else
if
(
Q_streq
(token,
"type"
)) {
117
/* employeeType_t */
118
token =
cgi
->Com_EParse(text, errhead,
name
);
119
if
(!*text)
120
return
;
121
/* error check is performed in E_GetEmployeeType function */
122
rank->
type
=
E_GetEmployeeType
(token);
123
}
else
124
cgi
->Com_Printf(
"CL_ParseRanks: unknown token \"%s\" ignored (medal/rank %s)\n"
, token,
name
);
125
}
while
(*text);
126
127
if
(rank->
image
==
nullptr
|| !strlen(rank->
image
))
128
cgi
->Com_Error(
ERR_DROP
,
"CL_ParseRanks: image is missing for rank %s"
, rank->
id
);
129
130
if
(rank->
name
==
nullptr
|| !strlen(rank->
name
))
131
cgi
->Com_Error(
ERR_DROP
,
"CL_ParseRanks: name is missing for rank %s"
, rank->
id
);
132
133
if
(rank->
shortname
==
nullptr
|| !strlen(rank->
shortname
))
134
rank->
shortname
= rank->
name
;
135
136
if
(rank->
level
== -1)
137
cgi
->Com_Error(
ERR_DROP
,
"CL_ParseRanks: level is missing for rank %s"
, rank->
id
);
138
}
cl_shared.h
Share stuff between the different cgame implementations.
ERR_DROP
#define ERR_DROP
Definition
common.h:211
cp_campaignPool
memPool_t * cp_campaignPool
Definition
cp_campaign.cpp:62
ccs
ccs_t ccs
Definition
cp_campaign.cpp:63
cp_campaign.h
Header file for single player campaign control.
cgi
const cgame_import_t * cgi
Definition
cp_cgame_callbacks.cpp:39
E_GetEmployeeType
employeeType_t E_GetEmployeeType(const char *type)
Convert string to employeeType_t.
Definition
cp_employee.cpp:213
CL_GetRankByIdx
rank_t * CL_GetRankByIdx(const int index)
Returns a rank at an index.
Definition
cp_rank.cpp:50
CL_GetRankIdx
int CL_GetRankIdx(const char *rankID)
Get the index of the given rankID in ccs.ranks array.
Definition
cp_rank.cpp:34
CL_ParseRanks
void CL_ParseRanks(const char *name, const char **text)
Parse medals and ranks defined in the medals.ufo file.
Definition
cp_rank.cpp:74
rankValues
static const value_t rankValues[]
Definition
cp_rank.cpp:58
cp_rank.h
MAX_RANKS
#define MAX_RANKS
Definition
cp_rank.h:26
level
level_locals_t level
Definition
g_main.cpp:38
Com_Parse
const char * Com_Parse(const char *data_p[], char *target, size_t size, bool replaceWhitespaces)
Parse a token out of a string.
Definition
parse.cpp:107
parse.h
Shared parsing functions.
index
QGL_EXTERN GLuint index
Definition
r_gl.h:110
i
QGL_EXTERN GLint i
Definition
r_gl.h:113
name
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
Definition
r_gl.h:110
V_FLOAT
@ V_FLOAT
Definition
scripts.h:54
V_TRANSLATION_STRING
@ V_TRANSLATION_STRING
Definition
scripts.h:59
V_HUNK_STRING
@ V_HUNK_STRING
Definition
scripts.h:69
V_NULL
@ V_NULL
Definition
scripts.h:49
V_INT
@ V_INT
Definition
scripts.h:52
MEMBER_SIZEOF
#define MEMBER_SIZEOF(TYPE, MEMBER)
Definition
scripts.h:34
Q_streq
#define Q_streq(a, b)
Definition
shared.h:136
OBJZERO
#define OBJZERO(obj)
Definition
shared.h:178
rank_t
Describes a rank that a recruit can gain.
Definition
cp_rank.h:29
rank_t::level
int level
Definition
cp_rank.h:40
rank_t::name
const char * name
Definition
cp_rank.h:31
rank_t::type
int type
Definition
cp_rank.h:34
rank_t::id
const char * id
Definition
cp_rank.h:30
rank_t::image
const char * image
Definition
cp_rank.h:33
rank_t::shortname
const char * shortname
Definition
cp_rank.h:32
value_t
Definition
scripts.h:167
src
client
cgame
campaign
cp_rank.cpp
Generated on __DATE__ __TIME__ for UFO: Alien Invasion by
1.17.0