int tech_parsegun(MECH * mech, char *buffer, int *loc, int *pos, int *brand) { char *args[3]; int l, argc, t, c = 0, pi, pb; argc = mech_parseattributes(buffer, args, 3); if(argc < 1 || argc > (2 + (brand != NULL))) return -1; if(argc == (2 + (brand != NULL)) || (brand && argc == 2 && atoi(args[1]))) { if((*loc = ArmorSectionFromString(MechType(mech), MechMove(mech), args[0])) < 0) return -1; l = atoi(args[1]); if(l <= 0 || l > CritsInLoc(mech, *loc)) return -4; *pos = l - 1; } else { /* Check if it's a number */ if(args[0][0] < '0' || args[0][0] > '9') return -1; l = atoi(args[0]); if(l < 0) return -1; if((t = FindWeaponNumberOnMech(mech, l, loc, pos)) == -1) return -1; } t = GetPartType(mech, *loc, *pos); if(brand != NULL && argc > 1 && !atoi(args[argc - 1])) { if(!find_matching_long_part(args[argc - 1], &c, &pi, &pb)) return -2; if(pi != t) return -3; *brand = pb; } else if(brand != NULL) *brand = GetPartBrand(mech, *loc, *pos); return 0; }
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); }