/******************************************************************************/ #include "stdafx.h" namespace EE{ namespace Game{ /******************************************************************************/ void Chr::actionBreak() // break current action { action=ACTION_NONE; path.clear(); // clear input input.move.zero(); input.turn.zero(); } /******************************************************************************/ Bool Chr::actionMoveTo(C Vec &pos) // set 'move to' action { // break any current action actionBreak(); // try to set new action path_target=pos; if(World.path().find(T.pos(), path_target, path)) // if found a path to the target destination { path.reverseOrder(); action=ACTION_MOVE_TO; // set new action return true; } return false; } /******************************************************************************/ void Chr::actionMoveDir(C Vec &dir) // set 'move to direction' action { // break any current action actionBreak(); // set new action action =ACTION_MOVE_DIR; move_dir=dir.xz(); } /******************************************************************************/ #define ANGLE_INC 10.0f #define DIR_INC 10.0f #define DIR_DEC 4.0f /******************************************************************************/ // set character 'input' according to 'from to' angles and character speeds // returns true - when the character is near the target angle and can proceed moving forward // returns false - if it should stay still and rotate only static Bool InputToAngle(Chr &chr, Flt from, Flt to, Flt turn_speed, Flt desired_speed) { Flt d=AngleDelta(from,to), ad=Abs (d ); if(ad<0.001f)chr.input_turn.x=chr.input.turn.x=0;else { Flt div=turn_speed*Time.d(); if( div>EPS) { Flt can =22*Time.d(), max =Lerp(0.1f, 3.0f, Mid((ad-DegToRad(5))/DegToRad(40), 0.0f, 1.0f)), want_d=d/div, d =want_d-chr.input_turn.x; Clamp(d , -can, can); chr.input_turn.x+=d; Clamp(chr.input_turn.x, -max, max); chr.input.turn.x=Sign(chr.input_turn.x); } } Flt limit=DegToRad(90); if(desired_speed>EPS)limit/=Max(1, desired_speed/4.1f); if( turn_speed>EPS)limit/=Max(1, turn_speed/3.5f); return ad=1), input.jump); } /******************************************************************************/ }} /******************************************************************************/