#apply
#include "../_include.txt"
#include "../../define/_vector2.txt"
#include "../../define/_const_pinball.txt"

/*
@param
タイプ
加算値
ビットフラグ
*/
cev[CEV_PB_ADD_SCORE] .name(">>>>得点を加える") {
    defv {
        a_type = TV_PB_ADD_SCORE
        a_point
        a_bit

        old
    }

    //加算が無効になっている
    @if `!enableScore bl {
        @ev.abort
    }

    //倍率を適用する
    @if `a_type == NUM_TYPE_SCORE && (a_bit & NUM_BIT_MULTI) bl {
        a_point = a_point * multiplier
    }

    pseudoSwitchState(a_type,
        [NUM_TYPE_SCORE, bl {
            @if score < MAX_SCORE bl {
                old = score
                score = min(score + a_point, MAX_SCORE)

                //アニメーションあり
                @if `a_bit & NUM_BIT_REEL bl {
                    scoreDisplay = old
                    scoreStep = max( (score - old) / 60, SCORE_REEL_MIN)                

                //アニメーションなし
                } .else bl {
                    scoreDisplay = score
                    bitOn(triggerFlg, SC_BIT_SCORE)
                }

                logCount += 1
                strLog .cat(__str("\c[2]+\",a_point, NEWLINE) .extract)
                bitOn(triggerFlg, SC_BIT_LOG)
            }
        },
        NUM_TYPE_BONUS, bl {
            @if bonus < MAX_BONUS bl {
                //パワーアップ中は取得ボーナスが倍になる
                old = (powerupTimer > 0 ? 2 : 1) * a_point

                bonus = min(bonus + old, MAX_BONUS)
                bitOn(triggerFlg, SC_BIT_BONUS)

                logCount += 1
                strLog .cat(__str("\c[5]+\",old, NEWLINE) .extract)
                bitOn(triggerFlg, SC_BIT_LOG)
            }
        },
        NUM_TYPE_MULTI, bl {
            @if multiplier < MAX_MULTI bl {
                multiplier = min(multiplier + a_point, MAX_MULTI)
                bitOn(triggerFlg, SC_BIT_MULTI)

                logCount += 1
                strLog .cat(__str("\c[7]+\",a_point, NEWLINE) .extract)
                bitOn(triggerFlg, SC_BIT_LOG)
            }
        },
        NUM_TYPE_CHANCE, bl {
            @if chance < MAX_CHANCE bl {
                chance = min(chance + a_point, MAX_CHANCE)
                bitOn(triggerFlg, SC_BIT_CHANCE)

                logCount += 1
                strLog .cat(__str("\c[9]+\",a_point, NEWLINE) .extract)
                bitOn(triggerFlg, SC_BIT_LOG)
            }
        } ]
    )
}