forked from github/server
refactorings
- learn_skill from unit.c to study.c - add academy.c module
This commit is contained in:
parent
3d5c7ba8fb
commit
02cfacd7f8
|
@ -83,6 +83,7 @@ set (ERESSEA_SRC
|
||||||
spells.c
|
spells.c
|
||||||
battle.c
|
battle.c
|
||||||
alchemy.c
|
alchemy.c
|
||||||
|
academy.c
|
||||||
upkeep.c
|
upkeep.c
|
||||||
vortex.c
|
vortex.c
|
||||||
names.c
|
names.c
|
||||||
|
|
|
@ -27,6 +27,7 @@ without prior permission by the authors of Eressea.
|
||||||
#include "console.h"
|
#include "console.h"
|
||||||
#include "reports.h"
|
#include "reports.h"
|
||||||
#include "seen.h"
|
#include "seen.h"
|
||||||
|
#include "study.h"
|
||||||
#include "calendar.h"
|
#include "calendar.h"
|
||||||
|
|
||||||
#include <kernel/config.h>
|
#include <kernel/config.h>
|
||||||
|
|
|
@ -21,6 +21,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include "xerewards.h"
|
#include "xerewards.h"
|
||||||
|
|
||||||
#include "magic.h"
|
#include "magic.h"
|
||||||
|
#include "study.h"
|
||||||
|
|
||||||
/* kernel includes */
|
/* kernel includes */
|
||||||
#include <kernel/item.h>
|
#include <kernel/item.h>
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include <platform.h>
|
#include <platform.h>
|
||||||
|
|
||||||
#include "xerewards.h"
|
#include "xerewards.h"
|
||||||
|
#include "study.h"
|
||||||
|
|
||||||
#include <kernel/unit.h>
|
#include <kernel/unit.h>
|
||||||
#include <kernel/item.h>
|
#include <kernel/item.h>
|
||||||
|
|
|
@ -1129,30 +1129,6 @@ void set_number(unit * u, int count)
|
||||||
u->number = (unsigned short)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)
|
void remove_skill(unit * u, skill_t sk)
|
||||||
{
|
{
|
||||||
skill *sv = u->skills;
|
skill *sv = u->skills;
|
||||||
|
|
|
@ -206,8 +206,6 @@ extern "C" {
|
||||||
void u_setfaction(struct unit *u, struct faction *f);
|
void u_setfaction(struct unit *u, struct faction *f);
|
||||||
void set_number(struct unit *u, int count);
|
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);
|
int invisible(const struct unit *target, const struct unit *viewer);
|
||||||
void free_unit(struct unit *u);
|
void free_unit(struct unit *u);
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include "move.h"
|
#include "move.h"
|
||||||
#include "alchemy.h"
|
#include "alchemy.h"
|
||||||
#include "chaos.h"
|
#include "chaos.h"
|
||||||
|
#include "study.h"
|
||||||
|
|
||||||
/* kernel includes */
|
/* kernel includes */
|
||||||
#include <kernel/building.h>
|
#include <kernel/building.h>
|
||||||
|
|
33
src/study.c
33
src/study.c
|
@ -25,6 +25,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include "move.h"
|
#include "move.h"
|
||||||
#include "monster.h"
|
#include "monster.h"
|
||||||
#include "alchemy.h"
|
#include "alchemy.h"
|
||||||
|
#include "academy.h"
|
||||||
|
|
||||||
#include <kernel/ally.h>
|
#include <kernel/ally.h>
|
||||||
#include <kernel/building.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/log.h>
|
||||||
#include <util/parser.h>
|
#include <util/parser.h>
|
||||||
#include <util/rand.h>
|
#include <util/rand.h>
|
||||||
|
#include <util/rng.h>
|
||||||
#include <util/umlaut.h>
|
#include <util/umlaut.h>
|
||||||
|
|
||||||
/* libc includes */
|
/* libc includes */
|
||||||
|
@ -58,8 +60,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#define TEACHNUMBER 10
|
|
||||||
|
|
||||||
static skill_t getskill(const struct locale *lang)
|
static skill_t getskill(const struct locale *lang)
|
||||||
{
|
{
|
||||||
char token[128];
|
char token[128];
|
||||||
|
@ -484,9 +484,8 @@ int teach_cmd(unit * u, struct order *ord)
|
||||||
replace_order(&u->orders, ord, new_order);
|
replace_order(&u->orders, ord, new_order);
|
||||||
free_order(new_order); /* parse_order & set_order have each increased the refcount */
|
free_order(new_order); /* parse_order & set_order have each increased the refcount */
|
||||||
}
|
}
|
||||||
if (academy && sk != NOSKILL) {
|
if (academy) {
|
||||||
academy = academy / 30; /* anzahl gelehrter wochen, max. 10 */
|
academy_teaching_bonus(u, sk, academy);
|
||||||
learn_skill(u, sk, academy / 30.0 / TEACHNUMBER);
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -824,3 +823,27 @@ void produceexp(struct unit *u, skill_t sk, int n)
|
||||||
{
|
{
|
||||||
produceexp_ex(u, sk, n, learn_skill);
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -33,9 +33,11 @@ extern "C" {
|
||||||
bool is_migrant(struct unit *u);
|
bool is_migrant(struct unit *u);
|
||||||
int study_cost(struct unit *u, skill_t talent);
|
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(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));
|
void produceexp_ex(struct unit *u, skill_t sk, int n, bool(*learn)(struct unit *, skill_t, double));
|
||||||
#define MAXTEACHERS 20
|
#define MAXTEACHERS 20
|
||||||
|
#define TEACHNUMBER 10
|
||||||
typedef struct teaching_info {
|
typedef struct teaching_info {
|
||||||
struct unit *teachers[MAXTEACHERS];
|
struct unit *teachers[MAXTEACHERS];
|
||||||
int value;
|
int value;
|
||||||
|
@ -43,6 +45,7 @@ extern "C" {
|
||||||
|
|
||||||
extern const struct attrib_type at_learning;
|
extern const struct attrib_type at_learning;
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue