From ecea0f09d1a5cd5bfb9da76283d29058fe2e1ec2 Mon Sep 17 00:00:00 2001 From: Adam Curtis Date: Sun, 6 Sep 2015 13:24:35 -0400 Subject: [PATCH 1/9] add smart defaults for UnitTest --- .../vscripts/libraries/projectiles.lua | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/game/dota_addons/barebones/scripts/vscripts/libraries/projectiles.lua b/game/dota_addons/barebones/scripts/vscripts/libraries/projectiles.lua index 61e8950..dcfcb0b 100644 --- a/game/dota_addons/barebones/scripts/vscripts/libraries/projectiles.lua +++ b/game/dota_addons/barebones/scripts/vscripts/libraries/projectiles.lua @@ -1,4 +1,4 @@ -PROJECTILES_VERSION = "0.83" +PROJECTILES_VERSION = "0.84" PROJECTILES_THINK = 0.01 @@ -99,6 +99,18 @@ function Projectiles:CalcNormal(pos, unit, scale) return Vector(zl - zr, zd - zu, 2*scale):Normalized() end +function Projectiles:DefaultUnitTest(unit) + local source = self.Source or self.caster + if source then + if self.iUnitTargetTeam or self.iUnitTargetFlags or self.iUnitTargetType then + return 0 == UnitFilter(unit, self.iUnitTargetTeam or 0, self.iUnitTargetType or 0, self.iUnitTargetFlags or 0, source:GetTeam()) + elseif self.ability then + return 0 == UnitFilter(unit, self.ability:GetAbilityTargetTeam(), self.ability:GetAbilityTargetType(), self.ability:GetAbilityTargetFlags(), source:GetTeam()) + end + end + return false +end + PROJECTILES_NOTHING = 0 PROJECTILES_DESTROY = 1 PROJECTILES_BOUNCE = 2 @@ -128,7 +140,7 @@ function Projectiles:CreateProjectile(projectile) projectile.fGroundOffset = projectile.fGroundOffset or 40 projectile.nChangeMax = projectile.nChangeMax or 1 projectile.fChangeDelay = projectile.fChangeDelay or .1 - projectile.UnitTest = projectile.UnitTest or function() return false end + projectile.UnitTest = projectile.UnitTest or Projectiles.DefaultUnitTest projectile.OnUnitHit = projectile.OnUnitHit or function() return end projectile.OnTreeHit = projectile.OnTreeHit or function() return end projectile.OnWallHit = projectile.OnWallHit or function() return end @@ -143,7 +155,7 @@ function Projectiles:CreateProjectile(projectile) projectile.bProvidesVision = projectile.bProvidesVision or false if projectile.bFlyingVision == nil then projectile.bFlyingVision = true end projectile.iVisionRadius = projectile.iVisionRadius or 200 - projectile.iVisionTeamNumber = projectile.iVisionTeamNumber or projectile.Source:GetTeam() + projectile.iVisionTeamNumber = projectile.iVisionTeamNumber or projectile.Source:GetTeam() or projectile.caster:GetTeam() projectile.fVisionTickTime = projectile.fVisionTickTime or .1 if projectile.fVisionTickTime <= 0 then projectile.fVisionTickTime = .1 @@ -169,6 +181,9 @@ function Projectiles:CreateProjectile(projectile) projectile.vSpawnOrigin = projectile.vSpawnOrigin or Vector(0,0,0) end + if projectile.ability then + projectile.caster = projectile.ability:GetCaster() + end projectile.rehit = {} projectile.pos = projectile.vSpawnOrigin projectile.vel = projectile.vVelocity / 30 From 41db4d038f5f97e1fd18291786194a9b239c17dd Mon Sep 17 00:00:00 2001 From: Adam Curtis Date: Sun, 6 Sep 2015 13:39:14 -0400 Subject: [PATCH 2/9] add documentation to ProjectilesReadme --- ProjectilesReadme.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ProjectilesReadme.md b/ProjectilesReadme.md index ad4c4be..4faff44 100644 --- a/ProjectilesReadme.md +++ b/ProjectilesReadme.md @@ -24,6 +24,9 @@ ####**Projectiles:CalcNormal(pos, unit, scale)** This function can be used to get the estimated normal Vector of the ground at the world point Vector 'pos'. The 'unit' parameter is used to specify what unit should be used with GetGroundPosition() in order to handle the ground collision sizing. This function can return odd values when used around sheer vertical edges. +####**Projectiles:DefaultUnitTest(unit)** + This is the default UnitTest function used if none is provided. This test will use the iUnitTargetTeam, iUnitTargetType, and iUnitTargetFlags keys on the projectile, if they're specified. Otherwise, it inherits targeting rules from the ability referenced by the ability key on the projectile. If none of these keys are available, the test will simply always fail. + **Projectile Table Functions** ============================= From cf73ea364b5de0a3a15ba04e94e058a38a63cf74 Mon Sep 17 00:00:00 2001 From: Adam Curtis Date: Sun, 6 Sep 2015 13:39:43 -0400 Subject: [PATCH 3/9] fix typo in ProjectilesReadme --- ProjectilesReadme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ProjectilesReadme.md b/ProjectilesReadme.md index 4faff44..946e2ff 100644 --- a/ProjectilesReadme.md +++ b/ProjectilesReadme.md @@ -15,7 +15,7 @@ **Projectiles Library Functions** ============================= ####**Projectiles:CreateProjectile(projectile)** - This function is used to create ane release the projectile defined by the projectile table passed to the function. The function returns an updated reference to the projectile table on which the Proejctile Table Functions can be called. See the Projectiles Table Format section for more detail on what properties can be used with the projectile table. + This function is used to create ane release the projectile defined by the projectile table passed to the function. The function returns an updated reference to the projectile table on which the Projectile Table Functions can be called. See the Projectiles Table Format section for more detail on what properties can be used with the projectile table. ####**Projectiles:CalcSlope(pos, unit, dir)** From 81b33391b76238fee484f9ffbbbd69b029ca9cfa Mon Sep 17 00:00:00 2001 From: Adam Curtis Date: Sun, 6 Sep 2015 13:43:03 -0400 Subject: [PATCH 4/9] add ability key docs to ProjectilesReadme --- ProjectilesReadme.md | 1 + 1 file changed, 1 insertion(+) diff --git a/ProjectilesReadme.md b/ProjectilesReadme.md index 946e2ff..cdf4941 100644 --- a/ProjectilesReadme.md +++ b/ProjectilesReadme.md @@ -80,6 +80,7 @@ Projectiles are effectively a formatted lua table which is registered with the P | iVisionTeamNumber | <Source unit's team> | The team for which to display this projectile's vision if enabled.| | nChangeMax | 1 | The maximum number of velocity/position changes this particle can undergo before it stops allowing changing position/velocity. | | Source | <none> | The source unit of this projectile | +| ability | <none> | The ability associated with this projectile | | TreeBehavior | PROJECTILES_DESTROY | The behavior that the particle should exhibit when colliding with a tree. PROJECTILES_NOTHING means to do nothing to the projectile. PROJECTILES_DESTROY means to destroy this projectile.| | UnitBehavior | PROJECTILES_DESTROY | The behavior that the particle should exhibit when colliding with a unit which passes the UnitTest function. PROJECTILES_NOTHING means to do nothing to the projectile. PROJECTILES_DESTROY means to destroy this projectile.| | vSpawnOrigin | Vector(0,0,0) | The initial spawn world position of this projectile. Can be specified in a table form to fire from the attachment point of a unit. Ex: {unit=unitHandle, attach="attach_attack1"[, offset=Vector(0,0,80)]}| From 56eb98c992461be4279f6d176ec1c5654131320d Mon Sep 17 00:00:00 2001 From: Adam Curtis Date: Sun, 6 Sep 2015 13:45:05 -0400 Subject: [PATCH 5/9] move ability docs to preserve alphabetical order --- ProjectilesReadme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ProjectilesReadme.md b/ProjectilesReadme.md index cdf4941..ef74079 100644 --- a/ProjectilesReadme.md +++ b/ProjectilesReadme.md @@ -48,6 +48,7 @@ Projectiles are effectively a formatted lua table which is registered with the P | Property | Default | Description | | :------------ | :--------| :-----| +| ability | <none> | The ability associated with this projectile | | bProvidesVision | false | If set to true, this projectile will provide vision around it as it travels. | | bCutTrees | false | If set to true, this projectile will cut any trees that it comes in contact with. | | bFlyingVision | true | If set to true and, this projectile will provide flying vision as it travels (if bProvidesVision is enabled) | @@ -80,7 +81,6 @@ Projectiles are effectively a formatted lua table which is registered with the P | iVisionTeamNumber | <Source unit's team> | The team for which to display this projectile's vision if enabled.| | nChangeMax | 1 | The maximum number of velocity/position changes this particle can undergo before it stops allowing changing position/velocity. | | Source | <none> | The source unit of this projectile | -| ability | <none> | The ability associated with this projectile | | TreeBehavior | PROJECTILES_DESTROY | The behavior that the particle should exhibit when colliding with a tree. PROJECTILES_NOTHING means to do nothing to the projectile. PROJECTILES_DESTROY means to destroy this projectile.| | UnitBehavior | PROJECTILES_DESTROY | The behavior that the particle should exhibit when colliding with a unit which passes the UnitTest function. PROJECTILES_NOTHING means to do nothing to the projectile. PROJECTILES_DESTROY means to destroy this projectile.| | vSpawnOrigin | Vector(0,0,0) | The initial spawn world position of this projectile. Can be specified in a table form to fire from the attachment point of a unit. Ex: {unit=unitHandle, attach="attach_attack1"[, offset=Vector(0,0,80)]}| From 73f628f8fe83a5bc57e747e0f96fb3fd35e000dd Mon Sep 17 00:00:00 2001 From: Adam Curtis Date: Sun, 6 Sep 2015 13:47:54 -0400 Subject: [PATCH 6/9] capitalize ability to match naming conventions used by valve's CreateLinearProjectile etc --- ProjectilesReadme.md | 2 +- .../barebones/scripts/vscripts/libraries/projectiles.lua | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ProjectilesReadme.md b/ProjectilesReadme.md index ef74079..d93fd6b 100644 --- a/ProjectilesReadme.md +++ b/ProjectilesReadme.md @@ -48,7 +48,7 @@ Projectiles are effectively a formatted lua table which is registered with the P | Property | Default | Description | | :------------ | :--------| :-----| -| ability | <none> | The ability associated with this projectile | +| Ability | <none> | The ability associated with this projectile | | bProvidesVision | false | If set to true, this projectile will provide vision around it as it travels. | | bCutTrees | false | If set to true, this projectile will cut any trees that it comes in contact with. | | bFlyingVision | true | If set to true and, this projectile will provide flying vision as it travels (if bProvidesVision is enabled) | diff --git a/game/dota_addons/barebones/scripts/vscripts/libraries/projectiles.lua b/game/dota_addons/barebones/scripts/vscripts/libraries/projectiles.lua index dcfcb0b..1c6264a 100644 --- a/game/dota_addons/barebones/scripts/vscripts/libraries/projectiles.lua +++ b/game/dota_addons/barebones/scripts/vscripts/libraries/projectiles.lua @@ -104,8 +104,8 @@ function Projectiles:DefaultUnitTest(unit) if source then if self.iUnitTargetTeam or self.iUnitTargetFlags or self.iUnitTargetType then return 0 == UnitFilter(unit, self.iUnitTargetTeam or 0, self.iUnitTargetType or 0, self.iUnitTargetFlags or 0, source:GetTeam()) - elseif self.ability then - return 0 == UnitFilter(unit, self.ability:GetAbilityTargetTeam(), self.ability:GetAbilityTargetType(), self.ability:GetAbilityTargetFlags(), source:GetTeam()) + elseif self.Ability then + return 0 == UnitFilter(unit, self.Ability:GetAbilityTargetTeam(), self.Ability:GetAbilityTargetType(), self.Ability:GetAbilityTargetFlags(), source:GetTeam()) end end return false @@ -181,8 +181,8 @@ function Projectiles:CreateProjectile(projectile) projectile.vSpawnOrigin = projectile.vSpawnOrigin or Vector(0,0,0) end - if projectile.ability then - projectile.caster = projectile.ability:GetCaster() + if projectile.Ability then + projectile.caster = projectile.Ability:GetCaster() end projectile.rehit = {} projectile.pos = projectile.vSpawnOrigin From 1651f320205a19ac76e983f5ea61d3dc573e4c55 Mon Sep 17 00:00:00 2001 From: Adam Curtis Date: Sun, 6 Sep 2015 13:48:10 -0400 Subject: [PATCH 7/9] update ProjectilesChangeLog --- ProjectilesChangeLog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ProjectilesChangeLog.md b/ProjectilesChangeLog.md index 68e01eb..06dcdc8 100644 --- a/ProjectilesChangeLog.md +++ b/ProjectilesChangeLog.md @@ -1,5 +1,8 @@ # projectiles.lua ChangeLog +### Version 0.84 +- Added smart default behavior for UnitTest + ### Version 0.83 - Added additional guards to better handle 'script_reload' From b7a1283c85a3dc64befb6ce9789424a16a153505 Mon Sep 17 00:00:00 2001 From: Adam Curtis Date: Sun, 6 Sep 2015 14:01:16 -0400 Subject: [PATCH 8/9] minor fix to ProjectilesReadme --- ProjectilesReadme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ProjectilesReadme.md b/ProjectilesReadme.md index d93fd6b..0b31853 100644 --- a/ProjectilesReadme.md +++ b/ProjectilesReadme.md @@ -25,7 +25,7 @@ This function can be used to get the estimated normal Vector of the ground at the world point Vector 'pos'. The 'unit' parameter is used to specify what unit should be used with GetGroundPosition() in order to handle the ground collision sizing. This function can return odd values when used around sheer vertical edges. ####**Projectiles:DefaultUnitTest(unit)** - This is the default UnitTest function used if none is provided. This test will use the iUnitTargetTeam, iUnitTargetType, and iUnitTargetFlags keys on the projectile, if they're specified. Otherwise, it inherits targeting rules from the ability referenced by the ability key on the projectile. If none of these keys are available, the test will simply always fail. + This is the default UnitTest function used if none is provided. This test will use the iUnitTargetTeam, iUnitTargetType, and iUnitTargetFlags keys on the projectile, if they're specified. Otherwise, it inherits targeting rules from the ability referenced by the Ability key on the projectile. If none of these keys are available, the test will simply always fail. **Projectile Table Functions** From ea3df3fcde0700ada95db0bba9a34d4a6c1f6d6b Mon Sep 17 00:00:00 2001 From: Adam Curtis Date: Mon, 21 Sep 2015 11:03:56 -0400 Subject: [PATCH 9/9] removed Caster property and improved defaults --- .../vscripts/libraries/projectiles.lua | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/game/dota_addons/barebones/scripts/vscripts/libraries/projectiles.lua b/game/dota_addons/barebones/scripts/vscripts/libraries/projectiles.lua index 1c6264a..8db8f12 100644 --- a/game/dota_addons/barebones/scripts/vscripts/libraries/projectiles.lua +++ b/game/dota_addons/barebones/scripts/vscripts/libraries/projectiles.lua @@ -100,15 +100,8 @@ function Projectiles:CalcNormal(pos, unit, scale) end function Projectiles:DefaultUnitTest(unit) - local source = self.Source or self.caster - if source then - if self.iUnitTargetTeam or self.iUnitTargetFlags or self.iUnitTargetType then - return 0 == UnitFilter(unit, self.iUnitTargetTeam or 0, self.iUnitTargetType or 0, self.iUnitTargetFlags or 0, source:GetTeam()) - elseif self.Ability then - return 0 == UnitFilter(unit, self.Ability:GetAbilityTargetTeam(), self.Ability:GetAbilityTargetType(), self.Ability:GetAbilityTargetFlags(), source:GetTeam()) - end - end - return false + return (self.iUnitTargetTeam or self.iUnitTargetFlags or self.iUnitTargetType) + and 0 == UnitFilter(unit, self.iUnitTargetTeam or 0, self.iUnitTargetType or 0, self.iUnitTargetFlags or 0, self.Source:GetTeam()) end PROJECTILES_NOTHING = 0 @@ -151,11 +144,19 @@ function Projectiles:CreateProjectile(projectile) projectile.ControlPointOrientations = projectile.ControlPointOrientations or {} projectile.ControlPointEntityAttaches = projectile.ControlPointEntityAttaches or {} + --derive defaults from Ability, if given. + if projectile.Ability then + projectile.Source = projectile.Source or projectile.Ability:GetCaster() + projectile.iUnitTargetTeam = projectile.iUnitTargetTeam or projectile.Ability:GetAbilityTargetTeam() + projectile.iUnitTargetType = projectile.iUnitTargetType or projectile.Ability:GetAbilityTargetType() + projectile.iUnitTargetFlags = projectile.iUnitTargetFlags or projectile.Ability:GetAbilityTargetFlags() + end + if projectile.bTreeFullCollision == nil then projectile.bTreeFullCollision = false end projectile.bProvidesVision = projectile.bProvidesVision or false if projectile.bFlyingVision == nil then projectile.bFlyingVision = true end projectile.iVisionRadius = projectile.iVisionRadius or 200 - projectile.iVisionTeamNumber = projectile.iVisionTeamNumber or projectile.Source:GetTeam() or projectile.caster:GetTeam() + projectile.iVisionTeamNumber = projectile.iVisionTeamNumber or projectile.Source:GetTeam() projectile.fVisionTickTime = projectile.fVisionTickTime or .1 if projectile.fVisionTickTime <= 0 then projectile.fVisionTickTime = .1 @@ -180,10 +181,7 @@ function Projectiles:CreateProjectile(projectile) else projectile.vSpawnOrigin = projectile.vSpawnOrigin or Vector(0,0,0) end - - if projectile.Ability then - projectile.caster = projectile.Ability:GetCaster() - end + projectile.rehit = {} projectile.pos = projectile.vSpawnOrigin projectile.vel = projectile.vVelocity / 30