UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
test_character.cpp
Go to the documentation of this file.
1 
5 /*
6 Copyright (C) 2002-2020 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++) {
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++) {
105  }
106 }
static void RunStrengthenImplant(character_t &chr, const implant_t &implant, const objDef_t &od)
this is a fire definition for our weapons/ammo
Definition: inv_shared.h:110
int installedTime
Definition: chr_shared.h:363
csi_t csi
Definition: common.cpp:39
int removedTime
Definition: chr_shared.h:364
TEST_F(CharacterTest, testImplants)
const implant_t * CHRSH_ApplyImplant(character_t &chr, const implantDef_t &def)
Add a new implant to a character.
Definition: chr_shared.cpp:179
const implantDef_t * def
Definition: chr_shared.h:362
void Com_ParseScripts(bool onlyServer)
Definition: scripts.cpp:3641
fireDef_t fd[MAX_WEAPONS_PER_OBJDEF][MAX_FIREDEFS_PER_WEAPON]
Definition: inv_shared.h:314
void Com_Printf(const char *const fmt,...)
Definition: common.cpp:386
Defines all attributes of objects used in the inventory.
Definition: inv_shared.h:264
implantDef_t implants[MAX_IMPLANTS]
Definition: q_shared.h:520
int installationTime
Definition: inv_shared.h:105
void CHRSH_UpdateImplants(character_t &chr)
Updates the characters permanent implants. Called every day.
Definition: chr_shared.cpp:139
fireDefIndex_t numFiredefs[MAX_WEAPONS_PER_OBJDEF]
Definition: inv_shared.h:315
static void RunEffectForImplant(const fireDef_t &fd, character_t &chr, const implant_t &implant, const objDef_t &od, const itemEffect_t &effect)
void TEST_Shutdown(void)
Definition: test_shared.cpp:34
itemEffect_t * activeEffect
Definition: inv_shared.h:131
#define MAX_WEAPONS_PER_OBJDEF
Definition: inv_shared.h:40
itemEffect_t * overdoseEffect
Definition: inv_shared.h:133
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
int numImplants
Definition: q_shared.h:521
static void TearDownTestCase()
const char * id
Definition: inv_shared.h:102
QGL_EXTERN GLfloat f
Definition: r_gl.h:114
static void SetUpTestCase()
QGL_EXTERN GLint i
Definition: r_gl.h:113
itemEffect_t * strengthenEffect
Definition: inv_shared.h:283
void TEST_Init(void)
Definition: test_shared.cpp:72
static void RunImplant(const implantDef_t &implantDef)
static character_t * GetCharacter(const char *teamDefID="phalanx")
#define lengthof(x)
Definition: shared.h:105
itemEffect_t * deactiveEffect
Definition: inv_shared.h:132
const struct objDef_s * item
Definition: inv_shared.h:104
const char * id
Definition: inv_shared.h:268
Describes a character with all its attributes.
Definition: chr_shared.h:369