richelbilderbeek / djog_unos_2018

Project by the Uno's at DJOG 2018-2019: Nature Zen
GNU General Public License v3.0
6 stars 2 forks source link

Any plant type should damage their own type when nearby #447

Closed richelbilderbeek closed 5 years ago

richelbilderbeek commented 5 years ago

Is your feature request related to a problem? Please describe.

Plants grow. And we let that be. But they should grow slower when too many of them are close to one another, due to light competition.

Instead of letting plants grow unconditionally, we let trees damage each other.

Describe the solution you'd like

Plants should grow normally as usual. But adjacent plants of the same type should hurt one another.

There is a test for the cacti:

  //#define FIX_ISSUE_447
  #ifdef FIX_ISSUE_447
  //Cacti damage nearby cacti
  {
    // Make two plants next to each other.
    game g({tile(0,0,0,3,3,10,tile_type::grassland)},
           {agent(agent_type::cactus, 10, 10, 10),
            agent(agent_type::cactus, 10, 10, 10)});

    // Check their initial health.
    const double prev_health1 = g.get_agents()[0].get_health();
    const double prev_health2 = g.get_agents()[1].get_health();

    // Damage time.
    for(int i = 0; i != 20; ++i){
      g.process_events();
    }

    // Check their health after doing damage
    const double after_health1 = g.get_agents()[0].get_health();
    const double after_health2 = g.get_agents()[1].get_health();

    // Plants should have damaged each other
    assert(after_health1 < prev_health1);
    assert(after_health2 < prev_health2);
  }
  #endif // FIX_ISSUE_447

Describe alternatives you've considered

None.

Additional context

None.

richelbilderbeek commented 5 years ago

Well done!