Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

action.cc

Go to the documentation of this file.
00001 /*
00002   svas_server -- virtual World Server of Svas
00003   Copyright (c) 2001, 2002 David Moreno Montero
00004  
00005  
00006   This program is free software; you can redistribute it and/or modify
00007   it under the terms of the GNU General Public License as published by
00008   the Free Software Foundation; either version 2 of the License, or
00009   (at your option) any later version.
00010  
00011   This program is distributed in the hope that it will be useful, but
00012   WITHOUT ANY WARRANTY; without even the implied warranty of
00013   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014   General Public License for more details.
00015  
00016   You should have received a copy of the GNU General Public License
00017   along with this program; if not, write to the Free Software
00018   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00019   02111-1307, USA.  
00020 
00021 */
00022 
00023 #include "action.h"
00024 #include "log.h"
00025 
00026 /**
00027  * If we drop a cylinder, we may have a message, and so at deletion of
00028  * the action, we should free memory
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 }

Generated on Mon Jun 17 19:53:43 2002 for Svas Server by doxygen1.2.16