Exemplo n.º 1
0
bool Env::sendMsg(long idSrc, long idDest, char *msg) {
    logMsg("SEND MSG : " + std::to_string(idSrc) + " -> " + std::to_string(idDest));
    // if (this->phy->getNeighbours(idSrc).count(idDest)) {
        this->agents.at(idDest)->addMsg(msg);

        // Display the sending message with dataAgents
        Agent * agentSrc = this->agents.at(idSrc);
        Agent * agentDest = this->agents.at(idDest);
        Vect posSrc = PosToCell(agentSrc->getPos().x, agentSrc->getPos().y);
        Vect posDest = PosToCell(agentDest->getPos().x, agentDest->getPos().y);
        if (posSrc != posDest) {
            float dist = ((724-Vect(posSrc - posDest).Length()) / 724.0) / 6.0;
            for (float n = 0; n < 1; n += dist) {
                Vect base = posDest + n * (posSrc - posDest);
                Vect dirSommet = Vect(posSrc - posDest);
                dirSommet.Normalize();
                Vect vectBase = Vect(dirSommet.y, -dirSommet.x);
                for (int j = 0; j < 20; j++) {
                    for (int i = -j*0.5; i <= j*0.5; i++) {
                        Vect point = base + j / 2.0 * dirSommet + i / 2.0 * vectBase;
                        if (point.x >= 0 && point.x < 512 && point.y >= 0 && point.y < 512) {
                            agentSrc->getVision(point.x, point.y)->dataAgent = 10 * (1 - n);
                        }
                    }
                }
            }
        }
        return true;
    //}
    //return false;
}
Exemplo n.º 2
0
Agent* Env::addAgent(float range, float speed) {
    int idAgent = this->agents.size();
    Agent *agent = new Agent(idAgent, phy, range/this->W, speed, (EnvAgents*)this);
    this->phy->addAgent(idAgent, agent->getPos(), agent->getAngle(), agent->getSize(), agent->getRange()/this->W);
    this->agents.insert(pair<long, Agent*>(idAgent, agent));
    this->phy->setMaxSpeed(idAgent, speed);
    return agent;
}
Exemplo n.º 3
0
void SWGraph::getRealConnectivities(ofstream& fp){
  
  // Para cada agente obtener su posicion 
  // y con esa posicion buscar los vecinos 
  // y contarlos.
  
  list<Agent*> vecinos;
  Agent* a = NULL;
  Position* pos=NULL;

  set<Agent*>::iterator i;
  for (i = agents.begin(); i != agents.end(); ++i) {  
    a = *i;
    pos = a->getPos();
    vecinos = getNeighbourgs(pos);
    //cout << a->getId()<< "\t" << vecinos.size()<<"\n";
    fp << a->getId()<< "\t" << vecinos.size()<<"\n";}

}