forked from github/server
BUG 2453: Erstausstattung und Default-Befehle für neue Parteien.
This commit is contained in:
parent
34d0b56c68
commit
6d10ee8fa5
7 changed files with 56 additions and 29 deletions
|
@ -4,6 +4,7 @@ eressea.log.debug('rules for game E2')
|
|||
math.randomseed(rng.random())
|
||||
|
||||
local equipment = require('eressea.equipment')
|
||||
|
||||
local sets = {
|
||||
['seed_faction'] = {
|
||||
['items'] = {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
require 'eressea.path'
|
||||
require 'eressea.resources'
|
||||
require 'eressea.equipment'
|
||||
require 'eressea.spells'
|
||||
|
||||
local self = {}
|
||||
|
|
|
@ -6,5 +6,6 @@ package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua'
|
|||
require 'eressea.path'
|
||||
require 'eressea'
|
||||
require 'eressea.xmlconf'
|
||||
|
||||
eressea.read_game(get_turn() .. ".dat")
|
||||
gmtool.editor()
|
||||
|
|
|
@ -631,28 +631,24 @@ void kernel_init(void)
|
|||
translation_init();
|
||||
}
|
||||
|
||||
static order * defaults[MAXLOCALES];
|
||||
|
||||
order *default_order(const struct locale *lang)
|
||||
{
|
||||
int i = locale_index(lang);
|
||||
order *result = 0;
|
||||
assert(i < MAXLOCALES);
|
||||
|
||||
result = defaults[i];
|
||||
if (!result) {
|
||||
keyword_t kwd;
|
||||
const char * str;
|
||||
keyword_t kwd = NOKEYWORD;
|
||||
order *result = 0;
|
||||
|
||||
assert(i < MAXLOCALES);
|
||||
kwd = keyword_disabled(K_WORK) ? NOKEYWORD : K_WORK;
|
||||
str = config_get("orders.default");
|
||||
if (str) {
|
||||
kwd = findkeyword(str);
|
||||
}
|
||||
if (kwd != NOKEYWORD) {
|
||||
result = create_order(kwd, lang, NULL);
|
||||
defaults[i] = result;
|
||||
return copy_order(result);
|
||||
}
|
||||
}
|
||||
return result ? copy_order(result) : 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int rule_give(void)
|
||||
|
@ -760,14 +756,6 @@ void free_config(void) {
|
|||
*/
|
||||
void free_gamedata(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i != MAXLOCALES; ++i) {
|
||||
if (defaults[i]) {
|
||||
free_order(defaults[i]);
|
||||
defaults[i] = 0;
|
||||
}
|
||||
}
|
||||
free(forbidden_ids);
|
||||
forbidden_ids = NULL;
|
||||
|
||||
|
|
|
@ -180,15 +180,22 @@ static void test_default_order(CuTest *tc) {
|
|||
|
||||
test_setup();
|
||||
loc = test_create_locale();
|
||||
ord = default_order(loc);
|
||||
CuAssertPtrEquals(tc, 0, ord);
|
||||
free_order(ord);
|
||||
|
||||
config_set("orders.default", "work");
|
||||
ord = default_order(loc);
|
||||
CuAssertPtrNotNull(tc, ord);
|
||||
CuAssertIntEquals(tc, K_WORK, getkeyword(ord));
|
||||
free_order(ord);
|
||||
|
||||
enable_keyword(K_WORK, false);
|
||||
ord = default_order(loc);
|
||||
CuAssertPtrEquals(tc, NULL, ord);
|
||||
free_order(ord);
|
||||
|
||||
config_set("orders.default", "entertain");
|
||||
ord = default_order(loc);
|
||||
CuAssertPtrNotNull(tc, ord);
|
||||
CuAssertIntEquals(tc, K_ENTERTAIN, getkeyword(ord));
|
||||
free_order(ord);
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include "group.h"
|
||||
#include "item.h"
|
||||
#include "messages.h"
|
||||
#include "order.h"
|
||||
#include "plane.h"
|
||||
#include "race.h"
|
||||
#include "region.h"
|
||||
|
@ -294,8 +295,13 @@ unit *addplayer(region * r, faction * f)
|
|||
assert(f->units == NULL);
|
||||
faction_setorigin(f, 0, r->x, r->y);
|
||||
u = create_unit(r, f, 1, f->race, 0, NULL, NULL);
|
||||
u->thisorder = default_order(f->locale);
|
||||
unit_addorder(u, copy_order(u->thisorder));
|
||||
name = config_get("rules.equip_first");
|
||||
equip_unit(u, name ? name : "first_unit");
|
||||
if (!equip_unit(u, name ? name : "first_unit")) {
|
||||
/* give every unit enough money to survive the first turn */
|
||||
i_change(&u->items, get_resourcetype(R_SILVER)->itype, maintenance_cost(u));
|
||||
}
|
||||
u->hp = unit_max_hp(u) * u->number;
|
||||
fset(u, UFL_ISNEW);
|
||||
if (f->race == get_race(RC_DAEMON)) {
|
||||
|
|
|
@ -3,8 +3,10 @@
|
|||
#include <kernel/ally.h>
|
||||
#include <kernel/alliance.h>
|
||||
#include <kernel/calendar.h>
|
||||
#include <kernel/callbacks.h>
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/item.h>
|
||||
#include <kernel/order.h>
|
||||
#include <kernel/plane.h>
|
||||
#include <kernel/race.h>
|
||||
#include <kernel/region.h>
|
||||
|
@ -298,9 +300,30 @@ static void test_save_special_items(CuTest *tc) {
|
|||
test_teardown();
|
||||
}
|
||||
|
||||
static void test_addplayer(CuTest *tc) {
|
||||
unit *u;
|
||||
region *r;
|
||||
faction *f;
|
||||
item_type *itype;
|
||||
test_setup();
|
||||
callbacks.equip_unit = NULL;
|
||||
itype = test_create_silver();
|
||||
r = test_create_plain(0, 0);
|
||||
f = test_create_faction(NULL);
|
||||
u = addplayer(r, f);
|
||||
CuAssertPtrNotNull(tc, u);
|
||||
CuAssertPtrEquals(tc, r, u->region);
|
||||
CuAssertPtrEquals(tc, f, u->faction);
|
||||
CuAssertIntEquals(tc, i_get(u->items, itype), 10);
|
||||
CuAssertPtrNotNull(tc, u->orders);
|
||||
CuAssertIntEquals(tc, K_WORK, getkeyword(u->orders));
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
CuSuite *get_faction_suite(void)
|
||||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
SUITE_ADD_TEST(suite, test_addplayer);
|
||||
SUITE_ADD_TEST(suite, test_max_migrants);
|
||||
SUITE_ADD_TEST(suite, test_addfaction);
|
||||
SUITE_ADD_TEST(suite, test_remove_empty_factions);
|
||||
|
|
Loading…
Reference in a new issue