예제 #1
0
  /** delete Orders with Status NONE from BuyOrders and tradeMarket */
  private void doGarbageOrders() {
    // Buyorders of Settlement do Garbage
    try {
      Integer[] keyArray = new Integer[tradeTransport.size()];
      int index = 0;
      for (TradeOrder order : tradeTransport.values()) {
        if (order.getStatus() == TradeStatus.NONE) {
          keyArray[index] = order.getId();
          index++;
        }
      }
      for (Integer id : keyArray) {
        if (id != null) {
          tradeTransport.remove(id);
        }
      }
    } catch (Exception e) {
      messageData.log("[Realms] doGarbageOrders BuyOrder exception " + e.getMessage());
      System.out.println("[Realms] ERROR doGarbageOrders BuyOrder exception " + e.getMessage());
      modelStatus = ModelStatus.MODEL_DISABLED;
    }

    try {
      // Central TradeMarket do Garbage
      if ((tradeMarket != null) && (tradeMarket.size() > 0)) {
        Integer[] keyArray = new Integer[tradeMarket.size()];
        int index = 0;
        for (TradeMarketOrder order : tradeMarket.values()) {
          if (order.getStatus() == TradeStatus.DECLINE) {
            keyArray[index] = order.getId();
            index++;
          } else {
            if (order.value() <= 0) {
              keyArray[index] = order.getId();
              index++;
            }
          }
        }

        for (Integer id : keyArray) {
          if (id != null) {
            tradeMarket.remove(id);
          }
        }
      }
    } catch (Exception e) {
      messageData.log("[Realms] doGarbageOrders SellOrder exception " + e.getMessage());
      System.out.println("[Realms] ERROR doGarbageOrders SellOrder exception " + e.getMessage());
      modelStatus = ModelStatus.MODEL_DISABLED;
    }
  }
예제 #2
0
  /**
   *
   *
   * <pre>
   * this represent the time aspect of the model.
   * age of realms is measured by the first settlement
   * trigger the tick action for the different objects
   * - transport
   * - tradeMarket
   * - Managers
   *   - colonyBuilder
   *   - colony
   *   - settlement
   *   - regiment
   *   - lehen
   *
   * finite state machine for
   * - Production
   * - Tax
   * - ModelCommand
   *
   * </pre>
   */
  public void OnTick() {
    try {
      // age of realms is measured by the first settlement
      if (this.getData().getSettlements().getSettlement(1) != null) {
        dayOfWeek = this.getData().getSettlements().getSettlement(1).getDayofWeek();
      }
      //			System.out.println("OnTick : "+modelStatus);
      // make timer run for trade  every tick
      // check transportqueues for fullfill
      tradeTransport.runTick();
      tradeMarket.runTick();
      // Builder
      colonyBuilderRun();
      settlementManagerRun();
      colonyManagerRun();
      regimentManagerRun();
      lehenManagerRun();
      switch (modelStatus) {
        case MODEL_ENABLED:
          garbageCounter++;
          // checkCommandQueue
          if (commandQueue.isEmpty() == false) {
            messageData.log("Enabled Next Command");
            modelStatus = nextCommandQueue();
            // checkMoveQueue
            return;
          }
          if (tradeQueue.isEmpty() == false) {
            modelStatus = nextTradeQueue();
          }

          if (garbageCounter >= garbageCounterLimit) {
            garbageCounter = 0;
            messageData.log("Enabled Garbage Collector for TradeOrder");
            doGarbageOrders();
            //				} else
            //				{
            //					logList.run();
            //
          }

          break;
        case MODEL_PRODUCTION:
          // nextProduction
          System.out.println("Next Produktion");
          messageData.log("Next Produktion");
          modelStatus = nextProductionQueue();
          // endProduction
          break;
        case MODEL_TAX:
          // nextTax
          messageData.log("Next Tax");
          modelStatus = nextTaxQueue();

          break;
        case MODEL_TRAINING:
          // nextTraining
          // endTraining
          break;
        case MODEL_BATTLE:
          // nextBattleStep
          // endBattle
          break;
        case MODEL_TRADE:
          // nextTradeQueue
          modelStatus = nextTradeQueue();
          // end TradeQueue
          break;
        case MODEL_MOVE:
          // nextMoveQueue
          // endMoveQueue
          break;
        case MODEL_COMMAND:
          // nextCommandQueue
          messageData.log("Command Next Command");
          modelStatus = nextCommandQueue();
          break;
        default:
          break;
      }
    } catch (Exception e) {
      messageData.log("[Realms] OnTick exception " + e.getMessage());
      messageData.log("[Realms] Model Disabled ! ");
      System.out.println("[Realms] ERROR exception " + e.getMessage());
      e.printStackTrace(System.out);
      System.out.println("[Realms] Model Disabled ! ");
      modelStatus = ModelStatus.MODEL_DISABLED;
    }
    return;
  }