00001 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- 00002 00003 this file is part of rcssserver3D 00004 Fri May 9 2003 00005 Copyright (C) 2002,2003 Koblenz University 00006 Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group 00007 $Id: createeffector.cpp,v 1.3 2004/02/12 14:07:25 fruit Exp $ 00008 00009 This program is free software; you can redistribute it and/or modify 00010 it under the terms of the GNU General Public License as published by 00011 the Free Software Foundation; version 2 of the License. 00012 00013 This program is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with this program; if not, write to the Free Software 00020 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00021 */ 00022 #include "createeffector.h" 00023 #include "createaction.h" 00024 #include <oxygen/agentaspect/agentaspect.h> 00025 #include <oxygen/gamecontrolserver/actionobject.h> 00026 #include <zeitgeist/logserver/logserver.h> 00027 #include <zeitgeist/scriptserver/scriptserver.h> 00028 00029 using namespace oxygen; 00030 using namespace boost; 00031 using namespace zeitgeist; 00032 using namespace std; 00033 00034 CreateEffector::CreateEffector() : Effector() 00035 { 00036 } 00037 00038 bool CreateEffector::Realize(shared_ptr<ActionObject> action) 00039 { 00040 shared_ptr<CreateAction> createAction = 00041 shared_dynamic_cast<CreateAction>(action); 00042 00043 if (createAction.get() == 0) 00044 { 00045 GetLog()->Error() 00046 << "ERROR: (CreateEffector) cannot realize an unknown ActionObject\n"; 00047 return false; 00048 } 00049 00050 shared_ptr<AgentAspect> aspect = GetAgentAspect(); 00051 if (aspect.get() == 0) 00052 { 00053 GetLog()->Error() 00054 << "ERROR: (CreateEffector) cannot find the AgentAspect\n"; 00055 return false; 00056 } 00057 00058 // call the ruby addAgent function that has to be defined in the 00059 // simulator init script with the AgentAspect path as the 00060 // argument. This function is then responsible to construct the 00061 // remaining agent nodes 00062 string cmd = "addAgent('" + aspect->GetFullPath() + "')"; 00063 GetCore()->GetScriptServer()->Eval(cmd); 00064 00065 return true; 00066 } 00067 00068 shared_ptr<ActionObject> 00069 CreateEffector::GetActionObject(const Predicate& predicate) 00070 { 00071 if (predicate.name != GetPredicate()) 00072 { 00073 GetLog()->Error() << "ERROR: (CreateEffector) invalid predicate" 00074 << predicate.name << "\n"; 00075 return shared_ptr<ActionObject>(); 00076 } 00077 00078 // 00079 // don't care for the supplied parameters for now; the desired agent 00080 // type should be passed later on and stored in the CreateAction object 00081 // 00082 00083 return shared_ptr<CreateAction>(new CreateAction(GetPredicate())); 00084 } 00085