Efforts to rescue up to 2,000 civilians trapped by fighting between government troops and Islamist militants in a southern Philippine city failed over the weekend. Authorities and witnesses said a proposed ceasefire ended in a hail of gunshots and explosions.

The civilians were pinned down nearly two weeks ago in the center of Marawi, on Mindanao island, where gunmen loyal to the so-called Islamic State are holding out against a military assault. The government said 178 people had been killed so far.

President Rodrigo Duterte has declared martial law in the region, and the military has bombarded Marawi with airstrikes and waged fierce street-to-street battles with gunmen since hundreds of them began a rampage through residential areas, waving the black flags of ISIS.

What's going on here? It's more complicated than ISIS alone.

Related: The truth about those ISIS-style flags waving in the Philippines

Patricio Abinales is a professor at the University of Hawaii’s Asian Studies program. He says there’s a long history of Muslim opposition to the government in the Philippines because Muslims lived on the islands before the predominantly Christian country was formed.

In the 1970s, the Moro National Liberation Front (MNLF), aided by the Muslim-majority countries of Libya and Malaysia, fought against the Philippine government “with the intention of breaking away Mindanao and a few other islands,” Abinales says, “on the grounds that Muslims were never Filipinos and that Muslims were being destroyed by the Filipino majority.”

The MNLF broke into splinter groups, and eventually one called the Moro Islamic Liberation Front (MILF) consolidated power. It’s unlikely that this group has real ties to ISIS, Abinales says, because, despite their ongoing push for independence, they’re highly pragmatic — putting family clans and business first, over ideology.

“What’s always forgotten about Philippine Islam is that it’s not only a religious community, it’s also a community that’s driven by trade,” he says.

Muslims living on the islands that are now the Philippines have been trading in Southeast Asia since the 12th century. These days, Abinales says, everything from guns to toilet paper to Viagra is brought in: “There’s a lot of un-Islamic commodities being traded because that’s how life is among Filipino Muslims.”

The ceasefire deal that broke down over the weekend was initially reached following a meeting last week between President Duterte and the MILF, which offered to broker a halt in hostilities using contacts with the fighters in Marawi, provincial crisis management committee spokesman Zia Alonto Adiong told Agence France-Presse.

Major Muslim rebel groups such as the MILF have signed accords with the government to forge a final peace, giving up separatist ambitions in return for autonomy. But small, hard-line groups such as the Maute and Abu Sayyaf, which are involved in the Marawi battle, refuse to negotiate and seek to unite behind ISIS.

It’s not clear how many ISIS-affiliated fighters are part of the insurgency on the island of Mindanao. Indonesian Defense Minister Ryamizard Ryacudu said over the weekend that there are about 1,200 ISIS operatives in the Philippines, while Philippine defense undersecretary Ricardo David put the figure at 250 to 400.

Agence France-Presse contributed to this report.