return final_spin;
    public static void spinUpCannon(IGame cgame, WeaponAttackAction atk) {        int threshold = 12;        int test;        Entity shooter;        Mounted weapon;        WeaponType wtype = new WeaponType();        // Double check this is an Ultra or Rotary cannon        shooter = atk.getEntity(cgame);        weapon = shooter.getEquipment(atk.getWeaponId());        wtype = (WeaponType) shooter.getEquipment(atk.getWeaponId()).getType();        if (!((wtype.getAmmoType() == AmmoType.T_AC_ULTRA) || (wtype.getAmmoType() == AmmoType.T_AC_ROTARY))){            return;        }        // Get the to-hit number        threshold = atk.toHit(cgame).getValue();        // Set the weapon to single shot mode        weapon.setMode("Single");        // If weapon can't hit target, exit the function with the weapon on single shot        if ((threshold == ToHitData.IMPOSSIBLE) || (threshold == ToHitData.AUTOMATIC_FAIL)) {            return;        }        // Set a random 2d6 roll        test = d6(2);        // If random roll is >= to-hit + 1, then set double-spin        if (test >= threshold + 1){            if (wtype.getAmmoType() == AmmoType.T_AC_ULTRA){                weapon.setMode("Ultra");            }            if (wtype.getAmmoType() == AmmoType.T_AC_ROTARY){                weapon.setMode("2-shot");            }        }        // If this is a Rotary cannon        if (wtype.getAmmoType() == AmmoType.T_AC_ROTARY){            // If random roll is >= to-hit + 2 then set to quad-spin            if (test >= threshold + 2){                weapon.setMode("4-shot");            }            // If random roll is >= to-hit + 3 then set to six-spin            if (test >= threshold + 3){                weapon.setMode("6-shot");            }        }    }