;
;   This file describes the unit group formation templates, any number of group formations can be specified
;   these templates are used to give a group of units a formation, the units available  in the group may not
;   totally fit the template in which case a best-fit is determined when the formation is created
;
;   Formation block positions can either be specified with a relative normalised (x,z) or they can be specified
;   relative to another formation block (when specifying in this manner rotation CANNOT be given)
;   a formation must be described entirely in one method or the other
;
;
;   formation                       the name given to this formation template
;
;   formation purposes              hints to ai for using this formation
;
;   ai_priority                     hint to the ai, denotes priority of using this template
;
;   BLOCK SPEC
;
;   min_units <VALUE>               minimum number of units block can have
;   max_units <VALUE>               maximum number of units block can have
;   not_general                     this block cannot contain the general unit
;   unit_type                       specifies units that can be allocated to the block
;                                   either : -
;                                               any
;                                               phalanx
;                                               non_phalanx_spear
;                                               chanting_screeching
;                                               ranged_missile_infantry
;                                               elephants
;                                               heavy_chariots
;                                               pilum_infantry
;                                               general_unit
;                                               <UNIT_CLASS> <UNIT_CATEGORY> <PRIORITY>
;                                   the priority dictates the order of assigning different unit types
;                                   a priority of zero means that type will only ever be assigned to this block
;                                   to fulfill block minimums
;   default_melee_state <OPTIONAL>  the melee state that will be assigned to units
;                                   in the formation
;   unit_formation                  the formation the units within this block will be in (wedge, square, ...)
;   unit_density                    either loose or close
;	min_unit_width					minimum unit width in men
;	max_unit_width					maximum unit width in men
;   block_formation                 the formation to organise the block into    (square, column, line)
;   normalised_pos                  (x,z) position relative to the center of the template (in normalised coords)
;   normalised_rot                  rotation in degress relative to the orientation of the template
;   block_relative_pos              b x z (x,z) position (in metres) relative to formation block b
;   inter_unit_spacing              distance to space units (in metres)
;   priority                        dictates the order in which units are assigned to the block


;****************************************************************
; OS26G:Triple Line. Missile troops in front, foot, in second row
; mounted in third row
;****************************************************************
begin_formation ai_triple_missiles_in_front
    ;;; purpose flags
    defend									
    attack
    ai_priority     0.20

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;; the missile units
    begin_block 0
        max_units               6
        unit_type               missile infantry    1.0
        unit_density            close
		min_unit_width			30
		max_unit_width			30
        block_formation         line
        block_relative_pos      0 0.0 0.0
        inter_unit_spacing      3.0
        priority                1.0
    end_block
    begin_block 1
        max_units               6
        unit_type               missile infantry    1.0
        unit_density            close
		min_unit_width			30
		max_unit_width			30
        block_formation         line
        block_relative_pos      0 0.0 -2.0
        inter_unit_spacing      3.0
        priority                0.9
    end_block
    begin_block 2
        max_units               6
        unit_type               missile infantry    1.0
        ;unit_density            close
		min_unit_width			30
		max_unit_width			30
        block_formation         line
        block_relative_pos      1 0.0 -2.0
        inter_unit_spacing      3.0
        priority                0.8
    end_block
    begin_block 3
        max_units               6
        unit_type               missile infantry    1.0
        unit_density            close
		min_unit_width			30
		max_unit_width			30
        block_formation         line
        block_relative_pos      2 0.0 -2.0
        inter_unit_spacing      3.0
        priority                0.7
    end_block
    begin_dummy_block 4
        spans 0 1 2 3
    end_dummy_block

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;; the infantry units
    begin_block 5
        max_units               6
        unit_type               heavy infantry      1.0
        unit_type               spearmen infantry   0.9
        unit_type               skirmish infantry   0.8
        unit_type               light infantry      0.7
        unit_density            close
		min_unit_width			20
		max_unit_width			20
        block_formation         line
        block_relative_pos      4 0.0 -5.0
        inter_unit_spacing      0.0
        priority                1.0
    end_block
    begin_block 6
        max_units               6
        unit_type               heavy infantry      1.0
        unit_type               spearmen infantry   0.9
        unit_type               skirmish infantry   0.8
        unit_type               light infantry      0.7
        unit_density            close
		min_unit_width			20
		max_unit_width			20
        block_formation         line
        block_relative_pos      5 0.0 -2.5
        inter_unit_spacing      0.0
        priority                0.9
    end_block
    begin_block 7
        max_units               6
        unit_type               heavy infantry      1.0
        unit_type               spearmen infantry   0.9
        unit_type               skirmish infantry   0.8
        unit_type               light infantry      0.7
        unit_density            close
		min_unit_width			20
		max_unit_width			20
        block_formation         line
        block_relative_pos      6 0.0 -1.5
        inter_unit_spacing      0.0
        priority                0.8
    end_block
    begin_block 8
        max_units               6
        unit_type               heavy infantry      1.0
        unit_type               spearmen infantry   0.9
        unit_type               skirmish infantry   0.8
        unit_type               light infantry      0.7
        unit_density            close
		min_unit_width			20
		max_unit_width			20
        block_formation         line
        block_relative_pos      7 0.0 -1.0
        inter_unit_spacing      0.0
        priority                0.7
    end_block
    begin_dummy_block 9
        spans 5 6 7 8
    end_dummy_block

    begin_dummy_block 10
        spans 4 9
    end_dummy_block

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;; missile cavalry

    begin_block 11
        unit_type               missile cavalry 1.0
        unit_density            close
		min_unit_width			30
		max_unit_width			30
        block_formation         line
        block_relative_pos      10 100.0 0.0
        inter_unit_spacing      3.0
        priority                1.0
    end_block
    begin_block 12
        unit_type               missile cavalry 1.0
        unit_density            close
		min_unit_width			30
		max_unit_width			30
        block_formation         line
        block_relative_pos      10 -100.0 0.0
        inter_unit_spacing      3.0
        priority                1.0
    end_block

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;; cavalry

    begin_block 13
        max_units               6
        unit_type               heavy cavalry      1.0
        unit_type               spearmen cavalry   0.9
        unit_type               skirmish cavalry   0.8
        unit_type               light cavalry      0.7
        unit_density            close
		min_unit_width			20
		max_unit_width			20
        block_formation         line
        block_relative_pos      10 0.0 -2.5
        inter_unit_spacing      0.0
        priority                1.0
    end_block
    begin_block 14
        max_units               6
        unit_type               heavy cavalry      1.0
        unit_type               spearmen cavalry   0.9
        unit_type               skirmish cavalry   0.8
        unit_type               light cavalry      0.7
        unit_density            close
		min_unit_width			20
		max_unit_width			20
        block_formation         line
        block_relative_pos      13 0.0 -1.0
        inter_unit_spacing      0.0
        priority                0.9
    end_block
    begin_block 15
        max_units               6
        unit_type               heavy cavalry      1.0
        unit_type               spearmen cavalry   0.9
        unit_type               skirmish cavalry   0.8
        unit_type               light cavalry      0.7
        unit_density            close
		min_unit_width			20
		max_unit_width			20
        block_formation         line
        block_relative_pos      14 0.0 -1.0
        inter_unit_spacing      0.0
        priority                0.8
    end_block
    begin_block 16
        max_units               6
        unit_type               heavy cavalry      1.0
        unit_type               spearmen cavalry   0.9
        unit_type               skirmish cavalry   0.8
        unit_type               light cavalry      0.7
        unit_density            close
        block_formation         line
        block_relative_pos      15 0.0 -1.0
        inter_unit_spacing      0.0
        priority                0.7
    end_block
    begin_dummy_block 17
        spans 13 14 15 16
    end_dummy_block

    begin_dummy_block 18
        spans 10 17
    end_dummy_block

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    ;; put the artillery and handlers behind everyone

    begin_block 19
        unit_type                   handler             1.0
        unit_type                   siege               1.0
        block_formation             line
        block_relative_pos          18 0.0 -5.0
        inter_unit_spacing          5.0
        priority                    1.0
    end_block

    ;;; special general block
    begin_block 20
        min_units               1
        max_units               1
        unit_type               general_unit            1.0
        unit_density            close
        block_formation         line
        block_relative_pos      19 0 -5.0
        inter_unit_spacing      25.0
        priority                1.0
    end_block

    main_line 9

end_formation

begin_formation ai_triple_missiles_in_front_easy

    ;;; purpose flags
    defend									
    attack
    ai_priority     0.10

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;; the missile units
    begin_block 0
        max_units               10
        unit_type               missile infantry    1.0
        unit_density            close
		min_unit_width			30
		max_unit_width			30
        block_formation         line
        block_relative_pos      0 0.0 0.0
        inter_unit_spacing      3.0
        priority                1.0
    end_block
    begin_block 1
        max_units               10
        unit_type               missile infantry    1.0
        unit_density            close
		min_unit_width			30
		max_unit_width			30
        block_formation         line
        block_relative_pos      0 0.0 -2.0
        inter_unit_spacing      3.0
        priority                0.9
    end_block
    begin_block 2
        max_units               10
        unit_type               missile infantry    1.0
        unit_density            close
		min_unit_width			30
		max_unit_width			30
        block_formation         line
        block_relative_pos      1 0.0 -2.0
        inter_unit_spacing      3.0
        priority                0.8
    end_block
    begin_block 3
        max_units               10
        unit_type               missile infantry    1.0
        unit_density            close
		min_unit_width			30
		max_unit_width			30
        block_formation         line
        block_relative_pos      2 0.0 -2.0
        inter_unit_spacing      3.0
        priority                0.7
    end_block
    begin_dummy_block 4
        spans 0 1 2 3
    end_dummy_block

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;; the infantry units
    begin_block 5
        max_units               10
        unit_type               heavy infantry      1.0
        unit_type               spearmen infantry   0.9
        unit_type               skirmish infantry   0.8
        unit_type               light infantry      0.7
        unit_density            close
		min_unit_width			20
		max_unit_width			20
        block_formation         line
        block_relative_pos      4 0.0 -5.0
        inter_unit_spacing      1.0
        priority                1.0
    end_block
    begin_block 6
        max_units               10
        unit_type               heavy infantry      1.0
        unit_type               spearmen infantry   0.9
        unit_type               skirmish infantry   0.8
        unit_type               light infantry      0.7
        unit_density            close
		min_unit_width			20
		max_unit_width			20
        block_formation         line
        block_relative_pos      5 0.0 -2.5
        inter_unit_spacing      1.0
        priority                0.9
    end_block
    begin_block 7
        max_units               10
        unit_type               heavy infantry      1.0
        unit_type               spearmen infantry   0.9
        unit_type               skirmish infantry   0.8
        unit_type               light infantry      0.7
        unit_density            close
		min_unit_width			20
		max_unit_width			20
        block_formation         line
        block_relative_pos      6 0.0 -1.5
        inter_unit_spacing      1.0
        priority                0.8
    end_block
    begin_block 8
        max_units               10
        unit_type               heavy infantry      1.0
        unit_type               spearmen infantry   0.9
        unit_type               skirmish infantry   0.8
        unit_type               light infantry      0.7
        unit_density            close
		min_unit_width			20
		max_unit_width			20
        block_formation         line
        block_relative_pos      7 0.0 -1.0
        inter_unit_spacing      1.0
        priority                0.7
    end_block
    begin_dummy_block 9
        spans 5 6 7 8
    end_dummy_block

    begin_dummy_block 10
        spans 4 9
    end_dummy_block

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;; missile cavalry

    begin_block 11
        unit_type               missile cavalry 1.0
        unit_density            close
		min_unit_width			30
		max_unit_width			30
        block_formation         line
        block_relative_pos      10 20.0 0.0
        inter_unit_spacing      3.0
        priority                1.0
    end_block
    begin_block 12
        unit_type               missile cavalry 1.0
        unit_density            close
		min_unit_width			30
		max_unit_width			30
        block_formation         line
        block_relative_pos      10 -20.0 0.0
        inter_unit_spacing      3.0
        priority                1.0
    end_block

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;; cavalry

    begin_block 13
        max_units               10
        unit_type               heavy cavalry      1.0
        unit_type               spearmen cavalry   0.9
        unit_type               skirmish cavalry   0.8
        unit_type               light cavalry      0.7
        unit_density            close
		min_unit_width			20
		max_unit_width			20
        block_formation         line
        block_relative_pos      10 0.0 -2.5
        inter_unit_spacing      0.0
        priority                1.0
    end_block
    begin_block 14
        max_units               10
        unit_type               heavy cavalry      1.0
        unit_type               spearmen cavalry   0.9
        unit_type               skirmish cavalry   0.8
        unit_type               light cavalry      0.7
        unit_density            close
		min_unit_width			20
		max_unit_width			20
        block_formation         line
        block_relative_pos      13 0.0 -1.0
        inter_unit_spacing      0.0
        priority                0.9
    end_block
    begin_block 15
        max_units               10
        unit_type               heavy cavalry      1.0
        unit_type               spearmen cavalry   0.9
        unit_type               skirmish cavalry   0.8
        unit_type               light cavalry      0.7
        unit_density            close
		min_unit_width			20
		max_unit_width			20
        block_formation         line
        block_relative_pos      14 0.0 -1.0
        inter_unit_spacing      0.0
        priority                0.8
    end_block
    begin_block 16
        max_units               10
        unit_type               heavy cavalry      1.0
        unit_type               spearmen cavalry   0.9
        unit_type               skirmish cavalry   0.8
        unit_type               light cavalry      0.7
        unit_density            close
        block_formation         line
        block_relative_pos      15 0.0 -1.0
        inter_unit_spacing      0.0
        priority                0.7
    end_block
    begin_dummy_block 17
        spans 13 14 15 16
    end_dummy_block

    begin_dummy_block 18
        spans 10 17
    end_dummy_block

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    ;; put the artillery and handlers behind everyone

    begin_block 19
        unit_type                   handler             1.0
        unit_type                   siege               1.0
        block_formation             line
        block_relative_pos          18 0.0 -5.0
        inter_unit_spacing          5.0
        priority                    1.0
    end_block

    ;;; special general block
    begin_block 20
        min_units               1
        max_units               1
        unit_type               general_unit            1.0
        unit_density            close
        block_formation         line
        block_relative_pos      19 0 -5.0
        inter_unit_spacing      20.0
        priority                1.0
    end_block

    main_line 5

