forked from github/server
implemented a suggested change to RESERVE.
http://bugs.eressea.de/view.php?id=1675#c5240 new setting "rule.reserve.twophase" reserves from self first, before reserving from others. fix a crash when trying to flush logs and there is no logfile.
This commit is contained in:
parent
5458fce59c
commit
e44d4aa9b9
|
@ -223,6 +223,10 @@ void process_explain(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void process_reserve(void) {
|
void process_reserve(void) {
|
||||||
|
int rule = get_param_int(global.parameters, "rule.reserve.twophase", 0);
|
||||||
|
if (rule) {
|
||||||
|
process_cmd(K_RESERVE, reserve_self, 0);
|
||||||
|
}
|
||||||
process_cmd(K_RESERVE, reserve_cmd, 0);
|
process_cmd(K_RESERVE, reserve_cmd, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
13
src/laws.c
13
src/laws.c
|
@ -4038,8 +4038,7 @@ int pay_cmd(unit * u, struct order *ord)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int reserve_i(unit * u, struct order *ord, int flags)
|
||||||
int reserve_cmd(unit * u, struct order *ord)
|
|
||||||
{
|
{
|
||||||
if (u->number > 0 && (urace(u)->ec_flags & GETITEM)) {
|
if (u->number > 0 && (urace(u)->ec_flags & GETITEM)) {
|
||||||
int use, count;
|
int use, count;
|
||||||
|
@ -4060,7 +4059,7 @@ int reserve_cmd(unit * u, struct order *ord)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
set_resvalue(u, rtype, 0); /* make sure the pool is empty */
|
set_resvalue(u, rtype, 0); /* make sure the pool is empty */
|
||||||
use = use_pooled(u, rtype, GET_DEFAULT, count);
|
use = use_pooled(u, rtype, flags, count);
|
||||||
if (use) {
|
if (use) {
|
||||||
set_resvalue(u, rtype, use);
|
set_resvalue(u, rtype, use);
|
||||||
change_resource(u, rtype, use);
|
change_resource(u, rtype, use);
|
||||||
|
@ -4070,6 +4069,14 @@ int reserve_cmd(unit * u, struct order *ord)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int reserve_cmd(unit * u, struct order *ord) {
|
||||||
|
return reserve_i(u, ord, GET_DEFAULT);
|
||||||
|
}
|
||||||
|
|
||||||
|
int reserve_self(unit * u, struct order *ord) {
|
||||||
|
return reserve_i(u, ord, GET_RESERVE | GET_SLACK);
|
||||||
|
}
|
||||||
|
|
||||||
int claim_cmd(unit * u, struct order *ord)
|
int claim_cmd(unit * u, struct order *ord)
|
||||||
{
|
{
|
||||||
const char *t;
|
const char *t;
|
||||||
|
|
|
@ -85,6 +85,7 @@ extern "C" {
|
||||||
extern int reshow_cmd(struct unit *u, struct order *ord);
|
extern int reshow_cmd(struct unit *u, struct order *ord);
|
||||||
extern int mail_cmd(struct unit *u, struct order *ord);
|
extern int mail_cmd(struct unit *u, struct order *ord);
|
||||||
extern int reserve_cmd(struct unit *u, struct order *ord);
|
extern int reserve_cmd(struct unit *u, struct order *ord);
|
||||||
|
extern int reserve_self(struct unit *u, struct order *ord);
|
||||||
extern int claim_cmd(struct unit *u, struct order *ord);
|
extern int claim_cmd(struct unit *u, struct order *ord);
|
||||||
extern int follow_cmd(struct unit *u, struct order *ord);
|
extern int follow_cmd(struct unit *u, struct order *ord);
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <kernel/building.h>
|
#include <kernel/building.h>
|
||||||
#include <kernel/faction.h>
|
#include <kernel/faction.h>
|
||||||
#include <kernel/item.h>
|
#include <kernel/item.h>
|
||||||
|
#include <kernel/order.h>
|
||||||
#include <kernel/race.h>
|
#include <kernel/race.h>
|
||||||
#include <kernel/region.h>
|
#include <kernel/region.h>
|
||||||
#include <kernel/ship.h>
|
#include <kernel/ship.h>
|
||||||
|
@ -17,6 +18,8 @@
|
||||||
#include <CuTest.h>
|
#include <CuTest.h>
|
||||||
#include <tests.h>
|
#include <tests.h>
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
static void test_new_building_can_be_renamed(CuTest * tc)
|
static void test_new_building_can_be_renamed(CuTest * tc)
|
||||||
{
|
{
|
||||||
region *r;
|
region *r;
|
||||||
|
@ -209,6 +212,68 @@ static void test_cannot_create_unit_above_limit(CuTest * tc)
|
||||||
CuAssertIntEquals(tc, 1, checkunitnumber(f, 4));
|
CuAssertIntEquals(tc, 1, checkunitnumber(f, 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_reserve_cmd(CuTest *tc) {
|
||||||
|
unit *u1, *u2;
|
||||||
|
faction *f;
|
||||||
|
region *r;
|
||||||
|
order *ord;
|
||||||
|
const resource_type *rtype;
|
||||||
|
const struct locale *loc;
|
||||||
|
|
||||||
|
test_cleanup();
|
||||||
|
test_create_world();
|
||||||
|
|
||||||
|
rtype = get_resourcetype(R_SILVER);
|
||||||
|
assert(rtype && rtype->itype);
|
||||||
|
f = test_create_faction(rc_find("human"));
|
||||||
|
r = findregion(0, 0);
|
||||||
|
assert(r && f);
|
||||||
|
u1 = test_create_unit(f, r);
|
||||||
|
u2 = test_create_unit(f, r);
|
||||||
|
assert(u1 && u2);
|
||||||
|
loc = get_locale("de");
|
||||||
|
assert(loc);
|
||||||
|
ord = create_order(K_RESERVE, loc, "200 SILBER");
|
||||||
|
assert(ord);
|
||||||
|
i_change(&u1->items, rtype->itype, 100);
|
||||||
|
i_change(&u2->items, rtype->itype, 100);
|
||||||
|
CuAssertIntEquals(tc, 200, reserve_cmd(u1, ord));
|
||||||
|
CuAssertIntEquals(tc, 200, i_get(u1->items, rtype->itype));
|
||||||
|
CuAssertIntEquals(tc, 0, i_get(u2->items, rtype->itype));
|
||||||
|
test_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_reserve_self(CuTest *tc) {
|
||||||
|
unit *u1, *u2;
|
||||||
|
faction *f;
|
||||||
|
region *r;
|
||||||
|
order *ord;
|
||||||
|
const resource_type *rtype;
|
||||||
|
const struct locale *loc;
|
||||||
|
|
||||||
|
test_cleanup();
|
||||||
|
test_create_world();
|
||||||
|
|
||||||
|
rtype = get_resourcetype(R_SILVER);
|
||||||
|
assert(rtype && rtype->itype);
|
||||||
|
f = test_create_faction(rc_find("human"));
|
||||||
|
r = findregion(0, 0);
|
||||||
|
assert(r && f);
|
||||||
|
u1 = test_create_unit(f, r);
|
||||||
|
u2 = test_create_unit(f, r);
|
||||||
|
assert(u1 && u2);
|
||||||
|
loc = get_locale("de");
|
||||||
|
assert(loc);
|
||||||
|
ord = create_order(K_RESERVE, loc, "200 SILBER");
|
||||||
|
assert(ord);
|
||||||
|
i_change(&u1->items, rtype->itype, 100);
|
||||||
|
i_change(&u2->items, rtype->itype, 100);
|
||||||
|
CuAssertIntEquals(tc, 100, reserve_self(u1, ord));
|
||||||
|
CuAssertIntEquals(tc, 100, i_get(u1->items, rtype->itype));
|
||||||
|
CuAssertIntEquals(tc, 100, i_get(u2->items, rtype->itype));
|
||||||
|
test_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
CuSuite *get_laws_suite(void)
|
CuSuite *get_laws_suite(void)
|
||||||
{
|
{
|
||||||
CuSuite *suite = CuSuiteNew();
|
CuSuite *suite = CuSuiteNew();
|
||||||
|
@ -219,6 +284,8 @@ CuSuite *get_laws_suite(void)
|
||||||
SUITE_ADD_TEST(suite, test_fishing_does_not_give_goblins_money);
|
SUITE_ADD_TEST(suite, test_fishing_does_not_give_goblins_money);
|
||||||
SUITE_ADD_TEST(suite, test_fishing_gets_reset);
|
SUITE_ADD_TEST(suite, test_fishing_gets_reset);
|
||||||
SUITE_ADD_TEST(suite, test_unit_limit);
|
SUITE_ADD_TEST(suite, test_unit_limit);
|
||||||
|
SUITE_ADD_TEST(suite, test_reserve_self);
|
||||||
|
SUITE_ADD_TEST(suite, test_reserve_cmd);
|
||||||
SUITE_ADD_TEST(suite, test_cannot_create_unit_above_limit);
|
SUITE_ADD_TEST(suite, test_cannot_create_unit_above_limit);
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include <platform.h>
|
#include <platform.h>
|
||||||
#include <kernel/types.h>
|
#include <kernel/types.h>
|
||||||
#include "tests.h"
|
#include "tests.h"
|
||||||
|
#include "keyword.h"
|
||||||
|
|
||||||
#include <kernel/config.h>
|
#include <kernel/config.h>
|
||||||
#include <kernel/region.h>
|
#include <kernel/region.h>
|
||||||
|
@ -26,6 +27,7 @@ struct race *test_create_race(const char *name)
|
||||||
{
|
{
|
||||||
race *rc = rc_get_or_create(name);
|
race *rc = rc_get_or_create(name);
|
||||||
rc->maintenance = 10;
|
rc->maintenance = 10;
|
||||||
|
rc->ec_flags |= GETITEM | GIVEITEM;
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,8 +143,11 @@ void test_create_world(void)
|
||||||
region *island[2];
|
region *island[2];
|
||||||
int i;
|
int i;
|
||||||
item_type * itype;
|
item_type * itype;
|
||||||
|
struct locale * loc;
|
||||||
|
|
||||||
get_or_create_locale("de");
|
loc = get_or_create_locale("de");
|
||||||
|
locale_setstring(loc, keyword(K_RESERVE), "RESERVIEREN");
|
||||||
|
locale_setstring(loc, "money", "SILBER");
|
||||||
init_resources();
|
init_resources();
|
||||||
|
|
||||||
itype = test_create_itemtype("horse");
|
itype = test_create_itemtype("horse");
|
||||||
|
|
|
@ -35,7 +35,7 @@ static FILE *logfile;
|
||||||
#define LOG_MAXBACKUPS 5
|
#define LOG_MAXBACKUPS 5
|
||||||
void log_flush(void)
|
void log_flush(void)
|
||||||
{
|
{
|
||||||
fflush(logfile);
|
if (logfile) fflush(logfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
void log_puts(const char *str)
|
void log_puts(const char *str)
|
||||||
|
|
Loading…
Reference in New Issue