Shuvit game master repo. http://shuvit.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ai_manager.py 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. def printplaying(skater,deck):
  2. splaying_layers = "S: "
  3. playing_layers = "D: "
  4. tplaying_layers = "T: "
  5. for x in range(9999):
  6. if skater.isPlayingAction(x):
  7. #if trucks.isPlayingAction(x):
  8. #if skater.isPlayingAction(x):
  9. splaying_layers += str(x)
  10. splaying_layers += " "
  11. if deck.isPlayingAction(x):
  12. #if trucks.isPlayingAction(x):
  13. #if skater.isPlayingAction(x):
  14. playing_layers += str(x)
  15. playing_layers += " "
  16. print(splaying_layers, playing_layers)
  17. def main():
  18. frame_rate = 60 #Set this to the framerate of your game.
  19. optimization = 1 #An integer, must be at least 1! Higher value will make a smaller saved file size. I do not reccomend setting it to anything other than 1 though.
  20. #recording_cutoff = 6974#7300 #3600 #Frames at which the oldest recorded frame will be deleted. 0 is no cutoff.
  21. recorder_state = 1 #This is the main state of the recorder object. State will be reverted to this value when the user breaks out of the playback.
  22. allow_playback_break = True #Allow the player to resume playing from the position in the recording.
  23. from bge import logic
  24. import aiRecord
  25. import aiSortData
  26. import npcChangeAnim
  27. from mathutils import Vector
  28. import math
  29. debugg = True
  30. cont = logic.getCurrentController()
  31. own = cont.owner
  32. scene = logic.getCurrentScene()
  33. dict = logic.globalDict
  34. own['valueIndex'] = own['valueIndex'] + 2
  35. #dict['recorder_on'] = recorder_on
  36. npc_index = own['npc_index']
  37. skater = dict['spawned_npcs'][npc_index]
  38. recorder_on = dict.get('recorder_on')
  39. own['recorder_on'] = recorder_on
  40. #print("recorder on: ", recorder_on)
  41. own["playback"] = True
  42. recording_cutoff = own['replay_length']
  43. idle_timer = own['idle_timer']
  44. npc_playback = own['npc_playback']
  45. if 'data_loaded' not in own:
  46. #own['data_loaded'] = 1
  47. aiRecord.loadData(cont, own)
  48. if debugg: print('ai_loadData')
  49. if npc_playback == True:
  50. cube = own
  51. aiRecord.loadData(cont, own)
  52. #own['move'] = False
  53. #....................
  54. valueIndex = own['valueIndex']
  55. n = (valueIndex / recording_cutoff) * 1000
  56. n = int(round(n))
  57. #print(own['valueIndex'])
  58. if own['objIndex'] < (recording_cutoff-3):
  59. own['objIndex'] = own['objIndex'] + 2
  60. else:
  61. own['objIndex'] = 4
  62. print('replay end')
  63. npcChangeAnim.main(cont)
  64. #own['npc_replay_name'] = '30secA.dat'
  65. own['inited'] = False
  66. own['rotate_in'] = True
  67. own['move_to'] = True
  68. own['rotate_out'] = True
  69. aiRecord.loadData(cont, own)
  70. else:
  71. if idle_timer < 5:
  72. idle_timer += 1
  73. #print('idling', idle_timer)
  74. else:
  75. idle_timer = 0
  76. own['npc_rotate'] = True
  77. if own['move'] == True:
  78. speed = .15
  79. target = own['rpStartLoc']
  80. my_vector = Vector([target[0], target[1], target[2]])
  81. length = (own.worldPosition - my_vector).length
  82. obj = own['target_object_name']
  83. vect = own.getVectTo(obj)
  84. if length < .1:
  85. own['move'] = False
  86. obj = own['target_object_name']
  87. own['idle_timer'] = idle_timer
  88. try:
  89. obj = own['target_object_name']
  90. #print(obj.worldPosition)
  91. except:
  92. pass
  93. #11111111
  94. if own['rotate_in'] == False and own['move_to'] == False and own['rotate_out'] == False:
  95. own['npc_playback'] = True
  96. #obj = own['target_object_name']
  97. #obj.endObject()
  98. #print('ending target')
  99. if own['rotate_in'] == True:
  100. tActu = cont.actuators['npcTracking']
  101. tActu.object = own['target_object_name']
  102. try:
  103. own['rotate_in_timer'] = own['rotate_in_timer'] + 1
  104. except:
  105. own['rotate_in_timer'] = 0
  106. if own['rotate_in_timer'] < 120:
  107. cont.activate(tActu)
  108. skater.playAction('reg_idle1', 0,120, layer=2, play_mode=1, speed=.5)
  109. else:
  110. cont.deactivate(tActu)
  111. own['rotate_in'] = False
  112. own['rotate_in_timer'] = 0
  113. skater.stopAction(2)
  114. elif own['move_to'] == True:
  115. target = own['rpStartLoc']
  116. #print(target, 'target', own.worldPosition, '++++++')
  117. my_vector = Vector([target[0], target[1], target[2]])
  118. length = (own.worldPosition - my_vector).length
  119. sActu = cont.actuators['npcSteering']
  120. sActu.target = own['target_object_name']
  121. #length = round(length, 7)
  122. if length > .1:
  123. #print(length, 'length < .1')
  124. #pass
  125. cont.activate(sActu)
  126. skater.playAction('reg_nwalk', 0,35, layer=2, play_mode=1, speed=.5)
  127. else:
  128. cont.deactivate(sActu)
  129. own['move_to'] = False
  130. print(length, 'length met')
  131. skater.stopAction(2)
  132. elif own['rotate_out'] == True:
  133. #own['rpStartZ'] = 180
  134. #print(own['rpStartZ'], 'start')
  135. xyz = own.localOrientation.to_euler()
  136. #print(xyz[2], 'non euler')
  137. rotz = math.degrees(xyz[2])
  138. xyz[2] = xyz[2] + 1.57
  139. rotz_b = rotz + 180
  140. if rotz_b > 360:
  141. rotz_b -= 360
  142. srotz_b = own['rpStartZ'] + 180
  143. if srotz_b > 360:
  144. srotz_b -= 360
  145. #print (rotz_b, srotz_b, '---rotations')
  146. #print (rotz, own['rpStartZ'], '---rotations')
  147. num = rotz - (own['rpStartZ'])
  148. amt = .03
  149. amt2 = 1
  150. local = own.worldOrientation.inverted() * ( own['target_object_name'].worldPosition - own.worldPosition)
  151. if local.x >0:
  152. #target is in front
  153. #print('in front')
  154. pass
  155. else:
  156. #target is behind
  157. #print('behind')
  158. pass
  159. if local.y > 0:
  160. #object on right
  161. #print('on right')
  162. rot = 'right'
  163. else:
  164. #object is on left
  165. #print('on left')
  166. rot = 'left'
  167. skater.playAction('reg_idle1', 0,120, layer=2, play_mode=1, speed=.5)
  168. if abs(num) < amt2:
  169. own['npc_playback'] = True
  170. own['npc_rotate'] = False
  171. print('----starting replay', num)
  172. own['rotate_out'] = False
  173. obj = own['target_object_name']
  174. obj.endObject()
  175. print('ending target')
  176. skater.stopAction(2)
  177. #elif rotz > own['rpStartZ']:
  178. elif rot == 'right':
  179. own.applyRotation([0,0,amt], True)
  180. own.worldPosition = own['rpStartLoc']
  181. #elif rotz < own['rpStartZ']:
  182. elif rot == 'left':
  183. own.applyRotation([0,0,-amt], True)
  184. own.worldPosition = own['rpStartLoc']
  185. #print(own['rotate_in'], own['move_to'], own['rotate_out'])
  186. main()