diff --git a/.gitignore b/.gitignore index f16be6bc9..98396d6f2 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ Release/ *.opensdf *.ipch *.sh +*.tmp src/*.vcproj.*.user tags build-vs2010 diff --git a/scripts/default.lua b/scripts/default.lua old mode 100644 new mode 100755 index 9b5e4c8a6..6d22b4f32 --- a/scripts/default.lua +++ b/scripts/default.lua @@ -26,7 +26,7 @@ function nmr_check(maxnmrs) if nmrs >= maxnmrs then print("Shit. More than " .. maxnmrs .. " factions with 1 NMR (" .. nmrs .. ")") write_summary() - write_game("aborted.dat") + eressea.write_game("aborted.dat") return -1 end print (nmrs .. " Factions with 1 NMR") @@ -35,10 +35,7 @@ end function open_game(turn) file = "" .. get_turn() - if read_game(file .. ".dat", "binary")~=0 then - return read_game(file, "text") - end - return 0 + return eressea.read_game(file .. ".dat") end function write_emails(locales) diff --git a/scripts/init.lua b/scripts/init.lua old mode 100644 new mode 100755 index ae39c50b2..bafa3da63 --- a/scripts/init.lua +++ b/scripts/init.lua @@ -8,7 +8,7 @@ function run_editor() turn = read_turn() set_turn(turn) end - read_game(turn .. ".dat") + eressea.read_game(turn .. ".dat") gmtool.editor() end diff --git a/scripts/tests/attrib.lua b/scripts/tests/attrib.lua old mode 100644 new mode 100755 index b86efa734..73d961d94 --- a/scripts/tests/attrib.lua +++ b/scripts/tests/attrib.lua @@ -11,9 +11,9 @@ end function test_attrib_global() a = attrib.create('global', {}) - write_game('attrib.dat') - free_game() - read_game('attrib.dat') + eressea.write_game('attrib.dat') + eressea.free_game() + eressea.read_game('attrib.dat') end function test_attrib() @@ -30,9 +30,9 @@ function test_attrib() a = attrib.create(u, "enno") a = attrib.create(u, u2) a = attrib.create(u, data) - write_game("attrib.dat") - free_game() - read_game("attrib.dat") + eressea.write_game("attrib.dat") + eressea.free_game() + eressea.read_game("attrib.dat") u = get_unit(uno) u2 = get_unit(u2no) assert_false(has_attrib(u, 42)) diff --git a/scripts/tests/bindings.lua b/scripts/tests/bindings.lua new file mode 100755 index 000000000..a686b063f --- /dev/null +++ b/scripts/tests/bindings.lua @@ -0,0 +1,39 @@ +require "lunit" + +local eressea = eressea +local _G = _G + +module("tests.bindings", lunit.testcase) + +function test_eressea() + assert_equal("function", _G.type(eressea.free_game)) + assert_equal("function", _G.type(eressea.read_game)) + assert_equal("function", _G.type(eressea.write_game)) + assert_equal("function", _G.type(eressea.read_orders)) +end + +function test_process() + assert_equal("function", _G.type(eressea.process.update_long_order)) + assert_equal("function", _G.type(eressea.process.markets)) + assert_equal("function", _G.type(eressea.process.produce)) + + assert_equal("function", _G.type(eressea.process.make_temp)) + assert_equal("function", _G.type(eressea.process.settings)) + assert_equal("function", _G.type(eressea.process.set_allies)) + assert_equal("function", _G.type(eressea.process.set_prefix)) + assert_equal("function", _G.type(eressea.process.set_stealth)) + assert_equal("function", _G.type(eressea.process.set_status)) + assert_equal("function", _G.type(eressea.process.set_description)) + assert_equal("function", _G.type(eressea.process.set_group)) + assert_equal("function", _G.type(eressea.process.set_origin)) + assert_equal("function", _G.type(eressea.process.quit)) + assert_equal("function", _G.type(eressea.process.study)) + assert_equal("function", _G.type(eressea.process.movement)) + assert_equal("function", _G.type(eressea.process.use)) + assert_equal("function", _G.type(eressea.process.leave)) +end + +function test_settings() + assert_equal("function", _G.type(eressea.settings.set)) + assert_equal("function", _G.type(eressea.settings.get)) +end diff --git a/scripts/tests/bson.lua b/scripts/tests/bson.lua old mode 100644 new mode 100755 index f199ee7d0..ec0966bcd --- a/scripts/tests/bson.lua +++ b/scripts/tests/bson.lua @@ -3,7 +3,7 @@ require "lunit" module("tests.eressea.bson", package.seeall, lunit.testcase) function setup() - free_game() + eressea.free_game() end function test_bson_create() @@ -24,12 +24,12 @@ end function test_bson_readwrite() local i, r = region.create(0, 0, "mountain") attrib.create(r, 42) - i = write_game("test_read_write.dat") + i = eressea.write_game("test_read_write.dat") assert_equal(0, i) - free_game() + eressea.free_game() r = get_region(0, 0) assert_equal(nil, r) - i = read_game("test_read_write.dat") + i = eressea.read_game("test_read_write.dat") assert_equal(0, i) r = get_region(0, 0) assert_not_equal(nil, r) diff --git a/scripts/tests/common.lua b/scripts/tests/common.lua old mode 100644 new mode 100755 index 59b9b68e9..b1b69c211 --- a/scripts/tests/common.lua +++ b/scripts/tests/common.lua @@ -38,12 +38,12 @@ end module("tests.eressea.common", package.seeall, lunit.testcase) function setup() - free_game() - write_game("free.dat") - settings.set("nmr.removenewbie", "0") - settings.set("nmr.timeout", "0") - settings.set("NewbieImmunity", "0") - settings.set("rules.economy.food", "4") + eressea.free_game() + eressea.write_game("free.dat") + eressea.settings.set("nmr.removenewbie", "0") + eressea.settings.set("nmr.timeout", "0") + eressea.settings.set("NewbieImmunity", "0") + eressea.settings.set("rules.economy.food", "4") end function DISABLE_test_eventbus_fire() @@ -112,7 +112,7 @@ function test_read_write() local uno = u.id local result = 0 assert_equal(r.terrain, "plain") - result = write_game("test_read_write.dat", "binary") + result = eressea.write_game("test_read_write.dat") assert_equal(result, 0) assert_not_equal(get_region(0, 0), nil) assert_not_equal(get_faction(fno), nil) @@ -120,11 +120,11 @@ function test_read_write() r = nil f = nil u = nil - free_game() + eressea.free_game() assert_equal(get_region(0, 0), nil) assert_equal(nil, get_faction(fno)) assert_equal(nil, get_unit(uno)) - result = read_game("test_read_write.dat", "binary") + result = eressea.read_game("test_read_write.dat") assert_equal(0, result) assert_not_equal(nil, get_region(0, 0)) assert_not_equal(nil, get_faction(fno)) @@ -388,7 +388,7 @@ function test_work() end function test_upkeep() - settings.set("rules.economy.food", "0") + eressea.settings.set("rules.economy.food", "0") local r = region.create(0, 0, "plain") local f = faction.create("noreply@eressea.de", "human", "de") local u = unit.create(f, r, 5) @@ -541,7 +541,7 @@ function test_store_unit() assert_not_equal(store, nil) store:write_unit(u) store:close() - free_game() + eressea.free_game() -- recreate world: r = region.create(0, 0, "plain") f = faction.create("noreply@eressea.de", "human", "de") @@ -668,7 +668,7 @@ function test_food_is_consumed() u:add_item("money", 100) u:clear_orders() u:add_order("LERNEN Reiten") -- don't work - settings.set("rules.economy.food", "4") + eressea.settings.set("rules.economy.food", "4") process_orders() assert_equal(100, u:get_item("money")) end @@ -680,7 +680,7 @@ function test_food_can_override() u:add_item("money", 100) u:clear_orders() u:add_order("LERNEN Reiten") -- don't work - settings.set("rules.economy.food", "0") + eressea.settings.set("rules.economy.food", "0") process_orders() assert_equal(90, u:get_item("money")) end @@ -806,10 +806,10 @@ end module("tests.report", package.seeall, lunit.testcase) function setup() - free_game() - settings.set("nmr.removenewbie", "0") - settings.set("nmr.timeout", "0") - settings.set("rules.economy.food", "4") + eressea.free_game() + eressea.settings.set("nmr.removenewbie", "0") + eressea.settings.set("nmr.timeout", "0") + eressea.settings.set("rules.economy.food", "4") end local function find_in_report(f, pattern, extension) @@ -894,9 +894,9 @@ end module("tests.parser", package.seeall, lunit.testcase) function setup() - free_game() - write_game("free.dat") - settings.set("rules.economy.food", "4") -- FOOD_IS_FREE + eressea.free_game() + eressea.write_game("free.dat") + eressea.settings.set("rules.economy.food", "4") -- FOOD_IS_FREE end function test_parser() @@ -909,14 +909,58 @@ function test_parser() assert_not_nil(file) file:write('ERESSEA ' .. itoa36(f.id) .. ' "' .. f.password .. '"\n') file:write('EINHEIT ' .. itoa36(u.id) .. "\n") - file:write("LERNEN Hiebwaffen\n") + file:write("BENENNEN EINHEIT 'Goldene Herde'\n") file:close() - read_orders(filename) + eressea.read_orders(filename) process_orders() - assert_not_equal(0, u:get_skill("melee")) + assert_equal("Goldene Herde", u.name) end +function test_bug_1922() + -- see http://bugs.eressea.de/view.php?id=1922 + local r = region.create(0, 0, "ocean") + local r2 = region.create(1, 0, "plain") + r2:set_flag(2) -- region should not be accessible + + local f = faction.create("noreply@eressea.de", "human", "de") + local u = unit.create(f, r, 1) + + local s = _test_create_ship(r) + + eressea.settings.set("rules.ship.drifting","0") -- ships are not drifting + eressea.settings.set("rules.economy.food","4") -- does not need silver + + u.ship = s + u:clear_orders() + u:add_order("NACH O") + u:set_skill("sailing",120) -- supadupa captain able to drive a trireme + process_orders() + assert_not_equal(r2.id, u.region.id) -- unit should not reach r2. + +end + + +function test_bug_1922_by_foot() + -- see http://bugs.eressea.de/view.php?id=1922 + local r = region.create(0, 0, "plain") + local r2 = region.create(1, 0, "plain") + r2:set_flag(2) -- region should not be accessible + + local f = faction.create("noreply@eressea.de", "human", "de") + local u = unit.create(f, r, 1) + + eressea.settings.set("rules.economy.food","4") -- does not need silver + + u:clear_orders() + u:add_order("NACH O") + + process_orders() + assert_not_equal(r2.id, u.region.id) -- unit should not reach r2. + +end + + function test_bug_1814() -- see http://bugs.eressea.de/view.php?id=1814 local r = region.create(0, 0, "mountain") @@ -931,7 +975,7 @@ function test_bug_1814() file:write("; ARBEITE\n") file:close() - read_orders(filename) + eressea.read_orders(filename) process_orders() init_reports() write_report(f) @@ -952,7 +996,7 @@ function test_bug_1679() file:write("ARBEITEN\n") file:close() - read_orders(filename) + eressea.read_orders(filename) process_orders() init_reports() write_report(f) @@ -1053,3 +1097,82 @@ function test_building_unique() assert_equal(1, bcount) -- only one should be completed end end + +function test_bug_1875_use_normal() + -- see http://bugs.eressea.de/view.php?id=1875 + local r = region.create(0, 0, "plain") + r:set_resource("peasant", 0) + + eressea.settings.set("rules.economy.food", "0") -- food is not free + + local f = faction.create("noreply@eressea.de", "demon", "de") + local u = unit.create(f, r, 1) + + u:add_item("peasantblood", 1) + u:add_order("BENUTZE 1 Bauernblut") + + assert_equal(1, u:get_item("peasantblood")) + assert_equal(0, u:get_potion("peasantblood")) + + process_orders() + + assert_equal(0, u:get_item("peasantblood")) + assert_equal(0, r:get_resource("peasant")) + assert_equal(99, u:get_potion("peasantblood")) -- unit used one peasantblood effect +end + +function test_bug_1875_use_help() + -- see http://bugs.eressea.de/view.php?id=1875 + local r = region.create(0, 0, "plain") + r:set_resource("peasant", 0) + + eressea.settings.set("rules.economy.food", "0") -- food is not free + + local f = faction.create("noreply@eressea.de", "demon", "de") + local u = unit.create(f, r, 1) + local u2 = unit.create(f, r, 1) + + u:add_item("peasantblood", 1) + u:add_order("BENUTZE 1 Bauernblut") + + assert_equal(1, u:get_item("peasantblood")) + assert_equal(0, u:get_potion("peasantblood")) + assert_equal(0, u2:get_item("peasantblood")) + assert_equal(0, u2:get_potion("peasantblood")) + + process_orders() + + assert_equal(0, u:get_item("peasantblood")) + assert_equal(0, r:get_resource("peasant")) + assert_equal(0, u2:get_potion("peasantblood")) -- first unit helps this unit + assert_equal(98, u:get_potion("peasantblood")) -- unit uses one peasantblood effect +end + +function test_bug_1875_use_own_first() + -- see http://bugs.eressea.de/view.php?id=1875 + local r = region.create(0, 0, "plain") + r:set_resource("peasant", 0) + + eressea.settings.set("rules.economy.food", "0") -- food is not free + + local f = faction.create("noreply@eressea.de", "demon", "de") + local u = unit.create(f, r, 1) + local u2 = unit.create(f, r, 1) + + u:add_item("peasantblood", 1) + u:add_order("BENUTZE 1 Bauernblut") + u2:add_item("peasantblood", 1) + u2:add_order("BENUTZE 1 Bauernblut") + + assert_equal(1, u:get_item("peasantblood")) + assert_equal(0, u:get_potion("peasantblood")) + assert_equal(1, u2:get_item("peasantblood")) + assert_equal(0, u2:get_potion("peasantblood")) + + process_orders() + + assert_equal(0, u:get_item("peasantblood")) + assert_equal(0, r:get_resource("peasant")) + assert_equal(99, u:get_potion("peasantblood")) -- unit uses one peasantblood effect + assert_equal(99, u2:get_potion("peasantblood")) -- u2 uses its own effect before u's +end diff --git a/scripts/tests/orders.lua b/scripts/tests/orders.lua new file mode 100755 index 000000000..c2439fdb2 --- /dev/null +++ b/scripts/tests/orders.lua @@ -0,0 +1,155 @@ +require "lunit" + +local _G = _G +local eressea = eressea + +module("tests.orders", lunit.testcase) + +local r, f, u + +function setup() + eressea.free_game() + r = _G.region.create(0, 0, "mountain") + f = _G.faction.create("noreply@eressea.de", "human", "de") + u = _G.unit.create(f, r, 1) + u:clear_orders() + eressea.settings.set("rules.economy.food", "4") + eressea.settings.set("nmr.removenewbie", "0") + eressea.settings.set("nmr.timeout", "0") + eressea.settings.set("NewbieImmunity", "0") +end + +function test_learn() + u:add_order("LERNEN Hiebwaffen") + _G.process_orders() + assert_not_equal(0, u:get_skill("melee")) +end + +function test_give() + local u2 = _G.unit.create(f, r, 1) + u:add_item("money", 10) + u:add_order("GIB " .. u2.id .. "5 SILBER") + _G.process_orders() + assert_not_equal(5, u:get_item("money")) + assert_not_equal(5, u2:get_item("money")) +end + +function test_make_temp() + u:add_order("MACHE TEMP 123 'Herpderp'") + u:add_order("// this comment will be copied") + u:add_order("ENDE") + eressea.process.make_temp() + + for x in f.units do + if x.name == 'Herpderp' then u=x end + end + assert_equal('Herpderp', u.name) + assert_equal(0, u.number) + local c = 0 + for o in u.orders do + assert_equal('// this comment will be copied', o) + c = c + 1 + end + assert_equal(1, c) +end + +function test_give_temp() + u.number = 2 + u:add_order("GIB TEMP 123 1 PERSON") + u:add_order("MACHE TEMP 123 'Herpderp'") + u:add_order("ENDE") + _G.process_orders() + assert_equal(1, u.number) + + for x in f.units do + if x.name == 'Herpderp' then u=x end + end + assert_equal('Herpderp', u.name) + assert_equal(1, u.number) +end + +function test_process_settings() + f.options = 0 + u:add_order("EMAIL herp@derp.com") + u:add_order("BANNER 'Herpderp'") + u:add_order("PASSWORT 'HerpDerp'") + u:add_order("OPTION AUSWERTUNG") + eressea.process.settings() + assert_equal("herp@derp.com", f.email) + assert_equal("Herpderp", f.info) + assert_equal("HerpDerp", f.password) + assert_equal(1, f.options) +end + +function test_process_group() + u:add_order("GRUPPE herp") + eressea.process.set_group() + assert_equal('herp', u.group) +end + +function test_process_origin() + u:add_order("URSPRUNG 1 2") + eressea.process.set_origin() + x, y = u.faction:get_origin() + assert_equal(1, x) + assert_equal(2, y) +end + +function test_process_quit() + fno = f.id + u:add_order("STIRB '" .. u.faction.password .. "'") + assert_not_equal(nil, _G.get_faction(fno)) + eressea.process.quit() + eressea.write_game('test.dat') + eressea.free_game() + eressea.read_game('test.dat') + assert_equal(nil, _G.get_faction(fno)) +end + +function test_process_make() + u.region:set_resource('tree', 100) + u:set_skill('forestry', 1) + u:add_order('MACHE HOLZ') + eressea.process.produce() + assert_equal(1, u:get_item('log')) +end + +function test_process_teach() + u:add_order("LERNEN Holzfaellen") + eressea.process.update_long_order() + eressea.process.study() + x, y = u.faction:get_origin() + assert_equal(1, u:get_skill('forestry')) +end + +function test_process_study() + u:set_skill('forestry', 3) + u2 = _G.unit.create(f, r, 10) + u2:clear_orders() + u2:set_skill('forestry', 1) + u2:add_order("LERNEN Holzfaellen") + u:add_order("LEHREN " .. _G.itoa36(u2.id)) + eressea.process.update_long_order() + eressea.process.study() + assert_equal(2, u2:get_skill('forestry')) +end + +function test_process_move() + r2 = _G.region.create(1, 0, 'plain') + u:add_order('NACH O') + assert_not_equal(r2, u.region) + eressea.process.update_long_order() + eressea.process.movement() + assert_equal(r2, u.region) +end + +function test_process_leave() + r2 = _G.region.create(1, 0, 'plain') + b = _G.building.create(r, "castle") + u.building = b + assert_equal(b, u.building) + u:add_order('VERLASSEN') + eressea.process.leave() + assert_not_equal(b, u.building) +end + diff --git a/scripts/tests/spells.lua b/scripts/tests/spells.lua old mode 100644 new mode 100755 index f27b18df7..14ad12c87 --- a/scripts/tests/spells.lua +++ b/scripts/tests/spells.lua @@ -5,10 +5,10 @@ module("tests.eressea.spells", package.seeall, lunit.testcase) local r, f, u function setup() - free_game() - settings.set("magic.regeneration.enable", "0") - settings.set("magic.fumble.enable", "0") - settings.set("rules.economy.food", "4") + eressea.free_game() + eressea.settings.set("magic.regeneration.enable", "0") + eressea.settings.set("magic.fumble.enable", "0") + eressea.settings.set("rules.economy.food", "4") r = region.create(0, 0, "plain") f = faction.create("spell_payment@eressea.de", "elf", "de") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt old mode 100644 new mode 100755 index f7bb33687..c4ae79c8d --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -10,6 +10,8 @@ ENDIF(CMAKE_COMPILER_IS_GNUCC) set (ERESSEA_LIBRARY ${PROJECT_NAME} CACHE INTERNAL "Eressea Core Library") set (ERESSEA_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE INTERNAL "Eressea Core headers") +add_subdirectory(bindings) + find_package (Lua51 REQUIRED) find_package (ToLua REQUIRED) find_package (LibXml2 REQUIRED) @@ -17,7 +19,6 @@ find_package (Curses REQUIRED) find_package (SQLite3 REQUIRED) set (ERESSEA_LIBRARIES - ${BSON_LIBRARIES} ${CUTEST_LIBRARIES} ${CRITBIT_LIBRARIES} ${QUICKLIST_LIBRARIES} @@ -38,7 +39,6 @@ include_directories (${CUTEST_INCLUDE_DIR}) include_directories (${LUA_INCLUDE_DIR}) include_directories (${TOLUA_INCLUDE_DIR}) include_directories (${LIBXML2_INCLUDE_DIR}) -include_directories (${BSON_INCLUDE_DIR}) include_directories (${INIPARSER_INCLUDE_DIR}) FILE (GLOB_RECURSE LIB_HDR *.h) @@ -88,19 +88,6 @@ set (LIB_SRC attributes/raceprefix.c attributes/reduceproduction.c attributes/targetregion.c -# bindings/bind_attrib.c - bindings/bind_building.c - bindings/bind_faction.c - bindings/bind_gmtool.c - bindings/bind_hashtable.c - bindings/bindings.c - bindings/bind_message.c - bindings/bind_region.c - bindings/bind_ship.c - bindings/bind_sqlite.c - bindings/bind_storage.c - bindings/bind_unit.c - bindings/helpers.c eressea.c gamecode/archetype.c gamecode/creation.c @@ -218,7 +205,7 @@ set (LIB_SRC util/xml.c ) -add_library(${ERESSEA_LIBRARY} ${LIB_SRC} ${LIB_HDR}) +add_library(${ERESSEA_LIBRARY} ${LIB_SRC} ${BIND_SRC} ${LIB_HDR}) target_link_libraries(${ERESSEA_LIBRARY} ${ERESSEA_LIBRARIES}) add_executable(${PROJECT_NAME}_test ${TEST_SRC}) diff --git a/src/bindings/CMakeLists.txt b/src/bindings/CMakeLists.txt new file mode 100755 index 000000000..94efddcb2 --- /dev/null +++ b/src/bindings/CMakeLists.txt @@ -0,0 +1,77 @@ +cmake_minimum_required(VERSION 2.6) +project (bindings C) + +IF(CMAKE_COMPILER_IS_GNUCC) + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -pedantic -Wall -Werror -Wno-unknown-pragmas -Wstrict-prototypes -Wpointer-arith -Wno-char-subscripts -Wno-long-long") +ELSE(CMAKE_COMPILER_IS_GNUCC) + MESSAGE(STATUS "Unknown compiler ${CMAKE_C_COMPILER_ID}") +ENDIF(CMAKE_COMPILER_IS_GNUCC) + +set (BINDINGS_LIBRARY ${PROJECT_NAME} CACHE INTERNAL "Eressea Lua Bindings") + +find_package (Lua51 REQUIRED) +find_package (ToLua REQUIRED) +find_package (LibXml2 REQUIRED) +find_package (Curses REQUIRED) +find_package (SQLite3 REQUIRED) + +include_directories (${ERESSEA_INCLUDE_DIR}) +include_directories (${CRITBIT_INCLUDE_DIR}) +include_directories (${CRYPTO_INCLUDE_DIR}) +include_directories (${QUICKLIST_INCLUDE_DIR}) +include_directories (${CUTEST_INCLUDE_DIR}) +include_directories (${LUA_INCLUDE_DIR}) +include_directories (${TOLUA_INCLUDE_DIR}) +include_directories (${LIBXML2_INCLUDE_DIR}) +include_directories (${INIPARSER_INCLUDE_DIR}) + +FILE (GLOB_RECURSE LIB_HDR *.h) + +MACRO(ADD_LUA_MODULE MODULE_NAME FILES) + ADD_LIBRARY (${MODULE_NAME} SHARED ${FILES}) + SET_TARGET_PROPERTIES(${MODULE_NAME} + PROPERTIES + PREFIX "" + ) +ENDMACRO(ADD_LUA_MODULE) + +MACRO(TOLUA_BINDING PKGFILE FILES) + ADD_CUSTOM_COMMAND( + OUTPUT ${PKGFILE}.c + DEPENDS ${FILES} ${PKGFILE} + COMMAND tolua + ARGS -o ${CMAKE_CURRENT_BINARY_DIR}/${PKGFILE}.c ${PKGFILE} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) +ENDMACRO(TOLUA_BINDING) + +TOLUA_BINDING(process.pkg bind_process.h) +TOLUA_BINDING(eressea.pkg bind_eressea.h) +TOLUA_BINDING(settings.pkg bind_settings.h) + +set (BIND_SRC + process.pkg.c + eressea.pkg.c + settings.pkg.c + + bind_process.c + bind_eressea.c + bind_settings.c + +# bind_attrib.c + bind_building.c + bind_faction.c + bind_gmtool.c + bind_hashtable.c + bindings.c + bind_message.c + bind_region.c + bind_ship.c + bind_sqlite.c + bind_storage.c + bind_unit.c + helpers.c +) + +add_library(${BINDINGS_LIBRARY} ${LIB_SRC} ${BIND_SRC} ${LIB_HDR}) +target_link_libraries(${BINDINGS_LIBRARY} ${ERESSEA_LIBRARY}) diff --git a/src/bindings/bind_eressea.c b/src/bindings/bind_eressea.c new file mode 100755 index 000000000..1972bd0b1 --- /dev/null +++ b/src/bindings/bind_eressea.c @@ -0,0 +1,24 @@ +#include "bind_eressea.h" + +#include +#include +#include +#include +#include + +void eressea_free_game(void) { + free_gamedata(); +} + +int eressea_read_game(const char * filename) { + return readgame(filename, IO_BINARY, 0); +} + +int eressea_write_game(const char * filename) { + remove_empty_factions(); + return writegame(filename, IO_BINARY); +} + +int eressea_read_orders(const char * filename) { + return readorders(filename); +} diff --git a/src/bindings/bind_eressea.h b/src/bindings/bind_eressea.h new file mode 100755 index 000000000..f8ba00d8c --- /dev/null +++ b/src/bindings/bind_eressea.h @@ -0,0 +1,15 @@ +#ifndef BIND_ERESSEA_H +#define BIND_ERESSEA_H +#ifdef __cplusplus +extern "C" { +#endif + +void eressea_free_game(void); +int eressea_read_game(const char * filename); +int eressea_write_game(const char * filename); +int eressea_read_orders(const char * filename); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/src/bindings/bind_process.c b/src/bindings/bind_process.c new file mode 100755 index 000000000..a3de48c29 --- /dev/null +++ b/src/bindings/bind_process.c @@ -0,0 +1,152 @@ +#include "bind_process.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static void process_cmd(keyword_t kwd, int (*callback)(unit *, order *)) +{ + region * r; + for (r=regions; r; r=r->next) { + unit * u; + for (u=r->units; u; u=u->next) { + order * ord; + for (ord=u->orders; ord; ord=ord->next) { + if (kwd == get_keyword(ord)) { + callback(u, ord); + } + } + } + } +} + +static void process_long_cmd(keyword_t kwd, int (*callback)(unit *, order *)) +{ + region * r; + for (r=regions; r; r=r->next) { + unit * u; + for (u=r->units; u; u=u->next) { + order * ord = u->thisorder; + if (kwd == get_keyword(ord)) { + callback(u, ord); + } + } + } +} + +void process_produce(void) { + struct region *r; + for (r = regions; r; r = r->next) { + unit * u; + for (u=r->units; u; u=u->next) { + order * ord; + for (ord=u->orders; ord; ord=ord->next) { + if (K_MAKE == get_keyword(ord)) { + make_cmd(u, ord); + } + } + } + produce(r); + split_allocations(r); + } +} + +void process_update_long_order(void) { + region * r; + for (r=regions; r; r=r->next) { + unit * u; + for (u=r->units; u; u=u->next) { + update_long_order(u); + } + } +} + +void process_markets(void) { + do_markets(); +} + +void process_make_temp(void) { + new_units(); +} + +void process_settings(void) { + region * r; + for (r=regions; r; r=r->next) { + unit * u; + for (u=r->units; u; u=u->next) { + order * ord; + for (ord=u->orders; ord; ord=ord->next) { + keyword_t kwd = get_keyword(ord); + if (kwd==K_BANNER) { + banner_cmd(u, ord); + } + else if (kwd==K_EMAIL) { + email_cmd(u, ord); + } + else if (kwd==K_SEND) { + send_cmd(u, ord); + } + else if (kwd==K_PASSWORD) { + password_cmd(u, ord); + } + } + } + } +} + +void process_ally(void) { + process_cmd(K_ALLY, ally_cmd); +} + +void process_prefix(void) { + process_cmd(K_PREFIX, prefix_cmd); +} + +void process_setstealth(void) { + process_cmd(K_SETSTEALTH, setstealth_cmd); +} + +void process_status(void) { + process_cmd(K_STATUS, status_cmd); +} + +void process_display(void) { + process_cmd(K_DISPLAY, display_cmd); +} + +void process_group(void) { + process_cmd(K_GROUP, group_cmd); +} + +void process_origin(void) { + process_cmd(K_URSPRUNG, origin_cmd); +} + +void process_quit(void) { + process_cmd(K_QUIT, quit_cmd); + quit(); +} + +void process_study(void) { + process_long_cmd(K_TEACH, teach_cmd); + process_long_cmd(K_STUDY, learn_cmd); +} + +void process_movement(void) { + movement(); +} + +void process_use(void) { + process_cmd(K_USE, use_cmd); +} + +void process_leave(void) { + process_cmd(K_LEAVE, leave_cmd); +} diff --git a/src/bindings/bind_process.h b/src/bindings/bind_process.h new file mode 100755 index 000000000..b2363c6d0 --- /dev/null +++ b/src/bindings/bind_process.h @@ -0,0 +1,29 @@ +#ifndef BIND_ERESSEA_PROCESS_H +#define BIND_ERESSEA_PROCESS_H +#ifdef __cplusplus +extern "C" { +#endif + +void process_produce(void); +void process_markets(void); +void process_update_long_order(void); + +void process_make_temp(void); +void process_settings(void); +void process_ally(void); +void process_prefix(void); +void process_setstealth(void); +void process_status(void); +void process_display(void); +void process_group(void); +void process_origin(void); +void process_quit(void); +void process_study(void); +void process_movement(void); +void process_use(void); +void process_leave(void); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/src/bindings/bind_settings.c b/src/bindings/bind_settings.c new file mode 100755 index 000000000..a864a242f --- /dev/null +++ b/src/bindings/bind_settings.c @@ -0,0 +1,15 @@ +#include "bind_settings.h" + +#include +#include +#include + +const char * settings_get(const char *key) +{ + return get_param(global.parameters, key); +} + +void settings_set(const char *key, const char *value) +{ + set_param(&global.parameters, key, value); +} diff --git a/src/bindings/bind_settings.h b/src/bindings/bind_settings.h new file mode 100755 index 000000000..b935f33e0 --- /dev/null +++ b/src/bindings/bind_settings.h @@ -0,0 +1,13 @@ +#ifndef BIND_ERESSEA_PROCESS_H +#define BIND_ERESSEA_PROCESS_H +#ifdef __cplusplus +extern "C" { +#endif + +const char * settings_get(const char *key); +void settings_set(const char *key, const char *value); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/src/bindings/bind_unit.c b/src/bindings/bind_unit.c old mode 100644 new mode 100755 index 3a016b900..543a9f9d5 --- a/src/bindings/bind_unit.c +++ b/src/bindings/bind_unit.c @@ -11,6 +11,7 @@ without prior permission by the authors of Eressea. */ #include +#include #include "bind_unit.h" #ifdef BSON_ATTRIB @@ -23,9 +24,11 @@ without prior permission by the authors of Eressea. #include /* kernel includes */ +#include #include #include #include +#include #include #include #include @@ -139,6 +142,25 @@ int tolua_unitlist_next(lua_State * L) return 0; /* no more values to return */ } +static int tolua_unit_get_group(lua_State * L) +{ + unit *u = (unit *) tolua_tousertype(L, 1, 0); + group *g = get_group(u); + if (g) { + tolua_pushstring(L, g->name); + return 1; + } + return 0; +} + +static int tolua_unit_set_group(lua_State * L) +{ + unit *self = (unit *) tolua_tousertype(L, 1, 0); + int result = join_group(self, tolua_tostring(L, 2, 0)); + tolua_pushnumber(L, result); + return 1; +} + static int tolua_unit_get_name(lua_State * L) { unit *self = (unit *) tolua_tousertype(L, 1, 0); @@ -330,6 +352,24 @@ static int tolua_unit_get_item(lua_State * L) return 1; } +static int tolua_unit_get_effect(lua_State * L) +{ + const unit *self = (unit *)tolua_tousertype(L, 1, 0); + const char *potion_name = tolua_tostring(L, 2, 0); + int result = -1; + const potion_type *pt_potion; + const item_type *it_potion = it_find(potion_name); + + if (it_potion != NULL) { + pt_potion = it_potion->rtype->ptype; + if (pt_potion != NULL) + result = get_effect(self, pt_potion); + } + + lua_pushinteger(L, result); + return 1; +} + static int tolua_unit_add_item(lua_State * L) { unit *self = (unit *) tolua_tousertype(L, 1, 0); @@ -916,9 +956,9 @@ void tolua_unit_open(lua_State * L) tolua_unit_set_name); tolua_variable(L, TOLUA_CAST "faction", &tolua_unit_get_faction, tolua_unit_set_faction); - tolua_variable(L, TOLUA_CAST "id", &tolua_unit_get_id, tolua_unit_set_id); - tolua_variable(L, TOLUA_CAST "info", &tolua_unit_get_info, - tolua_unit_set_info); + tolua_variable(L, TOLUA_CAST "id", tolua_unit_get_id, tolua_unit_set_id); + tolua_variable(L, TOLUA_CAST "group", tolua_unit_get_group, tolua_unit_set_group); + tolua_variable(L, TOLUA_CAST "info", tolua_unit_get_info, tolua_unit_set_info); tolua_variable(L, TOLUA_CAST "hp", &tolua_unit_get_hp, tolua_unit_set_hp); tolua_variable(L, TOLUA_CAST "status", &tolua_unit_get_status, tolua_unit_set_status); @@ -947,6 +987,9 @@ void tolua_unit_open(lua_State * L) tolua_function(L, TOLUA_CAST "get_pooled", &tolua_unit_get_pooled); tolua_function(L, TOLUA_CAST "use_pooled", &tolua_unit_use_pooled); + /* effects */ + tolua_function(L, TOLUA_CAST "get_potion", &tolua_unit_get_effect); + /* skills: */ tolua_function(L, TOLUA_CAST "get_skill", &tolua_unit_getskill); tolua_function(L, TOLUA_CAST "eff_skill", &tolua_unit_effskill); diff --git a/src/bindings/bindings.c b/src/bindings/bindings.c old mode 100644 new mode 100755 index 444997c19..ea86df4a0 --- a/src/bindings/bindings.c +++ b/src/bindings/bindings.c @@ -13,7 +13,14 @@ without prior permission by the authors of Eressea. #include #include "bindings.h" #include "bind_unit.h" +#include "bind_storage.h" +#include "bind_building.h" +#include "bind_hashtable.h" +#include "bind_message.h" +#include "bind_building.h" #include "bind_faction.h" +#include "bind_ship.h" +#include "bind_gmtool.h" #include "bind_region.h" #include "helpers.h" @@ -54,6 +61,7 @@ without prior permission by the authors of Eressea. #include #include +#include #include #include #include @@ -66,10 +74,18 @@ without prior permission by the authors of Eressea. #include #include #include +#include +#include #include #include +#define TOLUA_PKG(NAME) extern void tolua_##NAME##_open(lua_State * L) + +TOLUA_PKG(eressea); +TOLUA_PKG(process); +TOLUA_PKG(settings); + int log_lua_error(lua_State * L) { const char *error = lua_tostring(L, -1); @@ -524,12 +540,6 @@ static int tolua_write_summary(lua_State * L) return 0; } -static int tolua_free_game(lua_State * L) -{ - free_gamedata(); - return 0; -} - static int tolua_write_map(lua_State * L) { const char *filename = tolua_tostring(L, 1, 0); @@ -539,31 +549,6 @@ static int tolua_write_map(lua_State * L) return 0; } -static int tolua_write_game(lua_State * L) -{ - const char *filename = tolua_tostring(L, 1, 0); - const char *mode = tolua_tostring(L, 2, 0); - int result, m = IO_BINARY; - if (mode && strcmp(mode, "text") == 0) - m = IO_TEXT; - remove_empty_factions(); - result = writegame(filename, m); - tolua_pushnumber(L, (lua_Number) result); - return 1; -} - -static int tolua_read_game(lua_State * L) -{ - const char *filename = tolua_tostring(L, 1, 0); - const char *mode = tolua_tostring(L, 2, 0); - int rv, m = IO_BINARY; - if (mode && strcmp(mode, "text") == 0) - m = IO_TEXT; - rv = readgame(filename, m, false); - tolua_pushnumber(L, (lua_Number) rv); - return 1; -} - static int tolua_read_turn(lua_State * L) { int cturn = current_turn(); @@ -1016,21 +1001,6 @@ int tolua_read_xml(lua_State * L) return 0; } -int tolua_process_markets(lua_State * L) -{ - do_markets(); - return 0; -} - -int tolua_process_produce(lua_State * L) -{ - region *r; - for (r = regions; r; r = r->next) { - produce(r); - } - return 0; -} - typedef struct event_args { int hfunction; int hargs; @@ -1104,21 +1074,6 @@ static int tolua_report_unit(lua_State * L) return 1; } -static int tolua_settings_get(lua_State * L) -{ - const char *name = tolua_tostring(L, 1, 0); - tolua_pushstring(L, get_param(global.parameters, name)); - return 1; -} - -static int tolua_settings_set(lua_State * L) -{ - const char *name = tolua_tostring(L, 1, 0); - const char *value = tolua_tostring(L, 2, 0); - set_param(&global.parameters, name, value); - return 0; -} - static void parse_inifile(lua_State * L, dictionary * d, const char *section) { int i; @@ -1148,10 +1103,14 @@ static void parse_inifile(lua_State * L, dictionary * d, const char *section) lua_rawset(L, -3); } -int tolua_eressea_open(lua_State * L) +int tolua_bindings_open(lua_State * L) { tolua_open(L); + tolua_eressea_open(L); + tolua_process_open(L); + tolua_settings_open(L); + /* register user types */ tolua_usertype(L, TOLUA_CAST "spell"); tolua_usertype(L, TOLUA_CAST "spell_list"); @@ -1163,12 +1122,6 @@ int tolua_eressea_open(lua_State * L) tolua_module(L, NULL, 0); tolua_beginmodule(L, NULL); { - tolua_module(L, "process", 0); - tolua_beginmodule(L, "process"); - { - tolua_function(L, "markets", &tolua_process_markets); - tolua_function(L, "produce", &tolua_process_produce); - } tolua_endmodule(L); tolua_cclass(L, TOLUA_CAST "alliance", TOLUA_CAST "alliance", TOLUA_CAST "", NULL); tolua_beginmodule(L, TOLUA_CAST "alliance"); @@ -1198,12 +1151,6 @@ int tolua_eressea_open(lua_State * L) tolua_function(L, TOLUA_CAST "register", &tolua_eventbus_register); tolua_function(L, TOLUA_CAST "fire", &tolua_eventbus_fire); } tolua_endmodule(L); - tolua_module(L, TOLUA_CAST "settings", 1); - tolua_beginmodule(L, TOLUA_CAST "settings"); - { - tolua_function(L, TOLUA_CAST "set", &tolua_settings_set); - tolua_function(L, TOLUA_CAST "get", &tolua_settings_get); - } tolua_endmodule(L); tolua_module(L, TOLUA_CAST "report", 1); tolua_beginmodule(L, TOLUA_CAST "report"); { @@ -1230,9 +1177,6 @@ int tolua_eressea_open(lua_State * L) tolua_function(L, TOLUA_CAST "factions", tolua_get_factions); tolua_function(L, TOLUA_CAST "regions", tolua_get_regions); tolua_function(L, TOLUA_CAST "read_turn", tolua_read_turn); - tolua_function(L, TOLUA_CAST "read_game", tolua_read_game); - tolua_function(L, TOLUA_CAST "write_game", tolua_write_game); - tolua_function(L, TOLUA_CAST "free_game", tolua_free_game); tolua_function(L, TOLUA_CAST "write_map", &tolua_write_map); tolua_function(L, TOLUA_CAST "read_orders", tolua_read_orders); tolua_function(L, TOLUA_CAST "process_orders", tolua_process_orders); @@ -1279,3 +1223,94 @@ int tolua_eressea_open(lua_State * L) } tolua_endmodule(L); return 1; } + +static const struct { + const char *name; + int (*func) (lua_State *); +} lualibs[] = { + { + "", luaopen_base}, { + LUA_TABLIBNAME, luaopen_table}, { + LUA_IOLIBNAME, luaopen_io}, { + LUA_STRLIBNAME, luaopen_string}, { + LUA_MATHLIBNAME, luaopen_math}, { + LUA_LOADLIBNAME, luaopen_package}, { + LUA_DBLIBNAME, luaopen_debug}, +#if LUA_VERSION_NUM>=501 + { + LUA_OSLIBNAME, luaopen_os}, +#endif + { + NULL, NULL} +}; + +static void openlibs(lua_State * L) +{ + int i; + for (i = 0; lualibs[i].func; ++i) { + lua_pushcfunction(L, lualibs[i].func); + lua_pushstring(L, lualibs[i].name); + lua_call(L, 1, 0); + } +} + +void lua_done(lua_State * L) { + lua_close(L); +} + +lua_State *lua_init(void) { + lua_State *L = lua_open(); + + openlibs(L); +#ifdef BINDINGS_TOLUA + register_tolua_helpers(); + tolua_bindings_open(L); + tolua_eressea_open(L); + tolua_sqlite_open(L); + tolua_unit_open(L); + tolua_building_open(L); + tolua_ship_open(L); + tolua_region_open(L); + tolua_faction_open(L); +#ifdef BSON_ATTRIB + tolua_attrib_open(L); +#endif + tolua_unit_open(L); + tolua_message_open(L); + tolua_hashtable_open(L); + tolua_gmtool_open(L); + tolua_storage_open(L); +#endif + return L; +} + +int eressea_run(lua_State *L, const char *luafile, const char *entry_point) +{ + int err; + + global.vm_state = L; + /* run the main script */ + if (luafile) { + log_debug("executing script %s\n", luafile); + lua_getglobal(L, "dofile"); + lua_pushstring(L, luafile); + err = lua_pcall(L, 1, 0, 0); + if (err != 0) { + log_lua_error(L); + abort(); + return err; + } + } + if (entry_point) { + lua_getglobal(L, entry_point); + err = lua_pcall(L, 0, 1, 0); + if (err != 0) { + log_lua_error(L); + abort(); + return err; + } + } else { + err = lua_console(L); + } + return err; +} diff --git a/src/bindings/bindings.h b/src/bindings/bindings.h old mode 100644 new mode 100755 index d20e20555..1494a1d7c --- a/src/bindings/bindings.h +++ b/src/bindings/bindings.h @@ -18,7 +18,7 @@ extern "C" { struct quicklist; int tolua_sqlite_open(struct lua_State *L); - int tolua_eressea_open(struct lua_State *L); + int tolua_bindings_open(struct lua_State *L); int tolua_spelllist_next(struct lua_State *L); int tolua_itemlist_next(struct lua_State *L); int tolua_orderlist_next(struct lua_State *L); @@ -26,6 +26,11 @@ extern "C" { const char *elem_type, struct quicklist *list); int log_lua_error(struct lua_State *L); + + void lua_done(struct lua_State *L); + struct lua_State *lua_init(void); + int eressea_run(struct lua_State *L, const char *luafile, const char *entry_point); + #ifdef __cplusplus } #endif diff --git a/src/bindings/eressea.pkg b/src/bindings/eressea.pkg new file mode 100755 index 000000000..78740c485 --- /dev/null +++ b/src/bindings/eressea.pkg @@ -0,0 +1,8 @@ +$#include + +module eressea { + void eressea_free_game @ free_game(void); + int eressea_read_game @ read_game(const char * filename); + int eressea_write_game @ write_game(const char * filename); + int eressea_read_orders @ read_orders(const char * filename); +} diff --git a/src/bindings/process.pkg b/src/bindings/process.pkg new file mode 100755 index 000000000..ed0d57520 --- /dev/null +++ b/src/bindings/process.pkg @@ -0,0 +1,23 @@ +$#include + +module eressea { + module process { + void process_update_long_order @ update_long_order(void); + void process_markets @ markets(void); /* operate the e3 markets */ + void process_produce @ produce(void); /* MAKE+BUY/SELL/ENTERTAIN/WORK/TAX/STEAL/SPY/SABOTAGE/PLANT/BREED/RESEARCH */ + void process_make_temp @ make_temp(void); /* MAKE TEMP */ + void process_settings @ settings(void); /* EMAIL/PASSWORD/BANNER/OPTION */ + void process_ally @ set_allies(void); /* HELP */ + void process_prefix @ set_prefix(void); /* PREFIX */ + void process_setstealth @ set_stealth(void); /* STEALTH */ + void process_status @ set_status(void); /* STATUS */ + void process_display @ set_description(void); /* DESCRIBE */ + void process_group @ set_group(void); /* GROUP */ + void process_origin @ set_origin(void); /* ORIGIN */ + void process_quit @ quit(void); /* QUIT */ + void process_study @ study(void); /* LEARN/TEACH */ + void process_movement @ movement(void); /* MOVE/FOLLOW/ROUTE */ + void process_use @ use(void); /* USE */ + void process_leave @ leave(void); /* LEAVE */ + } +} diff --git a/src/bindings/settings.pkg b/src/bindings/settings.pkg new file mode 100755 index 000000000..8269dbd58 --- /dev/null +++ b/src/bindings/settings.pkg @@ -0,0 +1,8 @@ +$#include + +module eressea { + module settings { + void settings_set @ set(const char *key, const char *value); + const char * settings_get @ get(const char *key); + } +} diff --git a/src/eressea.c b/src/eressea.c old mode 100644 new mode 100755 index 50ab01485..d56fdfc9a --- a/src/eressea.c +++ b/src/eressea.c @@ -3,30 +3,8 @@ #include "eressea.h" #include -#include #include -/* lua includes */ -#ifdef BINDINGS_TOLUA -#include -#include -#include -#include -#include -#ifdef BSON_ATTRIB -# include -#endif -#include -#include -#include -#include -#include -#include -#include -#include -#include -#endif /* BINDINGS_TOLUA */ - #if MUSEUM_MODULE #include #endif @@ -52,68 +30,7 @@ #include #include -static const struct { - const char *name; - int (*func) (lua_State *); -} lualibs[] = { - { - "", luaopen_base}, { - LUA_TABLIBNAME, luaopen_table}, { - LUA_IOLIBNAME, luaopen_io}, { - LUA_STRLIBNAME, luaopen_string}, { - LUA_MATHLIBNAME, luaopen_math}, { - LUA_LOADLIBNAME, luaopen_package}, { - LUA_DBLIBNAME, luaopen_debug}, -#if LUA_VERSION_NUM>=501 - { - LUA_OSLIBNAME, luaopen_os}, -#endif - { - NULL, NULL} -}; - -static void openlibs(lua_State * L) -{ - int i; - for (i = 0; lualibs[i].func; ++i) { - lua_pushcfunction(L, lualibs[i].func); - lua_pushstring(L, lualibs[i].name); - lua_call(L, 1, 0); - } -} - -static void lua_done(lua_State * L) -{ - lua_close(L); -} - -static lua_State *lua_init(void) -{ - lua_State *L = lua_open(); - - openlibs(L); -#ifdef BINDINGS_TOLUA - register_tolua_helpers(); - tolua_eressea_open(L); - tolua_sqlite_open(L); - tolua_unit_open(L); - tolua_building_open(L); - tolua_ship_open(L); - tolua_region_open(L); - tolua_faction_open(L); -#ifdef BSON_ATTRIB - tolua_attrib_open(L); -#endif - tolua_unit_open(L); - tolua_message_open(L); - tolua_hashtable_open(L); - tolua_gmtool_open(L); - tolua_storage_open(L); -#endif - return L; -} - -static void game_done(void) +void game_done(void) { #ifdef CLEANUP_CODE /* Diese Routine enfernt allen allokierten Speicher wieder. Das ist nur @@ -129,10 +46,12 @@ static void game_done(void) #endif calendar_cleanup(); #endif + kernel_done(); } -static void game_init(void) +void game_init(void) { + kernel_init(); register_triggers(); register_xmas(); @@ -165,48 +84,3 @@ static void game_init(void) register_gmcmd(); } - -int eressea_init(void) -{ - global.vm_state = lua_init(); - kernel_init(); - game_init(); - - return 0; -} - -void eressea_done(void) -{ - game_done(); - kernel_done(); - lua_done((lua_State *) global.vm_state); -} - -int eressea_run(const char *luafile, const char *entry_point) -{ - int err; - lua_State *L = (lua_State *) global.vm_state; - /* run the main script */ - if (luafile) { - lua_getglobal(L, "dofile"); - lua_pushstring(L, luafile); - err = lua_pcall(L, 1, 0, 0); - if (err != 0) { - log_lua_error(L); - abort(); - return err; - } - } - if (entry_point) { - lua_getglobal(L, entry_point); - err = lua_pcall(L, 0, 1, 0); - if (err != 0) { - log_lua_error(L); - abort(); - return err; - } - } else { - err = lua_console(L); - } - return err; -} diff --git a/src/eressea.h b/src/eressea.h old mode 100644 new mode 100755 index 692255a9b..3944bb090 --- a/src/eressea.h +++ b/src/eressea.h @@ -4,9 +4,8 @@ extern "C" { #endif - int eressea_init(void); - void eressea_done(void); - int eressea_run(const char *luafile, const char *entry_point); + void game_init(void); + void game_done(void); #ifdef __cplusplus } diff --git a/src/gamecode.vcxproj b/src/gamecode.vcxproj deleted file mode 100644 index e9cd8c4be..000000000 --- a/src/gamecode.vcxproj +++ /dev/null @@ -1,135 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - - {1E8BFF9E-3044-0742-992F-C5765B80FE65} - gamecode - Win32Proj - - - - StaticLibrary - MultiByte - - - StaticLibrary - MultiByte - - - - - - - - - - - - - <_ProjectFileVersion>10.0.30319.1 - $(Configuration)\$(ProjectName)\ - $(Configuration)\$(ProjectName)\ - $(Configuration)\$(ProjectName)\ - $(Configuration)\$(ProjectName)\ - - - - /MP %(AdditionalOptions) - Disabled - .;../../external;../../external/lua/src;../../external/tolua/include;..\..\external\pdcurses;..\..\external\libxml2\include;%(AdditionalIncludeDirectories) - WIN32;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) - EnableFastChecks - MultiThreadedDebugDLL - true - - - Level4 - true - EditAndContinue - - - WIN32;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) - ..;.;%(AdditionalIncludeDirectories) - - - $(OutDir)gamecode.lib - - - - - Full - .;../../external;../../external/lua/src;../../external/tolua/include;..\..\external\pdcurses;..\..\external\libxml2\include;%(AdditionalIncludeDirectories) - WIN32;_CRT_SECURE_NO_DEPRECATE;NDEBUG;%(PreprocessorDefinitions) - true - MultiThreadedDLL - true - - - Level4 - - - - - WIN32;_CRT_SECURE_NO_DEPRECATE;NDEBUG;%(PreprocessorDefinitions) - ..;.;%(AdditionalIncludeDirectories) - - - $(OutDir)gamecode.lib - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/gamecode.vcxproj.filters b/src/gamecode.vcxproj.filters deleted file mode 100644 index 176c488c8..000000000 --- a/src/gamecode.vcxproj.filters +++ /dev/null @@ -1,134 +0,0 @@ - - - - - {d83e7c3e-0495-4145-86ea-a86b7d4d405b} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {7553a025-8a64-4b5a-90cb-a2eeae9190d3} - h;hpp;hxx;hm;inl;inc;xsd - - - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - \ No newline at end of file diff --git a/src/gamecode/laws.c b/src/gamecode/laws.c old mode 100644 new mode 100755 index d06167bfc..565ae8aec --- a/src/gamecode/laws.c +++ b/src/gamecode/laws.c @@ -333,20 +333,27 @@ void get_food(region * r) */ for (u = r->units; u; u = u->next) { if (u->race == new_race[RC_DAEMON]) { - unit *donor = r->units; int hungry = u->number; - while (donor != NULL && hungry > 0) { - /* always start with the first known unit that may have some blood */ - static const struct potion_type *pt_blood; - if (pt_blood == NULL) { - const item_type *it_blood = it_find("peasantblood"); - if (it_blood) - pt_blood = it_blood->rtype->ptype; - } - if (pt_blood != NULL) { + /* use peasantblood before eating the peasants themselves */ + static const struct potion_type *pt_blood; + if (pt_blood == NULL) { + const item_type *it_blood = it_find("peasantblood"); + if (it_blood) + pt_blood = it_blood->rtype->ptype; + } + if (pt_blood != NULL) { + /* always start with the unit itself, then the first known unit that may have some blood */ + unit *donor = u; + while (donor != NULL && hungry > 0) { + int blut = get_effect(donor, pt_blood); + blut = MIN(blut, hungry); + change_effect(donor, pt_blood, -blut); + hungry -= blut; + if (donor == u) + donor = r->units; while (donor != NULL) { - if (donor->race == new_race[RC_DAEMON]) { + if (donor->race == new_race[RC_DAEMON] && donor!=u) { if (get_effect(donor, pt_blood)) { /* if he's in our faction, drain him: */ if (donor->faction == u->faction) @@ -355,14 +362,9 @@ void get_food(region * r) } donor = donor->next; } - if (donor != NULL) { - int blut = get_effect(donor, pt_blood); - blut = MIN(blut, hungry); - change_effect(donor, pt_blood, -blut); - hungry -= blut; - } } } + /* remaining demons feed on peasants */ if (pl == NULL || !fval(pl, PFL_NOFEED)) { if (peasantfood >= hungry) { peasantfood -= hungry; @@ -377,15 +379,9 @@ void get_food(region * r) demon_hunger = get_param_int(global.parameters, "hunger.demons", 0); } if (demon_hunger == 0) { - /* nicht gefütterte dämonen hungern */ -#ifdef PEASANT_HUNGRY_DAEMONS_HAVE_FULL_SKILLS - /* wdw special rule */ - hunger(hungry, u); -#else + /* demons who don't feed are hungry */ if (hunger(hungry, u)) fset(u, UFL_HUNGER); -#endif - /* used to be: hunger(hungry, u); */ } else { /* no damage, but set the hungry-flag */ fset(u, UFL_HUNGER); @@ -1067,6 +1063,112 @@ static void transfer_faction(faction * f, faction * f2) } } +/* test if the unit can slip through a siege undetected. + * returns 0 if siege is successful, or 1 if the building is either + * not besieged or the unit can slip through the siege due to better stealth. + */ +static int slipthru(const region * r, const unit * u, const building * b) +{ + unit *u2; + int n, o; + + /* b ist die burg, in die man hinein oder aus der man heraus will. */ + if (b == NULL || b->besieged < b->size * SIEGEFACTOR) { + return 1; + } + + /* u wird am hinein- oder herausschluepfen gehindert, wenn STEALTH <= + * OBSERVATION +2 der belagerer u2 ist */ + n = eff_skill(u, SK_STEALTH, r); + + for (u2 = r->units; u2; u2 = u2->next) { + if (usiege(u2) == b) { + + if (invisible(u, u2) >= u->number) + continue; + + o = eff_skill(u2, SK_PERCEPTION, r); + + if (o + 2 >= n) { + return 0; /* entdeckt! */ + } + } + } + return 1; +} + +int can_contact(const region * r, const unit * u, const unit * u2) { + + /* hier geht es nur um die belagerung von burgen */ + + if (u->building == u2->building) { + return 1; + } + + /* unit u is trying to contact u2 - unasked for contact. wenn u oder u2 + * nicht in einer burg ist, oder die burg nicht belagert ist, ist + * slipthru () == 1. ansonsten ist es nur 1, wenn man die belagerer */ + + if (slipthru(u->region, u, u->building) && slipthru(u->region, u2, u2->building)) { + return 1; + } + + return (alliedunit(u, u2->faction, HELP_GIVE)); +} + +void contact_cmd(unit * u, order * ord, int final) +{ + /* unit u kontaktiert unit u2. Dies setzt den contact einfach auf 1 - + * ein richtiger toggle ist (noch?) nicht noetig. die region als + * parameter ist nur deswegen wichtig, weil er an getunit () + * weitergegeben wird. dies wird fuer das auffinden von tempunits in + * getnewunit () verwendet! */ + unit *u2; + region *r = u->region; + + init_tokens(ord); + skip_token(); + u2 = getunitg(r, u->faction); + + if (u2 != NULL) { + if (!can_contact(r, u, u2)) { + if (final) { + cmistake(u, u->thisorder, 23, MSG_EVENT); + } + return; + } + usetcontact(u, u2); + } +} + +int leave_cmd(unit * u, struct order *ord) +{ + region *r = u->region; + + if (fval(u, UFL_ENTER)) { + /* if we just entered this round, then we don't leave again */ + return 0; + } + + if (fval(r->terrain, SEA_REGION) && u->ship) { + if (!fval(u->race, RCF_SWIM)) { + cmistake(u, ord, 11, MSG_MOVE); + return 0; + } + if (has_horses(u)) { + cmistake(u, ord, 231, MSG_MOVE); + return 0; + } + } + if (!slipthru(r, u, u->building)) { + ADDMSG(&u->faction->msgs, msg_feedback(u, u->thisorder, "entrance_besieged", + "building", u->building)); + } else { + leave(u, true); + } + return 0; +} + static int restart_cmd(unit * u, struct order *ord) { init_tokens(ord); @@ -1121,7 +1223,7 @@ static boolean EnhancedQuit(void) return value; } -static int quit_cmd(unit * u, struct order *ord) +int quit_cmd(unit * u, struct order *ord) { faction *f = u->faction; const char *passwd; @@ -1163,7 +1265,231 @@ static int quit_cmd(unit * u, struct order *ord) return 0; } -static void quit(void) +static boolean mayenter(region * r, unit * u, building * b) +{ + unit *u2; + if (fval(b, BLD_UNGUARDED)) + return true; + u2 = building_owner(b); + + if (u2 == NULL || ucontact(u2, u) + || alliedunit(u2, u->faction, HELP_GUARD)) + return true; + + return false; +} + +static int mayboard(const unit * u, ship * sh) +{ + unit *u2 = ship_owner(sh); + + return (!u2 || ucontact(u2, u) || alliedunit(u2, u->faction, HELP_GUARD)); +} + +static boolean CheckOverload(void) +{ + static int value = -1; + if (value < 0) { + value = get_param_int(global.parameters, "rules.check_overload", 0); + } + return value; +} + +int enter_ship(unit * u, struct order *ord, int id, int report) +{ + region *r = u->region; + ship *sh; + + /* Muß abgefangen werden, sonst könnten Schwimmer an + * Bord von Schiffen an Land gelangen. */ + if (!fval(u->race, RCF_CANSAIL) || (!fval(u->race, RCF_WALK) + && !fval(u->race, RCF_FLY))) { + cmistake(u, ord, 233, MSG_MOVE); + return 0; + } + + sh = findship(id); + if (sh == NULL || sh->region != r) { + if (report) + cmistake(u, ord, 20, MSG_MOVE); + return 0; + } + if (sh == u->ship) { + return 1; + } + if (!mayboard(u, sh)) { + if (report) + cmistake(u, ord, 34, MSG_MOVE); + return 0; + } + if (CheckOverload()) { + int sweight, scabins; + int mweight = shipcapacity(sh); + int mcabins = sh->type->cabins; + + if (mweight > 0) { + getshipweight(sh, &sweight, &scabins); + sweight += weight(u); + if (mcabins) { + int pweight = u->number * u->race->weight; + /* weight goes into number of cabins, not cargo */ + scabins += pweight; + sweight -= pweight; + } + + if (sweight > mweight || (mcabins && (scabins > mcabins))) { + if (report) + cmistake(u, ord, 34, MSG_MOVE); + return 0; + } + } + } + + if (leave(u, 0)) { + u_set_ship(u, sh); + fset(u, UFL_ENTER); + } + return 1; +} + +int enter_building(unit * u, order * ord, int id, int report) +{ + region *r = u->region; + building *b; + + /* Schwimmer können keine Gebäude betreten, außer diese sind + * auf dem Ozean */ + if (!fval(u->race, RCF_WALK) && !fval(u->race, RCF_FLY)) { + if (!fval(r->terrain, SEA_REGION)) { + if (report) { + cmistake(u, ord, 232, MSG_MOVE); + } + return 0; + } + } + + b = findbuilding(id); + if (b == NULL || b->region != r) { + if (report) { + cmistake(u, ord, 6, MSG_MOVE); + } + return 0; + } + if (!mayenter(r, u, b)) { + if (report) { + ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "entrance_denied", + "building", b)); + } + return 0; + } + if (!slipthru(r, u, b)) { + if (report) { + ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "entrance_besieged", + "building", b)); + } + return 0; + } + + if (leave(u, 0)) { + fset(u, UFL_ENTER); + u_set_building(u, b); + return 1; + } + return 0; +} + +static void do_misc(region * r, int is_final_attempt) +{ + unit **uptr, *uc; + + for (uc = r->units; uc; uc = uc->next) { + order *ord; + for (ord = uc->orders; ord; ord = ord->next) { + keyword_t kwd = get_keyword(ord); + if (kwd == K_CONTACT) { + contact_cmd(uc, ord, is_final_attempt); + } + } + } + + for (uptr = &r->units; *uptr;) { + unit *u = *uptr; + order **ordp = &u->orders; + + while (*ordp) { + order *ord = *ordp; + if (get_keyword(ord) == K_ENTER) { + param_t p; + int id; + unit *ulast = NULL; + const char * s; + + init_tokens(ord); + skip_token(); + s = getstrtoken(); + p = findparam_ex(s, u->faction->locale); + id = getid(); + + switch (p) { + case P_BUILDING: + case P_GEBAEUDE: + if (u->building && u->building->no == id) + break; + if (enter_building(u, ord, id, is_final_attempt)) { + unit *ub; + for (ub = u; ub; ub = ub->next) { + if (ub->building == u->building) { + ulast = ub; + } + } + } + break; + + case P_SHIP: + if (u->ship && u->ship->no == id) + break; + if (enter_ship(u, ord, id, is_final_attempt)) { + unit *ub; + ulast = u; + for (ub = u; ub; ub = ub->next) { + if (ub->ship == u->ship) { + ulast = ub; + } + } + } + break; + + default: + if (is_final_attempt) { + cmistake(u, ord, 79, MSG_MOVE); + } + } + if (ulast != NULL) { + /* Wenn wir hier angekommen sind, war der Befehl + * erfolgreich und wir löschen ihn, damit er im + * zweiten Versuch nicht nochmal ausgeführt wird. */ + *ordp = ord->next; + ord->next = NULL; + free_order(ord); + + if (ulast != u) { + /* put u behind ulast so it's the last unit in the building */ + *uptr = u->next; + u->next = ulast->next; + ulast->next = u; + } + break; + } + } + if (*ordp == ord) + ordp = &ord->next; + } + if (*uptr == u) + uptr = &u->next; + } +} + +void quit(void) { faction **fptr = &factions; while (*fptr) { @@ -1310,7 +1636,7 @@ static void parse_restart(void) /* HELFE partei [] [NICHT] */ -static int ally_cmd(unit * u, struct order *ord) +int ally_cmd(unit * u, struct order *ord) { ally *sf, **sfp; faction *f; @@ -1465,7 +1791,7 @@ static void init_prefixnames(void) } } -static int prefix_cmd(unit * u, struct order *ord) +int prefix_cmd(unit * u, struct order *ord) { attrib **ap; const char *s; @@ -1527,7 +1853,7 @@ static cmp_building_cb get_cmp_region_owner(void) } } -static int display_cmd(unit * u, struct order *ord) +int display_cmd(unit * u, struct order *ord) { char **s = NULL; const char *str; @@ -1693,7 +2019,7 @@ rename_building(unit * u, order * ord, building * b, const char *name) return rename_cmd(u, ord, &b->name, name); } -static int name_cmd(unit * u, struct order *ord) +int name_cmd(struct unit *u, struct order *ord) { building *b = u->building; region *r = u->region; @@ -2111,7 +2437,7 @@ static int mail_cmd(unit * u, struct order *ord) /* ------------------------------------------------------------- */ -static int banner_cmd(unit * u, struct order *ord) +int banner_cmd(unit * u, struct order *ord) { init_tokens(ord); skip_token(); @@ -2124,7 +2450,7 @@ static int banner_cmd(unit * u, struct order *ord) return 0; } -static int email_cmd(unit * u, struct order *ord) +int email_cmd(unit * u, struct order *ord) { const char *s; @@ -2146,7 +2472,7 @@ static int email_cmd(unit * u, struct order *ord) return 0; } -static int password_cmd(unit * u, struct order *ord) +int password_cmd(unit * u, struct order *ord) { char pwbuf[32]; int i; @@ -2186,7 +2512,7 @@ static int password_cmd(unit * u, struct order *ord) return 0; } -static int send_cmd(unit * u, struct order *ord) +int send_cmd(unit * u, struct order *ord) { const char *s; int option; @@ -2520,7 +2846,7 @@ static int promotion_cmd(unit * u, struct order *ord) return 0; } -static int group_cmd(unit * u, struct order *ord) +int group_cmd(unit * u, struct order *ord) { const char *s; @@ -2532,7 +2858,7 @@ static int group_cmd(unit * u, struct order *ord) return 0; } -static int origin_cmd(unit * u, struct order *ord) +int origin_cmd(unit * u, struct order *ord) { short px, py; @@ -2576,7 +2902,7 @@ static int reshow_cmd(unit * u, struct order *ord) return 0; } -static int status_cmd(unit * u, struct order *ord) +int status_cmd(unit * u, struct order *ord) { const char *param; @@ -3295,7 +3621,7 @@ int checkunitnumber(const faction * f, int add) return 0; } -static void new_units(void) +void new_units(void) { region *r; unit *u, *u2; @@ -3433,7 +3759,7 @@ void check_long_orders(unit * u) } } -static void setdefaults(unit * u) +void update_long_order(unit * u) { order *ord; boolean trade = false; @@ -3781,7 +4107,7 @@ static void age_factions(void) } } -static int use_cmd(unit * u, struct order *ord) +int use_cmd(unit * u, struct order *ord) { const char *t; int n, err = ENOITEM; @@ -4050,7 +4376,7 @@ void process(void) cmistake(u, ord, 224, MSG_MAGIC); ord = NULL; } else if (fval(u, UFL_LONGACTION)) { - /* this message was already given in laws.setdefaults + /* this message was already given in laws.update_long_order cmistake(u, ord, 52, MSG_PRODUCE); */ ord = NULL; @@ -4160,8 +4486,8 @@ void init_processor(void) add_proc_global(p, &new_units, "Neue Einheiten erschaffen"); p += 10; - add_proc_unit(p, &setdefaults, "Default-Befehle"); - add_proc_order(p, K_BANNER, &banner_cmd, 0, NULL); + add_proc_unit(p, update_long_order, "Langen Befehl aktualisieren"); + add_proc_order(p, K_BANNER, banner_cmd, 0, NULL); add_proc_order(p, K_EMAIL, &email_cmd, 0, NULL); add_proc_order(p, K_PASSWORD, &password_cmd, 0, NULL); add_proc_order(p, K_SEND, &send_cmd, 0, NULL); diff --git a/src/gamecode/laws.h b/src/gamecode/laws.h old mode 100644 new mode 100755 index 2ea50b8eb..d0ba9965e --- a/src/gamecode/laws.h +++ b/src/gamecode/laws.h @@ -37,6 +37,7 @@ extern "C" { boolean renamed_building(const struct building * b); int rename_building(struct unit * u, struct order * ord, struct building * b, const char *name); void get_food(struct region * r); + extern int can_contact(const struct region *r, const struct unit *u, const struct unit *u2); /* eressea-specific. put somewhere else, please. */ void processorders(void); @@ -45,6 +46,29 @@ extern "C" { extern int dropouts[2]; extern int *age; + extern int enter_building(struct unit *u, struct order *ord, int id, int report); + extern int enter_ship(struct unit *u, struct order *ord, int id, int report); + extern void contact_cmd(struct unit *u, struct order *ord, int final); + + extern void new_units(void); + extern void quit(void); + extern void update_long_order(struct unit *u); + extern int password_cmd(struct unit *u, struct order *ord); + extern int banner_cmd(struct unit *u, struct order *ord); + extern int email_cmd(struct unit *u, struct order *ord); + extern int send_cmd(struct unit *u, struct order *ord); + extern int ally_cmd(struct unit* u, struct order *ord); + extern int prefix_cmd(struct unit *u, struct order *ord); + extern int setstealth_cmd(struct unit *u, struct order *ord); + extern int status_cmd(struct unit *u, struct order *ord); + extern int display_cmd(struct unit *u, struct order *ord); + extern int group_cmd(struct unit *u, struct order *ord); + extern int origin_cmd(struct unit *u, struct order *ord); + extern int quit_cmd(struct unit *u, struct order *ord); + extern int name_cmd(struct unit *u, struct order *ord); + extern int use_cmd(struct unit *u, struct order *ord); + extern int leave_cmd(struct unit *u, struct order *ord); + #ifdef __cplusplus } #endif diff --git a/src/gamecode/randenc.c b/src/gamecode/randenc.c index 61ecf3ac5..43d3370b2 100644 --- a/src/gamecode/randenc.c +++ b/src/gamecode/randenc.c @@ -1181,8 +1181,8 @@ static void rotting_herbs(void) for (r = regions; r; r = r->next) { unit *u; for (u = r->units; u; u = u->next) { - item **itmp = &u->items, *hbag = - *i_find(itmp, olditemtype[I_SACK_OF_CONSERVATION]); + item **itmp = &u->items; + item *hbag = *i_find(itmp, olditemtype[I_SACK_OF_CONSERVATION]); int rot_chance = rule_rot; if (hbag) diff --git a/src/gamecode/spy.c b/src/gamecode/spy.c index 76b0360b5..43eb475cb 100644 --- a/src/gamecode/spy.c +++ b/src/gamecode/spy.c @@ -19,9 +19,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include "spy.h" +#include "laws.h" /* kernel includes */ -#include #include #include #include diff --git a/src/kernel.vcxproj b/src/kernel.vcxproj deleted file mode 100644 index 24d6df48b..000000000 --- a/src/kernel.vcxproj +++ /dev/null @@ -1,297 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - - {6F104C0A-DDF5-A34B-A89C-0DC278DCEF6D} - kernel - Win32Proj - - - - StaticLibrary - MultiByte - - - StaticLibrary - MultiByte - - - - - - - - - - - - - <_ProjectFileVersion>10.0.30319.1 - $(Configuration)\$(ProjectName)\ - $(Configuration)\$(ProjectName)\ - $(Configuration)\$(ProjectName)\ - $(Configuration)\$(ProjectName)\ - - - - /MP %(AdditionalOptions) - Disabled - .;..\..\external;..\..\external\libxml2\include;%(AdditionalIncludeDirectories) - WIN32;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) - EnableFastChecks - MultiThreadedDebugDLL - true - - - Level4 - true - EditAndContinue - - - WIN32;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) - ..;.;%(AdditionalIncludeDirectories) - - - $(OutDir)kernel.lib - - - - - Full - .;..\..\external;..\..\external\libxml2\include;%(AdditionalIncludeDirectories) - WIN32;_CRT_SECURE_NO_DEPRECATE;NDEBUG;%(PreprocessorDefinitions) - true - MultiThreadedDLL - true - - - Level4 - - - - - WIN32;_CRT_SECURE_NO_DEPRECATE;NDEBUG;%(PreprocessorDefinitions) - ..;.;%(AdditionalIncludeDirectories) - - - $(OutDir)kernel.lib - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/kernel.vcxproj.filters b/src/kernel.vcxproj.filters deleted file mode 100644 index c75975ed2..000000000 --- a/src/kernel.vcxproj.filters +++ /dev/null @@ -1,625 +0,0 @@ - - - - - {0d7b749c-a7f2-4791-b356-6ae450020131} - - - {0ebbe376-a35f-44f6-97c6-9b449a839ddb} - - - {0f293992-e32e-49fb-a5f2-74686b0d042e} - - - {e12969f3-9de3-4f65-812d-1e120875a15c} - - - {c10dd4f8-3a6a-470b-8a04-bb652854e228} - - - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - triggers - - - triggers - - - triggers - - - triggers - - - triggers - - - triggers - - - triggers - - - triggers - - - triggers - - - triggers - - - triggers - - - triggers - - - triggers - - - triggers - - - items - - - items - - - items - - - items - - - items - - - items - - - items - - - items - - - modules - - - modules - - - modules - - - modules - - - modules - - - modules - - - modules - - - modules - - - modules - - - modules - - - attributes - - - attributes - - - attributes - - - attributes - - - attributes - - - attributes - - - attributes - - - attributes - - - attributes - - - attributes - - - attributes - - - attributes - - - attributes - - - attributes - - - attributes - - - attributes - - - attributes - - - attributes - - - attributes - - - attributes - - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - kernel - - - triggers - - - triggers - - - triggers - - - triggers - - - triggers - - - triggers - - - triggers - - - triggers - - - triggers - - - triggers - - - triggers - - - triggers - - - triggers - - - triggers - - - items - - - items - - - items - - - items - - - items - - - items - - - items - - - items - - - modules - - - modules - - - modules - - - modules - - - modules - - - modules - - - modules - - - modules - - - modules - - - modules - - - attributes - - - attributes - - - attributes - - - attributes - - - attributes - - - attributes - - - attributes - - - attributes - - - attributes - - - attributes - - - attributes - - - attributes - - - attributes - - - attributes - - - attributes - - - attributes - - - attributes - - - attributes - - - attributes - - - attributes - - - attributes - - - kernel - - - \ No newline at end of file diff --git a/src/kernel/alchemy.h b/src/kernel/alchemy.h index 2654c1a21..af7adf459 100644 --- a/src/kernel/alchemy.h +++ b/src/kernel/alchemy.h @@ -18,6 +18,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #ifndef H_KRNL_ALCHEMY_H #define H_KRNL_ALCHEMY_H + #ifdef __cplusplus extern "C" { #endif @@ -56,6 +57,7 @@ extern "C" { int amount, struct order *); extern void init_potions(void); + extern int get_effect(const struct unit *u, const struct potion_type *effect); extern int change_effect(struct unit *u, const struct potion_type *effect, int value); diff --git a/src/kernel/build.c b/src/kernel/build.c index 6b9746e24..a37265d23 100644 --- a/src/kernel/build.c +++ b/src/kernel/build.c @@ -69,99 +69,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* Name, MaxGroesse, MinBauTalent, Kapazitaet, {Eisen, Holz, Stein, BauSilber, * Laen, Mallorn}, UnterSilber, UnterSpezialTyp, UnterSpezial */ -static boolean CheckOverload(void) -{ - static int value = -1; - if (value < 0) { - value = get_param_int(global.parameters, "rules.check_overload", 0); - } - return value; -} - -/* test if the unit can slip through a siege undetected. - * returns 0 if siege is successful, or 1 if the building is either - * not besieged or the unit can slip through the siege due to better stealth. - */ -static int slipthru(const region * r, const unit * u, const building * b) -{ - unit *u2; - int n, o; - - /* b ist die burg, in die man hinein oder aus der man heraus will. */ - if (b == NULL || b->besieged < b->size * SIEGEFACTOR) { - return 1; - } - - /* u wird am hinein- oder herausschluepfen gehindert, wenn STEALTH <= - * OBSERVATION +2 der belagerer u2 ist */ - n = eff_skill(u, SK_STEALTH, r); - - for (u2 = r->units; u2; u2 = u2->next) { - if (usiege(u2) == b) { - - if (invisible(u, u2) >= u->number) - continue; - - o = eff_skill(u2, SK_PERCEPTION, r); - - if (o + 2 >= n) { - return 0; /* entdeckt! */ - } - } - } - return 1; -} - -int can_contact(const region * r, const unit * u, const unit * u2) -{ - - /* hier geht es nur um die belagerung von burgen */ - - if (u->building == u2->building) { - return 1; - } - - /* unit u is trying to contact u2 - unasked for contact. wenn u oder u2 - * nicht in einer burg ist, oder die burg nicht belagert ist, ist - * slipthru () == 1. ansonsten ist es nur 1, wenn man die belagerer */ - - if (slipthru(u->region, u, u->building) && slipthru(u->region, u2, u2->building)) { - return 1; - } - - return (alliedunit(u, u2->faction, HELP_GIVE)); -} - -static void contact_cmd(unit * u, order * ord, int final) -{ - /* unit u kontaktiert unit u2. Dies setzt den contact einfach auf 1 - - * ein richtiger toggle ist (noch?) nicht noetig. die region als - * parameter ist nur deswegen wichtig, weil er an getunit () - * weitergegeben wird. dies wird fuer das auffinden von tempunits in - * getnewunit () verwendet! */ - unit *u2; - region *r = u->region; - - init_tokens(ord); - skip_token(); - u2 = getunitg(r, u->faction); - - if (u2 != NULL) { - if (!can_contact(r, u, u2)) { - if (final) - cmistake(u, u->thisorder, 23, MSG_EVENT); - return; - } - usetcontact(u, u2); - } -} - -/* ------------------------------------------------------------- */ - -/* ------------------------------------------------------------- */ - -/* ------------------------------------------------------------- */ - struct building *getbuilding(const struct region *r) { building *b = findbuilding(getid()); @@ -1152,246 +1059,3 @@ void continue_ship(region * r, unit * u, int want) build_ship(u, sh, want); } -/* ------------------------------------------------------------- */ - -static boolean mayenter(region * r, unit * u, building * b) -{ - unit *u2; - if (fval(b, BLD_UNGUARDED)) - return true; - u2 = building_owner(b); - - if (u2 == NULL || ucontact(u2, u) - || alliedunit(u2, u->faction, HELP_GUARD)) - return true; - - return false; -} - -static int mayboard(const unit * u, ship * sh) -{ - unit *u2 = ship_owner(sh); - - return (!u2 || ucontact(u2, u) || alliedunit(u2, u->faction, HELP_GUARD)); -} - -int leave_cmd(unit * u, struct order *ord) -{ - region *r = u->region; - - if (fval(u, UFL_ENTER)) { - /* if we just entered this round, then we don't leave again */ - return 0; - } - - if (fval(r->terrain, SEA_REGION) && u->ship) { - if (!fval(u->race, RCF_SWIM)) { - cmistake(u, ord, 11, MSG_MOVE); - return 0; - } - if (has_horses(u)) { - cmistake(u, ord, 231, MSG_MOVE); - return 0; - } - } - if (!slipthru(r, u, u->building)) { - ADDMSG(&u->faction->msgs, msg_feedback(u, u->thisorder, "entrance_besieged", - "building", u->building)); - } else { - leave(u, true); - } - return 0; -} - -static boolean enter_ship(unit * u, struct order *ord, int id, boolean report) -{ - region *r = u->region; - ship *sh; - - /* Muß abgefangen werden, sonst könnten Schwimmer an - * Bord von Schiffen an Land gelangen. */ - if (!fval(u->race, RCF_CANSAIL) || (!fval(u->race, RCF_WALK) - && !fval(u->race, RCF_FLY))) { - cmistake(u, ord, 233, MSG_MOVE); - return false; - } - - sh = findship(id); - if (sh == NULL || sh->region != r) { - if (report) - cmistake(u, ord, 20, MSG_MOVE); - return false; - } - if (sh == u->ship) - return true; - if (!mayboard(u, sh)) { - if (report) - cmistake(u, ord, 34, MSG_MOVE); - return false; - } - if (CheckOverload()) { - int sweight, scabins; - int mweight = shipcapacity(sh); - int mcabins = sh->type->cabins; - - if (mweight > 0) { - getshipweight(sh, &sweight, &scabins); - sweight += weight(u); - if (mcabins) { - int pweight = u->number * u->race->weight; - /* weight goes into number of cabins, not cargo */ - scabins += pweight; - sweight -= pweight; - } - - if (sweight > mweight || (mcabins && (scabins > mcabins))) { - if (report) - cmistake(u, ord, 34, MSG_MOVE); - return false; - } - } - } - - if (leave(u, false)) { - u_set_ship(u, sh); - fset(u, UFL_ENTER); - } - return true; -} - -static boolean enter_building(unit * u, order * ord, int id, boolean report) -{ - region *r = u->region; - building *b; - - /* Schwimmer können keine Gebäude betreten, außer diese sind - * auf dem Ozean */ - if (!fval(u->race, RCF_WALK) && !fval(u->race, RCF_FLY)) { - if (!fval(r->terrain, SEA_REGION)) { - if (report) { - cmistake(u, ord, 232, MSG_MOVE); - } - return false; - } - } - - b = findbuilding(id); - if (b == NULL || b->region != r) { - if (report) { - cmistake(u, ord, 6, MSG_MOVE); - } - return false; - } - if (!mayenter(r, u, b)) { - if (report) { - ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "entrance_denied", - "building", b)); - } - return false; - } - if (!slipthru(r, u, b)) { - if (report) { - ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "entrance_besieged", - "building", b)); - } - return false; - } - - if (leave(u, false)) { - fset(u, UFL_ENTER); - u_set_building(u, b); - return true; - } - return false; -} - -void do_misc(region * r, int is_final_attempt) -{ - unit **uptr, *uc; - - for (uc = r->units; uc; uc = uc->next) { - order *ord; - for (ord = uc->orders; ord; ord = ord->next) { - keyword_t kwd = get_keyword(ord); - if (kwd == K_CONTACT) { - contact_cmd(uc, ord, is_final_attempt); - } - } - } - - for (uptr = &r->units; *uptr;) { - unit *u = *uptr; - order **ordp = &u->orders; - - while (*ordp) { - order *ord = *ordp; - if (get_keyword(ord) == K_ENTER) { - param_t p; - int id; - unit *ulast = NULL; - const char * s; - - init_tokens(ord); - skip_token(); - s = getstrtoken(); - p = findparam_ex(s, u->faction->locale); - id = getid(); - - switch (p) { - case P_BUILDING: - case P_GEBAEUDE: - if (u->building && u->building->no == id) - break; - if (enter_building(u, ord, id, is_final_attempt)) { - unit *ub; - for (ub = u; ub; ub = ub->next) { - if (ub->building == u->building) { - ulast = ub; - } - } - } - break; - - case P_SHIP: - if (u->ship && u->ship->no == id) - break; - if (enter_ship(u, ord, id, is_final_attempt)) { - unit *ub; - ulast = u; - for (ub = u; ub; ub = ub->next) { - if (ub->ship == u->ship) { - ulast = ub; - } - } - } - break; - - default: - if (is_final_attempt) { - cmistake(u, ord, 79, MSG_MOVE); - } - } - if (ulast != NULL) { - /* Wenn wir hier angekommen sind, war der Befehl - * erfolgreich und wir löschen ihn, damit er im - * zweiten Versuch nicht nochmal ausgeführt wird. */ - *ordp = ord->next; - ord->next = NULL; - free_order(ord); - - if (ulast != u) { - /* put u behind ulast so it's the last unit in the building */ - *uptr = u->next; - u->next = ulast->next; - ulast->next = u; - } - break; - } - } - if (*ordp == ord) - ordp = &ord->next; - } - if (*uptr == u) - uptr = &u->next; - } -} diff --git a/src/kernel/build.h b/src/kernel/build.h index 5407034bf..20577da8e 100644 --- a/src/kernel/build.h +++ b/src/kernel/build.h @@ -64,9 +64,6 @@ extern "C" { extern int destroy_cmd(struct unit *u, struct order *ord); extern int leave_cmd(struct unit *u, struct order *ord); - extern int can_contact(const struct region *r, const struct unit *u, - const struct unit *u2); - void do_siege(struct region *r); void build_road(struct region *r, struct unit *u, int size, direction_t d); void create_ship(struct region *r, struct unit *u, @@ -76,8 +73,6 @@ extern "C" { struct building *getbuilding(const struct region *r); struct ship *getship(const struct region *r); - void do_misc(struct region *r, int is_final_attempt); - void reportevent(struct region *r, char *s); void shash(struct ship *sh); diff --git a/src/kernel/faction.c b/src/kernel/faction.c old mode 100644 new mode 100755 index 7cde125de..009922bca --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -284,19 +284,22 @@ void destroyfaction(faction * f) unit *u = f->units; faction *ff; - if (!f->alive) + if (!f->alive) { return; + } fset(f, FFL_QUIT); - spellbook_clear(f->spellbook); - free(f->spellbook); - f->spellbook = 0; - + if (f->spellbook) { + spellbook_clear(f->spellbook); + free(f->spellbook); + f->spellbook = 0; + } while (f->battles) { struct bmsg *bm = f->battles; f->battles = bm->next; - if (bm->msgs) + if (bm->msgs) { free_messagelist(bm->msgs); + } free(bm); } diff --git a/src/kernel/group.c b/src/kernel/group.c old mode 100644 new mode 100755 index c61966968..a0b5821c5 --- a/src/kernel/group.c +++ b/src/kernel/group.c @@ -136,6 +136,17 @@ void free_group(group * g) free(g); } +group * get_group(const struct unit *u) +{ + if (fval(u, UFL_GROUP)) { + attrib * a = a_find(u->attribs, &at_group); + if (a) { + return (group *) a->data.v; + } + } + return 0; +} + void set_group(struct unit *u, struct group *g) { attrib *a = NULL; diff --git a/src/kernel/group.h b/src/kernel/group.h old mode 100644 new mode 100755 index bccbf4540..14dd119cd --- a/src/kernel/group.h +++ b/src/kernel/group.h @@ -40,6 +40,7 @@ extern "C" { extern struct attrib_type at_group; /* attribute for units assigned to a group */ extern boolean join_group(struct unit *u, const char *name); extern void set_group(struct unit *u, struct group *g); + extern struct group * get_group(const struct unit *u); extern void free_group(struct group *g); extern void write_groups(struct storage *F, struct group *g); diff --git a/src/kernel/move.c b/src/kernel/move.c index 5c1f7b9fc..993125b43 100644 --- a/src/kernel/move.c +++ b/src/kernel/move.c @@ -704,6 +704,7 @@ static float damage_drift(void) static void drifting_ships(region * r) { direction_t d; + if (get_param_int(global.parameters, "rules.ship.drifting", 1)==0) return; if (fval(r->terrain, SEA_REGION)) { ship **shp = &r->ships; @@ -1718,7 +1719,7 @@ sail(unit * u, order * ord, boolean move_on_land, region_list ** routep) assert(sh == u->ship || !"ship has sunk, but we didn't notice it"); - if (fval(next_point->terrain, FORBIDDEN_REGION)) { + if (fval(next_point->terrain, FORBIDDEN_REGION)||fval(next_point,RF_BLOCKED)) { ADDMSG(&f->msgs, msg_message("sailforbidden", "ship region", sh, next_point)); break; diff --git a/src/lua-bindings.vcxproj b/src/lua-bindings.vcxproj deleted file mode 100644 index 5714a1cbd..000000000 --- a/src/lua-bindings.vcxproj +++ /dev/null @@ -1,121 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - - {75501170-51C2-E641-BA8B-EDC008184192} - lua-bindings - Win32Proj - - - - StaticLibrary - MultiByte - - - StaticLibrary - MultiByte - - - - - - - - - - - - - <_ProjectFileVersion>10.0.30319.1 - $(Configuration)\$(ProjectName)\ - $(Configuration)\$(ProjectName)\ - $(Configuration)\$(ProjectName)\ - $(Configuration)\$(ProjectName)\ - - - - /MP %(AdditionalOptions) - Disabled - .;../../external;../../external/lua/src;../../external/tolua/include;..\..\external\pdcurses;..\..\external\libxml2\include;%(AdditionalIncludeDirectories) - WIN32;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) - EnableFastChecks - MultiThreadedDebugDLL - true - - - Level4 - true - EditAndContinue - - - WIN32;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) - .;%(AdditionalIncludeDirectories) - - - $(OutDir)lua-bindings.lib - - - - - Full - .;../../external;../../external/lua/src;../../external/tolua/include;..\..\external\pdcurses;..\..\external\libxml2\include;%(AdditionalIncludeDirectories) - WIN32;_CRT_SECURE_NO_DEPRECATE;NDEBUG;%(PreprocessorDefinitions) - true - MultiThreadedDLL - true - - - Level4 - - - - - WIN32;_CRT_SECURE_NO_DEPRECATE;NDEBUG;%(PreprocessorDefinitions) - .;%(AdditionalIncludeDirectories) - - - $(OutDir)lua-bindings.lib - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/lua-bindings.vcxproj.filters b/src/lua-bindings.vcxproj.filters deleted file mode 100644 index 83b65c358..000000000 --- a/src/lua-bindings.vcxproj.filters +++ /dev/null @@ -1,92 +0,0 @@ - - - - - {1a17299b-610f-40df-864f-84b37b67ebe7} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {5135c52b-b087-4aab-8d89-2b06da54e8e7} - h;hpp;hxx;hm;inl;inc;xsd - - - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - \ No newline at end of file diff --git a/src/util.vcxproj b/src/util.vcxproj deleted file mode 100644 index a0967f595..000000000 --- a/src/util.vcxproj +++ /dev/null @@ -1,162 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - - {F70CFB27-8A2F-E447-B452-4E1C590EDA6D} - util - Win32Proj - - - - StaticLibrary - MultiByte - - - StaticLibrary - MultiByte - - - - - - - - - - - - - <_ProjectFileVersion>10.0.30319.1 - $(Configuration)\$(ProjectName)\ - $(Configuration)\$(ProjectName)\ - $(Configuration)\$(ProjectName)\ - $(Configuration)\$(ProjectName)\ - - - - /MP %(AdditionalOptions) - Disabled - .;../../external;../../external/lua/src;../../external/pdcurses;..\..\external\libxml2\include;%(AdditionalIncludeDirectories) - WIN32;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) - EnableFastChecks - MultiThreadedDebugDLL - true - - - Level4 - true - EditAndContinue - - - WIN32;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) - ..;.;%(AdditionalIncludeDirectories) - - - $(OutDir)util.lib - - - - - Full - .;../../external;../../external/lua/src;../../external/pdcurses;..\..\external\libxml2\include;%(AdditionalIncludeDirectories) - WIN32;_CRT_SECURE_NO_DEPRECATE;NDEBUG;%(PreprocessorDefinitions) - true - MultiThreadedDLL - true - - - Level4 - - - - - WIN32;_CRT_SECURE_NO_DEPRECATE;NDEBUG;%(PreprocessorDefinitions) - ..;.;%(AdditionalIncludeDirectories) - - - $(OutDir)util.lib - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/util.vcxproj.filters b/src/util.vcxproj.filters deleted file mode 100644 index 43fb1d700..000000000 --- a/src/util.vcxproj.filters +++ /dev/null @@ -1,215 +0,0 @@ - - - - - {93caffaa-508e-4e78-b1ba-5a8d6aa4ab9a} - h;hpp;hxx;hm;inl;inc;xsd - - - {77dd9146-7564-475b-a364-b1610046b1bb} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Header Files - - - Source Files - - - Source Files - - - Source Files - - - \ No newline at end of file