Esempio n. 1
0
vector<DCppTemplate::stc_Flag> DCppTemplate::FindFileName()
{
    vector<DCppTemplate::stc_Flag> result;

    result = FindFlags(mp_TemplateContains,STR_CGFLAG_FILE_BEGIN.c_str(),STR_CGFLAG_FILE_END.c_str(),this->m_ContainSize,STR_CGFLAG_FILE_END.length()+1);
    return result;
}
Esempio n. 2
0
void CompletionModel::readSettings(QSettings *settings)
{
    beginResetModel();
    const int size = settings->beginReadArray(completionSettingsArrayPrefix());
    m_entries.clear();
    m_entries.reserve(size);
    for (int i = 0; i < size; ++i) {
        settings->setArrayIndex(i);
        CompletionEntry entry;
        entry.text = settings->value(completionSettingsTextKey()).toString();
        entry.findFlags = FindFlags(settings->value(completionSettingsFlagsKey(), 0).toInt());
        if (!entry.text.isEmpty())
            m_entries.append(entry);
    }
    settings->endArray();
    endResetModel();
}
Esempio n. 3
0
eCGFlagType DCppTemplate::GetFlagType(string flagStr)
{
    if (flagStr.length() <= 0)
        return CG_FLAG_NONE;
    vector<std::string> flagBegins;
    flagBegins.push_back(STR_CGFLAG_MACRO_BEGIN);
    flagBegins.push_back(STR_CGFLAG_FOMULE_BEGIN);

    for (auto Tag : flagBegins)
    {
        if (FindFlags(flagStr.c_str(),Tag.c_str(),STR_CGFLAG_FLAGTYPE_END.c_str(),flagStr.length(),STR_CGFLAG_FLAGTYPE_END.length()+1).size()>0)
        {
            if (Tag == STR_CGFLAG_MACRO_BEGIN)
                return CG_FLAG_Macro;
            else if (Tag == STR_CGFLAG_FOMULE_BEGIN)
                return CG_FLAG_Fomule;
        }
    }
    return CG_FLAG_NONE;
}
bool AIConstruction::BuildAlternativeRoad(const noFlag* flag, std::vector<Direction>& route)
{
    // LOG.write(("ai build alt road player %i at %i %i\n", flag->GetPlayer(), flag->GetPos());
    // Radius in dem nach würdigen Fahnen gesucht wird
    const unsigned short maxRoadLength = 10;
    // Faktor um den der Weg kürzer sein muss als ein vorhander Pfad, um gebaut zu werden
    const unsigned short lengthFactor = 5;

    // Flaggen in der Umgebung holen
    std::vector<const noFlag*> flags = FindFlags(flag->GetPos(), maxRoadLength);
    std::vector<Direction> mainroad = route;
    // targetflag for mainroad
    MapPoint t = flag->GetPos();
    for(auto i : mainroad)
    {
        t = aii.gwb.GetNeighbour(t, i);
    }
    const auto* mainflag = aii.gwb.GetSpecObj<noFlag>(t);

    // Jede Flagge testen...
    for(auto& i : flags)
    {
        const noFlag& curFlag = *i;
        // When the current flag is the end of the main route, we skip it as crossing the main route is dissallowed by crossmainpath check a
        // bit below
        if(mainflag && &curFlag == mainflag)
            continue;

        route.clear();
        unsigned newLength;
        // the flag should not be at a military building!
        if(aii.gwb.IsMilitaryBuildingOnNode(aii.gwb.GetNeighbour(curFlag.GetPos(), Direction::NORTHWEST), true))
            continue;

        if(!IsConnectedToRoadSystem(&curFlag))
            continue;

        // Gibts überhaupt einen Pfad zu dieser Flagge
        if(!aii.FindFreePathForNewRoad(flag->GetPos(), curFlag.GetPos(), &route, &newLength))
            continue;

        // Wenn ja, dann gucken ob unser momentaner Weg zu dieser Flagge vielleicht voll weit ist und sich eine Straße lohnt
        unsigned oldLength = 0;

        // Aktuelle Strecke zu der Flagge
        bool pathAvailable = aii.FindPathOnRoads(curFlag, *flag, &oldLength);
        if(!pathAvailable && mainflag)
        {
            pathAvailable = aii.FindPathOnRoads(curFlag, *mainflag, &oldLength);
            if(pathAvailable)
                oldLength += mainroad.size();
        }
        bool crossmainpath = false;
        unsigned size = 0;
        // more than 5 nonflaggable spaces on the route -> not really valid path
        unsigned temp = 0;
        t = flag->GetPos();
        for(auto j : route)
        {
            t = aii.gwb.GetNeighbour(t, j);
            MapPoint t2 = flag->GetPos();
            // check if we cross the planned main road
            for(auto k : mainroad)
            {
                t2 = aii.gwb.GetNeighbour(t2, k);
                if(t2 == t)
                {
                    crossmainpath = true;
                    break;
                }
            }
            RTTR_Assert(aii.GetBuildingQuality(t) == aijh.GetAINode(t).bq);
            if(aii.GetBuildingQuality(t) == BQ_NOTHING)
                temp++;
            else
            {
                if(size < temp)
                    size = temp;
                temp = 0;
            }
        }
        if(size > 2 || crossmainpath)
            continue;

        // Lohnt sich die Straße?
        if(!pathAvailable || newLength * lengthFactor < oldLength)
        {
            if(BuildRoad(flag, &curFlag, route))
            {
                constructionlocations.push_back(flag->GetPos());
                return true;
            }
        }
    }

    return false;
}
bool AIConstruction::ConnectFlagToRoadSytem(const noFlag* flag, std::vector<Direction>& route, unsigned maxSearchRadius /*= 14*/)
{
    // TODO: die methode kann  ganz schön böse Laufzeiten bekommen... Optimieren?

    // Radius in dem nach würdigen Fahnen gesucht wird
    // const unsigned short maxSearchRadius = 10;

    // flag of a military building? -> check if we really want to connect this right now
    const MapPoint bldPos = aii.gwb.GetNeighbour(flag->GetPos(), Direction::NORTHWEST);
    if(const auto* milBld = aii.gwb.GetSpecObj<const nobMilitary>(bldPos))
    {
        if(!MilitaryBuildingWantsRoad(*milBld))
            return false;
    }
    // Ziel, das möglichst schnell erreichbar sein soll
    // noFlag *targetFlag = gwb->GetSpecObj<nobHQ>(player->hqPos)->GetFlag();
    noFlag* targetFlag = FindTargetStoreHouseFlag(flag->GetPos());

    // Falls kein Lager mehr vorhanden ist, brauchen wir auch keinen Weg suchen
    if(!targetFlag)
        return false;

    // Flaggen in der Umgebung holen
    std::vector<const noFlag*> flags = FindFlags(flag->GetPos(), maxSearchRadius);

#ifdef DEBUG_AI
    std::cout << "FindFlagsNum: " << flags.size() << std::endl;
#endif

    const noFlag* shortest = nullptr;
    unsigned shortestLength = 99999;
    std::vector<Direction> tmpRoute;

    // Jede Flagge testen...
    for(const noFlag* curFlag : flags)
    {
        tmpRoute.clear();
        unsigned length;
        // the flag should not be at a military building!
        if(aii.gwb.IsMilitaryBuildingOnNode(aii.gwb.GetNeighbour(curFlag->GetPos(), Direction::NORTHWEST), true))
            continue;
        // Gibts überhaupt einen Pfad zu dieser Flagge
        if(!aii.FindFreePathForNewRoad(flag->GetPos(), curFlag->GetPos(), &tmpRoute, &length))
            continue;

        // Wenn ja, dann gucken ob dieser Pfad möglichst kurz zum "höheren" Ziel (allgemeines Lager im Moment) ist
        unsigned maxNonFlagPts = 0;
        // check for non-flag points on planned route: more than 2 nonflaggable spaces on the route -> not really valid path
        unsigned curNonFlagPts = 0;
        MapPoint tmpPos = flag->GetPos();
        for(auto j : tmpRoute)
        {
            tmpPos = aii.gwb.GetNeighbour(tmpPos, j);
            RTTR_Assert(aii.GetBuildingQuality(tmpPos) == aijh.GetAINode(tmpPos).bq);
            if(aii.GetBuildingQuality(tmpPos) == BQ_NOTHING)
                curNonFlagPts++;
            else
            {
                if(maxNonFlagPts < curNonFlagPts)
                    maxNonFlagPts = curNonFlagPts;
                curNonFlagPts = 0;
            }
        }
        if(maxNonFlagPts > 2)
            continue;

        // Find path from current flag to target. If the current flag IS the target then we have already a path with distance=0
        unsigned distance = 0;
        bool pathFound = curFlag == targetFlag || aii.FindPathOnRoads(*curFlag, *targetFlag, &distance);

        // Gewählte Fahne hat leider auch kein Anschluß an ein Lager, zu schade!
        if(!pathFound)
            continue;

        // Sind wir mit der Fahne schon verbunden? Einmal reicht!
        if(aii.FindPathOnRoads(*curFlag, *flag))
            continue;

        // Kürzer als der letzte? Nehmen! Existierende Strecke höher gewichten (2), damit möglichst kurze Baustrecken
        // bevorzugt werden bei ähnlich langen Wegmöglichkeiten
        if(2 * length + distance + 10 * maxNonFlagPts < shortestLength)
        {
            shortest = curFlag;
            shortestLength = 2 * length + distance + 10 * maxNonFlagPts;
            route = tmpRoute;
        }
    }

    if(shortest)
    {
        // LOG.write(("ai build main road player %i at %i %i\n", flag->GetPlayer(), flag->GetPos());
        if(!MinorRoadImprovements(flag, shortest, route))
            return false;
        // add new construction area to the list of active orders in the current nwf
        // to wait till path is constructed
        constructionlocations.push_back(flag->GetPos());
        constructionlocations.push_back(shortest->GetPos());
        return true;
    }
    return false;
}