Beispiel #1
0
void TextInputComponent::SetText(DRef& dref, int source)
{
    Q_UNUSED(source);

    if (dref.Type() == BOI_STD_D(String))
    {
        QString text = *dref.GetReadInstance<QString>();

        LockDraw();

        m_text = text;

        int numNewLines = m_text.count('\n');

        if (m_numNewLines != numNewLines)
        {
            m_numNewLines = numNewLines;
            UpdateDimensions();
        }

        UnlockDraw();

        Update();
    }
}
Beispiel #2
0
int TTowers::DeleteKilled ()
{
        int i,j,t=0;

        for (i = 0; i < nofBadLife; i++) {
                if (DrawLocks == 1) {
                        UnlockDraw (FALSE); ProcessMapAnim (); LockDraw ();
                }
                if (DrawLocks == 0) ProcessMapAnim ();
                if ((BL [i] < 0) || (BL [i] >= UNITS_TOP)) {
                        DeleteBL (i);
                        i--;
                        continue;
                }
                else {
                        if (Units [BL [i]] == NULL || BL [i] < BADLIFE) {
                                DeleteBL (i);
                                i--;
                        }
                }
        }

        for (i = 0; i < nofGoodLife; i++) {
                if (DrawLocks == 1) {
                        UnlockDraw (FALSE); ProcessMapAnim (); LockDraw ();
                }
                if (DrawLocks == 0) ProcessMapAnim ();
                if ((GL [i] < 0) || (GL [i] >= UNITS_TOP)) {
                        DeleteGL (i);
                        i--;
                        continue;
                }
                else {
                        if (Units [GL [i]] == NULL || GL [i] >= BADLIFE) {
                                DeleteGL (i);
                                i--;
                        }
                }
        }

//        if (AssignResult () != 0) return FALSE;

        return TRUE;

}
Beispiel #3
0
void TextInputComponent::HandleStateChanged(StateId stateId, DRef& dref)
{
    if (stateId == StateId_WindowSize)
    {
        const QSizeF* pSize = dref.GetReadInstance<QSizeF>();

        LockDraw();

        m_windowSize = *pSize;
        UpdateDimensions();

        UnlockDraw();
    }
}
Beispiel #4
0
void TextInputComponent::Draw(QPainter* pPainter,
                              const QStyleOptionGraphicsItem* pOption)
{
    Q_UNUSED(pOption);

    LockDraw();

    pPainter->fillRect(m_boundingRect, m_bgFill);

    QRectF rect = m_textRect;
    rect.adjust(-m_xPadding, -m_yPadding, m_xPadding, m_yPadding);

    pPainter->fillRect(rect, m_textBgFill);

    pPainter->setFont(m_font);
    pPainter->setPen(m_textPen);

    pPainter->drawText(m_textRect, Qt::AlignLeft | Qt::AlignTop, m_text);

    UnlockDraw();
}
Beispiel #5
0
int ArtificialIntelligence8 ()
{
    int i, j, k, r, st, x, y, id, h, hmax;
    TPoint p;
    char buf [40];
    TBase *Base;
    TField *f;

    Message (SigText[TXT_AI_ANALYSE]);

    // Prepocitame viditelnost
    AllowBadlife (TRUE);
    ComputeVisib ();
    RedrawMap ();
    
    LockDraw ();
    
    // Aktualizujeme specialni objekty
    Docks1 = GetField (D1X, D1Y) -> Unit;
    if (Docks1 == NO_UNIT || Units [Docks1] -> Type % BADLIFE != unDocks) 
        Docks1 = NO_UNIT;
    Docks2 = GetField (D2X, D2Y) -> Unit;
    if (Docks2 == NO_UNIT || Units [Docks2] -> Type % BADLIFE != unDocks) 
        Docks2 = NO_UNIT;
    Factory1 = GetField (F1X, F1Y) -> Unit;
    if (Factory1 == NO_UNIT || Units [Factory1] -> Type % BADLIFE != unFactory) 
        Factory1 = NO_UNIT;
    Factory2 = GetField (F2X, F2Y) -> Unit;
    if (Factory2 == NO_UNIT || Units [Factory2] -> Type % BADLIFE != unFactory) 
        Factory2 = NO_UNIT;
    Factory3 = GetField (F3X, F3Y) -> Unit;
    if (Factory3 == NO_UNIT || Units [Factory3] -> Type % BADLIFE != unFactory) 
        Factory3 = NO_UNIT;

    // Vyradime znicene jednotky z armad    
    Towers -> DeleteKilled2 (); Towers -> DeleteKilled ();
    Army1 -> DeleteKilled2 (); Army1 -> DeleteKilled ();
    Army2 -> DeleteKilled2 (); Army2 -> DeleteKilled ();
    Army3 -> DeleteKilled2 (); Army3 -> DeleteKilled ();
    AirArmy3 -> DeleteKilled2 (); AirArmy3 -> DeleteKilled ();
    Army4 -> DeleteKilled2 (); Army4 -> DeleteKilled ();
    Army5 -> DeleteKilled2 (); Army5 -> DeleteKilled ();
    Army6 -> DeleteKilled2 (); Army6 -> DeleteKilled ();
    Army7 -> DeleteKilled2 (); Army7 -> DeleteKilled ();
    Army8 -> DeleteKilled2 (); Army8 -> DeleteKilled ();
    AirArmy8 -> DeleteKilled2 (); AirArmy8 -> DeleteKilled ();
    Marine1 -> DeleteKilled2 (); Marine1 -> DeleteKilled ();
    Marine8 -> DeleteKilled2 (); Marine8 -> DeleteKilled ();
    DUPos = 0;
    
    // Testneme konec hry   
    st = AssignResult ();
    if (st != 0) {
        UnlockDraw ();  
        AllowBadlife (FALSE);       
        return st;  
    }

    // Zpracujeme seznam poli, na ktere se utocilo
    Army1 -> DoAttackedFields ();
    Army2 -> DoAttackedFields ();
    Army3 -> DoAttackedFields ();
    AirArmy3 -> DoAttackedFields ();
    Army4 -> DoAttackedFields ();
    Army5 -> DoAttackedFields ();
    Army6 -> DoAttackedFields ();
    Army7 -> DoAttackedFields ();
    Army8 -> DoAttackedFields ();
    AirArmy8 -> DoAttackedFields ();
    Marine1 -> DoAttackedFields ();
    Marine8 -> DoAttackedFields ();
    AttackFieldPos = 0;
    
    AnalyseLandscape ();    
    
    Message (SigText[TXT_AI_ARMY]);



//////////////////////////////// AKTIVACE ARMAD

    // Test zaktivovani armady 1
    if (Army1 -> Status == asSleeping) {
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;
            if (Army1 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army1 -> Status = asActive;
            }
        }
    }
    // Test zaktivovani armady 2
    if (Army2 -> Status == asSleeping) {
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;
            if (Army2 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army2 -> Status = asActive;
            }
        }
    }
    // Test zaktivovani armady 3
    if (Army3 -> Status == asSleeping) {
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;
            if (Army3 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army3 -> Status = asActive;
            }
        }
    }
    // Test zaktivovani armady 4
    if (Army4 -> Status == asSleeping) {
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;
            if (Army4 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army4 -> Status = asActive;
            }
        }
    }
    // Test zaktivovani armady 5
    if (Army5 -> Status == asSleeping) {
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;
            if (Army5 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army5 -> Status = asActive;
            }
        }
    }
    // Test zaktivovani armady 6
    if (Army6 -> Status == asSleeping) {
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;
            if (Army6 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army6 -> Status = asActive;
            }
        }
    }
    // Test zaktivovani armady 7
    if (Army7 -> Status == asSleeping) {
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;
            if (Army7 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army7 -> Status = asActive;
            }
        }
    }
    // Test zaktivovani armady 8
    if (Army8 -> Status == asSleeping) {
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;
            if (Army8 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army8 -> Status = asActive;
            }
        }
    }
    // Test zaktivovani marine 1
    if (Marine1 -> Status == asSleeping) {
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;
            if (Marine1 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Marine1 -> Status = asActive;
            }
        }
    }
    // Test zaktivovani marine 8
    if (Marine8 -> Status == asSleeping) {
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;
            if (Marine8 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Marine8 -> Status = asActive;
            }
        }
    }
    

///////////////////////////// AKCE ARMAD

    // Nastavime ProgressBar
    st = 0;
    st += Towers -> nofBadLife;
    if (Army1 -> Status == asActive || Army1 -> Status == asSuicide) st += Army1 -> nofBadLife;
    if (Army2 -> Status == asActive || Army2 -> Status == asSuicide) st += Army2 -> nofBadLife;
    if (Army3 -> Status == asActive || Army3 -> Status == asSuicide) st += Army3 -> nofBadLife;
    if (AirArmy3 -> Status == asActive || AirArmy3 -> Status == asSuicide) st += AirArmy3 -> nofBadLife;
    if (Army4 -> Status == asActive || Army4 -> Status == asSuicide) st += Army4 -> nofBadLife;
    if (Army5 -> Status == asActive || Army5 -> Status == asSuicide) st += Army5 -> nofBadLife;
    if (Army6 -> Status == asActive || Army6 -> Status == asSuicide) st += Army6 -> nofBadLife;
    if (Army7 -> Status == asActive || Army7 -> Status == asSuicide) st += Army7 -> nofBadLife;
    if (Army8 -> Status == asActive || Army8 -> Status == asSuicide) st += Army8 -> nofBadLife;
    if (AirArmy8 -> Status == asActive || AirArmy8 -> Status == asSuicide) st += AirArmy8 -> nofBadLife;
    if (Marine1 -> Status == asActive || Marine1 -> Status == asSuicide) st += Marine1 -> nofBadLife;
    if (Marine8 -> Status == asActive || Marine8 -> Status == asSuicide) st += Marine8 -> nofBadLife;
    if (st == 0) st = 5; // Magic number
    ProgressNull ();
    ProgressLimit (st);     

    // Vylozime letiste
    UnlockDraw ();
    for (i = BADLIFE; i < UNITS_TOP; i++){
        // Airport
        if (Units [i] != NULL && Units [i] -> Type - BADLIFE == unAirport) {            
            for (j = 0; j < ((TAirport *) Units [i]) -> LoadedUnits; j++) {
                id = ((TAirport *)Units [i]) -> Inventory [j];
                if (Units [id] -> AI_Info.State == aistFuel) {
                    st = ((TAirport *)Units [i]) -> UnloadUnit ((TUnit *)Units [id]);
                    if (st == 1) {
                        j--;
                        Units [id] -> AI_Info.State = aistNought;
                        for (k = 120; k > 1; k--) {
                            p = CartezianSnail (k);
                            p.x += Units [id] -> X; p.y += Units [id] -> Y;
                            if (p.x >= 0 && p.x < MapSizeX && p.y >= 0 && p.y < MapSizeY
                            && GetAircraftAt (p.x, p.y) == NULL) {
                                Units [id] -> Select ();
                                st = Units [id] -> MoveFar (p.x, p.y);
                                if (st == 1) break;
                                
                            }
                        }
                    }
                }
            }
        }
        // Heliport
        if (Units [i] != NULL && Units [i] -> Type - BADLIFE == unHeliport) {           
            for (j = 0; j < ((THeliport *) Units [i]) -> LoadedUnits; j++) {
                id = ((THeliport *)Units [i]) -> Inventory [j];
                if (Units [id] -> AI_Info.State == aistFuel) {
                    st = ((THeliport *)Units [i]) -> UnloadUnit ((TUnit *)Units [id]);
                    if (st == 1) {
                        j--;
                        Units [id] -> AI_Info.State = aistNought;
                        for (k = 120; k > 1; k--) {
                            p = CartezianSnail (k);
                            p.x += Units [id] -> X; p.y += Units [id] -> Y;
                            if (p.x >= 0 && p.x < MapSizeX && p.y >= 0 && p.y < MapSizeY
                            && GetAircraftAt (p.x, p.y) == NULL) {
                                Units [id] -> Select ();
                                st = Units [id] -> MoveFar (p.x, p.y);
                                if (st == 1) break;
                            }
                        }
                    }
                }
            }
        }
        // Laguna
        if (Units [i] != NULL && Units [i] -> Type - BADLIFE == unLaguna) {         
            for (j = 0; j < ((TLaguna *) Units [i]) -> LoadedUnits; j++) {
                id = ((TLaguna *)Units [i]) -> Inventory [j];
                if (Units [id] -> AI_Info.State == aistFuel) {
                    st = ((TLaguna *)Units [i]) -> UnloadUnit ((TUnit *)Units [id]);
                    if (st == 1) {
                        j--;
                        Units [id] -> AI_Info.State = aistNought;
                        for (k = 120; k > 1; k--) {
                            p = CartezianSnail (k);
                            p.x += Units [id] -> X; p.y += Units [id] -> Y;
                            if (p.x >= 0 && p.x < MapSizeX && p.y >= 0 && p.y < MapSizeY
                            && GetAircraftAt (p.x, p.y) == NULL) {
                                Units [id] -> Select ();
                                st = Units [id] -> MoveFar (p.x, p.y);
                                if (st == 1) break;
                            }
                        }
                    }
                }
            }
        }
        
    }
    LockDraw ();

    // Veze
    if (Towers -> MakeTurn () == FALSE) {
        st = AssignResult ();
        if (st != 0) {
            UnlockDraw ();  
            AllowBadlife (FALSE);       
            return st;  
        }
    }

    
    // ARMY 1
    if (Army1 -> Status == asActive || Army1 -> Status == asSuicide) {
        Army1 -> DeleteKilled ();
        
        // Zarazeni novych nepratel (GL)
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;            
            if (Army1 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army1 -> Insert (i);
            }
        }

        // Pokyn k sebevrazde       
        Army1 -> CountDangerous ();
        if (Army1 -> Dangerous <= CSuicide1) {
            Army1 -> Status = asSuicide;
        }       
        
        // Provedeme akce
        if (Army1 -> MakeTurn () == FALSE) {
            st = AssignResult ();
            if (st != 0) {
                UnlockDraw ();  
                AllowBadlife (FALSE);       
                return st;  
            }
        }

        // Likvidace armady 1
        Army1 -> CountDangerous ();     
        if (Army1 -> Dangerous <= CMinDang1) {
            Army1 -> Status = asDestroyed;          
        }
        
        
    }
    
    // ARMY 2
    if (Army2 -> Status == asActive || Army2 -> Status == asSuicide) {
        Army2 -> DeleteKilled ();
        
        // Zarazeni novych nepratel (GL)
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;            
            if (Army2 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army2 -> Insert (i);
            }
        }

        // Pokyn k sebevrazde       
        Army2 -> CountDangerous ();
        if (Army2 -> Dangerous <= CSuicide2) {
            Army2 -> Status = asSuicide;
        }       
        
        // Provedeme akce
        if (Army2 -> MakeTurn () == FALSE) {
            st = AssignResult ();
            if (st != 0) {
                UnlockDraw ();  
                AllowBadlife (FALSE);       
                return st;  
            }
        }

        // Likvidace armady 2
        if (Army2 -> Dangerous <= CMinDang2) {
            Army2 -> Status = asDestroyed;
        }
        
    }

    // ARMY 3
    if (Army3 -> Status == asActive || Army3 -> Status == asSuicide) {
        Army3 -> DeleteKilled ();
        
        // Zarazeni novych nepratel (GL)
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;            
            if (Army3 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army3 -> Insert (i);
            }
        }

        // Pokyn k sebevrazde       
        Army3 -> CountDangerous ();
        if (Army3 -> Dangerous <= CSuicide3) {
            Army3 -> Status = asSuicide;
        }       
        
        // Provedeme akce
        if (Army3 -> MakeTurn () == FALSE) {
            st = AssignResult ();
            if (st != 0) {
                UnlockDraw ();  
                AllowBadlife (FALSE);       
                return st;  
            }
        }
        
        // Likvidace armady 3
        if (Army3 -> Dangerous <= CMinDang3) {
            Army3 -> Status = asDestroyed;
        }
                
    }
    // AIR ARMY 3
    if (AirArmy3 -> Status == asActive || AirArmy3 -> Status == asSuicide) {
        AirArmy3 -> DeleteKilled ();
        
        // Zarazeni novych nepratel (GL)
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;            
            if (AirArmy3 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                AirArmy3 -> Insert (i);
            }
        }

        // Pokyn k sebevrazde       
        AirArmy3 -> CountDangerous ();
        if (AirArmy3 -> Dangerous <= CSuicideA3) {
            AirArmy3 -> Status = asSuicide;
        }       
        
        // Provedeme akce
        if (AirArmy3 -> MakeTurn () == FALSE) {
            st = AssignResult ();
            if (st != 0) {
                UnlockDraw ();  
                AllowBadlife (FALSE);       
                return st;  
            }
        }
        
        // Likvidace armady 3
        if (AirArmy3 -> Dangerous <= CMinDangA3) {
            AirArmy3 -> Status = asDestroyed;
        }
                
    }


                    
    // ARMY 4
    if (Army4 -> Status == asActive || Army4 -> Status == asSuicide) {
        Army4 -> DeleteKilled ();

        // Zarazeni novych nepratel (GL)
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;            
            if (Army4 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army4 -> Insert (i);
            }
        }
        
        // Pokyn k sebevrazde       
        Army4 -> CountDangerous ();
        if (Army4 -> Dangerous <= CSuicide4) {
            Army4 -> Status = asSuicide;
        }       
        
        // Provedeme akce
        if (Army4 -> MakeTurn () == FALSE) {
            st = AssignResult ();
            if (st != 0) {
                UnlockDraw ();  
                AllowBadlife (FALSE);       
                return st;  
            }
        }
        
        // Likvidace armady 4
        if (Army4 -> Dangerous <= CMinDang4) {
            Army4 -> Status = asDestroyed;
        }               
    }
    

    // ARMY 5
    if (Army5 -> Status == asActive || Army5 -> Status == asSuicide) {
        Army5 -> DeleteKilled ();

        // Zarazeni novych nepratel (GL)
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;            
            if (Army5 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army5 -> Insert (i);
            }
        }
        
        // Pokyn k sebevrazde       
        Army5 -> CountDangerous ();
        if (Army5 -> Dangerous <= CSuicide5) {
            Army5 -> Status = asSuicide;
        }       
        
        // Provedeme akce
        if (Army5 -> MakeTurn () == FALSE) {
            st = AssignResult ();
            if (st != 0) {
                UnlockDraw ();  
                AllowBadlife (FALSE);       
                return st;  
            }
        }
        
        // Likvidace armady 5
        if (Army5 -> Dangerous <= CMinDang5) {
            Army5 -> Status = asDestroyed;
        }               
    }


    // ARMY 6
    if (Army6 -> Status == asActive || Army6 -> Status == asSuicide) {
        Army6 -> DeleteKilled ();

        // Zarazeni novych nepratel (GL)
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;            
            if (Army6 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army6 -> Insert (i);
            }
        }
        
        // Pokyn k sebevrazde       
        Army6 -> CountDangerous ();
        if (Army6 -> Dangerous <= CSuicide6) {
            Army6 -> Status = asSuicide;
        }       
        
        // Provedeme akce
        if (Army6 -> MakeTurn () == FALSE) {
            st = AssignResult ();
            if (st != 0) {
                UnlockDraw ();  
                AllowBadlife (FALSE);       
                return st;  
            }
        }
        
        // Likvidace armady 6
        if (Army6 -> Dangerous <= CMinDang6) {
            Army6 -> Status = asDestroyed;
        }               
    }

    // ARMY 7
    if (Army7 -> Status == asActive || Army7 -> Status == asSuicide) {
        Army7 -> DeleteKilled ();

        // Zarazeni novych nepratel (GL)
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;            
            if (Army7 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army7 -> Insert (i);
            }
        }
        
        // Pokyn k sebevrazde       
        Army7 -> CountDangerous ();
        if (Army7 -> Dangerous <= CSuicide7) {
            Army7 -> Status = asSuicide;
        }       
        
        // Provedeme akce
        if (Army7 -> MakeTurn () == FALSE) {
            st = AssignResult ();
            if (st != 0) {
                UnlockDraw ();  
                AllowBadlife (FALSE);       
                return st;  
            }
        }
        
        // Likvidace armady 7
        if (Army7 -> Dangerous <= CMinDang7) {
            Army7 -> Status = asDestroyed;
        }               
    }

    // ARMY 8
    if (Army8 -> Status == asActive || Army8 -> Status == asSuicide) {
        Army8 -> DeleteKilled ();

        // Zarazeni novych nepratel (GL)
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;            
            if (Army8 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army8 -> Insert (i);
            }
        }
        
        // Pokyn k sebevrazde       
        Army8 -> CountDangerous ();
        if (Army8 -> Dangerous <= CSuicide8) {
            Army8 -> Status = asSuicide;
        }       
        
        // Provedeme akce
        if (Army8 -> MakeTurn () == FALSE) {
            st = AssignResult ();
            if (st != 0) {
                UnlockDraw ();  
                AllowBadlife (FALSE);       
                return st;  
            }
        }
        
        // Likvidace armady 6
        if (Army8 -> Dangerous <= CMinDang8) {
            Army8 -> Status = asDestroyed;
        }               
    }

    // AIR ARMY 8
    if (AirArmy8 -> Status == asActive || AirArmy8 -> Status == asSuicide) {
        AirArmy8 -> DeleteKilled ();

        // Zarazeni novych nepratel (GL)
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;            
            if (AirArmy8 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                AirArmy8 -> Insert (i);
            }
        }
        
        // Pokyn k sebevrazde       
        AirArmy8 -> CountDangerous ();
        if (AirArmy8 -> Dangerous <= CSuicideA8) {
            AirArmy8 -> Status = asSuicide;
        }       
        
        // Provedeme akce
        if (AirArmy8 -> MakeTurn () == FALSE) {
            st = AssignResult ();
            if (st != 0) {
                UnlockDraw ();  
                AllowBadlife (FALSE);       
                return st;  
            }
        }
        
        // Likvidace armady 6
        if (AirArmy8 -> Dangerous <= CMinDangA8) {
            AirArmy8 -> Status = asDestroyed;
        }               
    }

    // MARINE 1
    if (Marine1 -> Status == asActive || Marine1 -> Status == asSuicide) {
        Marine1 -> DeleteKilled ();

        // Zarazeni novych nepratel (GL)
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;            
            if (Marine1 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Marine1 -> Insert (i);
            }
        }
        
        // Pokyn k sebevrazde       
        Marine1 -> CountDangerous ();
        if (Marine1 -> Dangerous <= CSuicideM1) {
            Marine1 -> Status = asSuicide;
        }       
        
        // Provedeme akce
        if (Marine1 -> MakeTurn () == FALSE) {
            st = AssignResult ();
            if (st != 0) {
                UnlockDraw ();  
                AllowBadlife (FALSE);       
                return st;  
            }
        }
        
        // Likvidace armady 1
        if (Marine1 -> Dangerous <= CMinDangM1) {
            Marine1 -> Status = asDestroyed;
        }               
    }

    // MARINE 8
    if (Marine8 -> Status == asActive || Marine8 -> Status == asSuicide) {
        Marine8 -> DeleteKilled ();

        // Zarazeni novych nepratel (GL)
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;            
            if (Marine8 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Marine8 -> Insert (i);
            }
        }
        
        // Pokyn k sebevrazde       
        Marine8 -> CountDangerous ();
        if (Marine8 -> Dangerous <= CSuicideM8) {
            Marine8 -> Status = asSuicide;
        }       
        
        // Provedeme akce
        if (Marine8 -> MakeTurn () == FALSE) {
            st = AssignResult ();
            if (st != 0) {
                UnlockDraw ();  
                AllowBadlife (FALSE);       
                return st;  
            }
        }
        
        // Likvidace armady 8
        if (Marine8 -> Dangerous <= CMinDangM8) {
            Marine8 -> Status = asDestroyed;
        }               
    }



    AttackFieldPos = 0;
    
    UnlockDraw ();  
    AllowBadlife (FALSE);
    return AssignResult ();

    
}
Beispiel #6
0
void InitAI8 ()
{
    int i,j;
    TBase *Base;
    TAirport *Airport;
    TField *f;
    TUnit *u;
    TPoint p;

    AttackFieldPos = 0;
    DUPos = 0;

    MoneyGoodlife = 0;
    MoneyBadlife = 10000;
    MBPlaces = NULL;    
    DeniedPlaces = NULL;

    Docks1 = GetField (D1X, D1Y) -> Unit;   
    Docks2 = GetField (D2X, D2Y) -> Unit;   
    Factory1 = GetField (F1X, F1Y) -> Unit;
    Factory2 = GetField (F2X, F2Y) -> Unit;
    Factory3 = GetField (F3X, F3Y) -> Unit;
        
    Towers = new TTowers ();
    for (i = 0; i < UNITS_TOP; i++) {
        if (Units [i] == NULL) continue;
        // vsechny veze a GL
        if ((((TUnit *) Units [i]) -> Type >= (unHorizont + BADLIFE) 
        && ((TUnit *) Units [i]) -> Type  <= (unSpektrum + BADLIFE))
        || (((TUnit *) Units[i]) -> Type < BADLIFE)) 
            Towers -> Insert (i);
    }
    

    LockDraw ();        
    Army1 = new TGroundArmy();
    Army1 -> SetAR (A1X1, A1Y1, A1X2, A1Y2);
    Army1 -> SetRadar (-1, -1);
    Army1 -> InsertUnits ();

    Army2 = new TGroundArmy();
    Army2 -> SetAR (A2X1, A2Y1, A2X2, A2Y2);
    Army2 -> SetRadar (-1, -1);
    Army2 -> InsertUnits ();
    
    Army3 = new TGroundArmy();
    Army3 -> SetAR (A3X1, A3Y1, A3X2, A3Y2);
    Army3 -> SetRadar (-1, -1);
    Army3 -> InsertUnits ();

    AirArmy3 = new TAirArmy();
    AirArmy3 -> SetAR (AA3X1, AA3Y1, AA3X2, AA3Y2);
    AirArmy3 -> SetRadar (-1, -1);
    AirArmy3 -> InsertUnits ();
    AirArmy3 -> Status = asActive;

    Army4 = new TGroundArmy();
    Army4 -> SetAR (A4X1, A4Y1, A4X2, A4Y2);
    Army4 -> SetRadar (-1, -1);
    Army4 -> InsertUnits ();

    Army5 = new TGroundArmy();
    Army5 -> SetAR (A5X1, A5Y1, A5X2, A5Y2);
    Army5 -> SetRadar (-1, -1);
    Army5 -> InsertUnits ();

    Army6 = new TGroundArmy();
    Army6 -> SetAR (A6X1, A6Y1, A6X2, A6Y2);
    Army6 -> SetRadar (-1, -1);
    Army6 -> InsertUnits ();

    Army7 = new TGroundArmy();
    Army7 -> SetAR (A7X1, A7Y1, A7X2, A7Y2);
    Army7 -> SetRadar (-1, -1);
    Army7 -> InsertUnits ();

    Army8 = new TGroundArmy();
    Army8 -> SetAR (A8X1, A8Y1, A8X2, A8Y2);
    Army8 -> SetRadar (-1, -1);
    Army8 -> InsertUnits ();

    AirArmy8 = new TAirArmy();
    AirArmy8 -> SetAR (AA8X1, AA8Y1, AA8X2, AA8Y2);
    AirArmy8 -> SetRadar (-1, -1);
    AirArmy8 -> InsertUnits ();
    AirArmy8 -> Status = asActive;
    
    Marine1 = new TMarine();
    Marine1 -> SetAR (M1X1, M1Y1, M1X2, M1Y2);
    Marine1 -> SetRadar (-1, -1);
    Marine1 -> InsertUnits ();

    Marine8 = new TMarine();
    Marine8 -> SetAR (M8X1, M8Y1, M8X2, M8Y2);
    Marine8 -> SetRadar (-1, -1);
    Marine8 -> InsertUnits ();


    // Naplnime Docks 1
    for (i = TD1X1; i <= TD1X2; i++) {
        for (j = TD1Y1; j <= TD1Y2; j++) {
            f = GetField (i, j);
            if (f -> Unit != NO_UNIT ) {
                u = (TUnit *)Units [f -> Unit];
                u -> PlaceGround (FALSE);               
                ((TDocks *)Units [Docks1]) -> Inventory [((TDocks*)Units [Docks1]) 
                -> LoadedUnits++] = u -> ID;
                u -> X = u -> Y = -1;
            }
        }
    }       

    
    // Polozime miny    
    for (i = 0; MinePlaces8 [i].x != -1; i++) {
        MinePlace (MinePlaces8 [i].x, MinePlaces8 [i].y, BADLIFE);
    }
    UnlockDraw ();          

    // zamerime jednotku
    i = GetField (SelX, SelY) -> Unit;  
    Units [i] -> Select ();

    RedrawMap ();
    
}
Beispiel #7
0
void TextInputComponent::HandleKeyEvent(KeyEvent* pEvent)
{
    int eventType = pEvent->type;

    if (eventType == KeyEvent::Type_Press)
    {
        LockDraw();

        if (m_clearOnNext)
        {
            m_text.clear();
            m_clearOnNext = false;

            if (m_numNewLines > 0)
            {
                m_numNewLines = 0;
                UpdateDimensions();
            }
        }

        int key = pEvent->key;

        if (key == Qt::Key_Backspace)
        {
            if (m_text.endsWith('\n'))
            {
                m_numNewLines--;
                UpdateDimensions();
            }

            m_text.chop(1);
            EmitText();
            Update();
        }
        else if ((key == Qt::Key_Return) ||
                 (key == Qt::Key_Enter))
        {
            if (pEvent->modifiers & KeyEvent::Modifier_Shift)
            {
                m_text.append('\n');
                m_numNewLines++;

                UpdateDimensions();
            }
            else
            {
                ActionArgs* pArgs = (m_pActionArgs != NULL) ?
                                    (m_pActionArgs) :
                                    (new ActionArgs);
                pArgs->Set("Text", m_text);

                SI()->UpdateActiveAction(m_action, pArgs);
            }
        }
        else if ((key != Qt::Key_Shift) &&
                 (key != Qt::Key_Control))
        {
            QChar ch(key);

            if (ch.isPrint())
            {
                if (pEvent->modifiers & KeyEvent::Modifier_Shift)
                {
                    m_text.append(ch);
                }
                else
                {
                    m_text.append(ch.toLower());
                }

                EmitText();
                Update();
            }
        }

        UnlockDraw();
    }
}
Beispiel #8
0
void InitAI19 ()
{
    int i,j;
    TBase *Base;
    TAirport *Airport;
    TField *f;
    TUnit *u;
    TPoint p;

    LockDraw ();        
    
    AttackFieldPos = 0;
    DUPos = 0;

    MoneyGoodlife = 0;
    MoneyBadlife = 15000;
    MBPlaces = NULL;
    DeniedPlaces = NULL;
    
    Uran1 = GetField (U1X, U1Y) -> Unit;    
    Uran2 = GetField (U2X, U2Y) -> Unit;    
    Uran3 = GetField (U3X, U3Y) -> Unit;    
    Uran4 = GetField (U4X, U4Y) -> Unit;    
    Uran5 = GetField (U5X, U5Y) -> Unit;    
    
    Base1 = GetField (B1X, B1Y) -> Unit;
    Factory1 = GetField (F1X, F1Y) -> Unit;
    Factory2 = GetField (F2X, F2Y) -> Unit;
    Factory3 = GetField (F3X, F3Y) -> Unit;
    Factory4 = GetField (F4X, F4Y) -> Unit;
    
    
    Towers = new TTowers ();
    for (i = 0; i < UNITS_TOP; i++) {
        if (Units [i] == NULL) continue;
        // vsechny veze a GL
        if ((((TUnit *) Units [i]) -> Type >= (unHorizont + BADLIFE) 
        && ((TUnit *) Units [i]) -> Type  <= (unSpektrum + BADLIFE))
        || (((TUnit *) Units[i]) -> Type < BADLIFE)) 
            Towers -> Insert (i);
    }
    
    Army1 = new TGroundArmy();
    Army1 -> SetAR (A1X1, A1Y1, A1X2, A1Y2);
    Army1 -> SetRadar (R1X, R1Y);
    Army1 -> InsertUnits ();

    Army2 = new TGroundArmy();
    Army2 -> SetAR (A2X1, A2Y1, A2X2, A2Y2);
    Army2 -> SetRadar (R2X, R2Y);
    Army2 -> InsertUnits ();
    
    Army3 = new TGroundArmy();
    Army3 -> SetAR (A3X1, A3Y1, A3X2, A3Y2);
    Army3 -> SetRadar (R1X, R1Y);
    Army3 -> InsertUnits ();

    Army4 = new TGroundArmy();
    Army4 -> SetAR (A4X1, A4Y1, A4X2, A4Y2);
    Army4 -> SetRadar (R2X, R2Y);
    Army4 -> InsertUnits ();

    Army5 = new TGroundArmy();
    Army5 -> SetAR (A5X1, A5Y1, A5X2, A5Y2);
    Army5 -> SetRadar (-1, -1);
    Army5 -> InsertUnits ();

    Army6 = new TGroundArmy();
    Army6 -> SetAR (A6X1, A6Y1, A6X2, A6Y2);
    Army6 -> SetRadar (R6X, R6Y);
    Army6 -> InsertUnits ();

    Army7 = new TGroundArmy();
    Army7 -> SetAR (A7X1, A7Y1, A7X2, A7Y2);
    Army7 -> SetRadar (R7X, R7Y);
    Army7 -> InsertUnits ();

    Army8 = new TGroundArmy();
    Army8 -> SetAR (A8X1, A8Y1, A8X2, A8Y2);
    Army8 -> SetRadar (R8X, R8Y);
    Army8 -> InsertUnits ();

    Army9 = new TGroundArmy();
    Army9 -> SetAR (A9X1, A9Y1, A9X2, A9Y2);
    Army9 -> SetRadar (R9X, R9Y);
    Army9 -> InsertUnits ();

    Army10 = new TGroundArmy();
    Army10 -> SetAR (A10X1, A10Y1, A10X2, A10Y2);
    Army10 -> SetRadar (-1, -1);
    Army10 -> InsertUnits ();

    Army11 = new TGroundArmy();
    Army11 -> SetAR (A11X1, A11Y1, A11X2, A11Y2);
    Army11 -> SetRadar (-1, -1);
    Army11 -> InsertUnits ();

    Army12 = new TGroundArmy();
    Army12 -> SetAR (A12X1, A12Y1, A12X2, A12Y2);
    Army12 -> SetRadar (-1, -1);
    Army12 -> InsertUnits ();

    Army13 = new TGroundArmy();
    Army13 -> SetAR (A13X1, A13Y1, A13X2, A13Y2);
    Army13 -> SetRadar (-1, -1);
    Army13 -> InsertUnits ();

    Army14 = new TGroundArmy();
    Army14 -> SetAR (A14X1, A14Y1, A14X2, A14Y2);
    Army14 -> SetRadar (-1, -1);
    Army14 -> InsertUnits ();

    Army15 = new TGroundArmy();
    Army15 -> SetAR (A15X1, A15Y1, A15X2, A15Y2);
    Army15 -> SetRadar (-1, -1);
    Army15 -> InsertUnits ();

    Army16 = new TGroundArmy();
    Army16 -> SetAR (A16X1, A16Y1, A16X2, A16Y2);
    Army16 -> SetRadar (-1, -1);
    Army16 -> InsertUnits ();

    AirArmy1 = new TAirArmy();
    AirArmy1 -> SetAR (AA1X1, AA1Y1, AA1X2, AA1Y2);
    AirArmy1 -> SetRadar (-1, -1);
    AirArmy1 -> InsertUnits ();
    AirArmy1 -> Status = asActive;
    

    // Naplnime Urany
    for (i = TU1X1; i <= TU1X2; i++) {
        for (j = TU1Y1; j <= TU1Y2; j++) {
            f = GetField (i, j);
            if (f -> Unit != NO_UNIT ) {
                u = (TUnit *)Units [f -> Unit];
                u -> PlaceGround (FALSE);               
                ((TUran*)Units [Uran1]) -> Inventory [((TUran*)Units [Uran1]) 
                -> LoadedUnits++] = u -> ID;
                u -> X = u -> Y = -1;
            }
        }
    }       
    for (i = TU2X1; i <= TU2X2; i++) {
        for (j = TU2Y1; j <= TU2Y2; j++) {
            f = GetField (i, j);
            if (f -> Unit != NO_UNIT ) {
                u = (TUnit *)Units [f -> Unit];
                u -> PlaceGround (FALSE);               
                ((TUran*)Units [Uran2]) -> Inventory [((TUran*)Units [Uran2]) 
                -> LoadedUnits++] = u -> ID;
                u -> X = u -> Y = -1;
            }
        }
    }       
    for (i = TU3X1; i <= TU3X2; i++) {
        for (j = TU3Y1; j <= TU3Y2; j++) {
            f = GetField (i, j);
            if (f -> Unit != NO_UNIT ) {
                u = (TUnit *)Units [f -> Unit];
                u -> PlaceGround (FALSE);               
                ((TUran*)Units [Uran3]) -> Inventory [((TUran*)Units [Uran3]) 
                -> LoadedUnits++] = u -> ID;
                u -> X = u -> Y = -1;
            }
        }
    }       
    for (i = TU4X1; i <= TU4X2; i++) {
        for (j = TU4Y1; j <= TU4Y2; j++) {
            f = GetField (i, j);
            if (f -> Unit != NO_UNIT ) {
                u = (TUnit *)Units [f -> Unit];
                u -> PlaceGround (FALSE);               
                ((TUran*)Units [Uran4]) -> Inventory [((TUran*)Units [Uran4]) 
                -> LoadedUnits++] = u -> ID;
                u -> X = u -> Y = -1;
            }
        }
    }       
    for (i = TU5X1; i <= TU5X2; i++) {
        for (j = TU5Y1; j <= TU5Y2; j++) {
            f = GetField (i, j);
            if (f -> Unit != NO_UNIT ) {
                u = (TUnit *)Units [f -> Unit];
                u -> PlaceGround (FALSE);               
                ((TUran*)Units [Uran5]) -> Inventory [((TUran*)Units [Uran5]) 
                -> LoadedUnits++] = u -> ID;
                u -> X = u -> Y = -1;
            }
        }
    }       
        
    // Polozime miny    
    for (i = 0; MinePlaces19 [i].x != -1; i++) {
        MinePlace (MinePlaces19 [i].x, MinePlaces19 [i].y, BADLIFE);
    }
    
    // zamerime jednotku
    i = GetField (SelX, SelY) -> Unit;  
    Units [i] -> Select ();

    UnlockDraw ();          
    RedrawMap ();

}
Beispiel #9
0
int ArtificialIntelligence7 ()
{
    int i, j, r, st, x, y, id;
    char buf [40];
    TBase *Base;
    TField *f;

    Message (SigText[TXT_AI_ANALYSE]);
    
    // Prepocitame viditelnost
    AllowBadlife (TRUE);
    ComputeVisib ();
    RedrawMap ();
    
    LockDraw ();
    
    // Aktualizujeme specialni objekty
    Base6 = GetField (B6X, B6Y) -> Unit;
    if (Base6 == NO_UNIT || Units [Base6] -> Type % BADLIFE != unBase) 
        Base6 = NO_UNIT;
    Factory2 = GetField (F2X, F2Y) -> Unit;
    if (Factory2 == NO_UNIT || Units [Factory2] -> Type % BADLIFE != unFactory) 
        Factory2 = NO_UNIT;
    Radar2 = GetField (R2X, R2Y) -> Unit;
    if (Radar2 == NO_UNIT || Units [Radar2] -> Type % BADLIFE != unRadar) 
        Radar2 = NO_UNIT;
    Radar3 = GetField (R3X, R3Y) -> Unit;
    if (Radar2 == NO_UNIT || Units [Radar3] -> Type % BADLIFE != unRadar) 
        Radar3 = NO_UNIT;
    Radar4 = GetField (R4X, R4Y) -> Unit;
    if (Radar4 == NO_UNIT || Units [Radar4] -> Type % BADLIFE != unRadar) 
        Radar4 = NO_UNIT;
    Radar5 = GetField (R5X, R5Y) -> Unit;
    if (Radar5 == NO_UNIT || Units [Radar5] -> Type % BADLIFE != unRadar) 
        Radar5 = NO_UNIT;
    Radar6 = GetField (R6X, R6Y) -> Unit;
    if (Radar6 == NO_UNIT || Units [Radar6] -> Type % BADLIFE != unRadar) 
        Radar6 = NO_UNIT;

    // Vyradime znicene jednotky z armad        
    Towers -> DeleteKilled2 (); Towers -> DeleteKilled ();
    Army1 -> DeleteKilled2 (); Army1 -> DeleteKilled ();
    Army2 -> DeleteKilled2 (); Army2 -> DeleteKilled ();
    Army3 -> DeleteKilled2 (); Army3 -> DeleteKilled ();
    Army4 -> DeleteKilled2 (); Army4 -> DeleteKilled ();
    Army5 -> DeleteKilled2 (); Army5 -> DeleteKilled ();
    Army6 -> DeleteKilled2 (); Army6 -> DeleteKilled ();
    Army7 -> DeleteKilled2 (); Army7 -> DeleteKilled ();
    Army8 -> DeleteKilled2 (); Army8 -> DeleteKilled ();
    DUPos = 0;

    // Testneme konec hry   
    st = AssignResult ();
    if (st != 0) {
        UnlockDraw ();  
        AllowBadlife (FALSE);       
        return st;  
    }

    // Zpracujeme seznam poli, na ktere se utocilo
    Army1 -> DoAttackedFields ();
    Army2 -> DoAttackedFields ();
    Army3 -> DoAttackedFields ();
    Army4 -> DoAttackedFields ();
    Army5 -> DoAttackedFields ();
    Army6 -> DoAttackedFields ();
    Army7 -> DoAttackedFields ();
    Army8 -> DoAttackedFields ();
    AttackFieldPos = 0;

    AnalyseLandscape ();    
    
    Message (SigText[TXT_AI_ARMY]);
  
    Army1 -> Status = asActive;
        

  // Likvidace FACTORY II
    if ((Factory2 != NO_UNIT) && (Units[Factory2] != NULL) && ( (GetField(P1X,P1Y) -> Visib == 1) || (GetField(P2X,P2Y) -> Visib == 2) ) ) { 
      UnlockDraw ();
    if ((Pagoda1 != NO_UNIT) && (Units[Pagoda1] != NULL)) {
        Units[Pagoda1] -> Attack(75, 25);
        Units[Pagoda1] -> Attack(75, 25);
    }
    if ((Pagoda2 != NO_UNIT) && (Units[Pagoda2] != NULL)) {
        Units[Pagoda2] -> Attack(75, 28);
        Units[Pagoda2] -> Attack(75, 28);
    }
    LockDraw ();
  }


    // Test zaktivovani armady 2
    if (Army2 -> Status == asSleeping) {
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;
            if (Army2 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army2 -> Status = asActive;
                Army2 -> SetAIConst (1);
            }
        }
    }

    // Test zaktivovani armady 3
    if (Army3 -> Status == asSleeping) {
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;
            if (Army3 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army3 -> Status = asActive;
                Army3 -> SetAIConst (1);
            }
        }
    }

    // Test zaktivovani armady 4
    if (Army4 -> Status == asSleeping) {
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;
            if (Army4 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army4 -> Status = asActive;
                Army4 -> SetAIConst (1);
            }
        }
    }

    // Test zaktivovani armady 5
    if (Army5 -> Status == asSleeping) {
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;
            if (Army5 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army5 -> Status = asActive;
                Army5 -> SetAIConst (2);
            }
        }
    }

    // Test zaktivovani armady 6
    if (Army6 -> Status == asSleeping) {
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;
            if (Army6 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army6 -> Status = asActive;
                Army6 -> SetAIConst (1);
            }
        }
    }

    // Test zaktivovani armady 7
    if (Army7 -> Status == asSleeping) {
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;
            if (Army7 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army7 -> Status = asActive;
                Army7 -> SetAIConst (4);
            }
        }
    }

    // Test zaktivovani armady 8
    if (Army8 -> Status == asSleeping) {
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;
            if (Army8 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army8 -> Status = asActive;
                Army8 -> SetAIConst (1);
            }
        }
    }


    
    // Presun Olympu a Mohykanu
    if (ActualTurn == 1) {
    UnlockDraw();
    if ((Mohykan1 != NO_UNIT) && (Units[Mohykan1] != NULL)) {
      Units[Mohykan1] -> Select ();
      Units[Mohykan1] -> Move(M1DX, M1DY);
      if (Units [Mohykan1] != NULL) Army1 -> Insert (Mohykan1);
    }
    if ((Mohykan2 != NO_UNIT) && (Units[Mohykan2] != NULL)) {
      Units[Mohykan2] -> Select ();
      Units[Mohykan2] -> Move(M2DX, M2DY);
      if (Units [Mohykan2] != NULL) Army1 -> Insert (Mohykan2);
    }
    if ((Mohykan3 != NO_UNIT) && (Units[Mohykan3] != NULL)) {
      Units[Mohykan3] -> Select ();
      Units[Mohykan3] -> Move(M3DX, M3DY);
      if (Units [Mohykan3] != NULL) Army1 -> Insert (Mohykan3);
    }
    if ((Mohykan4 != NO_UNIT) && (Units[Mohykan4] != NULL)) {
      Units[Mohykan4] -> Select ();
      Units[Mohykan4] -> Move(M4DX, M4DY);
      if (Units [Mohykan4] != NULL) Army1 -> Insert (Mohykan4);
    }
    if ((Olymp1 != NO_UNIT) && (Units[Olymp1] != NULL)) {
      Units[Olymp1] -> Select ();
      Units[Olymp1] -> Move(O1DX, O1DY);
      if (Units [Olymp1] != NULL) Army1 -> Insert (Olymp1);
    }
    if ((Olymp2 != NO_UNIT) && (Units[Olymp2] != NULL)) {
      Units[Olymp2] -> Select ();
      Units[Olymp2] -> Move(O2DX, O2DY);
      if (Units [Olymp2] != NULL) Army1 -> Insert (Olymp2);
    }
    if ((Olymp3 != NO_UNIT) && (Units[Olymp3] != NULL)) {
      Units[Olymp3] -> Select ();
      Units[Olymp3] -> Move(O3DX, O3DY);
      if (Units [Olymp3] != NULL) Army1 -> Insert (Olymp3);
    }
    if ((Olymp4 != NO_UNIT) && (Units[Olymp4] != NULL)) {
      Units[Olymp4] -> Select ();
      Units[Olymp4] -> Move(O4DX, O4DY);
      if (Units [Olymp4] != NULL) Army1 -> Insert (Olymp4);
    }
    if ((Mesias1 != NO_UNIT) && (Units [Mesias1] != NULL)) Army1 -> Insert (Mesias1);
    if ((Ganymedes1 != NO_UNIT) && (Units [Ganymedes1] != NULL)) Army1 -> Insert (Ganymedes1);
    LockDraw();
  }
    

    // Dojel Olymp1 - vyklada se...
    if ((Olymp1 != NO_UNIT) && (Units [Olymp1] != NULL) && 
        IsInRect (Units [Olymp1] -> X, Units [Olymp1] -> Y, 
      O1DX, O1DY, O1DX, O1DY)) {
        UnlockDraw ();
        do {
            if (((TOlymp *) Units [Olymp1]) -> LoadedUnits > 0) {
                id = ((TOlymp *) Units [Olymp1]) -> Inventory [0];
                st = ((TOlymp *) Units [Olymp1]) -> UnloadUnit ((TUnit *)Units [id]);
            }
            else st = FALSE;
            if (st > 0) Army1 -> Insert (id);
        }
        while (st == TRUE); 
        LockDraw ();
    }
    
    // Dojel Olymp2 - vyklada se...
    if ((Olymp2 != NO_UNIT) && (Units [Olymp2] != NULL) && 
        IsInRect (Units [Olymp2] -> X, Units [Olymp2] -> Y, 
        O2DX, O2DY, O2DX, O2DY)) {
        UnlockDraw ();
        do {
            if (((TOlymp *) Units [Olymp2]) -> LoadedUnits > 0) {
                id = ((TOlymp *) Units [Olymp2]) -> Inventory [0];
                st = ((TOlymp *) Units [Olymp2]) -> UnloadUnit ((TUnit *)Units [id]);
            }
            else st = FALSE;
            if (st > 0) Army1 -> Insert (id);
        }
        while (st == TRUE); 
        LockDraw ();
        UnlockDraw();
    RedrawMap();
    LockDraw();
    }
    // Dojel Olymp3 - vyklada se...
    if ((Olymp3 != NO_UNIT) && (Units [Olymp3] != NULL) && 
        IsInRect (Units [Olymp3] -> X, Units [Olymp3] -> Y, 
        O3DX, O3DY, O3DX, O3DY)) {
        UnlockDraw ();
        do {
            if (((TOlymp *) Units [Olymp3]) -> LoadedUnits > 0) {
                id = ((TOlymp *) Units [Olymp3]) -> Inventory [0];
                st = ((TOlymp *) Units [Olymp3]) -> UnloadUnit ((TUnit *)Units [id]);
            }
            else st = FALSE;
            if (st > 0) Army1 -> Insert (id);
        }
        while (st == TRUE); 
        LockDraw ();
        UnlockDraw();
    RedrawMap();
    LockDraw();
    }
    // Dojel Olymp4 - vyklada se...
    if ((Olymp4 != NO_UNIT) && (Units [Olymp4] != NULL) && 
        IsInRect (Units [Olymp4] -> X, Units [Olymp4] -> Y, 
        O4DX, O4DY, O4DX, O4DY)) {
        UnlockDraw ();
        do {
            if (((TOlymp *) Units [Olymp4]) -> LoadedUnits > 0) {
                id = ((TOlymp *) Units [Olymp4]) -> Inventory [0];
                st = ((TOlymp *) Units [Olymp4]) -> UnloadUnit ((TUnit *)Units [id]);
            }
            else st = FALSE;
            if (st > 0) Army1 -> Insert (id);
        }
        while (st == TRUE); 
        LockDraw ();
        UnlockDraw();
    RedrawMap();
    LockDraw();
    }
    
    ComputeVisib ();


    // Nastavime ProgressBar
    st = 0;
    st += Towers -> nofBadLife;
    if (Army1 -> Status == asActive || Army1 -> Status == asSuicide) st += Army1 -> nofBadLife;
    if (Army2 -> Status == asActive || Army2 -> Status == asSuicide) st += Army2 -> nofBadLife;
    if (Army3 -> Status == asActive || Army3 -> Status == asSuicide) st += Army3 -> nofBadLife;
    if (Army4 -> Status == asActive || Army4 -> Status == asSuicide) st += Army4 -> nofBadLife;
    if (Army5 -> Status == asActive || Army5 -> Status == asSuicide) st += Army5 -> nofBadLife;
    if (Army6 -> Status == asActive || Army6 -> Status == asSuicide) st += Army6 -> nofBadLife;
    if (Army7 -> Status == asActive || Army7 -> Status == asSuicide) st += Army7 -> nofBadLife;
    if (Army8 -> Status == asActive || Army8 -> Status == asSuicide) st += Army8 -> nofBadLife;
    if (st == 0) st = 5; // Magic number
    ProgressNull ();
    ProgressLimit (st);     

    // Veze
    if (Towers -> MakeTurn () == FALSE) {
        st = AssignResult ();
        if (st != 0) {
            UnlockDraw ();  
            AllowBadlife (FALSE);       
            return st;  
        }
    }

    // ARMY 1
    if (Army1 -> Status == asActive || Army1 -> Status == asSuicide) {
        Army1 -> DeleteKilled ();
        
        // Zarazeni novych nepratel (GL)
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;            
            if (Army1 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army1 -> Insert (i);
            }
        }

        // Pokyn k sebevrazde       
        Army1 -> CountDangerous ();
        if (Army1 -> Dangerous <= CSuicide1) {
            Army1 -> Status = asSuicide;
        }       
        
        // Provedeme akce
        if (Army1 -> MakeTurn () == FALSE) {
            st = AssignResult ();
            if (st != 0) {
                UnlockDraw ();  
                AllowBadlife (FALSE);       
                return st;  
            }
        }

        // Likvidace armady 1
        Army1 -> CountDangerous ();     
        if (Army1 -> Dangerous <= CMinDang1) {
            Army1 -> Status = asDestroyed;          
        }
        
        
    }
    
    
    // ARMY 2
    if (Army2 -> Status == asActive || Army2 -> Status == asSuicide) {
        Army2 -> DeleteKilled ();
        
        // Zarazeni novych nepratel (GL)
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;            
            if (Army2 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army2 -> Insert (i);
            }
        }
        // Pokyn k sebevrazde       
        Army2 -> CountDangerous ();
        if (Army2 -> Dangerous <= CSuicide2) {
            Army2 -> Status = asSuicide;
        }       
        // Provedeme akce
        if (Army2 -> MakeTurn () == FALSE) {
            st = AssignResult ();
            if (st != 0) {
                UnlockDraw ();  
                AllowBadlife (FALSE);       
                return st;  
            }
        }
        // Likvidace armady 2
        if (Army2 -> Dangerous <= CMinDang2) {
            Army2 -> Status = asDestroyed;
        }
    }


    // ARMY 3
    if (Army3 -> Status == asActive || Army3 -> Status == asSuicide) {
        Army3 -> DeleteKilled ();
        
        // Zarazeni novych nepratel (GL)
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;            
            if (Army3 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army3 -> Insert (i);
            }
        }

        // Pokyn k sebevrazde       
        Army3 -> CountDangerous ();
        if (Army3 -> Dangerous <= CSuicide3) {
            Army3 -> Status = asSuicide;
        }       
        
        // Provedeme akce
        if (Army3 -> MakeTurn () == FALSE) {
            st = AssignResult ();
            if (st != 0) {
                UnlockDraw ();  
                AllowBadlife (FALSE);       
                return st;  
            }
        }

        // Likvidace armady 3
        if (Army3 -> Dangerous <= CMinDang3) {
            Army3 -> Status = asDestroyed;
        }
        
    }

    // ARMY 4
    if (Army4 -> Status == asActive || Army4 -> Status == asSuicide) {
        Army4 -> DeleteKilled ();
        
        // Zarazeni novych nepratel (GL)
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;            
            if (Army4 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army4 -> Insert (i);
            }
        }

        // Pokyn k sebevrazde       
        Army4 -> CountDangerous ();
        if (Army4 -> Dangerous <= CSuicide4) {
            Army4 -> Status = asSuicide;
        }       
        
        // Provedeme akce
        if (Army4 -> MakeTurn () == FALSE) {
            st = AssignResult ();
            if (st != 0) {
                UnlockDraw ();  
                AllowBadlife (FALSE);       
                return st;  
            }
        }

        // Likvidace armady 4
        if (Army4 -> Dangerous <= CMinDang4) {
            Army4 -> Status = asDestroyed;
        }
        
    }


    // ARMY 5
    if (Army5 -> Status == asActive || Army5 -> Status == asSuicide) {
        Army5 -> DeleteKilled ();
        
        // Zarazeni novych nepratel (GL)
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;            
            if (Army5 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army5 -> Insert (i);
            }
        }
        // Pokyn k sebevrazde       
        Army5 -> CountDangerous ();
        if (Army5 -> Dangerous <= CSuicide5) {
            Army5 -> Status = asSuicide;
        }       
        // Provedeme akce
        if (Army5 -> MakeTurn () == FALSE) {
            st = AssignResult ();
            if (st != 0) {
                UnlockDraw ();  
                AllowBadlife (FALSE);       
                return st;  
            }
        }
        // Likvidace armady 5
        if (Army5 -> Dangerous <= CMinDang4) {
            Army5 -> Status = asDestroyed;
        }
    }


    // ARMY 6
    if (Army6 -> Status == asActive || Army6 -> Status == asSuicide) {
        Army6 -> DeleteKilled ();
        
        // Zarazeni novych nepratel (GL)
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;            
            if (Army6 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army6 -> Insert (i);
            }
        }
        // Pokyn k sebevrazde       
        Army6 -> CountDangerous ();
        if (Army6 -> Dangerous <= CSuicide6) {
            Army6 -> Status = asSuicide;
        }       
        // Provedeme akce
        if (Army6 -> MakeTurn () == FALSE) {
            st = AssignResult ();
            if (st != 0) {
                UnlockDraw ();  
                AllowBadlife (FALSE);       
                return st;  
            }
        }
        // Likvidace armady 6
        if (Army6 -> Dangerous <= CMinDang6) {
            Army6 -> Status = asDestroyed;
        }
    }



    // ARMY 7
    if (Army7 -> Status == asActive || Army7 -> Status == asSuicide) {
        Army7 -> DeleteKilled ();
        
        // Zarazeni novych nepratel (GL)
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;            
            if (Army7 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army7 -> Insert (i);
            }
        }
        // Pokyn k sebevrazde       
        Army7 -> CountDangerous ();
        if (Army7 -> Dangerous <= CSuicide7) {
            Army7 -> Status = asSuicide;
        }       
        // Provedeme akce
        if (Army7 -> MakeTurn () == FALSE) {
            st = AssignResult ();
            if (st != 0) {
                UnlockDraw ();  
                AllowBadlife (FALSE);       
                return st;  
            }
        }
        // Likvidace armady 7
        if (Army7 -> Dangerous <= CMinDang6) {
            Army7 -> Status = asDestroyed;
        }
    }

    // ARMY 8
    if (Army8 -> Status == asActive || Army8 -> Status == asSuicide) {
        Army8 -> DeleteKilled ();
        
        // Zarazeni novych nepratel (GL)
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;            
            if (Army8 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army8 -> Insert (i);
            }
        }
        // Pokyn k sebevrazde       
        Army8 -> CountDangerous ();
        if (Army8 -> Dangerous <= CSuicide8) {
            Army8 -> Status = asSuicide;
        }       
        // Provedeme akce
        if (Army8 -> MakeTurn () == FALSE) {
            st = AssignResult ();
            if (st != 0) {
                UnlockDraw ();  
                AllowBadlife (FALSE);       
                return st;  
            }
        }
        // Likvidace armady 8
        if (Army8 -> Dangerous <= CMinDang6) {
            Army8 -> Status = asDestroyed;
        }
    }

    AttackFieldPos = 0;
    
    UnlockDraw ();  
    AllowBadlife (FALSE);
