From aa07c550abf8dd7f60c6e3122733db48dbeef28b Mon Sep 17 00:00:00 2001 From: CTD Date: Thu, 14 Aug 2014 02:20:09 +0200 Subject: [PATCH 1/3] Auto Lehrer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Config via study.speedup (sollte in E2 und E3 schon mit dem Wert 0 in der XML stehen) Wert 1: Wenn das gerade gelernte Talent wenig Lerntage hat als 1/3 der max. möglichen (ohne Bonus wie Akademie) hat, dann gibt es die doppelten Lerntage. Entspricht etwa dem alten Lehrer Schema. Wert 2: Es werden die Lerntage aller Talente der Einheit als Vergleichswert genommen, dann aber gegen den halben maximalen Lerntagewert. Es werden niemals die Lerntage der aktuellen Stufe mit eingerechnet, sondern nur die durchschnittlichen Lerntage der bereits fertig gelernten Stufen. In E2 sollte der Lehre Befehl deaktiviert werden wenn diese Option aktiviert wird. --- src/study.c | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/src/study.c b/src/study.c index 6adae692c..be408b601 100644 --- a/src/study.c +++ b/src/study.c @@ -493,25 +493,31 @@ int teach_cmd(unit * u, struct order *ord) return 0; } -static double study_speedup(unit * u) +static double study_speedup(unit * u, skill_t s, int rule_type) { -#define MINTURN 5 /* 5 */ -#define OFSTURN 2 /* 2 */ +#define MINTURN 16 + double learnweeks = 0; + int i; if (turn > MINTURN) { - static int speed_rule = -1; - if (speed_rule < 0) { - speed_rule = get_param_int(global.parameters, "study.speedup", 0); - } - if (speed_rule == 1) { - double learn_age = OFSTURN; - int i; + if (rule_type == 1) { for (i = 0; i != u->skill_size; ++i) { skill *sv = u->skills + i; - double learn_time = sv->level * (sv->level + 1) / 2.0; - learn_age += learn_time; + if (sv->id == s){ + learnweeks = sv->level * (sv->level + 1) / 2.0; + if (learnweeks < turn / 3) { + return 2.0; + } + } } - if (learn_age < turn) { - return 2.0 - learn_age / turn; + return 2.0; /* If the skill was not found it is the first study. */ + } + if (rule_type == 2) { + for (i = 0; i != u->skill_size; ++i) { + skill *sv = u->skills + i; + learnweeks = +(sv->level * (sv->level + 1) / 2.0); + } + if (learnweeks < turn / 3) { + return 2.0; } } } @@ -531,6 +537,7 @@ int learn_cmd(unit * u, order * ord) int money = 0; skill_t sk; int maxalchemy = 0; + int speed_rule = get_param_int(global.parameters, "study.speedup", 0); static int learn_newskills = -1; if (learn_newskills < 0) { const char *str = get_param(global.parameters, "study.newskills"); @@ -539,7 +546,6 @@ int learn_cmd(unit * u, order * ord) else learn_newskills = 1; } - if ((u_race(u)->flags & RCF_NOLEARN) || fval(u, UFL_WERE)) { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_race_nolearn", "race", u_race(u))); @@ -732,7 +738,7 @@ int learn_cmd(unit * u, order * ord) teach->value -= u->number * 10; } - multi *= study_speedup(u); + multi *= study_speedup(u, sk, speed_rule); days = study_days(u, sk); days = (int)((days + teach->value) * multi); From 1c8488f2b4ca2b358538501e0a10e40183284ef0 Mon Sep 17 00:00:00 2001 From: CTD Date: Thu, 14 Aug 2014 02:21:43 +0200 Subject: [PATCH 2/3] Wenn man 1/2 schreibt sollte auch 1/2 im Code stehen. --- src/study.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/study.c b/src/study.c index be408b601..44abd2329 100644 --- a/src/study.c +++ b/src/study.c @@ -516,7 +516,7 @@ static double study_speedup(unit * u, skill_t s, int rule_type) skill *sv = u->skills + i; learnweeks = +(sv->level * (sv->level + 1) / 2.0); } - if (learnweeks < turn / 3) { + if (learnweeks < turn / 2) { return 2.0; } } From 837227f69c8b107814fd369acd367186b98e2483 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 18 Oct 2014 19:53:13 +0200 Subject: [PATCH 3/3] PR code review comments. - make study rule an enum, for easier debugging - change parameter name (it's not a type) --- src/study.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/study.c b/src/study.c index 44abd2329..f0686c766 100644 --- a/src/study.c +++ b/src/study.c @@ -493,13 +493,19 @@ int teach_cmd(unit * u, struct order *ord) return 0; } -static double study_speedup(unit * u, skill_t s, int rule_type) +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) { #define MINTURN 16 double learnweeks = 0; int i; if (turn > MINTURN) { - if (rule_type == 1) { + if (rule == STUDY_FASTER) { for (i = 0; i != u->skill_size; ++i) { skill *sv = u->skills + i; if (sv->id == s){ @@ -511,7 +517,7 @@ static double study_speedup(unit * u, skill_t s, int rule_type) } return 2.0; /* If the skill was not found it is the first study. */ } - if (rule_type == 2) { + if (rule == STUDY_AUTOTEACH) { for (i = 0; i != u->skill_size; ++i) { skill *sv = u->skills + i; learnweeks = +(sv->level * (sv->level + 1) / 2.0); @@ -537,7 +543,7 @@ int learn_cmd(unit * u, order * ord) int money = 0; skill_t sk; int maxalchemy = 0; - int speed_rule = get_param_int(global.parameters, "study.speedup", 0); + int speed_rule = (study_rule_t)get_param_int(global.parameters, "study.speedup", 0); static int learn_newskills = -1; if (learn_newskills < 0) { const char *str = get_param(global.parameters, "study.newskills");