/***************************************************************************
*                                                                          *
*  Copyright (C) Golaem S.A.  All Rights Reserved.                         *
*                                                                          *
***************************************************************************/

#pragma once

#include "glmSDKAPI.h"
#include <glmAbstractTrigger.h>

namespace glm
{
    class Entity;

    // Boolean callback which returns true depending on a probability
    class GLM_SDK_API RandomTrigger : public AbstractTrigger
    {
    public:
        typedef SmartPointer<RandomTrigger> SP;

    private:
        float _probability;
        bool _dynamic;

        glm::Array<float> _randomData; //!< Per entity data
    public:
        GLM_CLASS_STAT_ID( glm::MemoryStatIds::Simulation);

        RandomTrigger(float probability = 0.f, bool isDynamic = true);
        virtual ~RandomTrigger();

        virtual void allocate(BehaviorGraph& behaviorGraph) override;
        virtual void resize(BehaviorGraph& behaviorGraph) override;
		virtual bool isShareable() override;

    protected:
        // cloning
        friend class CloneFactory;
        inline virtual RandomTrigger* create() const override;

        virtual void doReset(int64_t index, AbstractBehavior* behavior, BehaviorGraph& behaviorGraph) override;
        virtual bool doCall(int64_t index, AbstractBehavior* behavior, BehaviorGraph& behaviorGraph, bool isAttached) override;
    };

    //-------------------------------------------------------------------------
    inline RandomTrigger* RandomTrigger::create() const
    {
        RandomTrigger* myNewRandomTrigger = GLM_NEW(RandomTrigger, myNewRandomTrigger, getClassMemoryStatId());
        return myNewRandomTrigger;
    }
} // namespace glm
