1 ////////////////////////////////////////////////////////////////////////////////
2 //            Copyright (C) 2017 by Bertram (Valyria Tear)
3 //                         All Rights Reserved
4 //
5 // This code is licensed under the GNU GPL version 2. It is free software
6 // and you may modify it and/or redistribute it under the terms of this license.
7 // See http://www.gnu.org/copyleft/gpl.html for details.
8 ////////////////////////////////////////////////////////////////////////////////
9 
10 #include "skill_node.h"
11 
12 #include "utils/utils_common.h"
13 
14 namespace vt_global {
15 
SkillNode(uint32_t id,float x_location,float y_location,const std::string & icon_animation_filename,uint32_t experience_points_needed,int32_t skill_id_learned)16 SkillNode::SkillNode(uint32_t id,
17                      float x_location,
18                      float y_location,
19                      const std::string& icon_animation_filename,
20                      uint32_t experience_points_needed,
21                      int32_t skill_id_learned) :
22     _id(id),
23     _position(x_location, y_location),
24     _experience_points_needed(experience_points_needed),
25     _skill_id_learned(skill_id_learned)
26 {
27     if(!icon_animation_filename.empty() && !_icon_image.LoadFromAnimationScript(icon_animation_filename))
28         PRINT_WARNING << "Couldn't load animation from script: " << icon_animation_filename << std::endl;
29 }
30 
AddNeededItem(uint32_t item_id,uint32_t item_number)31 void SkillNode::AddNeededItem(uint32_t item_id, uint32_t item_number) {
32     if (item_number == 0) {
33         PRINT_WARNING << "Couldn't add 0 item number for item id: " << item_id << std::endl;
34         return;
35     }
36     _items_needed.push_back(std::pair<uint32_t, uint32_t>(item_id, item_number));
37 }
38 
AddStatUpgrade(uint32_t stat,uint32_t upgrade)39 void SkillNode::AddStatUpgrade(uint32_t stat, uint32_t upgrade) {
40     if (upgrade == 0) {
41         PRINT_WARNING << "Couldn't add 0 upgrade for stat id: " << stat << std::endl;
42         return;
43     }
44     _stats_upgrades.push_back(std::pair<uint32_t, uint32_t>(stat, upgrade));
45 }
46 
AddChildNodeLink(uint32_t node_id)47 void SkillNode::AddChildNodeLink(uint32_t node_id) {
48     // Prevent from double insertion
49     for(uint32_t cur_node_id : _children_nodes_links) {
50         if (cur_node_id == node_id) {
51             PRINT_WARNING << "Node link id: (" << node_id
52                           << ") already added: " << std::endl;
53             return;
54         }
55     }
56     _children_nodes_links.push_back(node_id);
57 }
58 
AddParentNodeLink(uint32_t node_id)59 void SkillNode::AddParentNodeLink(uint32_t node_id) {
60     // Prevent from double insertion
61     for(uint32_t cur_node_id : _parent_nodes_links) {
62         if (cur_node_id == node_id) {
63             PRINT_WARNING << "Parent node link id: (" << node_id
64                           << ") already added: " << std::endl;
65             return;
66         }
67     }
68     _parent_nodes_links.push_back(node_id);
69 }
70 
71 } // namespace vt_global
72