From ae7d86dae02844a8fc4c771f6b09110d69f81cde Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 11 Mar 2016 21:36:10 +0100 Subject: [PATCH] just a little bit of refactoring --- src/academy.c | 15 +++++++++++++++ src/academy.h | 2 +- src/study.c | 19 +++++++------------ src/util/umlaut.c | 1 - 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/academy.c b/src/academy.c index 5f948e280..60af23246 100644 --- a/src/academy.c +++ b/src/academy.c @@ -19,6 +19,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include +#include +#include #include "academy.h" #include "study.h" @@ -28,3 +31,15 @@ void academy_teaching_bonus(struct unit *u, skill_t sk, int academy) { learn_skill(u, sk, academy / 30.0 / TEACHNUMBER); } } + +bool academy_can_teach(unit *teacher, unit *student, skill_t sk) { + const struct building_type *btype = bt_find("academy"); + if (active_building(teacher, btype) && active_building(student, btype)) { + int j = study_cost(student, sk); + j = _max(50, j * 2); + /* kann Einheit das zahlen? */ + return get_pooled(student, get_resourcetype(R_SILVER), GET_DEFAULT, j) >= j; + /* sonst nehmen sie nicht am Unterricht teil */ + } + return false; +} diff --git a/src/academy.h b/src/academy.h index 49128feda..f6af93748 100644 --- a/src/academy.h +++ b/src/academy.h @@ -9,7 +9,7 @@ extern "C" { struct unit; void academy_teaching_bonus(struct unit *u, skill_t sk, int academy); - + bool academy_can_teach(struct unit *teacher, struct unit *student, skill_t sk); #ifdef __cplusplus } #endif diff --git a/src/study.c b/src/study.c index 3639eba44..a69dff705 100644 --- a/src/study.c +++ b/src/study.c @@ -230,18 +230,13 @@ teach_unit(unit * teacher, unit * student, int nteaching, skill_t sk, if (student->building && teacher->building == student->building) { /* Solange Akademien groessenbeschraenkt sind, sollte Lehrer und * Student auch in unterschiedlichen Gebaeuden stehen duerfen */ - const struct building_type *btype = bt_find("academy"); - if (active_building(teacher, btype) && active_building(student, btype)) { - int j = study_cost(student, sk); - j = _max(50, j * 2); - /* kann Einheit das zahlen? */ - if (get_pooled(student, get_resourcetype(R_SILVER), GET_DEFAULT, j) >= j) { - /* Jeder Schueler zusaetzlich +10 Tage wenn in Uni. */ - teach->value += (n / 30) * 10; /* learning erhoehen */ - /* Lehrer zusaetzlich +1 Tag pro Schueler. */ - if (academy) - *academy += n; - } /* sonst nehmen sie nicht am Unterricht teil */ + if (academy_can_teach(teacher, student, sk)) { + /* Jeder Schueler zusaetzlich +10 Tage wenn in Uni. */ + teach->value += (n / 30) * 10; /* learning erhoehen */ + /* Lehrer zusaetzlich +1 Tag pro Schueler. */ + if (academy) { + *academy += n; + } } } /* Teaching ist die Anzahl Leute, denen man noch was beibringen kann. Da diff --git a/src/util/umlaut.c b/src/util/umlaut.c index 872ad8ffd..abbd59372 100644 --- a/src/util/umlaut.c +++ b/src/util/umlaut.c @@ -171,7 +171,6 @@ void addtoken(void ** root, const char *str, variant id) ref = (tref *)malloc(sizeof(tref)); ref->ucs = ucs; - ref->node = 0; ref->node = node; ref->nexthash = tk->next[index]; tk->next[index] = ref;