Jump to content

Snapping Walls


Atrik
 Share

Recommended Posts

This mod allow snapping walls to any buildings (or entities like mineral deposits), increasing drastically their potential utility by making sure to leave no gaps, and/or speed at which you can place them.

snappingwalls-min(2).thumb.png.dc2d5754d55c61b9db87b423e21d1e22.png
Walls.. That snaps... :thumbup:


I did my best for the behavior to be simple and intuitive, but there are still a couple compromises that were done. Also there are vanilla flaws with wall placements that I couldn't address.

Mod compatibility:

  • Compatible mod (can be enabled in MP)
  • Works with other mods I tested that modify inputs (autociv, customtrainer, moderngui)

Features :

  • Starting wall tower can be snapped to any edge just like regular building
  • End wall tower can be snapped to any edge but might only really works on building corners
  • Towers can be used as start or end point for wall segments
  • Can continue wall building even in fog of war
  • Can restore wall segment and continue building from captured foreign civilization
  • Can continue palisade from stone wall tower
  • Performance improvements for most situations* when placing walls

*Known exception after placing a wall tower snapped to a building edge, performance is actually worse for a couple frames.

SnappingWalls.zip

Edited by Atrik
  • Like 7
  • Thanks 1
  • Haha 1
Link to comment
Share on other sites

Updated :

  • Significant performance improvement (First version was bad, this one fix it but also improve wall placement performance impacts in general)
     
  • Now other towers can be used as a starting or end point for wall placement instead of wall towers.
    This doesn't prevent you from walling easily around them : you can also snap walls and palisades to their edges! (The threshold distance makes it so easy to choose between the two you won't even be bothered).


    hanswallsnapdemo-min.thumb.png.d7a5f2827a93d679dc6770974bb491f7.pngiberwallsnapdemo-min.thumb.png.7496732b6f997ca9d5009cf553648dae.png
  • Like 2
Link to comment
Share on other sites

4 minutes ago, Perzival12 said:

What if you add the ability to snap walls to a fortress' towers? Then fortresses would be more realistic, more useful to build, and take up less space.

Wish I could, however this would either be very complicated, or needs to be as a incompatible mod setting some references point in fort templates or something. I wanted this mod to be compatible. :laugh:

Link to comment
Share on other sites

On 16/10/2025 at 6:52 AM, Atrik said:

Updated :

  • Significant performance improvement (First version was bad, this one fix it but also improve wall placement performance impacts in general)
     
  • Now other towers can be used as a starting or end point for wall placement instead of wall towers.
    This doesn't prevent you from walling easily around them : you can also snap walls and palisades to their edges! (The threshold distance makes it so easy to choose between the two you won't even be bothered).


    hanswallsnapdemo-min.thumb.png.d7a5f2827a93d679dc6770974bb491f7.pngiberwallsnapdemo-min.thumb.png.7496732b6f997ca9d5009cf553648dae.png

Why aren't you making this a pull request?

  • Like 3
Link to comment
Share on other sites

1 hour ago, wowgetoffyourcellphone said:

Why aren't you making this a pull request?

Unlikely to be accepted as a PR.
It lengthen the code by a bit; and is probably not how one would go about to implement all of the different features I've added, without the constraint of trying to make it into a compatible mod..

Link to comment
Share on other sites

19 hours ago, Atrik said:

Unlikely to be accepted as a PR.
It lengthen the code by a bit; and is probably not how one would go about to implement all of the different features I've added, without the constraint of trying to make it into a compatible mod..

I took a quick look at the code, correct me if I'm wrong, but for a PR it looks like you could directly move most of the logic to the GuiInterface.prototype.SetWallPlacementPreview method. I don't think length would be an issue since you largely rewrote the logic of that method anyway, which is itself already quite long. And I don't think anyone would mind having a bit more code for more desired behaviour. Also, that would make it even more performant because you wouldn't have to compute the entire entity state for each snap candidate and could pull values like the position from the simulation directly, which is a lot quicker. What do you think? I believe a lot of people (including me) would love to see this added to the main game.

  • Like 5
Link to comment
Share on other sites

3 hours ago, Vantha said:

I took a quick look at the code, correct me if I'm wrong, but for a PR it looks like you could directly move most of the logic to the GuiInterface.prototype.SetWallPlacementPreview method. I don't think length would be an issue since you largely rewrote the logic of that method anyway, which is itself already quite long. And I don't think anyone would mind having a bit more code for more desired behaviour. Also, that would make it even more performant because you wouldn't have to compute the entire entity state for each snap candidate and could pull values like the position from the simulation directly, which is a lot quicker. What do you think? I believe a lot of people (including me) would love to see this added to the main game.

Thanks, I've just realized I've slept an stupid, potentially error-generating mistake so I've just re-uploaded again with tiny fix... There are also small compromises I made as said in the opening comment... And the buildings templates that can be used as end wall sections (towers) are defined arbitrarily in a constant etc... So there are a few things that needs extra work. :sweatdrop:

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

1 hour ago, Perzival12 said:
On 16/10/2025 at 7:00 PM, Perzival12 said:

By the way, your download isn't recording how many people have downloaded it. :huh:

It seems to have been fixed, the newest upload says 5 downloads. Wonder what the bug was.

You probably got confused by the counter resetting because I'm reuploading shamefully the mod every time I find some bugs coming from the mod.. :rolleyes:

4rd reupload due to poorly handled exceptions :blush:... 
Also on @Vantha's tip I've tried to see if I could get some of the logic in guiinterface. I couldn't import much logic there but in SetWallPlacementPreview we could control additional visual effects of the previews. I also rewrote some of it to be able to reason from it...

Anyways... If the mod/code is working as I think it is now (finely), my guess is that it is still not possible to PR it as long as it is a constant storing tower-like structures, usable as start/end points for wall segments.

Link to comment
Share on other sites

23 hours ago, Atrik said:

Anyways... If the mod/code is working as I think it is now (finely), my guess is that it is still not possible to PR it as long as it is a constant storing tower-like structures, usable as start/end points for wall segments.

You could either define it in the GUI globally somewhere and then pass it to every GuiInterface call, or just make it a member of the GuiInterface directly. The Engine.PickSimilarPlayerEntities method does not exist in the simulation scripting context, but the same thing can be achieved through the GetEntitiesByPlayer method combined some additional manual checks. That would also allow filtering entities by the "Tower" class instead of their template names (as you mentioned in the comment), if wanted.

By the way, the GUI already caches entity states (in g_EntityStates).

  • Thanks 1
Link to comment
Share on other sites

19 hours ago, Vantha said:

You could either define it in the GUI globally somewhere and then pass it to every GuiInterface call, or just make it a member of the GuiInterface directly. The Engine.PickSimilarPlayerEntities method does not exist in the simulation scripting context, but the same thing can be achieved through the GetEntitiesByPlayer method combined some additional manual checks. That would also allow filtering entities by the "Tower" class instead of their template names (as you mentioned in the comment), if wanted.

By the way, the GUI already caches entity states (in g_EntityStates).

Good catch for the cached entities. :rolleyes:

Alright I think I've finished this up so we might have it now. Cool enough by replacing the method to retrieve snappable entites, a couple vanilla bugs for fixed just like that; notably the inability to continue wall placement in fog of war, but also inability to build from captured walls. I've listed all features achieved in opening comment. I've tested everything I could thing of to see if any exceptions are left unhandled but I think everything seems so much better now then it ever was. :victory:

Link to comment
Share on other sites

45 minutes ago, Atrik said:

Alright I think I've finished this up so we might have it now. Cool enough by replacing the method to retrieve snappable entites, a couple vanilla bugs for fixed just like that; notably the inability to continue wall placement in fog of war, but also inability to build from captured walls. I've listed all features achieved in opening comment. I've tested everything I could thing of to see if any exceptions are left unhandled but I think everything seems so much better now then it ever was. :victory:

Very nice. It also adds the missing tooltip when the starting turret can't be placed.

Do you want to open a PR? I can help with testing and reviewing.

  • Like 1
Link to comment
Share on other sites

I've tested all cases I could think of but we can always give it a couple days to see if something broken is discovered.

If not, I don't have a gitea account or repo set up, and I might be lazy to set one up (a bit of other reasons too that makes me not want to do it maybe...). I've made a version SnappingWalls.zip of the code that use function overwrites and comments cleanup to make it easier if someone want create a PR for main game.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...