Image copyright Reuters Image caption Most foreign embassies are housed in one building in the Taiwanese capital

Foreign diplomats stationed in Taiwan do not need to travel far to meet officials from the island's international aid office.

One building in Taipei, the capital, houses most embassies, and the International Co-operation and Development Fund is located on the upper floors.

Taiwan has long used development aid and assistance to keep its handful of diplomatic partners onside but its giant mainland neighbour is now an economic superpower.

The island's allies are being picked off by China in what Taiwan derisively calls a "diplomatic money game".

Sao Tome and Principe, one of Africa's smallest states, cut ties in December. Panama, a longstanding partner, has now done the same.

Analysts say more Central American nations could follow.

Fierce competition

Taiwan's diplomatic isolation dates back to 1971, when the United Nations switched diplomatic recognition to Beijing's People's Republic of China, and most countries followed suit. China sees Taiwan as a breakaway province and aims to deny it the trappings of a sovereign state.

Still, in the early 1990s, there were about 30 countries choosing to recognise Taipei over Beijing. That number is now down to 19, plus the Holy See.

The competition between Taiwan and China for the affections of small states mostly located in Central America, the Caribbean and the Pacific has been fierce.

Alliances have often switched back and forth, as a product of domestic politics and in response to economic incentives.

Image copyright EPA Image caption Ties with Panama date back more than a century

Take the tiny Caribbean island of St Lucia. It first recognised Taiwan in 1984, under conservative Prime Minister John Compton. But when the St Lucia Labour Party took power in 1997, the government switched to China.

Yet, in 2007, Mr Compton was back in power and restored ties with Taiwan, infuriating Beijing, which had funded large infrastructure projects.

The foreign minister at the time is reported to have suggested that one should "support those who give you the most". Taiwan subsequently built a national tennis centre, among other projects.

Although the Labour Party won the election in 2011, it did not, as expected, switch back to China. Prime Minister Kenny Anthony said his country could not continue to behave "as if our sovereignty is for sale to the highest bidder".

Image copyright AFP Image caption Panama and China sealed their friendship with champagne

St Lucia is not the only country to have swung like a pendulum between Taipei and Beijing: The Gambia, Liberia and Nicaragua are among others who have done the same.

How far China goes in trying to win over Taiwan's allies also depends on who is in power across the strait.

Playing politics

From 2000-2008, when the independence-leaning Democratic Progressive Party (DPP) was in charge, Taiwan lost many friends to China: Costa Rica, Senegal, Chad, Grenada, Dominica, Macedonia, Vanuatu, Liberia and Malawi.

China spent big: Costa Rica received a new stadium reportedly worth more than $100m (£78m).

It stopped pinching Taiwan's allies for a period beginning in 2008 when the China-friendly Ma Ying-jeou of the Kuomintang (KMT) became president

"In that period Taiwan stopped trying to buy new allies but it also developed closer ties to the PRC," said Dr Dafydd Fell, a Taiwan expert at the School of Oriental and African Studies (SOAS). A key part of that was an understanding that both sides accepted the "1992 Consensus" - that there is one China but that what this means is interpreted differently.

That changed after President Tsai Ing-wen of the DPP took office in May 2016. She doesn't accept the 1992 Consensus "and so Beijing is looking at ways to punish Taiwan", Dr Fell says. These include reducing tourism and targeting its diplomatic allies.

"I think it is likely we will see more switches in the near future."

Image copyright iStock/Getty Images Image caption Kiribati (pop: 110,000) established relations with Taiwan in 2003 and Beijing broke off ties

And who will be next?

Colin Alexander, a lecturer at Nottingham Trent University and the author of a book examining China and Taiwan's policies in Central America, says El Salvador or Nicaragua could turn away from Taipei.

El Salvador, he says, actually tried to recognise China during its diplomatic détente with Taiwan under President Ma and was rebuffed. The game has now changed.

Taiwanese President Tsai visited El Salvador, Guatemala, Honduras and Nicaragua in January to bolster her alliances after then President-elect Donald Trump caused outcry in Beijing by accepting a congratulatory phone call from her in early December.

In between the phone call and Ms Tsai's trip, Sao Tome and Principe flipped.

Who does Taiwan have diplomatic relations with?

In Latin America and the Caribbean: Belize, El Salvador, Haiti, Nicaragua, St Kitts and Nevis, St Vincent & the Grenadines, the Dominican Republic, Guatemala, Paraguay, Honduras and Saint Lucia

In Africa: Burkina Faso and Swaziland

In Europe: The Holy See

In the Pacific: Kiribati, Nauru, the Solomon Islands, Tuvalu, the Marshall Islands and Palau

For Central American countries that have become democracies, recognising China is not just about money, Mr Alexander says. They also want to be seen as "diplomatically normal", instead of global outliers.

At the same time, he adds: "If you're from a small Central American Republic and you have Taiwan as your ally, Taiwan treats you as a princess really and you get a lot of benefits from it.

"If you move over to China, you're just another country that recognises China".

What is the 'One China' policy?

Image copyright AFP Image caption President Tsai visited Guatemala as part of her four-nation Central America tour

Some of Taiwan's allies have touted their resistance to Chinese largesse and "dollar diplomacy".

Burkina Faso and Swaziland are Taiwan's last remaining partners in Africa, a continent into which China has poured billions in recent years.

"We get outrageous proposals telling us: 'If you sign with Beijing we'll offer you $50bn or even more,'" Burkina Faso Foreign Minister Alpha Barry told Bloomberg in January. "Taiwan is our friend and our partner. We're happy and we see no reason to reconsider the relationship."

Dilmei Olkeriil, the ambassador who represents the north Pacific nation of Palau in Taiwan, told the BBC she was "surprised" and "saddened" that Panama had switched to China. Ambassadors in Taiwan, she added, have a "close relationship".

She said it was unlikely her country would turn its back on Taiwan too, as most people support it.

Symbolic value

These formal diplomatic relationships are still seen as significant for Taiwan, but are not as important as they used to be in general public opinion, says Dr Fell.

The main value is symbolic: leaders can make diplomatic visits and countries can speak up for Taiwan at the UN and other international organisations.

But ultimately, the relationships Taiwan has with major powers, like the United States - "which are called unofficial but which function as the same as official diplomatic ties" - are more important, he says.

The island has dozens of trade offices around the world that function as de-facto embassies.

The current focus on wresting small states away from Taiwan's embrace may also be counterproductive to Beijing's long-term goals, according to Dr Fell.

"Taiwanese find their international isolation very frustrating", he says, "and Chinese pressure tends to reinforce Taiwanese national identity."