[Change] Made setSecondary static for minor optimization.

This commit is contained in:
Allanis 2014-05-20 15:50:49 +01:00
parent 3d85fa67f6
commit 22ebaef033
2 changed files with 8 additions and 8 deletions

View File

@ -74,6 +74,7 @@ void pilot_free(Pilot* p); /* Externed in player.c */
static int fleet_parse(Fleet* tmp, const xmlNodePtr parent);
static void pilot_dead(Pilot* p);
static int pilot_setOutfitMounts(Pilot* p, PilotOutfit* po, int o, int q);
static void pilot_setSecondary(Pilot* p, Outfit* o);
/**
* @brief Get the pilots position in the stack.
@ -552,11 +553,11 @@ void pilot_runHook(Pilot* p, int hook_type) {
* @param p Pilot to set secondary weapon.
* @param secondary Name of the secondary weapon to set.
*/
void pilot_setSecondary(Pilot* p, const char* secondary) {
static void pilot_setSecondary(Pilot* p, Outfit* o) {
int i;
/* No need for ammo if there is no secondary. */
if(secondary == NULL) {
if(o == NULL) {
p->secondary = NULL;
p->ammo = NULL;
return;
@ -564,7 +565,7 @@ void pilot_setSecondary(Pilot* p, const char* secondary) {
/* Find the secondary and set ammo appropriately. */
for(i = 0; i < p->noutfits; i++) {
if(strcmp(secondary, p->outfits[i].outfit->name)==0) {
if(p->outfits[i].outfit == o) {
p->secondary = &p->outfits[i];
pilot_setAmmo(p);
return;
@ -991,7 +992,7 @@ static int pilot_setOutfitMounts(Pilot* p, PilotOutfit* po, int o, int q) {
int pilot_addOutfit(Pilot* pilot, Outfit* outfit, int quantity) {
int i;
int o, q, free_space;
char* osec;
Outfit* osec;
PilotOutfit* po;
free_space = pilot_freeSpace(pilot);
@ -1040,7 +1041,7 @@ int pilot_addOutfit(Pilot* pilot, Outfit* outfit, int quantity) {
}
/* Hacks in case it reallocs. */
osec = (pilot->secondary) ? pilot->secondary->outfit->name : NULL;
osec = (pilot->secondary) ? pilot->secondary->outfit : NULL;
/* No need for ammo since it's already handled in setSecondary, */
/* since pilot has only one afterburner it's handled at the end. */
@ -1085,7 +1086,7 @@ int pilot_addOutfit(Pilot* pilot, Outfit* outfit, int quantity) {
*/
int pilot_rmOutfit(Pilot* pilot, Outfit* outfit, int quantity) {
int i, j, q, c, o;
char* osec;
Outfit* osec;
PilotOutfit* po;
c = (outfit_isMod(outfit)) ? outfit->u.mod.cargo : 0;
@ -1112,7 +1113,7 @@ int pilot_rmOutfit(Pilot* pilot, Outfit* outfit, int quantity) {
q += po->quantity;
/* Hack in case it reallocs - Can happen even when shrinking. */
osec = (pilot->secondary) ? pilot->secondary->outfit->name : NULL;
osec = (pilot->secondary) ? pilot->secondary->outfit : NULL;
/* Free some memory if needed. */
if(po->mounts != NULL)

View File

@ -244,7 +244,6 @@ void pilot_hyperspaceAbort(Pilot* p);
/* Special outfit stuff. */
int pilot_getMount(Pilot* p, int id, Vec2* v);
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);