Battle Analysis

Commands

Mouse down events are processed into a wargame command.

The wargame mode and wargame status is checked to create a command.

For example, during the moving mode of the movement phase:


	CommandGenerator.prototype.moveEvent = function(objectType, unitIndex, hexagonPoint) {

		if (objectType == "map") {  // note: unitIndex will be -1
			// this.moveRules.movingUnitIndex could be a moving unit or a reinforcing unit, so check it
			if (this.moveRules.unitsAreMoving()) {
				// click on map, so try to move
				//if (this.wargameRules.unitIsMoving(this.moveRules.movingUnitIndex) == true) {
					this.moveRules.move(hexagonPoint);
				//}
			}
			if (this.moveRules.unitsAreReinforcing() && this.moveRules.canReinforceDuringMovePhaseRule == true) {
				this.moveRules.reinforce(hexagonPoint);
			}
		}
		else {
			// click on a unit
			if (this.moveRules.unitsAreMoving() == false) {
				// no one is moving, so start new move
				if (this.wargameRules.unitCanMove(unitIndex) == true) {
					this.moveRules.startMoving(unitIndex);
				}
				if ( this.wargameRules.unitCanReinforce(unitIndex) == true && this.moveRules.canReinforceDuringMovePhaseRule == true ) {
					this.moveRules.startReinforcing(unitIndex);
				}
			}
			else {
				// clicked on moving
				if (this.wargameRules.unitIsMoving(unitIndex) == true) {
					this.moveRules.stopMoving(unitIndex); // Note: if stacking mode is enabled, function will pop counter on stack instead of stop
				}
				else {
					if (this.wargameRules.unitIsReinforcing(unitIndex) == true) {
						this.moveRules.stopReinforcing(unitIndex);
					}
					else {
					// clicked on another unit in another hexagon
						var currentMovingHexagonPoint = this.moveRules.getCurrentMovingHexagonPoint();
						if(currentMovingHexagonPoint.equals(hexagonPoint)){
							this.moveRules.moveOver(unitIndex);
						}
					}
				}
			}
		}
	}