I feel like I should tell a bit about the history of this fortification.

Before the French invasion of Spain, it didn't have much strategic value, as it was in the center of Spain.

It was built in 884 during the Reconquest of the Spanish Christian Kingdoms, and it was ampliated by the following castellans.

Between at least 1042 and 1277 it served as jail of noblemen, and from 1252 to 1284 and 1390 to 1454 served as palace. (Yes, I know the periods as jail and as palace are overlapped, but one tower could serve as jail while the rest of the castle served as palace).

It saw use as stronghold in the civil war of 1474-76.

In the XVI century it was used as artillery academy and gunpowder factory.

In 1736 there was a fire that burnt the wooden decorations of the palace, made on 1252.

So, before the French invasion, it was mainly a late-medieval castle, that's the part that's recognisable nowadays.
Then came the Napoleonic invaders in 1808 and they took the castle and the city, and held it for 5 years.
Because the French were invaders, they needed to secure every strategic position they could find, so the castle and the hill was again a strategic spot in the surrounding plain.

They brought the defenses up to date in those years and they built a hornwerk and ravelin on the hill of San Miguel.
From september to october of 1812 they went through a siege by Arthur Wellesley (later known as Duke of Wellington), where the siegers (Anglo-Portuguese) went through a great number of casualties, while the sieged (French) only lost a fifth of their numbers.

Later, in june 13, 1813 the French retired from the fort, and they made it explode to avoid leaving any equipment or documents usable to the enemy.

Today what remains is part of the medieval castle.