Methapolis  0.27
 All Classes Namespaces Files Functions Variables Enumerator
Utilities.java
Go to the documentation of this file.
1 package micropolisj.util;
2 
3 import java.awt.Rectangle;
4 
5 import micropolisj.engine.TileConstants;
6 
7 public class Utilities {
8 
9 
10  //bits 14, 13, 12 contain playerID (16 is always 0), 15 is power, first 8 bits tileValue
11  //allows 8 players (including neutral)
12  public static short codePlayerID(int tileValue, int playerID) {
13  int id = playerID << 11;
14  id = (tileValue & TileConstants.LOMASK) | id;
15  return (short) id;
16  }
17 
18  public static int getPlayerID(char encodedTile) {
19  return getPlayerID((short) encodedTile);
20  }
21 
22  public static int getPlayerID(int encodedTile) {
23  return getPlayerID((char)encodedTile);
24  }
25 
26  public static int getPlayerID(short encodedTile) {
27  // set powerbit to 0
28  encodedTile &= (TileConstants.PWRBIT - 1);
29  return encodedTile >> 11;
30  }
31 
32 
33  public static Rectangle moveRectangle(Rectangle rec, int dx, int dy) {
34  rec.setLocation(rec.x + dx, rec.y + dy);
35  return rec;
36  }
37 
38 
39 // public static void main(String[] args) {
40 // System.out.println((short)codePlayerID((char)130, 2));
41 // System.out.println(getPlayerID(codePlayerID(130, 7)));
42 // }
43 
44 
45 
46 
47 }