//  LockDraw();
    return AssignResult ();

    
}
Beispiel #10
0
void InitAI7 ()
{
    int i,j;
    TBase *Base;
    TField *f;
    TUnit *u;
    
    LockDraw();

    AttackFieldPos = 0;
    DUPos = 0;

    MoneyGoodlife = 600;
    MoneyBadlife = 7000;
    MBPlaces = NULL;
    DeniedPlaces = NULL;

    Base6 = GetField (B6X, B6Y) -> Unit;
    Factory2 = GetField (F2X, F2Y) -> Unit;
    Olymp1 = GetField (O1X, O1Y) -> Unit;
    Olymp2 = GetField (O2X, O2Y) -> Unit;
    Olymp3 = GetField (O3X, O3Y) -> Unit;
    Olymp4 = GetField (O4X, O4Y) -> Unit;
    Mohykan1 = GetField (M1X, M1Y) -> Unit;
    Mohykan2 = GetField (M2X, M2Y) -> Unit;
    Mohykan3 = GetField (M3X, M3Y) -> Unit;
    Mohykan4 = GetField (M4X, M4Y) -> Unit;
    Mesias1 = GetField (Me1X, Me1Y) -> Unit;
    Ganymedes1 = GetField (Ga1X, Ga1Y) -> Unit;
    Radar2 = GetField (R2X, R2Y) -> Unit;
    Pagoda1 = GetField (P1X, P1Y) -> Unit;
    Pagoda2 = GetField (P2X, P2Y) -> Unit;
    
    Towers = new TTowers ();
    for (i = 0; i < UNITS_TOP; i++) {
        if (Units [i] == NULL) continue;
        // vsechny veze a GL
        if ((((TUnit *) Units [i]) -> Type >= (unHorizont + BADLIFE) 
        && ((TUnit *) Units [i]) -> Type  <= (unSpektrum + BADLIFE))
        || (((TUnit *) Units[i]) -> Type < BADLIFE)) 
            Towers -> Insert (i);
    }
    

        
    Army1 = new TGroundArmy();
    Army1 -> SetAR (A1X1, A1Y1, A1X2, A1Y2);
    Army1 -> Status = asActive;
//  Army1 -> WayPoint.x = WP1X; Army1 -> WayPoint.y = WP1Y;
    Army1 -> SetAIConst(2);


    Army2 = new TGroundArmy();
    Army2 -> SetAR (A2X1, A2Y1, A2X2, A2Y2);
    Army2 -> SetRadar (R2X, R2Y);
    Army2 -> InsertUnits ();
    
    Army3 = new TGroundArmy();
    Army3 -> SetAR (A3X1, A3Y1, A3X2, A3Y2);
    Army3 -> SetRadar (R3X, R3Y);
    Army3 -> InsertUnits ();

    Army4 = new TGroundArmy();
    Army4 -> SetAR (A4X1, A4Y1, A4X2, A4Y2);
    Army4 -> SetRadar (R4X, R4Y);
    Army4 -> InsertUnits ();

    Army5 = new TGroundArmy();
    Army5 -> SetAR (A5X1, A5Y1, A5X2, A5Y2);
    Army5 -> SetRadar (R5X, R5Y);
    Army5 -> InsertUnits ();

    Army6 = new TGroundArmy();
    Army6 -> SetAR (A6X1, A6Y1, A6X2, A6Y2);
    Army6 -> SetRadar (R6X, R6Y);
    Army6 -> InsertUnits ();

    Army7 = new TGroundArmy();
    Army7 -> SetAR (A7X1, A7Y1, A7X2, A7Y2);
    Army7 -> InsertUnits ();
    
    Army8 = new TGroundArmy();
    Army8 -> SetAR (A8X1, A8Y1, A8X2, A8Y2);
    Army8 -> InsertUnits ();
    
    // Jednotky do Olympu
    for (i = TO1X1; i <= TO1X2; i++) {
        for (j = TO1Y1; j <= TO1Y2; j++) {
            f = GetField (i, j);
            if (f -> Unit != NO_UNIT) {
                u = (TUnit *)Units [f -> Unit];
                u -> PlaceGround (FALSE);               
                ((TOlymp*)Units [Olymp1]) -> Inventory [((TOlymp*)Units [Olymp1]) 
                -> LoadedUnits++] = u -> ID;
                u -> X = u -> Y = -1;
            }
        }
    }       
    for (i = TO2X1; i <= TO2X2; i++) {
        for (j = TO2Y1; j <= TO2Y2; j++) {
            f = GetField (i, j);
            if (f -> Unit != NO_UNIT) {
                u = (TUnit *)Units [f -> Unit];
                u -> PlaceGround (FALSE);               
                ((TOlymp*)Units [Olymp2]) -> Inventory [((TOlymp*)Units [Olymp2]) 
                -> LoadedUnits++] = u -> ID;
                u -> X = u -> Y = -1;
            }
        }
    }       
    for (i = TO3X1; i <= TO3X2; i++) {
        for (j = TO3Y1; j <= TO3Y2; j++) {
            f = GetField (i, j);
            if (f -> Unit != NO_UNIT) {
                u = (TUnit *)Units [f -> Unit];
                u -> PlaceGround (FALSE);               
                ((TOlymp*)Units [Olymp3]) -> Inventory [((TOlymp*)Units [Olymp3]) 
                -> LoadedUnits++] = u -> ID;
                u -> X = u -> Y = -1;
            }
        }
    }       
    for (i = TO4X1; i <= TO4X2; i++) {
        for (j = TO4Y1; j <= TO4Y2; j++) {
            f = GetField (i, j);
            if (f -> Unit != NO_UNIT) {
                u = (TUnit *)Units [f -> Unit];
                u -> PlaceGround (FALSE);               
                ((TOlymp*)Units [Olymp4]) -> Inventory [((TOlymp*)Units [Olymp4])
                -> LoadedUnits++] = u -> ID;
                u -> X = u -> Y = -1;
            }
        }
    }       
    
    // Polozime miny
    
    for (i = 0; MinePlaces7 [i].x != -1; i++) {
        MinePlace (MinePlaces7 [i].x, MinePlaces7 [i].y, BADLIFE);
    }
    UnlockDraw ();          


}
Beispiel #11
0
int ArtificialIntelligence9 ()
{
    int i, st;

    Message (SigText[TXT_AI_ANALYSE]);

    // Prepocitame viditelnost
    AllowBadlife (TRUE);
    ComputeVisib ();
    RedrawMap ();
    
    LockDraw ();
    
    // Aktualizujeme specialni objekty
    Factory1 = GetField (F1X, F1Y) -> Unit;
    if (Factory1 == NO_UNIT || Units [Factory1] -> Type % BADLIFE != unFactory) 
        Factory1 = NO_UNIT;
    Factory2 = GetField (F2X, F2Y) -> Unit;
    if (Factory2 == NO_UNIT || Units [Factory2] -> Type % BADLIFE != unFactory) 
        Factory2 = NO_UNIT;

    // Vyradime znicene jednotky z armad    
    Towers -> DeleteKilled2 (); Towers -> DeleteKilled ();
    Army1 -> DeleteKilled2 (); Army1 -> DeleteKilled ();
    Army2 -> DeleteKilled2 (); Army2 -> DeleteKilled ();
    Army3 -> DeleteKilled2 (); Army3 -> DeleteKilled ();
    Army4 -> DeleteKilled2 (); Army4 -> DeleteKilled ();
    Army5 -> DeleteKilled2 (); Army5 -> DeleteKilled ();
    Army6 -> DeleteKilled2 (); Army6 -> DeleteKilled ();
    Army7 -> DeleteKilled2 (); Army7 -> DeleteKilled ();
    Army8 -> DeleteKilled2 (); Army8 -> DeleteKilled ();
    Army9 -> DeleteKilled2 (); Army9 -> DeleteKilled ();
    Army10 -> DeleteKilled2 (); Army10 -> DeleteKilled ();
    DUPos = 0;
    
    // Testneme konec hry   
    st = AssignResult ();
    if (st != 0) {
        UnlockDraw ();  
        AllowBadlife (FALSE);       
        return st;  
    }

    // Zpracujeme seznam poli, na ktere se utocilo
    Army1 -> DoAttackedFields ();
    Army2 -> DoAttackedFields ();
    Army3 -> DoAttackedFields ();
    Army4 -> DoAttackedFields ();
    Army5 -> DoAttackedFields ();
    Army6 -> DoAttackedFields ();
    Army7 -> DoAttackedFields ();
    Army8 -> DoAttackedFields ();
    Army9 -> DoAttackedFields ();
    Army10 -> DoAttackedFields ();
    AttackFieldPos = 0;
    
    AnalyseLandscape ();    
    
    Message (SigText[TXT_AI_ARMY]);



//////////////////////////////// AKTIVACE ARMAD

    // Test zaktivovani armady 1
    if (Army1 -> Status == asSleeping) {
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;
            if (Army1 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army1 -> Status = asActive;
            }
        }
    }
    // Test zaktivovani armady 2
    if (Army2 -> Status == asSleeping) {
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;
            if (Army2 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army2 -> Status = asActive;
            }
        }
    }
    // Test zaktivovani armady 3
    if (Army3 -> Status == asSleeping) {
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;
            if (Army3 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army3 -> Status = asActive;
            }
        }
    }
    // Test zaktivovani armady 4
    if (Army4 -> Status == asSleeping) {
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;
            if (Army4 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army4 -> Status = asActive;
            }
        }
    }
    // Test zaktivovani armady 5
    if (Army5 -> Status == asSleeping) {
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;
            if (Army5 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army5 -> Status = asActive;
            }
        }
    }
    // Test zaktivovani armady 6
    if (Army6 -> Status == asSleeping) {
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;
            if (Army6 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army6 -> Status = asActive;
                ActivationTurn9 = ActualTurn + 1;
            }
        }
    }
    // Test zaktivovani armady 7
    if (Army7 -> Status == asSleeping) {
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;
            if (Army7 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army7 -> Status = asActive;
            }
        }
    }
    // Test zaktivovani armady 8
    if (Army8 -> Status == asSleeping) {
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;
            if (Army8 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army8 -> Status = asActive;
                ActivationTurn9 = ActualTurn + 1;
            }
        }
    }
    
    // Test zaktivovani armady 9
    if (Army8 -> Status == asSleeping) {
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] != NULL && Units [i] -> Y > A9AZY) {
                ActivationTurn9 = ActualTurn;
                break;
            }
        }
    }
    
    if (ActivationTurn9 == ActualTurn && Army9 -> Status == asSleeping) {
        Army9 -> Status = asActive;
        Army9 -> Place ();
        Army9 -> SetAIConst (3);
        Army9 -> WayPoint.x = A9WP1X; Army9 -> WayPoint.y = A9WP1Y;
    }
    // Test zaktivovani armady 10
    if (Army10 -> Status == asSleeping) {
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;
            if (Army10 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army10 -> Status = asActive;
            }
        }
    }
        

///////////////////////////// AKCE ARMAD

    // Nastavime ProgressBar
    st = 0;
    st += Towers -> nofBadLife;
    if (Army1 -> Status == asActive || Army1 -> Status == asSuicide) st += Army1 -> nofBadLife;
    if (Army2 -> Status == asActive || Army2 -> Status == asSuicide) st += Army2 -> nofBadLife;
    if (Army3 -> Status == asActive || Army3 -> Status == asSuicide) st += Army3 -> nofBadLife;
    if (Army4 -> Status == asActive || Army4 -> Status == asSuicide) st += Army4 -> nofBadLife;
    if (Army5 -> Status == asActive || Army5 -> Status == asSuicide) st += Army5 -> nofBadLife;
    if (Army6 -> Status == asActive || Army6 -> Status == asSuicide) st += Army6 -> nofBadLife;
    if (Army7 -> Status == asActive || Army7 -> Status == asSuicide) st += Army7 -> nofBadLife;
    if (Army8 -> Status == asActive || Army8 -> Status == asSuicide) st += Army8 -> nofBadLife;
    if (Army9 -> Status == asActive || Army9 -> Status == asSuicide) st += Army9 -> nofBadLife;
    if (Army10 -> Status == asActive || Army10 -> Status == asSuicide) st += Army10 -> nofBadLife;
    if (st == 0) st = 5; // Magic number
    ProgressNull ();
    ProgressLimit (st);     

    // Veze
    if (Towers -> MakeTurn () == FALSE) {
        st = AssignResult ();
        if (st != 0) {
            UnlockDraw ();  
            AllowBadlife (FALSE);       
            return st;  
        }
    }

    
    // ARMY 1
    if (Army1 -> Status == asActive || Army1 -> Status == asSuicide) {
        Army1 -> DeleteKilled ();
        
        // Zarazeni novych nepratel (GL)
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;            
            if (Army1 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army1 -> Insert (i);
            }
        }

        // Pokyn k sebevrazde       
        Army1 -> CountDangerous ();
        if (Army1 -> Dangerous <= CSuicide1) {
            Army1 -> Status = asSuicide;
        }       
        
        // Provedeme akce
        if (Army1 -> MakeTurn () == FALSE) {
            st = AssignResult ();
            if (st != 0) {
                UnlockDraw ();  
                AllowBadlife (FALSE);       
                return st;  
            }
        }

        // Likvidace armady 1
        Army1 -> CountDangerous ();     
        if (Army1 -> Dangerous <= CMinDang1) {
            Army1 -> Status = asDestroyed;          
        }
        
        
    }
    
    // ARMY 2
    if (Army2 -> Status == asActive || Army2 -> Status == asSuicide) {
        Army2 -> DeleteKilled ();
        
        // Zarazeni novych nepratel (GL)
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;            
            if (Army2 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army2 -> Insert (i);
            }
        }

        // Pokyn k sebevrazde       
        Army2 -> CountDangerous ();
        if (Army2 -> Dangerous <= CSuicide2) {
            Army2 -> Status = asSuicide;
        }       
        
        // Provedeme akce
        if (Army2 -> MakeTurn () == FALSE) {
            st = AssignResult ();
            if (st != 0) {
                UnlockDraw ();  
                AllowBadlife (FALSE);       
                return st;  
            }
        }

        // Likvidace armady 2
        if (Army2 -> Dangerous <= CMinDang2) {
            Army2 -> Status = asDestroyed;
        }
        
    }

    // ARMY 3
    if (Army3 -> Status == asActive || Army3 -> Status == asSuicide) {
        Army3 -> DeleteKilled ();
        
        // Zarazeni novych nepratel (GL)
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;            
            if (Army3 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army3 -> Insert (i);
            }
        }

        // Pokyn k sebevrazde       
        Army3 -> CountDangerous ();
        if (Army3 -> Dangerous <= CSuicide3) {
            Army3 -> Status = asSuicide;
        }       
        
        // Provedeme akce
        if (Army3 -> MakeTurn () == FALSE) {
            st = AssignResult ();
            if (st != 0) {
                UnlockDraw ();  
                AllowBadlife (FALSE);       
                return st;  
            }
        }
        
        // Likvidace armady 3
        if (Army3 -> Dangerous <= CMinDang3) {
            Army3 -> Status = asDestroyed;
        }
                
    }

                    
    // ARMY 4
    if (Army4 -> Status == asActive || Army4 -> Status == asSuicide) {
        Army4 -> DeleteKilled ();

        // Zarazeni novych nepratel (GL)
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;            
            if (Army4 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army4 -> Insert (i);
            }
        }
        
        // Pokyn k sebevrazde       
        Army4 -> CountDangerous ();
        if (Army4 -> Dangerous <= CSuicide4) {
            Army4 -> Status = asSuicide;
        }       
        
        // Provedeme akce
        if (Army4 -> MakeTurn () == FALSE) {
            st = AssignResult ();
            if (st != 0) {
                UnlockDraw ();  
                AllowBadlife (FALSE);       
                return st;  
            }
        }
        
        // Likvidace armady 4
        if (Army4 -> Dangerous <= CMinDang4) {
            Army4 -> Status = asDestroyed;
        }               
    }
    

    // ARMY 5
    if (Army5 -> Status == asActive || Army5 -> Status == asSuicide) {
        Army5 -> DeleteKilled ();

        // Zarazeni novych nepratel (GL)
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;            
            if (Army5 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army5 -> Insert (i);
            }
        }
        
        // Pokyn k sebevrazde       
        Army5 -> CountDangerous ();
        if (Army5 -> Dangerous <= CSuicide5) {
            Army5 -> Status = asSuicide;
        }       
        
        // Provedeme akce
        if (Army5 -> MakeTurn () == FALSE) {
            st = AssignResult ();
            if (st != 0) {
                UnlockDraw ();  
                AllowBadlife (FALSE);       
                return st;  
            }
        }
        
        // Likvidace armady 5
        if (Army5 -> Dangerous <= CMinDang5) {
            Army5 -> Status = asDestroyed;
        }               
    }


    // ARMY 6
    if (Army6 -> Status == asActive || Army6 -> Status == asSuicide) {
        Army6 -> DeleteKilled ();

        // Zarazeni novych nepratel (GL)
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;            
            if (Army6 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army6 -> Insert (i);
            }
        }
        
        // Pokyn k sebevrazde       
        Army6 -> CountDangerous ();
        if (Army6 -> Dangerous <= CSuicide6) {
            Army6 -> Status = asSuicide;
        }       
        
        // Provedeme akce
        if (Army6 -> MakeTurn () == FALSE) {
            st = AssignResult ();
            if (st != 0) {
                UnlockDraw ();  
                AllowBadlife (FALSE);       
                return st;  
            }
        }
        
        // Likvidace armady 6
        if (Army6 -> Dangerous <= CMinDang6) {
            Army6 -> Status = asDestroyed;
        }               
    }

    // ARMY 7
    if (Army7 -> Status == asActive || Army7 -> Status == asSuicide) {
        Army7 -> DeleteKilled ();

        // Zarazeni novych nepratel (GL)
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;            
            if (Army7 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army7 -> Insert (i);
            }
        }
        
        // Pokyn k sebevrazde       
        Army7 -> CountDangerous ();
        if (Army7 -> Dangerous <= CSuicide7) {
            Army7 -> Status = asSuicide;
        }       
        
        // Provedeme akce
        if (Army7 -> MakeTurn () == FALSE) {
            st = AssignResult ();
            if (st != 0) {
                UnlockDraw ();  
                AllowBadlife (FALSE);       
                return st;  
            }
        }
        
        // Likvidace armady 7
        if (Army7 -> Dangerous <= CMinDang7) {
            Army7 -> Status = asDestroyed;
        }               
    }

    // ARMY 8
    if (Army8 -> Status == asActive || Army8 -> Status == asSuicide) {
        Army8 -> DeleteKilled ();

        // Zarazeni novych nepratel (GL)
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;            
            if (Army8 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army8 -> Insert (i);
            }
        }
        
        // Pokyn k sebevrazde       
        Army8 -> CountDangerous ();
        if (Army8 -> Dangerous <= CSuicide8) {
            Army8 -> Status = asSuicide;
        }       
        
        // Provedeme akce
        if (Army8 -> MakeTurn () == FALSE) {
            st = AssignResult ();
            if (st != 0) {
                UnlockDraw ();  
                AllowBadlife (FALSE);       
                return st;  
            }
        }
        
        // Likvidace armady 8
        if (Army8 -> Dangerous <= CMinDang8) {
            Army8 -> Status = asDestroyed;
        }               
    }

    // ARMY 9
    if (Army9 -> Status == asActive || Army9 -> Status == asSuicide) {
        Army9 -> DeleteKilled ();

        // Zarazeni novych nepratel (GL)
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;            
            if (Army9 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army9 -> Insert (i);
            }
        }
        
        // Pokyn k sebevrazde       
        Army9 -> CountDangerous ();
        if (Army9 -> Dangerous <= CSuicide9) {
            Army9 -> Status = asSuicide;
        }       
        
        // Provedeme akce
        if (Army9 -> MakeTurn () == FALSE) {
            st = AssignResult ();
            if (st != 0) {
                UnlockDraw ();  
                AllowBadlife (FALSE);       
                return st;  
            }
        }
        
        // Likvidace armady 9
        if (Army9 -> Dangerous <= CMinDang9) {
            Army9 -> Status = asDestroyed;
        }               
    }
    // ARMY 10
    if (Army10 -> Status == asActive || Army10 -> Status == asSuicide) {
        Army10 -> DeleteKilled ();

        // Zarazeni novych nepratel (GL)
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;            
            if (Army10 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army10 -> Insert (i);
            }
        }
        
        // Pokyn k sebevrazde       
        Army10 -> CountDangerous ();
        if (Army10 -> Dangerous <= CSuicide10) {
            Army10 -> Status = asSuicide;
        }       
        
        // Provedeme akce
        if (Army10 -> MakeTurn () == FALSE) {
            st = AssignResult ();
            if (st != 0) {
                UnlockDraw ();  
                AllowBadlife (FALSE);       
                return st;  
            }
        }
        
        // Likvidace armady 10
        if (Army10 -> Dangerous <= CMinDang10) {
            Army10 -> Status = asDestroyed;
        }               
    }

    AttackFieldPos = 0;
    
    UnlockDraw ();  
    AllowBadlife (FALSE);
    return AssignResult ();

    
}
Beispiel #12
0
void InitAI9 ()
{
    int i;

    LockDraw ();        
    
    AttackFieldPos = 0;
    DUPos = 0;

    MoneyGoodlife = 0;
    MoneyBadlife = 7000;
    MBPlaces = NULL;    
    DeniedPlaces = NULL;
    
    ActivationTurn9 = 55;

    Gargantua1 = GetField (G1X, G1Y) -> Unit;
    Gargantua2 = GetField (G2X, G2Y) -> Unit;
    Gargantua3 = GetField (G3X, G3Y) -> Unit;
    Factory1 = GetField (F1X, F1Y) -> Unit;
    Factory2 = GetField (F2X, F2Y) -> Unit;
            
    Towers = new TTowers ();
    for (i = 0; i < UNITS_TOP; i++) {
        if (Units [i] == NULL) continue;
        // vsechny veze a GL
        if ((((TUnit *) Units [i]) -> Type >= (unHorizont + BADLIFE) 
        && ((TUnit *) Units [i]) -> Type  <= (unSpektrum + BADLIFE))
        || (((TUnit *) Units[i]) -> Type < BADLIFE)) 
            Towers -> Insert (i);
    }
    
    Army1 = new TGroundArmy();
    Army1 -> SetAR (A1X1, A1Y1, A1X2, A1Y2);
    Army1 -> SetRadar (R1X, R1Y);
    Army1 -> InsertUnits ();

    Army2 = new TGroundArmy();
    Army2 -> SetAR (A2X1, A2Y1, A2X2, A2Y2);
    Army2 -> SetRadar (R2X, R2Y);
    Army2 -> InsertUnits ();
    
    Army3 = new TGroundArmy();
    Army3 -> SetAR (A3X1, A3Y1, A3X2, A3Y2);
    Army3 -> SetRadar (R3X, R3Y);
    Army3 -> InsertUnits ();

    Army4 = new TGroundArmy();
    Army4 -> SetAR (A4X1, A4Y1, A4X2, A4Y2);
    Army4 -> SetRadar (R4X, R4Y);
    Army4 -> InsertUnits ();

    Army5 = new TGroundArmy();
    Army5 -> SetAR (A5X1, A5Y1, A5X2, A5Y2);
    Army5 -> SetRadar (-1, -1);
    Army5 -> InsertUnits ();

    Army6 = new TGroundArmy();
    Army6 -> SetAR (A6X1, A6Y1, A6X2, A6Y2);
    Army6 -> SetRadar (R6X, R6Y);
    Army6 -> InsertUnits ();

    Army7 = new TGroundArmy();
    Army7 -> SetAR (A7X1, A7Y1, A7X2, A7Y2);
    Army7 -> SetRadar (R7X, R7Y);
    Army7 -> InsertUnits ();

    Army8 = new TGroundArmy();
    Army8 -> SetAR (A8X1, A8Y1, A8X2, A8Y2);
    Army8 -> SetRadar (R8X, R8Y);
    Army8 -> InsertUnits ();

    Army9 = new TGroundArmy();
    Army9 -> SetAR (A9X1, A9Y1, A9X2, A9Y2);
    Army9 -> SetRadar (-1, -1);
    Army9 -> InsertUnits ();
    Army9 -> WayPoint.x = A9WP1X; Army9 -> WayPoint.y = A9WP1Y;
    Army9 -> Displace ();

    Army10 = new TGroundArmy();
    Army10 -> SetAR (A9X1, A9Y1, A9X2, A9Y2);
    Army10 -> SetRadar (-1, -1);
    Army10 -> InsertUnits ();
    
    // Polozime miny
    
    for (i = 0; MinePlaces9 [i].x != -1; i++) {
        MinePlace (MinePlaces9 [i].x, MinePlaces9 [i].y, BADLIFE);
    }

    // zamerime jednotku
    i = GetField (SelX, SelY) -> Unit;  
    Units [i] -> Select ();


    UnlockDraw ();          
    
    RedrawMap ();
}
Beispiel #13
0
int TTowers::ProblemJednotky (int Unit)
{
        int i, ix, shot, weapon;
        TObject *Target;
        double hmax;

        if (Unit < 0 || Unit >= UNITS_TOP) {
#ifdef DEBUG
                fprintf (dbgOutput, "Error: ProblemJednotky Unit = %i \n",Unit);
#endif
                AIError ();
                return TRUE;
        }
        if (Units [Unit] == NULL) {
#ifdef DEBUG
                fprintf (dbgOutput, "Error: ProblemJednotky Unit %i (=NULL) \n",Unit);
#endif
                AIError ();
                return TRUE;
        }

        UnlockDraw ();
        // HORIZONT - nutno vyzkouset
        if (Units [Unit] -> Type % BADLIFE == unHorizont) {
                Target = NULL;

                do {
                        if (DeleteKilled () == FALSE) return FALSE;
                        MakeDangerArray ();
                        hmax = 0;

                        for (i = 0; i < nofGoodLife; i++) { // Pro vsechny GL
                                ProcessMapAnim ();
                                weapon = ChooseWeapon (Unit, GL [i]);
                                if (weapon == -1) continue;
                                if ((AttackStatus (Unit, weapon, GL [i], 1) > hmax)  // Vyberu nejlepsi cil
                                && (((TUnit *)Units [Unit]) -> Weapons [weapon] ->
                                IsInRange (Units [Unit], Units [Unit]   -> X, Units [Unit] -> Y
                                , Units [GL[i]] -> X, Units [GL[i]] -> Y))) {
                                        hmax = AttackStatus (Unit, weapon, GL [i], 1);
                                        Target = Units [GL[i]];
                                        ix = i;
                                }
                        }

                        if (hmax > 0) {  // Nasel jsem cil a de se strilet
                                Units [Unit] -> Select ();
                                shot = Units [Unit] -> Attack (Target -> X, Target -> Y);
                                if (DeleteKilled () == FALSE) {
                                        RedrawMap ();
                                        LockDraw (); // Konec hry
                                        return FALSE;
                                }
                                if (Units [Unit] == NULL) {
                                        RedrawMap ();
                                        LockDraw (); // vez znicena
                                        return TRUE;
                                }
                        }

                }
                while ((Units [Unit] -> TimeUnits >=
                ((TUnit *)Units [Unit]) -> Weapons[0] -> TimeLost) && (hmax > 0));
          // hraju si dokud je cas na strelbu a je na co strilet
        }


        // THOR - komplet
        if (Units [Unit] -> Type % BADLIFE == unThor) {
                Target = NULL;
                do {
                        if (DeleteKilled () == FALSE) return FALSE;
                        MakeDangerArray ();
                        hmax = 0;

                        for (i = 0; i < nofGoodLife; i++) { // pro vsechny GL
                                ProcessMapAnim ();
                                weapon = ChooseWeapon (Unit, GL [i]);
                                if (weapon == -1) continue;
                                if ((AttackStatus (Unit, weapon, GL [i], 1) > hmax)  // vybereme nejlepsi cil
                                && (((TThor *)Units [Unit]) -> Weapons [weapon] -> IsInRange (Units [Unit]
                                , Units [Unit] -> X, Units [Unit] -> Y
                                , Units [GL[i]] -> X, Units [GL[i]] -> Y))) {
                                        hmax = AttackStatus (Unit, weapon, GL [i], 1);
                                        Target = Units [GL[i]];
                                        ix = i;
                                }
                        }

                        if ((hmax <= 0) || (((TThor *)Units [Unit]) -> Weapons [0] -> Ammo <= 0)) {
                           // zalezeme, protoze neni na co strilet, nebo dosli naboje
                                if (((TThor *)Units [Unit]) -> IsOverground) {
                                        Units [Unit] -> Select ();
                                        ((TThor *)Units [Unit]) -> GoOverground (0);
                                }
                        }

                        if (hmax > 0) { // Tady se bude strilet!!!
                                if (((TThor *)Units [Unit]) -> IsOverground) {  // je-li venku - pal!
                                Units [Unit] -> Select ();
                                shot = ((TThor *)Units [Unit]) -> Attack (Target -> X, Target -> Y);
                                        if (DeleteKilled () == FALSE) {
                                                LockDraw ();
                                                return FALSE;
                                        }
                                }
                                else {  //neni-li venku - vyleze
                                        Units [Unit] -> Select ();
                                        ((TThor *)Units [Unit]) -> GoOverground (1);
                                }
                        }

                }

                while ((((TThor *)Units [Unit]) -> TimeUnits >=
                ((TThor *)Units [Unit]) -> Weapons[0] -> TimeLost) && (hmax > 0));
                  // hraju si dokud je cas na strelbu a je na co strilet


        }

        // PAGODA, MINOTAURUS a SPEKTRUM - komplet
        if ((Units [Unit] -> Type % BADLIFE == unPagoda)
        || (Units [Unit] -> Type % BADLIFE == unMinotaurus)
        || (Units [Unit] -> Type % BADLIFE == unSpektrum)) {
                Target = NULL;

                do {
                        if (DeleteKilled () == FALSE) return FALSE;
                        MakeDangerArray ();
                        hmax = 0;

                        for (i = 0; i < nofGoodLife; i++) { // Pro vsechny GL
                                ProcessMapAnim ();
                                weapon = ChooseWeapon (Unit, GL [i]);
                                if (weapon == -1) continue;

                                if ((AttackStatus (Unit, weapon, GL [i], 1) > hmax)  // Vyberu nejlepsi cil
                                && (((TUnit *)Units [Unit]) -> Weapons [weapon] -> IsInRange (Units [Unit]
                                , Units [Unit] -> X, Units [Unit] -> Y
                                , Units [GL[i]] -> X, Units [GL[i]] -> Y))) {
                                        hmax = AttackStatus (Unit, weapon, GL [i], 1);
                                        Target = Units [GL[i]];
                                        ix = i;
                                }
                        }

                        if (hmax > 0) {  // Nasel jsem cil a de se strilet
                                Units [Unit] -> Select ();
                                shot = ((TUnit *)Units [Unit]) -> Attack (Target -> X, Target -> Y);
                                if (DeleteKilled () == FALSE) {
                                        RedrawMap ();
                                        LockDraw ();
                                        return FALSE;
                                }
                                if (Units [Unit] == NULL) {
                                        RedrawMap ();
                                        LockDraw ();
                                        return TRUE;
                                }
                        }

                }
                while ((((TUnit *)Units [Unit]) -> TimeUnits
                >= ((TUnit *)Units [Unit]) -> Weapons[0] -> TimeLost) && (hmax > 0));
          // hraju si dokud je cas na strelbu a je na co strilet
        }

        RedrawMap ();
        LockDraw ();
        return TRUE;
}
Beispiel #14
0
void InitAI17 ()
{
    int i,j;
    TField *f;
    TUnit *u;

    LockDraw ();            

    AttackFieldPos = 0;
    DUPos = 0;

    MoneyGoodlife = 0;
    MoneyBadlife = 10000;
    MBPlaces = NULL;
    DeniedPlaces = NULL;

    Oasa1 = GetField (O1X, O1Y) -> Unit;    
    Oasa2 = GetField (O2X, O2Y) -> Unit;    
    Oasa3 = GetField (O3X, O3Y) -> Unit;    
    Oasa4 = GetField (O4X, O4Y) -> Unit;    
    Oasa5 = GetField (O5X, O5Y) -> Unit;        Oasa6 = GetField (O6X, O6Y) -> Unit;        Neptun1 = GetField (N1X, N1Y) -> Unit;      Neptun2 = GetField (N2X, N2Y) -> Unit;      Laguna1 = GetField (L1X, L1Y) -> Unit;
    Laguna2 = GetField (L2X, L2Y) -> Unit;

    Factory1 = GetField (F1X, F1Y) -> Unit; 
    Base1 = GetField (B1X, B1Y) -> Unit;    


    Towers = new TTowers ();
    for (i = 0; i < UNITS_TOP; i++) {
        if (Units [i] == NULL) continue;
        // vsechny veze a GL
        if ((((TUnit *) Units [i]) -> Type >= (unHorizont + BADLIFE) 
        && ((TUnit *) Units [i]) -> Type  <= (unSpektrum + BADLIFE))
        || (((TUnit *) Units[i]) -> Type < BADLIFE)) 
            Towers -> Insert (i);
    }
    
    Army1 = new TGroundArmy();
    Army1 -> SetAR (A1X1, A1Y1, A1X2, A1Y2);
    Army1 -> SetRadar (-1, -1);
    Army1 -> InsertUnits ();

    Army2 = new TGroundArmy();
    Army2 -> SetAR (A2X1, A2Y1, A2X2, A2Y2);
    Army2 -> SetRadar (-1, -1);
    Army2 -> InsertUnits ();
    
    Army3 = new TGroundArmy();
    Army3 -> SetAR (A3X1, A3Y1, A3X2, A3Y2);
    Army3 -> SetRadar (-1, -1);
    Army3 -> InsertUnits ();

    Army4 = new TGroundArmy();
    Army4 -> SetAR (A4X1, A4Y1, A4X2, A4Y2);
    Army4 -> SetRadar (-1, -1);
    Army4 -> InsertUnits ();

    Army5 = new TGroundArmy();
    Army5 -> SetAR (A5X1, A5Y1, A5X2, A5Y2);
    Army5 -> SetRadar (R5X, R5Y);
    Army5 -> InsertUnits ();

    Army6 = new TGroundArmy();
    Army6 -> SetAR (A6X1, A6Y1, A6X2, A6Y2);
    Army6 -> SetRadar (R6X, R6Y);
    Army6 -> InsertUnits ();

    Army7 = new TGroundArmy();
    Army7 -> SetAR (A7X1, A7Y1, A7X2, A7Y2);
    Army7 -> SetRadar (R7X, R7Y);
    Army7 -> InsertUnits ();

    Marine1 = new TMarine ();
    Marine1 -> SetAR (M1X1, M1Y1, M1X2, M1Y2);
    Marine1 -> SetRadar (-1, -1);
    Marine1 -> InsertUnits ();
    Marine1 -> Status = asActive;
    Marine1 -> SetAIConst (2);
    Marine1 -> Insert (Oasa5);

    Marine2 = new TMarine ();
    Marine2 -> SetAR (M2X1, M2Y1, M2X2, M2Y2);
    Marine2 -> SetRadar (-1, -1);
    Marine2 -> InsertUnits ();
    Marine2 -> Status = asActive;
    Marine2 -> SetAIConst (2);
    Marine2 -> Insert (Oasa5);

    AirArmy1 = new TAirArmy();
    AirArmy1 -> SetAR (AA1X1, AA1Y1, AA1X2, AA1Y2);
    AirArmy1 -> SetRadar (-1, -1);
    AirArmy1 -> InsertUnits ();
    AirArmy1 -> Status = asActive;
    AirArmy1 -> Insert (Oasa5);
    

    AirArmy2 = new TAirArmy();
    AirArmy2 -> SetAR (AA2X1, AA2Y1, AA2X2, AA2Y2);
    AirArmy2 -> SetRadar (R2X, R2Y);
    AirArmy2 -> InsertUnits ();
    AirArmy2 -> Status = asActive;

    AirArmy3 = new TAirArmy();
    AirArmy3 -> SetAR (AA3X1, AA3Y1, AA3X2, AA3Y2);
    AirArmy3 -> SetRadar (-1, -1);
    AirArmy3 -> InsertUnits ();
    AirArmy3 -> Status = asActive;

    // Naplnime Oasy
    for (i = TO1X1; i <= TO1X2; i++) {
        for (j = TO1Y1; j <= TO1Y2; j++) {
            f = GetField (i, j);
            if (f -> Unit != NO_UNIT ) {
                u = (TUnit *)Units [f -> Unit];
                u -> PlaceGround (FALSE);               
                ((TOasa*)Units [Oasa1]) -> Inventory [((TOasa*)Units [Oasa1]) 
                -> LoadedUnits++] = u -> ID;
                u -> X = u -> Y = -1;
            }
        }
    }       
    for (i = TO2X1; i <= TO2X2; i++) {
        for (j = TO2Y1; j <= TO2Y2; j++) {
            f = GetField (i, j);
            if (f -> Unit != NO_UNIT ) {
                u = (TUnit *)Units [f -> Unit];
                u -> PlaceGround (FALSE);               
                ((TOasa*)Units [Oasa2]) -> Inventory [((TOasa*)Units [Oasa2]) 
                -> LoadedUnits++] = u -> ID;
                u -> X = u -> Y = -1;
            }
        }
    }       
    for (i = TO3X1; i <= TO3X2; i++) {
        for (j = TO3Y1; j <= TO3Y2; j++) {
            f = GetField (i, j);
            if (f -> Unit != NO_UNIT ) {
                u = (TUnit *)Units [f -> Unit];
                u -> PlaceGround (FALSE);               
                ((TOasa*)Units [Oasa3]) -> Inventory [((TOasa*)Units [Oasa3]) 
                -> LoadedUnits++] = u -> ID;
                u -> X = u -> Y = -1;
            }
        }
    }       
    for (i = TO4X1; i <= TO4X2; i++) {
        for (j = TO4Y1; j <= TO4Y2; j++) {
            f = GetField (i, j);
            if (f -> Unit != NO_UNIT ) {
                u = (TUnit *)Units [f -> Unit];
                u -> PlaceGround (FALSE);               
                ((TOasa*)Units [Oasa4]) -> Inventory [((TOasa*)Units [Oasa4]) 
                -> LoadedUnits++] = u -> ID;
                u -> X = u -> Y = -1;
            }
        }
    }       
    for (i = TO5X1; i <= TO5X2; i++) {
        for (j = TO5Y1; j <= TO5Y2; j++) {
            f = GetField (i, j);
            if (f -> Unit != NO_UNIT ) {
                u = (TUnit *)Units [f -> Unit];
                u -> PlaceGround (FALSE);               
                ((TOasa*)Units [Oasa5]) -> Inventory [((TOasa*)Units [Oasa5]) 
                -> LoadedUnits++] = u -> ID;
                u -> X = u -> Y = -1;
            }
        }
    }       
    for (i = TO6X1; i <= TO6X2; i++) {
        for (j = TO6Y1; j <= TO6Y2; j++) {
            f = GetField (i, j);
            if (f -> Unit != NO_UNIT ) {
                u = (TUnit *)Units [f -> Unit];
                u -> PlaceGround (FALSE);               
                ((TOasa*)Units [Oasa6]) -> Inventory [((TOasa*)Units [Oasa6]) 
                -> LoadedUnits++] = u -> ID;
                u -> X = u -> Y = -1;
            }
        }
    }       

    // Naplnime Neptuny
    for (i = TN1X1; i <= TN1X2; i++) {
        for (j = TN1Y1; j <= TN1Y2; j++) {
            f = GetField (i, j);
            if (f -> Unit != NO_UNIT ) {
                u = (TUnit *)Units [f -> Unit];
                u -> PlaceGround (FALSE);               
                ((TNeptun*)Units [Neptun1]) -> Inventory [((TNeptun*)Units [Neptun1]) 
                -> LoadedUnits++] = u -> ID;
                u -> X = u -> Y = -1;
            }
        }
    }       
    for (i = TN2X1; i <= TN2X2; i++) {
        for (j = TN2Y1; j <= TN2Y2; j++) {
            f = GetField (i, j);
            if (f -> Unit != NO_UNIT ) {
                u = (TUnit *)Units [f -> Unit];
                u -> PlaceGround (FALSE);               
                ((TNeptun*)Units [Neptun2]) -> Inventory [((TNeptun*)Units [Neptun2]) 
                -> LoadedUnits++] = u -> ID;
                u -> X = u -> Y = -1;
            }
        }
    }       

    // Naplnime Laguny
    for (i = TL1X1; i <= TL1X2; i++) {
        for (j = TL1Y1; j <= TL1Y2; j++) {
            u = GetAircraftAt (i, j);
            if (u != NULL) {
                u -> PlaceGround (FALSE);               
                ((TLaguna*)Units [Laguna1]) -> Inventory [((TLaguna*)Units [Laguna1]) 
                -> LoadedUnits++] = u -> ID;
                u -> X = u -> Y = -1;
            }
        }
    }       
    for (i = TL2X1; i <= TL2X2; i++) {
        for (j = TL2Y1; j <= TL2Y2; j++) {
            u = GetAircraftAt (i, j);
            if (u != NULL) {
                u -> PlaceGround (FALSE);               
                ((TLaguna*)Units [Laguna2]) -> Inventory [((TLaguna*)Units [Laguna2]) 
                -> LoadedUnits++] = u -> ID;
                u -> X = u -> Y = -1;
            }
        }
    }       
        
    // Polozime miny    
    for (i = 0; MinePlaces17 [i].x != -1; i++) {
        MinePlace (MinePlaces17 [i].x, MinePlaces17 [i].y, BADLIFE);
    }
    
    // zamerime jednotku
    i = GetField (SelX, SelY) -> Unit;  
    Units [i] -> Select ();

    UnlockDraw ();          
    RedrawMap ();

}
Beispiel #15
0
int ArtificialIntelligence5 ()
{
    int i, j, k, r, st, x, y, id;
    TPoint p;
    char buf [40];
    TBase *Base;
    TField *f;

    Message (SigText[TXT_AI_ANALYSE]);

    // Prepocitame viditelnost
    AllowBadlife (TRUE);
    ComputeVisib ();
    RedrawMap ();
    
    LockDraw ();
    
    // Aktualizujeme specialni objekty
    Base1 = GetField (B1X, B1Y) -> Unit;
    if (Base1 == NO_UNIT || Units [Base1] -> Type % BADLIFE != unBase) 
        Base1 = NO_UNIT;
    Base8 = GetField (B8X, B8Y) -> Unit;
    if (Base8 == NO_UNIT || Units [Base8] -> Type % BADLIFE != unBase) 
        Base8 = NO_UNIT;
    Radar1 = GetField (R1X, R1Y) -> Unit;
    if (Radar1 == NO_UNIT || Units [Radar1] -> Type % BADLIFE != unRadar) 
        Radar1 = NO_UNIT;
    Radar2 = GetField (R2X, R2Y) -> Unit;
    if (Radar2 == NO_UNIT || Units [Radar2] -> Type % BADLIFE != unRadar) 
        Radar2 = NO_UNIT;
    Radar4 = GetField (R4X, R4Y) -> Unit;
    if (Radar4 == NO_UNIT || Units [Radar4] -> Type % BADLIFE != unRadar) 
        Radar4 = NO_UNIT;
    Radar5 = GetField (R5X, R5Y) -> Unit;
    if (Radar5 == NO_UNIT || Units [Radar5] -> Type % BADLIFE != unRadar) 
        Radar5 = NO_UNIT;
    Radar8 = GetField (R8X, R8Y) -> Unit;
    if (Radar8 == NO_UNIT || Units [Radar8] -> Type % BADLIFE != unRadar) 
        Radar8 = NO_UNIT;       
    Factory8 = GetField (F8X, F8Y) -> Unit;
    if (Factory8 == NO_UNIT || Units [Factory8] -> Type % BADLIFE != unFactory) 
        Factory8 = NO_UNIT;
    Airport1 = GetField (A1X, A1Y) -> Unit;
    if (Airport1 == NO_UNIT || Units [Airport1] -> Type % BADLIFE != unAirport) 
        Airport1 = NO_UNIT;
    Airport8 = GetField (A8X, A8Y) -> Unit;
    if (Airport8 == NO_UNIT || Units [Airport8] -> Type % BADLIFE != unAirport) 
        Airport8 = NO_UNIT;

    // Vyradime znicene jednotky z armad    
    Towers -> DeleteKilled2 (); Towers -> DeleteKilled ();
    Army1 -> DeleteKilled2 (); Army1 -> DeleteKilled ();
    AirArmy1 -> DeleteKilled2 (); AirArmy1 -> DeleteKilled ();
    Army2 -> DeleteKilled2 (); Army2 -> DeleteKilled ();
    Army3 -> DeleteKilled2 (); Army3 -> DeleteKilled ();
    Army4 -> DeleteKilled2 (); Army4 -> DeleteKilled ();
    Army5 -> DeleteKilled2 (); Army5 -> DeleteKilled ();
    Army6 -> DeleteKilled2 (); Army6 -> DeleteKilled ();
    Army7 -> DeleteKilled2 (); Army7 -> DeleteKilled ();
    Army8 -> DeleteKilled2 (); Army8 -> DeleteKilled ();
    AirArmy8 -> DeleteKilled2 (); AirArmy8 -> DeleteKilled ();
    DUPos = 0;
    
    // Testneme konec hry   
    st = AssignResult ();
    if (st != 0) {
        UnlockDraw ();  
        AllowBadlife (FALSE);       
        return st;  
    }

    // Zpracujeme seznam poli, na ktere se utocilo
    Army1 -> DoAttackedFields ();
    AirArmy1 -> DoAttackedFields ();
    Army2 -> DoAttackedFields ();
    Army3 -> DoAttackedFields ();
    Army4 -> DoAttackedFields ();
    Army5 -> DoAttackedFields ();
    Army6 -> DoAttackedFields ();
    Army7 -> DoAttackedFields ();
    Army8 -> DoAttackedFields ();
    AirArmy8 -> DoAttackedFields ();
    AttackFieldPos = 0;

    AnalyseLandscape ();    
    
    Message (SigText[TXT_AI_ARMY]);     


//////////////////////////////// AKTIVACE ARMAD
    
    // Test zaktivovani armady 1
    if (Army1 -> Status == asSleeping) {
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;
            if (Army1 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army1 -> Status = asActive;
            }
        }
    }

    // Test zaktivovani armady 2
    if (Army2 -> Status == asSleeping) {
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;
            if (Army2 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army2 -> Status = asActive;
                Army2 -> SetAIConst (2); // AGRESIVE ARMY
            }
        }
    }
    if (Army2 -> Status == asActive) {
        if (Army2 -> Dangerous <= A2Escape && Army2 -> WayPoint.x == -1) {
            Army2 -> SetAIConst (3); // MOVING ARMY
            Army2 -> WayPoint.x = A2WP1X; Army2 -> WayPoint.y = A2WP1Y;         
        }
        if (Army2 -> IsAtWP () 
        && Army2 -> WayPoint.x == A2WP1X && Army2 -> WayPoint.y == A2WP1Y) {
            Army2 -> WayPoint.x = A2WP2X; Army2 -> WayPoint.y = A2WP2Y;
        }
        if (Army2 -> IsAtWP () 
        && Army2 -> WayPoint.x == A2WP2X && Army2 -> WayPoint.y == A2WP2Y) {
            Army2 -> SetAIConst (1);
            Xenon3ActivationTurn = ActualTurn;
        }   
    }
    
    
    // Test zaktivovani armady 3
    if (Army3 -> Status == asSleeping) {
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;
            if (Army3 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army3 -> Status = asActive;
            }
        }
    }
    
    // Test zaktivovani armady 4
    if (Army4 -> Status == asSleeping) {
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;
            if (Army4 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army4 -> Status = asActive;
            }
        }
    }

    // Test zaktivovani armady 5
    if (Army5 -> Status == asSleeping) {
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;
            if (Army5 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army5 -> Status = asActive;
            }
        }
    }
    // Test zaktivovani armady 6
    if (Army6 -> Status == asSleeping) {
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;
            if (Army6 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army6 -> Status = asActive;
            }
        }
    }

    // Test zaktivovani armady 7
    if (Army7 -> Status == asSleeping) {
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;
            if (Army7 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army7 -> Status = asActive;
            }
        }
    }


    // Test zaktivovani armady 8
    if (Army8 -> Status == asSleeping) {
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;
            if (Army8 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army8 -> Status = asActive;
            }
        }
    }
    

