Skip to content

Commit fbe5093

Browse files
authored
Merge pull request rcsoccersim#8 from wbwatkinson/add-y-params
Add ball y parameters for HFORef::resetField()
2 parents 83c80b6 + 060d604 commit fbe5093

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

src/referee.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -3235,7 +3235,13 @@ HFORef::resetField()
32353235
max_ball_x = std::max(max_ball_x, min_ball_x);
32363236
double ball_x = drand(min_ball_x * half_pitch_length,
32373237
max_ball_x * half_pitch_length, M_rng);
3238-
double ball_y = drand(-.4 * pitch_width, .4 * pitch_width, M_rng);
3238+
double min_ball_y =
3239+
std::max(std::min(ServerParam::instance().hfoMinBallY(), 1.), -1.);
3240+
double max_ball_y =
3241+
std::max(std::min(ServerParam::instance().hfoMaxBallY(), 1.), -1.);
3242+
max_ball_y = std::max(max_ball_y, min_ball_y);
3243+
double ball_y = drand(min_ball_y / 2.0 * pitch_width,
3244+
max_ball_y / 2.0 * pitch_width, M_rng);
32393245
M_stadium.placeBall( NEUTRAL, PVector(ball_x, ball_y) );
32403246
M_prev_ball_pos = M_stadium.ball().pos();
32413247
boost::variate_generator<boost::mt19937&, boost::uniform_int<> >

src/serverparam.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,8 @@ ServerParam::addParams()
858858
addParam( "hfo_offense_on_ball", M_hfo_offense_on_ball, "", 9 );
859859
addParam( "hfo_min_ball_pos_x", M_hfo_min_ball_pos_x, "", 9 );
860860
addParam( "hfo_max_ball_pos_x", M_hfo_max_ball_pos_x, "", 9 );
861+
addParam( "hfo_min_ball_pos_y", M_hfo_min_ball_pos_y, "", 9 );
862+
addParam( "hfo_max_ball_pos_y", M_hfo_max_ball_pos_y, "", 9 );
861863

862864
addParam( "nr_normal_halfs",
863865
rcss::conf::makeSetter( this, &ServerParam::setNrNormalHalfs ),

src/serverparam.h

+4
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,8 @@ class ServerParam {
427427
int M_hfo_offense_on_ball; /* Give the ball to an offensive player */
428428
double M_hfo_min_ball_pos_x; /* Governs the initialization x-position of ball */
429429
double M_hfo_max_ball_pos_x; /* Governs the initialization x-position of ball */
430+
double M_hfo_min_ball_pos_y; /* Governs the initialization y-position of ball */
431+
double M_hfo_max_ball_pos_y; /* Governs the initialization y-position of ball */
430432
int M_port; /* port number */
431433
int M_coach_port; /* coach port number */
432434
int M_olcoach_port; /* online coach port number */
@@ -772,6 +774,8 @@ class ServerParam {
772774
int hfoOffenseOnBall() const { return M_hfo_offense_on_ball; }
773775
double hfoMinBallX() const { return M_hfo_min_ball_pos_x; }
774776
double hfoMaxBallX() const { return M_hfo_max_ball_pos_x; }
777+
double hfoMinBallY() const { return M_hfo_min_ball_pos_y; }
778+
double hfoMaxBallY() const { return M_hfo_max_ball_pos_y; }
775779

776780
double cornerKickMargin() const { return M_corner_kick_margin; }
777781
double offsideActiveArea() const { return M_offside_active_area_size; }

0 commit comments

Comments
 (0)