void Club::updateAttackingPlay() { if (!stadium->gameIsOn) return; float stadium_width = stadium->playArea.width; float stadium_height = stadium->playArea.height; float goalEffect = (onTheRightGoal)?(-1.0):(1.0); sf::Vector2f ball_pos = stadium->ball->getPosition2(); sf::Vector2f relative_ball_pos = ball_pos; if (onTheRightGoal) { relative_ball_pos.x = stadium->playArea.width - relative_ball_pos.x; relative_ball_pos.y = stadium->playArea.height - relative_ball_pos.y; } // Update currentDefensiveLine currentDefensiveLine = 0.12 * log(31.0*(relative_ball_pos.x/stadium->playArea.width)+1.0) / ( log(2) * ((1.0/-0.9) * (defensiveLine-1.0) +1.0) ); if(onTheRightGoal) currentDefensiveLine = 1.0 - currentDefensiveLine; currentDefensiveLine *= stadium->playArea.width; // Update currentLeftmost float minX = 2.0; for (int i=1; i<11; i++) { if (lineUp[i]->tactical_x<minX) minX = lineUp[i]->tactical_x; } float howFar_defLine = onTheRightGoal?currentDefensiveLine:(stadium->playArea.width-currentDefensiveLine); currentLeftmost = currentDefensiveLine - goalEffect * ( (minX * howFar_defLine) / (0.9-minX)); currentWidth = 0.5 + 0.4 * attackingWidth; currentUppermost = ball_pos.y * (1.0-currentWidth); currentWidth *= stadium_height; findClosestPlayer(); // If someone kicked the ball in the earlier frame, increase the time passed since the ball is kicked. if (sinceBallIsPassed>0) sinceBallIsPassed += 1.0/60.0; SquadPosition* player; for (int j=0; j<11; j++) { player = lineUp[j]; ActionMap possibleActions; for (int i=0; i<attackingActions.size(); i++) { float weight = attackingActions[i]->checkPreconditions(player,stadium); if (weight>0) possibleActions.insert( ActionPair(-1.0*weight,attackingActions[i]) ); } if (possibleActions.size()>0) possibleActions.begin()->second->execute(player,stadium); } };
void Club::updateDefendingPlay() { if (!stadium->gameIsOn) return; findClosestPlayer(); float stadium_width = stadium->playArea.width; float stadium_height = stadium->playArea.height; float goalEffect = (onTheRightGoal)?(-1.0):(1.0); sf::Vector2f ball_pos = stadium->ball->getPosition2(); sf::Vector2f relative_ball_pos = ball_pos; if (onTheRightGoal) { relative_ball_pos.x = stadium->playArea.width - relative_ball_pos.x; relative_ball_pos.y = stadium->playArea.height - relative_ball_pos.y; } // Update currentDefensiveLine currentDefensiveLine = 0.08 * log(31.0*(relative_ball_pos.x/stadium->playArea.width)+1.0) / ( log(2) * ((1.0/-0.9) * (defensiveLine-1.0) +1.0) ); if(onTheRightGoal) currentDefensiveLine = 1 - currentDefensiveLine; currentDefensiveLine *= stadium->playArea.width; // Update currentLeftmost float minX = 2.0; for (int i=1; i<11; i++) { if (lineUp[i]->defending_x<minX) minX = lineUp[i]->defending_x; } float howFar_defLine = ((onTheRightGoal)?(currentDefensiveLine):(stadium->playArea.width-currentDefensiveLine)); currentLeftmost = currentDefensiveLine - goalEffect * ( (minX * howFar_defLine) / (1.0-minX)); // Update currentUppermost currentWidth = 0.5 + 0.4 * defendingWidth; currentUppermost = ball_pos.y * (1.0-currentWidth); currentWidth *= stadium_height; SquadPosition* player; for (int j=0; j<11; j++) { player = lineUp[j]; ActionMap possibleActions; for (int i=0; i<defendingActions.size(); i++) { float weight = defendingActions[i]->checkPreconditions(player,stadium); if (weight>0) possibleActions.insert( ActionPair(-weight,defendingActions[i]) ); } if (possibleActions.size()>0) possibleActions.begin()->second->execute(player,stadium); } };