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>
|
2018-09-29 19:32:39 +02:00
|
|
|
#include <util/param.h>
|
|
|
|
|
2014-06-21 08:59:04 +02:00
|
|
|
#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;
|
2015-01-30 20:37:14 +01:00
|
|
|
|
2014-08-23 09:17:58 +02:00
|
|
|
if (s) {
|
2018-12-09 03:42:08 +01:00
|
|
|
char buffer[64];
|
2014-08-23 09:17:58 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-09-09 15:13:20 +02:00
|
|
|
int skill_cost(skill_t sk) {
|
|
|
|
static int config;
|
|
|
|
static int costs[MAXSKILLS];
|
2018-10-28 21:27:24 +01:00
|
|
|
int cost = -1;
|
|
|
|
|
|
|
|
assert(sk >= 0 && sk < MAXSKILLS);
|
2018-09-09 15:13:20 +02:00
|
|
|
switch (sk) {
|
|
|
|
case SK_SPY:
|
|
|
|
cost = 100;
|
|
|
|
break;
|
|
|
|
case SK_TACTICS:
|
|
|
|
case SK_HERBALISM:
|
|
|
|
case SK_ALCHEMY:
|
|
|
|
cost = 200;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
cost = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (config_changed(&config)) {
|
|
|
|
memset(costs, 0, sizeof(costs));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (costs[sk] == 0) {
|
|
|
|
char buffer[256];
|
|
|
|
sprintf(buffer, "skills.cost.%s", skillnames[sk]);
|
|
|
|
costs[sk] = config_get_int(buffer, cost);
|
|
|
|
}
|
|
|
|
if (costs[sk] >= 0) {
|
|
|
|
return costs[sk];
|
|
|
|
}
|
|
|
|
return (cost > 0) ? cost : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool expensive_skill(skill_t sk) {
|
2018-10-28 21:27:24 +01:00
|
|
|
assert(sk >= 0 && sk < MAXSKILLS);
|
2018-09-09 15:13:20 +02:00
|
|
|
return (sk == SK_MAGIC) || skill_cost(sk) > 0;
|
|
|
|
}
|