33 LOG_INFO(
"MateriaSource constructor called");
34 for (
int i = 0; i < 4; ++i)
35 this->learnedMateria[i] = NULL;
45 LOG_INFO(
"MateriaSource copy constructor called");
46 for (
int i = 0; i < 4; ++i) {
47 if (other.learnedMateria[i])
48 this->learnedMateria[i] = other.learnedMateria[i]->
clone();
50 this->learnedMateria[i] = NULL;
63 LOG_INFO(
"MateriaSource copy assignment operator called");
65 this->learnCount = other.learnCount;
66 for (
int i = 0; i < 4; ++i) {
67 if (this->learnedMateria[i])
68 delete this->learnedMateria[i];
69 if (other.learnedMateria[i])
70 this->learnedMateria[i] = other.learnedMateria[i]->
clone();
72 this->learnedMateria[i] = NULL;
84 LOG_INFO(
"MateriaSource destructor called");
85 for (
int i = 0; i < 4; ++i) {
86 if (this->learnedMateria[i])
87 delete this->learnedMateria[i];
99 if (this->learnCount < 4 && materia) {
100 this->learnedMateria[this->learnCount++] = materia->
clone();
101 oss <<
"MateriaSource learned " << materia->
getType();
104 }
else if (materia) {
105 oss <<
"MateriaSource cannot learn more materia.";
120 for (
int i = 0; i < this->learnCount; ++i) {
121 if (this->learnedMateria[i] && this->learnedMateria[i]->getType() == type) {
122 oss <<
"MateriaSource creates " << type <<
std::endl;
124 return this->learnedMateria[i]->
clone();
127 oss <<
"MateriaSource does not know materia type " << type;
Defines the Logger class for console-based logging.
#define LOG_INFO(msg)
Macro for logging informational messages.
Declares the MateriaSource class.
Represents an abstract base class for all magical materias.
virtual AMateria * clone() const =0
std::string const & getType() const
Gets the type of the materia.
Represents a source for learning and creating Materias.
MateriaSource()
Default constructor for MateriaSource. Initializes the learning count to zero and sets all learned Ma...
virtual ~MateriaSource()
Destroys the MateriaSource object. Deallocates all dynamically allocated AMateria objects that were l...
MateriaSource & operator=(const MateriaSource &other)
Copy assignment operator for MateriaSource. Assigns values from another MateriaSource object,...
virtual void learnMateria(AMateria *materia)
Learns a Materia template for later creation. The MateriaSource makes a deep copy of the passed Mater...
virtual AMateria * createMateria(std::string const &type) const
Creates a new Materia based on a learned type. Returns a new instance (a clone) of a previously learn...