Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Tug of War game mode, where you must progressively capture the enemy CPs in a
- straight line to win.
- Maintainer: mat^2
- """
- from pyspades.constants import *
- from pyspades.server import Territory
- import random
- import math
- from math import pi
- HELP = [
- "In Tug of War, you capture your opponents' front CP to advance."
- ]
- class TugTerritory(Territory):
- disabled = True
- def add_player(self, player):
- if self.disabled:
- return
- Territory.add_player(self, player)
- def enable(self):
- self.disabled = False
- def disable(self):
- for player in self.players.copy():
- self.remove_player(player)
- self.disabled = True
- self.progress = float(self.team.id)
- def get_index(value):
- if value < 0:
- raise IndexError()
- return value
- def apply_script(protocol, connection, config):
- class TugConnection(connection):
- def get_spawn_location(self):
- if self.team.spawn_cp is None:
- base = self.team.last_spawn
- else:
- base = self.team.spawn_cp
- return base.get_spawn_location()
- def on_spawn(self, pos):
- for line in HELP:
- self.send_chat(line)
- return connection.on_spawn(self, pos)
- class TugProtocol(protocol):
- game_mode = TC_MODE
- def get_cp_entities(self):
- # generate positions
- map = self.map
- blue_cp = []
- green_cp = []
- points = self.map_info.extensions
- for i, point in enumerate(points['tow_locations']):
- if i < len(points['tow_locations']) / 2:
- blue_cp.append(point)
- else:
- green_cp.append(point)
- # make entities
- index = 0
- entities = []
- for i, (x, y) in enumerate(blue_cp):
- entity = TugTerritory(index, self, *(x, y, map.get_z(x, y)))
- entity.team = self.blue_team
- if i == 0:
- self.blue_team.last_spawn = entity
- entity.id = -1
- else:
- entities.append(entity)
- index += 1
- self.blue_team.cp = entities[-1]
- self.blue_team.cp.disabled = False
- self.blue_team.spawn_cp = entities[-2]
- for i, (x, y) in enumerate(green_cp):
- entity = TugTerritory(index, self, *(x, y, map.get_z(x, y)))
- entity.team = self.green_team
- if i == len(green_cp) - 1:
- self.green_team.last_spawn = entity
- entity.id = index
- else:
- entities.append(entity)
- index += 1
- self.green_team.cp = entities[-(len(points)-2)/2]
- self.green_team.cp.disabled = False
- self.green_team.spawn_cp = entities[-(len(points)-2)/2 + 1]
- return entities
- def on_cp_capture(self, territory):
- team = territory.team
- if team.id:
- move = -1
- else:
- move = 1
- for team in [self.blue_team, self.green_team]:
- try:
- team.cp = self.entities[get_index(team.cp.id + move)]
- team.cp.enable()
- except IndexError:
- pass
- try:
- team.spawn_cp = self.entities[get_index(
- team.spawn_cp.id + move)]
- except IndexError:
- team.spawn_cp = team.last_spawn
- cp = (self.blue_team.cp, self.green_team.cp)
- for entity in self.entities:
- if not entity.disabled and entity not in cp:
- entity.disable()
- return TugProtocol, TugConnection
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement