Bug: Guns Jamming on Ships (RESOLVED)

Resolution

The problem appears to be as follows (thanks jK):

QueryWeaponX is called before a weapon is fired to see if the firepoint, as well as the aimpoint, can see the target. If QueryWeaponX returns a piece that is not facing the target, the weapon won't fire. In the old code, the gun_x indices were initially set to zero, for which there was no case in QueryWeaponX; therefore, QueryWeaponX returned whatever the first piece for that unit was. This explains why some ships worked and others didn't--those ships whose first piece was aligned with the weapon worked all the time, while those whose first piece was the base only worked facing forwards.

This was fixed by putting gun_x = 1; in Create(), and making sure all QueryWeaponX calls returned a valid barrel NO MATTER THE VALUE OF gun_x.

This page will be saved for future reference.

Problem

Sometimes the weapons of ships will aim at their target but not fire ("jam"). This appears to happen if all of the following conditions are met:

  1. Since the last time the weapon started aiming after a RestoreAfterDelay, it had to move too far to aim at its target.
  2. The weapon has rocking enabled (not sure on this one).
  3. The weapon has never fired before.

However, the jamming is quite unpredictable.

GET PRINT statements before the end of AimWeapon do trigger when the weapon jams, but FireWeapon is not called during a jam. The jamming occurs in FPS mode as well; affected weapons show as "Ready" but do not fire when the mouse is clicked.

The last condition means that a weapon that has fired at least once is permanently free from this bug. However, I still consider it a serious bug.

History

This bug appeared when I (Evil4Zerggin) implemented ship rocking.

The ship rocking also suffers from a smaller bug, namely that the arguments of RockZ are interpreted (?) in reverse order from the way they are coded.

Attempts to Resolve

  • Removing the rocking code. I have only tested it with the Arm Cruiser so far. It did not solve the problem completely, although improvement was seen.
  • Putting the call to RockZ inside a conditional so that it would only rock if the weapon had already been fired at least once. This did not appear to help.
  • Increasing turret traverse rate. This did not appear to help.
  • Giving tolerance or pitch tolerance. Setting this to 512 for Atlantis did not help.
  • Adding sleep 50 statements to ShotX and RockZ. This did not appear to help.
  • Having the turret turn instantly to the target if the weapon has not fired before. Obviously this presents other issues; however, it seems to work for the Arm cruiser.
  • Splitting the turret turning code into another function did not help.
  • Putting a dummy start-script FireWeaponX in Create() did not help.
  • Compiling the script as a TAK script resulted in the following error:

CobError: stack not large enough, need: 1, have: 0 (too few arguments passed to function?) (in scripts/armcrus.cob:Shot1 at 26d)

Reliability did not improve.

  • Removing wake emits did not help.

Code

In addition to the unit code, the ships use rockz.h which in turn uses calc.h. These, as well as the unit code, can be found in the Scripts folder of the mod (see links at bottom).

Units Affected

Strangely, not all of the ships that I gave the rocking code suffer from this bug; this may mean that the bug stems from the aiming code, unit tags, the engine itself, or something strange with my computer. The following ships were given the rocking code; they are listed in roughly increasing order of severity of jamming:

  • Destroyers. I have never seen a destroyer jam.
  • Battleships. Once I got an Arm battleship to jam, but I have not been able to do it again.
  • Black Hydra (main cannon only). About 40% that I saw jammed in RAI battles.
  • Epoch. Technically, an individual weapon on the Epoch jams about as often as the Black Hydra's main cannon. However, the Epoch has more cannons. Generally about 30% of the cannons jammed in RAI battles.
  • Arm Cruiser (main cannon only). This jams fairly frequently; in RAI battles I saw many cruisers jam, although it may seem more common than they actually are due to the larger number of cruisers.
  • Strategic Plasma Cannon Ships. These ships are especially sensitive to the range to the target. Close to 50% jammed in RAI battles IIRC.

The following diagram shows the approximate areas in which the ships weapons will jam, for ships that are facing directly toward the bottom and not turning. The red circles represent the ship's maximum range and the green circles represent areas where the ship will not jam when fired at.

For Players

To get around this bug as a player, try the following:

  • If a weapon jams, wait for it to restore itself to facing forwards and try again.
  • Try to face your ships toward their targets until they fire at least once.
  • Fire your ships' weapons directly in front of themselves before sending them into actual combat.

Relevant Files

Headers

Units

Attachments