void Organism::removeRobot(RobotAgentPtr robot) {
	std::vector<RobotAgentPtr>::iterator it;
	for (it = this->agents.begin(); it != this->agents.end(); it++) {
		if ((*it)->getWorldModel()->_agentId == robot->getWorldModel()->_agentId) {
			this->agents.erase(it);
			break;
		}
	}
	robot->setOrganism(NULL);
    
	// Remove the organism if there is less than 1 robot left in it
	if (this->agents.size() < 1) {
		this->leader = RobotAgentPtr();
		this->setInactive();
	}else{
        // Create another leader in case the leader has just been removed. We'll just take the first one in the agents vector.
        if (this->leader == robot){
            this->leader = agents.at(0);
        }
    }
}
예제 #2
0
void RobotAgent::addNeighbour(RobotAgentPtr neighbour) {
	this->connected->push_back(RobotAgentPtr(neighbour));
}