Skip to content

Commit

Permalink
Merge pull request #29 from rcsoccersim/feature/fixed_teamname
Browse files Browse the repository at this point in the history
Add a fixed teamname feature
  • Loading branch information
hidehisaakiyama authored Jan 28, 2020
2 parents 398fef1 + 8e3980a commit 630667b
Show file tree
Hide file tree
Showing 22 changed files with 217 additions and 48 deletions.
10 changes: 5 additions & 5 deletions src/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ AudioSenderOnlineCoachv1::sendPlayerAudio( const Player & player,
{
serializer().serializePlayerAudio( transport(),
M_stadium.time(),
player.name(),
( listener().side() == player.side() ? player.name() : player.fixedName() ),
msg );
transport() << std::ends << std::flush;
}
Expand All @@ -949,7 +949,7 @@ AudioSenderOnlineCoachv7::sendPlayerAudio( const Player & player,
{
serializer().serializePlayerAudio( transport(),
M_stadium.time(),
player.shortName(),
( listener().side() == player.side() ? player.shortName() : player.fixedShortName() ),
msg );
transport() << std::ends << std::flush;
}
Expand Down Expand Up @@ -979,7 +979,7 @@ RegHolder vp12 = AudioSenderPlayer::factory().autoReg( &create< AudioSenderPlaye
RegHolder vp13 = AudioSenderPlayer::factory().autoReg( &create< AudioSenderPlayerv8 >, 13 );
RegHolder vp14 = AudioSenderPlayer::factory().autoReg( &create< AudioSenderPlayerv8 >, 14 );
RegHolder vp15 = AudioSenderPlayer::factory().autoReg( &create< AudioSenderPlayerv8 >, 15 );
//RegHolder vp16 = AudioSenderPlayer::factory().autoReg( &create< AudioSenderPlayerv8 >, 16 );
RegHolder vp16 = AudioSenderPlayer::factory().autoReg( &create< AudioSenderPlayerv8 >, 16 );

template< typename Sender >
AudioSender::Ptr
Expand All @@ -1003,7 +1003,7 @@ RegHolder vc12 = AudioSenderCoach::factory().autoReg( &create< AudioSenderCoachv
RegHolder vc13 = AudioSenderCoach::factory().autoReg( &create< AudioSenderCoachv7 >, 13 );
RegHolder vc14 = AudioSenderCoach::factory().autoReg( &create< AudioSenderCoachv7 >, 14 );
RegHolder vc15 = AudioSenderCoach::factory().autoReg( &create< AudioSenderCoachv7 >, 15 );
//RegHolder vc16 = AudioSenderCoach::factory().autoReg( &create< AudioSenderCoachv7 >, 16 );
RegHolder vc16 = AudioSenderCoach::factory().autoReg( &create< AudioSenderCoachv7 >, 16 );

template< typename Sender >
AudioSender::Ptr
Expand All @@ -1027,6 +1027,6 @@ RegHolder voc12 = AudioSenderOnlineCoach::factory().autoReg( &create< AudioSende
RegHolder voc13 = AudioSenderOnlineCoach::factory().autoReg( &create< AudioSenderOnlineCoachv7 >, 13 );
RegHolder voc14 = AudioSenderOnlineCoach::factory().autoReg( &create< AudioSenderOnlineCoachv7 >, 14 );
RegHolder voc15 = AudioSenderOnlineCoach::factory().autoReg( &create< AudioSenderOnlineCoachv7 >, 15 );
//RegHolder voc16 = AudioSenderOnlineCoach::factory().autoReg( &create< AudioSenderOnlineCoachv7 >, 16 );
RegHolder voc16 = AudioSenderOnlineCoach::factory().autoReg( &create< AudioSenderOnlineCoachv7 >, 16 );
}
}
2 changes: 1 addition & 1 deletion src/bodysender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ RegHolder vp12 = BodySenderPlayer::factory().autoReg( &create< BodySenderPlayerV
RegHolder vp13 = BodySenderPlayer::factory().autoReg( &create< BodySenderPlayerV13 >, 13 );
RegHolder vp14 = BodySenderPlayer::factory().autoReg( &create< BodySenderPlayerV14 >, 14 );
RegHolder vp15 = BodySenderPlayer::factory().autoReg( &create< BodySenderPlayerV14 >, 15 );
//RegHolder vp16 = BodySenderPlayer::factory().autoReg( &create< BodySenderPlayerV14 >, 16 );
RegHolder vp16 = BodySenderPlayer::factory().autoReg( &create< BodySenderPlayerV14 >, 16 );
}

}
12 changes: 10 additions & 2 deletions src/coach.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -689,12 +689,20 @@ Coach::team_names()

if ( ! M_stadium.teamLeft().name().empty() )
{
ost << " (team l " << M_stadium.teamLeft().name() << ")";
ost << " (team l "
<< ( side() == RIGHT
? M_stadium.teamLeft().fixedName()
: M_stadium.teamLeft().name() )
<< ")";
}

if ( ! M_stadium.teamRight().name().empty() )
{
ost << " (team r " << M_stadium.teamRight().name() << ")";
ost << " (team r "
<< ( side() == LEFT
? M_stadium.teamRight().fixedName()
: M_stadium.teamRight().name() )
<< ")";
}

ost << ")" << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion src/fullstatesender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ RegHolder vp12 = FullStateSenderPlayer::factory().autoReg( &create< FullStateSen
RegHolder vp13 = FullStateSenderPlayer::factory().autoReg( &create< FullStateSenderPlayerV13 >, 13 );
RegHolder vp14 = FullStateSenderPlayer::factory().autoReg( &create< FullStateSenderPlayerV13 >, 14 );
RegHolder vp15 = FullStateSenderPlayer::factory().autoReg( &create< FullStateSenderPlayerV13 >, 15 );
//RegHolder vp16 = FullStateSenderPlayer::factory().autoReg( &create< FullStateSenderPlayerV13 >, 16 );
RegHolder vp16 = FullStateSenderPlayer::factory().autoReg( &create< FullStateSenderPlayerV13 >, 16 );
}

}
2 changes: 1 addition & 1 deletion src/initsendercoach.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ RegHolder vc12 = InitSenderOfflineCoach::factory().autoReg( &create< InitSenderO
RegHolder vc13 = InitSenderOfflineCoach::factory().autoReg( &create< InitSenderOfflineCoachV8 >, 13 );
RegHolder vc14 = InitSenderOfflineCoach::factory().autoReg( &create< InitSenderOfflineCoachV8 >, 14 );
RegHolder vc15 = InitSenderOfflineCoach::factory().autoReg( &create< InitSenderOfflineCoachV8 >, 15 );
//RegHolder vc16 = InitSenderOfflineCoach::factory().autoReg( &create< InitSenderOfflineCoachV8 >, 16 );
RegHolder vc16 = InitSenderOfflineCoach::factory().autoReg( &create< InitSenderOfflineCoachV8 >, 16 );
}

}
2 changes: 1 addition & 1 deletion src/initsenderonlinecoach.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ RegHolder voc12 = InitSenderOnlineCoach::factory().autoReg( &create< InitSenderO
RegHolder voc13 = InitSenderOnlineCoach::factory().autoReg( &create< InitSenderOnlineCoachV8 >, 13 );
RegHolder voc14 = InitSenderOnlineCoach::factory().autoReg( &create< InitSenderOnlineCoachV8 >, 14 );
RegHolder voc15 = InitSenderOnlineCoach::factory().autoReg( &create< InitSenderOnlineCoachV8 >, 15 );
//RegHolder voc16 = InitSenderOnlineCoach::factory().autoReg( &create< InitSenderOnlineCoachV8 >, 16 );
RegHolder voc16 = InitSenderOnlineCoach::factory().autoReg( &create< InitSenderOnlineCoachV8 >, 16 );
}

}
2 changes: 1 addition & 1 deletion src/initsenderplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ RegHolder vp12 = InitSenderPlayer::factory().autoReg( &create< InitSenderPlayerV
RegHolder vp13 = InitSenderPlayer::factory().autoReg( &create< InitSenderPlayerV8 >, 13 );
RegHolder vp14 = InitSenderPlayer::factory().autoReg( &create< InitSenderPlayerV8 >, 14 );
RegHolder vp15 = InitSenderPlayer::factory().autoReg( &create< InitSenderPlayerV8 >, 15 );
//RegHolder vp16 = InitSenderPlayer::factory().autoReg( &create< InitSenderPlayerV8 >, 16 );
RegHolder vp16 = InitSenderPlayer::factory().autoReg( &create< InitSenderPlayerV8 >, 16 );
}

}
14 changes: 14 additions & 0 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,19 @@ Player::init( const double ver,
M_goalie_catch_ban = 0;
M_goalie_moves_since_catch = 0;

const std::string fixed_teamname = team()->fixedName();
{
char lname[128], sname[128];
snprintf( lname, 128, PLAYER_NAME_FORMAT, team()->name().c_str(), unum() );
snprintf( sname, 128, PLAYER_NAME_FORMAT_SHORT, team()->name().c_str(), unum(),
isGoalie() ? GOALIE_VISUAL_STRING : "" );
setName( lname, sname );

snprintf( lname, 128, PLAYER_NAME_FORMAT, fixed_teamname.c_str(), unum() );
snprintf( sname, 128, PLAYER_NAME_FORMAT_SHORT, fixed_teamname.c_str(), unum(),
isGoalie() ? GOALIE_VISUAL_STRING : "" );
M_fixed_name = lname;
M_fixed_short_name = sname;
}

char buf[128];
Expand All @@ -297,6 +304,13 @@ Player::init( const double ver,
snprintf( buf, 128, PLAYER_NAME_TOOFAR_FORMAT_SHORT );
M_short_name_toofar = buf;


snprintf( buf, 128, PLAYER_NAME_FAR_FORMAT, fixed_teamname.c_str() );
M_fixed_name_far = buf;
snprintf( buf, 128, PLAYER_NAME_FAR_FORMAT_SHORT, fixed_teamname.c_str() );
M_fixed_short_name_far = buf;


M_angle_body_committed = SideDirection( side() );

// pfr 8/14/00: for RC2000 evaluation
Expand Down
10 changes: 10 additions & 0 deletions src/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ class Player
std::string M_short_name_far;
std::string M_short_name_toofar;

std::string M_fixed_name;
std::string M_fixed_name_far;
std::string M_fixed_short_name;
std::string M_fixed_short_name_far;

double M_unum_far_length;
double M_unum_too_far_length;
double M_team_far_length;
Expand Down Expand Up @@ -239,6 +244,11 @@ class Player
const std::string & shortNameFar() const { return M_short_name_far; }
const std::string & shortNameTooFar() const { return M_short_name_toofar; }

const std::string & fixedName() const { return M_fixed_name; }
const std::string & fixedNameFar() const { return M_fixed_name_far; }
const std::string & fixedShortName() const { return M_fixed_short_name; }
const std::string & fixedShortNameFar() const { return M_fixed_short_name_far; }

const double & unumFarLength() const { return M_unum_far_length; }
const double & unumTooFarLength() const { return M_unum_too_far_length; }
const double & teamFarLength() const { return M_team_far_length; }
Expand Down
2 changes: 1 addition & 1 deletion src/serializercoachstdv14.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ SerializerCoachStdv14::create()
namespace {
RegHolder v14 = SerializerCoach::factory().autoReg( &SerializerCoachStdv14::create, 14 );
RegHolder v15 = SerializerCoach::factory().autoReg( &SerializerCoachStdv14::create, 15 );
//RegHolder v16 = SerializerCoach::factory().autoReg( &SerializerCoachStdv14::create, 16 );
RegHolder v16 = SerializerCoach::factory().autoReg( &SerializerCoachStdv14::create, 16 );
}

}
2 changes: 1 addition & 1 deletion src/serializercommonstdv8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ RegHolder v12 = SerializerCommon::factory().autoReg( &SerializerCommonStdv8::cre
RegHolder v13 = SerializerCommon::factory().autoReg( &SerializerCommonStdv8::create, 13 );
RegHolder v14 = SerializerCommon::factory().autoReg( &SerializerCommonStdv8::create, 14 );
RegHolder v15 = SerializerCommon::factory().autoReg( &SerializerCommonStdv8::create, 15 );
//RegHolder v16 = SerializerCommon::factory().autoReg( &SerializerCommonStdv8::create, 16 );
RegHolder v16 = SerializerCommon::factory().autoReg( &SerializerCommonStdv8::create, 16 );
}

}
2 changes: 1 addition & 1 deletion src/serializeronlinecoachstdv14.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ SerializerOnlineCoachStdv14::create()
namespace {
RegHolder v14 = SerializerOnlineCoach::factory().autoReg( &SerializerOnlineCoachStdv14::create, 14 );
RegHolder v15 = SerializerOnlineCoach::factory().autoReg( &SerializerOnlineCoachStdv14::create, 15 );
//RegHolder v16 = SerializerOnlineCoach::factory().autoReg( &SerializerOnlineCoachStdv14::create, 16 );
RegHolder v16 = SerializerOnlineCoach::factory().autoReg( &SerializerOnlineCoachStdv14::create, 16 );
}

}
2 changes: 1 addition & 1 deletion src/serializerplayerstdv14.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ SerializerPlayerStdv14::create()
namespace {
RegHolder v14 = SerializerPlayer::factory().autoReg( &SerializerPlayerStdv14::create, 14 );
RegHolder v15 = SerializerPlayer::factory().autoReg( &SerializerPlayerStdv14::create, 15 );
//RegHolder v16 = SerializerPlayer::factory().autoReg( &SerializerPlayerStdv14::create, 16 );
RegHolder v16 = SerializerPlayer::factory().autoReg( &SerializerPlayerStdv14::create, 16 );
}

}
88 changes: 75 additions & 13 deletions src/serverparam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,24 @@ lcm( int a,
return tmp;
}


