diff --git a/src/pilot.c b/src/pilot.c index 648d277..e6c7dd3 100644 --- a/src/pilot.c +++ b/src/pilot.c @@ -498,6 +498,30 @@ void pilot_setAmmo(Pilot* p) { p->ammo = NULL; } +/** + * @fn int pilot_getAmmo(Pilot* p, Outfit* o) + * @param p Pilot to get amount of ammo for. + * @param o Outfit to get ammo for. + * @return Amount of ammo for o on p. + */ +int pilot_getAmmo(Pilot* p, Outfit* o) { + int i; + char* name; + + /* Must be a launcher. */ + if(!outfit_isLauncher(o)) + return 0; + + /* Try to find the ammo. */ + name = o->u.lau.ammo; + for(i = 0; i < p->noutfits; i++) + if(strcmp(p->outfits[i].outfit->name, name)==0) + return p->outfits[i].quantity; + + /* Assume none. */ + return 0; +} + /** * @fn void pilot_setAfterburner(Pilot* p) * diff --git a/src/pilot.h b/src/pilot.h index efd7aa9..0a5ed8b 100644 --- a/src/pilot.h +++ b/src/pilot.h @@ -220,6 +220,7 @@ void pilot_hit(Pilot* p, const Solid* w, const unsigned int shooter, void pilot_switchSecondary(Pilot* p, int i); void pilot_setSecondary(Pilot* p, const char* secondary); void pilot_setAmmo(Pilot* p); +int pilot_getAmmo(Pilot* p, Outfit* o); void pilot_setAfterburner(Pilot* p); double pilot_face(Pilot* p, const double dir); void pilot_hyperspaceAbort(Pilot* p);