* Neue Lehrer-Meldung

* Mapper analysiert befehlsdatei für dropouts.
This commit is contained in:
Enno Rehling 2002-03-10 12:04:12 +00:00
parent 4e30efed94
commit 667e6673b2
7 changed files with 149 additions and 48 deletions

View File

@ -121,16 +121,34 @@ study_cost(unit *u, int talent)
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
typedef struct teaching_info {
unit * teacher;
int value;
} teaching_info;
static void
init_learning(struct attrib * a)
{
a->data.v = calloc(sizeof(teaching_info), 1);
}
static void
done_learning(struct attrib * a)
{
free(a->data.v);
}
static const attrib_type at_learning = { static const attrib_type at_learning = {
"learning", "learning",
NULL, NULL, NULL, NULL, NULL, init_learning, done_learning, NULL, NULL, NULL,
ATF_UNIQUE ATF_UNIQUE
}; };
static int static int
teach_unit(unit * teacher, unit * student, int teaching, skill_t sk, teach_unit(unit * teacher, unit * student, int nteaching, skill_t sk,
boolean report, int * academy) boolean report, int * academy)
{ {
teaching_info * teach = NULL;
attrib * a; attrib * a;
int n; int n;
@ -148,22 +166,27 @@ teach_unit(unit * teacher, unit * student, int teaching, skill_t sk,
n = student->number * 30; n = student->number * 30;
a = a_find(student->attribs, &at_learning); a = a_find(student->attribs, &at_learning);
if (a!=NULL) n -= a->data.i; if (a!=NULL) {
teach = (teaching_info*)a->data.v;
n -= teach->value;
}
n = min(n, teaching); n = min(n, nteaching);
if (n != 0) { if (n != 0) {
struct building * b = inside_building(teacher); struct building * b = inside_building(teacher);
const struct building_type * btype = b?b->type:NULL; const struct building_type * btype = b?b->type:NULL;
if (a==NULL) a = a_add(&student->attribs, a_new(&at_learning)); if (teach==NULL) {
a->data.i += n; a = a_add(&student->attribs, a_new(&at_learning));
teach = (teaching_info*)a->data.v;
}
teach->teacher = teacher;
teach->value += n;
/* Solange Akademien größenbeschränkt sind, sollte Lehrer und /* Solange Akademien größenbeschränkt sind, sollte Lehrer und
* Student auch in unterschiedlichen Gebäuden stehen dürfen */ * Student auch in unterschiedlichen Gebäuden stehen dürfen */
if (btype == &bt_academy if (btype == &bt_academy
/* && student->building==teacher->building
* && inside_building(student)!=NULL) */
&& student->building && student->building->type == &bt_academy) && student->building && student->building->type == &bt_academy)
{ {
int j = study_cost(student, sk); int j = study_cost(student, sk);
@ -171,7 +194,7 @@ teach_unit(unit * teacher, unit * student, int teaching, skill_t sk,
/* kann Einheit das zahlen? */ /* kann Einheit das zahlen? */
if (get_pooled(student, student->region, R_SILVER) >= j) { if (get_pooled(student, student->region, R_SILVER) >= j) {
/* Jeder Schüler zusätzlich +10 Tage wenn in Uni. */ /* Jeder Schüler zusätzlich +10 Tage wenn in Uni. */
a->data.i += (n / 30) * 10; /* learning erhöhen */ teach->value += (n / 30) * 10; /* learning erhöhen */
/* Lehrer zusätzlich +1 Tag pro Schüler. */ /* Lehrer zusätzlich +1 Tag pro Schüler. */
if (academy) *academy += n; if (academy) *academy += n;
} /* sonst nehmen sie nicht am Unterricht teil */ } /* sonst nehmen sie nicht am Unterricht teil */
@ -206,16 +229,8 @@ teach_unit(unit * teacher, unit * student, int teaching, skill_t sk,
* die Talentänderung (enno). * die Talentänderung (enno).
*/ */
teaching = max(0, teaching - student->number * 30); nteaching = max(0, nteaching - student->number * 30);
if (report || teacher->faction != student->faction) {
add_message(&student->faction->msgs, msg_message("teach",
"teacher student skill", teacher, student, sk));
if (teacher->faction != student->faction) {
add_message(&teacher->faction->msgs, msg_message("teach",
"teacher student skill", teacher, student, sk));
}
}
} }
return n; return n;
} }
@ -387,7 +402,7 @@ teach(region * r, unit * u)
msg_error(u, u->thisorder, "teach_nolearn", "student", u2)); msg_error(u, u->thisorder, "teach_nolearn", "student", u2));
continue; continue;
} }
if (eff_skill(u, sk, r) <= eff_skill(u2, sk, r)) { if (eff_skill(u2, sk, r) + TEACHDIFFERENCE >= eff_skill(u, sk, r)) {
add_message(&u->faction->msgs, add_message(&u->faction->msgs,
msg_error(u, u->thisorder, "teach_asgood", "student", u2)); msg_error(u, u->thisorder, "teach_asgood", "student", u2));
continue; continue;
@ -448,6 +463,7 @@ learn(void)
if (igetkeyword(u->thisorder, u->faction->locale) == K_STUDY) { if (igetkeyword(u->thisorder, u->faction->locale) == K_STUDY) {
double multi = 1.0; double multi = 1.0;
attrib * a = NULL; attrib * a = NULL;
teaching_info * teach = NULL;
int money = 0; int money = 0;
int maxalchemy = 0; int maxalchemy = 0;
if (u->race == new_race[RC_INSECT] && r_insectstalled(r) if (u->race == new_race[RC_INSECT] && r_insectstalled(r)
@ -485,6 +501,9 @@ learn(void)
p = studycost = study_cost(u,i); p = studycost = study_cost(u,i);
a = a_find(u->attribs, &at_learning); a = a_find(u->attribs, &at_learning);
if (a!=NULL) {
teach = (teaching_info*)a->data.v;
}
/* keine kostenpflichtigen Talente für Migranten. Vertraute sind /* keine kostenpflichtigen Talente für Migranten. Vertraute sind
* keine Migranten, wird in is_migrant abgefangen. Vorsicht, * keine Migranten, wird in is_migrant abgefangen. Vorsicht,
@ -597,7 +616,11 @@ learn(void)
} }
} }
if (a==NULL) a = a_add(&u->attribs, a_new(&at_learning)); if (teach==NULL) {
a = a_add(&u->attribs, a_new(&at_learning));
teach = (teaching_info*)a->data.v;
teach->teacher = NULL;
}
if (money>0) { if (money>0) {
use_pooled(u, r, R_SILVER, money); use_pooled(u, r, R_SILVER, money);
add_message(&u->faction->msgs, msg_message("studycost", add_message(&u->faction->msgs, msg_message("studycost",
@ -606,12 +629,12 @@ learn(void)
if (get_effect(u, oldpotiontype[P_WISE])) { if (get_effect(u, oldpotiontype[P_WISE])) {
l = min(u->number, get_effect(u, oldpotiontype[P_WISE])); l = min(u->number, get_effect(u, oldpotiontype[P_WISE]));
a->data.i += l * 10; teach->value += l * 10;
change_effect(u, oldpotiontype[P_WISE], -l); change_effect(u, oldpotiontype[P_WISE], -l);
} }
if (get_effect(u, oldpotiontype[P_FOOL])) { if (get_effect(u, oldpotiontype[P_FOOL])) {
l = min(u->number, get_effect(u, oldpotiontype[P_FOOL])); l = min(u->number, get_effect(u, oldpotiontype[P_FOOL]));
a->data.i -= l * 30; teach->value -= l * 30;
change_effect(u, oldpotiontype[P_FOOL], -l); change_effect(u, oldpotiontype[P_FOOL], -l);
} }
@ -621,10 +644,10 @@ learn(void)
|| i == SK_CATAPULT || i == SK_SWORD || i == SK_SPEAR || i == SK_CATAPULT || i == SK_SWORD || i == SK_SPEAR
|| i == SK_AUSDAUER || i == SK_WEAPONLESS) || i == SK_AUSDAUER || i == SK_WEAPONLESS)
{ {
a->data.i += u->number * (5+warrior_skill*5); teach->value += u->number * (5+warrior_skill*5);
} else { } else {
a->data.i -= u->number * (5+warrior_skill*5); teach->value -= u->number * (5+warrior_skill*5);
a->data.i = max(0, a->data.i); teach->value = max(0, teach->value);
} }
} }
@ -633,20 +656,20 @@ learn(void)
/* p ist Kosten ohne Uni, studycost mit; wenn /* p ist Kosten ohne Uni, studycost mit; wenn
* p!=studycost, ist die Einheit zwangsweise * p!=studycost, ist die Einheit zwangsweise
* in einer Uni */ * in einer Uni */
a->data.i += u->number * 10; teach->value += u->number * 10;
} }
if (is_cursed(r->attribs,C_BADLEARN,0)) { if (is_cursed(r->attribs,C_BADLEARN,0)) {
a->data.i -= u->number * 10; teach->value -= u->number * 10;
} }
#ifdef SKILLFIX_SAVE #ifdef SKILLFIX_SAVE
if (a && a->data.i) { if (teach && teach->value) {
int skill = get_skill(u, (skill_t)i); int skill = get_skill(u, (skill_t)i);
skillfix(u, (skill_t)i, skill, skillfix(u, (skill_t)i, skill,
(int)(u->number * 30 * multi), a->data.i); (int)(u->number * 30 * multi), teach->value);
} }
#endif #endif
days = (int)((u->number * 30 + a->data.i) * multi); days = (int)((u->number * 30 + teach->value) * multi);
if (fval(u, FL_HUNGER)) days = days / 2; if (fval(u, FL_HUNGER)) days = days / 2;
while (days) { while (days) {
if (days>=u->number*30) { if (days>=u->number*30) {
@ -659,6 +682,16 @@ learn(void)
} }
} }
if (a) { if (a) {
if (teach && teach->teacher) {
unit * teacher = teach->teacher;
if (teacher->faction != u->faction) {
add_message(&u->faction->msgs, msg_message("teach_student",
"teacher student skill", teacher, u, (skill_t)i));
add_message(&teacher->faction->msgs, msg_message("teach_teacher",
"teacher student skill level", teacher, u, (skill_t)i,
effskill(u, (skill_t)i)));
}
}
a_remove(&u->attribs, a); a_remove(&u->attribs, a);
a = NULL; a = NULL;
} }
@ -689,7 +722,6 @@ learn(void)
} }
void void
teaching(void) teaching(void)
{ {

View File

@ -276,7 +276,7 @@ ri36(FILE * F)
} }
#define MAXLINE 4096*16 #define MAXLINE 4096*16
static char * char *
getbuf(FILE * F) getbuf(FILE * F)
{ {
char lbuf[MAXLINE]; char lbuf[MAXLINE];

View File

@ -74,5 +74,6 @@ extern struct region * readregion(FILE * stream, int x, int y);
extern void writefaction(FILE * stream, const struct faction * f); extern void writefaction(FILE * stream, const struct faction * f);
extern struct faction * readfaction(FILE * stream); extern struct faction * readfaction(FILE * stream);
extern char * getbuf(FILE * F);
#endif #endif

View File

@ -24,6 +24,7 @@
#include <race.h> #include <race.h>
#include <region.h> #include <region.h>
#include <reports.h> #include <reports.h>
#include <save.h>
#include <study.h> #include <study.h>
#include <skill.h> #include <skill.h>
#include <unit.h> #include <unit.h>
@ -37,6 +38,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
const char * orderfile = NULL;
void void
RemovePartei(void) { RemovePartei(void) {
faction *f, *F; faction *f, *F;
@ -153,12 +156,57 @@ give_latestart_bonus(region *r, unit *u, int b)
typedef struct dropout { typedef struct dropout {
struct dropout * next; struct dropout * next;
const struct race * race; const struct race * race;
int x, y; int x, y, fno;
} dropout; } dropout;
static dropout * dropouts; static dropout * dropouts;
static newfaction * newfactions; static newfaction * newfactions;
void
read_orders(const char * filename)
{
faction * f = NULL;
FILE * F = fopen(filename, "r");
char * b;
char buffer[16];
if (F==NULL) return;
b = getbuf(F);
for (;;) {
switch (igetparam(b, default_locale)) {
case P_GAMENAME:
case P_FACTION:
strncpy(buffer, getstrtoken(), 16);
f = findfaction(atoi36(buffer));
if (f) fset(f, FL_MARK);
break;
case P_NEXT:
f = NULL;
break;
}
b = getbuf(F);
}
fclose(F);
for (f=factions;f;f=f->next) {
if (!fval(f, FL_MARK) && f->age <=1) {
ursprung * ur = f->ursprung;
while (ur && ur->id!=0) ur=ur->next;
if (ur) {
dropout * drop = calloc(sizeof(dropout), 1);
drop->x = ur->x;
drop->y = ur->y;
drop->fno = f->no;
drop->race = f->race;
drop->next = dropouts;
dropouts = drop;
}
}
freset(f, FL_MARK);
}
}
void void
read_dropouts(const char * filename) read_dropouts(const char * filename)
{ {
@ -174,10 +222,12 @@ read_dropouts(const char * filename)
drop->race = rc_find(race); drop->race = rc_find(race);
drop->x = x; drop->x = x;
drop->y = y; drop->y = y;
drop->fno = -1;
drop->next = dropouts; drop->next = dropouts;
dropouts = drop; dropouts = drop;
} }
} }
fclose(F);
} }
void void
@ -187,10 +237,12 @@ seed_dropouts(void)
while (*dropp) { while (*dropp) {
dropout *drop = *dropp; dropout *drop = *dropp;
region * r = findregion(drop->x, drop->y); region * r = findregion(drop->x, drop->y);
if (r && r->units==NULL) { if (r) {
boolean found = false; boolean found = false;
newfaction **nfp = &newfactions; newfaction **nfp = &newfactions;
while (*nfp) { unit * u;
for (u=r->units;u;u=u->next) if (u->faction->no==drop->fno) break;
if (u==NULL) while (*nfp) {
newfaction * nf = *nfp; newfaction * nf = *nfp;
if (nf->race==drop->race) { if (nf->race==drop->race) {
unit * u = addplayer(r, nf->email, nf->race, nf->lang); unit * u = addplayer(r, nf->email, nf->race, nf->lang);
@ -202,7 +254,7 @@ seed_dropouts(void)
} }
nfp = &nf->next; nfp = &nf->next;
} }
if (found) dropp=&drop->next; if (!found) dropp=&drop->next;
} else { } else {
*dropp = drop->next; *dropp = drop->next;
} }

View File

@ -56,6 +56,7 @@
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
extern const char * orderfile;
extern char *reportdir; extern char *reportdir;
extern char *datadir; extern char *datadir;
extern char *basedir; extern char *basedir;
@ -1447,6 +1448,9 @@ main(int argc, char *argv[])
else else
turn = atoi(argv[++i]); turn = atoi(argv[++i]);
break; break;
case 'v':
orderfile = argv[++i];
break;
case 'x': case 'x':
maxregions = atoi(argv[++i]); maxregions = atoi(argv[++i]);
maxregions = (maxregions*81+80) / 81; maxregions = (maxregions*81+80) / 81;

View File

@ -5761,17 +5761,23 @@
</locale> </locale>
</message> </message>
<message name="teach"> <message name="teach_student" section="study">
<type> <type>
<arg name="teacher" type="unit"></arg> <arg name="teacher" type="unit"></arg>
<arg name="student" type="unit"></arg> <arg name="student" type="unit"></arg>
<arg name="skill" type="skill"></arg> <arg name="skill" type="skill"></arg>
</type> </type>
<locale name="de"> <text locale="de">"$unit($teacher) lehrt $unit($student) $skill($skill)."</text>
<nr section="study"> </message>
<text>"$unit($teacher) lehrt $unit($student) $skill($skill)."</text>
</nr> <message name="teach_teacher" section="study">
</locale> <type>
<arg name="teacher" type="unit"></arg>
<arg name="student" type="unit"></arg>
<arg name="skill" type="skill"></arg>
<arg name="level" type="int"></arg>
</type>
<text locale="de">"$unit($teacher) lehrt $unit($student) $skill($skill) auf Stufe $int($level)."</text>
</message> </message>
<message name="teachdumb"> <message name="teachdumb">

View File

@ -3308,17 +3308,23 @@
</locale> </locale>
</message> </message>
<message name="teach"> <message name="teach_student" section="study">
<type> <type>
<arg name="teacher" type="unit"></arg> <arg name="teacher" type="unit"></arg>
<arg name="student" type="unit"></arg> <arg name="student" type="unit"></arg>
<arg name="skill" type="skill"></arg> <arg name="skill" type="skill"></arg>
</type> </type>
<locale name="en"> <text locale="en">"$unit($teacher) teaches $unit($student) $skill($skill)."</text>
<nr section="none"> </message>
<text>"$unit($teacher) teaches $unit($student) $skill($skill)."</text>
</nr> <message name="teach_teacher" section="study">
</locale> <type>
<arg name="teacher" type="unit"></arg>
<arg name="student" type="unit"></arg>
<arg name="skill" type="skill"></arg>
<arg name="level" type="int"></arg>
</type>
<text locale="en">"$unit($teacher) teaches $unit($student) $skill($skill) to level $int($level)."</text>
</message> </message>
<message name="spydetect"> <message name="spydetect">