forked from github/server
Merge pull request #756 from ennorehling/develop
Fix use of lua on macOS, some bugs.
This commit is contained in:
commit
7d17ecc01a
20 changed files with 147 additions and 120 deletions
|
@ -43,10 +43,10 @@ find_package (BerkeleyDB)
|
||||||
find_package (LibXml2 REQUIRED)
|
find_package (LibXml2 REQUIRED)
|
||||||
find_package (ToLua REQUIRED)
|
find_package (ToLua REQUIRED)
|
||||||
if (TOLUA_FOUND)
|
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)
|
find_package (Lua 5.2 REQUIRED)
|
||||||
elseif (${TOLUA_VERSION_STRING} VERSION_GREATER "5.1")
|
else ()
|
||||||
find_package (Lua 5.1 REQUIRED)
|
find_package (Lua51 REQUIRED)
|
||||||
endif()
|
endif()
|
||||||
endif(TOLUA_FOUND)
|
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 lunit DESTINATION ${CMAKE_INSTALL_PREFIX} FILES_MATCHING PATTERN "*.lua")
|
||||||
install(DIRECTORY share DESTINATION ${CMAKE_INSTALL_PREFIX})
|
install(DIRECTORY share DESTINATION ${CMAKE_INSTALL_PREFIX})
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -957,7 +957,7 @@
|
||||||
<skill name="unarmed" modifier="-99"/>
|
<skill name="unarmed" modifier="-99"/>
|
||||||
<attack type="1" damage="0d0"/>
|
<attack type="1" damage="0d0"/>
|
||||||
</race>
|
</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"/>
|
<ai splitsize="10000" moverandom="yes" learn="yes"/>
|
||||||
<attack type="1" damage="1d4"/>
|
<attack type="1" damage="1d4"/>
|
||||||
</race>
|
</race>
|
||||||
|
|
14
s/cmake-init
14
s/cmake-init
|
@ -38,15 +38,21 @@ ARGS=" -DCMAKE_BUILD_TYPE=$BUILD \
|
||||||
|
|
||||||
git submodule update --init
|
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)"
|
path="$(which tolua)"
|
||||||
if [ "$HAVE_TOLUA" = "0" ] || [ -z $path ] ; then
|
if [ "$HAVE_TOLUA" = "0" ] || [ -z $path ] ; then
|
||||||
echo "tolua is not installed, building from source"
|
echo "tolua is not installed, building from source"
|
||||||
cd $ROOT
|
cd $ROOT
|
||||||
if [ ! -d tolua ]; then
|
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..."
|
echo "fetching tolua ${LUA_VERSION} from github..."
|
||||||
git clone https://github.com/ennorehling/tolua-${LUA_VERSION}.git tolua
|
git clone https://github.com/ennorehling/tolua-${LUA_VERSION}.git tolua
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -403,3 +403,45 @@ function test_give_to_other_okay()
|
||||||
assert_equal(1, u1.number)
|
assert_equal(1, u1.number)
|
||||||
assert_equal(2, u2.number)
|
assert_equal(2, u2.number)
|
||||||
end
|
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
|
||||||
|
|
|
@ -11,7 +11,7 @@ function setup()
|
||||||
eressea.settings.set("magic.regeneration.enable", "0")
|
eressea.settings.set("magic.regeneration.enable", "0")
|
||||||
end
|
end
|
||||||
|
|
||||||
function test_mistletoe_okay()
|
function disable_test_mistletoe_okay()
|
||||||
local r = region.create(0, 0, "plain")
|
local r = region.create(0, 0, "plain")
|
||||||
local f = faction.create("human", "noreply@eressea.de", "de")
|
local f = faction.create("human", "noreply@eressea.de", "de")
|
||||||
local u = unit.create(f, r, 1)
|
local u = unit.create(f, r, 1)
|
||||||
|
@ -27,7 +27,7 @@ function test_mistletoe_okay()
|
||||||
turn_end()
|
turn_end()
|
||||||
end
|
end
|
||||||
|
|
||||||
function test_mistletoe_fail()
|
function disable_test_mistletoe_fail()
|
||||||
local r = region.create(0, 0, "plain")
|
local r = region.create(0, 0, "plain")
|
||||||
local f = faction.create("human", "noreply@eressea.de", "de")
|
local f = faction.create("human", "noreply@eressea.de", "de")
|
||||||
local u = unit.create(f, r, 1)
|
local u = unit.create(f, r, 1)
|
||||||
|
|
|
@ -7,7 +7,6 @@ otherfaction.test.c
|
||||||
|
|
||||||
SET(_FILES
|
SET(_FILES
|
||||||
attributes.c
|
attributes.c
|
||||||
fleechance.c
|
|
||||||
follow.c
|
follow.c
|
||||||
hate.c
|
hate.c
|
||||||
iceberg.c
|
iceberg.c
|
||||||
|
|
|
@ -25,7 +25,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
/* attributes includes */
|
/* attributes includes */
|
||||||
#include "follow.h"
|
#include "follow.h"
|
||||||
#include "fleechance.h"
|
|
||||||
#include "hate.h"
|
#include "hate.h"
|
||||||
#include "iceberg.h"
|
#include "iceberg.h"
|
||||||
#include "key.h"
|
#include "key.h"
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
|
@ -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
|
|
10
src/battle.c
10
src/battle.c
|
@ -55,7 +55,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
/* attributes includes */
|
/* attributes includes */
|
||||||
#include <attributes/key.h>
|
#include <attributes/key.h>
|
||||||
#include <attributes/fleechance.h>
|
|
||||||
#include <attributes/racename.h>
|
#include <attributes/racename.h>
|
||||||
#include <attributes/otherfaction.h>
|
#include <attributes/otherfaction.h>
|
||||||
#include <attributes/moved.h>
|
#include <attributes/moved.h>
|
||||||
|
@ -2330,7 +2329,6 @@ static double horse_fleeing_bonus(const unit * u)
|
||||||
double fleechance(unit * u)
|
double fleechance(unit * u)
|
||||||
{
|
{
|
||||||
double c = 0.20; /* Fluchtwahrscheinlichkeit in % */
|
double c = 0.20; /* Fluchtwahrscheinlichkeit in % */
|
||||||
attrib *a = a_find(u->attribs, &at_fleechance);
|
|
||||||
/* Einheit u versucht, dem Get<65>mmel zu entkommen */
|
/* Einheit u versucht, dem Get<65>mmel zu entkommen */
|
||||||
|
|
||||||
c += (effskill(u, SK_STEALTH, 0) * 0.05);
|
c += (effskill(u, SK_STEALTH, 0) * 0.05);
|
||||||
|
@ -2343,11 +2341,12 @@ double fleechance(unit * u)
|
||||||
else {
|
else {
|
||||||
c = fmin(c, 0.75);
|
c = fmin(c, 0.75);
|
||||||
}
|
}
|
||||||
|
#if 0
|
||||||
|
/* TODO: mistletoe */
|
||||||
if (a) {
|
if (a) {
|
||||||
c += a->data.flt;
|
c += a->data.flt;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3362,6 +3361,8 @@ static int join_battle(battle * b, unit * u, bool attack, fighter ** cp)
|
||||||
fighter *c = NULL;
|
fighter *c = NULL;
|
||||||
|
|
||||||
if (!attack) {
|
if (!attack) {
|
||||||
|
#if 0
|
||||||
|
/* TODO: mistletoe */
|
||||||
attrib *a = a_find(u->attribs, &at_fleechance);
|
attrib *a = a_find(u->attribs, &at_fleechance);
|
||||||
if (a != NULL) {
|
if (a != NULL) {
|
||||||
if (rng_double() <= a->data.flt) {
|
if (rng_double() <= a->data.flt) {
|
||||||
|
@ -3369,6 +3370,7 @@ static int join_battle(battle * b, unit * u, bool attack, fighter ** cp)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
for (s = b->sides; s != b->sides + b->nsides; ++s) {
|
for (s = b->sides; s != b->sides + b->nsides; ++s) {
|
||||||
|
|
|
@ -49,14 +49,18 @@
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
||||||
static int tolua_bufunit(lua_State * L) {
|
static int tolua_bufunit(lua_State * L) {
|
||||||
char buf[8192];
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
if (u) {
|
||||||
int mode = (int)tolua_tonumber(L, 2, (int)seen_unit);
|
faction *f = (faction *)tolua_tousertype(L, 2, u->faction);
|
||||||
if (!self) return 0;
|
if (f) {
|
||||||
|
char buf[8192];
|
||||||
bufunit(self->faction, self, 0, mode, buf, sizeof(buf));
|
int mode = (int)tolua_tonumber(L, 3, (int)seen_unit);
|
||||||
tolua_pushstring(L, buf);
|
bufunit(f, u, 0, mode, buf, sizeof(buf));
|
||||||
return 1;
|
tolua_pushstring(L, buf);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -513,9 +513,9 @@ static void report_crtypes(FILE * F, const struct locale *lang)
|
||||||
const struct nrmessage_type *nrt = nrt_find(lang, kmt->mtype);
|
const struct nrmessage_type *nrt = nrt_find(lang, kmt->mtype);
|
||||||
if (nrt) {
|
if (nrt) {
|
||||||
char buffer[DISPLAYSIZE];
|
char buffer[DISPLAYSIZE];
|
||||||
unsigned int hash = kmt->mtype->key;
|
int hash = (int)kmt->mtype->key;
|
||||||
assert(hash > 0);
|
assert(hash > 0);
|
||||||
fprintf(F, "MESSAGETYPE %u\n", hash);
|
fprintf(F, "MESSAGETYPE %d\n", hash);
|
||||||
fputc('\"', F);
|
fputc('\"', F);
|
||||||
fputs(str_escape(nrt_string(nrt), buffer, sizeof(buffer)), F);
|
fputs(str_escape(nrt_string(nrt), buffer, sizeof(buffer)), F);
|
||||||
fputs("\";text\n", 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;
|
variant var;
|
||||||
var.v = (void *)msg;
|
var.v = (void *)msg;
|
||||||
return (unsigned int)var.i;
|
return var.i & 0x7FFFFFFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** writes a quoted string to the file
|
/** 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];
|
char nrbuffer[1024 * 32];
|
||||||
nrbuffer[0] = '\0';
|
nrbuffer[0] = '\0';
|
||||||
if (nr_render(m->msg, f->locale, nrbuffer, sizeof(nrbuffer), f) > 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);
|
fprintf(F, "%u;type\n", hash);
|
||||||
fwritestr(F, nrbuffer);
|
fwritestr(F, nrbuffer);
|
||||||
fputs(";rendered\n", F);
|
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 (cr_render(m->msg, crbuffer, (const void *)f) == 0) {
|
||||||
if (crbuffer[0]) {
|
if (crbuffer[0]) {
|
||||||
if (!printed) {
|
if (!printed) {
|
||||||
fprintf(F, "MESSAGE %u\n", messagehash(m->msg));
|
fprintf(F, "MESSAGE %d\n", message_id(m->msg));
|
||||||
}
|
}
|
||||||
fputs(crbuffer, F);
|
fputs(crbuffer, F);
|
||||||
}
|
}
|
||||||
|
@ -814,7 +814,7 @@ void cr_output_unit(stream *out, const faction * f,
|
||||||
}
|
}
|
||||||
mage = get_familiar_mage(u);
|
mage = get_familiar_mage(u);
|
||||||
if (mage) {
|
if (mage) {
|
||||||
stream_printf(out, "%u;familiarmage\n", mage->no);
|
stream_printf(out, "%d;familiarmage\n", mage->no);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,8 +11,6 @@
|
||||||
#include "economy.h"
|
#include "economy.h"
|
||||||
#include "magic.h"
|
#include "magic.h"
|
||||||
|
|
||||||
#include <attributes/fleechance.h>
|
|
||||||
|
|
||||||
#include <spells/shipcurse.h>
|
#include <spells/shipcurse.h>
|
||||||
#include <spells/unitcurse.h>
|
#include <spells/unitcurse.h>
|
||||||
#include <spells/regioncurse.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,
|
use_pooled(user, itype->rtype, GET_SLACK | GET_RESERVE | GET_POOLED_SLACK,
|
||||||
user->number);
|
user->number);
|
||||||
|
#if 0
|
||||||
|
/* TODO: mistletoe */
|
||||||
a_add(&user->attribs, make_fleechance((float)1.0));
|
a_add(&user->attribs, make_fleechance((float)1.0));
|
||||||
|
#endif
|
||||||
ADDMSG(&user->faction->msgs,
|
ADDMSG(&user->faction->msgs,
|
||||||
msg_message("use_item", "unit item", user, itype->rtype));
|
msg_message("use_item", "unit item", user, itype->rtype));
|
||||||
|
|
||||||
|
|
|
@ -406,10 +406,9 @@ void save_special_items(unit *usrc)
|
||||||
faction *fm = get_monsters();
|
faction *fm = get_monsters();
|
||||||
static const race *rc_ghost;
|
static const race *rc_ghost;
|
||||||
static int cache;
|
static int cache;
|
||||||
static const char *name = NULL;
|
|
||||||
if (rc_changed(&cache)) {
|
if (rc_changed(&cache)) {
|
||||||
rc_ghost = get_race(RC_TEMPLATE);
|
rc_ghost = get_race(RC_TEMPLATE);
|
||||||
name = "ghost";
|
|
||||||
}
|
}
|
||||||
for (u = r->units; u; u = u->next) {
|
for (u = r->units; u; u = u->next) {
|
||||||
if (u->faction == fm) {
|
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);
|
u = create_unit(r, fm, 1, rc_ghost, 0, NULL, NULL);
|
||||||
if (name) {
|
unit_setname(u, unit_getname(usrc));
|
||||||
set_racename(&u->attribs, name);
|
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);
|
give_special_items(u, &usrc->items);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -253,7 +253,7 @@ static void test_set_email(CuTest *tc) {
|
||||||
test_teardown();
|
test_teardown();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_items_notlost(CuTest *tc) {
|
static void test_save_special_items(CuTest *tc) {
|
||||||
unit *u, *ug;
|
unit *u, *ug;
|
||||||
race * rc;
|
race * rc;
|
||||||
struct item_type *itype, *it_silver, *it_horse;
|
struct item_type *itype, *it_silver, *it_horse;
|
||||||
|
@ -266,16 +266,21 @@ static void test_items_notlost(CuTest *tc) {
|
||||||
rc = test_create_race("template");
|
rc = test_create_race("template");
|
||||||
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||||
i_change(&u->items, itype, 1);
|
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);
|
save_special_items(u);
|
||||||
CuAssertPtrNotNull(tc, u->next);
|
CuAssertPtrNotNull(tc, u->next);
|
||||||
ug = u->next;
|
ug = u->next;
|
||||||
CuAssertPtrEquals(tc, NULL, ug->next);
|
CuAssertPtrEquals(tc, NULL, ug->next);
|
||||||
CuAssertPtrEquals(tc, rc, (void *)ug->_race);
|
CuAssertPtrEquals(tc, rc, (void *)ug->_race);
|
||||||
|
CuAssertIntEquals(tc, 1, u->number);
|
||||||
CuAssertIntEquals(tc, 0, i_get(u->items, itype));
|
CuAssertIntEquals(tc, 0, i_get(u->items, itype));
|
||||||
CuAssertIntEquals(tc, 1, i_get(ug->items, itype));
|
CuAssertIntEquals(tc, 1, i_get(ug->items, itype));
|
||||||
CuAssertStrEquals(tc, "ghost", get_racename(ug->attribs));
|
CuAssertStrEquals(tc, "ghost", get_racename(ug->attribs));
|
||||||
|
CuAssertStrEquals(tc, u->_name, ug->_name);
|
||||||
|
|
||||||
i_change(&u->items, itype, 1);
|
i_change(&u->items, itype, 1);
|
||||||
|
/* when there is a monster, it takes all special items: */
|
||||||
save_special_items(u);
|
save_special_items(u);
|
||||||
CuAssertPtrEquals(tc, NULL, ug->next);
|
CuAssertPtrEquals(tc, NULL, ug->next);
|
||||||
CuAssertIntEquals(tc, 2, i_get(ug->items, itype));
|
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, itype, 1);
|
||||||
i_change(&u->items, it_horse, 5);
|
i_change(&u->items, it_horse, 5);
|
||||||
i_change(&u->items, it_silver, 10);
|
i_change(&u->items, it_silver, 10);
|
||||||
|
/* horses and money need to go to the region and are not taken: */
|
||||||
save_special_items(u);
|
save_special_items(u);
|
||||||
CuAssertIntEquals(tc, 3, i_get(ug->items, itype));
|
CuAssertIntEquals(tc, 3, i_get(ug->items, itype));
|
||||||
CuAssertIntEquals(tc, 5, i_get(u->items, it_horse));
|
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_check_passwd);
|
||||||
SUITE_ADD_TEST(suite, test_valid_race);
|
SUITE_ADD_TEST(suite, test_valid_race);
|
||||||
SUITE_ADD_TEST(suite, test_set_email);
|
SUITE_ADD_TEST(suite, test_set_email);
|
||||||
SUITE_ADD_TEST(suite, test_items_notlost);
|
SUITE_ADD_TEST(suite, test_save_special_items);
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
#include <platform.h>
|
#include <platform.h>
|
||||||
#include <kernel/config.h>
|
#include "faction.h"
|
||||||
|
#include "unit.h"
|
||||||
#include "race.h"
|
#include "race.h"
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
|
|
||||||
|
#include <util/language.h>
|
||||||
|
#include <attributes/raceprefix.h>
|
||||||
|
|
||||||
#include <tests.h>
|
#include <tests.h>
|
||||||
#include <CuTest.h>
|
#include <CuTest.h>
|
||||||
|
|
||||||
|
@ -151,6 +155,23 @@ static void test_rc_can_use(CuTest *tc) {
|
||||||
test_teardown();
|
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 *get_race_suite(void)
|
||||||
{
|
{
|
||||||
CuSuite *suite = CuSuiteNew();
|
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_find);
|
||||||
SUITE_ADD_TEST(suite, test_rc_set_param);
|
SUITE_ADD_TEST(suite, test_rc_set_param);
|
||||||
SUITE_ADD_TEST(suite, test_rc_can_use);
|
SUITE_ADD_TEST(suite, test_rc_can_use);
|
||||||
|
SUITE_ADD_TEST(suite, test_racename);
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2065,12 +2065,12 @@ void report_battle_start(battle * b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (first) {
|
if (first) {
|
||||||
sbs_strcpy(&sbs, " ");
|
sbs_strcat(&sbs, " ");
|
||||||
sbs_strcpy(&sbs, LOC(f->locale, "and"));
|
sbs_strcat(&sbs, LOC(f->locale, "and"));
|
||||||
sbs_strcpy(&sbs, " ");
|
sbs_strcat(&sbs, " ");
|
||||||
}
|
}
|
||||||
if (lastf) {
|
if (lastf) {
|
||||||
sbs_strcpy(&sbs, lastf);
|
sbs_strcat(&sbs, lastf);
|
||||||
}
|
}
|
||||||
|
|
||||||
m = msg_message("start_battle", "factions", zText);
|
m = msg_message("start_battle", "factions", zText);
|
||||||
|
|
|
@ -140,7 +140,8 @@ int study_cost(struct unit *u, skill_t sk)
|
||||||
int next_level = 1 + (u ? get_level(u, sk) : 0);
|
int next_level = 1 + (u ? get_level(u, sk) : 0);
|
||||||
/* Die Magiekosten betragen 50+Summe(50*Stufe) */
|
/* Die Magiekosten betragen 50+Summe(50*Stufe) */
|
||||||
/* 'Stufe' ist dabei die naechste zu erreichende 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) {
|
else switch (sk) {
|
||||||
case SK_SPY:
|
case SK_SPY:
|
||||||
|
|
|
@ -418,11 +418,24 @@ static void test_study_magic(CuTest *tc) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_study_cost_magic(CuTest *tc) {
|
static void test_study_cost_magic(CuTest *tc) {
|
||||||
|
unit * u;
|
||||||
|
|
||||||
test_setup();
|
test_setup();
|
||||||
config_set("skills.cost.magic", "50");
|
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
|
||||||
CuAssertIntEquals(tc, 50, study_cost(NULL, SK_MAGIC));
|
|
||||||
|
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");
|
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();
|
test_teardown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -213,6 +213,7 @@ static unsigned int mt_id(const message_type * mtype)
|
||||||
size_t i = strlen(mtype->name);
|
size_t i = strlen(mtype->name);
|
||||||
|
|
||||||
while (i > 0) {
|
while (i > 0) {
|
||||||
|
/* TODO: why not use str_hash? */
|
||||||
key = (mtype->name[--i] + key * 37);
|
key = (mtype->name[--i] + key * 37);
|
||||||
}
|
}
|
||||||
return key % 0x7FFFFFFF;
|
return key % 0x7FFFFFFF;
|
||||||
|
|
Loading…
Reference in a new issue