#apply
#include "../_include.txt"


cev[CEV_STEEL_BRIAN] .name("mg_鋼鉄のブライアン") {

    def {
        NUM_OF_VAR = 64
        NUM_OF_STR = 0
        NUM_OF_PIC = 24

        BASE_LAYER = 6

        PATH_BACK  = "sb\ba"
        PATH_ACTOR = "sb\ac"
        PATH_ENEMY = "sb\en"
        PATH_EVAL  = "sb\ev"
        PATH_DANGER= "sb\da"

        PIC_HEAD = 1
        PIC_BACK
        PIC_ENEMY
        PIC_ALEX
        PIC_DAISY
        PIC_BRIAN
        PIC_CAROL
        PIC_ATK_UP
        PIC_ATK_CENTER
        PIC_ATK_DOWN
        PIC_DMG_UP
        PIC_DMG_CENTER
        PIC_DMG_DOWN
        PIC_DMG_BRIAN
        PIC_DMG_ENEMY
        PIC_MESSAGE
        PIC_EVAL1
        PIC_EVAL2
        PIC_EVAL3

        //結果
        RESULT_ESCAPE = 0
        RESULT_WIN

        //位置
        POSITION_UP = 0
        POSITION_CENTER
        POSITION_DOWN

        //行動予約
        PL_ACT_NONE = 0
        PL_ACT_NEUTRAL
        PL_ACT_MOVE
        PL_ACT_ATTACK
        PL_ACT_GURDE
        PL_ACT_DAMAGE

        //攻撃の状態
        ATK_STATE_NONE = 0
        ATK_STATE_BEFORE_ENEMY
        ATK_STATE_ENEMY
        ATK_STATE_BEFORE_ACTOR
        ATK_STATE_ACTOR

        //戦闘アニメ
        ANIME_ALEX   = 24
        ANIME_CAROL
        ANIME_DAISY
        ANIME_ENEMY1
        ANIME_ENEMY2
        ANIME_ENEMY3

        //アニメバッファ
        BUFFER_ALEX = 0
        BUFFER_DAISY
        BUFFER_CAROL
        BUFFER_ENEMY

        //位置
        BRIAN_X = 210
        BRIAN_Y = 120
        ENEMY_X = 96
        ENEMY_Y = 120

        //定数
        NOCHANGE = -1
        ESCAPE_TIMER = 30
        ACTOR_TIMER = 40
    }

    //ピクチャの共通コマンド
    def {
        basePicCmd = bl {
            .chromakey(1)
            .mapLayer(BASE_LAYER)
            .eraseWhenTransfer
            .affectedByFlash
            .affectedByShake
        }

        bgPicCmd = bl {
            PATH_BACK
            .affectedByTint
            basePicCmd
        }

        actorPicCmd = bl {
            PATH_ACTOR
            .grid(4, 4)
            .affectedByTint
            basePicCmd
        }

        enemyPicCmd = bl {
            PATH_ENEMY
            .grid(3, 1)
            .affectedByTint
            basePicCmd
        }

        atkPicCmd = bl {
            PATH_DANGER
            .affectedByTint
            basePicCmd
        }

        evalPicCmd = bl {
            PATH_EVAL
            .grid(1, 4)
            basePicCmd
        }

        strPicCmd = bl {
            .size(0, 0)
            .font("", 12)
            .spacing(0, 4)
            .skin "" .nobg .noframe .noPadding
            basePicCmd
        }

        damageStrPicCmd = bl {
            .size(0, 0)
            .font("", 12) .bold
            .spacing(0, 4)
            .skin "" .nobg .noframe .noPadding
            .affectedByTint
            basePicCmd
        }

        mesStrPicCmd = bl {
            .size(320, 32)
            .font("", 12)
            .spacing(0, 4)
            .skin ""
            .affectedByTint
            basePicCmd
        }
    }

    //変数定義
    defv {
        gameLevel = TV_MINIGAME//難易度

        varInit

        actorCell
        actorPic
        attackPic
        ipt
        idx
        ptr
        tm1
        tm2
        ax
        ay
        sx
        sy

        result
        rank
        success
        failed
        action
        actionSub
        escapeInput
        enemyHp

        brianPos
        brianTimer

        upState
        upTimer
        upHitTimer

        centerState
        centerTimer
        centerHitTimer

        downState
        downTimer
        downHitTimer

        enemyAct
        upAct
        centerAct
        downAct

        enemyDmg
        brianDmg
        upDmg
        centerDmg
        downDmg

        varFoot
    }

    commentRangeOfVariables(varFoot, TV_MINIGAME, NUM_OF_VAR, NUM_OF_STR, NUM_OF_PIC)

    //プレイヤーの目標位置を取得する
    //u,c,d
    __fn _getBrianTargetPos $dvDst $idx bl {
        v[0 + __id($dvDst)] = [210, 210, 210][$idx]
        v[1 + __id($dvDst)] = [80,  120, 160][$idx]
    }

    //味方の設置位置を取得する
    //a,d,c
    __fn _getActorsHomePosition $dvDst $idx bl {
        v[0 + __id($dvDst)] = [260, 288, 260][$idx]
        v[1 + __id($dvDst)] = [ 80, 120, 160][$idx]
    }

    //------------------------------------------------------------------------------------
    //開始処理
    bl {
        initPicturesAndVariables(PIC_HEAD, NUM_OF_PIC, TV_MINIGAME, NUM_OF_VAR, 0, 0)
        storeAndStopBGM()
        msgBottom()
        
        //色調を暗く
        @scr.tint .rgbs(0, 0, 0, 100)

        //ゲーム開始
        @label.jump "selectLevel"
    }

    //------------------------------------------------------------------------------------
    //難易度選択
    @label.set "selectLevel"
    bl {
        @msg.show "\>ゲーム難易度を選択してください"
        @msg.choice bl {
            .case "\>易しい" {
                gameLevel = 0
            }
            .case "\>普通" {
                gameLevel = 1
            }
            .case "\>難しい" {
                gameLevel = 2
            }
            .cancel bl {
                @label.jump "gameEnd"
            }
        }

        @wait(2)

        @label.jump "gameLoop"
    }

    //------------------------------------------------------------------------------------
    //メインループ
    @label.set "gameLoop"
    bl {
        //変数初期化
        assignVarUsingDeclared(varInit, varFoot, 0)
        //敵
        enemyHp = [16, 32, 48][gameLevel]
        //プレイヤーの位置
        brianPos = POSITION_CENTER

        //BGM
        startBGM("rpgmk95_b2", FALSE, 0, 80, 100, 50)

        //評価画面のピクチャを隠す
        @foreach [PIC_EVAL1, PIC_EVAL2, PIC_EVAL3] .dst(tm1) bl {
            @pic.move[tm1] .trans(100)
        }

        //フラッシュ
        @scr.flash .once(2) .rgbv(31, 31, 31, 31) .wait
        @se.play "Combat2" .opt(100, 100, 50)

        //背景
        @pic.show[PIC_BACK] .pos(0, 0) .topLeft .scale(100) .trans(0) bgPicCmd

        //色調を戻す
        @scr.tint .rgbs(100, 100, 100, 100) .time(2) .wait

        //主人公入場
        @pic.show[PIC_BRIAN] .pos(360, 120) .scale(100) .trans(0) .cell(5) .rgbs(100, 100, 100, 100) actorPicCmd
        @pic.move[PIC_BRIAN] .pos(BRIAN_X, BRIAN_Y) .center .scale(100) .trans(0) .time(1)

        //味方入場
        @loop 3 .dst(idx) {
            actorPic = [PIC_ALEX, PIC_DAISY, PIC_CAROL][idx]
            tm1 = [1, 13, 9][idx]
            tm2 = 360
            _getActorsHomePosition(sx, idx)
            @pic.show[actorPic] .pos(tm2, sy) .scale(100) .trans(0) .cell(tm1) .rgbs(100, 100, 100, 100) actorPicCmd
            @pic.move[actorPic] .pos(sx, sy) .center .scale(100) .trans(0) .time(1)

        }

        //敵入場
        tm1 = gameLevel + 1
        @pic.show[PIC_ENEMY] .pos(-160, ENEMY_Y) .scale(100) .trans(0) .cell(tm1) .rgbs(100, 100, 100, 100) enemyPicCmd
        @pic.move[PIC_ENEMY] .pos(ENEMY_X, ENEMY_Y) .center .scale(100) .trans(0) .time(1)
        @wait(1)

        //敵名
        __loop ["               オークのエントリーだ！！", "                玄武のエントリーだ！！", "                魔王のエントリーだ！！"] $str $idx bl {
            @if gameLevel == $idx bl {
                @pic.strpic[PIC_MESSAGE] $str .pos(0, 0) .topLeft .scale(100) .trans(0) mesStrPicCmd 
            }
        }

        @wait(10)
        @pic.move[PIC_MESSAGE] .trans(100)

        //タイマーを少しずらす
        //アレックスだけ速い
        enemyAct = 500
        upAct = 500

        //----------------------------
        //メインループ
        @loop bl {
            @wait(0)

            //----------------------------
            //終了判定
            @if enemyHp <= 0 bl {
                result = RESULT_WIN
                @wait(2)//少しだけ間を空ける
                @label.jump "battleEnd"
            }

            //----------------------------
            //逃走
            @key.input .dst(ipt) .cancel
            escapeInput = ipt != 0 ? escapeInput + 1 : 0
            @if escapeInput >= ESCAPE_TIMER bl {
                result = RESULT_ESCAPE
                @label.jump "battleEnd"
            }

            //----------------------------
            //アクティブターン
            //アレックス,デイジー,キャロル
            @loop 3 .dst(idx) bl {
                tm1 = [ __id(upState), __id(centerState), __id(downState) ][idx]
                tm2 = [ __id(upAct), __id(centerAct), __id(downAct) ][idx]
                //速さの順は アレックス > キャロル > デイジー
                v[tm2] += [8, 2, 6][idx]
                @if `v[tm1] == ATK_STATE_NONE && v[tm2] >= 1000 bl {
                    v[tm2] = rnd(0, 200)
                    v[tm1] = ATK_STATE_BEFORE_ACTOR
                }
            }

            //敵
            enemyAct += [8, 12, 18][gameLevel]
            @if enemyAct >= 1000 bl {
                //ランダムに選択し、空いていた所を攻撃する
                //空いていない場合は次のフレームに持ち越す
                tm1 = [ __id(upState), __id(centerState), __id(downState) ][rnd(0, 2)]

                @if `v[tm1] == ATK_STATE_NONE bl {
                    //カウンターは少しずれる
                    //玄武はあまりブレないが、魔王はかなりブレる
                    enemyAct = rnd(0, [300, 100, 500][idx])

                    //攻撃
                    v[tm1] = ATK_STATE_BEFORE_ENEMY
                    v[tm1 + 1] = 0

                    //敵の点滅
                    tm1 = gameLevel + 1
                    @pic.show[PIC_ENEMY] .pos(ENEMY_X, ENEMY_Y) .scale(100) .trans(0) .cell(tm1) .rgbs(200, 200, 200, 100) enemyPicCmd
                    @pic.move[PIC_ENEMY] .relative .pos(0, 0) .scale(0) .trans(0) .rgbs(100, 100, 100, 100) .time(2)
                }
            }

            //----------------------------
            //攻撃
            action = PL_ACT_NONE
            actionSub = 0
            @loop 3 .dst(idx) {
                //変数
                def {
                    ptrVar = idx * 3 + __id(upState)
                    atkState  = v[ptr + 0]
                    atkTimer  = v[ptr + 1]
                    hitTimer = v[ptr + 2]
                    animId = [ANIME_ALEX, ANIME_DAISY, ANIME_CAROL][idx]
                    animBuffer = [BUFFER_ALEX, BUFFER_DAISY, BUFFER_CAROL][idx]
                    position = [POSITION_UP, POSITION_CENTER, POSITION_DOWN][idx]
                    atkWait  = [40, 35, 28][gameLevel]
                }

                //ピクチャ番号、セル番号
                actorCell = [1, 13, 9][idx]
                actorPic  = [PIC_ALEX, PIC_DAISY, PIC_CAROL][idx]
                attackPic = [PIC_ATK_UP, PIC_ATK_CENTER, PIC_ATK_DOWN][idx]
                //変数位置
                ptr = ptrVar
                //味方の位置
                _getActorsHomePosition(ax, idx)

                @if `atkState != ATK_STATE_NONE bl {
                    //敵からの攻撃を開始
                    @if `atkState == ATK_STATE_BEFORE_ENEMY bl {
                        atkState = ATK_STATE_ENEMY
                        atkTimer = atkWait
                        //攻撃予告
                        sx = 150
                        sy = ay
                        @pic.show[attackPic] .pos(sx, sy) .scale(120) .trans(0) .rgbs(100, 100, 100, 100) atkPicCmd
                        @pic.move[attackPic] .relative .pos(16, 0) .scale(-20) .trans(100) .time(2)
                        //場所によって周波数を変える
                        tm1 = [80, 100, 120][idx]
                        @se.play "Attack1" .opt(90, tm1, 50)

                    //敵からの攻撃
                    } .elif `atkState == ATK_STATE_ENEMY bl {
                        //タイマー
                        atkTimer -= 1
                        @if `atkTimer <= 0 bl {
                            atkState = ATK_STATE_NONE
                            atkTimer = 0
                            //防御成功
                            @if `brianPos == position bl {
                                action = PL_ACT_GURDE
                                //評価上昇
                                success += 1
                                //ダメージ表示
                                brianDmg = rnd(30, 99)

                            //味方が被弾
                            } .else bl {
                                hitTimer = ACTOR_TIMER
                                //評価下降
                                failed += 1
                                //ダメージ表示
                                v[__id(upDmg) + idx] = rnd(100, 200)
                                //タイマーが少し戻る
                                tm1 = [ __id(upAct), __id(centerAct), __id(downAct) ][idx]
                                v[tm1] = min(v[tm1], 1000 - 8 * 30)
                                //戦闘アニメ
                                tm1 = ANIME_ENEMY1 + gameLevel
                                @anim.show[tm1] .picTarget(actorPic) .buffer(BUFFER_ENEMY)
                                //怯む
                                tm1 = actorCell + 2
                                sx = ax
                                sy = ay
                                @pic.show[actorPic] .pos(sx, sy) .scale(100) .trans(0) .cell(tm1) .rgbs(200, 0, 0, 100) actorPicCmd
                                @pic.move[actorPic] .relative .pos(8, 0) .scale(0) .trans(0) .rgbs(100, 100, 100, 100) .time(3)
                            }
                        }

                    //味方からの攻撃を開始
                    } .elif `atkState == ATK_STATE_BEFORE_ACTOR bl {
                        atkState = ATK_STATE_ACTOR
                        atkTimer = atkWait
                        //点滅する
                        tm1 = actorCell
                        sx = ax
                        sy = ay
                        @pic.show[actorPic] .pos(sx, sy) .scale(100) .trans(0) .cell(tm1) .rgbs(200, 200, 200, 100) actorPicCmd
                        @pic.move[actorPic] .relative .pos(-8, 0) .scale(0) .trans(0) .rgbs(100, 100, 100, 100) .time(2)
                        //場所によって周波数を変える
                        tm1 = [80, 100, 120][idx]
                        @se.play "Attack2" .opt(90, tm1, 50)

                    //味方からの攻撃
                    } .elif `atkState == ATK_STATE_ACTOR bl {
                        //タイマー
                        atkTimer -= 1
                        @if `atkTimer <= 0 bl {
                            atkState = ATK_STATE_NONE
                            atkTimer = 0
                            //攻撃動作
                            hitTimer = ACTOR_TIMER
                            //構える
                            tm1 = actorCell + 1
                            sx = ax - 16
                            sy = ay
                            @pic.show[actorPic] .pos(sx, sy) .scale(100) .trans(0) .cell(tm1) .rgbs(100, 100, 100, 100) actorPicCmd
                            //戦闘アニメ
                            tm1 = animId
                            tm2 = animBuffer
                            //デイジー
                            @if idx == 1 bl {
                                //ダメージ表示
                                v[__id(brianDmg)..__id(downDmg)] = -999
                                //戦闘アニメ
                                @anim.show[tm1] .picTarget(PIC_DAISY) .buffer(tm2)

                            //アレックス or キャロル
                            } .else {
                                //攻撃を阻んだ
                                @if `brianPos == position bl {
                                    action = PL_ACT_DAMAGE
                                    //評価が下がる
                                    //味方を邪魔する方が印象が悪い
                                    failed += 1
                                    //ダメージ表示
                                    brianDmg = rnd(100, 300)
                                    //戦闘アニメ
                                    @anim.show[tm1] .picTarget(PIC_BRIAN) .buffer(tm2)

                                //攻撃
                                } .else bl {
                                    //HP減少
                                    enemyHp -= 1
                                    //ダメージ表示
                                    enemyDmg = rnd(200, 500)
                                    //戦闘アニメ
                                    @anim.show[tm1] .picTarget(PIC_ENEMY) .buffer(tm2)
                                    //敵ノックバック
                                    tm1 = gameLevel + 1
                                    @pic.show[PIC_ENEMY] .pos(ENEMY_X - 8, ENEMY_Y) .scale(100) .trans(0) .cell(tm1) .rgbs(200, 0, 0, 100) enemyPicCmd
                                    @pic.move[PIC_ENEMY] .relative .pos(8, 0) .scale(0) .trans(0) .rgbs(100, 100, 100, 100) .time(2)
                                }
                            }
                        }
                    }
                }

                //攻撃 or 怯み動作
                @if `hitTimer > 0 bl {
                    hitTimer -= 1
                    //動作を解除
                    @if `hitTimer <= 0 bl {
                        tm1 = actorCell + 0
                        sx = ax
                        sy = ay
                        @pic.show[actorPic] .pos(sx, sy) .scale(100) .trans(0) .cell(tm1) .rgbs(100, 100, 100, 100) actorPicCmd
                    }
                }
            }

            //----------------------------
            //ダメージ表示
            @loop 5 .dst(idx) bl {
                ptr = idx + __id(enemyDmg)
                @if `v[ptr] != 0 bl {
                    //座標
                    @if idx == 0 bl {
                        sx = ENEMY_X
                        sy = ENEMY_Y + 64

                    } .elif idx == 1 bl {
                        _getBrianTargetPos(sx, brianPos)
                        sy += 16

                    } .elif `between(idx, 2, 4) bl {
                        tm1 = idx - 2
                        _getActorsHomePosition(sx, tm1)
                        sy += 16

                    }

                    //ピクチャ番号
                    actorPic = [PIC_DMG_ENEMY, PIC_DMG_BRIAN, PIC_DMG_UP, PIC_DMG_CENTER, PIC_DMG_DOWN][idx]
                    //ダメージ量
                    tm1 = v[ptr]
                    //色を変える
                    @if tm1 > 0 bl {
                        @pic.strpic[actorPic] __str("\c[0]\",tm1) .pos(sx, sy) .scale(200) .trans(-500) .rgbs(100, 100, 100, 100) damageStrPicCmd

                    } .elif tm1 < 0 bl {
                        tm1 *= -1
                        @pic.strpic[actorPic] __str("\c[9]\",tm1) .pos(sx, sy) .scale(200) .trans(-500) .rgbs(100, 100, 100, 100) damageStrPicCmd
                    }

                    @pic.move[actorPic] .relative .pos(0, 16) .scale(0) .trans(600) .keepRgbs .time(5)
                    //変数初期化
                    v[ptr] = 0
                }
            }

            //----------------------------
            //ブライアン
            //予約済み
            @if action != PL_ACT_NONE bl {
            //通常状態
            } .else bl {
                //硬直
                @if brianTimer > 0 bl {
                    brianTimer -= 1

                    @if brianTimer <= 0 bl {
                        action = PL_ACT_NEUTRAL
                    }
                }

                //入力方向を取得する
                @key.input .dst(ipt) {
                    .up
                    .down
                    .right
                    .left
                }

                //center
                @if `(ipt == KEY_RIGHT || ipt == KEY_LEFT) && brianPos != POSITION_CENTER bl {
                    action = PL_ACT_MOVE
                    actionSub = POSITION_CENTER

                //up
                } .elif `ipt == KEY_UP && brianPos != POSITION_UP bl {
                    action = PL_ACT_MOVE
                    actionSub = POSITION_UP

                //down
                } .elif `ipt == KEY_DOWN && brianPos != POSITION_DOWN bl {
                    action = PL_ACT_MOVE
                    actionSub = POSITION_DOWN
                }
            }

            //----------------------------
            //動作
            @if action != PL_ACT_NONE bl {
                _getBrianTargetPos(sx, brianPos)
                //ニュートラル
                @if action == PL_ACT_NEUTRAL bl {
                    brianTimer = 0

                    @pic.show[PIC_BRIAN] .pos(sx, sy) .scale(100) .trans(0) .cell(5) .rgbs(100, 100, 100, 100) actorPicCmd

                //移動
                } .elif action == PL_ACT_MOVE bl {
                    brianTimer = 0
                    brianPos = actionSub

                    _getBrianTargetPos(sx, brianPos)
                    sy -= 16
                    @pic.show[PIC_BRIAN] .pos(sx, sy) .scale2(80, 120) .trans(0) .cell(5) .rgbs(100, 100, 100, 100) actorPicCmd
                    @pic.move[PIC_BRIAN] .relative .pos(0, 16) .center .scale2(20, -20) .trans(0) .time(1)
                    @se.play "Jump1" .opt(70, 150, 50)

                //ガード成功
                } .elif action == PL_ACT_GURDE bl {
                    brianTimer = ACTOR_TIMER

                    @pic.show[PIC_BRIAN] .pos(sx, sy) .scale(100) .trans(0) .cell(7) .rgbs(200, 200, 200, 100) actorPicCmd
                    @pic.move[PIC_BRIAN] .relative .pos( 4, 0) .scale(0) .trans(0) .rgbs(100, 100, 100, 100) .time(2)
                    @se.play "Sword1" .opt(100, 100, 50)

                //ダメージ
                } .elif action == PL_ACT_DAMAGE bl {
                    brianTimer = ACTOR_TIMER

                    @pic.show[PIC_BRIAN] .pos(sx, sy) .scale(100) .trans(0) .cell(7) .rgbs(200, 0, 0, 100) actorPicCmd
                    @pic.move[PIC_BRIAN] .relative .pos(-4, 0) .scale(0) .trans(0) .rgbs(100, 100, 100, 100) .time(2)
                    @se.play "voice_aa" .opt(100, 120, 50)

                }
            }
        }
    }

    //------------------------------------------------------------------------------------
    //戦闘終了
    @label.set "battleEnd"
    bl {
        //BGMフェードアウト
        stopBGM(1000)

        //----------------------------
        //逃走
        @if result == RESULT_ESCAPE bl {
            //メッセージ
            @pic.strpic[PIC_MESSAGE] "                  逃げた・・・" .pos(0, 0) .topLeft .scale(100) .trans(0) mesStrPicCmd 

            //味方を下げる
            @foreach [PIC_ALEX, PIC_BRIAN, PIC_DAISY, PIC_CAROL] .dst(tm1) {
                @pic.move[tm1] .relative .pos(160, 0) .scale(0) .trans(0) .time(2)
            }

            @se.play "Escape" .opt(80, 100, 50)
            @wait(15)

            //背景を暗くする
            @scr.tint .rgbs(0, 0, 0, 100) .time(2) .wait
            @wait(5)

            //雑音が混ざるので、BGMを停止させておく
            stopBGM(0)
            
            //確認なしで終了する
            @label.jump "gameEnd"

        //勝利
        } .else bl {
            //敵消滅演出
            @pic.move[PIC_ENEMY] .relative .pos(0, 0) .center .scale(0) .trans(0) .rgbs(200, 200, 200, 100)
            @wait(0)

            @se.play "Combat2" .opt(100, 100, 50)
            @scr.flash .once(2) .rgbv(31, 31, 31, 31)
            @scr.shake .once(8) .value(5, 5)

            @pic.move[PIC_ENEMY] .relative .pos(0, 16) .center .scale(0) .trans(100) .rgbs(150, 20, 20, 50) .time(10) 

            @wait(15)

            //勝利BGM
            startBGM("JEnd of Battle 1", FALSE, 0, 100, 100, 50)
            @wait(5)

            //メッセージ
            @pic.strpic[PIC_MESSAGE] "                  圧倒的勝利ッ！" .pos(0, 0) .topLeft .scale(100) .trans(0) mesStrPicCmd 

            //勝利ポーズ
            @pic.show[PIC_BRIAN] .pos(BRIAN_X, BRIAN_Y) .center .scale(100) .trans(0) .cell(8) .rgbs(200, 200, 200, 200) actorPicCmd
            @pic.move[PIC_BRIAN] .relative .pos(0, 0) .center .scale(0) .trans(0) .time(2) .rgbs(100, 100, 100, 100)

            @loop 3 .dst(idx) {
                actorPic = [PIC_ALEX, PIC_DAISY, PIC_CAROL][idx]
                tm1 = [4, 16, 12][idx]

                _getActorsHomePosition(sx, idx)
                @pic.show[actorPic] .pos(sx, sy) .center .scale(100) .trans(0) .cell(tm1) .rgbs(200, 200, 200, 200) actorPicCmd
                @pic.move[actorPic] .relative .pos(0, 0) .center .scale(0) .trans(0) .time(2) .rgbs(100, 100, 100, 100)
            }

            @wait(25)

            //評価画面へ
            @label.jump "evaluation"
        }
    }

    //------------------------------------------------------------------------------------
    //評価画面
    @label.set "evaluation"
    bl {
        //評価する
        tm1 = success + failed * 2
        @if tm1 > 0 bl {
            tm1 = success * 1000 / tm1
            @if tm1 < 500 bl {
                rank = 0
            } .elif tm1 < 800 bl {
                rank = 1
            } .elif tm1 < 1000 bl {
                rank = 2
            } .else bl {
                rank = 3
            }
        } .else bl {
            //例外は平凡扱いとする
            rank = 1
        }

        //----------------------------
        //背景を暗くする
        @scr.tint .rgbs(0, 0, 0, 100) .time(2) .wait
        @wait(5)

        //ピクチャを隠す
        @foreach [PIC_ATK_UP, PIC_ATK_CENTER, PIC_ATK_DOWN, PIC_ENEMY, PIC_ALEX, PIC_DAISY, PIC_BRIAN, PIC_CAROL, PIC_MESSAGE] .dst(tm1) bl {
            @pic.move[tm1] .trans(100)
        }

        //評価を表示する
        //表示1
        @pic.strpic[PIC_EVAL1] "\c[2]【 仲間からの評価 】\c[0]" .topLeft .pos(48, 40) .scale(100) .trans(0) strPicCmd
        @se.play "Cursor2" .opt(100, 100, 50)
        @wait(10)

        //表示2
        __loop ["かぶとむし。",
            "お前がいなかったら危なかったかもな",
            "的確な動き。頼りになるわね",
            "パーフェクト！正しく鉄壁です！"
        ] $str $idx bl {
            @if rank == $idx bl {
                @pic.strpic[PIC_EVAL2] $str .topLeft .pos(64, 64) .scale(100) .trans(0) strPicCmd
            }
        }

        @se.play "Cursor2" .opt(100, 130, 50)
        @wait .frame(4)
        @se.play "Cursor2" .opt(100, 170, 50)
        @wait(14)

        //表示3
        tm1 = 1 + rank
        @pic.show[PIC_EVAL3] .pos(160, 88) .topLeft .scale(100) .trans(0) .cell(tm1) evalPicCmd

        //効果音
        __loop [bl {
                @se.play "bell1" .opt(100, 80, 50)
            },
            bl {
                @se.play "pon" .opt(100, 100, 50)
            },
            bl {
                @se.play "Chime2" .opt(100, 100, 50)
            },
            bl {
                @scr.flash .once(2) .rgbv(31, 31, 31, 31)
                @se.play "cheers" .opt(100, 100, 50)
                @se.play "voice_ieeei2" .opt(80, 100, 50)
            }
        ] $block $idx bl {
            @if rank == $idx $block
        }

        //実績
        checkSetAchievement(achievedSteel, gameLevel >= 1 && rank >= 3)

        @wait(10)

        //----------------------------
        //報酬
        tm1 = (gameLevel + 1) * [20, 100, 180, 320][rank]
        //総収入に加える
        steelBrianIncome += tm1
        //実際に所持金に加える
        @party.money .add(tm1)

        @se.play "register" .opt(100, 100, 50)

        //メッセージ
        @msg.face("", 0, .left)
        @msg.show __str("\>\c[2]【 報酬 】\c[0]", NEWLINE, "\>\c[7]\", tm1, "\c[0] PT也\$")

        //選択肢
        @msg.choice bl {
            .cancel(2)
            .case "\>続ける" {
                @label.jump "gameLoop"
            }
            .case "\>難易度を変える" {
                @label.jump "selectLevel"
            }
            .case "\>やめる" {
                @label.jump "gameEnd"
            }
        }
    }

    //------------------------------------------------------------------------------------
    //終了する
    @label.set "gameEnd"
    bl {
        initPicturesAndVariables(PIC_HEAD, NUM_OF_PIC, TV_MINIGAME, NUM_OF_VAR, 0, 0)
        restoreBGM()
        fastFadeInTintOnly(1)
    }
}