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

void GV_func_8038A084(Actor *this);

/* .data */
ActorInfo D_80390F40 = { 0x24F, 0x37C, 0x0, 
    0, NULL, 
    GV_func_8038A084, actor_update_func_80326224, func_80325340, 
    2000, 0, 0.0f, 0
};

ParticleSettingsScaleAndLifetimeDrawModeEmitCount D_80390F64 = {
    {   {2.5f, 2.8f},
        {4.0f, 5.0f},
        {0.0f, 0.01f},
        {2.0f, 2.5f},
        0.1f, 0.4f
    },
    4.0f,
    1.0f
};

s32 D_80390F94[3] = {0xFF, 0xFF, 0x9B};

/* .code */
void func_80389FA0(f32 position[3]){
    ParticleEmitter *pCtrl = partEmitMgr_newEmitter(1);
    particleEmitter_setSprite(pCtrl, ASSET_70D_SPRITE_SMOKE_1);
    particleEmitter_setStartingFrameRange(pCtrl, 1, 6);
    particleEmitter_setRGB(pCtrl, D_80390F94);
    particleEmitter_setAlpha(pCtrl, 100);
    particleEmitter_setPosition(pCtrl, position);
    particleEmitter_setSpawnPositionRange( pCtrl, 
        -700.0f, 0.0f, -700.0f, 
         700.0f, 0.0f,  700.0f
    );
    particleEmitter_setParticleVelocityRange(pCtrl,
        0.0f, 40.0f, 0.0f,
        0.0f, 90.0f, 0.0f
    );
    func_802EFC28(pCtrl, &D_80390F64);
}

void GV_func_8038A084(Actor *this){
    if(this->unkF4_8 == 6 && !this->volatile_initialized){
        this->volatile_initialized = TRUE;
        if( jiggyscore_isCollected(JIGGY_42_GV_WATER_PYRAMID) && this->yaw == 1.0f){
            this->unk38_31 = TRUE;
        }
    }

    if(this->unkF4_8 == 6
        && viewport_func_8024DB50(this->position, 50.0f)
        && !this->unk38_31
        && randf() < 0.2
    ){
        func_80389FA0(this->position);
    }
}