std::string
check_teamname_format( std::string name )
{
if ( name.empty() ) return name;

const std::string available_chars = "+-_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

if ( name.find_first_not_of( available_chars ) != std::string::npos )
{
return std::string( "" );
}

if ( name.length() > 15 ) name.resize( 15 );

return name;
}

}


Expand Down Expand Up @@ -347,16 +365,16 @@ const bool ServerParam::GOLDEN_GOAL = false; // [15.0.0] true -> false
// 15.0.0
const double ServerParam::RED_CARD_PROBABILITY = 0.0;

// XXX
const double ServerParam::LONG_KICK_POWER_FACTOR = 2.0;
const int ServerParam::LONG_KICK_DELAY = 2;

// 16.0.0
const int ServerParam::ILLEGAL_DEFENSE_DURATION = 20;
const int ServerParam::ILLEGAL_DEFENSE_NUMBER = 0;
const double ServerParam::ILLEGAL_DEFENSE_DIST_X = 16.5;
const double ServerParam::ILLEGAL_DEFENSE_WIDTH = 40.32;

// XXX
const double ServerParam::LONG_KICK_POWER_FACTOR = 2.0;
const int ServerParam::LONG_KICK_DELAY = 2;

ServerParam &
ServerParam::instance()
{
Expand Down Expand Up @@ -912,16 +930,25 @@ ServerParam::addParams()
rcss::conf::makeGetter( M_red_card_probability ),
"", 15 );

// XXX
// addParam( "random_seed", M_random_seed, "", 999 );
// addParam( "long_kick_power_factor", M_long_kick_power_factor, "", 999 );
// addParam( "long_kick_delay", M_long_kick_delay, "", 999 );

// v16
addParam( "illegal_defense_duration", M_illegal_defense_duration, "", 16);
addParam( "illegal_defense_number", M_illegal_defense_number, "if be 0, illegal defense rule will be disable", 16);
addParam( "illegal_defense_dist_x", M_illegal_defense_dist_x, "", 16);
addParam( "illegal_defense_width", M_illegal_defense_width, "", 16);
addParam( "fixed_teamname_l",
rcss::conf::makeSetter( this, &ServerParam::setFixedTeamNameLeft ),
rcss::conf::makeGetter( M_fixed_teamname_l ),
"", 16 );
addParam( "fixed_teamname_r",
rcss::conf::makeSetter( this, &ServerParam::setFixedTeamNameRight ),
rcss::conf::makeGetter( M_fixed_teamname_r ),
"", 16 );

// XXX
// addParam( "random_seed", M_random_seed, "", 999 );
// addParam( "long_kick_power_factor", M_long_kick_power_factor, "", 999 );
// addParam( "long_kick_delay", M_long_kick_delay, "", 999 );


}

Expand Down Expand Up @@ -1108,6 +1135,39 @@ ServerParam::setRedCardProbability( double value )
M_red_card_probability = std::max( 0.0, std::min( value, 1.0 ) );
}


void
ServerParam::setFixedTeamNameLeft( std::string name )
{
name = check_teamname_format( name );

if ( ! M_fixed_teamname_r.empty()
&& name == M_fixed_teamname_r )
{
std::cerr << "Could not set server::fixed_teamname_l='" << name
<< "'. The same name is already set to server::fixed_teamname_r." << std::endl;
return;
}

M_fixed_teamname_l = name;
}

void
ServerParam::setFixedTeamNameRight( std::string name )
{
name = check_teamname_format( name );

if ( ! M_fixed_teamname_l.empty()
&& name == M_fixed_teamname_l )
{
std::cerr << "Could not set server::fixed_teamname_r='" << name
<< "'. The same name is already assigned to server::fixed_teamname_r." << std::endl;
return;
}

M_fixed_teamname_r = name;
}

void
ServerParam::clear()
{
Expand Down Expand Up @@ -1379,15 +1439,17 @@ ServerParam::setDefaults()
// 15.0.0
M_red_card_probability = RED_CARD_PROBABILITY;

// XXX
M_long_kick_power_factor = LONG_KICK_POWER_FACTOR;
M_long_kick_delay = LONG_KICK_DELAY;

// 16.0.0
M_illegal_defense_duration = ILLEGAL_DEFENSE_DURATION;
M_illegal_defense_number = ILLEGAL_DEFENSE_NUMBER;
M_illegal_defense_dist_x = ILLEGAL_DEFENSE_DIST_X;
M_illegal_defense_width = ILLEGAL_DEFENSE_WIDTH;
M_fixed_teamname_l = "";
M_fixed_teamname_r = "";

// XXX
M_long_kick_power_factor = LONG_KICK_POWER_FACTOR;
M_long_kick_delay = LONG_KICK_DELAY;

setHalfTime( HALF_TIME );
setExtraHalfTime( EXTRA_HALF_TIME );
Expand Down
23 changes: 15 additions & 8 deletions src/serverparam.h
Original file line number Diff line number Diff line change
Expand Up @@ -609,15 +609,17 @@ class ServerParam {
// 15.0.0
double M_red_card_probability;

// XXX
double M_long_kick_power_factor;
int M_long_kick_delay;

// 16.0.0
int M_illegal_defense_duration;
int M_illegal_defense_number;
double M_illegal_defense_dist_x;
double M_illegal_defense_width;
std::string M_fixed_teamname_l;
std::string M_fixed_teamname_r;

// XXX
double M_long_kick_power_factor;
int M_long_kick_delay;

private:

Expand Down Expand Up @@ -656,6 +658,9 @@ class ServerParam {
void setFoulDetectProbability( double value );
void setRedCardProbability( double value );

void setFixedTeamNameLeft( std::string name );
void setFixedTeamNameRight( std::string name );

void setSlowDownFactor();

public:
Expand Down Expand Up @@ -957,16 +962,18 @@ class ServerParam {
// v15
double redCardProbability() const { return M_red_card_probability; }

// XXX
double longKickPowerFactor() const { return M_long_kick_power_factor; }
int longKickDelay() const { return M_long_kick_delay; }

// v16
bool useIllegalDefense() const { return M_illegal_defense_number != 0; }
int illegalDefenseDuration() const { return M_illegal_defense_duration; }
int illegalDefenseNumber() const { return M_illegal_defense_number; }
double illegalDefenseDistX() const { return M_illegal_defense_dist_x; }
double illegalDefenseWidth() const { return M_illegal_defense_width; }
const std::string & fixedTeamNameLeft() const { return M_fixed_teamname_l; }
const std::string & fixedTeamNameRight() const { return M_fixed_teamname_r; }

// XXX
double longKickPowerFactor() const { return M_long_kick_power_factor; }
int longKickDelay() const { return M_long_kick_delay; }

};

Expand Down
Loading

0 comments on commit 630667b

Please sign in to comment.