Skip to content

Commit a06fa99

Browse files
author
efrec
committed
add team to ProjectileParams wherever projectiles are spawned
This adds better support for shields to handle projectiles and removes some mysteriousness to how they are handled. I've excluded lightning sparks specifically since they deny their ownerID (it is always -1) and how would lightning know who's who, anyway (how, indeed, would any projectile know its own team, but whatever).
1 parent 17b6381 commit a06fa99

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

luarules/gadgets/unit_custom_weapons_behaviours.lua

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ local spGetProjectileTimeToLive = Spring.GetProjectileTimeToLive
3636
local spGetProjectileVelocity = Spring.GetProjectileVelocity
3737
local spGetUnitIsDead = Spring.GetUnitIsDead
3838
local spGetUnitPosition = Spring.GetUnitPosition
39+
local spGetUnitTeam = Spring.GetUnitTeam
3940
local spGetUnitWeaponState = Spring.GetUnitWeaponState
4041
local spGetUnitWeaponTarget = Spring.GetUnitWeaponTarget
4142
local spSetProjectilePosition = Spring.SetProjectilePosition
@@ -147,27 +148,29 @@ do
147148
speed = { 0, 0, 0 },
148149
gravity = gravityPerFrame,
149150
ttl = 3000,
151+
owner = -1,
152+
team = -1,
150153
}
151154

152155
---@return integer weaponDefID
153156
---@return ProjectileParams projectileParams
154157
---@return number parentSpeed
155158
getProjectileArgs = function(params, projectileID)
156-
local weaponDefID = params.speceffect_def
157-
158159
local projectileParams = projectileParams
160+
projectileParams.cegTag = params.cegtag
161+
projectileParams.model = params.model
162+
local weaponDefID = params.speceffect_def
163+
local ownerID = spGetProjectileOwnerID(projectileID)
164+
projectileParams.owner = ownerID or -1
165+
projectileParams.team = spGetUnitTeam(ownerID) or -1
159166

160167
local pos = projectileParams.pos
161168
pos[1], pos[2], pos[3] = spGetProjectilePosition(projectileID)
162169

163170
local vel = projectileParams.speed
164-
local parentSpeed
171+
local parentSpeed;
165172
vel[1], vel[2], vel[3], parentSpeed = spGetProjectileVelocity(projectileID)
166173

167-
projectileParams.owner = spGetProjectileOwnerID(projectileID)
168-
projectileParams.cegTag = params.cegtag
169-
projectileParams.model = params.model
170-
171174
return weaponDefID, projectileParams, parentSpeed
172175
end
173176
end

luarules/gadgets/unit_custom_weapons_cluster.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ local spGetProjectileDefID = Spring.GetProjectileDefID
6767
local spGetUnitDefID = Spring.GetUnitDefID
6868
local spGetUnitPosition = Spring.GetUnitPosition
6969
local spGetUnitRadius = Spring.GetUnitRadius
70+
local spGetUnitTeam = Spring.GetUnitTeam
7071
local spGetUnitsInSphere = Spring.GetUnitsInSphere
7172
local spSpawnProjectile = Spring.SpawnProjectile
7273
local spDeleteProjectile = Spring.DeleteProjectile
@@ -402,6 +403,7 @@ local function spawnClusterProjectiles(data, x, y, z, attackerID, projectileID)
402403

403404
local params = spawnCache
404405
params.owner = attackerID or -1
406+
params.team = spGetUnitTeam(attackerID)
405407
params.ttl = data.weaponTtl
406408
local speed = params.speed
407409
local position = params.pos

0 commit comments

Comments
 (0)