forked from github/server
moving directories around for FOSS separation (WIP, DNC)
This commit is contained in:
parent
b28f8ad007
commit
773020e49a
96 changed files with 0 additions and 7179 deletions
src
.cproject.projectbuild_vs2003.batbuild_vs2005.bat
combined
common
bindings
bind_attrib.cbind_attrib.hbind_building.cbind_building.hbind_faction.cbind_faction.hbind_gmtool.cbind_gmtool.hbind_hashtable.cbind_hashtable.hbind_message.cbind_message.hbind_region.cbind_region.hbind_ship.cbind_ship.hbind_sqlite.cbind_storage.cbind_storage.hbind_unit.cbind_unit.hbindings.cbindings.hhelpers.chelpers.h
build
editing.cediting.hgmtool.cgmtool.hgmtool.vcprojgmtool_structs.hlua.hpputil
eressea/lua
alliance.cppbindings.hbindings.vcprojbuilding.cpperessea.cppevent.cppevent.hexport.hfaction.cppgamecode.cppgm.cppitem.cpplist.hmessage.cppobjects.cppobjects.hregion.cppscript.cppscript.hship.cppspell.cpptest.cppunit.cpp
header.txtpremake.luarts.txttodo.txttools
1017
src/.cproject
1017
src/.cproject
File diff suppressed because it is too large
Load diff
82
src/.project
82
src/.project
|
@ -1,82 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>eressea</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
|
||||
<triggers>clean,full,incremental,</triggers>
|
||||
<arguments>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.cleanBuildTarget</key>
|
||||
<value></value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.enableCleanBuild</key>
|
||||
<value>true</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>?name?</key>
|
||||
<value></value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.append_environment</key>
|
||||
<value>true</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.stopOnError</key>
|
||||
<value>true</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.buildCommand</key>
|
||||
<value>make</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.contents</key>
|
||||
<value>org.eclipse.cdt.make.core.activeConfigSettings</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.buildLocation</key>
|
||||
<value>${workspace_loc:/eressea/Debug}</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.useDefaultBuildCmd</key>
|
||||
<value>true</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.enableAutoBuild</key>
|
||||
<value>false</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.enableFullBuild</key>
|
||||
<value>true</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.buildArguments</key>
|
||||
<value></value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.fullBuildTarget</key>
|
||||
<value></value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.autoBuildTarget</key>
|
||||
<value></value>
|
||||
</dictionary>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.cdt.core.ccnature</nature>
|
||||
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
|
||||
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
|
||||
<nature>org.eclipse.cdt.core.cnature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
|
@ -1,2 +0,0 @@
|
|||
REM rebuild eressea projects for VC7.1
|
||||
premake --file premake.lua --target vs2003
|
|
@ -1,2 +0,0 @@
|
|||
REM rebuild eressea projects for VC8
|
||||
premake --file premake.lua --target vs2005
|
|
@ -1,24 +0,0 @@
|
|||
#include "common/settings.h"
|
||||
#include "common/config.h"
|
||||
#include "stdafx.hpp"
|
||||
|
||||
#include "eressea/server.cpp"
|
||||
|
||||
#ifdef BINDINGS_LUABIND
|
||||
#include "eressea/lua/alliance.cpp"
|
||||
#include "eressea/lua/building.cpp"
|
||||
#include "eressea/lua/eressea.cpp"
|
||||
#include "eressea/lua/event.cpp"
|
||||
#include "eressea/lua/faction.cpp"
|
||||
#include "eressea/lua/gamecode.cpp"
|
||||
#include "eressea/lua/gm.cpp"
|
||||
#include "eressea/lua/item.cpp"
|
||||
#include "eressea/lua/message.cpp"
|
||||
#include "eressea/lua/objects.cpp"
|
||||
#include "eressea/lua/region.cpp"
|
||||
#include "eressea/lua/script.cpp"
|
||||
#include "eressea/lua/ship.cpp"
|
||||
#include "eressea/lua/spell.cpp"
|
||||
#include "eressea/lua/test.cpp"
|
||||
#include "eressea/lua/unit.cpp"
|
||||
#endif
|
|
@ -1 +0,0 @@
|
|||
#include "stdafx.hpp"
|
|
@ -1,2 +0,0 @@
|
|||
#include "common/settings.h"
|
||||
#include "common/config.h"
|
|
@ -1,61 +0,0 @@
|
|||
#include <config.h>
|
||||
#include <kernel/eressea.h>
|
||||
|
||||
#include "list.h"
|
||||
|
||||
// kernel includes
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/alliance.h>
|
||||
|
||||
// lua includes
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (push)
|
||||
#pragma warning (disable: 4127)
|
||||
#endif
|
||||
#include <luabind/luabind.hpp>
|
||||
#include <luabind/iterator_policy.hpp>
|
||||
#include <luabind/object.hpp>
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (pop)
|
||||
#endif
|
||||
|
||||
using namespace luabind;
|
||||
|
||||
class factionlist_iterator {
|
||||
public:
|
||||
static faction_list * next(faction_list * node) { return node->next; }
|
||||
static faction * value(faction_list * node) { return node->data; }
|
||||
};
|
||||
|
||||
static eressea::list<faction *, faction_list *, factionlist_iterator>
|
||||
alliance_factions(const alliance& al)
|
||||
{
|
||||
return eressea::list<faction *, faction_list *, factionlist_iterator>(al.members);
|
||||
}
|
||||
|
||||
static alliance *
|
||||
add_alliance(int id, const char * name)
|
||||
{
|
||||
return makealliance(id, name);
|
||||
}
|
||||
|
||||
static eressea::list<alliance *>
|
||||
get_alliances(void) {
|
||||
return eressea::list<alliance *>(alliances);
|
||||
}
|
||||
|
||||
void
|
||||
bind_alliance(lua_State * L)
|
||||
{
|
||||
module(L)[
|
||||
def("alliances", &get_alliances, return_stl_iterator),
|
||||
def("get_alliance", &findalliance),
|
||||
def("add_alliance", &add_alliance),
|
||||
def("victorycondition", &victorycondition),
|
||||
class_<struct alliance>("alliance")
|
||||
.def_readonly("name", &alliance::name)
|
||||
.def_readonly("id", &alliance::id)
|
||||
.property("factions", &alliance_factions, return_stl_iterator)
|
||||
];
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
#ifndef LUA_BINDINGS_H
|
||||
#define LUA_BINDINGS_H
|
||||
|
||||
extern bool is_function(struct lua_State * L, const char * fname);
|
||||
|
||||
extern void bind_region(struct lua_State * L);
|
||||
extern void bind_unit(struct lua_State * L);
|
||||
extern void bind_ship(struct lua_State * L);
|
||||
extern void bind_building(struct lua_State * L);
|
||||
extern void bind_faction(struct lua_State * L);
|
||||
extern void bind_alliance(struct lua_State * L);
|
||||
extern void bind_eressea(struct lua_State * L);
|
||||
extern void bind_spell(struct lua_State * L) ;
|
||||
extern void bind_item(struct lua_State * L);
|
||||
extern void bind_event(struct lua_State * L);
|
||||
extern void bind_message(struct lua_State * L);
|
||||
extern void bind_objects(struct lua_State * L);
|
||||
|
||||
/* test routines */
|
||||
extern void bind_test(struct lua_State * L);
|
||||
|
||||
/* server only */
|
||||
extern void bind_script(struct lua_State * L);
|
||||
extern void bind_gamecode(struct lua_State * L);
|
||||
|
||||
/* gmtool only */
|
||||
extern void bind_gmtool(lua_State * L);
|
||||
|
||||
#endif
|
|
@ -1,311 +0,0 @@
|
|||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="8.00"
|
||||
Name="bindings"
|
||||
ProjectGUID="{74B1CBD4-3B6E-E544-9475-33FBB0BCE165}"
|
||||
RootNamespace="bindings"
|
||||
Keyword="Win32Proj"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="Debug/bindings"
|
||||
IntermediateDirectory="Debug/bindings"
|
||||
ConfigurationType="4"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalOptions="/MP"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="../..;../../common"
|
||||
PreprocessorDefinitions="WIN32;_CRT_SECURE_NO_DEPRECATE"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
EnableFunctionLevelLinking="true"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="4"
|
||||
WarnAsError="true"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="4"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="WIN32;_CRT_SECURE_NO_DEPRECATE"
|
||||
AdditionalIncludeDirectories="../..;../../common"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLibrarianTool"
|
||||
OutputFile="$(OutDir)/bindings.lib"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Profile|Win32"
|
||||
OutputDirectory="Profile/bindings"
|
||||
IntermediateDirectory="Profile/bindings"
|
||||
ConfigurationType="4"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="../..;../../common"
|
||||
PreprocessorDefinitions="WIN32;_CRT_SECURE_NO_DEPRECATE;NDEBUG"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
EnableFunctionLevelLinking="true"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="4"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="4"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="WIN32;_CRT_SECURE_NO_DEPRECATE;NDEBUG"
|
||||
AdditionalIncludeDirectories="../..;../../common"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLibrarianTool"
|
||||
OutputFile="$(OutDir)/bindings.lib"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="Release/bindings"
|
||||
IntermediateDirectory="Release/bindings"
|
||||
ConfigurationType="4"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="3"
|
||||
AdditionalIncludeDirectories="../..;../../common"
|
||||
PreprocessorDefinitions="WIN32;_CRT_SECURE_NO_DEPRECATE;NDEBUG"
|
||||
StringPooling="true"
|
||||
RuntimeLibrary="2"
|
||||
EnableFunctionLevelLinking="true"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="4"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="0"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="WIN32;_CRT_SECURE_NO_DEPRECATE;NDEBUG"
|
||||
AdditionalIncludeDirectories="../..;../../common"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLibrarianTool"
|
||||
OutputFile="$(OutDir)/bindings.lib"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<File
|
||||
RelativePath=".\alliance.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\bindings.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\building.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\eressea.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\event.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\event.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\export.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\faction.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\gamecode.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\item.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\list.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\message.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\objects.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\objects.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\region.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\script.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\script.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\ship.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\spell.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\test.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\unit.cpp"
|
||||
>
|
||||
</File>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
|
@ -1,154 +0,0 @@
|
|||
#include <config.h>
|
||||
#include <kernel/eressea.h>
|
||||
#include "list.h"
|
||||
#include "objects.h"
|
||||
#include "bindings.h"
|
||||
|
||||
// kernel includes
|
||||
#include <kernel/building.h>
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/unit.h>
|
||||
|
||||
// lua includes
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (push)
|
||||
#pragma warning (disable: 4127)
|
||||
#endif
|
||||
#include <lua.hpp>
|
||||
#include <luabind/luabind.hpp>
|
||||
#include <luabind/iterator_policy.hpp>
|
||||
#include <luabind/operator.hpp>
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (pop)
|
||||
#endif
|
||||
|
||||
// util includes
|
||||
#include <util/attrib.h>
|
||||
#include <util/base36.h>
|
||||
#include <util/lists.h>
|
||||
#include <util/log.h>
|
||||
|
||||
using namespace luabind;
|
||||
|
||||
static building *
|
||||
add_building(region * r, const char * name)
|
||||
{
|
||||
const building_type * btype = bt_find(name);
|
||||
if (btype==NULL) return NULL;
|
||||
return new_building(btype, r, NULL);
|
||||
}
|
||||
|
||||
static int
|
||||
lc_age(struct attrib * a)
|
||||
{
|
||||
building_action * data = (building_action*)a->data.v;
|
||||
const char * fname = data->fname;
|
||||
const char * fparam = data->param;
|
||||
building * b = data->b;
|
||||
int retval = -1;
|
||||
|
||||
assert(b!=NULL);
|
||||
if (fname!=NULL) {
|
||||
lua_State * L = (lua_State *)global.vm_state;
|
||||
if (is_function(L, fname)) {
|
||||
try {
|
||||
if (fparam) {
|
||||
std::string param(fparam);
|
||||
retval = luabind::call_function<int>(L, fname, b, param);
|
||||
} else {
|
||||
retval = luabind::call_function<int>(L, fname, b);
|
||||
}
|
||||
}
|
||||
catch (luabind::error& e) {
|
||||
lua_State* L = e.state();
|
||||
const char* error = lua_tostring(L, -1);
|
||||
log_error(("An exception occured while %s tried to call '%s': %s.\n",
|
||||
buildingname(b), fname, error));
|
||||
lua_pop(L, 1);
|
||||
/* std::terminate(); */
|
||||
}
|
||||
}
|
||||
}
|
||||
return (retval!=0)?AT_AGE_KEEP:AT_AGE_REMOVE;
|
||||
}
|
||||
|
||||
static const char *
|
||||
building_getinfo(const building * b)
|
||||
{
|
||||
return (const char*)b->display;
|
||||
}
|
||||
|
||||
static void
|
||||
building_setinfo(building * b, const char * info)
|
||||
{
|
||||
free(b->display);
|
||||
b->display = strdup(info);
|
||||
}
|
||||
|
||||
static std::ostream&
|
||||
operator<<(std::ostream& stream, const building& b)
|
||||
{
|
||||
stream << b.name;
|
||||
stream << " (" << itoa36(b.no) << ")";
|
||||
stream << ", " << b.type->_name;
|
||||
stream << " size " << b.size;
|
||||
return stream;
|
||||
}
|
||||
|
||||
static bool
|
||||
operator==(const building& a, const building&b)
|
||||
{
|
||||
return a.no==b.no;
|
||||
}
|
||||
|
||||
class buildingunit {
|
||||
public:
|
||||
static unit * next(unit * node) {
|
||||
building * b = node->building;
|
||||
do {
|
||||
node = node->next;
|
||||
} while (node !=NULL && node->building!=b);
|
||||
return node;
|
||||
}
|
||||
static unit * value(unit * node) { return node; }
|
||||
};
|
||||
|
||||
|
||||
static eressea::list<unit *, unit *, buildingunit>
|
||||
building_units(const building * b) {
|
||||
region * r = b->region;
|
||||
unit * u = r->units;
|
||||
while (u!=NULL && (!u->building || u->building->no!=b->no)) u=u->next;
|
||||
return eressea::list<unit *, unit *, buildingunit>(u);
|
||||
}
|
||||
|
||||
const char *
|
||||
building_gettype(const building& b) {
|
||||
return b.type->_name;
|
||||
}
|
||||
|
||||
void
|
||||
bind_building(lua_State * L)
|
||||
{
|
||||
at_building_action.age = lc_age;
|
||||
module(L)[
|
||||
def("get_building", &findbuilding),
|
||||
def("add_building", &add_building),
|
||||
|
||||
class_<struct building>("building")
|
||||
.def(self == building())
|
||||
.def(tostring(self))
|
||||
.property("name", &building_getname, &building_setname)
|
||||
.property("info", &building_getinfo, &building_setinfo)
|
||||
.property("units", &building_units, return_stl_iterator)
|
||||
.property("region", &building_getregion, &building_setregion)
|
||||
.property("type", &building_gettype)
|
||||
.def_readonly("id", &building::no)
|
||||
.def_readwrite("size", &building::size)
|
||||
.def("add_action", &building_addaction)
|
||||
.property("objects", &eressea::get_objects<building>)
|
||||
.scope [
|
||||
def("create", &add_building)
|
||||
]
|
||||
];
|
||||
}
|
|
@ -1,242 +0,0 @@
|
|||
#include <config.h>
|
||||
#include <kernel/eressea.h>
|
||||
|
||||
#include "bindings.h"
|
||||
|
||||
#include <attributes/key.h>
|
||||
#include <modules/autoseed.h>
|
||||
#include <modules/score.h>
|
||||
|
||||
// kernel includes
|
||||
#include <kernel/alliance.h>
|
||||
#include <kernel/calendar.h>
|
||||
#include <kernel/equipment.h>
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/item.h>
|
||||
#include <kernel/plane.h>
|
||||
#include <kernel/race.h>
|
||||
#include <kernel/reports.h>
|
||||
#include <kernel/save.h>
|
||||
#include <kernel/skill.h>
|
||||
#include <kernel/teleport.h>
|
||||
#include <kernel/unit.h>
|
||||
|
||||
#include <gamecode/laws.h>
|
||||
|
||||
// lua includes
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (push)
|
||||
#pragma warning (disable: 4127)
|
||||
#endif
|
||||
#include <lua.hpp>
|
||||
#include <luabind/luabind.hpp>
|
||||
#include <luabind/iterator_policy.hpp>
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (pop)
|
||||
#endif
|
||||
|
||||
// util includes
|
||||
#include <util/attrib.h>
|
||||
#include <util/language.h>
|
||||
#include <util/lists.h>
|
||||
#include <util/log.h>
|
||||
#include <util/base36.h>
|
||||
#include <util/rand.h>
|
||||
#include <util/rng.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
|
||||
using namespace luabind;
|
||||
|
||||
static int
|
||||
lua_addequipment(const char * eqname, const char * iname, const char * value)
|
||||
{
|
||||
if (iname==NULL) return -1;
|
||||
const struct item_type * itype = it_find(iname);
|
||||
if (itype==NULL) return -1;
|
||||
equipment_setitem(create_equipment(eqname), itype, value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
get_turn(void)
|
||||
{
|
||||
return turn;
|
||||
}
|
||||
|
||||
static int
|
||||
get_nmrs(int n)
|
||||
{
|
||||
if (n<=NMRTimeout()) {
|
||||
if (nmrs==NULL) update_nmrs();
|
||||
return nmrs[n];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
find_plane_id(const char * name)
|
||||
{
|
||||
plane * pl = getplanebyname(name);
|
||||
return pl?pl->id:0;
|
||||
}
|
||||
|
||||
static bool
|
||||
get_key(const char * name)
|
||||
{
|
||||
int flag = atoi36(name);
|
||||
attrib * a = find_key(global.attribs, flag);
|
||||
return (a!=NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
set_key(const char * name, bool value)
|
||||
{
|
||||
int flag = atoi36(name);
|
||||
attrib * a = find_key(global.attribs, flag);
|
||||
if (a==NULL && value) {
|
||||
add_key(&global.attribs, flag);
|
||||
} else if (a!=NULL && !value) {
|
||||
a_remove(&global.attribs, a);
|
||||
}
|
||||
}
|
||||
|
||||
static const char *
|
||||
get_gamename(void)
|
||||
{
|
||||
return global.gamename;
|
||||
}
|
||||
|
||||
static void
|
||||
lua_setstring(const char * lname, const char * key, const char * str)
|
||||
{
|
||||
struct locale * lang = find_locale(lname);
|
||||
locale_setstring(lang, key, str);
|
||||
}
|
||||
|
||||
static const char *
|
||||
lua_getstring(const char * lname, const char * key)
|
||||
{
|
||||
if (key) {
|
||||
struct locale * lang = find_locale(lname);
|
||||
return (const char*)locale_getstring(lang, key);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#define ISLANDSIZE 20
|
||||
#define TURNS_PER_ISLAND 5
|
||||
static void
|
||||
lua_autoseed(const char * filename, bool new_island)
|
||||
{
|
||||
newfaction * players = read_newfactions(filename);
|
||||
if (players!=NULL) {
|
||||
while (players) {
|
||||
int n = listlen(players);
|
||||
int k = (n+ISLANDSIZE-1)/ISLANDSIZE;
|
||||
k = n / k;
|
||||
n = autoseed(&players, k, new_island?0:TURNS_PER_ISLAND);
|
||||
if (n==0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef LUABIND_NO_EXCEPTIONS
|
||||
static void
|
||||
error_callback(lua_State * L)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
static int
|
||||
get_direction(const char * name)
|
||||
{
|
||||
for (int i=0;i!=MAXDIRECTIONS;++i) {
|
||||
if (strcasecmp(directions[i], name)==0) return i;
|
||||
}
|
||||
return NODIRECTION;
|
||||
}
|
||||
|
||||
static void
|
||||
lua_equipunit(unit * u, const char * eqname)
|
||||
{
|
||||
equip_unit(u, get_equipment(eqname));
|
||||
}
|
||||
|
||||
static void
|
||||
lua_learnskill(unit * u, const char * skname, float chances)
|
||||
{
|
||||
skill_t sk = sk_find(skname);
|
||||
if (sk!=NOSKILL) {
|
||||
learn_skill(u, sk, chances);
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
is_function(struct lua_State * luaState, const char * fname)
|
||||
{
|
||||
object g = globals(luaState);
|
||||
object fun = g[fname];
|
||||
if (fun.is_valid()) {
|
||||
if (type(fun)==LUA_TFUNCTION) {
|
||||
return true;
|
||||
}
|
||||
if (type(fun)!=LUA_TNIL) {
|
||||
log_warning(("Lua global object %s is not a function, type is %u\n", fname, type(fun)));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static const char *
|
||||
get_season(int turnno)
|
||||
{
|
||||
gamedate gd;
|
||||
get_gamedate(turnno, &gd);
|
||||
return seasonnames[gd.season];
|
||||
}
|
||||
|
||||
void
|
||||
bind_eressea(lua_State * L)
|
||||
{
|
||||
module(L)[
|
||||
def("atoi36", &atoi36),
|
||||
def("rng_int", &rng_int),
|
||||
def("itoa36", &itoa36),
|
||||
def("dice_roll", &dice_rand),
|
||||
def("equipment_setitem", &lua_addequipment),
|
||||
def("get_turn", &get_turn),
|
||||
def("get_season", &get_season),
|
||||
def("get_nmrs", &get_nmrs),
|
||||
def("remove_empty_units", &remove_empty_units),
|
||||
|
||||
def("update_subscriptions", &update_subscriptions),
|
||||
def("update_scores", &score),
|
||||
|
||||
def("equip_unit", &lua_equipunit),
|
||||
def("learn_skill", &lua_learnskill),
|
||||
|
||||
/* map making */
|
||||
def("autoseed", lua_autoseed),
|
||||
|
||||
/* string to enum */
|
||||
def("direction", &get_direction),
|
||||
|
||||
/* localization: */
|
||||
def("set_string", &lua_setstring),
|
||||
def("get_string", &lua_getstring),
|
||||
|
||||
def("set_key", &set_key),
|
||||
def("get_key", &get_key),
|
||||
|
||||
def("get_gamename", &get_gamename),
|
||||
/* planes not really implemented */
|
||||
def("get_plane_id", &find_plane_id)
|
||||
];
|
||||
#ifdef LUABIND_NO_EXCEPTIONS
|
||||
luabind::set_error_callback(error_callback);
|
||||
#endif
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
#include <config.h>
|
||||
#include <kernel/eressea.h>
|
||||
#include "event.h"
|
||||
|
||||
// kernel includes
|
||||
#include <kernel/unit.h>
|
||||
|
||||
// util includes
|
||||
#include <util/base36.h>
|
||||
#include <util/event.h>
|
||||
|
||||
// lua includes
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (push)
|
||||
#pragma warning (disable: 4127)
|
||||
#endif
|
||||
#include <lua.hpp>
|
||||
#include <luabind/luabind.hpp>
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (pop)
|
||||
#endif
|
||||
|
||||
using namespace luabind;
|
||||
|
||||
|
||||
const char *
|
||||
event::get_type(int i) const
|
||||
{
|
||||
return args[i].type;
|
||||
}
|
||||
|
||||
struct unit *
|
||||
event::get_unit(int i) const
|
||||
{
|
||||
return (struct unit *)args[i].data.v;
|
||||
}
|
||||
|
||||
const char *
|
||||
event::get_string(int i) const
|
||||
{
|
||||
return (const char*)args[i].data.v;
|
||||
}
|
||||
|
||||
int
|
||||
event::get_int(int i) const
|
||||
{
|
||||
return args[i].data.i;
|
||||
}
|
||||
|
||||
void
|
||||
bind_event(lua_State * L)
|
||||
{
|
||||
module(L)[
|
||||
class_<event>("event")
|
||||
.def("message", &event::get_message)
|
||||
.def("get_type", &event::get_type)
|
||||
.def("get_string", &event::get_string)
|
||||
.def("get_unit", &event::get_unit)
|
||||
.def("get_int", &event::get_int)
|
||||
];
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
#ifndef LUA_EVENT_H
|
||||
#define LUA_EVENT_H
|
||||
class event {
|
||||
public:
|
||||
event(char * m, struct event_arg * a) : args(a), msg(m) {}
|
||||
|
||||
const char * get_message(int i) const { return msg; }
|
||||
const char * get_type(int i) const;
|
||||
struct unit * get_unit(int i) const;
|
||||
const char * get_string(int i) const;
|
||||
int get_int(int i) const;
|
||||
|
||||
private:
|
||||
struct event_arg * args;
|
||||
char * msg;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,12 +0,0 @@
|
|||
#ifndef LUA_EXPORT_H
|
||||
#define LUA_EXPORT_H
|
||||
|
||||
struct lua_State;
|
||||
|
||||
extern void bind_region(struct lua_State * L);
|
||||
extern void bind_unit(struct lua_State * L);
|
||||
extern void bind_ship(struct lua_State * L);
|
||||
extern void bind_building(struct lua_State * L);
|
||||
extern void bind_faction(struct lua_State * L);
|
||||
|
||||
#endif
|
|
@ -1,315 +0,0 @@
|
|||
#include <config.h>
|
||||
#include <kernel/eressea.h>
|
||||
#include "list.h"
|
||||
#include "objects.h"
|
||||
|
||||
// kernel includes
|
||||
#include <kernel/alliance.h>
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/item.h>
|
||||
#include <kernel/message.h>
|
||||
#include <kernel/race.h>
|
||||
#include <kernel/unit.h>
|
||||
|
||||
// util includes
|
||||
#include <util/attrib.h>
|
||||
#include <util/base36.h>
|
||||
#include <util/language.h>
|
||||
|
||||
// attrib includes
|
||||
#include <attributes/attributes.h>
|
||||
#include <attributes/variable.h>
|
||||
|
||||
// lua includes
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (push)
|
||||
#pragma warning (disable: 4127)
|
||||
#endif
|
||||
#include <lua.hpp>
|
||||
#include <luabind/luabind.hpp>
|
||||
#include <luabind/iterator_policy.hpp>
|
||||
#include <luabind/out_value_policy.hpp>
|
||||
#include <luabind/copy_policy.hpp>
|
||||
#include <luabind/operator.hpp>
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (pop)
|
||||
#endif
|
||||
|
||||
#include <ostream>
|
||||
#include <cstring>
|
||||
using namespace luabind;
|
||||
|
||||
static faction *
|
||||
add_faction(const char * email, const char * racename, const char * lang)
|
||||
{
|
||||
const race * frace = findrace(racename, default_locale);
|
||||
if (frace==NULL) frace = findrace(racename, find_locale("de"));
|
||||
if (frace==NULL) frace = findrace(racename, find_locale("en"));
|
||||
if (frace==NULL) return NULL;
|
||||
locale * loc = find_locale(lang);
|
||||
faction * f = addfaction(email, NULL, frace, loc, 0);
|
||||
return f;
|
||||
}
|
||||
|
||||
static eressea::list<faction *>
|
||||
get_factions(void) {
|
||||
return eressea::list<faction *>(factions);
|
||||
}
|
||||
|
||||
class factionunit {
|
||||
public:
|
||||
static unit * next(unit * node) { return node->nextF; }
|
||||
static unit * value(unit * node) { return node; }
|
||||
};
|
||||
|
||||
static eressea::list<unit *, unit *, factionunit>
|
||||
faction_units(const faction * f)
|
||||
{
|
||||
return eressea::list<unit *, unit *, factionunit>(f->units);
|
||||
}
|
||||
|
||||
static void
|
||||
faction_setalliance(faction * f, alliance * team)
|
||||
{
|
||||
if (f->alliance==0) setalliance(f, team);
|
||||
}
|
||||
|
||||
static alliance *
|
||||
faction_getalliance(const faction * f)
|
||||
{
|
||||
return f->alliance;
|
||||
}
|
||||
|
||||
const char *
|
||||
faction_getlocale(const faction * f)
|
||||
{
|
||||
return locale_name(f->locale);
|
||||
}
|
||||
|
||||
void
|
||||
faction_setlocale(faction * f, const char * name)
|
||||
{
|
||||
f->locale = find_locale(name);
|
||||
}
|
||||
|
||||
static std::ostream&
|
||||
operator<<(std::ostream& stream, const faction& f)
|
||||
{
|
||||
stream << factionname(&f);
|
||||
return stream;
|
||||
}
|
||||
|
||||
static bool
|
||||
operator==(const faction& a, const faction&b)
|
||||
{
|
||||
return a.no==b.no;
|
||||
}
|
||||
|
||||
static int
|
||||
faction_getpolicy(const faction * a, const faction * b, const char * flag)
|
||||
{
|
||||
int mode;
|
||||
|
||||
for (mode=0;helpmodes[mode].name!=NULL;++mode) {
|
||||
if (strcmp(flag, helpmodes[mode].name)==0) {
|
||||
return get_alliance(a, b) & mode;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
faction_setpolicy(faction * a, faction * b, const char * flag, bool value)
|
||||
{
|
||||
int mode;
|
||||
|
||||
for (mode=0;helpmodes[mode].name!=NULL;++mode) {
|
||||
if (strcmp(flag, helpmodes[mode].name)==0) {
|
||||
if (value) set_alliance(a, b, get_alliance(a, b) | helpmodes[mode].status);
|
||||
else set_alliance(a, b, get_alliance(a, b) & ~helpmodes[mode].status);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
faction_additem(faction * f, const char * iname, int number)
|
||||
{
|
||||
if (iname!=NULL) {
|
||||
const item_type * itype = it_find(iname);
|
||||
if (itype!=NULL) {
|
||||
item * i = i_change(&f->items, itype, number);
|
||||
return i?i->number:0;
|
||||
} // if (itype!=NULL)
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void
|
||||
faction_addnotice(faction * f, const char * str)
|
||||
{
|
||||
const char * loc = LOC(f->locale, str);
|
||||
ADDMSG(&f->msgs, msg_message("msg_event", "string", loc));
|
||||
}
|
||||
|
||||
static const char *
|
||||
faction_getrace(const faction * f)
|
||||
{
|
||||
return f->race->_name[0];
|
||||
}
|
||||
|
||||
static void
|
||||
faction_setrace(faction * f, const char * rcname)
|
||||
{
|
||||
race * rc = rc_find(rcname);
|
||||
if (rc!=NULL) {
|
||||
f->race = rc;
|
||||
}
|
||||
}
|
||||
|
||||
static eressea::list<std::string, item *, eressea::bind_items>
|
||||
faction_items(const faction * f) {
|
||||
return eressea::list<std::string, item *, eressea::bind_items>(f->items);
|
||||
}
|
||||
|
||||
void
|
||||
faction_set_passw(faction * f, const char * passw)
|
||||
{
|
||||
free(f->passw);
|
||||
f->passw = strdup(passw);
|
||||
}
|
||||
|
||||
const char *
|
||||
faction_get_passw(const faction * f)
|
||||
{
|
||||
return f->passw;
|
||||
}
|
||||
|
||||
void
|
||||
faction_set_banner(faction * f, const char * banner)
|
||||
{
|
||||
free(f->banner);
|
||||
f->banner = strdup(banner);
|
||||
}
|
||||
|
||||
const char *
|
||||
faction_get_banner(const faction * f)
|
||||
{
|
||||
if (f->banner) {
|
||||
return (const char*)f->banner;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
void
|
||||
faction_set_email(faction * f, const char * email)
|
||||
{
|
||||
free(f->email);
|
||||
f->email = strdup(email);
|
||||
}
|
||||
|
||||
const char *
|
||||
faction_get_email(const faction * f)
|
||||
{
|
||||
return f->email;
|
||||
}
|
||||
|
||||
void
|
||||
faction_getorigin(const faction * f, int &x, int &y)
|
||||
{
|
||||
ursprung * origin = f->ursprung;
|
||||
while (origin!=NULL && origin->id!=0) {
|
||||
origin = origin->next;
|
||||
}
|
||||
if (origin) {
|
||||
x = origin->x;
|
||||
y = origin->y;
|
||||
} else {
|
||||
x = 0;
|
||||
y = 0;
|
||||
}
|
||||
}
|
||||
int
|
||||
faction_getorigin_x(const faction * f) {
|
||||
return f->ursprung->x;
|
||||
}
|
||||
void
|
||||
faction_setorigin_x(faction * f, int x) {
|
||||
f->ursprung->x = x;
|
||||
}
|
||||
|
||||
static int
|
||||
faction_getorigin_y(const faction * f) {
|
||||
return f->ursprung->y;
|
||||
}
|
||||
|
||||
static void
|
||||
faction_setorigin_y(faction * f, int y) {
|
||||
f->ursprung->y = y;
|
||||
}
|
||||
|
||||
static int
|
||||
faction_countheroes(const faction * f)
|
||||
{
|
||||
return countheroes(f);
|
||||
}
|
||||
|
||||
static void
|
||||
faction_renumber(faction * f, int no)
|
||||
{
|
||||
renumber_faction(f, no);
|
||||
}
|
||||
|
||||
static int
|
||||
faction_maxheroes(const faction * f)
|
||||
{
|
||||
return maxheroes(f);
|
||||
}
|
||||
|
||||
void
|
||||
bind_faction(lua_State * L)
|
||||
{
|
||||
module(L)[
|
||||
def("factions", &get_factions, return_stl_iterator),
|
||||
def("get_faction", &findfaction),
|
||||
def("faction_origin", &faction_getorigin, pure_out_value(_2) + pure_out_value(_3)),
|
||||
|
||||
class_<struct faction>("faction")
|
||||
.def(tostring(const_self))
|
||||
.def(self == faction())
|
||||
.def("set_policy", &faction_setpolicy)
|
||||
.def("get_policy", &faction_getpolicy)
|
||||
|
||||
// heroes
|
||||
.def("heroes", &faction_countheroes)
|
||||
.def("max_heroes", &faction_maxheroes)
|
||||
|
||||
.def_readonly("name", &faction::name)
|
||||
.def_readonly("score", &faction::score)
|
||||
.def_readonly("id", &faction::no)
|
||||
.def_readwrite("age", &faction::age)
|
||||
.def_readwrite("options", &faction::options)
|
||||
.def_readwrite("flags", &faction::flags)
|
||||
.def_readwrite("subscription", &faction::subscription)
|
||||
.def_readwrite("lastturn", &faction::lastorders)
|
||||
|
||||
.def("add_item", &faction_additem)
|
||||
.property("items", &faction_items, return_stl_iterator)
|
||||
.property("x", &faction_getorigin_x, &faction_setorigin_x)
|
||||
.property("y", &faction_getorigin_y, &faction_setorigin_y)
|
||||
|
||||
.def("renum", &faction_renumber)
|
||||
.def("add_notice", &faction_addnotice)
|
||||
.property("password", &faction_get_passw, &faction_set_passw)
|
||||
.property("info", &faction_get_banner, &faction_set_banner)
|
||||
.property("email", &faction_get_email, &faction_set_email)
|
||||
.property("locale", &faction_getlocale, &faction_setlocale)
|
||||
.property("units", &faction_units, return_stl_iterator)
|
||||
.property("alliance", &faction_getalliance, &faction_setalliance)
|
||||
.property("race", &faction_getrace, &faction_setrace)
|
||||
.property("objects", &eressea::get_objects<faction>)
|
||||
.scope [
|
||||
def("create", &add_faction)
|
||||
]
|
||||
];
|
||||
}
|
|
@ -1,223 +0,0 @@
|
|||
#include <config.h>
|
||||
#include <kernel/eressea.h>
|
||||
|
||||
#include "script.h"
|
||||
#include "../korrektur.h"
|
||||
|
||||
#include <attributes/key.h>
|
||||
#include <modules/autoseed.h>
|
||||
#include <modules/score.h>
|
||||
|
||||
// gamecode includes
|
||||
#include <gamecode/laws.h>
|
||||
#include <gamecode/monster.h>
|
||||
#include <gamecode/creport.h>
|
||||
#include <gamecode/report.h>
|
||||
#include <gamecode/summary.h>
|
||||
|
||||
#include <spells/spells.h>
|
||||
|
||||
// kernel includes
|
||||
#include <kernel/alliance.h>
|
||||
#include <kernel/equipment.h>
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/item.h>
|
||||
#include <kernel/ship.h>
|
||||
#include <kernel/message.h>
|
||||
#include <kernel/plane.h>
|
||||
#include <kernel/race.h>
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/reports.h>
|
||||
#include <kernel/save.h>
|
||||
#include <kernel/skill.h>
|
||||
#include <kernel/teleport.h>
|
||||
#include <kernel/unit.h>
|
||||
|
||||
// lua includes
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (push)
|
||||
#pragma warning (disable: 4127)
|
||||
#endif
|
||||
#include <lua.hpp>
|
||||
#include <luabind/luabind.hpp>
|
||||
#include <luabind/iterator_policy.hpp>
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (pop)
|
||||
#endif
|
||||
|
||||
// util includes
|
||||
#include <util/lists.h>
|
||||
#include <util/log.h>
|
||||
#include <util/language.h>
|
||||
#include <util/base36.h>
|
||||
#include <util/rand.h>
|
||||
#include <util/rng.h>
|
||||
|
||||
#include <libxml/encoding.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
|
||||
using namespace luabind;
|
||||
|
||||
static void
|
||||
lua_planmonsters(void)
|
||||
{
|
||||
unit * u;
|
||||
faction * f = get_monsters();
|
||||
|
||||
if (f==NULL) return;
|
||||
plan_monsters();
|
||||
for (u=f->units;u;u=u->nextF) {
|
||||
call_script(u);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef LUABIND_NO_EXCEPTIONS
|
||||
static void
|
||||
error_callback(lua_State * L)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
static int
|
||||
lua_writereport(faction * f)
|
||||
{
|
||||
time_t ltime = time(0);
|
||||
return write_reports(f, ltime);
|
||||
}
|
||||
|
||||
static int
|
||||
lua_writereports(void)
|
||||
{
|
||||
init_reports();
|
||||
return reports();
|
||||
}
|
||||
|
||||
static void
|
||||
message_unit(unit * sender, unit * target, const char * str)
|
||||
{
|
||||
deliverMail(target->faction, sender->region, sender, str, target);
|
||||
}
|
||||
|
||||
static void
|
||||
message_faction(unit * sender, faction * target, const char * str)
|
||||
{
|
||||
deliverMail(target, sender->region, sender, str, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
message_region(unit * sender, const char * str)
|
||||
{
|
||||
ADDMSG(&sender->region->msgs, msg_message("mail_result", "unit message", sender, str));
|
||||
}
|
||||
|
||||
static void
|
||||
set_encoding(const char * str)
|
||||
{
|
||||
enc_gamedata = xmlParseCharEncoding(str);
|
||||
}
|
||||
|
||||
static const char *
|
||||
get_encoding(void)
|
||||
{
|
||||
return xmlGetCharEncodingName((xmlCharEncoding)enc_gamedata);
|
||||
}
|
||||
|
||||
static int
|
||||
read_game(const char * filename, const char * mode)
|
||||
{
|
||||
int rv, m = IO_TEXT;
|
||||
if (strcmp(mode, "binary")==0) m = IO_BINARY;
|
||||
rv = readgame(filename, m, false);
|
||||
if (rv==0) {
|
||||
log_printf(" - Korrekturen Runde %d\n", turn);
|
||||
korrektur();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
static int
|
||||
write_game(const char *filename, const char * mode)
|
||||
{
|
||||
int result, m = IO_TEXT;
|
||||
if (strcmp(mode, "binary")==0) m = IO_BINARY;
|
||||
remove_empty_factions(true);
|
||||
result = writegame(filename, m);
|
||||
return result;
|
||||
}
|
||||
|
||||
static summary * sum_begin = 0;
|
||||
|
||||
static int
|
||||
init_summary()
|
||||
{
|
||||
sum_begin = make_summary();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
write_summary()
|
||||
{
|
||||
assert(sum_begin
|
||||
|| !"init_summary must be called before before write_summary");
|
||||
if (sum_begin) {
|
||||
summary * sum_end = make_summary();
|
||||
report_summary(sum_end, sum_begin, false);
|
||||
report_summary(sum_end, sum_begin, true);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
process_orders(void)
|
||||
{
|
||||
turn++;
|
||||
processorders();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
bind_gamecode(lua_State * L)
|
||||
{
|
||||
module(L)[
|
||||
def("read_game", &read_game),
|
||||
def("write_game", &write_game),
|
||||
def("free_game", &free_gamedata),
|
||||
|
||||
def("get_encoding", &get_encoding),
|
||||
def("set_encoding", &set_encoding),
|
||||
|
||||
def("init_summary", &init_summary),
|
||||
def("write_summary", &write_summary),
|
||||
|
||||
def("read_orders", &readorders),
|
||||
def("process_orders", &process_orders),
|
||||
|
||||
def("write_map", &crwritemap),
|
||||
def("write_passwords", &writepasswd),
|
||||
def("init_reports", &init_reports),
|
||||
def("write_reports", &lua_writereports),
|
||||
def("write_report", &lua_writereport),
|
||||
def("update_guards", &update_guards),
|
||||
|
||||
def("message_unit", &message_unit),
|
||||
def("message_faction", &message_faction),
|
||||
def("message_region", &message_region),
|
||||
|
||||
/* spells and stuff */
|
||||
def("levitate_ship", &levitate_ship),
|
||||
|
||||
/* scripted monsters */
|
||||
def("spawn_braineaters", &spawn_braineaters),
|
||||
def("spawn_undead", &spawn_undead),
|
||||
def("spawn_dragons", &spawn_dragons),
|
||||
def("plan_monsters", &lua_planmonsters)
|
||||
];
|
||||
#ifdef LUABIND_NO_EXCEPTIONS
|
||||
luabind::set_error_callback(error_callback);
|
||||
#endif
|
||||
}
|
|
@ -1,121 +0,0 @@
|
|||
#include <config.h>
|
||||
#include <kernel/eressea.h>
|
||||
|
||||
#include "bindings.h"
|
||||
#include "list.h"
|
||||
#include "../gmtool.h"
|
||||
#include "../gmtool_structs.h"
|
||||
|
||||
#include <kernel/region.h>
|
||||
|
||||
// lua includes
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (push)
|
||||
#pragma warning (disable: 4127)
|
||||
#endif
|
||||
#include <lua.hpp>
|
||||
#include <luabind/luabind.hpp>
|
||||
#include <luabind/iterator_policy.hpp>
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (pop)
|
||||
#endif
|
||||
|
||||
using namespace luabind;
|
||||
|
||||
region *
|
||||
current_region(void)
|
||||
{
|
||||
map_region * mr = cursor_region(¤t_state->display, ¤t_state->cursor);
|
||||
return mr?mr->r:NULL;
|
||||
}
|
||||
|
||||
static tag *
|
||||
next_tag(int hash, const state * st)
|
||||
{
|
||||
while (st && hash!=MAXTHASH) {
|
||||
tag * node = st->selected->tags[hash];
|
||||
while (node!=NULL) {
|
||||
region * r = findregion((short)node->coord.x, (short)node->coord.y);
|
||||
if (r) {
|
||||
return node;
|
||||
}
|
||||
node = node->nexthash;
|
||||
}
|
||||
++hash;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
class selectedregion {
|
||||
public:
|
||||
static tag * next(tag * self) {
|
||||
tag * node = self->nexthash;
|
||||
while (node) {
|
||||
region * r = findregion((short)node->coord.x, (short)node->coord.y);
|
||||
if (r) return node;
|
||||
node = node->nexthash;
|
||||
}
|
||||
coordinate * c = &self->coord;
|
||||
unsigned int hash;
|
||||
int nx, ny;
|
||||
|
||||
cnormalize(c, &nx, &ny);
|
||||
hash = ((nx << 12) ^ ny) & (MAXTHASH-1);
|
||||
|
||||
return next_tag(hash+1, current_state);
|
||||
}
|
||||
|
||||
static region * value(tag * node) {
|
||||
return findregion((short)node->coord.x, (short)node->coord.y);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
static eressea::list<region *, tag *, selectedregion>
|
||||
selected_regions(void)
|
||||
{
|
||||
return eressea::list<region *, tag *, selectedregion>(next_tag(0, current_state));
|
||||
}
|
||||
|
||||
static void
|
||||
gmtool_select_coordinate(int x, int y, bool select)
|
||||
{
|
||||
int nx = x, ny = y;
|
||||
plane * pl = findplane(x, y);
|
||||
pnormalize(&nx, &ny, pl);
|
||||
select_coordinate(current_state->selected, nx, ny, select?1:0);
|
||||
}
|
||||
|
||||
static void
|
||||
gmtool_select_region(region& r, bool select)
|
||||
{
|
||||
select_coordinate(current_state->selected, r.x, r.y, select?1:0);
|
||||
}
|
||||
|
||||
static void gmtool_open(void)
|
||||
{
|
||||
state_open();
|
||||
}
|
||||
|
||||
static void gmtool_close(void)
|
||||
{
|
||||
state_close(current_state);
|
||||
}
|
||||
|
||||
void
|
||||
bind_gmtool(lua_State * L)
|
||||
{
|
||||
module(L, "gmtool")[
|
||||
def("open", &gmtool_open),
|
||||
def("close", &gmtool_close),
|
||||
def("editor", &run_mapper),
|
||||
def("get_selection", &selected_regions, return_stl_iterator),
|
||||
def("get_cursor", ¤t_region),
|
||||
def("highlight", &highlight_region),
|
||||
def("select", &gmtool_select_region),
|
||||
def("select_at", &gmtool_select_coordinate)
|
||||
];
|
||||
#ifdef LUABIND_NO_EXCEPTIONS
|
||||
luabind::set_error_callback(error_callback);
|
||||
#endif
|
||||
}
|
|
@ -1,133 +0,0 @@
|
|||
#include <config.h>
|
||||
#include <kernel/eressea.h>
|
||||
|
||||
#include "bindings.h"
|
||||
#include "script.h"
|
||||
|
||||
// kernel includes
|
||||
#include <kernel/item.h>
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/unit.h>
|
||||
|
||||
// util includes
|
||||
#include <util/attrib.h>
|
||||
#include <util/functions.h>
|
||||
#include <util/log.h>
|
||||
|
||||
// lua includes
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (push)
|
||||
#pragma warning (disable: 4127)
|
||||
#endif
|
||||
#include <lua.hpp>
|
||||
#include <luabind/luabind.hpp>
|
||||
#include <luabind/iterator_policy.hpp>
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (pop)
|
||||
#endif
|
||||
|
||||
using namespace luabind;
|
||||
|
||||
static int
|
||||
lua_giveitem(unit * s, unit * d, const item_type * itype, int n, struct order * ord)
|
||||
{
|
||||
char fname[64];
|
||||
int retval = -1;
|
||||
const char * iname = itype->rtype->_name[0];
|
||||
|
||||
assert(s!=NULL);
|
||||
strcat(strcpy(fname, iname), "_give");
|
||||
|
||||
lua_State * L = (lua_State *)global.vm_state;
|
||||
if (is_function(L, fname)) {
|
||||
try {
|
||||
retval = luabind::call_function<int>(L, fname, s, d, iname, n);
|
||||
}
|
||||
catch (luabind::error& e) {
|
||||
lua_State* L = e.state();
|
||||
const char* error = lua_tostring(L, -1);
|
||||
log_error(("An exception occured while %s tried to call '%s': %s.\n",
|
||||
unitname(s), fname, error));
|
||||
lua_pop(L, 1);
|
||||
std::terminate();
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
static void
|
||||
item_register(const char * name, const char * appearance)
|
||||
{
|
||||
resource_type * rtype = (resource_type *)calloc(1, sizeof(resource_type));
|
||||
item_type * itype = (item_type *)calloc(1, sizeof(item_type));
|
||||
|
||||
rtype->_name[0] = strdup(name);
|
||||
rtype->_name[1] = strcat(strcpy((char*)malloc(strlen(name)+3), name), "_p");
|
||||
rtype->_appearance[0] = strdup(appearance);
|
||||
rtype->_appearance[1] = strcat(strcpy((char*)malloc(strlen(appearance)+3), appearance), "_p");
|
||||
|
||||
itype->use = lua_useitem;
|
||||
itype->rtype = rtype;
|
||||
|
||||
rt_register(rtype);
|
||||
it_register(itype);
|
||||
init_itemnames();
|
||||
}
|
||||
|
||||
static int
|
||||
limit_resource(const region * r, const resource_type * rtype)
|
||||
{
|
||||
char fname[64];
|
||||
snprintf(fname, sizeof(fname), "%s_limit", rtype->_name[0]);
|
||||
int retval = -1;
|
||||
|
||||
lua_State * L = (lua_State *)global.vm_state;
|
||||
if (is_function(L, fname)) {
|
||||
try {
|
||||
retval = call_function<int>(L, fname, r);
|
||||
}
|
||||
catch (error& e) {
|
||||
lua_State* L = e.state();
|
||||
const char* error = lua_tostring(L, -1);
|
||||
log_error(("An exception occured while trying to call '%s': %s.\n",
|
||||
fname, error));
|
||||
lua_pop(L, 1);
|
||||
std::terminate();
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
static void
|
||||
produce_resource(region * r, const resource_type * rtype, int norders)
|
||||
{
|
||||
char fname[64];
|
||||
snprintf(fname, sizeof(fname), "%s_produce", rtype->_name[0]);
|
||||
|
||||
lua_State * L = (lua_State *)global.vm_state;
|
||||
if (is_function(L, fname)) {
|
||||
try {
|
||||
call_function<void>(L, fname, r, norders);
|
||||
}
|
||||
catch (error& e) {
|
||||
lua_State* L = e.state();
|
||||
const char* error = lua_tostring(L, -1);
|
||||
log_error(("An exception occured while trying to call '%s': %s.\n",
|
||||
fname, error));
|
||||
lua_pop(L, 1);
|
||||
std::terminate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
bind_item(lua_State * L)
|
||||
{
|
||||
register_function((pf_generic)produce_resource, "lua_produceresource");
|
||||
register_function((pf_generic)limit_resource, "lua_limitresource");
|
||||
register_item_give(lua_giveitem, "lua_giveitem");
|
||||
|
||||
module(L)[
|
||||
def("register_item", &item_register)
|
||||
];
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
#ifndef LUA_LIST_H
|
||||
#define LUA_LIST_H
|
||||
|
||||
#include <string>
|
||||
#include <kernel/item.h>
|
||||
|
||||
namespace eressea {
|
||||
|
||||
template<class T, class N = T>
|
||||
class listnode {
|
||||
public:
|
||||
static N next(N& node) { return node->next; }
|
||||
static T value(N& node) { return node; }
|
||||
};
|
||||
|
||||
template<class T, class N = T, class nodetype = listnode<T, N> >
|
||||
class list {
|
||||
public:
|
||||
class iterator {
|
||||
public:
|
||||
iterator(const N& index) : m_index(index) {}
|
||||
~iterator() {}
|
||||
T operator*() { return nodetype::value(m_index); }
|
||||
bool operator==(const iterator& iter) {
|
||||
return iter.m_index==m_index;
|
||||
}
|
||||
bool operator!=(const iterator& iter) {
|
||||
return iter.m_index!=m_index;
|
||||
}
|
||||
iterator& operator++() {
|
||||
if (m_index) m_index = nodetype::next(m_index);
|
||||
return *this;
|
||||
}
|
||||
private:
|
||||
N m_index;
|
||||
};
|
||||
typedef iterator const_iterator;
|
||||
list<T, N, nodetype>(const N& clist) : m_clist(clist) {}
|
||||
iterator begin() const { return iterator(m_clist); }
|
||||
iterator end() const { return iterator(NULL); }
|
||||
|
||||
public:
|
||||
N m_clist;
|
||||
};
|
||||
|
||||
class bind_items {
|
||||
public:
|
||||
static item * next(item * node) { return node->next; }
|
||||
static std::string value(item * node) {
|
||||
return std::string(node->type->rtype->_name[0]);
|
||||
}
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,204 +0,0 @@
|
|||
#include <config.h>
|
||||
#include <kernel/eressea.h>
|
||||
|
||||
// kernel includes
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/item.h>
|
||||
#include <kernel/message.h>
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/unit.h>
|
||||
|
||||
// util includes
|
||||
#include <util/message.h>
|
||||
|
||||
// lua includes
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (push)
|
||||
#pragma warning (disable: 4127)
|
||||
#endif
|
||||
#include <lua.hpp>
|
||||
#include <luabind/luabind.hpp>
|
||||
#include <luabind/iterator_policy.hpp>
|
||||
#include <luabind/operator.hpp>
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (pop)
|
||||
#endif
|
||||
|
||||
#include <ostream>
|
||||
|
||||
using namespace luabind;
|
||||
|
||||
#define E_OK 0
|
||||
#define E_INVALID_MESSAGE 1
|
||||
#define E_INVALID_PARAMETER_NAME 2
|
||||
#define E_INVALID_PARAMETER_TYPE 3
|
||||
#define E_INVALID_PARAMETER_VALUE 4
|
||||
|
||||
class lua_message {
|
||||
public:
|
||||
lua_message(const char *type) : msg(0), args(0) {
|
||||
mtype = mt_find(type);
|
||||
if (mtype) {
|
||||
args = (variant*)calloc(mtype->nparameters, sizeof(variant));
|
||||
}
|
||||
}
|
||||
|
||||
~lua_message() {
|
||||
if (msg) msg_release(msg);
|
||||
if (mtype) {
|
||||
for (int i=0;i!=mtype->nparameters;++i) {
|
||||
if (mtype->types[i]->release) {
|
||||
mtype->types[i]->release(args[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int set_resource(const char * param, const char * resname) {
|
||||
if (mtype==0) return E_INVALID_MESSAGE;
|
||||
|
||||
int i = get_param(param);
|
||||
if (i==mtype->nparameters) {
|
||||
return E_INVALID_PARAMETER_NAME;
|
||||
}
|
||||
if (strcmp(mtype->types[i]->name, "resource")!=0) {
|
||||
return E_INVALID_PARAMETER_TYPE;
|
||||
}
|
||||
|
||||
args[i].v = (void*)rt_find(resname);
|
||||
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int set_unit(const char * param, const unit * u) {
|
||||
if (mtype==0) return E_INVALID_MESSAGE;
|
||||
|
||||
int i = get_param(param);
|
||||
if (i==mtype->nparameters) {
|
||||
return E_INVALID_PARAMETER_NAME;
|
||||
}
|
||||
if (strcmp(mtype->types[i]->name, "unit")!=0) {
|
||||
return E_INVALID_PARAMETER_TYPE;
|
||||
}
|
||||
|
||||
args[i].v = (void*)u;
|
||||
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int set_region(const char * param, const region * r) {
|
||||
if (mtype==0) return E_INVALID_MESSAGE;
|
||||
|
||||
int i = get_param(param);
|
||||
if (i==mtype->nparameters) {
|
||||
return E_INVALID_PARAMETER_NAME;
|
||||
}
|
||||
if (strcmp(mtype->types[i]->name, "region")!=0) {
|
||||
return E_INVALID_PARAMETER_TYPE;
|
||||
}
|
||||
|
||||
args[i].v = (void*)r;
|
||||
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int set_string(const char * param, const char * value) {
|
||||
if (mtype==0) return E_INVALID_MESSAGE;
|
||||
|
||||
int i = get_param(param);
|
||||
if (i==mtype->nparameters) {
|
||||
return E_INVALID_PARAMETER_NAME;
|
||||
}
|
||||
if (strcmp(mtype->types[i]->name, "string")!=0) {
|
||||
return E_INVALID_PARAMETER_TYPE;
|
||||
}
|
||||
|
||||
variant var;
|
||||
var.v = (void*)value;
|
||||
args[i] = mtype->types[i]->copy(var);
|
||||
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int set_int(const char * param, int value) {
|
||||
if (mtype==0) return E_INVALID_MESSAGE;
|
||||
|
||||
int i = get_param(param);
|
||||
if (i==mtype->nparameters) {
|
||||
return E_INVALID_PARAMETER_NAME;
|
||||
}
|
||||
if (strcmp(mtype->types[i]->name, "int")!=0) {
|
||||
return E_INVALID_PARAMETER_TYPE;
|
||||
}
|
||||
|
||||
args[i].i = value;
|
||||
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int send_faction(faction * f) {
|
||||
if (mtype==0) return E_INVALID_MESSAGE;
|
||||
if (msg==NULL) {
|
||||
msg = msg_create(mtype, args);
|
||||
}
|
||||
add_message(&f->msgs, msg);
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int send_region(region * r) {
|
||||
if (mtype==0) return E_INVALID_MESSAGE;
|
||||
if (msg==NULL) {
|
||||
msg = msg_create(mtype, args);
|
||||
}
|
||||
add_message(&r->msgs, msg);
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
protected:
|
||||
int get_param(const char * param) {
|
||||
for (int i=0;i!=mtype->nparameters;++i) {
|
||||
if (strcmp(mtype->pnames[i], param)==0) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return mtype->nparameters;
|
||||
}
|
||||
|
||||
const message_type * mtype;
|
||||
message * msg;
|
||||
variant * args;
|
||||
};
|
||||
|
||||
static std::ostream&
|
||||
operator<<(std::ostream& stream, const lua_message& msg)
|
||||
{
|
||||
stream << "(message object)";
|
||||
return stream;
|
||||
}
|
||||
|
||||
lua_message *
|
||||
create_lua_message(const char * str)
|
||||
{
|
||||
return new lua_message(str);
|
||||
}
|
||||
|
||||
void
|
||||
bind_message(lua_State * L)
|
||||
{
|
||||
module(L)[
|
||||
class_<lua_message>("message")
|
||||
.def(constructor<const char *>())
|
||||
.def(tostring(const_self))
|
||||
|
||||
.def("set_unit", &lua_message::set_unit)
|
||||
.def("set_region", &lua_message::set_region)
|
||||
.def("set_resource", &lua_message::set_resource)
|
||||
.def("set_int", &lua_message::set_int)
|
||||
.def("set_string", &lua_message::set_string)
|
||||
.def("send_faction", &lua_message::send_faction)
|
||||
.def("send_region", &lua_message::send_region)
|
||||
.scope [
|
||||
def("create", &create_lua_message)
|
||||
]
|
||||
];
|
||||
}
|
|
@ -1,117 +0,0 @@
|
|||
#include <config.h>
|
||||
#include <kernel/eressea.h>
|
||||
#include "objects.h"
|
||||
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/unit.h>
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/ship.h>
|
||||
#include <kernel/building.h>
|
||||
#include <util/attrib.h>
|
||||
|
||||
// lua includes
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (push)
|
||||
#pragma warning (disable: 4127)
|
||||
#endif
|
||||
#include <lua.hpp>
|
||||
#include <luabind/luabind.hpp>
|
||||
#include <luabind/object.hpp>
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (pop)
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
|
||||
using namespace luabind;
|
||||
|
||||
namespace eressea {
|
||||
|
||||
object objects::get(const char * name) {
|
||||
lua_State * L = (lua_State *) global.vm_state;
|
||||
attrib * a = a_find(*mAttribPtr, &at_object);
|
||||
for (; a && a->type == &at_object; a = a->next) {
|
||||
if (strcmp(object_name(a), name) == 0) {
|
||||
variant val;
|
||||
object_type type;
|
||||
|
||||
object_get(a, &type, &val);
|
||||
switch (type) {
|
||||
case TNONE:
|
||||
break;
|
||||
case TINTEGER:
|
||||
return object(L, val.i);
|
||||
case TREAL:
|
||||
return object(L, val.f);
|
||||
case TREGION:
|
||||
return object(L, (region*) val.v);
|
||||
case TBUILDING:
|
||||
return object(L, (building*) val.v);
|
||||
case TUNIT:
|
||||
return object(L, (unit*) val.v);
|
||||
case TSHIP:
|
||||
return object(L, (ship*) val.v);
|
||||
case TSTRING:
|
||||
return object(L, (const char*) val.v);
|
||||
default:
|
||||
assert(!"not implemented");
|
||||
}
|
||||
}
|
||||
}
|
||||
return object(); // nil
|
||||
}
|
||||
|
||||
static void set_object(attrib **attribs, const char * name, object_type type,
|
||||
variant val) {
|
||||
attrib * a = a_find(*attribs, &at_object);
|
||||
for (; a && a->type == &at_object; a = a->next) {
|
||||
if (strcmp(object_name(a), name) == 0) {
|
||||
object_set(a, type, val);
|
||||
return;
|
||||
}
|
||||
}
|
||||
a = a_add(attribs, object_create(name, type, val));
|
||||
}
|
||||
|
||||
template<> void objects::set<int, TINTEGER>(const char * name, int value) {
|
||||
variant val = { 0 };
|
||||
val.i = value;
|
||||
set_object(mAttribPtr, name, TINTEGER, val);
|
||||
}
|
||||
|
||||
template<> void objects::set<double, TREAL>(const char * name, double value) {
|
||||
variant val = { 0 };
|
||||
val.f = (float) value;
|
||||
set_object(mAttribPtr, name, TREAL, val);
|
||||
}
|
||||
|
||||
template<> void objects::set<const char *, TSTRING>(const char * name,
|
||||
const char * value) {
|
||||
variant val = { 0 };
|
||||
if (value) val.v = strdup(value);
|
||||
set_object(mAttribPtr, name, TSTRING, val);
|
||||
}
|
||||
|
||||
template<class V, object_type T> void objects::set(const char * name, V value) {
|
||||
variant val = { 0 };
|
||||
val.v = &value;
|
||||
set_object(mAttribPtr, name, T, val);
|
||||
}
|
||||
}
|
||||
|
||||
void bind_objects(struct lua_State * L) {
|
||||
using namespace eressea;
|
||||
|
||||
module(L)[class_<objects> ("objects") .def("get", &objects::get) .def(
|
||||
"set",
|
||||
(void(objects::*)(const char*, region&))&objects::set<region&, TREGION>)
|
||||
.def("set", (void(objects::*)(const char*, unit&))&objects::set<unit&, TUNIT>)
|
||||
.def("set", (void(objects::*)(const char*, faction&))&objects::set<faction&, TFACTION>)
|
||||
.def("set", (void(objects::*)(const char*, building&))&objects::set<building&, TBUILDING>)
|
||||
.def("set", (void(objects::*)(const char*, ship&))&objects::set<ship&, TSHIP>)
|
||||
// POD:
|
||||
// .def("set", (void(objects::*)(const char*, int))&objects::set<int, TINTEGER>)
|
||||
.def("set", (void(objects::*)(const char*, double))&objects::set<lua_Number, TREAL>)
|
||||
.def("set", (void(objects::*)(const char*, const char *))&objects::set<const char *, TSTRING>)
|
||||
];
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
#ifndef LUA_OBJECTS_H
|
||||
#define LUA_OBJECTS_H
|
||||
|
||||
#include <attributes/object.h>
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (push)
|
||||
#pragma warning (disable: 4127)
|
||||
#endif
|
||||
#include <luabind/object.hpp>
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (pop)
|
||||
#endif
|
||||
|
||||
struct lua_State;
|
||||
|
||||
namespace eressea {
|
||||
|
||||
class objects {
|
||||
public:
|
||||
objects(struct attrib ** attribs) : mAttribPtr(attribs) {}
|
||||
|
||||
luabind::object get(const char * name);
|
||||
// void set(const char * name, int type, luabind::object& value);
|
||||
template <class V, object_type T> void
|
||||
set(const char * name, V value);
|
||||
|
||||
private:
|
||||
struct attrib ** mAttribPtr;
|
||||
};
|
||||
|
||||
|
||||
template<class T> eressea::objects
|
||||
get_objects(const T& parent)
|
||||
{
|
||||
return eressea::objects(&const_cast<attrib *&>(parent.attribs));
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -1,381 +0,0 @@
|
|||
#include <config.h>
|
||||
#include <kernel/eressea.h>
|
||||
#include "list.h"
|
||||
#include "objects.h"
|
||||
|
||||
// kernel includes
|
||||
#include <kernel/building.h>
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/item.h>
|
||||
#include <kernel/message.h>
|
||||
#include <kernel/plane.h>
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/resources.h>
|
||||
#include <kernel/ship.h>
|
||||
#include <kernel/terrain.h>
|
||||
#include <kernel/unit.h>
|
||||
|
||||
#include <util/attrib.h>
|
||||
#include <util/log.h>
|
||||
|
||||
#include <attributes/key.h>
|
||||
|
||||
// lua includes
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (push)
|
||||
#pragma warning (disable: 4127)
|
||||
#endif
|
||||
#include <lua.hpp>
|
||||
#include <luabind/luabind.hpp>
|
||||
#include <luabind/iterator_policy.hpp>
|
||||
#include <luabind/operator.hpp>
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (pop)
|
||||
#endif
|
||||
|
||||
#include <ostream>
|
||||
using namespace luabind;
|
||||
|
||||
static eressea::list<region *>
|
||||
get_regions(void) {
|
||||
return eressea::list<region *>(regions);
|
||||
}
|
||||
|
||||
static eressea::list<unit *>
|
||||
region_units(const region * r) {
|
||||
return eressea::list<unit *>(r->units);
|
||||
}
|
||||
|
||||
static eressea::list<building *>
|
||||
region_buildings(const region * r) {
|
||||
return eressea::list<building *>(r->buildings);
|
||||
}
|
||||
|
||||
static eressea::list<ship *>
|
||||
region_ships(const region * r) {
|
||||
return eressea::list<ship *>(r->ships);
|
||||
}
|
||||
|
||||
static const char *
|
||||
region_getterrain(const region * r) {
|
||||
return (const char *)r->terrain->_name;
|
||||
}
|
||||
|
||||
static void
|
||||
lua_region_setowner(region * r, faction * f) {
|
||||
region_set_owner(r, f, turn);
|
||||
}
|
||||
|
||||
static faction *
|
||||
lua_region_getowner(const region * r) {
|
||||
return region_get_owner(r);
|
||||
}
|
||||
|
||||
static void
|
||||
region_setherbtype(region * r, const char * str) {
|
||||
const struct resource_type * rtype = rt_find(str);
|
||||
if (rtype!=NULL && rtype->itype!=NULL) {
|
||||
rsetherbtype(r, rtype->itype);
|
||||
}
|
||||
}
|
||||
|
||||
static const char *
|
||||
region_getherbtype(const region * r) {
|
||||
const struct item_type * itype = rherbtype(r);
|
||||
if (itype==NULL) return NULL;
|
||||
return itype->rtype->_name[0];
|
||||
}
|
||||
|
||||
static int
|
||||
region_plane(const region * r)
|
||||
{
|
||||
plane * pl = rplane(r);
|
||||
return plane_id(pl);
|
||||
}
|
||||
|
||||
static void
|
||||
region_addnotice(region * r, const char * str)
|
||||
{
|
||||
addmessage(r, NULL, str, MSG_MESSAGE, ML_IMPORTANT);
|
||||
}
|
||||
|
||||
static std::ostream&
|
||||
operator<<(std::ostream& stream, const region& r)
|
||||
{
|
||||
stream << regionname(&r, NULL) << ", " << (const char *)r.terrain->_name;
|
||||
return stream;
|
||||
}
|
||||
|
||||
static bool
|
||||
operator==(const region& a, const region& b)
|
||||
{
|
||||
return a.x==b.x && a.y==b.y;
|
||||
}
|
||||
|
||||
static bool
|
||||
region_getflag(const region * r, int bit)
|
||||
{
|
||||
if (r->flags & (1<<bit)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
static void
|
||||
region_setflag(region * r, int bit, bool set)
|
||||
{
|
||||
if (set) r->flags |= (1<<bit);
|
||||
else r->flags &= ~(1<<bit);
|
||||
}
|
||||
|
||||
static int
|
||||
region_get_resource(const region * r, const char * type)
|
||||
{
|
||||
const resource_type * rtype = rt_find(type);
|
||||
if (rtype!=NULL) {
|
||||
return region_getresource(r, rtype);
|
||||
} else {
|
||||
if (strcmp(type, "seed")==0) return rtrees(r, 0);
|
||||
if (strcmp(type, "sapling")==0) return rtrees(r, 1);
|
||||
if (strcmp(type, "tree")==0) return rtrees(r, 2);
|
||||
if (strcmp(type, "grave")==0) return deathcount(r);
|
||||
if (strcmp(type, "chaos")==0) return chaoscount(r);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
region_set_resource(region * r, const char * type, int value)
|
||||
{
|
||||
const resource_type * rtype = rt_find(type);
|
||||
if (rtype!=NULL) {
|
||||
region_setresource(r, rtype, value);
|
||||
} else {
|
||||
if (strcmp(type, "seed")==0) {
|
||||
rsettrees(r, 0, value);
|
||||
} else if (strcmp(type, "sapling")==0) {
|
||||
rsettrees(r, 1, value);
|
||||
} else if (strcmp(type, "tree")==0) {
|
||||
rsettrees(r, 2, value);
|
||||
} else if (strcmp(type, "grave")==0) {
|
||||
int fallen = value-deathcount(r);
|
||||
deathcounts(r, fallen);
|
||||
} else if (strcmp(type, "chaos")==0) {
|
||||
int fallen = value-chaoscount(r);
|
||||
chaoscounts(r, fallen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
region_setroad(region * r, int dir, lua_Number size)
|
||||
{
|
||||
if (r->terrain->max_road>0) {
|
||||
rsetroad(r, (direction_t)dir, (short)(r->terrain->max_road * size));
|
||||
}
|
||||
}
|
||||
|
||||
static lua_Number
|
||||
region_getroad(region * r, int dir)
|
||||
{
|
||||
lua_Number result = rroad(r, (direction_t)dir);
|
||||
if (r->terrain->max_road<=0 || result<=0) return 0;
|
||||
return r->terrain->max_road / result;
|
||||
}
|
||||
|
||||
static region *
|
||||
region_terraform(int x, int y, const char * tname)
|
||||
{
|
||||
const terrain_type * terrain = get_terrain(tname);
|
||||
region * r = findregion(x, y);
|
||||
if (terrain==NULL) {
|
||||
if (r!=NULL) {
|
||||
if (r->units!=NULL) {
|
||||
// TODO: error message
|
||||
return r;
|
||||
}
|
||||
// TODO: region löschen
|
||||
terraform_region(r, NULL);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
if (r==NULL) {
|
||||
struct plane * pl = findplane(x, y);
|
||||
r = new_region(x, y, pl, 0);
|
||||
}
|
||||
terraform_region(r, terrain);
|
||||
return r;
|
||||
}
|
||||
|
||||
static region *
|
||||
region_next(const region * r, int dir)
|
||||
{
|
||||
if (dir<0 || dir >=MAXDIRECTIONS) return NULL;
|
||||
return r_connect(r, (direction_t)dir);
|
||||
}
|
||||
|
||||
static void
|
||||
region_adddirection(region * r, region * rt, const char * name, const char * info)
|
||||
{
|
||||
create_special_direction(r, rt, -1, info, name);
|
||||
spec_direction * sd = special_direction(r, rt);
|
||||
sd->active = 1;
|
||||
}
|
||||
|
||||
static void
|
||||
region_remove(region * r)
|
||||
{
|
||||
remove_region(®ions, r);
|
||||
}
|
||||
|
||||
static void
|
||||
plane_remove(int plid)
|
||||
{
|
||||
region ** rp = ®ions;
|
||||
while (*rp) {
|
||||
region * r = *rp;
|
||||
plane * pl = rplane(r);
|
||||
if (pl && pl->id==plid) {
|
||||
remove_region(rp, r);
|
||||
} else {
|
||||
rp = &r->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
region_move(region * r, int x, int y)
|
||||
{
|
||||
if (findregion(x, y)) {
|
||||
log_error(("Bei %d, %d gibt es schon eine Region.\n", x, y));
|
||||
return;
|
||||
}
|
||||
#ifdef FAST_CONNECT
|
||||
direction_t dir;
|
||||
plane * pl = rplane(r);
|
||||
for (dir=0;dir!=MAXDIRECTIONS;++dir) {
|
||||
region * rn = r->connect[dir];
|
||||
int nx = x + delta_x[dir];
|
||||
int ny = y + delta_y[dir];
|
||||
pnormalize(&nx, &ny, pl);
|
||||
if (rn!=NULL) {
|
||||
direction_t reldir = reldirection(rn, r);
|
||||
rn->connect[reldir] = NULL;
|
||||
}
|
||||
rn = findregion(nx, ny);
|
||||
if (rn!=NULL) {
|
||||
direction_t reldir = (direction_t)((dir + 3) % MAXDIRECTIONS);
|
||||
rn->connect[reldir] = r;
|
||||
}
|
||||
r->connect[dir] = rn;
|
||||
}
|
||||
#endif
|
||||
runhash(r);
|
||||
r->x = x;
|
||||
r->y = y;
|
||||
rhash(r);
|
||||
}
|
||||
|
||||
static eressea::list<std::string, item *, eressea::bind_items>
|
||||
region_items(const region * r) {
|
||||
if (r->land) {
|
||||
return eressea::list<std::string, item *, eressea::bind_items>(r->land->items);
|
||||
} else {
|
||||
return eressea::list<std::string, item *, eressea::bind_items>(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
region_additem(region * r, const char * iname, int number)
|
||||
{
|
||||
if (iname!=NULL) {
|
||||
const item_type * itype = it_find(iname);
|
||||
if (itype!=NULL && r->land) {
|
||||
item * i = i_change(&r->land->items, itype, number);
|
||||
return i?i->number:0;
|
||||
} // if (itype!=NULL)
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static bool
|
||||
region_getkey(region * r, const char * name)
|
||||
{
|
||||
int flag = atoi36(name);
|
||||
attrib * a = find_key(r->attribs, flag);
|
||||
return (a!=NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
region_setkey(region * r, const char * name, bool value)
|
||||
{
|
||||
int flag = atoi36(name);
|
||||
attrib * a = find_key(r->attribs, flag);
|
||||
if (a==NULL && value) {
|
||||
add_key(&r->attribs, flag);
|
||||
} else if (a!=NULL && !value) {
|
||||
a_remove(&r->attribs, a);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
plane_getbyname(const char * str)
|
||||
{
|
||||
plane * pl = getplanebyname(str);
|
||||
if (pl) return pl->id;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
bind_region(lua_State * L)
|
||||
{
|
||||
module(L)[
|
||||
def("regions", &get_regions, return_stl_iterator),
|
||||
def("get_region", &findregion),
|
||||
def("get_region_by_id", &findregionbyid),
|
||||
def("terraform", ®ion_terraform),
|
||||
def("distance", &distance),
|
||||
def("remove_region", ®ion_remove),
|
||||
def("remove_plane", &plane_remove),
|
||||
def("getplanebyname", &plane_getbyname),
|
||||
|
||||
class_<struct region>("region")
|
||||
.def(tostring(const_self))
|
||||
.def(self == region())
|
||||
.property("name", ®ion_getname, ®ion_setname)
|
||||
.property("info", ®ion_getinfo, ®ion_setinfo)
|
||||
.property("owner", &lua_region_getowner, &lua_region_setowner)
|
||||
.property("herbtype", ®ion_getherbtype, ®ion_setherbtype)
|
||||
.property("terrain", ®ion_getterrain)
|
||||
.def("add_notice", ®ion_addnotice)
|
||||
.def("add_direction", ®ion_adddirection)
|
||||
|
||||
.def("get_key", ®ion_getkey)
|
||||
.def("set_key", ®ion_setkey)
|
||||
|
||||
.def("get_flag", ®ion_getflag)
|
||||
.def("set_flag", ®ion_setflag)
|
||||
|
||||
.def("move", ®ion_move)
|
||||
|
||||
.def("get_road", ®ion_getroad)
|
||||
.def("set_road", ®ion_setroad)
|
||||
|
||||
.def("next", ®ion_next)
|
||||
.def("get_resource", ®ion_get_resource)
|
||||
.def("set_resource", ®ion_set_resource)
|
||||
.def_readonly("x", ®ion::x)
|
||||
.def_readonly("y", ®ion::y)
|
||||
.def_readonly("id", ®ion::uid)
|
||||
.def_readwrite("age", ®ion::age)
|
||||
.def("add_item", ®ion_additem)
|
||||
.property("items", ®ion_items, return_stl_iterator)
|
||||
.property("plane_id", ®ion_plane)
|
||||
.property("units", ®ion_units, return_stl_iterator)
|
||||
.property("buildings", ®ion_buildings, return_stl_iterator)
|
||||
.property("ships", ®ion_ships, return_stl_iterator)
|
||||
.property("objects", &eressea::get_objects<region>)
|
||||
.scope [
|
||||
def("create", ®ion_terraform)
|
||||
]
|
||||
];
|
||||
}
|
|
@ -1,330 +0,0 @@
|
|||
/* vi: set ts=2:
|
||||
+-------------------+
|
||||
| | Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
| Eressea PBEM host | Enno Rehling <enno@eressea.de>
|
||||
| (c) 1998 - 2004 | Katja Zedel <katze@felidae.kn-bremen.de>
|
||||
| |
|
||||
+-------------------+
|
||||
|
||||
This program may not be used, modified or distributed
|
||||
without prior permission by the authors of Eressea.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <boost/version.hpp>
|
||||
#include <lua.hpp>
|
||||
#include <kernel/eressea.h>
|
||||
#include "script.h"
|
||||
#include "bindings.h"
|
||||
|
||||
// kernel includes
|
||||
#include <kernel/equipment.h>
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/item.h>
|
||||
#include <kernel/race.h>
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/spell.h>
|
||||
#include <kernel/unit.h>
|
||||
|
||||
// util includes
|
||||
#include <util/attrib.h>
|
||||
#include <util/functions.h>
|
||||
#include <util/log.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (push)
|
||||
#pragma warning (disable: 4127)
|
||||
#endif
|
||||
#include <luabind/luabind.hpp>
|
||||
#include <luabind/operator.hpp>
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (pop)
|
||||
#endif
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
using namespace luabind;
|
||||
|
||||
static void
|
||||
free_script(attrib * a) {
|
||||
if (a->data.v!=NULL) {
|
||||
object * f = (object *)a->data.v;
|
||||
delete f;
|
||||
}
|
||||
}
|
||||
|
||||
attrib_type at_script = {
|
||||
"script",
|
||||
NULL, free_script, NULL,
|
||||
NULL, NULL, ATF_UNIQUE
|
||||
};
|
||||
|
||||
int
|
||||
call_script(struct unit * u)
|
||||
{
|
||||
const attrib * a = a_findc(u->attribs, &at_script);
|
||||
if (a==NULL) a = a_findc(u->race->attribs, &at_script);
|
||||
if (a!=NULL && a->data.v!=NULL) {
|
||||
object * func = (object *)a->data.v;
|
||||
try {
|
||||
func->operator()(u);
|
||||
}
|
||||
catch (error& e) {
|
||||
lua_State* L = e.state();
|
||||
const char* error = lua_tostring(L, -1);
|
||||
log_error((error));
|
||||
lua_pop(L, 1);
|
||||
std::terminate();
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void
|
||||
setscript(struct attrib ** ap, void * fptr)
|
||||
{
|
||||
attrib * a = a_find(*ap, &at_script);
|
||||
if (a == NULL) {
|
||||
a = a_add(ap, a_new(&at_script));
|
||||
} else if (a->data.v!=NULL) {
|
||||
object * f = (object *)a->data.v;
|
||||
delete f;
|
||||
}
|
||||
a->data.v = fptr;
|
||||
}
|
||||
|
||||
/** callback to use lua for spell functions */
|
||||
static int
|
||||
lua_callspell(castorder *co)
|
||||
{
|
||||
const char * fname = co->sp->sname;
|
||||
unit * mage = co->familiar?co->familiar:co->magician.u;
|
||||
int retval = -1;
|
||||
const char * hashpos = strchr(fname, '#');
|
||||
char fbuf[64];
|
||||
|
||||
if (hashpos!=NULL) {
|
||||
ptrdiff_t len = hashpos - fname;
|
||||
assert(len<(ptrdiff_t)sizeof(fbuf));
|
||||
strncpy(fbuf, fname, len);
|
||||
fbuf[len] = '\0';
|
||||
fname = fbuf;
|
||||
}
|
||||
|
||||
lua_State * L = (lua_State *)global.vm_state;
|
||||
if (is_function(L, fname)) {
|
||||
try {
|
||||
retval = call_function<int>(L, fname, co->rt, mage, co->level, co->force);
|
||||
}
|
||||
catch (error& e) {
|
||||
lua_State* L = e.state();
|
||||
const char* error = lua_tostring(L, -1);
|
||||
log_error(("An exception occured while %s tried to call '%s': %s.\n",
|
||||
unitname(mage), fname, error));
|
||||
lua_pop(L, 1);
|
||||
std::terminate();
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
/** callback to initialize a familiar from lua. */
|
||||
static void
|
||||
lua_initfamiliar(unit * u)
|
||||
{
|
||||
char fname[64];
|
||||
snprintf(fname, sizeof(fname), "initfamiliar_%s", u->race->_name[0]);
|
||||
|
||||
lua_State * L = (lua_State *)global.vm_state;
|
||||
if (is_function(L, fname)) {
|
||||
try {
|
||||
call_function<int>(L, fname, u);
|
||||
}
|
||||
catch (error& e) {
|
||||
lua_State* L = e.state();
|
||||
const char* error = lua_tostring(L, -1);
|
||||
log_error(("An exception occured while %s tried to call '%s': %s.\n",
|
||||
unitname(u), fname, error));
|
||||
lua_pop(L, 1);
|
||||
std::terminate();
|
||||
}
|
||||
}
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s_familiar", u->race->_name[0]);
|
||||
create_mage(u, M_GRAY);
|
||||
equip_unit(u, get_equipment(fname));
|
||||
}
|
||||
|
||||
static int
|
||||
lua_changeresource(unit * u, const struct resource_type * rtype, int delta)
|
||||
{
|
||||
char fname[64];
|
||||
snprintf(fname, sizeof(fname), "%s_changeresource", rtype->_name[0]);
|
||||
int retval = -1;
|
||||
|
||||
lua_State * L = (lua_State *)global.vm_state;
|
||||
if (is_function(L, fname)) {
|
||||
try {
|
||||
retval = call_function<int>(L, fname, u, delta);
|
||||
}
|
||||
catch (error& e) {
|
||||
lua_State* L = e.state();
|
||||
const char* error = lua_tostring(L, -1);
|
||||
log_error(("An exception occured while %s tried to call '%s': %s.\n",
|
||||
unitname(u), fname, error));
|
||||
lua_pop(L, 1);
|
||||
std::terminate();
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
static int
|
||||
lua_getresource(unit * u, const struct resource_type * rtype)
|
||||
{
|
||||
char fname[64];
|
||||
snprintf(fname, sizeof(fname), "%s_getresource", rtype->_name[0]);
|
||||
int retval = -1;
|
||||
|
||||
lua_State * L = (lua_State *)global.vm_state;
|
||||
if (is_function(L, fname)) {
|
||||
try {
|
||||
retval = call_function<int>(L, fname, u);
|
||||
}
|
||||
catch (error& e) {
|
||||
lua_State* L = e.state();
|
||||
const char* error = lua_tostring(L, -1);
|
||||
log_error(("An exception occured while %s tried to call '%s': %s.\n",
|
||||
unitname(u), fname, error));
|
||||
lua_pop(L, 1);
|
||||
std::terminate();
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
static int
|
||||
lua_wage(const region * r, const faction * f, const race * rc)
|
||||
{
|
||||
const char * fname = "wage";
|
||||
int retval = -1;
|
||||
lua_State * L = (lua_State *)global.vm_state;
|
||||
|
||||
if (is_function(L, fname)) {
|
||||
try {
|
||||
retval = luabind::call_function<int>(L, fname, r, f, rc?rc->_name[0]:NULL);
|
||||
}
|
||||
catch (luabind::error& e) {
|
||||
lua_State* L = e.state();
|
||||
const char* error = lua_tostring(L, -1);
|
||||
log_error(("An exception occured while calling '%s': %s.\n", fname, error));
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
static int
|
||||
lua_maintenance(const unit * u)
|
||||
{
|
||||
const char * fname = "maintenance";
|
||||
int retval = -1;
|
||||
lua_State * L = (lua_State *)global.vm_state;
|
||||
|
||||
if (is_function(L, fname)) {
|
||||
try {
|
||||
retval = luabind::call_function<int>(L, fname, u);
|
||||
}
|
||||
catch (luabind::error& e) {
|
||||
lua_State* L = e.state();
|
||||
const char* error = lua_tostring(L, -1);
|
||||
log_error(("An exception occured while calling '%s': %s.\n", fname, error));
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
static void
|
||||
unit_setscript(struct unit * u, const luabind::object& f)
|
||||
{
|
||||
luabind::object * fptr = new luabind::object(f);
|
||||
setscript(&u->attribs, fptr);
|
||||
}
|
||||
|
||||
static void
|
||||
race_setscript(const char * rcname, const luabind::object& f)
|
||||
{
|
||||
race * rc = rc_find(rcname);
|
||||
if (rc!=NULL) {
|
||||
luabind::object * fptr = new luabind::object(f);
|
||||
setscript(&rc->attribs, fptr);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
lua_equipmentcallback(const struct equipment * eq, unit * u)
|
||||
{
|
||||
char fname[64];
|
||||
snprintf(fname, sizeof(fname), "equip_%s", eq->name);
|
||||
|
||||
lua_State * L = (lua_State *)global.vm_state;
|
||||
if (is_function(L, fname)) {
|
||||
try {
|
||||
call_function<int>(L, fname, u);
|
||||
}
|
||||
catch (error& e) {
|
||||
lua_State* L = e.state();
|
||||
const char* error = lua_tostring(L, -1);
|
||||
log_error(("An exception occured while %s tried to call '%s': %s.\n",
|
||||
unitname(u), fname, error));
|
||||
lua_pop(L, 1);
|
||||
std::terminate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** callback for an item-use function written in lua. */
|
||||
int
|
||||
lua_useitem(struct unit * u, const struct item_type * itype, int amount, struct order * ord)
|
||||
{
|
||||
int retval = 0;
|
||||
char fname[64];
|
||||
snprintf(fname, sizeof(fname), "use_%s", itype->rtype->_name[0]);
|
||||
|
||||
lua_State * L = (lua_State *)global.vm_state;
|
||||
if (is_function(L, fname)) {
|
||||
try {
|
||||
retval = luabind::call_function<int>(L, fname, u, amount);
|
||||
}
|
||||
catch (error& e) {
|
||||
lua_State* L = e.state();
|
||||
const char* error = lua_tostring(L, -1);
|
||||
log_error(("An exception occured while %s tried to call '%s': %s.\n",
|
||||
unitname(u), fname, error));
|
||||
lua_pop(L, 1);
|
||||
std::terminate();
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
void
|
||||
bind_script(lua_State * L)
|
||||
{
|
||||
register_function((pf_generic)&lua_callspell, "lua_castspell");
|
||||
register_function((pf_generic)&lua_initfamiliar, "lua_initfamiliar");
|
||||
register_item_use(&lua_useitem, "lua_useitem");
|
||||
register_function((pf_generic)&lua_getresource, "lua_getresource");
|
||||
register_function((pf_generic)&lua_changeresource, "lua_changeresource");
|
||||
register_function((pf_generic)&lua_equipmentcallback, "lua_equip");
|
||||
|
||||
register_function((pf_generic)&lua_wage, "lua_wage");
|
||||
register_function((pf_generic)&lua_maintenance, "lua_maintenance");
|
||||
|
||||
module(L)[
|
||||
def("set_race_brain", &race_setscript),
|
||||
def("set_unit_brain", &unit_setscript)
|
||||
];
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
/* vi: set ts=2:
|
||||
+-------------------+
|
||||
| | Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
| Eressea PBEM host | Enno Rehling <enno@eressea.de>
|
||||
| (c) 1998 - 2004 | Katja Zedel <katze@felidae.kn-bremen.de>
|
||||
| |
|
||||
+-------------------+
|
||||
|
||||
This program may not be used, modified or distributed
|
||||
without prior permission by the authors of Eressea.
|
||||
*/
|
||||
#ifndef KRNL_SCRIPT_H
|
||||
#define KRNL_SCRIPT_H
|
||||
|
||||
extern int call_script(struct unit * u);
|
||||
extern void setscript(struct attrib ** ap, void * fptr);
|
||||
|
||||
extern int lua_useitem(struct unit * u, const struct item_type * itype, int amount, struct order * ord);
|
||||
|
||||
#endif
|
|
@ -1,114 +0,0 @@
|
|||
#include <config.h>
|
||||
#include <kernel/eressea.h>
|
||||
#include "objects.h"
|
||||
|
||||
// kernel includes
|
||||
#include <kernel/build.h>
|
||||
#include <kernel/ship.h>
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/move.h>
|
||||
|
||||
// lua includes
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (push)
|
||||
#pragma warning (disable: 4127)
|
||||
#endif
|
||||
#include <lua.hpp>
|
||||
#include <luabind/luabind.hpp>
|
||||
#include <luabind/iterator_policy.hpp>
|
||||
#include <luabind/operator.hpp>
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (pop)
|
||||
#endif
|
||||
|
||||
#include <util/base36.h>
|
||||
|
||||
#include <ostream>
|
||||
using namespace luabind;
|
||||
|
||||
static std::ostream&
|
||||
operator<<(std::ostream& stream, const ship& sh)
|
||||
{
|
||||
stream << sh.name;
|
||||
stream << " (" << itoa36(sh.no) << ")";
|
||||
stream << ", " << sh.type->name;
|
||||
stream << " size " << sh.size;
|
||||
return stream;
|
||||
}
|
||||
|
||||
static bool
|
||||
operator==(const ship& a, const ship& sh)
|
||||
{
|
||||
return a.no==sh.no;
|
||||
}
|
||||
|
||||
static ship *
|
||||
add_ship(region * r, const char * sname)
|
||||
{
|
||||
const ship_type * stype = st_find(sname);
|
||||
ship * sh = new_ship(stype, NULL, r);
|
||||
sh->size = stype->construction->maxsize;
|
||||
return sh;
|
||||
}
|
||||
|
||||
static int
|
||||
ship_maxsize(const ship * s) {
|
||||
return s->type->construction->maxsize;
|
||||
}
|
||||
|
||||
const char *
|
||||
ship_gettype(const ship * s) {
|
||||
return s->type->name[0];
|
||||
}
|
||||
|
||||
int
|
||||
ship_getweight(const ship * s) {
|
||||
int w, c;
|
||||
getshipweight(s, &w, &c);
|
||||
return w;
|
||||
}
|
||||
|
||||
int
|
||||
ship_getcapacity(const ship * s) {
|
||||
return shipcapacity(s);
|
||||
}
|
||||
|
||||
static void
|
||||
ship_setregion(ship * sh, region * r)
|
||||
{
|
||||
move_ship(sh, sh->region, r, NULL);
|
||||
}
|
||||
|
||||
static region *
|
||||
ship_getregion(const ship * sh)
|
||||
{
|
||||
return sh->region;
|
||||
}
|
||||
|
||||
void
|
||||
bind_ship(lua_State * L)
|
||||
{
|
||||
module(L)[
|
||||
def("get_ship", &findship),
|
||||
def("add_ship", &add_ship),
|
||||
|
||||
class_<struct ship>("ship")
|
||||
.def(self == ship())
|
||||
.def(tostring(self))
|
||||
.property("type", &ship_gettype)
|
||||
.property("weight", &ship_getweight)
|
||||
.property("capacity", &ship_getcapacity)
|
||||
.property("maxsize", &ship_maxsize)
|
||||
.def_readonly("name", &ship::name)
|
||||
.property("region", &ship_getregion, &ship_setregion)
|
||||
.def_readonly("id", &ship::no)
|
||||
.def_readonly("info", &ship::display)
|
||||
.def_readwrite("damage", &ship::damage)
|
||||
.def_readwrite("size", &ship::size)
|
||||
.def_readwrite("coast", &ship::coast)
|
||||
.property("objects", &eressea::get_objects<ship>)
|
||||
.scope [
|
||||
def("create", &add_ship)
|
||||
]
|
||||
];
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
#include <config.h>
|
||||
#include <kernel/eressea.h>
|
||||
#include "list.h"
|
||||
|
||||
// kernel includes
|
||||
#include <kernel/magic.h>
|
||||
|
||||
// lua includes
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (push)
|
||||
#pragma warning (disable: 4127)
|
||||
#endif
|
||||
#include <luabind/luabind.hpp>
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (pop)
|
||||
#endif
|
||||
|
||||
using namespace luabind;
|
||||
|
||||
static const char *
|
||||
spell_getschool(const spell& sp)
|
||||
{
|
||||
return magic_school[sp.magietyp];
|
||||
}
|
||||
|
||||
void
|
||||
bind_spell(lua_State * L)
|
||||
{
|
||||
module(L)[
|
||||
class_<struct spell>("spell")
|
||||
.def_readonly("name", &spell::sname)
|
||||
.def_readonly("level", &spell::level)
|
||||
.property("school", &spell_getschool)
|
||||
];
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
#include <config.h>
|
||||
#include <kernel/eressea.h>
|
||||
|
||||
#include "bindings.h"
|
||||
#include "list.h"
|
||||
|
||||
// Lua includes
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (push)
|
||||
#pragma warning (disable: 4127)
|
||||
#endif
|
||||
#include <lua.hpp>
|
||||
#include <luabind/luabind.hpp>
|
||||
#include <luabind/iterator_policy.hpp>
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (pop)
|
||||
#endif
|
||||
|
||||
using namespace luabind;
|
||||
|
||||
#include <util/language.h>
|
||||
#include <util/rng.h>
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/skill.h>
|
||||
#include <kernel/terrainid.h>
|
||||
#include <modules/autoseed.h>
|
||||
|
||||
static const char *
|
||||
loc_getskill(const char * loc, const char * locstring)
|
||||
{
|
||||
struct locale * lang = find_locale(loc);
|
||||
skill_t result = findskill(locstring, lang);
|
||||
if (result==NOSKILL) return 0;
|
||||
return skillnames[result];
|
||||
}
|
||||
|
||||
static const char *
|
||||
loc_getkeyword(const char * loc, const char * locstring)
|
||||
{
|
||||
struct locale * lang = find_locale(loc);
|
||||
keyword_t result = findkeyword(locstring, lang);
|
||||
if (result==NOKEYWORD) return 0;
|
||||
return keywords[result];
|
||||
}
|
||||
|
||||
static void
|
||||
adamantium_island(region * r)
|
||||
{
|
||||
region_list *rp, *rlist = NULL;
|
||||
get_island(r, &rlist);
|
||||
|
||||
for (rp=rlist;rp;rp=rp->next) {
|
||||
region * ri = rp->data;
|
||||
if (ri->terrain==newterrain(T_MOUNTAIN)) {
|
||||
int base = 1 << (rng_int() % 4);
|
||||
seed_adamantium(ri, base);
|
||||
}
|
||||
}
|
||||
free_regionlist(rlist);
|
||||
}
|
||||
|
||||
void
|
||||
bind_test(lua_State * L)
|
||||
{
|
||||
module(L, "test")[
|
||||
def("loc_skill", &loc_getskill),
|
||||
def("loc_keyword", &loc_getkeyword),
|
||||
def("reorder_units", &reorder_units),
|
||||
def("adamantium_island", &adamantium_island)
|
||||
];
|
||||
}
|
|
@ -1,607 +0,0 @@
|
|||
#include <config.h>
|
||||
#include <kernel/eressea.h>
|
||||
#include "list.h"
|
||||
#include "objects.h"
|
||||
#include "bindings.h"
|
||||
#include "event.h"
|
||||
|
||||
// Atributes includes
|
||||
#include <attributes/racename.h>
|
||||
#include <attributes/key.h>
|
||||
|
||||
// kernel includes
|
||||
#include <kernel/building.h>
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/item.h>
|
||||
#include <kernel/magic.h>
|
||||
#include <kernel/message.h>
|
||||
#include <kernel/move.h>
|
||||
#include <kernel/order.h>
|
||||
#include <kernel/pool.h>
|
||||
#include <kernel/race.h>
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/ship.h>
|
||||
#include <kernel/skill.h>
|
||||
#include <kernel/spell.h>
|
||||
#include <kernel/unit.h>
|
||||
|
||||
// util includes
|
||||
#include <util/attrib.h>
|
||||
#include <util/base36.h>
|
||||
#include <util/event.h>
|
||||
#include <util/lists.h>
|
||||
#include <util/log.h>
|
||||
|
||||
// lua includes
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (push)
|
||||
#pragma warning (disable: 4127)
|
||||
#endif
|
||||
#include <lua.hpp>
|
||||
#include <luabind/luabind.hpp>
|
||||
#include <luabind/iterator_policy.hpp>
|
||||
#include <luabind/operator.hpp>
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (pop)
|
||||
#endif
|
||||
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
using namespace luabind;
|
||||
|
||||
class bind_spell_ptr {
|
||||
public:
|
||||
static spell_list * next(spell_list * node) { return node->next; }
|
||||
static spell * value(spell_list * node) { return node->data; }
|
||||
};
|
||||
|
||||
static eressea::list<spell *, spell_list *, bind_spell_ptr>
|
||||
unit_spells(const unit * u) {
|
||||
sc_mage * mage = get_mage(u);
|
||||
if (mage==NULL) return eressea::list<spell *, spell_list *, bind_spell_ptr>(NULL);
|
||||
spell_list * splist = mage->spells;
|
||||
return eressea::list<spell *, spell_list *, bind_spell_ptr>(splist);
|
||||
}
|
||||
|
||||
class bind_spell_list {
|
||||
public:
|
||||
static spell_list * next(spell_list * node) { return node->next; }
|
||||
static spell * value(spell_list * node) { return node->data; }
|
||||
};
|
||||
|
||||
class bind_orders {
|
||||
public:
|
||||
static order * next(order * node) { return node->next; }
|
||||
static std::string value(order * node) {
|
||||
char * cmd = (char*)getcommand(node);
|
||||
std::string s(cmd);
|
||||
free(cmd);
|
||||
return s;
|
||||
}
|
||||
};
|
||||
|
||||
static eressea::list<std::string, order *, bind_orders>
|
||||
unit_orders(const unit * u) {
|
||||
return eressea::list<std::string, order *, bind_orders>(u->orders);
|
||||
}
|
||||
|
||||
static eressea::list<std::string, item *, eressea::bind_items>
|
||||
unit_items(const unit * u) {
|
||||
return eressea::list<std::string, item *, eressea::bind_items>(u->items);
|
||||
}
|
||||
|
||||
static unit *
|
||||
add_unit(faction * f, region * r)
|
||||
{
|
||||
if (f->units==NULL) return addplayer(r, f);
|
||||
return createunit(r, f, 0, f->race);
|
||||
}
|
||||
|
||||
static void
|
||||
unit_setnumber(unit * u, int number)
|
||||
{
|
||||
if (u->number==0) {
|
||||
set_number(u, number);
|
||||
u->hp = unit_max_hp(u) * number;
|
||||
} else {
|
||||
scale_number(u, number);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
unit_setracename(unit * u, const char * name)
|
||||
{
|
||||
set_racename(&u->attribs, name);
|
||||
}
|
||||
|
||||
static int
|
||||
unit_getnumber(const unit * u)
|
||||
{
|
||||
return u->number;
|
||||
}
|
||||
|
||||
static int
|
||||
unit_getitem(const unit * u, const char * iname)
|
||||
{
|
||||
if (iname!=NULL) {
|
||||
const item_type * itype = it_find(iname);
|
||||
if (itype!=NULL) {
|
||||
return i_get(u->items, itype);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int
|
||||
unit_additem(unit * u, const char * iname, int number)
|
||||
{
|
||||
if (iname!=NULL) {
|
||||
const item_type * itype = it_find(iname);
|
||||
if (itype!=NULL) {
|
||||
item * i = i_change(&u->items, itype, number);
|
||||
return i?i->number:0;
|
||||
} // if (itype!=NULL)
|
||||
}
|
||||
const item_type * itype = it_find(iname);
|
||||
if (itype!=NULL) {
|
||||
item * i = i_change(&u->items, itype, number);
|
||||
return i?i->number:0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int
|
||||
unit_usepooled(unit * u, const char * iname, int number)
|
||||
{
|
||||
const resource_type * rtype = rt_find(iname);
|
||||
if (rtype!=NULL) {
|
||||
return use_pooled(u, rtype, GET_DEFAULT, number);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int
|
||||
unit_getpooled(unit * u, const char * iname)
|
||||
{
|
||||
const resource_type * rtype = rt_find(iname);
|
||||
if (rtype!=NULL) {
|
||||
return get_pooled(u, rtype, GET_DEFAULT, INT_MAX);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int
|
||||
unit_getskill(const unit * u, const char * skname)
|
||||
{
|
||||
skill_t sk = sk_find(skname);
|
||||
if (sk!=NOSKILL) {
|
||||
skill * sv = get_skill(u, sk);
|
||||
if (sv==NULL) return 0;
|
||||
return sv->level;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int
|
||||
unit_effskill(const unit * u, const char * skname)
|
||||
{
|
||||
skill_t sk = sk_find(skname);
|
||||
if (sk!=NOSKILL) {
|
||||
return effskill(u, sk);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int
|
||||
unit_setskill(unit * u, const char * skname, int level)
|
||||
{
|
||||
skill_t sk = sk_find(skname);
|
||||
if (sk!=NOSKILL) {
|
||||
set_level(u, sk, level);
|
||||
return level;
|
||||
} // if (sk!=NULL)
|
||||
return -1;
|
||||
}
|
||||
|
||||
static const char *
|
||||
unit_getrace(const unit * u)
|
||||
{
|
||||
return u->race->_name[0];
|
||||
}
|
||||
|
||||
static void
|
||||
unit_setrace(unit * u, const char * rcname)
|
||||
{
|
||||
race * rc = rc_find(rcname);
|
||||
if (rc!=NULL) {
|
||||
if (u->irace==u->race) u->irace = rc;
|
||||
u->race = rc;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
unit_castspell(unit * u, const char * name)
|
||||
{
|
||||
spell_list * slist = spells;
|
||||
while (slist!=NULL) {
|
||||
spell * sp = slist->data;
|
||||
if (strcmp(name, sp->sname)==0) {
|
||||
castorder * co = (castorder*)malloc(sizeof(castorder));
|
||||
co->distance = 0;
|
||||
co->familiar = NULL;
|
||||
co->force = sp->level;
|
||||
co->level = sp->level;
|
||||
co->magician.u = u;
|
||||
co->order = NULL;
|
||||
co->par = NULL;
|
||||
co->rt = u->region;
|
||||
co->sp = sp;
|
||||
if (sp->sp_function==NULL) {
|
||||
log_error(("spell '%s' has no function.\n", sp->sname));
|
||||
co->level = 0;
|
||||
} else {
|
||||
sp->sp_function(co);
|
||||
}
|
||||
free(co);
|
||||
}
|
||||
slist=slist->next;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
unit_addspell(unit * u, const char * name)
|
||||
{
|
||||
bool add = false;
|
||||
spell_list * slist = spells;
|
||||
while (slist!=NULL) {
|
||||
spell * sp = slist->data;
|
||||
if (strcmp(name, sp->sname)==0) {
|
||||
struct sc_mage * mage = get_mage(u);
|
||||
if (add) log_error(("two spells are called %s.\n", name));
|
||||
add_spell(get_spelllist(mage, u->faction), sp);
|
||||
add = true;
|
||||
}
|
||||
slist=slist->next;
|
||||
}
|
||||
if (!add) log_error(("spell %s could not be found\n", name));
|
||||
}
|
||||
|
||||
static unit *
|
||||
unit_isfamiliar(const unit * u)
|
||||
{
|
||||
attrib * a = a_find(u->attribs, &at_familiarmage);
|
||||
if (a!=NULL) {
|
||||
return (unit*)a->data.v;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static unit *
|
||||
unit_getfamiliar(const unit * u)
|
||||
{
|
||||
attrib * a = a_find(u->attribs, &at_familiar);
|
||||
if (a!=NULL) {
|
||||
return (unit*)a->data.v;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
unit_setfamiliar(unit * mage, unit * familiar)
|
||||
{
|
||||
create_newfamiliar(mage, familiar);
|
||||
}
|
||||
|
||||
static void
|
||||
unit_removespell(unit * u, const spell * sp)
|
||||
{
|
||||
sc_mage * mage = get_mage(u);
|
||||
if (mage!=NULL) {
|
||||
spell_list ** isptr = &mage->spells;
|
||||
while (*isptr && (*isptr)->data != sp) {
|
||||
isptr = &(*isptr)->next;
|
||||
}
|
||||
if (*isptr) {
|
||||
spell_list * sptr = *isptr;
|
||||
*isptr = sptr->next;
|
||||
free(sptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
unit_hpmax(const unit * u)
|
||||
{
|
||||
return unit_max_hp(u);
|
||||
}
|
||||
|
||||
static void
|
||||
unit_setregion(unit * u, region * r)
|
||||
{
|
||||
move_unit(u, r, NULL);
|
||||
}
|
||||
|
||||
static region *
|
||||
unit_getregion(const unit * u)
|
||||
{
|
||||
return u->region;
|
||||
}
|
||||
|
||||
static void
|
||||
unit_setship(unit * u, ship * s)
|
||||
{
|
||||
leave(u, true);
|
||||
if (u->region!=s->region) {
|
||||
move_unit(u, s->region, NULL);
|
||||
}
|
||||
u->ship = s;
|
||||
}
|
||||
|
||||
static ship *
|
||||
unit_getship(const unit * u)
|
||||
{
|
||||
return u->ship;
|
||||
}
|
||||
|
||||
static void
|
||||
unit_setbuilding(unit * u, building * b)
|
||||
{
|
||||
leave(u, true);
|
||||
if (u->region!=b->region) {
|
||||
move_unit(u, b->region, NULL);
|
||||
}
|
||||
u->building = b;
|
||||
}
|
||||
|
||||
static building *
|
||||
unit_getbuilding(const unit * u)
|
||||
{
|
||||
return u->building;
|
||||
}
|
||||
|
||||
static bool
|
||||
get_flag(const unit * u, const char * name)
|
||||
{
|
||||
int flag = atoi36(name);
|
||||
attrib * a = find_key(u->attribs, flag);
|
||||
return (a!=NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
set_flag(unit * u, const char * name, bool value)
|
||||
{
|
||||
int flag = atoi36(name);
|
||||
attrib * a = find_key(u->attribs, flag);
|
||||
if (a==NULL && value) {
|
||||
add_key(&u->attribs, flag);
|
||||
} else if (a!=NULL && !value) {
|
||||
a_remove(&u->attribs, a);
|
||||
}
|
||||
}
|
||||
|
||||
static std::ostream&
|
||||
operator<<(std::ostream& stream, const unit& u)
|
||||
{
|
||||
const char * rcname = get_racename(u.attribs);
|
||||
stream << u.name << " (" << itoa36(u.no) << "), " << u.number << " " << u.race->_name[0];
|
||||
if (rcname) stream << "/" << rcname;
|
||||
return stream;
|
||||
}
|
||||
|
||||
static bool
|
||||
operator==(const unit& a, const unit &b)
|
||||
{
|
||||
return a.no==b.no;
|
||||
}
|
||||
|
||||
static int
|
||||
unit_getaura(const unit * u)
|
||||
{
|
||||
return get_spellpoints(u);
|
||||
}
|
||||
|
||||
static void
|
||||
unit_setaura(unit * u, int points)
|
||||
{
|
||||
return set_spellpoints(u, points);
|
||||
}
|
||||
|
||||
static faction *
|
||||
unit_getfaction(const unit * u)
|
||||
{
|
||||
return u->faction;
|
||||
}
|
||||
|
||||
static void
|
||||
unit_setfaction(unit * u, faction * f)
|
||||
{
|
||||
u_setfaction(u, f);
|
||||
}
|
||||
|
||||
static const char *
|
||||
unit_getmagic(const unit * u)
|
||||
{
|
||||
sc_mage * mage = get_mage(u);
|
||||
return mage?magic_school[mage->magietyp]:NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
unit_setmagic(unit * u, const char * type)
|
||||
{
|
||||
sc_mage * mage = get_mage(u);
|
||||
magic_t mtype;
|
||||
for (mtype=0;mtype!=MAXMAGIETYP;++mtype) {
|
||||
if (strcmp(magic_school[mtype], type)==0) break;
|
||||
}
|
||||
if (mtype==MAXMAGIETYP) return;
|
||||
if (mage==NULL) {
|
||||
mage = create_mage(u, mtype);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
unit_add_order(unit * u, const char * str)
|
||||
{
|
||||
order * ord = parse_order(str, u->faction->locale);
|
||||
unit_addorder(u, ord);
|
||||
}
|
||||
|
||||
static void
|
||||
unit_clear_orders(unit * u)
|
||||
{
|
||||
free_orders(&u->orders);
|
||||
}
|
||||
|
||||
static int
|
||||
unit_weight(const struct unit * u)
|
||||
{
|
||||
return weight(u);
|
||||
}
|
||||
|
||||
typedef struct fctr_data {
|
||||
unit * target;
|
||||
luabind::object * fptr;
|
||||
} fctr_data;
|
||||
|
||||
#include <exception>
|
||||
|
||||
int
|
||||
fctr_handle(struct trigger * tp, void * data)
|
||||
{
|
||||
trigger * t = tp;
|
||||
event * evt = new event(NULL, (event_arg*)data);
|
||||
fctr_data * fd = (fctr_data*)t->data.v;
|
||||
try {
|
||||
fd->fptr->operator()(fd->target, evt);
|
||||
}
|
||||
catch (luabind::error& e) {
|
||||
lua_State* L = e.state();
|
||||
const char* error = lua_tostring(L, -1);
|
||||
log_error((error));
|
||||
lua_pop(L, 1);
|
||||
std::terminate();
|
||||
}
|
||||
|
||||
delete evt;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
fctr_init(trigger * t)
|
||||
{
|
||||
t->data.v = calloc(sizeof(fctr_data), 1);
|
||||
}
|
||||
|
||||
static void
|
||||
fctr_done(trigger * t)
|
||||
{
|
||||
free(t->data.v);
|
||||
}
|
||||
|
||||
static struct trigger_type tt_functor = {
|
||||
"functor",
|
||||
fctr_init,
|
||||
fctr_done,
|
||||
fctr_handle
|
||||
};
|
||||
|
||||
static trigger *
|
||||
trigger_functor(struct unit * u, const object& f)
|
||||
{
|
||||
luabind::object * fptr = new luabind::object(f);
|
||||
trigger * t = t_new(&tt_functor);
|
||||
fctr_data * td = (fctr_data*)t->data.v;
|
||||
td->target = u;
|
||||
td->fptr = fptr;
|
||||
return t;
|
||||
}
|
||||
|
||||
static void
|
||||
unit_addhandler(struct unit * u, const char * event, const object& f)
|
||||
{
|
||||
add_trigger(&u->attribs, event, trigger_functor(u, f));
|
||||
}
|
||||
|
||||
static int
|
||||
unit_capacity(const struct unit * u)
|
||||
{
|
||||
return walkingcapacity(u);
|
||||
}
|
||||
|
||||
static void
|
||||
unit_addnotice(unit * u, const char * str)
|
||||
{
|
||||
addmessage(u->region, u->faction, str, MSG_MESSAGE, ML_IMPORTANT);
|
||||
}
|
||||
|
||||
void
|
||||
bind_unit(lua_State * L)
|
||||
{
|
||||
module(L)[
|
||||
def("get_unit", &findunit),
|
||||
def("add_unit", &add_unit),
|
||||
|
||||
class_<struct unit>("unit")
|
||||
.def(tostring(const_self))
|
||||
.def(self == unit())
|
||||
.property("name", &unit_getname, &unit_setname)
|
||||
.property("info", &unit_getinfo, &unit_setinfo)
|
||||
.property("id", &unit_getid, &unit_setid)
|
||||
.property("faction", &unit_getfaction, &unit_setfaction)
|
||||
.def_readwrite("hp", &unit::hp)
|
||||
.def_readwrite("status", &unit::status)
|
||||
.property("weight", &unit_weight)
|
||||
.property("capacity", &unit_capacity)
|
||||
|
||||
.property("is_familiar", &unit_isfamiliar)
|
||||
.property("familiar", &unit_getfamiliar, &unit_setfamiliar)
|
||||
|
||||
// orders:
|
||||
.def("add_order", &unit_add_order)
|
||||
.def("clear_orders", &unit_clear_orders)
|
||||
.property("orders", &unit_orders, return_stl_iterator)
|
||||
|
||||
// key-attributes for named flags:
|
||||
.def("set_flag", &set_flag)
|
||||
.def("get_flag", &get_flag)
|
||||
.def_readwrite("flags", &unit::flags)
|
||||
.def_readwrite("age", &unit::age)
|
||||
|
||||
// items:
|
||||
.def("get_item", &unit_getitem)
|
||||
.def("add_item", &unit_additem)
|
||||
.property("items", &unit_items, return_stl_iterator)
|
||||
|
||||
.def("get_pooled", &unit_getpooled)
|
||||
.def("use_pooled", &unit_usepooled)
|
||||
|
||||
// skills:
|
||||
.def("get_skill", &unit_getskill)
|
||||
.def("eff_skill", &unit_effskill)
|
||||
.def("set_skill", &unit_setskill)
|
||||
|
||||
.def("add_notice", &unit_addnotice)
|
||||
|
||||
// npc logic:
|
||||
.def("add_handler", &unit_addhandler)
|
||||
|
||||
.def("set_racename", &unit_setracename)
|
||||
.def("add_spell", &unit_addspell)
|
||||
.def("remove_spell", &unit_removespell)
|
||||
.def("cast_spell", &unit_castspell)
|
||||
|
||||
.property("magic", &unit_getmagic, &unit_setmagic)
|
||||
.property("aura", &unit_getaura, &unit_setaura)
|
||||
.property("building", &unit_getbuilding, &unit_setbuilding)
|
||||
.property("ship", &unit_getship, &unit_setship)
|
||||
.property("region", &unit_getregion, &unit_setregion)
|
||||
.property("spells", &unit_spells, return_stl_iterator)
|
||||
.property("number", &unit_getnumber, &unit_setnumber)
|
||||
.property("race", &unit_getrace, &unit_setrace)
|
||||
.property("hp_max", &unit_hpmax)
|
||||
.property("objects", &eressea::get_objects<unit>)
|
||||
.scope [
|
||||
def("create", &add_unit)
|
||||
]
|
||||
];
|
||||
}
|
|
@ -1,9 +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 - 2005 |
|
||||
* | | This program may not be used, modified or distributed
|
||||
* +-------------------+ without prior permission by the authors of Eressea.
|
||||
*
|
||||
*/
|
164
src/premake.lua
164
src/premake.lua
|
@ -1,164 +0,0 @@
|
|||
project.name = "eressea"
|
||||
project.configs = { "Debug", "Profile", "Release" }
|
||||
|
||||
-- the name of the curses library on this system:
|
||||
c_defines = { }
|
||||
lib_curses = "curses"
|
||||
if (windows) then
|
||||
lib_curses = "pdcurses"
|
||||
c_defines = { "WIN32", "_CRT_SECURE_NO_DEPRECATE" }
|
||||
end
|
||||
|
||||
package = newpackage()
|
||||
package.name = "util"
|
||||
package.kind = "lib"
|
||||
package.language = "c"
|
||||
package.path = "common"
|
||||
package.includepaths = { "..", "." }
|
||||
package.files = matchfiles("../config.h", "settings.h", "util/*.c", "util/*.h", "iniparser/*.c", "iniparser/*.h")
|
||||
package.excludes = { "util/strncpy.c" }
|
||||
for k,v in project.configs do
|
||||
package.config[v].objdir = v .. "/" .. package.name
|
||||
package.config[v].libdir = v .. "/" .. package.name
|
||||
table.insert(package.config[v].buildflags, "extra-warnings")
|
||||
table.insert(package.config[v].buildflags, "no-debug-runtime")
|
||||
table.insert(package.config[v].buildflags, "singlethread-runtime")
|
||||
for index, name in c_defines do
|
||||
table.insert(package.config[v].defines, name)
|
||||
end
|
||||
if v~="Debug" then
|
||||
table.insert(package.config[v].defines, "NDEBUG")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
package = newpackage()
|
||||
package.name = "kernel"
|
||||
package.kind = "lib"
|
||||
package.language = "c"
|
||||
package.path = "common"
|
||||
package.includepaths = { "..", "." }
|
||||
package.files = matchfiles("kernel/*.c", "triggers/*.c", "spells/*.c", "items/*.c", "kernel/*.h", "triggers/*.h", "spells/*.h", "items/*.h", "modules/*.h", "modules/*.c", "attributes/*.h", "attributes/*.c")
|
||||
package.excludes = {
|
||||
"modules/victoryconditions.c",
|
||||
"modules/victoryconditions.h",
|
||||
"items/studypotion.c",
|
||||
"items/studypotion.h",
|
||||
"kernel/sqlstore.c",
|
||||
"kernel/sqlstore.h"
|
||||
}
|
||||
for k,v in project.configs do
|
||||
package.config[v].objdir = v .. "/" .. package.name
|
||||
package.config[v].libdir = v .. "/" .. package.name
|
||||
table.insert(package.config[v].buildflags, "extra-warnings")
|
||||
table.insert(package.config[v].buildflags, "no-debug-runtime")
|
||||
table.insert(package.config[v].buildflags, "singlethread-runtime")
|
||||
for index, name in c_defines do
|
||||
table.insert(package.config[v].defines, name)
|
||||
end
|
||||
if v~="Debug" then
|
||||
table.insert(package.config[v].defines, "NDEBUG")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
package = newpackage()
|
||||
package.name = "gamecode"
|
||||
package.kind = "lib"
|
||||
package.language = "c"
|
||||
package.path = "common"
|
||||
package.includepaths = { "..", "." }
|
||||
package.files = matchfiles("gamecode/*.c", "races/*.c", "gamecode/*.h", "races/*.h")
|
||||
for k,v in project.configs do
|
||||
package.config[v].objdir = v .. "/" .. package.name
|
||||
package.config[v].libdir = v .. "/" .. package.name
|
||||
table.insert(package.config[v].buildflags, "extra-warnings")
|
||||
table.insert(package.config[v].buildflags, "no-debug-runtime")
|
||||
table.insert(package.config[v].buildflags, "singlethread-runtime")
|
||||
for index, name in c_defines do
|
||||
table.insert(package.config[v].defines, name)
|
||||
end
|
||||
if v~="Debug" then
|
||||
table.insert(package.config[v].defines, "NDEBUG")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
package = newpackage()
|
||||
package.name = "bindings"
|
||||
package.kind = "lib"
|
||||
package.language = "c++"
|
||||
package.path = "eressea/lua"
|
||||
package.includepaths = { "../..", "../../common" }
|
||||
package.files = matchfiles("*.cpp", "*.h")
|
||||
package.excludes = { "gm.cpp" }
|
||||
for k,v in project.configs do
|
||||
package.config[v].objdir = v .. "/" .. package.name
|
||||
package.config[v].libdir = v .. "/" .. package.name
|
||||
table.insert(package.config[v].buildflags, "extra-warnings")
|
||||
table.insert(package.config[v].buildflags, "no-debug-runtime")
|
||||
table.insert(package.config[v].buildflags, "singlethread-runtime")
|
||||
for index, name in c_defines do
|
||||
table.insert(package.config[v].defines, name)
|
||||
end
|
||||
if v~="Debug" then
|
||||
table.insert(package.config[v].defines, "NDEBUG")
|
||||
end
|
||||
end
|
||||
|
||||
package = newpackage()
|
||||
package.name = "editor"
|
||||
package.kind = "lib"
|
||||
package.language = "c++"
|
||||
package.path = "eressea"
|
||||
package.includepaths = { "..", "../common" }
|
||||
package.files = { "gmtool.h", "gmtool.c", "editing.c", "editing.h", "curses/listbox.h", "curses/listbox.c", "lua/gm.cpp" }
|
||||
for k,v in project.configs do
|
||||
package.config[v].objdir = v .. "/" .. package.name
|
||||
package.config[v].libdir = v .. "/" .. package.name
|
||||
table.insert(package.config[v].buildflags, "extra-warnings")
|
||||
table.insert(package.config[v].buildflags, "no-debug-runtime")
|
||||
table.insert(package.config[v].buildflags, "singlethread-runtime")
|
||||
for index, name in c_defines do
|
||||
table.insert(package.config[v].defines, name)
|
||||
end
|
||||
if v~="Debug" then
|
||||
table.insert(package.config[v].defines, "NDEBUG")
|
||||
end
|
||||
end
|
||||
|
||||
package = newpackage()
|
||||
package.name = "eressea-lua"
|
||||
package.kind = "exe"
|
||||
package.language = "c++"
|
||||
package.path = "eressea"
|
||||
package.includepaths = { "..", "../common" }
|
||||
package.files = { "korrektur.c", "server.cpp", "console.c", "console.h" }
|
||||
package.links = { "util", "kernel", "gamecode", "bindings", "editor", "libxml2", lib_curses}
|
||||
for k,v in project.configs do
|
||||
package.config[v].objdir = v
|
||||
package.config[v].bindir = v
|
||||
table.insert(package.config[v].buildflags, "extra-warnings")
|
||||
table.insert(package.config[v].buildflags, "no-debug-runtime")
|
||||
table.insert(package.config[v].buildflags, "singlethread-runtime")
|
||||
for index, name in c_defines do
|
||||
table.insert(package.config[v].defines, name)
|
||||
end
|
||||
if (windows) then
|
||||
if target=="vs2005" then
|
||||
if v=="Debug" then
|
||||
package.config[v].links = { "lua5.1_d", "luabind_d" }
|
||||
else
|
||||
package.config[v].links = { "lua5.1", "luabind" }
|
||||
end
|
||||
else
|
||||
package.config[v].links = { "lua50", "luabind" }
|
||||
end
|
||||
end
|
||||
if v~="Debug" then
|
||||
table.insert(package.config[v].defines, "NDEBUG")
|
||||
end
|
||||
end
|
||||
|
||||
-- kernel: util, triggers, attributes, spells, items
|
||||
-- gamecode: races
|
24
src/rts.txt
24
src/rts.txt
|
@ -1,24 +0,0 @@
|
|||
Aenderungen fuer Eressea RTS:
|
||||
|
||||
* Befehle abgeschafft:
|
||||
|
||||
ARBEITEN, LEHREN, SPIONIEREN, SABOTIEREN, KRIEG, FRIEDEN, FORSCHEN, TARNEN, TREIBEN, UNTERHALTEN, KAUFEN, VERKAUFEN, ZUECHTEN, LIEFERE, MEINUNG, MAGIEGEBIET, NEUSTART, OPFERE, BETEN, JIHAD, INFO, GM, WERWESEN, ALLIANZ, XONTORMIA, SYNONYM
|
||||
|
||||
* Learning by doing abgeschafft.
|
||||
|
||||
* Skills disabled:
|
||||
|
||||
espionage, entertainment, taxation, tactics, stealth, trade, perception
|
||||
|
||||
* Alle Gebaeude entfernt, mit Ausnahme von Burgen
|
||||
|
||||
* Keine NPC-Monster
|
||||
|
||||
* Einheiten koennen ueber ihre Grundskills hinaus keine neuen Skills lernen
|
||||
|
||||
|
||||
|
||||
Offene Fragen:
|
||||
|
||||
* Soll es eine Maximalanzahl Einheiten geben?
|
||||
|
54
src/todo.txt
54
src/todo.txt
|
@ -1,54 +0,0 @@
|
|||
TODO:
|
||||
|
||||
Eressea:
|
||||
- AI: Nicht mehr als n Wyrme in die gleiche region. Keine 12 auf jeden Fall.
|
||||
- Gletscherauflösung 4./5. welt
|
||||
- new ITF_NOLOOT für sonnensegel
|
||||
- Deathcloud: Magieresistenz des Magiers in das attribut, nicht auflösen wenn magier tot.
|
||||
|
||||
Code cleanup:
|
||||
- curse type should contain effect-type
|
||||
- mehr itemtypes auslagern
|
||||
- getstrtoken() - das static loswerden?
|
||||
- readline implementieren
|
||||
- Make asserts into release-mode fails.
|
||||
- unterschiede in vin3 + wdw per config statt defines?
|
||||
- age branch (store birthdate instead of age)
|
||||
- give monsters name with lua
|
||||
- allocators aus economy nach XML
|
||||
- reporting units: http://eressea.upb.de/mantis/view.php?id=781
|
||||
- wdw pyramid spell could be written in lua (replace attrib with a flag)
|
||||
|
||||
Larger Features:
|
||||
- eressea (b/g)zip reports?
|
||||
- ZERSTÖRE - Man sollte alle Materialien zurückkriegen können:
|
||||
|
||||
Scripts, etc:
|
||||
- format=flowed annahme, eressea
|
||||
- english registration confirmation is deutsch!
|
||||
- XUL for Eressea
|
||||
|
||||
Old Terrain still needed:
|
||||
- random people encounters (get_allies)
|
||||
- creating dragons
|
||||
- drought curse
|
||||
- volcanoes
|
||||
- glacier logic
|
||||
- make_summary, volcano-count
|
||||
- save.c, conversion
|
||||
- terraform, old syntax
|
||||
- terraform, more horses in plains
|
||||
- dragon name
|
||||
- arena-module
|
||||
- build.c, Strassenbau
|
||||
- monster.c, ent movement
|
||||
- economy.c, insekten
|
||||
|
||||
unterschiede in vin3 + wdw per config statt defines?
|
||||
|
||||
#define NEWATSROI 1
|
||||
#define ATSBONUS 2
|
||||
#define ROIBONUS 4
|
||||
|
||||
#define ARENA_MODULE
|
||||
#define WORMHOLE_MODULE
|
|
@ -1,158 +0,0 @@
|
|||
/* libxml includes */
|
||||
#include <libxml/tree.h>
|
||||
#include <libxml/xpath.h>
|
||||
|
||||
/* libc includes */
|
||||
#include <string.h>
|
||||
|
||||
const char * prefix = "tolua_";
|
||||
const char * tmp_includes =
|
||||
"#include <lua.h>\n"
|
||||
"#include <tolua.h>\n"
|
||||
;
|
||||
void
|
||||
read_templates()
|
||||
{
|
||||
}
|
||||
|
||||
xmlDocPtr
|
||||
readfile(const char * filename)
|
||||
{
|
||||
xmlDocPtr doc;
|
||||
#ifdef XML_PARSE_XINCLUDE
|
||||
doc = xmlReadFile(filename, NULL, XML_PARSE_XINCLUDE);
|
||||
#else
|
||||
doc = xmlParseFile(filename);
|
||||
#endif
|
||||
return doc;
|
||||
}
|
||||
|
||||
static void
|
||||
open_function(xmlNodePtr node, FILE * out)
|
||||
{
|
||||
xmlChar * name = xmlGetProp(node, BAD_CAST "name");
|
||||
xmlNodePtr call;
|
||||
|
||||
if (fname) {
|
||||
fprintf(out, " tolua_function(tolua_S, \"%s\", %s);\n", name, fname);
|
||||
}
|
||||
xmlFree(name);
|
||||
}
|
||||
|
||||
static void
|
||||
open_variable(xmlNodePtr node, FILE * out)
|
||||
{
|
||||
xmlChar * name = xmlGetProp(node, BAD_CAST "name");
|
||||
xmlChar * getter = BAD_CAST "0";
|
||||
xmlChar * setter = BAD_CAST "0";
|
||||
fprintf(out, " tolua_variable(tolua_S, \"%s\", %s%s, %s%s);\n", name, prefix, getter, prefix, setter);
|
||||
xmlFree(name);
|
||||
}
|
||||
|
||||
static void
|
||||
open_method(xmlNodePtr node, FILE * out)
|
||||
{
|
||||
xmlChar * name = xmlGetProp(node, BAD_CAST "name");
|
||||
xmlFree(name);
|
||||
}
|
||||
|
||||
static void
|
||||
open_class(xmlNodePtr node, FILE * out)
|
||||
{
|
||||
xmlChar * lname = xmlGetProp(node, BAD_CAST "name");
|
||||
xmlChar * name = xmlGetProp(node, BAD_CAST "ctype");
|
||||
xmlChar * base = xmlGetProp(node, BAD_CAST "base");
|
||||
const char * col = "NULL";
|
||||
fprintf(out, " tolua_cclass(tolua_S, \"%s\", \"%s\", \"%s\", %s);\n",
|
||||
lname, name, base, col);
|
||||
xmlFree(lname);
|
||||
xmlFree(name);
|
||||
xmlFree(base);
|
||||
}
|
||||
|
||||
static void
|
||||
open_module(xmlNodePtr root, FILE * out)
|
||||
{
|
||||
xmlNodePtr node;
|
||||
xmlChar * name = xmlGetProp(root, BAD_CAST "name");
|
||||
if (name) {
|
||||
fprintf(out, " tolua_module(tolua_S, \"%s\", 0);\n", name);
|
||||
fprintf(out, " tolua_beginmodule(tolua_S, \"%s\");\n", name);
|
||||
xmlFree(name);
|
||||
} else {
|
||||
fputs(" tolua_module(tolua_S, 0, 0);\n", out);
|
||||
fputs(" tolua_beginmodule(tolua_S, 0);\n", out);
|
||||
}
|
||||
|
||||
for (node=root->children;node;node=node->next) {
|
||||
if (strcmp((const char *)node->name, "class")==0) {
|
||||
open_class(node, out);
|
||||
} else if (strcmp((const char *)node->name, "module")==0) {
|
||||
open_module(node, out);
|
||||
} else if (strcmp((const char *)node->name, "function")==0) {
|
||||
open_function(node, out);
|
||||
} else if (strcmp((const char *)node->name, "method")==0) {
|
||||
open_method(node, out);
|
||||
} else if (strcmp((const char *)node->name, "variable")==0) {
|
||||
open_variable(node, out);
|
||||
}
|
||||
}
|
||||
fputs(" tolua_endmodule(tolua_S);\n", out);
|
||||
}
|
||||
|
||||
static void
|
||||
open_type(xmlNodePtr root, FILE * out)
|
||||
{
|
||||
xmlChar * name = xmlGetProp(root, BAD_CAST "name");
|
||||
fprintf(out, " tolua_usertype(tolua_S, \"%s\");\n", name);
|
||||
xmlFree(name);
|
||||
}
|
||||
|
||||
void
|
||||
open_package(xmlNodePtr root, FILE * out)
|
||||
{
|
||||
xmlNodePtr node;
|
||||
xmlChar * pkg_name = xmlGetProp(root, BAD_CAST "name");
|
||||
fprintf(out, "int %s%s_open(struct lua_State * L) {\n", prefix, pkg_name);
|
||||
xmlFree(pkg_name);
|
||||
|
||||
fputs(" tolua_open(L);\n", out);
|
||||
|
||||
for (node=root->children;node;node=node->next) {
|
||||
if (strcmp((const char *)node->name, "type")==0) {
|
||||
open_type(node, out);
|
||||
} else if (strcmp((const char *)node->name, "module")==0) {
|
||||
open_module(node, out);
|
||||
}
|
||||
}
|
||||
fputs(" return 0;\n", out);
|
||||
fputs("}\n", out);
|
||||
}
|
||||
|
||||
int
|
||||
writefile(xmlDocPtr doc, FILE * out)
|
||||
{
|
||||
/* includes etc. */
|
||||
fputs(tmp_includes, out);
|
||||
fputc('\n', out);
|
||||
/* functions */
|
||||
|
||||
/* open */
|
||||
open_package(doc->children, out);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
xmlDocPtr doc;
|
||||
if (argc>1) {
|
||||
FILE * out = stdout;
|
||||
read_templates();
|
||||
doc = readfile(argv[1]);
|
||||
if (doc) {
|
||||
return writefile(doc, stdout);
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
|
@ -1,206 +0,0 @@
|
|||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="8.00"
|
||||
Name="codegen"
|
||||
ProjectGUID="{BEF9E49F-3E98-4CE7-B641-62456E656E34}"
|
||||
RootNamespace="codegen"
|
||||
Keyword="Win32Proj"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="4"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="kernel32.lib $(NoInherit) libxml2.lib "
|
||||
LinkIncremental="2"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
WholeProgramOptimization="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
|
||||
RuntimeLibrary="2"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="kernel32.lib $(NoInherit)"
|
||||
LinkIncremental="1"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\codegen.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
|
||||
>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
|
||||
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\..\eressea\tolua\message.xml"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<File
|
||||
RelativePath=".\ReadMe.txt"
|
||||
>
|
||||
</File>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
|
@ -1,362 +0,0 @@
|
|||
/* vi: set ts=2:
|
||||
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
| | Enno Rehling <enno@eressea-pbem.de>
|
||||
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
|
||||
| (c) 1998 - 2001 | 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.
|
||||
*/
|
||||
#include <config.h>
|
||||
#include <eressea.h>
|
||||
|
||||
#include <attributes/attributes.h>
|
||||
#include <attributes/key.h>
|
||||
#include <spells/spells.h>
|
||||
#include <triggers/triggers.h>
|
||||
#include <items/weapons.h>
|
||||
#include <items/items.h>
|
||||
|
||||
#include <modules/xmas2000.h>
|
||||
#include <modules/arena.h>
|
||||
#include <modules/museum.h>
|
||||
#include <modules/gmcmd.h>
|
||||
|
||||
#include <item.h>
|
||||
#include <faction.h>
|
||||
#include <race.h>
|
||||
#include <region.h>
|
||||
#include <reports.h>
|
||||
#include <resources.h>
|
||||
#include <save.h>
|
||||
#include <unit.h>
|
||||
#include <plane.h>
|
||||
#include <teleport.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <limits.h>
|
||||
#include <locale.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
extern boolean quiet;
|
||||
|
||||
extern char *reportdir;
|
||||
extern char *datadir;
|
||||
extern char *basedir;
|
||||
extern int maxregions;
|
||||
char datafile[256];
|
||||
|
||||
extern char * g_datadir;
|
||||
extern char * g_resourcedir;
|
||||
extern char * g_basedir;
|
||||
|
||||
/**/
|
||||
|
||||
static struct attrib_type at_age = {
|
||||
"age", NULL, NULL, NULL, NULL, NULL, ATF_UNIQUE
|
||||
};
|
||||
|
||||
/* make sure that this is done only once! */
|
||||
#define do_once(magic, fun) \
|
||||
{ \
|
||||
attrib * a = find_key(global.attribs, atoi36(magic)); \
|
||||
if (a) { \
|
||||
log_warning(("[do_once] a unique fix %d=\"%s\" was called a second time\n", atoi36(magic), magic)); \
|
||||
} else { \
|
||||
(fun); \
|
||||
a_add(&global.attribs, make_key(atoi36(magic))); \
|
||||
} \
|
||||
}
|
||||
|
||||
#if NEW_RESOURCEGROWTH
|
||||
static void
|
||||
convert_resources(void)
|
||||
{
|
||||
region *r;
|
||||
FILE * fixes = fopen("resource.fix", "w");
|
||||
log_open("resourcefix.log");
|
||||
for(r=regions;r;r=r->next) {
|
||||
attrib *a = a_find(r->attribs, &at_resources);
|
||||
r->resources = 0;
|
||||
terraform_resources(r);
|
||||
|
||||
if (a==NULL) continue;
|
||||
else {
|
||||
int INIT_STONE = 20; /* skip this many weeks */
|
||||
double ironmulti = 0.40;
|
||||
double laenmulti = 0.50;
|
||||
double stonemulti = 0.30; /* half the stones used */
|
||||
rawmaterial * rmiron = rm_get(r, rm_iron.rtype);
|
||||
rawmaterial * rmlaen = rm_get(r, rm_laen.rtype);
|
||||
rawmaterial * rmstone = rm_get(r, rm_stones.rtype);
|
||||
|
||||
int oldiron;
|
||||
int oldlaen = MAXLAENPERTURN * MIN(r->age, 100) / 2;
|
||||
int oldstone = terrain[rterrain(r)].quarries * MAX(0, r->age - INIT_STONE);
|
||||
int iron = a->data.sa[0];
|
||||
int laen = a->data.sa[1];
|
||||
int stone, level;
|
||||
int i, base;
|
||||
|
||||
/** STONE **/
|
||||
for (i=0;terrain[r->terrain].rawmaterials[i].type;++i) {
|
||||
if (terrain[r->terrain].rawmaterials[i].type == &rm_stones) break;
|
||||
}
|
||||
if (terrain[r->terrain].rawmaterials[i].type) {
|
||||
base = terrain[r->terrain].rawmaterials[i].base;
|
||||
stone = max (0, (int)(oldstone * stonemulti));
|
||||
level = 1;
|
||||
base = (int)(terrain[r->terrain].rawmaterials[i].base*(1+level*terrain[r->terrain].rawmaterials[i].divisor));
|
||||
while (stone >= base) {
|
||||
stone-=base;
|
||||
++level;
|
||||
base = (int)(terrain[r->terrain].rawmaterials[i].base*(1+level*terrain[r->terrain].rawmaterials[i].divisor));
|
||||
}
|
||||
rmstone->level = level;
|
||||
rmstone->amount = base - stone;
|
||||
assert (rmstone->amount > 0);
|
||||
log_printf("CONVERSION: %d stones @ level %d in %s\n", rmstone->amount, rmstone->level, regionname(r, NULL));
|
||||
} else {
|
||||
log_error(("found stones in %s of %s\n", terrain[r->terrain].name, regionname(r, NULL)));
|
||||
}
|
||||
|
||||
/** IRON **/
|
||||
if (r_isglacier(r) || r->terrain==T_ICEBERG) {
|
||||
oldiron = GLIRONPERTURN * MIN(r->age, 100) / 2;
|
||||
} else {
|
||||
oldiron = IRONPERTURN * r->age;
|
||||
}
|
||||
for (i=0;terrain[r->terrain].rawmaterials[i].type;++i) {
|
||||
if (terrain[r->terrain].rawmaterials[i].type == &rm_iron) break;
|
||||
}
|
||||
if (terrain[r->terrain].rawmaterials[i].type) {
|
||||
base = terrain[r->terrain].rawmaterials[i].base;
|
||||
iron = MAX(0, (int)(oldiron * ironmulti - iron ));
|
||||
level = 1;
|
||||
base = (int)(terrain[r->terrain].rawmaterials[i].base*(1+level*terrain[r->terrain].rawmaterials[i].divisor));
|
||||
while (iron >= base) {
|
||||
iron-=base;
|
||||
++level;
|
||||
base = (int)(terrain[r->terrain].rawmaterials[i].base*(1+level*terrain[r->terrain].rawmaterials[i].divisor));
|
||||
}
|
||||
rmiron->level = level;
|
||||
rmiron->amount = base - iron;
|
||||
assert (rmiron->amount > 0);
|
||||
log_printf("CONVERSION: %d iron @ level %d in %s\n", rmiron->amount, rmiron->level, regionname(r, NULL));
|
||||
} else {
|
||||
log_error(("found iron in %s of %s\n", terrain[r->terrain].name, regionname(r, NULL)));
|
||||
}
|
||||
|
||||
/** LAEN **/
|
||||
if (laen>=0) {
|
||||
if (rmlaen==NULL) {
|
||||
rmlaen = calloc(sizeof(rawmaterial), 1);
|
||||
rmlaen->next = r->resources;
|
||||
r->resources = rmlaen;
|
||||
}
|
||||
for (i=0;terrain[r->terrain].rawmaterials[i].type;++i) {
|
||||
if (terrain[r->terrain].rawmaterials[i].type == &rm_laen) break;
|
||||
}
|
||||
if (terrain[r->terrain].rawmaterials[i].type) {
|
||||
laen = MAX(0, (int)(oldlaen * laenmulti - laen));
|
||||
level = 1;
|
||||
base = (int)(terrain[r->terrain].rawmaterials[i].base*(1+level*terrain[r->terrain].rawmaterials[i].divisor));
|
||||
while (laen >= base) {
|
||||
laen-=base;
|
||||
++level;
|
||||
base = (int)(terrain[r->terrain].rawmaterials[i].base*(1+level*terrain[r->terrain].rawmaterials[i].divisor));
|
||||
}
|
||||
rmlaen->level = level;
|
||||
rmlaen->amount = base - laen;
|
||||
assert(rmlaen->amount>0);
|
||||
log_printf("CONVERSION: %d laen @ level %d in %s\n", rmlaen->amount, rmlaen->level, regionname(r, NULL));
|
||||
rmlaen = NULL;
|
||||
}
|
||||
}
|
||||
if (rmlaen) {
|
||||
struct rawmaterial *res;
|
||||
struct rawmaterial ** pres = &r->resources;
|
||||
if (laen!=-1) log_error(("found laen in %s of %s\n", terrain[r->terrain].name, regionname(r, NULL)));
|
||||
while (*pres!=rmlaen) pres = &(*pres)->next;
|
||||
res = *pres;
|
||||
*pres = (*pres)->next;
|
||||
free(res);
|
||||
}
|
||||
#ifndef NDEBUG
|
||||
{
|
||||
rawmaterial * res = r->resources;
|
||||
while (res) {
|
||||
assert(res->amount>0);
|
||||
assert(res->level>0);
|
||||
res = res->next;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
{
|
||||
rawmaterial * rmiron = rm_get(r, rm_iron.rtype);
|
||||
rawmaterial * rmlaen = rm_get(r, rm_laen.rtype);
|
||||
rawmaterial * rmstone = rm_get(r, rm_stones.rtype);
|
||||
fprintf(fixes, "%d %d %d %d %d %d %d %d %d\n",
|
||||
r->x, r->y, r->age,
|
||||
(rmstone)?rmstone->amount:-1, (rmiron)?rmiron->amount:-1, (rmlaen)?rmlaen->amount:-1,
|
||||
(rmstone)?rmstone->level:-1, (rmiron)?rmiron->level:-1, (rmlaen)?rmlaen->level:-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
log_close();
|
||||
fclose(fixes);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
fix_age(void)
|
||||
{
|
||||
region * r;
|
||||
int c;
|
||||
for (r=regions;r;r=r->next) {
|
||||
const unit * u;
|
||||
attrib * a = a_find(r->attribs, &at_age);
|
||||
if (a==NULL) {
|
||||
a = a_add(&r->attribs, a_new(&at_age));
|
||||
}
|
||||
|
||||
for (u=r->units;u;u=u->next) {
|
||||
faction * f = u->faction;
|
||||
if (f->age<=r->age) {
|
||||
a->data.sa[0]+= f->age;
|
||||
a->data.sa[1]++;
|
||||
if (a->data.sa[0]>0x7000) {
|
||||
a->data.sa[0] /= 10;
|
||||
a->data.sa[1] /= 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#define STEPS 3
|
||||
for (c=0;c!=STEPS;++c) for (r=regions;r;r=r->next) {
|
||||
attrib * a = a_find(r->attribs, &at_age);
|
||||
int x = 0;
|
||||
direction_t i;
|
||||
int age = a->data.sa[0], div = a->data.sa[1];
|
||||
if (age) ++x;
|
||||
for (i=0;i!=MAXDIRECTIONS;++i) {
|
||||
region * nr = rconnect(r, i);
|
||||
if (nr!=NULL) {
|
||||
attrib * na = a_find(nr->attribs, &at_age);
|
||||
age += na->data.sa[0];
|
||||
div += na->data.sa[1];
|
||||
++x;
|
||||
}
|
||||
}
|
||||
if (x) {
|
||||
a->data.sa[0] = (short)(age / x);
|
||||
a->data.sa[1] = (short)(div / x);
|
||||
}
|
||||
}
|
||||
|
||||
log_open("agefix.log");
|
||||
for (r=regions;r;r=r->next) {
|
||||
attrib * a = a_find(r->attribs, &at_age);
|
||||
int age = a->data.sa[0];
|
||||
if (a->data.sa[1]==0) continue;
|
||||
age /= a->data.sa[1];
|
||||
if (age*100<r->age*90) {
|
||||
log_printf("AGE: from %d to %d in region %s\n", r->age, age, regionname(r, NULL));
|
||||
r->age = age;
|
||||
}
|
||||
}
|
||||
log_close();
|
||||
}
|
||||
|
||||
static void
|
||||
fixit(void)
|
||||
{
|
||||
fix_age();
|
||||
do_once("rgrw", convert_resources());
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
char zText[MAX_PATH];
|
||||
boolean backup = true;
|
||||
boolean save = true;
|
||||
int i = 1;
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
|
||||
*datafile = 0;
|
||||
|
||||
while (i < argc && argv[i][0] == '-') {
|
||||
switch (argv[i][1]) {
|
||||
case 't':
|
||||
if (argv[i][2])
|
||||
turn = atoi((char *)(argv[i] + 2));
|
||||
else
|
||||
turn = atoi(argv[++i]);
|
||||
break;
|
||||
case 'x':
|
||||
maxregions = atoi(argv[++i]);
|
||||
maxregions = (maxregions*81+80) / 81;
|
||||
break;
|
||||
case 'q': quiet = true; break;
|
||||
case 'n':
|
||||
switch (argv[i][2]) {
|
||||
case 'b' : backup = false; break;
|
||||
case 's' : save = false; break;
|
||||
}
|
||||
break;
|
||||
case 'd':
|
||||
g_datadir = argv[++i];
|
||||
break;
|
||||
case 'r':
|
||||
g_resourcedir = argv[++i];
|
||||
break;
|
||||
case 'o':
|
||||
strcpy(datafile, argv[++i]);
|
||||
break;
|
||||
case 'b':
|
||||
g_basedir = argv[++i];
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
kernel_init();
|
||||
|
||||
init_triggers();
|
||||
|
||||
register_races();
|
||||
register_spells();
|
||||
|
||||
debug_language("locales.log");
|
||||
sprintf(zText, "%s/%s", resourcepath(), "eressea.xml");
|
||||
init_data(zText);
|
||||
init_locales();
|
||||
|
||||
init_attributes();
|
||||
init_resources();
|
||||
register_items();
|
||||
|
||||
init_rawmaterials();
|
||||
init_museum();
|
||||
init_arena();
|
||||
init_xmas2000();
|
||||
|
||||
init_gmcmd();
|
||||
|
||||
if(!*datafile)
|
||||
sprintf(datafile, "%s/%d", datapath(), turn);
|
||||
|
||||
readgame(backup);
|
||||
|
||||
fixit();
|
||||
|
||||
if (save) writegame(datafile, 1);
|
||||
return 0;
|
||||
}
|
|
@ -1,282 +0,0 @@
|
|||
|
||||
Nach den sehr erfolgreichen vergangenen drei Spielerbefragungen (unter
|
||||
http://pegasus.upb.de/umfrage-1999/index.html findet ihr die Ergebnisse
|
||||
der letzten Befragung) gibt es jetzt die vierte Spielerbefragung. Sie
|
||||
soll uns helfen, besser zu erfassen, wer die Spieler sind, was sie sich
|
||||
vom Spiel erhoffen, und ob wir auf dem richtigen Weg sind.
|
||||
|
||||
Diesmal hat sie noch einen ganz besonderen Grund (siehe Frage 2). Und wir
|
||||
wollen die sehr erfolgreiche Befragung zu den Clients fortsetzen.
|
||||
|
||||
Da wir den Fragebogen automatisch auswerten wollen, halte dich bitte
|
||||
an folgende Richtlinien:
|
||||
|
||||
- Bei Fragen, in denen ein Feld ([ ]) zur Auswahl steht, kreuze
|
||||
bitte das Feld an ([x]) oder schreibe die Antwort hinein
|
||||
([1234]).
|
||||
|
||||
[x] ich bin ein [99] Jahre alter Ork
|
||||
|
||||
Wo Schulnoten gefragt sind, benutze bitte nur die Standardschulnoten
|
||||
von 1-6, ohne Modifikatoren (+/-).
|
||||
|
||||
[1] Dämonen werden die Welt übernehmen
|
||||
|
||||
- Aendere die Formatierung des Fragebogens moeglichst nicht! Fuege
|
||||
insbesondere keine zusaetzlichen Umbrueche ein.
|
||||
|
||||
- Schicke deine Antwort mit dem Betreff 'Spielerumfrage' an
|
||||
eressea@eressea.amber.kn-bremen.de. Am einfachsten machst du
|
||||
dafuer einfach ein Reply auf diese Mail. Bitte schicke die
|
||||
Antwort nicht als Attachment und nicht in HTML!
|
||||
|
||||
|
||||
1. Angaben zur Person
|
||||
|
||||
Uns interessiert immer wieder, wer die Person hinter der Partei ist,
|
||||
fuer wen wir das Spiel eigentlich machen. Wie alt bist Du? Bist du
|
||||
maennlich oder weiblich?
|
||||
|
||||
1.1.1 [ ] Jahre alt
|
||||
1.1.2 [ ] maennlich
|
||||
1.1.3 [ ] weiblich
|
||||
|
||||
In welchem Land lebst du? Bitte keine Scherze wie "Tirol" oder
|
||||
"Sauerland". Wir werten das ganze elektronisch aus, und sowas kostet
|
||||
uns immer viel Zeit bei der Bereinigung der Daten.
|
||||
|
||||
1.2.1 [ ] Deutschland
|
||||
1.2.2 [ ] Oesterreich
|
||||
1.2.3 [ ] Schweiz
|
||||
1.2.4 [ ] anderes Land, und zwar: [ ]
|
||||
|
||||
Wie viele Monate spielst du schon Eressea?
|
||||
|
||||
1.3.1 [ ] Wochen
|
||||
|
||||
Wieviele Parteien hast du in dieser Zeit gespielt?
|
||||
(Urlaubsvertretungen nicht mitgezaehlt)
|
||||
|
||||
1.3.2 [ ] Parteien gespielt
|
||||
|
||||
Was waren der/die Grund/Gruende fuer den Neubeginn:
|
||||
|
||||
1.4.1 [ ] Schlechte Startbedingungen
|
||||
1.4.2 [ ] Krieg verloren
|
||||
1.4.3 [ ] Zuviele eigene Fehler
|
||||
1.4.4 [ ] Zuviele NMRs
|
||||
1.4.5 [ ] Unsympathische/schwierige Nachbarn
|
||||
1.4.6 [ ] Zu wenige Nachbarn
|
||||
1.4.7 [ ] Zu viele Nachbarn
|
||||
1.4.8 [ ] Das Gefuehl, alles erreicht zu haben
|
||||
1.4.9 [ ] Sonstiges, und zwar: [ ]
|
||||
|
||||
Wie gefällt dir das Spiel?
|
||||
|
||||
1.5.1 [ ] Bestes Spiel der Welt
|
||||
1.5.2 [ ] macht Spass
|
||||
1.5.3 [ ] ist okay
|
||||
1.5.4 [ ] ich mache demnaechst Schluss
|
||||
|
||||
Bitte benote, wie wichtig dir die folgenden Aspekte von Eressea sind.
|
||||
(1 - sehr wichtig, 6 - mir unwichtig)
|
||||
|
||||
1.6.1 [ ] Rollenspiel und Diplomatie
|
||||
1.6.2 [ ] Schlachten und Konflikte
|
||||
1.6.3 [ ] Entwicklung und Forscherdrang
|
||||
1.6.4 [ ] Geschichte und Geschichten von Eressea
|
||||
|
||||
Wie benotest du die folgenden Punkte? (1 - Klasse, 6 - Furchtbar)
|
||||
|
||||
1.7.1 [ ] Hilfe durch Entwickler, z.B. bei technischen Problemen
|
||||
1.7.2 [ ] Hilfen für Anfaenger
|
||||
1.7.3 [ ] Mailhandling (Befehle, Reports nachbestellen, etc.)
|
||||
1.7.4 [ ] Lesbarkeit der Reports
|
||||
1.7.5 [ ] Anzahl der Reportoptionen
|
||||
1.7.6 [ ] Umgangston unter den Spielern
|
||||
1.7.7 [ ] Xontormia Express
|
||||
|
||||
Bist Du Schueler, Student oder berufstaetig?
|
||||
|
||||
1.8.1 [ ] Schueler
|
||||
1.8.2 [ ] Student/Auszubildender
|
||||
1.8.3 [ ] Berufstaetig
|
||||
1.8.4 [ ] Nicht berufstaetig und nicht in Ausbildung
|
||||
|
||||
Noch ein paar Zusatzfragen. Kreuze an, was auf dich zutrifft.
|
||||
|
||||
1.9.1 [ ] Ich habe schon mindestens eine(n) Freund(in) zum Spiel ueberredet
|
||||
1.9.2 [ ] Eressea ist dasjenige Hobby, dem ich die meiste Zeit widme
|
||||
1.9.3 [ ] Ich spiele regelmaessig Onlinespiele
|
||||
(z.B. Halflife, Ultima Online)
|
||||
1.9.4 [ ] Meine Telefonrechnung (ohne Grundgebuehr) uebersteigt 40 DM/Monat
|
||||
1.9.5 [ ] Ich war schon einmal auf einem Eressea-Spielertreffen
|
||||
1.9.6 [ ] Ich spiele regelmaessig Pen&Paper Rollenspiele
|
||||
1.9.7 [ ] Ich habe durch das Spiel Freunde gefunden, mit denen ich auch
|
||||
ausserhalb Eresseas etwas unternehme
|
||||
|
||||
|
||||
|
||||
2. Zweites Spiel
|
||||
|
||||
Wir haben mehrfach darueber nachgedacht, ein zweites Spiel zu starten.
|
||||
Vor allem wollen wir das aktuelle Spiel am Leben erhalten, und das
|
||||
aktuelle Eressea wuerde davon auch nicht betroffen. Aber ein neues
|
||||
Spiel bietet die Moeglichkeit groesserer Veraenderungen, und die
|
||||
Beseitigung von Fehlern, die im laufenden Spiel nicht denkbar sind.
|
||||
Angenommen, es wuerde noch ein zweites Spiel wie Eressea gestartet.
|
||||
Wuerdest Du da mitspielen?
|
||||
|
||||
2.1.1 [ ] Ja, und in Eressea weiterspielen
|
||||
2.1.2 [ ] Ja, und mit Eressea aufhoeren
|
||||
2.1.3 [ ] Nein, ich habe an Eressea genug
|
||||
|
||||
Da so etwas wieder viel zusaetzliche Zeit in Anspruch nimmt, ist es
|
||||
wahrscheinlich fuer uns nicht vertretbar, so etwas kostenlos
|
||||
anzubieten. Waerst Du bereit, fuer ein zweites Spiel Geld auszugeben?
|
||||
|
||||
2.2.1 [ ] Nein, auf keinen Fall.
|
||||
2.2.2 [ ] Ja, aber dafuer muss es sich von Eressea ausreichend unterscheiden
|
||||
2.2.3 [ ] Ja.
|
||||
|
||||
Viele von uns haben durch Onlinespiele oder Handys bereits eine hohe
|
||||
Telefonrechnung. Der Preis eines PBeM kann wahrscheinlich mit der
|
||||
Telefoniersucht des durchschnittlichen Deutschen garnicht
|
||||
konkurrieren. Bitte ueberleg, wieviel es Dir wirklich wert ist. Ob es
|
||||
sich fuer uns lohnt, und wir uns fuer ein zweites Spiel einsetzen
|
||||
haengt vor allem von der Antwort auf diese Frage ab. Uns ist nicht
|
||||
geholfen, wenn jeder 50 Pfg schreibt, und auch nicht, wenn Fabelpreise
|
||||
entstehen, die spaeter niemand zahlt. Also: Falls ja, was waerst Du zu
|
||||
zahlen bereit?
|
||||
|
||||
2.3.1 [ ] DM/ZAT
|
||||
|
||||
|
||||
3. Welche Clients benutzt Du?
|
||||
|
||||
Bitte kreuze nur solche Clients an, die du REGELMAESSIG benutzt, um
|
||||
deine Zuege zu erstellen, nicht solche, die du nur ausprobiert hast.
|
||||
Falls Du der Autor eines der Programme bist, kreuze bitte nicht
|
||||
zusaetzlich 'Selbstgemachtes Programm' an.
|
||||
|
||||
3.1.1 [ ] crtools, eva, eformat (E. Rehling)
|
||||
3.1.2 [ ] Den Java-Client
|
||||
3.1.3 [ ] E/V Assistent (M. Pollaschke)
|
||||
3.1.4 [ ] ECheck (H. Peters)
|
||||
3.1.5 [ ] ECheck Frontend (J. Kirchhoff)
|
||||
3.1.6 [ ] EHMV (C. Schubert
|
||||
3.1.7 [ ] Einen Namensgenerator
|
||||
3.1.8 [ ] EMap (P. Stern)
|
||||
3.1.9 [ ] eSurvey (S. Tusk)
|
||||
3.1.10 [ ] gReport (S. Reich)
|
||||
3.1.11 [ ] HexMap (H. Peters)
|
||||
3.1.12 [ ] Kampfsimulator (F. Schatz)
|
||||
3.1.13 [ ] Mercator (R. Butenuth)
|
||||
3.1.14 [ ] NameMe (H. Peters)
|
||||
3.1.15 [ ] Perl Tools (G. Edelmayer, F. Wolkwitz)
|
||||
3.1.16 [ ] Vorlage (S. Schuemann)
|
||||
3.1.17 [ ] VPP (S. Schuemann)
|
||||
3.1.18 [ ] anderes, selbstgemachtes Programm
|
||||
3.1.19 [ ] andere, und zwar: [ ]
|
||||
|
||||
|
||||
4. Anleitung
|
||||
|
||||
Welches Format fuer die Anleitung ist Dir am liebsten, d.h. welche
|
||||
benutzt Du am meisten? Mehrfachnennungen sind erlaubt.
|
||||
|
||||
4.1.1 [ ] Word-Dokument
|
||||
4.1.2 [ ] Latex-Quelltext
|
||||
4.1.3 [ ] Postscript
|
||||
4.1.4 [ ] PDF
|
||||
4.1.5 [ ] HTML
|
||||
4.1.6 [ ] Windows Hilfedatei (CHM)
|
||||
4.1.7 [ ] ASCII
|
||||
4.1.8 [ ] andere, und zwar: [ ]
|
||||
|
||||
Wie bewertest du die Qualitaet der folgenden Aspekte der Anleitung?
|
||||
Bitte benutze normale Schulnoten (1-6).
|
||||
|
||||
4.2.1 [ ] Einsteigerfreundlichkeit
|
||||
4.2.2 [ ] Uebersichtlichkeit
|
||||
4.2.3 [ ] Informationsgehalt
|
||||
4.2.4 [ ] Stil
|
||||
|
||||
|
||||
5. Spielkonzepte
|
||||
|
||||
Natuerlich interessiert uns, wie ihr bestimmte Aspekte des Spiels
|
||||
bewertet, und wo ihr Handlungsbedarf für Aenderungen seht. Bitte
|
||||
bewerte auf einer Skala von 1-6, für wie gelungen du den betreffende
|
||||
Spielaspekt haelst. (1 - sehr gut/keine Aenderungen notwendig, 6 -
|
||||
miserabel/sofort aendern)
|
||||
|
||||
5.1.1 [ ] taktisches Kampfsystem
|
||||
(Alles, was den Ablauf einer einzigen Schlacht betrifft)
|
||||
5.1.2 [ ] strategisches Kampfsystem
|
||||
(Hierunter fallen 'groessere' Aspekte als eine einzelne Schlacht)
|
||||
5.1.3 [ ] Welt/Geographie
|
||||
5.1.4 [ ] Handel
|
||||
5.1.5 [ ] Seefahrt
|
||||
5.1.6 [ ] Monster/NPC
|
||||
5.1.7 [ ] Einsteigerbedingungen
|
||||
5.1.8 [ ] Rassenbalance
|
||||
5.1.9 [ ] anderes, und zwar: [ ]
|
||||
|
||||
In der Vergangenheit wurde in verschiedenen Diskussionen haeufig die
|
||||
Starre in den aelteren Welten kritisiert und als Abhilfe vorgeschlagen,
|
||||
drastische 'Questen' einzuführen, die bei Nichtgelingen auch schon
|
||||
einmal eine Welt praktisch zerstoeren koennen. Wie stehst du zu dieser
|
||||
Idee?
|
||||
|
||||
5.2.1 [ ] Bin ich voellig gegen
|
||||
5.2.2 [ ] Kommt drauf an
|
||||
5.2.3 [ ] Von mir aus in Ordnung
|
||||
|
||||
Im Fruehjahr wurde das Magiesystem umgestellt. Uns ist bewusst, das es
|
||||
noch Schwaechen gibt, trotzdem wuerde uns deine Meinung zum neuen
|
||||
Magiesystem interessieren. Bitte bewerte die folgenden Aussagen mit
|
||||
Schulnoten.
|
||||
|
||||
5.3.1 [ ] Das neue Magiesystem ist besser als das alte.
|
||||
5.3.2 [ ] Die Magiegebiete sind ausbalanciert.
|
||||
5.3.3 [ ] Die Gebiete und Zauber machen das Spiel interessanter.
|
||||
5.3.4 [ ] Die Zauberpatzer machen das Spiel interessanter.
|
||||
|
||||
|
||||
6. Uns interessiert, wie die Spielerschaft die 'Staerke' der einzelnen
|
||||
Rassen einschaetzt. Bitte ordne den unten angegebenen Rassen
|
||||
Zahlenwerte von 1-6 zu. (1 - sehr gute Rasse, 6 - sehr schlechte
|
||||
Rasse)
|
||||
|
||||
6.1.1 [ ] Goblins
|
||||
6.1.2 [ ] Trolle
|
||||
6.1.3 [ ] Orks
|
||||
6.1.4 [ ] Daemonen
|
||||
6.1.5 [ ] Elfen
|
||||
6.1.6 [ ] Meermenschen
|
||||
6.1.7 [ ] Menschen
|
||||
6.1.8 [ ] Zwerge
|
||||
6.1.9 [ ] Katzen
|
||||
6.1.10 [ ] Insekten
|
||||
6.1.11 [ ] Halblinge
|
||||
|
||||
Welche Rasse hat deine eigene Partei?
|
||||
|
||||
6.2.1 [ ] Goblins
|
||||
6.2.2 [ ] Trolle
|
||||
6.2.3 [ ] Orks
|
||||
6.2.4 [ ] Daemonen
|
||||
6.2.5 [ ] Elfen
|
||||
6.2.6 [ ] Meermenschen
|
||||
6.2.7 [ ] Menschen
|
||||
6.2.8 [ ] Zwerge
|
||||
6.2.9 [ ] Katzen
|
||||
6.2.10 [ ] Insekten
|
||||
6.2.11 [ ] Halblinge
|
||||
|
||||
|
||||
7. Wenn du noch etwas loswerden willst, Kritik, Anregungen, Kommentare
|
||||
aller Art, dann kannst Du das hier tun:
|
||||
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
sed -e 's/^ *[Ll][Ee][rR].*[Ss][Cc][Hh][Ww].*$/LERNE HIEBWAFFEN/g' | \
|
||||
sed -e 's/^ *[Ll][Ee][rR].*[Ss][Pp].*$/LERNE STANGENWAFFEN/g' | \
|
||||
sed -e 's/^ *[Ss][Ee][Nn][Dd][Ee] /OPTION /g'
|
||||
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
use Getopt::Std;
|
||||
|
||||
sub output_file {
|
||||
my $file = shift(@_);
|
||||
|
||||
foreach $dir (@searchpath) {
|
||||
$absname = $dir."/".$file;
|
||||
if ( -r $absname ) {
|
||||
system "cat $absname";
|
||||
last;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getopt('I');
|
||||
@searchpath = split(/:/,$opt_I);
|
||||
|
||||
while(<STDIN>) {
|
||||
$line = $_;
|
||||
|
||||
if( $line =~ /^\s*#include\s+\"(.*)\"/ ) {
|
||||
$file = $1;
|
||||
if(not ($file =~ /\.\./ or $file =~ /^\//) or $file =~ /;/) {
|
||||
output_file($file);
|
||||
}
|
||||
} else if ( $line =~ /^\s*#perl\s+\"(.*)\"/ ) {
|
||||
$script = $1;
|
||||
do $script;
|
||||
} else {
|
||||
print $line;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
|
||||
Dies ist eine sichere Implementation der #include - Funktionalität
|
||||
der C-Präprozessors. Er läßt keine absoluten Pfade oder .. in den
|
||||
Filenamen zu, und durchsucht nur die mit -I angegebenen Directories.
|
||||
|
|
@ -1,246 +0,0 @@
|
|||
/* vi: set ts=2:
|
||||
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
| | Enno Rehling <enno@eressea-pbem.de>
|
||||
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
|
||||
| (c) 1998 - 2001 | 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.
|
||||
*/
|
||||
#include <config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static struct vartype {
|
||||
const char * name;
|
||||
const char * type;
|
||||
const char * msg;
|
||||
} vartype[] = {
|
||||
{ "from", "unit", "donation"},
|
||||
{ "to", "unit", "donation" },
|
||||
|
||||
/* strange and to be changed */
|
||||
{ "destruction", "int", "siege" },
|
||||
{ "mode", "int", "travel" },
|
||||
{ "discover", "string", "givedumb" },
|
||||
{ "receipient", "unit", "givecommand" },
|
||||
{ "sink", "string", "entermaelstrom" },
|
||||
{ "sink", "string", "storm" },
|
||||
{ "using", "resource", "errusingpotion" },
|
||||
{ "type", "string", "scunicorn" },
|
||||
{ "special", "string", "new_fspecial" },
|
||||
{ "special", "string", "new_fspecial_level" },
|
||||
|
||||
/* broadband */
|
||||
|
||||
{ "regions", "string" },
|
||||
{ "succ", "string" },
|
||||
{ "renamed", "string" },
|
||||
{ "reason", "string" },
|
||||
{ "message", "string" },
|
||||
{ "value", "string" },
|
||||
{ "error", "string" },
|
||||
{ "string", "string" },
|
||||
{ "command", "string" },
|
||||
{ "spell", "string" }, /* ? */
|
||||
|
||||
{ "building", "building" },
|
||||
|
||||
{ "ship", "ship" },
|
||||
|
||||
{ "resource", "resource" },
|
||||
{ "potion", "resource" },
|
||||
{ "item", "resource" },
|
||||
{ "herb", "resource" },
|
||||
|
||||
{ "teacher", "unit" },
|
||||
{ "student", "unit" },
|
||||
{ "unit", "unit" },
|
||||
{ "renamer", "unit" },
|
||||
{ "spy", "unit" },
|
||||
{ "mage", "unit" },
|
||||
{ "opfer", "unit" },
|
||||
{ "target", "unit" },
|
||||
{ "recipient", "unit" },
|
||||
{ "follower", "unit" },
|
||||
|
||||
{ "skill", "skill" },
|
||||
|
||||
{ "faction", "faction" },
|
||||
|
||||
{ "region", "region" },
|
||||
{ "source", "region" },
|
||||
{ "regionn", "region" },
|
||||
{ "regionv", "region" },
|
||||
{ "end", "region" },
|
||||
{ "start", "region" },
|
||||
{ "runto", "region" },
|
||||
{ "to", "region" },
|
||||
{ "from", "region" },
|
||||
|
||||
{ "kills", "int" },
|
||||
{ "fallen", "int" },
|
||||
{ "amount", "int" },
|
||||
{ "aura", "int" },
|
||||
{ "months", "int" },
|
||||
{ "wanted", "int" },
|
||||
{ "money", "int" },
|
||||
{ "dead", "int" },
|
||||
{ "level", "int" },
|
||||
{ "days", "int" },
|
||||
{ "damage", "int" },
|
||||
{ "cost", "int" },
|
||||
{ "want", "int" },
|
||||
{ "size", "int" },
|
||||
{ "alive", "int" },
|
||||
{ "run", "int" },
|
||||
{ "hits", "int" },
|
||||
{ "turns", "int" },
|
||||
|
||||
{ "race", "race" },
|
||||
|
||||
{ "direction", "direction" },
|
||||
{ "dir", "direction" },
|
||||
|
||||
{ "id", "int" },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
static const char *
|
||||
type(const char * name,const char * msg)
|
||||
{
|
||||
int i = 0;
|
||||
while (vartype[i].name) {
|
||||
if (strcmp(name, vartype[i].name)==0 &&
|
||||
(vartype[i].msg==NULL || strcmp(vartype[i].msg, msg)==0)) {
|
||||
return vartype[i].type;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
fprintf(stderr, "unknown type for \"%s\" in message \"%s\".\n", name, msg);
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
static void
|
||||
parse_message(char * b, FILE * ostream)
|
||||
{
|
||||
const char * vtype;
|
||||
char *m, *a = NULL, message[8192];
|
||||
char * name;
|
||||
char * language;
|
||||
char * section = NULL;
|
||||
int i, level = 0;
|
||||
char * args[16];
|
||||
boolean f_symbol = false;
|
||||
|
||||
/* skip comments */
|
||||
if (b[0]=='#' || b[0]==0) return;
|
||||
|
||||
/* the name of this type */
|
||||
name = b;
|
||||
while (*b && *b!=';') ++b;
|
||||
if (!*b) return;
|
||||
*b++ = 0;
|
||||
|
||||
/* the section for this type */
|
||||
section = b;
|
||||
while (*b && *b!=';' && *b!=':') ++b;
|
||||
if (!strcmp(section, "none")) section=NULL;
|
||||
|
||||
/* if available, the level for this type */
|
||||
if (*b==':') {
|
||||
char * x;
|
||||
*b++ = 0;
|
||||
x = b;
|
||||
while (*b && *b!=';') ++b;
|
||||
level=atoi(x);
|
||||
}
|
||||
*b++ = 0;
|
||||
|
||||
/* the locale */
|
||||
language = b;
|
||||
while (*b && *b!=';') ++b;
|
||||
*b++ = 0;
|
||||
|
||||
/* parse the message */
|
||||
i = 0;
|
||||
m = message;
|
||||
*m++='\"';
|
||||
while (*b) {
|
||||
switch (*b) {
|
||||
case '{':
|
||||
f_symbol = true;
|
||||
a = ++b;
|
||||
break;
|
||||
case '}':
|
||||
*b++ = '\0';
|
||||
args[i] = strdup(a);
|
||||
vtype = type(args[i], name);
|
||||
if (strcmp(vtype, "string")==0) {
|
||||
sprintf(m, "$%s", args[i]);
|
||||
} else {
|
||||
sprintf(m, "$%s($%s)", vtype, args[i]);
|
||||
}
|
||||
m+=strlen(m);
|
||||
i++;
|
||||
f_symbol = false;
|
||||
break;
|
||||
case ' ':
|
||||
if (f_symbol) {
|
||||
a = ++b;
|
||||
break;
|
||||
}
|
||||
/* fall-through intended */
|
||||
default:
|
||||
if (!f_symbol) {
|
||||
*m++ = *b++;
|
||||
} else b++;
|
||||
}
|
||||
}
|
||||
strcpy(m, "\"");
|
||||
args[i] = NULL;
|
||||
|
||||
/* add the messagetype */
|
||||
fprintf(ostream, "<message name=\"%s\">\n", name);
|
||||
fputs("\t<type>\n", ostream);
|
||||
for (i=0;args[i];++i) {
|
||||
fprintf(ostream, "\t\t<arg name=\"%s\" type=\"%s\"></arg>\n", args[i], type(args[i], name));
|
||||
}
|
||||
fputs("\t</type>\n", ostream);
|
||||
fprintf(ostream, "\t<locale name=\"%s\">\n", language);
|
||||
fprintf(ostream, "\t\t<nr section=\"%s\">\n",
|
||||
section);
|
||||
fprintf(ostream, "\t\t\t<text>%s</text>\n", message);
|
||||
fputs("\t\t</nr>\n", ostream);
|
||||
fputs("\t</locale>\n", ostream);
|
||||
fputs("</message>\n\n", ostream);
|
||||
}
|
||||
|
||||
void
|
||||
read_messages(FILE * istream, FILE * ostream)
|
||||
{
|
||||
char buf[8192];
|
||||
fputs("<messages>\n", ostream);
|
||||
while (fgets(buf, sizeof(buf), istream)) {
|
||||
buf[strlen(buf)-1] = 0; /* \n weg */
|
||||
parse_message(buf, ostream);
|
||||
}
|
||||
fputs("</messages>\n", ostream);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
FILE * istream = stdin;
|
||||
FILE * ostream = stdout;
|
||||
int nretval = -1;
|
||||
if (argc>1) istream = fopen(argv[1], "rt+");
|
||||
if (argc>2) ostream = fopen(argv[2], "wt+");
|
||||
if (istream && ostream) {
|
||||
read_messages(istream, ostream);
|
||||
}
|
||||
return nretval;
|
||||
}
|
|
@ -1,119 +0,0 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
from Stack import *
|
||||
|
||||
class Node:
|
||||
def __init__(self, obj):
|
||||
self.obj = obj
|
||||
self.marker = 0
|
||||
|
||||
class Vertex:
|
||||
def __init__(self, node1, node2):
|
||||
self.nodes = (node1, node2)
|
||||
self.marker = 0
|
||||
|
||||
class Graph:
|
||||
|
||||
def __init__(self):
|
||||
self.nodes = []
|
||||
self.vertices = []
|
||||
|
||||
def remove_node(self, node):
|
||||
self.nodes.remove(node)
|
||||
for v in self.vertices:
|
||||
if v.nodes[0] == node or v.nodes[1] == node:
|
||||
self.vertices.remove(v)
|
||||
|
||||
def find_node(self, obj):
|
||||
for n in self.nodes:
|
||||
if n.obj == obj:
|
||||
return n
|
||||
|
||||
return None
|
||||
|
||||
def neighbours(self, node):
|
||||
n = []
|
||||
for v in self.vertices:
|
||||
if v.nodes[0] == node and v.nodes[1] not in n:
|
||||
n.append(v.nodes[1])
|
||||
elif v.nodes[1] == node and v.nodes[0] not in n:
|
||||
n.append(v.nodes[0])
|
||||
|
||||
return n
|
||||
|
||||
def reset_marker(self):
|
||||
for n in self.nodes:
|
||||
n.marker = 0
|
||||
for v in self.vertices:
|
||||
v.marker = 0
|
||||
|
||||
def dsearch(self,node):
|
||||
reset_marker()
|
||||
dg = [node]
|
||||
s = Stack()
|
||||
node.marker = 1
|
||||
s.push(node)
|
||||
while not s.empty():
|
||||
n = s.pop()
|
||||
for nb in self.neighbours(n):
|
||||
if nb.marker == 0:
|
||||
nb.marker = 1
|
||||
dg.append(nb)
|
||||
s.push(nb)
|
||||
return dg
|
||||
|
||||
def dgraphs(self):
|
||||
rl = []
|
||||
nodelist = self.nodes[:]
|
||||
while nodelist != []:
|
||||
start = nodelist.pop()
|
||||
self.reset_marker()
|
||||
g = Graph()
|
||||
g.nodes.append(start)
|
||||
start.marker = 1
|
||||
s = Stack()
|
||||
s.push(start)
|
||||
while not s.empty():
|
||||
tnode = s.pop()
|
||||
for nb in self.neighbours(tnode):
|
||||
if nb.marker == 0:
|
||||
nb.marker = 1
|
||||
g.nodes.append(nb)
|
||||
nodelist.remove(nb)
|
||||
s.push(nb)
|
||||
|
||||
for v in self.vertices:
|
||||
if v.nodes[0] in g.nodes:
|
||||
g.vertices.append(v)
|
||||
|
||||
rl.append(g)
|
||||
|
||||
return rl
|
||||
|
||||
# g = Graph()
|
||||
|
||||
# n1 = Node(1)
|
||||
# n2 = Node(2)
|
||||
# n3 = Node(3)
|
||||
# n4 = Node(4)
|
||||
# n5 = Node(5)
|
||||
# n6 = Node(6)
|
||||
|
||||
# g.nodes.append(n1)
|
||||
# g.nodes.append(n2)
|
||||
# g.nodes.append(n3)
|
||||
# g.nodes.append(n4)
|
||||
# g.nodes.append(n5)
|
||||
# g.nodes.append(n6)
|
||||
|
||||
# g.vertices.append(Vertex(n1,n2))
|
||||
# g.vertices.append(Vertex(n1,n4))
|
||||
# g.vertices.append(Vertex(n2,n6))
|
||||
|
||||
# for dg in g.dgraphs():
|
||||
# for e in dg:
|
||||
# print e.obj,
|
||||
# print
|
||||
|
||||
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
class Stack:
|
||||
def __init__(self):
|
||||
self.data = []
|
||||
|
||||
def push(self, obj):
|
||||
self.data.append(obj)
|
||||
|
||||
def pop(self):
|
||||
return self.data.pop()
|
||||
|
||||
def empty(self):
|
||||
if self.data == []:
|
||||
return 1
|
||||
return 0
|
||||
|
|
@ -1,145 +0,0 @@
|
|||
#!/usr/bin/python
|
||||
# vi:set ts=4:
|
||||
|
||||
# Algorithmus zur Berechnung von regionsübergreifenden Schlachten.
|
||||
# Testprogramm.
|
||||
|
||||
# 1) Graph aufbauen aus alle Attackierern und allen direkt attackierten
|
||||
|
||||
# 2) Helfer in den Graphen aufnehmen
|
||||
|
||||
# 3) Disjunkte Teilgraphen ermitteln
|
||||
|
||||
# 4) Innerhalb der Teilgraphen die 'Wer-schlägt-wen-Beziehung' aufbauen
|
||||
|
||||
import re
|
||||
from Graph import *
|
||||
|
||||
class heer:
|
||||
def __init__(self, rx, ry, f, p, o):
|
||||
self.rx = rx
|
||||
self.ry = ry
|
||||
self.f = f
|
||||
self.part = p
|
||||
self.o = o
|
||||
self.attacked = []
|
||||
|
||||
def toString(self):
|
||||
return "("+self.f+"/"+str(self.part)+","+str(self.rx)+","+str(self.ry)+")"
|
||||
|
||||
|
||||
def dist(x1, y1, x2, y2):
|
||||
dx = x1 - x2
|
||||
dy = y1 - y2
|
||||
if dy < 0:
|
||||
dy = -dy
|
||||
dx = -dx
|
||||
if dx >= 0:
|
||||
return dx + dy;
|
||||
if -dx >= dy:
|
||||
return -dx
|
||||
return dy
|
||||
|
||||
|
||||
def is_neighbour(h, r1, r2):
|
||||
x1 = r1[0]
|
||||
y1 = r1[1]
|
||||
x2 = r2[0]
|
||||
y2 = r2[1]
|
||||
|
||||
if dist(h.rx, h.ry, x1, y1) <= 1 and dist(h.rx, h.ry, x2, y2) <= 1:
|
||||
return 1
|
||||
|
||||
return 0
|
||||
|
||||
heere = [
|
||||
Node(heer(0,0, 'A', 1, 'A->B:-1,1')),
|
||||
Node(heer(0,0, 'A', 2, 'A->B:0,1')),
|
||||
Node(heer(-1,1, 'B', 1, '')),
|
||||
Node(heer(1,-1, 'B', 1, '')),
|
||||
Node(heer(0,1, 'B', 1, ''))
|
||||
]
|
||||
|
||||
def find_heer_node(x, y, f):
|
||||
for node in heere:
|
||||
h = node.obj
|
||||
if h.rx == x and h.ry == y and h.f == f:
|
||||
return node
|
||||
return None
|
||||
|
||||
def allied(f1, f2):
|
||||
if f1 == f2:
|
||||
return 1
|
||||
return 0
|
||||
|
||||
g1 = Graph()
|
||||
|
||||
a_re = re.compile('A->(\w):(-?\d+),(-?\d+)')
|
||||
l_re = re.compile('L->(\w)')
|
||||
|
||||
# Schritt 1
|
||||
|
||||
for node in heere:
|
||||
f = ''
|
||||
h = node.obj
|
||||
|
||||
mo = a_re.match(h.o)
|
||||
if mo != None:
|
||||
f = mo.group(1)
|
||||
x = int(mo.group(2))
|
||||
y = int(mo.group(3))
|
||||
|
||||
mo = l_re.match(h.o)
|
||||
if mo != None:
|
||||
f = mo.group(1)
|
||||
x = h.rx
|
||||
y = h.ry
|
||||
|
||||
if f != '':
|
||||
tnode = find_heer_node(x,y,f)
|
||||
if node not in g1.nodes:
|
||||
g1.nodes.append(node)
|
||||
if tnode not in g1.nodes:
|
||||
g1.nodes.append(tnode)
|
||||
g1.vertices.append(Vertex(node,tnode))
|
||||
tnode.obj.attacked.append((x,y,node))
|
||||
|
||||
# Schritt 2
|
||||
|
||||
for node1 in g1.nodes:
|
||||
heer1 = node1.obj
|
||||
for attack in heer1.attacked:
|
||||
attacker_node = attack[2]
|
||||
for node2 in heere:
|
||||
heer2 = node2.obj
|
||||
# heer 1 ist der angegriffene
|
||||
# heer 2 der potentielle Helfer
|
||||
if heer1 != heer2 and allied(heer1.f,heer2.f) and not allied(heer2.f, attacker_node.obj.f):
|
||||
if is_neighbour(heer2, (heer1.rx, heer1.ry), attack):
|
||||
if node2 not in g1.nodes:
|
||||
g1.nodes.append(node2)
|
||||
g1.vertices.append(Vertex(attacker_node,node2))
|
||||
|
||||
# Schritt 3
|
||||
|
||||
battles = g1.dgraphs()
|
||||
|
||||
count = 1
|
||||
|
||||
for battle in battles:
|
||||
print "Schlacht "+str(count),
|
||||
count = count + 1
|
||||
for node in battle.nodes:
|
||||
heer = node.obj
|
||||
print heer.toString()+",",
|
||||
print
|
||||
|
||||
# Schritt 4
|
||||
|
||||
for node in battle.nodes:
|
||||
heer = node.obj
|
||||
print "\tHeer "+str(heer.toString())+" attackiert gegen",
|
||||
for enemy in battle.neighbours(node):
|
||||
print str(enemy.obj.toString())+",",
|
||||
print
|
||||
|
|
@ -1,178 +0,0 @@
|
|||
/* vi: set ts=2:
|
||||
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
| | Enno Rehling <enno@eressea-pbem.de>
|
||||
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
|
||||
| (c) 1998 - 2001 | 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.
|
||||
*/
|
||||
#include <config.h>
|
||||
#include <kernel/eressea.h>
|
||||
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/unit.h>
|
||||
#include <kernel/save.h>
|
||||
|
||||
#include <util/base36.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <locale.h>
|
||||
|
||||
static char * orderfile = NULL;
|
||||
|
||||
static void mark_region(region * r, boolean mark)
|
||||
{
|
||||
if (!r) return;
|
||||
if (mark) fset(r, FL_MARK);
|
||||
else freset(r, FL_MARK);
|
||||
}
|
||||
|
||||
static void
|
||||
markup(FILE * in)
|
||||
{
|
||||
char command[16];
|
||||
char choice[16];
|
||||
int x, y;
|
||||
region * r;
|
||||
boolean mark;
|
||||
|
||||
while (!feof(in)) {
|
||||
fscanf(in, "%s %s", choice, command);
|
||||
if (choice[0]=='#') {
|
||||
fgets(buf, sizeof(buf), in);
|
||||
continue;
|
||||
}
|
||||
if (choice[0]=='e') return; /* end */
|
||||
if (choice[0]=='o') {
|
||||
orderfile = strdup(command);
|
||||
readorders(orderfile);
|
||||
continue;
|
||||
}
|
||||
mark = (choice[0]=='a'); /* add/del */
|
||||
switch (command[0]) {
|
||||
case 'r':
|
||||
if (!strcmp(command, "region")) {
|
||||
fscanf(in, "%d %d", &x, &y);
|
||||
r = findregion(x, y);
|
||||
if (r==NULL)
|
||||
printf("region %d,%d not found\n", x, y);
|
||||
else mark_region(r, mark);
|
||||
}
|
||||
break;
|
||||
case 'a':
|
||||
if (!strcmp(command, "area")) {
|
||||
int radius;
|
||||
fscanf(in, "%d %d %d", &x, &y, &radius);
|
||||
for (r=regions;r!=NULL;r=r->next) {
|
||||
if (koor_distance(x, y, r->x, r->y)<=radius)
|
||||
mark_region(r, mark);
|
||||
}
|
||||
} else if (!strcmp(command, "all")) {
|
||||
for (r==regions;r!=NULL;r=r->next) {
|
||||
mark_region(r, mark);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
reduce(void)
|
||||
{
|
||||
faction * f;
|
||||
region ** rp = ®ions;
|
||||
/* let's leak regions, big time. */
|
||||
for (f=factions;f;f=f->next) f->alive=0;
|
||||
while (*rp) {
|
||||
region * r = *rp;
|
||||
if (fval(r, FL_MARK)) {
|
||||
unit * u;
|
||||
for (u=r->units;u;u=u->next) u->faction->alive=1;
|
||||
rp=&r->next;
|
||||
}
|
||||
else *rp = r->next;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
usage(void)
|
||||
{
|
||||
fputs("usage: reduce [infile]\n", stderr);
|
||||
fputs("\ninput file syntax:\n"
|
||||
"\torders orderfile\n"
|
||||
"\tadd all\n"
|
||||
"\tadd region x y\n"
|
||||
"\tadd area x y r\n"
|
||||
"\tdel all\n"
|
||||
"\tdel region x y\n"
|
||||
"\tdel area x y r\n"
|
||||
"\tend\n", stderr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void
|
||||
writeorders(const char * orderfile)
|
||||
{
|
||||
FILE * F = fopen(orderfile, "wt");
|
||||
faction * f;
|
||||
if (F==NULL) return;
|
||||
|
||||
/* let's leak regions, big time. */
|
||||
for (f=factions;f;f=f->next) {
|
||||
region * r;
|
||||
if (f->alive==0) continue;
|
||||
fprintf(F, "PARTEI %s \"%s\"\n", itoa36(f->no), f->passw);
|
||||
for (r=regions;r;r=r->next) {
|
||||
if (fval(r, FL_MARK)) {
|
||||
unit * u;
|
||||
for (u=r->units;u;u=u->next) {
|
||||
strlist * o;
|
||||
fprintf(F, "EINHEIT %s\n", itoa36(u->no));
|
||||
for (o=u->orders;o;o=o->next) {
|
||||
fputs(o->s, F);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose(F);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char ** argv)
|
||||
{
|
||||
char * datadir = "data";
|
||||
char outfile[64];
|
||||
FILE * in = stdin;
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
|
||||
if (argc>1) {
|
||||
in = fopen(argv[1], "rt+");
|
||||
if (in==NULL) return usage();
|
||||
}
|
||||
|
||||
kernel_init();
|
||||
readgame(false);
|
||||
|
||||
markup(in);
|
||||
reduce();
|
||||
|
||||
remove_empty_factions();
|
||||
sprintf(outfile, "%s.cut", orderfile);
|
||||
if (orderfile) {
|
||||
writeorders(orderfile);
|
||||
}
|
||||
sprintf(outfile, "%s/%d.cut", datadir, turn);
|
||||
writegame(outfile, 0);
|
||||
|
||||
if (in!=stdin) fclose(in);
|
||||
return 0;
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
# we want this region:
|
||||
add region 1023 999
|
||||
# everything within 2 of (985,1035):
|
||||
add area 985 1035 2
|
||||
# but not the center itself:
|
||||
del region 985 1035
|
||||
# that's all folks.
|
||||
end
|
||||
# will not be executed:
|
||||
del all
|
|
@ -1,23 +0,0 @@
|
|||
#!/usr/bin/perl
|
||||
# vi:set ts=2:
|
||||
|
||||
$errorcount = 0;
|
||||
$linecount = 0;
|
||||
|
||||
while(<>) {
|
||||
$line = $_;
|
||||
|
||||
$linecount++;
|
||||
|
||||
if($line !~ /^\s*#/ && $line !~ /^\s*$/ && $line !~ /^\w+;(events|magic|errors|study|economy|battle|movement|production):[012345];(de|en);.+/) {
|
||||
print "syntax error in line $linecount: $line\n";
|
||||
$errorcount++;
|
||||
}
|
||||
}
|
||||
|
||||
if($errorcount > 0) {
|
||||
print "$errorcount errors found.\n";
|
||||
} else {
|
||||
print "No errors found.\n";
|
||||
}
|
||||
|
|
@ -1,284 +0,0 @@
|
|||
/* vi: set ts=2:
|
||||
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
| | Enno Rehling <enno@eressea-pbem.de>
|
||||
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
|
||||
| (c) 1998 - 2001 | 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.
|
||||
*/
|
||||
#include <config.h>
|
||||
|
||||
#include <message.h>
|
||||
#include <crmessage.h>
|
||||
#include <nrmessage.h>
|
||||
#include <translation.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static const char * sample = "\"enno and $if($eq($i,0),\"nobody else\",$if($eq($i,1),\"another guy\",\"$int($i) other people\")).\"";
|
||||
|
||||
void
|
||||
test_translation(void)
|
||||
{
|
||||
int x;
|
||||
const char * c;
|
||||
|
||||
c = translate_va("\"$name is a godlike $role.\"", "name role", "enno", "coder");
|
||||
if (c) puts(c);
|
||||
|
||||
for (x=0;x!=4;++x) {
|
||||
c = translate_va(sample, "i", x);
|
||||
if (c) puts(c);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
test_message(void)
|
||||
{
|
||||
char buffer[1024];
|
||||
struct message_type * mt_example = mt_new_va("example", "subject:string", "number:int", "object:string", NULL);
|
||||
message * msg = msg_create_va(mt_example, "enno", (void*)7, "autos");
|
||||
|
||||
tsf_register("string", &cr_string);
|
||||
tsf_register("int", &cr_int);
|
||||
|
||||
crt_register(mt_example);
|
||||
nrt_register(mt_example, NULL, "\"$subject hat $int($number) $object\"", 0, "default");
|
||||
cr_render(msg, buffer);
|
||||
puts(buffer);
|
||||
nr_render(msg, NULL, buffer);
|
||||
puts(buffer);
|
||||
}
|
||||
|
||||
#include <string.h>
|
||||
#include <util/language.h>
|
||||
|
||||
message *
|
||||
new_message(struct faction * receiver, const char* sig, ...)
|
||||
/* compatibility function, to keep the old function calls valid *
|
||||
* all old messagetypes are converted into a message with ONLY string parameters,
|
||||
* this function will convert given parameters to a string representation
|
||||
* based on the signature - like render() once did */
|
||||
{
|
||||
const message_type * mtype;
|
||||
va_list marker;
|
||||
const char * signature = strchr(sig, '%');
|
||||
char buffer[128];
|
||||
int i=0;
|
||||
const char * c = sig;
|
||||
const char * args[16];
|
||||
|
||||
strncpy(buffer, sig, signature-sig);
|
||||
buffer[signature-sig] = '\0';
|
||||
mtype = mt_find(buffer);
|
||||
|
||||
if (!mtype) {
|
||||
fprintf(stderr, "trying to create message of unknown type \"%s\"\n", buffer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
while(*c!='%') buffer[i++] = *(c++);
|
||||
buffer[i] = 0;
|
||||
|
||||
va_start(marker, sig);
|
||||
while (*c) {
|
||||
char type;
|
||||
char *p = buffer;
|
||||
assert(*c=='%');
|
||||
type = *(++c);
|
||||
/*
|
||||
case 'f': (*ep)->type = IT_FACTION; break;
|
||||
case 'u': (*ep)->type = IT_UNIT; break;
|
||||
case 'r': (*ep)->type = IT_REGION; break;
|
||||
case 'h': (*ep)->type = IT_SHIP; break;
|
||||
case 'b': (*ep)->type = IT_BUILDING; break;
|
||||
case 'X': (*ep)->type = IT_RESOURCETYPE; break;
|
||||
case 'x': (*ep)->type = IT_RESOURCE; break;
|
||||
case 't': (*ep)->type = IT_SKILL; break;
|
||||
case 's': (*ep)->type = IT_STRING; break;
|
||||
case 'i': (*ep)->type = IT_INT; break;
|
||||
case 'd': (*ep)->type = IT_DIRECTION; break;
|
||||
case 'S': (*ep)->type = IT_FSPECIAL; break;
|
||||
*/
|
||||
c+=2;
|
||||
while (*c && isalnum(*(unsigned char*)c)) *(p++) = *(c++);
|
||||
*p = '\0';
|
||||
for (i=0;i!=mtype->nparameters;++i) {
|
||||
if (!strcmp(buffer, mtype->pnames[i])) break;
|
||||
}
|
||||
assert(i!=mtype->nparameters || !"unknown parameter");
|
||||
|
||||
switch(type) {
|
||||
case 's':
|
||||
args[i] = va_arg(marker, const char *);
|
||||
break;
|
||||
case 'i':
|
||||
itoa(va_arg(marker, int), buffer, sizeof(buffer));
|
||||
args[i] = strdup(buffer);
|
||||
break;
|
||||
#ifdef ERESSEA_KERNEL
|
||||
case 'f':
|
||||
args[i] = factionname(va_arg(marker, const struct faction*));
|
||||
break;
|
||||
case 'u':
|
||||
args[i] = unitname(va_arg(marker, const struct unit*));
|
||||
break;
|
||||
case 'r':
|
||||
args[i] = rname(va_arg(marker, const struct region*), receiver->lang);
|
||||
break;
|
||||
case 'h':
|
||||
args[i] = shipname(va_arg(marker, const struct ship*));
|
||||
break;
|
||||
case 'b':
|
||||
args[i] = buildingname(va_arg(marker, const struct ship*));
|
||||
break;
|
||||
case 'X':
|
||||
args[i] = resourcename(va_arg(marker, const resource_type *), 0);
|
||||
break;
|
||||
case 'x':
|
||||
args[i] = resourcename(oldresourcetype[(resource_t)va_arg(marker, resource_t)], 0);
|
||||
break;
|
||||
case 't':
|
||||
args[i] = skillname(va_arg(marker, skill_t), NULL);
|
||||
break;
|
||||
case 'd':
|
||||
args[i] = directions[i];
|
||||
break;
|
||||
case 'S':
|
||||
#endif
|
||||
default:
|
||||
args[i] = NULL;
|
||||
}
|
||||
}
|
||||
return msg_create(mtype, args);
|
||||
}
|
||||
|
||||
static void
|
||||
parse_message(char * b)
|
||||
{
|
||||
char *m, *a, message[8192];
|
||||
char * name;
|
||||
char * language;
|
||||
struct locale * lang;
|
||||
char * section = NULL;
|
||||
int i, level = 0;
|
||||
char * args[16];
|
||||
boolean f_symbol = false;
|
||||
const struct message_type * mtype;
|
||||
|
||||
/* skip comments */
|
||||
if (b[0]=='#' || b[0]==0) return;
|
||||
|
||||
/* the name of this type */
|
||||
name = b;
|
||||
while (*b && *b!=';') ++b;
|
||||
if (!*b) return;
|
||||
*b++ = 0;
|
||||
|
||||
/* the section for this type */
|
||||
section = b;
|
||||
while (*b && *b!=';' && *b!=':') ++b;
|
||||
if (!strcmp(section, "none")) section=NULL;
|
||||
|
||||
/* if available, the level for this type */
|
||||
if (*b==':') {
|
||||
char * x;
|
||||
*b++ = 0;
|
||||
x = b;
|
||||
while (*b && *b!=';') ++b;
|
||||
level=atoi(x);
|
||||
}
|
||||
*b++ = 0;
|
||||
|
||||
/* the locale */
|
||||
language = b;
|
||||
while (*b && *b!=';') ++b;
|
||||
*b++ = 0;
|
||||
lang = find_locale(language);
|
||||
if (!lang) lang = make_locale(language);
|
||||
|
||||
/* parse the message */
|
||||
i = 0;
|
||||
m = message;
|
||||
*m++='\"';
|
||||
while (*b) {
|
||||
switch (*b) {
|
||||
case '{':
|
||||
f_symbol = true;
|
||||
a = ++b;
|
||||
break;
|
||||
case '}':
|
||||
*b++ = '\0';
|
||||
args[i] = strdup(a);
|
||||
sprintf(m, "$%s", args[i]);
|
||||
m+=strlen(m);
|
||||
i++;
|
||||
f_symbol = false;
|
||||
break;
|
||||
case ' ':
|
||||
if (f_symbol) {
|
||||
a = ++b;
|
||||
break;
|
||||
}
|
||||
/* fall-through intended */
|
||||
default:
|
||||
if (!f_symbol) {
|
||||
*m++ = *b++;
|
||||
} else b++;
|
||||
}
|
||||
}
|
||||
strcpy(m, "\"");
|
||||
args[i] = NULL;
|
||||
|
||||
/* add the messagetype */
|
||||
mtype = mt_register(mt_new(name, args));
|
||||
nrt_register(mtype, lang, message, 0, "default");
|
||||
crt_register(mtype);
|
||||
}
|
||||
|
||||
static void
|
||||
read_messages(FILE * F)
|
||||
{
|
||||
char buf[8192];
|
||||
while (fgets(buf, sizeof(buf), F)) {
|
||||
buf[strlen(buf)-1] = 0; /* \n weg */
|
||||
parse_message(buf);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_compat()
|
||||
{
|
||||
char buffer[1024];
|
||||
FILE * F = fopen("res/de/messages.txt", "rt");
|
||||
message * msg;
|
||||
if (F) {
|
||||
read_messages(F);
|
||||
fclose(F);
|
||||
msg = new_message(NULL, "entrise%s:region", "Porzel (8,7)");
|
||||
if (cr_render(msg, buffer)==0) puts(buffer);
|
||||
if (nr_render(msg, NULL, buffer)==0) puts(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char**argv)
|
||||
{
|
||||
translation_init();
|
||||
|
||||
test_message();
|
||||
test_translation();
|
||||
test_compat();
|
||||
|
||||
translation_done();
|
||||
return 0;
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
/* vi: set ts=2:
|
||||
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
| | Enno Rehling <enno@eressea-pbem.de>
|
||||
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
|
||||
| (c) 1998 - 2001 | 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.
|
||||
*/
|
||||
#include <config.h>
|
||||
#include <xml.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static int
|
||||
cbplaintext(const struct xml_stack * stack, const char * c)
|
||||
{
|
||||
puts(c);
|
||||
fflush(stdout);
|
||||
return XML_OK;
|
||||
}
|
||||
|
||||
static int
|
||||
cbtagend(const struct xml_stack * stack)
|
||||
{
|
||||
xml_tag * tag = stack->tag;
|
||||
printf("</%s>\n", tag->name);
|
||||
fflush(stdout);
|
||||
return XML_OK;
|
||||
}
|
||||
|
||||
static int
|
||||
cbtagbegin(const struct xml_stack * stack)
|
||||
{
|
||||
xml_tag * tag = stack->tag;
|
||||
xml_attrib * xa= tag->attribs;
|
||||
printf("<%s", tag->name);
|
||||
while (xa) {
|
||||
printf(" %s=\"%s\"", xa->name, xa->value);
|
||||
xa = xa->next;
|
||||
}
|
||||
printf(">\n");
|
||||
fflush(stdout);
|
||||
return XML_OK;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
FILE * istream = stdin;
|
||||
int nretval = -1;
|
||||
if (argc>1) istream = fopen(argv[1], "rt+");
|
||||
if (istream) {
|
||||
xml_callbacks xml_cb = { NULL };
|
||||
xml_cb.plaintext = cbplaintext;
|
||||
xml_cb.tagbegin = cbtagbegin;
|
||||
|
||||
nretval = xml_parse(istream, &xml_cb, NULL);
|
||||
if (istream!=stdin) fclose(istream);
|
||||
if (ostream!=stdout) fclose(ostream);
|
||||
}
|
||||
return nretval;
|
||||
}
|
Loading…
Add table
Reference in a new issue