Lunatic: expose player[].gotweapon, document it and *_weapon() methods.

git-svn-id: https://svn.eduke32.com/eduke32@4217 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2013-12-26 19:45:03 +00:00
parent 380aa880dc
commit 3cef7cccc0
2 changed files with 37 additions and 10 deletions

View file

@ -221,7 +221,8 @@ __attribute__((packed)) struct {
int16_t angrange, autoaimang; int16_t angrange, autoaimang;
uint16_t max_actors_killed, actors_killed; uint16_t max_actors_killed, actors_killed;
uint16_t gotweapon, zoom; ]]..defs_c.bitint_member("UBit16", "gotweapon")..[[
uint16_t zoom;
int16_x_64 loogiex; int16_x_64 loogiex;
int16_x_64 loogiey; int16_x_64 loogiey;
@ -1304,15 +1305,15 @@ local player_mt = {
end, end,
has_weapon = function(p, weap) has_weapon = function(p, weap)
return (band(p.gotweapon, lsh(1, weap)) ~= 0) return p.gotweaponbits:test(lsh(1,weap))
end, end,
give_weapon = function(p, weap) give_weapon = function(p, weap)
p.gotweapon = bit.bor(p.gotweapon, lsh(1, weap)) p.gotweaponbits:set(lsh(1,weap))
end, end,
take_weapon = function(p, weap) take_weapon = function(p, weap)
p.gotweapon = band(p.gotweapon, bit.bnot(lsh(1, weap))) p.gotweaponbits:clear(lsh(1,weap))
end, end,
-- Give or take weapon, for implementation of CON's .gotweapon access. -- Give or take weapon, for implementation of CON's .gotweapon access.

View file

@ -401,13 +401,11 @@ Functions
Returns an approximation of the angle between the line segments (0,0)->(1,0) Returns an approximation of the angle between the line segments (0,0)->(1,0)
and (0,0)->(`x`,`y`) in BUILD angle units in the range [0 .. 2047]. and (0,0)->(`x`,`y`) in BUILD angle units in the range [0 .. 2047].
[[krand]] [[krand]] `gv.krand()`::
`gv.krand()`::
Returns one value from the global engine-side pseudo-random number generator Returns one value from the global engine-side pseudo-random number generator
in the integer range [0{nbsp}..{nbsp}65535]. in the integer range [0{nbsp}..{nbsp}65535].
[[timing_funcs]] [[timing_funcs]] `gv.getticks()`, `gv.gethiticks()`::
`gv.getticks()`, `gv.gethiticks()`::
Each of these functions return a number that increases at a rate of 1 per Each of these functions return a number that increases at a rate of 1 per
millisecond. Their only intended application is to profile bits of code; they millisecond. Their only intended application is to profile bits of code; they
should not be used to control the game world. The two functions differ in their should not be used to control the game world. The two functions differ in their
@ -834,6 +832,7 @@ footnote:[The max-norm distance between points _p_~1~=(x~1~, y~1~) and
_p_~2~=(x~2~, y~2~) is defined as max(abs(x~2~ -- x~1~), abs(y~2~ -- y~1~)).] _p_~2~=(x~2~, y~2~) is defined as max(abs(x~2~ -- x~1~), abs(y~2~ -- y~1~)).]
of at least 1020 of at least 1020
BUILD x/y units. BUILD x/y units.
// ^ XXX: clipshapes? Also, clipdist is effective for moving sprites (A_MoveSprite()).
_`u8`_ `xrepeat`, `yrepeat`:: _`u8`_ `xrepeat`, `yrepeat`::
The size of the sprite in each dimension. For wall- and floor- aligned sprites, The size of the sprite in each dimension. For wall- and floor- aligned sprites,
@ -964,6 +963,7 @@ Accessible with the same indices and with the same restrictions as
Game-side composites Game-side composites
^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^
[[actor]]
===== `actor` ===== `actor`
The `actor` composite holds various run-time data about a sprite. Like The `actor` composite holds various run-time data about a sprite. Like
@ -974,6 +974,7 @@ have no meaning. Each element has the following members:
_`u16`_ `movflags`, {nbsp} _`bitfield`_ `movflagsbits`:: _`u16`_ `movflags`, {nbsp} _`bitfield`_ `movflagsbits`::
The actor's current <<actor_MOVFLAGS,movement flags>>. The actor's current <<actor_MOVFLAGS,movement flags>>.
[[actor_methods]]
===== `actor` methods ===== `actor` methods
The following methods query or set properties related to The following methods query or set properties related to
@ -1069,12 +1070,14 @@ index. Otherwise, returns *nil*.
// TODO: set_picnum, set_owner? // TODO: set_picnum, set_owner?
[[actor_static_functions]]
===== `actor` static functions ===== `actor` static functions
`actor.fall(i)`:: `actor.fall(i)`::
Causes the actor with index `i` to fall in a ``hard-coded'', not further Causes the actor with index `i` to fall in a ``hard-coded'', not further
specified fashion. specified fashion.
[[actor_static_data]]
===== `actor` static data ===== `actor` static data
[[actor_STAT]] [[actor_STAT]]
@ -1101,6 +1104,7 @@ Contains symbolic names of values applicable <<gameactor,`gameactor`>>'s
`dodgebullet`. `dodgebullet`.
''' '''
[[player]]
===== `player` ===== `player`
Accessible with the index 0 and any nonnegative `pli` index passed to a Accessible with the index 0 and any nonnegative `pli` index passed to a
@ -1139,6 +1143,7 @@ Player members marked _`bool`_ in the listing below yield Lua true or false on
reading and expect one of these values when assigned to. reading and expect one of these values when assigned to.
[[player_members]]
===== `player` members ===== `player` members
<<vector_types,_`xmath.ivec3`_>> `vel`:: <<vector_types,_`xmath.ivec3`_>> `vel`::
@ -1157,6 +1162,13 @@ most 8192.
`curr_weapon`:: `curr_weapon`::
The index of the player's currently selected weapon. The index of the player's currently selected weapon.
_`u16`_ `gotweapon`, {nbsp} _`bitfield`_ `gotweaponbits`::
Indicates whether each weapon is in the possession of the player. If bit 2^`w`^
is set for a <<gv_WEAPON,weapon index>> `w`, the player has got this
weapon. The player methods `has_weapon`, `give_weapon` and `take_weapon` can be
used to query or modify this member.
_`i16`_ +ammo_amount[_weapon_]+:: _`i16`_ +ammo_amount[_weapon_]+::
The current ammo amount for each weapon. The current ammo amount for each weapon.
@ -1174,8 +1186,21 @@ Whether the player currently has the jetpack, scuba gear, or night vision
goggles activated, respectively. goggles activated, respectively.
[[player_methods]]
===== `player` methods ===== `player` methods
`ps:has_weapon(widx)`::
Returns a boolean of whether player `ps` has got the weapon with index `widx`.
`ps:give_weapon(widx)`::
Adds the weapon given by index `widx` to player `ps`'s possession without
changing the currently held one.
`ps:take_weapon(widx)`::
Removes the weapon given by index `widx` from player `ps`'s possession. If an
attempt is made to remove the currently selected weapon, the behavior is
undefined.
`ps:fadecol(fadefrac, r, g, b [, speed [, prio]])`:: `ps:fadecol(fadefrac, r, g, b [, speed [, prio]])`::
Initiates a tinting that linearly fades over time and is blended with the whole Initiates a tinting that linearly fades over time and is blended with the whole
@ -1207,6 +1232,7 @@ CAUTION: If Lunatic code that uses `fadecol` is loaded together with CON code
that writes to the player's `pals` members directly at any point, the behavior that writes to the player's `pals` members directly at any point, the behavior
is undefined. is undefined.
[[player_iterators]]
===== `player` iterators ===== `player` iterators
+*for* i *in* player.all()+:: +*for* i *in* player.all()+::
@ -1775,7 +1801,7 @@ what EDuke32 uses. See the {wiki_action}[Action entry] in the EDuke32 wiki for
how the views are constructed for different `viewtype` values. how the views are constructed for different `viewtype` values.
`[4] incval` (default: 1):: `[4] incval` (default: 1)::
The value to add the actor's _current frame_ on each frame advance. May be -1, The value to add the actor's _current frame_ on each frame advance. May be --1,
0, or 1. 0, or 1.
// In the wild, sometimes other values, too. // In the wild, sometimes other values, too.
@ -1976,7 +2002,7 @@ index `parentspritenum`. The z velocity can be overridden by passing `zvel`.
// TODO: document how zvel is interpreted // TODO: document how zvel is interpreted
Returns the index of the spawned sprite on success, or -1 otherwise. Returns the index of the spawned sprite on success, or --1 otherwise.
The `fs` module -- virtual file system facilities The `fs` module -- virtual file system facilities