| 29 | return obj |
| 30 | |
| 31 | class Spawncluster(object): |
| 32 | def __init__(self, spawnpoint): |
| 33 | self._spawnpoints = [spawnpoint] |
| 34 | self.centroid = spawnpoint.position |
| 35 | self.min_time = spawnpoint.time |
| 36 | self.max_time = spawnpoint.time |
| 37 | |
| 38 | def __getitem__(self, key): |
| 39 | return self._spawnpoints[key] |
| 40 | |
| 41 | def __iter__(self): |
| 42 | for x in self._spawnpoints: |
| 43 | yield x |
| 44 | |
| 45 | def __contains__(self, item): |
| 46 | return item in self._spawnpoints |
| 47 | |
| 48 | def __len__(self): |
| 49 | return len(self._spawnpoints) |
| 50 | |
| 51 | def append(self, spawnpoint): |
| 52 | # update centroid |
| 53 | f = len(self._spawnpoints) / (len(self._spawnpoints) + 1.0) |
| 54 | self.centroid = utils.intermediate_point(spawnpoint.position, self.centroid, f) |
| 55 | |
| 56 | self._spawnpoints.append(spawnpoint) |
| 57 | |
| 58 | if spawnpoint.time < self.min_time: |
| 59 | self.min_time = spawnpoint.time |
| 60 | |
| 61 | if spawnpoint.time > self.max_time: |
| 62 | self.max_time = spawnpoint.time |
| 63 | |
| 64 | def simulate_centroid(self, spawnpoint): |
| 65 | f = len(self._spawnpoints) / (len(self._spawnpoints) + 1.0) |
| 66 | new_centroid = utils.intermediate_point(spawnpoint.position, self.centroid, f) |
| 67 | |
| 68 | return new_centroid |
| 69 | |
| 70 | def cost(spawnpoint, cluster, time_threshold): |
| 71 | distance = utils.distance(spawnpoint.position, cluster.centroid) |