Gadget that orders features reclaimed when placing buildings
Moderator: Moderators
- Forboding Angel
- Evolution RTS Developer
- Posts: 14673
- Joined: 17 Nov 2005, 02:43
Gadget that orders features reclaimed when placing buildings
ok, basically, I have a bunch of features that are non-blocking. In many cases trees and such. I need a gadget that will cause anything in the unit to be built's footprint to be reclaimed by the builder, or just lolpwned (spontaneous removal), I really don't care, I just need this. Spontaneous removal would be fine... I already have an effect in mind for it, but yes please, any thoughts? Help?
Re: Gadget that orders features reclaimed when placing buildings
destroy all features in a square around new buildings:
untested
Code: Select all
local a = 200
gadget::UnitCreated(unitID, unitDefID, teamID, builderID)
if Spring.GetUnitIsBuilding (unitID then
x,y,z=Spring.GetUnitPosition (unitID)
featuresToKill = Spring.GetFeaturesInRectangle (x-a,z-a, x+a, z+a)
for i in pairs(featuresToKill) do
Spring.DestroyFeature (featuresToKill [i])
end
end
end
- Forboding Angel
- Evolution RTS Developer
- Posts: 14673
- Joined: 17 Nov 2005, 02:43
Re: Gadget that orders features reclaimed when placing buildings
You sir, are my hero! gadget hotfixes thanks you 
Edit: Crashes the gadget handler. I'm guessing because I didn't set up the gadget right:
http://pastebin.com/gNpG7jN1

Edit: Crashes the gadget handler. I'm guessing because I didn't set up the gadget right:
http://pastebin.com/gNpG7jN1
- Forboding Angel
- Evolution RTS Developer
- Posts: 14673
- Joined: 17 Nov 2005, 02:43
Re: Gadget that orders features reclaimed when placing buildings
This is the error I get:
[f=0000000] Lua LoadCode pcall error = 2, LuaRules/main.lua, error = 2, LuaRules/gadgets.lua, [string "LuaRules/gadgets.lua"]:492: attempt to index local 'info' (a nil value)
(and yes I've fixed the typo on line 16
[f=0000000] Lua LoadCode pcall error = 2, LuaRules/main.lua, error = 2, LuaRules/gadgets.lua, [string "LuaRules/gadgets.lua"]:492: attempt to index local 'info' (a nil value)
(and yes I've fixed the typo on line 16

- Forboding Angel
- Evolution RTS Developer
- Posts: 14673
- Joined: 17 Nov 2005, 02:43
Re: Gadget that orders features reclaimed when placing buildings
ok, it was somehting else crashing the gadget handler. My mistake.
Here is the current iteration (thanks for the help abma!), http://pastebin.com/index/dsQy4UaM It isn't throwing any errors, but it also isn't working. :-/
Here is the current iteration (thanks for the help abma!), http://pastebin.com/index/dsQy4UaM It isn't throwing any errors, but it also isn't working. :-/
- Forboding Angel
- Evolution RTS Developer
- Posts: 14673
- Joined: 17 Nov 2005, 02:43
Re: Gadget that orders features reclaimed when placing buildings
Code: Select all
function gadget:GetInfo()
return {
name = "Engine Hotfixes",
desc = "Hotfixes for engine behavior",
author = "knorke",
date = "July 2011",
license = "PD",
layer = 0,
enabled = true,
}
end
-- Destroy features in the build rectangle of new units for blocking features
function gadget:UnitCreated(unitID, unitDefID, teamID, builderID)
if UnitDefs[unitDefID]["canMove"] == false then
x,y,z=Spring.GetUnitPosition (unitID)
local footprintx = UnitDefs[unitDefID]["xsize"] * 4
local footprintz = UnitDefs[unitDefID]["zsize"] * 4
featuresToKill = Spring.GetFeaturesInRectangle (x-footprintx,z-footprintz, x+footprintx, z+footprintz)
for i in pairs(featuresToKill) do
-- Spring.Echo('featuresToKill :'..featuresToKill [i])
local fx,fy,fz = Spring.GetFeaturePosition(featuresToKill [i])
if featuresToKill [i] ~= 0 then
Spring.PlaySoundFile("sounds/reclaimed.wav", 1, fx, fy, fz)
Spring.SpawnCEG("sparklegreen", fx, fy, fz)
Spring.DestroyFeature (featuresToKill [i])
end
end
end
end
Huge thanks to abma and jk for helping me understand simple lua logic and helping me get it running (actually abma got it working, at which point I had ot make a lot of corrections to get it to behave how I wanted, with much help form abma and jk).
This is how it works:
When you place a building to be built, this gadget checks in that building's footprint, if there is a feature in that footprint, it is destroyed. If a feature is destroyed, a sound and a ceg will fire off at the location of the feature that was removed. So you'll want to change reclaimed.wav and sparklegreen to something applicable for your game.
Why did I need this? Because evo makes features 2x2 and smaller non blocking, which also means that when placing buildings, the 2x2 and smaller features were never reclaimed, causing a lot of graphical yukiness. Imo, this acts the way spring should by default, but yeah, with this you no longer have to worry about non-blocking features giving you grief.
Re: Gadget that orders features reclaimed when placing buildings
Ideally reclaim behaviour would be separated from blocking behaviour engine side...
(I assume you already tried just forcing them reclaimable and autoReclaimable?)
(I assume you already tried just forcing them reclaimable and autoReclaimable?)
Re: Gadget that orders features reclaimed when placing buildings
no.Imo, this acts the way spring should by default
Or what if you want features to show through certain buildings? Maybe because they mark buildable positions or something, like geovents.
Or what if all buildings are on pillars like seen below and clipping is never a problem?

Then it would be super annoying to make Spring not delete the features.
Btw, might want to check that not to delete geovent features:
Code: Select all
if FeatureDefs[Spring.GetFeatureDefID(featuresToKill[i])].name == "geovent" then
- Forboding Angel
- Evolution RTS Developer
- Posts: 14673
- Joined: 17 Nov 2005, 02:43
Re: Gadget that orders features reclaimed when placing buildings
Non-blocking features are not reclaimed when a building is placed. That's the start of the entire problem.FLOZi wrote:Ideally reclaim behaviour would be separated from blocking behaviour engine side...
(I assume you already tried just forcing them reclaimable and autoReclaimable?)
What? All these features are reclaimable, and cons move through them just fine. What are you trying to say? You mean if the coverage was uberthick?knorke wrote:If non-blocking features were reclaimable, you could never move constructors through stuff like bushes. On rightclick they would try to reclaim instead of move.
- Forboding Angel
- Evolution RTS Developer
- Posts: 14673
- Joined: 17 Nov 2005, 02:43
Re: Gadget that orders features reclaimed when placing buildings
Fix for geothermal vents:
Code: Select all
function gadget:GetInfo()
return {
name = "Engine Hotfixes",
desc = "Hotfixes for engine behavior",
author = "knorke",
date = "July 2011",
license = "PD",
layer = 0,
enabled = true,
}
end
-- Destroy features in the build rectangle of new units for blocking features
function gadget:UnitCreated(unitID, unitDefID, teamID, builderID)
if UnitDefs[unitDefID]["canMove"] == false then
x,y,z=Spring.GetUnitPosition (unitID)
local footprintx = UnitDefs[unitDefID]["xsize"] * 4
local footprintz = UnitDefs[unitDefID]["zsize"] * 4
featuresToKill = Spring.GetFeaturesInRectangle (x-footprintx,z-footprintz, x+footprintx, z+footprintz)
for i in pairs(featuresToKill) do
-- Spring.Echo('featuresToKill :'..featuresToKill [i])
local fx,fy,fz = Spring.GetFeaturePosition(featuresToKill [i])
local isGeo = FeatureDefs[Spring.GetFeatureDefID(featuresToKill[i])].name == "geovent"
if featuresToKill [i] ~= 0 and not isGeo then
Spring.PlaySoundFile("sounds/reclaimed.wav", 1, fx, fy, fz)
Spring.SpawnCEG("sparklegreen", fx, fy, fz)
Spring.DestroyFeature (featuresToKill [i])
end
end
end
end
Re: Gadget that orders features reclaimed when placing buildings
just checking if feature.name=="geovent" will not be enough in 0.83 to detect all geovent features.
instead check for the geoThermal tag
https://github.com/1231e7b84a5de93a/spr ... b073f36755
instead check for the geoThermal tag
https://github.com/1231e7b84a5de93a/spr ... b073f36755
Re: Gadget that orders features reclaimed when placing buildings
Code: Select all
function gadget:GetInfo()
return {
name = "Engine Hotfixes",
desc = "Hotfixes for engine behavior",
author = "knorke",
date = "July 2011",
license = "PD",
layer = 0,
enabled = true,
}
end
if (gadgetHandler:IsSyncedCode()) then
-- LOCALISATIONS go here (I am too lazy to do this for you)
-- Destroy features in the build rectangle of new units for blocking features
function gadget:UnitCreated(unitID, unitDefID, teamID, builderID)
if UnitDefs[unitDefID].isBuilding then
local x, y, z = Spring.GetUnitPosition (unitID)
local footprintX = UnitDefs[unitDefID]["xsize"] * 4
local footprintZ = UnitDefs[unitDefID]["zsize"] * 4
local featuresToKill = Spring.GetFeaturesInRectangle (x - footprintX, z - footprintZ, x + footprintX, z + footprintZ)
for _, featureID in pairs(featuresToKill) do
local featureDef = FeatureDefs[Spring.GetFeatureDefID(featureID)]
if (not featureDef.name == "geovent") and (not featureDef.geoThermal) then
local fx,fy,fz = Spring.GetFeaturePosition(featureID)
Spring.PlaySoundFile("sounds/reclaimed.wav", 1, fx, fy, fz)
Spring.SpawnCEG("sparklegreen", fx, fy, fz)
Spring.DestroyFeature (featureID)
end
end
end
end
end
Last edited by FLOZi on 13 Jul 2011, 23:49, edited 2 times in total.
- Forboding Angel
- Evolution RTS Developer
- Posts: 14673
- Joined: 17 Nov 2005, 02:43
Re: Gadget that orders features reclaimed when placing buildings
Doesn't work flozi. No errors tho 

- Forboding Angel
- Evolution RTS Developer
- Posts: 14673
- Joined: 17 Nov 2005, 02:43
Re: Gadget that orders features reclaimed when placing buildings
?knorke wrote:in 0.83
Re: Gadget that orders features reclaimed when placing buildings
Yeah, but now featureDef.geoThermal should just return nil.
Re: Gadget that orders features reclaimed when placing buildings
Code: Select all
if (not featureDef.name == "geovent") and (not featureDef.geoThermal) then
Code: Select all
if (featureDef.name ~= "geovent") and (not featureDef.geoThermal) then
Re: Gadget that orders features reclaimed when placing buildings
Ah yes. I always forget that 'not' has such low precedence. 

- Forboding Angel
- Evolution RTS Developer
- Posts: 14673
- Joined: 17 Nov 2005, 02:43
Re: Gadget that orders features reclaimed when placing buildings
still doesn't work.
THis does but needs additions of r.83 geovents if I understand correctly. Also, flozi, the rectangle cannot be properly drawn if I were to put the localizations where you suggest anyway (because that's where they were originally and I had to learn the hard way)
Code: Select all
function gadget:GetInfo()
return {
name = "Engine Hotfixes",
desc = "Hotfixes for engine behavior",
author = "knorke",
date = "July 2011",
license = "PD",
layer = 0,
enabled = true,
}
end
-- Destroy features in the build rectangle of new units for blocking features
function gadget:UnitCreated(unitID, unitDefID, teamID, builderID)
if UnitDefs[unitDefID]["canMove"] == false then
x,y,z=Spring.GetUnitPosition (unitID)
local footprintx = UnitDefs[unitDefID]["xsize"] * 4
local footprintz = UnitDefs[unitDefID]["zsize"] * 4
featuresToKill = Spring.GetFeaturesInRectangle (x-footprintx,z-footprintz, x+footprintx, z+footprintz)
for i in pairs(featuresToKill) do
-- Spring.Echo('featuresToKill :'..featuresToKill [i])
local fx,fy,fz = Spring.GetFeaturePosition(featuresToKill [i])
local isGeo = FeatureDefs[Spring.GetFeatureDefID(featuresToKill[i])].name == "geovent"
if featuresToKill [i] ~= 0 and not isGeo then
Spring.PlaySoundFile("sounds/reclaimed.wav", 1, fx, fy, fz)
Spring.SpawnCEG("sparklegreen", fx, fy, fz)
Spring.DestroyFeature (featuresToKill [i])
end
end
end
end