/* * Copyright (c) 2002, Stefan Farfeleder * $Id: server_util.h,v 1.2 2002/09/17 17:15:05 stefan Exp $ */ #ifndef JFK_SERVER_UTIL_H #define JFK_SERVER_UTIL_H #include #include "object_s.h" #include "objhandle.h" #ifdef HAVE_STD_COMPARE #define COMPARE(a, b, c) compare(a, b, c) #else /* broken libstdc++ has the parameters wrong */ #define COMPARE(a, b, c) compare(c, a, b) #endif namespace JFK { namespace server { /* A pair two objects, the first of which can be used like a normal pointer, * the second can save the state of the first. */ class objpair { public: objpair() {} objpair(objhandle objh); objpair(const objpair& op); void do_backup() { oh[1].assign(oh[0]); } objhandle get_backup() { return oh[1]; } object* operator->() { return oh[0].p(); } operator objhandle() { return oh[0]; } objpair& operator=(const objpair& op); private: objhandle oh[2]; }; typedef objhandle (*creator_fp)(const std::string&); struct lvlhandler { std::string name; /* or */ double* attr; /* where the attribute is stored or NULL */ creator_fp cf; /* pointer to function that creates such an object or NULL */ double min; double max; /* the value must be in [min,max] */ bool operator==(const std::string& s) const; /* used for std::find() */ }; objhandle new_obstacle(const std::string& attributes); objhandle new_item(const std::string& attributes); objhandle new_weapon(const std::string& attributes); bool name_ok(const std::string& name); } } #endif