2014-06-21 08:59:04 +02:00
|
|
|
#include <platform.h>
|
|
|
|
#include <kernel/config.h>
|
|
|
|
#include "skill.h"
|
|
|
|
|
|
|
|
#include <util/umlaut.h>
|
|
|
|
#include <util/language.h>
|
|
|
|
#include <util/log.h>
|
|
|
|
#include <critbit.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
const char *skillnames[MAXSKILLS] = {
|
2015-01-30 20:37:14 +01:00
|
|
|
"alchemy",
|
|
|
|
"crossbow",
|
|
|
|
"mining",
|
|
|
|
"bow",
|
|
|
|
"building",
|
|
|
|
"trade",
|
|
|
|
"forestry",
|
|
|
|
"catapult",
|
|
|
|
"herbalism",
|
|
|
|
"magic",
|
|
|
|
"training",
|
|
|
|
"riding",
|
|
|
|
"armorer",
|
|
|
|
"shipcraft",
|
|
|
|
"melee",
|
|
|
|
"sailing",
|
|
|
|
"polearm",
|
|
|
|
"espionage",
|
|
|
|
"quarrying",
|
|
|
|
"roadwork",
|
|
|
|
"tactics",
|
|
|
|
"stealth",
|
|
|
|
"entertainment",
|
|
|
|
"weaponsmithing",
|
|
|
|
"cartmaking",
|
|
|
|
"perception",
|
|
|
|
"taxation",
|
|
|
|
"stamina",
|
|
|
|
"unarmed"
|
2014-06-21 08:59:04 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
bool skill_disabled[MAXSKILLS];
|
|
|
|
|
|
|
|
bool skill_enabled(skill_t sk) {
|
2015-10-30 12:40:48 +01:00
|
|
|
assert(sk != NOSKILL);
|
2014-06-21 08:59:04 +02:00
|
|
|
return !skill_disabled[sk];
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char * skill_key(int sk) {
|
2015-01-30 20:37:14 +01:00
|
|
|
assert(sk < MAXPARAMS && sk >= 0);
|
2014-06-21 08:59:04 +02:00
|
|
|
return skill_disabled[sk] ? 0 : mkname("skill", skillnames[sk]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void init_skill(const struct locale *lang, skill_t kwd, const char *str) {
|
|
|
|
void **tokens = get_translations(lang, UT_SKILLS);
|
|
|
|
struct critbit_tree **cb = (critbit_tree **)tokens;
|
|
|
|
add_translation(cb, str, (int)kwd);
|
|
|
|
}
|
|
|
|
|
|
|
|
void init_skills(const struct locale *lang) {
|
|
|
|
init_translations(lang, UT_SKILLS, skill_key, MAXSKILLS);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *skillname(skill_t sk, const struct locale *lang)
|
|
|
|
{
|
|
|
|
if (skill_disabled[sk]) return 0;
|
2015-01-08 20:55:29 +01:00
|
|
|
return LOC(lang, mkname("skill", skillnames[sk]));
|
2014-06-21 08:59:04 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void enable_skill(skill_t sk, bool value)
|
|
|
|
{
|
|
|
|
skill_disabled[sk] = !value;
|
|
|
|
}
|
|
|
|
|
|
|
|
skill_t findskill(const char *name)
|
|
|
|
{
|
|
|
|
skill_t i;
|
|
|
|
if (name == NULL) return NOSKILL;
|
|
|
|
if (strncmp(name, "sk_", 3) == 0) name += 3;
|
|
|
|
for (i = 0; i != MAXSKILLS; ++i) {
|
|
|
|
if (!skill_disabled[i] && strcmp(name, skillnames[i]) == 0) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NOSKILL;
|
|
|
|
}
|
|
|
|
|
|
|
|
skill_t get_skill(const char *s, const struct locale * lang)
|
|
|
|
{
|
2014-06-21 23:44:40 +02:00
|
|
|
skill_t result = NOSKILL;
|
2014-06-21 08:59:04 +02:00
|
|
|
char buffer[64];
|
2015-01-30 20:37:14 +01:00
|
|
|
|
2014-08-23 09:17:58 +02:00
|
|
|
if (s) {
|
|
|
|
char * str = transliterate(buffer, sizeof(buffer) - sizeof(int), s);
|
2014-12-12 11:28:37 +01:00
|
|
|
if (str) {
|
|
|
|
int i;
|
2015-07-12 10:35:09 +02:00
|
|
|
void * match;
|
2014-12-12 11:28:37 +01:00
|
|
|
void **tokens = get_translations(lang, UT_SKILLS);
|
|
|
|
struct critbit_tree *cb = (critbit_tree *)*tokens;
|
|
|
|
if (cb && cb_find_prefix(cb, str, strlen(str), &match, 1, 0)) {
|
|
|
|
cb_get_kv(match, &i, sizeof(int));
|
|
|
|
result = (skill_t)i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
log_warning("could not transliterate skill: %s", s);
|
2014-06-21 08:59:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|