-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathartillery3.py
339 lines (297 loc) · 9.83 KB
/
artillery3.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
from pyspades.constants import *
from pyspades.world import Grenade
from pyspades.server import grenade_packet
from pyspades.common import Vertex3
from pyspades.constants import UPDATE_FREQUENCY
import random
import commands
from commands import alias,admin, add, name, get_team, get_player,where_from
from twisted.internet import reactor
from twisted.internet.reactor import callLater
from math import sqrt,sin,asin, cos, acos, pi, tan,atan,degrees,radians,hypot,atan2,floor
SPEED = 4.7
RELOAD_TIME = 3
@admin
@name('s')
def s(connection, points):
global SPEED
SPEED = float(points)
return "SPEED %s " % SPEED
add(s)
@admin
@name('r')
def r(connection, points):
global RELOAD_TIME
RELOAD_TIME = float(points)
return "RELOAD_TIME %s " % RELOAD_TIME
add(r)
@commands.alias('ar')
def be_artillery(connection):
flag = True
if connection.team == -1:
return False
x, y, z = connection.world_object.position.get()
# if connection.team == connection.protocol.blue_team and x<192:
# flag=True
# if connection.team == connection.protocol.green_team and x>320:
# flag=True
if flag:
connection.artillery = not connection.artillery
connection.fix_pos(x,y,z+1.5)
if connection.artillery:
return 'you are now artillery'
else:
return 'you are no longer artillery'
else:
return "you can't be artillery here"
commands.add(be_artillery)
@commands.alias('fix')
def fix_ori(connection):
if connection.artillery:
connection.fix_ori = not connection.fix_ori
connection.angle_gun = connection.world_object.orientation.get()
connection.ev, connection.az = 0, 0
if connection.fix_ori:
return 'gun orientation fixed this angle'
else:
return 'now orientation depends on your aim'
return "only artillery can use this command. press /ar"
commands.add(fix_ori)
def apply_script(protocol,connection,config):
class ArtilleryConnection(connection):
artillery = False
angle_gun = 1, 1, 1
fix_ori = False
fw,bw,le,ri=False,False,False,False
shift=False
reloading=False
shell = 0
def add_score(self, score):
self.shell +=score*3
return connection.add_score(self, score)
def on_hit(self, hit_amount, hit_player, type, grenade):
if self.artillery and self==hit_player:
return False
return connection.on_hit(self, hit_amount, hit_player, type, grenade)
def fix_pos(self, x, y, z):
if self.artillery:
self.set_location((x, y, z))
reactor.callLater(0.01, self.fix_pos, x, y, z)
def on_kill(self,killer,type,grenade):
self.artillery = False
return connection.on_kill(self,killer,type,grenade)
def on_team_leave(self):
self.artillery = False
return connection.on_team_leave(self)
def on_spawn(self,pos):
self.artillery = False
return connection.on_spawn(self,pos)
def on_reset(self):
self.artillery = False
connection.on_reset(self)
def on_walk_update(self, fw, bw, le, ri):
if self.fix_ori and self.artillery:
if not fw:
self.fw = False
else:
if not self.fw:
x, y, z = self.angle_gun
theta=degrees(atan2(y,x))
phi=degrees(asin(z))
r=hypot(x, y)
if phi>-88.9:
if self.shift:
new_phi=phi-1.0
else:
new_phi=phi-0.1
else:
new_phi=phi
z=sin(radians(new_phi))
x*=cos(radians(new_phi))/r
y*=cos(radians(new_phi))/r
self.angle_gun = x, y, z
if self.shift:
self.send_chat("elevation +1.0 deg. now azimuth%1f, elevation%+1f "% ((theta+450)%360, -1.0*new_phi))
else:
self.send_chat("elevation +0.1 deg. now azimuth%1f, elevation%+1f "% ((theta+450)%360, -1.0*new_phi))
self.fw = True
if not bw:
self.bw = False
else:
if not self.bw:
x, y, z = self.angle_gun
theta=degrees(atan2(y,x))
phi=degrees(asin(z))
r=hypot(x, y)
if phi<88.9:
if self.shift:
new_phi=phi+1.0
else:
new_phi=phi+0.1
else:
new_phi=phi
z=sin(radians(new_phi))
x*=cos(radians(new_phi))/r
y*=cos(radians(new_phi))/r
self.angle_gun = x, y, z
if self.shift:
self.send_chat("elevation -1.0 deg. now azimuth%1f, elevation%+1f "% ((theta+450)%360, -1.0*new_phi))
else:
self.send_chat("elevation -0.1 deg. now azimuth%1f, elevation%+1f "% ((theta+450)%360, -1.0*new_phi))
self.bw = True
if not le:
self.le = False
else:
if not self.le:
x, y, z = self.angle_gun
theta=degrees(atan2(y,x))
phi=degrees(asin(z))
r=hypot(x, y)
if self.shift:
new_theta=theta-1.0
else:
new_theta=theta-0.1
x = cos(radians(new_theta))*r
y = sin(radians(new_theta))*r
self.angle_gun = x, y, z
if self.shift:
self.send_chat("azimuth -1.0 deg. now azimuth%1f, elevation%+1f "% ((new_theta+450)%360, -1.0*phi))
else:
self.send_chat("azimuth -0.1 deg. now azimuth%1f, elevation%+1f "% ((new_theta+450)%360, -1.0*phi))
self.le = True
if not ri:
self.ri = False
else:
if not self.ri:
x, y, z = self.angle_gun
theta=degrees(atan2(y,x))
phi=degrees(asin(z))
r=hypot(x, y)
if self.shift:
new_theta=theta+1.0
else:
new_theta=theta+0.1
x = cos(radians(new_theta))*r
y = sin(radians(new_theta))*r
self.angle_gun = x, y, z
if self.shift:
self.send_chat("azimuth +1.0 deg. now azimuth%1f, elevation%+1f "% ((new_theta+450)%360, -1.0*phi))
else:
self.send_chat("azimuth +0.1 deg. now azimuth%1f, elevation%+1f "% ((new_theta+450)%360, -1.0*phi))
self.ri = True
return connection.on_walk_update(self, fw, bw, le, ri)
def heavy_gun_reload(self):
self.reloading=False
if self.shell>0:
self.send_chat("reloading completion")
def on_animation_update(self,jump,crouch,sneak,sprint):
if sneak and self.world_object.secondary_fire and self.artillery:
if self.shell>0:
if not self.reloading:
self.shell-=1
self.send_chat("There is %s shells rest."% self.shell)
self.heavy_gun_fire()
self.reloading=True
reactor.callLater(RELOAD_TIME, self.heavy_gun_reload)
else:
self.send_chat("reloading now!!")
else:
self.send_chat("There is no shells anymore!")
if sprint:
self.shift=True
else:
self.shift=False
return connection.on_animation_update(self,jump,crouch,sneak,sprint)
def heavy_gun_fire(self):
x, y, z = self.world_object.position.get()
pos = Vertex3(x, y, z)
if self.fix_ori:
a,b,c=self.angle_gun
else:
a,b,c = self.world_object.orientation.get()
"""
sigma=3
phi=degrees(asin(c))
r=hypot(a, b)
new_phi=phi+random.gauss(0, sigma)
c=sin(radians(new_phi))
a*=cos(radians(new_phi))/r
b*=cos(radians(new_phi))/r
theta=degrees(atan2(b,a))
r=hypot(a, b)
new_theta=theta+random.gauss(0, sigma)
a = cos(radians(new_theta))*r
b = sin(radians(new_theta))*r
"""
exp_pos = Vertex3(x-a, y-b, z-c)
a = a * SPEED
b = b * SPEED
c = c * SPEED
forward = Vertex3(a, b, c)
grenade_packet.value=0.0
grenade_packet.player_id=self.player_id
grenade_packet.position=exp_pos.get()
grenade_packet.velocity=(0,0,0)
self.protocol.send_contained(grenade_packet)
# grenade = self.protocol.world.create_object(Grenade, 0.0, pos, None, forward, None)
t=0
while t<1000:
xg=x+a*t
yg=y+b*t
zg=0.0315*(t**2)/2.0 + c*t + z
t+=0.001
if self.protocol.map.get_solid(xg,yg,zg) or (not 0<xg<511) or (not 0<yg<511) or (zg>63) :
t=t/32.1
break
"""
collision = grenade.get_next_collision(UPDATE_FREQUENCY)
if collision:
impact, x, y, z = collision
print "ans", t-impact, xg-x,yg-y,zg-z
"""
self.protocol.world.create_object(Grenade, t, pos, None, forward, None )
grenade_packet.value = t
grenade_packet.player_id = self.player_id
grenade_packet.position = pos.get()
grenade_packet.velocity = (a,b,c)
self.protocol.send_contained(grenade_packet)
reactor.callLater(t, self.high_explosive, xg, yg, zg)
def high_explosive(self,x,y,z):
count = 0
self.protocol.world.create_object(Grenade,count,Vertex3(x,y,z),None,Vertex3(0,0,0.001),self.grenade_exploded)
grenade_packet.value=count
grenade_packet.player_id=self.player_id
grenade_packet.position=(x,y,z)
grenade_packet.velocity=(0,0,0.001)
self.protocol.send_contained(grenade_packet)
self.explode=True
while count<15:
reactor.callLater(count/100.0, self.makegre,x,y,z)
count+=1
while count<0.15:
(xg,yg,zg)=(random.uniform(-0.5,0.5),random.uniform(-0.5,0.5),random.uniform(-0.5,0.5))
dt=random.uniform(0,0.25)
self.protocol.world.create_object(Grenade,count+dt,Vertex3(x,y,z),None,Vertex3(xg,yg,zg),self.grenade_exploded)
grenade_packet.value=count+dt
grenade_packet.player_id=self.player_id
grenade_packet.position=(x,y,z)
grenade_packet.velocity=(xg,yg,zg)
self.protocol.send_contained(grenade_packet)
count+=0.01
def makegre(self,x,y,z):
sigma=1.5
(xg,yg,zg)=(random.gauss(0, sigma),random.gauss(0, sigma),random.gauss(0, sigma))
xp, yp, zp = x+xg, y+yg, z+zg
self.protocol.world.create_object(Grenade,0,Vertex3(xp,yp,zp),None,Vertex3(0,0,0),self.grenade_exploded)
if random.uniform(-0.2,1.2)<0:
grenade_packet.value=0
grenade_packet.player_id=self.player_id
grenade_packet.position=(xp,yp,zp)
grenade_packet.velocity=(0,0,0)
self.protocol.send_contained(grenade_packet)
def on_fall(self, damage):
if self.artillery:
return False
else:
return connection.on_fall(self, damage)
return protocol,ArtilleryConnection