Skip to content

Commit

Permalink
Added loading/saving of current skill node location.
Browse files Browse the repository at this point in the history
Ref #389
  • Loading branch information
Yohann Ferreira committed Aug 4, 2017
1 parent cd713ad commit 3ae96b9
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 18 deletions.
6 changes: 3 additions & 3 deletions data/config/skill_graph.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
skill_graph_start = {
-- Character id; node id
[BRONANN] = 0,
[KALYA] = 0,
[SYLVE] = 0,
[THANIS] = 0,
[KALYA] = 1,
[SYLVE] = 2,
[THANIS] = 3,
}


Expand Down
33 changes: 28 additions & 5 deletions src/common/global/global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1236,6 +1236,23 @@ void GameGlobal::_SaveCharacter(WriteScriptDescriptor &file, GlobalCharacter *ch
}
file.WriteLine("\n\t\t},");

// Write out the character's obtained skill nodes.
file.InsertNewLine();
file.WriteLine("\t\tobtained_skill_nodes = {");
const std::vector<uint32_t>& skill_nodes = character->GetObtainedSkillNodes();
for(uint32_t i = 0; i < skill_nodes.size(); i++) {
uint32_t skill_node = skill_nodes.at(i);

if(i == 0)
file.WriteLine("\t\t\t", false);
else
file.WriteLine(", ", false);
bool newline = (i > 0) && !(i % 10);
file.WriteLine(NumberToString(skill_node), newline);
}
file.WriteLine("\n\t\t},");
file.WriteLine("\t\tcurrent_skill_node = " + NumberToString(character->GetSkillNodeLocation()) + ",");

// Writes active status effects at the time of the save
file.InsertNewLine();
file.WriteLine("\t\tactive_status_effects = {");
Expand All @@ -1258,9 +1275,7 @@ void GameGlobal::_SaveCharacter(WriteScriptDescriptor &file, GlobalCharacter *ch
file.WriteLine("\t}");
else
file.WriteLine("\t},");
} // void GameGlobal::_SaveCharacter(WriteScriptDescriptor& file, GlobalCharacter* character, bool last)


}

void GameGlobal::_SaveEvents(WriteScriptDescriptor &file, GlobalEventGroup *event_group)
{
Expand Down Expand Up @@ -1293,7 +1308,6 @@ void GameGlobal::_SaveEvents(WriteScriptDescriptor &file, GlobalEventGroup *even
++i;
}
file.WriteLine("\n\t},");

}

void GameGlobal::_SaveQuests(WriteScriptDescriptor &file, const QuestLogEntry *quest_log_entry)
Expand All @@ -1319,7 +1333,6 @@ void GameGlobal::_SaveQuests(WriteScriptDescriptor &file, const QuestLogEntry *q
file.WriteLine("\"" + is_read + "\"", false);
// End writing
file.WriteLine("},");

}

void GameGlobal::_SaveWorldMap(vt_script::WriteScriptDescriptor &file)
Expand Down Expand Up @@ -1562,6 +1575,16 @@ void GameGlobal::_LoadCharacter(ReadScriptDescriptor &file, uint32_t id)
character->AddSkill(skill_ids[i]);
}

// Read the character's obtained skill nodes
character->ResetObtainedSkillNodes();
std::vector<uint32_t> skill_node_ids;
file.ReadTableKeys("obtained_skill_nodes", skill_node_ids);
character->SetObtainedSkillNodes(skill_node_ids);

// Read the current skill node location
uint32_t default_character_location = _skill_graph.GetStartingSkillNodeId(character->GetID());
character->SetSkillNodeLocation(file.ReadUInt("current_skill_node", default_character_location));

// Read the character's active status effects data
character->ResetActiveStatusEffects();
std::vector<int32_t> status_effects_ids;
Expand Down
49 changes: 44 additions & 5 deletions src/common/global/global_actors.h
Original file line number Diff line number Diff line change
Expand Up @@ -988,12 +988,44 @@ class GlobalCharacter : public GlobalActor
return &_special_skills;
}

//! The permanent skills are saved between two game sessions.
//! \brief The permanent skills are saved between two game sessions.
//! whereas the equipment skills are reloaded through equipment.
std::vector<uint32_t>& GetPermanentSkills() {
return _permanent_skills;
}

//! \brief Returns the skill nodes learned
const std::vector<uint32_t>& GetObtainedSkillNodes() const {
return _obtained_skill_nodes;
}

//! \brief reset the skill nodes learned
void ResetObtainedSkillNodes() {
_obtained_skill_nodes.clear();
}

//! \brief Set the skill nodes learned
void SetObtainedSkillNodes(std::vector<uint32_t>& skill_nodes) {
_obtained_skill_nodes.swap(skill_nodes);
}

//! \brief Adds a new skill nodes learned
void AddObtainedSkillNodes(uint32_t skill_node_id) {
_obtained_skill_nodes.emplace_back(skill_node_id);
// The character location is on the latest obtained skill_node_id.
SetSkillNodeLocation(skill_node_id);
}

//! \brief Set the skill nodes location
void SetSkillNodeLocation(uint32_t skill_node_id) {
_current_skill_node_id = skill_node_id;
}

//! \brief Get the skill nodes location
uint32_t GetSkillNodeLocation() const {
return _current_skill_node_id;
}

const std::vector<GLOBAL_INTENSITY>& GetEquipementStatusEffects() const {
return _equipment_status_effects;
}
Expand Down Expand Up @@ -1106,7 +1138,7 @@ class GlobalCharacter : public GlobalActor
// Skills available when no weapon is equipped.
std::vector<GlobalSkill *> _bare_hands_skills;

