示例#1
0
void Tribe::SendPerception(const char* pcpt, csArray<NPC*> npcs)
{
    Perception perception(pcpt);
    for(size_t i=0; i<npcs.GetSize(); i++)
    {
        NPC* npc = npcs[i];
        RDebug(this, 5, "--> Percept npc %s(%s): %s",npc->GetName(),ShowID(npc->GetEID()),perception.ToString(npc).GetDataSafe());

        npc->TriggerEvent(&perception);
    }
}
示例#2
0
void move()
{
    perception();

    // compute final direction and motor speed
    speed = 0.0;
    float desiredAngle = direction;

    double leftSpeed = 0.0;
    double rightSpeed = 0.0;

    // if angle is not big ... don't turn
    if (fabs(desiredAngle) < MOVE_THRESOLD * M_PI / 180.0)
    {
        // direction does not change...
        leftSpeed = speed;
        rightSpeed = speed;
    }
    // turn left
    else if (desiredAngle >= 0.0)
    {
        leftSpeed = -turnspeed;
        rightSpeed = turnspeed;

        // update internal direction according to movement
        float timestep = 0.25;
        float angle = 2.0 * M_PI * turnspeed * timestep / NUMBER_STEPS_FULL_TURN;
        updateDirections(-angle);
    }
    // turn right
    else
    {
        leftSpeed = turnspeed;
        rightSpeed = -turnspeed;

        // update internal direction according to movement
        float timestep = 0.25;
        float angle = 2.0 * M_PI * turnspeed * timestep / NUMBER_STEPS_FULL_TURN;
        updateDirections(angle);
    }

    // change movement direction
    e_set_speed_left(leftSpeed);
    e_set_speed_right(rightSpeed);
}
示例#3
0
void Tribe::SendPerception(const char* pcpt)
{
    Perception perception(pcpt);
    TriggerEvent(&perception);
}