12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104 |
- /**
- * b3
- *
- * Copyright (c) 2014 Renato de Pontes Pereira.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- **/
- //this.b3 = this.b3 || {};
- let b3 = {};
- /**
- * Behavior3JS
- * ===========
- *
- * * * *
- *
- * **Behavior3JS** is a Behavior Tree library written in JavaScript. It
- * provides structures and algorithms that assist you in the task of creating
- * intelligent agents for your game or application. Check it out some features
- * of Behavior3JS:
- *
- * - Based on the work of (Marzinotto et al., 2014), in which they propose a
- * **formal**, **consistent** and **general** definition of Behavior Trees;
- * - **Optimized to control multiple agents**: you can use a single behavior
- * tree instance to handle hundreds of agents;
- * - It was **designed to load and save trees in a JSON format**, in order to
- * use, edit and test it in multiple environments, tools and languages;
- * - A **cool visual editor** which you can access online;
- * - Several **composite, decorator and action nodes** available within the
- * library. You still can define your own nodes, including composites and
- * decorators;
- * - **Completely free**, the core module and the visual editor are all published
- * under the MIT License, which means that you can use them for your open source
- * and commercial projects;
- * - **Lightweight**, only 11.5KB!
- *
- * Visit http://behavior3js.guineashots.com to know more!
- *
- *
- * Core Classes and Functions
- * --------------------------
- *
- * This library include the following core structures...
- *
- * **Public:**
- *
- * - **BehaviorTree**: the structure that represents a Behavior Tree;
- * - **Blackboard**: represents a "memory" in an agent and is required to to
- * run a `BehaviorTree`;
- * - **Composite**: base class for all composite nodes;
- * - **Decorator**: base class for all decorator nodes;
- * - **Action**: base class for all action nodes;
- * - **Condition**: base class for all condition nodes;
- *
- * **Internal:**
- *
- *
- * - **Tick**: used as container and tracking object through the tree during
- * the tick signal;
- * - **BaseNode**: the base class that provide all common node features;
- *
- * *Some classes are used internally on Behavior3JS, but you may need to access
- * its functionalities eventually, specially the `Tick` object.*
- *
- *
- * Nodes Included
- * --------------
- *
- * **Composite Nodes**:
- *
- * - Sequence;
- * - Priority;
- * - MemSequence;
- * - MemPriority;
- *
- *
- * **Decorators**:
- *
- * - Inverter;
- * - Limiter
- * - MaxTime;
- * - Repeater;
- * - RepeaterUntilFailure;
- * - RepeaterUntilSuccess;
- *
- *
- * **Actions**:
- *
- * - Succeeder;
- * - Failer;
- * - Error;
- * - Runner;
- * - Wait.
- *
- * @module Behavior3JS
- * @main Behavior3JS
- **/
- (function() {
- "use strict";
- /**
- * List of all constants in Behavior3JS.
- *
- * @class Constants
- **/
- /**
- * Version of the library.
- *
- * @property VERSION
- * @type {String}
- */
- b3.VERSION = '0.1.0';
- /**
- * Returned when a criterion has been met by a condition node or an action node
- * has been completed successfully.
- *
- * @property SUCCESS
- * @type {Integer}
- */
- b3.SUCCESS = 1;
- /**
- * Returned when a criterion has not been met by a condition node or an action
- * node could not finish its execution for any reason.
- *
- * @property FAILURE
- * @type {Integer}
- */
- b3.FAILURE = 2;
- /**
- * Returned when an action node has been initialized but is still waiting the
- * its resolution.
- *
- * @property FAILURE
- * @type {Integer}
- */
- b3.RUNNING = 3;
- /**
- * Returned when some unexpected error happened in the tree, probably by a
- * programming error (trying to verify an undefined variable). Its use depends
- * on the final implementation of the leaf nodes.
- *
- * @property ERROR
- * @type {Integer}
- */
- b3.ERROR = 4;
- /**
- * Describes the node category as Composite.
- *
- * @property COMPOSITE
- * @type {String}
- */
- b3.COMPOSITE = 'composite';
- /**
- * Describes the node category as Decorator.
- *
- * @property DECORATOR
- * @type {String}
- */
- b3.DECORATOR = 'decorator';
- /**
- * Describes the node category as Action.
- *
- * @property ACTION
- * @type {String}
- */
- b3.ACTION = 'action';
- /**
- * Describes the node category as Condition.
- *
- * @property CONDITION
- * @type {String}
- */
- b3.CONDITION = 'condition';
- /**
- * List of internal and helper functions in Behavior3JS.
- *
- * @class Utils
- **/
- /**
- * This function is used to create unique IDs for trees and nodes.
- *
- * (consult http://www.ietf.org/rfc/rfc4122.txt).
- *
- * @method createUUID
- * @return {String} A unique ID.
- **/
- b3.createUUID = function() {
- var s = [];
- var hexDigits = "0123456789abcdef";
- for (var i = 0; i < 36; i++) {
- s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
- }
- // bits 12-15 of the time_hi_and_version field to 0010
- s[14] = "4";
- // bits 6-7 of the clock_seq_hi_and_reserved to 01
- s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);
- s[8] = s[13] = s[18] = s[23] = "-";
- var uuid = s.join("");
- return uuid;
- }
- /**
- * Class is a meta-factory function to create classes in JavaScript. It is a
- * shortcut for the CreateJS syntax style. By default, the class created by
- * this function have an initialize function (the constructor). Optionally, you
- * can specify the inheritance by passing another class as parameter.
- *
- * By default, all classes created using this function, may receives only a
- * settings parameter as argument. This pattern is commonly used by jQuery and
- * its plugins.
- *
- * Usage
- * -----
- *
- * // Creating a simple class
- * var BaseClass = b3.Class();
- *
- * // Using inheritance
- * var ChildClass = b3.Class(BaseClass);
- *
- * // Defining the constructor
- * ChildClass.prototype.initialize = function(settings) { ... }
- *
- * @method Class
- * @param {Object} [baseClass] The super class.
- * @return {Object} A new class.
- **/
- b3.Class = function(baseClass) {
- // create a new class
- var cls = function(params) {
- this.initialize(params);
- }
-
- // if base class is provided, inherit
- if (baseClass) {
- cls.prototype = new baseClass();
- cls.prototype.constructor = cls;
- }
-
- // create initialize if does not exist on baseClass
- cls.prototype.initialize = cls.prototype.initialize || function() {};
- return cls;
- }
- })();/**
- * Blackboard
- *
- * Copyright (c) 2014 Renato de Pontes Pereira.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- **/
- /**
- * @module Behavior3JS
- **/
- // namespace:
- //this.b3 = this.b3 || {};
- (function() {
- "use strict";
- /**
- * The Blackboard is the memory structure required by `BehaviorTree` and its
- * nodes. It only have 2 public methods: `set` and `get`. These methods works
- * in 3 different contexts: global, per tree, and per node per tree.
- *
- * Suppose you have two different trees controlling a single object with a
- * single blackboard, then:
- *
- * - In the global context, all nodes will access the stored information.
- * - In per tree context, only nodes sharing the same tree share the stored
- * information.
- * - In per node per tree context, the information stored in the blackboard can
- * only be accessed by the same node that wrote the data.
- *
- * The context is selected indirectly by the parameters provided to these
- * methods, for example:
- *
- * // getting/setting variable in global context
- * blackboard.set('testKey', 'value');
- * var value = blackboard.get('testKey');
- *
- * // getting/setting variable in per tree context
- * blackboard.set('testKey', 'value', tree.id);
- * var value = blackboard.get('testKey', tree.id);
- *
- * // getting/setting variable in per node per tree context
- * blackboard.set('testKey', 'value', tree.id, node.id);
- * var value = blackboard.get('testKey', tree.id, node.id);
- *
- * Note: Internally, the blackboard store these memories in different objects,
- * being the global on `_baseMemory`, the per tree on `_treeMemory` and the
- * per node per tree dynamically create inside the per tree memory (it is
- * accessed via `_treeMemory[id].nodeMemory`). Avoid to use these variables
- * manually, use `get` and `set` instead.
- *
- * @class Blackboard
- **/
- var Blackboard = b3.Class();
- var p = Blackboard.prototype;
- /**
- * Initialization method.
- *
- * @method initialize
- * @constructor
- **/
- p.initialize = function() {
- this._baseMemory = {};
- this._treeMemory = {};
- }
- /**
- * Internal method to retrieve the tree context memory. If the memory does
- * not exist, this method creates it.
- *
- * @method _getTreeMemory
- * @param {string} treeScope The id of the tree in scope.
- * @returns {Object} The tree memory.
- * @protected
- **/
- p._getTreeMemory = function(treeScope) {
- if (!this._treeMemory[treeScope]) {
- this._treeMemory[treeScope] = {
- 'nodeMemory' : {},
- 'openNodes' : [],
- 'traversalDepth' : 0,
- 'traversalCycle' : 0,
- };
- }
- return this._treeMemory[treeScope];
- };
- /**
- * Internal method to retrieve the node context memory, given the tree
- * memory. If the memory does not exist, this method creates is.
- *
- * @method _getNodeMemory
- * @param {String} treeMemory the tree memory.
- * @param {String} nodeScope The id of the node in scope.
- * @returns {Object} The node memory.
- * @protected
- **/
- p._getNodeMemory = function(treeMemory, nodeScope) {
- var memory = treeMemory['nodeMemory'];
- if (!memory[nodeScope]) {
- memory[nodeScope] = {};
- }
- return memory[nodeScope];
- };
- /**
- * Internal method to retrieve the context memory. If treeScope and
- * nodeScope are provided, this method returns the per node per tree
- * memory. If only the treeScope is provided, it returns the per tree
- * memory. If no parameter is provided, it returns the global memory.
- * Notice that, if only nodeScope is provided, this method will still
- * return the global memory.
- *
- * @method _getMemory
- * @param {String} treeScope The id of the tree scope.
- * @param {String} nodeScope The id of the node scope.
- * @returns {Object} A memory object.
- * @protected
- **/
- p._getMemory = function(treeScope, nodeScope) {
- var memory = this._baseMemory;
- if (treeScope) {
- memory = this._getTreeMemory(treeScope);
- if (nodeScope) {
- memory = this._getNodeMemory(memory, nodeScope);
- }
- }
- return memory;
- };
- /**
- * Stores a value in the blackboard. If treeScope and nodeScope are
- * provided, this method will save the value into the per node per tree
- * memory. If only the treeScope is provided, it will save the value into
- * the per tree memory. If no parameter is provided, this method will save
- * the value into the global memory. Notice that, if only nodeScope is
- * provided (but treeScope not), this method will still save the value into
- * the global memory.
- *
- * @method set
- * @param {String} key The key to be stored.
- * @param {String} value The value to be stored.
- * @param {String} treeScope The tree id if accessing the tree or node
- * memory.
- * @param {String} nodeScope The node id if accessing the node memory.
- **/
- p.set = function(key, value, treeScope, nodeScope) {
- var memory = this._getMemory(treeScope, nodeScope);
- memory[key] = value;
- };
- /**
- * Retrieves a value in the blackboard. If treeScope and nodeScope are
- * provided, this method will retrieve the value from the per node per tree
- * memory. If only the treeScope is provided, it will retrieve the value
- * from the per tree memory. If no parameter is provided, this method will
- * retrieve from the global memory. If only nodeScope is provided (but
- * treeScope not), this method will still try to retrieve from the global
- * memory.
- *
- * @method get
- * @param {String} key The key to be retrieved.
- * @param {String} treeScope The tree id if accessing the tree or node
- * memory.
- * @param {String} nodeScope The node id if accessing the node memory.
- * @returns {Object} The value stored or undefined.
- **/
- p.get = function(key, treeScope, nodeScope) {
- var memory = this._getMemory(treeScope, nodeScope);
- return memory[key];
- };
-
- b3.Blackboard = Blackboard;
- })();/**
- * Tick
- *
- * Copyright (c) 2014 Renato de Pontes Pereira.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- **/
- /**
- * @module Behavior3JS
- **/
- // namespace:
- //this.b3 = this.b3 || {};
- (function() {
- "use strict";
- /**
- * A new Tick object is instantiated every tick by BehaviorTree. It is passed
- * as parameter to the nodes through the tree during the traversal.
- *
- * The role of the Tick class is to store the instances of tree, debug, target
- * and blackboard. So, all nodes can access these informations.
- *
- * For internal uses, the Tick also is useful to store the open node after the
- * tick signal, in order to let `BehaviorTree` to keep track and close them
- * when necessary.
- *
- * This class also makes a bridge between nodes and the debug, passing the node
- * state to the debug if the last is provided.
- *
- * @class Tick
- **/
- var Tick = b3.Class();
- var p = Tick.prototype;
- /**
- * The tree reference.
- *
- * @property tree
- * @type {b3.BehaviorTree}
- * @readOnly
- */
-
- /**
- * The debug reference.
- *
- * @property debug
- * @type {Object}
- * @readOnly
- */
-
- /**
- * The target object reference.
- *
- * @property target
- * @type {Object}
- * @readOnly
- */
-
- /**
- * The blackboard reference.
- *
- * @property blackboard
- * @type {Blackboard}
- * @readOnly
- */
-
- /**
- * The list of open nodes. Update during the tree traversal.
- *
- * @property _openNodes
- * @type {Array}
- * @protected
- * @readOnly
- */
-
- /**
- * The number of nodes entered during the tick. Update during the tree
- * traversal.
- *
- * @property _nodeCount
- * @type {Integer}
- * @protected
- * @readOnly
- */
-
- /**
- * Initialization method.
- *
- * @method initialize
- * @constructor
- **/
- p.initialize = function() {
- // set by BehaviorTree
- this.tree = null;
- this.debug = null;
- this.target = null;
- this.blackboard = null;
- // updated during the tick signal
- this._openNodes = [];
- this._nodeCount = 0;
- }
- /**
- * Called when entering a node (called by BaseNode).
- *
- * @method _enterNode
- * @param {Object} node The node that called this method.
- * @protected
- **/
- p._enterNode = function(node) {
- this._nodeCount++;
- this._openNodes.push(node);
- // TODO: call debug here
- }
- /**
- * Callback when opening a node (called by BaseNode).
- *
- * @method _openNode
- * @param {Object} node The node that called this method.
- * @protected
- **/
- p._openNode = function(node) {
- // TODO: call debug here
- }
- /**
- * Callback when ticking a node (called by BaseNode).
- *
- * @method _tickNode
- * @param {Object} node The node that called this method.
- * @protected
- **/
- p._tickNode = function(node) {
- // TODO: call debug here
- }
- /**
- * Callback when closing a node (called by BaseNode).
- *
- * @method _closeNode
- * @param {Object} node The node that called this method.
- * @protected
- **/
- p._closeNode = function(node) {
- // TODO: call debug here
- this._openNodes.pop();
- }
- /**
- * Callback when exiting a node (called by BaseNode).
- *
- * @method _exitNode
- * @param {Object} node The node that called this method.
- * @protected
- **/
- p._exitNode = function(node) {
- // TODO: call debug here
- }
- b3.Tick = Tick;
- })();/**
- * BehaviorTree
- *
- * Copyright (c) 2014 Renato de Pontes Pereira.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- **/
- /**
- * @module Behavior3JS
- **/
- // namespace:
- //this.b3 = this.b3 || {};
- (function() {
- "use strict";
- /**
- * The BehaviorTree class, as the name implies, represents the Behavior Tree
- * structure.
- *
- * There are two ways to construct a Behavior Tree: by manually setting the
- * root node, or by loading it from a data structure (which can be loaded from
- * a JSON). Both methods are shown in the examples below and better explained
- * in the user guide.
- *
- * The tick method must be called periodically, in order to send the tick
- * signal to all nodes in the tree, starting from the root. The method
- * `BehaviorTree.tick` receives a target object and a blackboard as parameters.
- * The target object can be anything: a game agent, a system, a DOM object,
- * etc. This target is not used by any piece of Behavior3JS, i.e., the target
- * object will only be used by custom nodes.
- *
- * The blackboard is obligatory and must be an instance of `Blackboard`. This
- * requirement is necessary due to the fact that neither `BehaviorTree` or any
- * node will store the execution variables in its own object (e.g., the BT does
- * not store the target, information about opened nodes or number of times the
- * tree was called). But because of this, you only need a single tree instance
- * to control multiple (maybe hundreds) objects.
- *
- * Manual construction of a Behavior Tree
- * --------------------------------------
- *
- * var tree = new b3.BehaviorTree();
- *
- * tree.root = new b3.Sequence({children:[
- * new b3.Priority({children:[
- * new MyCustomNode(),
- * new MyCustomNode()
- * ]}),
- * ...
- * ]});
- *
- *
- * Loading a Behavior Tree from data structure
- * -------------------------------------------
- *
- * var tree = new b3.BehaviorTree();
- *
- * tree.load({
- * 'title' : 'Behavior Tree title'
- * 'description' : 'My description'
- * 'root' : 'node-id-1'
- * 'nodes' : {
- * 'node-id-1' : {
- * 'name' : 'Priority', // this is the node type
- * 'title' : 'Root Node',
- * 'description' : 'Description',
- * 'children' : ['node-id-2', 'node-id-3'],
- * },
- * ...
- * }
- * })
- *
- *
- * @class BehaviorTree
- **/
- var BehaviorTree = b3.Class();
- var p = BehaviorTree.prototype;
- /**
- * The tree id, must be unique. By default, created with `b3.createUUID`.
- *
- * @property id
- * @type {String}
- * @readOnly
- */
-
- /**
- * The tree title.
- *
- * @property title
- * @type {String}
- */
-
- /**
- * Description of the tree.
- *
- * @property description
- * @type {String}
- */
-
- /**
- * A dictionary with (key-value) properties. Useful to define custom
- * variables in the visual editor.
- *
- * @property properties
- * @type {Object}
- */
- /**
- * The reference to the root node. Must be an instance of `b3.BaseNode`.
- *
- * @property root
- * @type {BaseNode}
- */
- /**
- * The reference to the debug instance.
- *
- * @property debug
- * @type {Object}
- */
- /**
- * Initialization method.
- *
- * @method initialize
- * @constructor
- **/
- p.initialize = function() {
- this.id = b3.createUUID();
- this.title = 'The behavior tree';
- this.description = 'Default description';
- this.properties = {};
- this.root = null;
- this.debug = null;
- }
- /**
- * This method loads a Behavior Tree from a data structure, populating this
- * object with the provided data. Notice that, the data structure must
- * follow the format specified by Behavior3JS. Consult the guide to know
- * more about this format.
- *
- * You probably want to use custom nodes in your BTs, thus, you need to
- * provide the `names` object, in which this method can find the nodes by
- * `names[NODE_NAME]`. This variable can be a namespace or a dictionary,
- * as long as this method can find the node by its name, for example:
- *
- * //json
- * ...
- * 'node1': {
- * 'name': MyCustomNode,
- * 'title': ...
- * }
- * ...
- *
- * //code
- * var bt = new b3.BehaviorTree();
- * bt.load(data, {'MyCustomNode':MyCustomNode})
- *
- *
- * @method load
- * @param {Object} data The data structure representing a Behavior Tree.
- * @param {Object} [names] A namespace or dict containing custom nodes.
- **/
- p.load = function(data, names) {
- names = names || {};
- this.title = data.title || this.title;
- this.description = data.description || this.description;
- this.properties = data.properties || this.properties;
- var nodes = {};
- // Create the node list (without connection between them)
- for (var id in data.nodes) {
- var spec = data.nodes[id];
- if (spec.name in names) {
- // Look for the name in custom nodes
- var cls = names[spec.name];
- } else if (spec.name in b3) {
- // Look for the name in default nodes
- var cls = b3[spec.name];
- } else {
- // Invalid node name
- throw EvalError('BehaviorTree.load: Invalid node name + "'+
- spec.name+'".');
- }
- var node = new cls(spec.parameters);
- node.id = spec.id || node.id;
- node.title = spec.title || node.title;
- node.description = spec.description || node.description;
- node.properties = spec.properties || node.properties;
- node.parameters = spec.parameters || node.parameters;
- nodes[id] = node;
- }
- // Connect the nodes
- for (var id in data.nodes) {
- var spec = data.nodes[id];
- var node = nodes[id];
- if (node.category === b3.COMPOSITE && spec.children) {
- for (var i=0; i<spec.children.length; i++) {
- var cid = spec.children[i];
- node.children.push(nodes[cid]);
- }
- } else if (node.category === b3.DECORATOR && spec.child) {
- node.child = nodes[spec.child];
- }
- }
- this.root = nodes[data.root];
- };
- /**
- * This method dump the current BT into a data structure.
- *
- * Note: This method does not record the current node parameters. Thus,
- * it may not be compatible with load for now.
- *
- * @method dump
- * @returns {Object} A data object representing this tree.
- **/
- p.dump = function() {
- var data = {};
- data.title = this.title;
- data.description = this.description;
- data.root = (this.root)? this.root.id:null;
- data.properties = this.properties;
- data.nodes = {};
- if (!this.root) return data;
- var stack = [this.root];
- while (stack.length > 0) {
- var node = stack.pop();
- var spec = {};
- spec.id = node.id;
- spec.name = node.name;
- spec.title = node.title;
- spec.description = node.description;
- spec.properties = node.properties;
- spec.parameters = node.parameters;
-
- if (node.category === b3.COMPOSITE && node.children) {
- var children = []
- for (var i=node.children.length-1; i>=0; i--) {
- children.push(node.children[i].id);
- stack.push(node.children[i]);
- }
- spec.children = children;
- } else if (node.category === b3.DECORATOR && node.child) {
- stack.push(node.child);
- spec.child = node.child.id;
- }
- data.nodes[node.id] = spec;
- }
- return data;
- };
- /**
- * Propagates the tick signal through the tree, starting from the root.
- *
- * This method receives a target object of any type (Object, Array,
- * DOMElement, whatever) and a `Blackboard` instance. The target object has
- * no use at all for all Behavior3JS components, but surely is important
- * for custom nodes. The blackboard instance is used by the tree and nodes
- * to store execution variables (e.g., last node running) and is obligatory
- * to be a `Blackboard` instance (or an object with the same interface).
- *
- * Internally, this method creates a Tick object, which will store the
- * target and the blackboard objects.
- *
- * Note: BehaviorTree stores a list of open nodes from last tick, if these
- * nodes weren't called after the current tick, this method will close them
- * automatically.
- *
- * @method tick
- * @param {Object} target A target object.
- * @param {Blackboard} blackboard An instance of blackboard object.
- * @returns {Constant} The tick signal state.
- **/
- p.tick = function(target, blackboard) {
- if (!blackboard) {
- throw 'The blackboard parameter is obligatory and must be an ' +
- 'instance of b3.Blackboard';
- }
- /* CREATE A TICK OBJECT */
- var tick = new b3.Tick();
- tick.debug = this.debug;
- tick.target = target;
- tick.blackboard = blackboard;
- tick.tree = this;
- /* TICK NODE */
- var state = this.root._execute(tick);
- /* CLOSE NODES FROM LAST TICK, IF NEEDED */
- var lastOpenNodes = blackboard.get('openNodes', this.id);
- var currOpenNodes = tick._openNodes.slice(0);
- // does not close if it is still open in this tick
- var start = 0;
- for (var i=0; i<Math.min(lastOpenNodes.length, currOpenNodes.length); i++) {
- start = i+1;
- if (lastOpenNodes[i] !== currOpenNodes[i]) {
- break;
- }
- }
- // close the nodes
- for (var i=lastOpenNodes.length-1; i>=start; i--) {
- lastOpenNodes[i]._close(tick);
- }
- /* POPULATE BLACKBOARD */
- blackboard.set('openNodes', currOpenNodes, this.id);
- blackboard.set('nodeCount', tick._nodeCount, this.id);
- return state;
- };
-
- b3.BehaviorTree = BehaviorTree;
- })();/**
- * BaseNode
- *
- * Copyright (c) 2014 Renato de Pontes Pereira.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- **/
- /**
- * @module Behavior3JS
- **/
- // namespace:
- //this.b3 = this.b3 || {};
- (function() {
- "use strict";
- /**
- * The BaseNode class is used as super class to all nodes in BehaviorJS. It
- * comprises all common variables and methods that a node must have to execute.
- *
- * **IMPORTANT:** Do not inherit from this class, use `b3.Composite`,
- * `b3.Decorator`, `b3.Action` or `b3.Condition`, instead.
- *
- * The attributes are specially designed to serialization of the node in a JSON
- * format. In special, the `parameters` attribute can be set into the visual
- * editor (thus, in the JSON file), and it will be used as parameter on the
- * node initialization at `BehaviorTree.load`.
- *
- * BaseNode also provide 5 callback methods, which the node implementations can
- * override. They are `enter`, `open`, `tick`, `close` and `exit`. See their
- * documentation to know more. These callbacks are called inside the `_execute`
- * method, which is called in the tree traversal.
- *
- * @class BaseNode
- **/
- var BaseNode = b3.Class();
- var p = BaseNode.prototype;
- /**
- * Node ID.
- *
- * @property id
- * @type {String}
- * @readonly
- **/
- /**
- * Node name. Must be a unique identifier, preferable the same name of the
- * class. You have to set the node name in the prototype.
- *
- * @property name
- * @type {String}
- * @readonly
- **/
- p.name = null;
- /**
- * Node category. Must be `b3.COMPOSITE`, `b3.DECORATOR`, `b3.ACTION` or
- * `b3.CONDITION`. This is defined automatically be inheriting the
- * correspondent class.
- *
- * @property category
- * @type constant
- * @readonly
- **/
- p.category = null;
- /**
- * Node title.
- *
- * @property title
- * @type {String}
- * @optional
- * @readonly
- **/
- p.title = null;
- /**
- * Node description.
- *
- * @property description
- * @type {String}
- * @optional
- * @readonly
- **/
- p.description = null;
- /**
- * A dictionary (key, value) describing the node parameters. Useful for
- * defining parameter values in the visual editor. Note: this is only
- * useful for nodes when loading trees from JSON files.
- *
- * @property parameters
- * @type {Object}
- * @readonly
- **/
- p.parameters = null;
- /**
- * A dictionary (key, value) describing the node properties. Useful for
- * defining custom variables inside the visual editor.
- *
- * @property properties
- * @type {Object}
- * @readonly
- **/
- p.properties = null;
- /**
- * Initialization method.
- *
- * @method initialize
- * @constructor
- **/
- p.initialize = function() {
- this.id = b3.createUUID();
- this.title = this.title || this.name;
- this.description = '';
- this.parameters = {};
- this.properties = {};
- }
- /**
- * This is the main method to propagate the tick signal to this node. This
- * method calls all callbacks: `enter`, `open`, `tick`, `close`, and
- * `exit`. It only opens a node if it is not already open. In the same
- * way, this method only close a node if the node returned a status
- * different of `b3.RUNNING`.
- *
- * @method _execute
- * @param {Tick} tick A tick instance.
- * @returns {Constant} The tick state.
- * @protected
- **/
- p._execute = function(tick) {
- /* ENTER */
- this._enter(tick);
- /* OPEN */
- if (!tick.blackboard.get('isOpen', tick.tree.id, this.id)) {
- this._open(tick);
- }
- /* TICK */
- var status = this._tick(tick);
- /* CLOSE */
- if (status !== b3.RUNNING) {
- this._close(tick);
- }
- /* EXIT */
- this._exit(tick);
- return status;
- }
- /**
- * Wrapper for enter method.
- *
- * @method _enter
- * @param {Tick} tick A tick instance.
- * @protected
- **/
- p._enter = function(tick) {
- tick._enterNode(this);
- this.enter(tick);
- }
- /**
- * Wrapper for open method.
- *
- * @method _open
- * @param {Tick} tick A tick instance.
- * @protected
- **/
- p._open = function(tick) {
- tick._openNode(this);
- tick.blackboard.set('isOpen', true, tick.tree.id, this.id);
- this.open(tick);
- }
- /**
- * Wrapper for tick method.
- *
- * @method _tick
- * @param {Tick} tick A tick instance.
- * @returns {Constant} A state constant.
- * @protected
- **/
- p._tick = function(tick) {
- tick._tickNode(this);
- return this.tick(tick);
- }
- /**
- * Wrapper for close method.
- *
- * @method _close
- * @param {Tick} tick A tick instance.
- * @protected
- **/
- p._close = function(tick) {
- tick._closeNode(this);
- tick.blackboard.set('isOpen', false, tick.tree.id, this.id);
- this.close(tick);
- }
- /**
- * Wrapper for exit method.
- *
- * @method _exit
- * @param {Tick} tick A tick instance.
- * @protected
- **/
- p._exit = function(tick) {
- tick._exitNode(this);
- this.exit(tick);
- }
- /**
- * Enter method, override this to use. It is called every time a node is
- * asked to execute, before the tick itself.
- *
- * @method enter
- * @param {Tick} tick A tick instance.
- **/
- p.enter = function(tick) {}
- /**
- * Open method, override this to use. It is called only before the tick
- * callback and only if the not isn't closed.
- *
- * Note: a node will be closed if it returned `b3.RUNNING` in the tick.
- *
- * @method open
- * @param {Tick} tick A tick instance.
- **/
- p.open = function(tick) {}
- /**
- * Tick method, override this to use. This method must contain the real
- * execution of node (perform a task, call children, etc.). It is called
- * every time a node is asked to execute.
- *
- * @method tick
- * @param {Tick} tick A tick instance.
- **/
- p.tick = function(tick) {}
- /**
- * Close method, override this to use. This method is called after the tick
- * callback, and only if the tick return a state different from
- * `b3.RUNNING`.
- *
- * @method close
- * @param {Tick} tick A tick instance.
- **/
- p.close = function(tick) {}
- /**
- * Exit method, override this to use. Called every time in the end of the
- * execution.
- *
- * @method exit
- * @param {Tick} tick A tick instance.
- **/
- p.exit = function(tick) {}
-
- b3.BaseNode = BaseNode;
- })();/**
- * Action
- *
- * Copyright (c) 2014 Renato de Pontes Pereira.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- **/
- /**
- * @module Behavior3JS
- **/
- // namespace:
- //this.b3 = this.b3 || {};
- (function() {
- "use strict";
- /**
- * Action is the base class for all action nodes. Thus, if you want to
- * create new custom action nodes, you need to inherit from this class.
- *
- * For example, take a look at the Runner action:
- *
- * var Runner = b3.Class(b3.Action);
- * var p = Runner.prototype;
- *
- * p.name = 'Runner';
- *
- * p.tick = function(tick) {
- * return b3.RUNNING;
- * }
- *
- * @class Action
- * @extends BaseNode
- **/
- var Action = b3.Class(b3.BaseNode);
- var p = Action.prototype;
- /**
- * Node category. Default to `b3.ACTION`.
- *
- * @property category
- * @type {String}
- * @readonly
- **/
- p.category = b3.ACTION;
- p.__BaseNode_initialize = p.initialize;
- /**
- * Initialization method.
- *
- * @method initialize
- * @constructor
- **/
- p.initialize = function() {
- this.__BaseNode_initialize();
- }
- b3.Action = Action;
- })();/**
- * Composite
- *
- * Copyright (c) 2014 Renato de Pontes Pereira.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- **/
- /**
- * @module Behavior3JS
- **/
- // namespace:
- //this.b3 = this.b3 || {};
- (function() {
- "use strict";
- /**
- * Composite is the base class for all composite nodes. Thus, if you want to
- * create new custom composite nodes, you need to inherit from this class.
- *
- * When creating composite nodes, you will need to propagate the tick signal to
- * the children nodes manually. To do that, override the `tick` method and call
- * the `_execute` method on all nodes. For instance, take a look at how the
- * Sequence node inherit this class and how it call its children:
- *
- *
- * // Inherit from Composite, using the util function Class.
- * var Sequence = b3.Class(b3.Composite);
- * var p = Sequence.prototype;
- *
- * // Remember to set the name of the node.
- * p.name = 'Sequence';
- *
- * // Override the tick function
- * p.tick = function(tick) {
- *
- * // Iterates over the children
- * for (var i=0; i<this.children.length; i++) {
- *
- * // Propagate the tick
- * var status = this.children[i]._execute(tick);
- *
- * if (status !== b3.SUCCESS) {
- * return status;
- * }
- * }
- *
- * return b3.SUCCESS;
- * }
- *
- * @class Composite
- * @extends BaseNode
- **/
- var Composite = b3.Class(b3.z);
- var p = Composite.prototype;
- /**
- * Node category. Default to `b3.COMPOSITE`.
- *
- * @property category
- * @type {String}
- * @readonly
- **/
- p.category = b3.COMPOSITE;
- p.__BaseNode_initialize = p.initialize;
- /**
- * Initialization method.
- *
- * @method initialize
- * @constructor
- **/
- p.initialize = function(settings) {
- settings = settings || {};
- this.__BaseNode_initialize();
- this.children = (settings.children || []).slice(0);
- };
- b3.Composite = Composite;
- })();/**
- * Decorator
- *
- * Copyright (c) 2014 Renato de Pontes Pereira.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- **/
- /**
- * @module Behavior3JS
- **/
- // namespace:
- //this.b3 = this.b3 || {};
- (function() {
- "use strict";
- /**
- * Decorator is the base class for all decorator nodes. Thus, if you want to
- * create new custom decorator nodes, you need to inherit from this class.
- *
- * When creating decorator nodes, you will need to propagate the tick signal to
- * the child node manually, just like the composite nodes. To do that, override
- * the `tick` method and call the `_execute` method on the child node. For
- * instance, take a look at how the Inverter node inherit this class and how it
- * call its children:
- *
- *
- * // Inherit from Decorator, using the util function Class.
- * var Inverter = b3.Class(b3.Decorator);
- * var p = Inverter.prototype;
- *
- * // Remember to set the name of the node.
- * p.name = 'Inverter';
- *
- * // Override the tick function
- * p.tick = function(tick) {
- * if (!this.child) {
- * return b3.ERROR;
- * }
- *
- * // Propagate the tick
- * var status = this.child._execute(tick);
- *
- * if (status == b3.SUCCESS)
- * status = b3.FAILURE;
- * else if (status == b3.FAILURE)
- * status = b3.SUCCESS;
- *
- * return status;
- * };
- *
- * @class Decorator
- * @extends BaseNode
- **/
- var Decorator = b3.Class(b3.BaseNode);
- var p = Decorator.prototype;
- /**
- * Node category. Default to b3.DECORATOR.
- *
- * @property category
- * @type {String}
- * @readonly
- **/
- p.category = b3.DECORATOR;
- p.__BaseNode_initialize = p.initialize;
- /**
- * Initialization method.
- *
- * @method initialize
- * @constructor
- **/
- p.initialize = function(settings) {
- settings = settings || {};
- this.__BaseNode_initialize();
- this.child = settings.child || null;
- };
- b3.Decorator = Decorator;
- })();/**
- * Condition
- *
- * Copyright (c) 2014 Renato de Pontes Pereira.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- **/
- /**
- * @module Behavior3JS
- **/
- // namespace:
- //this.b3 = this.b3 || {};
- (function() {
- "use strict";
- /**
- * Condition is the base class for all condition nodes. Thus, if you want to
- * create new custom condition nodes, you need to inherit from this class.
- *
- * @class Condition
- * @extends BaseNode
- **/
- var Condition = b3.Class(b3.BaseNode);
- var p = Condition.prototype;
- /**
- * Node category. Default to `b3.CONDITION`.
- *
- * @property category
- * @type {String}
- * @readonly
- **/
- p.category = b3.CONDITION;
- p.__BaseNode_initialize = p.initialize;
- /**
- * Initialization method.
- *
- * @method initialize
- * @constructor
- **/
- p.initialize = function() {
- this.__BaseNode_initialize();
- }
- b3.Condition = Condition;
- })();/**
- * Sequence
- *
- * Copyright (c) 2014 Renato de Pontes Pereira.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- **/
- /**
- * @module Behavior3JS
- **/
- // namespace:
- //this.b3 = this.b3 || {};
- (function() {
- "use strict";
- /**
- * The Sequence node ticks its children sequentially until one of them returns
- * `FAILURE`, `RUNNING` or `ERROR`. If all children return the success state,
- * the sequence also returns `SUCCESS`.
- *
- * @class Sequence
- * @extends Composite
- **/
- var Sequence = b3.Class(b3.Composite);
- var p = Sequence.prototype;
- /**
- * Node name. Default to `Sequence`.
- *
- * @property name
- * @type {String}
- * @readonly
- **/
- p.name = 'Sequence';
- /**
- * Tick method.
- *
- * @method tick
- * @param {b3.Tick} tick A tick instance.
- * @returns {Constant} A state constant.
- **/
- p.tick = function(tick) {
- for (var i=0; i<this.children.length; i++) {
- var status = this.children[i]._execute(tick);
- if (status !== b3.SUCCESS) {
- return status;
- }
- }
- return b3.SUCCESS;
- }
- b3.Sequence = Sequence;
- })();/**
- * Priority
- *
- * Copyright (c) 2014 Renato de Pontes Pereira.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- **/
- /**
- * @module Behavior3JS
- **/
- // namespace:
- //this.b3 = this.b3 || {};
- (function() {
- "use strict";
- /**
- * Priority ticks its children sequentially until one of them returns
- * `SUCCESS`, `RUNNING` or `ERROR`. If all children return the failure state,
- * the priority also returns `FAILURE`.
- *
- * @class Priority
- * @extends Composite
- **/
- var Priority = b3.Class(b3.Composite);
- var p = Priority.prototype
- /**
- * Node name. Default to `Priority`.
- *
- * @property name
- * @type String
- * @readonly
- **/
- p.name = 'Priority';
- /**
- * Tick method.
- *
- * @method tick
- * @param {Tick} tick A tick instance.
- * @returns {Constant} A state constant.
- **/
- p.tick = function(tick) {
- for (var i=0; i<this.children.length; i++) {
- var status = this.children[i]._execute(tick);
- if (status !== b3.FAILURE) {
- return status;
- }
- }
- return b3.FAILURE;
- }
- b3.Priority = Priority;
- })();/**
- * MemSequence
- *
- * Copyright (c) 2014 Renato de Pontes Pereira.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- **/
- /**
- * @module Behavior3JS
- **/
- // namespace:
- //this.b3 = this.b3 || {};
- (function() {
- "use strict";
- /**
- * MemSequence is similar to Sequence node, but when a child returns a
- * `RUNNING` state, its index is recorded and in the next tick the MemPriority
- * call the child recorded directly, without calling previous children again.
- *
- * @class MemPriority
- * @extends Composite
- **/
- var MemSequence = b3.Class(b3.Composite);
- var p = MemSequence.prototype
- /**
- * Node name. Default to `MemSequence`.
- *
- * @property name
- * @type {String}
- * @readonly
- **/
- p.name = 'MemSequence';
- /**
- * Open method.
- *
- * @method open
- * @param {b3.Tick} tick A tick instance.
- **/
- p.open = function(tick) {
- tick.blackboard.set('runningChild', 0, tick.tree.id, this.id);
- }
- /**
- * Tick method.
- *
- * @method tick
- * @param {b3.Tick} tick A tick instance.
- * @returns {Constant} A state constant.
- **/
- p.tick = function(tick) {
- var child = tick.blackboard.get('runningChild', tick.tree.id, this.id);
- for (var i=child; i<this.children.length; i++) {
- var status = this.children[i]._execute(tick);
- if (status !== b3.SUCCESS) {
- if (status === b3.RUNNING) {
- tick.blackboard.set('runningChild', i, tick.tree.id, this.id);
- }
- return status;
- }
- }
- return b3.SUCCESS;
- }
- b3.MemSequence = MemSequence;
- })();/**
- * MemPriority
- *
- * Copyright (c) 2014 Renato de Pontes Pereira.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- **/
- /**
- * @module Behavior3JS
- **/
- // namespace:
- //this.b3 = this.b3 || {};
- (function() {
- "use strict";
- /**
- * MemPriority is similar to Priority node, but when a child returns a
- * `RUNNING` state, its index is recorded and in the next tick the, MemPriority
- * calls the child recorded directly, without calling previous children again.
- *
- * @class MemPriority
- * @extends Composite
- **/
- var MemPriority = b3.Class(b3.Composite);
- var p = MemPriority.prototype;
- /**
- * Node name. Default to `MemPriority`.
- *
- * @property name
- * @type {String}
- * @readonly
- **/
- p.name = 'MemPriority';
- /**
- * Open method.
- *
- * @method open
- * @param {b3.Tick} tick A tick instance.
- **/
- p.open = function(tick) {
- tick.blackboard.set('runningChild', 0, tick.tree.id, this.id);
- }
- /**
- * Tick method.
- *
- * @method tick
- * @param {b3.Tick} tick A tick instance.
- * @returns {Constant} A state constant.
- **/
- p.tick = function(tick) {
- var child = tick.blackboard.get('runningChild', tick.tree.id, this.id);
- for (var i=child; i<this.children.length; i++) {
- var status = this.children[i]._execute(tick);
- if (status !== b3.FAILURE) {
- if (status === b3.RUNNING) {
- tick.blackboard.set('runningChild', i, tick.tree.id, this.id);
- }
- return status;
- }
- }
- return b3.FAILURE;
- }
- b3.MemPriority = MemPriority;
- })();/**
- * Inverter
- *
- * Copyright (c) 2014 Renato de Pontes Pereira.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- **/
- /**
- * @module Behavior3JS
- **/
- // namespace:
- //this.b3 = this.b3 || {};
- (function() {
- "use strict";
- /**
- * The Inverter decorator inverts the result of the child, returning `SUCCESS`
- * for `FAILURE` and `FAILURE` for `SUCCESS`.
- *
- * @class Inverter
- * @extends Decorator
- **/
- var Inverter = b3.Class(b3.Decorator);
- var p = Inverter.prototype;
- /**
- * Node name. Default to `Inverter`.
- *
- * @property name
- * @type {String}
- * @readonly
- **/
- p.name = 'Inverter';
- /**
- * Tick method.
- *
- * @method tick
- * @param {Tick} tick A tick instance.
- * @returns {Constant} A state constant.
- **/
- p.tick = function(tick) {
- if (!this.child) {
- return b3.ERROR;
- }
- var status = this.child._execute(tick);
- if (status == b3.SUCCESS)
- status = b3.FAILURE;
- else if (status == b3.FAILURE)
- status = b3.SUCCESS;
- return status;
- };
- b3.Inverter = Inverter;
- })();/**
- * Limiter
- *
- * Copyright (c) 2014 Renato de Pontes Pereira.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- **/
- /**
- * @module Behavior3JS
- **/
- // namespace:
- //this.b3 = this.b3 || {};
- (function() {
- "use strict";
- /**
- * This decorator limit the number of times its child can be called. After a
- * certain number of times, the Limiter decorator returns `FAILURE` without
- * executing the child.
- *
- * @class Limiter
- * @extends Decorator
- **/
- var Limiter = b3.Class(b3.Decorator);
- var p = Limiter.prototype;
- /**
- * Node name. Default to `Limiter`.
- *
- * @property name
- * @type {String}
- * @readonly
- **/
- p.name = 'Limiter';
- /**
- * Node parameters.
- *
- * @property parameters
- * @type {String}
- * @readonly
- **/
- p.parameters = {'maxLoop': null};
-
- p.__Decorator_initialize = p.initialize;
- /**
- * Initialization method.
- *
- * Settings parameters:
- *
- * - **maxLoop** (*Integer*) Maximum number of repetitions.
- * - **child** (*BaseNode*) The child node.
- *
- * @method initialize
- * @param {Object} settings Object with parameters.
- * @constructor
- **/
- p.initialize = function(settings) {
- settings = settings || {};
- this.__Decorator_initialize(settings);
- if (!settings.maxLoop) {
- throw "maxLoop parameter in Limiter decorator is an obligatory " +
- "parameter";
- }
- this.maxLoop = settings.maxLoop;
- }
- /**
- * Open method.
- *
- * @method open
- * @param {Tick} tick A tick instance.
- **/
- p.open = function(tick) {
- //[20170319]# 修复limiter因为返回success或failure而重置i
- var i = tick.blackboard.get('i',tick.tree.id, this.id);
- if(!i){
- tick.blackboard.set('i', 0, tick.tree.id, this.id);
- }
- }
- /**
- * Tick method.
- *
- * @method tick
- * @param {Tick} tick A tick instance.
- * @returns {Constant} A state constant.
- **/
- p.tick = function(tick) {
- if (!this.child) {
- return b3.ERROR;
- }
- var i = tick.blackboard.get('i', tick.tree.id, this.id);
- if (i < this.maxLoop) {
- var status = this.child._execute(tick);
- if (status == b3.SUCCESS || status == b3.FAILURE)
- tick.blackboard.set('i', i+1, tick.tree.id, this.id);
-
- return status;
- }
- return b3.FAILURE;
- }
- b3.Limiter = Limiter;
- })();/**
- * MaxTime
- *
- * Copyright (c) 2014 Renato de Pontes Pereira.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- **/
- /**
- * @module Behavior3JS
- **/
- // namespace:
- //this.b3 = this.b3 || {};
- (function() {
- "use strict";
- /**
- * The MaxTime decorator limits the maximum time the node child can execute.
- * Notice that it does not interrupt the execution itself (i.e., the child must
- * be non-preemptive), it only interrupts the node after a `RUNNING` status.
- *
- * @class MaxTime
- * @extends Decorator
- **/
- var MaxTime = b3.Class(b3.Decorator);
- var p = MaxTime.prototype;
- /**
- * Node name. Default to `MaxTime`.
- *
- * @property name
- * @type {String}
- * @readonly
- **/
- p.name = 'MaxTime';
- /**
- * Node title. Default to `Max Time`.
- *
- * @property title
- * @type {String}
- * @readonly
- **/
- p.title = 'Max Time';
- /**
- * Node parameters.
- *
- * @property parameters
- * @type {String}
- * @readonly
- **/
- p.parameters = {'maxTime': null};
- p.__Decorator_initialize = p.initialize;
- /**
- * Initialization method.
- *
- * Settings parameters:
- *
- * - **maxTime** (*Integer*) Maximum time a child can execute.
- * - **child** (*BaseNode*) The child node.
- *
- * @method initialize
- * @param {Object} settings Object with parameters.
- * @constructor
- **/
- p.initialize = function(settings) {
- settings = settings || {};
- this.__Decorator_initialize(settings);
- if (!settings.maxTime) {
- throw "maxTime parameter in MaxTime decorator is an obligatory " +
- "parameter";
- }
- this.maxTime = settings.maxTime;
- };
- /**
- * Open method.
- *
- * @method open
- * @param {Tick} tick A tick instance.
- **/
- p.open = function(tick) {
- var startTime = (new Date()).getTime();
- tick.blackboard.set('startTime', startTime, tick.tree.id, this.id);
- };
-
- /**
- * Tick method.
- *
- * @method tick
- * @param {Tick} tick A tick instance.
- * @returns {Constant} A state constant.
- **/
- p.tick = function(tick) {
- if (!this.child) {
- return b3.ERROR;
- }
-
- var currTime = (new Date()).getTime();
- var startTime = tick.blackboard.get('startTime', tick.tree.id, this.id);
-
- var status = this.child._execute(tick);
- if (currTime - startTime > this.maxTime) {
- return b3.FAILURE;
- }
-
- return status;
- };
- b3.MaxTime = MaxTime;
- })();/**
- * Repeater
- *
- * Copyright (c) 2014 Renato de Pontes Pereira.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- **/
- /**
- * @module Behavior3JS
- **/
- // namespace:
- //this.b3 = this.b3 || {};
- (function() {
- "use strict";
- /**
- * Repeater is a decorator that repeats the tick signal until the child node
- * return `RUNNING` or `ERROR`. Optionally, a maximum number of repetitions
- * can be defined.
- *
- * @class Repeater
- * @extends Decorator
- **/
- var Repeater = b3.Class(b3.Decorator);
- var p = Repeater.prototype;
- /**
- * Node name. Default to `Repeater`.
- *
- * @property name
- * @type {String}
- * @readonly
- **/
- p.name = 'Repeater';
- /**
- * Node parameters.
- *
- * @property parameters
- * @type {String}
- * @readonly
- **/
- p.parameters = {'maxLoop': -1};
- p.__Decorator_initialize = p.initialize;
- /**
- * Initialization method.
- *
- * Settings parameters:
- *
- * - **maxLoop** (*Integer*) Maximum number of repetitions. Default to -1
- * (infinite).
- * - **child** (*BaseNode*) The child node.
- *
- * @method initialize
- * @param {Object} settings Object with parameters.
- * @constructor
- **/
- p.initialize = function(settings) {
- settings = settings || {};
- this.__Decorator_initialize(settings);
- this.maxLoop = settings.maxLoop || -1;
- };
- /**
- * Open method.
- *
- * @method open
- * @param {Tick} tick A tick instance.
- **/
- p.open = function(tick) {
- tick.blackboard.set('i', 0, tick.tree.id, this.id);
- };
- /**
- * Tick method.
- *
- * @method tick
- * @param {Tick} tick A tick instance.
- **/
- p.tick = function(tick) {
- if (!this.child) {
- return b3.ERROR;
- }
- var i = tick.blackboard.get('i', tick.tree.id, this.id);
- var status = b3.SUCCESS;
- while (this.maxLoop < 0 || i < this.maxLoop) {
- status = this.child._execute(tick);
- if (status == b3.SUCCESS || status == b3.FAILURE)
- i++;
- else
- break;
- }
- i = tick.blackboard.set('i', i, tick.tree.id, this.id);
- return status;
- };
- b3.Repeater = Repeater;
- })();/**
- * RepeatUntilFailure
- *
- * Copyright (c) 2014 Renato de Pontes Pereira.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- **/
- /**
- * @module Behavior3JS
- **/
- // namespace:
- //this.b3 = this.b3 || {};
- (function() {
- "use strict";
- /**
- * RepeatUntilFailure is a decorator that repeats the tick signal until the
- * node child returns `FAILURE`, `RUNNING` or `ERROR`. Optionally, a maximum
- * number of repetitions can be defined.
- *
- * @class RepeatUntilFailure
- * @extends Decorator
- **/
- var RepeatUntilFailure = b3.Class(b3.Decorator);
- var p = RepeatUntilFailure.prototype;
- /**
- * Node name. Default to `RepeatUntilFailure`.
- *
- * @property name
- * @type {String}
- * @readonly
- **/
- p.name = 'RepeatUntilFailure';
- /**
- * Node title. Default to `Repeat Until Failure`.
- *
- * @property title
- * @type {String}
- * @readonly
- **/
- p.title = 'Repeat Until Failure';
- /**
- * Node parameters.
- *
- * @property parameters
- * @type {String}
- * @readonly
- **/
- p.parameters = {'maxLoop': -1};
- p.__Decorator_initialize = p.initialize;
- /**
- * Initialization method.
- *
- * Settings parameters:
- *
- * - **maxLoop** (*Integer*) Maximum number of repetitions. Default to -1
- * (infinite).
- * - **child** (*BaseNode*) The child node.
- *
- * @method initialize
- * @param {Object} settings Object with parameters.
- * @constructor
- **/
- p.initialize = function(settings) {
- settings = settings || {};
- this.__Decorator_initialize(settings);
- this.maxLoop = settings.maxLoop || -1;
- }
- /**
- * Open method.
- *
- * @method open
- * @param {Tick} tick A tick instance.
- **/
- p.open = function(tick) {
- tick.blackboard.set('i', 0, tick.tree.id, this.id);
- }
- /**
- * Tick method.
- *
- * @method tick
- * @param {Tick} tick A tick instance.
- * @returns {Constant} A state constant.
- **/
- p.tick = function(tick) {
- if (!this.child) {
- return b3.ERROR;
- }
- var i = tick.blackboard.get('i', tick.tree.id, this.id);
- while (this.maxLoop < 0 || i < this.maxLoop) {
- var status = this.child._execute(tick);
- if (status == b3.SUCCESS)
- i++;
- else
- break;
- }
- var i = tick.blackboard.set('i', i, tick.tree.id, this.id);
- return status;
- }
- b3.RepeatUntilFailure = RepeatUntilFailure;
- })();/**
- * RepeatUntilSuccess
- *
- * Copyright (c) 2014 Renato de Pontes Pereira.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- **/
- /**
- * @module Behavior3JS
- **/
- // namespace:
- //this.b3 = this.b3 || {};
- (function() {
- "use strict";
- /**
- * RepeatUntilSuccess is a decorator that repeats the tick signal until the
- * node child returns `SUCCESS`, `RUNNING` or `ERROR`. Optionally, a maximum
- * number of repetitions can be defined.
- *
- * @class RepeatUntilSuccess
- * @extends Decorator
- **/
- var RepeatUntilSuccess = b3.Class(b3.Decorator);
- var p = RepeatUntilSuccess.prototype;
- /**
- * Node name. Default to `RepeatUntilSuccess`.
- *
- * @property name
- * @type {String}
- * @readonly
- **/
- p.name = 'RepeatUntilSuccess';
- /**
- * Node title. Default to `Repeat Until Success`.
- *
- * @property title
- * @type {String}
- * @readonly
- **/
- p.title = 'Repeat Until Success';
-
- /**
- * Node parameters.
- *
- * @property parameters
- * @type {String}
- * @readonly
- **/
- p.parameters = {'maxLoop': -1};
-
- p.__Decorator_initialize = p.initialize;
- /**
- * Initialization method.
- *
- * Settings parameters:
- *
- * - **maxLoop** (*Integer*) Maximum number of repetitions. Default to -1
- * (infinite).
- * - **child** (*BaseNode*) The child node.
- *
- * @method initialize
- * @param {Object} settings Object with parameters.
- * @constructor
- **/
- p.initialize = function(settings) {
- settings = settings || {};
- this.__Decorator_initialize(settings);
- this.maxLoop = settings.maxLoop || -1;
- }
- /**
- * Open method.
- *
- * @method open
- * @param {Tick} tick A tick instance.
- **/
- p.open = function(tick) {
- tick.blackboard.set('i', 0, tick.tree.id, this.id);
- }
- /**
- * Tick method.
- *
- * @method tick
- * @param {Tick} tick A tick instance.
- * @returns {Constant} A state constant.
- **/
- p.tick = function(tick) {
- if (!this.child) {
- return b3.ERROR;
- }
- var i = tick.blackboard.get('i', tick.tree.id, this.id);
- while (this.maxLoop < 0 || i < this.maxLoop) {
- var status = this.child._execute(tick);
- if (status == b3.FAILURE)
- i++;
- else
- break;
- }
- var i = tick.blackboard.set('i', i, tick.tree.id, this.id);
- return status;
- }
- b3.RepeatUntilSuccess = RepeatUntilSuccess;
- })();/**
- * Error
- *
- * Copyright (c) 2014 Renato de Pontes Pereira.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- **/
- /**
- * @module Behavior3JS
- **/
- // namespace:
- //this.b3 = this.b3 || {};
- (function() {
- "use strict";
- /**
- * This action node returns `ERROR` always.
- *
- * @class Error
- * @extends Action
- **/
- var Error = b3.Class(b3.Action);
- var p = Error.prototype;
- /**
- * Node name. Default to `Error`.
- *
- * @property name
- * @type {String}
- * @readonly
- **/
- p.name = 'Error';
- /**
- * Tick method.
- *
- * @method tick
- * @param {b3.Tick} tick A tick instance.
- * @returns {Constant} Always return `b3.ERROR`.
- **/
- p.tick = function(tick) {
- return b3.ERROR;
- }
- b3.Error = Error;
- })();/**
- * Failer
- *
- * Copyright (c) 2014 Renato de Pontes Pereira.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- **/
- /**
- * @module Behavior3JS
- **/
- // namespace:
- //this.b3 = this.b3 || {};
- (function() {
- "use strict";
- /**
- * This action node returns `FAILURE` always.
- *
- * @class Failer
- * @extends Action
- **/
- var Failer = b3.Class(b3.Action);
- var p = Failer.prototype;
- /**
- * Node name. Default to `Failer`.
- *
- * @property name
- * @type {String}
- * @readonly
- **/
- p.name = 'Failer';
- /**
- * Tick method.
- *
- * @method tick
- * @param {b3.Tick} tick A tick instance.
- * @returns {Constant} Always return `b3.FAILURE`.
- **/
- p.tick = function(tick) {
- return b3.FAILURE;
- }
- b3.Failer = Failer;
- })();/**
- * Runner
- *
- * Copyright (c) 2014 Renato de Pontes Pereira.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- **/
- /**
- * @module Behavior3JS
- **/
- // namespace:
- //this.b3 = this.b3 || {};
- (function() {
- "use strict";
- /**
- * This action node returns RUNNING always.
- *
- * @class Runner
- * @extends Action
- **/
- var Runner = b3.Class(b3.Action);
- var p = Runner.prototype;
- /**
- * Node name. Default to `Runner`.
- *
- * @property name
- * @type {String}
- * @readonly
- **/
- p.name = 'Runner';
- /**
- * Tick method.
- *
- * @method tick
- * @param {b3.Tick} tick A tick instance.
- * @returns {Constant} Always return `b3.RUNNING`.
- **/
- p.tick = function(tick) {
- return b3.RUNNING;
- }
- b3.Runner = Runner;
- })();/**
- * Succeeder
- *
- * Copyright (c) 2014 Renato de Pontes Pereira.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- **/
- /**
- * @module Behavior3JS
- **/
- // namespace:
- //this.b3 = this.b3 || {};
- (function() {
- "use strict";
- /**
- * This action node returns `SUCCESS` always.
- *
- * @class Succeeder
- * @extends Action
- **/
- var Succeeder = b3.Class(b3.Action);
- var p = Succeeder.prototype;
- /**
- * Node name. Default to `Succeeder`.
- *
- * @property name
- * @type String
- * @readonly
- **/
- p.name = 'Succeeder';
- /**
- * Tick method.
- *
- * @method tick
- * @param {b3.Tick} tick A tick instance.
- * @returns {Constant} Always return `b3.SUCCESS`.
- **/
- p.tick = function(tick) {
- return b3.SUCCESS;
- }
- b3.Succeeder = Succeeder;
- })();/**
- * Wait
- *
- * Copyright (c) 2014 Renato de Pontes Pereira.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- **/
- /**
- * @module Behavior3JS
- **/
- // namespace:
- //this.b3 = this.b3 || {};
- (function() {
- "use strict";
- /**
- * Wait a few seconds.
- *
- * @class Wait
- * @extends Action
- **/
- var Wait = b3.Class(b3.Action);
- var p = Wait.prototype;
-
- /**
- * Node name. Default to `Wait`.
- *
- * @property name
- * @type {String}
- * @readonly
- **/
- p.name = 'Wait';
- /**
- * Node parameters.
- *
- * @property parameters
- * @type {String}
- * @readonly
- **/
- p.parameters = {'milliseconds': 0};
- p.__Action_initialize = p.initialize;
- /**
- * Initialization method.
- *
- * Settings parameters:
- *
- * - **milliseconds** (*Integer*) Maximum time, in milliseconds, a child
- * can execute.
- *
- * @method initialize
- * @param {Object} settings Object with parameters.
- * @constructor
- **/
- p.initialize = function(settings) {
- settings = settings || {};
- this.__Action_initialize();
- this.endTime = settings.milliseconds || 0;
- }
- /**
- * Open method.
- *
- * @method open
- * @param {Tick} tick A tick instance.
- **/
- p.open = function(tick) {
- var startTime = (new Date()).getTime();
- tick.blackboard.set('startTime', startTime, tick.tree.id, this.id);
- }
- /**
- * Tick method.
- *
- * @method tick
- * @param {Tick} tick A tick instance.
- * @returns {Constant} A state constant.
- **/
- p.tick = function(tick) {
- var currTime = (new Date()).getTime();
- var startTime = tick.blackboard.get('startTime', tick.tree.id, this.id);
-
- if (currTime - startTime > this.endTime) {
- return b3.SUCCESS;
- }
-
- return b3.RUNNING;
- }
- b3.Wait = Wait;
- })();
- module.exports = b3;
|