-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathABBS_23.py
2187 lines (1939 loc) · 70 KB
/
ABBS_23.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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
"""
Advanced Battle Bot System
basicbot をもとに改造 20190130 yuyasato
"""
# BASIC BOTS
# fakes a connection and partially replicates player behavior
#
# pathfinding was stripped out since it is unfinished and depended
# on the C++ navigation module
#
# requires adding the 'local' attribute to server.py's ServerConnection
#
# *** 201,206 ****
# --- 201,207 ----
# last_block = None
# map_data = None
# last_position_update = None
# + local = False
#
# def __init__(self, *arg, **kw):
# BaseConnection.__init__(self, *arg, **kw)
# *** 211,216 ****
# --- 212,219 ----
# self.rapids = SlidingWindow(RAPID_WINDOW_ENTRIES)
#
# def on_connect(self):
# + if self.local:
# + return
# if self.peer.eventData != self.protocol.version:
# self.disconnect(ERROR_WRONG_VERSION)
# return
#
# bots should stare at you and pull the pin on a grenade when you get too close
# /addbot [amount] [green|blue]
# /toggleai
from math import cos, sin, floor
from random import uniform, randrange,gauss,random,choice,triangular,shuffle
from enet import Address
from twisted.internet.reactor import seconds, callLater
from pyspades.protocol import BaseConnection
from pyspades.contained import BlockAction, SetColor,ChatMessage
from pyspades.server import input_data, weapon_input, set_tool, set_color, make_color
from pyspades.world import Grenade
from pyspades.common import Vertex3
from pyspades.collision import vector_collision
from pyspades.constants import *
from commands import admin, add, name, get_team, alias
from pyspades import contained as loaders
from pyspades.packet import load_client_packet
from pyspades.bytes import ByteReader, ByteWriter
from math import floor,sin,cos,degrees,radians,atan2,acos,asin
LOGIC_FPS = 4.0
BOT_IN_BOTH=True
DEFAULT_BOT_NUM = 10
TARGET_POSITION_ASSIGNED = True
TOWmode = False
TDMmode = False#True
ARENAmode = True
ARENA_JUNKAI_SECT = 7
CPU_LV = [95,99] #BOTの強さレベル 最小値、最大値 (1~99)まで
BOTMUTE = False
def bulletBlock(self, pos):
x, y, z = pos
set_color = SetColor()
set_color.value = make_color(*self.color)
set_color.player_id = self.player_id
self.protocol.send_contained(set_color, save = True)
block_action = BlockAction()
block_action.x = x
block_action.y = y
block_action.z = z
block_action.player_id = self.player_id
def destroy():
block_action.value = DESTROY_BLOCK
self.protocol.send_contained(block_action, save = True)
self.protocol.map.destroy_point(x, y, z)
callLater(0.1, destroy)
block_action.value = BUILD_BLOCK
self.protocol.send_contained(block_action, save = True)
self.protocol.map.set_point(x, y, z, self.color)
@admin
@name('addbot') #BOT追加コマンド 例 : /addbot 5 green
def add_bot(connection, amount = None, team = None):
protocol = connection.protocol
if team:
bot_team = get_team(connection, team)
blue, green = protocol.blue_team, protocol.green_team
amount = int(amount or 1)
for i in xrange(amount):
if not team:
bot_team = blue if blue.count() < green.count() else green
bot = protocol.add_bot(bot_team)
if not bot:
return "Added %s bot(s)" % i
return "Added %s bot(s)" % amount
@admin
@name('botmute') #BOTmute
def botmute(connection):
global BOTMUTE
BOTMUTE = not BOTMUTE
return "BOTMUTE %s" % BOTMUTE
@admin
@name('toggleai') #BOTのAIを停止・回復させるコマンド
def toggle_ai(connection):
protocol = connection.protocol
protocol.ai_enabled = not protocol.ai_enabled
if not protocol.ai_enabled:
for bot in protocol.bots:
bot.flush_input()
state = 'enabled' if protocol.ai_enabled else 'disabled'
protocol.send_chat('AI %s!' % state)
protocol.irc_say('* %s %s AI' % (connection.name, state))
@admin
@name('togglebotdamageglobal') #不明
@alias('tbdg')
def toggle_bot_damage_global(connection):
protocol = connection.protocol
protocol.bot_damage = not protocol.bot_damage
state = 'enabled' if protocol.bot_damage else 'disabled'
protocol.send_chat('Bot damage has been %s!' % state)
protocol.irc_say('* %s %s bot damage' % (connection.name, state))
@admin
@name('togglebulletvisuals') #BOTの銃弾の弾道がブロックで残る
@alias('tbv')
def toggle_bullet_visuals(connection):
protocol = connection.protocol
protocol.bullet_visual = not protocol.bullet_visual
state = 'enabled' if protocol.bullet_visual else 'disabled'
protocol.send_chat('Bullet visuals have been %s!' % state)
protocol.irc_say('* %s %s bullet visuals' % (connection.name, state))
@admin
@name('botdamage') #BOTの攻撃によるダメージを受けるか否か
@alias('bd')
def toggle_bot_damage(connection):
connection.bot_damage_player = not connection.bot_damage_player
state = 'now' if connection.bot_damage_player else 'no longer'
connection.send_chat('You will %s take damage from bots!' % state)
@admin
@name('refill') #自分が回復
def practice_refill(connection):
connection.refill()
connection.send_chat("Refilled!")
add(add_bot)
add(toggle_ai)
add(toggle_bot_damage)
add(toggle_bot_damage_global)
add(toggle_bullet_visuals)
add(practice_refill)
add(botmute)
class LocalPeer:
#address = Address(None, 0)
address = Address('255.255.255.255', 0)
roundTripTime = 0.0
def send(self, *arg, **kw):
pass
def reset(self):
pass
def apply_script(protocol, connection, config):
class BotProtocol(protocol):
bots = None
botbullets = None
ai_enabled = True
bot_damage = True
bullet_visual = False
BOT_junkai_route = []
tdm_tgt_calc = 100
best_friends_pos = [Vertex3(255,255,0),Vertex3(255,255,0)]
def add_bot(self, team):
if len(self.connections) + len(self.bots) >= 32:
return None
bot = self.connection_class(self, None)
bot.join_game(team)
self.bots.append(bot)
return bot
def arena_begun(self):
for bot in self.bots:
bot.has_arena_tgt = False
def on_world_update(self):
if ARENAmode:
extensions = self.map_info.extensions
if extensions.has_key('BOT_junkai_route'):
self.BOT_junkai_route = extensions['BOT_junkai_route']
botonly = True
for player in self.players.values():
if not player.local:
botonly = False
break
if not botonly:
if self.bots and self.ai_enabled:
do_logic = self.loop_count % int(UPDATE_FPS / LOGIC_FPS) == 0
for bot in self.bots:
if do_logic:
bot.think()
bot.update()
if self.botbullets:
for bullet in self.botbullets[::-1]:
if not bullet.update():
self.botbullets.remove(bullet)
if TDMmode:
if self.tdm_tgt_calc <= 0:
self.tdm_tgt_calc = 100
best_friends_blue = None
best_friends_blue_dist = 99999
for player in self.blue_team.get_players():
dist=0
for friend in player.team.get_players():
dist += player.distance_calc(player.world_object.position.get(),friend.world_object.position.get())
if dist<best_friends_blue_dist:
best_friends_blue_dist=dist
best_friends_blue = player
best_friends_green = None
best_friends_green_dist = 99999
for player in self.green_team.get_players():
dist=0
for friend in player.team.get_players():
dist += player.distance_calc(player.world_object.position.get(),friend.world_object.position.get())
if dist<best_friends_green_dist:
best_friends_green_dist=dist
best_friends_green = player
if best_friends_blue is not None:
best_friends_blue = best_friends_blue.world_object.position
else:
best_friends_blue = Vertex3(255,255,0)
if best_friends_green is not None:
best_friends_green = best_friends_green.world_object.position
else:
best_friends_green = Vertex3(255,255,0)
self.best_friends_pos = [best_friends_blue, best_friends_green]
self.tdm_tgt_calc-=1
protocol.on_world_update(self)
def on_map_change(self, map):
self.bots = []
self.botbullets = []
protocol.on_map_change(self, map)
def on_map_leave(self):
for bot in self.bots[:]:
bot.disconnect()
self.bots = None
self.botbullets = None
protocol.on_map_leave(self)
class BotConnection(connection):
has_intel = False
aim = None
aimOffset = None
aim_at = None
target_aim = None
input = None
acquire_targets = True
player_pinkblock = False
bot_pinkblock_changed = False
last_pos = (0,0,0)
player_firing = None
fire_call = None
botfindtimer = None
bot_jump = None
bot_forceaimat = None
cpulevel=1
bot_damage_player = True
jumptime=0
xoff_tebure=0
yoff_tebure=0
vel=0
xt,yt,zt=0,0,0
dis=255
jisatu=0
digtime=0
ikeru=[0,0,0,0]
toolchangetime =0
last_fire = 0
sprinttime=0
target_direction=[1,0,0]
smg_shooting=0
crouchkaihing=0
umaretate = 20
aim_quit = 100
damaged_block = []
front_rcog = [[-1]*64, [-1]*64] # [R,L]
long_recg=0
crouchinputed = 0
ave_d_theta=[0,0,0,0,0,0,0,0,0,0]
ave_d_phi=[0,0,0,0,0,0,0,0,0,0]
pre2ori_theta=0
pre2ori_phi=0
has_arena_tgt = False
dir_arena_tgt = 1
num_arena_tgt = 0
route_arena_tgt=0
jikuu_arena_tgt=0
battle_distance = 60
xoff_okure=0
yoff_okure=0
ois = False
_turn_speed = None
_turn_vector = None
def _get_turn_speed(self):
return self._turn_speed
def _set_turn_speed(self, value):
self._turn_speed = value
self._turn_vector = Vertex3(cos(value), sin(value), 0.0)
turn_speed = property(_get_turn_speed, _set_turn_speed)
def __init__(self, protocol, peer):
if peer is not None:
return connection.__init__(self, protocol, peer)
self.local = True
connection.__init__(self, protocol, LocalPeer())
self.on_connect()
#~ self.saved_loaders = None
self._send_connection_data()
self.send_map()
self.aim = Vertex3()
self.target_aim = Vertex3()
self.target_orientation = Vertex3()
self.target_aim_final = Vertex3()
self.turn_speed = 0.15 # rads per tick
self.input = set()
bot_damage_player = True
self.color = (0xDF, 0x00, 0xDF)
self.bot_set_color(self.color)
def join_game(self, team):
name = 'The Zero'
if self.player_id==1:
name = 'Itti'
if self.player_id==2:
name = 'Huta'
if self.player_id==3:
name = 'Mii'
if self.player_id==4:
name = 'SISI'
if self.player_id==5:
name = 'Go is God'
if self.player_id==6:
name = 'rock'
if self.player_id==7:
name = '007'
if self.player_id==8:
name = 'hatti'
if self.player_id==9:
name = 'Qtaro-'
if self.player_id==10:
name = 'A-10'
if self.player_id==11:
name = 'yutasaito'
if self.player_id==12:
name = 'nekomimi'
if self.player_id==13:
name = 'golgo13'
if self.player_id==14:
name = 'simesaba'
if self.player_id==15:
name = 'OMUSUBI'
if self.player_id==16:
name = 'kikumon*'
if self.player_id==17:
name = 'jhon'
if self.player_id==18:
name = 'bipei'
if self.player_id==19:
name = 'otimpo'
if self.player_id==20:
name = 'aeria'
if self.player_id==21:
name = 'gapoi'
if self.player_id==22:
name = 'niwaka'
if self.player_id==23:
name = 'moukin'
if self.player_id==24:
name = 'isitubute'
if self.player_id==25:
name = 'nijugorou'
if self.player_id==26:
name = 'yujikato'
if self.player_id==27:
name = 'nubou'
if self.player_id==28:
name = 'tako'
if self.player_id==29:
name = 'oniku'
if self.player_id==30:
name = 'sanju-'
if self.player_id==31:
name = 'sa-ti-wan'
if self.player_id==32:
name = 'The LAst'
if self.player_id==33:
name = 'GOD_EXIST'
while True:
self.cpulevel=random()
if CPU_LV[1]/100.0>self.cpulevel>CPU_LV[0]/100.0:
break
# self.cpulevel = 0.6
self.battle_distance = uniform(10,80)
self.name = '%s %s' % (name,str(self.player_id + 1))
self.team = team
weapon_rdm = random()
if weapon_rdm>0.4:
self.set_weapon(RIFLE_WEAPON, True)
elif weapon_rdm>0.15:
self.set_weapon(SMG_WEAPON, True)
else:
self.set_weapon(SHOTGUN_WEAPON, True)
self.aimOffset = (0,0,0)#(uniform(-0.4, 0.4), uniform(-0.4, 0.4), 0)
self.protocol.players[(self.name, self.player_id)] = self
self.on_login(self.name)
self.spawn()
def disconnect(self, data = 0):
if not self.local:
return connection.disconnect(self)
if self.disconnected:
return
self.protocol.bots.remove(self)
self.disconnected = True
self.on_disconnect()
def find_nearest_player(self):
if self.bot_forceaimat != None:
return
self.botfindtimer = None
obj = self.world_object
if not obj:
return
pos = obj.position
player_distances = []
for player in self.team.other.get_players():
if player.hp>0:
if vector_collision(pos, player.world_object.position, 60+ self.cpulevel*65):
if self.canseeY(pos,player.world_object.position)>=0:
ex,ey,ez = player.world_object.position.get()
px,py,pz = pos.get()
ox,oy,oz = obj.orientation.get()
nx,ny,nz = ex-px, ey-py, ez-pz
dist = (nx**2+ny**2+nz**2)**0.5
nx/=dist
ny/=dist
nz/=dist
naiseki = nx*ox + ny*oy + nz*oz
if naiseki>1:
naiseki=1
if naiseki<-1:
naiseki=-1
nasukaku = degrees(acos(naiseki))
if max(self.cpulevel*100,45)>nasukaku:
player_distances.append(((player.world_object.position - pos), player))
if len(player_distances) > 0:
nearestindex = min(range(len(player_distances)), key=lambda i: abs(player_distances[i][0].length_sqr()))
self.aim_at = player_distances[nearestindex][1]
self.aim_quit = 70
else:
self.aim_quit-=1
def think(self):
obj = self.world_object
pos = obj.position
if self.acquire_targets:
self.find_nearest_player()
# find nearby foes
# if self.acquire_targets:
# # if self.botfindtimer == None:
# self.botfindtimer = callLater(max(1-(self.cpulevel)+0.1,0), self.find_nearest_player) #敵が認知界に入った時に、気づくまでの時間
# replicate player functionality
def bot_jumpfunc(self, a = None,b = None):
if self.world_object.velocity.z**2>0.001:
self.bot_jump = None
self.input.add('jump')
self.player_firing = callLater(0.3, self.player_stopfiring)
def bot_pinkblock_crouch(self):
def uncrouch():
self.player_firing = None
if self.player_firing == None:
self.player_firing = callLater(uniform(0.1, 0.4), uncrouch)
def cast_sensor(self,SENSOR_LENGTH,orientation):
x,y,z = orientation.get()
self.world_object.set_orientation(x,y,z)
blk = self.world_object.cast_ray(SENSOR_LENGTH)
if blk is not None:
dist = self.distance_calc(blk,self.world_object.position.get())
else:
dist=0
return dist
def orientation_calc(self, mypos,tgtpos):
d = self.distance_calc(mypos.get(),tgtpos.get())
if d == 0:
ori = Vertex3(1,0,0)
d = 0
return ori, d
ori = tgtpos - mypos
ori.x /=d
ori.y /=d
ori.z /=d
return ori, d
def canseeY2(self,mypos,ori, d):
if self.hp<=0:
return None
pos = [mypos.x,mypos.y,mypos.z]
ori = ori.get()
d_calc = 0.3 #bk
for calc_do in xrange(int(d / d_calc)):
pos[0] += ori[0]*d_calc
pos[1] += ori[1]*d_calc
pos[2] += ori[2]*d_calc
round_pos = (floor(pos[0]), floor(pos[1]), floor(pos[2]))
_x,_y,_z = round_pos
if _x > 511 or _x < 0 or _y > 511 or _y < 0 or _z > 62 or _z < -20:
return False
if _z >= 0:
if self.protocol.map.get_solid(*round_pos):
return False
return True
def canseeY(self,mypos,tgt_head, No_need_compx=False):
fori = self.world_object.orientation.get()
ori,d = self.orientation_calc(mypos,tgt_head)
self.world_object.set_orientation(*ori.get())
if self.world_object.cast_ray(d) is None:
self.world_object.set_orientation(*fori)
if No_need_compx:
return 0
if self.canseeY2(mypos,ori, d):
return 0
self.world_object.set_orientation(*fori)
if No_need_compx:
return -1
tgt_karada=Vertex3(tgt_head.x,tgt_head.y,tgt_head.z+1)
ori,d = self.orientation_calc(mypos,tgt_karada)
self.world_object.set_orientation(*ori.get())
if self.world_object.cast_ray(d) is None:
self.world_object.set_orientation(*fori)
if self.canseeY2(mypos,ori, d):
return 1
tgt_asi=Vertex3(tgt_head.x,tgt_head.y,tgt_head.z+2)
ori,d = self.orientation_calc(mypos,tgt_asi)
self.world_object.set_orientation(*ori.get())
if self.world_object.cast_ray(d) is None:
self.world_object.set_orientation(*fori)
if self.canseeY2(mypos,ori, d):
return 2
self.world_object.set_orientation(*fori)
return -1
def forward_recognition(self,px,py,pz,distf,TGT_ORIENT,SENSOR_LENGTH):
if TGT_ORIENT.y==0:
Rx, Ry = floor(px-TGT_ORIENT.y*0.47-TGT_ORIENT.x*0.5+distf*TGT_ORIENT.x)+0.505, floor(py+TGT_ORIENT.x*0.47-TGT_ORIENT.y*0.5+distf*TGT_ORIENT.y)+0.505
Lx, Ly = floor(px+TGT_ORIENT.y*0.47-TGT_ORIENT.x*0.5+distf*TGT_ORIENT.x)+0.505, floor(py-TGT_ORIENT.x*0.47-TGT_ORIENT.y*0.5+distf*TGT_ORIENT.y)+0.505
elif 0.05<((TGT_ORIENT.x/TGT_ORIENT.y)**2)**0.05<20:
Rx, Ry = px-TGT_ORIENT.y*0.47-TGT_ORIENT.x*0.5+distf*TGT_ORIENT.x, py+TGT_ORIENT.x*0.47-TGT_ORIENT.y*0.5+distf*TGT_ORIENT.y
Lx, Ly = px+TGT_ORIENT.y*0.47-TGT_ORIENT.x*0.5+distf*TGT_ORIENT.x, py-TGT_ORIENT.x*0.47-TGT_ORIENT.y*0.5+distf*TGT_ORIENT.y
else:
Rx, Ry = floor(px-TGT_ORIENT.y*0.47-TGT_ORIENT.x*0.5+distf*TGT_ORIENT.x)+0.505, floor(py+TGT_ORIENT.x*0.47-TGT_ORIENT.y*0.5+distf*TGT_ORIENT.y)+0.505
Lx, Ly = floor(px+TGT_ORIENT.y*0.47-TGT_ORIENT.x*0.5+distf*TGT_ORIENT.x)+0.505, floor(py-TGT_ORIENT.x*0.47-TGT_ORIENT.y*0.5+distf*TGT_ORIENT.y)+0.505
for rl in range(2):
for h in range(3):
if self.front_rcog[rl][int(pz+h)]<0:
if rl==0:
RLx = Rx
RLy = Ry
else:
RLx = Lx
RLy = Ly
self.world_object.position.set(RLx,RLy,pz+h)
d=self.cast_sensor(SENSOR_LENGTH-distf, TGT_ORIENT)
if d>0:d+=distf
self.front_rcog[rl][int(pz+h)]=d
c0r=self.front_rcog[0][int(pz)]
c1r=self.front_rcog[0][int(pz+1)]
c2r=self.front_rcog[0][int(pz+2)]
c0l=self.front_rcog[1][int(pz)]
c1l=self.front_rcog[1][int(pz+1)]
c2l=self.front_rcog[1][int(pz+2)]
pattern = 1
AP = 0
AP_CROUCH = 20
AP_JUMP = 5
AP_DANSA = 1
# 0 # -1 # 6661 # 6662 # 6663 # 666 #
# 0 # H X # H X # H X # H X # H X #
# 1 # B # B X # B X # B # B r #
# 2 # B # B X # B # B X # B r #
##################################################
if c0r + c0l + c1r + c1l + c2r + c2l ==0 : # 前方障害なし
pattern = 0
AP+=0
elif c1r + c1l + c2r + c2l== 0 :# -1 しゃがめば通れる
pattern = -1
AP+=AP_CROUCH
elif (0<c0r<=c1r+0.1 and 0<c0r<=c2r+0.1) or (0<c0l<=c1l+0.1 and 0<c0l<=c2l+0.1) : # DAME 無条件で前方障害有り判定
pattern = 6661
AP+=0
elif (0<c0r<=c1r+0.1 and c2r==0) or (0<c0l<=c1l+0.1 and c2l==0) : # DAME 無条件で前方障害有り判定
pattern = 6662
AP+=0
elif (0<c0r<=c2r+0.1 and c1r==0) or (0<c0l<=c2l+0.1 and c1l==0) : # DAME 無条件で前方障害有り判定
pattern = 6663
AP+=0
if 0<pattern<666:
# A # B # C # D #
# 0 # H - # H X # 0 X- #
# 1 # B X # B # 1 X #
# 2 X # B X # B X # 2 r- #
##################################################
if c0r + c0l + c1r + c1l == 0 : # A
AP+=AP_DANSA
pattern = 1
elif c1r>c2r+0.1>0 or c1l>c2l+0.1>0: #B
AP+=AP_DANSA
pattern = 1
elif (c1r == 0 and c0r>c2r+0.1>0 )or(c1l==0 and c0l>c2l+0.1>0): #C
AP+=AP_DANSA
pattern = 1
elif (c0r>c1r+0.1>0 or c0r==0) or (c0l>c1l+0.1>0 or c0l==0): #D
AP+=AP_JUMP
pattern = 2
else:
pattern = -99
dist=0
if pattern ==1 or pattern == 2:
UEtemae = 1.5
if pattern ==1:
if min(c2r,c2l)==0:
dist = max(0,max(c2r,c2l)-UEtemae) #土台ブロック存在地点の1.5bk手前から探索
else:
dist = max(0,min(c2r,c2l)-UEtemae)
else:
if min(c1r,c1l)==0:
dist = max(0,max(c1r,c1l)-UEtemae)
else:
dist = max(0,min(c1r,c1l)-UEtemae)
for rl in range(2):
h = -1
if self.front_rcog[rl][int(pz+h)]<0:
if rl==0:
RLx = Rx
RLy = Ry
else:
RLx = Lx
RLy = Ly
self.world_object.position.set(RLx+(dist-distf)*TGT_ORIENT.x,RLy+(dist-distf)*TGT_ORIENT.y,pz+h)
d=self.cast_sensor(SENSOR_LENGTH-dist, TGT_ORIENT)
if d>0:d+=dist
self.front_rcog[rl][int(pz+h)]=d
cu1r=self.front_rcog[0][int(pz-1)]
cu1l=self.front_rcog[1][int(pz-1)]
if 0<cu1r<=c2r+0.1 or 0<cu1l<=c2l+0.1:
pattern = 777
elif pattern == 2:
for rl in range(2):
h = -2
if self.front_rcog[rl][int(pz+h)]<0:
if rl==0:
RLx = Rx
RLy = Ry
else:
RLx = Lx
RLy = Ly
self.world_object.position.set(RLx+(dist-distf)*TGT_ORIENT.x,RLy+(dist-distf)*TGT_ORIENT.y,pz+h)
d=self.cast_sensor(SENSOR_LENGTH-dist, TGT_ORIENT)
if d>0:d+=dist
self.front_rcog[rl][int(pz+h)]=d
cu2r=self.front_rcog[0][int(pz-2)]
cu2l=self.front_rcog[1][int(pz-2)]
if 0<cu2r<=c1r+0.1 or 0<cu2l<=c1l+0.1:
pattern = 888
return pattern, AP,(dist+distf)
def inputcrouch(self, crouchadd):
inputedtime = seconds() - self.crouchinputed
lostime = 0.7-(self.cpulevel/2)
if inputedtime > lostime:
if crouchadd:
self.input.add('crouch')
self.crouchinputed = seconds()
elif inputedtime < lostime/2:
self.input.add('crouch')
def new_gosa(self,fired):
if fired:
R = (1-self.cpulevel)*5+2
theta = uniform(0,360)
xoff = R*cos(radians(theta))
yoff = R*sin(radians(theta))-3*(1-self.cpulevel)
else:
R = (1-self.cpulevel)*20+2
theta = uniform(0,360)
xoff = R*cos(radians(theta))
yoff = R*sin(radians(theta))
return xoff, yoff
def tgt_pos_update(self):
px,py,pzo = self.world_object.position.get()
if self.world_object.crouch:
pz=pzo-1
else:
pz=pzo
if TOWmode:
n = 0
hidari_team = self.protocol.entities[n].team
while True:
n += 1
if self.protocol.entities[n].team != hidari_team:break
if self.team != self.protocol.entities[n].team:
tgt_entity = self.protocol.entities[n]
ASSIGNED_POSITION = self.protocol.entities[n]
else:
tgt_entity = self.protocol.entities[n-1]
ASSIGNED_POSITION = self.protocol.entities[n-1]
collides = vector_collision(tgt_entity,
self.world_object.position, TC_CAPTURE_DISTANCE)
if self in tgt_entity.players:
ASSIGNED_POSITION = None
if not collides:
tgt_entity.remove_player(self)
else:
if collides:
ASSIGNED_POSITION = None
tgt_entity.add_player(self)
elif TDMmode:
if self.team == self.protocol.blue_team:
ASSIGNED_POSITION = self.protocol.best_friends_pos[1]
elif self.team == self.protocol.green_team:
ASSIGNED_POSITION = self.protocol.best_friends_pos[0]
elif ARENAmode:
junkai_route = self.protocol.BOT_junkai_route
if self.has_arena_tgt:
ii = self.num_arena_tgt
choiced_route = self.route_arena_tgt
tpos = junkai_route[choiced_route][ii]
d = self.distance_calc(tpos,self.world_object.position.get())
if d < max(5, 0.3*ARENA_JUNKAI_SECT):
self.jikuu_arena_tgt = 0
ii+=self.dir_arena_tgt
if 0 <= ii <= len(junkai_route[choiced_route])-1:
self.num_arena_tgt = ii
tpos = junkai_route[choiced_route][ii]
else:
self.has_arena_tgt = False
self.jikuu_arena_tgt += d
if self.jikuu_arena_tgt > ARENA_JUNKAI_SECT * UPDATE_FPS * 10:
self.has_arena_tgt = False
ASSIGNED_POSITION=Vertex3(*tpos)
else:
self.jikuu_arena_tgt = 0
routenum=len(junkai_route)
routechoce = range(routenum)
shuffle(routechoce)
for choiced_route in routechoce:
i = 0
mie = []
mind = 999
for junkaipos in junkai_route[choiced_route]:
d = self.distance_calc(junkaipos,self.world_object.position.get())
if d<mind+2*ARENA_JUNKAI_SECT:
if self.canseeY(self.world_object.position,Vertex3(*junkaipos),True)>=0:
mie.append([i,d])
if mind>=d:
mind=d
i+=1
if mind<4*ARENA_JUNKAI_SECT:
break
kouho=[]
for pt in mie:
if pt[1]<=d+2*ARENA_JUNKAI_SECT:
kouho.append(pt[0])
if kouho !=[]:
ii = choice(kouho)
tpos = junkai_route[choiced_route][ii]
ASSIGNED_POSITION = Vertex3(*tpos)
self.route_arena_tgt = choiced_route
self.has_arena_tgt = True
self.dir_arena_tgt = choice([-1,1])
self.num_arena_tgt = ii
else:
ASSIGNED_POSITION=None
if ASSIGNED_POSITION is None:
dd = 0
else:
apx,apy,apz = ASSIGNED_POSITION.get()
xd = apx - px
yd = apy - py
dd = (xd**2 + yd**2)**(0.5)
if dd == 0:
self.target_direction = Vertex3(1, 0, 0)
else:
self.target_direction = Vertex3(xd/dd, yd/dd, 0)
# self.protocol.green_team.base.set(ASSIGNED_POSITION.x,ASSIGNED_POSITION.y,ASSIGNED_POSITION.z)
# self.protocol.blue_team.base.set(self.world_object.position.x+xd/dd*4,self.world_object.position.y+yd/dd*4,self.world_object.position.z)
# self.protocol.update_entities()
def update(self):
if self.hp<=0:
return
second = seconds()
obj = self.world_object
pos = obj.position
ori = obj.orientation
spade_using =False
digging = False
dis=255
obj.set_orientation(*ori.get())
self.flush_input()
xt,yt,zt=self.world_object.orientation.get()
preori_theta = degrees(atan2(yt,xt))
preori_phi = degrees(asin(zt))
d_phi = preori_phi - self.pre2ori_phi
if preori_theta > 0:
if self.pre2ori_theta<0 and preori_theta - self.pre2ori_theta>180:
d_theta = 360 - (preori_theta - self.pre2ori_theta)
else:
d_theta = preori_theta - preori_theta
else:
if self.pre2ori_theta>0 and preori_theta - self.pre2ori_theta<-180:
d_theta = -360 - (preori_theta - self.pre2ori_theta)
else:
d_theta = preori_theta - self.pre2ori_theta
self.ave_d_theta.pop(0)
self.ave_d_theta.append(d_theta)
self.ave_d_phi.pop(0)
self.ave_d_phi.append(d_phi)
if self.aim_at and self.aim_at.world_object: #射撃対象敵プレイヤー認識状態
crouchadd = False
self.vel+=gauss(0, (1-self.cpulevel)*2)-(self.vel*0.3)
self.vel=max( min( (1-self.cpulevel)*5 , self.vel) , (1-self.cpulevel)*(-5)) #動目標の速度誤認係数
aim_at_pos = self.aim_at.world_object.position
aim_at_vel = self.aim_at.world_object.velocity
target_obj = self.aim_at.world_object
canseepos = self.canseeY(pos,aim_at_pos)
xt,yt,zt=target_obj.orientation.get()
aim_at_pos_future = Vertex3(aim_at_pos.x + aim_at_vel.x*self.vel, aim_at_pos.y + aim_at_vel.y*self.vel, aim_at_pos.z+canseepos + aim_at_vel.z*self.vel)
#動目標の予測位置誤認後位置
self.aim.set_vector(aim_at_pos_future)
self.aim -= pos
distance_to_aim = self.aim.normalize()
if self.battle_distance < distance_to_aim:#目標遠いなら進む
self.input.add('up')
if canseepos>=0: #目標視認可能状況
self.aim_quit=100
self.target_orientation.set_vector(self.aim)
if self.acquire_targets:
if self.tool != BLOCK_TOOL: #射撃指示
if self.smg_shooting>0:
self.fire_weapon()
elif distance_to_aim < 135 and self.fire_call is None and seconds() - self.sprinttime>0.5 and seconds() - self.toolchangetime>0.5:
self.fire_call = callLater(uniform(0,(1-self.cpulevel)*2.5)+1.1, self.fire_weapon) #射撃間隔
#回避行動制御
self.target_aim_final.set_vector(self.aim)
diff = target_obj.orientation - self.target_aim_final
diff = diff.length_sqr()
if diff > 0.01 and self.cpulevel>0.3:
p_dot = target_obj.orientation.perp_dot(self.target_aim_final)
if 0.1 > p_dot > -0.1:
if random()+self.cpulevel > 0.6: #レアケース ジャンプ回避
if self.bot_jump == None:
self.bot_jump = callLater(uniform(0.01,0.1), self.bot_jumpfunc)
if random() > 0.95 and self.cpulevel>0.4: #屈伸回避
crouchadd = True
if 0.1 > p_dot > 0.0:
self.input.add('right')
elif 0.0 > p_dot > -0.1:
self.input.add('left')
#狙点制御
#誤差半径収束
# if sum(self.ave_d_theta)>1 or sum(self.ave_d_phi)>1:
# self.xoff_okure, self.yoff_okure = self.new_gosa()
off_r = (self.xoff_okure**2+(self.yoff_okure*3)**2)**0.5
offaddtheta= uniform(0,360)
d_okure = 100
d_backokure = d_okure - ((self.cpulevel/2)+0.5)
if off_r<16:
d_okure_r = (2-self.cpulevel)*((self.cpulevel/2)+0.5)
else:
d_okure_r = ((self.cpulevel/2)+0.5)
xoffadd = cos(radians(offaddtheta))*off_r*d_okure_r/d_okure
yoffadd = sin(radians(offaddtheta))*off_r*d_okure_r/d_okure/3
self.xoff_okure = self.xoff_okure*d_backokure/d_okure + xoffadd
self.yoff_okure = self.yoff_okure*d_backokure/d_okure + yoffadd
#手ぶれ分
self.xoff_tebure+=gauss(0, (1-self.cpulevel/2)*0.2)-(self.xoff_tebure*0.01)
self.yoff_tebure+=gauss(0, (1-self.cpulevel/2)*0.2)-(self.yoff_tebure*0.01)