Lunatic: retire gv.*_WEAPON and gv.GET_* for gv.WEAPON.* and gv.GET.*.

git-svn-id: https://svn.eduke32.com/eduke32@4030 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2013-08-23 17:01:09 +00:00
parent 0a06ca29f2
commit 55a3cda9e1
4 changed files with 53 additions and 42 deletions

View file

@ -54,6 +54,9 @@ local check_sound_idx = bcheck.sound_idx
local check_number = bcheck.number
local check_type = bcheck.type
local lprivate = require("lprivate")
local GET, WEAPON = lprivate.GET, lprivate.WEAPON
local OUR_REQUIRE_STRING = [[
local _con=require'con'
local _ga,_av,_pv=_con._gamearray,_con.actorvar,_con.playervar
@ -587,7 +590,7 @@ function _tossweapon(pli) -- P_DropWeapon replacement
if (krandand(1) ~= 0) then
spawn(ffiC.WeaponPickupSprites[cw], ps.i)
elseif (cw==ffiC.RPG_WEAPON or cw==ffiC.HANDBOMB_WEAPON) then
elseif (cw==WEAPON.RPG or cw==WEAPON.HANDBOMB) then
if (D.EXPLOSION2 ~= nil) then
spawn(D.EXPLOSION2, ps.i)
end
@ -606,7 +609,7 @@ end
local function P_AddWeaponAmmoCommon(ps, weap, amount)
P_AddAmmo(ps, weap, amount)
if (ps.curr_weapon==ffiC.KNEE_WEAPON and ps:has_weapon(weap)) then
if (ps.curr_weapon==WEAPON.KNEE and ps:has_weapon(weap)) then
CF.P_AddWeaponMaybeSwitchI(ps.weapon._p, weap);
end
end
@ -1112,17 +1115,17 @@ end
local PALBITS = { [0]=1, [21]=2, [23]=4 }
local ICONS = {
[ffiC.GET_FIRSTAID] = 1, -- ICON_FIRSTAID
[ffiC.GET_STEROIDS] = 2,
[ffiC.GET_HOLODUKE] = 3,
[ffiC.GET_JETPACK] = 4,
[ffiC.GET_HEATS] = 5,
[ffiC.GET_SCUBA] = 6,
[ffiC.GET_BOOTS] = 7,
[GET.FIRSTAID] = 1, -- ICON_FIRSTAID
[GET.STEROIDS] = 2,
[GET.HOLODUKE] = 3,
[GET.JETPACK] = 4,
[GET.HEATS] = 5,
[GET.SCUBA] = 6,
[GET.BOOTS] = 7,
}
function _addinventory(ps, inv, amount, i)
if (inv == ffiC.GET_ACCESS) then
if (inv == GET.ACCESS) then
local pal = sprite[i].pal
if (PALBITS[pal]) then
ps.got_access = bor(ps.got_access, PALBITS[pal])
@ -1132,7 +1135,7 @@ function _addinventory(ps, inv, amount, i)
ps.inven_icon = ICONS[inv]
end
if (inv == ffiC.GET_SHIELD) then
if (inv == GET.SHIELD) then
amount = math.min(ps.max_shield_amount, amount)
end
-- NOTE: this is more permissive than CON, e.g. allows
@ -1142,9 +1145,9 @@ function _addinventory(ps, inv, amount, i)
end
function _checkpinventory(ps, inv, amount, i)
if (inv==ffiC.GET_SHIELD) then
if (inv==GET.SHIELD) then
return ps.inv_amount[inv] ~= ps.max_shield_amount
elseif (inv==ffiC.GET_ACCESS) then
elseif (inv==GET.ACCESS) then
local palbit = PALBITS[sprite[i].pal]
return palbit and (band(ps.got_access, palbit)~=0)
else
@ -1153,13 +1156,13 @@ function _checkpinventory(ps, inv, amount, i)
end
local INV_SELECTION_ORDER = {
ffiC.GET_FIRSTAID,
ffiC.GET_STEROIDS,
ffiC.GET_JETPACK,
ffiC.GET_HOLODUKE,
ffiC.GET_HEATS,
ffiC.GET_SCUBA,
ffiC.GET_BOOTS,
GET.FIRSTAID,
GET.STEROIDS,
GET.JETPACK,
GET.HOLODUKE,
GET.HEATS,
GET.SCUBA,
GET.BOOTS,
}
-- checkavailinven CON command
@ -1618,7 +1621,7 @@ function _ifp(flags, pli, aci)
return true
elseif (band(l,256)~=0 and vel <= -8 and holdskey(pli, "RUN")) then
return true
elseif (band(l,512)~=0 and (ps.quick_kick > 0 or (ps.curr_weapon == ffiC.KNEE_WEAPON and ps.kickback_pic > 0))) then
elseif (band(l,512)~=0 and (ps.quick_kick > 0 or (ps.curr_weapon == 0 and ps.kickback_pic > 0))) then
return true
elseif (band(l,1024)~=0 and sprite[ps.i].xrepeat < 32) then
return true

View file

@ -106,18 +106,14 @@ local WEAPON_NAMES = {
}
---- game structs ----
lprivate.GET = defs_c.conststruct(INV_NAMES)
lprivate.WEAPON = defs_c.conststruct(WEAPON_NAMES)
ffi.cdef([[
enum dukeinv_t {
]].. "GET_"..table.concat(INV_NAMES, ",GET_") ..[[,
GET_MAX
};
enum dukeweapon_t {
]].. table.concat(WEAPON_NAMES, "_WEAPON,").."_WEAPON," ..[[
MAX_WEAPONS
};
enum {
GET_MAX = 11,
MAX_WEAPONS = 12,
MAXPLAYERS = 16,
GTICSPERSEC = 30, // The real number of movement updates per second
};
@ -585,7 +581,7 @@ ffi.cdef[[
const int32_t screenpeek;
hudweapon_t hudweap;
int32_t g_logoFlags;
int32_t g_RETURN; // deprecated from Lua
int32_t g_RETURN;
]]
-- INTERNAL VARIABLES/FUNCTIONS
@ -1492,6 +1488,9 @@ gv_access.REND = defs_c.conststruct
POLYMER = 4,
}
gv_access.WEAPON = lprivate.WEAPON
gv_access.GET = lprivate.GET
function gv_access._get_yxaspect()
return ffiC.yxaspect
end
@ -2364,7 +2363,7 @@ local tmpmt = {
__newindex = function(_, key, val)
if (gv_access[key] == nil) then
-- Read-only vars handled by LuaJIT.
-- Variables declared 'const' are handled by LuaJIT.
ffiC[key] = val
else
error("write access forbidden", 2)

View file

@ -803,8 +803,16 @@ end
function conststruct(tab)
local strtab = { "struct {" }
for member, val in pairs(tab) do
strtab[#strtab+1] = "static const int "..member.."="..val..";"
if (tab[1] ~= nil) then
-- e.g. { "KNEE", "PISTOL", ... } provided
for i=1,#tab do
strtab[#strtab+1] = "static const int "..tab[i].."="..(i-1)..";"
end
else
-- e.g. { KNEE=0, PISTOL=1, ... } provided
for member, val in pairs(tab) do
strtab[#strtab+1] = "static const int "..member.."="..val..";"
end
end
strtab[#strtab+1] = "}"

View file

@ -246,6 +246,7 @@ gameevent
}
local D = require("CON.DEFS")
local WEAPON = gv.WEAPON
-- test event chaining
gameevent
@ -264,7 +265,7 @@ gameevent
else
pistol.shoots = D.SHOTSPARK1
end
ps.weapon[gv.PISTOL_WEAPON].firesound = D.LIGHTNING_SLAP
ps.weapon[WEAPON.PISTOL].firesound = D.LIGHTNING_SLAP
-- This succeeds, because sound2time is a time, not a sound.
ps.weapon.SHOTGUN.sound2time = 5000
@ -336,11 +337,11 @@ gameevent
local pl = player[0]
-- MAX < current is "allowed"
pl.max_ammo_amount[gv.RPG_WEAPON] = 17
pl:give_weapon(gv.RPG_WEAPON)
pl.ammo_amount[gv.RPG_WEAPON] = 54
pl.max_ammo_amount[WEAPON.RPG] = 17
pl:give_weapon(WEAPON.RPG)
pl.ammo_amount[WEAPON.RPG] = 54
pl:give_weapon(gv.SHRINKER_WEAPON)
pl:give_weapon(WEAPON.SHRINKER)
-- This looks much prettier:
pl.ammo_amount.SHRINKER = 2
@ -605,7 +606,7 @@ local function testbit(num, b)
end
local FADE_SPEED = {
[gv.KNEE_WEAPON] = 1/2.5,
[WEAPON.KNEE] = 1/2.5,
1/128,
1/5,
@ -617,7 +618,7 @@ local FADE_SPEED = {
5,
127, -- freezer; such a fast fade is not visible, but it clears any
-- existing one (if of higher priority)
[gv.GROW_WEAPON] = 9.9, -- test banker's rouding -- should be like 10
[WEAPON.GROW] = 9.9, -- test banker's rouding -- should be like 10
}
-- Test player[]:fadecol(), a better palfrom.