00001
00011 #ifndef __OBJECTAGENT__H__
00012 #define __OBJECTAGENT__H__
00013
00014 #include <wx/wx.h>
00015 #include <wx/colour.h>
00016
00017 #include "../common.h"
00018 #include "../gui/Image.h"
00019 #include "../tinyxml/tinyxml.h"
00020 #include "Object.h"
00021 #include "ObjectTrail.h"
00022 #include "ObjectTransferable.h"
00023
00027 class ObjectAgent: public Object {
00028 private:
00029
00030 friend class Interpreter;
00031
00032 public:
00036 class Behavior {
00037 private:
00039 string script;
00040
00041 public:
00045 explicit Behavior(const string & behaviorScript);
00046
00050 Behavior();
00051
00056 const string & GetBehavior() const {
00057 return script;
00058 }
00059
00063 void ChangeBehavior(string newBehavior) {
00064 script = newBehavior;
00065 }
00066
00070 static string CreateDefaultScriptTemplate();
00071 };
00072
00073 public:
00077 class Config: public Object::Config {
00078 public:
00094 Config(const string & imageFile, const Direction & objectDirection, const Action & objectAction,
00095 const string & objectName, const string & objectDescription,
00096 ObjectTransferable::Config * carryingObjectConfig, const string & trailImageFileName,
00097 const ObjectTrail::DurationSize & trailDuration, ObjectAgent::Behavior behavior):
00098 Object::Config(imageFile, objectDirection, objectAction, objectName, objectDescription),
00099 carryingObjConfig(carryingObjectConfig), trailImage(trailImageFileName),
00100 trailDurat(trailDuration), agentBehavior(behavior)
00101 {}
00102
00106 explicit Config(TiXmlElement * node);
00107
00111 virtual ~Config() {
00112 delete carryingObjConfig;
00113 }
00114
00120 virtual void ShowEditationWindow(wxWindow * parent, bool waitUntilClosed = true);
00121
00125 virtual TiXmlElement * CreateXmlNode() const;
00126
00130 const ObjectTransferable::Config * GetCarryingObjectConfig() const {
00131 return carryingObjConfig;
00132 }
00133
00137 virtual const string & GetObjectClassName() const {
00138 return CLASS_NAME;
00139 }
00140
00144 const string & GetTrailImageFileName() const {
00145 return trailImage.GetImageFileName();
00146 }
00147
00152 void ChangeTrailImage(const string & newTrailImageFileName) {
00153 trailImage.ChangeImage(newTrailImageFileName);
00154 }
00155
00159 ObjectTrail::DurationSize GetTrailDuration() const {
00160 return trailDurat;
00161 }
00162
00167 void SetTrailDuration(ObjectTrail::DurationSize newDuration) {
00168 trailDurat = newDuration;
00169 }
00170
00174 static ObjectTrail::DurationSize GetDurationSizeMin() {
00175 return ObjectTrail::GetDurationSizeMin();
00176 }
00177
00181 static ObjectTrail::DurationSize GetDurationSizeMax() {
00182 return ObjectTrail::GetDurationSizeMax();
00183 }
00184
00188 const ObjectAgent::Behavior & GetBehavior() const {
00189 return agentBehavior;
00190 }
00191
00196 void ChangeBehavior(const ObjectAgent::Behavior & newBehavior) {
00197 agentBehavior.ChangeBehavior(newBehavior.GetBehavior());
00198 }
00199
00205 virtual const wxColour * GetObjectTextColour() const {
00206 return wxBLUE;
00207 }
00208
00209 private:
00211 ObjectTransferable::Config * carryingObjConfig;
00213 GUI::Image trailImage;
00215 ObjectTrail::DurationSize trailDurat;
00217 ObjectAgent::Behavior agentBehavior;
00218 };
00219
00220
00221 public:
00226 ObjectAgent(const ObjectAgent::Config & config);
00227
00231 virtual ~ObjectAgent() {}
00232
00237 virtual void Collision(Object * collisionObject);
00238
00245 virtual Object::Config * CreateObjectConfig() const;
00246
00256 virtual void LoadFromConfig(const Object::Config & config, bool fullLoad = true);
00257
00264 virtual void SetAction(const Action & newAction) {
00265 action.SetAction(newAction.GetAction());
00266 }
00267
00273 virtual void SetDirection(const Direction & newDirection) {
00274 direction.SetDirection(newDirection.GetDirection());
00275 }
00276
00280 virtual const Priority & GetPriority() const {
00281 return ObjectAgent::PRIORITY;
00282 }
00283
00288 virtual bool CanAppearMoreThenOnce() const {
00289 return ObjectAgent::CAN_APPEAR_MORE_THEN_ONCE;
00290 }
00291
00296 virtual const string & GetClassName() const {
00297 return ObjectAgent::CLASS_NAME;
00298 }
00299
00303 virtual void ChooseNextAction() {
00304 if (nextActionSet) {
00305 nextActionSet = false;
00306 }
00307 else {
00308 Interpret();
00309 }
00310 }
00311
00316 virtual bool IsImaginary() const {
00317 return false;
00318 }
00319
00323 virtual bool IsEditableByUser() const {
00324 return true;
00325 }
00326
00330 virtual bool IsMoveableByUser() const {
00331 return true;
00332 }
00333
00337 bool HasObject() const {
00338 return (carryingObject != 0);
00339 }
00340
00345 void TakeObject(ObjectTransferable * object) {
00346 if (carryingObject != 0) {
00347 THROW(ExceptionObjectBadAction, "Agent " + GetObjectName() + " is carrying object already.");
00348 }
00349 carryingObject = object;
00350 }
00351
00356 ObjectTransferable * DropObject() {
00357 if (carryingObject == 0) {
00358 THROW(ExceptionObjectBadAction, "Agent " + GetObjectName() + " is not carrying object to drop.");
00359 }
00360 ObjectTransferable * object = carryingObject;
00361 carryingObject = 0;
00362 return object;
00363 }
00364
00369 string GetBehavior() const {
00370 return behavior.GetBehavior();
00371 }
00372
00376 void ChangeBehavior(const string &newBehavior) {
00377 behavior.ChangeBehavior(newBehavior);
00378 }
00379
00383 const string & GetTrailImageFileName() const {
00384 return trailImage.GetImageFileName();
00385 }
00386
00390 ObjectTrail::DurationSize GetTrailDuration() const {
00391 return trailDuration;
00392 }
00393
00397 bool IsPuttingTrail() const {
00398 return (GetTrailDuration() != 0);
00399 }
00400
00401 private:
00406 void Interpret();
00407
00412 void Interpret(string type);
00413
00415
00419 bool SimkinHasObject() const {
00420 return (carryingObject != 0);
00421 }
00422
00427 bool SimkinTakeObject() {
00428 if (carryingObject != 0) {
00429 return false;
00430 }
00431 action.SetAction(Action::TAKE_OBJECT);
00432 return true;
00433 }
00434
00439 bool SimkinDropObject() {
00440 if (carryingObject == 0) {
00441 return false;
00442 }
00443 action.SetAction(Action::DROP_OBJECT);
00444 return true;
00445 }
00446
00450 void SimkinTurnLeft() {
00451 action.SetAction(Action::TURN_LEFT);
00452 }
00453
00457 void SimkinTurnRight() {
00458 action.SetAction(Action::TURN_RIGHT);
00459 }
00460
00464 void SimkinTurnBack() {
00465 action.SetAction(Action::TURN_BACK);
00466 }
00467
00471 void SimkinGo() {
00472 action.SetAction(Action::GO);
00473 }
00474
00478 void RandomAction();
00479
00480 public:
00482 static const string CLASS_NAME;
00483
00484 private:
00486 ObjectTransferable * carryingObject;
00488 GUI::Image trailImage;
00490 ObjectTrail::DurationSize trailDuration;
00492 static const Object::Priority PRIORITY;
00494 static const bool CAN_APPEAR_MORE_THEN_ONCE;
00496 static const int AGENT_MOVEMENT_ACTIONS = Object::Action::TURN_BACK - Object::Action::FIRST_ACTION;
00498 bool nextActionSet;
00500 Behavior behavior;
00501 };
00502
00503
00504 #endif
00505
00506