Skip to content

Instantly share code, notes, and snippets.

@battila7
Created May 13, 2015 08:30
Show Gist options
  • Save battila7/14896268411a85bfb899 to your computer and use it in GitHub Desktop.
Save battila7/14896268411a85bfb899 to your computer and use it in GitHub Desktop.
Robocar Server-side ID patch
// In order to make it possible to identify cars on the client side you may add the following modifications
// to the following files
// car.hpp
// Add the following function to the SmarCar object
int get_id(void)
{
return id_;
}
void set_id(int val)
{
id_ = val;
}
// add this variable to the private variables of SmartCar
int id_;
//traffic.cpp
// Modify the addCop and addGangster methods
int justine::robocar::Traffic::addCop ( CarLexer& cl )
{
std::shared_ptr<CopCar> c;
c = std::make_shared<CopCar> ( *this, cl.get_guided(), cl.get_name() );
//TODO majd ráér később inicializálni, hogy ne lassítsa a szimulációt
c->init();
cars.push_back ( c );
m_cop_cars.push_back ( c );
int id {0};
do
{
id = std::rand();
}
while ( m_smart_cars_map.find ( id ) != m_smart_cars_map.end() );
c->set_id(id);
m_smart_cars_map[id] = c;
return id;
}
int justine::robocar::Traffic::addGangster ( CarLexer& cl )
{
std::shared_ptr<SmartCar> c;
c = std::make_shared<SmartCar> ( *this, CarType::GANGSTER, cl.get_guided() );
//TODO majd ráér később inicializálni, hogy ne lassítsa a szimulációt
c->init();
cars.push_back ( c );
m_smart_cars.push_back ( c );
int id {0};
do
{
id = std::rand();
}
while ( m_smart_cars_map.find ( id ) != m_smart_cars_map.end() );
c->set_id(id);
m_smart_cars_map[id] = c;
return id;
}
//traffic.cpp
//around line 230
// in method cmd_session
// REPLACE THIS!!!:
if ( c->get_type() == CarType::GANGSTER )
{
length += std::sprintf ( data+length,
"<OK %d %u %u %u>", cl->get_id(), c->from(),
c->to_node(), c->get_step() );
// WITH THIS
if ( c->get_type() == CarType::GANGSTER )
{
length += std::sprintf ( data+length,
"<OK %d %u %u %u>", c->get_id(), c->from(),
c->to_node(), c->get_step() );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment