Illustrate football team formations on a pitch Football is the sport where players kick the ball, not carry it. Some confused individuals might call this soccer.



A football team has one goalkeeper, and 10 players out on the pitch. There are many formations used in football, that dictates where each player should be (the player of course moves around, but it's the base position).

The most common formation is 4-4-2, which means that there are 4 defenders, 4 midfielders and two attackers. Other formations are ("defenders, midfielders, attackers" or "defenders, midfielders, midfielders, attackers"):


4-4-2
4-3-3
5-3-2
3-4-3
3-5-2
4-5-1
5-4-1
4-4-1-1
4-3-1-2
4-1-2-3
4-1-3-2
4-3-2-1
3-4-1-2
3-3-3-1


The challenge is to take two inputs, one for each of the two teams and output a overview of the players on the field.

In general: Most information about the layout of the ASCII-art can be found in the figures (a picture says more than 1000 words). Only the way to place the 10 players on the field is explained in detail:


The keeper and the penalty area takes up 3 rows of ASCII-characters


Layout and number of spaces can be found in the figure below

There is no empty row between the penalty area and the defenders
If there are 3 numbers in the formation (e.g. 4-4-2, 4-3-3 etc. Not 4-3-2-1):


There is no empty row between the defenders and the midfielders
There is one empty row between the midfielders and the attackers

If there are 4 numbers in the formation (e.g. 4-3-2-1, 3-3-3-1 etc. Not 4-4-2):


There is no empty row between the defender and the first row of midfielders
There is no empty row between the first row of midfielders and the second
There is no empty row between the second row of midfielders and the attackers 

There is no empty rows between the attackers and the center line
The team on the upper half are marked as x, and the team on the second half are marked as o.
Each row of players shall be distributed on the pitch as shown in the figures below. The number of spaces can be seen in the figure.


The following figure does not represent a valid formation, but is used to illustrate the layout and number of required spaces between each player. The input for this would be 2 3 4 5 and 5 4 2: 

+-----------------+
|     |  x  |     |
|     +-----+     |
|     x     x     |
|    x   x   x    |
|  x   x   x   x  |
|  x  x  x  x  x  |
+-----------------+
|     o     o     |
|                 |
|  o   o   o   o  |
|  o  o  o  o  o  |
|     +-----+     |
|     |  o  |     |
+-----------------+ 




Valid examples:

Input:
4 4 2, 5 3 1 1


+-----------------+
|     |  x  |     |
|     +-----+     |
|  x   x   x   x  |
|  x   x   x   x  |
|                 |
|     x     x     |
+-----------------+
|        o        |
|        o        |
|    o   o   o    |
|  o  o  o  o  o  |
|     +-----+     |
|     |  o  |     |
+-----------------+




Input:
3 5 2, 4 4 1 1


+-----------------+
|     |  x  |     |
|     +-----+     |
|    x   x   x    |
|  x  x  x  x  x  |
|                 |
|     x     x     |
+-----------------+
|        o        |
|        o        |
|  o   o   o   o  |
|  o   o   o   o  |
|     +-----+     |
|     |  o  |     |
+-----------------+


Rules:


Input can be on any convenient format, separated however you want. Format can be a single string (5311), comma separated digits (5,3,1,1), etc.


The input should not contain any other information than the two formations

The output should look exactly as the sample figures, but trailing spaces and newlines are OK.
You can assume only valid input is given (only formations in the list will be used).
Full program or function


This is code golf, so the shortest code in bytes win.
Python 2, 401 377 bytes

def g(x,o):
 r=lambda r:[&quot;|&quot;+&quot;  x&quot;*5+&quot;  |&quot;,&quot;|        x        |&quot;,&quot;|     x     x     |&quot;,&quot;|    x   x   x    |&quot;,&quot;|  x   x   x   x  |&quot;][r%5];d=&quot;+&quot;+&quot;-&quot;*17+&quot;+&quot;;h=[d,&quot;|     |  x  |     |&quot;,&quot;|     +-----+     |&quot;]+map(r,x);b=map(lambda r:r.replace(&quot;x&quot;,&quot;o&quot;),[s for s in h[:3]]+map(r,o))[::-1];e=&quot;|&quot;+&quot; &quot;*17+&quot;|&quot;
 if len(x)-4:h.insert(5,e)
 if len(o)-4:b.insert(1,e)
 print&quot;\n&quot;.join(h+[d]+b)

Ungolfed version with test environment here!
Function that takes two lists of the format [defenders, midfielders, midfielders, attackers] while the one midfielder number is optional. Team X (top) comes first, team O (bottom) second.