Advertisement
Guest User

convert_move_table.py

a guest
May 12th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2.  
  3. with open('move_table.c') as f:
  4. content = f.readlines()
  5.  
  6. f = open('2move_table.c', 'w')
  7.  
  8. for line in content:
  9. lin = line.strip()
  10. if len(lin) == 0 or lin[0] != '{':
  11. f.write( line )
  12. if line.startswith('const '):
  13. f.write( '// script_id base_power type accuracy pp effect_chance target priority move_flags arg1 split arg2\n' )
  14. else:
  15. lin = lin.split(',')
  16. nlin = ' {'
  17.  
  18. hexc = "0x%0.2X"
  19. decc = "%3s"
  20.  
  21. def get_checking_str(val):
  22. val = val.strip()
  23. if val[0].isdigit():
  24. return hexc % int(val, 0 )
  25. else:
  26. return val
  27.  
  28. #script_id
  29. num = hexc % int( lin[0][1:] , 0 )
  30. nlin += num
  31. nlin += ', '
  32.  
  33. #base_power
  34. num = decc % int( lin[1].strip() , 0 )
  35. nlin += num
  36. nlin += ', '
  37.  
  38. #type
  39. lin[2] = lin[2].strip()
  40. if not lin[2][0].isdigit():
  41. ptype = lin[2]
  42. else:
  43. num = int( lin[2].strip() , 0 )
  44. if num == 0x0:
  45. ptype = 'TYPE_NORMAL'
  46. elif num == 0x1:
  47. ptype = 'TYPE_FIGHTING'
  48. elif num == 0x2:
  49. ptype = 'TYPE_FLYING'
  50. elif num == 0x3:
  51. ptype = 'TYPE_POISON'
  52. elif num == 0x4:
  53. ptype = 'TYPE_GROUND'
  54. elif num == 0x5:
  55. ptype = 'TYPE_ROCK'
  56. elif num == 0x6:
  57. ptype = 'TYPE_BUG'
  58. elif num == 0x7:
  59. ptype = 'TYPE_GHOST'
  60. elif num == 0x8:
  61. ptype = 'TYPE_STEEL'
  62. elif num == 0x9:
  63. ptype = 'TYPE_EGG'
  64. elif num == 0xA:
  65. ptype = 'TYPE_FIRE'
  66. elif num == 0xB:
  67. ptype = 'TYPE_WATER'
  68. elif num == 0xC:
  69. ptype = 'TYPE_GRASS'
  70. elif num == 0xD:
  71. ptype = 'TYPE_ELECTRIC'
  72. elif num == 0xE:
  73. ptype = 'TYPE_PSYCHIC'
  74. elif num == 0xF:
  75. ptype = 'TYPE_ICE'
  76. elif num == 0x10:
  77. ptype = 'TYPE_DRAGON'
  78. elif num == 0x11:
  79. ptype = 'TYPE_DARK'
  80. elif num == 0x17:
  81. ptype = 'TYPE_FAIRY'
  82.  
  83. ptype = "%13s" % ptype
  84. nlin += ptype
  85. nlin += ', '
  86.  
  87. #accuracy
  88. num = decc % int( lin[3].strip() , 0 )
  89. nlin += num
  90. nlin += ', '
  91.  
  92. #pp
  93. num = decc % int( lin[4].strip() , 0 )
  94. nlin += num
  95. nlin += ', '
  96.  
  97. #effect_chance
  98. num = decc % int( lin[5].strip() , 0 )
  99. nlin += num
  100. nlin += ', '
  101.  
  102. #target
  103. num = hexc % int( lin[6].strip() , 0 )
  104. nlin += num
  105. nlin += ', '
  106.  
  107. #priority
  108. num = int( lin[7].strip() , 0 )
  109. if num >= 128:
  110. num -= 256
  111. num = decc % num
  112. nlin += num
  113. nlin += ', '
  114.  
  115. #move_flags
  116. nlin += lin[8].strip()
  117. nlin += ', '
  118.  
  119. #arg1
  120. nlin += get_checking_str(lin[9])
  121. nlin += ', '
  122.  
  123. #split
  124. lin[10] = lin[10].strip()
  125. if not lin[10][0].isdigit():
  126. mtype = lin[10]
  127. else:
  128. num = int( lin[10].strip() , 0 )
  129. if num == 0:
  130. mtype = 'MOVE_PHYSICAL'
  131. elif num == 1:
  132. mtype = 'MOVE_SPECIAL'
  133. elif num == 2:
  134. mtype = 'MOVE_STATUS'
  135. mtype = "%13s" % mtype
  136. nlin += mtype
  137. nlin += ', '
  138.  
  139. if len(lin) == 13:
  140. #arg2
  141. nlin += get_checking_str(lin[11].strip()[0:-1])
  142. nlin += '},'
  143. nlin += lin[12]
  144. else:
  145. nlin += lin[11].strip()
  146.  
  147. nlin += '\n'
  148.  
  149. f.write( nlin )
  150.  
  151.  
  152. f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement