jpw1991 / chebs-necromancy

Cheb's Necromancy adds Necromancy to Valheim via craftable wands and structures. Minions will follow you, guard your base, and perform menial tasks.
The Unlicense
10 stars 4 forks source link

Insane Idea: Neckro Hivemind #132

Closed jpw1991 closed 1 year ago

jpw1991 commented 1 year ago

Description

I've noticed that sometimes multiple Neckros attempt to get the same item. This gave me an insane idea.

Imagine if the Neckros all saw what every other Neckros sees and knows which one of them is pursuing an item? They could then organise themselves far better. If a Neckro knows that his buddy is already getting the Greydwarf Eye, then he can instead go and grab the Resin.

Is the feature related to a problem?

Yes. Seeing multiple Neckros run for the same object.

Solutions

Maybe something like a static dictionary (key: GameObject, value: Neckro) of GameObjects and their corresponding Neckro. Neckros check the static dictionary for valueless keys and if one is found, it puts itself there. When the item gets picked up, the Neckro deletes it from the dictionary and looks again. If the dictionary ever becomes empty, all Neckros perform a little scan in their area and add to the dictionary.

image

CW-Jesse commented 1 year ago

Not at all insane! And this feels like a problem with an elegant solution. Like, each ItemDrop could do a search for the nearest neckro and tell the neckro to pick it up if the neckro doesn't have any goals or if it's closer than the neckro's current goal.

jpw1991 commented 1 year ago

Not at all insane! And this feels like a problem with an elegant solution. Like, each ItemDrop could do a search for the nearest neckro and tell the neckro to pick it up if the neckro doesn't have any goals or if it's closer than the neckro's current goal.

I think that having each ItemDrop search for a Neckro would be insanely inefficient because it'd add overhead even when Neckros aren't around, and there'd be potentially hundreds of items searching for necks. Having the Neckros search for items is better because it'd be more efficient due to less objects searching.

But maybe you know something I don't? or I understood wrongly. Not sure

jpw1991 commented 1 year ago

I gave your idea more thought, and I think it could work like the following:

  1. Static list of Neckros
  2. ItemDrop awake does a distance check on nearby necks from static list, orders by closest to furthest
  3. Alerts the closest neck, it walks to get it

Yeah that should work and also be pretty efficient

CW-Jesse commented 1 year ago

Looks like you're right! I underestimated how many ItemDrops there were. I was thinking there'd often be fewer ItemDrops than neckros, but a quick look tells me that's not true.

All right, a neckro-out search makes sense.

CW-Jesse commented 1 year ago

The fastest thing to do is probably what you originally said, just to have each neckro "claim" the item it's going towards, which removes it from the list of items other neckros can look at. The Dictionary you originally described doesn't have to contain every item as a key; items should be added as keys once a neckro claims it.

CW-Jesse commented 1 year ago

I was... going for perfect, and what we want is fast and "good enough", which is its own type of perfect.

CW-Jesse commented 1 year ago

I guess it doesn't have to be a dictionary, then. Just a "claimed" list.

jpw1991 commented 1 year ago

I was... going for perfect, and what we want is fast and "good enough", which is its own type of perfect.

Very true haha

jpw1991 commented 1 year ago

Would you like to do this one, or should I?

CW-Jesse commented 1 year ago

Please do!

jpw1991 commented 1 year ago

Alright. This is ready to test