View Single Post
  #1  
Old 01-20-2015, 02:30 PM
iluvseq
Sarnak
 
Join Date: Aug 2009
Location: Somewhere
Posts: 53
Default EQEmu::GetSkillName() utility function

This patch adds a utility function to skills.h / skills.cpp to provide a lookup of skill ID -> skill name.

Currently this is only used in client.cpp Client::ShowSkillsWindow()

But it certainly could be useful in other places, such as when logging SKILLS__GAIN messages or sending client messages (I use it in my custom code to alert the client if they try to use a tradeskill that they haven't yet unlocked, for example).

Code:
diff --git a/common/skills.cpp b/common/skills.cpp
index ceb726d..c7e787f 100644
--- a/common/skills.cpp
+++ b/common/skills.cpp
@@ -55,3 +55,18 @@ bool EQEmu::IsSpecializedSkill(SkillUseTypes skill)
    return false;
  }
 }
+
+const char* EQEmu::GetSkillName(int skill)
+{
+ // this list of names must keep the same order as that in common/skills.h
+ const char* SkillName[] = {"1H Blunt","1H Slashing","2H Blunt","2H Slashing","Abjuration","Alteration","Apply Poison","Archery",
+   "Backstab","Bind Wound","Bash","Block","Brass Instruments","Channeling","Conjuration","Defense","Disarm","Disarm Traps","Divination",
+   "Dodge","Double Attack","Dragon Punch","Dual Wield","Eagle Strike","Evocation","Feign Death","Flying Kick","Forage","Hand to Hand",
+   "Hide","Kick","Meditate","Mend","Offense","Parry","Pick Lock","Piercing","Ripost","Round Kick","Safe Fall","Sense Heading",
+   "Singing","Sneak","Specialize Abjuration","Specialize Alteration","Specialize Conjuration","Specialize Divination","Specialize Evocation","Pick Pockets",
+   "Stringed Instruments","Swimming","Throwing","Tiger Claw","Tracking","Wind Instruments","Fishing","Make Poison","Tinkering","Research",
+   "Alchemy","Baking","Tailoring","Sense Traps","Blacksmithing","Fletching","Brewing","Alcohol Tolerance","Begging","Jewelry Making",
+   "Pottery","Percussion Instruments","Intimidation","Berserking","Taunt","Frenzy"};
+ return SkillName[skill];
+}
+
diff --git a/common/skills.h b/common/skills.h
index a589129..f91b561 100644
--- a/common/skills.h
+++ b/common/skills.h
@@ -268,6 +268,7 @@ typedef enum {
 namespace EQEmu {
  bool IsTradeskill(SkillUseTypes skill);
  bool IsSpecializedSkill(SkillUseTypes skill);
+ const char* GetSkillName(int skill);
 }

 #endif
diff --git a/zone/client.cpp b/zone/client.cpp
index b7d52e8..25f291a 100644
--- a/zone/client.cpp
+++ b/zone/client.cpp
@@ -4919,17 +4919,8 @@ void Client::ShowSkillsWindow()
  std::map<std::string, SkillUseTypes> Skills;
  std::map<std::string, SkillUseTypes>::iterator it;

- // this list of names must keep the same order as that in common/skills.h
- const char* SkillName[] = {"1H Blunt","1H Slashing","2H Blunt","2H Slashing","Abjuration","Alteration","Apply Poison","Archery",
-   "Backstab","Bind Wound","Bash","Block","Brass Instruments","Channeling","Conjuration","Defense","Disarm","Disarm Traps","Divination",
-   "Dodge","Double Attack","Dragon Punch","Dual Wield","Eagle Strike","Evocation","Feign Death","Flying Kick","Forage","Hand to Hand",
-   "Hide","Kick","Meditate","Mend","Offense","Parry","Pick Lock","Piercing","Ripost","Round Kick","Safe Fall","Sense Heading",
-   "Singing","Sneak","Specialize Abjuration","Specialize Alteration","Specialize Conjuration","Specialize Divination","Specialize Evocation","Pick Pockets",
-   "Stringed Instruments","Swimming","Throwing","Tiger Claw","Tracking","Wind Instruments","Fishing","Make Poison","Tinkering","Research",
-   "Alchemy","Baking","Tailoring","Sense Traps","Blacksmithing","Fletching","Brewing","Alcohol Tolerance","Begging","Jewelry Making",
-   "Pottery","Percussion Instruments","Intimidation","Berserking","Taunt","Frenzy"};
  for(int i = 0; i <= (int)HIGHEST_SKILL; i++)
-   Skills[SkillName[i]] = (SkillUseTypes)i;
+   Skills[EQEmu::GetSkillName(i)] = (SkillUseTypes)i;

  // print out all available skills
  for(it = Skills.begin(); it != Skills.end(); ++it) {
Reply With Quote