Advertisement
Jnk1296

AI Engine

Jul 18th, 2013
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.30 KB | None | 0 0
  1. package net.risenphoenix.jnk.StarField.AI;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. import net.risenphoenix.jnk.StarField.Engine;
  6. import net.risenphoenix.jnk.StarField.Entity.Entity;
  7. import net.risenphoenix.jnk.StarField.Entity.EntityType;
  8.  
  9. public class AIEngine {
  10.  
  11.     private ArrayList<SFAIAction> events = new ArrayList<SFAIAction>();
  12.     private ArrayList<SFAIAction> purge = new ArrayList<SFAIAction>();
  13.    
  14.     private int ticks;
  15.     private final int limit = 100;
  16.    
  17.     public void tickEngine() {
  18.         ticks++;
  19.        
  20.         tickActions();
  21.         checkStatus();
  22.         purge();
  23.        
  24.         if (ticks >= limit) {
  25.             assignActions();
  26.             ticks = 0;
  27.         }
  28.        
  29.     }
  30.    
  31.     private void tickActions() {
  32.         for (SFAIAction action:events) {
  33.             action.tickAction();
  34.         }
  35.     }
  36.    
  37.     private void checkStatus() {
  38.         for (SFAIAction action:events) {
  39.             if (action.isComplete()) {
  40.                 purge.add(action);
  41.             } else if (action.getTicks() >= limit) {
  42.                 purge.add(action);
  43.             }
  44.         }
  45.     }
  46.    
  47.     private void purge() {
  48.         for (SFAIAction action:purge) {
  49.             events.remove(action);
  50.         }
  51.        
  52.         purge.clear();
  53.     }
  54.    
  55.     private void assignActions() {
  56.         ArrayList<Entity> entities = Engine.game.getEntityEngine().getEntities();
  57.        
  58.         for (Entity e:entities) {
  59.             // Main AI Assignment Logic
  60.             if (e.getEntityType().equals(EntityType.ASTEROID)) {
  61.                
  62.             }
  63.         }
  64.     }
  65.    
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement