#include "MyShip.h"

#include "jp/ggaf/core/actor/ex/ActorDepository.h"
#include "jp/ggaf/dx/actor/supporter/Checker.h"
#include "jp/ggaf/dx/actor/supporter/VecDriver.h"
#include "jp/ggaf/dx/actor/supporter/GeoDriver.h"
#include "jp/ggaf/dx/actor/supporter/Scaler.h"
#include "jp/ggaf/dx/actor/supporter/SeTransmitterForActor.h"
#include "jp/ggaf/dx/model/Model.h"
#include "jp/ggaf/dx/util/CollisionArea.h"
#include "jp/ggaf/dx/util/CollisionPart.h"
#include "jp/ggaf/lib/actor/laserchip/LaserChipDepository.h"
#include "jp/ggaf/lib/util/CollisionChecker.h"
#include "jp/gecchi/VioletVreath/actor/effect/EffectTurbo001.h"
#include "jp/gecchi/VioletVreath/actor/my/MagicMeter.h"
#include "jp/gecchi/VioletVreath/actor/my/MagicMeter/DamageDispBar.h"
#include "jp/gecchi/VioletVreath/actor/my/MyLockonController.h"
#include "jp/gecchi/VioletVreath/actor/my/MyMagicEnergyCore.h"
#include "jp/gecchi/VioletVreath/actor/my/MyShot001.h"
#include "jp/gecchi/VioletVreath/actor/my/MySnipeShot001.h"
#include "jp/gecchi/VioletVreath/actor/my/MyStraightLaserChip001.h"
#include "jp/gecchi/VioletVreath/actor/my/MyTorpedoController.h"
#include "jp/gecchi/VioletVreath/God.h"
#include "jp/gecchi/VioletVreath/Config.h"
#include "jp/gecchi/VioletVreath/util/MyStgUtil.h"
#include "jp/gecchi/VioletVreath/actor/my/Bunshin/MyBunshinBase.h"
#include "jp/ggaf/lib/util/Direction26Util.h"
#include "jp/ggaf/lib/util/ColliAAPrism.h"
#include "jp/ggaf/lib/util/ColliAAPyramid.h"

using namespace GgafLib;
using namespace VioletVreath;

coord MyShip::lim_y_top_     =  0;
coord MyShip::lim_y_bottom_  =  0;
coord MyShip::lim_x_infront_ =  0;
coord MyShip::lim_x_behaind_ =  0;
coord MyShip::lim_z_left_    =  0;
coord MyShip::lim_z_right_   =  0;

uint32_t MyShip::shot2_matrix_[4][MYSHIP_SHOT_MATRIX] = {
    {
            8,           //  0001000
            0,           //  0000000
            0,           //  0000000
            0,           //  0000000
            0,           //  0000000
            0,           //  0000000
            8            //  0001000
    },
    {
            0,           //  0000000
            2,           //  0000010
            0,           //  0000000
            0,           //  0000000
            0,           //  0000000
           32,           //  0100000
            0            //  0000000
    },
    {
            0,           //  0000000
            0,           //  0000000
            0,           //  0000000
           65,           //  1000001
            0,           //  0000000
            0,           //  0000000
            0            //  0000000
    },
    {
            0,           //  0000000
           32,           //  0100000
            0,           //  0000000
            0,           //  0000000
            0,           //  0000000
            2,           //  0000010
            0            //  0000000

    }
};

uint32_t MyShip::shot3_matrix_[2][MYSHIP_SHOT_MATRIX] = {
    {
            8,           //  0001000
            0,           //  0000000
            0,           //  0000000
           65,           //  1000001
            0,           //  0000000
            0,           //  0000000
            8            //  0001000
    },
    {
            0,           //  0000000
           34,           //  0100010
            0,           //  0000000
            0,           //  0000000
            0,           //  0000000
           34,           //  0100010
            0            //  0000000
    }
};

/** 僜僼僩楢幩悢偱丄侾僾僢僔儏偱寕偮偙偲偑弌棃傞楢幩悢 */
#define SOFT_RAPIDSHOT_NUM       (3)
/** 僜僼僩楢幩悢偱偺僔儑僢僩偲僔儑僢僩偺娫妘 */
#define SOFT_RAPIDSHOT_INTERVAL  (4)

enum {
    SE_DAMAGED     ,
    SE_EXPLOSION   ,
    SE_TURBO       ,
    SE_CANT_TURBO  ,
    SE_FIRE_LASER  ,
    SE_FIRE_SHOT   ,
    SE_FIRE_TORPEDO,
};


