API Docs for:
Show:

File: gameplay\AI\Components.js

/**
 A component class responsible for Artificial Intelligence.
 @class AI
 @constructor
 @param friendCollideWith {Number} A bit mask used when querying the physics engine for friendly entities.
 @param foeCollideWith {Number} A bit mask used when querying the physics engine for enemy entities.
 */
function AI(friendCollideWith, foeCollideWith){
    //The length of the array is the number of AI scripts available.
    this._scripts = new Array(3);
    this._friendCollideWith = (friendCollideWith !== undefined) ? friendCollideWith : 0xFFFFFFFF;
    this._foeCollideWith = (foeCollideWith !== undefined) ? foeCollideWith : 0xFFFFFFFF;
}

AI.prototype = {
    constructor : AI,
    _componentIdentifier : 0,
    
    /**
     Adding a script object to the AI component causes the component's entity to be processed with the corresponding script function if all other required components are present.
     @method addScript
     @param script {Object} A script object.
     */
    addScript : function(script){
        this._scripts[script.constructor.prototype._scriptIdentifier] = script;
    },
    
    /**
     Removes a script object and thus cases the entity to no longer be handled by the corresponding script function.
     @method removeScript
     @param scriptConstructor {Function} Constructor of the script object to be removed.
     */
    removeScript : function(scriptConstructor){
        this._scripts[scriptConstructor.prototype._scriptIdentifier] = null;
    },
    
    /**
     Checks if the component has a script attached.
     @method hasScript
     @param scriptConstructor {Function} Constructor of the script object.
     @return {Boolean} Returns true if the component has the script attached.
     */
    hasScript : function(scriptConstructor){
        return Boolean(this._scripts[scriptConstructor.prototype._scriptIdentifier]);
    },
    
    /**
     Retrieves a script object.
     @method getScript
     @param scriptConstructor {Function} Constructor of the script object.
     @return {Object|Null|Undefined} Returns the script object, if present, otherwise the function will return null or undefined.
     */
    getScript : function(scriptConstructor){
        return this._scripts[scriptConstructor.prototype._scriptIdentifier];
    },
    
    /**
     @method getFriendCollideWith
     @return {Number}
     */
    getFriendCollideWith : function(){
        return this._friendCollideWith;
    },
    
    /**
     @method setFriendCollideWith
     @param friendCollideWith {Number} A bit mask used when querying the physics engine for friendly entities.
     */
    setFriendCollideWith : function(friendCollideWith){
        this._friendCollideWith = friendCollideWith;
    },
    
    /**
     @method getFoeCollideWith
     @return {Number}
     */
    getFoeCollideWith : function(){
        return this._foeCollideWith;
    },
    
    /**
     @method setFoeCollideWith
     @param foeCollideWith {Number} A bit mask used when querying the physics engine for enemy entities.
     */
    setFoeCollideWith : function(foeCollideWith){
        this._foeCollideWith = foeCollideWith;
    }
};