skill.cpp

Go to the documentation of this file.
00001 /*
00002  *  The Mana World Server
00003  *  Copyright 2004 The Mana World Development Team
00004  *
00005  *  This file is part of The Mana World.
00006  *
00007  *  The Mana World  is free software; you can redistribute  it and/or modify it
00008  *  under the terms of the GNU General  Public License as published by the Free
00009  *  Software Foundation; either version 2 of the License, or any later version.
00010  *
00011  *  The Mana  World is  distributed in  the hope  that it  will be  useful, but
00012  *  WITHOUT ANY WARRANTY; without even  the implied warranty of MERCHANTABILITY
00013  *  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
00014  *  more details.
00015  *
00016  *  You should  have received a  copy of the  GNU General Public  License along
00017  *  with The Mana  World; if not, write to the  Free Software Foundation, Inc.,
00018  *  59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00019  *
00020  *  $Id: skill.cpp 3189 2007-03-14 18:18:44Z rogier_polak $
00021  */
00022 
00023 #include "skill.h"
00024 
00025 #include "utils/logger.h"
00026 
00027 Skill::Skill(const std::string &ident) :
00028     id(ident),
00029     light(0.0),
00030     dark(0.0)
00031 {
00032     //
00033 }
00034 
00035 Skill::~Skill()
00036 {
00037     //cleanup
00038     for (unsigned int i = 0; i < children.size(); i++) {
00039         if (children[i])
00040             delete children[i];
00041     }
00042 }
00043 
00044 bool Skill::addSkill(const std::string &ident, Skill *skill)
00045 {
00046     if (ident == id) {
00047         // add skill to children
00048         children.push_back(skill);
00049         return true;
00050     }
00051 
00052     for (unsigned int i = 0; i < children.size(); i++) {
00053         //recurse
00054         if (children[i]->addSkill(ident, skill))
00055             return true;
00056     }
00057     return false;
00058 }
00059 
00060 bool Skill::useSkill()
00061 {
00062 #ifdef SCRIPT_SUPPORT
00063     //run skill script
00064     LOG_ERROR("Skill: Skills not implemented.");
00065 #else
00066     LOG_ERROR("Skill: Could not use skill; scripting disabled.");
00067 #endif
00068     return true;
00069 }
00070 
00071 bool Skill::setScript(const std::string &scriptName)
00072 {
00073     return true;
00074 }
00075 
00076 bool Skill::deleteSkill(const std::string &ident, bool delTree)
00077 {
00078     //prevent deletion of self
00079     if (ident == id) {
00080         LOG_ERROR("Skill: Attempt to delete self.");
00081         return false;
00082     }
00083 
00084     for (unsigned int i = 0; i < children.size(); i++) {
00085         if (children[i]->id == ident) {
00086             if (children[i]->children.size() > 0 && delTree)
00087                 return false;
00088             else {
00089                 //delete skill & remove from children
00090                 std::vector<Skill*>::iterator tmp = children.begin() + i;
00091                 delete children[i];
00092                 children.erase(tmp);
00093 
00094                 return true;
00095             }
00096         } else {
00097             //recurse
00098             if (children[i]->deleteSkill(ident))
00099                 return true;
00100         }
00101     }
00102     return false;
00103 }
00104 

Generated on Fri Mar 30 15:39:16 2007 for TMW Server by  doxygen 1.3.9.1