int GetBrandIndex(int type) { if(type == -1) return COMPUTER_INDEX; if(type == -2) return RADIO_INDEX; if(IsWeapon(type)) if(type < I2Weapon(num_def_weapons)) { type = Weapon2I(type); if(MechWeapons[type].special & PCOMBAT) return -1; if(IsFlamer(type)) return FLAMMER_INDEX; if(IsEnergy(type)) return ENERGY_INDEX; if(IsAutocannon(type)) return AC_INDEX; if(IsMissile(type)) return MISSILE_INDEX; return -1; } return -1; }
void mech_unjam_ammo_event(EVENT * objEvent) { MECH *objMech = (MECH *) objEvent->data; /* get the mech */ int wWeapNum = (int) objEvent->data2; /* and now the weapon number */ int wSect, wSlot, wWeapStatus, wWeapIdx; int ammoLoc, ammoCrit, ammoLeft; int wRoll = 0; int wRollNeeded = 0; if (Uncon(objMech) || !Started(objMech)) return; wWeapStatus = FindWeaponNumberOnMech(objMech, wWeapNum, &wSect, &wSlot); if (wWeapStatus == TIC_NUM_DESTROYED) /* return if the weapon has been destroyed */ return; wWeapIdx = FindWeaponIndex(objMech, wWeapNum); ammoLeft = FindAmmoForWeapon_sub(objMech, wSect, wSlot, wWeapIdx, 0, &ammoLoc, &ammoCrit, 0, 0); if (!ammoLeft) { SetPartTempNuke(objMech, wSect, wSlot, 0); mech_notify(objMech, MECHALL, tprintf ("You finish bouncing around and realize you nolonger have ammo for your %s!", get_parts_long_name(I2Weapon(wWeapIdx), 0))); return; } if (MechWeapons[wWeapStatus].special & RAC) { wRoll = Roll(); wRollNeeded = FindPilotGunnery(objMech, wWeapStatus) + 3; mech_notify(objMech, MECHPILOT, "You make a roll to unjam the weapon!"); mech_notify(objMech, MECHPILOT, tprintf("Modified Gunnery Skill: BTH %d\tRoll: %d", wRollNeeded, wRoll)); if (wRoll < wRollNeeded) { mech_notify(objMech, MECHALL, "Your attempt to remove the jammed slug fails. You'll need to try again to clear it."); return; } } else { if (!MadePilotSkillRoll(objMech, 0)) { mech_notify(objMech, MECHALL, "Your attempt to remove the jammed slug fails. You'll need to try again to clear it."); return; } } SetPartTempNuke(objMech, wSect, wSlot, 0); mech_notify(objMech, MECHALL, tprintf("You manage to clear the jam on your %s!", get_parts_long_name(I2Weapon(wWeapIdx), 0))); MechLOSBroadcast(objMech, "ejects a mangled shell!"); SetPartData(objMech, ammoLoc, ammoCrit, GetPartData(objMech, ammoLoc, ammoCrit) - 1); }