/***************************************************************************************** * Function Name: StopWalking * Description: This function makes the walking stops. if the x axis speed is over 20 * than decrease the speed to 20 and then stop the walking *****************************************************************************************/ void WalkingAndActions::StopWalking() { //int counter=0; //for(int i = 0; i < 1; i++) //{ #ifdef DEBUG_STOP_WALKING cout << "WalkingAndActions::StopWalking()\n"; #endif //check if the robot is making any action, if so throw exception if( IsActionOnGoing() == true ) { #ifdef DEBUG_STOP_WALKING cout << "[StopWalking]: Action is on going...\n"; #endif return; //throw "robot is in action mode"; } #ifdef DEBUG_STOP_WALKING cout << "[StopWalking]: before StopThreadRunning\n"; #endif StopThreadRunning(); #ifdef DEBUG_STOP_WALKING cout << "[StopWalking]: after StopThreadRunning, IsWalking == "<< IsWalking() << "\n"; #endif //no need to stop walking if the robot is not walking if( IsWalking() == true ) { #ifdef DEBUG_STOP_WALKING cout << "[StopWalking]: Walking is still on...\n"; #endif //if robot is in running mode and x_axis speed is over 10, the robot should decrease his speed //before stopping immediately so it won't fall while( m_walking->X_MOVE_AMPLITUDE > 10 ) { m_walking->X_MOVE_AMPLITUDE -= 10; //sleep for 100 ms usleep(100*1000); } #ifdef DEBUG_STOP_WALKING cout << "[StopWalking]: Walking is being stopped...\n"; #endif m_walking->Stop(); //wait until the motion is stopped while( IsWalking() == true ) { usleep(8*1000); } #ifdef DEBUG_STOP_WALKING cout << "[StopWalking]: Walking has been stopped.\n"; #endif //} } }
void EnergyReceiver::InitLevel() { if(IsWalking() && !EditorUtils::editor) { //Собираем точки привязки Gadgets::snapGadgets.FindSnap(GetIndex(), _shapElements); } // Под приёмниками энергии не может быть фишек или cтен. // Функция делает ячейки fake и явно задаёт нулевой уровень Game::Square *sq = GameSettings::gamefield[GetIndex()]; if(!Game::isSquare(sq) ) { sq = Game::GetValidSquare(GetIndex().x, GetIndex().y); } sq->SetFake(true); sq->SetWall(0); _timerForRunChipFall = -1.f; _crystalTimeScale = 0.6f; _uid = utils::lexical_cast(UID_NEXT++); ReleaseEffects(); InitEffects(); }
void CInstanceBase::NEW_Attack(float fDirRot) { if (IsDead()) return; if (IsStun()) return; if (IsKnockDown()) return; if (IsUsingSkill()) return; if (IsWalking()) EndWalking(); m_isGoing = FALSE; if (IsPoly()) { InputNormalAttack(fDirRot); } else { if (m_kHorse.IsMounting()) { InputComboAttack(fDirRot); } else { InputComboAttack(fDirRot); } } }
void C_HL2MP_Player::HandleSpeedChanges( void ) { int buttonsChanged = m_afButtonPressed | m_afButtonReleased; if( buttonsChanged & IN_SPEED ) { // The state of the sprint/run button has changed. if ( IsSuitEquipped() ) { if ( !(m_afButtonPressed & IN_SPEED) && IsSprinting() ) { StopSprinting(); } else if ( (m_afButtonPressed & IN_SPEED) && !IsSprinting() ) { if ( CanSprint() ) { StartSprinting(); } else { // Reset key, so it will be activated post whatever is suppressing it. m_nButtons &= ~IN_SPEED; } } } } else if( buttonsChanged & IN_WALK ) { if ( IsSuitEquipped() ) { // The state of the WALK button has changed. if( IsWalking() && !(m_afButtonPressed & IN_WALK) ) { StopWalking(); } else if( !IsWalking() && !IsSprinting() && (m_afButtonPressed & IN_WALK) && !(m_nButtons & IN_DUCK) ) { StartWalking(); } } } if ( IsSuitEquipped() && m_fIsWalking && !(m_nButtons & IN_WALK) ) StopWalking(); }
bool CInstanceBase::NEW_UseSkill(UINT uSkill, UINT uMot, UINT uMotLoopCount, bool isMovingSkill) { if (IsDead()) return false; if (IsStun()) return false; if (IsKnockDown()) return false; if (isMovingSkill) { if (!IsWalking()) StartWalking(); m_isGoing = TRUE; } else { if (IsWalking()) EndWalking(); m_isGoing = FALSE; } float fCurRot=m_GraphicThingInstance.GetTargetRotation(); SetAdvancingRotation(fCurRot); m_GraphicThingInstance.InterceptOnceMotion(CRaceMotionData::NAME_SKILL + uMot, 0.1f, uSkill, 1.0f); m_GraphicThingInstance.__OnUseSkill(uMot, uMotLoopCount, isMovingSkill); if (uMotLoopCount > 0) m_GraphicThingInstance.SetMotionLoopCount(uMotLoopCount); return true; }
void C_HL2MP_Player::HandleSpeedChanges( void ) { int buttonsChanged = m_afButtonPressed | m_afButtonReleased; if( buttonsChanged & IN_WALK ) { if ( IsSuitEquipped() ) { // The state of the WALK button has changed. if( IsWalking() && !(m_afButtonPressed & IN_WALK) ) { StopWalking(); } else if( !IsWalking() && (m_afButtonPressed & IN_WALK) && !(m_nButtons & IN_DUCK) ) { StartWalking(); } } } if ( IsSuitEquipped() && m_fIsWalking && !(m_nButtons & IN_WALK) ) StopWalking(); }
void C_HL2MP_Player::HandleSpeedChanges( void ) { bool bCanSprint = CanSprint(); bool bIsSprinting = IsSprinting(); bool bWantSprint = (bCanSprint && IsSuitEquipped() && (m_nButtons & IN_SPEED)); if (bIsSprinting != bWantSprint) { // If someone wants to sprint, make sure they've pressed the button to do so. We want to prevent the // case where a player can hold down the sprint key and burn tiny bursts of sprint as the suit recharges // We want a full debounce of the key to resume sprinting after the suit is completely drained if (bWantSprint) { StartSprinting(); } else { StopSprinting(); } } bool bIsWalking = IsWalking(); // have suit, pressing button, not sprinting or ducking bool bWantWalking; if (IsSuitEquipped()) { bWantWalking = (m_nButtons & IN_WALK) && !IsSprinting() && !(m_nButtons & IN_DUCK); } else { bWantWalking = true; } if (bIsWalking != bWantWalking) { if (bWantWalking) { StartWalking(); } else { StopWalking(); } } }
void CSDKPlayer::HandleSpeedChanges( void ) { bool bIsWalking = IsWalking(); bool bWantWalking; bWantWalking = true; if( bIsWalking != bWantWalking ) { if ( bWantWalking ) { StartWalking(); } else { StopWalking(); } } }
void EnergyReceiver::DrawUp() { if(!IsCellDraw()) { return; } Render::device.PushMatrix(); Render::device.MatrixTranslate(GetIndex()*GameSettings::SQUARE_SIDE); Game::MatrixSquareScale(); if(_crystalAnim.get()) { if(_timeAppear < 1) { Render::device.BeginClipping(IRect(-10, 4, 20, 20), ClippingMode::BOTTOM); } ////Хитрости для постепенного появления кристала из отверстия //FRect frect_crystal = FRect(0.f, 1.f, 0.f, 1.f); //FRect rect_crystal = FRect(0.f, _crystalAnim->GetOrigWidth(), 0.f, _crystalAnim->GetOrigHeight()); //rect_crystal.MoveBy(FPoint(17.f, 17.f + _fly_offset_y)); //FRect cut_rect = rect_crystal.CutBy(FRect(0.f, GameSettings::SQUARE_SIDEF, 5.5f, 200.f)); //frect_crystal.yStart = 1.f - cut_rect.Height() / rect_crystal.Height(); //rect_crystal = cut_rect; float alpha_cristall = math::clamp(0.f, 1.f, 1 + _timerForAppearOrder); if(_hideByThief) { //rect_crystal.yEnd = math::lerp(rect_crystal.yEnd, rect_crystal.yStart, _hideByThiefTime); //frect_crystal.yEnd = math::lerp(frect_crystal.yEnd, frect_crystal.yStart, _hideByThiefTime); alpha_cristall *= math::clamp(0.f, 1.f, 1 - (_hideByThiefTime - 0.5f)/0.2f); } Render::BeginAlphaMul(alpha_cristall); { if( IsWalking() ) { Render::BeginColor( Color(100, 255, 100) ); } Render::device.PushMatrix(); Render::device.MatrixTranslate(CRYSTAL_POS_ANIM_ON_SQUARE + FPoint(0.f, _fly_offset_y)); _crystalAnim->Draw(); Render::device.PopMatrix(); //_crystalAnim->Bind(); //Render::DrawRect(rect_crystal.MovedBy(CRYSTAL_POS_ANIM_ON_SQUARE), frect_crystal); if( IsWalking() ) { Render::EndColor(); } } Render::EndAlphaMul(); if(_timeAppear < 1) { Render::device.EndClipping(); } } Render::BeginAlphaMul(math::clamp(0.f, 1.f, 1 + _timerForAppearOrder)); Render::device.PushMatrix(); _effContUpStatic.Draw(); Render::device.MatrixTranslate(math::Vector3(0.f, _fly_offset_y , 0.f)); _effContUp.Draw(); Render::device.PopMatrix(); Render::EndAlphaMul(); FPoint offset(0.f, 0.f); if(_order && _order->IsReadyToBreak()) { offset.x += math::sin(_localTime*30.f); } if(_state != ER_INIT) { _effectCellCont.Draw(); if(IsOrdered()) { _order->Draw(offset.Rounded()); } } Render::device.PopMatrix(); }
/***************************************************************************************** * Method Name: StartAction * Description: This method gets an action and execute it * Arguments: action - action to perform *****************************************************************************************/ void WalkingAndActions::StartAction(Actions_t action) { #ifdef DEBUG_START_ACTION cout << "[StartAction]: Action type: " << action << "\n"; #endif #ifdef DEBUG_START_ACTION printf("[StartAction]: Stopping StartWalking thread...\n"); #endif StopThreadRunning(); #ifdef DEBUG_START_ACTION printf("[StartAction]: StartWalking thread stopped.\n"); #endif sigset_t mask; sigemptyset(&mask); sigaddset(&mask, SIGINT); sigaddset(&mask, SIGUSR2); bool isSigmaskSuccess = pthread_sigmask(SIG_BLOCK, &mask, NULL); #ifdef DEBUG_START_ACTION if(isSigmaskSuccess) { printf("[StartAction]: Sigmask failed\n"); } else { printf("[StartAction]: Sigmask success\n"); } #endif pthread_mutex_lock(& m_walkingAndActionsMutex); #ifdef DEBUG_START_ACTION printf("[StartAction]: Mutex has been locked. \n"); #endif //check if in walking mode if( IsWalking() == true ) { #ifdef DEBUG_START_ACTION printf("[StartAction]: The robot is walking - StopWalking...\n"); #endif StopWalking(); #ifdef DEBUG_START_ACTION printf("[StartAction]: The robot has stopped walking.\n"); #endif } while( IsActionOnGoing() == true ) { #ifdef DEBUG_START_ACTION printf("[StartAction]: An action is ongoing...\n"); #endif usleep(8000); } #ifdef DEBUG_START_ACTION printf("[StartAction]: Walking and actions has been stopped. \n"); #endif //action module take control of the body without head m_action->m_Joint.SetEnableBodyWithoutHead(true,true); //action module start the action #ifdef DEBUG_START_ACTION printf("[StartAction]: Starting the action...\n"); #endif m_action->Start( (int)action ); #ifdef DEBUG_START_ACTION cout << "[StartAction]: Check if action is still running...\n"; #endif while(m_action->IsRunning()) { usleep(8000); } #ifdef DEBUG_START_ACTION cout << "[StartAction]: Action: " << (int)action << " has been done\n"; #endif ResetWalkingParams(); #ifdef DEBUG_START_ACTION cout << "[StartAction]: Walking Params has been reseted\n"; #endif pthread_mutex_unlock(& m_walkingAndActionsMutex); #ifdef DEBUG_START_ACTION printf("[StartAction]: Mutex has been unlocked. \n"); #endif pthread_sigmask(SIG_UNBLOCK, &mask, NULL); }
/***************************************************************************************** * Function Name: ChangeMotionValue * Description: This function increases the value of a chosen axis * if the new value exceeds the maximum value than maximum value is taken * (same for minimum) * Arguments: motionArg - chosen axis to change the value to * increaseDecreaseSpeedBy - increase(+) or decrease (-) the speed by * Return Values: Return the value of the chosen axis *****************************************************************************************/ double WalkingAndActions::ChangeMotionValue(MotionArgs_t motionArg, double increaseDecreaseSpeedBy) { double *value; double max; double min; //check if the the robot is in motion, if not throw exception if (IsActionOnGoing() == true) { // throw "robot is not in motion"; return 0; } if(IsWalking() == false) { StartWalking(); } switch(motionArg) { case X_SPEED: //get the pointer to m_walking->X_MOVE_AMPLITUDE value = &(m_walking->X_MOVE_AMPLITUDE); //get the pointer to m_maxXSpeed max = m_maxXSpeed; //get the pointer to m_minXSpeed min = m_minXSpeed; break; case Y_SPEED: //get the pointer to m_walking->Y_MOVE_AMPLITUDE value = &(m_walking->Y_MOVE_AMPLITUDE); //get the pointer to m_maxLeftYawSpeed max = m_maxYSpeed; //get the pointer to m_maxRightYawSpeed min = m_minYSpeed; break; case ROTATION_ANGLE: //get the pointer to m_walking->Y_MOVE_AMPLITUDE value = &(m_walking->A_MOVE_AMPLITUDE); //get the pointer to m_maxLeftTurningAngle max = m_maxLeftTurningAngle; //get the pointer to m_maxRightTurningAngle min = m_maxRightTurningAngle; break; default: //if no such walking attribute throw exception throw "no such walking attribute"; break; } //if the new target value is about to cross the max value than insert the max in the vaule if( ( *value + increaseDecreaseSpeedBy ) > max) { *value = max; } //if the new target value is about to cross the max value than insert the max in the vaule else if( ( *value + increaseDecreaseSpeedBy ) < min) { *value = min; } //else insert calculate new attribute else { *value += increaseDecreaseSpeedBy; } //return the new set attribute return *value; }
/***************************************************************************************** * Function Name: StartWalking * Description: This function starts the walking motion with speed values. if walking already started, * return false. if the arguments of speed values exceeds the max and min values * throw an exception. the function zeros the speeds. * The method change speed as it increases or decreases in steps * Arguments: xSpeed - the x axis speed * ySpeed - the y axis speed * angle - strength of angle turn * Return Values: Return false when walking already started, and True on success *****************************************************************************************/ bool WalkingAndActions::StartWalking(double xSpeed, double ySpeed, double angle) { bool isHipPitchOffsetSet = false; double oldXSpeed = GetMotionValue(X_SPEED); #ifdef DEBUG_WALKING_AND_ACTIONS_EXTENDED_ON printf("[StartWalking]: starting... \n"); #endif sigset_t mask; pthread_sigmask(SIG_BLOCK, &mask, NULL); sigemptyset(&mask); sigaddset(&mask, SIGINT); sigaddset(&mask, SIGUSR2); bool isSigmaskSuccess = pthread_sigmask(SIG_BLOCK, &mask, NULL); #ifdef DEBUG_WALKING_AND_ACTIONS_SIGNAL_ON if(isSigmaskSuccess) { printf("[StartWalking]: Sigmask failed\n"); } else { printf("[StartWalking]: Sigmask success\n"); } #endif pthread_mutex_lock(& m_walkingAndActionsMutex); #ifdef DEBUG_WALKING_AND_ACTIONS_ON printf("[StartWalking]: Mutex locked\n"); #endif //check if the robot is walking, if not start walking. if(IsWalking() == false) { //start the walking. m_walking->Start(); } //cout << "locking mutex in StartwalkingSafe\n"; while( IsActionOnGoing() == true ) { usleep(8000); } //walking enable control of the body m_walking->m_Joint.SetEnableBodyWithoutHead(true,true); //check if the values of the arguments are not exceeding the if (xSpeed < m_minXSpeed) xSpeed=m_minXSpeed; if (xSpeed > m_maxXSpeed) xSpeed=m_maxXSpeed; if (ySpeed < m_minYSpeed) ySpeed=m_minYSpeed; if (ySpeed > m_maxYSpeed) ySpeed=m_maxYSpeed; if (angle < m_maxRightTurningAngle) angle=m_maxRightTurningAngle; if (angle > m_maxLeftTurningAngle) angle=m_maxLeftTurningAngle; if (ySpeed < MAX_SPEED_TO_SLOW_FIRST) { while ( (ySpeed - GetMotionValue(Y_SPEED)) > 0 && m_isThreadRunning) { ChangeMotionValue(Y_SPEED,1); usleep(40*1000); } while ( (ySpeed - GetMotionValue(Y_SPEED)) < 0 && m_isThreadRunning) { ChangeMotionValue(Y_SPEED,-1); usleep(40*1000); } } if (angle < MAX_SPEED_TO_SLOW_FIRST) { while ( (angle - GetMotionValue(ROTATION_ANGLE)) > 0 && m_isThreadRunning) { ChangeMotionValue(ROTATION_ANGLE,1); usleep(40*1000); } while ( (angle - GetMotionValue(ROTATION_ANGLE)) < 0 && m_isThreadRunning) { ChangeMotionValue(ROTATION_ANGLE,-1); usleep(40*1000); } } while ( (xSpeed - GetMotionValue(X_SPEED)) > 10 && m_isThreadRunning) { #ifdef HIP_PITCH_OFFSET_ON if(oldXSpeed <= 0 && xSpeed > 0 && GetMotionValue(X_SPEED) >= 0 && GetMotionValue(X_SPEED) < 3 && m_walkingMode == RUNNING) { m_walking->HIP_PITCH_OFFSET = m_runningHipPitchOffsetForward; isHipPitchOffsetSet = true; } #endif ChangeMotionValue(X_SPEED,3); usleep(100*1000); } while ( (xSpeed - GetMotionValue(X_SPEED)) < -10 && m_isThreadRunning) { #ifdef HIP_PITCH_OFFSET_ON if(oldXSpeed >= 0 && xSpeed < 0 && GetMotionValue(X_SPEED) <= 0 && GetMotionValue(X_SPEED) > -3 && m_walkingMode == RUNNING) { m_walking->HIP_PITCH_OFFSET = m_runningHipPitchOffsetBackward; isHipPitchOffsetSet = true; } #endif ChangeMotionValue(X_SPEED,-3); usleep(100*1000); } #ifdef HIP_PITCH_OFFSET_ON if(oldXSpeed >= 0 && xSpeed < 0 && !isHipPitchOffsetSet && m_walkingMode == RUNNING) { m_walking->HIP_PITCH_OFFSET = m_runningHipPitchOffsetBackward; } if(oldXSpeed <= 0 && xSpeed > 0 && !isHipPitchOffsetSet && m_walkingMode == RUNNING) { m_walking->HIP_PITCH_OFFSET = m_runningHipPitchOffsetForward; } #endif m_walking->X_MOVE_AMPLITUDE = xSpeed; while ( (ySpeed - GetMotionValue(Y_SPEED)) > 0 && m_isThreadRunning) { ChangeMotionValue(Y_SPEED,1); usleep(40*1000); } while ( (ySpeed - GetMotionValue(Y_SPEED)) < 0 && m_isThreadRunning) { ChangeMotionValue(Y_SPEED,-1); usleep(40*1000); } while ( (angle - GetMotionValue(ROTATION_ANGLE)) > 0 && m_isThreadRunning) { ChangeMotionValue(ROTATION_ANGLE,1); usleep(40*1000); } while ( (angle - GetMotionValue(ROTATION_ANGLE)) < 0 && m_isThreadRunning) { ChangeMotionValue(ROTATION_ANGLE,-1); usleep(40*1000); } m_isThreadRunning = false; pthread_mutex_unlock(& m_walkingAndActionsMutex); #ifdef DEBUG_WALKING_AND_ACTIONS_ON printf("[StartWalking]: Mutex unlocked\n"); #endif #ifdef DEBUG_WALKING_AND_ACTIONS_CHANGE_OFFSET cout << "[WalkingAndActions::StartWalking]: HIP_PITCH_OFFSET = " << m_walking->HIP_PITCH_OFFSET << "\n"; #endif isSigmaskSuccess = pthread_sigmask(SIG_UNBLOCK, &mask, NULL); #ifdef DEBUG_WALKING_AND_ACTIONS_SIGNAL_ON if(isSigmaskSuccess) { printf("[StartWalking]: Sigmask failed\n"); } else { printf("[StartWalking]: Sigmask success\n"); } #endif //cout << "leaving StartwalkingSafe\n"; //return success return true; }
// 리턴값 TRUE가 무엇인가가 있다 BOOL CInstanceBase::CheckAdvancing() { #ifdef __MOVIE_MODE__ if (IsMovieMode()) return FALSE; #endif if (!__IsMainInstance() && !IsAttacking()) { if (IsPC() && IsWalking()) { CPythonCharacterManager& rkChrMgr=CPythonCharacterManager::Instance(); for(CPythonCharacterManager::CharacterIterator i = rkChrMgr.CharacterInstanceBegin(); i!=rkChrMgr.CharacterInstanceEnd();++i) { CInstanceBase* pkInstEach=*i; if (pkInstEach==this) continue; if (!pkInstEach->IsDoor()) continue; if (m_GraphicThingInstance.TestActorCollision(pkInstEach->GetGraphicThingInstanceRef())) { BlockMovement(); return true; } } } return FALSE; } if (m_GraphicThingInstance.CanSkipCollision()) { //Tracenf("%x VID %d 충돌 스킵", ELTimer_GetMSec(), GetVirtualID()); return FALSE; } BOOL bUsingSkill = m_GraphicThingInstance.IsUsingSkill(); m_dwAdvActorVID = 0; UINT uCollisionCount=0; CPythonCharacterManager& rkChrMgr=CPythonCharacterManager::Instance(); for(CPythonCharacterManager::CharacterIterator i = rkChrMgr.CharacterInstanceBegin(); i!=rkChrMgr.CharacterInstanceEnd();++i) { CInstanceBase* pkInstEach=*i; if (pkInstEach==this) continue; CActorInstance& rkActorSelf=m_GraphicThingInstance; CActorInstance& rkActorEach=pkInstEach->GetGraphicThingInstanceRef(); //NOTE : Skil을 쓰더라도 Door Type과는 Collision체크 한다. if( bUsingSkill && !rkActorEach.IsDoor() ) continue; // 앞으로 전진할수 있는가? if (rkActorSelf.TestActorCollision(rkActorEach)) { uCollisionCount++; if (uCollisionCount==2) { rkActorSelf.BlockMovement(); return TRUE; } rkActorSelf.AdjustDynamicCollisionMovement(&rkActorEach); if (rkActorSelf.TestActorCollision(rkActorEach)) { rkActorSelf.BlockMovement(); return TRUE; } else { NEW_MoveToDestPixelPositionDirection(NEW_GetDstPixelPositionRef()); } } } // 맵속성 체크 CPythonBackground& rkBG=CPythonBackground::Instance(); const D3DXVECTOR3 & rv3Position = m_GraphicThingInstance.GetPosition(); const D3DXVECTOR3 & rv3MoveDirection = m_GraphicThingInstance.GetMovementVectorRef(); // NOTE : 만약 이동 거리가 크다면 쪼개서 구간 별로 속성을 체크해 본다 // 현재 설정해 놓은 10.0f는 임의의 거리 - [levites] int iStep = int(D3DXVec3Length(&rv3MoveDirection) / 10.0f); D3DXVECTOR3 v3CheckStep = rv3MoveDirection / float(iStep); D3DXVECTOR3 v3CheckPosition = rv3Position; for (int j = 0; j < iStep; ++j) { v3CheckPosition += v3CheckStep; // Check if (rkBG.isAttrOn(v3CheckPosition.x, -v3CheckPosition.y, CTerrainImpl::ATTRIBUTE_BLOCK)) { BlockMovement(); //return TRUE; } } // Check D3DXVECTOR3 v3NextPosition = rv3Position + rv3MoveDirection; if (rkBG.isAttrOn(v3NextPosition.x, -v3NextPosition.y, CTerrainImpl::ATTRIBUTE_BLOCK)) { BlockMovement(); return TRUE; } return FALSE; }