MyShip::MyShip(const char* prm_name) :
        VvMyActor<DefaultD3DXMeshActor>(prm_name, "VicViper", StatusReset(MyShip)) {
//DefaultMeshActor(prm_name, "jiki") {
//CubeMapMeshActor(prm_name, "wakka") {
//DefaultD3DXAniMeshActor(prm_name, "AnimatedSkelton") {
    _class_name = "MyShip";

    //effectBlendOne(); //壛嶼崌惉Technique巜掕

    //夋柺偺戝偒偝偵敽偭偰丄堏摦斖埻傪寛掕
    //偙偺偁偨傝偼FovX偵埶懚偡傞偺偱旝挷惍丅
    static const coord game_buffer_width  = PX_C(CONFIG::GAME_BUFFER_WIDTH);
    static const coord game_buffer_height = PX_C(CONFIG::GAME_BUFFER_HEIGHT);
    MyShip::lim_y_top_     =  (game_buffer_height/2) + game_buffer_height*4;  //忋偼丄崅偝4夋柺暘尒偊側偄椞堟傑偱堏摦壜擻
    MyShip::lim_y_bottom_  = -(game_buffer_height/2) - game_buffer_height*4;  //壓偼丄崅偝4夋柺暘尒偊側偄椞堟傑偱堏摦壜擻
    MyShip::lim_x_infront_ =  (game_buffer_width/2)  + game_buffer_width*2;   //慜偼丄暆偺2夋柺暘尒偊側偄椞堟傑偱堏摦壜擻
    MyShip::lim_x_behaind_ = -(game_buffer_width/2)  - game_buffer_width*1;   //屻傠偼丄暆偺侾夋柺暘尒偊側偄椞堟傑偱堏摦壜擻
    MyShip::lim_z_left_    =  (game_buffer_height/2) + game_buffer_height*4;   //庤慜偼丄崅偝4夋柺暘尒偊側偄椞堟傑偱堏摦壜擻
    MyShip::lim_z_right_   = -(game_buffer_height/2) - game_buffer_height*4;   //墱偼丄崅偝4夋柺暘尒偊側偄椞堟傑偱堏摦壜擻
    _TRACE_("MyShip 斖埻 X("<<MyShip::lim_x_behaind_<<" 乣 "<<MyShip::lim_x_infront_<<")  Y("<<MyShip::lim_y_bottom_<<" 乣 "<<MyShip::lim_y_top_<<")  Z("<<MyShip::lim_z_right_<<" 乣 "<<MyShip::lim_z_left_<<")");


    //CommonScene偑new偺応崌愝掕
    angRxVelo_BeginMZ_ = 1000;   //墱枖偼庤慜傊捠忢Z捠忢堏摦奐巒帪偺X幉夞揮妏懍搙偺弶懍搙
    angRxAcce_MZ_ = 300;         //墱枖偼庤慜傊捠忢Z堏摦拞偺X幉夞揮妏懍搙偺弶妏壛懍搙
    angRxTopVelo_MZ_ = 5000;     //墱枖偼庤慜傊捠忢Z堏摦拞偺X幉夞揮妏懍搙偺忋尷妏懍搙
    angRxStop_MZ_ = 90000;       //墱枖偼庤慜傊捠忢Z堏摦拞偺X幉夞揮妏偺栚昗掆巭妏搙
    angRxVelo_BeginMZT_ = 20000; //墱枖偼庤慜傊Turbo堏摦奐巒帪偺X幉夞揮妏懍搙偺弶懍搙

    mv_speed_ = 0;
    veloBeginMT_ = 0;
    setMoveSpeed(2000);


//    //debug ---->
//    pDepo_TestGuShot_ = NEW GgafCore::ActorDepository("Depo_TestGuShot");
//    for (int i = 0; i < 25; i++) { //僥僗僩僌乕抏僗僩僢僋
//        pDepo_TestGuShot_->appendChild(NEW TestGuShot("TestGuShot"));
//    }
//    appendGroupChild(pDepo_TestGuShot_);
//    pDepo_TestChokiShot_ = NEW GgafCore::ActorDepository("Depo_TestChokiShot");
//    for (int i = 0; i < 25; i++) { //僥僗僩僠儑僉抏僗僩僢僋
//        pDepo_TestChokiShot_->appendChild(NEW TestChokiShot("TestChokiShot"));
//    }
//    appendGroupChild(pDepo_TestChokiShot_);
//    pDepo_TestPaShot_ = NEW GgafCore::ActorDepository("Depo_TestPaShot");
//    for (int i = 0; i < 25; i++) { //僥僗僩僷乕抏僗僩僢僋
//        pDepo_TestPaShot_->appendChild(NEW TestPaShot("TestPaShot"));
//    }
//    appendGroupChild(pDepo_TestPaShot_);
//    pDepo_TestNomalShot_ = NEW GgafCore::ActorDepository("Depo_TestNomalShot");
//    for (int i = 0; i < 25; i++) { //僥僗僩僲乕儅儖抏僗僩僢僋
//        pDepo_TestNomalShot_->appendChild(NEW TestNomalShot("TestNomalShot"));
//    }
//    appendGroupChild(pDepo_TestNomalShot_);
//    //<---- debug


    pDepo_MyShots001_ = NEW GgafCore::ActorDepository("RotShot001");
    MyShot001* pShot;
    for (int i = 0; i < 50; i++) { //帺抏僗僩僢僋
        pShot = NEW MyShot001("MY_MyShot001");
        pShot->inactivate();
        pDepo_MyShots001_->put(pShot);
    }
    appendGroupChild(pDepo_MyShots001_);

    pDepo_MySnipeShots001_ = NEW GgafCore::ActorDepository("RotShot001");
    MySnipeShot001* pSnipeShot;
    for (int i = 0; i < 5; i++) { //帺抏僗僩僢僋
        pSnipeShot = NEW MySnipeShot001("MY_MySnipeShot001");
        pSnipeShot->inactivate();
        pDepo_MySnipeShots001_->put(pSnipeShot);
    }
    appendGroupChild(pDepo_MySnipeShots001_);

    pLaserChipDepo_ = NEW LaserChipDepository("MyRotLaser");
    MyStraightLaserChip001* pChip;
    for (int i = 0; i < 80; i++) { //儗乕僓乕僗僩僢僋
        std::string name = "MyStraightLaserChip001("+XTOS(i)+")";
        pChip = NEW MyStraightLaserChip001(name.c_str());
        pChip->setPositionSource(this); //埵抲偩偗摨婜
        pLaserChipDepo_->put(pChip);
    }
    pLaserChipDepo_->config(80, 25);
    appendGroupChild(pLaserChipDepo_);

    //儘僢僋僆儞僐儞僩儘乕儔乕
    pLockonCtrler_ = NEW MyLockonController("MySHipLockonController");
    appendGroupChild(pLockonCtrler_);

    //僼僅僩儞僐儞僩儘乕儔乕
    pTorpedoCtrler_ = NEW MyTorpedoController("TorpedoController", this, pLockonCtrler_);
    appendGroupChild(pTorpedoCtrler_);

    pEffectTurbo001_ = NEW EffectTurbo001("EffectTurbo001");
    appendGroupChild(pEffectTurbo001_);
//    pEffectTurbo002_ = NEW EffectTurbo002("EffectTurbo002");
//    appendGroupChild(pEffectTurbo002_);

    pMyMagicEnergyCore_ = NEW MyMagicEnergyCore("MyMagicEnergyCore");
    appendGroupChild(pMyMagicEnergyCore_);

    //26曽岦偵堏摦偟偨応崌偺帺婡偺孹偒掕媊
    pSenakai_ = &(senakai_[13]);
    pSenakai_[DIR26(-1,-1,-1)] = -D_ANG(120);
    pSenakai_[DIR26(-1,-1, 0)] =  0;
    pSenakai_[DIR26(-1,-1, 1)] =  D_ANG(120);
    pSenakai_[DIR26(-1, 0,-1)] = -D90ANG;
    pSenakai_[DIR26(-1, 0, 0)] =  0;
    pSenakai_[DIR26(-1, 0, 1)] =  D90ANG;
    pSenakai_[DIR26(-1, 1,-1)] = -D_ANG(30);
    pSenakai_[DIR26(-1, 1, 0)] =  0;
    pSenakai_[DIR26(-1, 1, 1)] =  D_ANG(30);
    pSenakai_[DIR26( 0,-1,-1)] = -D135ANG;
    pSenakai_[DIR26( 0,-1, 0)] =  0;
    pSenakai_[DIR26( 0,-1, 1)] =  D135ANG;
    pSenakai_[DIR26( 0, 0,-1)] = -D90ANG;
    pSenakai_[DIR26( 0, 0, 0)] =  0;
    pSenakai_[DIR26( 0, 0, 1)] =  D90ANG;
    pSenakai_[DIR26( 0, 1,-1)] = -D45ANG;
    pSenakai_[DIR26( 0, 1, 0)] =  0;
    pSenakai_[DIR26( 0, 1, 1)] =  D45ANG;
    pSenakai_[DIR26( 1,-1,-1)] = -D_ANG(120);
    pSenakai_[DIR26( 1,-1, 0)] =  0;
    pSenakai_[DIR26( 1,-1, 1)] =  D_ANG(120);
    pSenakai_[DIR26( 1, 0,-1)] = -D90ANG;
    pSenakai_[DIR26( 1, 0, 0)] =  0;
    pSenakai_[DIR26( 1, 0, 1)] =  D90ANG;
    pSenakai_[DIR26( 1, 1,-1)] = -D_ANG(30);
    pSenakai_[DIR26( 1, 1, 0)] =  0;
    pSenakai_[DIR26( 1, 1, 1)] =  D_ANG(30);

    GgafDx::SeTransmitterForActor* pSeTx = getSeTransmitter();
    pSeTx->set(SE_DAMAGED     , "WAVE_MY_DAMAGED_001");
    pSeTx->set(SE_EXPLOSION   , "WAVE_MY_SE_EXPLOSION_001");
    pSeTx->set(SE_TURBO       , "WAVE_MY_TURBO_001");
    pSeTx->set(SE_CANT_TURBO  , "WAVE_MY_CANT_TURBO_001");
    pSeTx->set(SE_FIRE_LASER  , "WAVE_MY_FIRE_LASER_001");
    pSeTx->set(SE_FIRE_SHOT   , "WAVE_MY_FIRE_SHOT_001");
    pSeTx->set(SE_FIRE_TORPEDO, "WAVE_MY_FIRE_TORPEDO_001");

    veloTurboTop_ = 30000;
    veloTurboBottom_ = 10000;

    is_being_soft_rapidshot_ = false;
    soft_rapidshot_shot_count_ = 0;
    soft_rapidshot_push_cnt_ = 0;
    soft_rapidshot_shot_count_in_one_push_ = 0;
    soft_rapidshot_frames_in_one_push = 0;
    is_snipe_shot_ = false;

    is_just_shot_ = false;
    is_shooting_laser_ = false;
    can_shoot_laser_ = false;
    frame_shot_pressed_ = 0;

    can_control_ = true;
    is_diving_ = false;

    blown_veloX_ = 0;
    blown_veloY_ = 0;
    blown_veloZ_ = 0;
    mv_way_sgn_x_ = 0;
    mv_way_sgn_y_ = 0;
    mv_way_sgn_z_ = 0;
    mv_way_ = DIR26(mv_way_sgn_x_, mv_way_sgn_y_, mv_way_sgn_z_);
    prev_way_ = mv_way_;
    is_just_change_mv_way_ = false;

    //MP弶婜抣
    mp_ = MY_SHIP_START_MP;
    //mp_傪曄偊傞偲丄撪晹嶲徠偡傞 MpBar 偺昞帵偑楢摦偟偰曄傢傞

    //Vreath偼幚抣傪 getStatus() 偺STAT_Stamina抣傪嶲徠偡傞傛偆偵愝掕丅
//    vreath_.link( &(getStatus()->_paValue[STAT_Stamina]._int_val) );
    //STAT_Stamina偑尭傟偽丄vreath_ 偑曄壔偟丄偦傟傪撪晹嶲徠偡傞 VreathBar 偺昞帵偑楢摦偟偰曄傢傞

    //杺朄儊乕僞乕愝抲
    pMagicMeter_ = NEW MagicMeter("MagicMeter", &mp_, &(getStatus()->_value[STAT_Stamina]._int_val) );
    pMagicMeter_->setPosition(PX_C(100), PX_C(CONFIG::GAME_BUFFER_HEIGHT) - (pMagicMeter_->height_) - PX_C(16+16+16));
    appendGroupChild(pMagicMeter_);

    r_blown_velo_decay_ = 0.8;

    invincible_frames_ = 0;

    trace_delay_count_ = 0;
    is_trace_waiting_ = false;

    shot_level_ = 1;

    prev_x_ = _x;
    prev_y_ = _y;
    prev_z_ = _z;
}

void MyShip::onCreateModel() {
    GgafDx::Model* pModel = getModel();
    pModel->setSpecular(5.0, 1.0);
}

void MyShip::initialize() {
    _TRACE_(FUNC_NAME<<"");

    //庬暿偵怳傝暘偗
//    bringSceneMediator()->appendGroupChild(KIND_MY_SHOT_NOMAL, pDepo_MyShots001_->extract());
//    bringSceneMediator()->appendGroupChild(KIND_MY_SHOT_NOMAL, pDepo_MyWaves001_->extract());
    //bringSceneMediator()->appendGroupChild(KIND_MY_SHOT_NOMAL, pLaserChipDepo_->extract());

    setHitAble(true);
    CollisionChecker* pChecker = getCollisionChecker();
    pChecker->createCollisionArea(1);
//    pChecker->setColliSphere(0, -100000, -50000, 20000, 100000);
// pChecker->setColliAABox(0, -100000, -50000, 20000, 10000, 40000, 80000);
//    pChecker->setColliSphere(1, 0,-100000,0, 30000, true, true, true);
//    pChecker->setColliSphere(2, 0,100000,0, 30000, true, true, true);
//    pChecker->setColliSphere(3, 0,0,-100000, 30000, true, true, true);
//    pChecker->setColliSphere(4, 0,0,100000, 30000, true, true, true);

//    pChecker->setColliAACube(0, 40000);
/////////////TEST
      pChecker->setColliAACube(0, PX_C(40));

    GgafDx::VecDriver* const pVecDriver = getVecDriver();
    pVecDriver->setMvVelo(0);

    //setMaterialColor(1.0, 0.5, 0.5);
    setAlpha(1.0);
    GgafDx::GeoDriver* const pGeoDriver = getGeoDriver();
    pGeoDriver->forceVxyzMvVeloRange(-veloTurboTop_, veloTurboTop_);
    pGeoDriver->setZeroVxyzMvAcce();

    getVecDriver()->setRollFaceAngVelo(300);
}


void MyShip::onReset() {
    _TRACE_(FUNC_NAME<<" "<<NODE_INFO<<"");
    is_being_soft_rapidshot_ = false;
    soft_rapidshot_shot_count_ = 0;
    soft_rapidshot_push_cnt_ = 0;
    soft_rapidshot_shot_count_in_one_push_ = 0;
    soft_rapidshot_frames_in_one_push = 0;
    is_snipe_shot_ = false;
    is_being_soft_rapidshot_ = false;
    is_just_shot_ = false;
    is_shooting_laser_ = false;
    can_shoot_laser_ = false;
    frame_shot_pressed_ = 0;
    _x = _y = _z = 0;
    mv_way_sgn_x_ = 0;
    mv_way_sgn_y_ = 0;
    mv_way_sgn_z_ = 0;
    mv_way_ = DIR26(mv_way_sgn_x_, mv_way_sgn_y_, mv_way_sgn_z_);
//    mv_way_switch_.reset();

    mp_ = MY_SHIP_START_MP;
    getStatus()->reset();

    setInvincibleFrames(60 * 10); //搊応帪偺柍揋帪娫
}

