From d43cfe623245418a66310425ba02c6a6b05b3644 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Thu, 13 Jun 2013 17:11:09 +0000 Subject: [PATCH] Lunatic savegames: store g_playerWeapon[][], fix 'require' with submodules. git-svn-id: https://svn.eduke32.com/eduke32@3883 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/lunatic/bcheck.lua | 6 ++++++ polymer/eduke32/source/lunatic/defs.ilua | 6 +++++- polymer/eduke32/source/lunatic/test.elua | 17 ++++++++++++----- polymer/eduke32/source/savegame.c | 4 +++- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/polymer/eduke32/source/lunatic/bcheck.lua b/polymer/eduke32/source/lunatic/bcheck.lua index 41471a7ab..f6b80a0cf 100644 --- a/polymer/eduke32/source/lunatic/bcheck.lua +++ b/polymer/eduke32/source/lunatic/bcheck.lua @@ -1,6 +1,7 @@ -- Bound-checking functions for engine and game "things". local ffiC = require("ffi").C +local type = type local error = error local con_lang = require("con_lang") @@ -97,5 +98,10 @@ function bcheck.top_level(funcname) end end +function bcheck.number(val) + if (type(val)~="number") then + error("invalid argument: must be a number", 3) + end +end return bcheck diff --git a/polymer/eduke32/source/lunatic/defs.ilua b/polymer/eduke32/source/lunatic/defs.ilua index b9d14474b..30a16d2f6 100644 --- a/polymer/eduke32/source/lunatic/defs.ilua +++ b/polymer/eduke32/source/lunatic/defs.ilua @@ -178,6 +178,7 @@ local check_sector_idx, check_tile_idx = bcheck.sector_idx, bcheck.tile_idx local check_sprite_idx = bcheck.sprite_idx local check_weapon_idx, check_inventory_idx = bcheck.weapon_idx, bcheck.inventory_idx local check_sound_idx = bcheck.sound_idx +local check_number = bcheck.number bcarray.new("int16_t", 64, "loogie", "int16_x_64") -- TODO: randomize member names bcarray.new("int16_t", ffiC.MAX_WEAPONS, "weapon", "int16_x_MAX_WEAPONS", WEAPON_NAMES) @@ -1082,6 +1083,8 @@ local weapondata_mt = { -- Set to 'true' if we set a tile or sound member. local didit = false + check_number(val) + if (string.match(member, "sound")) then if (val < 0) then val = 0 -- Set to 0 if oob (e.g. CrackDown). @@ -1896,7 +1899,8 @@ do -- XXX: System gamevars? for modname, modvars in pairs(module_gamevars) do - sb:addrawf("M=require%q", modname) + -- NOTE: when emitting 'require' code, reverse '.' -> '/' substitution. + sb:addrawf("M=require%q", modname:gsub("/",".")) for i=1,#modvars do local varname = modvars[i] -- Serialize gamevar named 'varname' from module named 'modname'. diff --git a/polymer/eduke32/source/lunatic/test.elua b/polymer/eduke32/source/lunatic/test.elua index ba71deed8..b9c152c14 100644 --- a/polymer/eduke32/source/lunatic/test.elua +++ b/polymer/eduke32/source/lunatic/test.elua @@ -221,6 +221,8 @@ gameevent end } +local D = require("CON.DEFS") + -- test event chaining gameevent { @@ -232,8 +234,13 @@ gameevent local ps = player[playeri] print("\n--- I'm first!") -- DBG_.oom() - ps.weapon.PISTOL.shoots = 2605 -- RPG - ps.weapon[gv.PISTOL_WEAPON].firesound = 351 -- thunder + local pistol = ps.weapon.PISTOL + if (pistol.shoots ~= D.RPG) then + pistol.shoots = D.RPG + else + pistol.shoots = D.SHOTSPARK1 + end + ps.weapon[gv.PISTOL_WEAPON].firesound = D.LIGHTNING_SLAP -- XXX: provide either named constants or methods? ps.pipebombControl = 2 @@ -307,7 +314,7 @@ gameevent player[0].weapon.SHOTGUN.shoots = 1653 local proj = projectile[1653] proj.drop = 0 - proj:set_trail(2329) -- SMALLSMOKE + proj:set_trail(D.SMALLSMOKE) t = gv.gethitickms() local N=1 @@ -333,6 +340,7 @@ gameevent -- N=100: about 160 us * 100 = about 16 ms -- Make the DUKECAR in E1L1 into a zombie actor (temporarily) + -- NOTE: Use static value (not the one from 'D'). if (sprite[24].picnum==2491) then sprite.changestat(24, actor.STAT.ZOMBIEACTOR) end @@ -392,7 +400,6 @@ con.ai("AITEMP", "TROOPFLINTCH", "SHRUNKVELS", 0) local TROOPSTRENGTH = 30 -local D = require("CON.DEFS") local AF = actor.FLAGS local CS = sprite.CSTAT @@ -505,7 +512,7 @@ gameevent function(aci) local tspr = atsprite[aci] - if (tspr:getspr().picnum==1680) then + if (tspr:getspr().picnum==D.LIZTROOP) then local tspr2 = tspr:dup() if (tspr2) then tspr2.x = tspr2.x + 512*math.cos(gv.totalclock/60) diff --git a/polymer/eduke32/source/savegame.c b/polymer/eduke32/source/savegame.c index 0e1ca1e59..3805325fd 100644 --- a/polymer/eduke32/source/savegame.c +++ b/polymer/eduke32/source/savegame.c @@ -1038,7 +1038,9 @@ static const dataspec_t svgm_anmisc[] = { DS_NOCHK|DS_DYNAMIC|DS_CNT(g_numQuoteRedefinitions), &savegame_quoteredefs, MAXQUOTELEN, (intptr_t)&g_numQuoteRedefinitions }, { DS_NOCHK|DS_LOADFN, (void *)&sv_quoteredefload, 0, 1 }, { DS_NOCHK|DS_SAVEFN|DS_LOADFN, (void *)&sv_postquoteredef, 0, 1 }, - +#ifdef LUNATIC + { 0, g_playerWeapon, sizeof(weapondata_t), MAXPLAYERS*MAX_WEAPONS }, +#endif { DS_SAVEFN, (void *)&sv_restsave, 0, 1 }, { 0, savegame_restdata, 1, sizeof(savegame_restdata) }, // sz/cnt swapped for kdfread { DS_LOADFN, (void *)&sv_restload, 0, 1 },