Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public boolean canSee(Tile t){
- int perception=getSpecial(PERCEPTION_ID);
- int dist=location.distanceToTile(t);
- int xDist=location.getX()-t.getX();
- int yDist=location.getY()-t.getY();
- int stepDist=1;
- int stepRemain=0;
- Tile checkTile;
- //Check for out of sight range
- if(!(dist<=perception)){
- return false;
- }
- //Can always see your current location
- if(t.equals(location)){
- return true;
- }
- if(xDist>=0){ //positive x
- if(yDist>=0){ //positive y
- if(Math.abs(xDist)>=Math.abs(yDist)){ //further along x axis
- stepDist=(xDist+1)/(yDist+1);
- stepRemain=(xDist+1)%(yDist+1);
- if(stepRemain==0){
- int j=0;
- int step=stepDist;
- for(int i=0;i<(xDist+1);i++){
- checkTile=Map.getCurrentMap().getTile(location.getX()-i,location.getY()-j);
- if(checkTile.equals(t)){
- return true;
- }
- if(checkTile!=null&&checkTile.getTerrainObject()!=null&&!checkTile.getTerrainObject().canSeeThrough()){
- return false;
- }
- step--;
- if(step==0){
- step=stepDist;
- j++;
- }
- }
- }else{
- int j=0;
- int step=stepDist;
- for(int i=0;i<(xDist+1);i++){
- checkTile=Map.getCurrentMap().getTile(location.getX()-i,location.getY()-j);
- if(checkTile.equals(t)){
- return true;
- }
- if(checkTile!=null&&checkTile.getTerrainObject()!=null&&!checkTile.getTerrainObject().canSeeThrough()){
- return false;
- }
- step--;
- if(step==0){
- if(i<stepDist&&j==0){
- stepDist++;
- }else{
- stepRemain--;
- if(stepRemain==0){
- stepDist--;
- }
- }
- step=stepDist;
- j++;
- }
- }
- }
- }else{ //further along y axis
- stepDist=(yDist+1)/(xDist+1);
- stepRemain=(yDist+1)%(xDist+1);
- if(stepRemain==0){
- int j=0;
- int step=stepDist;
- for(int i=0;i<(yDist+1);i++){
- checkTile=Map.getCurrentMap().getTile(location.getX()-j,location.getY()-i);
- if(checkTile.equals(t)){
- return true;
- }
- if(checkTile!=null&&checkTile.getTerrainObject()!=null&&!checkTile.getTerrainObject().canSeeThrough()){
- return false;
- }
- step--;
- if(step==0){
- step=stepDist;
- j++;
- }
- }
- }else{
- int j=0;
- int step=stepDist;
- for(int i=0;i<(yDist+1);i++){
- checkTile=Map.getCurrentMap().getTile(location.getX()-j,location.getY()-i);
- if(checkTile.equals(t)){
- return true;
- }
- if(checkTile!=null&&checkTile.getTerrainObject()!=null&&!checkTile.getTerrainObject().canSeeThrough()){
- return false;
- }
- step--;
- if(step==0){
- if(i<stepDist&&j==0){
- stepDist++;
- }else{
- stepRemain--;
- if(stepRemain==0){
- stepDist--;
- }
- }
- step=stepDist;
- j++;
- }
- }
- }
- }
- }else{ //negative y
- if(Math.abs(xDist)>=Math.abs(yDist)){ //further along x axis
- stepDist=Math.abs((xDist+1)/(yDist-1));
- stepRemain=(xDist+1)%(yDist-1);
- if(stepRemain==0){
- int j=0;
- int step=stepDist;
- for(int i=0;i<(xDist+1);i++){
- checkTile=Map.getCurrentMap().getTile(location.getX()-i,location.getY()+j);
- if(checkTile.equals(t)){
- return true;
- }
- if(checkTile!=null&&checkTile.getTerrainObject()!=null&&!checkTile.getTerrainObject().canSeeThrough()){
- return false;
- }
- step--;
- if(step==0){
- step=stepDist;
- j++;
- }
- }
- }else{
- int j=0;
- int step=stepDist;
- for(int i=0;i<(xDist+1);i++){
- checkTile=Map.getCurrentMap().getTile(location.getX()-i,location.getY()+j);
- if(checkTile.equals(t)){
- return true;
- }
- if(checkTile!=null&&checkTile.getTerrainObject()!=null&&!checkTile.getTerrainObject().canSeeThrough()){
- return false;
- }
- step--;
- if(step==0){
- if(i<stepDist&&j==0){
- stepDist++;
- }else{
- stepRemain--;
- if(stepRemain==0){
- stepDist--;
- }
- }
- step=stepDist;
- j++;
- }
- }
- }
- }else{ //further along y axis
- stepDist=Math.abs((yDist-1)/(xDist+1));
- stepRemain=(yDist-1)%(xDist+1);
- if(stepRemain==0){
- int j=0;
- int step=stepDist;
- for(int i=0;i>(yDist-1);i--){
- checkTile=Map.getCurrentMap().getTile(location.getX()-j,location.getY()-i);
- if(checkTile.equals(t)){
- return true;
- }
- if(checkTile!=null&&checkTile.getTerrainObject()!=null&&!checkTile.getTerrainObject().canSeeThrough()){
- return false;
- }
- step--;
- if(step==0){
- step=stepDist;
- j++;
- }
- }
- }else{
- int j=0;
- int step=stepDist;
- for(int i=0;i>(yDist-1);i--){
- checkTile=Map.getCurrentMap().getTile(location.getX()-j,location.getY()-i);
- if(checkTile.equals(t)){
- return true;
- }
- if(checkTile!=null&&checkTile.getTerrainObject()!=null&&!checkTile.getTerrainObject().canSeeThrough()){
- return false;
- }
- step--;
- if(step==0){
- if(i<stepDist&&j==0){
- stepDist++;
- }else{
- stepRemain--;
- if(stepRemain==0){
- stepDist--;
- }
- }
- step=stepDist;
- j++;
- }
- }
- }
- }
- }
- }else{ //negative x
- if(yDist>=0){ //positive y
- if(Math.abs(xDist)>=Math.abs(yDist)){ //further along x axis
- stepDist=Math.abs((xDist-1)/(yDist+1));
- stepRemain=(xDist-1)%(yDist+1);
- if(stepRemain==0){
- int j=0;
- int step=stepDist;
- for(int i=0;i>(xDist-1);i--){
- checkTile=Map.getCurrentMap().getTile(location.getX()-i,location.getY()-j);
- if(checkTile.equals(t)){
- return true;
- }
- if(checkTile!=null&&checkTile.getTerrainObject()!=null&&!checkTile.getTerrainObject().canSeeThrough()){
- return false;
- }
- step--;
- if(step==0){
- step=stepDist;
- j++;
- }
- }
- }else{
- int j=0;
- int step=stepDist;
- for(int i=0;i>(xDist-1);i--){
- checkTile=Map.getCurrentMap().getTile(location.getX()-i,location.getY()-j);
- if(checkTile.equals(t)){
- return true;
- }
- if(checkTile!=null&&checkTile.getTerrainObject()!=null&&!checkTile.getTerrainObject().canSeeThrough()){
- return false;
- }
- step--;
- if(step==0){
- if(i<stepDist&&j==0){
- stepDist++;
- }else{
- stepRemain--;
- if(stepRemain==0){
- stepDist--;
- }
- }
- step=stepDist;
- j++;
- }
- }
- }
- }else{ //further along y axis
- stepDist=Math.abs((yDist+1)/(xDist-1));
- stepRemain=(yDist+1)%(xDist-1);
- if(stepRemain==0){
- int j=0;
- int step=stepDist;
- for(int i=0;i<(yDist+1);i++){
- checkTile=Map.getCurrentMap().getTile(location.getX()+j,location.getY()-i);
- if(checkTile.equals(t)){
- return true;
- }
- if(checkTile!=null&&checkTile.getTerrainObject()!=null&&!checkTile.getTerrainObject().canSeeThrough()){
- return false;
- }
- step--;
- if(step==0){
- step=stepDist;
- j++;
- }
- }
- }else{
- int j=0;
- int step=stepDist;
- for(int i=0;i<(yDist+1);i++){
- checkTile=Map.getCurrentMap().getTile(location.getX()+j,location.getY()-i);
- if(checkTile.equals(t)){
- return true;
- }
- if(checkTile!=null&&checkTile.getTerrainObject()!=null&&!checkTile.getTerrainObject().canSeeThrough()){
- return false;
- }
- step--;
- if(step==0){
- if(i<stepDist&&j==0){
- stepDist++;
- }else{
- stepRemain--;
- if(stepRemain==0){
- stepDist--;
- }
- }
- step=stepDist;
- j++;
- }
- }
- }
- }
- }else{ //negative y
- if(Math.abs(xDist)>=Math.abs(yDist)){ //further along x axis
- stepDist=Math.abs((xDist-1)/(yDist-1));
- stepRemain=(xDist-1)%(yDist-1);
- if(stepRemain==0){
- int j=0;
- int step=stepDist;
- for(int i=0;i>(xDist-1);i--){
- checkTile=Map.getCurrentMap().getTile(location.getX()-i,location.getY()+j);
- if(checkTile.equals(t)){
- return true;
- }
- if(checkTile!=null&&checkTile.getTerrainObject()!=null&&!checkTile.getTerrainObject().canSeeThrough()){
- return false;
- }
- step--;
- if(step==0){
- step=stepDist;
- j++;
- }
- }
- }else{
- int j=0;
- int step=stepDist;
- for(int i=0;i>(xDist-1);i--){
- checkTile=Map.getCurrentMap().getTile(location.getX()-i,location.getY()+j);
- if(checkTile.equals(t)){
- return true;
- }
- if(checkTile!=null&&checkTile.getTerrainObject()!=null&&!checkTile.getTerrainObject().canSeeThrough()){
- return false;
- }
- step--;
- if(step==0){
- if(i<stepDist&&j==0){
- stepDist++;
- }else{
- stepRemain--;
- if(stepRemain==0){
- stepDist--;
- }
- }
- step=stepDist;
- j++;
- }
- }
- }
- }else{ //further along y axis
- stepDist=Math.abs((yDist-1)/(xDist-1));
- stepRemain=(yDist-1)%(xDist-1);
- if(stepRemain==0){
- int j=0;
- int step=stepDist;
- for(int i=0;i>(yDist-1);i--){
- checkTile=Map.getCurrentMap().getTile(location.getX()+j,location.getY()-i);
- if(checkTile.equals(t)){
- return true;
- }
- if(checkTile!=null&&checkTile.getTerrainObject()!=null&&!checkTile.getTerrainObject().canSeeThrough()){
- return false;
- }
- step--;
- if(step==0){
- step=stepDist;
- j++;
- }
- }
- }else{
- int j=0;
- int step=stepDist;
- for(int i=0;i>(yDist-1);i--){
- checkTile=Map.getCurrentMap().getTile(location.getX()+j,location.getY()-i);
- if(checkTile.equals(t)){
- return true;
- }
- if(checkTile!=null&&checkTile.getTerrainObject()!=null&&!checkTile.getTerrainObject().canSeeThrough()){
- return false;
- }
- step--;
- if(step==0){
- if(i<stepDist&&j==0){
- stepDist++;
- }else{
- stepRemain--;
- if(stepRemain==0){
- stepDist--;
- }
- }
- step=stepDist;
- j++;
- }
- }
- }
- }
- }
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement