Mercurial > touhou
comparison pytouhou/formats/sht.py @ 220:0595315d3880
Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sun, 18 Dec 2011 14:14:32 +0100 |
parents | 136d29ffe3c2 |
children | 5afc75f71fed |
comparison
equal
deleted
inserted
replaced
219:091301805cce | 220:0595315d3880 |
---|---|
19 logger = get_logger(__name__) | 19 logger = get_logger(__name__) |
20 | 20 |
21 | 21 |
22 class Shot(object): | 22 class Shot(object): |
23 def __init__(self): | 23 def __init__(self): |
24 self.interval = 0. | 24 self.interval = 0 |
25 self.unknown1 = None | 25 self.unknown1 = None |
26 self.pos = (0., 0.) | 26 self.pos = (0., 0.) |
27 self.hitbox = (0., 0.) | 27 self.hitbox = (0., 0.) |
28 self.angle = 0. | 28 self.angle = 0. |
29 self.speed = 0. | 29 self.speed = 0. |
39 | 39 |
40 | 40 |
41 class SHT(object): | 41 class SHT(object): |
42 def __init__(self): | 42 def __init__(self): |
43 self.unknown1 = None | 43 self.unknown1 = None |
44 self.level_count = 9 | |
45 self.bombs = 0. | 44 self.bombs = 0. |
46 self.unknown2 = None | 45 self.unknown2 = None |
47 self.hitbox = 0. | 46 self.hitbox = 0. |
48 self.graze_hitbox = 0. | 47 self.graze_hitbox = 0. |
49 self.autocollected_item_speed = 0. | 48 self.autocollection_speed = 0. |
50 self.item_hitbox = 0. | 49 self.item_hitbox = 0. |
51 self.percentage_of_cherry_loss_on_die = 0. | 50 self.percentage_of_cherry_loss_on_die = 0. |
52 self.point_of_collection = 0 | 51 self.point_of_collection = 0 |
53 self.horizontal_vertical_speed = 0. | 52 self.horizontal_vertical_speed = 0. |
54 self.horizontal_vertical_focused_speed = 0. | 53 self.horizontal_vertical_focused_speed = 0. |
57 self.shots = {} | 56 self.shots = {} |
58 | 57 |
59 | 58 |
60 @classmethod | 59 @classmethod |
61 def read(cls, file): | 60 def read(cls, file): |
62 (_, level_count, bombs, _, hitbox, graze_hitbox, | 61 sht = cls() |
63 autocollected_item_speed, item_hitbox, percentage_of_cherry_loss_on_die, | 62 |
64 point_of_collection, horizontal_vertical_speed, | 63 data = unpack('<hhfI10f', file.read(52)) |
65 horizontal_vertical_focused_speed, diagonal_speed, | 64 (sht.unknown1, level_count, sht.bombs, sht.unknown2, sht.hitbox, |
66 diagonal_focused_speed) = unpack('<hhfI10f', file.read(52)) | 65 sht.graze_hitbox, sht.autocollection_speed, sht.item_hitbox, |
66 sht.percentage_of_cherry_loss_on_die, sht.point_of_collection, | |
67 sht.horizontal_vertical_speed, sht.horizontal_vertical_focused_speed, | |
68 sht.diagonal_speed, sht.diagonal_focused_speed) = data | |
67 | 69 |
68 levels = [] | 70 levels = [] |
69 for i in xrange(level_count): | 71 for i in xrange(level_count): |
70 offset, power = unpack('<II', file.read(8)) | 72 offset, power = unpack('<II', file.read(8)) |
71 levels.append((power, offset)) | 73 levels.append((power, offset)) |
72 | 74 |
73 sht = cls() | |
74 sht.shots = {} | 75 sht.shots = {} |
75 | 76 |
76 for power, offset in levels: | 77 for power, offset in levels: |
77 sht.shots[power] = [] | 78 sht.shots[power] = [] |
78 file.seek(offset) | 79 file.seek(offset) |
82 if interval == 0xffff and unknown1 == 0xffff: | 83 if interval == 0xffff and unknown1 == 0xffff: |
83 break | 84 break |
84 | 85 |
85 shot = Shot() | 86 shot = Shot() |
86 | 87 |
87 data = file.read(48) | 88 shot.interval = interval |
89 shot.unknown1 = unknown1 | |
90 | |
91 data = unpack('<6fHBBhh4I', file.read(48)) | |
88 (x, y, hitbox_x, hitbox_y, shot.angle, shot.speed, | 92 (x, y, hitbox_x, hitbox_y, shot.angle, shot.speed, |
89 shot.damage, shot.orb, shot.unknown2, shot.sprite, | 93 shot.damage, shot.orb, shot.unknown2, shot.sprite, |
90 shot.unknown3, unknown4, homing, unknown5, | 94 shot.unknown3, shot.unknown4, shot.homing, shot.unknown5, |
91 unknown6) = unpack('<6fHBBhh4I', data) | 95 shot.unknown6) = data |
92 | 96 |
93 shot.pos = (x, y) | 97 shot.pos = (x, y) |
94 shot.hitbox = (hitbox_x, hitbox_y) | 98 shot.hitbox = (hitbox_x, hitbox_y) |
95 shot.unknown4 = bool(unknown4) | |
96 shot.homing = bool(homing) | |
97 shot.unknown5 = bool(unknown5) | |
98 shot.unknown6 = bool(unknown6) | |
99 | 99 |
100 sht.shts[power].append(shot) | 100 sht.shots[power].append(shot) |
101 | 101 |
102 | 102 |
103 return sht | 103 return sht |
104 | 104 |