void add_spawners()

in procgen/src/games/starpilot.cpp [226:327]


    void add_spawners() {
        int t = 1 + rand_gen.randint(hp_min_enemy_delta_t, hp_max_enemy_delta_t);

        bool can_spawn_left = options.distribution_mode != EasyMode;

        for (int i = 0; t <= SHOOTER_WIN_TIME; i++) {
            int group_size = 1;
            float start_weight = rand_gen.rand01() * total_prob_weight;
            float curr_weight = start_weight;
            int type;

            for (type = 2; type < NUM_BASIC_OBJECTS; type++) {
                curr_weight -= hp_object_prob_weight[type];

                if (curr_weight <= 0) {
                    break;
                }
            }

            if (type >= NUM_BASIC_OBJECTS) {
                type = NUM_BASIC_OBJECTS - 1;
            }

            float r = hp_object_r[type];
            int flyer_theme = 0;

            if (type == FLYER || type == FAST_FLYER) {
                group_size = rand_gen.randint(0, hp_max_group_size) + 1;
                flyer_theme = rand_gen.randn(NUM_SHIP_THEMES);
            }

            float y_pos = rand_pos(r, main_height);

            for (int j = 0; j < group_size; j++) {
                int spawn_time = t + j * 5;
                int fire_time = rand_gen.randint(10, 100);

                float k = 2 * PI / 4;
                float theta = (rand_gen.rand01() - .5) * k;
                float v_scale = hp_vs[type];

                if (rand_gen.randint(0, 2) == 1) {
                    theta = 0;
                }

                float health = hp_healths[type];

                if (type == METEOR || type == CLOUD) {
                    theta = 0;
                    v_scale = hp_slow_v;
                    fire_time = -1;
                } else if (type == TURRET) {
                    theta = 0;
                    v_scale = hp_slow_v;
                    fire_time = rand_gen.randint(20, 30);
                }

                v_scale *= V_SCALE;

                float vx = -1 * cos(theta) * v_scale;
                float vy = sin(theta) * v_scale;

                bool spawn_right = true;
                float x_pos;

                if (type == FLYER || type == FAST_FLYER) {
                    if (rand_gen.rand01() > hp_spawn_right_threshold && can_spawn_left) {
                        spawn_right = false;
                    }
                }

                if (spawn_right) {
                    x_pos = main_width + r;
                } else {
                    x_pos = -r;
                    vx *= -1;
                }

                auto spawner = std::make_shared<Entity>(x_pos, y_pos, vx, vy, r, type);
                spawner->fire_time = fire_time;
                spawner->spawn_time = spawn_time;
                spawner->health = health;

                if (type == CLOUD) {
                    spawner->render_z = 1;
                    choose_random_theme(spawner);
                } else if (type == METEOR) {
                    choose_random_theme(spawner);
                } else if (type == FLYER || type == FAST_FLYER) {
                    spawner->image_theme = flyer_theme;
                    spawner->rotation = ((vx > 0) ? -1 : 1) * PI / 2;
                } else if (type == TURRET) {
                    choose_random_theme(spawner);
                    match_aspect_ratio(spawner);
                }

                spawners.push_back(spawner);
            }

            t += rand_gen.randint(hp_min_enemy_delta_t, hp_max_enemy_delta_t);
        }
    }