UFO: Alien Invasion
Toggle main menu visibility
Loading...
Searching...
No Matches
test_character.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
25
26
#include "
test_shared.h
"
27
#include "
../client/cl_team.h
"
28
29
class
CharacterTest
:
public
::testing::Test {
30
protected
:
31
static
void
SetUpTestCase
() {
32
TEST_Init
();
33
34
Com_ParseScripts
(
true
);
35
}
36
37
static
void
TearDownTestCase
() {
38
TEST_Shutdown
();
39
}
40
};
41
42
static
character_t
*
GetCharacter
(
const
char
* teamDefID =
"phalanx"
)
43
{
44
static
character_t
chr;
45
CL_GenerateCharacter
(&chr, teamDefID);
46
return
&chr;
47
}
48
49
static
void
RunStrengthenImplant
(
character_t
& chr,
const
implant_t
& implant,
const
objDef_t
& od)
50
{
51
Com_Printf
(
"%s "
, od.
id
);
53
}
54
55
static
void
RunEffectForImplant
(
const
fireDef_t
& fd,
character_t
& chr,
const
implant_t
& implant,
const
objDef_t
& od,
const
itemEffect_t
& effect)
56
{
57
Com_Printf
(
"%s "
, implant.
def
->
id
);
59
}
60
61
static
void
RunImplant
(
const
implantDef_t
& implantDef)
62
{
63
character_t
* chr =
GetCharacter
();
64
const
objDef_t
* od = implantDef.
item
;
65
ASSERT_TRUE(
nullptr
!= od);
66
const
implant_t
* implant =
CHRSH_ApplyImplant
(*chr, implantDef);
67
ASSERT_TRUE(
nullptr
!= implant);
68
ASSERT_TRUE(
nullptr
!= implant->
def
);
69
Com_Printf
(
"implant: '%s': "
, implant->
def
->
id
);
70
ASSERT_EQ(implant->
removedTime
, 0);
71
ASSERT_NE(implant->
installedTime
, 0);
72
ASSERT_TRUE(
nullptr
!= implant->
def
);
73
ASSERT_EQ(implant->
installedTime
, implantDef.
installationTime
);
74
for
(
int
i
= 0;
i
< implantDef.
installationTime
;
i
++) {
75
CHRSH_UpdateImplants
(*chr);
76
}
77
ASSERT_EQ(implant->
installedTime
, 0);
78
79
int
effects = 0;
80
if
(od->
strengthenEffect
!=
nullptr
) {
81
RunStrengthenImplant
(*chr, *implant, *od);
82
effects++;
83
}
84
for
(
int
w = 0; w <
MAX_WEAPONS_PER_OBJDEF
; w++) {
85
for
(
int
f
= 0;
f
< od->
numFiredefs
[w];
f
++) {
86
const
fireDef_t
& fd = od->
fd
[w][
f
];
87
const
itemEffect_t
* effect[] = { fd.
activeEffect
, fd.
deactiveEffect
, fd.
overdoseEffect
};
88
for
(
int
e = 0; e <
lengthof
(effect); e++) {
89
if
(effect[e] ==
nullptr
)
90
continue
;
91
RunEffectForImplant
(fd, *chr, *implant, *od, *effect[e]);
92
effects++;
93
}
94
}
95
}
96
ASSERT_TRUE(effects >= 1);
97
Com_Printf
(
"passed %i effects\n"
, effects);
98
}
99
100
TEST_F
(
CharacterTest
, testImplants)
101
{
102
Com_Printf
(
"\n"
);
103
for
(
int
i
= 0;
i
<
csi
.numImplants;
i
++) {
104
RunImplant
(
csi
.implants[
i
]);
105
}
106
}
CHRSH_ApplyImplant
const implant_t * CHRSH_ApplyImplant(character_t &chr, const implantDef_t &def)
Add a new implant to a character.
Definition
chr_shared.cpp:180
CHRSH_UpdateImplants
void CHRSH_UpdateImplants(character_t &chr)
Updates the characters permanent implants. Called every day.
Definition
chr_shared.cpp:140
CL_GenerateCharacter
void CL_GenerateCharacter(character_t *chr, const char *teamDefName)
Generates the skills and inventory for a character and for a 2x2 unit.
Definition
cl_team.cpp:235
cl_team.h
CharacterTest
Definition
test_character.cpp:29
CharacterTest::SetUpTestCase
static void SetUpTestCase()
Definition
test_character.cpp:31
CharacterTest::TearDownTestCase
static void TearDownTestCase()
Definition
test_character.cpp:37
csi
csi_t csi
Definition
common.cpp:39
Com_Printf
void Com_Printf(const char *const fmt,...)
Definition
common.cpp:428
MAX_WEAPONS_PER_OBJDEF
#define MAX_WEAPONS_PER_OBJDEF
Definition
inv_shared.h:40
f
QGL_EXTERN GLfloat f
Definition
r_gl.h:114
i
QGL_EXTERN GLint i
Definition
r_gl.h:113
Com_ParseScripts
void Com_ParseScripts(bool onlyServer)
Definition
scripts.cpp:3619
lengthof
#define lengthof(x)
Definition
shared.h:105
character_t
Describes a character with all its attributes.
Definition
chr_shared.h:388
fireDef_t
this is a fire definition for our weapons/ammo
Definition
inv_shared.h:110
fireDef_t::activeEffect
itemEffect_t * activeEffect
Definition
inv_shared.h:131
fireDef_t::deactiveEffect
itemEffect_t * deactiveEffect
Definition
inv_shared.h:132
fireDef_t::overdoseEffect
itemEffect_t * overdoseEffect
Definition
inv_shared.h:133
implant_t
Definition
chr_shared.h:372
implant_t::removedTime
int removedTime
Definition
chr_shared.h:375
implant_t::def
const implantDef_t * def
Definition
chr_shared.h:373
implant_t::installedTime
int installedTime
Definition
chr_shared.h:374
implantDef_t
Definition
inv_shared.h:101
implantDef_t::item
const struct objDef_s * item
Definition
inv_shared.h:104
implantDef_t::installationTime
int installationTime
Definition
inv_shared.h:105
implantDef_t::id
const char * id
Definition
inv_shared.h:102
itemEffect_t
Definition
inv_shared.h:88
objDef_t
Defines all attributes of objects used in the inventory.
Definition
inv_shared.h:264
objDef_t::fd
fireDef_t fd[MAX_WEAPONS_PER_OBJDEF][MAX_FIREDEFS_PER_WEAPON]
Definition
inv_shared.h:314
objDef_t::numFiredefs
fireDefIndex_t numFiredefs[MAX_WEAPONS_PER_OBJDEF]
Definition
inv_shared.h:315
objDef_t::strengthenEffect
itemEffect_t * strengthenEffect
Definition
inv_shared.h:283
objDef_t::id
const char * id
Definition
inv_shared.h:268
GetCharacter
static character_t * GetCharacter(const char *teamDefID="phalanx")
Definition
test_character.cpp:42
RunStrengthenImplant
static void RunStrengthenImplant(character_t &chr, const implant_t &implant, const objDef_t &od)
Definition
test_character.cpp:49
TEST_F
TEST_F(CharacterTest, testImplants)
Definition
test_character.cpp:100
RunEffectForImplant
static void RunEffectForImplant(const fireDef_t &fd, character_t &chr, const implant_t &implant, const objDef_t &od, const itemEffect_t &effect)
Definition
test_character.cpp:55
RunImplant
static void RunImplant(const implantDef_t &implantDef)
Definition
test_character.cpp:61
TEST_Shutdown
void TEST_Shutdown(void)
Definition
test_shared.cpp:34
TEST_Init
void TEST_Init(void)
Definition
test_shared.cpp:72
test_shared.h
src
tests
test_character.cpp
Generated on __DATE__ __TIME__ for UFO: Alien Invasion by
1.17.0