void MyShip::onActive() {
    _TRACE_(FUNC_NAME<<"");
    //儗乕僓乕傗儘僢僋儞僞乕僎僢僩傗嫑棆偑巕偵偄傞偨傔
    //屄暿偵屇傃弌偡
    pLockonCtrler_->onActive();
    pTorpedoCtrler_->onActive();
}
void MyShip::onInactive() {
    _TRACE_(FUNC_NAME<<"");
    //儗乕僓乕傗儘僢僋儞僞乕僎僢僩傗嫑棆偑巕偵偄傞偨傔
    //屄暿偵屇傃弌偡
    pLockonCtrler_->onInactive();
    pTorpedoCtrler_->onInactive();
//    pLaserChipDepo_->reset();
}
void MyShip::processBehavior() {
    VirtualButton* pVbPlay = VB_PLAY;
    GgafDx::VecDriver* const pVecDriver = getVecDriver();
    GgafDx::GeoDriver* const pGeoDriver = getGeoDriver();
    //憖嶌嫅斲
    if (!can_control_) {
        return;
    }
    updateMoveWay();
    if (getStatus()->get(STAT_Stamina) < 0) {
        //懅愗傟
    } else {
        if (pVbPlay->isPressed(VB_OPTION)) {
            int tmp = mv_speed_;
            mv_speed_ /= 8; //僆僾僔儑儞憖嶌拞堏摦偼抶偄
            moveNomal();
            mv_speed_ = tmp;
        } else {
            moveNomal();
        }

        if (pVbPlay->isPushedDown(VB_TURBO)) {
            if (pGeoDriver->_velo_vx_mv == 0 && pGeoDriver->_velo_vy_mv == 0 && pGeoDriver->_velo_vz_mv == 0) {
                //僞乕儃堏摦姰慡偵廔椆偟側偄偲師偺僞乕儃偼幚峴晄壜
                moveTurbo();
                UTIL::activateProperEffect01Of(this); //僞乕儃奐巒偺僄僼僃僋僩
                getSeTransmitter()->play3D(SE_TURBO);
            } else {
                //僞乕儃堏摦拞
                getSeTransmitter()->play3D(SE_CANT_TURBO);
            }
        } else {
            //Not僞乕儃奐巒帪
            if (pVbPlay->isPressed(VB_TURBO)) {
                //僞乕儃儃僞儞傪墴偟懕偗傞偙偲偱丄懍搙尭悐偑備傞傗偐偵側傝丄
                //堏摦嫍棧傪怢偽偡
                pGeoDriver->_velo_vx_mv *= 0.96;
                pGeoDriver->_velo_vy_mv *= 0.96;
                pGeoDriver->_velo_vz_mv *= 0.96;
            } else {
                //僞乕儃傪棧偟偨応崌丄懍搙尭悐丅
                pGeoDriver->_velo_vx_mv *= 0.8;
                pGeoDriver->_velo_vy_mv *= 0.8;
                pGeoDriver->_velo_vz_mv *= 0.8;
            }
            if (ABS(pGeoDriver->_velo_vx_mv) <= 2) {
                pGeoDriver->_velo_vx_mv = 0;
            }
            if (ABS(pGeoDriver->_velo_vy_mv) <= 2) {
                pGeoDriver->_velo_vy_mv = 0;
            }
            if (ABS(pGeoDriver->_velo_vz_mv) <= 2) {
                pGeoDriver->_velo_vz_mv = 0;
            }
        }

        if (pVbPlay->isDoublePushedDown(VB_OPTION,8,8) ) {
            pGeoDriver->setZeroVxyzMvVelo(); //僞乕儃堏摦拞偱傕掆巭偡傞丅乮僞乕儃僉儍儞僙儖揑偵側傞両乯
        }
    }

    //僗僺儞偑惃偄傛偔夞偭偰偄傞側傜偽懍搙傪庛傔傞
    angvelo MZ = angRxTopVelo_MZ_-3000; //3000偼捠忢慁夞帪偵懍搙傪庛傔偰angRxTopVelo_MZ_傪挻偊側偄傛偆偵偡傞偨傔丄傗傗庤慜偱尭懍偡傞偲尵偆堄枴乮TODO:梫挷惍乯丅
    if (pVecDriver->_angvelo_face[AXIS_X] >= MZ) {
        pVecDriver->_angvelo_face[AXIS_X] *= 0.93;
        //_getVecDriver()->setFaceAngAcce(AXIS_X, -1*angRxAcce_MZ_*2);
    } else if (pVecDriver->_angvelo_face[AXIS_X] <= -MZ) {
        pVecDriver->_angvelo_face[AXIS_X] *= 0.93;
        //_getVecDriver()->setFaceAngAcce(AXIS_X, angRxAcce_MZ_*2);
    }

    //慁夞偟側偄堏摦曽岦偺応崌丄婡懱傪悈暯偵偡傞乮扐偟惃偄傛偔夞偭偰偄側偄応崌偵尷傞丅setStopTargetFaceAng偺戞4堷悢傛傝妏懍搙偑備傞偄応崌庴偗擖傟乯
    if (pSenakai_[mv_way_] == 0) {
        angle dist = pVecDriver->getFaceAngDistance(AXIS_X, 0, TURN_CLOSE_TO);
        if (0 <= dist && dist < D180ANG) {
            getVecDriver()->setFaceAngAcce(AXIS_X, angRxAcce_MZ_);
        } else if (-1*D180ANG < dist && dist < 0) {
            getVecDriver()->setFaceAngAcce(AXIS_X, -1*angRxAcce_MZ_);
        }
        pVecDriver->setMvAcce(0);
        pVecDriver->setStopTargetFaceAng(AXIS_X, 0, TURN_BOTH, angRxTopVelo_MZ_);
    }

    ////////////////////////////////////////////////////

    //嵗昗偵斀塮
    pVecDriver->behave();
    pGeoDriver->behave();
    getSeTransmitter()->behave();

    if (invincible_frames_ > 0) {
        setHitAble(false);
        invincible_frames_ --;
        if (getActiveFrame() % 2 == 0) {
            setAlpha(0.6);
        } else {
            setAlpha(0);
        }
        if (invincible_frames_ == 0) {
            setHitAble(true);
            setAlpha(1.0);
        }
    } else {

    }
    //悂偭旘傃
    if (ABS(blown_veloX_) < PX_C(1)) {
        blown_veloX_ = 0;
    } else {
        _x += blown_veloX_;
        blown_veloX_ *= r_blown_velo_decay_;
    }
    if (ABS(blown_veloY_) < PX_C(1)) {
        blown_veloY_ = 0;
    } else {
        _y += blown_veloY_;
        blown_veloY_ *= r_blown_velo_decay_;
    }
    if (ABS(blown_veloZ_) < PX_C(1)) {
        blown_veloZ_ = 0;
    } else {
        _z += blown_veloZ_;
        blown_veloZ_ *= r_blown_velo_decay_;
    }


    if (is_diving_) {
        //撍擖儌乕僔儑儞帪偼丄堏摦斖埻惂屼柍偟
    } else {
        //捠忢堏摦斖埻惂屼
        if (_y > MyShip::lim_y_top_) {
            _y = MyShip::lim_y_top_;
        } else if (_y < MyShip::lim_y_bottom_ ) {
            _y = MyShip::lim_y_bottom_;
        }

        if (_x > MyShip::lim_x_infront_) {
            _x = MyShip::lim_x_infront_;
        } else if (_x < MyShip::lim_x_behaind_) {
            _x = MyShip::lim_x_behaind_;
        }

        if (_z > MyShip::lim_z_left_) {
            _z = MyShip::lim_z_left_;
        } else if (_z < MyShip::lim_z_right_) {
            _z = MyShip::lim_z_right_;
        }
    }

    //枅僼儗乕儉偺屇媧偺徚旓
    getStatus()->minus(STAT_Stamina, MY_SHIP_VREATH_COST);

    //僔儑僢僩娭楢張棟
    is_shooting_laser_ = false;
    if (pVbPlay->isPressed(VB_SHOT1)) {
        frame_shot_pressed_ ++;
        if (can_shoot_laser_) {
            if (frame_shot_pressed_ > 30) { //30僼儗乕儉墴偟偭傁側偟偱儗乕僓乕傊
                is_shooting_laser_ = true;
            }
        }
    } else {
        frame_shot_pressed_ = 0;
        pLockonCtrler_->releaseAllLockon(); //儘僢僋僆儞夝彍
    }

    //儗乕僓乕敪幩
    if (is_shooting_laser_) {
        if (pVbPlay->isPressed(VB_SHOT1)) {
            LaserChip* pLaserChip = pLaserChipDepo_->dispatch();
            if (pLaserChip) {
                if (pLaserChip->getInfrontChip() == nullptr) {
                    getSeTransmitter()->play3D(SE_FIRE_LASER);
                }
            }
        } else {

        }
    }

    //僜僼僩楢幩
    //侾僾僢僔儏栚偺弶抏偺傒侾敪偺傒敪幩偺僗僫僀僾僔儑僢僩丅
    //俀僾僢僔儏栚埲崀僜僼僩楢幩丄侾僾僢僔儏偱4F枅偵嵟戝3敪
    if (pVbPlay->isPushedDown(VB_SHOT1) && !pVbPlay->isPressed(VB_POWERUP)) {
        if (is_being_soft_rapidshot_) {
            if (soft_rapidshot_frames_in_one_push >= SOFT_RAPIDSHOT_INTERVAL) {
                //僾僢僔儏屻偺僜僼僩楢幩偵傛傞俀敪栚偺 SOFT_RAPIDSHOT_INTERVAL 僼儗乕儉傛傝師偺僾僢僔儏偑抶偄応崌
                //楢幩偲楢幩偺偮側偓栚偑柍偄傛偆偵墘弌偡傞傔偵丄
                //soft_rapidshot_frames_in_one_push 傪 SOFT_RAPIDSHOT_INTERVAL 攞偺抣擾抧嵟彫抣偵偡傞
                soft_rapidshot_frames_in_one_push = soft_rapidshot_frames_in_one_push % SOFT_RAPIDSHOT_INTERVAL;
                if (soft_rapidshot_frames_in_one_push > 0) {
                    //soft_rapidshot_frames_in_one_push 偑塣椙偔0側傜偽丄SOFT_RAPIDSHOT_NUM 敪偺抏偑僜僼僩楢幩偵傛傝敪幩偝傟傞偙偲偵側傞偑丄
                    //soft_rapidshot_frames_in_one_push > 0 側傜偽丄SOFT_RAPIDSHOT_NUM-1 敪偵側傝侾敪尭偭偰偟傑偆丅
                    //偙傟傪旔偗傞堊丄SOFT_RAPIDSHOT_NUM 敪偺抏傪寕偮偙偲傪曐徹偡傞偨傔偵丄soft_rapidshot_frames_in_one_push傪曗惓
                    soft_rapidshot_frames_in_one_push -= SOFT_RAPIDSHOT_INTERVAL;
                }
                soft_rapidshot_shot_count_in_one_push_ = 0;
                soft_rapidshot_push_cnt_++;
            } else {
                //僾僢僔儏屻丄僜僼僩楢幩偵傛傞俀敪栚偺 SOFT_RAPIDSHOT_INTERVAL 僼儗乕儉傛傝師偺僾僢僔儏偑懍偄応崌
                //偙傟傪庴偗擖傟偰嫮惂揑偵敪幩偱偒傞(SOFT_RAPIDSHOT_INTERVAL傛傝懍偄庤摦楢幩偼丄楢幩桪愭)
                soft_rapidshot_frames_in_one_push = 0;
                soft_rapidshot_shot_count_in_one_push_ = 0;
                soft_rapidshot_push_cnt_++;
            }
        } else {
            //僜僼僩楢幩奐巒両
            is_being_soft_rapidshot_ = true;
            soft_rapidshot_frames_in_one_push = 0;
            soft_rapidshot_shot_count_in_one_push_ = 0;
            soft_rapidshot_push_cnt_ = 1;
        }
    }

    if (is_being_soft_rapidshot_) {
        //僜僼僩楢幩拞丄幚嵺偵僔儑僢僩傪曻偮僞僀儈儞僌偺敾掕
        if (soft_rapidshot_frames_in_one_push % SOFT_RAPIDSHOT_INTERVAL == 0) {
            //僔儑僢僩傪曻偮僞僀儈儞僌偱偼偁傞偑丄壥偨偟偰僔儑僢僩偟偰傕傛偄偐丠
            soft_rapidshot_shot_count_++;
            soft_rapidshot_shot_count_in_one_push_++;
            //僜僼僩楢幩堐帩帪娫奜敾掕
            if(soft_rapidshot_frames_in_one_push > SOFT_RAPIDSHOT_INTERVAL*(SOFT_RAPIDSHOT_NUM-1)) {
                //僜僼僩楢幩夝彍
                is_being_soft_rapidshot_ = false;
                soft_rapidshot_shot_count_ = 0;
                soft_rapidshot_shot_count_in_one_push_ = 0;
                soft_rapidshot_push_cnt_ = 0;
                is_just_shot_ = false; //僔儑僢僩柍偟傛
            } else {
                //僜僼僩楢幩堐帩帪娫撪側偺偱
                is_just_shot_ = true;  //僔儑僢僩偟傑偟傚偆
                soft_rapidshot_frames_in_one_push++;
            }
        } else {
            //僜僼僩楢幩拞偩偑丄僞僀儈儞僌偑埆偄
            is_just_shot_ = false;
            soft_rapidshot_frames_in_one_push++;
        }
    } else {
         //僜僼僩楢幩拞偱偡傜側偄
        is_just_shot_ = false;
    }

    //僗僫僀僾僔儑僢僩偺敾掕
    is_snipe_shot_ = false;
    if (is_just_shot_) {
        if (soft_rapidshot_push_cnt_ == 1) { //嵟弶偺僾僢僔儏偱偁傞丅
            if (soft_rapidshot_shot_count_in_one_push_ == 1) {  //嵟弶偺僾僢僔儏偺侾敪栚偱偁傞
                is_snipe_shot_ = true; //僗僫僀僾僔儑僢僩両
            }
            if (2 <= soft_rapidshot_shot_count_in_one_push_ && soft_rapidshot_shot_count_in_one_push_ <= SOFT_RAPIDSHOT_NUM) {
                is_just_shot_ = false; //僗僫僀僾僔儑僢僩帪偺僾僢僔儏偼丄弶抏埲奜傪柍棟傗傝僔儑僢僩柍偟嫺惓丅
            } else {
                is_just_shot_ = true;
            }
        }
    } else {
    }

    if (is_just_shot_) {
        if (is_snipe_shot_) {
            //僗僫僀僾僔儑僢僩帪
            MySnipeShot001* const pSnipeShot = (MySnipeShot001*)pDepo_MySnipeShots001_->dispatch();
            if (pSnipeShot) {
                getSeTransmitter()->play3D(SE_FIRE_SHOT);
                pSnipeShot->setPositionAt(this);
                pSnipeShot->getVecDriver()->setRzRyMvAng(_rz, _ry);
                pSnipeShot->getVecDriver()->setMvVelo(PX_C(100));
                pSnipeShot->getVecDriver()->setMvAcce(100);
            }
        } else {
            //僗僫僀僾僔儑僢僩埲奜帪
            if (shot_level_ >= 1) {
                MyShot001* const pShot = (MyShot001*)pDepo_MyShots001_->dispatch();
                if (pShot) {
                    getSeTransmitter()->play3D(SE_FIRE_SHOT);
                    pShot->setPositionAt(this);
                    pShot->getVecDriver()->setRzRyMvAng(_rz, _ry);
                    pShot->getVecDriver()->setMvVelo(PX_C(70));
                    pShot->getVecDriver()->setMvAcce(80);
                }
            }

            if (shot_level_ == 2) {
                uint32_t i = soft_rapidshot_shot_count_ % 4;
                UTIL::shotWay003(this,
                                 pDepo_MyShots001_ , MyShip::shot2_matrix_[i],
                                 nullptr, nullptr,
                                 nullptr, nullptr,
                                 PX_C(1),
                                 MYSHIP_SHOT_MATRIX, MYSHIP_SHOT_MATRIX,
                                 D_ANG(5), D_ANG(5),
                                 PX_C(70), 100,
                                 1, 0, 1.0);
            } else if (shot_level_ >= 3) {
                uint32_t i = soft_rapidshot_shot_count_ % 2;
                UTIL::shotWay003(this,
                                 pDepo_MyShots001_ , MyShip::shot3_matrix_[i],
                                 nullptr, nullptr,
                                 nullptr, nullptr,
                                 PX_C(1),
                                 MYSHIP_SHOT_MATRIX, MYSHIP_SHOT_MATRIX,
                                 D_ANG(5), D_ANG(5),
                                 PX_C(70), 100,
                                 1, 0, 1.0);
            }
        }
    }


    //岝巕嫑棆敪幩
    if (pVbPlay->isPushedDown(VB_SHOT2)) {
        if (this->pTorpedoCtrler_->fire()) {
            getSeTransmitter()->play3D(SE_FIRE_TORPEDO);
        }
    }


    if (prev_x_ == _x && prev_y_ == _y && prev_z_ == _z) {
        is_move_ = false;
    } else {
        is_move_ = true;
    }
    mv_offset_x_ = _x - prev_x_;
    mv_offset_y_ = _y - prev_y_;
    mv_offset_z_ = _z - prev_z_;
    prev_x_ = _x;
    prev_y_ = _y;
    prev_z_ = _z;
}

