package mygame;
import com.jme3.app.SimpleApplication;
import com.jme3.input.KeyInput;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import java.util.ArrayList;
import com.jme3.input.MouseInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.input.controls.MouseButtonTrigger;
import com.jme3.light.AmbientLight;
import com.jme3.light.DirectionalLight;
import com.jme3.light.PointLight;
import com.jme3.math.FastMath;
import com.jme3.math.Quaternion;
import com.jme3.post.FilterPostProcessor;
import com.jme3.scene.Spatial;
import com.jme3.system.AppSettings;
import com.jme3.texture.Texture2D;
import com.jme3.ui.Picture;
import com.jme3.water.WaterFilter;
import java.util.LinkedList;
public class Main extends SimpleApplication {
public static void main(final String[] args) {
Main app = new Main();
AppSettings settings = new AppSettings(false);
settings.setFullscreen(false);
settings.setTitle("Containing");
settings.setSettingsDialogImage("/Interface/containing.jpg");
app.setSettings(settings);
app.start();
// Create Client. That gets the commands from Controller.
Thread EchoClientSimmulator = new Thread(){
public void run(){
EchoClient.main(args);
}
};
EchoClientSimmulator.start();
}
// zoek uit hoe een echte string buffer werkt. "roundedbuffer."
static LinkedList<String> inputBuffer = new LinkedList();
ArrayList<Truck> truckList = new ArrayList<Truck>();
ArrayList<TruckCrane> truckCraneList = new ArrayList<TruckCrane>();
ArrayList<ShipCrane> shipCraneList = new ArrayList<ShipCrane>();
ArrayList<SeaShipCrane> seaShipCraneList = new ArrayList<SeaShipCrane>();
ArrayList<Container> containerList = new ArrayList<Container>();
ArrayList<AGV> AGVList = new ArrayList<AGV>();
ArrayList<StorageCrane> storageCraneList = new ArrayList<StorageCrane>();
Box floor;
Quaternion pitch90 = new Quaternion();
// JOS
Spatial scene;
FilterPostProcessor fpp;
private WaterFilter water;
public ArrayList<Container> contList = new ArrayList<Container>();
ArrayList<BargeShip> bList = new ArrayList<BargeShip>();
SeaShip s;
Train train;
Train [] wagons = new Train[35];
//universele schaal
public static final float Scale = 2f;
Container shipcontainers[][][] = new Container[20][6][16];
@Override
public void simpleInitApp() {
viewPort.setBackgroundColor(ColorRGBA.LightGray);
flyCam.setMoveSpeed(300);
flyCam.setRotationSpeed(10f);
cam.setLocation(new Vector3f(10f,20f,-35f)); // set cam location
cam.setFrustumFar(9000); // set how far cam can see
cam.onFrameChange();
//initFloor();// create floor.
//Jos`
initPPcWater();
initScene();
Interface();
initLight();
Platform p = new Platform(rootNode, assetManager); // place the floor
// spawn 10 ship cranes.
for(int i = 0; i < 10; i++)
{
//truckList.get(i).truckNode.setLocalTranslation(-778 - (i*2.9f),- 11.45f,300);
seaShipCraneList.add(new SeaShipCrane(this.rootNode, this.assetManager, new Vector3f(875,0,350-(i*60))));
}
for(int i = 0; i < 100; i++)
{
containerList.add( new Container(this.rootNode, this.assetManager));
truckList.add( new Truck(this.rootNode, this.assetManager));
truckList.get(i).addContainer(containerList.get(i));
AGVList.add(new AGV(this.rootNode, this.assetManager));
// fix for placement of agv/trucks.
int value = 0;
try{
value = Math.round(i/6);
//System.out.println("Value! "+ value);
}
catch(Exception e){
//halp
}
truckList.get(i).truckNode.setLocalTranslation(-805 + (i*2.9f) + (value * 1.8f),- 11.45f,300);
AGVList.get(i).agvNode.setLocalTranslation(-805 + (i*2.9f) + (value * 1.8f),- 11.45f,-300);
/*=======
truckList.get(i).truckNode.setLocalTranslation(-800 - (i*5),- 11.45f,-360);
AGVList.get(i).agvNode.setLocalTranslation(200 - (10*i), - 11.45f, -300);
truckCraneList.add( new TruckCrane(this.rootNode, this.assetManager,
new Vector3f(-80 - (i*20),0,-400)));
}
// spawn 10 seaship cranes
for(int i = 0; i < 10; i++)
{
seaShipCraneList.add(new SeaShipCrane(this.rootNode, this.assetManager, new Vector3f(875,0,350-(i*60))));
>>>>>>> master2*/
}
for(int i = 0; i < 8; i++){
if(shipCraneList.size() < 4)
shipCraneList.add(new ShipCrane(this.rootNode, this.assetManager, new Vector3f(680-(i*60),0,-450)));
else
shipCraneList.add(new ShipCrane(this.rootNode, this.assetManager, new Vector3f(680-((i*60)+170),0,-450)));
}
// spawn 10 truckcranes. Place AGVs and trucks at a location.
for(int k=0; k < 20;k++)
{
truckCraneList.add( new TruckCrane(this.rootNode, this.assetManager,
new Vector3f(-80 - (k*10),0,-400)));
/*truckCraneList.get(k).setAGV(AGVList.get(k));
truckCraneList.get(k).setTruck(truckList.get(k));*/
//truckList.get(k).truckNode.setLocalTranslation(-150+(10*k), - 11.45f, 150);
//AGVList.get(k).agvNode.setLocalTranslation(150+(10*k), - 11.45f, -150);
//useCommand("tc " + k + " 1");
}
/* shipCraneList.add( new ShipCrane(this.rootNode, this.assetManager,
new Vector3f(100,0,0)));
seaShipCraneList.add( new SeaShipCrane(this.rootNode, this.assetManager,
new Vector3f(-100,0,0)));*/
// spawn new bargeships
for(int i = 0; i < 2; i++)
{
bList.add(new BargeShip(rootNode, assetManager));
}
float x1 = 0f;
float z1 = 0;
for (BargeShip b : bList)
{
b.shipNode.setLocalTranslation(x1, 0f, z1);
x1 += 400f;
}
s = new SeaShip(rootNode, assetManager); // spawn a big ship
newTrain(20);
for(int i = 0; i < 80; i++){
storageCraneList.add(
new StorageCrane(this.rootNode, this.assetManager,
new Vector3f(-797.5f+(i*19.2f),0,300)));
}
s = new SeaShip(rootNode, assetManager); // spawn a big ship.
//s.rootNode.
// input commands for testing use.
inputManager.addMapping("shoot",
new MouseButtonTrigger(MouseInput.BUTTON_LEFT) );
inputManager.addMapping("play",
new MouseButtonTrigger(MouseInput.BUTTON_RIGHT));
inputManager.addListener(actionListener, "shoot", "play");
useCommand("cmd storage2 1 44");
}
// <editor-fold defaultstate="collapsed" desc="Platformen eromheen">
private void TreinPlatform(){
Box platform = new Box(534f, 30f, 1107f);
Geometry p = new Geometry("platform", platform);
Material plat_mat;
plat_mat = new Material (assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
p.setMaterial(plat_mat);
p.setLocalTranslation(0, -15f, 1326f);
plat_mat.setColor("Color", ColorRGBA.LightGray);
this.rootNode.attachChild(p);
}
private void AchterPlatform(){
Box platform = new Box(1107f, 30f, 1534);
Geometry p = new Geometry("platform", platform);
Material plat_mat;
plat_mat = new Material (assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
p.setMaterial(plat_mat);
p.setLocalTranslation(-1641f, -15f, 213f);
plat_mat.setColor("Color", ColorRGBA.LightGray);
this.rootNode.attachChild(p);
}
private void VrachtwagenPlatform(){
Box platform = new Box(267f, 30f, 50f);
Geometry p = new Geometry("platform", platform);
Material plat_mat;
plat_mat = new Material (assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
p.setMaterial(plat_mat);
p.setLocalTranslation(-300f, -15f, -271f);
plat_mat.setColor("Color", ColorRGBA.LightGray);
this.rootNode.attachChild(p);
}
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="Lichten">
private void initLight()
{
AmbientLight ambient = new AmbientLight();
ambient.setColor(ColorRGBA.White);
rootNode.addLight(ambient);
PointLight lamp = new PointLight();
lamp.setPosition(Vector3f.ZERO);
lamp.setColor(ColorRGBA.White);
lamp.setRadius(4000f);
lamp.setPosition(new Vector3f(1,1150,1));
rootNode.addLight(lamp);
DirectionalLight sun = new DirectionalLight();
sun.setDirection((new Vector3f(-0.5f, -0.5f, -0.5f)).normalizeLocal());
sun.setColor(ColorRGBA.White);
rootNode.addLight(sun);
}
//</editor-fold>
// <editor-fold defaultstate="collapsed" desc="Scene">
private void initScene(){
scene = assetManager.loadModel("Scenes/Scene.j3o");
rootNode.attachChild(scene);
}
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="Water">
public void initPPcWater()
{
fpp = new FilterPostProcessor(assetManager);
water = new WaterFilter(rootNode, new Vector3f (-4f,-1f,5f));
water.setCenter(Vector3f.ZERO);
water.setRadius(260000000);
water.setWaveScale(0.012f);
water.setMaxAmplitude(2f); //0.5
water.setFoamExistence(new Vector3f(1f, 4f, 0.5f));
water.setFoamTexture((Texture2D) assetManager.loadTexture("Common/MatDefs/Water/Textures/foam.jpg"));
water.setRefractionStrength(0.2f);
water.setWaterHeight(-20f);
fpp.addFilter(water);
viewPort.addProcessor(fpp);
}
//</editor-fold>
// <editor-fold defaultstate="collapsed" desc="InitInputs">
public void initInputs(){
inputManager.addMapping("shoot",
new KeyTrigger(KeyInput.KEY_P));
ActionListener AL = new ActionListener() {
public void onAction(String name, boolean keyPressed, float tpf) {
if (name.equals("shoot") && keyPressed) {
System.out.println("Start ship");
s.setMotion();
s.playMotion();
for (BargeShip b : bList){
b.setMotion();
b.playMotion();
}
}
}
};
inputManager.addListener(AL, "shoot");
};
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="Interface">
public void Interface(){
setDisplayStatView(false); setDisplayFps(false);
Picture pic = new Picture("HUD Picture");
pic.setImage(assetManager, "Textures/nhl.png", true);
pic.setWidth(settings.getWidth()/5);
pic.setHeight(settings.getHeight()/5);
pic.setPosition(0f,20f);
Picture pic2 = new Picture("HUD Picture");
pic2.setImage(assetManager, "Textures/groep5.png", true);
pic2.setWidth(settings.getWidth()/5);
pic2.setHeight(settings.getHeight()/3);
pic2.setPosition(settings.getWidth()/1.25f, settings.getHeight()/1.5f);
guiNode.attachChild(pic);
guiNode.attachChild(pic2);
}
// </editor-fold>
//Train
public void newTrain(int awagon)
{
for(int i=0; i<awagon;i++)
{
train = new Train(assetManager);
train.setLocalTranslation((400f - (36.9f*i)), -13.5f, 410f);
wagons[i] = train;
rootNode.attachChild(wagons[i]);
}
}
@Override
public void simpleUpdate(float tpf) {
//TODO: add update code
while (!inputBuffer.isEmpty())
{
System.out.println("pop" + inputBuffer.getFirst());
useCommand(inputBuffer.pop());
}
// for(AGV agv : AGVList)
// {
// agv.move();
// }
// for(Truck truck : truckList)
// {
// truck.move();
// }
// for(TruckCrane tc: truckCraneList)
// {
// tc.setContainerLoc();
// }
for(ShipCrane sc: shipCraneList)
{
sc.moveMagnet();
}
for(SeaShipCrane ssc: seaShipCraneList)
{
ssc.moveMagnet();
}
}
// Get a string convert it to a command.
public void useCommand(String command){
String[] parts = command.split(" ");
//if(parts.length == 3){
String cmd = parts[1];
int id = 0;
int action = 0;
try{
id = Integer.parseInt(parts[2]);// id
action = Integer.parseInt(parts[3]);// command
}
catch(Exception e){System.out.println(e + "\n cannot convert string part to int.");}
if(cmd.equals("tc")) // TruckCrane
{
try{
// System.out.println(truckCraneList.get(id));
truckCraneList.get(id).setMotion(action);
truckCraneList.get(id).playMotion();
}
catch(Exception e){System.out.println(e);}
}
else if(cmd.equals("sc")) // ShipCrane
{
try{
// System.out.println(shipCraneList.get(id));
shipCraneList.get(id).setMotion(action);
shipCraneList.get(id).playMotion();
}
catch(Exception e){System.out.println(e);}
}
else if(cmd.equals("storage")) // ShipCrane
{ // id = welke kraan, action = welke rij.
try{
int deep = Integer.parseInt(parts[3]);
int height = Integer.parseInt(parts[4]);
}catch(Exception e){System.out.println(e);}
try{
// System.out.println(shipCraneList.get(id));
storageCraneList.get(id).moveLeftRight(action);
storageCraneList.get(id).playMotion();
}
catch(Exception e){System.out.println(e);}
}
else if(cmd.equals("storage2")) // ShipCrane
{ // id = welke kraan, action = welke rij.
try{
// System.out.println(shipCraneList.get(id));
storageCraneList.get(id).setMotion(action, 1);
storageCraneList.get(id).playMotion();
}
catch(Exception e){System.out.println(e);}
}
else if(cmd.equals("ssc")) // SeaShipCrane
{
try{
//System.out.println(seaShipCraneList.get(id));
seaShipCraneList.get(id).setMotion(action);
seaShipCraneList.get(id).playMotion();
}
catch(Exception e){System.out.println(e);}
}
else if(cmd.equals("tcAddTruck")){
try{
// System.out.println(truckList.get(action));
truckCraneList.get(id).setTruck(truckList.get(action));
}
catch(Exception e){System.out.println(e);}
}
else if(cmd.equals("tcAddAGV")){
try{
// System.out.println(AGVList.get(action));
truckCraneList.get(id).setAGV(AGVList.get(action));
}
catch(Exception e){System.out.println(e);}
}
//}
//else
// System.out.println("Invalid String : size = " + parts.length + ", must be 3");
}
private ActionListener actionListener = new ActionListener() {
public void onAction(String name, boolean keyPressed, float tpf) {
if (name.equals("play") && !keyPressed) {
for(int i = 0; i < truckList.size(); i++)
{
if(truckList.get(i).isArrived == true && AGVList.get(i).isArrived == true)
{
innerloop: for(int j = 0; j < truckCraneList.size(); j ++)
{
// if(truckCraneList.get(j).truck == null && truckCraneList.get(j).agv == null)
// {
truckCraneList.get(i).setTruck(truckList.get(i));
truckCraneList.get(i).setAGV(AGVList.get(i));
if(truckList.get(i).container != null && AGVList.get(i).container == null)
{
truckCraneList.get(i).setMotion(1);
truckCraneList.get(i).playMotion();
}
if(truckList.get(i).container == null && AGVList.get(i).container != null)
{
truckCraneList.get(i).setMotion(2);
truckCraneList.get(i).playMotion();
}
break innerloop;
// }
}
}
}
// truckList.get(0).setMotionTerug();
// truckList.get(0).playMotion();
//System.out.println("START Truck AGV");
// for(TruckCrane truckC : truckCraneList)
// {
// System.out.println("\n" +truckC.truckCraneNode.getLocalTranslation());
// truckC.setMotion(1);
// truckC.playMotion();
// }
}
if (name.equals("shoot") && !keyPressed) { // commented out size because there are more trucks than cranes.
for(int i = 0; i < 20; i++)//truckList.size(); i++)
{
if(truckList.get(i).isLeaving == true)
{
truckList.get(i).setMotionTerug();
}
if(truckList.get(i).isLeaving == false)
{
innerloop: for(int j = 0; j < 20; j++)//truckCraneList.size(); j++)
{
if(truckCraneList.get(j).truck == null)
{
truckList.get(i).destination = new Vector3f(truckCraneList.get(j).spawnLoc.x ,
truckCraneList.get(j).truckCraneNode.getLocalTranslation().y - 11.45f, truckCraneList.get(j).spawnLoc.z + 45);
truckList.get(i).setMotionHeen();
truckCraneList.get(j).truck = truckList.get(i);
break innerloop;
}
}
}
truckList.get(i).playMotion();
if(AGVList.get(i).idle == true && AGVList.get(i).isLeaving == false)
{
innerloop: for(int j = 0; j < 20; j++)//truckCraneList.size(); j++)
{
if(truckCraneList.get(j).agv == null)
{
AGVList.get(i).destination = new Vector3f(truckCraneList.get(j).spawnLoc.x ,
truckCraneList.get(j).truckCraneNode.getLocalTranslation().y - 11.45f, truckCraneList.get(j).spawnLoc.z + 70);
AGVList.get(i).setMotionTC();
truckCraneList.get(j).agv = AGVList.get(i);
AGVList.get(i).idle = false;
break innerloop;
}
}
}
if(AGVList.get(i).isLeaving == true)
{
AGVList.get(i).setIdle();
AGVList.get(i).isLeaving = false;
}
AGVList.get(i).playMotion();
}
//System.out.println("START AGV Truck");
// for(TruckCrane truckC : truckCraneList)
// {
// System.out.println("\n" +truckC.truckCraneNode.getLocalTranslation());
// truckC.setMotion(1);
// truckC.playMotion();
// }
// for(TruckCrane truckC : truckCraneList)
// {
// truckC.setMotion(2);
// truckC.playMotion();
// }
/*System.out.println(inputBuffer.size());
for(String line: inputBuffer)
{
System.out.println("comand : " + line);
}*/
}
}
};
@Override
public void simpleRender(RenderManager rm) {
//TODO: add render code
}
}