forked from github/server
parent
0197fce9a1
commit
ccb1799726
25
src/study.c
25
src/study.c
|
@ -53,6 +53,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <util/rng.h>
|
#include <util/rng.h>
|
||||||
#include <util/umlaut.h>
|
#include <util/umlaut.h>
|
||||||
|
|
||||||
|
#include <quicklist.h>
|
||||||
|
|
||||||
/* libc includes */
|
/* libc includes */
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
@ -216,24 +218,11 @@ teach_unit(unit * teacher, unit * student, int nteaching, skill_t sk,
|
||||||
n = _min(n, nteaching);
|
n = _min(n, nteaching);
|
||||||
|
|
||||||
if (n != 0) {
|
if (n != 0) {
|
||||||
int index = 0;
|
|
||||||
|
|
||||||
if (teach == NULL) {
|
if (teach == NULL) {
|
||||||
a = a_add(&student->attribs, a_new(&at_learning));
|
a = a_add(&student->attribs, a_new(&at_learning));
|
||||||
teach = (teaching_info *)a->data.v;
|
teach = (teaching_info *)a->data.v;
|
||||||
}
|
}
|
||||||
else {
|
ql_push(&teach->teachers, teacher);
|
||||||
while (teach->teachers[index] && index != MAXTEACHERS)
|
|
||||||
++index;
|
|
||||||
}
|
|
||||||
if (index < MAXTEACHERS)
|
|
||||||
teach->teachers[index++] = teacher;
|
|
||||||
if (index < MAXTEACHERS) {
|
|
||||||
teach->teachers[index] = NULL;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
log_error("MAXTEACHERS=%d is too low for student %s, teacher %s", MAXTEACHERS, unitname(student), unitname(teacher));
|
|
||||||
}
|
|
||||||
teach->value += n;
|
teach->value += n;
|
||||||
|
|
||||||
if (student->building && teacher->building == student->building) {
|
if (student->building && teacher->building == student->building) {
|
||||||
|
@ -717,7 +706,7 @@ int study_cmd(unit * u, order * ord)
|
||||||
a = a_add(&u->attribs, a_new(&at_learning));
|
a = a_add(&u->attribs, a_new(&at_learning));
|
||||||
teach = (teaching_info *)a->data.v;
|
teach = (teaching_info *)a->data.v;
|
||||||
assert(teach);
|
assert(teach);
|
||||||
teach->teachers[0] = 0;
|
teach->teachers = NULL;
|
||||||
}
|
}
|
||||||
if (money > 0) {
|
if (money > 0) {
|
||||||
use_pooled(u, get_resourcetype(R_SILVER), GET_DEFAULT, money);
|
use_pooled(u, get_resourcetype(R_SILVER), GET_DEFAULT, money);
|
||||||
|
@ -766,9 +755,9 @@ int study_cmd(unit * u, order * ord)
|
||||||
|
|
||||||
learn_skill(u, sk, days);
|
learn_skill(u, sk, days);
|
||||||
if (a != NULL) {
|
if (a != NULL) {
|
||||||
int index = 0;
|
ql_iter qli = qli_init(&teach->teachers);
|
||||||
while (teach->teachers[index] && index != MAXTEACHERS) {
|
while (qli_more(qli)) {
|
||||||
unit *teacher = teach->teachers[index++];
|
unit *teacher = (unit *)qli_next(&qli);
|
||||||
if (teacher->faction != u->faction) {
|
if (teacher->faction != u->faction) {
|
||||||
bool feedback = alliedunit(u, teacher->faction, HELP_GUARD);
|
bool feedback = alliedunit(u, teacher->faction, HELP_GUARD);
|
||||||
if (feedback) {
|
if (feedback) {
|
||||||
|
|
|
@ -27,6 +27,7 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct unit;
|
struct unit;
|
||||||
|
struct quicklist;
|
||||||
|
|
||||||
int teach_cmd(struct unit *u, struct order *ord);
|
int teach_cmd(struct unit *u, struct order *ord);
|
||||||
int study_cmd(struct unit *u, struct order *ord);
|
int study_cmd(struct unit *u, struct order *ord);
|
||||||
|
@ -45,10 +46,9 @@ extern "C" {
|
||||||
|
|
||||||
void demon_skillchange(struct unit *u);
|
void demon_skillchange(struct unit *u);
|
||||||
|
|
||||||
#define MAXTEACHERS 32
|
|
||||||
#define TEACHNUMBER 10
|
#define TEACHNUMBER 10
|
||||||
typedef struct teaching_info {
|
typedef struct teaching_info {
|
||||||
struct unit *teachers[MAXTEACHERS];
|
struct quicklist *teachers;
|
||||||
int value;
|
int value;
|
||||||
} teaching_info;
|
} teaching_info;
|
||||||
|
|
||||||
|
|
|
@ -18,9 +18,11 @@
|
||||||
#include <util/base36.h>
|
#include <util/base36.h>
|
||||||
#include <tests.h>
|
#include <tests.h>
|
||||||
|
|
||||||
|
#include <CuTest.h>
|
||||||
|
#include <quicklist.h>
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#include <CuTest.h>
|
|
||||||
|
|
||||||
#define MAXLOG 4
|
#define MAXLOG 4
|
||||||
typedef struct log_entry {
|
typedef struct log_entry {
|
||||||
|
@ -537,9 +539,9 @@ static void test_teach_message(CuTest *tc) {
|
||||||
teach = (teaching_info *)a->data.v;
|
teach = (teaching_info *)a->data.v;
|
||||||
CuAssertPtrNotNull(tc, teach->teachers);
|
CuAssertPtrNotNull(tc, teach->teachers);
|
||||||
CuAssertIntEquals(tc, 600, teach->value);
|
CuAssertIntEquals(tc, 600, teach->value);
|
||||||
CuAssertPtrEquals(tc, u1, teach->teachers[0]);
|
CuAssertIntEquals(tc, 2, ql_length(teach->teachers));
|
||||||
CuAssertPtrEquals(tc, u2, teach->teachers[1]);
|
CuAssertPtrEquals(tc, u1, ql_get(teach->teachers, 0));
|
||||||
CuAssertPtrEquals(tc, NULL, teach->teachers[2]);
|
CuAssertPtrEquals(tc, u2, ql_get(teach->teachers, 1));
|
||||||
study_cmd(u, u->thisorder);
|
study_cmd(u, u->thisorder);
|
||||||
CuAssertPtrEquals(tc, NULL, test_find_messagetype(u1->faction->msgs, "teach_teacher"));
|
CuAssertPtrEquals(tc, NULL, test_find_messagetype(u1->faction->msgs, "teach_teacher"));
|
||||||
CuAssertPtrNotNull(tc, test_find_messagetype(u2->faction->msgs, "teach_teacher"));
|
CuAssertPtrNotNull(tc, test_find_messagetype(u2->faction->msgs, "teach_teacher"));
|
||||||
|
|
Loading…
Reference in New Issue