Joined: 17 Nov 2005, 02:43 Location: Raegquitting Spring on 04/24/12
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?
Joined: 22 Feb 2006, 01:02 Location: cheap kitchen
destroy all features in a square around new buildings:
Code:
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
Joined: 17 Nov 2005, 02:43 Location: Raegquitting Spring on 04/24/12
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. :-/
Joined: 17 Nov 2005, 02:43 Location: Raegquitting Spring on 04/24/12
Code:
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
Ok, a couple hours later, we have a perfectly functioning gadget.
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.
Ideally reclaim behaviour would be separated from blocking behaviour engine side... (I assume you already tried just forcing them reclaimable and autoReclaimable?)
Joined: 22 Feb 2006, 01:02 Location: cheap kitchen
Quote:
Imo, this acts the way spring should by default
no. 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:
if FeatureDefs[Spring.GetFeatureDefID(featuresToKill[i])].name == "geovent" then
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.
Joined: 17 Nov 2005, 02:43 Location: Raegquitting Spring on 04/24/12
FLOZi wrote:
Ideally reclaim behaviour would be separated from blocking behaviour engine side... (I assume you already tried just forcing them reclaimable and autoReclaimable?)
Non-blocking features are not reclaimed when a building is placed. That's the start of the entire problem.
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.
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?
Joined: 17 Nov 2005, 02:43 Location: Raegquitting Spring on 04/24/12
Fix for geothermal vents:
Code:
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
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, 22:49, edited 2 times in total.
Joined: 17 Nov 2005, 02:43 Location: Raegquitting Spring on 04/24/12
still doesn't work.
Code:
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
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)
Users browsing this forum: No registered users and 2 guests
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum