/** * @brief Adds an outfit to a weapon set. * * @param p Pilot to manipulate. * @param id ID of the weapon set. * @param o Outfit to add. * @param level Level of the trigger. */ void pilot_weapSetAdd( Pilot* p, int id, PilotOutfitSlot *o, int level ) { PilotWeaponSet *ws; PilotWeaponSetOutfit *slot; Outfit *oo; int i, j; double r; ws = pilot_weapSet(p,id); /* Make sure outfit is valid. */ oo = o->outfit; if (oo == NULL) return; /* Make sure outfit type is weapon (or usable). */ if (!outfit_isActive(oo)) return; /* Create if needed. */ if (ws->slots == NULL) ws->slots = array_create( PilotWeaponSetOutfit ); /* Check if already there. */ for (i=0; i<array_size(ws->slots); i++) { if (ws->slots[i].slot == o) { ws->slots[i].level = level; /* Update if needed. */ if (id == p->active_set) pilot_weapSetUpdateOutfits( p, ws ); return; } } /* Add it. */ slot = &array_grow( &ws->slots ); slot->level = level; slot->slot = o; r = outfit_range(oo); if (r > 0) slot->range2 = pow2(r); /* Updated cached weapset. */ o->weapset = -1; for (j=0; j<PILOT_WEAPON_SETS; j++) { if (pilot_weapSetCheck(p, j, o) != -1) { o->weapset = j; break; } } /* Update range. */ pilot_weapSetUpdateRange( ws ); /* Update if needed. */ if (id == p->active_set) pilot_weapSetUpdateOutfits( p, ws ); }
/** * @brief Adds an outfit to the pilot, ignoring CPU or other limits. * * @note Does not call pilot_calcStats(). * * @param pilot Pilot to add the outfit to. * @param outfit Outfit to add to the pilot. * @param s Slot to add ammo to. * @return 0 on success. */ int pilot_addOutfitRaw( Pilot* pilot, Outfit* outfit, PilotOutfitSlot *s ) { Outfit *o; /* Set the outfit. */ s->outfit = outfit; /* Set some default parameters. */ s->timer = 0.; /* Some per-case scenarios. */ if (outfit_isFighterBay(outfit)) { s->u.ammo.outfit = NULL; s->u.ammo.quantity = 0; s->u.ammo.deployed = 0; } if (outfit_isTurret(outfit)) /* used to speed up AI */ pilot->nturrets++; else if (outfit_isBolt(outfit)) pilot->ncannons++; else if (outfit_isJammer(outfit)) pilot->njammers++; else if (outfit_isAfterburner(outfit)) pilot->nafterburners++; if (outfit_isBeam(outfit)) { /* Used to speed up some calculations. */ s->u.beamid = 0; pilot->nbeams++; } if (outfit_isLauncher(outfit)) { s->u.ammo.outfit = NULL; s->u.ammo.quantity = 0; s->u.ammo.deployed = 0; /* Just in case. */ } /* Check if active. */ o = s->outfit; s->active = outfit_isActive(o); /* Update heat. */ pilot_heatCalcSlot( s ); return 0; }
/** * @brief Adds an outfit to the pilot, ignoring CPU or other limits. * * @note Does not call pilot_calcStats(). * * @param pilot Pilot to add the outfit to. * @param outfit Outfit to add to the pilot. * @param s Slot to add ammo to. * @return 0 on success. */ int pilot_addOutfitRaw( Pilot* pilot, Outfit* outfit, PilotOutfitSlot *s ) { Outfit *o; /* Set the outfit. */ s->outfit = outfit; /* Set some default parameters. */ s->timer = 0.; /* Some per-case scenarios. */ if (outfit_isFighterBay(outfit)) { s->u.ammo.outfit = NULL; s->u.ammo.quantity = 0; s->u.ammo.deployed = 0; } if (outfit_isTurret(outfit)) /* used to speed up AI */ pilot_setFlag(pilot, PILOT_HASTURRET); if (outfit_isBeam(outfit)) { /* Used to speed up some calculations. */ s->u.beamid = -1; pilot_setFlag(pilot, PILOT_HASBEAMS); } if (outfit_isLauncher(outfit)) { s->u.ammo.outfit = NULL; s->u.ammo.quantity = 0; s->u.ammo.deployed = 0; /* Just in case. */ } /* Check if active. */ o = s->outfit; s->active = outfit_isActive(o); /* Update heat. */ pilot_heatCalcSlot( s ); return 0; }
/** * @brief Tries to automatically set and create the pilot's weapon set. * * Weapon set 0 is for all weapons. <br /> * Weapon set 1 is for forward weapons. Ammo using weapons are secondaries. <br /> * Weapon set 2 is for turret weapons. Ammo using weapons are secondaries. <br /> * Weapon set 3 is for all weapons. Forwards are primaries and turrets are secondaries. <br /> * Weapon set 4 is for seeking weapons. High payload variants are secondaries. <br /> * Weapon set 5 is for fighter bays. <br /> * * @param p Pilot to automagically generate weapon lists. */ void pilot_weaponAuto( Pilot *p ) { PilotOutfitSlot *slot; Outfit *o; int i, level, id; /* Clear weapons. */ pilot_weaponClear( p ); /* Set modes. */ pilot_weapSetType( p, 0, WEAPSET_TYPE_CHANGE ); pilot_weapSetType( p, 1, WEAPSET_TYPE_CHANGE ); pilot_weapSetType( p, 2, WEAPSET_TYPE_CHANGE ); pilot_weapSetType( p, 3, WEAPSET_TYPE_CHANGE ); pilot_weapSetType( p, 4, WEAPSET_TYPE_WEAPON ); pilot_weapSetType( p, 5, WEAPSET_TYPE_WEAPON ); pilot_weapSetType( p, 6, WEAPSET_TYPE_ACTIVE ); pilot_weapSetType( p, 7, WEAPSET_TYPE_ACTIVE ); pilot_weapSetType( p, 8, WEAPSET_TYPE_ACTIVE ); pilot_weapSetType( p, 9, WEAPSET_TYPE_ACTIVE ); /* All should be inrange. */ if (!pilot_isPlayer(p)) for (i=0; i<PILOT_WEAPON_SETS; i++){ pilot_weapSetInrange( p, i, 1 ); /* Update range and speed (at 0)*/ pilot_weapSetUpdateRange( &p->weapon_sets[i] ); } /* Iterate through all the outfits. */ for (i=0; i<p->noutfits; i++) { slot = p->outfits[i]; o = slot->outfit; /* Must be non-empty, and a weapon or active outfit. */ if ((o == NULL) || !outfit_isActive(o)) { slot->level = -1; /* Clear level. */ slot->weapset = -1; continue; } /* Manually defined group preempts others. */ if (o->group) { id = o->group; } /* Bolts and beams. */ else if (outfit_isBolt(o) || outfit_isBeam(o) || (outfit_isLauncher(o) && !outfit_isSeeker(o->u.lau.ammo))) { id = outfit_isTurret(o) ? 2 : 1; } /* Seekers. */ else if (outfit_isLauncher(o) && outfit_isSeeker(o->u.lau.ammo)) { id = 4; } /* Fighter bays. */ else if (outfit_isFighterBay(o)) { id = 5; } /* Ignore rest. */ else { slot->level = -1; continue; } /* Set level based on secondary flag. */ level = outfit_isSecondary(o); /* Add to its base group. */ pilot_weapSetAdd( p, id, slot, level ); /* Also add another copy to another group. */ if (id == 1) { /* Forward. */ pilot_weapSetAdd( p, 0, slot, level ); /* Also get added to 'All'. */ pilot_weapSetAdd( p, 3, slot, 0 ); /* Also get added to 'Fwd/Tur'. */ } else if (id == 2) { /* Turrets. */ pilot_weapSetAdd( p, 0, slot, level ); /* Also get added to 'All'. */ pilot_weapSetAdd( p, 3, slot, 1 ); /* Also get added to 'Fwd/Tur'. */ } else if (id == 4) /* Seekers */ pilot_weapSetAdd( p, 0, slot, level ); /* Also get added to 'All'. */ } /* Update active weapon set. */ pilot_weapSetUpdateOutfits( p, &p->weapon_sets[ p->active_set ] ); }