Territory.java 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* This program is free software; you can redistribute it and/or modify
  2. * it under the terms of the GNU General Public License as published by
  3. * the Free Software Foundation; either version 2, or (at your option)
  4. * any later version.
  5. *
  6. * This program is distributed in the hope that it will be useful,
  7. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. * GNU General Public License for more details.
  10. *
  11. * You should have received a copy of the GNU General Public License
  12. * along with this program; if not, write to the Free Software
  13. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  14. * 02111-1307, USA.
  15. *
  16. * http://www.gnu.org/copyleft/gpl.html
  17. */
  18. /*
  19. coded by Balancer
  20. ported to L2JRU by Mr
  21. balancer@balancer.ru
  22. http://balancer.ru
  23. version 0.1.1, 2005-06-07
  24. version 0.1, 2005-03-16
  25. */
  26. package net.sf.l2j.gameserver;
  27. import java.util.Map;
  28. import java.util.logging.Logger;
  29. import javolution.util.FastMap;
  30. import net.sf.l2j.gameserver.lib.SqlUtils;
  31. import net.sf.l2j.gameserver.model.L2Territory;
  32. public class Territory
  33. {
  34. private static Logger _log = Logger.getLogger(TradeController.class.getName());
  35. private static final Territory _instance = new Territory();
  36. private static Map<Integer,L2Territory> _territory;
  37. public static Territory getInstance()
  38. {
  39. return _instance;
  40. }
  41. private Territory()
  42. {
  43. // load all data at server start
  44. reload_data();
  45. }
  46. public int[] getRandomPoint(int terr)
  47. {
  48. return _territory.get(terr).getRandomPoint();
  49. }
  50. public int getProcMax(int terr)
  51. {
  52. return _territory.get(terr).getProcMax();
  53. }
  54. public void reload_data()
  55. {
  56. _territory = new FastMap<Integer,L2Territory>();
  57. Integer[][] point = SqlUtils.get2DIntArray(new String[]{"loc_id","loc_x","loc_y","loc_zmin","loc_zmax","proc"}, "locations", "loc_id > 0");
  58. for(Integer[] row : point)
  59. {
  60. // _log.info("row = "+row[0]);
  61. Integer terr = row[0];
  62. if(terr == null)
  63. {
  64. _log.warning("Null territory!");
  65. continue;
  66. }
  67. if(_territory.get(terr) == null)
  68. {
  69. L2Territory t = new L2Territory(terr);
  70. _territory.put(terr, t);
  71. }
  72. _territory.get(terr).add(row[1],row[2],row[3],row[4],row[5]);
  73. }
  74. }
  75. }