public int upgradeLevel(Upgrade type) {
    if (upgrades == null) return 0 ;
    int num = 0 ;
    for (int i = 0 ; i < upgrades.length ; i++) {
      if (upgrades[i] == type && upgradeStates[i] == STATE_INTACT) num++ ;
    }
    return num ;
  }