Mercurial > touhou
annotate pytouhou/formats/sht.py @ 224:9bb26dbb8438
Remove useless and occasionally problematic (think about non-utf8 terminals) print calls.
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Mon, 19 Dec 2011 20:29:30 +0100 |
parents | 0595315d3880 |
children | 5afc75f71fed |
rev | line source |
---|---|
214
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
1 # -*- encoding: utf-8 -*- |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
2 ## |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
3 ## Copyright (C) 2011 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
4 ## |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
5 ## This program is free software; you can redistribute it and/or modify |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
6 ## it under the terms of the GNU General Public License as published |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
7 ## by the Free Software Foundation; version 3 only. |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
8 ## |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
9 ## This program is distributed in the hope that it will be useful, |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
12 ## GNU General Public License for more details. |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
13 ## |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
14 |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
15 from struct import unpack |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
16 |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
17 from pytouhou.utils.helpers import get_logger |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
18 |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
19 logger = get_logger(__name__) |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
20 |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
21 |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
22 class Shot(object): |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
23 def __init__(self): |
220
0595315d3880
Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
214
diff
changeset
|
24 self.interval = 0 |
214
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
25 self.unknown1 = None |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
26 self.pos = (0., 0.) |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
27 self.hitbox = (0., 0.) |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
28 self.angle = 0. |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
29 self.speed = 0. |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
30 self.damage = 0 |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
31 self.orb = 0 |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
32 self.unknown2 = None |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
33 self.sprite = 0 |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
34 self.unknown3 = None |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
35 self.unknown4 = None |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
36 self.homing = False |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
37 self.unknown5 = None |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
38 self.unknown6 = None |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
39 |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
40 |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
41 class SHT(object): |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
42 def __init__(self): |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
43 self.unknown1 = None |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
44 self.bombs = 0. |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
45 self.unknown2 = None |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
46 self.hitbox = 0. |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
47 self.graze_hitbox = 0. |
220
0595315d3880
Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
214
diff
changeset
|
48 self.autocollection_speed = 0. |
214
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
49 self.item_hitbox = 0. |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
50 self.percentage_of_cherry_loss_on_die = 0. |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
51 self.point_of_collection = 0 |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
52 self.horizontal_vertical_speed = 0. |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
53 self.horizontal_vertical_focused_speed = 0. |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
54 self.diagonal_speed = 0. |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
55 self.diagonal_focused_speed = 0. |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
56 self.shots = {} |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
57 |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
58 |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
59 @classmethod |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
60 def read(cls, file): |
220
0595315d3880
Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
214
diff
changeset
|
61 sht = cls() |
0595315d3880
Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
214
diff
changeset
|
62 |
0595315d3880
Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
214
diff
changeset
|
63 data = unpack('<hhfI10f', file.read(52)) |
0595315d3880
Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
214
diff
changeset
|
64 (sht.unknown1, level_count, sht.bombs, sht.unknown2, sht.hitbox, |
0595315d3880
Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
214
diff
changeset
|
65 sht.graze_hitbox, sht.autocollection_speed, sht.item_hitbox, |
0595315d3880
Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
214
diff
changeset
|
66 sht.percentage_of_cherry_loss_on_die, sht.point_of_collection, |
0595315d3880
Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
214
diff
changeset
|
67 sht.horizontal_vertical_speed, sht.horizontal_vertical_focused_speed, |
0595315d3880
Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
214
diff
changeset
|
68 sht.diagonal_speed, sht.diagonal_focused_speed) = data |
214
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
69 |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
70 levels = [] |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
71 for i in xrange(level_count): |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
72 offset, power = unpack('<II', file.read(8)) |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
73 levels.append((power, offset)) |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
74 |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
75 sht.shots = {} |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
76 |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
77 for power, offset in levels: |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
78 sht.shots[power] = [] |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
79 file.seek(offset) |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
80 |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
81 while True: |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
82 interval, unknown1 = unpack('<HH', file.read(4)) |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
83 if interval == 0xffff and unknown1 == 0xffff: |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
84 break |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
85 |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
86 shot = Shot() |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
87 |
220
0595315d3880
Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
214
diff
changeset
|
88 shot.interval = interval |
0595315d3880
Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
214
diff
changeset
|
89 shot.unknown1 = unknown1 |
0595315d3880
Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
214
diff
changeset
|
90 |
0595315d3880
Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
214
diff
changeset
|
91 data = unpack('<6fHBBhh4I', file.read(48)) |
214
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
92 (x, y, hitbox_x, hitbox_y, shot.angle, shot.speed, |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
93 shot.damage, shot.orb, shot.unknown2, shot.sprite, |
220
0595315d3880
Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
214
diff
changeset
|
94 shot.unknown3, shot.unknown4, shot.homing, shot.unknown5, |
0595315d3880
Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
214
diff
changeset
|
95 shot.unknown6) = data |
214
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
96 |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
97 shot.pos = (x, y) |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
98 shot.hitbox = (hitbox_x, hitbox_y) |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
99 |
220
0595315d3880
Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
214
diff
changeset
|
100 sht.shots[power].append(shot) |
214
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
101 |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
102 |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
103 return sht |
136d29ffe3c2
Add support for PCB’s SHT format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
104 |