예제 #1
0
/**
 * @brief Checks to see if can equip/remove an outfit from a slot.
 *
 *    @param p Pilot to check if can equip.
 *    @param s Slot being checked to see if it can equip/remove an outfit.
 *    @param o Outfit to check (NULL if being removed).
 *    @return NULL if can swap, or error message if can't.
 */
const char* pilot_canEquip( Pilot *p, PilotOutfitSlot *s, Outfit *o )
{
    Outfit *o_old;
    const char *err;
    double pa, ps, pe, pf;

    /* Just in case. */
    if ((p==NULL) || (s==NULL))
        return "Nothing selected.";

    if (o!=NULL) {
        /* Check slot type. */
        if (!outfit_fitsSlot( o, &s->sslot->slot ))
            return "Does not fit slot.";
        /* Check outfit limit. */
        if ((o->limit != NULL) && pilot_hasOutfitLimit( p, o->limit ))
            return "Already have an outfit of this type installed";
    }
    else {
        /* Check fighter bay. */
        if ((o==NULL) && (s!=NULL) && (s->u.ammo.deployed > 0))
            return "Recall the fighters first";
    }

    /* Store health. */
    pa = p->armour;
    ps = p->shield;
    pe = p->energy;
    pf = p->fuel;

    /* Swap outfit. */
    o_old       = s->outfit;
    s->outfit   = o;

    /* Check sanity. */
    pilot_calcStats( p );
    /* can now equip outfit even if ship won't be spaceworthy
     * err = pilot_checkSpaceworthy( p );*/
    /* actually, this is also redundant */
    if (!pilot_slotsCheckSanity(p))
        err = "Does not fit in slot";
    else
        err = NULL;

    /* Swap back. */
    s->outfit   = o_old;

    /* Recalc. */
    pilot_calcStats( p );

    /* Recover health. */
    p->armour = pa;
    p->shield = ps;
    p->energy = pe;
    p->fuel   = pf;

    return err;
}
예제 #2
0
/**
 * @brief Pilot sanity check - makes sure stats are sane.
 *
 *    @param p Pilot to check.
 *    @return The reason why the pilot is not sane (or NULL if sane).
 */
const char* pilot_checkSpaceworthy( Pilot *p )
{
   if (!pilot_slotsCheckSanity(p))
      return "Doesn't fit slot";

   /* CPU. */
   if (p->cpu < 0)
      return "Insufficient CPU";

   /* Movement. */
   if (p->thrust < 0.)
      return "Insufficient Thrust";
   if (p->speed < 0.)
      return "Insufficient Speed";
   if (p->turn < 0.)
      return "Insufficient Turn";

   /* Health. */
   if (p->armour_max < 0.)
      return "Insufficient Armour";
   if (p->armour_regen < 0.)
      return "Insufficient Armour Regeneration";
   if (p->shield_max < 0.)
      return "Insufficient Shield";
   if (p->shield_regen < 0.)
      return "Insufficient Shield Regeneration";
   if (p->energy_max < 0.)
      return "Insufficient Energy";
   if (p->energy_regen < 0.)
      return "Insufficient Energy Regeneration";

   /* Misc. */
   if (p->fuel_max < 0.)
      return "Insufficient Fuel Maximum";
   if (p->fuel_consumption < 0.)
      return "Insufficient Fuel Consumption";
   if (p->cargo_free < 0)
      return "Insufficient Free Cargo Space";

   /* Core Slots */
   if (!pilot_slotsCheckRequired(p))
      return "Not All Core Slots are equipped";

   /* All OK. */
   return NULL;
}