1 /**
2 * @file
3 * @brief Alien containment class
4 */
5
6 /*
7 Copyright (C) 2002-2013 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"
26 /** @todo cp_research.h would be enough but it has an unresolved depenency on cp_camapign.h */
27 #include "cp_campaign.h"
28 #include "cp_research.h"
29
30 #define BREATHINGAPPARATUS_TECH "rs_alien_breathing"
31
32 /**
33 * @brief Returns the number of capacity needed for an alien in the containment
34 * @param[in] teamDef Pointer to the alien Team Definition
35 * @param[in] isDead If the alien to calculate for is dead
36 */
getCapacityNeedForAlien(const teamDef_t * teamDef,const bool isDead) const37 int AlienContainment::getCapacityNeedForAlien(const teamDef_t* teamDef, const bool isDead) const
38 {
39 return 1;
40 }
41
42 /**
43 * @brief Private metod to reset current capacities
44 */
resetCurrentCapacities(void)45 void AlienContainment::resetCurrentCapacities(void)
46 {
47 if (this->aliveCapacity)
48 this->aliveCapacity->cur = 0;
49 if (this->deadCapacity)
50 this->deadCapacity->cur = 0;
51 }
52
53 /**
54 * @brief Returns if storing a specific life form is supported by the containment
55 * @param[in] team Pointer to the alien Team Definition
56 */
isLifeSupported(const teamDef_t * team)57 bool AlienContainment::isLifeSupported(const teamDef_t* team)
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 */
72 /** @todo find a way that doesn't need a tech ID hardcoded */
73 const technology_t* tech = RS_GetTechByID(BREATHINGAPPARATUS_TECH);
74 if (!tech)
75 return false;
76
77 return RS_IsResearched_ptr(tech);
78 }
79
80 /**
81 * @brief Add aliens to the containment by teamDef
82 * @param[in] team Pointer to the alien Team Definition
83 * @param[in] alive Number of alive aliens
84 * @param[in] dead Number of dead aliens
85 */
add(const teamDef_t * team,int alive,int dead)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
110 /**
111 * @brief Add aliens to the containment by scripted team ID
112 * @param[in] teamId Scripted team ID string
113 * @param[in] alive Number of alive aliens
114 * @param[in] dead Number of dead aliens
115 */
add(const char * teamId,int alive,int dead)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
126 /**
127 * @brief Creates and initializes AlienContainment object
128 */
AlienContainment(capacities_t * aliveCapacity,capacities_t * deadCapacity)129 AlienContainment::AlienContainment (capacities_t* aliveCapacity, capacities_t* deadCapacity) : aliveCapacity(aliveCapacity), deadCapacity(deadCapacity)
130 {
131 this->resetCurrentCapacities();
132 }
133
134 /**
135 * @brief Destroys AlienContainer with it's internal data
136 */
~AlienContainment(void)137 AlienContainment::~AlienContainment (void)
138 {
139 this->resetCurrentCapacities();
140 }
141