forked from github/server
- new test case (recruiting)
- logging and compilation fixes
This commit is contained in:
parent
5ea74d8bd8
commit
24182c4d06
6 changed files with 119 additions and 104 deletions
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
#include "eressea/server.cpp"
|
#include "eressea/server.cpp"
|
||||||
|
|
||||||
#ifndef BINDINGS_TOLUA
|
#ifdef BINDINGS_LUABIND
|
||||||
#include "eressea/lua/alliance.cpp"
|
#include "eressea/lua/alliance.cpp"
|
||||||
#include "eressea/lua/building.cpp"
|
#include "eressea/lua/building.cpp"
|
||||||
#include "eressea/lua/eressea.cpp"
|
#include "eressea/lua/eressea.cpp"
|
||||||
|
|
|
@ -837,7 +837,7 @@ demographics(void)
|
||||||
free(free_migrants);
|
free(free_migrants);
|
||||||
free_migrants = m;
|
free_migrants = m;
|
||||||
};
|
};
|
||||||
putchar('\n');
|
if (verbosity>=1) putchar('\n');
|
||||||
|
|
||||||
remove_empty_units();
|
remove_empty_units();
|
||||||
|
|
||||||
|
@ -3930,7 +3930,7 @@ update_subscriptions(void)
|
||||||
strcat(strcpy(zText, basepath()), "/subscriptions");
|
strcat(strcpy(zText, basepath()), "/subscriptions");
|
||||||
F = fopen(zText, "r");
|
F = fopen(zText, "r");
|
||||||
if (F==NULL) {
|
if (F==NULL) {
|
||||||
log_info((0, "could not open %s.\n", zText));
|
log_warning((0, "could not open %s.\n", zText));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
|
|
@ -357,10 +357,6 @@ extern void reorder_units(struct region * r);
|
||||||
|
|
||||||
extern const char *localenames[];
|
extern const char *localenames[];
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
#include <stdafx.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/** compatibility: **/
|
/** compatibility: **/
|
||||||
extern race_t old_race(const struct race *);
|
extern race_t old_race(const struct race *);
|
||||||
extern const struct race * new_race[];
|
extern const struct race * new_race[];
|
||||||
|
|
|
@ -258,31 +258,31 @@ _log_info(unsigned int level, const char * format, ...)
|
||||||
va_start(marker, format);
|
va_start(marker, format);
|
||||||
vfprintf(logfile, format, marker);
|
vfprintf(logfile, format, marker);
|
||||||
va_end(marker);
|
va_end(marker);
|
||||||
}
|
if (logfile!=stderr) {
|
||||||
if (logfile!=stderr) {
|
if (stderr_level>=level) {
|
||||||
if (stderr_level>=level) {
|
fprintf(stderr, "INFO[%u]: ", level);
|
||||||
fprintf(stderr, "INFO[%u]: ", level);
|
va_start(marker, format);
|
||||||
va_start(marker, format);
|
if (stdio_codepage) {
|
||||||
if (stdio_codepage) {
|
char buffer[MAXLENGTH];
|
||||||
char buffer[MAXLENGTH];
|
char converted[MAXLENGTH];
|
||||||
char converted[MAXLENGTH];
|
|
||||||
|
|
||||||
vsnprintf(buffer, sizeof(buffer), format, marker);
|
vsnprintf(buffer, sizeof(buffer), format, marker);
|
||||||
if (cp_convert(buffer, converted, MAXLENGTH, stdio_codepage)==0) {
|
if (cp_convert(buffer, converted, MAXLENGTH, stdio_codepage)==0) {
|
||||||
fputs(converted, stderr);
|
fputs(converted, stderr);
|
||||||
} else {
|
} else {
|
||||||
/* fall back to non-converted output */
|
/* fall back to non-converted output */
|
||||||
va_end(marker);
|
va_end(marker);
|
||||||
va_start(marker, format);
|
va_start(marker, format);
|
||||||
vfprintf(stderr, format, marker);
|
vfprintf(stderr, format, marker);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
vfprintf(stderr, format, marker);
|
vfprintf(stderr, format, marker);
|
||||||
}
|
}
|
||||||
va_end(marker);
|
va_end(marker);
|
||||||
}
|
}
|
||||||
if (log_flags & LOG_FLUSH) {
|
if (log_flags & LOG_FLUSH) {
|
||||||
log_flush();
|
log_flush();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,11 +122,11 @@
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#pragma warning (pop)
|
#pragma warning (pop)
|
||||||
#endif // _MSC_VER
|
#endif // _MSC_VER
|
||||||
#endif // BINDINGS_LUABIND
|
|
||||||
|
|
||||||
#include "lua/script.h"
|
#include "lua/script.h"
|
||||||
#include <boost/version.hpp>
|
#include <boost/version.hpp>
|
||||||
|
|
||||||
|
#endif // BINDINGS_LUABIND
|
||||||
|
|
||||||
#include <libxml/encoding.h>
|
#include <libxml/encoding.h>
|
||||||
|
|
||||||
/* stdc++ includes */
|
/* stdc++ includes */
|
||||||
|
|
|
@ -100,48 +100,48 @@ local function test_unit()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function test_region()
|
local function test_region()
|
||||||
free_game()
|
free_game()
|
||||||
local r = region.create(0, 0, "plain")
|
local r = region.create(0, 0, "plain")
|
||||||
r:set_resource("horse", 42)
|
r:set_resource("horse", 42)
|
||||||
r:set_resource("money", 45)
|
r:set_resource("money", 45)
|
||||||
r:set_resource("peasant", 200)
|
r:set_resource("peasant", 200)
|
||||||
assert(r:get_resource("horse") == 42)
|
assert(r:get_resource("horse") == 42)
|
||||||
assert(r:get_resource("money") == 45)
|
assert(r:get_resource("money") == 45)
|
||||||
assert(r:get_resource("peasant") == 200)
|
assert(r:get_resource("peasant") == 200)
|
||||||
r.name = nil
|
r.name = nil
|
||||||
r.info = nil
|
r.info = nil
|
||||||
assert(r.name=="")
|
assert(r.name=="")
|
||||||
assert(r.info=="")
|
assert(r.info=="")
|
||||||
r.name = "Alabasterheim"
|
r.name = "Alabasterheim"
|
||||||
r.info = "Hier wohnen die siebzehn Zwerge"
|
r.info = "Hier wohnen die siebzehn Zwerge"
|
||||||
assert(tostring(r) == "Alabasterheim (0,0)")
|
assert(tostring(r) == "Alabasterheim (0,0)")
|
||||||
end
|
end
|
||||||
|
|
||||||
local function test_building()
|
local function test_building()
|
||||||
free_game()
|
free_game()
|
||||||
local u
|
local u
|
||||||
local f = faction.create("enno@eressea.de", "human", "de")
|
local f = faction.create("enno@eressea.de", "human", "de")
|
||||||
local r = region.create(0, 0, "plain")
|
local r = region.create(0, 0, "plain")
|
||||||
local b = building.create(r, "castle")
|
local b = building.create(r, "castle")
|
||||||
u = unit.create(f, r)
|
u = unit.create(f, r)
|
||||||
u.number = 1
|
u.number = 1
|
||||||
u.building = b
|
u.building = b
|
||||||
u = unit.create(f, r)
|
u = unit.create(f, r)
|
||||||
u.number = 2
|
u.number = 2
|
||||||
-- u.building = b
|
-- u.building = b
|
||||||
u = unit.create(f, r)
|
u = unit.create(f, r)
|
||||||
u.number = 3
|
u.number = 3
|
||||||
u.building = b
|
u.building = b
|
||||||
local units = 0
|
local units = 0
|
||||||
for u in b.units do
|
for u in b.units do
|
||||||
units = units + 1
|
units = units + 1
|
||||||
end
|
end
|
||||||
assert(units==2)
|
assert(units==2)
|
||||||
local r2 = region.create(0, 1, "plain")
|
local r2 = region.create(0, 1, "plain")
|
||||||
assert(b.region==r)
|
assert(b.region==r)
|
||||||
b.region = r2
|
b.region = r2
|
||||||
assert(b.region==r2)
|
assert(b.region==r2)
|
||||||
assert(r2.buildings()==b)
|
assert(r2.buildings()==b)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function loadscript(name)
|
local function loadscript(name)
|
||||||
|
@ -153,30 +153,30 @@ local function loadscript(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function test_message()
|
local function test_message()
|
||||||
free_game()
|
free_game()
|
||||||
local r = region.create(0, 0, "plain")
|
local r = region.create(0, 0, "plain")
|
||||||
local f = faction.create("enno@eressea.de", "human", "de")
|
local f = faction.create("enno@eressea.de", "human", "de")
|
||||||
local u = unit.create(f, r)
|
local u = unit.create(f, r)
|
||||||
local msg = message.create("item_create_spell")
|
local msg = message.create("item_create_spell")
|
||||||
msg:set_unit("mage", u)
|
msg:set_unit("mage", u)
|
||||||
msg:set_int("number", 1)
|
msg:set_int("number", 1)
|
||||||
msg:set_resource("item", "sword")
|
msg:set_resource("item", "sword")
|
||||||
msg:send_region(r)
|
msg:send_region(r)
|
||||||
msg:send_faction(f)
|
msg:send_faction(f)
|
||||||
|
|
||||||
return msg
|
return msg
|
||||||
end
|
end
|
||||||
|
|
||||||
local function test_hashtable()
|
local function test_hashtable()
|
||||||
free_game()
|
free_game()
|
||||||
local f = faction.create("enno@eressea.de", "human", "de")
|
local f = faction.create("enno@eressea.de", "human", "de")
|
||||||
f.objects:set("enno", "smart guy")
|
f.objects:set("enno", "smart guy")
|
||||||
f.objects:set("age", 10)
|
f.objects:set("age", 10)
|
||||||
assert(f.objects:get("jesus") == nil)
|
assert(f.objects:get("jesus") == nil)
|
||||||
assert(f.objects:get("enno") == "smart guy")
|
assert(f.objects:get("enno") == "smart guy")
|
||||||
assert(f.objects:get("age") == 10)
|
assert(f.objects:get("age") == 10)
|
||||||
f.objects:set("age", nil)
|
f.objects:set("age", nil)
|
||||||
assert(f.objects:get("age") == nil)
|
assert(f.objects:get("age") == nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
function test_events()
|
function test_events()
|
||||||
|
@ -185,7 +185,7 @@ function test_events()
|
||||||
str = evt:get(0)
|
str = evt:get(0)
|
||||||
u2 = evt:get(1)
|
u2 = evt:get(1)
|
||||||
assert(u2~=nil)
|
assert(u2~=nil)
|
||||||
print(str=="Du Elf stinken")
|
assert(str=="Du Elf stinken")
|
||||||
message_unit(u, u2, "thanks unit, i got your message: " .. str)
|
message_unit(u, u2, "thanks unit, i got your message: " .. str)
|
||||||
message_faction(u, u2.faction, "thanks faction, i got your message: " .. str)
|
message_faction(u, u2.faction, "thanks faction, i got your message: " .. str)
|
||||||
message_region(u, "thanks region, i got your message: " .. str)
|
message_region(u, "thanks region, i got your message: " .. str)
|
||||||
|
@ -218,18 +218,37 @@ function test_events()
|
||||||
assert(fail==0)
|
assert(fail==0)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function test_recruit()
|
||||||
|
free_game()
|
||||||
|
local r = region.create(0, 0, "plain")
|
||||||
|
local f = faction.create("enno@eressea.de", "human", "de")
|
||||||
|
local u = unit.create(f, r)
|
||||||
|
u.number = 1
|
||||||
|
local n = 3
|
||||||
|
r:set_resource("peasant", 200)
|
||||||
|
u:clear_orders()
|
||||||
|
u:add_item("money", 85*n+20)
|
||||||
|
u:add_order("REKRUTIERE " .. n)
|
||||||
|
process_orders()
|
||||||
|
assert(u.number == n+1)
|
||||||
|
local p = r:get_resource("peasant")
|
||||||
|
assert(p<200 and p>=200-n)
|
||||||
|
assert(u:get_item("money")==10)
|
||||||
|
end
|
||||||
|
|
||||||
loadscript("extensions.lua")
|
loadscript("extensions.lua")
|
||||||
tests = {
|
tests = {
|
||||||
["test_pure"] = test_pure,
|
["pure"] = test_pure,
|
||||||
["test_read_write"] = test_read_write,
|
["read_write"] = test_read_write,
|
||||||
["test_faction"] = test_faction,
|
["faction"] = test_faction,
|
||||||
["test_region"] = test_region,
|
["region"] = test_region,
|
||||||
["test_building"] = test_building,
|
["building"] = test_building,
|
||||||
["test_unit"] = test_unit,
|
["unit"] = test_unit,
|
||||||
["test_message"] = test_message,
|
["message"] = test_message,
|
||||||
["test_hashtable"] = test_hashtable,
|
["hashtable"] = test_hashtable,
|
||||||
["test_gmtool"] = test_gmtool,
|
["gmtool"] = test_gmtool,
|
||||||
["test_events"] = test_events
|
["events"] = test_events,
|
||||||
|
["recruit"] = test_recruit
|
||||||
}
|
}
|
||||||
|
|
||||||
fail = 0
|
fail = 0
|
||||||
|
|
Loading…
Reference in a new issue