blob: 774506b203dc032ac5bf7ee1480aa9e2b8579a5b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* MateriaSource.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/14 17:19:10 by charles #+# #+# */
/* Updated: 2020/11/13 14:40:54 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include "MateriaSource.hpp"
MateriaSource::MateriaSource() : m_learned_size(0) {}
MateriaSource::MateriaSource(MateriaSource const& other)
: m_learned_size(0) { *this = other; }
MateriaSource& MateriaSource::operator=(MateriaSource const& other)
{
destroyLearned();
m_learned_size = other.m_learned_size;
for (int i = 0; i < m_learned_size; i++)
m_learned[i] = other.m_learned[i]->clone();
return *this;
}
MateriaSource::~MateriaSource() { destroyLearned(); }
void MateriaSource::learnMateria(AMateria* materia)
{
if (m_learned_size >= 4)
return;
m_learned[m_learned_size] = materia->clone();
m_learned_size++;
}
AMateria* MateriaSource::createMateria(std::string const& type)
{
for (int i = 0; i < m_learned_size; i++)
if (m_learned[i]->getType() == type)
return m_learned[i]->clone();
return NULL;
}
void MateriaSource::destroyLearned()
{
for (int i = 0; i < m_learned_size; i++)
delete m_learned[i];
}
|