refactorings

- learn_skill from unit.c to study.c
- add academy.c module
This commit is contained in:
Enno Rehling 2016-03-08 15:13:49 +01:00
parent 3d5c7ba8fb
commit 02cfacd7f8
9 changed files with 36 additions and 31 deletions

View File

@ -83,6 +83,7 @@ set (ERESSEA_SRC
spells.c
battle.c
alchemy.c
academy.c
upkeep.c
vortex.c
names.c

View File

@ -27,6 +27,7 @@ without prior permission by the authors of Eressea.
#include "console.h"
#include "reports.h"
#include "seen.h"
#include "study.h"
#include "calendar.h"
#include <kernel/config.h>

View File

@ -21,6 +21,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "xerewards.h"
#include "magic.h"
#include "study.h"
/* kernel includes */
#include <kernel/item.h>

View File

@ -1,6 +1,7 @@
#include <platform.h>
#include "xerewards.h"
#include "study.h"
#include <kernel/unit.h>
#include <kernel/item.h>

View File

@ -1129,30 +1129,6 @@ void set_number(unit * u, int count)
u->number = (unsigned short)count;
}
bool learn_skill(unit * u, skill_t sk, double learn_chance)
{
skill *sv = u->skills;
if (learn_chance < 1.0 && rng_int() % 10000 >= learn_chance * 10000)
if (!chance(learn_chance))
return false;
while (sv != u->skills + u->skill_size) {
assert(sv->weeks > 0);
if (sv->id == sk) {
if (sv->weeks <= 1) {
sk_set(sv, sv->level + 1);
}
else {
sv->weeks--;
}
return true;
}
++sv;
}
sv = add_skill(u, sk);
sk_set(sv, 1);
return true;
}
void remove_skill(unit * u, skill_t sk)
{
skill *sv = u->skills;

View File

@ -206,8 +206,6 @@ extern "C" {
void u_setfaction(struct unit *u, struct faction *f);
void set_number(struct unit *u, int count);
bool learn_skill(struct unit *u, skill_t sk, double chance);
int invisible(const struct unit *target, const struct unit *viewer);
void free_unit(struct unit *u);

View File

@ -25,6 +25,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "move.h"
#include "alchemy.h"
#include "chaos.h"
#include "study.h"
/* kernel includes */
#include <kernel/building.h>

View File

@ -25,6 +25,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "move.h"
#include "monster.h"
#include "alchemy.h"
#include "academy.h"
#include <kernel/ally.h>
#include <kernel/building.h>
@ -48,6 +49,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <util/log.h>
#include <util/parser.h>
#include <util/rand.h>
#include <util/rng.h>
#include <util/umlaut.h>
/* libc includes */
@ -58,8 +60,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <string.h>
#include <math.h>
#define TEACHNUMBER 10
static skill_t getskill(const struct locale *lang)
{
char token[128];
@ -484,9 +484,8 @@ int teach_cmd(unit * u, struct order *ord)
replace_order(&u->orders, ord, new_order);
free_order(new_order); /* parse_order & set_order have each increased the refcount */
}
if (academy && sk != NOSKILL) {
academy = academy / 30; /* anzahl gelehrter wochen, max. 10 */
learn_skill(u, sk, academy / 30.0 / TEACHNUMBER);
if (academy) {
academy_teaching_bonus(u, sk, academy);
}
return 0;
}
@ -824,3 +823,27 @@ void produceexp(struct unit *u, skill_t sk, int n)
{
produceexp_ex(u, sk, n, learn_skill);
}
bool learn_skill(unit * u, skill_t sk, double learn_chance)
{
skill *sv = u->skills;
if (learn_chance < 1.0 && rng_int() % 10000 >= learn_chance * 10000)
if (!chance(learn_chance))
return false;
while (sv != u->skills + u->skill_size) {
assert(sv->weeks > 0);
if (sv->id == sk) {
if (sv->weeks <= 1) {
sk_set(sv, sv->level + 1);
}
else {
sv->weeks--;
}
return true;
}
++sv;
}
sv = add_skill(u, sk);
sk_set(sv, 1);
return true;
}

View File

@ -33,9 +33,11 @@ extern "C" {
bool is_migrant(struct unit *u);
int study_cost(struct unit *u, skill_t talent);
bool learn_skill(struct unit *u, skill_t sk, double chance);
void produceexp(struct unit *u, skill_t sk, int n);
void produceexp_ex(struct unit *u, skill_t sk, int n, bool(*learn)(struct unit *, skill_t, double));
#define MAXTEACHERS 20
#define TEACHNUMBER 10
typedef struct teaching_info {
struct unit *teachers[MAXTEACHERS];
int value;
@ -43,6 +45,7 @@ extern "C" {
extern const struct attrib_type at_learning;
#ifdef __cplusplus
}
#endif