-
Notifications
You must be signed in to change notification settings - Fork 68
/
flagreturn.py
47 lines (36 loc) · 1.5 KB
/
flagreturn.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""
Makes the flag returnable in Quake-like fashion.
.. codeauthor:: mat^2 & learn_more
"""
from pyspades.collision import vector_collision
from pyspades.constants import CTF_MODE
def apply_script(protocol, connection, config):
if protocol.game_mode != CTF_MODE:
return protocol, connection
class ReturnConnection(connection):
def on_flag_take(self):
self.team.other.flag.out = True
return connection.on_flag_take(self)
def on_flag_capture(self):
self.team.other.flag.out = False
self.team.other.flag.start = self.team.other.flag.get()
return connection.on_flag_capture(self)
def on_position_update(self):
flag = self.team.flag
if flag.player is None and flag.out:
if vector_collision(self.world_object.position, flag):
flag.out = False
flag.set(*flag.start)
flag.update()
self.protocol.send_chat('%s intel was returned by %s!' % (
self.team.name, self.name), global_message=None)
return connection.on_position_update(self)
class ReturnProtocol(protocol):
def set_map(self, map):
protocol.set_map(self, map)
for team in self.teams.values():
if team.spectator:
continue
team.flag.out = False
team.flag.start = team.flag.get()
return ReturnProtocol, ReturnConnection