Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // new canSee code
- public boolean canSee(Tile t){
- int perception=getSpecial(PERCEPTION_ID);
- int absoluteDist=location.distanceToTile(t);
- int xDist=location.getX()-t.getX();
- int yDist=location.getY()-t.getY();
- int dist;
- int stepDist=1;
- int stepRemain=0;
- int xNeg;
- int yNeg;
- Tile checkTile;
- //Check for out of sight range
- if(!(absoluteDist<=perception)){
- return false;
- }
- //Can always see your current location
- if(t.equals(location)){
- return true;
- }
- //check if distance for each coord is positive or negative
- if(xDist>=0){ //positive x
- xNeg=1;
- }else{ //negative x
- xNeg=-1;
- }
- if(yDist>=0){ //positive y
- yNeg=1;
- }else{ //negative y
- yNeg=-1;
- }
- //check if tile is further along X or Y coords and set variables
- boolean furtherX;
- if(Math.abs(xDist)>=Math.abs(yDist)){ //further along x axis
- stepDist=Math.abs((xDist+xNeg)/(yDist+yNeg));
- stepRemain=Math.abs((xDist+xNeg)%(yDist+yNeg));
- dist=xDist+xNeg;
- furtherX=true;
- }else{ //further along y axis
- stepDist=Math.abs((yDist+yNeg)/(xDist+xNeg));
- stepRemain=Math.abs((yDist+yNeg)%(xDist+xNeg));
- dist=yDist+yNeg;
- furtherX=false;
- }
- //check for if stepRemain is >0
- boolean complex;
- if(stepRemain==0){
- complex=false;
- }else{
- complex=true;
- }
- //actual loop to determine if the Tile is visible to the Creature or not
- int j=0;
- int step=stepDist;
- for(int i=0;i<Math.abs(dist);i++){
- if(furtherX){
- checkTile=Map.getCurrentMap().getTile(location.getX()-(xNeg*i),location.getY()-(yNeg*j));
- }else{
- checkTile=Map.getCurrentMap().getTile(location.getX()-(xNeg*j),location.getY()-(yNeg*i));
- }
- //if the tile you're currently checking is the target tile, then you can see it
- if(checkTile.equals(t)){
- return true;
- }
- //If the tile you're currently checking is not the target tile, and there's objects you can't see through on the tile, you can't see the target
- if(checkTile!=null&&checkTile.getTerrainObject()!=null&&!checkTile.getTerrainObject().canSeeThrough()){
- return false;
- }
- step--;
- if(step==0){
- if(complex){
- if(j==0){
- stepDist++;
- }else{
- stepRemain--;
- if(stepRemain==0){
- stepDist--;
- }
- }
- }
- step=stepDist;
- j++;
- }
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement