From 648de4d36cf3999c16dfe4d26f3a5deef5d3aa9e Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 17 Jun 2012 17:24:23 -0700 Subject: [PATCH] Binding CAST, ENTER, CONTACT to Lua --- scripts/tests/bindings.lua | 3 + scripts/tests/orders.lua | 26 ++++++++ src/bindings/bind_process.c | 15 +++++ src/bindings/bind_process.h | 3 + src/bindings/process.pkg | 3 + src/gamecode/laws.c | 114 ++++++++++++++++++------------------ src/gamecode/laws.h | 4 +- 7 files changed, 109 insertions(+), 59 deletions(-) diff --git a/scripts/tests/bindings.lua b/scripts/tests/bindings.lua index bad3d454d..fc325c608 100755 --- a/scripts/tests/bindings.lua +++ b/scripts/tests/bindings.lua @@ -38,6 +38,9 @@ function test_process() assert_equal("function", _G.type(eressea.process.restack)) assert_equal("function", _G.type(eressea.process.set_spells)) assert_equal("function", _G.type(eressea.process.set_help)) + assert_equal("function", _G.type(eressea.process.contact)) + assert_equal("function", _G.type(eressea.process.enter)) + assert_equal("function", _G.type(eressea.process.magic)) end function test_settings() diff --git a/scripts/tests/orders.lua b/scripts/tests/orders.lua index 0e14e3653..076e27be6 100755 --- a/scripts/tests/orders.lua +++ b/scripts/tests/orders.lua @@ -190,3 +190,29 @@ function test_process_renumber() assert_equal(666, u.id) end +function test_process_enter() + b = _G.building.create(r, default_building) + u:add_order("BETRETEN GEBAEUDE " .. _G.itoa36(b.id)) + eressea.process.enter(1) + assert_equal(b, u.building) +end + +function test_process_restack() + eressea.process.restack() +end + +function test_process_setspells() + eressea.process.set_spells() +end + +function test_process_help() + eressea.process.set_help() +end + +function test_process_contact() + eressea.process.contact() +end + +function test_process_magic() + eressea.process.magic() +end diff --git a/src/bindings/bind_process.c b/src/bindings/bind_process.c index ae25eb109..5010bf2f9 100755 --- a/src/bindings/bind_process.c +++ b/src/bindings/bind_process.c @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -198,6 +199,20 @@ void process_sethelp(void) { process_cmd(K_ALLY, ally_cmd, 0); } +void process_contact(void) { + process_cmd(K_CONTACT, contact_cmd, 0); +} + +void process_magic(void) { + magic(); +} + +void process_enter(int final) { + region * r; + for (r=regions; r; r=r->next) { + do_enter(r, final); + } +} void process_maintenance(void) { region * r; diff --git a/src/bindings/bind_process.h b/src/bindings/bind_process.h index b12cd0c24..7fd9a1508 100755 --- a/src/bindings/bind_process.h +++ b/src/bindings/bind_process.h @@ -30,6 +30,9 @@ void process_renumber(void); void process_restack(void); void process_setspells(void); void process_sethelp(void); +void process_contact(void); +void process_enter(int final); +void process_magic(void); #ifdef __cplusplus } diff --git a/src/bindings/process.pkg b/src/bindings/process.pkg index 5ffab96d2..81a189633 100755 --- a/src/bindings/process.pkg +++ b/src/bindings/process.pkg @@ -27,5 +27,8 @@ module eressea { void process_restack @ restack(void); /* SORT */ void process_setspells @ set_spells(void); /* COMBATSPELL */ void process_sethelp @ set_help(void); /* HELP */ + void process_contact @ contact(void); /* CONTACT */ + void process_enter @ enter(int message); /* ENTER */ + void process_magic @ magic(void); /* CAST */ } } diff --git a/src/gamecode/laws.c b/src/gamecode/laws.c index d1fb4a70a..1d925f98f 100755 --- a/src/gamecode/laws.c +++ b/src/gamecode/laws.c @@ -135,8 +135,7 @@ static void checkorders(void) { faction *f; - if (verbosity >= 1) - puts(" - Warne spaete Spieler..."); + log_info(" - Warne spaete Spieler..."); for (f = factions; f; f = f->next) if (!is_monsters(f) && turn - f->lastorders == NMRTimeout() - 1) ADDMSG(&f->msgs, msg_message("turnreminder", "")); @@ -966,8 +965,7 @@ void demographics(void) remove_empty_units(); - if (verbosity >= 1) - puts(" - Einwanderung..."); + log_info(" - Einwanderung..."); for (r = regions; r; r = r->next) { if (r->land && r->land->newpeasants) { int rp = rpeasants(r) + r->land->newpeasants; @@ -1078,7 +1076,7 @@ int can_contact(const region * r, const unit * u, const unit * u2) { return (alliedunit(u, u2->faction, HELP_GIVE)); } -void contact_cmd(unit * u, order * ord, int final) +int contact_cmd(unit * u, order * ord) { /* unit u kontaktiert unit u2. Dies setzt den contact einfach auf 1 - * ein richtiger toggle ist (noch?) nicht noetig. die region als @@ -1094,13 +1092,12 @@ void contact_cmd(unit * u, order * ord, int final) if (u2 != NULL) { if (!can_contact(r, u, u2)) { - if (final) { - cmistake(u, u->thisorder, 23, MSG_EVENT); - } - return; + cmistake(u, u->thisorder, 23, MSG_EVENT); + return -1; } usetcontact(u, u2); } + return 0; } int leave_cmd(unit * u, struct order *ord) @@ -1316,19 +1313,23 @@ int enter_building(unit * u, order * ord, int id, int report) return 0; } -static void do_misc(region * r, int is_final_attempt) +static void do_contact(region * r) { - unit **uptr, *uc; - - for (uc = r->units; uc; uc = uc->next) { + unit * u; + for (u = r->units; u; u = u->next) { order *ord; - for (ord = uc->orders; ord; ord = ord->next) { + for (ord = u->orders; ord; ord = ord->next) { keyword_t kwd = get_keyword(ord); if (kwd == K_CONTACT) { - contact_cmd(uc, ord, is_final_attempt); + contact_cmd(u, ord); } } } +} + +void do_enter(struct region *r, int is_final_attempt) +{ + unit **uptr; for (uptr = &r->units; *uptr;) { unit *u = *uptr; @@ -1407,38 +1408,6 @@ static void do_misc(region * r, int is_final_attempt) } } -void quit(void) -{ - faction **fptr = &factions; - while (*fptr) { - faction *f = *fptr; - if (f->flags & FFL_QUIT) { - if (EnhancedQuit()) { - /* this doesn't work well (use object_name()) */ - attrib *a = a_find(f->attribs, &at_object); - if (a) { - variant var; - object_type type; - var.i = 0; - object_get(a, &type, &var); - assert(var.i && type == TINTEGER); - if (var.i) { - int f2_id = var.i; - faction *f2 = findfaction(f2_id); - - assert(f2_id > 0); - assert(f2 != NULL); - transfer_faction(f, f2); - } - } - } - destroyfaction(f); - } - if (*fptr == f) - fptr = &f->next; - } -} - int dropouts[2]; int *age = NULL; @@ -1517,9 +1486,39 @@ static void remove_idle_players(void) } } } +} - if (verbosity >= 1) - puts(" - beseitige leere Einheiten und leere Parteien..."); +void quit(void) +{ + faction **fptr = &factions; + while (*fptr) { + faction *f = *fptr; + if (f->flags & FFL_QUIT) { + if (EnhancedQuit()) { + /* this doesn't work well (use object_name()) */ + attrib *a = a_find(f->attribs, &at_object); + if (a) { + variant var; + object_type type; + var.i = 0; + object_get(a, &type, &var); + assert(var.i && type == TINTEGER); + if (var.i) { + int f2_id = var.i; + faction *f2 = findfaction(f2_id); + + assert(f2_id > 0); + assert(f2 != NULL); + transfer_faction(f, f2); + } + } + } + destroyfaction(f); + } + if (*fptr == f) + fptr = &f->next; + } + remove_idle_players(); remove_empty_units(); } @@ -4416,12 +4415,12 @@ void do_siege(region * r) static void enter_1(region * r) { - do_misc(r, 0); + do_enter(r, 0); } static void enter_2(region * r) { - do_misc(r, 1); + do_enter(r, 1); } static void maintain_buildings_1(region * r) @@ -4492,9 +4491,10 @@ void init_processor(void) p += 10; add_proc_global(p, &age_factions, "Parteienalter++"); add_proc_order(p, K_MAIL, &mail_cmd, 0, "Botschaften"); + add_proc_order(p, K_CONTACT, &contact_cmd, 0, "Kontaktieren"); p += 10; /* all claims must be done before we can USE */ - add_proc_region(p, &enter_1, "Kontaktieren & Betreten (1. Versuch)"); + add_proc_region(p, &enter_1, "Betreten (1. Versuch)"); add_proc_order(p, K_USE, &use_cmd, 0, "Benutzen"); if (!global.disabled[K_GM]) { @@ -4515,7 +4515,7 @@ void init_processor(void) } p += 10; /* can't allow reserve before siege (weapons) */ - add_proc_region(p, &enter_1, "Kontaktieren & Betreten (2. Versuch)"); + add_proc_region(p, &enter_1, "Betreten (2. Versuch)"); add_proc_order(p, K_RESERVE, &reserve_cmd, 0, "Reservieren"); add_proc_order(p, K_CLAIM, &claim_cmd, 0, NULL); add_proc_unit(p, &follow_unit, "Folge auf Einheiten setzen"); @@ -4532,7 +4532,6 @@ void init_processor(void) p += 10; /* QUIT fuer sich alleine */ add_proc_global(p, quit, "Sterben"); - add_proc_global(p, remove_idle_players, "remove idle players"); if (!global.disabled[K_CAST]) { p += 10; @@ -4553,7 +4552,7 @@ void init_processor(void) add_proc_postregion(p, &split_allocations, "Produktion II"); p += 10; - add_proc_region(p, &enter_2, "Kontaktieren & Betreten (3. Versuch)"); + add_proc_region(p, &enter_2, "Betreten (3. Versuch)"); p += 10; add_proc_region(p, &sinkships, "Schiffe sinken"); @@ -4615,8 +4614,7 @@ void processorders(void) do_markets(); } - if (verbosity >= 1) - puts(" - Attribute altern"); + log_info(" - Attribute altern"); ageing(); remove_empty_units(); @@ -4640,7 +4638,7 @@ int writepasswd(void) F = cfopen(zText, "w"); if (F) { faction *f; - puts("writing passwords..."); + log_info("writing passwords..."); for (f = factions; f; f = f->next) { fprintf(F, "%s:%s:%s:%s:%u\n", diff --git a/src/gamecode/laws.h b/src/gamecode/laws.h index 5a6664764..3dd492153 100755 --- a/src/gamecode/laws.h +++ b/src/gamecode/laws.h @@ -48,7 +48,6 @@ extern "C" { 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); @@ -56,6 +55,8 @@ extern "C" { extern void restack_units(void); extern void update_long_order(struct unit *u); extern void sinkships(struct region * r); + extern void do_enter(struct region *r, int is_final_attempt); + 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); @@ -76,6 +77,7 @@ extern "C" { extern int promotion_cmd(struct unit *u, struct order *ord); extern int renumber_cmd(struct unit *u, struct order *ord); extern int combatspell_cmd(struct unit *u, struct order *ord); + extern int contact_cmd(struct unit *u, struct order *ord); #ifdef __cplusplus }