UFO: Alien Invasion
Loading...
Searching...
No Matches
test_character.cpp
Go to the documentation of this file.
1
4
5/*
6Copyright (C) 2002-2025 UFO: Alien Invasion.
7
8This program is free software; you can redistribute it and/or
9modify it under the terms of the GNU General Public License
10as published by the Free Software Foundation; either version 2
11of the License, or (at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
17See the GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
21Foundation, 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
29class CharacterTest: public ::testing::Test {
30protected:
31 static void SetUpTestCase() {
32 TEST_Init();
33
34 Com_ParseScripts(true);
35 }
36
37 static void TearDownTestCase() {
39 }
40};
41
42static character_t* GetCharacter (const char* teamDefID = "phalanx")
43{
44 static character_t chr;
45 CL_GenerateCharacter(&chr, teamDefID);
46 return &chr;
47}
48
49static void RunStrengthenImplant (character_t& chr, const implant_t& implant, const objDef_t& od)
50{
51 Com_Printf("%s ", od.id);
53}
54
55static 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
61static void RunImplant (const implantDef_t& implantDef)
62{
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++) {
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
100TEST_F(CharacterTest, testImplants)
101{
102 Com_Printf("\n");
103 for (int i = 0; i < csi.numImplants; i++) {
104 RunImplant(csi.implants[i]);
105 }
106}
const implant_t * CHRSH_ApplyImplant(character_t &chr, const implantDef_t &def)
Add a new implant to a character.
void CHRSH_UpdateImplants(character_t &chr)
Updates the characters permanent implants. Called every day.
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
static void SetUpTestCase()
static void TearDownTestCase()
csi_t csi
Definition common.cpp:39
void Com_Printf(const char *const fmt,...)
Definition common.cpp:428
#define MAX_WEAPONS_PER_OBJDEF
Definition inv_shared.h:40
QGL_EXTERN GLfloat f
Definition r_gl.h:114
QGL_EXTERN GLint i
Definition r_gl.h:113
void Com_ParseScripts(bool onlyServer)
Definition scripts.cpp:3619
#define lengthof(x)
Definition shared.h:105
Describes a character with all its attributes.
Definition chr_shared.h:388
this is a fire definition for our weapons/ammo
Definition inv_shared.h:110
itemEffect_t * activeEffect
Definition inv_shared.h:131
itemEffect_t * deactiveEffect
Definition inv_shared.h:132
itemEffect_t * overdoseEffect
Definition inv_shared.h:133
int removedTime
Definition chr_shared.h:375
const implantDef_t * def
Definition chr_shared.h:373
int installedTime
Definition chr_shared.h:374
const struct objDef_s * item
Definition inv_shared.h:104
int installationTime
Definition inv_shared.h:105
const char * id
Definition inv_shared.h:102
Defines all attributes of objects used in the inventory.
Definition inv_shared.h:264
fireDef_t fd[MAX_WEAPONS_PER_OBJDEF][MAX_FIREDEFS_PER_WEAPON]
Definition inv_shared.h:314
fireDefIndex_t numFiredefs[MAX_WEAPONS_PER_OBJDEF]
Definition inv_shared.h:315
itemEffect_t * strengthenEffect
Definition inv_shared.h:283
const char * id
Definition inv_shared.h:268
static character_t * GetCharacter(const char *teamDefID="phalanx")
static void RunStrengthenImplant(character_t &chr, const implant_t &implant, const objDef_t &od)
TEST_F(CharacterTest, testImplants)
static void RunEffectForImplant(const fireDef_t &fd, character_t &chr, const implant_t &implant, const objDef_t &od, const itemEffect_t &effect)
static void RunImplant(const implantDef_t &implantDef)
void TEST_Shutdown(void)
void TEST_Init(void)