<commit_before>//
// Created by vincent on 13/06/17.
//

#include "Game.hpp"
#include "Bomb.hpp"

unsigned int			is::Bomb::ID = 0;


is::Bomb::Bomb(is::map &map, irr::video::ITexture *texture, irr::scene::IAnimatedMesh *bombMesh, const irr::core::vector3df &posMap, int power,
	       irr::video::IVideoDriver &videoDriver, irr::scene::ISceneManager &sceneManager) :
	_id(ID++),
	_posMap(posMap),
	_posSpace(posMap.Y * SCALE - SCALE / 2, 0.55 * SCALE, posMap.X * SCALE + SCALE / 2),
	_power(power),
	_map(map),
	_videoDriver(videoDriver),
	_sceneManager(sceneManager),
	_alreadyBlowUp(false),
	_start_clock(std::clock()),
	_state(BOMB_PLANTED),
	_fires()
{
  if (!(this->_node = this->_sceneManager.addAnimatedMeshSceneNode(bombMesh)))
    throw is::IndieStudioException("Error on loading bomb.");
  this->_node->setPosition(this->_posSpace);
  this->_node->setScale({0.5f * SCALE, 0.5f * SCALE, 0.5f * SCALE});
  this->_map.addObject(Type::BOMB, {(int)posMap.X, (int)posMap.Y, (int)posMap.Z});
  std::cerr << "Bomb() id = " << this->_id << std::endl;
  std::cout << "Bomb pos.x = " << posMap.X << " pos.y = " << posMap.Y << " pos.Z = " << posMap.Z << std::endl;
}

is::Bomb::~Bomb()
{
  this->_map.delObject({(int)this->_posMap.X, (int)this->_posMap.Y, (int)this->_posMap.Z});
  std::cerr << "~Bomb() id = " << this->_id << std::endl;
}


void is::Bomb::draw()
{
  this->_node->render();
}

void is::Bomb::remove()
{
  this->_node->remove();
}

bool is::Bomb::blowUp(std::list<std::shared_ptr<is::Bomb>> bombs)
{
  std::clock_t 		end_clock = std::clock();
  int 			duration = static_cast<int>((std::clock() - _start_clock) / CLOCKS_PER_SEC);

  if (this->_state == BOMB_PLANTED && duration == ((_id == 0) ? (2) : (5)))
    {
      this->_explosion(bombs);
    }
  else if (this->_state == FIRE && duration == 2)
      {
	this->_stopFires();
	return (true);
      }
  return (false);
}

