#include #include #include "exception.h" #include "obstacle_s.h" #include "parse.h" using namespace JFK::server; using std::string; obstacle::obstacle(int itype) : JFK::obstacle(itype) { } void obstacle::assign(const object* o) { *this = *dynamic_cast(o); } string obstacle::diffstring(const object*) const { return ""; } /* n= has to come before the points! */ void obstacle::fromstring(const string& s) { int index = 0; string arg = argument(0, s); while (arg.length() > 0) { string id = identifier(arg); if (id == "x") x = strtodbl(value(arg)); else if (id == "y") y = strtodbl(value(arg)); else if (id == "type") type = strtoint(value(arg)); else if (id == "n") p.resize(strtoint(value(arg)), point(0.0, 0.0)); else { size_t pindex = strtoint(id.substr(1, id.length() - 1)); if (pindex < p.size()) { if (id[0] == 'x') p[pindex].x = strtodbl(value(arg)); else if (id[0] == 'y') p[pindex].y = strtodbl(value(arg)); } } //else throw exception("wrong string"); better ignore... index++; arg = argument(index, s); } } void obstacle::delegate_collision(object* obj) const { obj->collide_with_obstacle(this); }