Thalassicus / cep-bnw

Civ V Communitas Expansion Pack
32 stars 22 forks source link

City State quest #165

Closed GrantSP closed 10 years ago

GrantSP commented 10 years ago

Not sure if this one is going to be fixable.

While doing a test on another matter I just received a quest from a close by CS asking for any civilization to build the "National Yields".

As this is given to the player as a dummy building from the outset I'm not sure how this can be resolved.

As expected, the very next turn I fulfilled this quest and was granted a new ally, incidentally this CS just happened to have the luxury my city was craving thus giving me a two-fold bonus.

Now some 20 or so turns later this CS grants me the same gift because of having "again" built the "National Yields", despite still with only one city.

stackpoint commented 10 years ago

Wow, they really improved the GitHub interface.

I'll take a look at the source and see what the wonder criteria is for that quest.

stackpoint commented 10 years ago
/// Best wonder for a Quest given to ePlayer?
BuildingTypes CvMinorCivAI::GetBestWonderForQuest(PlayerTypes ePlayer)
{
    BuildingTypes eBestWonder;

    FStaticVector<BuildingTypes, 50, true, c_eCiv5GameplayDLL, 0> veValidBuildings; // 50 wonders should be overkill

    int iWorldPlayerLoop;
    PlayerTypes eWorldPlayer;
    CvCity* pLoopCity;
    int iCityLoop;
    int iWonderProgress;
    int iCompletionThreshold = /*25*/ GC.getMINOR_CIV_QUEST_WONDER_COMPLETION_THRESHOLD();
    bool bFoundWonderTooFarAlong;

    // Loop through all Buildings and see if they're useful
    for(int iBuildingLoop = 0; iBuildingLoop < GC.getNumBuildingInfos(); iBuildingLoop++)
    {
        const BuildingTypes eBuilding = static_cast<BuildingTypes>(iBuildingLoop);
        CvBuildingEntry* pkBuildingInfo = GC.getBuildingInfo(eBuilding);

        //Skip if NULL
        if(pkBuildingInfo == NULL)
            continue;

        bFoundWonderTooFarAlong = false;

        // Must be a wonder
        if(!isWorldWonderClass(pkBuildingInfo->GetBuildingClassInfo()))
        {
            continue;
        }

        // Must be able to build it
        if(!GET_PLAYER(ePlayer).canConstruct(eBuilding))
        {
            continue;
        }

        // Someone CAN be building this wonder right now, but they can't be more than a certain % of the way done (25% by default)
        for(iWorldPlayerLoop = 0; iWorldPlayerLoop < MAX_MAJOR_CIVS; iWorldPlayerLoop++)
        {
            eWorldPlayer = (PlayerTypes) iWorldPlayerLoop;

            for(pLoopCity = GET_PLAYER(eWorldPlayer).firstCity(&iCityLoop); pLoopCity != NULL; pLoopCity = GET_PLAYER(eWorldPlayer).nextCity(&iCityLoop))
            {
                iWonderProgress = pLoopCity->GetCityBuildings()->GetBuildingProduction(eBuilding);

                if(iWonderProgress * 100 / pLoopCity->getProductionNeeded(eBuilding) >= iCompletionThreshold)
                {
                    bFoundWonderTooFarAlong = true;
                    break;
                }
            }
            if(bFoundWonderTooFarAlong)
            {
                break;
            }
        }
        if(bFoundWonderTooFarAlong)
        {
            continue;
        }

        veValidBuildings.push_back(eBuilding);
    }

    // Didn't find any valid Wonders
    if(veValidBuildings.size() == 0)
    {
        return NO_BUILDING;
    }

    int iRandIndex = GC.getGame().getJonRandNum(veValidBuildings.size(), "Finding random Wonder for Minor to give out a quest to construct.");
    eBestWonder = veValidBuildings[iRandIndex];

    return eBestWonder;
}

Here's the code. National Yields (aka BUILDING_GREAT_HALL / TXT_KEY_BUILDING_PALACE) shouldn't be constructable with a cost of 0. But the player::canConstruct uses a check of pBuildingInfo.GetProductionCost() == -1 to determine if a building is constructable. I'll push out an update with all the buildings with a cost of 0 to a cost of -1.

stackpoint commented 10 years ago

Should be fixed here: https://github.com/Thalassicus/cep-bnw/commit/eb78dc5a28cce6bcf78e2618489dca27dff11a40

GrantSP commented 10 years ago

I assume then that without this fix all our dummy buildings (with a 0 cost) could have come under consideration for CS quests. Maybe they did and none of us paid any attention?

stackpoint commented 10 years ago

It might've been possible but I assume that those dummy buildings weren't flagged as a wonder while the National Yields formerly known as the Palace formerly known as the Great Hall was(?)