/*
* File name: Phys3Master.java (package eas.simulation.users.lukas.lukesPhysics3)
* Author(s): Lukas König
* Java version: 6.0
* Generation date: 28.01.2011 (19:51:12)
*
* (c) This file and the EAS (Easy Agent Simulation) framework containing it
* is protected by Creative Commons by-nc-sa license. Any altered or
* further developed versions of this file have to meet the agreements
* stated by the license conditions.
*
* In a nutshell
* -------------
* You are free:
* - to Share -- to copy, distribute and transmit the work
* - to Remix -- to adapt the work
*
* Under the following conditions:
* - Attribution -- You must attribute the work in the manner specified by the
* author or licensor (but not in any way that suggests that they endorse
* you or your use of the work).
* - Noncommercial -- You may not use this work for commercial purposes.
* - Share Alike -- If you alter, transform, or build upon this work, you may
* distribute the resulting work only under the same or a similar license to
* this one.
*
* + Detailed license conditions (Germany):
* http://creativecommons.org/licenses/by-nc-sa/3.0/de/
* + Detailed license conditions (unported):
* http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en
*
* This header must be placed in the beginning of any version of this file.
*/
package eas.users.demos.rocketMan;
import eas.math.geometry.Vector2D;
import eas.plugins.masterScheduler.AbstractDefaultKeyEventMaster;
import eas.plugins.standard.visualization.chartPlugin.ChartEvent;
import eas.simulation.ConstantsSimulation;
import eas.simulation.Wink;
import eas.simulation.event.EASEvent;
import eas.simulation.spatial.sim2D.physicalSimulation.physicsEngine.DistanceJoint;
import eas.simulation.spatial.sim2D.physicalSimulation.physicsEngine.Joint;
import eas.simulation.spatial.sim2D.physicalSimulation.physicsEngine.net.phys2d.math.Vector2f;
import eas.startSetup.ParCollection;
/**
* @author Lukas König
*/
public class Phys3MasterA extends AbstractDefaultKeyEventMaster<Phys3Env> {
/**
*
*/
private static final long serialVersionUID = -3873683207305362953L;
private Joint j1, j2;
@Override
public Phys3Env[] generateRunnables(ParCollection params) {
Phys3Env[] envs = new Phys3Env[1];
final Phys3Env env = new Phys3Env(0, params, new Vector2f(0, 5), 100);
envs[0] = env;
env.addAgent(new Phys3Agent(0, env, "Agent0", 10, params), new Vector2D(0, -10), 180);
env.addAgent(new Phys3JetAgent(1, env, "Agent1", 10, params), new Vector2D(-3, 0), 180);
env.addAgent(new Phys3JetAgent(2, env, "Agent2", 10, params), new Vector2D(3, 0), 180);
j1 = new DistanceJoint(
env.getAgent(0),
env.getAgent(1),
new Vector2f(4, -5),
new Vector2f(0, 0.9f),
0);
j2 = new DistanceJoint(
env.getAgent(0),
env.getAgent(2),
new Vector2f(-4, -5),
new Vector2f(0, 0.9f),
0);
env.add(j1);
env.add(j2);
env.addAgent(new StaticObstacleLong(100, env, params), new Vector2D(0, 1), 0);
env.addAgent(new StaticObstacleShort(101, env, params), new Vector2D(-50, -30), 0);
env.setPerfectFit(true);
return envs;
}
@Override
public synchronized void handleEvent(EASEvent e, Phys3Env env, Wink lastTick,
ParCollection params) {
super.handleEvent(e, env, lastTick, params);
if (e.getEventDescription().equals(ConstantsSimulation.KEY_EVENT_IDENTIFIER + "r") && !((StaticObstacleShort) env.getAgent(101)).gesperrt) {
env.remove(j1);
env.remove(j2);
env.removeAgent(0);
env.removeAgent(1);
env.removeAgent(2);
env.removeAgent(100);
env.removeAgent(101);
env.addAgent(new Phys3Agent(0, env, "Agent0", 10, params), new Vector2D(0, -10), 180);
env.addAgent(new Phys3JetAgent(1, env, "Agent1", 10, params), new Vector2D(-3, 0), 180);
env.addAgent(new Phys3JetAgent(2, env, "Agent2", 10, params), new Vector2D(3, 0), 180);
j1 = new DistanceJoint(
env.getAgent(0),
env.getAgent(1),
new Vector2f(4, -5),
new Vector2f(0, 0.9f),
0);
j2 = new DistanceJoint(
env.getAgent(0),
env.getAgent(2),
new Vector2f(-4, -5),
new Vector2f(0, 0.9f),
0);
env.add(j1);
env.add(j2);
env.addAgent(new StaticObstacleLong(100, env, params), new Vector2D(0, 1), 0);
env.addAgent(new StaticObstacleShort(101, env, params), new Vector2D(-50, -30), 0);
env.setPerfectFit(true);
}
}
@Override
public String id() {
return ConstantsSimulation.DEFAULT_MASTER_SCHEDULER_ID + "-rocketA";
}
@Override
public void runDuringSimulation(Phys3Env umg, Wink simZyk, ParCollection params) {
super.runDuringSimulation(umg, simZyk, params);
umg.getSimTime().broadcastEvent(new ChartEvent("Rocket chart", "Fuel wasted", umg.allFuel()));
}
}