View topic - Gadget that orders features reclaimed when placing buildings



All times are UTC + 1 hour


Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: 11 Jul 2011, 04:34 
Evolution RTS Developer
User avatar

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?


Top
 Offline Profile  
 
PostPosted: 11 Jul 2011, 05:11 
Moderator
User avatar

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

untested


Top
 Offline Profile  
 
PostPosted: 11 Jul 2011, 05:33 
Evolution RTS Developer
User avatar

Joined: 17 Nov 2005, 02:43
Location: Raegquitting Spring on 04/24/12
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


Top
 Offline Profile  
 
PostPosted: 11 Jul 2011, 06:11 
Evolution RTS Developer
User avatar

Joined: 17 Nov 2005, 02:43
Location: Raegquitting Spring on 04/24/12
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 :-)


Top
 Offline Profile  
 
PostPosted: 11 Jul 2011, 06:27 
Evolution RTS Developer
User avatar

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. :-/


Top
 Offline Profile  
 
PostPosted: 11 Jul 2011, 10:00 
Evolution RTS Developer
User avatar

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.


Top
 Offline Profile  
 
PostPosted: 11 Jul 2011, 14:15 
Moderator
User avatar

Joined: 29 Apr 2005, 00:14
Location: #moddev - join it!
Ideally reclaim behaviour would be separated from blocking behaviour engine side...
(I assume you already tried just forcing them reclaimable and autoReclaimable?)


Top
 Offline Profile  
 
PostPosted: 11 Jul 2011, 15:12 
Moderator
User avatar

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?
Image
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.


Top
 Offline Profile  
 
PostPosted: 12 Jul 2011, 10:17 
Evolution RTS Developer
User avatar

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?


Top
 Offline Profile  
 
PostPosted: 13 Jul 2011, 05:58 
Evolution RTS Developer
User avatar

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


Top
 Offline Profile  
 
PostPosted: 13 Jul 2011, 07:10 
Moderator
User avatar

Joined: 22 Feb 2006, 01:02
Location: cheap kitchen
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


Top
 Offline Profile  
 
PostPosted: 13 Jul 2011, 14:36 
Moderator
User avatar

Joined: 29 Apr 2005, 00:14
Location: #moddev - join it!
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
     
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.

Top
 Offline Profile  
 
PostPosted: 13 Jul 2011, 22:15 
Evolution RTS Developer
User avatar

Joined: 17 Nov 2005, 02:43
Location: Raegquitting Spring on 04/24/12
Doesn't work flozi. No errors tho :-)


Top
 Offline Profile  
 
PostPosted: 13 Jul 2011, 22:48 
Moderator
User avatar

Joined: 29 Apr 2005, 00:14
Location: #moddev - join it!
Try now? :(


Top
 Offline Profile  
 
PostPosted: 14 Jul 2011, 23:02 
Evolution RTS Developer
User avatar

Joined: 17 Nov 2005, 02:43
Location: Raegquitting Spring on 04/24/12
Nope. :?


Top
 Offline Profile  
 
PostPosted: 16 Jul 2011, 17:15 
Moderator
User avatar

Joined: 22 Feb 2006, 01:02
Location: cheap kitchen
knorke wrote:
in 0.83
?


Top
 Offline Profile  
 
PostPosted: 16 Jul 2011, 17:41 
Moderator
User avatar

Joined: 29 Apr 2005, 00:14
Location: #moddev - join it!
Yeah, but now featureDef.geoThermal should just return nil.


Top
 Offline Profile  
 
PostPosted: 16 Jul 2011, 18:51 
Spring Developer

Joined: 08 Oct 2006, 15:58
Code:
if (not featureDef.name == "geovent") and (not featureDef.geoThermal) then


should be

Code:
if (featureDef.name ~= "geovent") and (not featureDef.geoThermal) then


Top
 Offline Profile  
 
PostPosted: 16 Jul 2011, 20:24 
Moderator
User avatar

Joined: 29 Apr 2005, 00:14
Location: #moddev - join it!
Ah yes. I always forget that 'not' has such low precedence. :oops:


Top
 Offline Profile  
 
PostPosted: 17 Jul 2011, 05:01 
Evolution RTS Developer
User avatar

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)


Top
 Offline Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour


Who is online

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

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group

Site layout created by Roflcopter et al.