/
game_featureReclaim.lua
40 lines (35 loc) · 1.34 KB
/
game_featureReclaim.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
function gadget:GetInfo()
return {
name = "Reset Reclaim amounts",
desc = "Sets all map features to 10 energy and 0 metal",
author = "Tobi and Nemo, based on a bit by lurker, Reformed by Forboding Angel",
date = "December, 2008",
license = "public domain",
layer = 0,
enabled = false -- loaded by default?
}
end
if gadgetHandler:IsSyncedCode() then
-- SYNCED
-- The code below mimics Spring's internal reclaiming code, with the major
-- difference that no resources are ever added to anyone's storage.
-- Author: Tobi Vollebregt
local reclaimLeft = {}
local SpawnCEG = Spring.SpawnCEG
local GetFeaturePosition = Spring.GetFeaturePosition
function gadget:AllowFeatureBuildStep(builderID, builderTeam, featureID, featureDefID, part)
-- 2009/09/01: 10x faster reclaim (hence 0.1), 110 sec for standard tree seems tad bit much
reclaimLeft[featureID] = (reclaimLeft[featureID] or 0.1) + part
if (reclaimLeft[featureID] <= 0) then
Spring.DestroyFeature(featureID)
--Spring.AddTeamResource(builderTeam, "e", 1)
local fx, fy, fz = GetFeaturePosition(featureID)
Spring.PlaySoundFile("sounds/miscfx/reclaimed.wav", 0.5, fx, fy, fz)
SpawnCEG("sparklegreen", fx, fy, fz)
end
return false
end
function gadget:FeatureDestroyed(featureID, allyTeam)
reclaimLeft[featureID] = nil
end
end