end_formation

;****************************************************************
; Bridge assault column
;****************************************************************
begin_formation ai_crossing_assault_force

    ;;; purpose flags
    crossing_assault_force
    ai_priority                 1

    ;;; front block
    begin_block 0
        min_units               1
        max_units				3
        not_general
        unit_type               heavy infantry      1.0
        unit_density            close
        max_unit_width          40
        block_formation         column
        block_relative_pos      0 0.0 0.0
        inter_unit_spacing      2.0
        priority                0.9
    end_block

    ;;; behind
    begin_block 1
        max_units               2
        not_general
        unit_type               heavy infantry      1.0
        unit_type               light infantry      0.9
        unit_type               heavy cavalry       0.7
        unit_type               light cavalry       0.7
        unit_type               skirmish cavalry    0.7
        unit_type               heavy infantry      0.6
        unit_type               light infantry      0.6
        unit_type               skirmish infantry   0.6
        unit_type               any                 0.1
        unit_density            close
        max_unit_width          20
        block_formation         column
        block_relative_pos      0 0.0 -2.0
        inter_unit_spacing      2.0
        priority                0.8

    end_block

    ;;; further behind
    begin_block 2
        max_units               3
        not_general
        unit_type               light infantry      0.9
        unit_type               heavy cavalry       0.7
        unit_type               light cavalry       0.7
        unit_type               skirmish cavalry    0.7
        unit_type               missile cavalry     0.7
        unit_type               heavy infantry      0.6
        unit_type               light infantry      0.6
        unit_type               skirmish infantry   0.6
        unit_type               any                 0.1
        unit_density            close
        max_unit_width          20
        block_formation         column
        block_relative_pos      1 0.0 -2.0
        inter_unit_spacing      2.0
        priority                0.6
    end_block

    ;;; main body of units (everything else)
    begin_block 3
        unit_type               any                 1.0
        unit_density            close
        block_formation         column
        block_relative_pos      2 0.0 -8.0
        inter_unit_spacing      2.0
        priority                0.4
    end_block

    ;;; if we have any swimming units put them on the flanks so they can swim over
    ;;; and increase our attacking bandwidth
    begin_dummy_block 4
        spans 0 1 2 3
    end_dummy_block

    begin_block 5
        ;;; at the moment all swimming units have to swim   max_units               2
        not_general
        unit_type               swimming            1.0
        unit_density            close
        block_formation         line
        block_relative_pos      4 -10.0 0
        inter_unit_spacing      2.0
        priority                1.0
    end_block

    begin_block 6
   		not_general
        unit_type               swimming            1.0
        unit_density            close
        block_formation         line
        block_relative_pos      4 10.0 0
        inter_unit_spacing      2.0
        priority                1.0
    end_block

end_formation


;****************************************************************
; Bridge assault crossing buffer
;****************************************************************

begin_formation ai_crossing_assault_buffer
	
	;;; purpose flags
	crossing_assault_buffer
	ai_priority 1
	
	begin_block 0
        unit_type               heavy infantry      1.0
        unit_type               light infantry      0.9
        unit_type               missile infantry	0.4
        unit_type               missile cavalry		0.3
        unit_density			close
		max_unit_width			20
        block_formation			line
        normalised_pos			0.5		1.0
        normalised_rot			0
        inter_unit_spacing		2.0
        priority				1.0
	end_block
	
	begin_block 1
        unit_type               heavy infantry      1.0
        unit_type               light infantry      0.8
        unit_type               missile infantry	0.4
        unit_type               missile cavalry		0.3
        unit_density			close
		max_unit_width			20
        block_formation			line
        normalised_pos			0.8125	0.75
        normalised_rot			45
        inter_unit_spacing		2.0
        priority				0.5
	end_block
	
	begin_block 2
        unit_type               heavy infantry      1.0
        unit_type               light infantry      0.8
        unit_type               missile infantry	0.4
        unit_type               missile cavalry		0.3
        unit_density			close
		max_unit_width			20
        block_formation			line
        normalised_pos			0.1875	0.75
        normalised_rot			315
        inter_unit_spacing		2.0
        priority				0.5
	end_block
	
	begin_block 3
        unit_type               heavy infantry      1.0
        unit_type               light infantry      0.8
        unit_density			close
		max_unit_width			20
        block_formation			line
        normalised_pos			1.0		0.25
        normalised_rot			75
        inter_unit_spacing		2.0
        priority				0.2
	end_block
	
	begin_block 4
        unit_type               heavy infantry      1.0
        unit_type               light infantry      0.8
        unit_density			close
		max_unit_width			20
        block_formation			line
        normalised_pos			0.0		0.25
        normalised_rot			285
        inter_unit_spacing		2.0
        priority				0.2
	end_block
	
	begin_block 5
        unit_type               any					0.1
        unit_density			close
		max_unit_width			20
        block_formation			column
        normalised_pos			0.5		0.0
        normalised_rot			0
        inter_unit_spacing		2.0
        priority				0.1
	end_block
	
end_formation

;****************************************************************
; Bridge assault cover force
;****************************************************************
begin_formation ai_crossing_assault_cover

    crossing_assault_cover
    ai_priority                 1

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;; the missile units
    begin_dummy_block 0                                         ;; centre slot left empty for assault column to pass through
        spacer 0.0 0.0 30 20
    end_dummy_block
    
    begin_block 1
        max_units               1
        not_general
        unit_type               missile infantry    1.0
        unit_type               missile cavalry    	0.8
        unit_density            close
		min_unit_width			30
		max_unit_width			30
        block_formation         line
        block_relative_pos      0 1.0 0.0
        inter_unit_spacing      1.0
        priority                1.0
    end_block
    begin_block 2
        max_units               1
        not_general
        unit_type               missile infantry    1.0
        unit_type               missile cavalry    	0.8
        unit_density            close
		min_unit_width			30
		max_unit_width			30
        block_formation         line
        block_relative_pos      0 -1.0 0.0 
        inter_unit_spacing      1.0
        priority                1.0
    end_block
    begin_block 3
        max_units               1
        not_general
        unit_type               missile infantry    1.0
        unit_type               missile cavalry    	0.8
        unit_density            close
		min_unit_width			30
		max_unit_width			30
        block_formation         line
        block_relative_pos      1 1.0 0.0
        inter_unit_spacing      1.0
        priority                0.8
    end_block
    begin_block 4
        max_units               1
        not_general
        unit_type               missile infantry    1.0
        unit_type               missile cavalry    	0.8
        unit_density            close
		min_unit_width			30
		max_unit_width			30
        block_formation         line
        block_relative_pos      2 -1.0 0.0
        inter_unit_spacing      1.0
        priority                0.8
    end_block
    
    begin_block 5
        max_units               3
        not_general
        unit_type               missile infantry    1.0
        unit_type               siege               0.9
        unit_type               missile cavalry    	0.8
        unit_density            close
		min_unit_width			30
		max_unit_width			30
        block_formation         line
        block_relative_pos      1 0.0 -3.0
        inter_unit_spacing      1.0
        priority                1.0
    end_block
    begin_block 6
        max_units               3
        not_general
        unit_type               missile infantry    1.0
        unit_type               siege               0.9
        unit_type               missile cavalry    	0.8
        unit_density            close
		min_unit_width			30
		max_unit_width			30
        block_formation         line
        block_relative_pos      2 0.0 -3.0 
        inter_unit_spacing      1.0
        priority                1.0
    end_block
    begin_dummy_block 7
        spans 0 1 2 3 4 5 6
    end_dummy_block

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    ;;; special general block
    begin_block 8
        max_units               1
        unit_type               general_unit            1.0
        unit_type				any						0.1	
        unit_density            close
        block_formation         line
        block_relative_pos      7 0 -5.0
        inter_unit_spacing      1.0
        priority                1.0
    end_block

end_formation


;****************************************************************
; Crossing Block
; For blocking a crossing against a cavalry heavy opponent
; Semicircular formation around end of crossing
;****************************************************************
begin_formation ai_crossing_block_cavalry

    crossing_block
    anti_cavalry
    ai_priority                 1

    ;; forward missile units
    begin_block 0
        max_units               2
        unit_type               missile infantry    1.0
        unit_density            close
		min_unit_width			30
		max_unit_width			60
        block_formation         line
        block_relative_pos      0 0.0 0.0
        inter_unit_spacing      3.0
        priority                1.0
    end_block
    begin_block 1
        max_units               6
        unit_type               missile infantry    1.0
        unit_density            close
		min_unit_width			30
		max_unit_width			60
        block_formation         line
        block_relative_pos      0 1.0 0.0
        inter_unit_spacing      3.0
        priority                0.8
    end_block
    begin_block 2
        max_units               6
        unit_type               missile infantry    1.0
        unit_density            close
		min_unit_width			30
		max_unit_width			60
        block_formation         line
        block_relative_pos      0 -1.0 0.0 
        inter_unit_spacing      3.0
        priority                0.8
    end_block
    begin_dummy_block 3
        spans 0 1 2
    end_dummy_block

    ;; forward melee units
    begin_block 4
        max_units               4
        unit_type               		spearmen infantry		1.0
        unit_type				heavy infantry			0.8
        unit_type				light infantry			0.4
        unit_density            close
		min_unit_width			20
		max_unit_width			20
        block_formation         line
        block_relative_pos      3 0.0 -3.0
        inter_unit_spacing      1.0
        priority                0.6
    end_block
    begin_block 5
        max_units               6
        unit_type				heavy infantry			1.0
        unit_type               		spearmen infantry		0.8
        unit_type				light infantry			0.4
        unit_density            close
		min_unit_width			20
		max_unit_width			20
        block_formation         line
        block_relative_pos      4 0.0 -2.0
        inter_unit_spacing      1.0
        priority                0.4
    end_block
    begin_block 6
        max_units               6
        unit_type				heavy cavalry			1.0
        unit_type               		light cavalry			0.8
        unit_density            close
		min_unit_width			20
		max_unit_width			20
        block_formation         line
        block_relative_pos      5 0.0 -3.0 
        inter_unit_spacing      1.0
        priority                0.4
    end_block
    begin_dummy_block 7
        spans 4 5 6
    end_dummy_block

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    ;;; special general block
    begin_block 8
        min_units               1
        max_units               1
        unit_type               general_unit            1.0
        unit_density            close
        block_formation         line
        block_relative_pos      7 0 -3.0
        inter_unit_spacing      1.0
        priority                1.0
    end_block

    ;; put the artillery and handlers behind everyone

    begin_block 9
        unit_type                   any             	0.6
        unit_type                   siege               1.0
        block_formation             line
        block_relative_pos          8 0.0 -5.0
        inter_unit_spacing          3.0
        priority                    0.1
    end_block

end_formation


;****************************************************************
; Crossing Block
; For blocking a crossing against a infantry heavy opponent
;****************************************************************
begin_formation ai_crossing_block_infantry

    crossing_block
    anti_infantry
    ai_priority                 1

    ;; forward missile units
    begin_block 0
        max_units               2
        unit_type               missile infantry    1.0
        unit_density            close
		min_unit_width			30
		max_unit_width			60
        block_formation         line
        block_relative_pos      0 0.0 0.0
        inter_unit_spacing      3.0
        priority                1.0
    end_block
    begin_block 1
        max_units               6
        unit_type               missile infantry    1.0
        unit_density            close
		min_unit_width			30
		max_unit_width			60
        block_formation         line
        block_relative_pos      0 1.0 0.0
        inter_unit_spacing      3.0
        priority                0.8
    end_block
    begin_block 2
        max_units               6
        unit_type               missile infantry    1.0
        unit_density            close
		min_unit_width			30
		max_unit_width			60
        block_formation         line
        block_relative_pos      0 -1.0 0.0 
        inter_unit_spacing      3.0
        priority                0.8
    end_block
    begin_dummy_block 3
        spans 0 1 2
    end_dummy_block

    ;; forward melee units
    begin_block 4
        max_units               4
        unit_type				heavy infantry			1.0
        unit_type               		spearmen infantry		0.8
        unit_type				light infantry			0.4
        unit_density            close
		min_unit_width			20
		max_unit_width			20
        block_formation         line
        block_relative_pos      3 0.0 -3.0
        inter_unit_spacing      1.0
        priority                0.6
    end_block
    begin_block 5
        max_units               6
        unit_type				heavy infantry			1.0
        unit_type               		spearmen infantry		0.8
        unit_type				light infantry			0.4
        unit_density            close
		min_unit_width			20
		max_unit_width			20
        block_formation         line
        block_relative_pos      4 0.0 -2.0
        inter_unit_spacing      1.0
        priority                0.4
    end_block
    begin_block 6
        max_units               6
        unit_type				heavy cavalry			1.0
        unit_type               		light cavalry			0.8
        unit_density            close
		min_unit_width			20
		max_unit_width			20
        block_formation         line
        block_relative_pos      5 0.0 -3.0 
        inter_unit_spacing      1.0
        priority                0.4
    end_block
    begin_dummy_block 7
        spans 4 5 6
    end_dummy_block

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    ;;; special general block
    begin_block 8
        min_units               1
        max_units               1
        unit_type               general_unit            1.0
        unit_density            close
        block_formation         line
        block_relative_pos      7 0 -3.0
        inter_unit_spacing      1.0
        priority                1.0
    end_block

    ;; put the artillery and handlers behind everyone

    begin_block 9
        unit_type                   any             	0.6
        unit_type                   siege               1.0
        block_formation             line
        block_relative_pos          8 0.0 -5.0
        inter_unit_spacing          3.0
        priority                    0.1
    end_block

end_formation




;****************************************************************
; Crossing Defend
; For defending a crossing when the odds are against us
; This variant is targetted towards a cavalry heavy opponent
;****************************************************************
begin_formation ai_crossing_defend_cavalry

    crossing_defend
    anti_cavalry
    ai_priority                 1
    
    ;; forward missile units
    begin_block 0
        max_units               2
        unit_type               missile infantry    1.0
        unit_type               missile cavalry    	0.8
        unit_density            close
		min_unit_width			30
		max_unit_width			30
        block_formation         line
        block_relative_pos      0 0.0 0.0
        inter_unit_spacing      3.0
        priority                1.0
    end_block
    begin_block 1
        max_units               6
        unit_type               missile infantry    1.0
        unit_type               missile cavalry    	0.8
        unit_density            close
		min_unit_width			30
		max_unit_width			30
        block_formation         line
        block_relative_pos      0 1.0 0.0
        inter_unit_spacing      3.0
        priority                0.8
    end_block
    begin_block 2
        max_units               6
        unit_type               missile infantry    1.0
        unit_type               missile cavalry    	0.8
        unit_density            close
		min_unit_width			30
		max_unit_width			30
        block_formation         line
        block_relative_pos      0 -1.0 0.0 
        inter_unit_spacing      3.0
        priority                0.8
    end_block
    begin_dummy_block 3
        spans 0 1 2
    end_dummy_block

    ;; forward melee units
    begin_block 4
        max_units               2
        unit_type               spearmen infantry		1.0
        unit_type				heavy infantry			0.8
        unit_type				light infantry			0.4
        unit_density            close
		min_unit_width			30
		max_unit_width			30
        block_formation         line
        block_relative_pos      3 0.0 -3.0
        inter_unit_spacing      1.0
        priority                0.6
    end_block
    begin_block 5
        max_units               6
        unit_type               spearmen infantry		1.0
        unit_type				heavy infantry			0.8
        unit_type				light infantry			0.4
        unit_density            close
		min_unit_width			30
		max_unit_width			30
        block_formation         line
        block_relative_pos      4 1.0 0.0
        inter_unit_spacing      1.0
        priority                0.4
    end_block
    begin_block 6
        max_units               6
        unit_type               spearmen infantry		1.0
        unit_type				heavy infantry			0.8
        unit_type				light infantry			0.4
        unit_density            close
		min_unit_width			30
		max_unit_width			30
        block_formation         line
        block_relative_pos      4 -1.0 0.0 
        inter_unit_spacing      1.0
        priority                0.4
    end_block
    begin_dummy_block 7
        spans 4 5 6
    end_dummy_block

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    ;; put the artillery and handlers behind everyone

    begin_block 8
        unit_type                   any             	1.0
        unit_type                   siege               1.0
        block_formation             line
        block_relative_pos          7 0.0 -5.0
        inter_unit_spacing          1.0
        priority                    0.1
    end_block

    ;;; special general block
    begin_block 9
        min_units               1
        max_units               1
        unit_type               general_unit            1.0
        unit_density            close
        block_formation         line
        block_relative_pos      8 0 -5.0
        inter_unit_spacing      1.0
        priority                1.0
    end_block

end_formation




;****************************************************************
; Crossing Defend
; For defending a crossing when the odds are against us
; This variant is targetted towards an infantry heavy opponent
;****************************************************************
begin_formation ai_crossing_defend_infantry

    crossing_defend
    anti_infantry
    ai_priority                 1

    ;;; missile units in the centre
    begin_block 0
        max_units               3
        unit_type               missile infantry                1.0
        unit_type               missile cavalry                 0.8
        unit_density            close
        block_formation         line
        block_relative_pos      0 0.0 0.0
        inter_unit_spacing      2.0
        priority                1
    end_block

    ;;; protective shield of heavy infantry for the missile troops
    begin_block 1
        max_units               3
        unit_type               heavy infantry                  1.0
        unit_type               heavy cavalry                   0.9
        unit_type               light infantry                  0.7
        unit_type               light cavalry                   0.6
        unit_density            close
        block_formation         line
        block_relative_pos      0 0.0 15.0
        inter_unit_spacing      2.0
        priority                1.0
    end_block

    ;;; close support melee for shooters left flank
    begin_block 2
        max_units               2
        unit_type               heavy infantry                  1.0
        unit_type               light infantry                  0.7
        unit_type               skirmish infantry               0.7
        unit_type               heavy cavalry                   0.7
        unit_type               light cavalry                   0.7
        unit_type               skirmish cavalry                0.7
        block_formation         line
        block_relative_pos      1 -0.5 -7.0
        inter_unit_spacing      2.0
        priority                0.9
    end_block

    ;;; close support melee for shooters right flank
    begin_block 3
        max_units               2
        unit_type               heavy infantry                  1.0
        unit_type               light infantry                  0.7
        unit_type               skirmish infantry               0.7
        unit_type               heavy cavalry                   0.7
        unit_type               light cavalry                   0.7
        unit_type               skirmish cavalry                0.7
        block_formation         line
        block_relative_pos      1 0.5 -7.0
        inter_unit_spacing      2.0
        priority                0.9
    end_block

    ;;; fast moving left side outflankers
    begin_block 4
        max_units               2
        unit_type               heavy cavalry                   0.7
        unit_type               light cavalry                   0.7
        unit_type               skirmish cavalry                0.7
        block_formation         line
        block_relative_pos      0 -10.0 1.0
        inter_unit_spacing      2.0
        priority                0.6
    end_block

    ;;; melee troops to left of flank shooters
    begin_block 5
        max_units               2
        unit_type               heavy cavalry                   1.0
        unit_type               light cavalry                   0.7
        unit_type               skirmish cavalry                0.7
        block_formation         line
        block_relative_pos      0 10.0 1.0
        inter_unit_spacing      2.0
        priority                0.6
    end_block

    ;;; everyone else in the second line
    begin_block 6
        unit_type               any                             1.0
        block_formation         line
        block_relative_pos      0 0.0 -10.0
        inter_unit_spacing      2.0
        priority                0.1
    end_block

end_formation




;****************************************************************
; Wall Assault
; Siege engine in the centre, covering troops on the flanks
; other units in a column behind, waiting to go up the siege tower
;****************************************************************
begin_formation ai_wall_assault

    wall_assault_force
    ai_priority                 1

    ;;; gap for siege engines in the centre
    begin_dummy_block 0                                         ;; centre slot left empty for assault column to pass through
        spacer 0.0 0.0 15 10
    end_dummy_block

;    ;;; archers to the left of siege engine
;    begin_block 1
;        unit_type               missile infantry                1.0
;        unit_type               missile cavalry                 0.8
;        unit_type               heavy infantry                  0.1
;        unit_type               any                             0.0
;        unit_density            close
;        block_formation         column
;        block_relative_pos      0 -5.0 0.0
;        inter_unit_spacing      0.0
;        priority                1
;    end_block
;
;    ;;; archers to the right of siege engine
;    begin_block 2
;        unit_type               missile infantry                1.0
;        unit_type               missile cavalry                 0.8
;        unit_type               heavy infantry                  0.1
;        unit_type               any                             0.0
;        unit_density            close
;        block_formation         column
;        block_relative_pos      0 5.0 0.0
;        inter_unit_spacing      0.0
;        priority                1
;    end_block

    ;;; all other units behind the siege engine
    begin_block 1
        ;max_units               3
        unit_type               any                             0.5
        unit_density            close
        block_formation         column
        block_relative_pos      0 0.0 -1.0
        inter_unit_spacing      1.0
        priority                0.7
    end_block

end_formation



