import com.swath.*;
import com.swath.cmd.*;

/**
 * USDT Upgrade Steal Dump Transport
 *
 * @author Michaelis
 */
public class USDT extends UserDefinedScript {
        private Parameter planet1;
        private Parameter planet2;
        private Parameter ship1;
        private Parameter ship2;
        private Parameter product1;
        private Parameter product2;
        private Parameter times;

        public String getName() {
                return "Upgrade Steal Dump Transport";
        }

        public boolean initScript() throws Exception {
                if (!atPrompt(Swath.COMMAND_PROMPT)) return false;

                planet1 = new Parameter("Planet #1");
                planet1.setType(Parameter.INTEGER);

                ship1 = new Parameter("Ship #1");
                ship1.setType(Parameter.INTEGER);

                planet2 = new Parameter("Planet #2");
                planet2.setType(Parameter.INTEGER);

                ship2 = new Parameter("Ship #2");
                ship2.setType(Parameter.INTEGER);

                product1 = new Parameter("Product #1");
                product1.addChoice(0, "Fuel Ore");
                product1.addChoice(1, "Organics");
                product1.addChoice(2, "Equipment");
                product1.setCurrentChoice(2);

                product2 = new Parameter("Product #2");
                product2.addChoice(0, "Fuel Ore");
                product2.addChoice(1, "Organics");
                product2.addChoice(2, "Equipment");
                product2.setCurrentChoice(2);                

                times = new Parameter("# of times (0 infinite)");
                times.setType(Parameter.INTEGER);

                registerParam(planet1);
                registerParam(ship1);
                registerParam(planet2);
                registerParam(ship2);
                registerParam(product1);
                registerParam(product2);
                registerParam(times);

                return true;
        }

        public boolean runScript() throws Exception {
                
                int hld=Swath.ship.emptyHolds();
                int upg=hld/10+1;
                int ore=0;
                int org=0;
                int equ=0;
                int i=0;
                String str;
                if (times.getInteger()==0){
                        while(true){
                                if (product1.getInteger()==1){
                                        SendString.exec("o1"+upg+"\rq/");
                                        Steal.exec(Swath.FUEL_ORE);
                                }
                                if (product1.getInteger()==2){
                                        SendString.exec("o2"+upg+"\rq/");
                                        Steal.exec(Swath.ORGANICS);
                                }
                                if (product1.getInteger()==3){
                                        SendString.exec("o3"+upg+"\rq/");
                                        Steal.exec(Swath.EQUIPMENT);
                                }
                                SendString.exec("/");
                                ore=Swath.ship.fuel();
                                ore=ore * -1;
                                org=Swath.ship.organics();
                                org=org * -1;
                                equ=Swath.ship.equipment();
                                equ=equ * -1;
                                Land.exec(planet1.getInteger());
                                str="";
                                str=WaitForText.exec("[D]");
                                TakeLeaveProducts.exec(ore, org, equ);
                                LiftOff.exec();
                                Transport.exec(ship2.getInteger());
                                if (product2.getInteger()==1){
                                        SendString.exec("o1"+upg+"\rq/");
                                        Steal.exec(Swath.FUEL_ORE);
                                }
                                if (product2.getInteger()==2){
                                        SendString.exec("o2"+upg+"\rq/");
                                        Steal.exec(Swath.ORGANICS);
                                }
                                if (product2.getInteger()==3){
                                        SendString.exec("o3"+upg+"\rq/");
                                        Steal.exec(Swath.EQUIPMENT);
                                }
                                SendString.exec("/");
                                ore=Swath.ship.fuel();
                                ore=ore * -1;
                                org=Swath.ship.organics();
                                org=org * -1;
                                equ=Swath.ship.equipment();
                                equ=equ * -1;
                                Land.exec(planet1.getInteger());
                                str="";
                                str=WaitForText.exec("[D]");
                                TakeLeaveProducts.exec(ore, org, equ);
                                LiftOff.exec();
                                Transport.exec(ship1.getInteger());
                                i++;
                        }
                }
                if (times.getInteger()>0){
                        while(i != times.getInteger()){
                                if (product1.getInteger()==1){
                                        SendString.exec("o1"+upg+"\rq/");
                                        Steal.exec(Swath.FUEL_ORE);
                                }
                                if (product1.getInteger()==2){
                                        SendString.exec("o2"+upg+"\rq/");
                                        Steal.exec(Swath.ORGANICS);
                                }
                                if (product1.getInteger()==3){
                                        SendString.exec("o3"+upg+"\rq/");
                                        Steal.exec(Swath.EQUIPMENT);
                                }
                                SendString.exec("/");
                                ore=Swath.ship.fuel();
                                ore=ore * -1;
                                org=Swath.ship.organics();
                                org=org * -1;
                                equ=Swath.ship.equipment();
                                equ=equ * -1;
                                Land.exec(planet1.getInteger());
                                str="";
                                str=WaitForText.exec("[D]");
                                TakeLeaveProducts.exec(ore, org, equ);
                                LiftOff.exec();
                                Transport.exec(ship2.getInteger());
                                if (product2.getInteger()==1){
                                        SendString.exec("o1"+upg+"\rq/");
                                        Steal.exec(Swath.FUEL_ORE);
                                }
                                if (product2.getInteger()==2){
                                        SendString.exec("o2"+upg+"\rq/");
                                        Steal.exec(Swath.ORGANICS);
                                }
                                if (product2.getInteger()==3){
                                        SendString.exec("o3"+upg+"\rq/");
                                        Steal.exec(Swath.EQUIPMENT);
                                }
                                SendString.exec("/");
                                ore=Swath.ship.fuel();
                                ore=ore * -1;
                                org=Swath.ship.organics();
                                org=org * -1;
                                equ=Swath.ship.equipment();
                                equ=equ * -1;
                                Land.exec(planet1.getInteger());
                                str="";
                                str=WaitForText.exec("[D]");
                                TakeLeaveProducts.exec(ore, org, equ);
                                LiftOff.exec();
                                Transport.exec(ship1.getInteger());
                                i++;
                        }
                }        
                return true;
        }

        public void endScript(boolean finished){
        }
}
