……..Having left this interval, he drew two trenches fifteen feet broad, and of the same depth; the innermost of them, being in low and level ground, he filled with water conveyed from the river. Behind these he raised a rampart and wall twelve feet high; to this he added a parapet and battlements, with large stakes cut like stags' horns, projecting from the junction of the parapet and battlements, to prevent the enemy from scaling it, and surrounded the entire work with turrets, which were eighty feet distant from one another.
Killing at range
While it is possible to use slings and even bows at this range, the significance of setting an outer perimeter 400’ probably reflects the effective range of artillery set in turrets and towers.
Whites of their eyes.
The principle weapon in this type of fighting would be the spear, javelin, or more specifically the Pilum; unlike a bow, it can be used with one hand, and from behind a shield.
At about 80’ the defenders could launch the first volley of pila with the considerable advantage of 12’ or more of additional height. At this range, even if it did not kill, the hardened point of pilum range could piece shields, and then softer shank would bend rendering the weapon and the shield useless [below right]. This effect is described in a battle by Caesar.
His soldiers hurling their javelins from the higher ground, easily broke the enemy's phalanx. That being dispersed, they made a charge on them with drawn swords. It was a great hindrance to the Gauls in fighting, that, when several of their bucklers had been by one stroke of the (Roman) javelins pierced through and pinned fast together, as the point of the iron had bent itself, they could neither pluck it out, nor, with their left hand entangled, fight with sufficient ease; so that many, after having long tossed their arm about, chose rather to cast away the buckler from their hand, and to fight with their person unprotected.
Above left; An attacker in the ditch as viewed from a 24' tower.
This tactic of counter-attacking was not necessarily the last resort, ramparts offer concealment, in the sense that may be difficult for the attacker to perceive the dissolution of forces, and from that, their intent. Building a rampart my look like a defensive posture, but may in fact be an elaborate ruse to get the enemy into a position where they can be caught in just such a counter attack. 
References and further reading
 C. Julius Caesar. Caesar's Gallic War. Translator. W. A. McDevitte. Translator. W. S. Bohn. 1st Edition. New York. Harper & Brothers. 1869. Harper's New Classical Library.
 Birley, R. 2009 Vindolanda: A Roman Frontier Fort on Hadrian’s Wall. Amberley; Plate 1; Turf Wall reconstruction.