/*
* Updates or adds a new aircraft, depending on if it exists or not
*
* TODO: Change to a get/set update methodology, called from the parser itself
* This is just messy and inefficient
*
*/
aircraft_node *setAircraft(aircraft_node *root_node,aircraft *new_aircraft){
 aircraft *ac = getAircraftByICAO(root_node,new_aircraft->icao_address);
 if(ac!=NULL){
  // AC exists, update it
  if(new_aircraft->icao_address>0)
   ac->icao_address=new_aircraft->icao_address;
  if(new_aircraft->velocity>0)
   ac->velocity=new_aircraft->velocity;
  if(new_aircraft->heading>0)
   ac->heading=new_aircraft->heading;
  if(new_aircraft->altitude>0)
   ac->altitude=new_aircraft->altitude;
  if(new_aircraft->vrate>0)
   ac->vrate=new_aircraft->vrate;
  if(new_aircraft->latitude>0)
   ac->latitude=new_aircraft->latitude;
  if(new_aircraft->longitude>0)
   ac->longitude=new_aircraft->longitude;
  if(new_aircraft->callsign!=NULL){
   if(ac->callsign!=NULL){ // Callsign already allocated
    memcpy(ac->callsign,new_aircraft->callsign,sizeof(unsigned char)*9);
   }else{ // Callsign not already allocated
    ac->callsign=malloc(sizeof(unsigned char)*9);
    memcpy(ac->callsign,new_aircraft->callsign,sizeof(unsigned char)*9);
   }
  }
  ac->last_seen = time(NULL);
  return root_node;
 }else{
  return addAircraft(root_node,new_aircraft);
 }
}
示例#2
0
文件: Engine.cpp 项目: krosk/airsim
Engine::Engine() :
	moveSystem(MoveSystem()),
	aiSystemAircraft(AiSystemAircraft())
{
    for(int i = 1; i < 2; i++)
    {
        addAircraft(i);
    }
    
    moveMovableEntity(1, 100, 50, 0, 60);
}
int main(void) {

	int airborneFighters, i;
	Fighter *fighters;
	
	printf("How many fighters are deployed?\n");
	scanf("%d", &airborneFighters);
	
	// Allocating memory for active aircraft deployed
	fighters = (Fighter*) malloc(sizeof(Fighter) * airborneFighters);
	if(fighters == NULL)
		printf("Error during memory allocation\n");
		
	addAircraft(fighters, airborneFighters);
	displayAircraft(fighters, airborneFighters);
	
	// Free memory allocated by malloc()
	free(fighters);
	
	return 0;
}