int 			is::Bomb::_reducePower(std::list<std::shared_ptr<is::Bomb>> bombs,
						  irr::core::vector3df pos,
						  int power,
						  const std::function<void(irr::core::vector3df &)> &callback)
{
  int			ret = 0;
  const 		Block *b;

  //std::cerr << "_reducPower" << std::endl;
  callback(pos);
  //std::cout << "pos.x = " << pos.X << " pos.y = " << pos.Y << " pos.z = " << pos.Z<< std::endl;
  while (this->_map.canIMoove(is::Vector3d(pos.X, pos.Y, pos.Z)) && ret < power)
    {
      callback(pos);
      ret += 1;
    }

  if ((b = this->_map.findBlock({(int)pos.X, (int)pos.Y, (int)pos.Z}))->getType() == is::Type::BREAK)
    {
      this->_blocksToDelete.emplace_back(pos.X, pos.Y, pos.Z);
      ret += 1;
    }
  else if (b->getType() == Type::BOMB)
      {
	auto it = std::find_if(bombs.begin(), bombs.end(), [pos](auto bomb) { return pos == bomb->getPos(); });

	std::cout << std::boolalpha << _alreadyBlowUp << std::endl;
	if ((*it)->_alreadyBlowUp == false)
	  (*it)->_explosion(bombs);
	ret += 1;
	//std::cout << "DESTRUIT UNE AUTRE BOMBE" << std::endl;
      }
  //std::cout << "ret = " << ret << std::endl;<commit_msg>MAJ Bomb<commit_after>//
// Created by vincent on 13/06/17.
//

#include "Game.hpp"
#include "Bomb.hpp"

unsigned int			is::Bomb::ID = 0;


is::Bomb::Bomb(is::map &map, irr::video::ITexture *texture, irr::scene::IAnimatedMesh *bombMesh, const irr::core::vector3df &posMap, int power,
	       irr::video::IVideoDriver &videoDriver, irr::scene::ISceneManager &sceneManager) :
	_id(ID++),
	_posMap(posMap),
	_posSpace(posMap.Y * SCALE - SCALE / 2, 0.55 * SCALE, posMap.X * SCALE + SCALE / 2),
	_power(power),
	_map(map),
	_videoDriver(videoDriver),
	_sceneManager(sceneManager),
	_alreadyBlowUp(false),
	_start_clock(std::clock()),
	_state(BOMB_PLANTED),
	_fires()
{
  if (!(this->_node = this->_sceneManager.addAnimatedMeshSceneNode(bombMesh)))
    throw is::IndieStudioException("Error on loading bomb.");
  this->_node->setPosition(this->_posSpace);
  this->_node->setScale({0.5f * SCALE, 0.5f * SCALE, 0.5f * SCALE});
  this->_map.addObject(Type::BOMB, {(int)posMap.X, (int)posMap.Y, (int)posMap.Z});
  std::cerr << "Bomb() id = " << this->_id << std::endl;
  std::cout << "Bomb pos.x = " << posMap.X << " pos.y = " << posMap.Y << " pos.Z = " << posMap.Z << std::endl;
}

is::Bomb::~Bomb()
{
  this->_map.delObject({(int)this->_posMap.X, (int)this->_posMap.Y, (int)this->_posMap.Z});
  std::cerr << "~Bomb() id = " << this->_id << std::endl;
}


void is::Bomb::draw()
{
  this->_node->render();
}

void is::Bomb::remove()
{
  this->_node->remove();
}

bool is::Bomb::blowUp(std::list<std::shared_ptr<is::Bomb>> bombs)
{
  std::clock_t 		end_clock = std::clock();
  int 			duration = static_cast<int>((std::clock() - _start_clock) / CLOCKS_PER_SEC);

  if (this->_state == BOMB_PLANTED && duration == ((_id == 0) ? (2) : (5)))
    {
      this->_explosion(bombs);
    }
  else if (this->_state == FIRE && duration == 2)
      {
	this->_stopFires();
	return (true);
      }
  return (false);
}

int 			is::Bomb::_reducePower(std::list<std::shared_ptr<is::Bomb>> bombs,
						  irr::core::vector3df pos,
						  int power,
						  const std::function<void(irr::core::vector3df &)> &callback)
{
  int			ret = 0;
  const 		Block *b;

  //std::cerr << "_reducPower" << std::endl;
  callback(pos);
  //std::cout << "pos.x = " << pos.X << " pos.y = " << pos.Y << " pos.z = " << pos.Z<< std::endl;
  while (this->_map.canIMoove(is::Vector3d(pos.X, pos.Y, pos.Z)) && ret < power)
    {
      callback(pos);
      ret += 1;
    }

  if ((b = this->_map.findBlock({(int)pos.X, (int)pos.Y, (int)pos.Z}))->getType() == is::Type::BREAK)
    {
      this->_blocksToDelete.emplace_back(pos.X, pos.Y, pos.Z);
      ret += 1;
    }
  else if (b->getType() == Type::BOMB)
      {
	ret += 1;
	auto it = std::find_if(bombs.begin(),
			       bombs.end(),
			       [pos](auto bomb) { return pos.X == bomb->getPos().X && pos.Y == bomb->getPos().Y && pos.Z == bomb->getPos().Z; });
	if (it == bombs.end())
	  return (ret);

	std::cout << std::boolalpha << _alreadyBlowUp << std::endl;
	if ((*it)->_alreadyBlowUp == false)
	  (*it)->_explosion(bombs);
	//std::cout << "DESTRUIT UNE AUTRE BOMBE" << std::endl;
      }
  //std::cout << "ret = " << ret << std::endl;
{'fraction_non_alphanumeric': 0.22727272727272727, 'fraction_numerical': 0.00974025974025974, 'mean_word_length': 3.706646294881589, 'pattern_counts': {'":': 0, '<': 137, '<?xml version=': 0, '>': 77, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1827928', 'n_tokens_mistral': 2590, 'n_tokens_neox': 2473, 'n_words': 427}