Example #1
0
static void json_skill(cJSON *json, struct locale *lang) {
    cJSON *child;
    if (json->type != cJSON_Object) {
        log_error("skill for locale `%s` not a json object: %d", locale_name(lang), json->type);
        return;
    }
    for (child = json->child; child; child = child->next) {
        skill_t sk = findskill(child->string);
        if (sk != NOSKILL) {
            if (child->type == cJSON_String) {
                init_skill(lang, sk, child->valuestring);
                locale_setstring(lang, mkname("skill", skillnames[sk]), child->valuestring);
            }
            else if (child->type == cJSON_Array) {
                cJSON *entry;
                for (entry = child->child; entry; entry = entry->next) {
                    init_skill(lang, sk, entry->valuestring);
                    if (entry == child->child) {
                        locale_setstring(lang, mkname("skill", skillnames[sk]), entry->valuestring);
                    }
                }
            }
            else {
                log_error("invalid type %d for skill `%s`", child->type, child->string);
            }
        }
        else {
            log_error("unknown skill `%s` for locale `%s`", child->string, locale_name(lang));
        }
    }
}
Example #2
0
/**
 ** GM: SKILL <unit> <skill> <tage>
 ** requires: permission-key "gmskil"
 **/
static void gm_skill(const void *tnext, struct unit *u, struct order *ord)
{
  unit *to = findunit(getid());
  skill_t skill = findskill(getstrtoken(), u->faction->locale);
  int num = getint();

  if (to == NULL || rplane(to->region) != rplane(u->region)) {
    /* unknown or in another plane */
    ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "feedback_unit_not_found",
        ""));
  } else if (skill == NOSKILL || skill == SK_MAGIC || skill == SK_ALCHEMY) {
    /* unknown or not enough */
    mistake(u, ord, "unknown skill, or skill cannot be raised.");
  } else if (num < 0 || num > 30) {
    /* sanity check failed */
    mistake(u, ord, "invalid value.");
  } else {
    /* checking permissions */
    attrib *permissions = a_find(u->faction->attribs, &at_permissions);
    if (!permissions || !has_permission(permissions, atoi36("gmskil"))) {
      mistake(u, ord, "permission denied.");
    } else {
      set_level(to, skill, num);
    }
  }
}
Example #3
0
/** disable a feature.
 * features are identified by eone of:
 * 1. the keyword for their orders,
 * 2. the name of the skill they use,
 * 3. a "module.enabled" flag in the settings
 */
static void disable_feature(const char *str) {
    char name[32];
    int k;
    skill_t sk;
    sk = findskill(str);
    if (sk != NOSKILL) {
        enable_skill(sk, false);
        return;
    }
    for (k = 0; k != MAXKEYWORDS; ++k) {
        // FIXME: this loop is slow as balls.
        if (strcmp(keywords[k], str) == 0) {
            log_debug("disable keyword %s\n", str);
            enable_keyword(k, false);
            return;
        }
    }
    _snprintf(name, sizeof(name), "%s.enabled", str);
    log_info("disable feature %s\n", name);
    config_set(name, "0");
}
Example #4
0
int getskill(void)
{
    return findskill(getstr());
}