//! A vector storing only the skills that are permanently learned. This is useful when recomputing
//! \brief A vector storing only the skills that are permanently learned. This is useful when recomputing
//! the available skills, on equip/unequip.
std::vector<uint32_t> _permanent_skills;
//@}
Expand Down Expand Up @@ -1224,7 +1256,7 @@ class GlobalCharacter : public GlobalActor
*** experience level growth easier.
***
**/
int32_t _experience_for_next_level;
int32_t _experience_for_next_level; // TODO: Drop this using skill nodes

/** \brief The amount of growth that should be added to each of the character's stats
*** These members are incremented by the _ProcessPeriodicGrowth() function, which detects when a character
Expand All @@ -1244,7 +1276,7 @@ class GlobalCharacter : public GlobalActor
uint32_t _mag_def_growth;
uint32_t _stamina_growth;
float _evade_growth;
//@}
//@} // TODO: Drop this using skill nodes

/** \brief Contains pointers to all skills that were learned by achieving the current experience level
***
Expand All @@ -1262,7 +1294,14 @@ class GlobalCharacter : public GlobalActor
*** location (assuming the GlobalSkill object that was removed was also deleted). Therefore, any skills that
*** are removed from a character should also be removed from this container if they exist.
**/
std::vector<GlobalSkill*> _new_skills_learned;
std::vector<GlobalSkill*> _new_skills_learned; // TODO: Drop this using skill nodes

//! \brief Stores the list of skill nodes already learned by the character
std::vector<uint32_t> _obtained_skill_nodes;

//! \brief Stores the current skill node id the character is located at,
//! in the skill_graph
uint32_t _current_skill_node_id;

/** \brief Calculates an actor's physical and magical attack ratings
*** This function sums the actor's phys_atk/mag_atk with their weapon's attack ratings
Expand Down
34 changes: 34 additions & 0 deletions src/common/global/skill_graph/skill_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,32 @@ bool SkillGraph::Initialize(const std::string& skill_graph_file)

script.CloseTable(); // node_id
}

script.CloseTable(); // skill_graph

// Load starting positions
std::vector<uint32_t> characters_ids;
script.ReadTableKeys("skill_graph_start", characters_ids);
if (characters_ids.empty()) {
PRINT_WARNING << "Empty 'skill_graph_start' table in "
<< skill_graph_file << std::endl;
return false;
}

if (!script.OpenTable("skill_graph_start")) {
PRINT_WARNING << "Couldn't open table 'skill_graph_start' in "
<< skill_graph_file << std::endl;
return false;
}

// Read each node data
for (uint32_t character_id : characters_ids) {
uint32_t starting_node_id = script.ReadUInt(character_id);
_starting_node_ids.insert(std::pair<uint32_t, uint32_t>(character_id, starting_node_id));
}

script.CloseTable(); // skill_graph_start

return true;
}

Expand Down Expand Up @@ -129,4 +155,12 @@ SkillNode* SkillGraph::GetSkillNode(uint32_t skill_node_id)
return nullptr;
}

uint32_t SkillGraph::GetStartingSkillNodeId(uint32_t character_id) const
{
auto it = _starting_node_ids.find(character_id);
if (it == _starting_node_ids.end())
return 0; // Sane default value
return it->second;
}

} // namespace vt_global
10 changes: 10 additions & 0 deletions src/common/global/skill_graph/skill_graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,20 @@ class SkillGraph
return _skill_graph_data;
}

//! \brief Gets the character's starting skill node id.
//! \param character_id The given character id.
//! \returns the given starting skill node id
//! or uint32_t max if not found.
uint32_t GetStartingSkillNodeId(uint32_t character_id) const;

private:
//! \brief The vector of skill nodes.
std::vector<SkillNode*> _skill_graph_data;

//! \brief Contains the starting node ids per character ids.
//! Contains <character_id, skill_node_id>
std::map<uint32_t, uint32_t> _starting_node_ids;

//! \brief Read item data and add them in the skill node data
void _ReadItemsNeeded(vt_script::ReadScriptDescriptor& script,
SkillNode* skill_node);
Expand Down
8 changes: 4 additions & 4 deletions src/engine/script/script_read.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,12 @@ class ReadScriptDescriptor : public ScriptDescriptor
return _ReadData<uint32_t>(key, 0);
}

uint32_t ReadUInt(const std::string &key) {
return _ReadData<int32_t>(key, 0);
uint32_t ReadUInt(const std::string& key, uint32_t default_value = 0) {
return _ReadData<int32_t>(key, default_value);
}

uint32_t ReadUInt(int32_t key) {
return _ReadData<uint32_t>(key, 0);
uint32_t ReadUInt(int32_t key, uint32_t default_value = 0) {
return _ReadData<uint32_t>(key, default_value);
}

float ReadFloat(const std::string &key) {
Expand Down
1 change: 0 additions & 1 deletion src/modes/menu/menu_windows/menu_skillgraph_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ void SkillGraphWindow::_UpdateSkillCharacterSelectState()
_char_select.InputConfirm();
_char_select.SetCursorState(VIDEO_CURSOR_STATE_HIDDEN);


// If the character is unset, set the default node
GlobalCharacter* character =
GlobalManager->GetActiveParty()->GetCharacterAtIndex(_char_select.GetSelection());
Expand Down

0 comments on commit 3ae96b9

Please sign in to comment.