#include #include #include "exception.h" #include "item_s.h" #include "object_s.h" #include "parse.h" using namespace JFK::server; using std::string; item::item(int itype) : JFK::item(itype), ttl(4000) { type = itype; } void item::assign(const object* o) { *this = *dynamic_cast(o); } string item::diffstring(const object*) const { return ""; // Items stay at their position till they are killed... } /* overwrite from JFK::item to accept "reappear" too */ void item::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 == "reappear") reappear = strtoint(value(arg)); // else throw exception("wrong string"); ignore better... index++; arg = argument(index, s); } } object* item::action(double t) { if (type == GRAVE) ttl -= t; if (ttl < 0.0) suicide = true; return NULL; } void item::delegate_collision(object* obj) const { obj->collide_with_item(this); } void item::collide_with_person(const person*) { if (type != GRAVE) suicide = true; }