UFO: Alien Invasion
Loading...
Searching...
No Matches
aliencontainment.cpp
Go to the documentation of this file.
1
5
6/*
7Copyright (C) 2002-2025 UFO: Alien Invasion.
8
9This program is free software; you can redistribute it and/or
10modify it under the terms of the GNU General Public License
11as published by the Free Software Foundation; either version 2
12of the License, or (at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
18See the GNU General Public License for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, 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
37int 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
86bool 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
116bool 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
133
#define BREATHINGAPPARATUS_TECH
Alien containment class header.
bool CHRSH_IsTeamDefRobot(const teamDef_t *const td)
Check if a team definition is a robot.
bool CHRSH_IsTeamDefAlien(const teamDef_t *const td)
Check if a team definition is alien.
int getAlive(void) const
Return number of all alive aliens in the cargo.
virtual bool add(const teamDef_t *team, int alive, int dead)
Add aliens to the cargo by teamDef.
int getDead(void) const
Return number of all dead bodies in the cargo.
AlienContainment(capacities_t *aliveCapacity, capacities_t *deadCapacity)
Creates and initializes AlienContainment object.
capacities_t * deadCapacity
capacities_t * aliveCapacity
static bool isLifeSupported(const teamDef_t *team)
Returns if storing a specific life form is supported by the containment.
void resetCurrentCapacities(void)
Private metod to reset current capacities.
virtual bool add(const teamDef_t *team, int alive, int dead)
Add aliens to the containment by teamDef.
virtual ~AlienContainment(void)
Destroys AlienContainer with it's internal data.
static int getCapacityNeedForAlien(const teamDef_t *teamDef, const bool isDead)
Returns the number of capacity needed for an alien in the containment.
Header file for single player campaign control.
const cgame_import_t * cgi
void RS_MarkCollected(technology_t *tech)
Marks a give technology as collected.
technology_t * RS_GetTechForTeam(const teamDef_t *team)
Returns technology entry for a team.
bool RS_IsResearched_ptr(const technology_t *tech)
Checks whether an item is already researched.
technology_t * RS_GetTechByID(const char *id)
return a pointer to the technology identified by given id string
Header for research related stuff.
Store capacities in base.
Definition cp_capacity.h:41
This is the technology parsed from research.ufo.