📄 basicdash.cpp
字号:
} else { command = TurnToPoint(creator, target, body).getCommand(); mode = CT_TURN; } } else { command = TurnToPoint(creator, target, body).getCommand(); mode = CT_TURN; }}DashNormalGotoPoint::DashNormalGotoPoint(ActionType creator, const Point &target, float distance, const Body &body, float idealBodyDir, float maxDashPower): BasicAction(creator){ float deltaAngle, validDeltaAngle; Vector targetVector; targetVector.setByPoints(body.getPos(), target); deltaAngle = getDeltaAngle(targetVector.getDirection(), body.getBodyDir()); distance = max((float) EPS, distance); validDeltaAngle = arcTan2(distance, targetVector.getMagnitude()); mode = CT_EMPTY; command = NULL; float dashPower = 100; if(body.getStamina() < 2500) dashPower = 80; if(body.getStamina() < 2000) dashPower = 60; if(body.getStamina() < 1500) dashPower = body.getStaminaIncMax(); if(dashPower > maxDashPower) dashPower = maxDashPower; if (fabs(deltaAngle) <= 6/*GOTOPOINTMINDELTAANGLE*/ || fabs(deltaAngle) <= validDeltaAngle) { if (targetVector.getMagnitude() > distance) { command = new DashCommand(creator, dashPower); mode = CT_DASH; } else { command = TurnToAngle(creator, idealBodyDir, body).getCommand(); mode = CT_TURN; } } else { command = TurnToPoint(creator, target, body).getCommand(); mode = CT_TURN; } if (maxDashPower == 0) { if (command == NULL) command = TurnToAngle(creator, idealBodyDir, body).getCommand(); else { delete command; command = TurnToAngle(creator, idealBodyDir, body).getCommand(); } }}Command *DashNormalGotoPoint::getCommand(){ return command;}CommandType DashNormalGotoPoint::getMode(){ return mode;}/*DashFarNormalGotoPoint::DashFarNormalGotoPoint(const Point &target, float distance, Body *body, GotoPointMode mode): BasicAction(), target(target), distance(distance), body(body), mode(mode){}Command *DashFarNormalGotoPoint::getCommand(){ return NULL;}*//*DashClear::DashClear(Ball *ball, Body *body, bool isOpp): BasicAction(), ball(ball), body(body), isOpp(isOpp){ Point kickPoint; float delta; Vector goalVector; LogMaker.Log("Clear."); if (isOpp) { delta = 2.5; if (body.getPosition()->getX() > 0) delta = 2.25; else if (body.getPosition()->getX() > 27) delta = 2;// kickPoint.X = body.getPosition()->getX() + Delta; ////////////////TOF Chasbide// kickPoint.Y = body.getPosition()->getY(); basicActions.Kick.KickToPointVelocity((Point){49,0},delta,body,ball,RSC); } else { if(ball.getVelocity()->getMagnidute() > 2) { if(ball.getAbsVec()->getMagnidute() > .8) { if(body.getPosition()->getY() < 0) { kickPoint.X = 0.00; ////////////////TOF Chasbide kickPoint.Y = 9.00; BasicActions.Kick.kickToPointMaxVelocity(kickPoint,body,ball,RSC); } else { kickPoint.X = 0.00; ////////////////TOF Chasbide kickPoint.Y = -9.00; BasicActions.Kick.kickToPointMaxVelocity(kickPoint,body,ball,RSC); } } else { kickPoint.X = body.getPosition()->getX() + 42; ////////////////TOF Chasbide kickPoint.Y = body.getPosition()->getY(); BasicActions.Kick.kickToPointMaxVelocity(kickPoint,body,ball,RSC); } } else if(ball.getVelocity()->getMagnidute() > .9) { Vector ballVector; ballVector.setByPoints(body.getPosition()->getX(), body.getPosition()->getY(), ball.getPosition()->getX(), ball.getPosition()->getY()); ballVector.setAsPolar(.45, ballVector.Angle); kickPoint.X = body.getPosition()->getX() + ballVector.X; kickPoint.Y = body.getPosition()->getY() + ballVector.Y; BasicActions.Kick.KickToPointArriveVelocity(kickPoint, 0, body, ball, RSC); } else { ///in ke joloye darvaze dar mavaghei, bayad be darvazeban pass bede va hamin joori be jolo shoot nakone ra bayad ba'dan bezaram kickPoint.X = body.getPosition()->getX() + 42; ////////////////TOF Chasbide kickPoint.Y = body.getPosition()->getY(); BasicActions.Kick.KickToPointArriveVelocity(kickPoint, 0, body, ball, RSC); } }}Command *DashClear::getCommand(){ return NULL;}*/FreeKickGotoPoint::FreeKickGotoPoint(ActionType creator, const Point &point, float standDirection, float collisionDistance, const Body &body): BasicAction(creator){ Vector pointVector; Vector standVector; Vector targetVector; Vector goVector; Point targetPoint; float distance; bool intersectFlag = false; command = NULL; #ifdef FREEKICK_GOTO_POINT_LOGLOG << "FKGotoPoint 1targetP : " << point << endl;#endif#ifdef FREEKICK_GOTO_POINT_LOGLOG << "FKGotoPoint coldist : " << collisionDistance << endl;#endif standVector.setAsPolar(body.getSize() + collisionDistance + 0.1, standDirection + 180);#ifdef FREEKICK_GOTO_POINT_LOGLOG << "FKGotoPoint 2standV : " << standVector << endl;#endif targetPoint = (Vector&)point + standVector;#ifdef FREEKICK_GOTO_POINT_LOGLOG << "FKGotoPoint 2targetP : " << targetPoint << endl;#endif pointVector.setByPoints(body.getPos(), point); targetVector.setByPoints(body.getPos(), targetPoint);#ifdef FREEKICK_GOTO_POINT_LOGLOG << "FKGotoPoint 1targetV : " << targetVector << endl;#endif Line targetLine; targetLine.setByPoints(body.getPos(), targetPoint); distance = targetLine.getPointDist(point);#ifdef FREEKICK_GOTO_POINT_LOGLOG << "FKGotoPoint distance : " << distance << endl;#endif if (distance < body.getSize() + collisionDistance + 0.01 && targetVector.getMagnitude() > standVector.getMagnitude() && pointVector.getMagnitude() < targetVector.getMagnitude()) { // intersect#ifdef FREEKICK_GOTO_POINT_LOGLOG << "FKGotoPoint intersect " << endl;#endif float angleDiff; intersectFlag = true; angleDiff = normalizeAngle( absoluteAngle(standVector.getDirection()) - absoluteAngle(180 + pointVector.getDirection())); standVector.setAsPolar(body.getSize() + collisionDistance + 2.0, pointVector.getDirection() + (angleDiff / 2) + 180); targetPoint = (Vector&)point + standVector; targetVector.setByPoints(body.getPos(), targetPoint); } else { } goVector = targetVector; #ifdef FREEKICK_GOTO_POINT_LOGLOG << "FKGotoPoint 3targetP : " << targetPoint << endl;#endif ExactGotoPoint doGotoPoint(creator, targetPoint, 0.2, body); command = doGotoPoint.getCommand(); #ifdef FREEKICK_GOTO_POINT_LOGLOG << "FKGotoPoint mode : " << doGotoPoint.getMode() << endl;#endif if (command) {#ifdef FREEKICK_GOTO_POINT_LOGLOG << "FKGotoPoint command : " << command->toString() << endl;#endif } if (intersectFlag || doGotoPoint.getMode() != CT_EMPTY) status = 1; else status = 0;}Command *FreeKickGotoPoint::getCommand(){ return command;}int FreeKickGotoPoint::getStatus() const{ return status;}/* 2 1 |---------------------- Y23 X1 | |---------------------- Y1*/// 4 5 ForbiddenAreaGotoPoint::ForbiddenAreaGotoPoint(ActionType creator, const Point &point, float rectX1, float rectY1, float rectY2, const Body &body): BasicAction(creator){ int sourcePlace = 0; int goModel = 0;#ifdef FORBIDDENAREA_GOTO_POINT_LOGLOG << "ForbiddenAreaGotoPoint Rect" << endl;#endif command = NULL;#ifdef FORBIDDENAREA_GOTO_POINT_LOGLOG << "FAGotoPoint Point 1st=" << point << endl;#endif rectY1 = min(rectY1, rectY2); rectY2 = max(rectY1, rectY2);#ifdef FORBIDDENAREA_GOTO_POINT_LOGLOG << "ForbiddenAreaGotoPoint X1 = " << rectX1 << endl;LOG << "ForbiddenAreaGotoPoint Y1 = " << rectY1 << endl; LOG << "ForbiddenAreaGotoPoint Y2 = " << rectY2 << endl; #endif forbiddenSourceFlag = false; forbiddenTargetFlag = false; realTargetPlace = 1; realTargetPoint = point; goAroundFlag = false; if (point.x > rectX1 && point.y > rectY1 && point.y < rectY2) {#ifdef FORBIDDENAREA_GOTO_POINT_LOGLOG << "FAGotoPoint forbiddenTargetFlag = true" << endl;#endif float minDistance; forbiddenTargetFlag = true; realTargetPoint.x = rectX1; minDistance = point.x - rectX1; if (point.y - rectY1 < minDistance) {#ifdef FORBIDDENAREA_GOTO_POINT_LOGLOG << "FAGotoPoint near1" << endl;#endif realTargetPoint.x = point.x; realTargetPoint.y = rectY1; minDistance = point.y - rectY1; } if (rectY2 - point.y < minDistance) {#ifdef FORBIDDENAREA_GOTO_POINT_LOGLOG << "FAGotoPoint near2" << endl;#endif realTargetPoint.x = point.x; realTargetPoint.y = rectY2; minDistance = rectY2 - point.y; } }#ifdef FORBIDDENAREA_GOTO_POINT_LOGLOG << "FAGotoPoint Point 2nd=" << realTargetPoint << endl;#endif if (body.getPos().getX() > rectX1 + 0.8 && body.getPos().getY() > rectY1 + 0.8 && body.getPos().getY() < rectY2 - 0.8) {#ifdef FORBIDDENAREA_GOTO_POINT_LOGLOG << "FAGotoPoint forbiddenSourceFlag = true" << endl;#endif forbiddenSourceFlag = true; float minDistance; realTargetPoint.x = rectX1; minDistance = body.getPos().getX() - rectX1; if (body.getPos().getY() - rectY1 < minDistance) {#ifdef FORBIDDENAREA_GOTO_POINT_LOGLOG << "FAGotoPoint fsource near1" << endl;#endif realTargetPoint.x = body.getPos().getX(); realTargetPoint.y = rectY1; minDistance = body.getPos().getY() - rectY1; } if (rectY2 - body.getPos().getY() < minDistance) {#ifdef FORBIDDENAREA_GOTO_POINT_LOGLOG << "FAGotoPoint fsource near2" << endl;#endif realTargetPoint.x = body.getPos().getX(); realTargetPoint.y = rectY2; minDistance = rectY2 - body.getPos().getY(); } DashNormalGotoPoint doGotoPoint(creator, realTargetPoint, 1.2, body, 90); command = doGotoPoint.getCommand(); if (doGotoPoint.getMode() == CT_EMPTY) status = 0; else status = 1; return; /* command = new EmptyCommand(); status = 0; return; */ } if (realTargetPoint.x > rectX1 && realTargetPoint.y >= rectY2) realTargetPlace = 1; if (realTargetPoint.x <= rectX1 && realTargetPoint.y >= rectY2) realTargetPlace = 2; if (realTargetPoint.x <= rectX1 && realTargetPoint.y < rectY2 && realTargetPoint.y > rectY1) realTargetPlace = 3; if (realTargetPoint.x <= rectX1 && realTargetPoint.y <= rectY1) realTargetPlace = 4; if (realTargetPoint.x > rectX1 && realTargetPoint.y <= rectY1) realTargetPlace = 5; if (body.getPos().getX() > rectX1 && body.getPos().getY() >= rectY2) sourcePlace = 1; if (body.getPos().getX() <= rectX1 && body.getPos().getY() >= rectY2) sourcePlace = 2; if (body.getPos().getX() <= rectX1 && body.getPos().getY() < rectY2 &&
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -