View difference between Paste ID: 7GQscT4x and p8KGfHap
SHOW: | | - or go back to the newest paste.
1
# The idea of Push
2
# 	Teams spawn at set locations with the intel
3
#	They push the intel towards the CP's, which is also a set location
4
#
5
#Essentially we need read the map meta data get the spawn and cp locations 
6
#	and have the players and cp spawn at the apporiate locations
7
#
8
#Bonus feature: on intel cap the map rollbacks
9
#
10
# Sample extensions dictionary of an arena map with two gates:
11
# In this example there is one spawn location for blue and two spawn locations for green.
12
# extensions = {
13
#      'push': True,
14
#	   'push_spawn_range' : 5,
15
#      'push_blue_spawn' : (91, 276, 59),
16
#	   'push_blue_cp' : (91, 276, 59),
17
#      'push_green_spawn' : (78, 86, 59),
18
#	   'push_green_cp' : (78, 86, 59),
19
#      'water_damage' : 100
20
 # }
21
from pyspades.constants import *
22
from random import randint
23
24
# If ALWAYS_ENABLED is False, then the 'push' key must be set to True in
25-
 def apply_script(protocol, connection, config):
25+
26-
    class PushConnection(connection):   
26+
27
28
29
30
31
def get_entity_location(self, entity_id, extensions):
32
	
33-
				if ALWAYS_ENABLED:
33+
	if entity_id == BLUE_BASE and extensions.has_key('push_blue_cp'):
34-
					self.push_enabled = True
34+
		return extensions['push_blue_cp']
35
	elif entity_id == GREEN_BASE and extensions.has_key('push_green_cp'):
36-
					if extensions.has_key('push'):
36+
		return extensions['push_green_cp']
37-
						self.push_enabled = extensions['push']
37+
	#this next part might seem counter intiutive but you need the blue intel to spawn near the greens and vice versa
38-
					else:
38+
	elif entity_id == BLUE_FLAG and extensions.has_key('push_green_spawn'):
39-
						self.push_enabled = False
39+
		return extensions['push_blue_spawn']
40-
				if self.push_enabled:
40+
	elif entity_id == GREEN_FLAG and extensions.has_key('push_blue_spawn'):
41-
					if extensions.has_key('push_blue_spawn'):
41+
		return extensions['push_green_spawn']
42-
						self.blue_team.push_spawns = extensions['push_blue_spawn']
42+
43-
					
43+
def get_spawn_location(connection, extensions):
44-
					if extensions.has_key('push_green_spawn'):
44+
	#distance from spawn center to randomly spawn in
45-
						self.green_team.push_spawns = extensions['push_green_spawn']
45+
	spawn_range = 5;
46-
					
46+
	if extensions.has_key('push_spawn_range'):
47-
							
47+
		spawn_range = extensions['push_spawn_range']
48
		
49
	if self.team is self.protocol.blue_team:
50
		if extensions.has_key('push_blue_spawn'):
51
			xb = extensions['push_blue_spawn'[0]]
52
			yb = extensions['push_blue_spawn'[1]]
53
			xb += randint(-spawn_range, spawn_range)
54
			yb += randint(-spawn_range, spawn_range)
55
			return (xb, yb, connection.protocol.map.get_z(xb, yb))
56
	
57
	if self.team is self.protocol.green_team:
58
		if extensions.has_key('push_green_spawn'):
59
			xb = extensions['push_green_spawn'[0]]
60
			yb = extensions['push_green_spawn'[1]]
61
			xb += randint(-spawn_range, spawn_range)
62
			yb += randint(-spawn_range, spawn_range)
63
			return (xb, yb, connection.protocol.map.get_z(xb, yb))
64
			
65
def apply_script(protocol, connection, config):
66
	print "Yes we are in the def apply script"
67
	class PushConnection(connection):
68
		print "Hi Push Connection, nice to see you here"
69
		#self.protocol.send_chat("Attempting to start the Push Script")
70
		#def on_flag_drop(self):
71
			#if the flag falls in the water reset back to spawn location.
72
		
73
	class PushProtocol(protocol):
74
		push_enabled =False
75
			
76
		def on_map_change(self, map):
77
			extensions = self.map_info.extensions
78
			if ALWAYS_ENABLED:
79
				self.push_enabled = True
80
			else:
81
				if extensions.has_key('push'):
82
					self.push_enabled = extensions['push']
83
				else:
84
					self.push_enabled = False
85
			if self.push_enabled:
86
				self.map_info.get_entity_location = get_entity_location
87
				self.map_info.get_spawn_location = get_spawn_location
88
			return protocol.on_map_change(self, map)
89
		
90
	return PushProtocol, PushConnection		
91
92
return PushProtocol, PushConnection