Ejemplo n.º 1
0
  public void process() {
    if (ai_interval.hitInterval()) {

      if (update_intel_interval.hitInterval()) {
        this.updateIntel();
      }

      if (attack_type_to_build == -1) {
        SelectRandomUnitTypeAndQty(true);
      }
      if (defence_type_to_build == -1) {
        SelectRandomUnitTypeAndQty(false);
      }

      if (max_map_threat <= 1) {
        if (build_mine || max_map_target == 0) {
          if (best_mine_location.x >= 0) {
            if (buyUnit(UnitStats.MINE, best_mine_location, 1, true)) {
              this.build_mine = Functions.rnd(1, BUY_MINE_CHANCE) > 1;
            }
          } else {
            if (Main.DEBUG_AI) {
              main.addLogEntry("No potential mine location found.");
            }
          }
        } else if (max_map_target > 0) {
          if (buyUnit(
              attack_type_to_build, top_target_location, this.num_attackers_to_build, false)) {
            this.num_attackers_to_build--;
            if (this.num_attackers_to_build == 0) {
              this.build_mine = Functions.rnd(1, BUY_MINE_CHANCE) > 1;
              SelectRandomUnitTypeAndQty(true);
            } else {
              ai_interval.fireInterval(); // SO we buy again quickly!
            }
          }
        }
      } else { // Defend!
        if (buyUnit(defence_type_to_build, top_threat_location, num_defenders_to_build, false)) {
          num_defenders_to_build--;
          if (num_defenders_to_build == 0) {
            SelectRandomUnitTypeAndQty(false);
          } else {
            ai_interval.fireInterval(); // SO we buy again quickly!
          }
        }
      }
    }
  }
Ejemplo n.º 2
0
  public void startNewGame(int players_race) {
    if (this.img_cache.areImagesLoaded()) {
      i_game_stage = STAGE_PLAYING_GAME;

      // log.add("Game started!");
      log.clear();
      log.add("Use the menu on the left to select what to build.");
      log.add("Build units by clicking on the map.");

      game_data = new GameData(this, players_race, num_w.getNumber(), num_h.getNumber());

      input_msgs.clear();
      icon_panel = new IconPanel(this, 20, 50);
      icon_panel.reset();

      // Create starting units
      sprites = new ThreadSafeArrayList();

      new UnitMiningPlatform(this, 0, 0, 0);
      this.game_data.map_data.map[0][0].minerals = MapGen.MAX_MINERALS;
      int x = num_w.getNumber() - 1;
      int y = num_h.getNumber() - 1;
      new UnitMiningPlatform(this, x, y, 1);
      this.game_data.map_data.map[x][y].minerals = MapGen.MAX_MINERALS;

      menus.clear();

      map_update_interval.fireInterval();
    } else {
      log.add("Still loading images!  Please wait...");
    }
  }