package com.deftwun.zombiecopter.systems;

import com.badlogic.ashley.core.Engine;
import com.badlogic.ashley.core.Entity;
import com.badlogic.ashley.core.EntitySystem;
import com.badlogic.ashley.core.Family;
import com.badlogic.gdx.utils.Array;
import com.deftwun.zombiecopter.ComponentMappers;
import com.deftwun.zombiecopter.DropOffPoint;
import com.deftwun.zombiecopter.App;
import com.deftwun.zombiecopter.GameEngine;
import com.deftwun.zombiecopter.components.Collector;
import com.deftwun.zombiecopter.components.PhysicsComponent;


//Drop off points are areas that an entity with a 'collector' component can drop off civilians when within range. 
//TODO: Could be made to include different types of collectables ..
public class CivilianDropOffSystem extends EntitySystem {
	private Array<DropOffPoint> points = new Array<DropOffPoint>();
	private int totalCivsReturned = 0;
	
	public int getTotalCiviliansDroppedOff(){
		return totalCivsReturned;
	}
	
	public void add(DropOffPoint point){
		points.add(point);
	}
	
	@Override
	public void removedFromEngine(Engine engine) {
		points.clear();
	}

	@SuppressWarnings("unchecked")
	@Override
	public void update(float deltaTime) {
		GameEngine engine = App.engine;
		ComponentMappers maps = engine.mappers;
		
		for (DropOffPoint point : points){
			for (Entity e : engine.getEntitiesFor(Family.all(Collector.class).get())){
				Collector c = maps.collector.get(e);
				PhysicsComponent phys = maps.physics.get(e);
				
				if (phys.getPosition().dst(point.position) < point.range){
					totalCivsReturned += c.civilians;
					c.civilians = 0;
				}
				
			}
		}

	}
	
}

@@ -53,202 +53,178 @@
 com.
-badlogic.ashley.core.Engine;%0D%0Aimport com.badlogic.ashley.core.Entity;%0D%0Aimport com.badlogic.ashley.core.EntitySystem;%0D%0Aimport com.badlogic.ashley.core.Family;%0D%0Aimport com.badlogic.gdx.utils.Array
+artemis.Aspect;%0D%0Aimport com.artemis.Entity;%0D%0Aimport com.artemis.systems.EntityProcessingSystem;%0D%0Aimport com.badlogic.gdx.utils.Array;%0D%0Aimport com.deftwun.zombiecopter.App
 ;%0D%0Ai
@@ -324,91 +324,8 @@
 t;%0D%0A
-import com.deftwun.zombiecopter.App;%0D%0Aimport com.deftwun.zombiecopter.GameEngine;%0D%0A
 impo
@@ -675,16 +675,26 @@
 s Entity
+Processing
 System %7B
@@ -950,219 +950,147 @@
 %09%7D%0D%0A
-%09%0D%0A%09@Override%0D%0A%09public void removedFromEngine(Engine engine) %7B%0D%0A%09%09points.clear();%0D%0A%09%7D%0D%0A%0D%0A%09@SuppressWarnings(%22unchecked%22)%0D%0A%09@Override%0D%0A%09public void update(float deltaTime) %7B%0D%0A%09%09GameEngine engine = App.engine;%0D%0A%09%09
+%0D%0A%09public CivilianDropOffSystem() %7B%0D%0A%09%09super(Aspect.all(Collector.class));%0D%0A%09%7D%0D%0A%0D%0A%09@Override%0D%0A%09protected void process(Entity e) %7B%0D%0A%09%09final 
 Comp
@@ -1109,16 +1109,20 @@
  maps = 
+App.
 engine.m
@@ -1130,20 +1130,16 @@
 ppers;%0D%0A
-%09%09%0D%0A
 %09%09for (D
@@ -1172,88 +1172,8 @@
 )%7B%0D%0A
-%09%09%09for (Entity e : engine.getEntitiesFor(Family.all(Collector.class).get()))%7B%0D%0A%09
 %09%09%09C
@@ -1209,17 +1209,16 @@
 et(e);%0D%0A
-%09
 %09%09%09Physi
@@ -1258,23 +1258,16 @@
 et(e);%0D%0A
-%09%09%09%09%0D%0A%09
 %09%09%09if (p
@@ -1321,17 +1321,16 @@
 ange)%7B%0D%0A
-%09
 %09%09%09%09tota
@@ -1364,17 +1364,16 @@
 s;%0D%0A%09%09%09%09
-%09
 c.civili
@@ -1386,39 +1386,23 @@
 0;%0D%0A
-%09%09%09%09%7D%0D%0A%09%09%09%09%0D%0A
 %09%09%09%7D%0D%0A
+%0D%0A
 %09%09%7D%0D%0A
-%0D%0A%09%7D%0D%0A
 %09
+%7D
 %0D%0A%7D%0D

Migrate CivilianDropOffSystem.java