#include <ultra64.h>
#include "functions.h"
#include "variables.h"

typedef struct {
    ParticleEmitter *unk0;
    ParticleEmitter *unk4;
} ActorLocal_cutscenes_69F0;

extern void func_8038CF50(Actor *this);

/* .data */
ActorInfo D_8038E7A0 = {
    0x211, 0x341, 0x45D,
    1, NULL,
    NULL, func_8038CF50, actor_draw,
    0, 0xA000, 0.0f, 0
};

s32 D_8038E7C4[3] = {0xFF, 0xFF, 0xFF};

ParticleScaleAndLifetimeRanges D_8038E7D0 = {
    {0.7f, 0.9f},
    {0.4f, 0.5f},
    {0.0f, 0.01f},
    {0.4f, 0.7f},
    0.15f, 0.3f
};

ParticleSettingsVelocityPosition D_8038E7F8 ={
    { {-10.0f, -10.0f, -10.0f}, {10.0f, 10.0f, 10.0f} },
    { {0.0f, 30.0f, 0.0f}, {0.0f, 30.0f, 0.0f} }
};

s32 D_8038E828[3] = {0xFF, 0xFF, 0xFF};

ParticleScaleAndLifetimeRanges D_8038E834 = {
    {0.05f, 0.1f},
    {0.1f, 0.2f},
    {0.0f, 0.01f},
    {1.4f, 1.5f},
    0.01f, 0.3f
};

ParticleSettingsVelocityPosition D_8038E85C ={
    { {-5.0f, -5.0f, -5.0f}, {5.0f, 5.0f, 5.0f} },
    { {0.0f, 30.0f, 0.0f}, {0.0f, 30.0f, 0.0f} }
};


/* .code */
void func_8038CDE0(ParticleEmitter *pCtrl){
    particleEmitter_setSprite(pCtrl, ASSET_45A_SPRITE_GREEN_GLOW);
    particleEmitter_setRGB(pCtrl, D_8038E7C4);
    particleEmitter_setAlpha(pCtrl, 0xff);
    particleEmitter_setAngularVelocityRange(pCtrl, -600.0f, -600.0f,-600.0f, 600.0f, 600.0f, 600.0f);
    particleEmitter_setPositionAndVelocityRanges(pCtrl, &D_8038E7F8);
    particleEmitter_setScaleAndLifetimeRanges(pCtrl, &D_8038E7D0);
    particleEmitter_func_802EFA78(pCtrl, 1);
    particleEmitter_setDrawMode(pCtrl, 4);
    particleEmitter_manualFree(pCtrl);
}

void func_8038CE98(ParticleEmitter *pCtrl){
    particleEmitter_setSprite(pCtrl, ASSET_713_SPRITE_SPARKLE_YELLOW);
    particleEmitter_setRGB(pCtrl, D_8038E828);
    particleEmitter_setAlpha(pCtrl, 0xff);
    particleEmitter_setAngularVelocityRange(pCtrl, -600.0f, -600.0f,-600.0f, 600.0f, 600.0f, 600.0f);
    particleEmitter_setPositionAndVelocityRanges(pCtrl, &D_8038E85C);
    particleEmitter_setScaleAndLifetimeRanges(pCtrl, &D_8038E834);
    particleEmitter_func_802EFA78(pCtrl, 1);
    particleEmitter_setDrawMode(pCtrl, 4);
    particleEmitter_manualFree(pCtrl);
}

extern void func_8038CF50(Actor *this){
    ActorLocal_cutscenes_69F0 *local  = (ActorLocal_cutscenes_69F0 *) &this->local;
    f32 sp40[3];
    int i;

    if(!this->volatile_initialized){
        this->volatile_initialized = TRUE;
        local->unk0 = partEmitMgr_newEmitter(6);
        local->unk4 = partEmitMgr_newEmitter(6);

        func_8038CDE0(local->unk0);
        func_8038CE98(local->unk4);
    }//L8038CFBC

    func_80343DEC(this);

    if(this->marker->unk14_21){
        for(i = 5; i < 6; i++){
            if(randf() < 0.4){
                func_8034A174(this->marker->unk44, i, sp40);
                particleEmitter_setPosition(local->unk0, sp40);
                particleEmitter_emitN(local->unk0, 1);
                
                particleEmitter_setPosition(local->unk4, sp40);
                particleEmitter_emitN(local->unk4, 1);

            }
        }
    }//L8038D05C
}

