Merge pull request #756 from ennorehling/develop

Fix use of lua on macOS, some bugs.
This commit is contained in:
Enno Rehling 2018-01-11 17:42:53 +01:00 committed by GitHub
commit 7d17ecc01a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 147 additions and 120 deletions

View File

@ -43,10 +43,10 @@ find_package (BerkeleyDB)
find_package (LibXml2 REQUIRED)
find_package (ToLua REQUIRED)
if (TOLUA_FOUND)
if (${TOLUA_VERSION_STRING} VERSION_GREATER "5.2")
if (${TOLUA_VERSION_STRING} VERSION_EQUAL "5.2")
find_package (Lua 5.2 REQUIRED)
elseif (${TOLUA_VERSION_STRING} VERSION_GREATER "5.1")
find_package (Lua 5.1 REQUIRED)
else ()
find_package (Lua51 REQUIRED)
endif()
endif(TOLUA_FOUND)
@ -66,3 +66,4 @@ install(DIRECTORY scripts DESTINATION ${CMAKE_INSTALL_PREFIX} FILES_MATCHING PAT
install(DIRECTORY lunit DESTINATION ${CMAKE_INSTALL_PREFIX} FILES_MATCHING PATTERN "*.lua")
install(DIRECTORY share DESTINATION ${CMAKE_INSTALL_PREFIX})

View File

@ -957,7 +957,7 @@
<skill name="unarmed" modifier="-99"/>
<attack type="1" damage="0d0"/>
</race>
<race name="template" magres="100" maxaura="0.000000" regaura="0.000000" weight="0" capacity="1000" speed="10.000000" hp="10" damage="1d4" unarmedattack="-2" unarmeddefense="-2" playerrace="yes" fly="yes" swim="yes" walk="yes" shapeshift="yes" shapeshiftany="yes" giveperson="yes" giveunit="yes" getitem="yes" recruitethereal="yes" recruitunlimited="yes" equipment="yes">
<race name="template" maintenance="0" magres="100" maxaura="0.000000" regaura="0.000000" weight="0" capacity="1000" speed="10.000000" hp="10" damage="1d4" unarmedattack="-2" unarmeddefense="-2" playerrace="yes" fly="yes" swim="yes" walk="yes" shapeshift="yes" shapeshiftany="yes" giveperson="yes" giveunit="yes" getitem="yes" recruitethereal="yes" recruitunlimited="yes" equipment="yes">
<ai splitsize="10000" moverandom="yes" learn="yes"/>
<attack type="1" damage="1d4"/>
</race>

View File

@ -38,15 +38,21 @@ ARGS=" -DCMAKE_BUILD_TYPE=$BUILD \
git submodule update --init
LUA_VERSION="5.2"
LUA_DIR=/usr
if [ -d /usr/include/lua5.1 ]; then
LUA_VERSION="5.1"
elif [ -d /usr/local/include/lua5.1 ]; then
LUA_DIR=/usr/local
LUA_VERSION="5.1"
fi
export LUA_DIR
path="$(which tolua)"
if [ "$HAVE_TOLUA" = "0" ] || [ -z $path ] ; then
echo "tolua is not installed, building from source"
cd $ROOT
if [ ! -d tolua ]; then
LUA_VERSION="5.2"
if [ -d /usr/include/lua5.1 ] || [ -d /usr/local/include/lua5.1 ]; then
LUA_VERSION="5.1"
fi
echo "fetching tolua ${LUA_VERSION} from github..."
git clone https://github.com/ennorehling/tolua-${LUA_VERSION}.git tolua
fi

View File

@ -403,3 +403,45 @@ function test_give_to_other_okay()
assert_equal(1, u1.number)
assert_equal(2, u2.number)
end
local function get_name(x)
return x.name .. " (" .. itoa36(x.id) .. ")"
end
function test_faction_stealth()
local f = faction.create('human')
local f2 = faction.create('human')
local r = region.create(0, 0, 'plain')
local u = unit.create(f, r)
local u2 = unit.create(f2, r)
assert_equal(get_name(u) .. ", 1 Mensch, aggressiv.", u:show(f))
assert_equal(get_name(u) .. ", " .. get_name(f) .. ", 1 Mensch.", u:show(f2))
u:add_order("TARNE PARTEI NUMMER " .. itoa36(f2.id))
process_orders()
assert_equal(get_name(u) .. ", " .. get_name(f2) .. ", 1 Mensch, aggressiv.", u:show(f))
assert_equal(get_name(u) .. ", " .. get_name(f2) .. ", 1 Mensch.", u:show(f2))
u:clear_orders()
u:add_order("TARNE PARTEI NUMMER")
process_orders()
assert_equal(get_name(u) .. ", 1 Mensch, aggressiv.", u:show(f))
assert_equal(get_name(u) .. ", " .. get_name(f) .. ", 1 Mensch.", u:show(f2))
end
function test_faction_anonymous()
local f = faction.create('human')
local f2 = faction.create('human')
local r = region.create(0, 0, 'plain')
local u = unit.create(f, r)
local u2 = unit.create(f2, r)
assert_equal(get_name(u) .. ", 1 Mensch, aggressiv.", u:show(f))
assert_equal(get_name(u) .. ", " .. get_name(f) .. ", 1 Mensch.", u:show(f2))
u:add_order("TARNE PARTEI")
process_orders()
assert_equal(get_name(u) .. ", anonym, 1 Mensch, aggressiv.", u:show(f))
assert_equal(get_name(u) .. ", anonym, 1 Mensch.", u:show(f2))
u:clear_orders()
u:add_order("TARNE PARTEI NICHT")
process_orders()
assert_equal(get_name(u) .. ", 1 Mensch, aggressiv.", u:show(f))
assert_equal(get_name(u) .. ", " .. get_name(f) .. ", 1 Mensch.", u:show(f2))
end

View File

@ -11,7 +11,7 @@ function setup()
eressea.settings.set("magic.regeneration.enable", "0")
end
function test_mistletoe_okay()
function disable_test_mistletoe_okay()
local r = region.create(0, 0, "plain")
local f = faction.create("human", "noreply@eressea.de", "de")
local u = unit.create(f, r, 1)
@ -27,7 +27,7 @@ function test_mistletoe_okay()
turn_end()
end
function test_mistletoe_fail()
function disable_test_mistletoe_fail()
local r = region.create(0, 0, "plain")
local f = faction.create("human", "noreply@eressea.de", "de")
local u = unit.create(f, r, 1)

View File

@ -7,7 +7,6 @@ otherfaction.test.c
SET(_FILES
attributes.c
fleechance.c
follow.c
hate.c
iceberg.c

View File

@ -25,7 +25,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* attributes includes */
#include "follow.h"
#include "fleechance.h"
#include "hate.h"
#include "iceberg.h"
#include "key.h"

View File

@ -1,40 +0,0 @@
/*
Copyright (c) 1998-2015, Enno Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
**/
#include <platform.h>
#include "fleechance.h"
#include <util/attrib.h>
#include <stdlib.h>
attrib_type at_fleechance = {
"fleechance",
NULL,
NULL,
NULL,
NULL,
NULL,
};
attrib *make_fleechance(float fleechance)
{
attrib *a = a_new(&at_fleechance);
a->data.flt = fleechance;
return a;
}

View File

@ -1,32 +0,0 @@
/*
Copyright (c) 1998-2015, Enno Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
**/
#ifndef H_ATTRIBUTE_FLEECHANCE
#define H_ATTRIBUTE_FLEECHANCE
#ifdef __cplusplus
extern "C" {
#endif
extern struct attrib_type at_fleechance;
struct attrib *make_fleechance(float fleechance);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -55,7 +55,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* attributes includes */
#include <attributes/key.h>
#include <attributes/fleechance.h>
#include <attributes/racename.h>
#include <attributes/otherfaction.h>
#include <attributes/moved.h>
@ -2330,7 +2329,6 @@ static double horse_fleeing_bonus(const unit * u)
double fleechance(unit * u)
{
double c = 0.20; /* Fluchtwahrscheinlichkeit in % */
attrib *a = a_find(u->attribs, &at_fleechance);
/* Einheit u versucht, dem Get<65>mmel zu entkommen */
c += (effskill(u, SK_STEALTH, 0) * 0.05);
@ -2343,11 +2341,12 @@ double fleechance(unit * u)
else {
c = fmin(c, 0.75);
}
#if 0
/* TODO: mistletoe */
if (a) {
c += a->data.flt;
}
#endif
return c;
}
@ -3362,6 +3361,8 @@ static int join_battle(battle * b, unit * u, bool attack, fighter ** cp)
fighter *c = NULL;
if (!attack) {
#if 0
/* TODO: mistletoe */
attrib *a = a_find(u->attribs, &at_fleechance);
if (a != NULL) {
if (rng_double() <= a->data.flt) {
@ -3369,6 +3370,7 @@ static int join_battle(battle * b, unit * u, bool attack, fighter ** cp)
return false;
}
}
#endif
}
for (s = b->sides; s != b->sides + b->nsides; ++s) {

View File

@ -49,14 +49,18 @@
#include <limits.h>
static int tolua_bufunit(lua_State * L) {
char buf[8192];
unit *self = (unit *)tolua_tousertype(L, 1, 0);
int mode = (int)tolua_tonumber(L, 2, (int)seen_unit);
if (!self) return 0;
bufunit(self->faction, self, 0, mode, buf, sizeof(buf));
tolua_pushstring(L, buf);
return 1;
unit *u = (unit *)tolua_tousertype(L, 1, 0);
if (u) {
faction *f = (faction *)tolua_tousertype(L, 2, u->faction);
if (f) {
char buf[8192];
int mode = (int)tolua_tonumber(L, 3, (int)seen_unit);
bufunit(f, u, 0, mode, buf, sizeof(buf));
tolua_pushstring(L, buf);
return 1;
}
}
return 0;
}

View File

@ -513,9 +513,9 @@ static void report_crtypes(FILE * F, const struct locale *lang)
const struct nrmessage_type *nrt = nrt_find(lang, kmt->mtype);
if (nrt) {
char buffer[DISPLAYSIZE];
unsigned int hash = kmt->mtype->key;
int hash = (int)kmt->mtype->key;
assert(hash > 0);
fprintf(F, "MESSAGETYPE %u\n", hash);
fprintf(F, "MESSAGETYPE %d\n", hash);
fputc('\"', F);
fputs(str_escape(nrt_string(nrt), buffer, sizeof(buffer)), F);
fputs("\";text\n", F);
@ -530,11 +530,11 @@ static void report_crtypes(FILE * F, const struct locale *lang)
}
}
static unsigned int messagehash(const struct message *msg)
static int message_id(const struct message *msg)
{
variant var;
var.v = (void *)msg;
return (unsigned int)var.i;
return var.i & 0x7FFFFFFF;
}
/** writes a quoted string to the file
@ -580,7 +580,7 @@ static void render_messages(FILE * F, faction * f, message_list * msgs)
char nrbuffer[1024 * 32];
nrbuffer[0] = '\0';
if (nr_render(m->msg, f->locale, nrbuffer, sizeof(nrbuffer), f) > 0) {
fprintf(F, "MESSAGE %u\n", messagehash(m->msg));
fprintf(F, "MESSAGE %d\n", message_id(m->msg));
fprintf(F, "%u;type\n", hash);
fwritestr(F, nrbuffer);
fputs(";rendered\n", F);
@ -591,7 +591,7 @@ static void render_messages(FILE * F, faction * f, message_list * msgs)
if (cr_render(m->msg, crbuffer, (const void *)f) == 0) {
if (crbuffer[0]) {
if (!printed) {
fprintf(F, "MESSAGE %u\n", messagehash(m->msg));
fprintf(F, "MESSAGE %d\n", message_id(m->msg));
}
fputs(crbuffer, F);
}
@ -814,7 +814,7 @@ void cr_output_unit(stream *out, const faction * f,
}
mage = get_familiar_mage(u);
if (mage) {
stream_printf(out, "%u;familiarmage\n", mage->no);
stream_printf(out, "%d;familiarmage\n", mage->no);
}
}

View File

@ -11,8 +11,6 @@
#include "economy.h"
#include "magic.h"
#include <attributes/fleechance.h>
#include <spells/shipcurse.h>
#include <spells/unitcurse.h>
#include <spells/regioncurse.h>
@ -387,7 +385,10 @@ use_mistletoe(struct unit *user, const struct item_type *itype, int amount,
}
use_pooled(user, itype->rtype, GET_SLACK | GET_RESERVE | GET_POOLED_SLACK,
user->number);
#if 0
/* TODO: mistletoe */
a_add(&user->attribs, make_fleechance((float)1.0));
#endif
ADDMSG(&user->faction->msgs,
msg_message("use_item", "unit item", user, itype->rtype));

View File

@ -406,10 +406,9 @@ void save_special_items(unit *usrc)
faction *fm = get_monsters();
static const race *rc_ghost;
static int cache;
static const char *name = NULL;
if (rc_changed(&cache)) {
rc_ghost = get_race(RC_TEMPLATE);
name = "ghost";
}
for (u = r->units; u; u = u->next) {
if (u->faction == fm) {
@ -418,9 +417,12 @@ void save_special_items(unit *usrc)
}
}
u = create_unit(r, fm, 1, rc_ghost, 0, NULL, NULL);
if (name) {
set_racename(&u->attribs, name);
unit_setname(u, unit_getname(usrc));
if (usrc->number > 1) {
/* some units have plural names, it would be neat if they aren't single: */
scale_number(u, 2);
}
set_racename(&u->attribs, "ghost");
give_special_items(u, &usrc->items);
}

View File

@ -253,7 +253,7 @@ static void test_set_email(CuTest *tc) {
test_teardown();
}
static void test_items_notlost(CuTest *tc) {
static void test_save_special_items(CuTest *tc) {
unit *u, *ug;
race * rc;
struct item_type *itype, *it_silver, *it_horse;
@ -266,16 +266,21 @@ static void test_items_notlost(CuTest *tc) {
rc = test_create_race("template");
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
i_change(&u->items, itype, 1);
/* when there is no monster in the region, a ghost of the dead unit is created: */
save_special_items(u);
CuAssertPtrNotNull(tc, u->next);
ug = u->next;
CuAssertPtrEquals(tc, NULL, ug->next);
CuAssertPtrEquals(tc, rc, (void *)ug->_race);
CuAssertIntEquals(tc, 1, u->number);
CuAssertIntEquals(tc, 0, i_get(u->items, itype));
CuAssertIntEquals(tc, 1, i_get(ug->items, itype));
CuAssertStrEquals(tc, "ghost", get_racename(ug->attribs));
CuAssertStrEquals(tc, u->_name, ug->_name);
i_change(&u->items, itype, 1);
/* when there is a monster, it takes all special items: */
save_special_items(u);
CuAssertPtrEquals(tc, NULL, ug->next);
CuAssertIntEquals(tc, 2, i_get(ug->items, itype));
@ -284,6 +289,7 @@ static void test_items_notlost(CuTest *tc) {
i_change(&u->items, itype, 1);
i_change(&u->items, it_horse, 5);
i_change(&u->items, it_silver, 10);
/* horses and money need to go to the region and are not taken: */
save_special_items(u);
CuAssertIntEquals(tc, 3, i_get(ug->items, itype));
CuAssertIntEquals(tc, 5, i_get(u->items, it_horse));
@ -306,6 +312,6 @@ CuSuite *get_faction_suite(void)
SUITE_ADD_TEST(suite, test_check_passwd);
SUITE_ADD_TEST(suite, test_valid_race);
SUITE_ADD_TEST(suite, test_set_email);
SUITE_ADD_TEST(suite, test_items_notlost);
SUITE_ADD_TEST(suite, test_save_special_items);
return suite;
}

View File

@ -1,8 +1,12 @@
#include <platform.h>
#include <kernel/config.h>
#include "faction.h"
#include "unit.h"
#include "race.h"
#include "item.h"
#include <util/language.h>
#include <attributes/raceprefix.h>
#include <tests.h>
#include <CuTest.h>
@ -151,6 +155,23 @@ static void test_rc_can_use(CuTest *tc) {
test_teardown();
}
static void test_racename(CuTest *tc) {
unit *u;
struct locale * lang;
test_setup();
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
u->faction->locale = lang = test_create_locale();
locale_setstring(lang, "race::human_p", "Menschen");
locale_setstring(lang, "race::human", "Mensch");
locale_setstring(lang, "prefix::dark", "Dunkel");
CuAssertStrEquals(tc, "Mensch", racename(lang, u, u->_race));
u->number = 2;
CuAssertStrEquals(tc, "Menschen", racename(lang, u, u->_race));
set_prefix(&u->faction->attribs, "dark");
CuAssertStrEquals(tc, "Dunkelmenschen", racename(lang, u, u->_race));
test_teardown();
}
CuSuite *get_race_suite(void)
{
CuSuite *suite = CuSuiteNew();
@ -161,6 +182,7 @@ CuSuite *get_race_suite(void)
SUITE_ADD_TEST(suite, test_rc_find);
SUITE_ADD_TEST(suite, test_rc_set_param);
SUITE_ADD_TEST(suite, test_rc_can_use);
SUITE_ADD_TEST(suite, test_racename);
return suite;
}

View File

@ -2065,12 +2065,12 @@ void report_battle_start(battle * b)
}
}
if (first) {
sbs_strcpy(&sbs, " ");
sbs_strcpy(&sbs, LOC(f->locale, "and"));
sbs_strcpy(&sbs, " ");
sbs_strcat(&sbs, " ");
sbs_strcat(&sbs, LOC(f->locale, "and"));
sbs_strcat(&sbs, " ");
}
if (lastf) {
sbs_strcpy(&sbs, lastf);
sbs_strcat(&sbs, lastf);
}
m = msg_message("start_battle", "factions", zText);

View File

@ -140,7 +140,8 @@ int study_cost(struct unit *u, skill_t sk)
int next_level = 1 + (u ? get_level(u, sk) : 0);
/* Die Magiekosten betragen 50+Summe(50*Stufe) */
/* 'Stufe' ist dabei die naechste zu erreichende Stufe */
cost = 50 * (1 + ((next_level + 1) * next_level / 2));
cost = config_get_int("skills.cost.magic", 50);
return cost * (1 + ((next_level + next_level * next_level) / 2));
}
else switch (sk) {
case SK_SPY:

View File

@ -418,11 +418,24 @@ static void test_study_magic(CuTest *tc) {
}
static void test_study_cost_magic(CuTest *tc) {
unit * u;
test_setup();
config_set("skills.cost.magic", "50");
CuAssertIntEquals(tc, 50, study_cost(NULL, SK_MAGIC));
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
CuAssertIntEquals(tc, 100, study_cost(u, SK_MAGIC));
set_level(u, SK_MAGIC, 1);
CuAssertIntEquals(tc, 200, study_cost(u, SK_MAGIC));
set_level(u, SK_MAGIC, 2);
CuAssertIntEquals(tc, 350, study_cost(u, SK_MAGIC));
set_level(u, SK_MAGIC, 29);
CuAssertIntEquals(tc, 23300, study_cost(u, SK_MAGIC));
set_level(u, SK_MAGIC, 27);
CuAssertIntEquals(tc, 20350, study_cost(u, SK_MAGIC));
config_set("skills.cost.magic", "100");
CuAssertIntEquals(tc, 100, study_cost(NULL, SK_MAGIC));
CuAssertIntEquals(tc, 2*20350, study_cost(u, SK_MAGIC));
test_teardown();
}

View File

@ -213,6 +213,7 @@ static unsigned int mt_id(const message_type * mtype)
size_t i = strlen(mtype->name);
while (i > 0) {
/* TODO: why not use str_hash? */
key = (mtype->name[--i] + key * 37);
}
return key % 0x7FFFFFFF;