From ebe0ecaded8ff689da328910ab24c836591e78d2 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Sun, 30 Jun 2013 20:38:44 +0000 Subject: [PATCH] Lunatic: add actor methods allowing overriding action delay and move hvel/vvel. Add testing code for an example actor 1275 (newspaper) to test.elua. git-svn-id: https://svn.eduke32.com/eduke32@3918 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/game.c | 1 + polymer/eduke32/source/gameexec.c | 1 + polymer/eduke32/source/lunatic/control.lua | 2 +- polymer/eduke32/source/lunatic/defs.ilua | 14 +++++++++++ polymer/eduke32/source/lunatic/test.elua | 27 +++++++++++++++++++++- 5 files changed, 43 insertions(+), 2 deletions(-) diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index 4ca3809d9..63f70f974 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -7661,6 +7661,7 @@ PALONLY: #else t->picnum += k + startframe + l*t_data3; #endif + // XXX: t->picnum can be out-of-bounds by bad user code. if (l > 0) while (tilesizx[t->picnum] == 0 && t->picnum > 0) diff --git a/polymer/eduke32/source/gameexec.c b/polymer/eduke32/source/gameexec.c index e3037c8a3..2f76dec67 100644 --- a/polymer/eduke32/source/gameexec.c +++ b/polymer/eduke32/source/gameexec.c @@ -598,6 +598,7 @@ GAMEEXEC_STATIC void VM_Move(void) vm.g_t[0]++; + // If the move ID is zero, or the movflags are 0 if (vm.g_t[1] == 0 || a == 0) { if (deadflag || (actor[vm.g_i].bpos.x != vm.g_sp->x) || (actor[vm.g_i].bpos.y != vm.g_sp->y)) diff --git a/polymer/eduke32/source/lunatic/control.lua b/polymer/eduke32/source/lunatic/control.lua index fd2a57218..98d61f6da 100644 --- a/polymer/eduke32/source/lunatic/control.lua +++ b/polymer/eduke32/source/lunatic/control.lua @@ -85,7 +85,7 @@ local function def_action_or_move(what, tab) lastid[what] = lastid[what]-1 -- Pass args table to ffi.new, which can take either: a table with numeric - -- indices, or a table with key-value pairs. + -- indices, or a table with key-value pairs, *but not in combination*. -- See http://luajit.org/ext_ffi_semantics.html#init_table return am_ctype[what](lastid[what], tab) end diff --git a/polymer/eduke32/source/lunatic/defs.ilua b/polymer/eduke32/source/lunatic/defs.ilua index 4178cf01f..643050328 100644 --- a/polymer/eduke32/source/lunatic/defs.ilua +++ b/polymer/eduke32/source/lunatic/defs.ilua @@ -982,6 +982,11 @@ local actor_mt = { return ffi.cast(actor_ptr_ct, a).t_data[2] end, + -- Override action delay. The action ID is kept. + set_action_delay = function(a, delay) + ffi.cast(actor_ptr_ct, a).ac.delay = delay + end, + -- move set_move = function(a, mov, movflags) a = ffi.cast(actor_ptr_ct, a) @@ -1017,6 +1022,15 @@ local actor_mt = { end end, + -- Override velocity, keeping move ID. + set_hvel = function(a, hvel) + ffi.cast(actor_ptr_ct, a).mv.hvel = hvel + end, + + set_vvel = function(a, vvel) + ffi.cast(actor_ptr_ct, a).mv.vvel = vvel + end, + -- ai set_ai = function(a, ai) local oa = a diff --git a/polymer/eduke32/source/lunatic/test.elua b/polymer/eduke32/source/lunatic/test.elua index 466ba34cf..30f4e6405 100644 --- a/polymer/eduke32/source/lunatic/test.elua +++ b/polymer/eduke32/source/lunatic/test.elua @@ -395,9 +395,12 @@ local hs = stat.new() local con = require("con") local AC, MV = con.AC, con.MV +local CAC, CMV, CAI = require("CON.ACTION"), require("CON.MOVE"), require("CON.AI") +assert(CAC); assert(CMV); assert(CAI) + local AC, MV = {}, {} -AC.TROOPSTAND = con.action{0,1,5,1,1} +AC.TROOPSTAND = assert(CAC.ATROOPSTAND) -- or con.action{0,1,5,1,1} AC.TROOPFLINTCH = con.action{50, 1, 1, 1, 6} MV.SHRUNKVELS = con.move{hvel=32} con.ai(AC.TROOPFLINTCH, MV.SHRUNKVELS, 0) -- unused; TODO: test @@ -450,9 +453,31 @@ gameactor con.killit() end end + + if (actr:has_action(CAC.ATROOPWALKING)) then + if (actr:get_count() % 50 == 0) then + spr.hitag = bit.bxor(spr.hitag, actor.MOVFLAGS.spin) + end + end end } +gameactor +{ + 1275, -- newspaper, E4L6 sprite #513 + + -- XXX: I want to write "{0, 4, delay=20}" + action = con.action{0, 4, 1, 1, 20}, + move = con.move{}, -- so that the ID is nonzero + + func = function(aci) + local delay = math.sin(0.1 * 2*math.pi*gv.totalclock/120) + actor[aci]:set_action_delay(20 + 10*delay) + actor[aci]:set_hvel(50*delay) + sprite[aci].hitag = actor.MOVFLAGS.geth + end, +} + gameevent { "DISPLAYROOMS",