UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
aliencontainment.cpp
Go to the documentation of this file.
1 
6 /*
7 Copyright (C) 2002-2020 UFO: Alien Invasion.
8 
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
13 
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 
18 See the GNU General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 */
24 
25 #include "aliencontainment.h"
27 #include "cp_campaign.h"
28 #include "cp_research.h"
29 
30 #define BREATHINGAPPARATUS_TECH "rs_alien_breathing"
31 
37 int AlienContainment::getCapacityNeedForAlien(const teamDef_t* teamDef, const bool isDead)
38 {
39  return 1;
40 }
41 
46 {
47  if (this->aliveCapacity)
48  this->aliveCapacity->cur = 0;
49  if (this->deadCapacity)
50  this->deadCapacity->cur = 0;
51 }
52 
58 {
59  /* No team - not supported */
60  if (!team)
61  return false;
62 
63  /* humans supported */
64  if (!CHRSH_IsTeamDefAlien(team))
65  return true;
66 
67  /* Robots are supported */
68  if (CHRSH_IsTeamDefRobot(team))
69  return true;
70 
71  /* Organic aliens need breathing apparatus known */
74  if (!tech)
75  return false;
76 
77  return RS_IsResearched_ptr(tech);
78 }
79 
86 bool AlienContainment::add(const teamDef_t* team, int alive, int dead)
87 {
88  if (!team)
89  return false;
90 
91  if (!isLifeSupported(team)) {
92  dead += alive;
93  alive = 0;
94  }
95 
96  if (AlienCargo::add(team, alive, dead)) {
97  if (this->aliveCapacity)
98  this->aliveCapacity->cur += alive * getCapacityNeedForAlien(team, false);
99  if (this->deadCapacity)
100  this->deadCapacity->cur += dead * getCapacityNeedForAlien(team, true);
101  if (this->getAlive(team) > 0 || this->getDead(team) > 0) {
102  technology_t* tech = RS_GetTechForTeam(team);
103  RS_MarkCollected(tech);
104  }
105  return true;
106  }
107  return false;
108 }
109 
116 bool AlienContainment::add(const char* teamId, int alive, int dead)
117 {
118  if (!teamId)
119  return false;
120  const teamDef_t* team = cgi->Com_GetTeamDefinitionByID(teamId);
121  if (!team)
122  return false;
123  return this->add(team, alive, dead);
124 }
125 
129 AlienContainment::AlienContainment (capacities_t* aliveCapacity, capacities_t* deadCapacity) : aliveCapacity(aliveCapacity), deadCapacity(deadCapacity)
130 {
131  this->resetCurrentCapacities();
132 }
133 
138 {
139  this->resetCurrentCapacities();
140 }
static bool isLifeSupported(const teamDef_t *team)
Returns if storing a specific life form is supported by the containment.
virtual bool add(const teamDef_t *team, int alive, int dead)
Add aliens to the cargo by teamDef.
Definition: aliencargo.cpp:38
bool RS_IsResearched_ptr(const technology_t *tech)
Checks whether an item is already researched.
int getDead(void) const
Return number of all dead bodies in the cargo.
Definition: aliencargo.cpp:141
void resetCurrentCapacities(void)
Private metod to reset current capacities.
#define BREATHINGAPPARATUS_TECH
bool CHRSH_IsTeamDefAlien(const teamDef_t *const td)
Check if a team definition is alien.
Definition: chr_shared.cpp:82
Header for research related stuff.
virtual ~AlienContainment(void)
Destroys AlienContainer with it's internal data.
technology_t * RS_GetTechForTeam(const teamDef_t *team)
Returns technology entry for a team.
static int getCapacityNeedForAlien(const teamDef_t *teamDef, const bool isDead)
Returns the number of capacity needed for an alien in the containment.
capacities_t * aliveCapacity
capacities_t * deadCapacity
void RS_MarkCollected(technology_t *tech)
Marks a give technology as collected.
const cgame_import_t * cgi
This is the technology parsed from research.ufo.
Definition: cp_research.h:137
bool CHRSH_IsTeamDefRobot(const teamDef_t *const td)
Check if a team definition is a robot.
Definition: chr_shared.cpp:102
technology_t * RS_GetTechByID(const char *id)
return a pointer to the technology identified by given id string
Alien containment class header.
int getAlive(void) const
Return number of all alive aliens in the cargo.
Definition: aliencargo.cpp:133
AlienContainment(capacities_t *aliveCapacity, capacities_t *deadCapacity)
Creates and initializes AlienContainment object.
virtual bool add(const teamDef_t *team, int alive, int dead)
Add aliens to the containment by teamDef.
Header file for single player campaign control.
const teamDef_t *IMPORT * Com_GetTeamDefinitionByID(const char *team)
Store capacities in base.
Definition: cp_capacity.h:41