Exemplo n.º 1
0
Agent* AgentList::addOrUpdateAgent(sockaddr* publicSocket, sockaddr* localSocket, char agentType, uint16_t agentId) {
    AgentList::iterator agent = end();
    
    if (publicSocket) {
        for (agent = begin(); agent != end(); agent++) {
            if (agent->matches(publicSocket, localSocket, agentType)) {
                // we already have this agent, stop checking
                break;
            }
        }
    } 
    
    if (agent == end()) {
        // we didn't have this agent, so add them
        Agent* newAgent = new Agent(publicSocket, localSocket, agentType, agentId);
        
        if (socketMatch(publicSocket, localSocket)) {
            // likely debugging scenario with two agents on local network
            // set the agent active right away
            newAgent->activatePublicSocket();
        }
   
        if (newAgent->getType() == AGENT_TYPE_VOXEL_SERVER ||
            newAgent->getType() == AGENT_TYPE_AVATAR_MIXER ||
            newAgent->getType() == AGENT_TYPE_AUDIO_MIXER) {
            // this is currently the cheat we use to talk directly to our test servers on EC2
            // to be removed when we have a proper identification strategy
            newAgent->activatePublicSocket();
        }
        
        addAgentToList(newAgent);
        
        return newAgent;
    } else {
        
        if (agent->getType() == AGENT_TYPE_AUDIO_MIXER ||
            agent->getType() == AGENT_TYPE_VOXEL_SERVER) {
            // until the Audio class also uses our agentList, we need to update
            // the lastRecvTimeUsecs for the audio mixer so it doesn't get killed and re-added continously
            agent->setLastHeardMicrostamp(usecTimestampNow());
        }
        
        // we had this agent already, do nothing for now
        return &*agent;
    }    
}
Exemplo n.º 2
0
int Grid1D::getNumCooperators(){

  list<Agent*> ags;
  int count = 0;
  Agent* a = NULL;

  set<Agent*>::iterator i;
  for (i = agents.begin(); i != agents.end(); ++i) {  
    a = *i;
    if ((a->getType()) == COOP){
      count++;
    }
  }
  return count;
}
Exemplo n.º 3
0
void Agent::clone(Agent b){
	type = b.getType();
	decompositionTime = b.decompositionTime;
	decomposed = b.decomposed;
	shooted = b.shooted;
	lifeTime = b.lifeTime;
	infected = b.infected;
	gender = b.gender;
	age = b.age;
	hasAGun = b.hasAGun;
	infectionTime = b.infectionTime;
	yearTime = b.yearTime;
	deadByConversion = b.deadByConversion;
	naturalDead = b.naturalDead;
	lifeExpectancy = b.lifeExpectancy;
	numBabies = b.numBabies;
}