package edu.stuy.starlorn.util;

import edu.stuy.starlorn.world.Path;
import edu.stuy.starlorn.world.Wave;
import edu.stuy.starlorn.world.Level;
import edu.stuy.starlorn.entities.EnemyShip;

public class Generator {
    public static Path generatePath(int numPoints) {
        Path p = new Path();
        int screenWidth = 100;
        int screenHeight = 100;
        int firstx = (int) Math.round(Math.random()) * screenWidth; // Spawn us at one edge
        int firsty = (int) (Math.random() * screenHeight);
        p.addCoords(firstx, firsty);
        for (int i = 0; i < numPoints; i++) {
            int x = (int) (Math.random() * screenWidth);
            int y = (int) (Math.random() * screenHeight);
            p.addCoords(x, y);
        }
        p.addCoords(Math.abs(firstx - screenWidth), (int) (Math.random() *screenHeight); // Add a point somewhere on the opposite side of spawn
        return p;
    }

    public static Path generatePath() {
        return generatePath(10);
    }

    public static Wave generateWave(int dificulty) {
        Wave wave = new Wave();
        int numEnemies = (int) (Math.random() * dificulty * dificulty);
        EnemyShip enemyType = generateEnemy(dificulty);
        Path path = generatePath();
        wave.setPath(path);
        wave.setEnemyType(enemyType);
        wave.setNumEnemies(numEnemies);
        return wave;
    }

    public static Wave generateWave() {
        return generateWave(1);
    }

    public static Level generateLevel(int numWaves, int dificulty) {
        Level level = new Level();
        for (int i = 0; i < numWaves; i++) {
            level.addWave(generateWave(dificulty));
        }
        return level;
    }

    public static Level generateLevel() {
        return generateLevel(1, 1);
    }

    public static EnemyShip generateEnemy(int dificulty) {
        EnemyShip enemy = new EnemyShip();
        Path path = generatePath(dificulty + 5);
        int damage = (int) (Math.random() * dificulty); 
        int shotSpeed = (int) (Math.random() * dificulty);
        int health = (int) (Math.random() * dificulty * 10);
        int cooldown = (int) (Math.random() * (100 / dificulty) + 5);
        int cooldownRate = (int) (Math.random() * Math.log(dificulty)); // increase the cooldown rate logarithmically
        int movementSpeed = (int) (Math.random() * dificulty);
        enemy.setPath(path);
        enemy.setBaseDamage(damage);
        enemy.setBaseShotSpeed(shotSpeed);
        enemy.setMaxHealth(health);
        enemy.setCooldown(cooldown);
        enemy.setCooldownRate(cooldownRate);
        enemy.setMovementSpeed(movementSpeed);
        return enemy;
    }

    public static EnemyShip generateEnemy() {
        return generateEnemy(1);
    }
}

@@ -554,72 +554,276 @@
     
-for (int i = 0; i %3C numPoints; i++) %7B%0A            int x =
+int prevx = firstx;%0A        int prevy = firsty;%0A        for (int i = 0; i %3C numPoints; i++) %7B%0A            // Pick locations within the size of the screen / 10 nearby the previous value, and make sure it's in the range of the screen%0A            int x = (prevx +
  (int) 
+(
 (Mat
@@ -828,27 +828,34 @@
 ath.random()
+ - .5)
  * 
+(
 screenWidth)
@@ -853,17 +853,36 @@
 eenWidth
-)
+/10))) %25 screenWidth
 ;%0A      
@@ -894,23 +894,33 @@
  int y =
+ (prevy +
  (int) 
+(
 (Math.ra
@@ -917,35 +917,42 @@
  ((Math.random()
+ - .5)
  * 
+(
 screenHeight);%0A 
@@ -939,33 +939,53 @@
  * (screenHeight
-)
+/10))) %25 screenHeight
 ;%0A            p.
@@ -1098,16 +1098,17 @@
 nHeight)
+)
 ; // Add

Generate the path a bit less chaotically