import java.awt.*;
import java.applet.*;

public class Computer {

   int type;		/*CPU type*/
   int os;			/*current OS*/
   int x, y;		/*location*/
   boolean busy;		/*is the computer being used?*/
   static int TOASTER = 0;	/* computer 0 is a toaster */
   static int PC = 5;	/* type>=PC means the computer is a PC*/
   static int OFFSET = 4;	/* offset of screen from 0,0 */
   static int BORDER = 50;	/* BORDER pixels free on all sides*/
   JBill2 game;
   
   public Computer(JBill2 a) {
      game=a;
   }
   
   int setup(int i) {
      int j, counter=0;
      boolean flag;
      do {
	 if (++counter>4000) 
	   return 0;
	 x = game.RAND(BORDER, game.scrwidth - BORDER - game.net.width);
	 y = game.RAND(BORDER, game.scrheight - BORDER - game.net.height);
	 flag=true;
	 /*checks for conflicting computer placement*/
	 for (j=0; j<i && flag; j++)
	   if (game.INTERSECT(x, y,
			      game.net.width-game.bill.list[0].XOFFSET+game.bill.width,
			      game.net.height, game.net.computers[j].x,
			      game.net.computers[j].y,
			      game.net.width-game.bill.list[0].XOFFSET+game.bill.width,
			      game.net.height))
	     flag=false;
      } while (!flag);
      type = game.RAND(1, game.net.NUM_SYS);
      os = determineOS();
      busy=false;
      return 1;
   }
   
   int find_stray() {
      int i;
      for (i=0; i < game.bill.MAX_BILLS; i++) {
	 if (game.bill.list[i].state != game.bill.list[i].STRAY) 
	   continue;
	 if (game.INTERSECT(x, y, game.net.width, game.net.height, game.bill.list[i].x,
			    game.bill.list[i].y, game.OS.width, game.OS.height))
	   return i;
      }
      return -1;
   }
   
   boolean oncomputer (int locx, int locy) {
      return (Math.abs(locx-x) < game.net.width && Math.abs(locy-y) < game.net.height);
   }
   
   boolean compatible (int system) {
      return (type==system || (type>=PC && system>=game.OS.PC));
   }
   
   int determineOS() {
      if (type<PC) return type;
      else return game.RAND (game.OS.PC, game.OS.NUM_OS);
   }
   
   void draw() {
      game.ui.draw(game.net.pictures[type], x, y);
      if (os != game.OS.OFF)
	game.ui.draw(game.OS.os[os], x + OFFSET, y + OFFSET);
   }


}
