/**
 * Class StarSystem is an aggregate of Planets, plus it has drift boxes.
 */

import java.util.*;
public class StarSystem {
    private int starid;
    private String name;
    private Planet[] systemplanets;
    private Province province;
    Planet aggregation;

    /**
     * StarSystem(int, String, Planet[])
     * @param ID StarSystem's ID number
     * @param nam name of StarSystem
     * @param planets Planets in StarSystem
     */    
    public StarSystem (int ID, String nam, Planet[] planets) 
    {
       int i;
        starid = ID;
        name = nam;
        systemplanets = planets;
       for(i=0; i<planets.length; i++) planets[i].isInSystem(this);
    }
    
    public static StarSystem allSystem[];

    /**
     * getName()
     * Returns the StarSystem's name
     * @return StarSystem's Name
     */    
    
    public String getName()
    {
    return name;
    }
    
    /** 
     * getStarId()
     * Returns the StarSystem's ID number
     * @return StarSystem's ID Number
     */   
    
    public int getStarId()
    {
    return starid;
    }

    /** 
     * getProvince()
     * Returns the star system's Province
     * @return Province
     */   
    
    public Province getProvince()
    {
    return Province.get(starid/10);
    }
    
    
    /*
     * get(int)
     * Returns StarSystem with matching ID
     * @param id StarSystem ID Number
     * @return StarSystem
     */    
    public static StarSystem get(int id)
    {
       int i;
       for(i=0; i<25; i++)
          if (allSystem[i].getStarId() == id) return allSystem[i];
       return null;
    }
    
    /*
     *  getSystem(String)
     *  gets a Star System with the same name
     */
    
    public static StarSystem getSystem(String name)
    {
       int i;
       for(i=0; i<25; i++)
          if (allSystem[i].getName().equals(name)) return allSystem[i];
       return null;
    }
           
   /**
    * Province calls this when it is being created, please do not call it!
    */
   public void isInProvince(Province p)
   {
      province = p;
   }

   /** getsystemplanets()
    * returns the list of planets in the same star system
    * @return List of Planets in StarSystem
    */
   
   public Planet[] getsystemplanets()
   {
       return systemplanets;
   }

   /**
    * getsiblingPlanets
    * Returns the planets in the starsystem as a vector 
    * @return Vector of Planets in StarSystem
    */   
   
   public Vector getsiblingplanets()
   {
      Vector planetList = new Vector(1);

      for (int i = 0; i < systemplanets.length;i++)
          planetList.addElement(systemplanets[i]);

      return planetList;
   }

   /**
    * hasRace(String)
    * Search StarSystem and returns planets containing a race
    * @param race Race to Search for
    * @return List (Vector) of planets with Race
    */   
   
    public Vector hasRace(String race,boolean pvignored) {
      Vector Planetlist = new Vector(1);
      int currentloyalty;

      for (int j= 0; j < systemplanets.length;j++) {
          if (systemplanets[j].hasRace(race, pvignored))
             Planetlist.addElement(systemplanets[j]);
      }

      return Planetlist;
    }
    
    /**
     *getMissionChars()
     *returns a vector of planets containing characters on the specified side (Rebel or Imperial)
     */
    public Vector getMissionChars(int side)
    {
        Vector MChars=new Vector();
        int p;
        for(p=0;p<systemplanets.length;p++)
        {
            if(systemplanets[p].hasMissionChars(side))
                MChars.add(systemplanets[p]);
        }
        return MChars;
    }

   /*
    * init()
    * Initializes all the StarSystems in Freedom in the Galaxy
    */
   
    public static void init()
    {
	/*
         * have to have planets in order to have star systems.
         */
	Planet.init();

        allSystem = new StarSystem[25];
        
        Planet[] System1 = {Planet.Underworld[0],Planet.Underworld[1],Planet.Underworld[2]};
        Planet[] System2 = {Planet.Underworld[3],Planet.Underworld[4]};
        Planet[] System3 = {Planet.Underworld[5]};
        Planet[] System4 = {Planet.Underworld[6],Planet.Underworld[7],Planet.Underworld[8]};
        Planet[] System5 = {Planet.Underworld[9],Planet.Underworld[10]};
        Planet[] System6 = {Planet.Underworld[11],Planet.Underworld[12],Planet.Underworld[13]};
        Planet[] System7 = {Planet.Underworld[14],Planet.Underworld[15]};
        Planet[] System8 = {Planet.Underworld[16],Planet.Underworld[17],Planet.Underworld[18]};
        Planet[] System9 = {Planet.Underworld[19],Planet.Underworld[20]};
        Planet[] System10 = {Planet.Underworld[21]};
        Planet[] System11 = {Planet.Underworld[22],Planet.Underworld[23]};
        Planet[] System12 = {Planet.Underworld[24],Planet.Underworld[25],Planet.Underworld[26]};
        Planet[] System13 = {Planet.Underworld[27]};
        Planet[] System14 = {Planet.Underworld[28],Planet.Underworld[29]};
        Planet[] System15 = {Planet.Underworld[30],Planet.Underworld[31]};
        Planet[] System16 = {Planet.Underworld[32],Planet.Underworld[33]};
        Planet[] System17 = {Planet.Underworld[34]};
        Planet[] System18 = {Planet.Underworld[35],Planet.Underworld[36],Planet.Underworld[37]};
        Planet[] System19 = {Planet.Underworld[38],Planet.Underworld[39]};
        Planet[] System20 = {Planet.Underworld[40]};
        Planet[] System21 = {Planet.Underworld[41],Planet.Underworld[42],Planet.Underworld[43]};
        Planet[] System22 = {Planet.Underworld[44],Planet.Underworld[45],Planet.Underworld[46]};
        Planet[] System23 = {Planet.Underworld[47]};
        Planet[] System24 = {Planet.Underworld[48],Planet.Underworld[49]};
        Planet[] System25 = {Planet.Underworld[50]};

        allSystem[0] = new StarSystem(11,"Tardyn",System1);
        allSystem[1] = new StarSystem(12,"Uracus",System2);
        allSystem[2] = new StarSystem(13,"Zamorax",System3);
        allSystem[3] = new StarSystem(14,"Atriard",System4);
        allSystem[4] = new StarSystem(15,"Bex",System5);
        allSystem[5] = new StarSystem(16,"Osirius",System6);
        allSystem[6] = new StarSystem(21,"Phisaria",System7);
        allSystem[7] = new StarSystem(22,"Egrix",System8);
        allSystem[8] = new StarSystem(23,"Ancore",System9);
        allSystem[9] = new StarSystem(24,"Gellas",System10);
        allSystem[10] = new StarSystem(31,"Pycius",System11);
        allSystem[11] = new StarSystem(32,"Ribex",System12);
        allSystem[12] = new StarSystem(33,"Rorth",System13);
        allSystem[13] = new StarSystem(34,"Aziz",System14);
        allSystem[14] = new StarSystem(35,"Luine",System15);
        allSystem[15] = new StarSystem(41,"Erwind",System16);
        allSystem[16] = new StarSystem(42,"Wex",System17);
        allSystem[17] = new StarSystem(43,"Varu",System18);
        allSystem[18] = new StarSystem(44,"Deblon",System19);
        allSystem[19] = new StarSystem(45,"Martigna",System20);
        allSystem[20] = new StarSystem(51,"Zakir",System21);
        allSystem[21] = new StarSystem(52,"Eudox",System22);
        allSystem[22] = new StarSystem(53,"Corusa",System23);
        allSystem[23] = new StarSystem(54,"Irajeba",System24);
        allSystem[24] = new StarSystem(55,"Moda",System25);
       }
}
