package de.nameless.gameEngine.gameObjects;
import java.util.Vector;
import de.nameless.graphicEngine.NEabstractGraphicObject;
import de.nameless.graphicEngine.animation.lib.NEMultiLable;
import de.nameless.graphicEngine.animation.lib.NEVisibleLable;
import de.nameless.graphicEngine.lib.NELandscapeGraphic;
import de.nameless.graphicEngine.lib.NELineQuad;
import de.nameless.graphicEngine.lib.NEQuad;
import de.nameless.graphicEngine.lib.NEWater;
import de.nameless.graphicEngine.lib.NEflowAnimation;
public class NEField extends NEGameObject {
/**
*
*/
private static final long serialVersionUID = 1L;
public int cordX;
public int cordY;
public int typ;
public static final int GRASS = 0;
public static final int FOREST = 1;
public static final int RIVE = 2;
public NEVisibleLable reachable;
public static NEMultiLable showGrid = new NEMultiLable();
private NEField North;
private NEField East;
private NEField South;
private NEField West;
private NELineQuad grid;
private NEQuad reachableMark;
public float restWay = 0;
public float restWayAttack = 0;
public Vector<NEField> BestWay;
public Vector<NEField> BestWayAttack;
private static boolean WaterAnimationStarted = false;
public NELandUnit containtLUnit;
public NEField(int typ) {
super();
BestWay = new Vector<NEField>();
BestWayAttack = new Vector<NEField>();
this.typ = typ;
}
@Override
public Vector<NEabstractGraphicObject> getOwnGfx() {
//gfx = new Vector<NEabstractGraphicObject>();
NELandscapeGraphic Q;
grid = new NELineQuad();
grid.x = this.x;
grid.y = this.y;
grid.layer = 10;
grid.setColor(1f, 1f, 0.5f, 0.1f);
this.showGrid.add(new NEVisibleLable(grid));
gfx.add(grid);
reachableMark = new NEQuad();
reachableMark.setTexture("Selection.tga");
reachableMark.layer = 2;
reachableMark.x = this.x;
reachableMark.y = this.y;
reachableMark.setColor(0.5f, 0.5f, 1, 0.5f);
reachable = new NEVisibleLable(reachableMark);
gfx.add(reachableMark);
switch (typ) {
case FOREST:
Q = new NELandscapeGraphic("Grass", 2,4);
Q.randomRotate90X();
Q.x = this.x;
Q.y = this.y;
Q.layer = 1;
gfx.add(Q);
Q = new NELandscapeGraphic("Forest", 2*1.3f, 2);
Q.x = this.x;
Q.y = this.y;
Q.layer = 3;
Q.xAngel = 90;
gfx.add(Q);
break;
case GRASS:
Q = new NELandscapeGraphic("Grass", 2,4);
Q.randomRotate90X();
Q.x = this.x;
Q.y = this.y;
Q.layer = 1;
gfx.add(Q);
break;
case RIVE:
Q = new NELandscapeGraphic("Grass", 2,4);
Q.randomRotate90X();
Q.x = this.x;
Q.y = this.y;
Q.layer = -10;
gfx.add(Q);
NEWater W = new NEWater();
W.x = this.x;
W.y = this.y;
W.layer = -9;
if(!WaterAnimationStarted){
W.addAnimation(new NEflowAnimation());
WaterAnimationStarted = true;
}
NEWater W1 = new NEWater();
W1.x = this.x;
W1.y = this.y;
W1.layer = -8;
W1.xAngel = 180;
NEWater W2 = new NEWater();
W2.x = this.x;
W2.y = this.y;
W2.layer = -7;
W2.xAngel = 90;
NEWater W3 = new NEWater();
W3.x = this.x;
W3.y = this.y;
W3.layer = -6;
W3.xAngel = 270;
Q = new NELandscapeGraphic("River", 2);
Q.x = this.x;
Q.y = this.y;
Q.layer = 1;
int n = 0;
if(this.North != null) {
if (this.North.typ == RIVE) n++;
} else {
n++;
}
if(this.East != null) {
if (this.East.typ == RIVE) n++;
} else {
n++;
}
if(this.South != null) {
if (this.South.typ == RIVE) n++;
} else {
n++;
}
if(this.West != null) {
if (this.West.typ == RIVE) n++;
} else {
n++;
}
Q.enableSprites(3, 3, 0, 0);
switch(n){
case 0:
Q.setSprite(2, 0);
break;
case 1:
if(openedTo(North, RIVE)){
Q.setSprite(2, 1);
Q.xAngel = 270;
} else if(openedTo(East, RIVE)){
Q.setSprite(2, 1);
Q.xAngel = 180;
}else if(openedTo(South, RIVE)){
Q.setSprite(2, 1);
Q.xAngel = 90;
}else if(openedTo(West, RIVE)){
Q.setSprite(2, 1);
Q.xAngel = 0;
}
break;
case 2:
if(openedTo(West, RIVE) && openedTo(East, RIVE)){
Q.setSprite(1, 1);
} else if(openedTo(North, RIVE) && openedTo(South, RIVE)){
Q.setSprite(1, 1);
Q.xAngel = 0;
}
if(openedTo(West, RIVE) && openedTo(North, RIVE)){
Q.setSprite(1, 0);
Q.xAngel = 0;
} else if(openedTo(North, RIVE) && openedTo(East, RIVE)){
Q.setSprite(1, 0);
Q.xAngel = 270;
}else if(openedTo(South, RIVE) && openedTo(East, RIVE)){
Q.setSprite(1, 0);
Q.xAngel = 180;
} else if(openedTo(South, RIVE) && openedTo(West, RIVE)){
Q.setSprite(1, 0);
Q.xAngel = 90;
}
break;
case 3:
if(!openedTo(North, RIVE)){
Q.setSprite(0, 0);
Q.xAngel = 270;
} else if(!openedTo(East, RIVE)){
Q.setSprite(0, 0);
Q.xAngel = 180;
}else if(!openedTo(South, RIVE)){
Q.setSprite(0, 0);
Q.xAngel = 90;
}else if(!openedTo(West, RIVE)){
Q.setSprite(0, 0);
Q.xAngel = 0;
}
break;
case 4:
Q.setSprite(0, 1);
break;
}
gfx.add(Q);
gfx.add(W);
gfx.add(W1);
gfx.add(W2);
gfx.add(W3);
break;
default:
break;
}
return gfx.getContent();
}
public NEField getNorth() {
return North;
}
public void setNorth(NEField north) {
North = north;
}
public NEField getEast() {
return East;
}
public void setEast(NEField east) {
East = east;
}
public NEField getSouth() {
return South;
}
public void setSouth(NEField south) {
South = south;
}
public NEField getWest() {
return West;
}
public void setWest(NEField west) {
West = west;
}
private boolean openedTo(NEField s, int typ){
return s==null || s.typ == typ;
}
public boolean containsUnit(){
return containtLUnit!=null;
}
@Override
public String toString() {
return "landschaft:" +
this.cordX +"," + cordY; /*+"\n"
+ " " + North.typ + " \n"
+ West.typ + typ + East.typ + "\n"
+ " " + South.typ + " \n";
*/
}
@Override
public void putGfxPos() {
}
}