forked from flags/Reactor-3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.py
2325 lines (1809 loc) · 70.6 KB
/
player.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
from globals import *
from alife import *
from overwatch import events
import libtcodpy as tcod
import graphics as gfx
import crafting
import worldgen
import bad_numbers
import weapons
import dialog
import timers
import inputs
import melee
import debug
import zones
import logic
import menus
import items
import time
import life
import maps
import logging
def handle_input():
global PLACING_TILE,RUNNING,SETTINGS,KEYBOARD_STRING
if gfx.window_is_closed():
SETTINGS['running'] = False
return True
if INPUT['\x1b'] or INPUT['q']:
if ACTIVE_MENU['menu'] >= 0:
menus.delete_menu(ACTIVE_MENU['menu'], abort=True)
elif LIFE[SETTINGS['controlling']]['targeting']:
LIFE[SETTINGS['controlling']]['targeting'] = None
LIFE[SETTINGS['controlling']]['throwing'] = None
LIFE[SETTINGS['controlling']]['firing'] = None
SELECTED_TILES[0] = []
elif LIFE[SETTINGS['controlling']]['actions']:
life.clear_actions(LIFE[SETTINGS['controlling']])
life.stop(LIFE[SETTINGS['controlling']])
if LIFE[SETTINGS['controlling']]['actions']:
LIFE[SETTINGS['controlling']]['actions'] = []
elif INPUT['\x1b']:
SETTINGS['running'] = False
gfx.refresh_view('map')
if INPUT['\t']:
if not SETTINGS['controlling'] or not LIFE[SETTINGS['controlling']]['group']:
return False
_menu_items = [menus.create_item('single', 'Attack', 'Focus attack on target.')]
_menu_items.append(menus.create_item('single', 'Health', 'Check health of...'))
_menu_items.append(menus.create_item('single', 'Location', 'Get location of...'))
_menu = menus.create_menu(title='Command',
menu=_menu_items,
padding=(1,1),
position=(1,1),
format_str='$k: $v',
on_select=send_command)
menus.activate_menu(_menu)
if INPUT['-']:
if SETTINGS['draw console']:
SETTINGS['draw console'] = False
else:
SETTINGS['draw console'] = True
if SETTINGS['draw console']:
return
if INPUT['up'] or (SETTINGS['controlling'] and INPUT['8']):
if not ACTIVE_MENU['menu'] == -1:
menus.move_up(MENUS[ACTIVE_MENU['menu']], MENUS[ACTIVE_MENU['menu']]['index'])
elif LIFE[SETTINGS['controlling']]['targeting']:
LIFE[SETTINGS['controlling']]['targeting'][1]-=1
elif life.has_dialog(LIFE[SETTINGS['controlling']]):
_dialog = dialog.get_dialog(life.has_dialog(LIFE[SETTINGS['controlling']]))
if _dialog['cursor_index'] > 0:
_dialog['cursor_index'] -= 1
elif LIFE[SETTINGS['controlling']]['pos'][1]>0 and not LIFE[SETTINGS['controlling']]['dead']:
life.clear_actions(LIFE[SETTINGS['controlling']])
life.add_action(LIFE[SETTINGS['controlling']],{'action': 'move', 'to': (LIFE[SETTINGS['controlling']]['pos'][0], LIFE[SETTINGS['controlling']]['pos'][1]-1, LIFE[SETTINGS['controlling']]['pos'][2])},200)
if INPUT['down'] or (SETTINGS['controlling'] and INPUT['2']):
if not ACTIVE_MENU['menu'] == -1:
menus.move_down(MENUS[ACTIVE_MENU['menu']], MENUS[ACTIVE_MENU['menu']]['index'])
elif LIFE[SETTINGS['controlling']]['targeting']:
LIFE[SETTINGS['controlling']]['targeting'][1]+=1
elif life.has_dialog(LIFE[SETTINGS['controlling']]):
_dialog = dialog.get_dialog(life.has_dialog(LIFE[SETTINGS['controlling']]))
if _dialog['cursor_index'] < _dialog['max_cursor_index']-1:
_dialog['cursor_index'] += 1
elif LIFE[SETTINGS['controlling']]['pos'][1]<MAP_SIZE[1]-1 and not LIFE[SETTINGS['controlling']]['dead']:
life.clear_actions(LIFE[SETTINGS['controlling']])
life.add_action(LIFE[SETTINGS['controlling']],{'action': 'move', 'to': (LIFE[SETTINGS['controlling']]['pos'][0],LIFE[SETTINGS['controlling']]['pos'][1]+1, LIFE[SETTINGS['controlling']]['pos'][2])},200)
if INPUT['right'] or (SETTINGS['controlling'] and INPUT['6']):
if not ACTIVE_MENU['menu'] == -1:
menus.next_item(MENUS[ACTIVE_MENU['menu']],MENUS[ACTIVE_MENU['menu']]['index'])
menus.item_changed(ACTIVE_MENU['menu'],MENUS[ACTIVE_MENU['menu']]['index'])
elif LIFE[SETTINGS['controlling']]['targeting']:
LIFE[SETTINGS['controlling']]['targeting'][0]+=1
elif LIFE[SETTINGS['controlling']]['pos'][0]<MAP_SIZE[0]-1 and not LIFE[SETTINGS['controlling']]['dead']:
life.clear_actions(LIFE[SETTINGS['controlling']])
life.add_action(LIFE[SETTINGS['controlling']],{'action': 'move', 'to': (LIFE[SETTINGS['controlling']]['pos'][0]+1,LIFE[SETTINGS['controlling']]['pos'][1], LIFE[SETTINGS['controlling']]['pos'][2])},200)
if INPUT['left'] or (SETTINGS['controlling'] and INPUT['4']):
if not ACTIVE_MENU['menu'] == -1:
menus.previous_item(MENUS[ACTIVE_MENU['menu']],MENUS[ACTIVE_MENU['menu']]['index'])
menus.item_changed(ACTIVE_MENU['menu'],MENUS[ACTIVE_MENU['menu']]['index'])
elif LIFE[SETTINGS['controlling']]['targeting']:
LIFE[SETTINGS['controlling']]['targeting'][0]-=1
elif LIFE[SETTINGS['controlling']]['pos'][0]>0 and not LIFE[SETTINGS['controlling']]['dead']:
life.clear_actions(LIFE[SETTINGS['controlling']])
life.add_action(LIFE[SETTINGS['controlling']],{'action': 'move', 'to': (LIFE[SETTINGS['controlling']]['pos'][0]-1,LIFE[SETTINGS['controlling']]['pos'][1], LIFE[SETTINGS['controlling']]['pos'][2])},200)
if INPUT['\r']:
if ACTIVE_MENU['menu'] > -1:
menus.item_selected(ACTIVE_MENU['menu'],MENUS[ACTIVE_MENU['menu']]['index'])
return False
_dialog = life.has_dialog(LIFE[SETTINGS['controlling']])
if SETTINGS['controlling'] and _dialog:
dialog.select_choice(_dialog)
#if '_drawn' in _dialog:
# del _dialog['_drawn']
#dialog.give_menu_response(LIFE[SETTINGS['controlling']], _dialog)
return False
if not SETTINGS['controlling']:
return False
if INPUT['.'] or (SETTINGS['controlling'] and INPUT['5']):
_skip = False
for event in EVENTS:
if not event['delay']:
_skip = True
break
if not _skip:
life.add_action(LIFE[SETTINGS['controlling']], {'action': 'rest'}, 200)
else:
logic.show_next_event()
if INPUT[' ']:
if SETTINGS['paused']:
SETTINGS['paused'] = False
gfx.refresh_view('map')
else:
SETTINGS['paused'] = True
gfx.refresh_view('map')
if INPUT['?']:
#gfx.screenshot()
if SETTINGS['recording']:
SETTINGS['recording'] = False
logging.info('Stopped recording')
else:
SETTINGS['recording'] = True
logging.info('Recording')
if INPUT['P']:
if SETTINGS['paused']:
SETTINGS['paused'] = False
else:
SETTINGS['paused'] = True
if INPUT['a']:
if menus.get_menu_by_name('Activate')>-1:
menus.delete_menu(menus.get_menu_by_name('Activate'))
return False
_items = []
for entry in life.get_fancy_inventory_menu_items(LIFE[SETTINGS['controlling']], show_containers=False, check_hands=True):
if not 'id' in entry:
continue
if 'ON_ACTIVATE' in ITEMS[entry['id']]['flags']:
_items.append(entry)
_nearby_items = []
for item_uid in LIFE[SETTINGS['controlling']]['seen_items']:
_item = ITEMS[item_uid]
if not 'ON_ACTIVATE' in ITEMS[item_uid]['flags']:
continue
if bad_numbers.distance(LIFE[SETTINGS['controlling']]['pos'], ITEMS[item_uid]['pos'])>1:
continue
_nearby_items.append(menus.create_item('single', _item['name'], None, icon=_item['icon'], id=item_uid))
if _nearby_items:
_items.append(menus.create_item('title', 'Nearby', None))
_items.extend(_nearby_items)
if not _items:
gfx.message('You have no items to activate.')
return False
_i = menus.create_menu(title='Activate',
menu=_items,
padding=(1,1),
position=(1,1),
format_str='[$i] $k: $v',
on_select=lambda entry: life.activate_item(LIFE[SETTINGS['controlling']], entry['id']),
close_on_select=True)
menus.activate_menu(_i)
if INPUT['A']:
if menus.get_menu_by_name('Eat')>-1:
menus.delete_menu(menus.get_menu_by_name('Eat'))
return False
_food = []
for _item in life.get_all_inventory_items(LIFE[SETTINGS['controlling']], matches=[{'type': 'food'}, {'type': 'drink'}, {'type': 'medicine'}]):
_food.append(menus.create_item('single',
items.get_name(_item),
None,
icon=_item['icon'],
id=_item['uid']))
if not _food:
gfx.message('You have nothing to eat.')
return False
_i = menus.create_menu(title='Eat',
menu=_food,
padding=(1,1),
position=(1,1),
format_str='[$i] $k',
on_select=inventory_eat)
menus.activate_menu(_i)
if INPUT['i']:
if menus.get_menu_by_name('Inventory')>-1:
menus.delete_menu(menus.get_menu_by_name('Inventory'))
return False
_inventory = life.get_fancy_inventory_menu_items(LIFE[SETTINGS['following']],check_hands=True)
if not _inventory:
gfx.message('You have no items.')
return False
_i = menus.create_menu(title='Inventory',
menu=_inventory,
padding=(1,1),
position=(1,1),
format_str='[$i] $k: $v',
on_select=inventory_select)
menus.activate_menu(_i)
if INPUT['e']:
if menus.get_menu_by_name('Equip')>-1:
menus.delete_menu(menus.get_menu_by_name('Equip'))
return False
_inventory = life.get_fancy_inventory_menu_items(LIFE[SETTINGS['controlling']],show_equipped=False,check_hands=False)
if not _inventory:
gfx.message('You have no items to equip.')
return False
_i = menus.create_menu(title='Equip',
menu=_inventory,
padding=(1,1),
position=(1,1),
format_str='[$i] $k',
on_select=inventory_select,
action='Equip')
menus.activate_menu(_i)
if INPUT['E']:
if menus.get_menu_by_name('Unequip')>-1:
menus.delete_menu(menus.get_menu_by_name('Equip'))
return False
_inventory = life.get_fancy_inventory_menu_items(LIFE[SETTINGS['controlling']],show_equipped=True,check_hands=True,show_containers=False)
if not _inventory:
gfx.message('You have no items to unequip.')
return False
_i = menus.create_menu(title='Unequip',
menu=_inventory,
padding=(1,1),
position=(1,1),
format_str='[$i] $k',
on_select=inventory_select,
action='Unequip')
menus.activate_menu(_i)
if INPUT['c']:
life.crouch(LIFE[SETTINGS['controlling']])
if INPUT['C']:
life.stand(LIFE[SETTINGS['controlling']])
if INPUT['d']:
if menus.get_menu_by_name('Drop')>-1:
menus.delete_menu(menus.get_menu_by_name('Drop'))
return False
_inventory = life.get_fancy_inventory_menu_items(LIFE[SETTINGS['controlling']], show_containers=True, check_hands=True)
if not _inventory:
gfx.message('You have no items to drop.')
return False
_i = menus.create_menu(title='Drop',
menu=_inventory,
padding=(1,1),
position=(1,1),
format_str='[$i] $k: $v',
on_select=inventory_select,
action='Drop')
menus.activate_menu(_i)
if INPUT['t']:
if not menus.get_menu_by_name('Arm')==-1:
return False
if menus.get_menu_by_name('Throw')>-1 and menus.get_menu_by_name('Arm')==-1:
menus.delete_menu(menus.get_menu_by_name('Throw'))
return False
if LIFE[SETTINGS['controlling']]['targeting']:
life.throw_item(LIFE[SETTINGS['controlling']], LIFE[SETTINGS['controlling']]['throwing'], LIFE[SETTINGS['controlling']]['targeting'])
LIFE[SETTINGS['controlling']]['targeting'] = None
SELECTED_TILES[0] = []
return True
_throwable = life.get_fancy_inventory_menu_items(LIFE[SETTINGS['controlling']], show_equipped=True, check_hands=True)
if not _throwable:
return False
_i = menus.create_menu(title='Throw',
menu=_throwable,
padding=(1,1),
position=(1,1),
format_str='[$i] $k: $v',
on_select=inventory_select,
action='Throw')
menus.activate_menu(_i)
if INPUT['T']:
if not ACTIVE_MENU['menu'] == -1:
return False
create_tracking_menu()
if INPUT['v']:
if menus.get_menu_by_name('Talk')>-1:
menus.delete_menu(menus.get_menu_by_name('Talk'))
return False
if not LIFE[SETTINGS['controlling']]['targeting']:
_menu_items = menus.create_target_list()
if not len(_menu_items)>1:
gfx.message('There\'s nobody to talk to.')
return False
_i = menus.create_menu(title='Talk to...',
menu=_menu_items,
padding=(1,1),
position=(1,1),
format_str='$k',
on_select=create_dialog,
on_close=exit_target,
on_move=target_view)
menus.activate_menu(_i)
return True
else:
_target = None
for entry in [LIFE[i] for i in LIFE]:
if entry['pos'] == LIFE[SETTINGS['controlling']]['targeting']:
_target = entry
break
if not _target:
gfx.message('There\'s nobody standing here!')
return False
if INPUT['V']:
if menus.get_menu_by_name('Radio')>-1:
menus.delete_menu(menus.get_menu_by_name('Radio'))
else:
return create_radio_menu()
if INPUT['m']:
if not ACTIVE_MENU['menu'] == -1:
return False
_player = LIFE[SETTINGS['controlling']]
_menu_items = []
for mission in _player['missions'].values():
if not mission['tasks']:
continue
_menu_items.append(menus.create_item('title', mission['name'], None))
for task_id in mission['tasks']:
_task = mission['tasks'][task_id]
if _task['completed']:
_completed = 'x'
else:
_completed = ' '
_menu_items.append(menus.create_item('single', _completed, _task['description'], enabled=_completed == ' '))
if not _menu_items:
gfx.message('You have no missions.')
return False
_i = menus.create_menu(title='Missions',
menu=_menu_items,
padding=(1,1),
position=(1,1),
format_str='[$k] $v')
menus.activate_menu(_i)
if INPUT['M']:
if menus.get_menu_by_name('Fight')>-1:
return False
_menu_items = menus.create_target_list()
if not _menu_items:
gfx.message('You have nothing to aim at!')
return False
_i = menus.create_menu(title='Fight',
menu=_menu_items,
padding=(1,1),
position=(1,1),
format_str='$k',
on_select=handle_advanced_movement,
on_close=exit_target,
on_move=target_view)
menus.activate_menu(_i)
if INPUT['f']:
if menus.get_menu_by_name('Select Limb')>-1:
return False
if menus.get_menu_by_name('Aim at...')>-1:
return False
if menus.get_menu_by_name('Fire')>-1:
menus.delete_menu(menus.get_menu_by_name('Fire'))
return False
if LIFE[SETTINGS['controlling']]['targeting']:
if menus.get_menu_by_name('Select Target')>-1:
return False
_alife_menu = []
for _life in life.get_all_life_at_position(life, LIFE[SETTINGS['controlling']]['targeting']):
_alife = LIFE[_life]
_alife_menu.append(menus.create_item('single',
'%s' % ' '.join(_alife['name']),
'Nearby',
target=_alife))
if len(_alife_menu)>=2:
_i = menus.create_menu(title='Select Target',
menu=_alife_menu,
padding=(1,1),
position=(1,1),
format_str='$k: $v',
on_select=inventory_fire_select_limb)
menus.activate_menu(_i)
elif _alife_menu:
inventory_fire_select_limb(_alife_menu[0], no_delete=True)
return True
_weapons = []
for hand in LIFE[SETTINGS['controlling']]['hands']:
_limb = life.get_limb(LIFE[SETTINGS['controlling']], hand)
if not _limb['holding']:
continue
_item = life.get_inventory_item(LIFE[SETTINGS['controlling']],_limb['holding'][0])
if _item['type'] == 'gun':
_weapons.append(menus.create_item('single',
_item['name'],
'(Range: temp)',
icon=_item['icon'],
id=_item['uid']))
if not _weapons:
gfx.message('You have nothing to shoot!')
return False
_i = menus.create_menu(title='Fire',
menu=_weapons,
padding=(1,1),
position=(1,1),
format_str='[$i] $k: $v',
on_select=inventory_fire)
#LIFE[SETTINGS['controlling']]['shoot_timer'] = LIFE[SETTINGS['controlling']]['shoot_timer_max']
menus.activate_menu(_i)
if INPUT['F']:
if menus.get_menu_by_name('Fire Rate')>-1:
return False
_weapons = life.get_held_items(LIFE[SETTINGS['controlling']], matches=[{'type': 'gun'}])
if not _weapons:
gfx.message('You aren\'t holding any weapons.')
return False
_menu = []
for _item in _weapons:
_weapon = ITEMS[_item]
_menu.append(menus.create_item('single',
_weapon['name'],
weapons.get_fire_mode(_weapon),
icon=_weapon['icon'],
item=_weapon['uid']))
_i = menus.create_menu(title='Fire Rate',
menu=_menu,
padding=(1,1),
position=(1,1),
format_str='[$i] $k: $v',
on_select=inventory_change_fire_rate)
menus.activate_menu(_i)
if INPUT['r']:
if menus.get_menu_by_name('Reload')>-1:
menus.delete_menu(menus.get_menu_by_name('Reload'))
return False
_menu = []
_loaded_weapons = []
_unloaded_weapons = []
_non_empty_ammo = []
_empty_ammo = []
for weapon in life.get_all_inventory_items(LIFE[SETTINGS['following']],matches=[{'type': 'gun'}]):
_feed_uid = weapons.get_feed(weapon)
if _feed_uid:
_feed = items.get_item_from_uid(_feed_uid)
_loaded_weapons.append(menus.create_item('single',
weapon['name'],
'%s/%s' % (len(_feed['rounds']),_feed['maxrounds']),
icon=weapon['icon'],
id=weapon['uid']))
else:
_unloaded_weapons.append(menus.create_item('single',
weapon['name'],
'Empty',
icon=weapon['icon'],
id=weapon['uid']))
for ammo in life.get_all_inventory_items(LIFE[SETTINGS['following']],matches=[{'type': 'magazine'},{'type': 'clip'}]):
#TODO: Make `parent` an actual key.
if 'parent' in ammo:
continue
if ammo['rounds']:
_non_empty_ammo.append(menus.create_item('single',
ammo['name'],
'%s/%s' % (len(ammo['rounds']),ammo['maxrounds']),
icon=ammo['icon'],
id=ammo['uid']))
else:
_empty_ammo.append(menus.create_item('single',
ammo['name'],
'%s/%s' % (len(ammo['rounds']),ammo['maxrounds']),
icon=ammo['icon'],
id=ammo['uid']))
if _loaded_weapons:
_menu.append(menus.create_item('title','Loaded weapons',None))
_menu.extend(_loaded_weapons)
#TODO: Disabled for now.
#if _unloaded_weapons:
# _menu.append(menus.create_item('title','Unloaded weapons',None))
# _menu.extend(_unloaded_weapons)
if _non_empty_ammo:
_menu.append(menus.create_item('title','Mags/Clips (Non-empty)',None))
_menu.extend(_non_empty_ammo)
if _empty_ammo:
_menu.append(menus.create_item('title','Mags/Clips (Empty)',None))
_menu.extend(_empty_ammo)
if not _menu:
gfx.message('You have no ammo!')
return False
_i = menus.create_menu(title='Reload',
menu=_menu,
padding=(1,1),
position=(1,1),
format_str='$k: $v',
on_select=inventory_reload)
menus.activate_menu(_i)
if INPUT['s']:
if LIFE[SETTINGS['controlling']]['strafing']:
LIFE[SETTINGS['controlling']]['strafing'] = False
print 'Not strafing'
else:
LIFE[SETTINGS['controlling']]['strafing'] = True
print 'Strafing'
if INPUT['S']:
#if not LIFE[SETTINGS['controlling']]['encounters']:
# return False
#SETTINGS['following'] = LIFE[SETTINGS['controlling']]['id']
#_target = LIFE[SETTINGS['controlling']]['encounters'].pop(0)['target']
#LIFE[SETTINGS['controlling']]['shoot_timer'] = 0
#speech.communicate(LIFE[SETTINGS['controlling']], 'surrender', matches=[{'id': _target['id']}])
#logging.debug('** SURRENDERING **')
if menus.get_menu_by_name('Stats')>-1:
menus.delete_menu(menus.get_menu_by_name('Stats'))
return False
_stats = []
_stats.append(menus.create_item('title', 'Stats', None))
_stats.append(menus.create_item('spacer', '=', None))
for key in LIFE[SETTINGS['controlling']]['stats']:
if key == 'description':
continue
_stats.append(menus.create_item('single', key.title(), LIFE[SETTINGS['controlling']]['stats'][key]))
_i = menus.create_menu(title='Options',
menu=_stats,
padding=(1,1),
position=(1,1),
format_str='$k: $v')
menus.activate_menu(_i)
if INPUT['j']:
if LIFE[SETTINGS['controlling']]['job']:
create_tasks_menu()
else:
create_jobs_menu()
#for key in LIFE[SETTINGS['controlling']]['job']:
# if key == 'description':
# continue
#
# _stats.append(menus.create_item('single', key.title(), LIFE[SETTINGS['controlling']]['stats'][key]))
if INPUT['w']:
if menus.get_menu_by_name('Wounds')>-1:
menus.delete_menu(menus.get_menu_by_name('Wounds'))
else:
create_wound_menu(SETTINGS['controlling'])
if INPUT['W']:
if menus.get_menu_by_name('Heal')>-1:
menus.delete_menu(menus.get_menu_by_name('Heal'))
return False
_pos = LIFE[SETTINGS['controlling']]['pos']
_items = []
#Sue me.
for life_id in LIFE[SETTINGS['controlling']]['seen']:
if bad_numbers.distance(LIFE[SETTINGS['controlling']]['pos'], LIFE[life_id]['pos'])>1:
continue
_items.append(menus.create_item('single', ' '.join(LIFE[life_id]['name']), None, target=life_id))
if not _items:
gfx.message('There\'s nobody to heal nearby.')
return False
_i = menus.create_menu(title='Heal',
menu=_items,
padding=(1,1),
position=(1,1),
format_str='$k',
on_select=create_target_wound_menu)
menus.activate_menu(_i)
if INPUT['O']:
if menus.get_menu_by_name('Debug (Developer)')>-1:
menus.delete_menu(menus.get_menu_by_name('Debug (Developer)'))
return False
_online_alife = len([l['id'] for l in LIFE.values() if l['online'] and not l['dead'] and l['think_rate_max']<30])
_online_alife_in_passive = len([l['id'] for l in LIFE.values() if l['online'] and not l['dead'] and l['think_rate_max']>=30])
_offline_alife = len([l['id'] for l in LIFE.values() if not l['online'] and not l['dead']])
_options = []
_options.append(menus.create_item('title', 'Testing', None))
_options.append(menus.create_item('list', 'Show camp ownership', str(len(WORLD_INFO['camps']))))
_options.append(menus.create_item('list', 'Drop cache', 'Create cache drop'))
_options.append(menus.create_item('list', 'Show visible chunks', ['off', 'on']))
_options.append(menus.create_item('title', 'Map Operations', None))
_options.append(menus.create_item('single', 'Save', 'Offload game to disk'))
_options.append(menus.create_item('single', 'Load', 'Load game from disk'))
_options.append(menus.create_item('single', 'Reload map', 'Reloads map from disk'))
_options.append(menus.create_item('single', 'Update chunk map', 'Generates chunk map'))
_options.append(menus.create_item('title', 'World Info', None))
_options.append(menus.create_item('single', 'ALife (%s)' % len(LIFE), 'Online: %s (%s), Offline: %s' % (_online_alife, _online_alife_in_passive, _offline_alife)))
_options.append(menus.create_item('single', 'ALife memories', sum([len(l['memory']) for l in LIFE.values() if not l['dead']])))
_options.append(menus.create_item('single', 'Groups', len(WORLD_INFO['groups'])))
_options.append(menus.create_item('single', 'Seed', WORLD_INFO['seed']))
_i = menus.create_menu(title='Debug (Developer)',
menu=_options,
padding=(1,1),
position=(1,1),
format_str='$k: $v',
on_select=handle_options_menu,
on_change=handle_options_menu_change)
menus.activate_menu(_i)
if INPUT['z']:
life.pass_out(LIFE[SETTINGS['controlling']], length=500)
if INPUT['Z']:
life.crawl(LIFE[SETTINGS['controlling']])
if INPUT[',']:
_items = items.get_items_at(LIFE[SETTINGS['controlling']]['pos'], check_bodies=True)
if not _items:
gfx.message('There is nothing here to pick up.')
return False
if menus.get_menu_by_name('Pick up')>-1:
menus.delete_menu(menus.get_menu_by_name('Pick up'))
return False
create_pick_up_item_menu(_items)
if INPUT['o']:
_pos = LIFE[SETTINGS['controlling']]['pos']
_items = []
for pos in [(-1, 0), (1, 0), (0, -1), (0, 1), (-1, -1), (1, -1), (-1, 1), (1, 1), (0, 0)]:
__pos = (_pos[0]+pos[0], _pos[1]+pos[1], _pos[2])
_items.extend(items.get_items_at(__pos))
#Sue me again.
for life_id in LIFE[SETTINGS['controlling']]['seen']:
if bad_numbers.distance(LIFE[SETTINGS['controlling']]['pos'], LIFE[life_id]['pos'])>1:
continue
for item_uid in life.get_all_equipped_items(LIFE[life_id]):
if 'capacity' in ITEMS[item_uid]:
_items.append(ITEMS[item_uid])
if menus.get_menu_by_name('Pick up')>-1:
menus.delete_menu(menus.get_menu_by_name('Pick up'))
return False
if not _items:
gfx.message('There\'s nothing to pick up.')
return False
create_open_item_menu(_items)
if INPUT['b']:
if WORLD_INFO['time_scale'] == 12:
WORLD_INFO['time_scale'] = 1
else:
WORLD_INFO['time_scale'] = 12
if INPUT['n']:
import pathfinding
for pos in pathfinding.create_path(LIFE[SETTINGS['controlling']],
LIFE[SETTINGS['controlling']]['pos'],
(LIFE[SETTINGS['controlling']]['pos'][0]-5,
LIFE[SETTINGS['controlling']]['pos'][1]-5,
LIFE[SETTINGS['controlling']]['pos'][2]-5),
[zones.get_zone_at_coords(LIFE[SETTINGS['controlling']]['pos'])]):
print pos
SELECTED_TILES[0].append((pos[0], pos[1], 2))
#if INPUT['N']:
# if not SETTINGS['kill threads']:
# logging.debug('Killing threads...')
#
# SETTINGS['kill threads'] = True
if INPUT['y']:
_id = int(SETTINGS['following'])
while _id>1:
_id -= 1
if not LIFE[str(_id)]['dead']:
break
life.focus_on(LIFE[str(_id)])
SELECTED_TILES[0] = []
FADE_TO_WHITE[0] = 0
gfx.refresh_view('map')
if INPUT['u']:
_id = int(SETTINGS['following'])
while _id<len(LIFE):
_id += 1
if not LIFE[str(_id)]['dead']:
break
life.focus_on(LIFE[str(_id)])
SELECTED_TILES[0] = []
FADE_TO_WHITE[0] = 0
gfx.refresh_view('map')
if INPUT['l']:
create_look_list()
if INPUT['k']:
if menus.get_menu_by_name('Crafting')>-1:
menus.delete_menu(menus.get_menu_by_name('Crafting'))
else:
create_crafting_menu()
if INPUT['1']:
if LIFE[SETTINGS['controlling']]:
if LIFE[SETTINGS['controlling']]['targeting']:
LIFE[SETTINGS['controlling']]['targeting'][0]-=1
LIFE[SETTINGS['controlling']]['targeting'][1]+=1
else:
life.clear_actions(LIFE[SETTINGS['controlling']])
life.add_action(LIFE[SETTINGS['controlling']],
{'action': 'move',
'to': (LIFE[SETTINGS['controlling']]['pos'][0]-1, LIFE[SETTINGS['controlling']]['pos'][1]+1, LIFE[SETTINGS['controlling']]['pos'][2])},
200)
else:
CAMERA_POS[2] = 1
if INPUT['2']:
if not LIFE[SETTINGS['controlling']]:
CAMERA_POS[2] = 2
if INPUT['3']:
if LIFE[SETTINGS['controlling']]:
if LIFE[SETTINGS['controlling']]['targeting']:
LIFE[SETTINGS['controlling']]['targeting'][0]+=1
LIFE[SETTINGS['controlling']]['targeting'][1]+=1
else:
life.clear_actions(LIFE[SETTINGS['controlling']])
life.add_action(LIFE[SETTINGS['controlling']],
{'action': 'move',
'to': (LIFE[SETTINGS['controlling']]['pos'][0]+1, LIFE[SETTINGS['controlling']]['pos'][1]+1, LIFE[SETTINGS['controlling']]['pos'][2])},
200)
else:
CAMERA_POS[2] = 3
if INPUT['4']:
if not LIFE[SETTINGS['controlling']]:
CAMERA_POS[2] = 4
if INPUT['5']:
if not LIFE[SETTINGS['controlling']]:
CAMERA_POS[2] = 5
if INPUT['7']:
if LIFE[SETTINGS['controlling']]:
if LIFE[SETTINGS['controlling']]['targeting']:
LIFE[SETTINGS['controlling']]['targeting'][0]-=1
LIFE[SETTINGS['controlling']]['targeting'][1]-=1
else:
life.clear_actions(LIFE[SETTINGS['controlling']])
life.add_action(LIFE[SETTINGS['controlling']],
{'action': 'move',
'to': (LIFE[SETTINGS['controlling']]['pos'][0]-1, LIFE[SETTINGS['controlling']]['pos'][1]-1, LIFE[SETTINGS['controlling']]['pos'][2])},
200)
if INPUT['9']:
if LIFE[SETTINGS['controlling']]:
if LIFE[SETTINGS['controlling']]['targeting']:
LIFE[SETTINGS['controlling']]['targeting'][0]+=1
LIFE[SETTINGS['controlling']]['targeting'][1]-=1
else:
life.clear_actions(LIFE[SETTINGS['controlling']])
life.add_action(LIFE[SETTINGS['controlling']],
{'action': 'move',
'to': (LIFE[SETTINGS['controlling']]['pos'][0]+1, LIFE[SETTINGS['controlling']]['pos'][1]-1, LIFE[SETTINGS['controlling']]['pos'][2])},
200)
def inventory_select(entry):
key = entry['key']
value = entry['values'][entry['value']]
_item_uid = entry['id']
_item = life.get_inventory_item(LIFE[SETTINGS['following']], _item_uid)
_menu_items = []
if 'storing' in _item and not 'is_item' in entry:
_stored_items = life.get_custom_fancy_inventory_menu_items(LIFE[SETTINGS['following']], _item['storing'])
_i = menus.create_menu(title=items.get_name(_item),
menu=_stored_items,
padding=(1,1),
position=(1,1),
format_str='[$i] $k',
on_select=inventory_select,
action=MENUS[ACTIVE_MENU['menu']]['action'])
menus.activate_menu(_i)
else:
handle_inventory_item_select(entry)
def handle_inventory_item_select(entry):
_item_uid = entry['id']
_item = life.get_inventory_item(LIFE[SETTINGS['controlling']], _item_uid)
_menu_items = []
if MENUS[ACTIVE_MENU['menu']]['action']:
entry['key'] = MENUS[ACTIVE_MENU['menu']]['action']
return handle_inventory_item_select_action(entry)
if life.item_is_equipped(LIFE[SETTINGS['controlling']], _item_uid):
_menu_items.append(menus.create_item('single',
'Unequip',
None,
id=_item_uid))
else:
_menu_items.append(menus.create_item('single',
'Equip',
None,
id=_item_uid))
_menu_items.append(menus.create_item('single',
'Drop',
None,
id=_item_uid))
_menu_items.append(menus.create_item('single',
'Throw',
None,
id=_item_uid))
_i = menus.create_menu(title='Action',
menu=_menu_items,
padding=(1,1),
position=(1,1),
format_str='$k',
on_select=handle_inventory_item_select_action)
menus.activate_menu(_i)
def handle_inventory_item_select_action(entry):
key = entry['key']
value = entry['values'][entry['value']]
_item_uid = entry['id']
_item = life.get_inventory_item(LIFE[SETTINGS['controlling']], _item_uid)