forked from github/server
Merge branch 'master' of github.com:eressea/core
This commit is contained in:
commit
6ae4f5a646
|
@ -0,0 +1,5 @@
|
|||
cmake_minimum_required(VERSION 2.4)
|
||||
project (core C)
|
||||
|
||||
add_subdirectory (../dependencies "${CMAKE_CURRENT_BINARY_DIR}/dependencies")
|
||||
add_subdirectory (src eressea)
|
|
@ -1,9 +1,14 @@
|
|||
function creation_message(mage, type, number)
|
||||
local msg = message.create("item_create_spell")
|
||||
msg:set_unit("mage", mage)
|
||||
msg:set_int("number", number)
|
||||
msg:set_resource("item", type)
|
||||
return msg
|
||||
local err = 0
|
||||
err = err + msg:set_unit("mage", mage)
|
||||
err = err + msg:set_int("number", number)
|
||||
err = err + msg:set_resource("item", type)
|
||||
if err ~= 0 then
|
||||
return nil
|
||||
else
|
||||
return msg
|
||||
end
|
||||
end
|
||||
|
||||
local function create_item(mage, level, name, number)
|
||||
|
|
|
@ -0,0 +1,189 @@
|
|||
cmake_minimum_required(VERSION 2.4)
|
||||
project (eressea C)
|
||||
|
||||
set (CORE_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE INTERNAL "Eressea Core headers")
|
||||
|
||||
find_package (Lua51 REQUIRED)
|
||||
find_package (LibXml2 REQUIRED)
|
||||
|
||||
include_directories (${CORE_INCLUDE_DIR})
|
||||
include_directories (${CRITBIT_INCLUDE_DIR})
|
||||
include_directories (${CRYPTO_INCLUDE_DIR})
|
||||
include_directories (${QUICKLIST_INCLUDE_DIR})
|
||||
include_directories (${CUTEST_INCLUDE_DIR})
|
||||
include_directories (${LUA_INCLUDE_DIR})
|
||||
include_directories (${LIBXML2_INCLUDE_DIR})
|
||||
include_directories (${BSON_INCLUDE_DIR})
|
||||
include_directories (${INIPARSER_INCLUDE_DIR})
|
||||
|
||||
add_library(${PROJECT_NAME}
|
||||
attributes/alliance.c
|
||||
attributes/attributes.c
|
||||
attributes/fleechance.c
|
||||
attributes/follow.c
|
||||
attributes/giveitem.c
|
||||
attributes/gm.c
|
||||
attributes/hate.c
|
||||
attributes/iceberg.c
|
||||
attributes/key.c
|
||||
attributes/matmod.c
|
||||
attributes/moved.c
|
||||
attributes/movement.c
|
||||
attributes/object.c
|
||||
attributes/orcification.c
|
||||
attributes/otherfaction.c
|
||||
attributes/overrideroads.c
|
||||
attributes/racename.c
|
||||
attributes/raceprefix.c
|
||||
attributes/reduceproduction.c
|
||||
attributes/targetregion.c
|
||||
bindings/bind_attrib.c
|
||||
bindings/bind_building.c
|
||||
bindings/bind_faction.c
|
||||
bindings/bind_gmtool.c
|
||||
bindings/bind_hashtable.c
|
||||
bindings/bindings.c
|
||||
bindings/bind_message.c
|
||||
bindings/bind_region.c
|
||||
bindings/bind_ship.c
|
||||
bindings/bind_sqlite.c
|
||||
bindings/bind_storage.c
|
||||
bindings/bind_unit.c
|
||||
bindings/helpers.c
|
||||
eressea.c
|
||||
gamecode/archetype.c
|
||||
gamecode/creation.c
|
||||
gamecode/creport.c
|
||||
gamecode/economy.c
|
||||
gamecode/economy_test.c
|
||||
gamecode/give.c
|
||||
gamecode/items.c
|
||||
gamecode/laws.c
|
||||
gamecode/laws_test.c
|
||||
gamecode/market.c
|
||||
gamecode/market_test.c
|
||||
gamecode/monster.c
|
||||
gamecode/randenc.c
|
||||
gamecode/report.c
|
||||
gamecode/spy.c
|
||||
gamecode/study.c
|
||||
gamecode/summary.c
|
||||
gamecode/xmlreport.c
|
||||
gmtool.c
|
||||
items/artrewards.c
|
||||
items/demonseye.c
|
||||
items/itemtypes.c
|
||||
items/phoenixcompass.c
|
||||
items/seed.c
|
||||
items/speedsail.c
|
||||
items/weapons.c
|
||||
items/xerewards.c
|
||||
kernel/alchemy.c
|
||||
kernel/alliance.c
|
||||
kernel/battle.c
|
||||
kernel/battle_test.c
|
||||
kernel/binarystore.c
|
||||
kernel/build.c
|
||||
kernel/building.c
|
||||
kernel/building_test.c
|
||||
kernel/calendar.c
|
||||
kernel/command.c
|
||||
kernel/config.c
|
||||
kernel/connection.c
|
||||
kernel/curse.c
|
||||
kernel/curse_test.c
|
||||
kernel/equipment.c
|
||||
kernel/equipment_test.c
|
||||
kernel/faction.c
|
||||
kernel/group.c
|
||||
kernel/item.c
|
||||
kernel/item_test.c
|
||||
kernel/magic.c
|
||||
kernel/magic_test.c
|
||||
kernel/message.c
|
||||
kernel/move.c
|
||||
kernel/move_test.c
|
||||
kernel/names.c
|
||||
kernel/order.c
|
||||
kernel/pathfinder.c
|
||||
kernel/plane.c
|
||||
kernel/player.c
|
||||
kernel/pool.c
|
||||
kernel/pool_test.c
|
||||
kernel/race.c
|
||||
kernel/region.c
|
||||
kernel/reports.c
|
||||
kernel/reports_test.c
|
||||
kernel/resources.c
|
||||
kernel/save.c
|
||||
kernel/ship.c
|
||||
kernel/ship_test.c
|
||||
kernel/skill.c
|
||||
kernel/spellbook.c
|
||||
kernel/spellbook_test.c
|
||||
kernel/spell.c
|
||||
kernel/spell_test.c
|
||||
kernel/sqlite.c
|
||||
kernel/teleport.c
|
||||
kernel/terrain.c
|
||||
kernel/textstore.c
|
||||
kernel/unit.c
|
||||
kernel/xmlreader.c
|
||||
modules/arena.c
|
||||
modules/autoseed.c
|
||||
modules/dungeon.c
|
||||
modules/gmcmd.c
|
||||
modules/museum.c
|
||||
modules/score.c
|
||||
modules/weather.c
|
||||
modules/wormhole.c
|
||||
modules/xecmd.c
|
||||
modules/xmas.c
|
||||
tests.c
|
||||
tests_test.c
|
||||
triggers/changefaction.c
|
||||
triggers/changerace.c
|
||||
triggers/clonedied.c
|
||||
triggers/createcurse.c
|
||||
triggers/createunit.c
|
||||
triggers/gate.c
|
||||
triggers/giveitem.c
|
||||
triggers/killunit.c
|
||||
triggers/removecurse.c
|
||||
triggers/shock.c
|
||||
triggers/timeout.c
|
||||
triggers/triggers.c
|
||||
triggers/unguard.c
|
||||
triggers/unitmessage.c
|
||||
util/attrib.c
|
||||
util/base36.c
|
||||
util/base36_test.c
|
||||
util/bsdstring.c
|
||||
util/bsdstring_test.c
|
||||
util/console.c
|
||||
util/crmessage.c
|
||||
util/dice.c
|
||||
util/eventbus.c
|
||||
util/event.c
|
||||
util/filereader.c
|
||||
util/functions.c
|
||||
util/functions_test.c
|
||||
util/goodies.c
|
||||
util/language.c
|
||||
util/listbox.c
|
||||
util/lists.c
|
||||
util/log.c
|
||||
util/message.c
|
||||
util/nrmessage.c
|
||||
util/os.c
|
||||
util/parser.c
|
||||
util/rand.c
|
||||
util/resolve.c
|
||||
util/sql.c
|
||||
util/strings.c
|
||||
util/translation.c
|
||||
util/umlaut.c
|
||||
util/umlaut_test.c
|
||||
util/unicode.c
|
||||
util/xml.c
|
||||
)
|
|
@ -10,6 +10,8 @@ This program may not be used, modified or distributed
|
|||
without prior permission by the authors of Eressea.
|
||||
*/
|
||||
|
||||
#include <lua.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include <platform.h>
|
||||
#include <kernel/types.h>
|
||||
#include <curses.h>
|
||||
|
||||
#include "bind_gmtool.h"
|
||||
|
|
|
@ -72,6 +72,7 @@ int msg_set_resource(lua_message * msg, const char *param, const char *resname)
|
|||
{
|
||||
if (msg->mtype) {
|
||||
int i = mtype_get_param(msg->mtype, param);
|
||||
const resource_type * rtype;
|
||||
if (i == msg->mtype->nparameters) {
|
||||
return E_INVALID_PARAMETER_NAME;
|
||||
}
|
||||
|
@ -79,8 +80,12 @@ int msg_set_resource(lua_message * msg, const char *param, const char *resname)
|
|||
return E_INVALID_PARAMETER_TYPE;
|
||||
}
|
||||
|
||||
msg->args[i].v = (void *)rt_find(resname);
|
||||
|
||||
rtype = rt_find(resname);
|
||||
if (rtype) {
|
||||
msg->args[i].v = (void *)rtype;
|
||||
} else {
|
||||
return E_INVALID_PARAMETER_VALUE;
|
||||
}
|
||||
return E_OK;
|
||||
}
|
||||
return E_INVALID_MESSAGE;
|
||||
|
|
|
@ -21,6 +21,7 @@ without prior permission by the authors of Eressea.
|
|||
|
||||
#include <kernel/alliance.h>
|
||||
#include <kernel/building.h>
|
||||
#include <kernel/curse.h>
|
||||
#include <kernel/skill.h>
|
||||
#include <kernel/equipment.h>
|
||||
#include <kernel/calendar.h>
|
||||
|
|
|
@ -35,6 +35,7 @@ without prior permission by the authors of Eressea.
|
|||
#include <kernel/alliance.h>
|
||||
#include <kernel/connection.h>
|
||||
#include <kernel/building.h>
|
||||
#include <kernel/curse.h>
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/group.h>
|
||||
#include <kernel/item.h>
|
||||
|
|
|
@ -20,6 +20,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
|
||||
#include <platform.h>
|
||||
#include <kernel/config.h>
|
||||
#include <kernel/types.h>
|
||||
#include "economy.h"
|
||||
|
||||
/* gamecode includes */
|
||||
|
@ -33,6 +34,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <kernel/alchemy.h>
|
||||
#include <kernel/building.h>
|
||||
#include <kernel/calendar.h>
|
||||
#include <kernel/curse.h>
|
||||
#include <kernel/equipment.h>
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/item.h>
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "platform.h"
|
||||
#include <platform.h>
|
||||
#include <kernel/types.h>
|
||||
#include "economy.h"
|
||||
|
||||
#include <kernel/unit.h>
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "economy.h"
|
||||
|
||||
/* kernel includes */
|
||||
#include <kernel/curse.h>
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/item.h>
|
||||
#include <kernel/magic.h>
|
||||
|
|
|
@ -39,6 +39,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <kernel/alliance.h>
|
||||
#include <kernel/battle.h>
|
||||
#include <kernel/connection.h>
|
||||
#include <kernel/curse.h>
|
||||
#include <kernel/building.h>
|
||||
#include <kernel/calendar.h>
|
||||
#include <kernel/faction.h>
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "platform.h"
|
||||
#include <platform.h>
|
||||
#include <kernel/types.h>
|
||||
#include "market.h"
|
||||
#include "tests.h"
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <kernel/build.h>
|
||||
#include <kernel/building.h>
|
||||
#include <kernel/calendar.h>
|
||||
#include <kernel/curse.h>
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/group.h>
|
||||
#include <kernel/item.h>
|
||||
|
|
|
@ -25,6 +25,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
|
||||
#include <kernel/alchemy.h>
|
||||
#include <kernel/building.h>
|
||||
#include <kernel/curse.h>
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/item.h>
|
||||
#include <kernel/magic.h>
|
||||
|
|
|
@ -32,6 +32,7 @@ without prior permission by the authors of Eressea.
|
|||
#include <kernel/alchemy.h>
|
||||
#include <kernel/alliance.h>
|
||||
#include <kernel/connection.h>
|
||||
#include <kernel/curse.h>
|
||||
#include <kernel/building.h>
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/group.h>
|
||||
|
|
|
@ -1,59 +0,0 @@
|
|||
#include <config.h>
|
||||
#include <kernel/eressea.h>
|
||||
#include "studypotion.h"
|
||||
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/item.h>
|
||||
#include <kernel/order.h>
|
||||
#include <kernel/skill.h>
|
||||
#include <kernel/study.h>
|
||||
#include <kernel/unit.h>
|
||||
|
||||
#include <util/attrib.h>
|
||||
#include <util/functions.h>
|
||||
|
||||
/* BEGIN it_studypotion */
|
||||
#define MAXGAIN 15
|
||||
static int
|
||||
use_studypotion(struct unit *u, const struct item_type *itype, int amount,
|
||||
struct order *ord)
|
||||
{
|
||||
if (get_keyword(u->thisorder) == K_STUDY) {
|
||||
skill_t sk;
|
||||
skill *sv;
|
||||
|
||||
init_tokens(u->thisorder);
|
||||
skip_token();
|
||||
sk = findskill(getstrtoken(), u->faction->locale);
|
||||
sv = get_skill(u, sk);
|
||||
|
||||
if (sv && sv->level > 2) {
|
||||
/* TODO: message */
|
||||
} else if (study_cost(u, sk) > 0) {
|
||||
/* TODO: message */
|
||||
} else {
|
||||
attrib *a = a_find(u->attribs, &at_learning);
|
||||
teaching_info *teach;
|
||||
if (a == NULL) {
|
||||
a = a_add(&u->attribs, a_new(&at_learning));
|
||||
}
|
||||
teach = (teaching_info *) a->data.v;
|
||||
if (amount > MAXGAIN)
|
||||
amount = MAXGAIN;
|
||||
teach->value += amount * 30;
|
||||
if (teach->value > MAXGAIN * 30) {
|
||||
teach->value = MAXGAIN * 30;
|
||||
}
|
||||
i_change(&u->items, itype, -amount);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return EUNUSABLE;
|
||||
}
|
||||
|
||||
void register_studypotion(void)
|
||||
{
|
||||
register_function((pf_generic) use_studypotion, "use_studypotion");
|
||||
}
|
||||
|
||||
/* END it_studypotion */
|
|
@ -1,30 +0,0 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, 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_ITM_STUDYPOTION
|
||||
#define H_ITM_STUDYPOTION
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern void register_studypotion(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -83,7 +83,7 @@ void equipment_setskill(equipment * eq, skill_t sk, const char *value)
|
|||
}
|
||||
}
|
||||
|
||||
void equipment_addspell(equipment * eq, spell * sp, int level)
|
||||
void equipment_addspell(equipment * eq, struct spell * sp, int level)
|
||||
{
|
||||
if (eq) {
|
||||
if (!eq->spellbook) {
|
||||
|
|
|
@ -24,6 +24,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
|
||||
#include "alchemy.h"
|
||||
#include "build.h"
|
||||
#include "curse.h"
|
||||
#include "faction.h"
|
||||
#include "message.h"
|
||||
#include "pool.h"
|
||||
|
|
|
@ -22,11 +22,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "curse.h"
|
||||
struct fighter;
|
||||
struct building;
|
||||
struct spellbook;
|
||||
|
||||
/* ------------------------------------------------------------- */
|
||||
|
||||
#define MAXCOMBATSPELLS 3 /* PRECOMBAT COMBAT POSTCOMBAT */
|
||||
|
|
|
@ -38,6 +38,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <util/unicode.h>
|
||||
|
||||
/* libc includes */
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <wctype.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -466,7 +467,7 @@ const char *abkz(const char *s, char *buf, size_t buflen, size_t maxchars)
|
|||
void register_names(void)
|
||||
{
|
||||
register_function((pf_generic) describe_braineater, "describe_braineater");
|
||||
/* function name
|
||||
/* function name
|
||||
* generate a name for a nonplayerunit
|
||||
* race->generate_name() */
|
||||
register_function((pf_generic) undead_name, "nameundead");
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
#include <platform.h>
|
||||
#include <kernel/types.h>
|
||||
|
||||
#include "pool.h"
|
||||
#include "unit.h"
|
||||
#include "item.h"
|
||||
#include "region.h"
|
||||
#include "skill.h"
|
||||
#include <CuTest.h>
|
||||
#include <tests.h>
|
||||
|
||||
|
|
|
@ -50,11 +50,12 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <attributes/raceprefix.h>
|
||||
|
||||
/* libc includes */
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <ctype.h>
|
||||
|
||||
/** external variables **/
|
||||
race *races;
|
||||
|
|
|
@ -62,16 +62,16 @@ static void test_regionid(CuTest * tc) {
|
|||
plain = test_create_terrain("plain", 0);
|
||||
r = test_create_region(0, 0, plain);
|
||||
|
||||
memset(buffer, 0xff, sizeof(buffer));
|
||||
memset(buffer, -2, sizeof(buffer));
|
||||
len = f_regionid(r, 0, buffer, sizeof(buffer));
|
||||
CuAssertIntEquals(tc, 11, len);
|
||||
CuAssertStrEquals(tc, "plain (0,0)", buffer);
|
||||
|
||||
memset(buffer, -1, sizeof(buffer));
|
||||
memset(buffer, -2, sizeof(buffer));
|
||||
len = f_regionid(r, 0, buffer, 11);
|
||||
CuAssertIntEquals(tc, 10, len);
|
||||
CuAssertStrEquals(tc, "plain (0,0", buffer);
|
||||
CuAssertIntEquals(tc, -1, buffer[11]);
|
||||
CuAssertIntEquals(tc, (char)-2, buffer[11]);
|
||||
}
|
||||
|
||||
CuSuite *get_reports_suite(void)
|
||||
|
|
|
@ -98,7 +98,7 @@ static void txt_r_tok_buf(struct storage *store, char *result, size_t size)
|
|||
char format[16];
|
||||
if (result && size > 0) {
|
||||
format[0] = '%';
|
||||
sprintf(format + 1, "%us", size);
|
||||
sprintf(format + 1, "%lus", (unsigned long)size);
|
||||
fscanf((FILE *) store->userdata, format, result);
|
||||
if (result[0] == NULL_TOKEN) {
|
||||
result[0] = 0;
|
||||
|
|
|
@ -38,6 +38,7 @@ struct attrib_type;
|
|||
struct building;
|
||||
struct building_type;
|
||||
struct curse;
|
||||
struct curse_type;
|
||||
struct equipment;
|
||||
struct faction;
|
||||
struct fighter;
|
||||
|
@ -48,6 +49,7 @@ struct luxury_type;
|
|||
struct order;
|
||||
struct plane;
|
||||
struct potion_type;
|
||||
struct quicklist;
|
||||
struct race;
|
||||
struct region;
|
||||
struct region_list;
|
||||
|
|
|
@ -18,12 +18,14 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
|
||||
#include <platform.h>
|
||||
#include <kernel/config.h>
|
||||
#include <kernel/types.h>
|
||||
#include "unit.h"
|
||||
|
||||
#include "building.h"
|
||||
#include "faction.h"
|
||||
#include "group.h"
|
||||
#include "connection.h"
|
||||
#include "curse.h"
|
||||
#include "item.h"
|
||||
#include "move.h"
|
||||
#include "order.h"
|
||||
|
@ -1757,4 +1759,4 @@ struct spellbook * unit_get_spellbook(const struct unit * u)
|
|||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,8 +40,6 @@
|
|||
#include <util/sql.h>
|
||||
#include <util/unicode.h>
|
||||
|
||||
#include <libxml/encoding.h>
|
||||
|
||||
/* libc includes */
|
||||
#include <limits.h>
|
||||
#include <memory.h>
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#include <platform.h>
|
||||
#include <kernel/types.h>
|
||||
#include "tests.h"
|
||||
|
||||
#include "tests_test.c"
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
#include <util/language.h>
|
||||
#include <platform.h>
|
||||
|
||||
#include <kernel/types.h>
|
||||
#include <kernel/item.h>
|
||||
#include <kernel/region.h>
|
||||
|
||||
#include <util/language.h>
|
||||
|
||||
#include <CuTest.h>
|
||||
|
||||
static void test_recreate_world(CuTest * tc)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef UTIL_BSDSTRING_H
|
||||
#define UTIL_BSDSTRING_H
|
||||
|
||||
#include <stddef.h>
|
||||
extern int wrptr(char **ptr, size_t * size, int bytes);
|
||||
|
||||
#ifndef HAVE_STRLCPY
|
||||
|
|
|
@ -15,11 +15,11 @@ static void test_strlcat(CuTest * tc)
|
|||
buffer[0] = '\0';
|
||||
CuAssertIntEquals(tc, 4, strlcat(buffer, "herp", 8));
|
||||
CuAssertStrEquals(tc, "herp", buffer);
|
||||
CuAssertIntEquals(tc, -2, buffer[5]);
|
||||
CuAssertIntEquals(tc, (char)-2, buffer[5]);
|
||||
|
||||
CuAssertIntEquals(tc, 8, strlcat(buffer, "derp", 8));
|
||||
CuAssertStrEquals(tc, "herpder", buffer);
|
||||
CuAssertIntEquals(tc, -2, buffer[8]);
|
||||
CuAssertIntEquals(tc, (char)-2, buffer[8]);
|
||||
}
|
||||
|
||||
static void test_strlcpy(CuTest * tc)
|
||||
|
@ -33,11 +33,11 @@ static void test_strlcpy(CuTest * tc)
|
|||
|
||||
CuAssertIntEquals(tc, 4, strlcpy(buffer, "herp", 8));
|
||||
CuAssertStrEquals(tc, "herp", buffer);
|
||||
CuAssertIntEquals(tc, -2, buffer[5]);
|
||||
CuAssertIntEquals(tc, (char)-2, buffer[5]);
|
||||
|
||||
CuAssertIntEquals(tc, 8, strlcpy(buffer, "herpderp", 8));
|
||||
CuAssertStrEquals(tc, "herpder", buffer);
|
||||
CuAssertIntEquals(tc, -2, buffer[8]);
|
||||
CuAssertIntEquals(tc, (char)-2, buffer[8]);
|
||||
}
|
||||
|
||||
static void test_slprintf(CuTest * tc)
|
||||
|
@ -51,11 +51,11 @@ static void test_slprintf(CuTest * tc)
|
|||
|
||||
CuAssertIntEquals(tc, 4, slprintf(buffer, 8, "%s", "herp"));
|
||||
CuAssertStrEquals(tc, "herp", buffer);
|
||||
CuAssertIntEquals(tc, -2, buffer[5]);
|
||||
CuAssertIntEquals(tc, (char)-2, buffer[5]);
|
||||
|
||||
CuAssertIntEquals(tc, 8, slprintf(buffer, 8, "%s", "herpderp"));
|
||||
CuAssertStrEquals(tc, "herpder", buffer);
|
||||
CuAssertIntEquals(tc, -2, buffer[8]);
|
||||
CuAssertIntEquals(tc, (char)-2, buffer[8]);
|
||||
}
|
||||
|
||||
CuSuite *get_bsdstring_suite(void)
|
||||
|
|
193
src/util/graph.c
193
src/util/graph.c
|
@ -1,193 +0,0 @@
|
|||
/* vi: set ts=2:
|
||||
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
| | Enno Rehling <enno@eressea.de>
|
||||
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
|
||||
| (c) 1998 - 2003 | Henning Peters <faroul@beyond.kn-bremen.de>
|
||||
| | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de>
|
||||
+-------------------+ Stefan Reich <reich@halbling.de>
|
||||
|
||||
This program may not be used, modified or distributed
|
||||
without prior permission by the authors of Eressea.
|
||||
*/
|
||||
|
||||
/* This is a very simple graph library. It is not optimized in any
|
||||
way, and relies heavily on the vset and stack routines. */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "vset.h"
|
||||
#include "graph.h"
|
||||
|
||||
void graph_init(graph * g)
|
||||
{
|
||||
vset_init(&g->nodes);
|
||||
vset_init(&g->edges);
|
||||
}
|
||||
|
||||
void graph_free(graph * g)
|
||||
{
|
||||
vset_destroy(&g->nodes);
|
||||
vset_destroy(&g->edges);
|
||||
}
|
||||
|
||||
void graph_add_node(graph * g, node * n)
|
||||
{
|
||||
vset_add(&g->nodes, n);
|
||||
}
|
||||
|
||||
void graph_add_edge(graph * g, edge * v)
|
||||
{
|
||||
vset_add(&g->nodes, v);
|
||||
}
|
||||
|
||||
void graph_remove_node(graph * g, node * n)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i != g->edges.size; ++i) {
|
||||
edge *v = g->edges.data[i];
|
||||
if (v->node1 == n || v->node2 == n) {
|
||||
vset_erase(&g->nodes, v);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
vset_erase(&g->nodes, n);
|
||||
}
|
||||
|
||||
node *graph_find_node(graph * g, void *object)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i != g->nodes.size; ++i) {
|
||||
node *node = g->nodes.data[i];
|
||||
if (node->object == object) {
|
||||
return g->nodes.data[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* The vset returned has to freed externally, else this will be a
|
||||
memory leak. */
|
||||
|
||||
vset *graph_neighbours(graph * g, node * n)
|
||||
{
|
||||
unsigned int i;
|
||||
vset *vs = malloc(sizeof(vs));
|
||||
vset_init(vs);
|
||||
for (i = 0; i != g->edges.size; ++i) {
|
||||
edge *v = g->edges.data[i];
|
||||
if (v->node1 == n && vset_count(vs, v->node2) == 0) {
|
||||
vset_add(vs, v->node2);
|
||||
} else if (v->node2 == n && vset_count(vs, v->node1) == 0) {
|
||||
vset_add(vs, v->node1);
|
||||
}
|
||||
}
|
||||
|
||||
return vs;
|
||||
}
|
||||
|
||||
void graph_resetmarkers(graph * g)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i != g->nodes.size; ++i) {
|
||||
node *node = g->nodes.data[i];
|
||||
node->marker = 0;
|
||||
}
|
||||
for (i = 0; i != g->edges.size; ++i) {
|
||||
edge *edge = g->edges.data[i];
|
||||
edge->marker = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* The vset returned has to freed externally, else this will be a
|
||||
memory leak. */
|
||||
|
||||
vset *graph_connected_nodes(graph * g, node * n)
|
||||
{
|
||||
vset *vs = malloc(sizeof(vset));
|
||||
vset s;
|
||||
|
||||
vset_init(vs);
|
||||
vset_init(&s);
|
||||
graph_resetmarkers(g);
|
||||
vset_add(vs, n);
|
||||
n->marker = 1;
|
||||
vset_add(&s, n);
|
||||
while (s.size > 0) {
|
||||
node *n = vset_pop(&s);
|
||||
vset *vs_nb = graph_neighbours(g, n);
|
||||
unsigned int i;
|
||||
for (i = 0; i != vs_nb->size; ++i) {
|
||||
node *nb = vs_nb->data[i];
|
||||
if (nb->marker == 0) {
|
||||
nb->marker = 1;
|
||||
vset_add(vs, nb);
|
||||
vset_add(&s, nb);
|
||||
}
|
||||
}
|
||||
vset_destroy(vs_nb);
|
||||
free(vs_nb);
|
||||
}
|
||||
|
||||
vset_destroy(&s);
|
||||
|
||||
return vs;
|
||||
}
|
||||
|
||||
/* The vset returned has to freed externally, else this will be a
|
||||
memory leak. */
|
||||
|
||||
vset *graph_disjunct_graphs(graph * g)
|
||||
{
|
||||
vset *dg = malloc(sizeof(vset));
|
||||
vset nodes;
|
||||
|
||||
vset_init(dg);
|
||||
vset_init(&nodes);
|
||||
vset_concat(&nodes, &g->nodes);
|
||||
|
||||
while (nodes.size > 0) {
|
||||
graph *gt = malloc(sizeof(graph));
|
||||
vset s;
|
||||
unsigned int i;
|
||||
node *start;
|
||||
|
||||
graph_init(gt);
|
||||
start = vset_pop(&nodes);
|
||||
graph_resetmarkers(g);
|
||||
graph_add_node(gt, start);
|
||||
start->marker = 1;
|
||||
vset_init(&s);
|
||||
vset_add(&s, start);
|
||||
while (s.size > 0) {
|
||||
vset *nbs = graph_neighbours(g, vset_pop(&s));
|
||||
for (i = 0; i != nbs->size; ++i) {
|
||||
node *nb = nbs->data[i];
|
||||
if (nb->marker == 0) {
|
||||
nb->marker = 1;
|
||||
graph_add_node(gt, nb);
|
||||
vset_erase(&nodes, nb);
|
||||
vset_add(&s, nb);
|
||||
}
|
||||
}
|
||||
vset_destroy(nbs);
|
||||
free(nbs);
|
||||
}
|
||||
|
||||
vset_destroy(&s);
|
||||
|
||||
for (i = 0; i != g->edges.size; ++i) {
|
||||
edge *v = g->edges.data[i];
|
||||
if (vset_count(&g->nodes, v->node1)) {
|
||||
graph_add_edge(gt, v);
|
||||
}
|
||||
}
|
||||
|
||||
vset_add(dg, gt);
|
||||
}
|
||||
|
||||
vset_destroy(&nodes);
|
||||
|
||||
return dg;
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
/* vi: set ts=2:
|
||||
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
| | Enno Rehling <enno@eressea.de>
|
||||
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
|
||||
| (c) 1998 - 2003 | Henning Peters <faroul@beyond.kn-bremen.de>
|
||||
| | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de>
|
||||
+-------------------+ Stefan Reich <reich@halbling.de>
|
||||
|
||||
This program may not be used, modified or distributed
|
||||
without prior permission by the authors of Eressea.
|
||||
*/
|
||||
|
||||
#ifndef GRAPH_H
|
||||
#define GRAPH_H
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct node {
|
||||
int marker;
|
||||
void *object;
|
||||
} node;
|
||||
|
||||
typedef struct edge {
|
||||
int marker;
|
||||
node *node1;
|
||||
node *node2;
|
||||
} edge;
|
||||
|
||||
typedef struct graph {
|
||||
vset nodes;
|
||||
vset edges;
|
||||
} graph;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -6,13 +6,14 @@
|
|||
| | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de>
|
||||
+-------------------+ Stefan Reich <reich@halbling.de>
|
||||
|
||||
This program may not be used, modified or distributed
|
||||
This program may not be used, modified or distributed
|
||||
without prior permission by the authors of Eressea.
|
||||
*/
|
||||
#include <platform.h>
|
||||
#include "log.h"
|
||||
#include "unicode.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
@ -154,7 +155,7 @@ static void _log_write(FILE * stream, int codepage, const char * prefix, const c
|
|||
if (codepage) {
|
||||
char buffer[MAXLENGTH];
|
||||
char converted[MAXLENGTH];
|
||||
|
||||
|
||||
vsnprintf(buffer, sizeof(buffer), format, args);
|
||||
if (cp_convert(buffer, converted, MAXLENGTH, codepage) == 0) {
|
||||
fputs(converted, stream);
|
||||
|
@ -308,4 +309,3 @@ void log_printf(FILE * io, const char *format, ...)
|
|||
log_flush();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue