예제 #1
0
/// Doesn't find a defender at the flag -> Send defenders or capture it
void nofAttacker::ContinueAtFlag()
{
    RTTR_Assert(attacked_goal);
    // Greifen wir grad ein Gebäude an?
    if(state == STATE_ATTACKING_FIGHTINGVSDEFENDER || (state == STATE_FIGHTING && attacked_goal->GetFlag()->GetPos() == pos))
    {
        // Dann neuen Verteidiger rufen
        if(attacked_goal->CallDefender(this)) //-V522
        {
            // Verteidiger gefunden --> hinstellen und auf ihn warten
            SwitchStateAttackingWaitingForDefender();
        } else
        {
            // check for soldiers of other non-friendly non-owner players to fight
            if(FindEnemiesNearby(attacked_goal->GetPlayer()))
                return;
            // kein Verteidiger gefunden --> ins Gebäude laufen und es erobern
            state = STATE_ATTACKING_CAPTURINGFIRST;
            StartWalking(Direction::NORTHWEST);

            // Normalen Militärgebäuden schonmal Bescheid sagen
            if(attacked_goal->GetGOT() == GOT_NOB_MILITARY)
                static_cast<nobMilitary*>(attacked_goal)->PrepareCapturing();
        }
    } else
    {
        // weiterlaufen
        state = STATE_ATTACKING_WALKINGTOGOAL;
        MissAttackingWalk();
    }
}
예제 #2
0
/// Ist am Militärgebäude angekommen
void nofAttacker::ReachedDestination()
{
    // Sind wir direkt an der Flagge?
    if(pos == attacked_goal->GetFlag()->GetPos())
    {
        // Building already captured? Continue capturing
        // This can only be a far away attacker
        if(attacked_goal->GetPlayer() == player)
        {
            state = STATE_ATTACKING_CAPTURINGNEXT;
            RTTR_Assert(dynamic_cast<nobMilitary*>(attacked_goal));
            auto* goal = static_cast<nobMilitary*>(attacked_goal);
            RTTR_Assert(goal->IsFarAwayCapturer(this));
            // Start walking first so the flag is free
            StartWalking(Direction::NORTHWEST);
            // Then tell the building
            goal->FarAwayCapturerReachedGoal(this);
            return;
        }

        // Post schicken "Wir werden angegriffen" TODO evtl. unschön, da jeder Attacker das dann aufruft
        SendPostMessage(attacked_goal->GetPlayer(), new PostMsgWithBuilding(GetEvMgr().GetCurrentGF(), _("We are under attack!"),
                                                                            PostCategory::Military, *attacked_goal));

        // Dann Verteidiger rufen
        if(attacked_goal->CallDefender(this))
        {
            // Verteidiger gefunden --> hinstellen und auf ihn warten
            SwitchStateAttackingWaitingForDefender();
        } else
        {
            // kein Verteidiger gefunden --> ins Gebäude laufen und es erobern
            state = STATE_ATTACKING_CAPTURINGFIRST;
            StartWalking(Direction::NORTHWEST);
            // Normalen Militärgebäuden schonmal Bescheid sagen
            if(attacked_goal->GetGOT() == GOT_NOB_MILITARY)
                static_cast<nobMilitary*>(attacked_goal)->PrepareCapturing();
        }
    } else
    {
        // dann hinstellen und warten, bis wir an die Reihe kommmen mit Kämpfen und außerdem diesen Platz
        // reservieren, damit sich kein anderer noch hier hinstellt
        state = STATE_ATTACKING_WAITINGAROUNDBUILDING;
        // zur Flagge hin ausrichten
        Direction dir(Direction::WEST);
        MapPoint attFlagPos = attacked_goal->GetFlag()->GetPos();
        if(pos.y == attFlagPos.y && pos.x <= attFlagPos.x)
            dir = Direction::EAST;
        else if(pos.y == attFlagPos.y && pos.x > attFlagPos.x)
            dir = Direction::WEST;
        else if(pos.y < attFlagPos.y && pos.x < attFlagPos.x)
            dir = Direction::SOUTHEAST;
        else if(pos.y < attFlagPos.y && pos.x > attFlagPos.x)
            dir = Direction::SOUTHWEST;
        else if(pos.y > attFlagPos.y && pos.x < attFlagPos.x)
            dir = Direction::NORTHEAST;
        else if(pos.y > attFlagPos.y && pos.x > attFlagPos.x)
            dir = Direction::NORTHWEST;
        else /* (pos.x ==  attFlagPos.x)*/
        {
            if(pos.y < attFlagPos.y && !(safeDiff(pos.y, attFlagPos.y) & 1))
                dir = Direction::SOUTHEAST;
            else if(pos.y < attFlagPos.y && (safeDiff(pos.y, attFlagPos.y) & 1))
            {
                if(pos.y & 1)
                    dir = Direction::SOUTHWEST;
                else
                    dir = Direction::SOUTHEAST;
            } else if(pos.y > attFlagPos.y && !(safeDiff(pos.y, attFlagPos.y) & 1))
                dir = Direction::NORTHEAST;
            else /* (pos.y > attFlagPos.y && (safeDiff(pos.y, attFlagPos.y) & 1))*/
            {
                if(pos.y & 1)
                    dir = Direction::NORTHWEST;
                else
                    dir = Direction::NORTHEAST;
            }
        }
        FaceDir(dir);
        if(attacked_goal->GetPlayer() == player)
        {
            // Building already captured? -> Then we might be a far-away-capturer
            // -> Tell the building, that we are here
            RTTR_Assert(dynamic_cast<nobMilitary*>(attacked_goal));
            auto* goal = static_cast<nobMilitary*>(attacked_goal);
            if(goal->IsFarAwayCapturer(this))
                goal->FarAwayCapturerReachedGoal(this);
        }
    }
}
예제 #3
0
/// Ist am Militärgebäude angekommen
void nofAttacker::ReachedDestination()
{
    // Sind wir direkt an der Flagge?
    if(pos == attacked_goal->GetFlag()->GetPos())
    {
        // Building already captured? Continue capturing
        // This can only be a far away attacker
        if(attacked_goal->GetPlayer() == player)
        {
            state = STATE_ATTACKING_CAPTURINGNEXT;
            CapturingWalking();
            static_cast<nobMilitary*>(attacked_goal)->FarAwayAttackerReachedGoal(this);
            return;
        }

        // Post schicken "Wir werden angegriffen" TODO evtl. unschön, da jeder Attacker das dann aufruft
        if(attacked_goal->GetPlayer() == GAMECLIENT.GetPlayerID())
            GAMECLIENT.SendPostMessage(
                new ImagePostMsgWithLocation(_("We are under attack!"), PMC_MILITARY, pos,
                                             attacked_goal->GetBuildingType(), attacked_goal->GetNation()));

        // Dann Verteidiger rufen
        if(attacked_goal->CallDefender(this))
        {
            // Verteidiger gefunden --> hinstellen und auf ihn warten
            SwitchStateAttackingWaitingForDefender();


        }
        else
        {
            // kein Verteidiger gefunden --> ins Gebäude laufen und es erobern
            state = STATE_ATTACKING_CAPTURINGFIRST;
            StartWalking(1);
			// Normalen Militärgebäuden schonmal Bescheid sagen
            if(attacked_goal->GetGOT() == GOT_NOB_MILITARY)
                static_cast<nobMilitary*>(attacked_goal)->PrepareCapturing();
        }
    }
    else
    {
        // dann hinstellen und warten, bis wir an die Reihe kommmen mit Kämpfen und außerdem diesen Platz
        // reservieren, damit sich kein anderer noch hier hinstellt
        state = STATE_ATTACKING_WAITINGAROUNDBUILDING;
        // zur Flagge hin ausrichten
        MapPoint attFlagPos = attacked_goal->GetFlag()->GetPos();
        if(pos.y == attFlagPos.y && pos.x <= attFlagPos.x) dir = 3;
        else if(pos.y == attFlagPos.y && pos.x > attFlagPos.x) dir = 0;
        else if(pos.y < attFlagPos.y && pos.x < attFlagPos.x) dir = 4;
        else if(pos.y < attFlagPos.y && pos.x >  attFlagPos.x) dir = 5;
        else if(pos.y > attFlagPos.y && pos.x < attFlagPos.x) dir = 2;
        else if(pos.y > attFlagPos.y && pos.x >  attFlagPos.x) dir = 1;
        else if(pos.x ==  attFlagPos.x)
        {
            if(pos.y < attFlagPos.y && !(SafeDiff(pos.y, attFlagPos.y) & 1)) dir = 4;
            else if(pos.y < attFlagPos.y && (SafeDiff(pos.y, attFlagPos.y) & 1))
            {
                if(pos.y & 1) dir = 5; else dir = 4;
            }
            else if(pos.y > attFlagPos.y && !(SafeDiff(pos.y, attFlagPos.y) & 1)) dir = 2;
            else if(pos.y > attFlagPos.y && (SafeDiff(pos.y, attFlagPos.y) & 1))
            {
                if(pos.y & 1) dir = 1; else dir = 2;
            }
        }
    }
}