Пример #1
0
void Building::updateInhabitants(const Context& context) {
    // Bin ich ein Haus?
    if (!isHouse()) {
        return;
    }

    // Laune berücksichtigen. Neutral = keine Veränderung
    const PopulationTier* populationTier = mapObjectType->populationTier;
    if (colony->populationTiers[populationTier].populationSatisfaction == PopulationSatisfaction::NEUTRAL) {
        return;
    }

    if (colony->populationTiers[populationTier].populationSatisfaction == PopulationSatisfaction::BAD ||
        colony->populationTiers[populationTier].populationSatisfaction == PopulationSatisfaction::WORST) {

        // TODO mies gelaunte Häuser
        Log::debug("Houses are not satisfied. TODO decrease inhabitants");
        return;
    }

    // ggf. Aufstieg machen
    checkForHouseAdvancement(context);

    // Haus voll?
    if (inhabitants >= mapObjectType->populationTier->maxPopulationPerHouse) {
        return;
    }

    // In den ersten 2 Minuten kein Bevölkerungswachstum
    if (context.game->getTicks() - createdTicks < 125*TICKS_PER_SECOND) {
        return;
    }

    // Nicht alle Gebäude auf einmal. Maximal alle 500ms einer
    // TODO Zufall
    if (context.game->getTicks() - colony->populationTiers[populationTier].lastIncreaseTicks < 500) {
        return;
    }

    colony->populationTiers[populationTier].lastIncreaseTicks = context.game->getTicks();
    context.game->addInhabitantsToBuilding(this, 1);
    // TODO Siedler und höhere Bevölkerungsgruppen nehmen nicht um 1, sondern mehr zu
}
Пример #2
0
bool ChessModel::isMovable(char player, QPair<int, int> st, QPair<int, int> ed) const
{
    if (player == 'A') {
        st.first = 14 - st.first;
        st.second = 6 - st.second;
        ed.first = 14 - ed.first;
        ed.second = 6 - ed.second;
    }
    if (st.first < 1 || st.first > 13 || st.second < 1 || st.second > 5 ||
            ed.first < 1 || ed.first > 13 || ed.second < 1 || ed.second > 5) return 0;
    if (getChessId(player, ed) != -1) return 0;
    if (getChessId(player, st) == -1) return 0;
    if (isHouse(ed) && (getChessId('A' + 'B' - player, ed) != -1)) return 0;

    int pt = pieceType[getChessId(player, st)];
    if (pt == 10 || pt == 12) return 0;

    if (ed.first == 7  && (ed.second == 2 || ed.second == 4)) return 0;
    if ((st.first == 1 || st.first == 13) && (st.second == 2 || st.second == 4)) return 0;
    int dis = abs(st.first - ed.first) + abs(st.second - ed.second);

    if (dis == 1) return 1;
    if (dis == 2 && (isHouse(st) || isHouse(ed))) return 1;

    if (isRail(st) && isRail(ed)) {
        if (st.first == ed.first) {
            bool flag = 1;
            for (int i = qMin(st.second, ed.second) + 1; i <= qMax(st.second, ed.second) - 1; i++)
                if (getChessId('A', qMakePair(st.first, i)) != -1 || getChessId('B', qMakePair(st.first, i)) != -1)
                    flag = 0;
            if (flag) return 1;
        }
        if (st.second == ed.second) {
            bool flag = 1;
            for (int i = qMin(st.first, ed.first) + 1; i <= qMax(st.first, ed.first) - 1; i++)
                if (getChessId('A', qMakePair(i, st.second)) != -1 || getChessId('B', qMakePair(i, st.second)) != -1)
                    flag = 0;
            if (flag) return 1;
        }
        if (pt != 9) return 0;
        QQueue< QPair<int, int> > queue;
        QSet< QPair<int, int> > set;
        queue.push_back(st);
        while (!queue.empty()) {
            QPair<int, int> now = queue.front();
            queue.pop_front();
            for (int i = 0; i < 4; i++) {
                QPair<int, int> tmp = now;
                tmp.first += dx[i];
                tmp.second += dy[i];
                if (isRail(tmp) && getChessId('A', tmp) == -1 && getChessId('B', tmp) == -1 && set.find(tmp) == set.end()) {
                    queue.push_back(tmp);
                    set.insert(tmp);
                }
            }
        }
        for (auto itm : set) {
            if (qAbs(itm.first - ed.first) + qAbs(itm.second - ed.second) <= 1)
                return 1;
        }
    }
    return 0;
}