About spawners

(Oliver) #1

I’ve been wondering how you could implement a Spawner component for Evoli. I’ve tried two approaches so far, and I’m wondering if it is possible to make the most generic one work.

First, I tried making it as generic as possible:

struct Spawner {
  // Other fields related to spawn rates
  archetype: Vec<Component>
}

Doing it this way requires me to somehow acquire storages for each of the components during system execution, but I am not sure how, if it is even possible. I was wondering if someone had some ideas on how to achieve a working implementation of this abstraction?

The other approach I tried was simply to have an ent_type that is an enum, and thus either Carnivore or Herbivore. This should be fairly simple to implement (since one could reuse creatures::create_carnivore and creatures::create_herbivore), but is also inflexible since we’d have to touch this system every time a new type of creature is added to Evoli.

struct Spawner {
  // Other fields related to spawn rates
  ent_type: SpawnerEntityType
}

As far as I understand, a long-term goal is to have more “user-defined” creature variations through mutations and such, and this implementation would not allow for that.

Does anyone have any ideas on how to implement something like the first attempt I made in specs? Or are there other flexible alternatives that might be Just As Good:tm:?

2 Likes

(Erlend Sogge Heggen) #2

I can’t speak to the implementation details but I’ll elaborate on the spec a bit since it’s been only sparsely described in the MVP doc.

My thinking for the very first iteration was that the rate at which a species spawns depends on how many species-creatures exist.

We’re gonna start off with all creatures not being assigned any type of gender. Their spawn rate is subject to a multiplier based on how many of that creature is left in the game.

Spawn formula:
Spawn rate - sr-multiplier * species #

Let’s say spawn rate for Predator is set to 12s
Spawn rate multiplier for predator is set to 0.2
Predator # is 20

0.2x20 = 4
12 - 0.2x20 = 8

A new predator should spawn every 8 seconds.

  • Spawn rate should not be able to go lower than 0.5 seconds
  • for now creatures can spawn anywhere. In a later iteration they should only spawn in a radius around other creatures.
0 Likes

(Oliver) #3

Okay, so it’s not a entity as the issue describes, but just a system?

0 Likes

(Erlend Sogge Heggen) #4

@onbjerg Did you see the conversation on Discord that led to this comment by @distransient

statically encoding the required storages in system data and just matching on the arms of an enum for the spawning logic should he just fine for Evoli

I can try copy and paste the larger discussion in here once I’m on a laptop.

If you feel you still don’t have enough to proceed feel free to keep asking questions. If you wanna let this one go that’s also fine, you’ll still be credited for getting us most of the way there :slight_smile:

0 Likes

(Erlend Sogge Heggen) #5

Work on Spawner has been continued by @sunreef:

Thanks for getting us started @onbjerg!

0 Likes