;****************************************************************
; Siege deployment
; The engines have already been assigned at this point
; Put rams in the centre front, other engines at the front either side
;****************************************************************
begin_formation deployment_siege

    standard_siege_attacker_deployment
    ai_priority                                                 1

    ;;; rams at the centre
    begin_block 0
        unit_type               carrying_siege_engine ram       1.0
        unit_density            close
        block_formation         line
        block_relative_pos      0 0.0 0.0
        inter_unit_spacing      2.0
        priority                1.0
    end_block

    ;; other engines left side
    begin_block 1
        unit_type               carrying_siege_engine ladder    1.0
        unit_type               carrying_siege_engine tower     1.0
        unit_type               siege                           1.0
        unit_density            close
        block_formation         line
        block_relative_pos      0 -2.0 0.0
        inter_unit_spacing      2.0
        priority                1.0
    end_block

    ;; other infantry left side
    begin_block 2
        unit_type               heavy infantry                  0.7
        unit_type               light infantry                  0.7
        unit_type               skirmish infantry               0.7
        unit_density            close
        block_formation         line
        block_relative_pos      1 -2.0 0.0
        inter_unit_spacing      2.0
        priority                0.5
    end_block

    ;; other engines right side
    begin_block 3
        unit_type               carrying_siege_engine ladder    1.0
        unit_type               carrying_siege_engine tower     1.0
        unit_type               siege                           1.0
        unit_density            close
        block_formation         line
        block_relative_pos      0 2.0 0.0
        inter_unit_spacing      2.0
        priority                1.0
    end_block

    ;; other infantry right side
    begin_block 4
        unit_type               heavy infantry                  0.7
        unit_type               light infantry                  0.7
        unit_type               skirmish infantry               0.7
        unit_density            close
        block_formation         line
        block_relative_pos      3 2.0 0.0
        inter_unit_spacing      2.0
        priority                0.5
    end_block

    begin_dummy_block 5
        spans 0 1 2 3 4
    end_dummy_block

    begin_block 6
        unit_type               heavy cavalry                   1.0
        unit_type               light cavalry                   1.0
        unit_type               skirmish cavalry                1.0
        unit_type               any                             0.1
        unit_density            close
        block_formation         line
        block_relative_pos      5 2.0 0.0
        inter_unit_spacing      2.0
        priority                0.1
    end_block

    begin_block 7
        unit_type               heavy cavalry                   1.0
        unit_type               light cavalry                   1.0
        unit_type               skirmish cavalry                1.0
        unit_type               any                             0.1
        unit_density            close
        block_formation         line
        block_relative_pos      5 -2.0 0.0
        inter_unit_spacing      2.0
        priority                0.1
    end_block

    ;;; archers behind to give support
    begin_block 8
        unit_type               missile infantry                1.0
        unit_density            close
        block_formation         line
        block_relative_pos      5 0.0 -10.0
        inter_unit_spacing      2.0
        priority                0.1
    end_block

end_formation


;****************************************************************
; Ambush deployment
; Column marching formation for the army being ambushed
;****************************************************************
begin_formation ambush_defender_deployment

    standard_ambush_defender_deployment
    ai_priority 1

    ;;; general at the front
    begin_block 0
        min_units               1
        max_units               1
        unit_type               general_unit            1.0
        unit_density            close
        max_unit_width          4
        block_formation         line
        block_relative_pos      0 0.0 0.0
        inter_unit_spacing      2.0
        priority                1.0
    end_block

    ;;; all other units behind
    begin_block 1
        unit_type               any                 1.0
        unit_density            close
        max_unit_width          4
        block_formation         column
        block_relative_pos      0 0.0 -2.0
        inter_unit_spacing      2.0
        priority                1.0
    end_block


end_formation

;****************************************************************

begin_formation ai_standard_hiding

    ;;; purpose flags
    hiding

    ai_priority         1

        begin_block 0
            min_units           1
            unit_type           any 1.0
            unit_density        close
            block_formation     square
            block_relative_pos  0 0.0 0.0
            inter_unit_spacing  1.0
            priority            1.0
        end_block

end_formation

;****************************************************************

begin_formation ai_breach_defense_infantry

    ;;; purpose flags
    breach_defense_force

    ai_priority     1.0

    begin_dummy_block 0                                         ;; centre slot left empty for assault column to pass through
        spacer 0.0 0.0 20 20
    end_dummy_block

    ;;; left and forward
    begin_block 1
        max_units               1
    	not_general
        unit_type				heavy infantry			1.0
        unit_type				light infantry			0.5
        unit_type				any						0.1
        unit_density            close
        block_formation         line
        block_relative_pos  	0 -1.0 0.0
        inter_unit_spacing      2.0
        priority                1.0
    end_block

    ;;; right and forward
    begin_block 2
        max_units               1
    	not_general
        unit_type				heavy infantry			1.0
        unit_type				light infantry			0.5
        unit_type				any						0.1
        unit_density            close
        block_formation         line
        block_relative_pos  	0 1.0 0.0
        inter_unit_spacing      2.0
        priority                1.0
    end_block

    ;;; left and forward
    begin_block 3
        max_units               1
    	not_general
        unit_type				heavy infantry			1.0
        unit_type				light infantry			0.5
        unit_type				any						0.1
        unit_density            close
        block_formation         line
        block_relative_pos  	1 0.0 -1.0
        inter_unit_spacing      2.0
        priority                0.6
    end_block

    ;;; right and forward
    begin_block 4
        max_units               1
    	not_general
        unit_type				heavy infantry			1.0
        unit_type				light infantry			0.5
        unit_type				any						0.1
        unit_density            close
        block_formation         line
        block_relative_pos  	2 0.0 -1.0
        inter_unit_spacing      2.0
        priority                0.6
    end_block

    ;;; backup
    begin_block 5
        unit_type				any						0.1
        unit_density            close
        block_formation         line
        block_relative_pos  	0 0.0 -5.0
        inter_unit_spacing      2.0
        priority                0.1
    end_block

end_formation

;****************************************************************

begin_formation ai_settlement_defense_street_artillery

    ;;; purpose flags
    settlement
    artillery
    defend

    ai_priority     1.0

    ;;; centre of group blocking the breach
    begin_block 0
    	not_general
        unit_type           	siege               1.0
        unit_density            close
        block_formation         column
        block_relative_pos  	0 0.0 0.0
        inter_unit_spacing      2.0
        priority                1.0
    end_block

    ;;; backup
    begin_block 1
        unit_type				any						0.1
        unit_density            close
        block_formation         line
        block_relative_pos  	0 0.0 -5.0
        inter_unit_spacing      2.0
        priority                0.1
    end_block

