/** * @brief Creates an escort. * * @param p Parent of the escort (who he's guarding). * @param ship Name of the ship escort should have. * @param pos Position to create escort at. * @param vel Velocity to create escort with. * @param dir Direction to face. * @param type Type of escort. * @param add Whether or not to add it to the escort list. * @return The ID of the escort on success. */ unsigned int escort_create( Pilot *p, char *ship, Vector2d *pos, Vector2d *vel, double dir, EscortType_t type, int add ) { Ship *s; Pilot *pe; unsigned int e; PilotFlags f; unsigned int parent; /* Get important stuff. */ parent = p->id; s = ship_get(ship); /* Set flags. */ pilot_clearFlagsRaw( f ); pilot_setFlagRaw( f, PILOT_NOJUMP ); if (type == ESCORT_TYPE_BAY) pilot_setFlagRaw( f, PILOT_CARRIED ); /* Create the pilot. */ e = pilot_create( s, NULL, p->faction, "escort", dir, pos, vel, f ); pe = pilot_get(e); pe->parent = parent; /* Add to escort list. */ if (add != 0) escort_addList( p, ship, type, e, 1 ); return e; }
/** * @brief Creates a pilot belonging to afleet. * * @param flt Fleet to which pilot belongs to. * @param plt Pilot to create. * @param dir Direction to face. * @param pos Position to create at. * @param vel Initial velocity. * @param ai AI to use (NULL is default). * @param flags Flags to create with. * @param systemFleet System fleet the pilot belongs to. * @return The ID of the pilot created. * * @sa pilot_create */ unsigned int fleet_createPilot( Fleet *flt, FleetPilot *plt, double dir, Vector2d *pos, Vector2d *vel, const char* ai, PilotFlags flags, const int systemFleet ) { unsigned int p; p = pilot_create( plt->ship, plt->name, flt->faction, (ai != NULL) ? ai : (plt->ai != NULL) ? plt->ai : flt->ai, dir, pos, vel, flags, systemFleet ); return p; }
/** * @brief Creates an escort. * * @param parent Parent of the escort (who he's guarding). * @param ship Name of the ship escort should have. * @param pos Position to create escort at. * @param vel Velocity to create escort with. * @param carried Does escort come out of the parent? */ int escort_create( unsigned int parent, char *ship, Vector2d *pos, Vector2d *vel, int carried ) { Ship *s; Pilot *p, *pe; char buf[16]; unsigned int e, f; double dir; /* Get important stuff. */ p = pilot_get(parent); s = ship_get(ship); snprintf(buf, 16, "escort*%u", parent); /* Set flags. */ f = PILOT_ESCORT; if (carried) f |= PILOT_CARRIED; /* Get the direction. */ if (carried) dir = p->solid->dir; else dir = 0.; /* Create the pilot. */ e = pilot_create( s, NULL, p->faction, buf, dir, pos, vel, f ); pe = pilot_get(e); pe->parent = parent; /* Add to escort list. */ p->nescorts++; if (p->nescorts == 1) p->escorts = malloc(sizeof(unsigned int) * ESCORT_PREALLOC); else if (p->nescorts > ESCORT_PREALLOC) p->escorts = realloc( p->escorts, sizeof(unsigned int) * p->nescorts ); p->escorts[p->nescorts-1] = e; return 0; }