Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1] 2 3 ... 5

Author Topic: [Prealpha] Dwarfvet - Working Animal Caretakers  (Read 16298 times)

NCommander

  • Bay Watcher
  • Dwarven Military Master
    • View Profile
    • SoylentNews
[Prealpha] Dwarfvet - Working Animal Caretakers
« on: April 22, 2015, 12:16:10 pm »

The initial release of the DwarfVet plugin (with DFHack) is available for Windows and Linux for DF 43.03. PM me if you want to test. This is a very early alpha, and should not be considered complete. May cause crashes, explosions and !!fun!!. I've sent a pull request to the DFhack guys to see what they think.

Changelog
  • Initial Release

Usage Instructions
 - Enable Animal Caretaker labor on a dwarf
 - Denote an animal hospital (an activity zone that is both a hospital and an animal activity area)

Wanted
 - Any save where animals request traction or crutches.

I request that mod authors do not distribute this version of DFHack or dwarfvet with their plugins; once its feature complete, fair game.

I don't have access to a Mac, so no Mac version. if someone compiles DFHack with my plugin, I'll update this page.
« Last Edit: June 05, 2016, 08:12:54 am by NCommander »
Logged
Quote from: TheFlame52
Fucking hell man, you aren't just getting the short end of the stick, you're being beaten with it.
Quote from: NRDL
Is your plan really to flush water into hell, and have the CARP marines fight them without threat of flame or disease?  If so, you are awesome, and one of the greatest DF military visionaries I've seen yet ( not that I've seen that many, or any, for that matter )

TheFlame52

  • Bay Watcher
  • Master of the randomly generated
    • View Profile
Re: !!SCIENCE!! - Working Animal Caretakers!
« Reply #1 on: April 22, 2015, 02:26:42 pm »

Brilliant.

IRON_GAUNTLET

  • Bay Watcher
    • View Profile
Re: !!SCIENCE!! - Working Animal Caretakers!
« Reply #2 on: April 22, 2015, 03:30:20 pm »

hey, that's kind of big actually. It shouldn't be too much code for Toady to change up and fix. And I'm sure that we can figure out a way to use this for !!SCIENCE!!. Does he read the forums?
Logged
bay12: the place where the simulated mass murder of children is acceptable and even encouraged, but a demographic survey is controversial.

TheFlame52

  • Bay Watcher
  • Master of the randomly generated
    • View Profile
Re: !!SCIENCE!! - Working Animal Caretakers!
« Reply #3 on: April 22, 2015, 04:13:54 pm »

1. Can we get Ruby or Putnam in here to make a script that does this?
2. How did you do it?

NCommander

  • Bay Watcher
  • Dwarven Military Master
    • View Profile
    • SoylentNews
Re: !!SCIENCE!! - Working Animal Caretakers!
« Reply #4 on: April 22, 2015, 04:59:34 pm »

1. Can we get Ruby or Putnam in here to make a script that does this?
2. How did you do it?

Currently, not really, I'm probably going to have to implement it in C since I need to do some serious struct manipulation on the fly to make it work. Also, my hack as it is only works on critters that CAN_LEARN; what I do is mark them as dorfs in game, and wait until they generate the REST job, then change them back; the game seems to semi-remember that they're animals so animal caretaker will still grab them even if their current form is dwarf.

Using DFHack gm-editor, do the following to reproduce, NOTE: must be an animal that CAN_LEARN, animals without this are missing thought/wants structures and will reliably crash the game.

1. Injury an animal (my preferred way is to teleport them a few Z levels up)
2. Select the animal, and open it in gm-editor, modify the race to 461 for Dwarf, set the population id (may not be necessary) to match your forts pop_id, then edit enemies->current_race/original_race to 461; close and reopen the units window, you should end up with "Peasent"; they should automatically generate the diagonsis needed (you can see this on the Health screen).
3. Wait for the animal to take the REST job, then edit the values back to the original numbers
4. An animal caretaker will take the animal to the hospital, do any necessary medical work.
5. Deconstruct the bed once the dorf finishes.

Further Details:
Digging deeper into this, the game does process job structs for all units on the map, even if they are non-citizens, once the rest job is generated, everything else works, EXCEPT the job is never canceled; the animal is never moved out of bed. Unforutnately, nothing in DFHack seems to generate the job struct on the fly, so I'm going to have to do a bit of experimentation on figuring out how it works; it may just be easier to get animals to generate REST themselves if I can find the necessary logic with IDA Pro. Will keep you posted.

Second Edit

I've got the start of a plugin that at least of right now can detect if a creature has or doesn't have the rest job. I've got a livestream tonight so I won't  be able to get further but I think I can actually make this work.
« Last Edit: April 22, 2015, 05:50:19 pm by NCommander »
Logged
Quote from: TheFlame52
Fucking hell man, you aren't just getting the short end of the stick, you're being beaten with it.
Quote from: NRDL
Is your plan really to flush water into hell, and have the CARP marines fight them without threat of flame or disease?  If so, you are awesome, and one of the greatest DF military visionaries I've seen yet ( not that I've seen that many, or any, for that matter )

omega_dwarf

  • Bay Watcher
  • Adequate Architect, Dabbling Modder
    • View Profile
Re: !!SCIENCE!! - Working Animal Caretakers!
« Reply #5 on: April 23, 2015, 05:28:39 pm »

Nice work! I didn't even know that was what an animal caretaker was supposed to do :P

It's a shame Toady doesn't just fix things like this. It seems like he isn't even aware of most of them. He's focused on the future, new features, etc. Which is admirable, because it's easy to lose focus and forward progress when working on a game, but not always the greatest for playability.

NCommander

  • Bay Watcher
  • Dwarven Military Master
    • View Profile
    • SoylentNews
Re: !!SCIENCE!! - Working Animal Caretakers!
« Reply #6 on: April 23, 2015, 09:22:09 pm »

I've dug deeper into this. It actually looks like the underlying problem is Recover Wounded, *not* Rest which I thought. After a serious round of probing stuff with DFHack, animals generate the necessary health structure, and seem to use the same logic as dwarves for setting health->recovery_needed; once they're recovered, and in the hospital, everything more or less works as I described it.

The game seems hardcoded to ignore anything though with recovery_needed that isn't a dwarf. I'm pretty sure I can fix this, but I have yet to locate the code in the game which controls Recover Wounded jobs, nor have I managed to force the game to ignore the logic that cancels it out. (my guess is the game assumes if race != current_civ, the creature is a transformed werebeast).
Logged
Quote from: TheFlame52
Fucking hell man, you aren't just getting the short end of the stick, you're being beaten with it.
Quote from: NRDL
Is your plan really to flush water into hell, and have the CARP marines fight them without threat of flame or disease?  If so, you are awesome, and one of the greatest DF military visionaries I've seen yet ( not that I've seen that many, or any, for that matter )

Skullsploder

  • Bay Watcher
    • View Profile
Re: !!SCIENCE!! - Working Animal Caretakers!
« Reply #7 on: April 24, 2015, 10:35:56 am »

PTW. If you can make this into a proper plugin/fix, vanilla be damned this is something I'm downloading.
Logged
"is it harmful for my dwarves ? I bet it is"
Always a safe default assumption in this game 

Button

  • Bay Watcher
  • Plants Specialist
    • View Profile
Re: !!SCIENCE!! - Working Animal Caretakers!
« Reply #8 on: April 24, 2015, 11:48:08 am »

PTW. If you manage a binary patch to let wounded aminols be recovered, may I include it in the Modest Mod?
Logged
I used to work on Modest Mod and Plant Fixes.

Always assume I'm not seriously back

TheFlame52

  • Bay Watcher
  • Master of the randomly generated
    • View Profile
Re: !!SCIENCE!! - Working Animal Caretakers!
« Reply #9 on: April 24, 2015, 03:25:03 pm »

I really want this because medical skills are some of the few useful skills that can't be trained easily/safely. I want to make legendary bone setters by dropping dogs off a tower.

NCommander

  • Bay Watcher
  • Dwarven Military Master
    • View Profile
    • SoylentNews
Re: !!SCIENCE!! - Working Animal Caretakers!
« Reply #10 on: April 25, 2015, 12:54:50 am »

I really want this because medical skills are some of the few useful skills that can't be trained easily/safely. I want to make legendary bone setters by dropping dogs off a tower.

Ironically, I managed this in my reclaim in Failcannon; had a legendary doctor across the board in under three years due to ghost attacks.

I noticed an interesting quirk in hospital behavior today when I was streaming Shatteredlines; due to the fortress layout, the prison and the hospital overlap each other. One of my dwarves (my avatar ironically) got a beating while chained (she was No Job (Chained), and the local doctor ran into the prison, and did all the labors, only cancelling when a traction bench wasn't available. I can probably reproduce this easily enough (I've got a baron, and a mayor, with a count come), to look at the patientst struct to see if I can reproduce it accurately.

My first attempt at finding the check for the needs_recovery vector failed; I managed to find two seperate functions that look at it, but nothing that appears to look at a cast, and are called from many other points in DF; my x86 assembly isn't great so I'm not sure I can find it.I'm like seeing if I can create the necessary memory structures on the fly, its less "messy"