end_formation

;****************************************************************

begin_formation ai_settlement_defense_plaza

	;;; purpose flags
	plaza
	
	ai_priority		1.0
	
	;;; centre forward block
	begin_block 0
		max_units				2
    	not_general
        unit_type               heavy infantry      1.0
        unit_type               light infantry      0.9
        unit_density			close
		max_unit_width			20
        block_formation			line
        normalised_pos			0.5		1.0
        normalised_rot			0
        inter_unit_spacing		2.0
        priority				1.0
	end_block
	
	;;; forward and right block
	begin_block 1
		max_units				2
    	not_general
        unit_type               heavy infantry      1.0
        unit_type               light infantry      0.9
        unit_density			close
		max_unit_width			20
        block_formation			line
        normalised_pos			0.8125	0.75
        normalised_rot			45
        inter_unit_spacing		2.0
        priority				0.5
	end_block
	
	;;; forward and left block
	begin_block 2
		max_units				2
    	not_general
        unit_type               heavy infantry      1.0
        unit_type               light infantry      0.9
        unit_density			close
		max_unit_width			20
        block_formation			line
        normalised_pos			0.1875	0.75
        normalised_rot			315
        inter_unit_spacing		2.0
        priority				0.5
	end_block
	
	;;; right block
	begin_block 3
		max_units				2
    	not_general
        unit_type               heavy infantry      1.0
        unit_type               light infantry      0.9
        unit_density			close
		max_unit_width			20
        block_formation			line
        normalised_pos			1.0		0.25
        normalised_rot			75
        inter_unit_spacing		2.0
        priority				0.2
	end_block
	
	;;; left block
	begin_block 4
		max_units				2
    	not_general
        unit_type               heavy infantry      1.0
        unit_type               light infantry      0.9
        unit_density			close
		max_unit_width			20
        block_formation			line
        normalised_pos			0.0		0.25
        normalised_rot			285
        inter_unit_spacing		2.0
        priority				0.2
	end_block

	;;; centre back catch all block	
	begin_block 5
        unit_type               any					0.1
        unit_density			close
		max_unit_width			20
        block_formation			column
        normalised_pos			0.5		0.0
        normalised_rot			0
        inter_unit_spacing		2.0
        priority				0.1
	end_block

end_formation

;****************************************************************

begin_formation ai_settlement_attack_reform

    ai_priority                                                 0

    ;;; rams at the centre
    begin_block 0
        unit_type               carrying_siege_engine ram       1.0
        unit_density            close
        block_formation         line
        block_relative_pos      0 0.0 0.0
        inter_unit_spacing      0.5
        priority                1.0
    end_block

    ;; other engines left side
    begin_block 1
        unit_type               carrying_siege_engine ladder    1.0
        unit_type               carrying_siege_engine tower     1.0
        unit_type               siege                           1.0
        unit_density            close
        block_formation         line
        block_relative_pos      0 -1.0 0.0
        inter_unit_spacing      0.5
        priority                1.0
    end_block

    ;; other infantry left side
    begin_block 2
        unit_type               heavy infantry                  0.7
        unit_type               light infantry                  0.7
        unit_type               skirmish infantry               0.7
        unit_type               missile infantry	            0.4
        unit_density            close
        block_formation         line
        block_relative_pos      1 -1.0 0.0
        inter_unit_spacing      0.5
        priority                0.5
    end_block

    ;; other engines right side
    begin_block 3
        unit_type               carrying_siege_engine ladder    1.0
        unit_type               carrying_siege_engine tower     1.0
        unit_type               siege                           1.0
        unit_density            close
        block_formation         line
        block_relative_pos      0 1.0 0.0
        inter_unit_spacing      0.5
        priority                1.0
    end_block

    ;; other infantry right side
    begin_block 4
        unit_type               heavy infantry                  0.7
        unit_type               light infantry                  0.7
        unit_type               skirmish infantry               0.7
        unit_type               missile infantry	            0.4
        unit_density            close
        block_formation         line
        block_relative_pos      3 1.0 0.0
        inter_unit_spacing      0.5
        priority                0.5
    end_block

    begin_dummy_block 5
        spans 0 1 2 3 4
    end_dummy_block

    ;;; cavalry on both sides
    begin_block 6
        unit_type               heavy cavalry                   1.0
        unit_type               light cavalry                   1.0
        unit_type               skirmish cavalry                1.0
        unit_type               any                             0.1
        unit_density            close
        block_formation         line
        block_relative_pos      5 1.0 0.0
        inter_unit_spacing      0.5
        priority                0.1
    end_block
    begin_block 7
        unit_type               heavy cavalry                   1.0
        unit_type               light cavalry                   1.0
        unit_type               skirmish cavalry                1.0
        unit_type               any                             0.1
        unit_density            close
        block_formation         line
        block_relative_pos      5 -1.0 0.0
        inter_unit_spacing      0.5
        priority                0.1
    end_block

end_formation

;****************************************************************

begin_formation ai_settlement_assault_gate

    ai_priority                                                 0

    begin_block 0
        unit_type               any 1.0
        unit_density            close
        block_formation         line
        block_relative_pos      0 0.0 0.0
        inter_unit_spacing      1.0
        priority                1.0
    end_block

end_formation

;****************************************************************

begin_formation ai_street_defense_infantry
    ;;; purpose flags
    street
    defend

    ai_priority     1.0

    ;;; 
    begin_block 0
    	max_units				2
    	not_general
        unit_type           	heavy infantry		1.0
        unit_type           	light infantry		1.0
        unit_density            close
        block_formation         line
        block_relative_pos  	0 0.0 0.0
        inter_unit_spacing      2.0
        priority                1.0
    end_block

    ;;; 
    begin_block 1
        unit_type           	any					0.5
        unit_density            close
        block_formation         line
        block_relative_pos  	0 0.0 -1.0
        inter_unit_spacing      2.0
        priority                0.5
    end_block
end_formation

