Esempio 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;
}
Esempio n. 2
0
void Rand::behaviour(AgentControl *agent) {
    if (t>10) {
        Vect force = Vect((rand() % 100) - 50, (rand() % 100) - 50);
        force.Normalize();
        agent->getPhy()->applyForce(100*force);
        t = 0;
    }
    t++;
}