Other interesting facts:

1. Animals with the REST job (and presumably any other job) will try and go to whatever coordinates. When a unit is wounded but physically able to move, it will automatically path to the hospital with a bed set as the x/y/z destination

2. As best I can tell, if the unit can't move, it will pop requires_recovery if it is 1. resting, 2. conscious (even for a tick), this is why Recovering Wounded is so blasted buggy. If a unit never regains consciousness, it will never properly generate the flag

3. Once in the hospital, it will generate a patient field; I'm wondering if just creating this if the unit is in a hospital will make the magic happen.
Logged
Quote from: TheFlame52
Fucking hell man, you aren't just getting the short end of the stick, you're being beaten with it.
Quote from: NRDL
Is your plan really to flush water into hell, and have the CARP marines fight them without threat of flame or disease?  If so, you are awesome, and one of the greatest DF military visionaries I've seen yet ( not that I've seen that many, or any, for that matter )

NCommander

  • Bay Watcher
  • Dwarven Military Master
    • View Profile
    • SoylentNews
Re: !!SCIENCE!! - Working Animal Caretakers!
« Reply #11 on: April 25, 2015, 01:15:08 am »

JACKPOT, I had a thought about this after posting it, and after a bit of tweaking, I managed to get it to work as a job.









Seeing the hospital job kick during Shatteredlines made me realize what was missing. The rest job (which has flags->special set), HAS to land in the hospital. As soon as I did that with a specifically marked hospital zone. My Animal Caretaker/Doctor took off and did his job.

I also realized you can mark a hospital as a pen/pasture, and I realize while I may not be able to get recover wounded to work, I *can* generate pen/pasture jobs on the fly in their place, and simply get them to drop an animal on exactly the right space to get the hospital to work.

EDIT: I need to experiment more with Recover Wounded, although part of me feels like Pen/Pasture may be more approiate.

EDIT 2: As long as the job doesn't land in a bed, everything works perfectly. Though I've yet to manage to injury an animal in a way that requires traction (its possible only something humanoid can be tractioned)

EDIT 3: I'm fairly sure its possible we might see a cat crutch walker if there isn't logic to prevent it It appears there is active logic to prevent pets (or non humanoids) from getting traction or crutches; forcibly setting those flags are cleared immediately in the next tick.

EDIT 4: I'm open to ideas how this should work; since I can make the job basically land wherever I want, I'm wondering if the correct way to handle this is to have an animal chained up, which would mark the spot where they should land; like a bed does for a dwarf, then you can put a table and a traction bench next to it. Though IMHO, surgery seems to go find on animals w/o one ...

EDIT 5: I'm vaguely curious if a chain in hospital in a hospital zone might just make it work ... the dwarf that got healthcare in Shatteredlines did not take the rest job as far as I could tell. MORE SCIENCE! Nope, causes the rest job to cancel; I have no idea why it worked in Shatteredlines; maybe the rest job was actually there and just hidden.

EDIT 6: Since you can use this job to basically get an animal to go anywhere on command, there are interesting possibilities; you could easy cook up a mode to actively have a squad of animals to go X/Y/Z.

PTW. If you manage a binary patch to let wounded aminols be recovered, may I include it in the Modest Mod?

I'm going to post this as a merge into DFHack proper, under an open source license. You're welcome to include it in Modest Mod (or whatever), though I'd appreicate it if you credited me.

EDIT 7: holy ****, I just realized the full implications of what I could do with this; I can generate jobs related to animals on the fly, *including* give food/give water; finally a way to get animals in *general* fed and not depend on owners.
« Last Edit: April 25, 2015, 04:17:10 am by NCommander »
Logged
Quote from: TheFlame52
Fucking hell man, you aren't just getting the short end of the stick, you're being beaten with it.
Quote from: NRDL
Is your plan really to flush water into hell, and have the CARP marines fight them without threat of flame or disease?  If so, you are awesome, and one of the greatest DF military visionaries I've seen yet ( not that I've seen that many, or any, for that matter )

Di

  • Bay Watcher
    • View Profile
Re: !!SCIENCE!! - Working Animal Caretakers! (Now Reproducable On Demand)
« Reply #12 on: April 25, 2015, 04:42:19 am »

Well done!
Thought anything  related to dfhack is probably indeed more related to modding board.

Also, can these jobs be set for non civ-members?
Logged
Quote from: Creamcorn
Dwarf Fortress: Where you meet the limit of your imagination, moral compass, sanity and CPU processor.
http://www.bay12forums.com/smf/index.php?topic=103080.0 Fix sober vampires!
http://www.bay12forums.com/smf/index.php?topic=91442.0 Dwarven Cognitive Science

NCommander

  • Bay Watcher
  • Dwarven Military Master
    • View Profile
    • SoylentNews
Re: !!SCIENCE!! - Working Animal Caretakers! (Now Reproducable On Demand)
« Reply #13 on: April 25, 2015, 05:09:10 am »

Well done!
Thought anything  related to dfhack is probably indeed more related to modding board.

Also, can these jobs be set for non civ-members?

Theoretically, yes. I know digging been done for enemies. There's nothing that strictly speaking prevents any creature from taking any job; if you wanted to create an animal that ran into your fort, grabbed a workplace, created an artifact, and ran off, it should be completely doable.

EDIT: Moving this to the DF MOdding forum
« Last Edit: April 25, 2015, 05:18:57 am by NCommander »
Logged
Quote from: TheFlame52
Fucking hell man, you aren't just getting the short end of the stick, you're being beaten with it.
Quote from: NRDL
Is your plan really to flush water into hell, and have the CARP marines fight them without threat of flame or disease?  If so, you are awesome, and one of the greatest DF military visionaries I've seen yet ( not that I've seen that many, or any, for that matter )

NCommander

  • Bay Watcher
  • Dwarven Military Master
    • View Profile
    • SoylentNews
Re: !!SCIENCE!! - Working Animal Caretakers! (Now Reproducable On Demand)
« Reply #14 on: April 25, 2015, 06:30:24 am »

I've made some progress on the plugin; it currently walks the entire list of units, and looks for eligible ones. I've had to write a set of criteria; I want a sanity check to make sure this sounds good:

It first excludes all invaders, HFS, FB, titans, and dead units (as hilarious as it would be to treat fallen enemies), then it runs through the following checks:

      /**
       * So, for a unit to be elligable for the hospital, all the following must be true
       *
       * 1. It must be a member of our civilization
       * 2. It must have a health struct (which is generated by combat)
       * 3. health->requires_diagonsis must be set to true
       * 4. If health->requires_recovery is set, the creature can't move under its own power
       *    and a Recover Wounded or Pen/Pasture job MUST be created - TODO
       * 4.1 If CAN_LEARN, and can move, go to the hospital under own power
       * 4.2 If it can't move, make a hauling job happen
       * 4.3 If in a cage/chain, Pen/Pasture it to the hospital
       * 5. It must be tame (semi-wild counts for this(?))
       * 6. An open spot in the "Animal Hospital" (activity zone with hospital+animal training set)
       *     must be available
       */

2 and 3 seem to work reliably. I need to science 4 to see if that actually works; I think it does, but my method of animal injuring isn't precise enough to know for sure. If anyone knows how to maim any animal reliably to the point they can't walk, let me know. Otherwise, I'm building a kittypault.

With dwarves, they'll automatically path to the hospital, and sit in a bed. I think the correct thing to do is check the critter for the CAN_LEARN tag, and if its there, do that (out of the box, I think gremlins are the only tamable CAN_LEARN boost). Otherwise we're going to need a recover task; I haven't gotten these working reliably, but abusing pen/pasture could do the trick.

4.1 (Caged/Chained) is annoying. I had issues with recovered wounded and animals, and I doubt it would work for a critter in a cage/pen (else we'd never have caged dwarves). Not sure how to get a critter out of a cage. Plus the headache of putting them BACK in a cage; we may end up in a "hilarious" situation where the Animal Caretaker, and the Pen/Pasture get in a tug-of-war (though given its an injured animal, for all I know, they might both win). I'm hoping zone.cpp has most of this logic figured out for sheer sanity reasons.

5 is semi-problematic; I don't do a lot of animal training in my forts, so I'm probably going to have to build a fort entirely for this purpose and watch how animals go wild. I'm guessing the tame status goes to 9 (WildUntamed), but the civ flag isn't cleared, which is why they're TRAPAVOID; I might as well fix this case as well while I'm here.

6. This was the closest I could think equals animal hospital. We don't want to send them to a regular hospital because if they go into a bed, they seem to get stuck and never leave until its deconstruction. Animal health jobs never seem to cause traction or crutch requests, so it shouldn't be a BIG deal, but I'm thinking I'm going to be dropping every animal in vanilla a couple of Z levels and mopping up the bits.

Logged
Quote from: TheFlame52
Fucking hell man, you aren't just getting the short end of the stick, you're being beaten with it.
Quote from: NRDL
Is your plan really to flush water into hell, and have the CARP marines fight them without threat of flame or disease?  If so, you are awesome, and one of the greatest DF military visionaries I've seen yet ( not that I've seen that many, or any, for that matter )
Pages: [1] 2 3 ... 5