Advertisement
SKYIINET

BaseEntityLogicA

Oct 31st, 2014
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.77 KB | None | 0 0
  1. package Game.Pworld.Pmapping;
  2.  
  3. import java.awt.Point;
  4. import java.awt.geom.Point2D;
  5. import java.util.HashMap;
  6. import java.util.HashSet;
  7. import java.util.Map;
  8. import java.util.Set;
  9.  
  10. import Base.Indexer;
  11. import Base.MapValueSet;
  12. import Game.Pworld.Pentities.EntityData;
  13. import Game.Pworld.Pentitydefinitions.EntityAttribute;
  14. import Game.Pworld.Pentitydefinitions.GameObjects;
  15.  
  16. public class BaseEntityLogicA {
  17.    
  18.     class Point1{
  19.        
  20.         Point point;
  21.         final int n1;
  22.         public Point1(int x, int y, int n1){
  23.             point = new Point(x,y);
  24.             this.n1 = n1;
  25.         }
  26.         public Point1(Point p, int n1){
  27.             point = new Point(p);
  28.             this.n1 = n1;
  29.         }
  30.        
  31.         @Override
  32.         public String toString(){
  33.             return getPosInfo(point,n1);
  34.         }
  35.        
  36.         public String getPosInfo(Point p, int h){
  37.             return ("[x: "+ p.x + ", y: "+ p.y + ", Num 1: "+ n1+"]");
  38.         }
  39.        
  40.     }
  41.    
  42.     class SectionH{
  43.         private Indexer indxSec = new Indexer();
  44.         /**@param Integer used with unique SectionTag
  45.          * @param SectionInfo */
  46.         private Map<Integer,SectionInfo> SectionMap = new HashMap<Integer, SectionInfo>();
  47.        
  48.         /**@param Integer used with unique SectionTag
  49.          * @param Integer used with unique EntityTag */
  50.         private MapValueSet<Integer,Integer> SectionEntitySet = new MapValueSet<Integer,Integer>();
  51.        
  52.         public int addEmptySection(SectionInfo si){
  53.             int tag = indxSec.getNextTag();
  54.             SectionMap.put(tag, si);
  55.             return tag;
  56.         }
  57.        
  58.         public void addEntity(int sTag, int eTag){
  59.             if(SectionEntitySet.mapContains(eTag)){
  60.                 SectionEntitySet.removeAtValue(eTag);
  61.             }
  62.                 SectionEntitySet.put(sTag, eTag);
  63.         }
  64.  
  65.         public int getHeight(int tag) {
  66.             return SectionMap.get(tag).getHeight();
  67.         }
  68.        
  69.         public Set<Integer> getSections(){
  70.             return SectionMap.keySet();
  71.         }
  72.        
  73.         public Set<Integer> getSectionEntities(int SectionTag){
  74.             return SectionEntitySet.getSet(SectionTag);
  75.         }
  76.     }
  77.    
  78.     class GridH{
  79.        
  80.         public final int GRID_SIZE = 192;
  81.         /**@param Point used as Grid Index
  82.          * @param Integer used with unique EntityTag */
  83.         private MapValueSet<String,Integer> GridMap = new MapValueSet<String,Integer>();
  84.        
  85.         public Point placeEntityIntoGrid(Point2D pos, int height, int entTag){
  86.             Point p = new Point((int) (pos.getX()/GRID_SIZE),(int) (pos.getY()/GRID_SIZE));
  87.                 if(GridMap.mapContains(entTag)){
  88.                     GridMap.removeAtValue(entTag);
  89.                 }
  90.             GridMap.put(new Point1(p,height).toString(), entTag);  
  91.             return p;
  92.         }
  93.        
  94.     }
  95.    
  96.     class EntityH{
  97.        
  98.         GameObjects gObjs = new GameObjects();
  99.        
  100.         private Indexer indxEnt = new Indexer();
  101.         /**@param Integer used with unique EntityTag
  102.          * @param EntityData */
  103.         private Map<Integer,EntityData> EntityMap = new HashMap<Integer,EntityData>();
  104.        
  105.         /**@param EntityAttribute
  106.          * @param Integer used with unique EntityTag*/
  107.         private MapValueSet<EntityAttribute,Integer> EntityAttributeValues = new MapValueSet<EntityAttribute,Integer>();
  108.        
  109.         public int setEntity(EntityData ED){
  110.             int entTag = indxEnt.getNextTag();
  111.             ED.setTag(entTag);
  112.             EntityMap.put(entTag, ED);
  113.            
  114.             for(int i = 0; i < EntityAttribute.values().length; i++){
  115.                 if(gObjs.getGameObject(ED.getName()).getAttributes().containsKey(EntityAttribute.values()[i])){
  116.                     EntityAttributeValues.put(EntityAttribute.values()[i],entTag);
  117.                 }          
  118.             }
  119.             return entTag;
  120.         }
  121.  
  122.         public void SetPosition(Point2D pos, int eTag) {
  123.             EntityMap.get(eTag).setPosition(pos);          
  124.         }
  125.  
  126.         public Point2D getPosition(int eTag) {
  127.             return EntityMap.get(eTag).getPosition();
  128.         }
  129.  
  130.         public EntityData getEntityData(int eTag) {
  131.            
  132.             return EntityMap.get(eTag);
  133.         }
  134.        
  135.     }  
  136.  
  137.     private Point1 pointField = new Point1(new Point(),0);
  138.    
  139.     SectionH    section = new SectionH();
  140.     EntityH     entity = new EntityH();
  141.     GridH       grid = new GridH();
  142.    
  143.     public int addEntity(EntityData ED){
  144.         int tag = -1;
  145.         section.addEntity(ED.getSection(), tag =  entity.setEntity(ED));
  146.         grid.placeEntityIntoGrid(ED.getPosition(), section.getHeight(ED.getTag()), ED.getTag());
  147.         return tag;
  148.     }
  149.    
  150.     public void addEmptySection(SectionInfo si){
  151.         section.addEmptySection(si);
  152.     }
  153.    
  154.     public void moveEntity(Point2D pos, int eTag, int sTag){
  155.         EntityData hold = entity.getEntityData(eTag);
  156.             hold.setPosition(pos);
  157.             hold.setSection(sTag);     
  158.         grid.placeEntityIntoGrid(pos,section.getHeight(sTag),sTag);
  159.     }
  160.    
  161.     public String getEntityPosition(int eTag){
  162.         EntityData ED = entity.getEntityData(eTag);
  163.         Point2D ePos = ED.getPosition();
  164.        
  165.         Point p = new Point((int) (ePos.getX()/grid.GRID_SIZE),(int) (ePos.getY()/grid.GRID_SIZE));
  166.         return pointField.getPosInfo(p, section.getHeight(ED.getSection()));
  167.     }
  168.    
  169.     public Set<Integer> getSections(){
  170.         return section.getSections();
  171.     }
  172.    
  173.     public Set<Integer> getSectionEntities(int SectionTag){
  174.         return section.getSectionEntities(SectionTag);
  175.     }
  176.    
  177.  
  178. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement