Torpedos are the secondary weapon used by ships in BerryBots. They move a specified distance, passing through walls and other ships. When they explode, they deal damage to all ships in the area. They are hard to aim and can only be fired infrequently, but do a large amount of damage, possibly to multiple ships.
A torpedo can be fired in any direction and distance by calling the fireTorpedo function on a Ship object. The torpedo originates from the center of the firing ship and travels a distance of 12 each tick, passing through any walls or ships, until it reaches the specified distance. Then it explodes, doing damage to all ships within a blast radius of 100. It deals 30 damage at the center of the blast, scaling quadratically to 0 at the edges. (So 15 damage at distance 29.29, 7.5 damage at 50, 1 damage at 81.74.) It also does knockback in the same amount, altering the ships' trajectories. After firing, a ship's torpedo gun takes 100 ticks to cool down - at maximum, it can fire a torpedo every 100th tick. On the first tick that a torpedo is fired, it advances an extra tick.
A torpedo can damage the ship that fired it, as well as that ship's teammates. Damaging friendly ships (teammates or self) is tracked separately from damaging enemy ships, so it can be counted differently in scoring. (The battlestage sample scoring module subtracts points for friendly damage and kills.) If multiple torpedos hit a ship on the tick that it is destroyed, the "kill" is split across the firing ships - that is, the return value of Admin.shipKills() increases by .5 (or .333, or .25, etc) for each ship. But if lasers kill that ship first, the torpedos don't get a share.
By default, ships cannot fire torpedos. The stage needs to enable torpedo guns by setting Battle Mode to true, or by manually enabling torpedo guns for individual ships with Admin.setShipTorpedoEnabled().