summaryrefslogtreecommitdiff
path: root/graphs/cpp/caste_or_cast/queen.cc
blob: d1a998f501443c9db1fd4884f949569824196d89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "queen.hh"

#include <iostream>

#include "colony.hh"
#include "nurturer.hh"
#include "provider.hh"

void Queen::layEgg()
{
    std::cout << "Queen is laying an Egg.\n";
    // if the queen tries to lay an egg without enough food_level
    // it loses a health point
    if (food_level_ < 0)
        hp_ -= 1;
    // checking if the colony_ attribute is not expired
    std::shared_ptr<Colony> colony = check_colony_access();
    // either create a new Provider or a new Nurturer
    static bool choose = false;
    if (choose)
        eggs_queue_.emplace(std::make_shared<Provider>(
            colony, food_level_ * 0.5 + 0.2, DevelopmentStage::EGG));
    else
        eggs_queue_.emplace(std::make_shared<Nurturer>(
            colony, food_level_ * 0.1 + 0.13, DevelopmentStage::EGG));
    choose = !choose;
    // consequences of laying an egg
    colony->cleanliness -= 0.6;
    food_level_ -= 5.7;
}