MateriaSource.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* ************************************************************************** */
  2. /* */
  3. /* ::: :::::::: */
  4. /* MateriaSource.cpp :+: :+: :+: */
  5. /* +:+ +:+ +:+ */
  6. /* By: bchanot <bchanot@42.fr> +#+ +:+ +#+ */
  7. /* +#+#+#+#+#+ +#+ */
  8. /* Created: 2025/12/24 15:47:01 by bchanot #+# #+# */
  9. /* Updated: 2025/12/24 15:49:20 by bchanot ### ########.fr */
  10. /* */
  11. /* ************************************************************************** */
  12. #include "MateriaSource.hpp"
  13. #include <string.h>
  14. /*
  15. ** ------------------------------- CONSTRUCTOR --------------------------------
  16. */
  17. MateriaSource::MateriaSource()
  18. {
  19. for (int i = 0; i < 4; i++)
  20. this->_items[i] = NULL;
  21. }
  22. MateriaSource::MateriaSource( const MateriaSource & src )
  23. {
  24. for (int i = 0; i < 4; i++)
  25. this->_items[i] = src._items[i]->clone();
  26. }
  27. /*
  28. ** -------------------------------- DESTRUCTOR --------------------------------
  29. */
  30. MateriaSource::~MateriaSource()
  31. {
  32. }
  33. /*
  34. ** --------------------------------- OVERLOAD ---------------------------------
  35. */
  36. MateriaSource & MateriaSource::operator=( MateriaSource const & rhs )
  37. {
  38. if ( this != &rhs )
  39. {
  40. for (int i = 0; i < 4; i++) {
  41. this->_items[i] = rhs._items[i]->clone();
  42. }
  43. }
  44. return *this;
  45. }
  46. std::ostream & operator<<( std::ostream & o, MateriaSource const & i )
  47. {
  48. (void)i;
  49. //o << "Value = " << i.getValue();
  50. return o;
  51. }
  52. /*
  53. ** --------------------------------- METHODS ----------------------------------
  54. */
  55. void MateriaSource::learnMateria(AMateria* source) {
  56. if (source) {
  57. for (int i = 0; i < 4; i++) {
  58. if (!this->_items[i]) {
  59. this->_items[i] = source->clone();
  60. return ;
  61. }
  62. }
  63. }
  64. }
  65. AMateria* MateriaSource::createMateria(std::string const & type){
  66. for (int i = 0; i < 4; i++) {
  67. if (this->_items[i] && !type.compare(this->_items[i]->getType())) {
  68. return this->_items[i]->clone();
  69. }
  70. }
  71. return NULL;
  72. }
  73. /*
  74. ** --------------------------------- ACCESSOR ---------------------------------
  75. */
  76. /* ************************************************************************** */