Package civquest.util

Examples of civquest.util.Coordinate


  }

  public void remove(HasID hasID) {
    if (hasID instanceof Field) {
      Field f = (Field)hasID;
      Coordinate pos = f.getPosition();
      fields[pos.x][pos.y] = null;
    } else if (hasID instanceof MapObject) {
      // Fields are MapObjects, but we don't want to treat them as
      // MapObjects here (at least for now)
      removeMapObject((MapObject)hasID);
View Full Code Here


    // add MapObject to its Field
    Field field = mo.getField();
    assert field != null : "When adding MapObject to MapData, it must "
      + "already know its Field!";
    Coordinate pos = field.getPosition();
    fields[pos.x][pos.y].addMapObject(mo);
  }
View Full Code Here

    // remove mo from its field
    Field field = mo.getField();

    if (field != null) {
      Coordinate pos = field.getPosition();
      fields[pos.x][pos.y].removeMapObject(mo);
    } else {
      assert false : "Case not implemented!";
    }
  }
View Full Code Here

 
    List<Field> seaFields = new ArrayList<Field>();
    for(int n = -1;n <= 1;n += 2)
      {
        Coordinate[] ncoord = new Coordinate[2];
        ncoord[0] = adjustToMapSize(new Coordinate(coord.x + n,coord.y));
        ncoord[1] = adjustToMapSize(new Coordinate(coord.x,coord.y + n));
        for(int z = 0;z < 2;z++)
          if(ncoord[z] != null)
            {
              Field nfield = getField(ncoord[z]);
              if(nfield.isSea())
View Full Code Here

    /** Returns if any of the 8 neighborfields of the given field has the
   *  given distanceToCoast.
   */
    public boolean hasNeighborFieldDistanceToCoast(Field field,int distance) {
    Coordinate position = field.getPosition();
    for(int n = -1;n <= 1;n++)
      for(int z = -1;z <= 1;z += 2)
        {
          Coordinate pos = adjustToMapSize(new Coordinate(position.x + n,
                                  position.y + z));
          if((pos != null) && (getField(pos).getDistanceToCoast() == distance))
            return true;
        }
    for(int n = -1;n <= 1;n += 2)
      {
        Coordinate pos = adjustToMapSize(new Coordinate(position.x + n,position.y));
        if((pos != null) && (getField(pos).getDistanceToCoast() == distance))
          return true;
      }
    return false;
    }
View Full Code Here

    /** Returns if any of the 8 neighborfields of the given field has the
   *  given distanceToSea.
   */
    public boolean hasNeighborFieldDistanceToSea(Field field,int distance) {
  Coordinate position = field.getPosition();
  for(int n = -1;n <= 1;n++)
      for(int z = -1;z <= 1;z += 2)
    {
        Coordinate pos = adjustToMapSize(new Coordinate(position.x + n,
                              position.y + z));
        if((pos != null) && (getField(pos).getDistanceToSea() == distance))
      return true;
    }
  for(int n = -1;n <= 1;n += 2)
      {
    Coordinate pos = adjustToMapSize(new Coordinate(position.x + n,position.y));
    if((pos != null) && (getField(pos).getDistanceToSea() == distance))
        return true;
      }
  return false;
    }
View Full Code Here

     *  This function is especially useful for recursive functions that are
   *  called for some neighbor-coordinates of the original field.
   */
    public abstract Coordinate adjustToMapSize(Coordinate coord);
    public Coordinate adjustToMapSize(int x,int y) {
    return adjustToMapSize(new Coordinate(x,y));
  }
View Full Code Here

    // Do this in a more efficient way
    Rectangle viewRect = new Rectangle(quadMap.getViewportPosition(),
                       quadMap.getViewportPosition().add(quadMap.getViewportSize()));
    Properties properties = quadMap.getProperties();
    Coordinate dScroll = new Coordinate(properties.getScrollSize().x , 0);

    // The leftmost coordinate we want to use for testing if viewRect
    // contains it.       
    Coordinate testCoord = geoPrim.getBoundingRect().getTopLeftCorner();       

    while (testCoord.x <= viewRect.getX2()) {
            geoPrim.paint(g, (Coordinate)(viewRect.getTopLeftCorner().clone()));
            testCoord = testCoord.add(dScroll);
            geoPrim.addOffset(dScroll);
        }
  }
View Full Code Here

  public void drawEllipse(Graphics g, Coordinate m, Coordinate radius, boolean filled) {
    drawGeoPrimitive(g, new Arc(m, radius.x, radius.y, 0, 360, filled));
  }

  public void drawShortestLine(int x1, int y1, int x2, int y2, Graphics g) {
    drawShortestLine(new Coordinate(x1, y1), new Coordinate(x2, y2), g);
  }
View Full Code Here

    } else {
      int directDist = (int)(c1.getDistanceTo(c2));
     
      // Assure c1.x <= c2.x
      if (c1.x > c2.x) {
        Coordinate tmp = c1;
        c1 = c2;
        c2 = tmp;
      }

      Properties properties = quadMap.getProperties();
      int width = properties.getScrollSize().x;
      int ym = c2.y + (int)((double)(c1.y - c2.y)
                  * ((double)(width - c2.x) / (double)(width - c2.x + c1.x)));
     
      int l1 = (int)(Math.sqrt(c1.x * c1.x + ((c1.y - ym) * (c1.y - ym))));
      int l2 = (int)(Math.sqrt((width - c2.x) * (width - c2.x) + (ym - c2.y) * (ym - c2.y)));

      if (directDist <= l1 + l2) {
        if (dashed) {
          drawDashedLine(c1, c2, g, dashLength);
        } else {
          drawLine(c1, c2, g);
        }
      } else {
                if (dashed) {
          drawDashedLine(new Coordinate(0, ym), c1, g, dashLength);
          drawDashedLine(c2, new Coordinate(width - 1, ym), g, dashLength);
        } else {
          drawLine(new Coordinate(0, ym), c1, g);
          drawLine(c2, new Coordinate(width - 1, ym), g);
        }
      }
    }
  }
View Full Code Here

TOP

Related Classes of civquest.util.Coordinate

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.