Object.h

Go to the documentation of this file.
00001 
00011 #ifndef __OBJECT__H__
00012 #define __OBJECT__H__
00013 
00014 #include <wx/wx.h>
00015 #include <wx/colour.h>
00016 
00017 #include "../common.h"
00018 #include "../Direction.h"
00019 #include "../gui/Image.h"
00020 #include "../tinyxml/tinyxml.h"
00021 #include "../configs/EditableInWindowConfig.h"
00022 
00028 class Object {
00029 public:
00037         class Action {
00038         public:
00042                 enum Actions {
00043                         // Helping constant
00044                         FIRST_ACTION = 1,  
00045 
00046                         // All objects
00047                         WAIT = FIRST_ACTION,   
00048 
00049                         // Agent
00050                         GO,            
00051                         TURN_LEFT,     
00052                         TURN_RIGHT,    
00053                         TURN_BACK,     
00054                         TAKE_OBJECT,   
00055                         DROP_OBJECT,   
00056 
00057                         // Trail
00058                         EXPIRED_REMOVE 
00059                 };
00060 
00065                 Action(Actions action = WAIT):
00066                         currentAction(action) {}
00067 
00072                 explicit Action(int action) {
00073                         if (action < WAIT || action > EXPIRED_REMOVE) {
00074                                 THROW(ExceptionObjectBadAction, string("Action number ") +
00075                                         Conversions::ToString(action) + " is illegal.");
00076                         }
00077 
00078                         currentAction = static_cast<Actions>(action);
00079                 }
00080 
00084                 ~Action() {}
00085 
00089                 Actions GetAction() const {
00090                         return currentAction;
00091                 }
00092 
00097                 void SetAction(Actions newAction) {
00098                         currentAction = newAction;
00099                 }
00100 
00101         private:
00103                 Actions currentAction;
00104         };
00105 
00106 public:
00112         class Config: public EditableInWindowConfig {
00113         public:
00122                 Config(const string & imageFile, const Direction & objectDirection, const Object::Action & objectAction,
00123                              const string & objectName, const string & objectDescription):
00124                         direction(objectDirection), action(objectAction), image(imageFile), name(objectName),
00125                         description(objectDescription)
00126                 {}
00127 
00131                 explicit Config(TiXmlElement * node);
00132 
00136                 virtual ~Config() {}
00137 
00141                 virtual TiXmlElement * CreateXmlNode() const =0;
00142 
00146                 virtual const string & GetObjectClassName() const =0;
00147 
00151                 const Action & GetAction() const {
00152                         return action;
00153                 }
00154 
00159                 void SetAction(Action newAction) {
00160                         action = newAction;
00161                 }
00162 
00166                 const Direction & GetDirection() const {
00167                         return direction;
00168                 }
00169 
00174                 void SetDirection(Direction newDirection) {
00175                         direction = newDirection;
00176                 }
00177 
00181                 const GUI::Image & GetImage() const {
00182                         return image;
00183                 }
00184 
00189                 void ChangeImage(const string & newImageFileName) {
00190                         image.ChangeImage(newImageFileName);
00191                 }
00192 
00196                 const string & GetObjectName() const {
00197                         return name;
00198                 }
00199 
00204                 void SetObjectName(string newName) {
00205                         name = newName;
00206                 }
00207 
00211                 const string & GetObjectDescription() const {
00212                         return description;
00213                 }
00214 
00219                 void SetObjectDescription(string newDescription) {
00220                         description = newDescription;
00221                 }
00222 
00228                 virtual const wxColour * GetObjectTextColour() const =0;
00229 
00230         protected:
00232                 Direction direction;
00234                 Action action;
00235 
00236         private:
00238                 GUI::Image image;
00240                 string name;
00242                 string description;
00243         };
00244 
00245 public:
00250         Object(const Config & config):
00251                 direction(config.GetDirection()), action(config.GetAction()), image(config.GetImage()), ticketNumber(0),
00252                 name(config.GetObjectName()), description(config.GetObjectDescription())
00253         {}
00254 
00258         virtual ~Object() {}
00259 
00264         virtual void Collision(Object * collisionObject) =0;
00265 
00272         virtual Config * CreateObjectConfig() const =0;
00273 
00283         virtual void LoadFromConfig(const Object::Config & config, bool fullLoad = true);
00284 
00291         virtual void SetAction(const Action & newAction) =0;
00292 
00296         const Action & GetAction() const {
00297                 return action;
00298         }
00299 
00305         virtual void SetDirection(const Direction & newDirection) =0;
00306 
00312         void ChangeDirectionAccToAction();
00313 
00317         const Direction & GetDirection() const {
00318                 return direction;
00319         }
00320 
00329         void DrawImage(wxCoord x, wxCoord y, wxDC &dc) {
00330                 image.Draw(x, y, dc, direction);
00331         }
00332 
00339         void ScaleImage(int size) {
00340                 image.Scale(size);
00341         }
00342 
00349         typedef int Priority;
00350 
00354         virtual const Priority & GetPriority() const =0;
00355 
00360         virtual bool CanAppearMoreThenOnce() const =0;
00361 
00366         virtual const string & GetClassName() const =0;
00367 
00373         virtual void ChooseNextAction() =0;
00374 
00379         virtual bool IsImaginary() const =0;
00380 
00384         virtual bool IsEditableByUser() const =0;
00385 
00389         virtual bool IsMoveableByUser() const =0;
00390 
00394         typedef size_t TicketSize;
00395 
00400         void SetTicketNumber(TicketSize number) {
00401                 ticketNumber = number;
00402         }
00403 
00407         TicketSize GetTicketNumber() const {
00408                 return ticketNumber;
00409         }
00410 
00415         void SetObjectName(const string& newName) {
00416                 name = newName;
00417         }
00418 
00422         const string & GetObjectName() const {
00423                 return name;
00424         }
00425 
00430         void SetObjectDescription(const string & newDescription) {
00431                 description = newDescription;
00432         }
00433 
00437         const string & GetObjectDescription() const {
00438                 return description;
00439         }
00440 
00441 protected:
00447         const string & GetImageFileName() const {
00448                 return image.GetImageFileName();
00449         }
00450 
00455         void ChangeImage(const string & newImageFileName) {
00456                 image.ChangeImage(newImageFileName);
00457         }
00458 
00459 protected:
00461         Direction direction;
00463         Action action;
00464 
00465 private:
00467         GUI::Image image;
00469         TicketSize ticketNumber;
00471         string name;
00473         string description;
00474 };
00475 
00476 #endif /* #ifndef __OBJECT__H__ */
00477 
00478 /* End of file Object.h */

Generated on Sun Apr 29 11:46:10 2007 for IPP/ICP2007 by  doxygen 1.4.7