コード例 #1
0
ファイル: GameState.cpp プロジェクト: mkristofik/battle-sim
void GameState::runActionSeq(Action action)
{
    // The First Strike ability lets the defender get its retaliation in prior
    // to the actual attack.  We must therefore split the attack into two
    // separate actions, a move and (if the attacker is still alive) an attack.
    if (isFirstStrikeAllowed(action)) {
        if (action.path.size() > 1) {
            auto moveAction = action;
            moveAction.type = ActionType::MOVE;
            actionCallback(moveAction);
        }
        auto firstStrike = makeRetaliation(action);
        actionCallback(firstStrike);

        const auto &att = getUnit(action.attacker);
        if (att.isAlive()) {
            action = makeAttack(action.attacker, action.defender, att.aHex);
        }
        else {
            return;
        }
    }

    actionCallback(action);

    if (isBindAllowed(action)) {
        auto binder = makeBind(action.attacker, action.defender);
        actionCallback(binder);
    }
    if (isRetaliationAllowed(action)) {
        auto retal = makeRetaliation(action);
        actionCallback(retal);

        // TODO: can we generalize this for any ability that happens on attack
        // and retaliate?
        if (isBindAllowed(retal)) {
            auto binder = makeBind(retal.attacker, retal.defender);
            actionCallback(binder);
        }
    }
    if (isDoubleStrikeAllowed(action)) {
        const auto &att = getUnit(action.attacker);
        auto secondStrike = makeAttack(att.entityId, action.defender, att.aHex);
        actionCallback(secondStrike);
    }
    if (isTrampleAllowed(action)) {
        const auto &def = getUnit(action.defender);
        auto trample = makeMove(action.attacker, def.aHex);
        actionCallback(trample);
    }
}
コード例 #2
0
int DnDCharacter::makeRoll(QString type, QString mod, int bonus){
    if(type == "attack")
        return makeAttack(type, mod,bonus);
    else if(type == "will" || type == "fortitude" || type == "reflex")
        return makeSave(type,mod,bonus);
    else if(type == "None")
        return die->roll() + getMod(mod) + bonus;
    else
        return die->roll() + getValue(type).toInt() + getMod(mod) + bonus;
}
コード例 #3
0
ファイル: GameState.cpp プロジェクト: mkristofik/battle-sim
std::vector<Action> GameState::getPossibleActions() const
{
    const auto &unit = getActiveUnit();
    assert(unit.isAlive());

    auto reachableHexes = getReachableHexes(unit);
    std::vector<Action> actions;

    if (canUseRangedAttack(unit.entityId)) {
        for (auto e : getAllEnemies(unit.entityId)) {
            actions.push_back(makeAttack(unit.entityId, e, unit.aHex));
        }
    }
    else if (canUseSpell(unit.entityId)) {
        for (const auto &target : units_) {
            if (!target.isAlive()) continue;
            auto possible = makeAttack(unit.entityId, target.entityId,
                                       unit.aHex);
            if (possible.type == ActionType::NONE) continue;
            actions.push_back(std::move(possible));
        }
    }
    else if (canUseMeleeAttack(unit.entityId)) {
        for (auto aHex : reachableHexes) {
            for (auto e : getAdjEnemies(unit.entityId, aHex)) {
                actions.push_back(makeAttack(unit.entityId, e, aHex));
            }
        }
    }

    actions.emplace_back(makeSkip(unit.entityId));

    for (auto aHex : reachableHexes) {
        if (aHex != unit.aHex) {
            actions.emplace_back(makeMove(unit.entityId, aHex));
        }
    }

    return actions;
}
コード例 #4
0
ファイル: badcontrol.cpp プロジェクト: drtrev/curses
void Badcontrol::go(float playerX, float playerY, double sync, Bulletcontrol &bulletcontrol, Powerupcontrol &powerupcontrol, Timer &timer, bool &gameover, Net &net, Server &server)
{
    // s = ut + 0.5 * att
    // a = 0
    formationX += speedX * sync;

    // check if any baddie has hit the edge of the screen, using their place in formation
    // If they have, change formation direction
    for (int i = 0; i < badlen; i++) {
        if (bad[i].getActive() && !bad[i].getDying()) {
            if ((formationX + bad[i].getOffsetX() + bad[i].getWidth() / 2.0 > out->getWidth() && speedX > 0.0)
                    || (formationX + bad[i].getOffsetX() - bad[i].getWidth() / 2.0 < 0 && speedX < 0.0))
            {
                speedX = -speedX;
                if (moveDown) {
                    formationY++;
                    speedX = (speedX < 0) ? speedX - speedInc : speedX + speedInc;
                    for (int i = 0; i < badlen; i++) {
                        if (bad[i].getActive() && !bad[i].getDying()) {
                            if (formationY + bad[i].getOffsetY() + bad[i].getHeight() / 2.0 > out->getHeight()) {
                                gameover = true;
                            }
                        }
                    }
                }
                break;
            }
        }
    }

    if (spawning) spawn(timer, net, server);

    int dead = 0;

    for (int i = 0; i < badlen; i++) {
        if (bad[i].getActive()) bad[i].go(i, formationX, formationY, playerX, playerY, sync, bulletcontrol, powerupcontrol, timer, net, server);
        else dead++;
    }

    if (dead == badlen) {
        makeAttack(attackWave, timer.getCurrent());

        Unit unit;
        unit.attack.flag = UNIT_ATTACK;
        unit.attack.wave = attackWave;

        net.addUnitAll(unit, server, -1);

        attackWave++;
        if (attackWave > attacklen) attackWave = 0;
    }
}