diff --git a/classes/Gun-methods.lua b/classes/Gun-methods.lua index 0f9ea08..42c1b02 100644 --- a/classes/Gun-methods.lua +++ b/classes/Gun-methods.lua @@ -1,10 +1,18 @@ +-- @within Gun.gun +-- @compact + local gun_default = Guns4d.gun local mat4 = leef.math.mat4 --I dont remember why I made this, used it though lmao function gun_default.multiplier_coefficient(multiplier, ratio) return 1+((multiplier*ratio)-ratio) end ---update gun, the main function. + +--- The entry method for the update of the gun +-- +-- calls virtually all functions that begin with `update` once. Also updates subclass +-- +-- @tparam float dt function gun_default:update(dt) assert(self.instance, "attempt to call object method on a class") if not self:has_entity() then self:add_entity(); self:clear_animation() end @@ -41,10 +49,11 @@ function gun_default:update(dt) self.crosshair:update() end --finalize transforms - self:update_rotations() + self:update_transforms() end -function gun_default:update_rotations() +--- updates self.total_offsets which stores offsets for bones +function gun_default:update_transforms() local total_offset = self.total_offsets --axis rotations total_offset.player_axial.x = 0; total_offset.player_axial.y = 0 @@ -64,7 +73,7 @@ function gun_default:update_rotations() --total_offset.gun_axial.x = 0; total_offset.gun_axial.y = 0 end ---manage burstfire +--- Update and fire the queued weapon burst function gun_default:update_burstfire() if self.rechamber_time <= 0 then while true do @@ -80,7 +89,8 @@ function gun_default:update_burstfire() end end end ---cycle firemodes, typically activated by default_controls.lua. + +--- cycles to the next firemode of the weapon function gun_default:cycle_firemodes() --cannot get length using length operator because it's a proxy table local length = 0 @@ -93,7 +103,8 @@ function gun_default:cycle_firemodes() self:update_image_and_text_meta() self.player:set_wielded_item(self.itemstack) end ---remember to set_wielded_item to self.itemstack! otherwise these changes will not apply! + +--- update the inventory information of the gun function gun_default:update_image_and_text_meta(meta) meta = meta or self.meta local ammo = self.ammo_handler.ammo @@ -129,7 +140,8 @@ function gun_default:update_image_and_text_meta(meta) end meta:set_string("inventory_image", image) end ---draw the gun from holster + +--- plays the draw animation and sound for the gun, delays usage. function gun_default:draw() assert(self.instance, "attempt to call object method on a class") local props = self.properties @@ -143,7 +155,8 @@ function gun_default:draw() self.ammo_handler:chamber_round() self.rechamber_time = props.charging.draw_time end ---attempt to fire the weapon + +--- attempt to fire the gun function gun_default:attempt_fire() assert(self.instance, "attempt to call object method on a class") local props = self.properties @@ -196,6 +209,8 @@ local function rand_sign(b) if math.random() > b then int=-1 end return int end + +--- simulate recoil by adding to the recoil velocity (called by attempt_fire) function gun_default:recoil() assert(self.instance, "attempt to call object method on a class") local rprops = self.properties.recoil @@ -216,6 +231,8 @@ function gun_default:recoil() end self.time_since_last_fire = 0 end + +--- update the offsets of the player's look created by the gun function gun_default:update_look_offsets(dt) assert(self.instance, "attempt to call object method on a class") local handler = self.handler @@ -328,6 +345,12 @@ local ttransform = mat4.identity() local out = vector.new() --reserve the memory, we still want to create new vectors each time though. --gets the gun's position relative to the player. Relative indicates wether it's relative to the player's horizontal look --offset is relative to the's rotation + +--- get the global position of the gun. This is customized to rely on the assumption that there are 3-4 main rotations and 2-3 translations. If the behavior of the bones are changed this method may not work +-- @tparam vec3 offset_pos +-- @tparam bool relative_y wether the y axis is relative to the player's look +-- @tparam bool relative_x wether the x axis is relative to the player's look +-- @treturn vec3 position of gun (in global or local orientation) relative to the player's position function gun_default:get_pos(offset, relative_y, relative_x, with_animation) assert(self.instance, "attempt to call object method on a class") --local player = self.player @@ -415,7 +438,7 @@ end --=============================================== ENTITY ====================================================== - +--- adds the gun entity function gun_default:add_entity() assert(self.instance, "attempt to call object method on a class") self.entity = minetest.add_entity(self.player:get_pos(), "guns4d:gun_entity") @@ -433,6 +456,8 @@ end local tmp_mat4_rot = mat4.identity() local ip_time = Guns4d.config.gun_axial_interpolation_time local ip_time2 = Guns4d.config.translation_interpolation_time + +--- updates the gun's entity function gun_default:update_entity() local obj = self.entity local player = self.player @@ -475,6 +500,9 @@ function gun_default:update_entity() } }) end + +--- checks if the gun entity exists... +-- @treturn bool function gun_default:has_entity() assert(self.instance, "attempt to call object method on a class") if not self.entity then return false end @@ -482,7 +510,8 @@ function gun_default:has_entity() return true end - +--- updates the gun's wag offset for walking +-- @tparam float dt function gun_default:update_wag(dt) local handler = self.handler local wag = self.offsets.walking @@ -533,6 +562,9 @@ function gun_default:update_wag(dt) end end local e = 2.7182818284590452353602874713527 --I don't know how to find it otherwise... + +--- updates the gun's recoil simulation +-- @tparam float dt function gun_default:update_recoil(dt) for axis, _ in pairs(self.offsets.recoil) do for _, i in pairs({"x","y"}) do @@ -571,6 +603,9 @@ function gun_default:update_recoil(dt) end --print(self.velocities.recoil.player_axial.x, self.velocities.recoil.player_axial.y) end + +--- updates the gun's animation data +-- @tparam dt function gun_default:update_animation(dt) local ent = self.entity local data = self.animation_data @@ -584,6 +619,11 @@ function gun_default:update_animation(dt) end --IMPORTANT!!! this does not directly modify the animation_data table anymore, it's all hooked through ObjRef:set_animation() (init.lua) so if animation is set elsewhere it doesnt break. --this may be deprecated in the future- as it is no longer really needed now that I hook ObjRef functions. +--- sets the gun's animation in the same format as ObjRef:set_animation() (future deprecation?) +-- @tparam table frames `{x=int, y=int}` +-- @tparam float|nil length length of the animation in seconds +-- @tparam int fps frames per second of the animation +-- @tparam bool loop wether to loop function gun_default:set_animation(frames, length, fps, loop) loop = loop or false --why the fuck default is true? I DONT FUCKIN KNOW (this undoes this) assert(type(frames)=="table" and frames.x and frames.y, "frames invalid or nil in set_animation()!") @@ -596,6 +636,8 @@ function gun_default:set_animation(frames, length, fps, loop) end self.entity:set_animation(frames, fps, 0, loop) --see init.lua for modified ObjRef stuff. end + +--- clears the animation to the rest state function gun_default:clear_animation() local loaded = false if self.properties.ammo.magazine_only then @@ -625,6 +667,11 @@ local function adjust_gain(tbl, v) end end end + +--- plays a list of sounds for the gun's user and thirdpersons +-- @tparam soundspec_list sound parameters following the format of @{Guns4d.play_sounds} +-- @treturn integer thirdperson sound's guns4d sound handle +-- @treturn integer firstperson sound's guns4d sound handle function gun_default:play_sounds(sound) local thpson_sound = Guns4d.table.deep_copy(sound) local fsprsn_sound = Guns4d.table.deep_copy(sound) diff --git a/classes/Gun.lua b/classes/Gun.lua index 7080d84..722c908 100644 --- a/classes/Gun.lua +++ b/classes/Gun.lua @@ -9,17 +9,20 @@ local Vec = vector -- **method documentation coming soon** (or never...) -- -- The appearance and handling of guns by default are defined by two table fields: their @{lvl1_fields.consts|consts} and their @{lvl1_fields.properties|properties}. --- @{lvl1_fields.properties|properties} define nearly everything, from how a gun handles to how it looks, what model it uses, +-- @{lvl1_fields.properties|properties} define nearly everything, from how a gun handles to how it looks, what model it uses, etc. -- while @{lvl1_fields.consts|consts} define attributes that should never change, like bones within the gun, framerates, --- hwether the gun is allowed to have certain attributes at all. The other fields of the class define tracking variables or other important things for the internal workings. +-- wether the gun is allowed to have certain attributes at all. The other fields of the class define tracking variables or other important things for the internal workings. -- --- There are essentially only 2 fields you must define to register a gun: @{gun.itemstring|itemstring}, @{gun.name|name}, and @{lvl1_fields.properties|properties} --- To hold the gun, the item defined in itemstring must exist. To have a functional gun however, more will need to be changed in terms of properties. +-- There are essentially only 3 fields you must define to register a gun: @{gun.itemstring|itemstring}, @{gun.name|name}, and @{lvl1_fields.properties|properties}. +-- To hold the gun, the item defined in itemstring must actually exist, it will not automatically register. To have a functional gun however, more will need to be changed in terms of properties. +-- it's reccomended that you take a look at existing mods (like guns4d_pack_1) for guidance -- -- Guns4d uses a class system for most moving parts- including the gun. New guns therefore are created with the :inherit(def) method, -- where def is the definition of your new gun- or rather the changed parts of it. So to make a new gun you can run Guns4d.gun:inherit() -- or you can do the same thing with a seperate class of weapons. Set name to "__template" for template classes of guns. -- +-- *Please note:* there are likey undocumented fields that are used in internal functions. If you find one, please make an issue on Github. +-- -- -- @class gun -- @field properties @{lvl1_fields.properties|properties} which define the vast majority of gun attributes and may change accross instances @@ -29,20 +32,18 @@ local Vec = vector local gun_default = { --- `string` the name of the gun. Set to __template for guns which have no instances and serve as a template. It is safe to set name to the same as @{gun.itemstring} name = "__guns4d:default__", + --- `string` the itemstring of the gun- i.e. `"guns4d_pack_1:m4"`. Set to `""` for `__template` guns. + itemstring = "", --- `ItemStack` the gun itemstack. Remember to player:set_wielded_item(self.itemstack) when making meta or itemstack changes. itemstack = nil, + --- `ObjRef` the operator of the weapon. This may at some point be deprecated when I start to implement AI/mob usage + player = nil, --- `MetaDataRef` itemstack meta meta = nil, --- `string` the ID of the gun used for tracking of it's inventory id = nil, --- `ObjRef` the gun entity gun_entity = nil, - --- `string` inventory image for when the gun has no magazine - inventory_image_magless = nil, - --- `string` inventory image for when the gun is loaded. This is added automatically during construction. - inventory_image = nil, - --- `string` the itemstring of the gun- i.e. `"guns4d_pack_1:m4"`. Set to `""` for `__template` guns. - itemstring = "", --- list of registered guns, **DO NOT MODIFY** I really need a metatable for this class... _registered = {}, --- `bool` is the bolt charged @@ -80,32 +81,86 @@ local gun_default = { -- @field sway `table` @{gun.properties.sway|defines the guns idle sway} -- @field wag `table` @{gun.properties.wag|defines the movement of the gun while walking} -- @field charging `table` @{gun.properties.charging|defines how rounds are chambered into the gun} - -- @field ammo @{gun.properties.ammo|defines what ammo the gun uses} - -- @field visuals @{gun.properties.visuals|defines visual attributes of the gun} + -- @field ammo `table` @{gun.properties.ammo|defines what ammo the gun uses} + -- @field visuals `table` @{gun.properties.visuals|defines visual attributes of the gun} -- @compact properties = { - + --- `Ammo_handler` the class (based on) ammo_handler to create an instance of and use. Default is `Guns4d.ammo_handler` + ammo_handler = Guns4d.ammo_handler, + --- `Attachment_handler` attachment_handler class to use. Default is `Guns4d.attachment_handler` + attachment_handler = Guns4d.attachment_handler, + --- `Sprite_scope` sprite scope class to use + sprite_scope = nil, + --- `Dynamic_crosshair` crosshair class to use + crosshair = nil, + --- starting vertical rotation of the gun + initial_vertical_rotation = -60, --- `float`=.5 max angular deviation (vertical) from breathing breathing_scale = .5, --- `vector` the offset from the center of the muzzle flash. Used by fire() flash_offset = Vec.new(), --- `int`=600 The number of rounds (cartidges) this gun can throw per minute. Used by update(), fire() and default controls firerateRPM = 600, - --- properties.hip - -- @table gun.properties.hip - -- @compact - hip = {--#1 - --- `vector` the offset of the gun (relative to the right arm's default position) at hip. - offset = Vec.new(), - --- the ratio that the look rotation is expressed through player_axial (rotated around the viewport) rotation as opposed to gun_axial (rotating the entity). - axis_rotation_ratio = .75, - --- sway speed multiplier while at hip - sway_vel_mul = 5, - --- sway angle multiplier while at hip+ - sway_angle_mul = 1, + --- `string` inventory image for when the gun has no magazine + inventory_image_magless = nil, + --- `string` inventory image for when the gun is loaded. This is added automatically during construction. + inventory_image = nil, + --- an ordered list of reloading states used by @{default_controls}. + -- + -- the default reload states for a magazine operated weapon, copied from the m4. + -- @example + -- {action="charge", time=.5, anim="charge", sounds={sound="ar_charge", delay = .2}}, + -- {action="unload_mag", time=.25, anim="unload", sounds = {sound="ar_mag_unload"}}, + -- {action="store", time=.5, anim="store", sounds = {sound="ar_mag_store"}}, + -- {action="load", time=.5, anim="load", sounds = {sound="ar_mag_load", delay = .25}}, + -- {action="charge", time=.5, anim="charge", sounds={sound="ar_charge", delay = .2}} + reload = {}, + --- a table {x1,y1,z1,x2,y2,z2} specifying the bounding box of the model. The first 3 (x1,y1,z1) are the lower of their counterparts. This is autogenerated if not present. + model_bounding_box = nil, + --- `string` overlay on the item to use when infinite ammo is on + infinite_inventory_overlay = "inventory_overlay_inf_ammo.png", + --- `int`=3 how many rounds in burst using when firemode is at "burst" + burst = 3, + --- `table` containing a list of actions for PC users passed to @{Control_handler} + pc_control_actions = { --used by control_handler + __overfill=true, --this table will not be filled in. + aim = Guns4d.default_controls.aim, + auto = Guns4d.default_controls.auto, + reload = Guns4d.default_controls.reload, + on_use = Guns4d.default_controls.on_use, + firemode = Guns4d.default_controls.firemode, + jump_cancel_ads = Guns4d.default_controls.jump_cancel_ads + }, + --- `table` containing a list of actions for touch screen users passed to @{Control_handler} + touch_control_actions = { + __overfill=true, + aim = Guns4d.default_touch_controls.aim, + auto = Guns4d.default_touch_controls.auto, + reload = Guns4d.default_touch_controls.reload, + on_secondary_use = Guns4d.default_touch_controls.on_secondary_use, + firemode = Guns4d.default_touch_controls.firemode, + jump_cancel_ads = Guns4d.default_touch_controls.jump_cancel_ads + }, + inventory = { + --[[attachment_slots = { + underbarrel = { + formspec_inventory_location = {x=0, y=1} + slots = 2, + rail = "picatinny" --only attachments fit for this type will be usable. + allowed = { + "group:guns4d_underbarrel" + }, + bone = "" --the bone both to attach to and to display at on the menu. + } + },]] + render_size = 2, --length (in meters) which is visible accross the z/forward axis at y/up=0, x=0. For orthographic this will be the scale of the orthographic camera. Default 2 + render_image = "m4_ortho.png", --expects an image of the right side of the gun, where the gun is facing the right. Default "m4_ortho.png" + --rendered_from_model = true --if true the rendering is automatically moved to the center of the screen }, --- properties.ads + -- -- @table gun.properties.ads + -- @see lvl1_fields.properties|properties -- @compact ads = { --#2 --- `vector` the offset of the gun relative to the eye's position at hip. @@ -115,12 +170,26 @@ local gun_default = { --- the time it takes to go into full aim aim_time = 1, }, - --- `int`=3 how many rounds in burst using when firemode is at "burst" - burst = 3, + --- properties.hip + -- + -- @table gun.properties.hip + -- @see lvl1_fields.properties|properties + -- @compact + hip = {--#1 + --- `vector` the offset of the gun (relative to the right arm's default position) at hip. + offset = Vec.new(), + --- the ratio that the look rotation is expressed through player_axial (rotated around the viewport) rotation as opposed to gun_axial (rotating the entity). + axis_rotation_ratio = .75, + --- sway speed multiplier while at hip + sway_vel_mul = 5, + --- sway angle multiplier while at hip + sway_angle_mul = 1, + }, --- properties.firemodes -- -- list containing the firemodes of the gun. Default only contains "single". Strings allowed by default: -- @table gun.properties.firemodes + -- @see lvl1_fields.properties|properties -- @compact -- @field "single" -- @field "burst" @@ -128,26 +197,26 @@ local gun_default = { firemodes = { --#3 "single", --not limited to semi-automatic. }, - --- `string` overlay on the item to use when infinite ammo is on - infinite_inventory_overlay = "inventory_overlay_inf_ammo.png", --- properties.firemode_inventory_overlays -- - -- defines the overlay on the gun item for each firemode. These are selected automatically by firemode string. Defaults are as follows: + -- Defines the overlay on the gun item for each firemode. These are selected automatically by firemode string. Defaults are as follows: -- @table gun.properties.firemode_inventory_overlays + -- @see lvl1_fields.properties|properties -- @compact firemode_inventory_overlays = { --#4 - --- "inventory_overlay_single.png" + --- singlefire default: "inventory_overlay_single.png" single = "inventory_overlay_single.png", - --- "inventory_overlay_auto.png" + --- automatic default: "inventory_overlay_auto.png" auto = "inventory_overlay_auto.png", - --- "inventory_overlay_burst.png" + --- burstfire default: "inventory_overlay_burst.png" burst = "inventory_overlay_burst.png", - --- "inventory_overlay_safe.png" (unimplemented firemode) + --- safe default: "inventory_overlay_safe.png" (unimplemented firemode) safe = "inventory_overlay_safe.png" }, --- properties.recoil -- -- **IMPORTANT**: expects fields to be tables containing a "gun_axial" and "player_axial" field. + -- @see lvl1_fields.properties|properties -- @example -- property = { -- gun_axial = type @@ -202,6 +271,7 @@ local gun_default = { -- -- **IMPORTANT**: expects fields to be tables containing a "gun_axial" and "player_axial" field. In the same format as @{gun.properties.recoil} -- @table gun.properties.sway + -- @see lvl1_fields.properties|properties -- @compact sway = { --#6 --- `float` maximum angle of the sway @@ -228,6 +298,7 @@ local gun_default = { --- properties.wag -- -- @table gun.properties.wag + -- @see lvl1_fields.properties|properties -- @compact wag = { --- `float`=1.6 the cycle speed multiplier @@ -240,81 +311,28 @@ local gun_default = { player_axial = {x=1,y=1}, }, }, - --- `table` containing a list of actions for PC users passed to @{Control_handler} - pc_control_actions = { --used by control_handler - __overfill=true, --this table will not be filled in. - aim = Guns4d.default_controls.aim, - auto = Guns4d.default_controls.auto, - reload = Guns4d.default_controls.reload, - on_use = Guns4d.default_controls.on_use, - firemode = Guns4d.default_controls.firemode, - jump_cancel_ads = Guns4d.default_controls.jump_cancel_ads - }, - --- `table` containing a list of actions for touch screen users passed to @{Control_handler} - touch_control_actions = { - __overfill=true, - aim = Guns4d.default_touch_controls.aim, - auto = Guns4d.default_touch_controls.auto, - reload = Guns4d.default_touch_controls.reload, - on_secondary_use = Guns4d.default_touch_controls.on_secondary_use, - firemode = Guns4d.default_touch_controls.firemode, - jump_cancel_ads = Guns4d.default_touch_controls.jump_cancel_ads - }, - --[[ parts framework coming soon. example for m4 - parts = { - barrel = { - operable_without = false, - group = "guns4d_m4_barrel" - default = "guns4d:m4_15in" - } - } - ]] - inventory = { - --[[attachment_slots = { - underbarrel = { - formspec_inventory_location = {x=0, y=1} - slots = 2, - rail = "picatinny" --only attachments fit for this type will be usable. - allowed = { - "group:guns4d_underbarrel" - }, - bone = "" --the bone both to attach to and to display at on the menu. - } - },]] - render_size = 2, --length (in meters) which is visible accross the z/forward axis at y/up=0, x=0. For orthographic this will be the scale of the orthographic camera. - render_image = "m4_ortho.png", --expects an image of the right side of the gun, where the gun is facing the right. - --rendered_from_model = true --if true the rendering is automatically moved to the center of the screen - }, --- properties.charging -- -- @table gun.properties.charging + -- @see lvl1_fields.properties|properties -- @compact charging = { --#7 - --- `bool` defines wether the draw animation is played on swap (when loaded). Used in the instance construction method + --- `bool` defines wether the draw animation is played on swap (when loaded). Default true. require_draw_on_swap = true, --- `string` "none" bolt will never need to be charged after reload, "catch" when fired to empty bolt will not need to be charged after reload, "no_catch" bolt will always need to be charged after reload. - bolt_charge_mode = "none", --"none"-chamber is always full, "catch"-when fired to dry bolt will not need to be charged after reload, "no_catch" bolt will always need to be charged after reload. + bolt_charge_mode = "none", --"none"-chamber is always full, "catch"-when fired to dry bolt will not need to be charged after reload, "no_catch" bolt will always need to be charged after reload. Default "none" --- `float` the time it takes to swap to the gun draw_time = 1, - --- `string` name of the animation to play from @{gun.properties.visuals.animations|visuals.animations} + --- `string` name of the animation to play from @{gun.properties.visuals.animations|visuals.animations}. Default "draw" draw_animation = "draw", - --- `string` name of the sound to play from @{gun.properties.sounds|sounds} + --- `string` name of the sound to play from @{gun.properties.sounds|sounds}. Default "draw" draw_sound = "draw" --sound = soundspec }, - --- and ordered list of reloading states used by @{default_controls}. - -- - -- the default reload states for a magazine operated weapon, copied from the m4. - -- @example - -- {action="charge", time=.5, anim="charge", sounds={sound="ar_charge", delay = .2}}, - -- {action="unload_mag", time=.25, anim="unload", sounds = {sound="ar_mag_unload"}}, - -- {action="store", time=.5, anim="store", sounds = {sound="ar_mag_store"}}, - -- {action="load", time=.5, anim="load", sounds = {sound="ar_mag_load", delay = .25}}, - -- {action="charge", time=.5, anim="charge", sounds={sound="ar_charge", delay = .2}} - reload = {}, --- properties.ammo -- -- @table gun.properties.ammo + -- @see lvl1_fields.properties|properties -- @compact ammo = { --#8 --- `bool` wether the gun only uses a magazine or accepts raw ammunition too. @@ -330,24 +348,35 @@ local gun_default = { --- properties.visuals -- -- @table gun.properties.visuals + -- @see lvl1_fields.properties|properties -- @compact visuals = { --- name of mesh to display. Currently only supports b3d mesh = nil, - --- list of textures to use + --- list of textures to use. textures = {}, - --- scale multiplier + --- scale multiplier. Default 1 scale = 1, - --- toggles backface culling + --- toggles backface culling. Default true backface_culling = true, - --- a table of animations in the format {x=int, y=float}. Indexes define the name of the animation to be refrenced by other functions of the gun. + --- a table of animations. Indexes define the name of the animation to be refrenced by other functions of the gun. + -- should be in the format `{x=integer,y=integer}` + -- @example + -- animations = { + -- empty = {x=0,y=0} + -- loaded = {x=1,y=1} + -- fire = {x=10,y=20} + -- draw = {x=24,y=30} --DEFAULT of charging.draw_animation. + -- } + -- + -- There are other animations which are variable which are not listed here, these are usually defined by properties such as: + -- @{reload}, @{gun.properties.charging.draw_animation|draw_animation} animations = { --used by animations handler for idle, and default controls empty = {x=0,y=0}, loaded = {x=1,y=1}, + fire = {x=0,y=0}, }, }, - --- a table {x1,y1,z1,x2,y2,z2} specifying the bounding box of the model. The first 3 (x1,y1,z1) are the lower of their counterparts - model_bounding_box = nil, --- a table of @{guns4d_soundspec|soundspecs} to be referenced by other functions sounds = { --this does not contain reload sound effects. fire = { @@ -380,18 +409,40 @@ local gun_default = { } }, }, - ammo_handler = Guns4d.ammo_handler, - attachment_handler = Guns4d.attachment_handler, - sprite_scope = nil, - crosshair = nil, - initial_vertical_rotation = -60, + }, + --- `vector` containing the offset from animations, this will be generated if {@consts.ANIMATIONS_OFFSET_AIM}=true + animation_rotation = vector.new(), + --- all offsets from @{offsets|gun.offset} of a type added together gun in the same format as a @{offsets|an offset} (that is, five vectors, `gun_axial`, `player_axial`, etc.). Note that if + -- offsets are changed after update, this will not be updated automatically until the next update. update_rotations() must be called to do so. + total_offsets = { + gun_axial = vector.new(), --rotation of the gun entity (around entity's own axis) + player_axial = vector.new(), --rotation around the eye (the player's axis) + gun_trans = vector.new(), --translation of the gun relative to attached bone's rotation + player_trans = vector.new(), --translation of the gun relative to the player's eye + look_trans = vector.new() --translation/offset of the player's eye + }, + --- velocities in the format of @{offsets|offsets}, but only containing angular (`gun_axial` and `player_axial`) offsets. + velocities = { + recoil = { + gun_axial = Vec.new(), + player_axial = Vec.new(), + }, + init_recoil = { + gun_axial = Vec.new(), + player_axial = Vec.new(), + }, + sway = { + gun_axial = Vec.new(), + player_axial = Vec.new(), + }, }, --- offsets -- -- a list of tables each containing offset vectors These are required for automatic initialization of offsets. + -- note rotations are in degrees, and translations are in meters. -- @example -- recoil = { - -- gun_axial = {x=0, y=0}, --rotation of the gun around it's origin + -- gun_axial = {x=0, y=0}, --rotation of the gun around it's origin. -- player_axial = {x=0, y=0}, --rotation of the gun around the bone it's attached to -- --translations of gun -- player_trans = {x=0, y=0, z=0}, --translation of the bone the gun is attached to @@ -433,31 +484,6 @@ local gun_default = { gun_trans = Vec.new() }, }, - --- `vector` containing the offset from animations, this will be generated if {@consts.ANIMATIONS_OFFSET_AIM}=true - animation_rotation = vector.new(), - --- total offsets of the gun in the same format as a @{offsets|an offset} - --[[total_offsets = { - gun_axial = vector.new(), rotation of the gun entity (around entity's own axis) - player_axial = vector.new(), rotation around the eye (the player's axis) - gun_trans = vector.new(), translation of the gun relative to attached bone's rotation - player_trans = vector.new(), translation of the gun relative to the player's eye - look_trans = vector.new() translation/offset of the player's eye - }, ]] - --player_rotation = Vec.new(), - velocities = { - recoil = { - gun_axial = Vec.new(), - player_axial = Vec.new(), - }, - init_recoil = { - gun_axial = Vec.new(), - player_axial = Vec.new(), - }, - sway = { - gun_axial = Vec.new(), - player_axial = Vec.new(), - }, - }, --- consts -- -- These are variables that are constant across the class and should usually not ever be changed by instnaces diff --git a/classes/Physics_system.lua b/classes/Physics_system.lua new file mode 100644 index 0000000..30fe91b --- /dev/null +++ b/classes/Physics_system.lua @@ -0,0 +1,49 @@ + +local physics_system = leef.class.new_class:inherit({ + objects = {}, --table of vectors, + object_pos = vector.new(), + center_of_mass = vector.new(), + object_weight = 1, --weight in kg + forcefields = {} +}) + +--forcefield def + +--[[ +{ + midline_radius = 0, --midline of attraction/repulsion + deadzone_radius = 1, + border_radius = 0 + pos = vec3(), + elastic_constant = 0 --F = e * d^(|e|/e) +} +]] + +--calculate delta-velocity of a given forcefield +--@tparam int index of the forcefield +--@treturn deltaV of +local rpos = vector.new() +--not going to optimize this because AHHHHHHHHHH its a lot of vector math +function physics_system:update(dt) +end +function physics_system:calculate_dv(dt, i) + local pos = + + + + local field = self.forcefields[i] + local borderR = field.border_radius + local deadzoneR = field.deadzone_radius + local midlineR = field.midline_radius + local fpos = field.pos + + --rpos.x, rpos.y, rpos.z = pos.x-fpos.x,pos.y-fpos.y,pos.z-fpos.x + rpos = pos-fpos --relative pos + local midline_intersect = rpos:normalize()*midlineR --dir*r is the intersect with midline + local d=(midline_intersect-pos):length() --distance from midline + local e= field.elastic_constant + local f = e*d^(math.abs(e)/e) --force + + --local a = f/self.object_weight --acceleration + return a*dt --change in velocity +end diff --git a/docs/class/Gun.html b/docs/class/Gun.html index 99dd4b7..bd97feb 100644 --- a/docs/class/Gun.html +++ b/docs/class/Gun.html @@ -29,10 +29,10 @@
gun
properties
properties.hip
-properties.ads
properties.hip
+properties.firemodes
properties.firemode_inventory_overlays
@@ -69,6 +69,7 @@method documentation coming soon (or never...)
The appearance and handling of guns by default are defined by two table fields: their consts and their properties. -properties define nearly everything, from how a gun handles to how it looks, what model it uses, +properties define nearly everything, from how a gun handles to how it looks, what model it uses, etc. while consts define attributes that should never change, like bones within the gun, framerates, -hwether the gun is allowed to have certain attributes at all. The other fields of the class define tracking variables or other important things for the internal workings.
-There are essentially only 2 fields you must define to register a gun: itemstring, name, and properties -To have a functional gun however, more will need to be changed in terms of properties.
+wether the gun is allowed to have certain attributes at all. The other fields of the class define tracking variables or other important things for the internal workings. +There are essentially only 3 fields you must define to register a gun: itemstring, name, and properties. +To hold the gun, the item defined in itemstring must actually exist, it will not automatically register. To have a functional gun however, more will need to be changed in terms of properties. +it's reccomended that you take a look at existing mods (like guns4d_pack_1) for guidance
Guns4d uses a class system for most moving parts- including the gun. New guns therefore are created with the :inherit(def) method, where def is the definition of your new gun- or rather the changed parts of it. So to make a new gun you can run Guns4d.gun:inherit() or you can do the same thing with a seperate class of weapons. Set name to "__template" for template classes of guns.
+Please note: there are likey undocumented fields that are used in internal functions. If you find one, please make an issue on Github.
itemstring¶ | +
|
+||
itemstack¶ |
|
||
player¶ | +
|
+||
meta¶ |
|
@@ -134,21 +147,6 @@ or you can do the same thing with a seperate class of weapons. Set name to "
||
inventory_image_magless¶ | -
|
-||
inventory_image¶ | -
|
-||
itemstring¶ | -
|
-||
_registered¶ | list of registered guns, DO NOT MODIFY I really need a metatable for this class... |
@@ -209,24 +207,6 @@ or you can do the same thing with a seperate class of weapons. Set name to "
||
reload¶ | -and ordered list of reloading states used by default_controls. -the default reload states for a magazine operated weapon, copied from the m4. -Example-
- |
-||
model_bounding_box¶ | -a table {x1,y1,z1,x2,y2,z2} specifying the bounding box of the model. The first 3 (x1,y1,z1) are the lower of their counterparts - |
-||
sounds¶ | a table of soundspecs to be referenced by other functions |
@@ -237,9 +217,14 @@ or you can do the same thing with a seperate class of weapons. Set name to "
||
gun_axial¶ | -total offsets of the gun in the same format as a an offset -[[total_offsets = { + | total_offsets¶ | +all offsets from gun.offset of a type added together gun in the same format as a an offset (that is, five vectors, |
+
velocities¶ | +velocities in the format of offsets, but only containing angular ( |
Ammo_handler
the class (based on) ammo_handler to create an instance of and use. Default is Guns4d.ammo_handler
Attachment_handler
attachment_handler class to use. Default is Guns4d.attachment_handler
Sprite_scope
sprite scope class to use
Dynamic_crosshair
crosshair class to use
starting vertical rotation of the gun
int
=3 how many rounds in burst using when firemode is at "burst"
string
inventory image for when the gun has no magazine
string
inventory image for when the gun is loaded. This is added automatically during construction.
an ordered list of reloading states used by default_controls.
+the default reload states for a magazine operated weapon, copied from the m4.
+{action="charge", time=.5, anim="charge", sounds={sound="ar_charge", delay = .2}},
+{action="unload_mag", time=.25, anim="unload", sounds = {sound="ar_mag_unload"}},
+{action="store", time=.5, anim="store", sounds = {sound="ar_mag_store"}},
+{action="load", time=.5, anim="load", sounds = {sound="ar_mag_load", delay = .25}},
+{action="charge", time=.5, anim="charge", sounds={sound="ar_charge", delay = .2}}
+
+a table {x1,y1,z1,x2,y2,z2} specifying the bounding box of the model. The first 3 (x1,y1,z1) are the lower of their counterparts. This is autogenerated if not present.
int
=3 how many rounds in burst using when firemode is at "burst"
table
containing a list of actions for PC users passed to Control_handler
offset¶ | -
|
-
axis_rotation_ratio¶ | -the ratio that the look rotation is expressed through player_axial (rotated around the viewport) rotation as opposed to gun_axial (rotating the entity). - |
-
sway_vel_mul¶ | -sway speed multiplier while at hip - |
-
sway_angle_mul¶ | -sway angle multiplier while at hip+ - |
-
offset¶ | +
|
+
axis_rotation_ratio¶ | +the ratio that the look rotation is expressed through player_axial (rotated around the viewport) rotation as opposed to gun_axial (rotating the entity). + |
+
sway_vel_mul¶ | +sway speed multiplier while at hip + |
+
sway_angle_mul¶ | +sway angle multiplier while at hip + |
+
list containing the firemodes of the gun. Default only contains "single". Strings allowed by default:
+list containing the firemodes of the gun. Default only contains "single". Strings allowed by default: +
single¶ | -"inventory_overlay_single.png" + | singlefire default: "inventory_overlay_single.png" |
auto¶ | -"inventory_overlay_auto.png" + | automatic default: "inventory_overlay_auto.png" |
burst¶ | -"inventory_overlay_burst.png" + | burstfire default: "inventory_overlay_burst.png" |
safe¶ | -"inventory_overlay_safe.png" (unimplemented firemode) + | safe default: "inventory_overlay_safe.png" (unimplemented firemode) |
IMPORTANT: expects fields to be tables containing a "gun_axial" and "player_axial" field.
+IMPORTANT: expects fields to be tables containing a "gun_axial" and "player_axial" field. +
property = {
gun_axial = type
@@ -528,7 +573,8 @@ this means that increasing it decreases the time it takes for the angular veloci
¶
-IMPORTANT: expects fields to be tables containing a "gun_axial" and "player_axial" field. In the same format as gun.properties.recoil
+IMPORTANT: expects fields to be tables containing a "gun_axial" and "player_axial" field. In the same format as gun.properties.recoil
+
See also properties
@@ -562,6 +608,8 @@ this means that increasing it decreases the time it takes for the angular veloci
¶
+See also properties
+
@@ -589,11 +637,13 @@ this means that increasing it decreases the time it takes for the angular veloci
¶
+See also properties
+
require_draw_on_swap¶
-bool
defines wether the draw animation is played on swap (when loaded). Used in the instance construction method
+bool
defines wether the draw animation is played on swap (when loaded). Default true.
@@ -608,12 +658,12 @@ this means that increasing it decreases the time it takes for the angular veloci
draw_animation¶
-string
name of the animation to play from visuals.animations
+string
name of the animation to play from visuals.animations. Default "draw"
draw_sound¶
-string
name of the sound to play from sounds
+string
name of the sound to play from sounds. Default "draw"
@@ -626,6 +676,8 @@ this means that increasing it decreases the time it takes for the angular veloci
¶
+See also properties
+
@@ -658,31 +710,44 @@ this means that increasing it decreases the time it takes for the angular veloci
¶
+See also properties
+
mesh¶
-name of mesh to display
+name of mesh to display. Currently only supports b3d
textures¶
-list of textures to use
+list of textures to use.
scale¶
-scale multiplier
+scale multiplier. Default 1
backface_culling¶
-toggles backface culling
+toggles backface culling. Default true
animations¶
-a table of animations in the format {x=int, y=float}. Indexes define the name of the animation to be refrenced by other functions of the gun.
+a table of animations. Indexes define the name of the animation to be refrenced by other functions of the gun.
+should be in the format {x=integer,y=integer}
+Example
+animations = {
+ empty = {x=0,y=0}
+ loaded = {x=1,y=1}
+ fire = {x=10,y=20}
+ draw = {x=24,y=30} --DEFAULT of charging.draw_animation.
+}
+
+There are other animations which are variable which are not listed here, these are usually defined by properties such as:
+reload, draw_animation
@@ -695,10 +760,11 @@ this means that increasing it decreases the time it takes for the angular veloci
¶
-a list of tables each containing offset vectors These are required for automatic initialization of offsets.
+a list of tables each containing offset vectors These are required for automatic initialization of offsets.
+note rotations are in degrees, and translations are in meters.
Example
recoil = {
- gun_axial = {x=0, y=0}, --rotation of the gun around it's origin
+ gun_axial = {x=0, y=0}, --rotation of the gun around it's origin.
player_axial = {x=0, y=0}, --rotation of the gun around the bone it's attached to
--translations of gun
player_trans = {x=0, y=0, z=0}, --translation of the bone the gun is attached to
diff --git a/docs/class/player_model_handler.html b/docs/class/player_model_handler.html
index 608ea6d..59c1cda 100644
--- a/docs/class/player_model_handler.html
+++ b/docs/class/player_model_handler.html
@@ -46,6 +46,7 @@
play_sound
Bullet_hole
Control_handler
+Gun-methods
diff --git a/docs/index.html b/docs/index.html
index 2ae2279..c2b0534 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -37,6 +37,7 @@
play_sound
Bullet_hole
Control_handler
+Gun-methods
diff --git a/docs/index.js b/docs/index.js
index 75c0c31..932231c 100644
--- a/docs/index.js
+++ b/docs/index.js
@@ -1,10 +1,11 @@
var docs = [
-{path:"class/gun.html", type:"class", title:"Gun.gun", text:"Gun class fields Defining a gun: *method documentation coming soon* (or never...) The appearance and handling of guns by default are defined by two table fields: their consts and their properties. properties define nearly everything, from how a gun handles to how it looks, what model it uses, while consts define attributes that should never change, like bones within the gun, framerates, hwether the gun is allowed to have certain attributes at all. The other fields of the class define tracking variables or other important things for the internal workings. There are essentially only 2 fields you must define to register a gun: itemstring, name, and properties To have a functional gun however, more will need to be changed in terms of properties. Guns4d uses a class system for most moving parts- including the gun. New guns therefore are created with the :inherit(def) method, where def is the definition of your new gun- or rather the changed parts of it. So to make a new gun you can run Guns4d.gun:inherit() or you can do the same thing with a seperate class of weapons. Set name to \"__template\" for template classes of guns."},
+{path:"class/gun.html", type:"class", title:"Gun.gun", text:"Gun class fields Defining a gun: *method documentation coming soon (or never...) The appearance and handling of guns by default are defined by two table fields: their consts and their properties. properties define nearly everything, from how a gun handles to how it looks, what model it uses, etc. while consts define attributes that should never change, like bones within the gun, framerates, wether the gun is allowed to have certain attributes at all. The other fields of the class define tracking variables or other important things for the internal workings. There are essentially only 3 fields you must define to register a gun: itemstring, name, and properties. To hold the gun, the item defined in itemstring must actually exist, it will not automatically register. To have a functional gun however, more will need to be changed in terms of properties. it's reccomended that you take a look at existing mods (like guns4d_pack_1) for guidance Guns4d uses a class system for most moving parts- including the gun. New guns therefore are created with the :inherit(def) method, where def is the definition of your new gun- or rather the changed parts of it. So to make a new gun you can run Guns4d.gun:inherit() or you can do the same thing with a seperate class of weapons. Set name to \"__template\" for template classes of guns. Please note:* there are likey undocumented fields that are used in internal functions. If you find one, please make an issue on Github."},
{path:"class/player_model_handler.html", type:"class", title:"Player_model_handler.player_model_handler", text:"player_model_handler defining the player model when holding a gun each player model should have a \"gun holding equivelant\". There are numerous reasons for this first and foremost is that because Minetest is a [redacted mindless insults]. because of this you cannot unset bone offsets and return to normal animations. Bone offsets are needed for the arms to aim at the gun there's no simple way around this fact. Since every model is different custom behavior has to be defined for most."},
{path:"module/misc_helpers.html", type:"module", title:"misc_helpers", text:""},
{path:"module/play_sound.html", type:"module", title:"play_sound", text:"implements tools for quickly playing audio."},
{path:"module/Bullet_hole.html", type:"module", title:"Bullet_hole", text:""},
{path:"module/Control_handler.html", type:"module", title:"Control_handler", text:""},
+{path:"module/Gun-methods.html", type:"module", title:"Gun-methods", text:""},
{path:"module/Gun.html", type:"module", title:"Gun", text:""},
{path:"module/play_sound.html#guns4d_soundspec.min_hear_distance", type:"field", title:"guns4d_soundspec.min_hear_distance", text:"float this is useful if you wish to play a sound which has a \"far\" sound, such as distant gunshots. incompatible with to_player"},
{path:"module/play_sound.html#guns4d_soundspec.sounds", type:"field", title:"guns4d_soundspec.sounds", text:"table a weighted_randoms table for randomly selecting sounds. The output will overwrite the sound field."},
@@ -18,13 +19,12 @@ var docs = [
{path:"class/gun.html#gun.consts", type:"field", title:"gun.consts", text:"constants which define gun attributes and should not be changed in an instance of the gun"},
{path:"class/gun.html#gun.offsets", type:"field", title:"gun.offsets", text:"runtime storage of offsets generated by recoil sway wag or any other element."},
{path:"class/gun.html#gun.name", type:"field", title:"gun.name", text:"string the name of the gun. Set to __template for guns which have no instances and serve as a template. It is safe to set name to the same as gun.itemstring"},
+{path:"class/gun.html#gun.itemstring", type:"field", title:"gun.itemstring", text:"string the itemstring of the gun- i.e. \"guns4d_pack_1:m4\". Set to \"\" for __template guns."},
{path:"class/gun.html#gun.itemstack", type:"field", title:"gun.itemstack", text:"ItemStack the gun itemstack. Remember to player:set_wielded_item(self.itemstack) when making meta or itemstack changes."},
+{path:"class/gun.html#gun.player", type:"field", title:"gun.player", text:"ObjRef the operator of the weapon. This may at some point be deprecated when I start to implement AI/mob usage"},
{path:"class/gun.html#gun.meta", type:"field", title:"gun.meta", text:"MetaDataRef itemstack meta"},
{path:"class/gun.html#gun.id", type:"field", title:"gun.id", text:"string the ID of the gun used for tracking of it's inventory"},
{path:"class/gun.html#gun.gun_entity", type:"field", title:"gun.gun_entity", text:"ObjRef the gun entity"},
-{path:"class/gun.html#gun.inventory_image_magless", type:"field", title:"gun.inventory_image_magless", text:"string inventory image for when the gun has no magazine"},
-{path:"class/gun.html#gun.inventory_image", type:"field", title:"gun.inventory_image", text:"string inventory image for when the gun is loaded. This is added automatically during construction."},
-{path:"class/gun.html#gun.itemstring", type:"field", title:"gun.itemstring", text:"string the itemstring of the gun- i.e. \"guns4d_pack_1:m4\". Set to \"\" for __template guns."},
{path:"class/gun.html#gun._registered", type:"field", title:"gun._registered", text:"list of registered guns, *DO NOT MODIFY* I really need a metatable for this class..."},
{path:"class/gun.html#gun.bolt_charged", type:"field", title:"gun.bolt_charged", text:"bool is the bolt charged"},
{path:"class/gun.html#gun.particle_spawners", type:"field", title:"gun.particle_spawners", text:"table list of particle spawner handles (generated by firing)"},
@@ -45,27 +45,38 @@ var docs = [
{path:"class/gun.html#lvl1_fields.properties.sway", type:"field", title:"lvl1_fields.properties.sway", text:"table defines the guns idle sway"},
{path:"class/gun.html#lvl1_fields.properties.wag", type:"field", title:"lvl1_fields.properties.wag", text:"table defines the movement of the gun while walking"},
{path:"class/gun.html#lvl1_fields.properties.charging", type:"field", title:"lvl1_fields.properties.charging", text:"table defines how rounds are chambered into the gun"},
-{path:"class/gun.html#lvl1_fields.properties.ammo", type:"field", title:"lvl1_fields.properties.ammo", text:"defines what ammo the gun uses"},
-{path:"class/gun.html#lvl1_fields.properties.visuals", type:"field", title:"lvl1_fields.properties.visuals", text:"defines visual attributes of the gun"},
+{path:"class/gun.html#lvl1_fields.properties.ammo", type:"field", title:"lvl1_fields.properties.ammo", text:"table defines what ammo the gun uses"},
+{path:"class/gun.html#lvl1_fields.properties.visuals", type:"field", title:"lvl1_fields.properties.visuals", text:"table defines visual attributes of the gun"},
+{path:"class/gun.html#lvl1_fields.properties.ammo_handler", type:"field", title:"lvl1_fields.properties.ammo_handler", text:"Ammo_handler the class (based on) ammo_handler to create an instance of and use. Default is Guns4d.ammo_handler"},
+{path:"class/gun.html#lvl1_fields.properties.attachment_handler", type:"field", title:"lvl1_fields.properties.attachment_handler", text:"Attachment_handler attachment_handler class to use. Default is Guns4d.attachment_handler"},
+{path:"class/gun.html#lvl1_fields.properties.sprite_scope", type:"field", title:"lvl1_fields.properties.sprite_scope", text:"Sprite_scope sprite scope class to use"},
+{path:"class/gun.html#lvl1_fields.properties.crosshair", type:"field", title:"lvl1_fields.properties.crosshair", text:"Dynamic_crosshair crosshair class to use"},
+{path:"class/gun.html#lvl1_fields.properties.initial_vertical_rotation", type:"field", title:"lvl1_fields.properties.initial_vertical_rotation", text:"starting vertical rotation of the gun"},
{path:"class/gun.html#lvl1_fields.properties.breathing_scale", type:"field", title:"lvl1_fields.properties.breathing_scale", text:"float=.5 max angular deviation (vertical) from breathing"},
{path:"class/gun.html#lvl1_fields.properties.flash_offset", type:"field", title:"lvl1_fields.properties.flash_offset", text:"vector the offset from the center of the muzzle flash. Used by fire()"},
{path:"class/gun.html#lvl1_fields.properties.firerateRPM", type:"field", title:"lvl1_fields.properties.firerateRPM", text:"int=600 The number of rounds (cartidges) this gun can throw per minute. Used by update(), fire() and default controls"},
-{path:"class/gun.html#gun.properties.hip.offset", type:"field", title:"gun.properties.hip.offset", text:"vector the offset of the gun (relative to the right arm's default position) at hip."},
-{path:"class/gun.html#gun.properties.hip.axis_rotation_ratio", type:"field", title:"gun.properties.hip.axis_rotation_ratio", text:"the ratio that the look rotation is expressed through player_axial (rotated around the viewport) rotation as opposed to gun_axial (rotating the entity)."},
-{path:"class/gun.html#gun.properties.hip.sway_vel_mul", type:"field", title:"gun.properties.hip.sway_vel_mul", text:"sway speed multiplier while at hip"},
-{path:"class/gun.html#gun.properties.hip.sway_angle_mul", type:"field", title:"gun.properties.hip.sway_angle_mul", text:"sway angle multiplier while at hip+"},
+{path:"class/gun.html#lvl1_fields.properties.inventory_image_magless", type:"field", title:"lvl1_fields.properties.inventory_image_magless", text:"string inventory image for when the gun has no magazine"},
+{path:"class/gun.html#lvl1_fields.properties.inventory_image", type:"field", title:"lvl1_fields.properties.inventory_image", text:"string inventory image for when the gun is loaded. This is added automatically during construction."},
+{path:"class/gun.html#lvl1_fields.properties.reload", type:"field", title:"lvl1_fields.properties.reload", text:"an ordered list of reloading states used by default_controls. the default reload states for a magazine operated weapon, copied from the m4. Example"},
+{path:"class/gun.html#lvl1_fields.properties.model_bounding_box", type:"field", title:"lvl1_fields.properties.model_bounding_box", text:"a table {x1,y1,z1,x2,y2,z2} specifying the bounding box of the model. The first 3 (x1,y1,z1) are the lower of their counterparts. This is autogenerated if not present."},
+{path:"class/gun.html#lvl1_fields.properties.infinite_inventory_overlay", type:"field", title:"lvl1_fields.properties.infinite_inventory_overlay", text:"string overlay on the item to use when infinite ammo is on"},
+{path:"class/gun.html#lvl1_fields.properties.burst", type:"field", title:"lvl1_fields.properties.burst", text:"int=3 how many rounds in burst using when firemode is at \"burst\""},
+{path:"class/gun.html#lvl1_fields.properties.pc_control_actions", type:"field", title:"lvl1_fields.properties.pc_control_actions", text:"table containing a list of actions for PC users passed to Control_handler"},
+{path:"class/gun.html#lvl1_fields.properties.touch_control_actions", type:"field", title:"lvl1_fields.properties.touch_control_actions", text:"table containing a list of actions for touch screen users passed to Control_handler"},
{path:"class/gun.html#gun.properties.ads.offset", type:"field", title:"gun.properties.ads.offset", text:"vector the offset of the gun relative to the eye's position at hip."},
{path:"class/gun.html#gun.properties.ads.horizontal_offset", type:"field", title:"gun.properties.ads.horizontal_offset", text:"float the horizontal offset of the eye when aiming"},
{path:"class/gun.html#gun.properties.ads.aim_time", type:"field", title:"gun.properties.ads.aim_time", text:"the time it takes to go into full aim"},
-{path:"class/gun.html#lvl1_fields.properties.burst", type:"field", title:"lvl1_fields.properties.burst", text:"int=3 how many rounds in burst using when firemode is at \"burst\""},
+{path:"class/gun.html#gun.properties.hip.offset", type:"field", title:"gun.properties.hip.offset", text:"vector the offset of the gun (relative to the right arm's default position) at hip."},
+{path:"class/gun.html#gun.properties.hip.axis_rotation_ratio", type:"field", title:"gun.properties.hip.axis_rotation_ratio", text:"the ratio that the look rotation is expressed through player_axial (rotated around the viewport) rotation as opposed to gun_axial (rotating the entity)."},
+{path:"class/gun.html#gun.properties.hip.sway_vel_mul", type:"field", title:"gun.properties.hip.sway_vel_mul", text:"sway speed multiplier while at hip"},
+{path:"class/gun.html#gun.properties.hip.sway_angle_mul", type:"field", title:"gun.properties.hip.sway_angle_mul", text:"sway angle multiplier while at hip"},
{path:"class/gun.html#gun.properties.firemodes."single"", type:"field", title:"gun.properties.firemodes.\"single\"", text:""},
{path:"class/gun.html#gun.properties.firemodes."burst"", type:"field", title:"gun.properties.firemodes.\"burst\"", text:""},
{path:"class/gun.html#gun.properties.firemodes."auto"", type:"field", title:"gun.properties.firemodes.\"auto\"", text:""},
-{path:"class/gun.html#lvl1_fields.properties.infinite_inventory_overlay", type:"field", title:"lvl1_fields.properties.infinite_inventory_overlay", text:"string overlay on the item to use when infinite ammo is on"},
-{path:"class/gun.html#gun.properties.firemode_inventory_overlays.single", type:"field", title:"gun.properties.firemode_inventory_overlays.single", text:"\"inventory_overlay_single.png\""},
-{path:"class/gun.html#gun.properties.firemode_inventory_overlays.auto", type:"field", title:"gun.properties.firemode_inventory_overlays.auto", text:"\"inventory_overlay_auto.png\""},
-{path:"class/gun.html#gun.properties.firemode_inventory_overlays.burst", type:"field", title:"gun.properties.firemode_inventory_overlays.burst", text:"\"inventory_overlay_burst.png\""},
-{path:"class/gun.html#gun.properties.firemode_inventory_overlays.safe", type:"field", title:"gun.properties.firemode_inventory_overlays.safe", text:"\"inventory_overlay_safe.png\" (unimplemented firemode)"},
+{path:"class/gun.html#gun.properties.firemode_inventory_overlays.single", type:"field", title:"gun.properties.firemode_inventory_overlays.single", text:"singlefire default: \"inventory_overlay_single.png\""},
+{path:"class/gun.html#gun.properties.firemode_inventory_overlays.auto", type:"field", title:"gun.properties.firemode_inventory_overlays.auto", text:"automatic default: \"inventory_overlay_auto.png\""},
+{path:"class/gun.html#gun.properties.firemode_inventory_overlays.burst", type:"field", title:"gun.properties.firemode_inventory_overlays.burst", text:"burstfire default: \"inventory_overlay_burst.png\""},
+{path:"class/gun.html#gun.properties.firemode_inventory_overlays.safe", type:"field", title:"gun.properties.firemode_inventory_overlays.safe", text:"safe default: \"inventory_overlay_safe.png\" (unimplemented firemode)"},
{path:"class/gun.html#gun.properties.recoil.velocity_correction_factor", type:"field", title:"gun.properties.recoil.velocity_correction_factor", text:"float TL:DR higher decreases recoil at expense of smoothness. 1/value is the deviation of a normalized bell curve, where x is the time since firing. this means that increasing it decreases the time it takes for the angular velocity to fully \"decay\"."},
{path:"class/gun.html#gun.properties.recoil.target_correction_factor", type:"field", title:"gun.properties.recoil.target_correction_factor", text:"float Correction of recoil offset per second is calculated as such: target_correction_factor[axis]time_since_firerecoil[axis]"},
{path:"class/gun.html#gun.properties.recoil.target_correction_max_rate", type:"field", title:"gun.properties.recoil.target_correction_max_rate", text:"float The maximum rate per second of recoil offset as determined with target_correction_factor"},
@@ -80,32 +91,29 @@ var docs = [
{path:"class/gun.html#gun.properties.wag.cycle_speed", type:"field", title:"gun.properties.wag.cycle_speed", text:"float=1.6 the cycle speed multiplier"},
{path:"class/gun.html#gun.properties.wag.decay_speed", type:"field", title:"gun.properties.wag.decay_speed", text:"float=1 decay factor when walking has stopped and offset remains."},
{path:"class/gun.html#gun.properties.wag.offset", type:"field", title:"gun.properties.wag.offset", text:"table containing angular deviation while walking in the same format as an offset vector. Acts as a multiplier on the figure-8 generated while walking."},
-{path:"class/gun.html#lvl1_fields.properties.pc_control_actions", type:"field", title:"lvl1_fields.properties.pc_control_actions", text:"table containing a list of actions for PC users passed to Control_handler"},
-{path:"class/gun.html#lvl1_fields.properties.touch_control_actions", type:"field", title:"lvl1_fields.properties.touch_control_actions", text:"table containing a list of actions for touch screen users passed to Control_handler"},
-{path:"class/gun.html#gun.properties.charging.require_draw_on_swap", type:"field", title:"gun.properties.charging.require_draw_on_swap", text:"bool defines wether the draw animation is played on swap (when loaded). Used in the instance construction method"},
+{path:"class/gun.html#gun.properties.charging.require_draw_on_swap", type:"field", title:"gun.properties.charging.require_draw_on_swap", text:"bool defines wether the draw animation is played on swap (when loaded). Default true."},
{path:"class/gun.html#gun.properties.charging.bolt_charge_mode", type:"field", title:"gun.properties.charging.bolt_charge_mode", text:"string \"none\" bolt will never need to be charged after reload, \"catch\" when fired to empty bolt will not need to be charged after reload, \"no_catch\" bolt will always need to be charged after reload."},
{path:"class/gun.html#gun.properties.charging.draw_time", type:"field", title:"gun.properties.charging.draw_time", text:"float the time it takes to swap to the gun"},
-{path:"class/gun.html#gun.properties.charging.draw_animation", type:"field", title:"gun.properties.charging.draw_animation", text:"string name of the animation to play from visuals.animations"},
-{path:"class/gun.html#gun.properties.charging.draw_sound", type:"field", title:"gun.properties.charging.draw_sound", text:"string name of the sound to play from sounds"},
-{path:"class/gun.html#gun.reload", type:"field", title:"gun.reload", text:"and ordered list of reloading states used by default_controls. the default reload states for a magazine operated weapon, copied from the m4. Example"},
+{path:"class/gun.html#gun.properties.charging.draw_animation", type:"field", title:"gun.properties.charging.draw_animation", text:"string name of the animation to play from visuals.animations. Default \"draw\""},
+{path:"class/gun.html#gun.properties.charging.draw_sound", type:"field", title:"gun.properties.charging.draw_sound", text:"string name of the sound to play from sounds. Default \"draw\""},
{path:"class/gun.html#gun.properties.ammo.magazine_only", type:"field", title:"gun.properties.ammo.magazine_only", text:"bool wether the gun only uses a magazine or accepts raw ammunition too."},
{path:"class/gun.html#gun.properties.ammo.accepted_bullets", type:"field", title:"gun.properties.ammo.accepted_bullets", text:"table a list of accepted bullet itemstrings"},
{path:"class/gun.html#gun.properties.ammo.accepted_magazines", type:"field", title:"gun.properties.ammo.accepted_magazines", text:"table a list of accepted magazine itemstrings"},
{path:"class/gun.html#gun.properties.ammo.initial_mag", type:"field", title:"gun.properties.ammo.initial_mag", text:"string the mag the gun starts with. Set to \"empty\" for no mag, otherwise it defaults to accepted_magazines[1] (if present)"},
-{path:"class/gun.html#gun.properties.visuals.mesh", type:"field", title:"gun.properties.visuals.mesh", text:"name of mesh to display"},
-{path:"class/gun.html#gun.properties.visuals.textures", type:"field", title:"gun.properties.visuals.textures", text:"list of textures to use"},
-{path:"class/gun.html#gun.properties.visuals.scale", type:"field", title:"gun.properties.visuals.scale", text:"scale multiplier"},
-{path:"class/gun.html#gun.properties.visuals.backface_culling", type:"field", title:"gun.properties.visuals.backface_culling", text:"toggles backface culling"},
-{path:"class/gun.html#gun.properties.visuals.animations", type:"field", title:"gun.properties.visuals.animations", text:"a table of animations in the format {x=int, y=float}. Indexes define the name of the animation to be refrenced by other functions of the gun."},
-{path:"class/gun.html#gun.model_bounding_box", type:"field", title:"gun.model_bounding_box", text:"a table {x1,y1,z1,x2,y2,z2} specifying the bounding box of the model. The first 3 (x1,y1,z1) are the lower of their counterparts"},
+{path:"class/gun.html#gun.properties.visuals.mesh", type:"field", title:"gun.properties.visuals.mesh", text:"name of mesh to display. Currently only supports b3d"},
+{path:"class/gun.html#gun.properties.visuals.textures", type:"field", title:"gun.properties.visuals.textures", text:"list of textures to use."},
+{path:"class/gun.html#gun.properties.visuals.scale", type:"field", title:"gun.properties.visuals.scale", text:"scale multiplier. Default 1"},
+{path:"class/gun.html#gun.properties.visuals.backface_culling", type:"field", title:"gun.properties.visuals.backface_culling", text:"toggles backface culling. Default true"},
+{path:"class/gun.html#gun.properties.visuals.animations", type:"field", title:"gun.properties.visuals.animations", text:"a table of animations. Indexes define the name of the animation to be refrenced by other functions of the gun. should be in the format {x=integer,y=integer} Example There are other animations which are variable which are not listed here, these are usually defined by properties such as: draw_animation"},
{path:"class/gun.html#gun.sounds", type:"field", title:"gun.sounds", text:"a table of soundspecs to be referenced by other functions"},
+{path:"class/gun.html#gun.animation_rotation", type:"field", title:"gun.animation_rotation", text:"vector containing the offset from animations, this will be generated if {@consts.ANIMATIONS_OFFSET_AIM}=true"},
+{path:"class/gun.html#gun.total_offsets", type:"field", title:"gun.total_offsets", text:"all offsets from gun.offset of a type added together gun in the same format as a an offset (that is, five vectors, gun_axial, player_axial, etc.). Note that if offsets are changed after update, this will not be updated automatically until the next update. update_rotations() must be called to do so."},
+{path:"class/gun.html#gun.velocities", type:"field", title:"gun.velocities", text:"velocities in the format of offsets, but only containing angular (gun_axial and player_axial) offsets."},
{path:"class/gun.html#lvl1_fields.offsets.recoil", type:"field", title:"lvl1_fields.offsets.recoil", text:""},
{path:"class/gun.html#lvl1_fields.offsets.sway", type:"field", title:"lvl1_fields.offsets.sway", text:""},
{path:"class/gun.html#lvl1_fields.offsets.walking", type:"field", title:"lvl1_fields.offsets.walking", text:""},
{path:"class/gun.html#lvl1_fields.offsets.breathing", type:"field", title:"lvl1_fields.offsets.breathing", text:""},
{path:"class/gun.html#lvl1_fields.offsets.look", type:"field", title:"lvl1_fields.offsets.look", text:""},
-{path:"class/gun.html#gun.animation_rotation", type:"field", title:"gun.animation_rotation", text:"vector containing the offset from animations, this will be generated if {@consts.ANIMATIONS_OFFSET_AIM}=true"},
-{path:"class/gun.html#gun.gun_axial", type:"field", title:"gun.gun_axial", text:"total offsets of the gun in the same format as a an offset [[total_offsets = {"},
{path:"class/gun.html#lvl1_fields.consts.KEYFRAME_SAMPLE_PRECISION", type:"field", title:"lvl1_fields.consts.KEYFRAME_SAMPLE_PRECISION", text:"frequency of keyframe samples for animation offsets and"},
{path:"class/gun.html#lvl1_fields.consts.DEFAULT_MAX_HEAR_DISTANCE", type:"field", title:"lvl1_fields.consts.DEFAULT_MAX_HEAR_DISTANCE", text:"default max hear distance when not specified"},
{path:"class/gun.html#lvl1_fields.consts.DEFAULT_FPS", type:"field", title:"lvl1_fields.consts.DEFAULT_FPS", text:"fps=60 animation fps i.e. during firing when no length is specified"},
@@ -128,6 +136,25 @@ var docs = [
{path:"module/play_sound.html#Guns4d.stop_sounds", type:"function", title:"Guns4d.stop_sounds", text:"stops a list of sounds"},
{path:"module/Bullet_hole.html#Bullet_hole.construct", type:"function", title:"Bullet_hole.construct", text:""},
{path:"module/Control_handler.html#controls.toggle_touchscreen_mode", type:"function", title:"controls:toggle_touchscreen_mode", text:""},
+{path:"module/Gun-methods.html#gun_default.update", type:"function", title:"gun_default:update", text:"The entry method for the update of the gun calls virtually all functions that begin with update once. Also updates subclass"},
+{path:"module/Gun-methods.html#gun_default.update_transforms", type:"function", title:"gun_default:update_transforms", text:"updates self.total_offsets which stores offsets for bones"},
+{path:"module/Gun-methods.html#gun_default.update_burstfire", type:"function", title:"gun_default:update_burstfire", text:"Update and fire the queued weapon burst"},
+{path:"module/Gun-methods.html#gun_default.cycle_firemodes", type:"function", title:"gun_default:cycle_firemodes", text:"cycles to the next firemode of the weapon"},
+{path:"module/Gun-methods.html#gun_default.update_image_and_text_meta", type:"function", title:"gun_default:update_image_and_text_meta", text:"update the inventory information of the gun"},
+{path:"module/Gun-methods.html#gun_default.draw", type:"function", title:"gun_default:draw", text:"plays the draw animation and sound for the gun, delays usage."},
+{path:"module/Gun-methods.html#gun_default.attempt_fire", type:"function", title:"gun_default:attempt_fire", text:"attempt to fire the gun"},
+{path:"module/Gun-methods.html#gun_default.recoil", type:"function", title:"gun_default:recoil", text:"simulate recoil by adding to the recoil velocity (called by attempt_fire)"},
+{path:"module/Gun-methods.html#gun_default.update_look_offsets", type:"function", title:"gun_default:update_look_offsets", text:"update the offsets of the player's look created by the gun"},
+{path:"module/Gun-methods.html#gun_default.get_pos", type:"function", title:"gun_default:get_pos", text:"get the global position of the gun. This is customized to rely on the assumption that there are 3-4 main rotations and 2-3 translations. If the behavior of the bones are changed this method may not work"},
+{path:"module/Gun-methods.html#gun_default.add_entity", type:"function", title:"gun_default:add_entity", text:"adds the gun entity"},
+{path:"module/Gun-methods.html#gun_default.update_entity", type:"function", title:"gun_default:update_entity", text:"updates the gun's entity"},
+{path:"module/Gun-methods.html#gun_default.has_entity", type:"function", title:"gun_default:has_entity", text:"checks if the gun entity exists..."},
+{path:"module/Gun-methods.html#gun_default.update_wag", type:"function", title:"gun_default:update_wag", text:"updates the gun's wag offset for walking"},
+{path:"module/Gun-methods.html#gun_default.update_recoil", type:"function", title:"gun_default:update_recoil", text:"updates the gun's recoil simulation"},
+{path:"module/Gun-methods.html#gun_default.update_animation", type:"function", title:"gun_default:update_animation", text:"updates the gun's animation data"},
+{path:"module/Gun-methods.html#gun_default.set_animation", type:"function", title:"gun_default:set_animation", text:"sets the gun's animation in the same format as ObjRef:set_animation() (future deprecation?)"},
+{path:"module/Gun-methods.html#gun_default.clear_animation", type:"function", title:"gun_default:clear_animation", text:"clears the animation to the rest state"},
+{path:"module/Gun-methods.html#gun_default.play_sounds", type:"function", title:"gun_default:play_sounds", text:"plays a list of sounds for the gun's user and thirdpersons"},
{path:"class/player_model_handler.html#player_model.construct", type:"function", title:"player_model.construct", text:""},
{path:"module/misc_helpers.html#math", type:"section", title:"math helpers", text:"in guns4d.math"},
{path:"module/misc_helpers.html#table", type:"section", title:"table helpers", text:"in guns4d.table"},
diff --git a/docs/module/Bullet_hole.html b/docs/module/Bullet_hole.html
index e0c2578..e848818 100644
--- a/docs/module/Bullet_hole.html
+++ b/docs/module/Bullet_hole.html
@@ -44,6 +44,7 @@
play_sound
Bullet_hole
Control_handler
+Gun-methods
diff --git a/docs/module/Control_handler.html b/docs/module/Control_handler.html
index 8927120..ae572be 100644
--- a/docs/module/Control_handler.html
+++ b/docs/module/Control_handler.html
@@ -17,7 +17,7 @@
-
+
diff --git a/docs/module/Gun-methods.html b/docs/module/Gun-methods.html
new file mode 100644
index 0000000..e568412
--- /dev/null
+++ b/docs/module/Gun-methods.html
@@ -0,0 +1,433 @@
+
+
+
+
+
+ Gun-methods - Guns4d
+
+
+
+
+
+
+
+
+
+Module Gun-methods
+¶
+
+
+
+Synopsis
+Functions
+
+
+gun_default:update()
+The entry method for the update of the gun
+
+
+
+gun_default:update_transforms()
+updates self.total_offsets which stores offsets for bones
+
+
+
+gun_default:update_burstfire()
+Update and fire the queued weapon burst
+
+
+
+gun_default:cycle_firemodes()
+cycles to the next firemode of the weapon
+
+
+
+gun_default:update_image_and_text_meta()
+update the inventory information of the gun
+
+
+
+gun_default:draw()
+plays the draw animation and sound for the gun, delays usage
+
+
+
+gun_default:attempt_fire()
+attempt to fire the gun
+
+
+
+gun_default:recoil()
+simulate recoil by adding to the recoil velocity (called by attempt_fire)
+
+
+
+gun_default:update_look_offsets()
+update the offsets of the player's look created by the gun
+
+
+
+gun_default:get_pos()
+get the global position of the gun
+
+
+
+gun_default:add_entity()
+adds the gun entity
+
+
+
+gun_default:update_entity()
+updates the gun's entity
+
+
+
+gun_default:has_entity()
+checks if the gun entity exists
+
+
+
+gun_default:update_wag()
+updates the gun's wag offset for walking
+
+
+
+gun_default:update_recoil()
+updates the gun's recoil simulation
+
+
+
+gun_default:update_animation()
+updates the gun's animation data
+
+
+
+gun_default:set_animation()
+sets the gun's animation in the same format as ObjRef:set_animation() (future deprecation?)
+
+
+
+gun_default:clear_animation()
+clears the animation to the rest state
+
+
+
+gun_default:play_sounds()
+plays a list of sounds for the gun's user and thirdpersons
+
+
+
+
+
+-
+gun_default:update(dt)
+¶
+
+-
+
The entry method for the update of the gun
+calls virtually all functions that begin with update
once. Also updates subclass
+
+Parameters
+
+
+dt
+(float)
+
+
+
+
+-
+gun_default:update_transforms()
+¶
+
+-
+
updates self.total_offsets which stores offsets for bones
+
+
+-
+gun_default:update_burstfire()
+¶
+
+-
+
Update and fire the queued weapon burst
+
+
+-
+gun_default:cycle_firemodes()
+¶
+
+-
+
cycles to the next firemode of the weapon
+
+
+-
+gun_default:update_image_and_text_meta(meta)
+¶
+
+-
+
update the inventory information of the gun
+
+
+-
+gun_default:draw()
+¶
+
+-
+
plays the draw animation and sound for the gun, delays usage.
+
+
+-
+gun_default:attempt_fire()
+¶
+
+-
+
attempt to fire the gun
+
+
+-
+gun_default:recoil()
+¶
+
+-
+
simulate recoil by adding to the recoil velocity (called by attempt_fire)
+
+
+-
+gun_default:update_look_offsets(dt)
+¶
+
+-
+
update the offsets of the player's look created by the gun
+
+
+-
+gun_default:get_pos(offset, relative_y, relative_x, with_animation)
+¶
+
+-
+
get the global position of the gun. This is customized to rely on the assumption that there are 3-4 main rotations and 2-3 translations. If the behavior of the bones are changed this method may not work
+
+Parameters
+
+
+offset
+()
+
+
+
+relative_y
+(bool)
+wether the y axis is relative to the player's look
+
+
+
+relative_x
+(bool)
+wether the x axis is relative to the player's look
+
+
+
+with_animation
+()
+
+
+
+Return Values
+
+
+(vec3)
+position of gun (in global or local orientation) relative to the player's position
+
+
+
+
+-
+gun_default:add_entity()
+¶
+
+-
+
adds the gun entity
+
+
+-
+gun_default:update_entity()
+¶
+
+-
+
updates the gun's entity
+
+
+-
+gun_default:has_entity()
+¶
+
+-
+
checks if the gun entity exists...
+
+Return Values
+
+
+(bool)
+
+
+
+
+-
+gun_default:update_wag(dt)
+¶
+
+-
+
updates the gun's wag offset for walking
+
+Parameters
+
+
+dt
+(float)
+
+
+
+
+-
+gun_default:update_recoil(dt)
+¶
+
+-
+
updates the gun's recoil simulation
+
+Parameters
+
+
+dt
+(float)
+
+
+
+
+-
+gun_default:update_animation(dt)
+¶
+
+-
+
updates the gun's animation data
+
+
+-
+gun_default:set_animation(frames, length, fps, loop)
+¶
+
+-
+
sets the gun's animation in the same format as ObjRef:set_animation() (future deprecation?)
+
+Parameters
+
+
+frames
+(table)
+{x=int, y=int}
+
+
+
+length
+(float or nil)
+length of the animation in seconds
+
+
+
+fps
+(int)
+frames per second of the animation
+
+
+
+loop
+(bool)
+wether to loop
+
+
+
+
+-
+gun_default:clear_animation()
+¶
+
+-
+
clears the animation to the rest state
+
+
+-
+gun_default:play_sounds(sound)
+¶
+
+-
+
plays a list of sounds for the gun's user and thirdpersons
+
+Parameters
+
+
+sound
+(soundspec_list)
+parameters following the format of Guns4d.play_sounds()
+
+
+
+Return Values
+
+
+1.
+(integer)
+thirdperson sound's guns4d sound handle
+
+
+
+2.
+(integer)
+firstperson sound's guns4d sound handle
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/docs/module/misc_helpers.html b/docs/module/misc_helpers.html
index e5ba31a..26125dd 100644
--- a/docs/module/misc_helpers.html
+++ b/docs/module/misc_helpers.html
@@ -50,6 +50,7 @@
play_sound
Bullet_hole
Control_handler
+Gun-methods
diff --git a/docs/module/play_sound.html b/docs/module/play_sound.html
index 6df01ce..e3e6f98 100644
--- a/docs/module/play_sound.html
+++ b/docs/module/play_sound.html
@@ -46,6 +46,7 @@
play_sound
Bullet_hole
Control_handler
+Gun-methods
diff --git a/docs/search.html b/docs/search.html
index 5a4740e..24b6ea0 100644
--- a/docs/search.html
+++ b/docs/search.html
@@ -37,6 +37,7 @@
play_sound
Bullet_hole
Control_handler
+Gun-methods
diff --git a/generate_docs/guns4d - Shortcut.lnk b/generate_docs/guns4d - Shortcut.lnk
new file mode 100644
index 0000000..944fca1
Binary files /dev/null and b/generate_docs/guns4d - Shortcut.lnk differ