///////////////////////////// AKCE ARMAD

    // Nastavime ProgressBar
    st = 0;
    st += Towers -> nofBadLife;
    if (Army1 -> Status == asActive || Army1 -> Status == asSuicide) st += Army1 -> nofBadLife;
    if (AirArmy1 -> Status == asActive || AirArmy1 -> Status == asSuicide) st += AirArmy1 -> nofBadLife;
    if (Army2 -> Status == asActive || Army2 -> Status == asSuicide) st += Army2 -> nofBadLife;
    if (Army3 -> Status == asActive || Army3 -> Status == asSuicide) st += Army3 -> nofBadLife;
    if (Army4 -> Status == asActive || Army4 -> Status == asSuicide) st += Army4 -> nofBadLife;
    if (Army5 -> Status == asActive || Army5 -> Status == asSuicide) st += Army5 -> nofBadLife;
    if (Army6 -> Status == asActive || Army6 -> Status == asSuicide) st += Army6 -> nofBadLife;
    if (Army7 -> Status == asActive || Army7 -> Status == asSuicide) st += Army7 -> nofBadLife;
    if (Army8 -> Status == asActive || Army8 -> Status == asSuicide) st += Army8 -> nofBadLife;
    if (AirArmy8 -> Status == asActive || AirArmy8 -> Status == asSuicide) st += AirArmy8 -> nofBadLife;
    if (st == 0) st = 5; // Magic number
    ProgressNull ();
    ProgressLimit (st);     

    // Vylozime letiste
    UnlockDraw ();
    for (i = BADLIFE; i < UNITS_TOP; i++){
        // Airport
        if (Units [i] != NULL && Units [i] -> Type - BADLIFE == unAirport) {            
            for (j = 0; j < ((TAirport *) Units [i]) -> LoadedUnits; j++) {
                id = ((TAirport *)Units [i]) -> Inventory [j];
                if (Units [id] -> AI_Info.State == aistFuel) {
                    st = ((TAirport *)Units [i]) -> UnloadUnit ((TUnit *)Units [id]);
                    if (st == 1) {
                        j--;
                        Units [id] -> AI_Info.State = aistNought;
                        for (k = 120; k > 1; k--) {
                            p = CartezianSnail (k);
                            p.x += Units [id] -> X; p.y += Units [id] -> Y;
                            if (p.x >= 0 && p.x < MapSizeX && p.y >= 0 && p.y < MapSizeY
                            && GetAircraftAt (p.x, p.y) == NULL) {
                                Units [id] -> Select ();
                                st = Units [id] -> MoveFar (p.x, p.y);
                                if (st == 1) break;
                                
                            }
                        }
                    }
                }
            }
        }
        // Heliport
        if (Units [i] != NULL && Units [i] -> Type - BADLIFE == unHeliport) {           
            for (j = 0; j < ((THeliport *) Units [i]) -> LoadedUnits; j++) {
                id = ((THeliport *)Units [i]) -> Inventory [j];
                if (Units [id] -> AI_Info.State == aistFuel) {
                    st = ((THeliport *)Units [i]) -> UnloadUnit ((TUnit *)Units [id]);
                    if (st == 1) {
                        j--;
                        Units [id] -> AI_Info.State = aistNought;
                        for (k = 120; k > 1; k--) {
                            p = CartezianSnail (k);
                            p.x += Units [id] -> X; p.y += Units [id] -> Y;
                            if (p.x >= 0 && p.x < MapSizeX && p.y >= 0 && p.y < MapSizeY
                            && GetAircraftAt (p.x, p.y) == NULL) {
                                Units [id] -> Select ();
                                st = Units [id] -> MoveFar (p.x, p.y);
                                if (st == 1) break;
                            }
                        }
                    }
                }
            }
        }
        // Laguna
        if (Units [i] != NULL && Units [i] -> Type - BADLIFE == unLaguna) {         
            for (j = 0; j < ((TLaguna *) Units [i]) -> LoadedUnits; j++) {
                id = ((TLaguna *)Units [i]) -> Inventory [j];
                if (Units [id] -> AI_Info.State == aistFuel) {
                    st = ((TLaguna *)Units [i]) -> UnloadUnit ((TUnit *)Units [id]);
                    if (st == 1) {
                        j--;
                        Units [id] -> AI_Info.State = aistNought;
                        for (k = 120; k > 1; k--) {
                            p = CartezianSnail (k);
                            p.x += Units [id] -> X; p.y += Units [id] -> Y;
                            if (p.x >= 0 && p.x < MapSizeX && p.y >= 0 && p.y < MapSizeY
                            && GetAircraftAt (p.x, p.y) == NULL) {
                                Units [id] -> Select ();
                                st = Units [id] -> MoveFar (p.x, p.y);
                                if (st == 1) break;
                            }
                        }
                    }
                }
            }
        }
        
    }
    LockDraw ();


    // Veze
    if (Towers -> MakeTurn () == FALSE) {
        st = AssignResult ();
        if (st != 0) {
            UnlockDraw ();  
            AllowBadlife (FALSE);       
            return st;  
        }
    }

    
    // ARMY 1
    if (Army1 -> Status == asActive || Army1 -> Status == asSuicide) {
        Army1 -> DeleteKilled ();
        
        // Zarazeni novych nepratel (GL)
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;            
            if (Army1 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army1 -> Insert (i);
            }
        }

        // Pokyn k sebevrazde       
        Army1 -> CountDangerous ();
        if (Army1 -> Dangerous <= CSuicide1) {
            Army1 -> Status = asSuicide;
        }       
        
        // Provedeme akce
        if (Army1 -> MakeTurn () == FALSE) {
            st = AssignResult ();
            if (st != 0) {
                UnlockDraw ();  
                AllowBadlife (FALSE);       
                return st;  
            }
        }

        // Likvidace armady 1
        Army1 -> CountDangerous ();     
        if (Army1 -> Dangerous <= CMinDang1) {
            Army1 -> Status = asDestroyed;          
        }
        
        
    }
    if (AirArmy1 -> Status == asActive || AirArmy1 -> Status == asSuicide) {
        AirArmy1 -> DeleteKilled ();
        
        // Zarazeni novych nepratel (GL)
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;            
            if (AirArmy1 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                AirArmy1 -> Insert (i);
            }
        }

        // Pokyn k sebevrazde       
        AirArmy1 -> CountDangerous ();
        if (AirArmy1 -> Dangerous <= CSuicideA1) {
            AirArmy1 -> Status = asSuicide;
        }       
        
        // Provedeme akce
        if (AirArmy1 -> MakeTurn () == FALSE) {
            st = AssignResult ();
            if (st != 0) {
                UnlockDraw ();  
                AllowBadlife (FALSE);       
                return st;  
            }
        }

        // Likvidace armady 1
        AirArmy1 -> CountDangerous ();      
        if (AirArmy1 -> Dangerous <= CMinDangA1) {
            AirArmy1 -> Status = asDestroyed;           
        }
        
        
    }
    
    // ARMY 2
    if (Army2 -> Status == asActive || Army2 -> Status == asSuicide) {
        Army2 -> DeleteKilled ();
        
        // Zarazeni novych nepratel (GL)
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;            
            if (Army2 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army2 -> Insert (i);
            }
        }

        // Pokyn k sebevrazde       
        Army2 -> CountDangerous ();
        if (Army2 -> Dangerous <= CSuicide2) {
            Army2 -> Status = asSuicide;
        }       
        
        // Provedeme akce
        if (Army2 -> MakeTurn () == FALSE) {
            st = AssignResult ();
            if (st != 0) {
                UnlockDraw ();  
                AllowBadlife (FALSE);       
                return st;  
            }
        }

        // Likvidace armady 2
        if (Army2 -> Dangerous <= CMinDang2) {
            Army2 -> Status = asDestroyed;
        }
        
    }

    // ARMY 3
    if (Army3 -> Status == asActive || Army3 -> Status == asSuicide) {
        Army3 -> DeleteKilled ();
        
        // Zarazeni novych nepratel (GL)
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;            
            if (Army3 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army3 -> Insert (i);
            }
        }

        // Pokyn k sebevrazde       
        Army3 -> CountDangerous ();
        if (Army3 -> Dangerous <= CSuicide3) {
            Army3 -> Status = asSuicide;
        }       
        
        // Provedeme akce
        if (Army3 -> MakeTurn () == FALSE) {
            st = AssignResult ();
            if (st != 0) {
                UnlockDraw ();  
                AllowBadlife (FALSE);       
                return st;  
            }
        }
        
        // Likvidace armady 3
        if (Army3 -> Dangerous <= CMinDang3) {
            Army3 -> Status = asDestroyed;
        }
                
    }

    // ARMY 4
    if (Army4 -> Status == asActive || Army4 -> Status == asSuicide) {
        Army4 -> DeleteKilled ();

        // Zarazeni novych nepratel (GL)
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;            
            if (Army4 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army4 -> Insert (i);
            }
        }
        
        // Pokyn k sebevrazde       
        Army4 -> CountDangerous ();
        if (Army4 -> Dangerous <= CSuicide4) {
            Army4 -> Status = asSuicide;
        }       
        
        // Provedeme akce
        if (Army4 -> MakeTurn () == FALSE) {
            st = AssignResult ();
            if (st != 0) {
                UnlockDraw ();  
                AllowBadlife (FALSE);       
                return st;  
            }
        }
        
        // Likvidace armady 4
        if (Army4 -> Dangerous <= CMinDang4) {
            Army4 -> Status = asDestroyed;
        }               
    }
    

    // ARMY 5
    if (Army5 -> Status == asActive || Army5 -> Status == asSuicide) {
        Army5 -> DeleteKilled ();

        // Zarazeni novych nepratel (GL)
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;            
            if (Army5 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army5 -> Insert (i);
            }
        }
        
        // Pokyn k sebevrazde       
        Army5 -> CountDangerous ();
        if (Army5 -> Dangerous <= CSuicide5) {
            Army5 -> Status = asSuicide;
        }       
        
        // Provedeme akce
        if (Army5 -> MakeTurn () == FALSE) {
            st = AssignResult ();
            if (st != 0) {
                UnlockDraw ();  
                AllowBadlife (FALSE);       
                return st;  
            }
        }
        
        // Likvidace armady 5
        if (Army5 -> Dangerous <= CMinDang5) {
            Army5 -> Status = asDestroyed;
        }               
    }


    // ARMY 6
    if (Army6 -> Status == asActive || Army6 -> Status == asSuicide) {
        Army6 -> DeleteKilled ();

        // Zarazeni novych nepratel (GL)
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;            
            if (Army6 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army6 -> Insert (i);
            }
        }
        
        // Pokyn k sebevrazde       
        Army6 -> CountDangerous ();
        if (Army6 -> Dangerous <= CSuicide6) {
            Army6 -> Status = asSuicide;
        }       
        
        // Provedeme akce
        if (Army6 -> MakeTurn () == FALSE) {
            st = AssignResult ();
            if (st != 0) {
                UnlockDraw ();  
                AllowBadlife (FALSE);       
                return st;  
            }
        }
        
        // Likvidace armady 6
        if (Army6 -> Dangerous <= CMinDang6) {
            Army6 -> Status = asDestroyed;
        }               
    }

    // ARMY 7
    if (Army7 -> Status == asActive || Army7 -> Status == asSuicide) {
        Army7 -> DeleteKilled ();

        // Zarazeni novych nepratel (GL)
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;            
            if (Army7 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army7 -> Insert (i);
            }
        }
        
        // Pokyn k sebevrazde       
        Army7 -> CountDangerous ();
        if (Army7 -> Dangerous <= CSuicide7) {
            Army7 -> Status = asSuicide;
        }       
        
        // Provedeme akce
        if (Army7 -> MakeTurn () == FALSE) {
            st = AssignResult ();
            if (st != 0) {
                UnlockDraw ();  
                AllowBadlife (FALSE);       
                return st;  
            }
        }
        
        // Likvidace armady 7
        if (Army7 -> Dangerous <= CMinDang7) {
            Army7 -> Status = asDestroyed;
        }               
    }

    // ARMY 8
    if (Army8 -> Status == asActive || Army8 -> Status == asSuicide) {
        Army8 -> DeleteKilled ();

        // Zarazeni novych nepratel (GL)
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;            
            if (Army8 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                Army8 -> Insert (i);
            }
        }
        
        // Pokyn k sebevrazde       
        Army8 -> CountDangerous ();
        if (Army8 -> Dangerous <= CSuicide8) {
            Army8 -> Status = asSuicide;
        }       
        
        // Provedeme akce
        if (Army8 -> MakeTurn () == FALSE) {
            st = AssignResult ();
            if (st != 0) {
                UnlockDraw ();  
                AllowBadlife (FALSE);       
                return st;  
            }
        }
        
        // Likvidace armady 8
        if (Army8 -> Dangerous <= CMinDang8) {
            Army8 -> Status = asDestroyed;
        }               
    }

    // AIR ARMY 8
    if (AirArmy8 -> Status == asActive || AirArmy8 -> Status == asSuicide) {
        AirArmy8 -> DeleteKilled ();

        // Zarazeni novych nepratel (GL)
        for (i = 0; i < BADLIFE; i++) {
            if (Units [i] == NULL) continue;            
            if (Army8 -> IsInVisualRange (Units [i] -> X, Units [i] -> Y)) {
                AirArmy8 -> Insert (i);
            }
        }
        
        // Pokyn k sebevrazde       
        AirArmy8 -> CountDangerous ();
        if (AirArmy8 -> Dangerous <= CSuicide8) {
            AirArmy8 -> Status = asSuicide;
        }       
        
        // Provedeme akce
        if (AirArmy8 -> MakeTurn () == FALSE) {
            st = AssignResult ();
            if (st != 0) {
                UnlockDraw ();  
                AllowBadlife (FALSE);       
                return st;  
            }
        }
        
        // Likvidace armady 8
        if (AirArmy8 -> Dangerous <= CMinDang8) {
            AirArmy8 -> Status = asDestroyed;
        }               
    }


    // Xenon 3
    if (Xenon3 != NO_UNIT && Units [Xenon3] != NULL && Units [Xenon3] -> Type - BADLIFE == unXenon
    && Xenon3ActivationTurn <= ActualTurn && X3MineCnt >= 0) {
        for (i = X3MineCnt; Xenon3Mines [i].x != -1; i++) {
            UnlockDraw ();
            st = ((TXenon *)Units [Xenon3]) 
            -> MoveFar (Xenon3Mines [i].x, Xenon3Mines [i].y);
            if (Units [Xenon3] == NULL) {
                LockDraw (); // Jednotka znicena
                break;
            }
            if (st) {
                st = ((TXenon *)Units [Xenon3]) -> PlaceMine ();
                if (st) {
                    X3MineCnt++;
                    if (X3MineCnt == 3) ((TXenon *)Units [Xenon3]) 
                        -> MoveFar (A2WP2X, A2WP2Y);
                }
            }
            LockDraw ();            
        }
    }




    AttackFieldPos = 0;
    
    UnlockDraw ();  
    AllowBadlife (FALSE);
    return AssignResult (); 
}
Beispiel #16
0
void InitAI5 ()
{
    int i,j;
    TBase *Base;
    THeliport *Heliport;
    TAirport *Airport;
    TField *f;
    TUnit *u;
    
    LockDraw ();
    
    AttackFieldPos = 0;
    DUPos = 0;

    MoneyGoodlife = 0;
    MoneyBadlife = 5000;
    MBPlaces = NULL;    
    DeniedPlaces = NULL;

    ActivationTurn1 = MaxInt;
    ActivationTurn2 = MaxInt;
    ActivationTurn3 = MaxInt;
    ActivationTurn4 = MaxInt;
    ActivationTurn5 = MaxInt;
    ActivationTurn6 = MaxInt;
    ActivationTurn7 = MaxInt;
    ActivationTurn8 = MaxInt;
    Xenon3ActivationTurn = MaxInt;
    X3MineCnt = 0;

    Base1 = GetField (B1X, B1Y) -> Unit;
    Base8 = GetField (B8X, B8Y) -> Unit;
    Radar1 = GetField (R1X, R1Y) -> Unit;
    Radar2 = GetField (R2X, R2Y) -> Unit;
    Radar4 = GetField (R4X, R4Y) -> Unit;
    Radar5 = GetField (R5X, R5Y) -> Unit;
    Radar8 = GetField (R8X, R8Y) -> Unit;
    Factory8 = GetField (F8X, F8Y) -> Unit;
    Airport1 = GetField (A1X, A1Y) -> Unit;
    Airport8 = GetField (A8X, A8Y) -> Unit;
    Heliport4 = GetField (H4X, H4Y) -> Unit;
    
    Xenon3 = GetField (X3X, X3Y) -> Unit;
    
    for (i = BADLIFE; i < UNITS_TOP; i++) {
        if (Units [i] != NULL && Units [i] -> X == K1X && Units [i] -> Y == K1Y) {
            Kobra1 = i;
            break;
        }
    }
    
    
        
    Towers = new TTowers ();
    for (i = 0; i < UNITS_TOP; i++) {
        if (Units [i] == NULL) continue;
        // vsechny veze a GL
        if ((((TUnit *) Units [i]) -> Type >= (unHorizont + BADLIFE) 
        && ((TUnit *) Units [i]) -> Type  <= (unSpektrum + BADLIFE))
        || (((TUnit *) Units[i]) -> Type < BADLIFE)) 
            Towers -> Insert (i);
    }
    

        
    Army1 = new TGroundArmy();
    Army1 -> SetAR (A1X1, A1Y1, A1X2, A1Y2);
    Army1 -> SetRadar (R1X, R1Y);
    Army1 -> WayPoint.x = A1WPX; Army1 -> WayPoint.y = A1WPY; 
    Army1 -> InsertUnits ();

    AirArmy1 = new TAirArmy ();
    AirArmy1 -> SetAR (AA1X1, AA1Y1, AA1X2, AA1Y2); 
    AirArmy1 -> WayPoint.x = A1WPX; AirArmy1 -> WayPoint.y = A1WPY;     
    AirArmy1 -> SetAIConst (2); // AGRESIVE ARMY
    AirArmy1 -> Status = asActive;
    AirArmy1 -> InsertUnits ();
        

    Army2 = new TGroundArmy();
    Army2 -> SetAR (A2X1, A2Y1, A2X2, A2Y2);
    Army2 -> SetRadar (R2X, R2Y);
    Army2 -> InsertUnits ();
    
    Army3 = new TGroundArmy();
    Army3 -> SetAR (A3X1, A3Y1, A3X2, A3Y2);
    Army3 -> SetRadar (-1, -1);
    Army3 -> InsertUnits ();

    Army4 = new TGroundArmy();
    Army4 -> SetAR (A4X1, A4Y1, A4X2, A4Y2);
    Army4 -> SetRadar (R4X, R4Y);
    Army4 -> InsertUnits ();

    Army5 = new TGroundArmy();
    Army5 -> SetAR (A5X1, A5Y1, A5X2, A5Y2);
    Army5 -> SetRadar (R5X, R5Y);
    Army5 -> InsertUnits ();

    Army6 = new TGroundArmy();
    Army6 -> SetAR (A6X1, A6Y1, A6X2, A6Y2);
    Army6 -> SetRadar (-1, -1);
    Army6 -> InsertUnits ();

    Army7 = new TGroundArmy();
    Army7 -> SetAR (A7X1, A7Y1, A7X2, A7Y2);
    Army7 -> SetRadar (-1, -1);
    Army7 -> InsertUnits ();

    Army8 = new TGroundArmy();
    Army8 -> SetAR (A8X1, A8Y1, A8X2, A8Y2);
    Army8 -> SetRadar (R8X, R8Y);
    Army8 -> InsertUnits ();
    
    AirArmy8 = new TAirArmy ();
    AirArmy8 -> SetAR (AA8X1, AA8Y1, AA8X2, AA8Y2);
    AirArmy8 -> SetRadar (R8X, R8Y);
    AirArmy8 -> Status = asActive;
    AirArmy8 -> InsertUnits ();

    
    // Jednotky do zakladny
    Base = (TBase*)Units [Base1];
    for (i = TB1X1; i <= TB1X2; i++) {
        for (j = TB1Y1; j <= TB1Y2; j++) {
            f = GetField (i, j);
            if ((f -> Unit != NO_UNIT) && (f -> Unit >= BADLIFE)) {
                u = (TUnit *)Units [f -> Unit];
                u -> PlaceGround (FALSE);               
                Base -> Inventory [Base -> LoadedUnits++] = u -> ID;
                u -> X = u -> Y = -1;
                
            }
        }
    }
    // Kobra 1 do Airportu
    Airport = (TAirport*)Units [Airport1];
    Units [Kobra1] -> PlaceGround (FALSE);
    Airport -> Inventory [Airport -> LoadedUnits++] = Kobra1;
    Units [Kobra1] -> X = Units [Kobra1] -> Y = -1;
    
    // Rexove do Heliportu 4
    Heliport = (THeliport *)Units [Heliport4];
    for (i = TH4X1; i <= TH4X2; i++) {
        for (j = TH4Y1; j <= TH4Y2; j++) {
            u = GetAircraftAt (i, j);
            if ((u != NULL) && (u -> Type >= BADLIFE)) {
                u -> PlaceGround (FALSE);               
                Heliport -> Inventory [Heliport -> LoadedUnits++] = u -> ID;
                u -> X = u -> Y = -1;
                
            }
        }
    }
    
    
    // Polozime miny
    for (i = 0; MinePlaces5 [i].x != -1; i++) {
        MinePlace (MinePlaces5 [i].x, MinePlaces5 [i].y, BADLIFE);
    }
    
    UnlockDraw ();          


///////////////////////////////////////////////////////////////////



    

}