📄 opptypes.cpp
字号:
int uniNum; Vector accleration;#ifdef OPPTYPES_LOG1 LOG << "OppTypes: checkForDashes " << endl;#endif if (worldModelHistory.getSize() <= 3) return; if (worldModel->getCurTime() - worldModel->getRefereeHearTime() < 3 || worldModel->getPlayMode() == PM_BEFORE_KICK_OFF || worldModel->getPlayMode() == PM_GOAL || worldModel->getPlayMode() == PM_GOAL_OPP) { LOG << "OppTypes: Ignoring checkForDashes because of playmode" << endl; return; } #ifdef OPPTYPES_LOG1 LOG << "OppTypes: checking " << endl;#endif for (uniNum = 0;uniNum < 11; uniNum++) { if (foundSure[uniNum]) continue; if (worldModelHistory[-1]->getFullPlayer(TID_OPPONENT, uniNum).isAlive() && worldModel->getFullPlayer(TID_OPPONENT, uniNum).isAlive()) { accleration = (worldModel->getFullPlayer(TID_OPPONENT, uniNum).getVel() * (1 / maxPlayerDecay)) - worldModelHistory[-1]->getFullPlayer(TID_OPPONENT, uniNum).getVel(); if (worldModelHistory[-1]->getFullPlayer(TID_OPPONENT, uniNum).getBodyDir() == worldModel->getFullPlayer(TID_OPPONENT, uniNum).getBodyDir() && accleration.getMagnitude() > 0.3) //TODO : 0.3 <= (dash_power_rate - new_dash_power_rate_delta_max)* max_power informDash(uniNum, worldModelHistory[-1]->getCurTime()); } } if (worldModelHistory.getSize() <= 4) return; for (uniNum = 0;uniNum < 11; uniNum++) { if (foundSure[uniNum]) continue; if (worldModelHistory[-1]->getFullPlayer(TID_OPPONENT, uniNum).isAlive() && worldModelHistory[-2]->getFullPlayer(TID_OPPONENT, uniNum).isAlive() && worldModel->getFullPlayer(TID_OPPONENT, uniNum).isAlive()) { accleration = (worldModel->getFullPlayer(TID_OPPONENT, uniNum).getVel() * (1 / maxPlayerDecay)) - worldModelHistory[-1]->getFullPlayer(TID_OPPONENT, uniNum).getVel(); if (worldModelHistory[-1]->getFullPlayer(TID_OPPONENT, uniNum).getBodyDir() == worldModel->getFullPlayer(TID_OPPONENT, uniNum).getBodyDir() && accleration.getMagnitude() > 0.3) { accleration = (worldModelHistory[-1]->getFullPlayer(TID_OPPONENT, uniNum). getVel() * (1 / maxPlayerDecay)) - worldModelHistory[-2]->getFullPlayer(TID_OPPONENT, uniNum).getVel(); if (worldModelHistory[-2]->getFullPlayer(TID_OPPONENT, uniNum).getBodyDir() == worldModelHistory[-1]->getFullPlayer(TID_OPPONENT, uniNum).getBodyDir() && accleration.getMagnitude() > 0.3) //TODO : 0.3 <= (dash_power_rate - new_dash_power_rate_delta_max)* max_power informMaxDash(uniNum, worldModelHistory[-2]->getCurTime()); } } }}void OppTypes::informDash(int uniNum, unsigned time){ int i;#ifdef OPPTYPES_LOG2 char logString[8];#endif for (i = 0; i < 7; i++) { if (sureNot[uniNum][i]) {#ifdef OPPTYPES_LOG2 logString[i] = 'X';#endif continue; } if (!types[i].isAbleToDash(worldModelHistory[time + 1]-> getFullPlayer(TID_OPPONENT, uniNum).getVel(), worldModelHistory[time]-> getFullPlayer(TID_OPPONENT, uniNum).getVel(), worldModelHistory[time]-> getFullPlayer(TID_OPPONENT, uniNum).getBodyDir(), worldModel->getServerParam())) {#ifdef OPPTYPES_LOG2 logString[i] = 'N';#endif sureNot[uniNum][i] = true; } else {#ifdef OPPTYPES_LOG2 logString[i] = '0';#endif } }#ifdef OPPTYPES_LOG2 logString[7] = 0; LOG << "OppTypes:informDash p=" << uniNum + 1 << " t=" << time << " " << " info:" << logString << endl;#endif}void OppTypes::informMaxDash(int uniNum, unsigned time){ int i;#ifdef OPPTYPES_LOG2 char logString[8];#endif for (i = 0; i < 7; i++) { if (sureNot[uniNum][i]) {#ifdef OPPTYPES_LOG2 logString[i] = 'X';#endif continue; } if (types[i].isMaxDash(worldModelHistory[time + 1]-> getFullPlayer(TID_OPPONENT, uniNum).getVel(), worldModelHistory[time]-> getFullPlayer(TID_OPPONENT, uniNum).getVel(), worldModelHistory[time]-> getFullPlayer(TID_OPPONENT, uniNum).getBodyDir(), worldModel->getServerParam())) {#ifdef OPPTYPES_LOG2 logString[i] = 'Y';#endif sureIs[uniNum][i] += (100 - sureIs[uniNum][i]) * 0.02; } else {#ifdef OPPTYPES_LOG2 logString[i] = '0';#endif } }#ifdef OPPTYPES_LOG2 logString[7] = 0; LOG << "OppTypes:informMaxDash p=" << uniNum + 1 << " t=" << time << " " << " info:" << logString << endl;#endif}void OppTypes::checkForKicks(){ int numPlayersAbleToKick = 0; // Tackle is a kick for us! int lastOppPlayerAbleToKick = -1; Vector acclerate; int uniNum;#ifdef OPPTYPES_LOG1 LOG << "OppTypes: checkForKicks " << endl;#endif if (worldModelHistory.getSize() <= 2) return; if (worldModel->getCurTime() - worldModel->getRefereeHearTime() < 2 || worldModel->getPlayMode() == PM_BEFORE_KICK_OFF || worldModel->getPlayMode() == PM_GOAL || worldModel->getPlayMode() == PM_GOAL_OPP) {#ifdef OPPTYPES_LOG1 LOG << "OppTypes: Ignoring checkForKicks because of playmode" << endl; #endif return; } #ifdef OPPTYPES_LOG1 LOG << "OppTypes: checking " << endl;#endif acclerate = worldModel->getBall().getVel() * (1 / (worldModel->getServerParam())["ball_decay"].asFloat()) - worldModelHistory[-1]->getBall().getVel(); if (acclerate.getMagnitude() > 0.2) {#ifdef OPPTYPES_LOG1 LOG << "OppTypes::Ball is kicked" << endl;#endif // check ability of opponents for (uniNum = 0;uniNum < 11; uniNum++) { if (worldModelHistory[-1]->getFullPlayer(TID_OPPONENT, uniNum).isAlive() && worldModel->getFullPlayer(TID_OPPONENT, uniNum).isAlive()) { if (worldModelHistory[-1]->getFullPlayer(TID_OPPONENT, uniNum). getDistance(worldModelHistory[-1]->getBall()) <= maxKickableArea) {#ifdef OPPTYPES_LOG1 LOG << " Opp " << uniNum + 1 << " is able to kick" << endl;#endif lastOppPlayerAbleToKick = uniNum; numPlayersAbleToKick++; } if (worldModelHistory[-1]->getFullPlayer(TID_OPPONENT, uniNum). getDistance(worldModelHistory[-1]->getBall()) < (worldModel->getServerParam())["tackle_dist"].asFloat() && worldModelHistory[-1]->getFullPlayer(TID_OPPONENT, uniNum). isTackling() == false && worldModel->getFullPlayer(TID_OPPONENT, uniNum). isTackling() == true) {#ifdef OPPTYPES_LOG1 LOG << " Opp " << uniNum + 1 << " is able to kick(tackle)" << endl;#endif lastOppPlayerAbleToKick = -1; numPlayersAbleToKick++; } } } // check ability of teammates for (uniNum = 0;uniNum < 11; uniNum++) { if (worldModelHistory[-1]->getFullPlayer(TID_TEAMMATE, uniNum).isAlive() && worldModel->getFullPlayer(TID_TEAMMATE, uniNum).isAlive()) {// LOG << " testTmm " << uniNum + 1 << " ball_dist = ";// LOG << worldModelHistory[-1]->getFullPlayer(TID_TEAMMATE, uniNum).// getDistance(worldModelHistory[-1]->getBall()) << endl; if (worldModelHistory[-1]->getFullPlayer(TID_TEAMMATE, uniNum). getDistance(worldModelHistory[-1]->getBall()) <= maxKickableArea) {#ifdef OPPTYPES_LOG1 LOG << " Tmm " << uniNum + 1 << " is able to kick" << endl;#endif numPlayersAbleToKick++; } if (worldModelHistory[-1]->getFullPlayer(TID_TEAMMATE, uniNum). getDistance(worldModelHistory[-1]->getBall()) < (worldModel->getServerParam())["tackle_dist"].asFloat() && worldModelHistory[-1]->getFullPlayer(TID_TEAMMATE, uniNum). isTackling() == false && worldModel->getFullPlayer(TID_TEAMMATE, uniNum). isTackling() == true) {#ifdef OPPTYPES_LOG1 LOG << " Tmm " << uniNum + 1 << " is able to kick(tackle)" << endl;#endif numPlayersAbleToKick++; } } } if (numPlayersAbleToKick == 0) {#ifdef OPPTYPES_LOG1 LOG << "OppTypes: WHAT!!!!! ball kicked without kicker" << endl;#endif return; } if (numPlayersAbleToKick > 1) {#ifdef OPPTYPES_LOG1 LOG << "OppTypes: many kickers" << endl;#endif return; } if (lastOppPlayerAbleToKick == -1) {#ifdef OPPTYPES_LOG1 LOG << "only teammate kickers or opponents tacklers" << endl;#endif return; } if (foundSure[lastOppPlayerAbleToKick]) {#ifdef OPPTYPES_LOG1 LOG << "foundSure = true" << endl;#endif return; } informKick(lastOppPlayerAbleToKick, worldModelHistory[-1]->getCurTime(), acclerate); }}void OppTypes::informKick(int uniNum, unsigned time, Vector acclerate){ int i;#ifdef OPPTYPES_LOG2 char logString[8];#endif for (i = 0; i < 7; i++) { if (sureNot[uniNum][i]) {#ifdef OPPTYPES_LOG2 logString[i] = 'X';#endif continue; } if (!types[i].isAbleToKick( worldModelHistory[time]->getFullPlayer(TID_OPPONENT, uniNum).getPos(), worldModelHistory[time]->getBall().getPos(), worldModelHistory[time]->getFullPlayer(TID_OPPONENT, uniNum).getBodyDir(), acclerate, worldModel->getFieldSide(), worldModel->getServerParam())) {#ifdef OPPTYPES_LOG2 logString[i] = 'N';#endif sureNot[uniNum][i] = true; } else {#ifdef OPPTYPES_LOG2 logString[i] = '0';#endif } }#ifdef OPPTYPES_LOG2 logString[7] = 0; LOG << "OppTypes:informKick p=" << uniNum + 1 << " t=" << time << " " << " info:" << logString << endl;#endif}bool OppTypes::find(){ bool changed; int newType[11]; int uniNum, i; float max; int maxi, ableNum;#ifdef OPPTYPES_LOG1 char logString[8];#endif for (uniNum = 0; uniNum < 11; uniNum++) { ableNum = 0; max = -1; maxi = 0; for (i = 0; i < 7; i++) if (!sureNot[uniNum][i]) { ableNum++; if (sureIs[uniNum][i] > max) { max = sureIs[uniNum][i]; maxi = i; } } if (max < 0) { maxi = 0; resetPlayer(uniNum); } if (ableNum == 1) foundSure[uniNum] = true; else foundSure[uniNum] = false; newType[uniNum] = maxi; } changed = false; for (uniNum = 0; uniNum < 11; uniNum++) { if (newType[uniNum] != foundType[uniNum]) { changed = true; foundType[uniNum] = newType[uniNum]; } }#ifdef OPPTYPES_LOG1 logString[7] = 0; for (uniNum = 0; uniNum < 11; uniNum++) { for (i = 0; i < 7; i++) { if (sureNot[uniNum][i]) logString[i] = 'N'; else logString[i] = 'Y'; } if (foundSure[uniNum]) LOG << "foundOppType p " << uniNum + 1 << " = " << foundType[uniNum] << " <" << sureIs[uniNum][foundType[uniNum]] << "> info:" << logString << endl; else LOG << "foundOppType p " << uniNum + 1 << " = (" << foundType[uniNum] << ") <" << sureIs[uniNum][foundType[uniNum]] << "> info:" << logString << endl; }#endif if (changed) return true; else return false;}void OppTypes::setFreeForm(){ int i; freeFormString = "(T "; // Opponent heterogenous types flag for (i = 0; i < 11; i++) freeFormString += char('0' + foundType[i]); freeFormString += ")"; freeFormReadyFlag = true;}OppTypes::~OppTypes(){} bool OppTypes::execute(){ LOG << "OppTypes execute" << endl; if (!typesSet) initialize(); // check goalie int i; for (i = 0; i < 10; i++) if (worldModel->getFullPlayer(TID_OPPONENT, i).isAlive() && worldModel->getFullPlayer(TID_OPPONENT, i).isGoalie()) resetPlayerForFirstTime(i); checkForTurns(); checkForDashes(); checkForKicks(); if (find()) setFreeForm(); return true;}void OppTypes::initialize(){ int i; for (i = 0; i < 7; i++) types[i].setByPlayerType(worldModel->getPlayerType(i)); maxPlayerDecay = 0; for (i = 0; i < 7; i++) if (types[i].playerDecay > maxPlayerDecay) maxPlayerDecay = types[i].playerDecay; maxKickableArea = 0; for (i = 0; i < 7; i++) if (types[i].kickableMargin + types[i].playerSize + worldModel->getServerParam()["ball_size"].asFloat() > maxKickableArea) maxKickableArea = types[i].kickableMargin + types[i].playerSize + worldModel->getServerParam()["ball_size"].asFloat();#ifdef OPPTYPES_LOG3 LOG << "OppTypes:maxKickableArea = " << maxKickableArea << endl;#endif typesSet = true;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -