var gdjs;(function(l){const p=new l.Logger("Pathfinding behavior");class f extends l.RuntimeBehavior{constructor(e,s,n){super(e,s,n);this._path=[];this._pathFound=!1;this._speed=0;this._angularSpeed=0;this._distanceOnSegment=0;this._totalSegmentDistance=0;this._currentSegment=0;this._reachedEnd=!1;this._movementAngle=0;this._path===void 0||(this._path.length=0),this._allowDiagonals=s.allowDiagonals,this._acceleration=s.acceleration,this._maxSpeed=s.maxSpeed,this._angularMaxSpeed=s.angularMaxSpeed,this._rotateObject=s.rotateObject,this._angleOffset=s.angleOffset,this._cellWidth=s.cellWidth,this._cellHeight=s.cellHeight,this._gridOffsetX=s.gridOffsetX||0,this._gridOffsetY=s.gridOffsetY||0,this._extraBorder=s.extraBorder,this._smoothingMaxCellGap=s.smoothingMaxCellGap||0,this._manager=l.PathfindingObstaclesManager.getManager(e),this._searchContext=new l.PathfindingRuntimeBehavior.SearchContext(this._manager)}applyBehaviorOverriding(e){return e.allowDiagonals!==void 0&&this.allowDiagonals(e.allowDiagonals),e.acceleration!==void 0&&this.setAcceleration(e.acceleration),e.maxSpeed!==void 0&&this.setMaxSpeed(e.maxSpeed),e.angularMaxSpeed!==void 0&&this.setAngularMaxSpeed(e.angularMaxSpeed),e.rotateObject!==void 0&&this.setRotateObject(e.rotateObject),e.angleOffset!==void 0&&this.setAngleOffset(e.angleOffset),e.cellWidth!==void 0&&this.setCellWidth(e.cellWidth),e.cellHeight!==void 0&&this.setCellHeight(e.cellHeight),e.gridOffsetX!==void 0&&(this._gridOffsetX=e.gridOffsetX),e.gridOffsetY!==void 0&&(this._gridOffsetY=e.gridOffsetY),e.extraBorder!==void 0&&this.setExtraBorder(e.extraBorder),e.smoothingMaxCellGap!==void 0&&(this._smoothingMaxCellGap=e.smoothingMaxCellGap),!0}getNetworkSyncData(e){return{...super.getNetworkSyncData(e),props:{path:this._path,pf:this._pathFound,sp:this._speed,as:this._angularSpeed,cs:this._currentSegment,tss:this._totalSegmentDistance,re:this._reachedEnd,ma:this._movementAngle,dos:this._distanceOnSegment}}}updateFromNetworkSyncData(e,s){super.updateFromNetworkSyncData(e,s);const n=e.props;n.path!==void 0&&(this._path=n.path),n.pf!==void 0&&(this._pathFound=n.pf),n.sp!==void 0&&(this._speed=n.sp),n.as!==void 0&&(this._angularSpeed=n.as),n.cs!==void 0&&n.cs!==this._currentSegment&&(this._currentSegment=n.cs),n.tss!==void 0&&(this._totalSegmentDistance=n.tss),n.re!==void 0&&(this._reachedEnd=n.re),n.ma!==void 0&&(this._movementAngle=n.ma),n.dos!==void 0&&(this._distanceOnSegment=n.dos)}setCellWidth(e){this._cellWidth=e}getCellWidth(){return this._cellWidth}setCellHeight(e){this._cellHeight=e}getCellHeight(){return this._cellHeight}setGridOffsetX(e){this._gridOffsetX=e}getGridOffsetX(){return this._gridOffsetX}setGridOffsetY(e){this._gridOffsetY=e}getGridOffsetY(){return this._gridOffsetY}setAcceleration(e){this._acceleration=e}getAcceleration(){return this._acceleration}setMaxSpeed(e){this._maxSpeed=e}getMaxSpeed(){return this._maxSpeed}setSpeed(e){this._speed=e}getSpeed(){return this._speed}getMovementAngle(){return this._movementAngle}movementAngleIsAround(e,s){return Math.abs(l.evtTools.common.angleDifference(this._movementAngle,e))<=s}setAngularMaxSpeed(e){this._angularMaxSpeed=e}getAngularMaxSpeed(){return this._angularMaxSpeed}setAngleOffset(e){this._angleOffset=e}getAngleOffset(){return this._angleOffset}setExtraBorder(e){this._extraBorder=e}getExtraBorder(){return this._extraBorder}allowDiagonals(e){this._allowDiagonals=e}diagonalsAllowed(){return this._allowDiagonals}setRotateObject(e){this._rotateObject=e}isObjectRotated(){return this._rotateObject}getNodeX(e){return e0){l.pathfinding.simplifyPath(this._path,this._smoothingMaxCellGap*Math.min(this._cellWidth,this._cellHeight),l.PathfindingRuntimeBehavior._smoothingResultVertices,l.PathfindingRuntimeBehavior._smoothingWorkingVertices);let d=this._path;this._path=l.PathfindingRuntimeBehavior._smoothingResultVertices,l.PathfindingRuntimeBehavior._smoothingResultVertices=d}this._enterSegment(0),this._pathFound=!0;return}this._pathFound=!1}_enterSegment(e){if(this._path.length!==0)if(this._currentSegment=e,this._currentSegmentthis._maxSpeed&&(this._speed=this._maxSpeed)),this._angularSpeed=this._angularMaxSpeed,this._distanceOnSegment+=(this._speed+n)/2*s;const t=this._totalSegmentDistance-this._distanceOnSegment;t<=0&&this._currentSegmenta)return console.warn(`No path was found after covering ${a} cells.`),!1;const o=this._openNodes.shift();if(o.open=!1,o.pos[0]==this._destination[0]&&o.pos[1]==this._destination[1])return this._finalNode=o,!0;this._insertNeighbors(o)}return!1}_freeAllNodes(){if(this._nodeCache.length<=32e3){for(const t in this._allNodes)if(this._allNodes.hasOwnProperty(t)){const i=this._allNodes[t];for(const h in i)i.hasOwnProperty(h)&&this._nodeCache.push(i[h])}}this._allNodes=[]}_insertNeighbors(t){this._addOrUpdateNode(t.pos[0]+1,t.pos[1],t,1),this._addOrUpdateNode(t.pos[0]-1,t.pos[1],t,1),this._addOrUpdateNode(t.pos[0],t.pos[1]+1,t,1),this._addOrUpdateNode(t.pos[0],t.pos[1]-1,t,1),this._allowDiagonals&&(this._addOrUpdateNode(t.pos[0]+1,t.pos[1]+1,t,1.414213562),this._addOrUpdateNode(t.pos[0]+1,t.pos[1]-1,t,1.414213562),this._addOrUpdateNode(t.pos[0]-1,t.pos[1]-1,t,1.414213562),this._addOrUpdateNode(t.pos[0]-1,t.pos[1]+1,t,1.414213562))}_getNode(t,i){if(this._allNodes.hasOwnProperty(t)){if(this._allNodes[t].hasOwnProperty(i))return this._allNodes[t][i]}else this._allNodes[t]=[];let h;this._nodeCache.length!==0?(h=this._nodeCache.shift(),h.reinitialize(t,i)):h=new c(t,i);const r=t*this._cellWidth+this._gridOffsetX,a=i*this._cellHeight+this._gridOffsetY;let o=!1;const _=this._cellHeight>this._cellWidth?this._cellHeight*2:this._cellWidth*2;this._obstacles.getAllObstaclesAround(r,a,_,this._closeObstacles);for(let d=0;dh.smallestCost+(h.cost+a.cost)/2*r)){if(a.smallestCost!=-1){for(let o=0;o=a.estimateCost){this._openNodes.splice(o,0,a);break}}}}s.SearchContext=e}(f=l.PathfindingRuntimeBehavior||(l.PathfindingRuntimeBehavior={}))})(gdjs||(gdjs={})); //# sourceMappingURL=pathfindingruntimebehavior.js.map