2010-08-08 10:06:34 +02:00
|
|
|
#include <platform.h>
|
2012-06-04 03:41:07 +02:00
|
|
|
#include <kernel/types.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
#include "tests.h"
|
|
|
|
|
2012-06-04 11:35:56 +02:00
|
|
|
#include <kernel/config.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
#include <kernel/region.h>
|
|
|
|
#include <kernel/terrain.h>
|
|
|
|
#include <kernel/item.h>
|
|
|
|
#include <kernel/unit.h>
|
|
|
|
#include <kernel/race.h>
|
|
|
|
#include <kernel/faction.h>
|
|
|
|
#include <kernel/building.h>
|
|
|
|
#include <kernel/ship.h>
|
2012-06-04 11:41:07 +02:00
|
|
|
#include <kernel/spell.h>
|
|
|
|
#include <kernel/spellbook.h>
|
2011-03-13 02:01:20 +01:00
|
|
|
#include <kernel/terrain.h>
|
|
|
|
#include <util/functions.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
#include <util/language.h>
|
2012-06-02 03:05:07 +02:00
|
|
|
#include <util/log.h>
|
|
|
|
|
|
|
|
#include <assert.h>
|
2014-03-15 19:29:11 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
struct race *test_create_race(const char *name)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-06-13 07:14:07 +02:00
|
|
|
race *rc = rc_get_or_create(name);
|
2011-03-13 02:01:20 +01:00
|
|
|
rc->flags |= RCF_PLAYERRACE;
|
|
|
|
rc->maintenance = 10;
|
2010-08-08 10:06:34 +02:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2011-03-13 02:01:20 +01:00
|
|
|
struct region *test_create_region(int x, int y, const terrain_type *terrain)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
region *r = new_region(x, y, NULL, 0);
|
2010-08-08 10:06:34 +02:00
|
|
|
terraform_region(r, terrain);
|
|
|
|
rsettrees(r, 0, 0);
|
|
|
|
rsettrees(r, 1, 0);
|
|
|
|
rsettrees(r, 2, 0);
|
|
|
|
rsethorses(r, 0);
|
|
|
|
rsetpeasants(r, terrain->size);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
struct faction *test_create_faction(const struct race *rc)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2012-05-17 21:23:25 +02:00
|
|
|
faction *f = addfaction("nobody@eressea.de", NULL, rc?rc:rc_find("human"), default_locale, 0);
|
2010-08-08 10:06:34 +02:00
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
struct unit *test_create_unit(struct faction *f, struct region *r)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2012-05-25 08:50:27 +02:00
|
|
|
unit *u = create_unit(r, f, 1, f?f->race:rc_find("human"), 0, 0, 0);
|
2010-08-08 10:06:34 +02:00
|
|
|
return u;
|
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
void test_cleanup(void)
|
|
|
|
{
|
2014-06-14 02:36:05 +02:00
|
|
|
test_clear_terrains();
|
|
|
|
test_clear_resources();
|
|
|
|
global.functions.maintenance = NULL;
|
|
|
|
global.functions.wage = NULL;
|
|
|
|
default_locale = 0;
|
|
|
|
free_locales();
|
|
|
|
free_spells();
|
|
|
|
free_buildingtypes();
|
|
|
|
free_shiptypes();
|
|
|
|
free_races();
|
|
|
|
free_spellbooks();
|
|
|
|
free_gamedata();
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-13 02:01:20 +01:00
|
|
|
terrain_type *
|
|
|
|
test_create_terrain(const char * name, unsigned int flags)
|
|
|
|
{
|
2014-06-16 06:19:47 +02:00
|
|
|
terrain_type * t = get_or_create_terrain(name);
|
2013-12-29 14:38:58 +01:00
|
|
|
t->_name = _strdup(name);
|
2011-03-13 02:01:20 +01:00
|
|
|
t->flags = flags;
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
|
|
|
building * test_create_building(region * r, const building_type * btype)
|
|
|
|
{
|
2012-05-27 17:38:17 +02:00
|
|
|
building * b = new_building(btype?btype:bt_find("castle"), r, default_locale);
|
|
|
|
b->size = b->type->maxsize>0?b->type->maxsize:1;
|
2011-03-13 02:01:20 +01:00
|
|
|
return b;
|
|
|
|
}
|
2011-03-16 05:04:38 +01:00
|
|
|
|
2012-05-17 09:13:30 +02:00
|
|
|
ship * test_create_ship(region * r, const ship_type * stype)
|
|
|
|
{
|
2012-05-27 17:38:17 +02:00
|
|
|
ship * s = new_ship(stype?stype:st_find("boat"), r, default_locale);
|
|
|
|
s->size = s->type->construction?s->type->construction->maxsize:1;
|
2012-05-17 09:13:30 +02:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2012-07-02 03:00:31 +02:00
|
|
|
ship_type * test_create_shiptype(const char ** names)
|
|
|
|
{
|
2014-06-13 07:14:07 +02:00
|
|
|
ship_type * stype = st_get_or_create(names[0]);
|
2012-07-02 03:00:31 +02:00
|
|
|
locale_setstring(default_locale, names[0], names[0]);
|
|
|
|
return stype;
|
|
|
|
}
|
|
|
|
|
|
|
|
building_type * test_create_buildingtype(const char * name)
|
|
|
|
{
|
|
|
|
building_type * btype = (building_type*)calloc(sizeof(building_type), 1);
|
|
|
|
btype->flags = BTF_NAMECHANGE;
|
2013-12-29 14:38:58 +01:00
|
|
|
btype->_name = _strdup(name);
|
2012-07-02 03:00:31 +02:00
|
|
|
locale_setstring(default_locale, name, name);
|
|
|
|
bt_register(btype);
|
|
|
|
return btype;
|
|
|
|
}
|
|
|
|
|
2011-03-16 05:04:38 +01:00
|
|
|
item_type * test_create_itemtype(const char ** names) {
|
|
|
|
resource_type * rtype;
|
|
|
|
item_type * itype;
|
|
|
|
|
|
|
|
rtype = new_resourcetype(names, NULL, RTF_ITEM);
|
|
|
|
itype = new_itemtype(rtype, ITF_ANIMAL|ITF_BIG, 5000, 7000);
|
|
|
|
|
|
|
|
return itype;
|
|
|
|
}
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
/** creates a small world and some stuff in it.
|
|
|
|
* two terrains: 'plain' and 'ocean'
|
|
|
|
* one race: 'human'
|
|
|
|
* one ship_type: 'boat'
|
|
|
|
* one building_type: 'castle'
|
|
|
|
* in 0.0 and 1.0 is an island of two plains, around it is ocean.
|
|
|
|
*/
|
|
|
|
void test_create_world(void)
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
terrain_type *t_plain, *t_ocean;
|
|
|
|
region *island[2];
|
2010-08-08 10:06:34 +02:00
|
|
|
int i;
|
2012-10-22 03:37:51 +02:00
|
|
|
const char * names[] = { "horse", "horse_p", "boat", "boat_p", "iron", "iron_p", "stone", "stone_p" };
|
2012-05-19 20:26:46 +02:00
|
|
|
|
2012-05-19 20:49:47 +02:00
|
|
|
make_locale("de");
|
2012-05-19 20:26:46 +02:00
|
|
|
init_resources();
|
|
|
|
assert(!olditemtype[I_HORSE]);
|
2011-03-16 05:04:38 +01:00
|
|
|
|
2012-10-22 03:37:51 +02:00
|
|
|
olditemtype[I_HORSE] = test_create_itemtype(names+0);
|
|
|
|
olditemtype[I_IRON] = test_create_itemtype(names+4);
|
|
|
|
olditemtype[I_STONE] = test_create_itemtype(names+6);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2011-03-16 05:04:38 +01:00
|
|
|
t_plain = test_create_terrain("plain", LAND_REGION | FOREST_REGION | WALK_INTO | CAVALRY_REGION);
|
|
|
|
t_plain->size = 1000;
|
2011-03-13 02:01:20 +01:00
|
|
|
t_ocean = test_create_terrain("ocean", SEA_REGION | SAIL_INTO | SWIM_INTO);
|
2011-03-16 05:04:38 +01:00
|
|
|
t_ocean->size = 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
island[0] = test_create_region(0, 0, t_plain);
|
|
|
|
island[1] = test_create_region(1, 0, t_plain);
|
2011-03-07 08:02:35 +01:00
|
|
|
for (i = 0; i != 2; ++i) {
|
2011-03-09 06:16:47 +01:00
|
|
|
int j;
|
2011-03-07 08:02:35 +01:00
|
|
|
region *r = island[i];
|
|
|
|
for (j = 0; j != MAXDIRECTIONS; ++j) {
|
2011-03-09 06:16:47 +01:00
|
|
|
region *rn = r_connect(r, (direction_t)j);
|
2010-08-08 10:06:34 +02:00
|
|
|
if (!rn) {
|
2011-03-07 08:02:35 +01:00
|
|
|
rn = test_create_region(r->x + delta_x[j], r->y + delta_y[j], t_ocean);
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-19 04:29:35 +02:00
|
|
|
test_create_race("human");
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2012-07-02 03:00:31 +02:00
|
|
|
test_create_buildingtype("castle");
|
|
|
|
test_create_shiptype(names+2);
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
2012-06-04 11:35:56 +02:00
|
|
|
|