Subversion Repositories eduke32

Rev

Rev 4567 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4567 Rev 4570
Line 1474... Line 1474...
1474
function Cmd.gamevar(identifier, initval, flags)
1474
function Cmd.gamevar(identifier, initval, flags)
1475
    if (check.sysvar_def_attempt(identifier)) then
1475
    if (check.sysvar_def_attempt(identifier)) then
1476
        return
1476
        return
1477
    end
1477
    end
1478
1478
1479
    -- TODO: handle user bits like NORESET or NODEFAULT
-
 
1480
    if (bit.band(flags, bit.bnot(GVFLAG.USER_MASK)) ~= 0) then
1479
    if (bit.band(flags, bit.bnot(GVFLAG.USER_MASK)) ~= 0) then
1481
        -- TODO: a couple of the presumably safe ones
1480
        -- TODO: a couple of the presumably safe ones
1482
        errprintf("gamevar flags other than 1, 2, 1024 or 131072: NYI or forbidden")
1481
        errprintf("gamevar flags other than 1, 2, 1024 or 131072: NYI or forbidden")
1483
        return
1482
        return
1484
    end
1483
    end
Line 1490... Line 1489...
1490
        errprintf("invalid gamevar flags: must be either PERPLAYER or PERACTOR, not both")
1489
        errprintf("invalid gamevar flags: must be either PERPLAYER or PERACTOR, not both")
1491
        return
1490
        return
1492
    end
1491
    end
1493
1492
1494
    local ogv = g_gamevar[identifier]
1493
    local ogv = g_gamevar[identifier]
-
 
1494
    -- handle NORESET or NODEFAULT
1495
    local isSessionVar = (bit.band(flags, GVFLAG.NODEFAULT) ~= 0)
1495
    local isSessionVar = (bit.band(flags, GVFLAG.NODEFAULT) ~= 0)
1496
    local storeWithSavegames = (bit.band(flags, GVFLAG.NORESET) == 0)
1496
    local storeWithSavegames = (bit.band(flags, GVFLAG.NORESET) == 0)
1497
1497
1498
    if (isSessionVar and (perPlayer or perActor)) then
1498
    if (isSessionVar and (perPlayer or perActor)) then
1499
        if (ogv == nil) then  -- warn only once per gamevar
1499
        if (ogv == nil) then  -- warn only once per gamevar
Line 1571... Line 1571...
1571
                      conl.MAXSESSIONVARS)
1571
                      conl.MAXSESSIONVARS)
1572
            return
1572
            return
1573
        end
1573
        end
1574
1574
1575
        -- Declare new session gamevar.
1575
        -- Declare new session gamevar.
1576
        g_gamevar[identifier] = { name=format("_gv._sessionVar[%d]", g_numSessionVars),
1576
        local gv = { name=format("_gv._sessionVar[%d]", g_numSessionVars),
1577
                                  flags=flags, loc=getLocation(), used=0 }
1577
                     flags=flags, loc=getLocation(), used=0 }
1578
        g_numSessionVars = g_numSessionVars+1
1578
        g_numSessionVars = g_numSessionVars+1
-
 
1579
-
 
1580
        g_gamevar[identifier] = gv;
-
 
1581
        -- Initialize it (i.e. set to the declared initial value) on first run,
-
 
1582
        -- but not from savegames.
-
 
1583
        addcodef("if _S then %s=%d end", gv.name, initval)
-
 
1584
1579
        return
1585
        return
1580
    end
1586
    end
1581
1587
1582
    local gv = { name=mangle_name(identifier, "V"), flags=flags, loc=getLocation(), used=0 }
1588
    local gv = { name=mangle_name(identifier, "V"), flags=flags, loc=getLocation(), used=0 }
1583
    g_gamevar[identifier] = gv
1589
    g_gamevar[identifier] = gv