Seite 159 von 162 ErsteErste ... 59109149155156157158159160161162 LetzteLetzte
Ergebnis 2.371 bis 2.385 von 2421

Thema: BASE: SDK & Python Diskussion (Coder's Lair)

  1. #2371
    Waddehaddedudeda Avatar von Cybah
    Registriert seit
    01.09.06
    Beiträge
    30.455
    Drullo und ich haben gerade folgenden Fehler gehabt (mit Absturz, reproduzierbar (6.1)):

    Assert Failed

    File: CvGlobals.cpp
    Line: 2500
    Expression: eImprovementNum > -1
    Message:

    Was sagt der Fehler aus?

    Wenn ich als Japan (eigentlich Drullo) alleine starte, kommt er nicht. Wenn ich als Inka starte, kommt der Fehler, egal ob alleine geladen oder mit Drullo.
    Pucc's Lets Plays BASE 6.0: #1 #2 #3 #4 #5

    Download von BASE 6.4 [D]: HIER (klick mich!) (Stand: 08.07.2022)

  2. #2372
    Waddehaddedudeda Avatar von Cybah
    Registriert seit
    01.09.06
    Beiträge
    30.455
    Scheint nen Fehler von dir zu sein

    PHP-Code:
                                                if(!(pLoopPlot->getNonObsoleteBonusType(getTeam()) != NO_BONUS && !GC.getImprovementInfo(pLoopPlot->getImprovementType()).isImprovementBonusMakesValid(pLoopPlot->getBonusType())))
                                                {
                                                    if (
    pLoopPlot->getImprovementType() != NO_IMPROVEMENT && pLoopPlot->getImprovementType() != GC.getRUINS_IMPROVEMENT()) 
    Die NO_IMPROVEMENT Abfrage muss vermutlich eins höher?


    Edit:
    Geändert von Cybah (27. Juni 2015 um 02:11 Uhr)
    Pucc's Lets Plays BASE 6.0: #1 #2 #3 #4 #5

    Download von BASE 6.4 [D]: HIER (klick mich!) (Stand: 08.07.2022)

  3. #2373
    Waddehaddedudeda Avatar von Cybah
    Registriert seit
    01.09.06
    Beiträge
    30.455
    Crash in > CvGameCoreDLL.dll!CvPlayerAI::AI_foundValue(int iX=199, int iY=28, int iMinRivalRange=-1, bool bStartingLoc=true) Line 4410 + 0x48 bytes C++

    PHP-Code:
    File:  CvPlayerAI.cpp
    Line
    :  4601
    Expression
    :  iValue >= 0
    Message


    Verweist wird auf diese Rechnung:

    PHP-Code:
            if(iDistance 6)
            {
                
    iValue /= 100 std::min(iValue 10000, (iDistance 6) * 10);
            } 

    Und der Fehler tritt auf einer ultragigantischen Karte auf.

    http://www.civforum.de/showthread.ph...=1#post6789979
    Pucc's Lets Plays BASE 6.0: #1 #2 #3 #4 #5

    Download von BASE 6.4 [D]: HIER (klick mich!) (Stand: 08.07.2022)

  4. #2374
    Civ4 BASE Coder Avatar von rucivfan
    Registriert seit
    10.07.11
    Ort
    Antarktika
    Beiträge
    19.017
    Cybah: Das muss falsch von dir sein. Wenn das Zeile 4601 wäre, müsste was mit "iValue >= 0" in ihr stehen. Tut es nicht.

  5. #2375
    Waddehaddedudeda Avatar von Cybah
    Registriert seit
    01.09.06
    Beiträge
    30.455
    Die Expression ist die obere. Der Callstack verweist dennoch (auch?) auf das untere.

    Aber kannste dir ja selbst nochmal angucken. Savepost ist hier verlinkt.
    Pucc's Lets Plays BASE 6.0: #1 #2 #3 #4 #5

    Download von BASE 6.4 [D]: HIER (klick mich!) (Stand: 08.07.2022)

  6. #2376
    Civ4 BASE Coder Avatar von rucivfan
    Registriert seit
    10.07.11
    Ort
    Antarktika
    Beiträge
    19.017
    Die Expression Meldung ist zwar ein Indiz auf den Fehler, aber steht trotzdem in keinen direkten Zusammenhang mit den Fehler. Betrifft nur Karten größer als Riesig wegen Integerüberlauf und einer damit einhergehenden möglichen Division durch 0.

  7. #2377
    Waddehaddedudeda Avatar von Cybah
    Registriert seit
    01.09.06
    Beiträge
    30.455
    Mit anderen Worten es gibt ne Lösung.
    Pucc's Lets Plays BASE 6.0: #1 #2 #3 #4 #5

    Download von BASE 6.4 [D]: HIER (klick mich!) (Stand: 08.07.2022)

  8. #2378
    Civ4 BASE Coder Avatar von rucivfan
    Registriert seit
    10.07.11
    Ort
    Antarktika
    Beiträge
    19.017
    Cybah: siehe anhang
    Angehängte Dateien Angehängte Dateien

  9. #2379
    Moderator Avatar von Kathy
    Registriert seit
    11.10.07
    Beiträge
    17.023
    Ich habe mal eine Frage: Ich meine, dass ihr irgendwann einmal den Code, der berechnet, ob eine Einheit geupgradet werden kann, optimiert hättet. Ist das so? Und wenn ja, darf ich den Code dann auch in meinen Mod übernehmen? Wie finde ich ihn?
    That's why I am here: Mein Mod
    Mehr Technologien, mehr Einheiten, mehr Zivilisationen, mehr Gebäude

    Die aktuelle Story zum Mod:
    Die Vereinigten Staaten von Amerika

    Alte Stories zu alten Versionen:
    Alte Storys

  10. #2380
    Waddehaddedudeda Avatar von Cybah
    Registriert seit
    01.09.06
    Beiträge
    30.455
    Um was zu erreichen?
    Pucc's Lets Plays BASE 6.0: #1 #2 #3 #4 #5

    Download von BASE 6.4 [D]: HIER (klick mich!) (Stand: 08.07.2022)

  11. #2381
    Moderator Avatar von Kathy
    Registriert seit
    11.10.07
    Beiträge
    17.023
    Soweit ich mich erinnere, ging es damals darum, dass bei einem Stack ziemlich oft die Berechnung durchgeführt wurde, wenn er aus vielen Einheiten bestand. Diese unnötige Rechenarbeit sollte wegoptimiert werden. Da bei mir Stacks von 50 und mehr Einheiten keine Seltenheit sind, und ich eine sehr lange Civ4UnitInfos.xml habe (und diese Berechnungen, soweit ich sie verstehe, n mal durchgeführt werden, wobei n der Anzahl der Einträge in der Datei entspricht) war meine Hoffnung, so deutlich effizientere Rechenzeit zu bekommen.
    That's why I am here: Mein Mod
    Mehr Technologien, mehr Einheiten, mehr Zivilisationen, mehr Gebäude

    Die aktuelle Story zum Mod:
    Die Vereinigten Staaten von Amerika

    Alte Stories zu alten Versionen:
    Alte Storys

  12. #2382
    Waddehaddedudeda Avatar von Cybah
    Registriert seit
    01.09.06
    Beiträge
    30.455
    Hier... das obere ist das, was du bei dir auskommentieren musst. Keine Gewähr, dass es bei dir ohne Anpassungen funktioniert. Habe nicht überprüft, ob Codeteile von rucivfans Code an anderer Stelle verwendet werden:

    Achtung Spoiler:
    PHP-Code:
    // rucivfan_upgrade_optimization ruo[
    // old code[
    //int CvUnit::upgradePrice(UnitTypes eUnit) const
    //{
    //    int iPrice;
    //
    //    CyArgsList argsList;
    //    argsList.add(getOwnerINLINE());
    //    argsList.add(getID());
    //    argsList.add((int) eUnit);
    //    long lResult=0;
    //    gDLL->getPythonIFace()->callFunction(PYGameModule, "getUpgradePriceOverride", argsList.makeFunctionArgs(), &lResult);
    //    if (lResult >= 0)
    //    {
    //        return lResult;
    //    }
    //
    //    if (isBarbarian())
    //    {
    //        return 0;
    //    }
    //
    //    //rucivfan_code_optimization rco[
    //    iPrice = GC.getBASE_UNIT_UPGRADE_COST();
    //
    //    iPrice += (std::max(0, (GET_PLAYER(getOwnerINLINE()).getProductionNeeded(eUnit) - GET_PLAYER(getOwnerINLINE()).getProductionNeeded(getUnitType()))) * GC.getUNIT_UPGRADE_COST_PER_PRODUCTION());
    //    // ]rucivfan_code_optimization rco
    //    
    //    if (!isHuman() && !isBarbarian())
    //    {
    //        iPrice *= GC.getHandicapInfo(GC.getGameINLINE().getHandicapType()).getAIUnitUpgradePercent();
    //        iPrice /= 100;
    //
    //        iPrice *= std::max(0, ((GC.getHandicapInfo(GC.getGameINLINE().getHandicapType()).getAIPerEraModifier() * GET_PLAYER(getOwnerINLINE()).getCurrentEra()) + 100));
    //        iPrice /= 100;
    //    }
    //
    //    iPrice -= (iPrice * getUpgradeDiscount()) / 100;
    //
    //    return iPrice;
    //}
    //
    //
    //bool CvUnit::upgradeAvailable(UnitTypes eFromUnit, UnitClassTypes eToUnitClass, int iCount) const
    //{
    //    UnitTypes eLoopUnit;
    //    int iI;
    //    int numUnitClassInfos = GC.getNumUnitClassInfos();
    //
    //    if (iCount > numUnitClassInfos)
    //    {
    //        return false;
    //    }
    //
    //    CvUnitInfo &fromUnitInfo = GC.getUnitInfo(eFromUnit);
    //
    //    if (fromUnitInfo.getUpgradeUnitClass(eToUnitClass))
    //    {
    //        return true;
    //    }
    //
    //    for (iI = 0; iI < numUnitClassInfos; ++iI)
    //    {
    //        if (fromUnitInfo.getUpgradeUnitClass(iI))
    //        {
    //            eLoopUnit = ((UnitTypes)(GC.getCivilizationInfo(getCivilizationType()).getCivilizationUnits(iI)));
    //
    //            if (eLoopUnit != NO_UNIT)
    //            {
    //                if (upgradeAvailable(eLoopUnit, eToUnitClass, (iCount + 1)))
    //                {
    //                    return true;
    //                }
    //            }
    //        }
    //    }
    //
    //    return false;
    //}
    //
    //
    //bool CvUnit::canUpgrade(UnitTypes eUnit, bool bTestVisible) const
    //{
    //    if (eUnit == NO_UNIT)
    //    {
    //        return false;
    //    }
    //
    //    if(!isReadyForUpgrade())
    //    {
    //        return false;
    //    }
    //    
    //    if (!bTestVisible)
    //    {
    //        if (GET_PLAYER(getOwnerINLINE()).getGold() < upgradePrice(eUnit))
    //        {
    //            return false;
    //        }
    //    }
    //    
    //    if (hasUpgrade(eUnit))
    //    {
    //        return true;
    //    }
    //
    //    return false;
    //}
    //
    //bool CvUnit::isReadyForUpgrade() const
    //{
    //    if (!canMove())
    //    {
    //        return false;
    //    }
    //
    //    if (plot()->getTeam() != getTeam())
    //    {
    //        return false;
    //    }
    //
    //    return true;
    //}
    //
    //// has upgrade is used to determine if an upgrade is possible,
    //// it specifically does not check whether the unit can move, whether the current plot is owned, enough gold
    //// those are checked in canUpgrade()
    //// does not search all cities, only checks the closest one
    //bool CvUnit::hasUpgrade(bool bSearch) const
    //{
    //    return (getUpgradeCity(bSearch) != NULL);
    //}
    //
    //// has upgrade is used to determine if an upgrade is possible,
    //// it specifically does not check whether the unit can move, whether the current plot is owned, enough gold
    //// those are checked in canUpgrade()
    //// does not search all cities, only checks the closest one
    //bool CvUnit::hasUpgrade(UnitTypes eUnit, bool bSearch) const
    //{
    //    return (getUpgradeCity(eUnit, bSearch) != NULL);
    //}
    //
    //// finds the 'best' city which has a valid upgrade for the unit,
    //// it specifically does not check whether the unit can move, or if the player has enough gold to upgrade
    //// those are checked in canUpgrade()
    //// if bSearch is true, it will check every city, if not, it will only check the closest valid city
    //// NULL result means the upgrade is not possible
    //CvCity* CvUnit::getUpgradeCity(bool bSearch) const
    //{
    //    CvPlayerAI &kPlayer = GET_PLAYER(getOwnerINLINE());
    //    UnitAITypes eUnitAI = AI_getUnitAIType();
    //    CvArea *pArea = area();
    //
    //    int iCurrentValue = kPlayer.AI_unitValue(getUnitType(), eUnitAI, pArea);
    //
    //    int iBestSearchValue = MAX_INT;
    //    CvCity* pBestUpgradeCity = NULL;
    //    
    //    for (int iI = 0; iI < GC.getNumUnitInfos(); ++iI)
    //    {
    //        int iNewValue = kPlayer.AI_unitValue(((UnitTypes)iI), eUnitAI, pArea);
    //        if (iNewValue > iCurrentValue)
    //        {
    //            int iSearchValue;
    //            CvCity* pUpgradeCity = getUpgradeCity((UnitTypes)iI, bSearch, &iSearchValue);
    //            if (pUpgradeCity != NULL)
    //            {
    //                // if not searching or close enough, then this match will do
    //                if (!bSearch || iSearchValue < 16)
    //                {
    //                    return pUpgradeCity;
    //                }
    //                
    //                if (iSearchValue < iBestSearchValue)
    //                {
    //                    iBestSearchValue = iSearchValue;
    //                    pBestUpgradeCity = pUpgradeCity;
    //                }
    //            }
    //        }
    //    }
    //
    //    return pBestUpgradeCity;
    //}
    //
    //// finds the 'best' city which has a valid upgrade for the unit, to eUnit type
    //// it specifically does not check whether the unit can move, or if the player has enough gold to upgrade
    //// those are checked in canUpgrade()
    //// if bSearch is true, it will check every city, if not, it will only check the closest valid city
    //// if iSearchValue non NULL, then on return it will be the city's proximity value, lower is better
    //// NULL result means the upgrade is not possible
    //CvCity* CvUnit::getUpgradeCity(UnitTypes eUnit, bool bSearch, int* iSearchValue) const
    //{
    //    if (eUnit == NO_UNIT)
    //    {
    //        return false;
    //    }
    //    
    //    CvPlayerAI &kPlayer = GET_PLAYER(getOwnerINLINE());
    //    CvUnitInfo &kUnitInfo = GC.getUnitInfo(eUnit);
    //
    //    if (GC.getCivilizationInfo(kPlayer.getCivilizationType()).getCivilizationUnits(kUnitInfo.getUnitClassType()) != eUnit)
    //    {
    //        return false;
    //    }
    //
    //    if (!upgradeAvailable(getUnitType(), ((UnitClassTypes)(kUnitInfo.getUnitClassType()))))
    //    {
    //        return false;
    //    }
    //
    //    if (kUnitInfo.getCargoSpace() < getCargo())
    //    {
    //        return false;
    //    }
    //
    //    CLLNode<IDInfo>* pUnitNode = plot()->headUnitNode();
    //    while (pUnitNode != NULL)
    //    {
    //        CvUnit* pLoopUnit = ::getUnit(pUnitNode->m_data);
    //        pUnitNode = plot()->nextUnitNode(pUnitNode);
    //
    //        if (pLoopUnit->getTransportUnit() == this)
    //        {
    //            if (kUnitInfo.getSpecialCargo() != NO_SPECIALUNIT)
    //            {
    //                if (kUnitInfo.getSpecialCargo() != pLoopUnit->getSpecialUnitType())
    //                {
    //                    return false;
    //                }
    //            }
    //
    //            if (kUnitInfo.getDomainCargo() != NO_DOMAIN)
    //            {
    //                if (kUnitInfo.getDomainCargo() != pLoopUnit->getDomainType())
    //                {
    //                    return false;
    //                }
    //            }
    //        }
    //    }
    //    
    //    // sea units must be built on the coast
    //    bool bCoastalOnly = (getDomainType() == DOMAIN_SEA);
    //
    //    // results
    //    int iBestValue = MAX_INT;
    //    CvCity* pBestCity = NULL;
    //        
    //    // if search is true, check every city for our team
    //    if (bSearch)
    //    {
    //        // air units can travel any distance
    //        bool bIgnoreDistance = (getDomainType() == DOMAIN_AIR);
    //
    //        TeamTypes eTeam = getTeam();
    //        int iArea = getArea();
    //        int iX = getX_INLINE(), iY = getY_INLINE();
    //
    //        // check every player on our team's cities
    //        for (int iI = 0; iI < MAX_PLAYERS; ++iI)
    //        {
    //            // is this player on our team?
    //            CvPlayerAI &kLoopPlayer = GET_PLAYER((PlayerTypes)iI);
    //            if (kLoopPlayer.isAlive() && kLoopPlayer.getTeam() == eTeam)
    //            {
    //                int iLoop;
    //                for (CvCity* pLoopCity = kLoopPlayer.firstCity(&iLoop); pLoopCity != NULL; pLoopCity = kLoopPlayer.nextCity(&iLoop))
    //                {
    //                    // if coastal only, then make sure we are coast
    //                    CvArea *pWaterArea = NULL;
    //                    if (!bCoastalOnly || ((pWaterArea = pLoopCity->waterArea()) != NULL && !pWaterArea->isLake()))
    //                    {
    //                        // can this city tran this unit?
    //                        if (pLoopCity->canTrain(eUnit, false, false, true))
    //                        {
    //                            // if we do not care about distance, then the first match will do
    //                            if (bIgnoreDistance)
    //                            {
    //                                // if we do not care about distance, then return 1 for value
    //                                if (iSearchValue != NULL)
    //                                {
    //                                    *iSearchValue = 1;
    //                                }
    //
    //                                return pLoopCity;
    //                            }
    //
    //                            int iValue = plotDistance(iX, iY, pLoopCity->getX_INLINE(), pLoopCity->getY_INLINE());
    //
    //                            // if not same area, not as good (lower numbers are better)
    //                            if (iArea != pLoopCity->getArea() && (!bCoastalOnly || iArea != pWaterArea->getID()))
    //                            {
    //                                iValue *= 16;
    //                            }
    //
    //                            // if we cannot path there, not as good (lower numbers are better)
    //                            if (!generatePath(pLoopCity->plot(), 0, true))
    //                            {
    //                                iValue *= 16;
    //                            }
    //
    //                            if (iValue < iBestValue)
    //                            {
    //                                iBestValue = iValue;
    //                                pBestCity = pLoopCity;
    //                            }
    //                        }
    //                    }
    //                }
    //            }
    //        }
    //    }
    //    else
    //    {
    //        // find the closest city
    //        CvCity* pClosestCity = GC.getMapINLINE().findCity(getX_INLINE(), getY_INLINE(), NO_PLAYER, getTeam(), true, bCoastalOnly);
    //        if (pClosestCity != NULL)
    //        {
    //            // if we can train, then return this city (otherwise it will return NULL)
    //            if (pClosestCity->canTrain(eUnit, false, false, true))
    //            {
    //                // did not search, always return 1 for search value
    //                iBestValue = 1;
    //
    //                pBestCity = pClosestCity;
    //            }
    //        }
    //    }
    //
    //    // return the best value, if non-NULL
    //    if (iSearchValue != NULL)
    //    {
    //        *iSearchValue = iBestValue;
    //    }
    //
    //    return pBestCity;
    //}
    //
    //void CvUnit::upgrade(UnitTypes eUnit)
    //{
    //    CvUnit* pUpgradeUnit;
    //
    //    if (!canUpgrade(eUnit))
    //    {
    //        return;
    //    }
    //
    //    GET_PLAYER(getOwnerINLINE()).changeGold(-(upgradePrice(eUnit)));
    //
    //    pUpgradeUnit = GET_PLAYER(getOwnerINLINE()).initUnit(eUnit, getX_INLINE(), getY_INLINE(), AI_getUnitAIType());
    //
    //    FAssertMsg(pUpgradeUnit != NULL, "UpgradeUnit is not assigned a valid value");
    //
    //    pUpgradeUnit->joinGroup(getGroup());
    //
    //    pUpgradeUnit->convert(this);
    //
    //    pUpgradeUnit->finishMoves();
    //
    ///************************************************************************************************/
    ///* BETTER_BTS_AI_MOD                      02/24/10                                jdog5000      */
    ///*                                                                                              */
    ///* AI Logging                                                                                   */
    ///************************************************************************************************/
    //    if( gUnitLogLevel > 2 )
    //    {
    //        CvWString szString;
    //        getUnitAIString(szString, AI_getUnitAIType());
    //        logBBAI("    %S spends %d to upgrade %S to %S, unit AI %S", GET_PLAYER(getOwnerINLINE()).getCivilizationDescription(0), upgradePrice(eUnit), getName(0).GetCString(), pUpgradeUnit->getName(0).GetCString(), szString.GetCString());
    //    }
    ///************************************************************************************************/
    ///* BETTER_BTS_AI_MOD                       END                                                  */
    ///************************************************************************************************/
    //}
    // ]old code

    // new code[
    int CvUnit::upgradePrice(UnitTypes eUnit) const
    {
        
    int iPrice;

        if(
    GC.getUSE_ON_UNIT_UPGRADE_PRICE_CALLBACK())
        {
            
    CyArgsList argsList;
            
    argsList.add(getOwnerINLINE());
            
    argsList.add(getID());
            
    argsList.add((int) eUnit);
            
    long lResult=0;
            
    gDLL->getPythonIFace()->callFunction(PYGameModule"getUpgradePriceOverride"argsList.makeFunctionArgs(), &lResult);
            if (
    lResult >= 0)
            {
                return 
    lResult;
            }
        }

        if (
    isBarbarian())
        {
            return 
    0;
        }

        
    CvUnitInfo &kUnitUpgrade GC.getUnitInfo(eUnit);
        
    CvPlayer &kPlayer GET_PLAYER(getOwnerINLINE());

        
    iPrice GC.getUNIT_UPGRADE_BASE_COST();

        
    iPrice += std::max(0, (kUnitUpgrade.getProductionCost() - getUnitInfo().getProductionCost())) * GC.getUNIT_UPGRADE_COST_PER_PRODUCTION();

        if(
    getDomainType() == DOMAIN_AIR)
        {
            
    iPrice += std::max(0kUnitUpgrade.getAirCombat() - getUnitInfo().getAirCombat()) * GC.getUNIT_UPGRADE_COST_PER_AIR_COMBAT();
        }
        else
        {
            
    iPrice += std::max(0kUnitUpgrade.getCombat() - getUnitInfo().getCombat()) * GC.getUNIT_UPGRADE_COST_PER_COMBAT();
        }

        if(
    kUnitUpgrade.getUnitCombatType() != getUnitCombatType())
        {
            
    iPrice += GC.getUNIT_UPGRADE_COST_COMBAT_TYPE_CHANGE();
        }

        
    iPrice *= GC.getUNIT_UPGRADE_COST_PERCENT();
        
    iPrice /= 100;

        
    iPrice *= GC.getGameSpeedInfo(GC.getGameINLINE().getGameSpeedType()).getTrainPercent();
        
    iPrice /= 100;

        
    iPrice *= GC.getEraInfo(GC.getGameINLINE().getStartEra()).getTrainPercent();
        
    iPrice /= 100;
        
        
    iPrice *= std::max(0100 getUpgradeDiscount());
        
    iPrice /= 100;

        if(!
    kPlayer.isHuman())
        {
            
    CvHandicapInfo &kHandicapInfo GC.getHandicapInfo(GC.getGameINLINE().getHandicapType());

            
    iPrice *= kHandicapInfo.getAIUnitUpgradePercent();
            
    iPrice /= 100;

            
    iPrice *= std::max(0, (kHandicapInfo.getAIPerEraModifier() * kPlayer.getCurrentEra()) + 100);
            
    iPrice /= 100;
        }

        return 
    iPrice;
    }


    bool CvUnit::upgradeAvailable(UnitTypes eFromUnitUnitClassTypes eToUnitClassint iCount) const
    {
        
    UnitTypes eLoopUnit;
        
    int iI;

        if (
    iCount GC.getNumUnitClassInfos())
        {
            return 
    false;
        }

        
    CvUnitInfo &fromUnitInfo GC.getUnitInfo(eFromUnit);
        
    CvCivilizationInfo &kCivilization GC.getCivilizationInfo(getCivilizationType());

        for (
    iI 0iI fromUnitInfo.getNumUpgradeUnitClass(); ++iI)
        {
            
    UnitClassTypes eLoopUnitClass = (UnitClassTypes)fromUnitInfo.getUpgradeUnitClass(iI);
            if( 
    eLoopUnitClass == eToUnitClass)
            {
                return 
    true;
            }

            
    eLoopUnit = ((UnitTypes)(kCivilization.getCivilizationUnits(eLoopUnitClass)));
            if (
    eLoopUnit != NO_UNIT)
            {
                if (
    upgradeAvailable(eLoopUniteToUnitClass, (iCount 1)))
                {
                    return 
    true;
                }
            }
        }

        return 
    false;
    }

    bool CvUnit::oneUpgradesAvailable(UnitTypes eUnitint iCount) const
    {
        
    UnitTypes eLoopUnit;
        
    int iI;

        if (
    iCount GC.getNumUnitClassInfos())
        {
            return 
    false;
        }

        
    CvUnitInfo &kUnitInfo GC.getUnitInfo(eUnit);
        
    CvCivilizationInfo &kCivilization GC.getCivilizationInfo(getCivilizationType());

        if(
    iCount 0)
        {
            if(
    hasUpgrade(eUnitfalse))
            {
                return 
    true;
            }
        }    

        for (
    iI 0iI kUnitInfo.getNumUpgradeUnitClass(); ++iI)
        {
            
    eLoopUnit = ((UnitTypes)(kCivilization.getCivilizationUnits((UnitClassTypes)kUnitInfo.getUpgradeUnitClass(iI))));
            if (
    eLoopUnit != NO_UNIT)
            {
                if (
    oneUpgradesAvailable(eLoopUnit, (iCount 1)))
                {
                    return 
    true;
                }        
            }
        }

        return 
    false;
    }

    bool CvUnit::allUpgradesAvailable(UnitTypes eUnitint iCount) const
    {
        
    UnitTypes eLoopUnit;
        
    int iI;

        
    CvUnitInfo &kUnitInfo GC.getUnitInfo(eUnit);
        
    CvCivilizationInfo &kCivilization GC.getCivilizationInfo(getCivilizationType());

        for (
    iI 0iI kUnitInfo.getNumUpgradeUnitClass(); ++iI)
        {
            
    eLoopUnit = ((UnitTypes)(kCivilization.getCivilizationUnits((UnitClassTypes)kUnitInfo.getUpgradeUnitClass(iI))));
            if (
    eLoopUnit != NO_UNIT)
            {
                if (!
    oneUpgradesAvailable(eLoopUnit, (iCount 1)))
                {
                    return 
    false;
                }
            }
        }

        if(
    kUnitInfo.getNumUpgradeUnitClass() == 0)
        {
            return 
    false;
        }

        return 
    true;
    }

    bool CvUnit::getAvailableUpgrades(std::vector<UnitTypes> &vctiUnitUpgradesUnitTypes eFromUnitint iCount)
    {
        
    UnitTypes eLoopUnit;
        
    int iI;
        
    bool bOneUpgradeAvailable;

        
    CvUnitInfo &kUnitInfo GC.getUnitInfo(eFromUnit);
        
    CvCivilizationInfo &kCivilization GC.getCivilizationInfo(getCivilizationType());

        
    bOneUpgradeAvailable false;

        for (
    iI 0iI kUnitInfo.getNumUpgradeUnitClass(); ++iI)
        {
            
    eLoopUnit = ((UnitTypes)(kCivilization.getCivilizationUnits((UnitClassTypes)kUnitInfo.getUpgradeUnitClass(iI))));
            if (
    eLoopUnit != NO_UNIT)
            {
                if(
    getAvailableUpgrades(vctiUnitUpgradeseLoopUnit, (iCount 1)))
                {
                    
    bOneUpgradeAvailable true;
                }
                else
                {
                    if(
    hasUpgrade(eLoopUnitfalse))
                    {
                        if(
    find(vctiUnitUpgrades.begin(), vctiUnitUpgrades.end(), eLoopUnit) == vctiUnitUpgrades.end())
                        {
                            
    vctiUnitUpgrades.push_back(eLoopUnit);
                        }
                        
                        
    bOneUpgradeAvailable true;
                    }
                }
            }
        }

        return 
    bOneUpgradeAvailable;
    }

    bool CvUnit::canUpgrade(UnitTypes eUnitbool bTestVisible) const
    {
        if (
    eUnit == NO_UNIT)
        {
            return 
    false;
        }

        if(!
    isReadyForUpgrade())
        {
            return 
    false;
        }
        
        if (!
    bTestVisible)
        {
            if (!
    hasUpgradeGold(eUnit))
            {
                return 
    false;
            }
        }
        
        if (
    hasUpgrade(eUnittrue))
        {
            return 
    true;
        }

        return 
    false;
    }

    bool CvUnit::isReadyForUpgrade() const
    {
        if (!
    canMove())
        {
            return 
    false;
        }

        if (
    plot()->getTeam() != getTeam())
        {
            return 
    false;
        }

        return 
    true;
    }

    bool  CvUnit::hasUpgrade(UnitTypes eUnitbool bTestIsUpgrade) const
    {
        if (
    eUnit == NO_UNIT)
        {
            return 
    false;
        }
        
        
    CvPlayerAI &kPlayer GET_PLAYER(getOwnerINLINE());
        
    CvUnitInfo &kUnitInfo GC.getUnitInfo(eUnit);

        if (
    GC.getCivilizationInfo(kPlayer.getCivilizationType()).getCivilizationUnits(kUnitInfo.getUnitClassType()) != eUnit)
        {
            return 
    false;
        }

        if(
    bTestIsUpgrade)
        {
            if (!
    upgradeAvailable(getUnitType(), ((UnitClassTypes)(kUnitInfo.getUnitClassType()))))
            {
                return 
    false;
            }

            if (
    oneUpgradesAvailable(eUnit))
            {
                return 
    false;
            }
        }

        if (!(
    kPlayer.canTrain(eUnitfalsefalsetrue)))
        {
            return 
    false;
        }

        if (
    kUnitInfo.getCargoSpace() < getCargo())
        {
            return 
    false;
        }

        
    CLLNode<IDInfo>* pUnitNode plot()->headUnitNode();
        while (
    pUnitNode != NULL)
        {
            
    CvUnitpLoopUnit = ::getUnit(pUnitNode->m_data);
            
    pUnitNode plot()->nextUnitNode(pUnitNode);

            if (
    pLoopUnit->getTransportUnit() == this)
            {
                if (
    kUnitInfo.getSpecialCargo() != NO_SPECIALUNIT)
                {
                    if (
    kUnitInfo.getSpecialCargo() != pLoopUnit->getSpecialUnitType())
                    {
                        return 
    false;
                    }
                }

                if (
    kUnitInfo.getDomainCargo() != NO_DOMAIN)
                {
                    if (
    kUnitInfo.getDomainCargo() != pLoopUnit->getDomainType())
                    {
                        return 
    false;
                    }
                }
            }
        }

        
    bool bValid false;
        
        if(!
    bValid)
        {
            if(
    plot()->getTeam() == getTeam())
            {
                if (
    plot()->canTrain(eUnitfalsefalsefalsetrue))
                {
                    
    bValid true;
                }
            }
        }

        if(!
    bValid)
        {
            
    //if(plot()->getTeam() != getTeam() || plot()->getWorkingCity() == NULL)
            
    {
                
    CvCitypCapitalCity kPlayer.getCapitalCity();
                if(
    pCapitalCity != NULL)
                {
                    if(
    pCapitalCity->plot()->canTrain(eUnitfalsefalsefalsetrue))
                    {
                        
    bValid true;
                    }
                }
            }
        }

        if(!
    bValid)
        {
            return 
    false;
        }

        return 
    true;
    }


    bool CvUnit::hasUpgradeGold(UnitTypes eUnit) const
    {
        return 
    upgradePrice(eUnit) <= GET_PLAYER(getOwnerINLINE()).getGold();
    }

    void CvUnit::upgrade(UnitTypes eUnit)
    {
        
    CvUnitpUpgradeUnit;

        if (!
    canUpgrade(eUnit))
        {
            return;
        }

        
    FAssertMsg(eUnit NO_UNIT"eUnit is not assigned a valid value");

        
    GET_PLAYER(getOwnerINLINE()).changeGold(-(upgradePrice(eUnit)));

        
    pUpgradeUnit GET_PLAYER(getOwnerINLINE()).initUnit(eUnitgetX_INLINE(), getY_INLINE(), AI_getUnitAIType());

        
    FAssertMsg(pUpgradeUnit != NULL"UpgradeUnit is not assigned a valid value");

        
    pUpgradeUnit->joinGroup(getGroup());

        
    pUpgradeUnit->convert(this);

        
    pUpgradeUnit->finishMoves();

        if (
    pUpgradeUnit->getExperience() > GC.getUNIT_UPGRADE_MAX_EXPERIENCE_AFTER_UPGRADE())
        {
            
    pUpgradeUnit->setExperience(GC.getUNIT_UPGRADE_MAX_EXPERIENCE_AFTER_UPGRADE());
        }    

    /************************************************************************************************/
    /* BETTER_BTS_AI_MOD                      02/24/10                                jdog5000      */
    /*                                                                                              */
    /* AI Logging                                                                                   */
    /************************************************************************************************/
        
    if(GC.getLogging())
        {
            if( 
    gUnitLogLevel )
            {
                
    CvWString szString;
                
    getUnitAIString(szStringAI_getUnitAIType());
                
    logBBAI("    %S spends %d to upgrade %S to %S, unit AI %S"GET_PLAYER(getOwnerINLINE()).getCivilizationDescription(0), upgradePrice(eUnit), getName(0).GetCString(), pUpgradeUnit->getName(0).GetCString(), szString.GetCString());
            }
        }
    /************************************************************************************************/
    /* BETTER_BTS_AI_MOD                       END                                                  */
    /************************************************************************************************/
    }
    // ]new code
    // ]rucivfan_upgrade_optimization ruo 



    Ein Hinweis aber: Wenn der Compiler bei sowas wie GC.getUNIT_UPGRADE_BASE_COST meckert, liegts daran, dass diese als Globals eingerichtet wurden. Das müsstest du dann auch machen oder entsprechend umschreiben zu getdefineint oder wie das heißt. Dass wir Globals benutzen hat auch Performance Gründe.
    Pucc's Lets Plays BASE 6.0: #1 #2 #3 #4 #5

    Download von BASE 6.4 [D]: HIER (klick mich!) (Stand: 08.07.2022)

  13. #2383
    Moderator Avatar von Kathy
    Registriert seit
    11.10.07
    Beiträge
    17.023
    Danke für den Code. Aber ich fürchte, ich blicke da nicht genügend durch. Wenn es nur der Code wäre, würde ich es noch nachvollziehen können bzw. die fehlenden Änderungen am Header nachtragen können. Die Globals kann ich (auch wenn es schlecht ist) durch die Werte aus CvGlobalDefines.xml ersetzen. Ein paar Punkte kann ich Anpassen (zum Beispiel das mit dem UnitCombat Chance und dem AirUnitcombat, das gab es im Original nicht).

    Aber was macht "getNumUpgradeUnitClass"? Das wird leider in dem Code nicht definiert, ich weiß also nicht, was ich damit machen soll, wie die Zahl gesetzt wird etc. Und ich fürchte ohne das bringt der ganze Code keinen Sinn, wenn ich es richtig verstanden habe ist das das Herzstück des Ganzen.

    Ich habe mir auch das aktuelle BASE heruntergeladen, aber da ist ja nur der kompilierte Code drin, nicht die ganzen .cpp und .h-Dateien, ich kann da also auch nichts finden.
    That's why I am here: Mein Mod
    Mehr Technologien, mehr Einheiten, mehr Zivilisationen, mehr Gebäude

    Die aktuelle Story zum Mod:
    Die Vereinigten Staaten von Amerika

    Alte Stories zu alten Versionen:
    Alte Storys

  14. #2384
    Waddehaddedudeda Avatar von Cybah
    Registriert seit
    01.09.06
    Beiträge
    30.455
    Der ganze Code ist auch nicht public. Ich schau nachher aber nochmal nach dem Teilstück.
    Pucc's Lets Plays BASE 6.0: #1 #2 #3 #4 #5

    Download von BASE 6.4 [D]: HIER (klick mich!) (Stand: 08.07.2022)

  15. #2385
    Waddehaddedudeda Avatar von Cybah
    Registriert seit
    01.09.06
    Beiträge
    30.455
    edit. doppelpost.
    Pucc's Lets Plays BASE 6.0: #1 #2 #3 #4 #5

    Download von BASE 6.4 [D]: HIER (klick mich!) (Stand: 08.07.2022)

Seite 159 von 162 ErsteErste ... 59109149155156157158159160161162 LetzteLetzte

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •