package edu.agh.tunev.model.kkm;

import java.util.Vector;

import edu.agh.tunev.model.AbstractModel;
import edu.agh.tunev.model.PersonProfile;
import edu.agh.tunev.model.PersonState;
import edu.agh.tunev.statistics.LifeStatistics;
import edu.agh.tunev.statistics.Statistics.AddCallback;
import edu.agh.tunev.world.World;
import edu.agh.tunev.world.World.ProgressCallback;

public final class Model extends AbstractModel {

	public final static String MODEL_NAME = "Autorski (\u00a9 2012 Jakub Rakoczy)";

	public Model(World world) {
		super(world);
	}

	private static final double DT = 0.05;

	@Override
	public void simulate(double duration, Vector<PersonProfile> profiles,
			ProgressCallback progressCallback, AddCallback addCallback) {
		// number of iterations
		int num = (int) Math.round(Math.ceil(world.getDuration() / DT));
		progressCallback.update(0, num, "Initializing...");

		// init charts
		LifeStatistics lifeStatistics = new LifeStatistics();
		addCallback.add(lifeStatistics);

		// init board
		Board board = new Board(world);

		// init people
		for (PersonProfile profile : profiles)
			board.addAgent(new Agent(board, profile));

		// simulate
		double t = 0;
		for (int iteration = 1; iteration <= num; iteration++) {
			// update
			t += DT;
			board.update(t, DT);

			// chart inputs
			int currentNumDead = 0;
			int currentNumAlive = 0;
			int currentNumRescued = 0;

			// save states
			for (Agent p : board.getAgents()) {
				interpolator.saveState(p.profile, t, new PersonState(
						p.position, p.phi, p.getStance()));
				if (p.isExited())
					currentNumRescued++;
				else if (!p.isAlive())
					currentNumDead++;
				else
					currentNumAlive++;
			}

			// update charts
			lifeStatistics.add(t, currentNumAlive, currentNumRescued,
					currentNumDead);

			// UI simulation progress bar
			progressCallback.update(iteration, num,
					(iteration < num ? "Simulating..." : "Done."));
		}
	}

}

@@ -1458,86 +1458,37 @@
 %09%09%09%09
-interpolator.saveState(p.profile, t, new PersonState(%0A%09%09%09%09%09%09p.position, p.phi,
+PersonState.Movement stance =
  p.g
@@ -1497,19 +1497,18 @@
 Stance()
-))
 ;
+ 
 %0A%09%09%09%09if 
@@ -1521,16 +1521,18 @@
 xited())
+ %7B
 %0A%09%09%09%09%09cu
@@ -1546,24 +1546,73 @@
 mRescued++;%0A
+%09%09%09%09%09stance = PersonState.Movement.HIDDEN;%0A%09%09%09%09%7D%0A
 %09%09%09%09else if 
@@ -1625,16 +1625,18 @@
 Alive())
+ %7B
 %0A%09%09%09%09%09cu
@@ -1659,35 +1659,175 @@
 %09%09%09%09
-else%0A%09%09%09%09%09currentNumAlive++
+%09stance = PersonState.Movement.DEAD;%0A%09%09%09%09%7D%0A%09%09%09%09else%0A%09%09%09%09%09currentNumAlive++;%0A%09%09%09%09interpolator.saveState(p.profile, t, new PersonState(%0A%09%09%09%09%09%09p.position, p.phi, stance))
 ;%0A%09%09

Fix marking of the corpses, disappearing of the survived