Team.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. """
  2. This file is part of RuneOptimizer.
  3. RuneOptimizer is free software: you can redistribute it and/or modify it
  4. under the terms of the GNU General Public License as published by the Free
  5. Software Foundation, either version 3 of the License, or (at your option)
  6. any later version.
  7. RuneOptimizer is distributed in the hope that it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. You should have received a copy of the GNU General Public License along with
  12. RuneOptimizer. If not, see <https://www.gnu.org/licenses/>.
  13. """
  14. class Team():
  15. """
  16. A team of units.
  17. Very similar to the Teams class, but this one loads units, so it's not
  18. safe to have as property of Unit.
  19. Parameters
  20. ----------
  21. id : str
  22. Team identifier.
  23. name : str
  24. Team name.
  25. priority : int
  26. Team priority, from 1 to 50.
  27. units : Unit[]
  28. """
  29. _id = None
  30. _name = ""
  31. _priority = 1
  32. _units = []
  33. def __init__(self, id=None):
  34. if id != None:
  35. self._load(id)
  36. def _load(self, id):
  37. global conn
  38. cursor = conn.execute(
  39. "SELECT id, name, priority FROM teams WHERE id = ?",
  40. (id,)
  41. )
  42. row = cursor.fetchone()
  43. if row != None:
  44. self._id = str(row[0])
  45. self._name = str(row[1])
  46. self._priority = int(row[2])
  47. # Load units
  48. self._units = []
  49. cursor = conn.execute(
  50. "SELECT unit FROM units_teams WHERE team = ?",
  51. (self._id,)
  52. )
  53. rows = cursor.fetchall()
  54. for row in rows:
  55. self.units.append(Unit(str(row[0])))
  56. @property
  57. def id(self):
  58. return self._id
  59. @property
  60. def name(self):
  61. return self._name
  62. @property
  63. def priority(self):
  64. return self._priority
  65. @property
  66. def units(self):
  67. return self._units