Ejemplo n.º 1
0
 /**
  * Method that writes to a channel to inform others that an artillery has been seen. Primarily
  * used by HQ to know to build a shields encampment.
  *
  * @throws GameActionException
  */
 public void reportArtillerySighting() throws GameActionException {
   Robot[] nearbyEnemyRobots = rc.senseNearbyGameObjects(Robot.class, 14, rc.getTeam().opponent());
   for (Robot robot : nearbyEnemyRobots) {
     RobotInfo robotInfo = rc.senseRobotInfo(robot);
     if (robotInfo.type == RobotType.ARTILLERY) {
       BroadcastSystem.write(ChannelType.ARTILLERY_SEEN, Constants.TRUE);
     }
   }
 }
Ejemplo n.º 2
0
  @Override
  public void run() {
    try {
      //			System.out.println("start: " + Clock.getBytecodeNum());
      BroadcastSystem.write(powerChannel, (int) rc.getTeamPower());
      //			System.out.println("end: " + Clock.getBytecodeNum());
      DataCache.updateRoundVariables();

      // Check if enemy's nuke is half done
      if (!enemyNukeHalfDone) {
        enemyNukeHalfDone = rc.senseEnemyNukeHalfDone();
      }
      if (enemyNukeHalfDone) {
        // Broadcast this
        BroadcastSystem.write(ChannelType.ENEMY_NUKE_HALF_DONE, 1);
      }

      //			if (Clock.getRoundNum() < 20) {
      //				BroadcastSystem.write(ChannelType.CHANNEL1, 0);
      //				BroadcastSystem.read(ChannelType.CHANNEL1);
      //				BroadcastSystem.write(ChannelType.CHANNEL1, 0);
      //			} else {
      //				rc.resign();
      //			}
      //

      if (Clock.getRoundNum() % Constants.CHANNEL_CYCLE == 0 && Clock.getRoundNum() > 0) {
        EncampmentJobSystem.updateJobsOnCycle();
      } else {
        EncampmentJobSystem.updateJobsAfterChecking();
      }

      if (rc.isActive()) {

        boolean upgrade = false;
        if (!rc.hasUpgrade(Upgrade.DEFUSION)
            && enemyNukeHalfDone
            && DataCache.numAlliedSoldiers > 5) {
          upgrade = true;
          rc.researchUpgrade(Upgrade.DEFUSION);
        } else if (rc.getTeamPower() < 100) {
          if (!rc.hasUpgrade(Upgrade.DEFUSION)) {
            upgrade = true;
            rc.researchUpgrade(Upgrade.DEFUSION);
          } else if (!rc.hasUpgrade(Upgrade.PICKAXE)) {
            upgrade = true;
            rc.researchUpgrade(Upgrade.PICKAXE);
          } else if (!rc.hasUpgrade(Upgrade.FUSION)) {
            upgrade = true;
            rc.researchUpgrade(Upgrade.FUSION);
          }
        }
        if (!upgrade) {

          // Spawn a soldier
          Direction desiredDir = rc.getLocation().directionTo(rc.senseEnemyHQLocation());
          Direction dir = getSpawnDirection(rc, desiredDir);
          if (dir != null) {
            EncampmentJobSystem.updateJobs();
            rc.spawn(dir);
          }
        }
        //				if (Clock.getRoundNum() < 5) {
        //					Direction dir = rc.getLocation().directionTo(rc.senseEnemyHQLocation());
        //					rc.spawn(dir);
        //				}
      }

      //			// TODO: find out what strategy to switch to?
      //			// this.strategy = HQStrategy.xxx
      //			if (rc.isActive()) {
      //				switch (strategy) {
      //				case CREATE_SOLDIER:
      //					create_soldier();
      //					break;
      //				case RESEARCH_DEFUSION:
      //					if (!rc.hasUpgrade(Upgrade.DEFUSION)) {
      //						rc.researchUpgrade(Upgrade.DEFUSION);
      //					}
      //					break;
      //				case RESEARCH_FUSION:
      //					if (!rc.hasUpgrade(Upgrade.FUSION)) {
      //						rc.researchUpgrade(Upgrade.FUSION);
      //					}
      //					break;
      //				case RESEARCH_NUKE:
      //					if (!rc.hasUpgrade(Upgrade.NUKE)) {
      //						rc.researchUpgrade(Upgrade.NUKE);
      //					}
      //					break;
      //				case RESEARCH_PICKAXE:
      //					if (!rc.hasUpgrade(Upgrade.PICKAXE)) {
      //						rc.researchUpgrade(Upgrade.PICKAXE);
      //					}
      //					break;
      //				case RESEARCH_VISION:
      //					if (!rc.hasUpgrade(Upgrade.VISION)) {
      //						rc.researchUpgrade(Upgrade.VISION);
      //					}
      //					break;
      //				default:
      //					break;
      //				}
      //			}
    } catch (Exception e) {
      System.out.println("caught exception before it killed us:");
      System.out.println(rc.getRobot().getID());
      e.printStackTrace();
    }
  }