Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Reverse grass-trample script  (Read 2890 times)

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Reverse grass-trample script
« on: June 29, 2016, 06:31:01 am »

I was wondering if its possible to make a sort of anti-grass-trample effect using a dfhack script. Specific units would spawn grass or run "regrass" only on the tile they are currently standing on.

It would be the regrass script limited to a single tile, using the location of a specific unit.

It would be fun to see druids walking across a glacier, sprouting grass underneath their feet.
Logged
::: ☼Meph Tileset☼☼Map Tileset☼- 32x graphic sets with TWBT :::
::: ☼MASTERWORK DF☼ - A comprehensive mod pack now on Patreon - 250.000+ downloads and counting :::
::: WorldBicyclist.com - Follow my bike tours around the world - 148 countries visited :::

milo christiansen

  • Bay Watcher
  • Something generic here
    • View Profile
Re: Reverse grass-trample script
« Reply #1 on: July 01, 2016, 02:22:31 pm »

Definitely possible, even fairly easy.

Unfortunately I am rather busy with my own (non-DF) projects at the moment...

Have you ever considered learning Lua?
Logged
Rubble 8 - The most powerful modding suite in existence!
After all, coke is for furnaces, not for snorting.
You're not true dwarven royalty unless you own the complete 'Signature Collection' baby-bone bedroom set from NOKEAS

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: Reverse grass-trample script
« Reply #2 on: July 01, 2016, 08:14:52 pm »

Would it be based on unit registering or caste registering? The former would be much faster (I mean much faster; it would only have to do the antitrample function every tick for every antitrample unit, which assumes that there's an antitrample unit in the first place among other things) but obviously wouldn't, um, allow caste registering.

Definitely possible, even fairly easy.

Unfortunately I am rather busy with my own (non-DF) projects at the moment...

Have you ever considered learning Lua?

I dunno, you'd have to make sure the unit is either:

1. on a different pos it was last tick (expensive memory-wise, not too much of a problem with 64-bit tbh)
2. currently moving and that the action in question hasn't already been operated on (expensive computation-wise, sort of; I've already written this one for sparking, so I prefer it lol)

Roses

  • Bay Watcher
    • View Profile
Re: Reverse grass-trample script
« Reply #3 on: July 01, 2016, 08:22:52 pm »

If you were ok with not regrowing grass at every tick couldn't you also check every, say 5 ticks or what have you, and fill in from the pathing array?
Logged

Pvt. Pirate

  • Bay Watcher
  • Dabbling Linux User
    • View Profile
Re: Reverse grass-trample script
« Reply #4 on: July 26, 2016, 02:48:50 am »

wouldn't it suffice to randomly have ground blocks checked for if they're any kind of soil and have a 50% chance to spawn grass on them?
Logged
"dwarves are by definition alcohol powered parasitic beards, which will cling to small caveadapt humanoids." (Chaia)

lethosor

  • Bay Watcher
    • View Profile
Re: Reverse grass-trample script
« Reply #5 on: July 26, 2016, 07:11:52 pm »


I dunno, you'd have to make sure the unit is either:

1. on a different pos it was last tick (expensive memory-wise, not too much of a problem with 64-bit tbh)
2. currently moving and that the action in question hasn't already been operated on (expensive computation-wise, sort of; I've already written this one for sparking, so I prefer it lol)
It really wouldn't take up much memory, but it could become really slow, especially if you're checking every tick. That part could be done in C++ (EventManager/eventful?), though, I guess.
Logged
DFHack - Dwarf Manipulator (Lua) - DF Wiki talk

There was a typo in the siegers' campfire code. When the fires went out, so did the game.

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: Reverse grass-trample script
« Reply #6 on: July 26, 2016, 07:21:33 pm »

It gets horrifyingly slow, and yeah, an onAction event in eventmanager for exporting to eventful would be ideal, I think.

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: Reverse grass-trample script
« Reply #7 on: July 26, 2016, 07:37:15 pm »

If its such an issue with FPS, just ignore this request... I can lock the thread too.

The script would be mostly for atmosphere, the look. Not a useful game mechanic.
Logged
::: ☼Meph Tileset☼☼Map Tileset☼- 32x graphic sets with TWBT :::
::: ☼MASTERWORK DF☼ - A comprehensive mod pack now on Patreon - 250.000+ downloads and counting :::
::: WorldBicyclist.com - Follow my bike tours around the world - 148 countries visited :::

Dirst

  • Bay Watcher
  • [EASILY_DISTRA
    • View Profile
Re: Reverse grass-trample script
« Reply #8 on: July 26, 2016, 07:44:24 pm »

Adding an onMovement event to Eventful would probably be the fastest method, but running a simple check on every unit every tick doesn't seem to be that expensive.  There's no need to preserve the position list across saves, so it's just an array of integer triples.  If every tick is too slow, just run it every 5 or 10 ticks.

Rough draft:
Code: [Select]
local was_at = {}

function checkForMovement()
for k,v in ipairs(df.global.world.units.active) do
if was_at[v.id] then
if was_at[v.id][1]~=v.pos.x or was_at[v.id][2]~=v.pos.y or was_at[v.id][1]~=v.pos.z then
was_at[v.id] = {v.pos.x,v.pos.y.v.pos.z}
-- process grass at v.pos
end
else
was_at[v.id] = {v.pos.x,v.pos.y.v.pos.z}
-- process grass at v.pos
end
end
end

require('repeat-util').scheduleEvery('onAction',1,'ticks',checkForMovement)

Alternatively, just process the tile wherever they are standing... grass continues to regenerate as they stand there.

Edit: Omitted the .id suffix as pointed out by lethosor.
« Last Edit: July 26, 2016, 08:04:27 pm by Dirst »
Logged
Just got back, updating:
(0.42 & 0.43) The Earth Strikes Back! v2.15 - Pay attention...  It's a mine!  It's-a not yours!
(0.42 & 0.43) Appearance Tweaks v1.03 - Tease those hippies about their pointy ears.
(0.42 & 0.43) Accessibility Utility v1.04 - Console tools to navigate the map

lethosor

  • Bay Watcher
    • View Profile
Re: Reverse grass-trample script
« Reply #9 on: July 26, 2016, 07:49:07 pm »

That'll probably break if units.active changes at all, which it could. You should probably use unit IDs as indices into was_at instead.
Logged
DFHack - Dwarf Manipulator (Lua) - DF Wiki talk

There was a typo in the siegers' campfire code. When the fires went out, so did the game.

Dirst

  • Bay Watcher
  • [EASILY_DISTRA
    • View Profile
Re: Reverse grass-trample script
« Reply #10 on: July 26, 2016, 08:04:47 pm »

That'll probably break if units.active changes at all, which it could. You should probably use unit IDs as indices into was_at instead.
Actually, that was supposed to be v.id as the index.  Thanks, I updated the original message.
Logged
Just got back, updating:
(0.42 & 0.43) The Earth Strikes Back! v2.15 - Pay attention...  It's a mine!  It's-a not yours!
(0.42 & 0.43) Appearance Tweaks v1.03 - Tease those hippies about their pointy ears.
(0.42 & 0.43) Accessibility Utility v1.04 - Console tools to navigate the map

Zorbeltuss

  • Bay Watcher
    • View Profile
Re: Reverse grass-trample script
« Reply #11 on: July 30, 2016, 11:42:16 pm »

If its such an issue with FPS, just ignore this request... I can lock the thread too.

The script would be mostly for atmosphere, the look. Not a useful game mechanic.
So you're saying that you don't want to chain a few druids in your indoor grazing area? ;)

/Zorbeltuss
Logged
Kun hölmöllä on moottorisaha, jokainen häviää. / Kaikki jotuvat tappiolle kun hölmöllä on moottorisaha.

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: Reverse grass-trample script
« Reply #12 on: July 31, 2016, 05:55:54 pm »

I already made a stable workshops and hay to feed to grazers once, its much more reliable. ;)
Logged
::: ☼Meph Tileset☼☼Map Tileset☼- 32x graphic sets with TWBT :::
::: ☼MASTERWORK DF☼ - A comprehensive mod pack now on Patreon - 250.000+ downloads and counting :::
::: WorldBicyclist.com - Follow my bike tours around the world - 148 countries visited :::