00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "action.h"
00024 #include "log.h"
00025
00026
00027
00028
00029
00030 Action::~Action(){
00031 if ((action==dropCylinder)||(action==sendMessageAction)){
00032 if (NULL!=message)
00033 delete message;
00034 }
00035 }
00036
00037
00038 Action::Action(ActionList _action=none, unsigned short int _energy=0,
00039 char _type=0, unsigned char _cylinder=0){
00040 action=_action;
00041 energy=_energy;
00042 cylinder=_cylinder;
00043 type=_type;
00044 };
00045
00046 Action::Action(unsigned short int _energy,
00047 GrowType _type){
00048 action=growTo;
00049 energy=_energy;
00050 growType=_type;
00051 }
00052
00053 Action::Action(unsigned short int _energy,
00054 MoveType _type){
00055 action=moveCylinder;
00056 energy=_energy;
00057 moveType=_type;
00058 }
00059
00060 Action::Action(double _angle, double _height, unsigned short int _energy){
00061 action=newCylinder;
00062 energy=_energy;
00063 angle=_angle;
00064 height=_height;
00065 }
00066
00067 Action::Action(unsigned char son, unsigned short int _energy){
00068 action=sendEnergy;
00069 energy=_energy;
00070 cylinder=son;
00071 }
00072
00073 Action::Action(unsigned char son, const char *creationMessage, unsigned long int messageSize_){
00074 action=dropCylinder;
00075 cylinder=son;
00076 messageSize=messageSize_;
00077 if (messageSize!=0){
00078 message=new char[messageSize];
00079 if (NULL==message)
00080 throw string("Can't Allocate Memory for a message in Action::Action(...)");
00081 memcpy(message, creationMessage, messageSize);
00082 }
00083 else
00084 message=NULL;
00085 }
00086
00087 Action::Action(unsigned long int _agentId, unsigned long int _messageSize, const char *_message){
00088 action=sendMessageAction;
00089 agentId=_agentId;
00090 messageSize=_messageSize;
00091 if (messageSize!=0){
00092 message=new char[messageSize];
00093 if (NULL==message)
00094 throw string("Can't Allocate Memory for a message in Action::Action(...)");
00095 memcpy(message, _message, messageSize);
00096 }
00097 else
00098 message=NULL;
00099 }