void MyShip::processJudgement() {
    //TODO:帺敋 TEST
    if (GgafDx::Input::isPushedDownKey(DIK_0)) {
        //帺婡敋敪奐嵜
        setHitAble(false);
        getSeTransmitter()->play3D(SE_EXPLOSION);
        throwEventUpperTree(EVENT_MY_SHIP_WAS_DESTROYED_BEGIN);
    }
    //TODO:僟儊乕僕僥僗僩 TEST
    if (GgafDx::Input::isPushedDownKey(DIK_9)) {
        int vreath = getStatus()->get(STAT_Stamina);
        getStatus()->minus(STAT_Stamina, 10000);
        int damage = vreath - getStatus()->get(STAT_Stamina);
        if (damage > 0) {
            pMagicMeter_->pDamageDispBar_->dispDamage(vreath, vreath-damage);
        }
    }
}

void MyShip::onHit(const GgafCore::Actor* prm_pOtherActor) {
    GgafDx::GeometricActor* pOther = (GgafDx::GeometricActor*)prm_pOtherActor;
    //偙偙偵僸僢僩僄僼僃僋僩
    int vreath = getStatus()->get(STAT_Stamina);
    if (UTIL::calcMyStamina(this, pOther) <= 0) {
        //帺婡敋敪奐嵜
        setHitAble(false);
        getSeTransmitter()->play3D(SE_EXPLOSION);
        throwEventUpperTree(EVENT_MY_SHIP_WAS_DESTROYED_BEGIN);
    }
    int damage = vreath - getStatus()->get(STAT_Stamina);
    if (damage > 0) {
        pMagicMeter_->pDamageDispBar_->dispDamage(vreath, vreath-damage);
    }

    //暻偺応崌摿暿側張棟
    if (pOther->lookUpKind() & KIND_CHIKEI) {
        //悂偭旘傃曽岦傪峫偊傞丅
        //尰嵼偺堏摦偺媡曽岦乮悂偭旘傃埿椡偼俀攞偵乯
        float vx1,vy1,vz1;
        coord dX1 = -mv_offset_x_;
        coord dY1 = -mv_offset_y_;
        coord dZ1 = -mv_offset_z_;
        if (dX1 == 0 && dY1 == 0 && dZ1 == 0) {
            vx1 = vy1 = vz1 = 0;
        } else {
            UTIL::getNormalizedVector(dX1, dY1, dZ1,
                                     vx1, vy1, vz1 );
        }
        float vx2, vy2, vz2;
        coord dX2,dY2,dZ2;
        if ( pOther->instanceOf(Obj_MassWallActor)) {
            GgafDx::CollisionPart** papColli = pOther->_pChecker->_pCollisionArea->_papColliPart;

            ColliAABox* pBox = (ColliAABox*)(papColli[0]); //[0]BOX,[1]僾儕僘儉,[2]僺儔儈僢僪
            ColliAAPrism* pPrism = (ColliAAPrism*)(papColli[1]); //[0]BOX,[1]僾儕僘儉,[2]僺儔儈僢僪
            ColliAAPyramid* pPyramid = (ColliAAPyramid*)(papColli[2]); //[0]BOX,[1]僾儕僘儉,[2]僺儔儈僢僪
            if (pBox->_is_valid_flg) {
                //僾儕僘儉埲奜偺暻
                dX2 = (_x - pOther->_x);
                dY2 = (_y - pOther->_y);
                dZ2 = (_z - pOther->_z);
            } else if (pPrism->_is_valid_flg) {
                //僾儕僘儉暻
                //悂偭旘傇廳怱嵗昗傪曗惓
                pos_t pos_info = pPrism->_pos_info;
                if (pos_info & POS_PRISM_XY_xx) {
                    if (pos_info & POS_PRISM_xx_PP) {
                        //            仾 y+
                        // (_x1,_y2)      (_x2,_y2)
                        //        劇劅劅劅劉
                        //        劆乢偙偪劆
                        // x- 仼  劆  乢傜劆  仺 x+
                        //        劆    乢劆
                        //        劋劅劅劅劊
                        // (_x1,_y1)      (_x2,_y1)
                        //            伀 y-
                        dX2 = (_x - (pOther->_x + pPrism->_hdx));
                        dY2 = (_y - (pOther->_y + pPrism->_hdy));
                        dZ2 = (_z - (pOther->_z               ));
                    } else if (pos_info & POS_PRISM_xx_NP) {
                        //            仾 y+
                        // (_x1,_y2)      (_x2,_y2)
                        //        劇劅劅劅劉
                        //        劆偙偪乛劆
                        // x- 仼  劆傜乛  劆  仺 x+
                        //        劆乛    劆
                        //        劋劅劅劅劊
                        // (_x1,_y1)      (_x2,_y1)
                        //            伀 y-
                        dX2 = (_x - (pOther->_x - pPrism->_hdx));
                        dY2 = (_y - (pOther->_y + pPrism->_hdy));
                        dZ2 = (_z - (pOther->_z               ));
                    } else if (pos_info & POS_PRISM_xx_PN) {
                        //            仾 y+
                        // (_x1,_y2)      (_x2,_y2)
                        //        劇劅劅劅劉
                        //        劆    乛劆
                        // x- 仼  劆  乛偙劆  仺 x+
                        //        劆乛偪傜劆
                        //        劋劅劅劅劊
                        // (_x1,_y1)      (_x2,_y1)
                        //            伀 y-
                        dX2 = (_x - (pOther->_x + pPrism->_hdx));
                        dY2 = (_y - (pOther->_y - pPrism->_hdy));
                        dZ2 = (_z - (pOther->_z               ));
                    } else { // 偺偙傝偼 POS_PRISM_xx_NN
                        //            仾 y+
                        // (_x1,_y2)      (_x2,_y2)
                        //        劇劅劅劅劉
                        //        劆乢    劆
                        // x- 仼  劆偙乢  劆  仺 x+
                        //        劆偪傜乢劆
                        //        劋劅劅劅劊
                        // (_x1,_y1)      (_x2,_y1)
                        //            伀 y-
                        dX2 = (_x - (pOther->_x - pPrism->_hdx));
                        dY2 = (_y - (pOther->_y - pPrism->_hdy));
                        dZ2 = (_z - (pOther->_z               ));
                    }

                } else if (pos_info & POS_PRISM_YZ_xx) {

                    if (pos_info & POS_PRISM_xx_PP) {
                        //            仾 z+
                        // (_y1,_z2)      (_y2,_z2)
                        //        劇劅劅劅劉
                        //        劆乢偙偪劆
                        // y- 仼  劆  乢傜劆  仺 y+
                        //        劆    乢劆
                        //        劋劅劅劅劊
                        // (_y1,_z1)      (_y2,_z1)
                        //            伀 z-
                        dX2 = (_x - (pOther->_x               ));
                        dY2 = (_y - (pOther->_y + pPrism->_hdy));
                        dZ2 = (_z - (pOther->_z + pPrism->_hdz));
                    } else if (pos_info & POS_PRISM_xx_NP) {
                        //            仾 z+
                        // (_y1,_z2)      (_y2,_z2)
                        //        劇劅劅劅劉
                        //        劆偙偪乛劆
                        // y- 仼  劆傜乛  劆  仺 y+
                        //        劆乛    劆
                        //        劋劅劅劅劊
                        // (_y1,_z1)      (_y2,_z1)
                        //            伀 z-
                        dX2 = (_x - (pOther->_x               ));
                        dY2 = (_y - (pOther->_y - pPrism->_hdy));
                        dZ2 = (_z - (pOther->_z + pPrism->_hdz));
                    } else if (pos_info & POS_PRISM_xx_PN) {
                        //            仾 z+
                        // (_y1,_z2)      (_y2,_z2)
                        //        劇劅劅劅劉
                        //        劆    乛劆
                        // y- 仼  劆  乛偙劆  仺 y+
                        //        劆乛偪傜劆
                        //        劋劅劅劅劊
                        // (_y1,_z1)      (_y2,_z1)
                        //            伀 z-
                        dX2 = (_x - (pOther->_x               ));
                        dY2 = (_y - (pOther->_y + pPrism->_hdy));
                        dZ2 = (_z - (pOther->_z - pPrism->_hdz));
                    } else { // 偺偙傝偼 POS_PRISM_xx_NN
                        //            仾 z+
                        // (_y1,_z2)      (_y2,_z2)
                        //        劇劅劅劅劉
                        //        劆乢    劆
                        // y- 仼  劆偙乢  劆  仺 y+
                        //        劆偪傜乢劆
                        //        劋劅劅劅劊
                        // (_y1,_z1)      (_y2,_z1)
                        //            伀 z-
                        dX2 = (_x - (pOther->_x               ));
                        dY2 = (_y - (pOther->_y - pPrism->_hdy));
                        dZ2 = (_z - (pOther->_z - pPrism->_hdz));
                    }

                } else if (pos_info & POS_PRISM_ZX_xx) {
                    if (pos_info & POS_PRISM_xx_PP) {
                        //            仾 x+
                        // (_z1,_x2)      (_z2,_x2)
                        //        劇劅劅劅劉
                        //        劆乢偙偪劆
                        // z- 仼  劆  乢傜劆  仺 z+
                        //        劆    乢劆
                        //        劋劅劅劅劊
                        // (_z1,_x1)      (_z2,_x1)
                        //            伀 x-
                        dX2 = (_x - (pOther->_x + pPrism->_hdx));
                        dY2 = (_y - (pOther->_y               ));
                        dZ2 = (_z - (pOther->_z + pPrism->_hdz));
                    } else if (pos_info & POS_PRISM_xx_NP) {
                        //            仾 x+
                        // (_z1,_x2)      (_z2,_x2)
                        //        劇劅劅劅劉
                        //        劆偙偪乛劆
                        // z- 仼  劆傜乛  劆  仺 z+
                        //        劆乛    劆
                        //        劋劅劅劅劊
                        // (_z1,_x1)      (_z2,_x1)
                        //            伀 x-
                        dX2 = (_x - (pOther->_x + pPrism->_hdx));
                        dY2 = (_y - (pOther->_y               ));
                        dZ2 = (_z - (pOther->_z - pPrism->_hdz));
                    } else if (pos_info & POS_PRISM_xx_PN) {
                        //            仾 x+
                        // (_z1,_x2)      (_z2,_x2)
                        //        劇劅劅劅劉
                        //        劆    乛劆
                        // z- 仼  劆  乛偙劆  仺 z+
                        //        劆乛偪傜劆
                        //        劋劅劅劅劊
                        // (_z1,_x1)      (_z2,_x1)
                        //            伀 x-
                        dX2 = (_x - (pOther->_x - pPrism->_hdx));
                        dY2 = (_y - (pOther->_y               ));
                        dZ2 = (_z - (pOther->_z + pPrism->_hdz));
                    } else { // 偺偙傝偼 POS_PRISM_xx_NN
                        //            仾 x+
                        // (_z1,_x2)      (_z2,_x2)
                        //        劇劅劅劅劉
                        //        劆乢    劆
                        // z- 仼  劆偙乢  劆  仺 z+
                        //        劆偪傜乢劆
                        //        劋劅劅劅劊
                        // (_z1,_x1)      (_z2,_x1)
                        //            伀 x-
                        dX2 = (_x - (pOther->_x - pPrism->_hdx));
                        dY2 = (_y - (pOther->_y                ));
                        dZ2 = (_z - (pOther->_z - pPrism->_hdz));
                    }
                } else if (pPyramid->_is_valid_flg) {
                    //TODO:僺儔儈僢僪傆偭偲傇廳怱
                    dX2 = (_x - pOther->_x);
                    dY2 = (_y - pOther->_y);
                    dZ2 = (_z - pOther->_z);
                }
            } else {

            }
        } else {
            //暻偠傖側偄応崌偼拞怱嵗昗偱悂偭旘傇曽岦寛掕
            GgafDx::CollisionArea* pCollisionArea = pOther->_pChecker->_pCollisionArea;
            if (pCollisionArea->_hit_colli_part_index >= 0) {
                GgafDx::CollisionPart* pPart = pCollisionArea->_papColliPart[pCollisionArea->_hit_colli_part_index];
                dX2 = (_x - (pOther->_x + pPart->_cx));
                dY2 = (_y - (pOther->_y + pPart->_cy));
                dZ2 = (_z - (pOther->_z + pPart->_cz));
            } else {
                dX2 = (_x - pOther->_x);
                dY2 = (_y - pOther->_y);
                dZ2 = (_z - pOther->_z);
            }
        }

        if (dX2 == 0 && dY2 == 0 && dZ2 == 0) {
            vx2 = vy2 = vz2 = 0;
        } else {
            UTIL::getNormalizedVector(dX2, dY2, dZ2,
                                     vx2, vy2, vz2 );
        }

        float vx3, vy3, vz3;
        UTIL::getNormalizedVector(
                    vx1+vx2, vy1+vy2, vz1+vz2,
                    vx3, vy3, vz3);
        setBlownVelo(vx3*PX_C(40), vy3*PX_C(40), vz3*PX_C(40), 0.8);
        setInvincibleFrames(120);
    }
    if (pOther->lookUpKind() & KIND_ITEM)  {
    } else {
        UTIL::activateExplosionEffectOf(this);
        getSeTransmitter()->play3D(SE_DAMAGED);
    }
}


