10 Commits
Author SHA1 Message Date
Yorick 5d0ae9ca98 final commit 2015-04-09 09:29:13 +02:00
Yorick 719d58aae9 done 2015-04-09 01:55:12 +02:00
Yorick 4897a9440b ohgodwhy 2015-04-09 01:30:38 +02:00
Yorick 2e947589be merge 2015-04-09 00:56:42 +02:00
Remco a6f32b5739 Editing disabled while running simulator 2015-04-09 00:51:18 +02:00
Yorick 6178311c4b Merge remote-tracking branch 'origin/kenneth' into develop 2015-04-09 00:35:30 +02:00
Yorick 920fd8117e KUT 2015-04-09 00:33:18 +02:00
guusvdongen 911714f9b5 Update Visitor.java 2015-04-08 21:15:45 +02:00
unknown 254167ba15 print out line op 2015-04-08 17:40:22 +02:00
unknown b8a7d9c02d change 2015-04-08 17:24:29 +02:00
4 changed files with 71 additions and 26 deletions
+2
View File
@@ -52,6 +52,7 @@ public class ControlPanel extends JPanel
public void actionPerformed(ActionEvent e) public void actionPerformed(ActionEvent e)
{ {
p.getT().start(); p.getT().start();
p.setPlay(true);
runningLabel.setText("Simulation Started"); runningLabel.setText("Simulation Started");
} }
}); });
@@ -64,6 +65,7 @@ public class ControlPanel extends JPanel
public void actionPerformed(ActionEvent e) public void actionPerformed(ActionEvent e)
{ {
p.getT().stop(); p.getT().stop();
p.setPlay(false);
runningLabel.setText("Simulation Stopped"); runningLabel.setText("Simulation Stopped");
} }
}); });
+12 -1
View File
@@ -63,6 +63,7 @@ public class Panel extends JPanel implements ActionListener
private Path currentPath; private Path currentPath;
private static int width = 1920; private static int width = 1920;
private static int height = 1080; private static int height = 1080;
private boolean play = false;
Point2D cameraPoint = new Point2D.Double(getWidth() / 2, getHeight() / 2); Point2D cameraPoint = new Point2D.Double(getWidth() / 2, getHeight() / 2);
float cameraScale = 1; float cameraScale = 1;
@@ -148,7 +149,7 @@ public class Panel extends JPanel implements ActionListener
addMouseWheelListener(new MouseWheel(this)); addMouseWheelListener(new MouseWheel(this));
addFocusListener(new WindowFocusListener(this)); addFocusListener(new WindowFocusListener(this));
t = new Timer(1000 / 50, this); t = new Timer(1000/60, this);
} }
public int getPanelInfoLength() public int getPanelInfoLength()
@@ -666,6 +667,16 @@ public class Panel extends JPanel implements ActionListener
{ {
this.t = t; this.t = t;
} }
public void setPlay(boolean play)
{
this.play = play;
}
public boolean getPlay()
{
return play;
}
public void newWorld(int width, int height, int terrainIndex) public void newWorld(int width, int height, int terrainIndex)
{ {
+53 -24
View File
@@ -11,6 +11,7 @@ import java.util.ArrayList;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Random;
import Agenda.Agenda; import Agenda.Agenda;
import Agenda.Event; import Agenda.Event;
@@ -86,11 +87,13 @@ public class Visitor
public void update(ArrayList<DrawObject> objects, int currentTime, ArrayList<Visitor> visitors, ArrayList<Path> paths, Panel panel) public void update(ArrayList<DrawObject> objects, int currentTime, ArrayList<Visitor> visitors, ArrayList<Path> paths, Panel panel)
{ {
DrawObject target = getEntrance(); DrawObject target = getEntrance();
for (Action a : actions) for (Action a : actions)
{ {
if (currentTime >= a.getStartTime() && currentTime < a.getStoptime()) if (currentTime >= a.getStartTime() && currentTime < a.getStoptime())
{ {
this.finalTarget = a.getWaypoint().getSelf(); this.finalTarget = a.getWaypoint().getSelf();
} }
} }
@@ -100,9 +103,7 @@ public class Visitor
public void move(DrawObject tar, Panel panel) public void move(DrawObject tar, Panel panel)
{ {
System.out.println("CurrentTarget: " + target); Point2D targetPoint = panel.getWaypoint(target).getPosition();
System.out.println("FinalTarget: " + finalTarget);
Point2D targetPoint = panel.getWaypoint(target).getAccuratePoint();
double newRot = Math.atan2(targetPoint.getY() - position.getY(), targetPoint.getX() - position.getX()); double newRot = Math.atan2(targetPoint.getY() - position.getY(), targetPoint.getX() - position.getX());
@@ -139,6 +140,7 @@ public class Visitor
if (hasCollisionDO(object)) if (hasCollisionDO(object))
{ {
possible = false; possible = false;
} }
} }
@@ -147,20 +149,25 @@ public class Visitor
position = oldPosition; position = oldPosition;
rotation += 0.2; rotation += 0.2;
} }
if (checkIfOnWaypoint(panel)) if (checkIfOnWaypoint(panel))
{ {
HashMap<Integer, int[]> options = new HashMap<Integer, int[]>(); HashMap<Integer, int[]> options = new HashMap<Integer, int[]>();
for (Waypoint w : panel.getWaypoints()) for (Waypoint w : panel.getWaypoints())
{ {
options.put(w.getSelf(), w.getOptions()); options.put(w.getSelf(), w.getOptions());
} }
for (Map.Entry<Integer, int[]> e : options.entrySet()) if (finalTarget != target)
{ {
for (int i : e.getValue()) for (Map.Entry<Integer, int[]> e : options.entrySet())
{ {
if (finalTarget != target) // System.out.println("KEY: " + e.getKey());
for (int i : e.getValue())
{ {
// System.out.println("VAL: " + i);
if (finalTarget == i && e.getKey() == target) if (finalTarget == i && e.getKey() == target)
{ {
target = finalTarget; target = finalTarget;
@@ -172,6 +179,7 @@ public class Visitor
break; break;
} }
} }
} }
} }
} }
@@ -245,6 +253,7 @@ public class Visitor
if (hasCollision(object) && object != this) if (hasCollision(object) && object != this)
{ {
possible = false; possible = false;
} }
} }
@@ -368,7 +377,7 @@ public class Visitor
while (startTime < stopTime) while (startTime < stopTime)
{ {
int random = (int) Math.floor(Math.random() * 51); int random = (int) Math.floor(Math.random() * 51);
if (random < 40) if (random < 30)
{ {
Point2D position = null; Point2D position = null;
DrawObject targetStage = null; DrawObject targetStage = null;
@@ -380,20 +389,35 @@ public class Visitor
posEvents.add(e); posEvents.add(e);
} }
} }
int totalPopularity = 0;
if (posEvents.size() != 0) for (Event ev : posEvents)
{ {
int r = (int) Math.floor(Math.random() * posEvents.size()); totalPopularity += ev.getExpectedPopularity();
Event evs = posEvents.get(r); }
for (DrawObject d : objects)
Random rand = new Random();
int n = rand.nextInt(totalPopularity + 1);
int currentPop = 0;
if (posEvents != null)
{
for (Event evs : posEvents)
{ {
if (d.getFileName().equals("stage")) int before = currentPop;
currentPop = currentPop + evs.getExpectedPopularity();
if (before < n && currentPop >= n)
{ {
Stage s = (Stage) d; for (DrawObject d : objects)
if (s.getStage().getName().equals(evs.getStage().getName()))
{ {
position = s.getPosition(); if (d.getFileName().equals("stage"))
targetStage = d; {
Stage s = (Stage) d;
if (s.getStage().getName().equals(evs.getStage().getName()))
{
position = s.getPosition();
targetStage = d;
}
}
} }
} }
} }
@@ -402,13 +426,13 @@ public class Visitor
int randomtime = (int) (40 + (Math.random() * (60 - 40))); int randomtime = (int) (40 + (Math.random() * (60 - 40)));
if (position != null) if (position != null)
{ {
Waypoint w = getClosestWaypoint(position); Waypoint w = getClosedWaypoint(position);
actions.add(new Action(position, startTime, randomtime, targetStage, w)); actions.add(new Action(position, startTime, randomtime, targetStage, w));
} }
startTime = startTime + randomtime; startTime = startTime + randomtime;
} }
else if (random >= 40 && random < 45) else if (random >= 30 && random < 40)
{ {
Point2D position = null; Point2D position = null;
DrawObject targetStage = null; DrawObject targetStage = null;
@@ -426,15 +450,16 @@ public class Visitor
int r = (int) Math.floor(Math.random() * foodPlaces.size()); int r = (int) Math.floor(Math.random() * foodPlaces.size());
position = foodPlaces.get(r).getPosition(); position = foodPlaces.get(r).getPosition();
targetStage = foodPlaces.get(r); targetStage = foodPlaces.get(r);
Waypoint w = getClosestWaypoint(position); Waypoint w = getClosedWaypoint(position);
actions.add(new Action(position, startTime, 35, targetStage, w)); actions.add(new Action(position, startTime, 35, targetStage, w));
startTime = startTime + 20; startTime = startTime + 20;
} }
startTime = startTime + 35; startTime = startTime + 35;
} }
else if (random > 45) else if (random >= 40)
{ {
Point2D position = null; Point2D position = null;
DrawObject targetStage = null; DrawObject targetStage = null;
ArrayList<DrawObject> toilets = new ArrayList<DrawObject>(); ArrayList<DrawObject> toilets = new ArrayList<DrawObject>();
@@ -445,13 +470,15 @@ public class Visitor
toilets.add(d); toilets.add(d);
} }
} }
if (toilets.size() != 0) if (toilets.size() != 0)
{ {
int r = (int) Math.floor(Math.random() * toilets.size()); int r = (int) Math.floor(Math.random() * toilets.size());
position = toilets.get(r).getPosition(); position = toilets.get(r).getPosition();
targetStage = toilets.get(r); targetStage = toilets.get(r);
Waypoint w = getClosestWaypoint(position); Waypoint w = getClosedWaypoint(position);
actions.add(new Action(position, startTime, 35, targetStage, w)); actions.add(new Action(position, startTime, 35, targetStage, w));
startTime = startTime + 20; startTime = startTime + 20;
} }
startTime = startTime + 35; startTime = startTime + 35;
@@ -460,7 +487,7 @@ public class Visitor
} }
} }
public Waypoint getClosestWaypoint(Point2D point) public Waypoint getClosedWaypoint(Point2D point)
{ {
Waypoint waypoint = null; Waypoint waypoint = null;
int distance = 10000; int distance = 10000;
@@ -468,6 +495,7 @@ public class Visitor
{ {
if (w.getPosition().distance(point) < distance) if (w.getPosition().distance(point) < distance)
{ {
waypoint = w; waypoint = w;
distance = (int) w.getPosition().distance(point); distance = (int) w.getPosition().distance(point);
} }
@@ -477,6 +505,7 @@ public class Visitor
public boolean hasCollisionDO(DrawObject object) public boolean hasCollisionDO(DrawObject object)
{ {
Image image = Images.getImage(filename); Image image = Images.getImage(filename);
Image image2 = Images.getImage(object.getFileName()); Image image2 = Images.getImage(object.getFileName());
Rectangle recta = new Rectangle((int) position.getX(), (int) position.getY(), image.getWidth(null), image.getHeight(null)); Rectangle recta = new Rectangle((int) position.getX(), (int) position.getY(), image.getWidth(null), image.getHeight(null));
@@ -525,4 +554,4 @@ public class Visitor
} }
return false; return false;
} }
} }
+4 -1
View File
@@ -34,6 +34,8 @@ public class Mouse extends MouseAdapter
panel.setLastClickPosition(clickPoint); panel.setLastClickPosition(clickPoint);
panel.setLastMousePosition(e.getPoint()); panel.setLastMousePosition(e.getPoint());
if(!panel.getPlay())
{
if (!panel.getClickedOption().equals("Path")) if (!panel.getClickedOption().equals("Path"))
{ {
if (e.getY() < 150) if (e.getY() < 150)
@@ -150,13 +152,14 @@ public class Mouse extends MouseAdapter
panel.getCurrentPath().addPoint(new Point2D.Double(clickPoint.getX(), clickPoint.getY())); panel.getCurrentPath().addPoint(new Point2D.Double(clickPoint.getX(), clickPoint.getY()));
}
} }
panel.repaint(); panel.repaint();
} }
public void mouseReleased(MouseEvent e) public void mouseReleased(MouseEvent e)
{ {
if (panel.getDragObject() != null) if (panel.getDragObject() != null && !panel.getPlay())
{ {
if (panel.getDragObject().getRectangleColor() != Color.RED) if (panel.getDragObject().getRectangleColor() != Color.RED)
{ {