00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
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
00048 children.push_back(skill);
00049 return true;
00050 }
00051
00052 for (unsigned int i = 0; i < children.size(); i++) {
00053
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
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
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
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
00098 if (children[i]->deleteSkill(ident))
00099 return true;
00100 }
00101 }
00102 return false;
00103 }
00104