void MyShip::setMoveSpeed(velo prm_speed_velo) {
    //lv_MoveSpeed_ = lv;
    //mv_speed_ = PX_C(lv);
    mv_speed_ = prm_speed_velo;
    veloBeginMT_ = mv_speed_ * 20;
}

void MyShip::onCatchEvent(hashval prm_no, void* prm_pSource) {
}

void MyShip::setBlownVelo(velo prm_blown_veloX, velo prm_blown_veloY, velo prm_blown_veloZ, double prm_r_blown_velo_attenuate) {
    blown_veloX_ += prm_blown_veloX;
    blown_veloY_ += prm_blown_veloY;
    blown_veloZ_ += prm_blown_veloZ;
    r_blown_velo_decay_ = prm_r_blown_velo_attenuate;
}

void MyShip::setInvincibleFrames(int prm_frames) {
    setHitAble(false);
    invincible_frames_ = prm_frames;
}
void MyShip::updateMoveWay() {
    VirtualButton* pVbPlay = VB_PLAY;
    dir26 pos_camera = pVAM->getPosCam();
    dir26 pos_up = pVAM->getPosUp();
    dir26* pa_dir8 = VamSysCamWorker::cam_to_8dir_[pos_camera]; //俉曽岦僎僢僩
    //UP曽岦傪扵偡丅
    int up_idx = 0;
    for (int i = 0; i < 8; i++) {
        if (pos_up == pa_dir8[i]) {
            up_idx = i; //UP曽岦僀儞僨僢僋僗曐懚
        }
    }
    //pa_dir8[up_idx] 偑忋偱偁傞
    bool isPressed_VB_UP    = pVbPlay->isPressed(VB_UP);
    bool isPressed_VB_DOWN  = pVbPlay->isPressed(VB_DOWN);
    bool isPressed_VB_LEFT  = pVbPlay->isPressed(VB_LEFT);
    bool isPressed_VB_RIGHT = pVbPlay->isPressed(VB_RIGHT);
    int mv_dir = -1; //擖椡曽岦斣崋0~7(忋偐傜塃夞傝偺俉曽岦)
    if (isPressed_VB_UP) {
        if (isPressed_VB_RIGHT) {
            mv_dir = 1; //塃忋
        } else if (isPressed_VB_LEFT) {
            mv_dir = 7; //嵍忋
        } else {
            mv_dir = 0; //忋
        }
    } else if (isPressed_VB_DOWN) {
        if (isPressed_VB_RIGHT) {
            mv_dir = 3; //塃壓
        } else if (isPressed_VB_LEFT) {
            mv_dir = 5; //嵍壓
        } else {
            mv_dir = 4; //壓
        }
    } else if (isPressed_VB_RIGHT) {
        mv_dir = 2;
    } else if (isPressed_VB_LEFT) {
        mv_dir = 6;
    }
    dir26 new_mv_way = DIR26(0, 0, 0);
    if (mv_dir > -1) {
        int dir_8_idx = (up_idx + mv_dir) % 8;
        new_mv_way = pa_dir8[dir_8_idx];
    }
    prev_way_ = mv_way_;
    mv_way_ = new_mv_way;
    Direction26Util::cnvDirNo2Sgn(mv_way_,
                                  mv_way_sgn_x_, mv_way_sgn_y_, mv_way_sgn_z_);
    is_just_change_mv_way_ = (prev_way_ != mv_way_ ? true : false);
}

void MyShip::moveNomal() {
    const dir26 mv_way = mv_way_;
    float vx,vy,vz;
    Direction26Util::cnvDirNo2Vec(mv_way, vx, vy, vz);
    _x += mv_speed_ * vx;
    _y += mv_speed_ * vy;
    _z += mv_speed_ * vz;
    if (is_just_change_mv_way_) {
        angle rz, ry;
        Direction26Util::cnvDirNo2RzRy(mv_way, rz, ry);
        getVecDriver()->setRzRyMvAng(rz, ry);
        //慁夢
        int sgn_turn = pSenakai_[mv_way] > pSenakai_[prev_way_] ? 1 : -1;
        if (sgn_turn != 0) {
            getVecDriver()->setFaceAngAcce(AXIS_X, sgn_turn*angRxAcce_MZ_);
            getVecDriver()->setStopTargetFaceAng(AXIS_X, pSenakai_[mv_way],
                                              TURN_CLOSE_TO,
                                              angRxTopVelo_MZ_);
        }
    }
}

void MyShip::moveTurbo() {
    GgafDx::GeoDriver* const pGeoDriver = getGeoDriver();
    float vx,vy,vz;
    Direction26Util::cnvDirNo2Vec(mv_way_, vx, vy, vz);
    pGeoDriver->addVxMvVelo(veloBeginMT_ * vx);
    pGeoDriver->addVyMvVelo(veloBeginMT_ * vy);
    pGeoDriver->addVzMvVelo(veloBeginMT_ * vz);
    angle rz, ry;
    Direction26Util::cnvDirNo2RzRy(mv_way_, rz, ry);
    getVecDriver()->setRzRyMvAng(rz, ry);

    //慁夢
    angle senkai = pSenakai_[mv_way_];
    if (senkai != 0) {
        double senkai_spin_speed_rate = (1.0 * D90ANG / senkai); //慁夞帪丄90搙-90搙偵孹偔応崌 1.0丄1.0 偲側傞丅
        getVecDriver()->setRollFaceAngVelo(angRxVelo_BeginMZT_ * senkai_spin_speed_rate);
    }
}

MyShip::~MyShip() {
}


