-
Notifications
You must be signed in to change notification settings - Fork 21
/
classes.rpy
3500 lines (3017 loc) · 155 KB
/
classes.rpy
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
## This file declares all the classes in the battle engine
# 1) battle manager class
# 2) custom displayables
# 3) Action objects (these gets activated when you click a button) [[DEFUNCT]]
# 4) battleship blueprint class
# 5) Weapon blueprint classes
# 6) library (specific ships/weapons) [[MOVED]]
# 7) planet class
# 8) bonus stuff
# 9) actions
init -2 python:
import pygame
##here the Battle class gets defined. it forms the core and spine of the entire combat engine.
##it gets initialized into an instance called BM, short for battlemanager
class Battle(store.object): # handles managing a list of all battle units, handles turns and manages enemy AI
def __init__(self):
#when the first instance gets created a couple of default values get initialized.
self.cmd = 0 #your command point total
self.money = 0 #go on, set this to 999'999'999. you know you want to.
self.seen_skirmish = False #if not seen skirmish before Ava explains it.
self.save_version = config.version
self.ships = [] #holds all ships to display on the map
self.covers = [] #holds a list of all the cover on the map
self.enemy_vanguard_path = []#stores the hexes that the enemy's vanguard will go through.
self.player_vanguard_path = []#stores the hexes that the player's vanguard will go through (only used by AI).
self.missiles = [] #all the missiles on screen. right now all missiles are fired one by one
self.selected = None #current selection
self.hovered = None #what unit are you hovering over
self.target = None #the current target of whatever attack is going on
self.selectedmode = False #this makes the move target buttons appear
self.targetingmode = False#keeps chance to hit target windows on screen etc
self.moving = False #set to true when a ship is moving from point a to b
self.just_moved = False #when True the button to take back your last movement is shown
self.missile_moving = False #tells the battle screen a missile is moving from a to b
self.phase = 'Player' #keeps track of who's turn it is
self.weaponhover = None #the weapon you are hovering over. used for chance to hit target window and tooltips
self.active_weapon = None #similar to weaponhover, but is used after you actually click a weapon so you can target something
self.mission = 1 #what mission are we on? decides where to loop and is important for in battle events
self.turn_count = 1 #most important when calculating command points awarded
self.grid = [] #keep track of what cells in the grid are free and which are not.
self.vanguard = False #when True the battlemap shows the vanguard cannon being fired.
self.active_strategy = [None,0] #you can have either 'full forward' or 'all guard' active, but not both.
self.vanguardtarget = False #When True the player can select a target for the VC cannon
self.warping = False #used by the short range warp order. it makes an outline of the selected ship show at the mouse cursor
self.targetwarp = False #used by the short ranged warp order. it creates buttons on the tiles
self.showing_orders = False #This is True when the list of orders is visible.
self.show_tooltips = True #hide or show tooltips
self.debugoverlay = False #overlay coords etc for debug purposes
self.show_grid = True #show or hide the grid. no grid is much faster!
self.formation_range = 6 #the farthest column the player can place units during the formation phase
self.mercenary_count = 0 #the number of mercenaries in service to the Sunrider. [no longer used]
self.remove_mode = False #when True the player can easily remove units in skirmish
self.player_ai = False
self.battlestart = store.object()
self.end_turn_callbacks = []
self.lowest_difficulty = 3 #lowest recorded difficulty. bragging rights!
self.lead_ships = []
self.mouse_location = (0,0)
self.vanguard_damage = 800
self.vanguard_range = 6
self.orders = {
'FULL FORWARD':[750,'full_forward'],
'ALL GUARD':[750,'all_guard'],
'REPAIR DRONES':[750,'repair_drones'],
'VANGUARD CANNON':[2500,'vanguard_cannon']
}
self.order_used = False #when True the orders button is hidden.
#environment modifiers are initialized here and can be changed later
self.environment = {
'accuracy':100,
'turndamage':0,
'damage':0,
'energyregen':0,
}
self.battlemode = False #True during battle. when set to False the battle loop will end.
self.stopAI = False #when set to True all AI action is disabled.
self.edgescroll = (0,0)
self.xadj = ui.adjustment() #used by the viewport in the battlescreen
self.yadj = ui.adjustment()
#when True you can drag the main viewport (the battle map with the grid) around. this needs to be
#disabled when text is showing on screen otherwise mouseclicks get eaten by the viewport and do not advance text
#DEFUNCT!
self.draggable = True
self.debug_log = []
#Battle log
self.show_battle_log = False
self.battle_log = []
self.battle_log_yadj = ui.adjustment(adjustable=True)
#dispatchers
self.skirmish_dispatcher = { 'start' : self.skirmish_start,
'quit' : self.skirmish_quit,
'remove' : self.skirmish_remove,
'playermusic' : self.skirmish_playermusic,
'enemymusic' : self.skirmish_enemymusic,
"zoom" : self.common_zoom,
"next ship" : self.common_next_ship,
"deselect" : self.common_deselect,
"selection" : self.skirmish_selection,
"warptarget" : self.skirmish_warptarget }
self.formation_dispatcher = { "start" : self.formation_start,
"zoom" : self.common_zoom,
"next ship" : self.common_next_ship,
"deselect" : self.common_deselect,
"selection" : self.formation_selection,
"warptarget" : self.formation_warptarget }
self.battle_dispatcher = { "anime" : self.battle_anime,
"cheat" : self.battle_cheat,
"I WIN" : self.battle_inst_win,
"deselect" : self.battle_deselect,
"next ship" : self.battle_next_ship,
"previous ship" : self.battle_previous_ship,
"zoom" : self.battle_zoom,
"selection" : self.battle_selection,
"move" : self.battle_move,
"cancel movement" : self.battle_cancel_movement,
"RESURRECTION" : self.battle_order_resurrection,
"ALL GUARD" : self.battle_order_all_guard,
"FULL FORWARD" : self.battle_order_full_forward,
"REPAIR DRONES" : self.battle_order_repair_drones,
"SHORT RANGE WARP" : self.battle_short_range_warp,
"RETREAT" : self.battle_retreat,
"VANGUARD CANNON" : self.battle_order_vanguard_cannon,
"toggle player ai" : self.toggle_player_ai,
"endturn" : self.battle_end_turn }
#stores a matrix of the grid to keep track of what spots are free. False is free, True is occupied
for a in range(GRID_SIZE[0]):
self.grid.append([False]*GRID_SIZE[1])
self.battle_bg = "Background/space{!s}.jpg".format(renpy.random.randint(1,9))
self.result = None #store result of ui.interact()
#here we start defining a few methods which part of the battlemanager
## insert entry to battle log
# @param type The list of tags
# @param message The formatted string
# @param position Determines position of log entry
def battle_log_insert(self, type, message, position = None):
entry = [type, message]
#zero is not supposed to be
if position:
self.battle_log.insert(position, entry)
else:
self.battle_log.append(entry)
self.battle_log_yadj.change(self.battle_log_yadj.value + 125)
#trimming, in case this list can lead to or contribute to memory leaks.
def battle_log_trimm(self):
if len(self.battle_log) > 500:
start = len(self.battle_log) - 500
self.battle_log = self.battle_log[start:]
self.battle_log_yadj.change(self.battle_log_yadj.value - (125 * start))
## pop entry from battle log
# @param index The index of entry to remove
def battle_log_pop(self, index = None):
if index is None:
self.battle_log.pop()
else:
self.battle_log.pop(index)
self.battle_log_yadj.change(self.battle_log_yadj.value - 125)
def select_ship(self,ship,play_voice = True):
self.selected = ship
if ship.faction == 'Player' and play_voice:
a = renpy.random.randint(0,len(ship.selection_voice)-1)
renpy.music.play('sound/Voice/{}'.format(ship.selection_voice[a]),channel = ship.voice_channel)
del a
if self.mission != 'skirmish' and BM.phase != 'formation':
renpy.show_screen('commands')
ship.movement_tiles = get_movement_tiles(ship)
self.selectedmode = True
def unselect_ship(self,ship):
renpy.hide_screen('commands')
self.selectedmode = False
self.selected = None
self.targetingmode = False
if ship != None:
ship.movement_tiles = []
def dispatch_handler(self, result, dispatch_type = 'battle'):
ui_action = None
#check handling of dispatcher
if result is None: return self.common_none
elif isinstance(result, bool): return self.common_bool
elif isinstance(result, list):
disp_type = dispatch_type + "_dispatcher"
ui_action = getattr(self, disp_type).get(result[0], self.common_unexpected)
else:
disp_type = dispatch_type + "_dispatcher"
ui_action = getattr(self, disp_type).get(result, self.common_unexpected)
return ui_action
########################################################
## Common dispatcher
########################################################
def common_unexpected(self):
if isinstance(self.result, list):
self.debug_log.append("Unexpected dispatcher key: " + str(self.result[0]))
else:
self.debug_log.append("Unexpected dispatcher key: " + self.result)
def common_none(self):
pass
def common_bool(self):
pass
def common_zoom(self):
zoom_handling(self.result, self)
def common_next_ship(self):
templist = []
for ship in player_ships:
if ship.location == None:
templist.append(ship)
if self.selected == None:
if len(templist) > 0:
self.select_ship(templist[0])
else:
if self.selected.location != None:
set_cell_available(self.selected.location)
if self.selected in templist:
index = templist.index(self.selected)
else:
index = 0
if index == (len(templist)-1):
index = 0
else:
index += 1
self.select_ship(templist[index])
if self.selected != None:
self.targetwarp = True
renpy.show_screen('mousefollow')
def common_deselect(self):
#if you picked up an enemy unit that was already put down right clicking should delete it entirely
#player ships automatically return to the blue pool to be placed again later.
if self.selected != None:
if self.selected in enemy_ships:
self.ships.remove(self.selected)
enemy_ships.remove(self.selected)
self.targetwarp = False
renpy.hide_screen('mousefollow')
self.unselect_ship(self.selected)
########################################################
## Common dispatcher end
########################################################
#------------------------------------------------------#
########################################################
## Skirmish dispatcher
########################################################
#similar to formation. Should be merged?
def skirmish_start(self):
if len(enemy_ships) == 0:
show_message('Please add at least 1 enemy ship')
renpy.jump('mission_skirmish')
player_ship_present = False
for ship in player_ships:
if ship.location != None:
player_ship_present = True
if not player_ship_present:
show_message('Please add at least 1 player ship')
renpy.jump('mission_skirmish')
renpy.hide_screen('player_unit_pool_collapsed')
renpy.hide_screen('enemy_unit_pool_collapsed')
renpy.hide_screen('player_unit_pool')
renpy.hide_screen('enemy_unit_pool')
renpy.hide_screen('mousefollow')
renpy.hide_screen('battle_screen')
renpy.hide_screen('store_union') #seems like it has trouble staying closed?
self.battlemode = False
def skirmish_quit(self):
renpy.hide_screen('store_union') #seems like it has trouble staying closed?
renpy.hide_screen('player_unit_pool_collapsed')
renpy.hide_screen('enemy_unit_pool_collapsed')
renpy.hide_screen('player_unit_pool')
renpy.hide_screen('enemy_unit_pool')
renpy.hide_screen('mousefollow')
renpy.hide_screen('battle_screen')
BM.cmd = store.tempcmd
BM.money = store.tempmoney
BM.mission = None
store.player_ships = store.player_ships_original
store.sunrider = store.original_sunrider
BM.mission = None
BM.ships = []
for pship in player_ships:
BM.ships.append(pship)
clean_battle_exit()
renpy.jump('dispatch')
def skirmish_remove(self):
if self.remove_mode:
self.remove_mode = False
else:
self.remove_mode = True
def skirmish_playermusic(self):
store.PlayerTurnMusic = self.result[1]
show_message('Player music was changed')
def skirmish_enemymusic(self):
store.EnemyTurnMusic = self.result[1]
show_message('Enemy music was changed')
def skirmish_selection(self):
# this result can be from one of the imagebuttons in the pool screens or returned from
# MouseTracker because a hex with a unit in it was clicked.
selected_ship = self.result[1]
# BM.selected = selected_ship
if self.remove_mode:
if selected_ship.location != None:
if selected_ship.faction != 'Player':
if selected_ship in enemy_ships:
self.ships.remove(selected_ship)
enemy_ships.remove(selected_ship)
set_cell_available(selected_ship.location)
else:
set_cell_available(selected_ship.location)
selected_ship.location = None
else: #normal mode
self.targetwarp = True
renpy.show_screen('mousefollow')
if selected_ship.faction == 'Player':
self.select_ship(selected_ship)
else:
if selected_ship.location != None:
self.select_ship(selected_ship)
if selected_ship in enemy_ships:
self.ships.remove(self.selected)
enemy_ships.remove(self.selected)
else:
self.selected = deepcopy(selected_ship) #breaks alias
self.selected.weapons = self.selected.default_weapon_list
if self.selected != None:
if self.selected.location != None:
set_cell_available(self.selected.location)
self.selected.location = None
def skirmish_warptarget(self):
# returned from MouseTracker if you click on an empty hex when BM.warptarget == True.
if self.selected != None:
new_location = self.result[1]
set_cell_available(new_location,True)
if self.selected.faction != 'Player':
enemy_ships.append(self.selected)
self.ships.append(self.selected)
self.selected.location = new_location
if self.selected.faction != 'Player' and pygame.key.get_mods() != 0:
self.selected = deepcopy(self.selected) #breaks alias
else:
self.targetwarp = False
renpy.hide_screen('mousefollow')
self.unselect_ship(self.selected)
sort_ship_list()
########################################################
## Skirmish dispatcher end
########################################################
def skirmish_phase(self):
self.result = ui.interact()
self.dispatch_handler(self.result, 'skirmish')()
#------------------------------------------------------#
########################################################
## Formation dispatcher
########################################################
def formation_start(self):
#check if there are still player units that are not placed
unplaced_units = False
for ship in player_ships:
if ship.location == None:
unplaced_units = True
if unplaced_units:
show_message('there are still ships you have not placed!')
else:
renpy.hide_screen('player_unit_pool_collapsed')
renpy.hide_screen('enemy_unit_pool_collapsed')
renpy.hide_screen('player_unit_pool')
renpy.hide_screen('enemy_unit_pool')
renpy.hide_screen('mousefollow')
self.phase = 'Player'
renpy.jump('mission{}'.format(self.mission))
def formation_selection(self):
# this result can be from one of the imagebuttons in the pool screens or returned from
# MouseTracker because a hex with a unit in it was clicked.
selected_ship = self.result[1]
if selected_ship.faction == 'Player':
self.targetwarp = True
renpy.show_screen('mousefollow')
self.select_ship(selected_ship)
if self.selected.location != None:
set_cell_available(self.selected.location)
self.selected.location = None
def formation_warptarget(self):
# returned from MouseTracker if you click on an empty hex when self.warptarget == True.
if self.selected != None:
new_location = self.result[1]
#when setting up before a mission you can't put your ships farther to the right than column 7
if new_location[0] > self.formation_range:
show_message('too far infield')
else:
set_cell_available(new_location,True) #passing True actually sets it unavailable
if self.selected.faction != 'Player':
enemy_ships.append(self.selected)
self.ships.append(self.selected)
self.selected.location = new_location
if self.selected.faction != 'Player' and pygame.key.get_mods() != 0:
self.selected = deepcopy(self.selected) #breaks alias
else:
self.targetwarp = False
renpy.hide_screen('mousefollow')
self.unselect_ship(self.selected)
########################################################
## Formation dispatcher end
########################################################
def formation_phase(self):
self.phase='formation'
while True:
self.result = ui.interact()
self.dispatch_handler(self.result,'formation')()
if self.battlemode == False: #whenever this is set to False battle ends.
break
#------------------------------------------------------#
########################################################
## Battle dispatcher
########################################################
def battle_anime(self):
if not hasattr(store,'damage'):
store.damage = 50
if not hasattr(self,'attacker'):
self.attacker = sunrider
if not hasattr(store,'hit_count'):
store.hit_count = 1
if not hasattr(store,'total_armor_negation'):
store.total_armor_negation = 10
if not hasattr(store,'total_shield_negation'):
store.total_shield_negation = 10
if not hasattr(store,'total_flak_interception'):
store.total_flak_interception = 0
if self.target == None:
self.target = sunrider
try:
renpy.call_in_new_context('atkanim_legion_missile')
except:
show_message('animation label does not exist!')
def battle_cheat(self):
self.cmd = 99999
for ship in player_ships:
ship.set_stat('en',9999)
def battle_inst_win(self):
instant_win()
def battle_deselect(self):
if self.active_weapon != None:
self.active_weapon = None
self.targetingmode = False
self.weaponhover = None
elif self.selected != None:
self.unselect_ship(self.selected)
else:
pass
def battle_next_ship(self):
if self.selected == None or not BM.selected in player_ships: #rollback can screw with the identity of BM.selected
self.select_ship(sunrider)
return
if self.selected != None and len(player_ships) > 1:
if self.selected.faction == 'Player':
index = player_ships.index(self.selected)
looping = True
while looping:
if index == (len(player_ships)-1):
index = 0
else:
index += 1
if player_ships[index].location != None:
looping = False
self.select_ship(player_ships[index])
def battle_previous_ship(self):
if self.selected != None and len(player_ships) > 1:
if self.selected.faction == 'Player':
index = player_ships.index(self.selected)
looping = True
while looping:
if index == 0:
index = len(player_ships)-1
else:
index -= 1
if player_ships[index].location != None:
looping = False
self.select_ship(player_ships[index])
#def battle_mousefollow_click(self):
# pass
def battle_zoom(self):
zoom_handling(self.result,self) #see funtion.rpy how this is handled. it took a LONG time to get it to a point I am happy with
if self.selectedmode: self.selected.movement_tiles = get_movement_tiles(self.selected)
def battle_selection(self):
# if self.result == None:
# return
self.target = self.result[1]
self.hovered = None
#if no ship is currently selected select the ship that was just clicked on.
if self.selected == None:
self.select_ship(self.target)
return
#you do not have a weapon active.
if not self.targetingmode:
#did you select the active ship?
if self.target == self.selected:
self.unselect_ship(self.selected)
else:
self.select_ship(self.target)
return
#you do have a weapon active.
else:
weapon = self.active_weapon
#is this a valid target?
if weapon.wtype == 'Melee':
if get_ship_distance(self.selected,self.target) > 1 or self.target.stype != 'Ryder':
return
self.targetingmode = False
#did you click the currently selected ship?
if self.target == self.selected:
if weapon.wtype == 'Support':
pass #you clicked your selected ship with a support weapon active. do not end the method.
else:
self.unselect_ship(self.result[1])
return #do end the method. this is important.
#did you click an ally?
elif self.target.faction == 'Player':
if weapon.wtype == 'Support' or weapon.wtype == 'Special':
if self.target.cth <= 0:
self.draggable = False
renpy.say('',"The target is out of range, captain!")
self.draggable = True
self.targetingmode = True #try again
return #do end the method, this is important.
else:
#you clicked an ally unit with a support weapon active. do not end the method.
pass
else:
self.select_ship(self.target)
return
#you clicked an enemy with an active weapon.
else:
#check if you can hit the target. if not, let the player know he's stupid.
if self.target.cth <= 0:
self.draggable = False
renpy.say('Ava','It\'s hopeless, captain!')
self.draggable = True
return #do end the method, this is important.
else:
self.attacker = self.selected
if self.active_weapon.wtype == 'Curse' or self.active_weapon.wtype == 'Special':
weapon.fire(self.selected,self.target)
self.active_weapon = None
self.weaponhover = None
if self.selected != None:
self.selected.movement_tiles = get_movement_tiles(self.selected)
return
if self.active_weapon.wtype == 'Melee':
pass #do not show the atkanim, because there aren't any for melee.
else:
try:
animation_name = self.active_weapon.wtype.lower()
if weapon.animation_name != None:
animation_name = weapon.animation_name
renpy.call_in_new_context('atkanim_{}_{}'.format(self.selected.animation_name,animation_name))
except:
show_message('missing animation. "atkanim_{}_{}" does\'t seem to exist'.format(self.selected.animation_name,self.active_weapon.wtype.lower()))
#up till now nothing ended the method meaning it's okay to fire the weapon at the target - be it support or not.
result = weapon.fire(self.selected,self.target)
self.target.receive_damage(result,self.selected,weapon.wtype)
if self.selected != None:
self.selected.movement_tiles = get_movement_tiles(self.selected)
# update_stats() - updated in receive_damage()
self.active_weapon = None
self.weaponhover = None
# renpy.hide_screen('battle_screen')
# renpy.show_screen('battle_screen')
return #battle_selection end
def battle_move(self): #this means you clicked on one of the blue squares indicating you want to move somewhere
self.selected.move_ship(self.result[1],self) #result[1] is the new location to move towards
update_stats()
def battle_cancel_movement(self):
#expect that any actions will remove cancel button
self.battle_log_pop()
ship = self.selected
ship.en += get_distance(ship.location,ship.current_location)*ship.get_stat('move_cost')
a = ship.location[0]-1 #make the next line of code a little shorter
b = ship.location[1]-1
self.grid[a][b] = False #tell the BM that the old cell is now free again
ship.location = ship.current_location
a = ship.location[0]-1 #make the next line of code a little shorter
b = ship.location[1]-1
self.grid[a][b] = True #tell the BM that the old cell is now free again
ship.movement_tiles = get_movement_tiles(ship)
def battle_order_resurrection(self):
if self.cmd >= self.orders[self.result[0]][0]:
self.cmd -= self.orders[self.result[0]][0]
renpy.show_screen('ryderlist')
result = ui.interact()
if result[0] == 'deselect':
self.cmd += self.orders['RESURRECTION'][0]
renpy.hide_screen('ryderlist')
self.order_used = False
return
elif result[0] == 'selection':
revived_ship = result[1]
renpy.hide_screen('ryderlist')
launch_location = get_free_spot_near(sunrider.location) #so useful
revived_ship.set_stat('en',0)
revived_ship.set_stat('hp',revived_ship.get_stat('max_hp'))
destroyed_ships.remove(revived_ship)
player_ships.append(revived_ship)
self.ships.append(revived_ship)
revived_ship.location = launch_location
set_cell_available(launch_location, True) #the optional True actually lets me set this cell /un/available
message = "ORDER: {0} is resurrected".format(revived_ship.name)
self.battle_log_insert(['order'], message)
BM.order_used = True
#Phoenix rising from the ashes!
if revived_ship.name == 'Phoenix':
revived_ship.set_stat('en',revived_ship.get_stat('max_en') / 2)
#wipe all modifiers after a res
# for modifier in revived_ship.modifiers:
# revived_ship.modifiers[modifier] = [0,0]
revived_ship.buffs = []
#play the resurrect voice
if hasattr(revived_ship,'resurrect_voice'):
if len(revived_ship.resurrect_voice) > 0:
renpy.music.play( 'sound/Voice/'+renpy.random.choice(revived_ship.resurrect_voice),channel=revived_ship.voice_channel )
else:
self.order_used = False
def battle_order_all_guard(self):
if self.cmd >= self.orders[self.result[0]][0]:
self.cmd -= self.orders[self.result[0]][0]
strategy,remaining_turns = self.active_strategy
if strategy == 'full forward':
show_message("Full Forward order cancelled!")
for ship in player_ships:
ship.remove_buff('Full Forward')
if strategy == "all guard" and remaining_turns == 5:
show_message('already active!')
self.order_used = False
self.cmd += self.orders[self.result[0]][0]
#actually process the buffs
self.active_strategy = ['all guard',5]
for ship in player_ships:
ship.set_buff(AllGuard)
#bookkeeping
self.battle_log_insert(['order'], "ORDER: ALL GUARD")
BM.order_used = True
store.show_message('all ships gained improved flak, shielding and evasion!')
#play a voice
random_ship = renpy.random.choice( get_player_ships_in_battle() )
random_voice = renpy.random.choice(random_ship.buffed_voice)
renpy.music.play('sound/Voice/{}'.format(random_voice),channel = random_ship.voice_channel)
#animation
for ship in player_ships:
ship.getting_buff = True
renpy.hide_screen('battle_screen')
renpy.show_screen('battle_screen')
renpy.pause(1)
for ship in player_ships:
ship.getting_buff = False
renpy.hide_screen('battle_screen')
renpy.show_screen('battle_screen')
update_stats()
else:
renpy.music.play('sound/Voice/Ava/Ava Others 9.ogg',channel='avavoice')
self.order_used = False
def battle_order_full_forward(self):
if self.cmd >= self.orders[self.result[0]][0]:
self.cmd -= self.orders[self.result[0]][0]
strategy,remaining_turns = self.active_strategy
if strategy == 'all guard':
show_message("All Guard order cancelled!")
for ship in player_ships:
ship.remove_buff('All Guard')
if strategy == "full forward" and remaining_turns == 5:
show_message('already active!')
self.order_used = False
self.cmd += self.orders[self.result[0]][0]
#actually process the buffs
self.active_strategy = ['full forward',5]
for ship in player_ships:
ship.set_buff(FullForward)
#bookkeeping
self.battle_log_insert(['order'], "ORDER: FULL FORWARD")
BM.order_used = True
store.show_message('All ships gain 20% damage and 15% accuracy!')
#play a voice
random_ship = player_ships[renpy.random.randint(0,len(player_ships)-1)]
random_voice = renpy.random.randint(0,len(random_ship.buffed_voice)-1)
renpy.music.play('sound/Voice/{}'.format(random_ship.buffed_voice[random_voice]),channel = random_ship.voice_channel)
#animation
for ship in player_ships:
ship.getting_buff = True
renpy.hide_screen('battle_screen')
renpy.show_screen('battle_screen')
renpy.pause(1)
for ship in player_ships:
ship.getting_buff = False
renpy.hide_screen('battle_screen')
renpy.show_screen('battle_screen')
else:
renpy.music.play('sound/Voice/Ava/Ava Others 9.ogg',channel='avavoice')
self.order_used = False
def battle_order_repair_drones(self):
if self.cmd >= self.orders[self.result[0]][0]:
if sunrider.repair_drones != None:
if sunrider.repair_drones <= 0:
show_message('No available repair droids in storage!')
self.order_used = False
return
else:
sunrider.repair_drones -= 1
self.cmd -= self.orders[self.result[0]][0]
message = "ORDER: Repair drones restore 50% of Sunrider's hull integrity"
self.battle_log_insert(['order'], message)
show_message(message)
BM.order_used = True
sunrider.hp += int(sunrider.max_hp * 0.5)
if sunrider.hp > sunrider.max_hp: sunrider.hp = sunrider.max_hp
sunrider.getting_buff = True
renpy.hide_screen('battle_screen')
renpy.show_screen('battle_screen')
a = renpy.random.randint(0,len(sunrider.buffed_voice)-1)
renpy.music.play('sound/Voice/{}'.format(sunrider.buffed_voice[a]),channel = sunrider.voice_channel)
del a
renpy.pause(1)
sunrider.getting_buff = False
renpy.hide_screen('battle_screen')
renpy.show_screen('battle_screen')
else:
renpy.music.play('sound/Voice/Ava/Ava Others 9.ogg',channel='avavoice')
self.order_used = False
def battle_short_range_warp(self):
if self.cmd >= self.orders[self.result[0]][0]:
self.cmd -= self.orders[self.result[0]][0]
if self.selected != None:
self.unselect_ship(self.selected)
self.selected = sunrider #show the sunrider's label
self.phase = None #disables the end turn button
self.order_used = False #debug
self.targetwarp = True
renpy.hide_screen('commands')
renpy.hide_screen('battle_screen')
renpy.show_screen('battle_screen')
renpy.show_screen('mousefollow')
looping = True
while looping:
result = ui.interact()
if result[0] == "warptarget":
new_location = result[1]
store.flash_locations = [ sunrider.location,new_location ]
self.warping = True
renpy.hide_screen('battle_screen')
renpy.show_screen('battle_screen')
renpy.hide_screen('mousefollow')
renpy.music.play('sound/large_warpout.ogg', channel = 'sound5')
renpy.pause(1.0, hard=True) #hard means unskippable
self.warping = False
x,y = self.selected.location
self.grid[x-1][y-1] = False
self.selected.location = new_location
x,y = self.selected.location
self.grid[x-1][y-1] = True
looping = False
self.phase = 'Player'
self.targetwarp = False
renpy.hide_screen('battle_screen')
renpy.show_screen('battle_screen')
if result[0] == "zoom":
zoom_handling(result,self)
if result[0] == 'deselect':
self.cmd += self.orders['SHORT RANGE WARP'][0]
looping = False
renpy.hide_screen('mousefollow')
self.phase = 'Player'
self.targetwarp = False
else:
self.order_used = False
renpy.music.play('sound/Voice/Ava/Ava Others 9.ogg',channel='avavoice')
def battle_retreat(self):
clean_battle_exit()
renpy.jump('retreat')
def battle_order_vanguard_cannon(self):
inrange = False
#check to see if any enemy units are within reach of the VC
for ship in enemy_ships:
if get_distance(sunrider.location,ship.location) <= BM.vanguard_range:
inrange = True
if inrange:
if self.cmd >= self.orders[self.result[0]][0]:
self.cmd -= self.orders[self.result[0]][0]
self.vanguardtarget = True
looping = True
while looping:
result = ui.interact()
if result[0] == "selection":
#the player has clicked a location
if result[1].faction != 'Player' and get_ship_distance(sunrider,result[1]) <= BM.vanguard_range:
loc1 = sunrider.location
loc2 = result[1].location
listlocs = interpolate_hex(loc1, loc2)
hasship = False
#test whether there are targets in the path.
for loc in listlocs:
if not get_cell_available(loc):
for ship in enemy_ships:
if ship.location[0] == loc[0] and ship.location[1] == loc[1]:
hasship = True
if not hasship:
#no good targets found
self.cmd += self.orders['VANGUARD CANNON'][0]
looping = False
self.order_used = False
return
self.vanguardtarget = False #resolve firing the VGC, no further targeting is required.
renpy.music.play('Music/March_of_Immortals.ogg')
renpy.call_in_new_context('atkanim_sunrider_vanguard')
renpy.hide_screen('battle_screen')
renpy.show_screen('battle_screen')
renpy.pause(1)
store.damage = BM.vanguard_damage
store.hit_count = 1
store.total_armor_negation = 0
store.total_shield_negation = 0
store.total_flak_interception = 0
templist = enemy_ships[:]
self.battle_log_insert(['order'], "ORDER: FIRE VANGUARD CANNON")
for ship in templist:
for tile in listlocs:
if ship.location != None and self.battlemode: #failsaves. it's now legal for a location to be None
if ship.location[0] == tile[0] and ship.location[1] == tile[1]:
#if ship.location[1] == sunrider.location[1]:
# if ship.location[0]-sunrider.location[0] >=0:
# if ship.location[0]-sunrider.location[0] <=7:
if ship in enemy_ships: #it's possible the ship was already deleted because of the boss being killed
self.target = ship
ship.receive_damage(BM.vanguard_damage,sunrider,'Vanguard')
looping = False
if BM.battlemode: #have to check this because killing the last enemy unit ends the battle.
renpy.hide_screen('battle_screen')
renpy.show_screen('battle_screen')
BM.order_used = True
if result[0] == 'deselect':
self.cmd += self.orders['VANGUARD CANNON'][0]
looping = False
self.vanguardtarget = False
self.order_used = False
else:
renpy.music.play('sound/Voice/Ava/Ava Others 9.ogg',channel='avavoice')
self.order_used = False
else:
renpy.say('Ava','It\'s hopeless, captain!')
self.order_used = False
def toggle_player_ai(self):
self.player_ai = not self.player_ai
def battle_end_turn(self):
if self.targetingmode:
self.battle_deselect()
self.end_player_turn()
########################################################
## Battle dispatcher end
########################################################
def start(self):
self.battle_log_insert(['system'], "-------------BATTLE START-------------")
BM.player_ai = False
battlemode() #stop scrollback and set BM.battlemode = True
update_stats() #used to update some attributes like armour and shields
renpy.show_screen('battle_screen')
#new formation feature (only after mission 12 for now)
if self.editableformations():
self.phase = 'formation'
for ship in player_ships:
if ship.location != None:
set_cell_available(ship.location)
ship.location = None
if not ship in BM.ships:
BM.ships.append(ship)
renpy.show_screen('player_unit_pool_collapsed')
renpy.show_screen('player_unit_pool')
BM.selectedmode = False #failsafe
BM.targetmode = False
BM.selected = None #the selected unit doesn't show up in the pool
self.formation_phase()
else:
self.jumptomission()
def jumptomission(self):
renpy.jump('mission{}'.format(self.mission))
def editableformations(self):
return (type(self.mission) != str and self.mission > 12) #apparently string>int is completely legal in python :o
def battle(self):
for ship in player_ships:
if not hasattr(ship, 'blbl'):
ship.blbl = ship.lbl
if self.player_ai:
self.player_AI()
self.toggle_player_ai()
self.result = 'endturn'
else:
#battle_screen should be shown, and ui.interact waits for your input. 'result' stores the value return from the Return actionable in the screen
self.result = ui.interact()