forked from vaendryl/Sunrider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
classes.rpy
2432 lines (2095 loc) · 110 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.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.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.cmd = 0 #your command point total
self.vanguard = False #when True the battlemap shows the vanguard cannon being fired.
self.vanguardtarget = False #creates buttons to select vanguard fire direction
self.money = 0 #go on, set this to 999'999'999. you know you want to.
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.pending_upgrades = [] #lists upgrades the user has not saved
self.mouse_location = (0,0)
self.orders = {
'FULL FORWARD':[750,'full_forward'],
'REPAIR DRONES':[750,'repair_drones'],
'VANGUARD CANNON':[2500,'vanguard_cannon'],
}
self.order_used = False #when True the orders button is hidden.
#environment modififiers 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
self.draggable = True
#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))
#here we start defining a few methods part of the battlemanager
def select_ship(self,ship,play_voice = True):
self.selectedmode = 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
renpy.show_screen('commands')
ship.movement_tiles = get_movement_tiles(ship)
def unselect_ship(self,ship):
renpy.hide_screen('commands')
self.selectedmode = False
self.selected = None
self.targetingmode = False
ship.movement_tiles = []
def start(self):
battlemode(self)
update_stats() #used to update some attributes like armor and shields
renpy.show_screen('battle_screen')
renpy.jump('mission{}'.format(self.mission))
def battle(self):
#battle_screen should be shown, and ui.interact waits for your input. 'result' stores the value return from the Return actionable in the screen
result = ui.interact()
self.just_moved = False #this sets it so you can no longer take back your move
renpy.hide_screen('game_over_gimmick') #disables the screensaver gimmick
if self.stopAI and sunrider.hp < 0: #some failsafe checking. stopAI functions like an emergency stop for AI code
renpy.jump('sunrider_destroyed')
if hasattr(store,'mochi'):
if hasattr(mochi,'hp'):
if mochi.hp < 0 and mochi in player_ships:
renpy.jump('sunrider_destroyed')
#sanity check
for ship in BM.ships:
if ship.hp <= 0:
destroyed_ships.append(ship)
if ship in player_ships:
player_ships.remove(ship)
if ship in enemy_ships:
enemy_ships.remove(ship)
if ship in BM.ships:
BM.ships.remove(ship)
#only used for debug
if result == 'anime':
if not hasattr(store,'damage'):
store.damage = 50
if not hasattr(BM,'attacker'):
BM.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 BM.target == None:
BM.target = sunrider
try:
renpy.call_in_new_context('hitanim_piratebase_rocket')
except:
show_message('animation label does not exist!')
if result == 'cheat':
BM.cmd = 99999
for ship in player_ships:
ship.en = 9999
if result == 'I WIN':
instant_win()
if result == 'deselect':
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
if result == "next ship":
if self.selected == None:
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])
if result == "previous ship":
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])
# if result[0] == 'mousefollow_click':
# a,b = result[1]
# yoffset = 27 * zoomlevel
# hexheight = HEXD * zoomlevel
# hexwidth = HEXW * zoomlevel
# y = int( (b+BM.yadj.value-yoffset) / hexheight )
# if y%2==0:
# xoffset = hexwidth/2
# else:
# xoffset = 0
# x = int( (a+BM.xadj.value-xoffset) / hexwidth )
# show_message( '{}/{}'.format(x,y) )
# # show_message( '{}/{}'.format(a,b) )
if result[0] == "zoom":
zoom_handling(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)
# self.just_moved = True #zooming doesn't have to reset this button
if result[0] == 'selection': #this means you clicked on a ship, which could mean various things depending on circumstance.
self.target = 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
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(result[1])
return #do end the method. this is important.
#did you click an ally?
elif self.target.faction == 'Player':
if weapon.wtype == 'Support':
if self.target.cth <= 0:
self.draggable = False
renpy.say('Ava','It\'s hopeless, 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:
BM.attacker = BM.selected
if self.active_weapon.wtype == 'Curse':
weapon.fire(self.selected,self.target)
self.active_weapon = None
self.weaponhover = None
if BM.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:
renpy.call_in_new_context('atkanim_{}_{}'.format(self.selected.animation_name,self.active_weapon.wtype.lower()))
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 BM.selected != None:
self.selected.movement_tiles = get_movement_tiles(self.selected)
update_stats()
self.active_weapon = None
self.weaponhover = None
# renpy.hide_screen('battle_screen')
# renpy.show_screen('battle_screen')
return
if result[0] == 'move': #this means you clicked on one of the blue squares indicating you want to move somewhere
self.selected.move_ship(result[1],self) #result[1] is the new location to move towards
update_stats()
if result == 'cancel movement':
ship = BM.selected
ship.en += get_distance(ship.location,ship.current_location)*ship.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)
if result == 'FULL FORWARD':
if self.cmd >= self.orders[result][0]:
self.cmd -= self.orders[result][0]
succesful = False
for ship in player_ships:
if apply_modifier(ship,'accuracy',15,5): succesful = True
if apply_modifier(ship,'damage',20,5): succesful = True
if not succesful:
show_message('already active!')
BM.order_used = False
BM.cmd += self.orders[result][0]
else:
show_message('All ships gain 20% damage and 15% accuracy!')
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)
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')
BM.order_used = False
if result == 'REPAIR DRONES':
if self.cmd >= self.orders[result][0]:
if sunrider.repair_drones != None:
if sunrider.repair_drones <= 0:
show_message('No available repair droids in storage!')
BM.order_used = False
return
else:
sunrider.repair_drones -= 1
self.cmd -= self.orders[result][0]
show_message('The Sunrider restored 50% of her hull integrity!')
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')
BM.order_used = False
if result == 'SHORT RANGE WARP':
if self.cmd >= self.orders[result][0]:
self.cmd -= self.orders[result][0]
if BM.selected != None:
BM.unselect_ship(BM.selected)
BM.selected = sunrider #show the sunrider's label
BM.phase = None #disables the end turn button
BM.order_used = False #debug
BM.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 ]
BM.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
BM.warping = False
x,y = BM.selected.location
BM.grid[x-1][y-1] = False
BM.selected.location = new_location
x,y = BM.selected.location
BM.grid[x-1][y-1] = True
looping = False
BM.phase = 'Player'
BM.targetwarp = False
renpy.hide_screen('battle_screen')
renpy.show_screen('battle_screen')
if result[0] == "zoom":
zoom_handling(result,self)
if result == 'deselect':
self.cmd += self.orders['SHORT RANGE WARP'][0]
looping = False
renpy.hide_screen('mousefollow')
BM.phase = 'Player'
BM.targetwarp = False
else:
BM.order_used = False
renpy.music.play('sound/Voice/Ava/Ava Others 9.ogg',channel='avavoice')
if result == 'VANGUARD CANNON':
inrange = False
templist = enemy_ships[:]
for ship in templist:
if get_distance(sunrider.location,ship.location) <= 7:
inrange = True
if inrange:
if self.cmd >= self.orders[result][0]:
self.cmd -= self.orders[result][0]
BM.vanguardtarget = True
looping = True
while looping:
result = ui.interact()
if result[0] == "selection":
if result[1].faction != 'Player':
loc1 = sunrider.location
loc2 = result[1].location
listlocs = interpolate_hex(loc1, loc2)
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 = 800
store.hit_count = 1
store.total_armor_negation = 0
store.total_shield_negation = 0
templist = enemy_ships[:]
for ship in templist:
for tile in listlocs:
if ship.location != None: #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 and self.battlemode: #it's possible the ship was already deleted because of the boss being killed
BM.target = ship
ship.receive_damage(800,sunrider,'Vanguard')
looping = False
BM.vanguardtarget = False
renpy.hide_screen('battle_screen')
renpy.show_screen('battle_screen')
self.cmd -= self.orders[prev_result][0]
loc1 = sunrider.location
loc2 = result[1].location
listlocs = interpolate_grid(loc1, loc2)
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 = 800
store.hit_count = 1
store.total_armor_negation = 0
store.total_shield_negation = 0
templist = reversed(enemy_ships[:])
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 and it's possible the battle is already over due to zapping the boss
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
BM.target = ship
ship.receive_damage(800,sunrider,'Vanguard')
looping = False
BM.vanguardtarget = False
renpy.hide_screen('battle_screen')
renpy.show_screen('battle_screen')
if result == 'deselect':
self.cmd += self.orders['VANGUARD CANNON'][0]
looping = False
BM.vanguardtarget = False
BM.order_used = False
else:
renpy.music.play('sound/Voice/Ava/Ava Others 9.ogg',channel='avavoice')
BM.order_used = False
else:
renpy.say('Ava','It\'s hopeless, captain!')
BM.order_used = False
if result[0] == 'hover': #you are hovering over one of the weapon buttons
self.weaponhover = result[1]
if self.weaponhover.wtype == 'Support':
for ship in player_ships:
ship.cth = get_acc(result[1], BM.selected, ship)
else:
ignore_evasion = False
if self.weaponhover.wtype == 'Curse':
ignore_evasion = True
for ship in enemy_ships:
ship.cth = get_acc(result[1], BM.selected, ship, ignore_evasion)
if result[0] == 'weapon_fire': #you actually clicked on one of the weapon buttons
if result[1].wtype == 'Support':
if result[1].self_buff:
result[1].fire(BM.selected,BM.selected)
update_stats()
BM.selected.movement_tiles = get_movement_tiles(BM.selected)
return
self.targetingmode = True #displays targeting info over enemy_ships
self.active_weapon = result[1]
self.weaponhover = BM.active_weapon
ignore_evasion = False
#the hover thing is not 100% trustworthy so we calculate CTH again based on the selected weapon
if self.weaponhover.wtype == 'Curse':
ignore_evasion = True
for ship in enemy_ships:
ship.cth = get_acc(result[1], BM.selected, ship, ignore_evasion)
update_stats()
if result == 'endturn':
self.end_player_turn()
if len(enemy_ships) == 0 and self.battlemode: #check if there are enemy_ships remaining.
renpy.hide_screen('commands')
self.battle_end()
renpy.hide_screen('battle_screen')
if len(player_ships) == 0: #all player units destroyed!
self.battlemode = False #this ends the battle loop
VNmode()
renpy.hide_screen('battle_screen')
renpy.hide_screen('commands')
return
#ending a turn
def end_player_turn(self):
renpy.hide_screen('commands')
self.selected = None #some sanity checking
self.target = None
self.moving = False
self.selectedmode = False
self.targetingmode = False
self.active_weapon = None
self.turn_count += 1
renpy.music.play(EnemyTurnMusic)
renpy.call_in_new_context('endofturn')
for ship in self.ships:
ship.flak_effectiveness = 100
self.enemy_AI() #call the AI to take over
##I have NO idea why this dumb workaround is needed, but the destroy() method -somehow- doesn't want to jump to this label sometimes.
if sunrider.hp < 0:
renpy.jump('sunrider_destroyed')
for ship in self.ships:
ship.flak_effectiveness = 100
for ship in player_ships:
ship.en = ship.max_en
self.active_weapon = None
self.selected = None
self.selectedmode = False
self.order_used = False
if self.battlemode:
renpy.music.play(PlayerTurnMusic)
renpy.call_in_new_context('endofturn')
def enemy_AI(self):
##lead ships don't care about looking for other ships for protection
##other ships come to them! instead, lead ships typically go on the
##offensive, dragging allies along.
self.lead_ships = []
total_defense = 0
update_stats()
for eship in enemy_ships:
total_defense += eship.shield_generation + eship.flak + eship.armor
average_defense = total_defense / float(len(enemy_ships))
##because I assume most of the time there will be many mooks and only
##a few high defense ships the few that are are definitely above average.
##this method is very dynamic and doesn't rely on blueprint flags.
for eship in enemy_ships:
defense = eship.shield_generation + eship.flak + eship.armor
if defense > average_defense:
self.lead_ships.append(eship)
##the lead ships are heaving a go first
for eship in self.lead_ships:
if BM.stopAI:
return
eship.en = eship.max_en
eship.lbl = im.MatrixColor(eship.blbl,im.matrix.brightness(0.3))
renpy.pause(0.3)
try:
if not eship.modifiers['energy regen'][0] == -100:
eship.AI()
else:
show_message('the {} is disabled!'.format(eship.name) )
except:
eship.modifiers['energy regen'] = (0,0)
eship.AI()
eship.lbl = eship.blbl
## the rest of the enemy units take their turns after
for ship in enemy_ships:
if BM.stopAI:
return
#now all the not-lead ships take their turn
if ship not in self.lead_ships:
try:
if ship.modifiers['energy regen'][0] == -100:
show_message('the {} is disabled!'.format(ship.name) )
ship.en = 0
else:
ship.en = ship.max_en
except:
ship.modifiers['energy regen'] = (0,0)
ship.en = ship.max_en
ship.lbl = im.MatrixColor(ship.blbl,im.matrix.brightness(0.3))
renpy.pause(0.3)
ship.AI()
ship.lbl = ship.blbl
#ending the battle - reset values for next battle
def battle_end(self, lost = False):
self.battlemode = False #this ends the battle loop
if self.selected != None: self.unselect_ship(self.selected)
self.targetingmode = False
self.weaponhover = None
self.hovered = None
renpy.hide_screen('tooltips')
BM.phase = 'Player'
if not lost:
#show the victory screen
renpy.music.stop()
renpy.music.play('Music/Posthumus_Regium_Finale.ogg', loop = False)
renpy.hide_screen('commands')
self.draggable = False
renpy.show_screen('victory')
renpy.pause(3.0)
renpy.hide_screen('victory')
store.repair_cost = 0
store.total_money = 0
store.boss_killed = False
store.surrender_bonus = 0
for ship in destroyed_ships:
if ship.faction == 'Player':
store.repair_cost += int(ship.max_hp * 0.2)
else:
if ship.boss: store.boss_killed = True #check if a boss was killed
store.total_money += ship.money_reward
if store.boss_killed:
for ship in enemy_ships:
if ship.hp > 0:
store.surrender_bonus += ship.money_reward / 2
for ship in player_ships:
store.repair_cost += int((ship.max_hp - ship.hp)*0.1)
store.net_gain = int(store.total_money + store.surrender_bonus - store.repair_cost)
self.money += int(net_gain)
self.cmd += int((net_gain*10)/(BM.turn_count+2)) #this is independent of the victory screen display!
renpy.show_screen('victory2')
renpy.pause(1)
renpy.hide_screen('victory2')
self.draggable = True
self.turn_count = 1
self.ships = []
self.selectedmode = False
VNmode() #return to visual novel mode. this mostly just restored scrolling rollback
for ship in destroyed_ships:
if ship.faction == 'Player':
player_ships.append(ship)
self.ships.append(ship)
for ship in player_ships:
self.ships.append(ship)
for ship in player_ships:
ship.en = ship.max_en
ship.hp = ship.max_hp
ship.hate = 100
ship.total_damage = 0
ship.total_missile_damage = 0
ship.total_kinetic_damage = 0
ship.total_energy_damage = 0
ship.missiles = ship.max_missiles
ship.location = None #this helps if you add new ships but don't know the current location of the existing ones.
for modifier in ship.modifiers:
ship.modifiers[modifier] = [0,0]
#reset the entire grid to empty and BM.ships with only the player_ships list
clean_grid()
BM.covers = []
renpy.block_rollback()
## Displayables ##
class MouseTracker(renpy.Displayable):
"""this class keeps track of where the mouse is and what it does and relates
drags and clicks to the viewport and the BM. This way the ships can be simple
images instead of imagebuttons, reducing lag. I guess this doesn't have to be
a displayable but it works so meh"""
def __init__(self,**kwargs):
renpy.Displayable.__init__(self,**kwargs)
self.width = 0
self.height = 0
self.mouse_has_moved = True
self.rel = (0,0)
def render(self, width, height, st, at):
render = renpy.Render(self.width, self.height)
return render
def event(self, ev, x, y, st):
if ev.type == pygame.MOUSEBUTTONDOWN and ev.button == 1:
self.mouse_has_moved = False
self.rel = pygame.mouse.get_rel()
if ev.type == pygame.MOUSEMOTION:
self.mouse_has_moved = True
renpy.hide_screen('game_over_gimmick')
# if the left mouse button is pressed, it's a drag
if ev.buttons[0] == 1:
BM.xadj.change(BM.xadj.value - ev.rel[0] * 2)
BM.yadj.change(BM.yadj.value - ev.rel[1] * 2)
# if abs(ev.rel[0]) + abs(ev.rel[1]) > 5:
mouse_location = get_mouse_location()
#check for hovering over movement tiles
if BM.selected != None:
if BM.mouse_location != mouse_location and ev.buttons[0] != 1:
if get_distance(BM.selected.location,mouse_location) <=4:
BM.mouse_location = mouse_location
self.mouse_has_moved = True
renpy.restart_interaction()
#check for hovering over ships
if BM.hovered != None:
if BM.hovered.location != mouse_location:
BM.hovered = None
renpy.restart_interaction()
else:
for ship in BM.ships:
if ship.location == mouse_location:
BM.hovered = ship
renpy.restart_interaction()
break
elif ev.type == pygame.MOUSEBUTTONUP and ev.button == 1:
# being very careful that the mouse -did not move- recently before an actual click is registered
# otherwise it's a drag
if not self.mouse_has_moved and pygame.mouse.get_rel() == (0,0):
mouse_location = get_mouse_location()
if BM.targetwarp:
if get_cell_available(mouse_location):
return ['warptarget',get_mouse_location()]
elif BM.selected != None and BM.weaponhover == None:
if BM.selected.faction == 'Player':
if get_cell_available(mouse_location):
distance = get_distance(BM.selected.location,mouse_location)
if distance <= 4: #perhaps not really needed anymore?
move_range = int(float(BM.selected.en) / BM.selected.move_cost)
if distance <= move_range:
return [ 'move' , mouse_location ]
if (BM.weaponhover == None or BM.active_weapon != None) and not BM.targetwarp:
for ship in BM.ships:
if ship.location == mouse_location:
return ['selection',ship]
else:
pass
class MouseFollow(renpy.Displayable):
'''custom displayables harness the power of pygame directly.
this class creates an object that will display an image at the mouse cursor
which gets redrawn every frame so it follows the cursor.'''
def __init__(self,child,**kwargs):
renpy.Displayable.__init__(self,**kwargs)
self.child = renpy.displayable(child)
self.width = 0
self.height = 0
self.position = renpy.get_mouse_pos()
def render(self, width, height, st, at):
#create the basic Render from the passed displayable (the child)
child_render = renpy.render(self.child, width, height, st ,at)
#get the size of the label
self.width, self.height = child_render.get_size()
#make a new Render object with the size of the child.
render = renpy.Render(self.width, self.height)
#grab the mouse location
x,y = renpy.get_mouse_pos()
#adjust the position so that the middle of the label lines up with the mouse cursor
self.position = (x - self.width / 2 , y - self.height / 2)
#blitting means actually showing it on screen
render.blit(child_render, self.position)
# request a redraw asap (= next frame)
renpy.redraw(self, 0)
#return the render object so that renpy can do things with it.
return render
def event(self, ev, x, y, st):
pass
# if ev.type == pygame.MOUSEBUTTONDOWN and ev.button == 1:
def visit(self):
return [ self.child ]
##blueprints##
#this class is the basis of all unit types in the game. these values are the default one if none are specified.
class Battleship(store.object):
def __init__(self):
self.shield_generation = 0
self.shields = self.shield_generation
self.shield_range = -1
self.shield_color = '000'
self.max_hp = 200
self.hp = self.max_hp
self.max_en = 100
self.en = self.max_en
self.repair = 0
self.flak = 0
self.flak_range = 1
self.flak_effectiveness = 100
self.flak_used = False
self.flaksim = None
self.fireing_flak = False
self.morale = 100
self.enemies = {}
self.hate = 100 #this is actually how much the enemy hates you. aka threat
self.attraction = 0 #AI uses this. ships that provide lots of cover attract others
self.fear = {
'kinetics':20,
'missiles':20,
'energy':20,
}
self.kinetic_dmg = 1 #normal damage at start. increased by upgrades
self.kinetic_acc = 1
self.kinetic_cost = 1
self.energy_dmg = 1
self.energy_acc = 1
self.energy_cost = 1
self.missile_dmg = 1
self.missile_eccm = 0
self.missile_cost = 1
self.melee_dmg = 1
self.melee_acc = 1
self.melee_cost = 1
self.move_cost_multiplier = 1.0
#[display name, level,increase/upgrade,upgrade cost,cost multiplier]
self.upgrades = {
'max_hp':['Hull Plating',1,100,100,1.5],
'max_en':['Energy Reactor',1,5,200,1.4],
'move_cost_multiplier':['Move Cost',1,-0.05,100,2.5],
'evasion':['Evasion',1,5,500,2.5],
'kinetic_dmg':['Kinetic Damage',1,0.05,100,1.5],
'kinetic_acc':['Kinetic Accuracy',1,0.05,100,1.5],
'kinetic_cost':['Kinetic Energy Cost',1,-0.05,100,2.0],
'energy_dmg':['Energy Damage',1,0.05,100,1.5],
'energy_acc':['Energy Accuracy',1,0.05,100,1.5],
'energy_cost':['Energy Energy Cost',1,-0.05,100,2.0],
'missile_dmg':['Missile Damage',1,0.10,100,1.5],
'missile_eccm':['Missile Flak Resistance',1,1,100,1.5],
'missile_cost':['Missile Energy Cost',1,-0.10,100,2.0],
'max_missiles':['Missile Storage',1,1,500,3],
'melee_dmg':['Melee Damage',1,0.05,100,1.5],
'melee_acc':['Melee Accuracy',1,0.05,100,1.5],
'melee_cost':['Melee Energy Cost',1,-0.05,100,2.0],
'shield_generation':['Shield Power',1,5,500,2],
'shield_range':['Shield Range',1,1,1000,5],
'flak':['Flak',1,5,500,2],
'base_armor':['Armor',1,5,500,2],
'repair':['Repair Crew',1,50,500,2]
}
self.total_damage = 0 #refers to damage done, not taken. used by AI
self.total_kinetic_damage = 0
self.total_missile_damage = 0
self.total_energy_damage = 0
self.base_armor = 10
self.armor = self.base_armor
self.armor_color = '000'
self.weapons = []
self.max_weapons = 9
self.max_missiles = 0
self.max_rockets = 0
self.missiles = self.max_missiles
self.rockets = self.max_rockets
self.move_cost = 50
self.cmd_reward = 100
self.money_reward = 100
self.cth = 0
self.getting_buff = False
self.getting_curse = False
self.boss = False
self.spawns = []
self.location = (1,1)
self.movement_tiles = []
self.portrait = None
self.death_animation = 'no_animation' #the default death animation: none.
self.miss_animation = 'no_animation' #gets called when this ship avoids getting hit
self.id = 0 #used to identify enemy_ships more easily
#modifiers list temporary (de)buffs.
#these values represent the strength of the modifier and the number of turns it stays in effect
self.modifiers = {
'accuracy':[0,0],
'move_cost':[0,0],
'evasion':[0,0],
'damage':[0,0],
'armor':[0,0],
'shield':[0,0],
'flak':[0,0],
'energy':[0,0],
'stealth':[0,0],
'shield_generation':[0,0],
'energy regen':[0,0],
}
def receive_damage(self,damage,attacker,wtype):
BM.attacker = attacker
if damage == 'no energy':
renpy.say('ERROR','the {} does not have the energy for this attack'.format(self.name))
elif damage == 'no ammo':
renpy.say('ERROR','the {} does not have enough ammo for this attack'.format(self.name))
elif damage == 'miss':
if wtype == 'Melee':
store.damage = damage
renpy.call_in_new_context('melee_attack_player')
else:
try:
renpy.call_in_new_context('miss_{}'.format(self.animation_name)) #show the miss animation
except:
show_message('missing animation. "miss_{}" does\'t seem to exist'.format(self.animation_name))
else:
#handle healing
if wtype == 'Support':
self.hp += int(damage)
if self.hp > self.max_hp:
self.hp = self.max_hp