2016-11-01 17:25:52 +01:00
|
|
|
/*
|
2015-01-30 22:10:29 +01:00
|
|
|
Copyright (c) 1998-2015, Enno Rehling <enno@eressea.de>
|
2014-08-16 11:41:19 +02:00
|
|
|
Katja Zedel <katze@felidae.kn-bremen.de
|
|
|
|
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
**/
|
|
|
|
|
2017-12-30 07:34:17 +01:00
|
|
|
#ifdef _MSC_VER
|
2010-08-08 10:06:34 +02:00
|
|
|
#include <platform.h>
|
2017-12-30 07:34:17 +01:00
|
|
|
#endif
|
2010-08-08 10:06:34 +02:00
|
|
|
#include <kernel/config.h>
|
|
|
|
#include "study.h"
|
2018-02-14 20:00:48 +01:00
|
|
|
|
2016-11-16 22:46:01 +01:00
|
|
|
#include "laws.h"
|
2014-08-27 06:40:18 +02:00
|
|
|
#include "move.h"
|
2016-12-23 18:05:38 +01:00
|
|
|
#include "monsters.h"
|
2014-08-27 06:40:18 +02:00
|
|
|
#include "alchemy.h"
|
2016-03-08 15:13:49 +01:00
|
|
|
#include "academy.h"
|
2018-02-14 20:00:48 +01:00
|
|
|
#include "kernel/calendar.h"
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2017-08-21 20:18:19 +02:00
|
|
|
#include <spells/regioncurse.h>
|
|
|
|
|
2015-11-24 18:52:09 +01:00
|
|
|
#include <kernel/ally.h>
|
2018-09-29 19:32:39 +02:00
|
|
|
#include <kernel/attrib.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
#include <kernel/building.h>
|
2012-06-03 22:39:42 +02:00
|
|
|
#include <kernel/curse.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
#include <kernel/faction.h>
|
|
|
|
#include <kernel/item.h>
|
2014-06-09 18:54:48 +02:00
|
|
|
#include <kernel/messages.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
#include <kernel/order.h>
|
|
|
|
#include <kernel/plane.h>
|
|
|
|
#include <kernel/pool.h>
|
|
|
|
#include <kernel/race.h>
|
|
|
|
#include <kernel/region.h>
|
|
|
|
#include <kernel/terrain.h>
|
|
|
|
#include <kernel/unit.h>
|
|
|
|
|
|
|
|
/* util includes */
|
|
|
|
#include <util/base36.h>
|
|
|
|
#include <util/language.h>
|
2015-07-02 16:23:38 +02:00
|
|
|
#include <util/log.h>
|
2018-09-29 19:32:39 +02:00
|
|
|
#include <util/param.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
#include <util/parser.h>
|
|
|
|
#include <util/rand.h>
|
2016-03-08 15:13:49 +01:00
|
|
|
#include <util/rng.h>
|
2017-12-30 19:49:21 +01:00
|
|
|
#include <util/strings.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
#include <util/umlaut.h>
|
2017-08-21 20:18:19 +02:00
|
|
|
|
2017-01-26 18:58:29 +01:00
|
|
|
#include <selist.h>
|
2016-12-11 21:29:07 +01:00
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
/* libc includes */
|
|
|
|
#include <assert.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
2017-12-29 17:00:16 +01:00
|
|
|
#define TEACH_ALL 1
|
|
|
|
#define TEACH_FRIENDS
|
|
|
|
|
2018-07-05 20:06:32 +02:00
|
|
|
skill_t getskill(const struct locale *lang)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-12-22 16:31:10 +01:00
|
|
|
char token[128];
|
|
|
|
const char * s = gettoken(token, sizeof(token));
|
2014-09-21 16:43:17 +02:00
|
|
|
return s ? get_skill(s, lang) : NOSKILL;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
magic_t getmagicskill(const struct locale * lang)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-08-16 11:41:19 +02:00
|
|
|
void **tokens = get_translations(lang, UT_MAGIC);
|
|
|
|
variant token;
|
|
|
|
const char *s = getstrtoken();
|
|
|
|
|
|
|
|
if (tokens && s && s[0]) {
|
|
|
|
if (findtoken(*tokens, s, &token) == E_TOK_SUCCESS) {
|
|
|
|
return (magic_t)token.i;
|
|
|
|
}
|
|
|
|
else {
|
2015-10-29 09:32:31 +01:00
|
|
|
char buffer[8];
|
2014-08-16 11:41:19 +02:00
|
|
|
buffer[0] = s[0];
|
|
|
|
buffer[1] = s[1];
|
|
|
|
buffer[2] = '\0';
|
|
|
|
if (findtoken(*tokens, buffer, &token) == E_TOK_SUCCESS) {
|
|
|
|
return (magic_t)token.i;
|
|
|
|
}
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
2014-08-16 11:41:19 +02:00
|
|
|
return M_NONE;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------- */
|
2014-03-07 04:12:12 +01:00
|
|
|
/* familiars and toads are not migrants */
|
2012-06-24 07:41:07 +02:00
|
|
|
bool is_migrant(unit * u)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2016-09-19 07:02:45 +02:00
|
|
|
static int cache;
|
2016-09-20 20:27:41 +02:00
|
|
|
static const race *toad_rc;
|
2016-09-19 07:02:45 +02:00
|
|
|
|
2014-08-16 11:41:19 +02:00
|
|
|
if (u_race(u) == u->faction->race)
|
|
|
|
return false;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-08-16 11:41:19 +02:00
|
|
|
if (fval(u_race(u), RCF_UNDEAD | RCF_ILLUSIONARY))
|
|
|
|
return false;
|
|
|
|
if (is_familiar(u))
|
|
|
|
return false;
|
2016-09-19 07:02:45 +02:00
|
|
|
if (rc_changed(&cache)) {
|
|
|
|
toad_rc = get_race(RC_TOAD);
|
|
|
|
}
|
|
|
|
return u_race(u) != toad_rc;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------- */
|
2012-06-24 07:41:07 +02:00
|
|
|
bool magic_lowskill(unit * u)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2016-09-20 20:27:41 +02:00
|
|
|
static const race *toad_rc;
|
2016-09-19 07:02:45 +02:00
|
|
|
static int cache;
|
|
|
|
if (rc_changed(&cache)) {
|
|
|
|
toad_rc = get_race(RC_TOAD);
|
|
|
|
}
|
|
|
|
return u_race(u) == toad_rc;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2017-12-29 15:58:12 +01:00
|
|
|
int study_cost(struct unit *u, skill_t sk)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2017-12-29 15:58:12 +01:00
|
|
|
if (sk == SK_MAGIC) {
|
2018-09-09 15:13:20 +02:00
|
|
|
static int config;
|
|
|
|
static int cost;
|
2017-12-29 15:58:12 +01:00
|
|
|
/* Die Magiekosten betragen 50+Summe(50*Stufe) */
|
|
|
|
/* 'Stufe' ist dabei die naechste zu erreichende Stufe */
|
2018-09-09 15:13:20 +02:00
|
|
|
if (config_changed(&config)) {
|
|
|
|
cost = config_get_int("skills.cost.magic", 50);
|
|
|
|
}
|
|
|
|
if (cost > 0) {
|
|
|
|
int next_level = 1 + (u ? get_level(u, sk) : 0);
|
|
|
|
return cost * (1 + ((next_level + next_level * next_level) / 2));
|
|
|
|
}
|
|
|
|
return cost;
|
2017-12-29 15:58:12 +01:00
|
|
|
}
|
2018-09-09 15:13:20 +02:00
|
|
|
return skill_cost(sk);
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------- */
|
|
|
|
|
2018-02-09 21:20:43 +01:00
|
|
|
static void init_learning(variant *var)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2018-12-15 19:38:40 +01:00
|
|
|
var->v = calloc(1, sizeof(teaching_info));
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2018-02-09 21:20:43 +01:00
|
|
|
static void done_learning(variant *var)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2018-02-09 21:20:43 +01:00
|
|
|
teaching_info *teach = (teaching_info *)var->v;
|
2017-07-31 12:55:05 +02:00
|
|
|
selist_free(teach->teachers);
|
2018-02-09 21:20:43 +01:00
|
|
|
free(teach);
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const attrib_type at_learning = {
|
2014-08-16 11:41:19 +02:00
|
|
|
"learning",
|
2016-02-09 06:43:19 +01:00
|
|
|
init_learning, done_learning, NULL, NULL, NULL, NULL,
|
2014-08-16 11:41:19 +02:00
|
|
|
ATF_UNIQUE
|
2010-08-08 10:06:34 +02:00
|
|
|
};
|
|
|
|
|
2017-07-31 12:55:05 +02:00
|
|
|
#define EXPERIENCEDAYS 10
|
|
|
|
|
2018-07-09 03:31:13 +02:00
|
|
|
static int study_days(unit * scholar, skill_t sk)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2017-07-28 09:55:39 +02:00
|
|
|
int speed = STUDYDAYS;
|
2018-07-09 03:31:13 +02:00
|
|
|
if (u_race(scholar)->study_speed) {
|
|
|
|
speed += u_race(scholar)->study_speed[sk];
|
2017-07-28 09:55:39 +02:00
|
|
|
if (speed < STUDYDAYS) {
|
2018-07-09 03:31:13 +02:00
|
|
|
skill *sv = unit_skill(scholar, sk);
|
2014-08-16 11:41:19 +02:00
|
|
|
if (sv == 0) {
|
2017-07-28 09:55:39 +02:00
|
|
|
speed = STUDYDAYS;
|
2014-08-16 11:41:19 +02:00
|
|
|
}
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
2018-07-09 03:31:13 +02:00
|
|
|
return scholar->number * speed;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2018-07-09 03:31:13 +02:00
|
|
|
teach_unit(unit * teacher, unit * scholar, int nteaching, skill_t sk,
|
2017-09-02 03:12:02 +02:00
|
|
|
bool report, int *academy_students)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-08-16 11:41:19 +02:00
|
|
|
teaching_info *teach = NULL;
|
|
|
|
attrib *a;
|
2017-09-02 03:12:02 +02:00
|
|
|
int students;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2018-07-09 03:31:13 +02:00
|
|
|
if (magic_lowskill(scholar)) {
|
2014-08-16 11:41:19 +02:00
|
|
|
cmistake(teacher, teacher->thisorder, 292, MSG_EVENT);
|
|
|
|
return 0;
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2018-07-09 03:31:13 +02:00
|
|
|
students = scholar->number;
|
2017-09-02 03:12:02 +02:00
|
|
|
/* subtract already taught students */
|
2018-07-09 03:31:13 +02:00
|
|
|
a = a_find(scholar->attribs, &at_learning);
|
2014-08-16 11:41:19 +02:00
|
|
|
if (a != NULL) {
|
|
|
|
teach = (teaching_info *)a->data.v;
|
2017-09-02 03:12:02 +02:00
|
|
|
students -= teach->students;
|
2014-08-16 11:41:19 +02:00
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2017-12-29 19:26:20 +01:00
|
|
|
if (students > nteaching) students = nteaching;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2017-09-02 03:12:02 +02:00
|
|
|
if (students > 0) {
|
2014-08-16 11:41:19 +02:00
|
|
|
if (teach == NULL) {
|
2018-07-09 03:31:13 +02:00
|
|
|
a = a_add(&scholar->attribs, a_new(&at_learning));
|
2014-08-16 11:41:19 +02:00
|
|
|
teach = (teaching_info *)a->data.v;
|
|
|
|
}
|
2017-01-26 18:58:29 +01:00
|
|
|
selist_push(&teach->teachers, teacher);
|
2017-09-02 15:50:03 +02:00
|
|
|
teach->days += students * STUDYDAYS;
|
2017-09-02 03:12:02 +02:00
|
|
|
teach->students += students;
|
2014-08-16 11:41:19 +02:00
|
|
|
|
2018-07-09 03:31:13 +02:00
|
|
|
if (scholar->building && teacher->building == scholar->building) {
|
2016-03-07 22:40:57 +01:00
|
|
|
/* Solange Akademien groessenbeschraenkt sind, sollte Lehrer und
|
|
|
|
* Student auch in unterschiedlichen Gebaeuden stehen duerfen */
|
2017-09-02 03:12:02 +02:00
|
|
|
/* FIXME comment contradicts implementation */
|
2018-07-09 03:31:13 +02:00
|
|
|
if (academy_can_teach(teacher, scholar, sk)) {
|
2016-03-11 21:36:10 +01:00
|
|
|
/* Jeder Schueler zusaetzlich +10 Tage wenn in Uni. */
|
2017-09-02 15:50:03 +02:00
|
|
|
teach->days += students * EXPERIENCEDAYS; /* learning erhoehen */
|
2017-09-02 03:12:02 +02:00
|
|
|
/* Lehrer zusaetzlich +1 Tag pro Schueler. */
|
|
|
|
if (academy_students) {
|
|
|
|
*academy_students += students;
|
2016-03-11 21:36:10 +01:00
|
|
|
}
|
2016-03-07 22:40:57 +01:00
|
|
|
}
|
2014-08-16 11:41:19 +02:00
|
|
|
}
|
|
|
|
}
|
2017-09-02 03:12:02 +02:00
|
|
|
return students;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2017-07-31 12:56:12 +02:00
|
|
|
int teach_cmd(unit * teacher, struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-08-16 11:41:19 +02:00
|
|
|
plane *pl;
|
2017-07-31 12:56:12 +02:00
|
|
|
region *r = teacher->region;
|
2016-03-25 17:05:01 +01:00
|
|
|
skill_t sk_academy = NOSKILL;
|
2017-09-02 03:12:02 +02:00
|
|
|
int teaching, i, j, count, academy_students = 0;
|
2014-08-16 11:41:19 +02:00
|
|
|
|
2017-08-24 16:47:24 +02:00
|
|
|
if (r->attribs) {
|
|
|
|
if (get_curse(r->attribs, &ct_gbdream)) {
|
|
|
|
ADDMSG(&teacher->faction->msgs,
|
|
|
|
msg_feedback(teacher, ord, "gbdream_noteach", ""));
|
2017-08-21 20:18:19 +02:00
|
|
|
return 0;
|
2014-08-16 11:41:19 +02:00
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
2017-07-31 12:56:12 +02:00
|
|
|
if ((u_race(teacher)->flags & RCF_NOTEACH) || fval(teacher, UFL_WERE)) {
|
|
|
|
cmistake(teacher, ord, 274, MSG_EVENT);
|
2014-08-16 11:41:19 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-08-16 11:41:19 +02:00
|
|
|
pl = rplane(r);
|
|
|
|
if (pl && fval(pl, PFL_NOTEACH)) {
|
2017-07-31 12:56:12 +02:00
|
|
|
cmistake(teacher, ord, 273, MSG_EVENT);
|
2014-08-16 11:41:19 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2017-09-02 03:12:02 +02:00
|
|
|
teaching = teacher->number * TEACHNUMBER;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2017-07-31 12:56:12 +02:00
|
|
|
if ((i = get_effect(teacher, oldpotiontype[P_FOOL])) > 0) { /* Trank "Dumpfbackenbrot" */
|
2017-12-29 19:26:20 +01:00
|
|
|
if (i > teaching) i = teaching;
|
2014-08-16 11:41:19 +02:00
|
|
|
/* Trank wirkt pro Schueler, nicht pro Lehrer */
|
2017-09-02 03:12:02 +02:00
|
|
|
teaching -= i;
|
2017-07-31 12:56:12 +02:00
|
|
|
change_effect(teacher, oldpotiontype[P_FOOL], -i);
|
2017-09-02 03:12:02 +02:00
|
|
|
j = teaching;
|
2017-07-31 12:56:12 +02:00
|
|
|
ADDMSG(&teacher->faction->msgs, msg_message("teachdumb", "teacher amount", teacher, j));
|
2014-08-16 11:41:19 +02:00
|
|
|
}
|
2017-09-02 03:12:02 +02:00
|
|
|
if (teaching <= 0)
|
2014-08-16 11:41:19 +02:00
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-08-16 11:41:19 +02:00
|
|
|
count = 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2017-10-09 20:33:47 +02:00
|
|
|
init_order_depr(ord);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
#if TEACH_ALL
|
2017-07-31 12:56:12 +02:00
|
|
|
if (getparam(teacher->faction->locale) == P_ANY) {
|
2016-03-25 17:05:01 +01:00
|
|
|
skill_t sk;
|
2018-07-09 03:31:13 +02:00
|
|
|
unit *scholar;
|
2014-08-16 11:41:19 +02:00
|
|
|
skill_t teachskill[MAXSKILLS];
|
2015-10-29 16:50:55 +01:00
|
|
|
int t = 0;
|
2015-10-29 09:39:33 +01:00
|
|
|
|
2015-10-29 16:50:55 +01:00
|
|
|
do {
|
2017-07-31 12:56:12 +02:00
|
|
|
sk = getskill(teacher->faction->locale);
|
|
|
|
teachskill[t] = getskill(teacher->faction->locale);
|
2015-10-29 16:50:55 +01:00
|
|
|
} while (sk != NOSKILL);
|
2015-10-29 09:39:33 +01:00
|
|
|
|
2018-07-09 03:31:13 +02:00
|
|
|
for (scholar = r->units; teaching > 0 && scholar; scholar = scholar->next) {
|
|
|
|
if (LongHunger(scholar)) {
|
2015-10-29 09:39:33 +01:00
|
|
|
continue;
|
2015-11-21 18:13:16 +01:00
|
|
|
}
|
2018-07-09 03:31:13 +02:00
|
|
|
else if (scholar->faction == teacher->faction) {
|
|
|
|
if (getkeyword(scholar->thisorder) == K_STUDY) {
|
2014-08-16 11:41:19 +02:00
|
|
|
/* Input ist nun von student->thisorder !! */
|
2018-07-09 03:31:13 +02:00
|
|
|
init_order(scholar->thisorder, scholar->faction->locale);
|
|
|
|
sk = getskill(scholar->faction->locale);
|
2014-08-16 11:41:19 +02:00
|
|
|
if (sk != NOSKILL && teachskill[0] != NOSKILL) {
|
2015-10-29 09:39:33 +01:00
|
|
|
for (t = 0; teachskill[t] != NOSKILL; ++t) {
|
|
|
|
if (sk == teachskill[t]) {
|
2014-08-16 11:41:19 +02:00
|
|
|
break;
|
2015-10-29 09:39:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
sk = teachskill[t];
|
2014-08-16 11:41:19 +02:00
|
|
|
}
|
|
|
|
if (sk != NOSKILL
|
2018-07-09 03:31:13 +02:00
|
|
|
&& effskill_study(teacher, sk) - TEACHDIFFERENCE > effskill_study(scholar, sk)) {
|
|
|
|
teaching -= teach_unit(teacher, scholar, teaching, sk, true, &academy_students);
|
2014-08-16 11:41:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
#ifdef TEACH_FRIENDS
|
2018-07-09 03:31:13 +02:00
|
|
|
else if (alliedunit(teacher, scholar->faction, HELP_GUARD)) {
|
|
|
|
if (getkeyword(scholar->thisorder) == K_STUDY) {
|
2014-08-16 11:41:19 +02:00
|
|
|
/* Input ist nun von student->thisorder !! */
|
2018-07-09 03:31:13 +02:00
|
|
|
init_order(scholar->thisorder, scholar->faction->locale);
|
|
|
|
sk = getskill(scholar->faction->locale);
|
2014-08-16 11:41:19 +02:00
|
|
|
if (sk != NOSKILL
|
2018-07-09 03:31:13 +02:00
|
|
|
&& effskill_study(teacher, sk) - TEACHDIFFERENCE >= effskill(scholar, sk, NULL)) {
|
|
|
|
teaching -= teach_unit(teacher, scholar, teaching, sk, true, &academy_students);
|
2014-08-16 11:41:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
#endif
|
2015-10-29 09:39:33 +01:00
|
|
|
}
|
2014-08-16 11:41:19 +02:00
|
|
|
}
|
|
|
|
else
|
2010-08-08 10:06:34 +02:00
|
|
|
#endif
|
2014-08-16 11:41:19 +02:00
|
|
|
{
|
|
|
|
char zOrder[4096];
|
2015-10-29 16:36:20 +01:00
|
|
|
size_t sz = sizeof(zOrder);
|
2014-08-16 11:41:19 +02:00
|
|
|
order *new_order;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-08-16 11:41:19 +02:00
|
|
|
zOrder[0] = '\0';
|
2017-10-09 20:33:47 +02:00
|
|
|
init_order_depr(ord);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-08-16 11:41:19 +02:00
|
|
|
while (!parser_end()) {
|
2016-03-25 17:05:01 +01:00
|
|
|
skill_t sk;
|
2018-07-09 03:31:13 +02:00
|
|
|
unit *scholar;
|
2014-08-16 11:41:19 +02:00
|
|
|
bool feedback;
|
2014-12-12 21:06:47 +01:00
|
|
|
|
2018-07-09 03:31:13 +02:00
|
|
|
getunit(r, teacher->faction, &scholar);
|
2014-08-16 11:41:19 +02:00
|
|
|
++count;
|
|
|
|
|
|
|
|
/* Falls die Unit nicht gefunden wird, Fehler melden */
|
|
|
|
|
2018-07-09 03:31:13 +02:00
|
|
|
if (!scholar) {
|
2014-08-16 11:41:19 +02:00
|
|
|
char tbuf[20];
|
|
|
|
const char *uid;
|
|
|
|
const char *token;
|
|
|
|
/* Finde den string, der den Fehler verursacht hat */
|
|
|
|
parser_pushstate();
|
2017-10-09 20:33:47 +02:00
|
|
|
init_order_depr(ord);
|
2014-08-16 11:41:19 +02:00
|
|
|
|
|
|
|
for (j = 0; j != count - 1; ++j) {
|
|
|
|
/* skip over the first 'count' units */
|
2017-07-31 12:56:12 +02:00
|
|
|
getunit(r, teacher->faction, NULL);
|
2014-08-16 11:41:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
token = getstrtoken();
|
|
|
|
|
|
|
|
/* Beginne die Fehlermeldung */
|
2017-11-10 07:56:56 +01:00
|
|
|
if (isparam(token, teacher->faction->locale, P_TEMP)) {
|
2014-08-16 11:41:19 +02:00
|
|
|
token = getstrtoken();
|
2017-07-31 12:56:12 +02:00
|
|
|
sprintf(tbuf, "%s %s", LOC(teacher->faction->locale,
|
2014-08-16 11:41:19 +02:00
|
|
|
parameters[P_TEMP]), token);
|
|
|
|
uid = tbuf;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
uid = token;
|
|
|
|
}
|
2017-07-31 12:56:12 +02:00
|
|
|
ADDMSG(&teacher->faction->msgs, msg_feedback(teacher, ord, "unitnotfound_id",
|
2014-08-16 11:41:19 +02:00
|
|
|
"id", uid));
|
|
|
|
|
|
|
|
parser_popstate();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-07-09 03:31:13 +02:00
|
|
|
feedback = teacher->faction == scholar->faction
|
|
|
|
|| alliedunit(scholar, teacher->faction, HELP_GUARD);
|
2014-08-16 11:41:19 +02:00
|
|
|
|
|
|
|
/* Neuen Befehl zusammenbauen. TEMP-Einheiten werden automatisch in
|
|
|
|
* ihre neuen Nummern uebersetzt. */
|
2015-10-29 16:36:20 +01:00
|
|
|
if (zOrder[0]) {
|
|
|
|
strncat(zOrder, " ", sz - 1);
|
|
|
|
--sz;
|
|
|
|
}
|
2018-07-09 03:31:13 +02:00
|
|
|
sz -= str_strlcpy(zOrder + 4096 - sz, itoa36(scholar->no), sz);
|
2014-08-16 11:41:19 +02:00
|
|
|
|
2018-07-09 03:31:13 +02:00
|
|
|
if (getkeyword(scholar->thisorder) != K_STUDY) {
|
2017-07-31 12:56:12 +02:00
|
|
|
ADDMSG(&teacher->faction->msgs,
|
2018-07-09 03:31:13 +02:00
|
|
|
msg_feedback(teacher, ord, "teach_nolearn", "student", scholar));
|
2014-08-16 11:41:19 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-07-31 12:56:12 +02:00
|
|
|
/* Input ist nun von student->thisorder !! */
|
2014-08-16 11:41:19 +02:00
|
|
|
parser_pushstate();
|
2018-07-09 03:31:13 +02:00
|
|
|
init_order(scholar->thisorder, scholar->faction->locale);
|
|
|
|
sk = getskill(scholar->faction->locale);
|
2014-08-16 11:41:19 +02:00
|
|
|
parser_popstate();
|
|
|
|
|
|
|
|
if (sk == NOSKILL) {
|
2017-07-31 12:56:12 +02:00
|
|
|
ADDMSG(&teacher->faction->msgs,
|
2018-07-09 03:31:13 +02:00
|
|
|
msg_feedback(teacher, ord, "teach_nolearn", "student", scholar));
|
2014-08-16 11:41:19 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-07-09 03:31:13 +02:00
|
|
|
if (effskill_study(scholar, sk) > effskill_study(teacher, sk)
|
2015-08-27 16:16:55 +02:00
|
|
|
- TEACHDIFFERENCE) {
|
2014-08-16 11:41:19 +02:00
|
|
|
if (feedback) {
|
2017-07-31 12:56:12 +02:00
|
|
|
ADDMSG(&teacher->faction->msgs, msg_feedback(teacher, ord, "teach_asgood",
|
2018-07-09 03:31:13 +02:00
|
|
|
"student", scholar));
|
2014-08-16 11:41:19 +02:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (sk == SK_MAGIC) {
|
|
|
|
/* ist der Magier schon spezialisiert, so versteht er nur noch
|
|
|
|
* Lehrer seines Gebietes */
|
2018-11-18 21:47:14 +01:00
|
|
|
magic_t mage2 = unit_get_magic(scholar);
|
|
|
|
if (mage2 != M_GRAY) {
|
|
|
|
magic_t mage1 = unit_get_magic(teacher);
|
|
|
|
if (mage1 != mage2) {
|
|
|
|
if (feedback) {
|
|
|
|
ADDMSG(&teacher->faction->msgs, msg_feedback(teacher, ord,
|
|
|
|
"error_different_magic", "target", scholar));
|
|
|
|
}
|
|
|
|
continue;
|
2014-08-16 11:41:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-03-25 17:05:01 +01:00
|
|
|
sk_academy = sk;
|
2018-07-09 03:31:13 +02:00
|
|
|
teaching -= teach_unit(teacher, scholar, teaching, sk, false, &academy_students);
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
2017-07-31 12:56:12 +02:00
|
|
|
new_order = create_order(K_TEACH, teacher->faction->locale, "%s", zOrder);
|
|
|
|
replace_order(&teacher->orders, ord, new_order);
|
2014-08-16 11:41:19 +02:00
|
|
|
free_order(new_order); /* parse_order & set_order have each increased the refcount */
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
2017-09-02 03:12:02 +02:00
|
|
|
if (academy_students > 0 && sk_academy!=NOSKILL) {
|
|
|
|
academy_teaching_bonus(teacher, sk_academy, academy_students);
|
2014-08-16 11:41:19 +02:00
|
|
|
}
|
2017-10-09 20:33:47 +02:00
|
|
|
init_order_depr(NULL);
|
2014-08-16 11:41:19 +02:00
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2014-10-18 19:53:13 +02:00
|
|
|
typedef enum study_rule_t {
|
|
|
|
STUDY_DEFAULT = 0,
|
|
|
|
STUDY_FASTER = 1,
|
|
|
|
STUDY_AUTOTEACH = 2
|
|
|
|
} study_rule_t;
|
|
|
|
|
|
|
|
static double study_speedup(unit * u, skill_t s, study_rule_t rule)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-08-14 02:20:09 +02:00
|
|
|
#define MINTURN 16
|
2014-08-16 11:41:19 +02:00
|
|
|
if (turn > MINTURN) {
|
2014-10-18 19:53:13 +02:00
|
|
|
if (rule == STUDY_FASTER) {
|
2018-02-11 16:14:00 +01:00
|
|
|
double learnweeks = 0;
|
|
|
|
int i;
|
2014-08-14 02:20:09 +02:00
|
|
|
for (i = 0; i != u->skill_size; ++i) {
|
|
|
|
skill *sv = u->skills + i;
|
2015-11-21 18:13:16 +01:00
|
|
|
if (sv->id == s) {
|
2014-08-14 02:20:09 +02:00
|
|
|
learnweeks = sv->level * (sv->level + 1) / 2.0;
|
2015-10-29 08:52:51 +01:00
|
|
|
if (learnweeks < turn / 3.0) {
|
2014-08-14 02:20:09 +02:00
|
|
|
return 2.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 2.0; /* If the skill was not found it is the first study. */
|
2014-08-16 11:41:19 +02:00
|
|
|
}
|
2014-10-18 19:53:13 +02:00
|
|
|
if (rule == STUDY_AUTOTEACH) {
|
2018-02-11 16:14:00 +01:00
|
|
|
double learnweeks = 0;
|
|
|
|
int i;
|
2014-08-16 11:41:19 +02:00
|
|
|
for (i = 0; i != u->skill_size; ++i) {
|
|
|
|
skill *sv = u->skills + i;
|
2015-03-19 15:31:25 +01:00
|
|
|
learnweeks += (sv->level * (sv->level + 1) / 2.0);
|
2014-08-16 11:41:19 +02:00
|
|
|
}
|
2015-10-29 08:52:51 +01:00
|
|
|
if (learnweeks < turn / 2.0) {
|
2014-08-14 02:20:09 +02:00
|
|
|
return 2.0;
|
2014-08-16 11:41:19 +02:00
|
|
|
}
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
2014-08-16 11:41:19 +02:00
|
|
|
return 1.0;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2016-11-16 22:46:01 +01:00
|
|
|
static bool ExpensiveMigrants(void)
|
|
|
|
{
|
|
|
|
static bool rule;
|
|
|
|
static int cache;
|
|
|
|
if (config_changed(&cache)) {
|
|
|
|
rule = config_get_int("study.expensivemigrants", 0) != 0;
|
|
|
|
}
|
|
|
|
return rule;
|
|
|
|
}
|
|
|
|
|
2017-01-26 18:58:29 +01:00
|
|
|
struct teach_data {
|
|
|
|
unit *u;
|
|
|
|
skill_t sk;
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool cb_msg_teach(void *el, void *arg) {
|
|
|
|
struct teach_data *td = (struct teach_data *)arg;
|
|
|
|
unit *ut = (unit *)el;
|
|
|
|
unit * u = td->u;
|
|
|
|
skill_t sk = td->sk;
|
|
|
|
if (ut->faction != u->faction) {
|
|
|
|
bool feedback = alliedunit(u, ut->faction, HELP_GUARD);
|
|
|
|
if (feedback) {
|
|
|
|
ADDMSG(&ut->faction->msgs, msg_message("teach_teacher",
|
|
|
|
"teacher student skill level", ut, u, sk,
|
2019-02-02 20:36:23 +01:00
|
|
|
effskill(u, sk, NULL)));
|
2017-01-26 18:58:29 +01:00
|
|
|
}
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("teach_student",
|
|
|
|
"teacher student skill", ut, u, sk));
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void msg_teachers(struct selist *teachers, struct unit *u, skill_t sk) {
|
|
|
|
struct teach_data cbdata;
|
|
|
|
cbdata.sk = sk;
|
|
|
|
cbdata.u = u;
|
|
|
|
selist_foreach_ex(teachers, cb_msg_teach, &cbdata);
|
|
|
|
}
|
|
|
|
|
2018-10-28 21:27:24 +01:00
|
|
|
bool check_student(const struct unit *u, struct order *ord, skill_t sk) {
|
|
|
|
int err = 0;
|
2019-02-16 20:14:34 +01:00
|
|
|
const race *rc = u_race(u);
|
2018-10-28 21:27:24 +01:00
|
|
|
|
|
|
|
if (sk < 0) {
|
|
|
|
err = 77;
|
|
|
|
}
|
|
|
|
/* Hack: Talente mit Malus -99 koennen nicht gelernt werden */
|
2019-02-16 20:14:34 +01:00
|
|
|
else if (rc->bonus[sk] == -99) {
|
2018-10-28 21:27:24 +01:00
|
|
|
err = 771;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
static int config;
|
|
|
|
static bool learn_newskills;
|
|
|
|
|
|
|
|
if (config_changed(&config)) {
|
|
|
|
learn_newskills = config_get_int("study.newskills", 1) != 0;
|
|
|
|
}
|
|
|
|
if (!learn_newskills) {
|
|
|
|
skill *sv = unit_skill(u, sk);
|
|
|
|
if (sv == NULL) {
|
|
|
|
/* we can only learn skills we already have */
|
|
|
|
err = 771;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (err) {
|
|
|
|
if (ord) {
|
|
|
|
cmistake(u, ord, err, MSG_EVENT);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((u_race(u)->flags & RCF_NOLEARN) || fval(u, UFL_WERE)) {
|
|
|
|
if (ord) {
|
|
|
|
ADDMSG(&u->faction->msgs,
|
|
|
|
msg_feedback(u, ord, "error_race_nolearn", "race", u_race(u)));
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-07-09 13:24:21 +02:00
|
|
|
int study_cmd(unit * u, order * ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-08-16 11:41:19 +02:00
|
|
|
region *r = u->region;
|
2015-11-23 20:58:51 +01:00
|
|
|
int p;
|
2014-08-16 11:41:19 +02:00
|
|
|
int l;
|
|
|
|
int studycost, days;
|
|
|
|
double multi = 1.0;
|
|
|
|
attrib *a = NULL;
|
|
|
|
teaching_info *teach = NULL;
|
|
|
|
int money = 0;
|
|
|
|
skill_t sk;
|
|
|
|
int maxalchemy = 0;
|
2015-11-22 10:44:46 +01:00
|
|
|
int speed_rule = (study_rule_t)config_get_int("study.speedup", 0);
|
2016-10-03 20:36:46 +02:00
|
|
|
static const race *rc_snotling;
|
|
|
|
static int rc_cache;
|
|
|
|
|
|
|
|
if (rc_changed(&rc_cache)) {
|
|
|
|
rc_snotling = get_race(RC_SNOTLING);
|
|
|
|
}
|
2015-07-07 00:49:12 +02:00
|
|
|
|
2017-10-09 20:33:47 +02:00
|
|
|
(void)init_order(ord, u->faction->locale);
|
2014-08-16 11:41:19 +02:00
|
|
|
sk = getskill(u->faction->locale);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2018-10-28 21:27:24 +01:00
|
|
|
if (!check_student(u, ord, sk)) {
|
2017-12-29 15:58:12 +01:00
|
|
|
return -1;
|
2014-08-16 11:41:19 +02:00
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-08-16 11:41:19 +02:00
|
|
|
/* snotlings koennen Talente nur bis T8 lernen */
|
2016-10-03 20:36:46 +02:00
|
|
|
if (u_race(u) == rc_snotling) {
|
2014-08-16 11:41:19 +02:00
|
|
|
if (get_level(u, sk) >= 8) {
|
|
|
|
cmistake(u, ord, 308, MSG_EVENT);
|
2017-12-29 15:58:12 +01:00
|
|
|
return -1;
|
2014-08-16 11:41:19 +02:00
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2014-08-16 11:41:19 +02:00
|
|
|
p = studycost = study_cost(u, sk);
|
|
|
|
a = a_find(u->attribs, &at_learning);
|
|
|
|
if (a != NULL) {
|
|
|
|
teach = (teaching_info *)a->data.v;
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-08-16 11:41:19 +02:00
|
|
|
/* keine kostenpflichtigen Talente fuer Migranten. Vertraute sind
|
|
|
|
* keine Migranten, wird in is_migrant abgefangen. Vorsicht,
|
|
|
|
* studycost darf hier noch nicht durch Akademie erhoeht sein */
|
|
|
|
if (studycost > 0 && !ExpensiveMigrants() && is_migrant(u)) {
|
|
|
|
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_migrants_nolearn",
|
|
|
|
""));
|
2017-12-29 15:58:12 +01:00
|
|
|
return -1;
|
2014-08-16 11:41:19 +02:00
|
|
|
}
|
|
|
|
/* Akademie: */
|
2015-11-16 02:13:48 +01:00
|
|
|
if (active_building(u, bt_find("academy"))) {
|
2017-12-30 07:34:17 +01:00
|
|
|
studycost = studycost * 2;
|
|
|
|
if (studycost < 50) studycost = 50;
|
2015-07-07 00:49:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (sk == SK_MAGIC) {
|
2018-11-21 21:46:59 +01:00
|
|
|
magic_t mtype;
|
2015-07-07 00:49:12 +02:00
|
|
|
if (u->number > 1) {
|
|
|
|
cmistake(u, ord, 106, MSG_MAGIC);
|
2017-12-29 15:58:12 +01:00
|
|
|
return -1;
|
2015-07-07 00:49:12 +02:00
|
|
|
}
|
|
|
|
if (is_familiar(u)) {
|
|
|
|
/* Vertraute zaehlen nicht zu den Magiern einer Partei,
|
|
|
|
* koennen aber nur Graue Magie lernen */
|
2018-11-21 21:46:59 +01:00
|
|
|
mtype = M_GRAY;
|
2015-07-07 00:49:12 +02:00
|
|
|
}
|
|
|
|
else if (!has_skill(u, SK_MAGIC)) {
|
|
|
|
int mmax = skill_limit(u->faction, SK_MAGIC);
|
|
|
|
/* Die Einheit ist noch kein Magier */
|
|
|
|
if (count_skill(u->faction, SK_MAGIC) + u->number > mmax) {
|
|
|
|
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_max_magicians",
|
|
|
|
"amount", mmax));
|
2017-12-29 15:58:12 +01:00
|
|
|
return -1;
|
2015-07-07 00:49:12 +02:00
|
|
|
}
|
2018-11-21 21:46:59 +01:00
|
|
|
mtype = getmagicskill(u->faction->locale);
|
|
|
|
if (mtype == M_NONE || mtype == M_GRAY) {
|
2015-07-07 00:49:12 +02:00
|
|
|
/* wurde kein Magiegebiet angegeben, wird davon
|
|
|
|
* ausgegangen, dass das normal gelernt werden soll */
|
|
|
|
if (u->faction->magiegebiet != 0) {
|
2018-11-21 21:46:59 +01:00
|
|
|
mtype = u->faction->magiegebiet;
|
2015-07-07 00:49:12 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Es wurde kein Magiegebiet angegeben und die Partei
|
|
|
|
* hat noch keins gewaehlt. */
|
2018-11-21 21:46:59 +01:00
|
|
|
mtype = getmagicskill(u->faction->locale);
|
|
|
|
if (mtype == M_NONE) {
|
2015-07-07 00:49:12 +02:00
|
|
|
cmistake(u, ord, 178, MSG_MAGIC);
|
2017-12-29 15:58:12 +01:00
|
|
|
return -1;
|
2015-07-07 00:49:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-11-21 21:46:59 +01:00
|
|
|
if (mtype != u->faction->magiegebiet) {
|
2015-07-07 00:49:12 +02:00
|
|
|
/* Es wurde versucht, ein anderes Magiegebiet zu lernen
|
|
|
|
* als das der Partei */
|
|
|
|
if (u->faction->magiegebiet != 0) {
|
|
|
|
cmistake(u, ord, 179, MSG_MAGIC);
|
2017-12-29 15:58:12 +01:00
|
|
|
return -1;
|
2015-07-07 00:49:12 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Lernt zum ersten mal Magie und legt damit das
|
|
|
|
* Magiegebiet der Partei fest */
|
2018-11-21 21:46:59 +01:00
|
|
|
u->faction->magiegebiet = mtype;
|
2015-07-07 00:49:12 +02:00
|
|
|
}
|
|
|
|
}
|
2018-11-21 21:46:59 +01:00
|
|
|
create_mage(u, mtype);
|
2015-07-07 00:49:12 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* ist schon ein Magier und kein Vertrauter */
|
|
|
|
if (u->faction->magiegebiet == 0) {
|
|
|
|
/* die Partei hat noch kein Magiegebiet gewaehlt. */
|
2018-11-21 21:46:59 +01:00
|
|
|
mtype = getmagicskill(u->faction->locale);
|
|
|
|
if (mtype == M_NONE) {
|
|
|
|
mtype = getmagicskill(u->faction->locale);
|
|
|
|
if (mtype == M_NONE) {
|
2015-07-07 00:49:12 +02:00
|
|
|
cmistake(u, ord, 178, MSG_MAGIC);
|
2017-12-29 15:58:12 +01:00
|
|
|
return -1;
|
2015-07-07 00:49:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Legt damit das Magiegebiet der Partei fest */
|
2018-11-21 21:46:59 +01:00
|
|
|
u->faction->magiegebiet = mtype;
|
2015-07-07 00:49:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sk == SK_ALCHEMY) {
|
2019-02-02 20:36:23 +01:00
|
|
|
maxalchemy = effskill(u, SK_ALCHEMY, NULL);
|
2015-07-07 00:49:12 +02:00
|
|
|
if (!has_skill(u, SK_ALCHEMY)) {
|
|
|
|
int amax = skill_limit(u->faction, SK_ALCHEMY);
|
|
|
|
if (count_skill(u->faction, SK_ALCHEMY) + u->number > amax) {
|
|
|
|
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_max_alchemists",
|
|
|
|
"amount", amax));
|
2017-12-29 15:58:12 +01:00
|
|
|
return -1;
|
2015-07-07 00:49:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (studycost) {
|
|
|
|
int cost = studycost * u->number;
|
|
|
|
money = get_pooled(u, get_resourcetype(R_SILVER), GET_DEFAULT, cost);
|
2017-12-29 19:26:20 +01:00
|
|
|
if (money > cost) money = cost;
|
2015-07-07 00:49:12 +02:00
|
|
|
}
|
|
|
|
if (money < studycost * u->number) {
|
|
|
|
studycost = p; /* Ohne Univertreurung */
|
2017-12-29 19:26:20 +01:00
|
|
|
if (money > studycost) money = studycost;
|
2015-07-07 00:49:12 +02:00
|
|
|
if (p > 0 && money < studycost * u->number) {
|
|
|
|
cmistake(u, ord, 65, MSG_EVENT);
|
|
|
|
multi = money / (double)(studycost * u->number);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (teach == NULL) {
|
|
|
|
a = a_add(&u->attribs, a_new(&at_learning));
|
|
|
|
teach = (teaching_info *)a->data.v;
|
|
|
|
assert(teach);
|
2016-12-11 21:29:07 +01:00
|
|
|
teach->teachers = NULL;
|
2015-07-07 00:49:12 +02:00
|
|
|
}
|
|
|
|
if (money > 0) {
|
|
|
|
use_pooled(u, get_resourcetype(R_SILVER), GET_DEFAULT, money);
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("studycost",
|
|
|
|
"unit region cost skill", u, u->region, money, sk));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (get_effect(u, oldpotiontype[P_WISE])) {
|
2017-12-30 07:34:17 +01:00
|
|
|
l = get_effect(u, oldpotiontype[P_WISE]);
|
|
|
|
if (l > u->number) l = u->number;
|
2017-09-02 15:50:03 +02:00
|
|
|
teach->days += l * EXPERIENCEDAYS;
|
2015-07-07 00:49:12 +02:00
|
|
|
change_effect(u, oldpotiontype[P_WISE], -l);
|
|
|
|
}
|
|
|
|
if (get_effect(u, oldpotiontype[P_FOOL])) {
|
2017-12-30 07:34:17 +01:00
|
|
|
l = get_effect(u, oldpotiontype[P_FOOL]);
|
|
|
|
if (l > u->number) l = u->number;
|
2017-09-02 15:50:03 +02:00
|
|
|
teach->days -= l * STUDYDAYS;
|
2015-07-07 00:49:12 +02:00
|
|
|
change_effect(u, oldpotiontype[P_FOOL], -l);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p != studycost) {
|
|
|
|
/* ist_in_gebaeude(r, u, BT_UNIVERSITAET) == 1) { */
|
|
|
|
/* p ist Kosten ohne Uni, studycost mit; wenn
|
|
|
|
* p!=studycost, ist die Einheit zwangsweise
|
|
|
|
* in einer Uni */
|
2017-09-02 15:50:03 +02:00
|
|
|
teach->days += u->number * EXPERIENCEDAYS;
|
2015-07-07 00:49:12 +02:00
|
|
|
}
|
|
|
|
|
2017-08-21 20:48:00 +02:00
|
|
|
if (is_cursed(r->attribs, &ct_badlearn)) {
|
2017-09-02 15:50:03 +02:00
|
|
|
teach->days -= u->number * EXPERIENCEDAYS;
|
2015-07-07 00:49:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
multi *= study_speedup(u, sk, speed_rule);
|
|
|
|
days = study_days(u, sk);
|
2017-09-02 15:50:03 +02:00
|
|
|
days = (int)((days + teach->days) * multi);
|
2015-07-07 00:49:12 +02:00
|
|
|
|
|
|
|
/* the artacademy currently improves the learning of entertainment
|
|
|
|
of all units in the region, to be able to make it cumulative with
|
|
|
|
with an academy */
|
|
|
|
|
|
|
|
if (sk == SK_ENTERTAINMENT
|
|
|
|
&& buildingtype_exists(r, bt_find("artacademy"), false)) {
|
|
|
|
days *= 2;
|
|
|
|
}
|
|
|
|
|
2016-03-12 22:37:33 +01:00
|
|
|
learn_skill(u, sk, days);
|
2015-07-07 00:49:12 +02:00
|
|
|
if (a != NULL) {
|
2017-01-26 18:58:29 +01:00
|
|
|
if (teach->teachers) {
|
|
|
|
msg_teachers(teach->teachers, u, sk);
|
2015-07-07 00:49:12 +02:00
|
|
|
}
|
|
|
|
a_remove(&u->attribs, a);
|
|
|
|
a = NULL;
|
|
|
|
}
|
2016-11-16 22:46:01 +01:00
|
|
|
u->flags |= (UFL_LONGACTION | UFL_NOTMOVING);
|
2015-07-07 00:49:12 +02:00
|
|
|
|
|
|
|
/* Anzeigen neuer Traenke */
|
|
|
|
/* Spruchlistenaktualiesierung ist in Regeneration */
|
|
|
|
|
|
|
|
if (sk == SK_ALCHEMY) {
|
|
|
|
faction *f = u->faction;
|
2019-02-02 20:36:23 +01:00
|
|
|
int skill = effskill(u, SK_ALCHEMY, NULL);
|
2015-07-07 00:49:12 +02:00
|
|
|
if (skill > maxalchemy) {
|
2018-01-12 09:17:01 +01:00
|
|
|
show_potions(f, skill);
|
2015-07-07 00:49:12 +02:00
|
|
|
}
|
|
|
|
}
|
2018-11-17 21:24:59 +01:00
|
|
|
init_order(NULL, NULL);
|
2015-07-07 00:49:12 +02:00
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
2016-03-08 14:09:22 +01:00
|
|
|
|
2016-03-24 22:31:07 +01:00
|
|
|
static int produceexp_days(void) {
|
2016-09-23 20:36:57 +02:00
|
|
|
static int config, rule;
|
|
|
|
if (config_changed(&config)) {
|
2017-07-28 09:55:39 +02:00
|
|
|
rule = config_get_int("study.produceexp", EXPERIENCEDAYS);
|
2016-09-23 20:36:57 +02:00
|
|
|
}
|
|
|
|
return rule;
|
2016-03-08 14:09:22 +01:00
|
|
|
}
|
|
|
|
|
2016-03-24 22:31:07 +01:00
|
|
|
void produceexp_ex(struct unit *u, skill_t sk, int n, learn_fun learn)
|
2016-03-08 14:09:22 +01:00
|
|
|
{
|
2016-03-24 22:31:07 +01:00
|
|
|
assert(u && n <= u->number);
|
|
|
|
if (n > 0 && (is_monsters(u->faction) || playerrace(u_race(u)))) {
|
|
|
|
int days = produceexp_days();
|
2017-08-04 15:17:18 +02:00
|
|
|
learn(u, sk, days * n);
|
2016-03-08 14:09:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void produceexp(struct unit *u, skill_t sk, int n)
|
|
|
|
{
|
2016-03-24 22:31:07 +01:00
|
|
|
produceexp_ex(u, sk, n, learn_skill);
|
2016-03-08 14:09:22 +01:00
|
|
|
}
|
2016-03-08 15:13:49 +01:00
|
|
|
|
2016-03-09 23:20:05 +01:00
|
|
|
static learn_fun inject_learn_fun = 0;
|
|
|
|
|
|
|
|
void inject_learn(learn_fun fun) {
|
|
|
|
inject_learn_fun = fun;
|
|
|
|
}
|
2017-12-09 11:00:37 +01:00
|
|
|
|
2017-08-04 15:17:18 +02:00
|
|
|
/** days should be scaled by u->number; STUDYDAYS * u->number is one week worth of learning */
|
2016-03-12 14:52:33 +01:00
|
|
|
void learn_skill(unit *u, skill_t sk, int days) {
|
2016-03-13 19:13:58 +01:00
|
|
|
int leveldays = STUDYDAYS * u->number;
|
2016-03-12 22:37:33 +01:00
|
|
|
int weeks = 0;
|
2017-12-09 11:00:37 +01:00
|
|
|
|
2018-07-11 21:07:31 +02:00
|
|
|
if (fval(u, UFL_HUNGER)) {
|
|
|
|
days /= 2;
|
|
|
|
}
|
2018-02-03 14:16:01 +01:00
|
|
|
assert(sk >= 0 && sk < MAXSKILLS);
|
2016-03-23 11:56:17 +01:00
|
|
|
if (inject_learn_fun) {
|
|
|
|
inject_learn_fun(u, sk, days);
|
|
|
|
return;
|
|
|
|
}
|
2016-03-13 19:13:58 +01:00
|
|
|
while (days >= leveldays) {
|
2016-03-12 22:37:33 +01:00
|
|
|
++weeks;
|
2016-03-13 19:13:58 +01:00
|
|
|
days -= leveldays;
|
2016-03-12 22:37:33 +01:00
|
|
|
}
|
2016-03-13 19:13:58 +01:00
|
|
|
if (days > 0 && rng_int() % leveldays < days) {
|
2016-03-12 22:37:33 +01:00
|
|
|
++weeks;
|
|
|
|
}
|
2016-03-17 21:21:23 +01:00
|
|
|
if (weeks > 0) {
|
2017-07-31 12:55:05 +02:00
|
|
|
increase_skill(u, sk, weeks);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void reduce_skill_days(unit *u, skill_t sk, int days) {
|
|
|
|
skill *sv = unit_skill(u, sk);
|
|
|
|
if (sv) {
|
|
|
|
while (days > 0) {
|
|
|
|
if (days >= STUDYDAYS * u->number) {
|
|
|
|
reduce_skill(u, sv, 1);
|
|
|
|
days -= STUDYDAYS;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (chance (days / ((double) STUDYDAYS * u->number))) /* (rng_int() % (30 * u->number) < days)*/
|
|
|
|
reduce_skill(u, sv, 1);
|
|
|
|
days = 0;
|
|
|
|
}
|
2016-03-17 21:21:23 +01:00
|
|
|
}
|
2016-03-12 14:52:33 +01:00
|
|
|
}
|
|
|
|
}
|
2016-03-13 13:31:54 +01:00
|
|
|
|
2019-02-09 12:50:12 +01:00
|
|
|
/** Talente von Daemonen verschieben sich.
|
2016-03-13 13:31:54 +01:00
|
|
|
*/
|
|
|
|
void demon_skillchange(unit *u)
|
|
|
|
{
|
|
|
|
skill *sv = u->skills;
|
2017-12-22 19:14:01 +01:00
|
|
|
int upchance = 15, downchance = 10;
|
|
|
|
static int config;
|
|
|
|
static bool rule_hunger;
|
|
|
|
static int cfgup, cfgdown;
|
|
|
|
|
|
|
|
if (config_changed(&config)) {
|
|
|
|
rule_hunger = config_get_int("hunger.demon.skills", 0) != 0;
|
|
|
|
cfgup = config_get_int("skillchange.demon.up", 15);
|
|
|
|
cfgdown = config_get_int("skillchange.demon.down", 10);
|
|
|
|
}
|
|
|
|
if (cfgup == 0) {
|
|
|
|
/* feature is disabled */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
upchance = cfgup;
|
|
|
|
downchance = cfgdown;
|
2016-03-13 13:31:54 +01:00
|
|
|
|
|
|
|
if (fval(u, UFL_HUNGER)) {
|
|
|
|
/* hungry demons only go down, never up in skill */
|
|
|
|
if (rule_hunger) {
|
2017-12-22 19:14:01 +01:00
|
|
|
downchance = upchance;
|
2016-03-13 13:31:54 +01:00
|
|
|
upchance = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (sv != u->skills + u->skill_size) {
|
|
|
|
int roll = rng_int() % 100;
|
|
|
|
if (sv->level > 0 && roll < upchance + downchance) {
|
|
|
|
int weeks = 1 + rng_int() % 3;
|
|
|
|
if (roll < downchance) {
|
|
|
|
reduce_skill(u, sv, weeks);
|
|
|
|
if (sv->level < 1) {
|
|
|
|
/* demons should never forget below 1 */
|
|
|
|
set_level(u, sv->id, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2017-08-04 15:17:18 +02:00
|
|
|
learn_skill(u, sv->id, STUDYDAYS * u->number * weeks);
|
2016-03-13 13:31:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
++sv;
|
|
|
|
}
|
|
|
|
}
|