Merge pull request #892 from ennorehling/develop

LERNE AUTO fix
This commit is contained in:
Enno Rehling 2020-02-21 21:14:03 +01:00 committed by GitHub
commit b89824f721
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 41 additions and 9 deletions

2
.gitignore vendored
View File

@ -46,3 +46,5 @@ tests/data/185.dat
/cutest/
/critbit/
*.mo
/CMakeSettings.json
/.vs

View File

@ -96,7 +96,7 @@ void autostudy_run(scholar scholars[], int nscholars)
int mint;
ts += scholars[se].u->number; /* count total scholars */
mint = (ts + 10) / 11; /* need a minimum of ceil(ts/11) teachers */
for (; mint > tt && si != nscholars; ++si) {
for (; mint > tt && si != nscholars - 1; ++si) {
tt += scholars[si].u->number;
}
}

View File

@ -110,6 +110,40 @@ static void test_autostudy_run_twoteachers(CuTest *tc) {
test_teardown();
}
/**
* Reproduce Bug 2640
*/
static void test_autostudy_run_bigunit(CuTest *tc) {
scholar scholars[4];
int nscholars;
unit *u1, *u2, *ulist;
faction *f;
region *r;
skill_t skill;
test_setup();
r = test_create_plain(0, 0);
f = test_create_faction(NULL);
u1 = test_create_unit(f, r);
set_number(u1, 20);
set_level(u1, SK_ENTERTAINMENT, 16);
u1->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_ENTERTAINMENT]);
u2 = test_create_unit(f, r);
set_number(u2, 1000);
set_level(u2, SK_ENTERTAINMENT, 10);
u2->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_ENTERTAINMENT]);
ulist = r->units;
CuAssertIntEquals(tc, 2, nscholars = autostudy_init(scholars, 4, &ulist, &skill));
CuAssertPtrEquals(tc, NULL, ulist);
autostudy_run(scholars, nscholars);
CuAssertIntEquals(tc, SK_ENTERTAINMENT, skill);
CuAssertIntEquals(tc, 0, scholars[0].learn);
CuAssertIntEquals(tc, 200, scholars[1].learn);
test_teardown();
}
static void test_autostudy_run(CuTest *tc) {
scholar scholars[4];
int nscholars;
@ -325,6 +359,7 @@ CuSuite *get_automate_suite(void)
SUITE_ADD_TEST(suite, test_autostudy_run_noteachers);
SUITE_ADD_TEST(suite, test_autostudy_run_teachers_learn);
SUITE_ADD_TEST(suite, test_autostudy_run_twoteachers);
SUITE_ADD_TEST(suite, test_autostudy_run_bigunit);
SUITE_ADD_TEST(suite, test_autostudy_run_skilldiff);
return suite;
}

View File

@ -647,7 +647,7 @@ void leave_building(unit * u)
{
building * b = u->building;
u->building = 0;
u->building = NULL;
if (b->_owner == u) {
building_update_owner(b);
assert(b->_owner != u);

View File

@ -1226,13 +1226,6 @@ void do_enter(struct region *r, bool is_final_attempt)
}
}
if (ulast != NULL) {
/* Wenn wir hier angekommen sind, war der Befehl
* erfolgreich und wir loeschen ihn, damit er im
* zweiten Versuch nicht nochmal ausgefuehrt wird. */
*ordp = ord->next;
ord->next = NULL;
free_order(ord);
if (ulast != u) {
/* put u behind ulast so it's the last unit in the building */
*uptr = u->next;

View File

@ -44,6 +44,7 @@
/* attributes includes */
#include <attributes/targetregion.h>
#include <attributes/otherfaction.h>
#include <attributes/hate.h>
#include <spells/regioncurse.h>
@ -772,6 +773,7 @@ void plan_monsters(faction * f)
if (fval(u, UFL_ANON_FACTION)) {
u->flags &= ~UFL_ANON_FACTION;
}
a_removeall(&u->attribs, &at_otherfaction);
if (rc->splitsize < 10) {
/* hermit-type monsters eat each other */