Help on Summit's Gate

I can’t seem to figure out what to do here. My troops (soldiers, archers) kill all the ogres, but only go for one of the catapults. Here is my code. It isn’t complete, but I am taking the level step by step:

friends = hero.findFriends()
enemies = hero.findEnemies()
for friend in friends:
    if friend and friend.type is "archer":
        for enemy in enemies:
            if enemy and enemy.type is "fangrider":
                hero.command(friend, "attack", enemy)
    else:
        hero.command(friend, "attack", enemy)
        
for friend in friends:
    if friend and friend.type is "soldier":
        for enemy in enemies:
            if enemy and enemy.type is "ogre":
                hero.command(friend, "attack", enemy)
        
for friend in friends:
    if friend:
        for enemy in enemies:
            if enemy and enemy.type is "catapult":
                hero.command(friend, "attack", enemy)

You probably need flags for this level

I hate flags so I manage to pass it without flag, but it took quite a long time to.

Many good advices are here: Please help with Summit's Gate!