<commit_before>#include "insect.hpp"
#include "graph/graph.hpp"
#include <iostream>

void Insect::draw(sf::RenderTarget& target, Graph *g, sf::Sprite sprite) {
  Branch *b = g->getBranch(path.getBranchID(currentBranch));
  float cpos = pos;
  float sign = 1.0f;
  if (b->getSecondNode() == path.getNodeID(currentBranch)) {
    cpos = 1-pos;
    sign = -1.0f;
  }
  sf::Vector2f posVect = b->getSpline().evaluatePos(cpos);
  sf::Vector2f speedVect = b->getSpline().evaluateSpeed(cpos) * sign;
  angle = atan2(speedVect.y, speedVect.x);

  sprite.setRotation(angle * 180.0f / 3.14159265f + 90.0f);
  sprite.setPosition(posVect);
  hitbox.setPosition(posVect);
  target.draw(hitbox);
  target.draw(sprite);
}

void Insect::move(float dt, Graph* g) {
  float len = g->getBranch(path.getBranchID(currentBranch))->getLength();
  pos += speed * dt / len;
  if (pos > 1.0f) {
    pos = 0.0f;
    currentBranch += 1;
    if (currentBranch == path.size())
    {
        currentBranch = 0;
        reachedObjective = true;
    }
  }
}

Insect::type Insect::getType() {
  return mType;
}

Insect::Insect(type mType, float fhitbox
	       ,int currentBranch
	       , float pos, float speed, float angle, Node::ID obj, bool bo) : mType(mType)
						      , hitbox(fhitbox)
						      , currentBranch(currentBranch)
						      , pos(pos)
						      , speed(speed)
						      , angle(angle)
						      , objective(obj)
						      , reachedObjective(bo)
{
  hitbox.setOrigin(fhitbox, fhitbox);
}

Aphid::Aphid(AphidBehaviour::ID b, Node spawn, Graph *g) : Insect(Insect::Aphid, 10, 0, 0.0f, 50.0f, 0.0f, spawn, false)
						    , behaviour(b, spawn, *g)
{
  path = behaviour.getPath();
  objective = behaviour.getObjective();
}


LadyBug::LadyBug(Insect::type type, Node spawn, Graph *g) : Insect(type, 12, 0, 0.0f, 50.f*1.5f, 0.0f, spawn, true)
{
    path = AphidBehaviour(AphidBehaviour::Offensive, Node::ID(spawn), *g).getPath();
}<commit_msg>ladyBug spawn avec un path safe<commit_after>#include "insect.hpp"
#include "graph/graph.hpp"
#include <iostream>

void Insect::draw(sf::RenderTarget& target, Graph *g, sf::Sprite sprite) {
  Branch *b = g->getBranch(path.getBranchID(currentBranch));
  float cpos = pos;
  float sign = 1.0f;
  if (b->getSecondNode() == path.getNodeID(currentBranch)) {
    cpos = 1-pos;
    sign = -1.0f;
  }
  sf::Vector2f posVect = b->getSpline().evaluatePos(cpos);
  sf::Vector2f speedVect = b->getSpline().evaluateSpeed(cpos) * sign;
  angle = atan2(speedVect.y, speedVect.x);

  sprite.setRotation(angle * 180.0f / 3.14159265f + 90.0f);
  sprite.setPosition(posVect);
  hitbox.setPosition(posVect);
  target.draw(hitbox);
  target.draw(sprite);
}

void Insect::move(float dt, Graph* g) {
  float len = g->getBranch(path.getBranchID(currentBranch))->getLength();
  pos += speed * dt / len;
  if (pos > 1.0f) {
    pos = 0.0f;
    currentBranch += 1;
    if (currentBranch == path.size())
    {
        currentBranch = 0;
        reachedObjective = true;
    }
  }
}

Insect::type Insect::getType() {
  return mType;
}

Insect::Insect(type mType, float fhitbox
	       ,int currentBranch
	       , float pos, float speed, float angle, Node::ID obj, bool bo) : mType(mType)
						      , hitbox(fhitbox)
						      , currentBranch(currentBranch)
						      , pos(pos)
						      , speed(speed)
						      , angle(angle)
						      , objective(obj)
						      , reachedObjective(bo)
{
  hitbox.setOrigin(fhitbox, fhitbox);
}

Aphid::Aphid(AphidBehaviour::ID b, Node spawn, Graph *g) : Insect(Insect::Aphid, 10, 0, 0.0f, 50.0f, 0.0f, spawn, false)
						    , behaviour(b, spawn, *g)
{
  path = behaviour.getPath();
  objective = behaviour.getObjective();
}


LadyBug::LadyBug(Insect::type type, Node spawn, Graph *g) : Insect(type, 12, 0, 0.0f, 50.f*1.5f, 0.0f, spawn, true)
{
    Branch::ID spawnBranch = g->getNeighbours(spawn).begin()->second;
    path.addBranch(spawn, spawnBranch);
    path.addBranch((*g)[spawnBranch].getFirstNode(), spawnBranch);
}
{'fraction_non_alphanumeric': 0.1584630838774485, 'fraction_numerical': 0.025615268709191362, 'mean_word_length': 3.3293478260869565, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '6293159', 'n_tokens_mistral': 1666, 'n_tokens_neox': 1519, 'n_words': 292}