annotate pytouhou/vm/eclrunner.py @ 636:4fa0a8e7d941

Add a GLFW implementation of gui.Window.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sun, 14 May 2017 20:14:03 +0100
parents e15672733c93
children d18c0bf11138
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
52
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 51
diff changeset
1 # -*- encoding: utf-8 -*-
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 51
diff changeset
2 ##
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 51
diff changeset
3 ## Copyright (C) 2011 Thibaut Girka <thib@sitedethib.com>
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 51
diff changeset
4 ##
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 51
diff changeset
5 ## This program is free software; you can redistribute it and/or modify
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 51
diff changeset
6 ## it under the terms of the GNU General Public License as published
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 51
diff changeset
7 ## by the Free Software Foundation; version 3 only.
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 51
diff changeset
8 ##
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 51
diff changeset
9 ## This program is distributed in the hope that it will be useful,
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 51
diff changeset
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 51
diff changeset
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 51
diff changeset
12 ## GNU General Public License for more details.
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 51
diff changeset
13 ##
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 51
diff changeset
14
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 51
diff changeset
15
313
2ba2462afc70 Implement hardcoded function 9.
Thibaut Girka <thib@sitedethib.com>
parents: 312
diff changeset
16 from math import atan2, cos, sin, pi, hypot
51
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
17
58
3da4de9decd0 Use logging module
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
18 from pytouhou.utils.helpers import get_logger
3da4de9decd0 Use logging module
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
19
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 67
diff changeset
20 from pytouhou.vm.common import MetaRegistry, instruction
51
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
21
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 67
diff changeset
22 logger = get_logger(__name__)
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
23
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
24
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
25
590
e15672733c93 Switch to Python 3.x instead of 2.7.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 575
diff changeset
26 class ECLMainRunner(metaclass=MetaRegistry):
372
704bea2e4360 Use a future-proof ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 365
diff changeset
27 __slots__ = ('_main', '_subs', '_game', 'frame',
376
69ec72b990a4 Support more than one version of a vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 372
diff changeset
28 'instruction_pointer', 'boss_wait', 'handlers')
97
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
29
372
704bea2e4360 Use a future-proof ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 365
diff changeset
30 def __init__(self, main, subs, game):
704bea2e4360 Use a future-proof ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 365
diff changeset
31 self._main = main
704bea2e4360 Use a future-proof ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 365
diff changeset
32 self._subs = subs
151
5cf927cbd9c5 Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents: 150
diff changeset
33 self._game = game
376
69ec72b990a4 Support more than one version of a vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 372
diff changeset
34 self.handlers = self._handlers[6]
180
5a1533677a9a Freeze time during spellcards
Thibaut Girka <thib@sitedethib.com>
parents: 178
diff changeset
35 self.frame = 0
306
52d791bb7c32 Rename a few attributes/methods to make a little more sense.
Thibaut Girka <thib@sitedethib.com>
parents: 304
diff changeset
36 self.boss_wait = False
97
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
37
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
38 self.instruction_pointer = 0
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
39
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
40
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
41 def run_iter(self):
284
91eb0afcb1e3 Fix time stop handling.
Thibaut Girka <thib@sitedethib.com>
parents: 283
diff changeset
42 if not self._game.boss:
306
52d791bb7c32 Rename a few attributes/methods to make a little more sense.
Thibaut Girka <thib@sitedethib.com>
parents: 304
diff changeset
43 self.boss_wait = False
284
91eb0afcb1e3 Fix time stop handling.
Thibaut Girka <thib@sitedethib.com>
parents: 283
diff changeset
44
97
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
45 while True:
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
46 try:
372
704bea2e4360 Use a future-proof ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 365
diff changeset
47 frame, sub, instr_type, args = self._main[self.instruction_pointer]
97
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
48 except IndexError:
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
49 break
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
50
286
4838e9bab0f9 Implement dialogs (MSG files).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 284
diff changeset
51 # The msg_wait instruction stops the reading of the ECL, not just the frame incrementation.
306
52d791bb7c32 Rename a few attributes/methods to make a little more sense.
Thibaut Girka <thib@sitedethib.com>
parents: 304
diff changeset
52 if frame > self.frame or self._game.msg_wait or self.boss_wait:
97
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
53 break
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
54 else:
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
55 self.instruction_pointer += 1
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
56
180
5a1533677a9a Freeze time during spellcards
Thibaut Girka <thib@sitedethib.com>
parents: 178
diff changeset
57 if frame == self.frame:
97
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
58 try:
376
69ec72b990a4 Support more than one version of a vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 372
diff changeset
59 callback = self.handlers[instr_type]
97
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
60 except KeyError:
575
e4c9eafab6d0 Don’t log every instruction executed, nobody is interested in that, and demote unhandled opcodes to debug.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 564
diff changeset
61 logger.debug('[%d - %04d] unhandled main opcode %d (args: %r)',
e4c9eafab6d0 Don’t log every instruction executed, nobody is interested in that, and demote unhandled opcodes to debug.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 564
diff changeset
62 id(self), self.frame, instr_type, args)
97
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
63 else:
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
64 callback(self, sub, instr_type, *args)
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
65
306
52d791bb7c32 Rename a few attributes/methods to make a little more sense.
Thibaut Girka <thib@sitedethib.com>
parents: 304
diff changeset
66 if not (self._game.msg_wait or self.boss_wait):
180
5a1533677a9a Freeze time during spellcards
Thibaut Girka <thib@sitedethib.com>
parents: 178
diff changeset
67 self.frame += 1
5a1533677a9a Freeze time during spellcards
Thibaut Girka <thib@sitedethib.com>
parents: 178
diff changeset
68
97
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
69
171
2f3665a77f11 Add support for the last unknown value of the enemy spawning.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 169
diff changeset
70 def _pop_enemy(self, sub, instr_type, x, y, z, life, bonus_dropped, die_score):
140
a9d46c4b5764 Fix move_to (handle variables) and spawn_enemy
Thibaut Girka <thib@sitedethib.com>
parents: 134
diff changeset
71 if instr_type & 4:
a9d46c4b5764 Fix move_to (handle variables) and spawn_enemy
Thibaut Girka <thib@sitedethib.com>
parents: 134
diff changeset
72 if x < -990: #102h.exe@0x411820
151
5cf927cbd9c5 Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents: 150
diff changeset
73 x = self._game.prng.rand_double() * 368
140
a9d46c4b5764 Fix move_to (handle variables) and spawn_enemy
Thibaut Girka <thib@sitedethib.com>
parents: 134
diff changeset
74 if y < -990: #102h.exe@0x41184b
151
5cf927cbd9c5 Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents: 150
diff changeset
75 y = self._game.prng.rand_double() * 416
140
a9d46c4b5764 Fix move_to (handle variables) and spawn_enemy
Thibaut Girka <thib@sitedethib.com>
parents: 134
diff changeset
76 if z < -990: #102h.exe@0x411881
270
7a9135b88853 Partially fix some of Flandre's spellcards.
Thibaut Girka <thib@sitedethib.com>
parents: 269
diff changeset
77 z = self._game.prng.rand_double() * 800
316
f0be7ea62330 Fix a bug with ECL instruction 96, and fix overall ECL handling.
Thibaut Girka <thib@sitedethib.com>
parents: 313
diff changeset
78 enemy = self._game.new_enemy((x, y, z), life, instr_type,
f0be7ea62330 Fix a bug with ECL instruction 96, and fix overall ECL handling.
Thibaut Girka <thib@sitedethib.com>
parents: 313
diff changeset
79 bonus_dropped, die_score)
372
704bea2e4360 Use a future-proof ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 365
diff changeset
80 enemy.process = ECLRunner(self._subs, sub, enemy, self._game, self._pop_enemy) #TODO
316
f0be7ea62330 Fix a bug with ECL instruction 96, and fix overall ECL handling.
Thibaut Girka <thib@sitedethib.com>
parents: 313
diff changeset
81 enemy.process.run_iteration()
140
a9d46c4b5764 Fix move_to (handle variables) and spawn_enemy
Thibaut Girka <thib@sitedethib.com>
parents: 134
diff changeset
82
a9d46c4b5764 Fix move_to (handle variables) and spawn_enemy
Thibaut Girka <thib@sitedethib.com>
parents: 134
diff changeset
83
97
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
84 @instruction(0)
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
85 @instruction(2)
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
86 @instruction(4)
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
87 @instruction(6)
171
2f3665a77f11 Add support for the last unknown value of the enemy spawning.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 169
diff changeset
88 def pop_enemy(self, sub, instr_type, x, y, z, life, bonus_dropped, die_score):
151
5cf927cbd9c5 Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents: 150
diff changeset
89 if self._game.boss:
97
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
90 return
171
2f3665a77f11 Add support for the last unknown value of the enemy spawning.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 169
diff changeset
91 self._pop_enemy(sub, instr_type, x, y, z, life, bonus_dropped, die_score)
97
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
92
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
93
286
4838e9bab0f9 Implement dialogs (MSG files).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 284
diff changeset
94 @instruction(8)
4838e9bab0f9 Implement dialogs (MSG files).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 284
diff changeset
95 def call_msg(self, sub, instr_type):
4838e9bab0f9 Implement dialogs (MSG files).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 284
diff changeset
96 self._game.new_msg(sub)
4838e9bab0f9 Implement dialogs (MSG files).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 284
diff changeset
97
4838e9bab0f9 Implement dialogs (MSG files).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 284
diff changeset
98
4838e9bab0f9 Implement dialogs (MSG files).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 284
diff changeset
99 @instruction(9)
4838e9bab0f9 Implement dialogs (MSG files).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 284
diff changeset
100 def wait_msg(self, sub, instr_type):
4838e9bab0f9 Implement dialogs (MSG files).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 284
diff changeset
101 self._game.msg_wait = True
4838e9bab0f9 Implement dialogs (MSG files).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 284
diff changeset
102
4838e9bab0f9 Implement dialogs (MSG files).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 284
diff changeset
103
4838e9bab0f9 Implement dialogs (MSG files).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 284
diff changeset
104 @instruction(10)
4838e9bab0f9 Implement dialogs (MSG files).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 284
diff changeset
105 def resume_ecl(self, sub, instr_type, unk1, unk2):
545
bcff39c920ab Set boss mode directly from the enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 497
diff changeset
106 boss = self._game.boss
286
4838e9bab0f9 Implement dialogs (MSG files).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 284
diff changeset
107 self._game.msg_wait = False
497
3da7395f39e3 Make enemy callbacks programmables.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
108 if not boss.boss_callback:
286
4838e9bab0f9 Implement dialogs (MSG files).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 284
diff changeset
109 raise Exception #TODO
497
3da7395f39e3 Make enemy callbacks programmables.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
110 boss.boss_callback.fire()
286
4838e9bab0f9 Implement dialogs (MSG files).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 284
diff changeset
111
4838e9bab0f9 Implement dialogs (MSG files).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 284
diff changeset
112
283
b6c068c8f7f2 Fix ECL time flow. Spellcard do not stop time. Instruction 0xc does.
Thibaut Girka <thib@sitedethib.com>
parents: 279
diff changeset
113 @instruction(12)
306
52d791bb7c32 Rename a few attributes/methods to make a little more sense.
Thibaut Girka <thib@sitedethib.com>
parents: 304
diff changeset
114 def wait_for_boss_death(self, sub, instr_type):
52d791bb7c32 Rename a few attributes/methods to make a little more sense.
Thibaut Girka <thib@sitedethib.com>
parents: 304
diff changeset
115 self.boss_wait = True
283
b6c068c8f7f2 Fix ECL time flow. Spellcard do not stop time. Instruction 0xc does.
Thibaut Girka <thib@sitedethib.com>
parents: 279
diff changeset
116
b6c068c8f7f2 Fix ECL time flow. Spellcard do not stop time. Instruction 0xc does.
Thibaut Girka <thib@sitedethib.com>
parents: 279
diff changeset
117
97
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
118
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
119
590
e15672733c93 Switch to Python 3.x instead of 2.7.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 575
diff changeset
120 class ECLRunner(metaclass=MetaRegistry):
376
69ec72b990a4 Support more than one version of a vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 372
diff changeset
121 __slots__ = ('_subs', '_enemy', '_game', '_pop_enemy', 'variables', 'sub',
69ec72b990a4 Support more than one version of a vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 372
diff changeset
122 'frame', 'instruction_pointer', 'comparison_reg', 'stack',
69ec72b990a4 Support more than one version of a vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 372
diff changeset
123 'running', 'handlers')
23
444ac7bca7bc Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
124
372
704bea2e4360 Use a future-proof ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 365
diff changeset
125 def __init__(self, subs, sub, enemy, game, pop_enemy):
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
126 # Things not supposed to change
372
704bea2e4360 Use a future-proof ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 365
diff changeset
127 self._subs = subs
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
128 self._enemy = enemy
151
5cf927cbd9c5 Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents: 150
diff changeset
129 self._game = game
372
704bea2e4360 Use a future-proof ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 365
diff changeset
130 self._pop_enemy = pop_enemy
376
69ec72b990a4 Support more than one version of a vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 372
diff changeset
131 self.handlers = self._handlers[6]
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
132
316
f0be7ea62330 Fix a bug with ECL instruction 96, and fix overall ECL handling.
Thibaut Girka <thib@sitedethib.com>
parents: 313
diff changeset
133 self.running = True
f0be7ea62330 Fix a bug with ECL instruction 96, and fix overall ECL handling.
Thibaut Girka <thib@sitedethib.com>
parents: 313
diff changeset
134
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
135 # Things supposed to change (and be put in the stack)
47
1f1793e7ec8e Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
136 self.variables = [0, 0, 0, 0,
1f1793e7ec8e Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
137 0., 0., 0., 0.,
1f1793e7ec8e Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
138 0, 0, 0, 0]
51
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
139 self.comparison_reg = 0
307
5930b33a0370 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 306
diff changeset
140 self.switch_to_sub(sub)
23
444ac7bca7bc Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
141
47
1f1793e7ec8e Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
142 self.stack = []
23
444ac7bca7bc Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
143
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
144
364
b07e2f71f240 Empty ECL stack when calling a callback.
Thibaut Girka <thib@sitedethib.com>
parents: 362
diff changeset
145 def switch_to_sub(self, sub, preserve_stack=False):
b07e2f71f240 Empty ECL stack when calling a callback.
Thibaut Girka <thib@sitedethib.com>
parents: 362
diff changeset
146 if not preserve_stack:
b07e2f71f240 Empty ECL stack when calling a callback.
Thibaut Girka <thib@sitedethib.com>
parents: 362
diff changeset
147 self.stack = []
316
f0be7ea62330 Fix a bug with ECL instruction 96, and fix overall ECL handling.
Thibaut Girka <thib@sitedethib.com>
parents: 313
diff changeset
148 self.running = True
291
f6b8483a990d Refactor a bit and fix Rumia's disparition.
Thibaut Girka <thib@sitedethib.com>
parents: 287
diff changeset
149 self.frame = 0
f6b8483a990d Refactor a bit and fix Rumia's disparition.
Thibaut Girka <thib@sitedethib.com>
parents: 287
diff changeset
150 self.sub = sub
f6b8483a990d Refactor a bit and fix Rumia's disparition.
Thibaut Girka <thib@sitedethib.com>
parents: 287
diff changeset
151 self.instruction_pointer = 0
f6b8483a990d Refactor a bit and fix Rumia's disparition.
Thibaut Girka <thib@sitedethib.com>
parents: 287
diff changeset
152
f6b8483a990d Refactor a bit and fix Rumia's disparition.
Thibaut Girka <thib@sitedethib.com>
parents: 287
diff changeset
153
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
154 def run_iteration(self):
316
f0be7ea62330 Fix a bug with ECL instruction 96, and fix overall ECL handling.
Thibaut Girka <thib@sitedethib.com>
parents: 313
diff changeset
155 # Process script
f0be7ea62330 Fix a bug with ECL instruction 96, and fix overall ECL handling.
Thibaut Girka <thib@sitedethib.com>
parents: 313
diff changeset
156 while self.running:
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
157 try:
372
704bea2e4360 Use a future-proof ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 365
diff changeset
158 frame, instr_type, rank_mask, param_mask, args = self._subs[self.sub][self.instruction_pointer]
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
159 except IndexError:
316
f0be7ea62330 Fix a bug with ECL instruction 96, and fix overall ECL handling.
Thibaut Girka <thib@sitedethib.com>
parents: 313
diff changeset
160 self.running = False
f0be7ea62330 Fix a bug with ECL instruction 96, and fix overall ECL handling.
Thibaut Girka <thib@sitedethib.com>
parents: 313
diff changeset
161 break
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
162
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
163 if frame > self.frame:
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
164 break
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
165 else:
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
166 self.instruction_pointer += 1
57
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 55
diff changeset
167
151
5cf927cbd9c5 Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents: 150
diff changeset
168 if not rank_mask & (0x100 << self._game.rank):
57
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 55
diff changeset
169 continue
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 55
diff changeset
170
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
171 if frame == self.frame:
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
172 try:
376
69ec72b990a4 Support more than one version of a vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 372
diff changeset
173 callback = self.handlers[instr_type]
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
174 except KeyError:
575
e4c9eafab6d0 Don’t log every instruction executed, nobody is interested in that, and demote unhandled opcodes to debug.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 564
diff changeset
175 logger.debug('[%d %r - %04d] unhandled opcode %d (args: %r)',
e4c9eafab6d0 Don’t log every instruction executed, nobody is interested in that, and demote unhandled opcodes to debug.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 564
diff changeset
176 id(self), [self.sub] + [e[0] for e in self.stack],
e4c9eafab6d0 Don’t log every instruction executed, nobody is interested in that, and demote unhandled opcodes to debug.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 564
diff changeset
177 self.frame, instr_type, args)
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
178 else:
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
179 callback(self, *args)
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
180
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
181 self.frame += 1
316
f0be7ea62330 Fix a bug with ECL instruction 96, and fix overall ECL handling.
Thibaut Girka <thib@sitedethib.com>
parents: 313
diff changeset
182
47
1f1793e7ec8e Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
183
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
184 def _getval(self, value):
48
8353c33d53d4 Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents: 47
diff changeset
185 if -10012 <= value <= -10001:
8353c33d53d4 Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents: 47
diff changeset
186 return self.variables[int(-10001-value)]
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
187 elif -10025 <= value <= -10013:
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
188 if value == -10013:
151
5cf927cbd9c5 Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents: 150
diff changeset
189 return self._game.rank
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
190 elif value == -10014:
151
5cf927cbd9c5 Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents: 150
diff changeset
191 return self._game.difficulty
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
192 elif value == -10015:
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
193 return self._enemy.x
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
194 elif value == -10016:
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
195 return self._enemy.y
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
196 elif value == -10017:
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
197 return self._enemy.z
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
198 elif value == -10018:
79
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
199 player = self._enemy.select_player()
494
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 489
diff changeset
200 return player.x
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
201 elif value == -10019:
79
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
202 player = self._enemy.select_player()
494
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 489
diff changeset
203 return player.y
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
204 elif value == -10021:
564
a0fa01cd9f70 Make Enemy.get_angle able to target any Element, not only Player.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 545
diff changeset
205 player = self._enemy.select_player()
a0fa01cd9f70 Make Enemy.get_angle able to target any Element, not only Player.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 545
diff changeset
206 return self._enemy.get_angle(player)
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
207 elif value == -10022:
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
208 return self._enemy.frame
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
209 elif value == -10024:
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
210 return self._enemy.life
57
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 55
diff changeset
211 elif value == -10025:
494
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 489
diff changeset
212 return self._enemy.select_player().character #TODO
57
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 55
diff changeset
213 raise NotImplementedError(value) #TODO
48
8353c33d53d4 Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents: 47
diff changeset
214 else:
8353c33d53d4 Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents: 47
diff changeset
215 return value
8353c33d53d4 Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents: 47
diff changeset
216
8353c33d53d4 Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents: 47
diff changeset
217
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
218 def _setval(self, variable_id, value):
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
219 if -10012 <= variable_id <= -10001:
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
220 self.variables[int(-10001-variable_id)] = value
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
221 elif -10025 <= variable_id <= -10013:
55
de358a7684c8 Fix a few bugs
Thibaut Girka <thib@sitedethib.com>
parents: 53
diff changeset
222 if variable_id == -10015:
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
223 self._enemy.x = value
55
de358a7684c8 Fix a few bugs
Thibaut Girka <thib@sitedethib.com>
parents: 53
diff changeset
224 elif variable_id == -10016:
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
225 self._enemy.y = value
55
de358a7684c8 Fix a few bugs
Thibaut Girka <thib@sitedethib.com>
parents: 53
diff changeset
226 elif variable_id == -10017:
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
227 self._enemy.z = value
55
de358a7684c8 Fix a few bugs
Thibaut Girka <thib@sitedethib.com>
parents: 53
diff changeset
228 elif variable_id == -10022:
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
229 self._enemy.frame = value
55
de358a7684c8 Fix a few bugs
Thibaut Girka <thib@sitedethib.com>
parents: 53
diff changeset
230 elif variable_id == -10024:
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
231 self._enemy.life = value
55
de358a7684c8 Fix a few bugs
Thibaut Girka <thib@sitedethib.com>
parents: 53
diff changeset
232 else:
de358a7684c8 Fix a few bugs
Thibaut Girka <thib@sitedethib.com>
parents: 53
diff changeset
233 raise IndexError #TODO: proper exception
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
234 else:
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
235 raise IndexError #TODO: proper exception
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
236
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
237
51
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
238 @instruction(0)
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
239 def noop(self):
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
240 pass #TODO: Really?
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
241
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
242
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
243 @instruction(1)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
244 def destroy(self, arg):
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
245 #TODO: arg?
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 302
diff changeset
246 self._enemy.removed = True
48
8353c33d53d4 Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents: 47
diff changeset
247
8353c33d53d4 Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents: 47
diff changeset
248
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
249 @instruction(2)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
250 def relative_jump(self, frame, instruction_pointer):
52
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 51
diff changeset
251 """Jumps to a relative offset in the same subroutine.
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 51
diff changeset
252
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 51
diff changeset
253 Warning: the relative offset has been translated to an instruction pointer
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 51
diff changeset
254 by the ECL parsing code (see pytouhou.formats.ecl).
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 51
diff changeset
255 """
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
256 self.frame, self.instruction_pointer = frame, instruction_pointer
48
8353c33d53d4 Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents: 47
diff changeset
257
8353c33d53d4 Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents: 47
diff changeset
258
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
259 @instruction(3)
53
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
260 def relative_jump_ex(self, frame, instruction_pointer, variable_id):
52
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 51
diff changeset
261 """If the given variable is non-zero, decrease it by 1 and jump to a
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 51
diff changeset
262 relative offset in the same subroutine.
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 51
diff changeset
263
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 51
diff changeset
264 Warning: the relative offset has been translated to an instruction pointer
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 51
diff changeset
265 by the ECL parsing code (see pytouhou.formats.ecl).
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 51
diff changeset
266 """
91
f7525fa66bb0 Fix ECL instruction 3
Thibaut Girka <thib@sitedethib.com>
parents: 87
diff changeset
267 counter_value = self._getval(variable_id) - 1
f7525fa66bb0 Fix ECL instruction 3
Thibaut Girka <thib@sitedethib.com>
parents: 87
diff changeset
268 if counter_value > 0:
f7525fa66bb0 Fix ECL instruction 3
Thibaut Girka <thib@sitedethib.com>
parents: 87
diff changeset
269 self._setval(variable_id, counter_value)
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
270 self.frame, self.instruction_pointer = frame, instruction_pointer
47
1f1793e7ec8e Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
271
1f1793e7ec8e Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
272
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
273 @instruction(4)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
274 @instruction(5)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
275 def set_variable(self, variable_id, value):
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
276 self._setval(variable_id, self._getval(value))
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
277
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
278
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
279 @instruction(6)
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
280 def set_random_int(self, variable_id, maxval):
63
8527fe640844 Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 62
diff changeset
281 """Set the specified variable to a random int in the [0, maxval) range.
52
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 51
diff changeset
282 """
151
5cf927cbd9c5 Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents: 150
diff changeset
283 self._setval(variable_id, int(self._getval(maxval) * self._game.prng.rand_double()))
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
284
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
285
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
286 @instruction(8)
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
287 def set_random_float(self, variable_id, maxval):
52
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 51
diff changeset
288 """Set the specified variable to a random float in [0, maxval) range.
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 51
diff changeset
289 """
151
5cf927cbd9c5 Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents: 150
diff changeset
290 self._setval(variable_id, self._getval(maxval) * self._game.prng.rand_double())
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
291
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
292
59
4fe37a620b22 Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents: 58
diff changeset
293 @instruction(9)
144
cadfc5e5ad7a Fix a stupid inversion of properties.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 140
diff changeset
294 def set_random_float2(self, variable_id, amp, minval):
151
5cf927cbd9c5 Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents: 150
diff changeset
295 self._setval(variable_id, self._getval(minval) + self._getval(amp) * self._game.prng.rand_double())
59
4fe37a620b22 Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents: 58
diff changeset
296
4fe37a620b22 Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents: 58
diff changeset
297
75
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
298 @instruction(10)
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
299 def store_x(self, variable_id):
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
300 self._setval(variable_id, self._enemy.x)
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
301
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
302
63
8527fe640844 Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 62
diff changeset
303 @instruction(14)
65
0efec109f798 Merge compare and substract functions, remove dangerous casts and add comments about differences with the original engine.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 64
diff changeset
304 @instruction(21)
0efec109f798 Merge compare and substract functions, remove dangerous casts and add comments about differences with the original engine.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 64
diff changeset
305 def substract(self, variable_id, a, b):
0efec109f798 Merge compare and substract functions, remove dangerous casts and add comments about differences with the original engine.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 64
diff changeset
306 #TODO: 14 takes only ints and 21 only floats.
0efec109f798 Merge compare and substract functions, remove dangerous casts and add comments about differences with the original engine.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 64
diff changeset
307 # The original engine dereferences the variables in the type it waits for, so this isn't exactly the correct implementation, but the data don't contain such case.
0efec109f798 Merge compare and substract functions, remove dangerous casts and add comments about differences with the original engine.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 64
diff changeset
308 self._setval(variable_id, self._getval(a) - self._getval(b))
63
8527fe640844 Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 62
diff changeset
309
8527fe640844 Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 62
diff changeset
310
87
fda176f07d6d Fix add_int
Thibaut Girka <thib@sitedethib.com>
parents: 83
diff changeset
311 @instruction(13)
fda176f07d6d Fix add_int
Thibaut Girka <thib@sitedethib.com>
parents: 83
diff changeset
312 @instruction(20)
fda176f07d6d Fix add_int
Thibaut Girka <thib@sitedethib.com>
parents: 83
diff changeset
313 def add(self, variable_id, a, b):
fda176f07d6d Fix add_int
Thibaut Girka <thib@sitedethib.com>
parents: 83
diff changeset
314 #TODO: 13 takes only ints and 20 only floats.
fda176f07d6d Fix add_int
Thibaut Girka <thib@sitedethib.com>
parents: 83
diff changeset
315 # The original engine dereferences the variables in the type it waits for, so this isn't exactly the correct implementation, but the data don't contain such case.
fda176f07d6d Fix add_int
Thibaut Girka <thib@sitedethib.com>
parents: 83
diff changeset
316 self._setval(variable_id, self._getval(a) + self._getval(b))
fda176f07d6d Fix add_int
Thibaut Girka <thib@sitedethib.com>
parents: 83
diff changeset
317
fda176f07d6d Fix add_int
Thibaut Girka <thib@sitedethib.com>
parents: 83
diff changeset
318
63
8527fe640844 Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 62
diff changeset
319 @instruction(15)
8527fe640844 Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 62
diff changeset
320 def multiply_int(self, variable_id, a, b):
65
0efec109f798 Merge compare and substract functions, remove dangerous casts and add comments about differences with the original engine.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 64
diff changeset
321 #TODO: takes only ints.
0efec109f798 Merge compare and substract functions, remove dangerous casts and add comments about differences with the original engine.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 64
diff changeset
322 self._setval(variable_id, self._getval(a) * self._getval(b))
63
8527fe640844 Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 62
diff changeset
323
8527fe640844 Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 62
diff changeset
324
8527fe640844 Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 62
diff changeset
325 @instruction(16)
8527fe640844 Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 62
diff changeset
326 def divide_int(self, variable_id, a, b):
65
0efec109f798 Merge compare and substract functions, remove dangerous casts and add comments about differences with the original engine.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 64
diff changeset
327 #TODO: takes only ints.
0efec109f798 Merge compare and substract functions, remove dangerous casts and add comments about differences with the original engine.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 64
diff changeset
328 self._setval(variable_id, self._getval(a) // self._getval(b))
63
8527fe640844 Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 62
diff changeset
329
8527fe640844 Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 62
diff changeset
330
8527fe640844 Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 62
diff changeset
331 @instruction(17)
8527fe640844 Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 62
diff changeset
332 def modulo(self, variable_id, a, b):
65
0efec109f798 Merge compare and substract functions, remove dangerous casts and add comments about differences with the original engine.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 64
diff changeset
333 self._setval(variable_id, self._getval(a) % self._getval(b))
63
8527fe640844 Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 62
diff changeset
334
8527fe640844 Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 62
diff changeset
335
96
54929d495654 Handle ECL instruction 18
Thibaut Girka <thib@sitedethib.com>
parents: 95
diff changeset
336 @instruction(18)
54929d495654 Handle ECL instruction 18
Thibaut Girka <thib@sitedethib.com>
parents: 95
diff changeset
337 def increment(self, variable_id):
54929d495654 Handle ECL instruction 18
Thibaut Girka <thib@sitedethib.com>
parents: 95
diff changeset
338 self._setval(variable_id, self._getval(variable_id) + 1)
54929d495654 Handle ECL instruction 18
Thibaut Girka <thib@sitedethib.com>
parents: 95
diff changeset
339
54929d495654 Handle ECL instruction 18
Thibaut Girka <thib@sitedethib.com>
parents: 95
diff changeset
340
63
8527fe640844 Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 62
diff changeset
341 @instruction(23)
8527fe640844 Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 62
diff changeset
342 def divide_float(self, variable_id, a, b):
65
0efec109f798 Merge compare and substract functions, remove dangerous casts and add comments about differences with the original engine.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 64
diff changeset
343 #TODO: takes only floats.
63
8527fe640844 Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 62
diff changeset
344 self._setval(variable_id, self._getval(a) / self._getval(b))
8527fe640844 Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 62
diff changeset
345
8527fe640844 Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 62
diff changeset
346
77
6fa6d74a049a Handle a new ECL instruction, and add some names.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 76
diff changeset
347 @instruction(25)
6fa6d74a049a Handle a new ECL instruction, and add some names.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 76
diff changeset
348 def get_direction(self, variable_id, x1, y1, x2, y2):
6fa6d74a049a Handle a new ECL instruction, and add some names.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 76
diff changeset
349 #TODO: takes only floats.
147
a61c96265779 Fix a crash with ECL instruction 25
Thibaut Girka <thib@sitedethib.com>
parents: 144
diff changeset
350 self._setval(variable_id, atan2(self._getval(y2) - self._getval(y1), self._getval(x2) - self._getval(x1)))
77
6fa6d74a049a Handle a new ECL instruction, and add some names.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 76
diff changeset
351
6fa6d74a049a Handle a new ECL instruction, and add some names.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 76
diff changeset
352
155
ed86bec43b93 Implement two new instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 154
diff changeset
353 @instruction(26)
ed86bec43b93 Implement two new instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 154
diff changeset
354 def float_to_unit_circle(self, variable_id):
ed86bec43b93 Implement two new instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 154
diff changeset
355 #TODO: takes only floats.
ed86bec43b93 Implement two new instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 154
diff changeset
356 self._setval(variable_id, (self._getval(variable_id) + pi) % (2*pi) - pi)
ed86bec43b93 Implement two new instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 154
diff changeset
357
ed86bec43b93 Implement two new instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 154
diff changeset
358
51
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
359 @instruction(27)
63
8527fe640844 Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 62
diff changeset
360 @instruction(28)
65
0efec109f798 Merge compare and substract functions, remove dangerous casts and add comments about differences with the original engine.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 64
diff changeset
361 def compare(self, a, b):
0efec109f798 Merge compare and substract functions, remove dangerous casts and add comments about differences with the original engine.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 64
diff changeset
362 #TODO: 27 takes only ints and 28 only floats.
51
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
363 a, b = self._getval(a), self._getval(b)
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
364 if a < b:
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
365 self.comparison_reg = -1
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
366 elif a == b:
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
367 self.comparison_reg = 0
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
368 else:
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
369 self.comparison_reg = 1
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
370
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
371
64
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
372 @instruction(29)
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
373 def relative_jump_if_lower_than(self, frame, instruction_pointer):
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
374 if self.comparison_reg == -1:
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
375 self.relative_jump(frame, instruction_pointer)
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
376
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
377
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
378 @instruction(30)
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
379 def relative_jump_if_lower_or_equal(self, frame, instruction_pointer):
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
380 if self.comparison_reg != 1:
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
381 self.relative_jump(frame, instruction_pointer)
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
382
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
383
51
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
384 @instruction(31)
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
385 def relative_jump_if_equal(self, frame, instruction_pointer):
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
386 if self.comparison_reg == 0:
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
387 self.relative_jump(frame, instruction_pointer)
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
388
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
389
64
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
390 @instruction(32)
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
391 def relative_jump_if_greater_than(self, frame, instruction_pointer):
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
392 if self.comparison_reg == 1:
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
393 self.relative_jump(frame, instruction_pointer)
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
394
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
395
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
396 @instruction(33)
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
397 def relative_jump_if_greater_or_equal(self, frame, instruction_pointer):
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
398 if self.comparison_reg != -1:
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
399 self.relative_jump(frame, instruction_pointer)
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
400
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
401
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
402 @instruction(34)
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
403 def relative_jump_if_not_equal(self, frame, instruction_pointer):
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
404 if self.comparison_reg != 0:
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
405 self.relative_jump(frame, instruction_pointer)
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
406
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
407
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
408 @instruction(35)
47
1f1793e7ec8e Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
409 def call(self, sub, param1, param2):
1f1793e7ec8e Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
410 self.stack.append((self.sub, self.frame, self.instruction_pointer,
195
52c0b9399413 Fix ECL function calls... again
Thibaut Girka <thib@sitedethib.com>
parents: 194
diff changeset
411 list(self.variables), self.comparison_reg))
185
68e6d3faeee6 Don’t reinitialize variables when another sub is called.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 183
diff changeset
412 self.variables[0] = param1
194
efa847ee8b3c Fix ECL function calls
Thibaut Girka <thib@sitedethib.com>
parents: 193
diff changeset
413 self.variables[4] = param2
364
b07e2f71f240 Empty ECL stack when calling a callback.
Thibaut Girka <thib@sitedethib.com>
parents: 362
diff changeset
414 self.switch_to_sub(sub, preserve_stack=True)
47
1f1793e7ec8e Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
415
1f1793e7ec8e Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
416
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
417 @instruction(36)
47
1f1793e7ec8e Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
418 def ret(self):
51
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
419 self.sub, self.frame, self.instruction_pointer, self.variables, self.comparison_reg = self.stack.pop()
47
1f1793e7ec8e Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
420
1f1793e7ec8e Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
421
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
422 @instruction(39)
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
423 def call_if_equal(self, sub, param1, param2, a, b):
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
424 if self._getval(a) == self._getval(b):
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
425 self.call(sub, param1, param2)
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
426
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
427
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
428 @instruction(43)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
429 def set_pos(self, x, y, z):
74
adac26098408 Handle variables in set_pos instruction (Daiyousei...)
Thibaut Girka <thib@sitedethib.com>
parents: 70
diff changeset
430 self._enemy.set_pos(self._getval(x), self._getval(y), self._getval(z))
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
431
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
432
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
433 @instruction(45)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
434 def set_angle_speed(self, angle, speed):
251
4b549894ef6b Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents: 250
diff changeset
435 self._enemy.update_mode = 0
270
7a9135b88853 Partially fix some of Flandre's spellcards.
Thibaut Girka <thib@sitedethib.com>
parents: 269
diff changeset
436 self._enemy.angle, self._enemy.speed = self._getval(angle), self._getval(speed)
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
437
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
438
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
439 @instruction(46)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
440 def set_rotation_speed(self, speed):
251
4b549894ef6b Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents: 250
diff changeset
441 self._enemy.update_mode = 0
295
2a60642e8892 Fix Remilia’s bat form.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 291
diff changeset
442 self._enemy.rotation_speed = self._getval(speed)
23
444ac7bca7bc Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
443
444ac7bca7bc Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
444
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
445 @instruction(47)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
446 def set_speed(self, speed):
251
4b549894ef6b Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents: 250
diff changeset
447 self._enemy.update_mode = 0
295
2a60642e8892 Fix Remilia’s bat form.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 291
diff changeset
448 self._enemy.speed = self._getval(speed)
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
449
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
450
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
451 @instruction(48)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
452 def set_acceleration(self, acceleration):
251
4b549894ef6b Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents: 250
diff changeset
453 self._enemy.update_mode = 0
295
2a60642e8892 Fix Remilia’s bat form.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 291
diff changeset
454 self._enemy.acceleration = self._getval(acceleration)
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
455
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
456
70
7c1f20407b3e Add set_random_angle support
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
457 @instruction(49)
7c1f20407b3e Add set_random_angle support
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
458 def set_random_angle(self, min_angle, max_angle):
151
5cf927cbd9c5 Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents: 150
diff changeset
459 angle = self._game.prng.rand_double() * (max_angle - min_angle) + min_angle
70
7c1f20407b3e Add set_random_angle support
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
460 self._enemy.angle = angle
7c1f20407b3e Add set_random_angle support
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
461
7c1f20407b3e Add set_random_angle support
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
462
51
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
463 @instruction(50)
70
7c1f20407b3e Add set_random_angle support
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
464 def set_random_angle_ex(self, min_angle, max_angle):
59
4fe37a620b22 Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents: 58
diff changeset
465 if self._enemy.screen_box:
4fe37a620b22 Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents: 58
diff changeset
466 minx, miny, maxx, maxy = self._enemy.screen_box
4fe37a620b22 Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents: 58
diff changeset
467 else:
4fe37a620b22 Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents: 58
diff changeset
468 minx, miny, maxx, maxy = (0., 0., 0., 0.)
4fe37a620b22 Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents: 58
diff changeset
469
151
5cf927cbd9c5 Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents: 150
diff changeset
470 angle = self._game.prng.rand_double() * (max_angle - min_angle) + min_angle
59
4fe37a620b22 Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents: 58
diff changeset
471 sa, ca = sin(angle), cos(angle)
4fe37a620b22 Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents: 58
diff changeset
472
4fe37a620b22 Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents: 58
diff changeset
473 if self._enemy.x > maxx - 96.0:
4fe37a620b22 Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents: 58
diff changeset
474 ca = -abs(ca)
4fe37a620b22 Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents: 58
diff changeset
475 elif self._enemy.x < minx + 96.0:
4fe37a620b22 Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents: 58
diff changeset
476 ca = abs(ca)
4fe37a620b22 Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents: 58
diff changeset
477
4fe37a620b22 Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents: 58
diff changeset
478 if self._enemy.y > maxy - 48.0:
4fe37a620b22 Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents: 58
diff changeset
479 sa = -abs(sa)
4fe37a620b22 Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents: 58
diff changeset
480 elif self._enemy.y < miny + 48.0:
4fe37a620b22 Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents: 58
diff changeset
481 sa = abs(sa)
4fe37a620b22 Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents: 58
diff changeset
482 self._enemy.angle = atan2(sa, ca)
51
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
483
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
484
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
485 @instruction(51)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
486 def target_player(self, unknown, speed):
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
487 #TODO: unknown
564
a0fa01cd9f70 Make Enemy.get_angle able to target any Element, not only Player.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 545
diff changeset
488 player = self._enemy.select_player()
a0fa01cd9f70 Make Enemy.get_angle able to target any Element, not only Player.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 545
diff changeset
489
251
4b549894ef6b Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents: 250
diff changeset
490 self._enemy.update_mode = 0
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
491 self._enemy.speed = speed
564
a0fa01cd9f70 Make Enemy.get_angle able to target any Element, not only Player.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 545
diff changeset
492 self._enemy.angle = self._enemy.get_angle(player)
43
7195aaf95f6e Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents: 42
diff changeset
493
7195aaf95f6e Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents: 42
diff changeset
494
183
b6d7ce644f34 Implement two new ECL instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 182
diff changeset
495 @instruction(52)
b6d7ce644f34 Implement two new ECL instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 182
diff changeset
496 def move_in_decel(self, duration, angle, speed):
b6d7ce644f34 Implement two new ECL instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 182
diff changeset
497 self._enemy.angle, self._enemy.speed = angle, speed
b6d7ce644f34 Implement two new ECL instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 182
diff changeset
498 self._enemy.stop_in(duration, lambda x: 2. * x - x ** 2)
b6d7ce644f34 Implement two new ECL instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 182
diff changeset
499
b6d7ce644f34 Implement two new ECL instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 182
diff changeset
500
76
f305c0e406d6 Handle all move_to_* ECL instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 75
diff changeset
501 @instruction(56)
f305c0e406d6 Handle all move_to_* ECL instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 75
diff changeset
502 def move_to_linear(self, duration, x, y, z):
140
a9d46c4b5764 Fix move_to (handle variables) and spawn_enemy
Thibaut Girka <thib@sitedethib.com>
parents: 134
diff changeset
503 self._enemy.move_to(duration,
a9d46c4b5764 Fix move_to (handle variables) and spawn_enemy
Thibaut Girka <thib@sitedethib.com>
parents: 134
diff changeset
504 self._getval(x), self._getval(y), self._getval(z),
489
59bd29568753 Remove identity lambda for interpolators, improves performances slightly.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 471
diff changeset
505 None)
76
f305c0e406d6 Handle all move_to_* ECL instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 75
diff changeset
506
f305c0e406d6 Handle all move_to_* ECL instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 75
diff changeset
507
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
508 @instruction(57)
76
f305c0e406d6 Handle all move_to_* ECL instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 75
diff changeset
509 def move_to_decel(self, duration, x, y, z):
140
a9d46c4b5764 Fix move_to (handle variables) and spawn_enemy
Thibaut Girka <thib@sitedethib.com>
parents: 134
diff changeset
510 self._enemy.move_to(duration,
a9d46c4b5764 Fix move_to (handle variables) and spawn_enemy
Thibaut Girka <thib@sitedethib.com>
parents: 134
diff changeset
511 self._getval(x), self._getval(y), self._getval(z),
a9d46c4b5764 Fix move_to (handle variables) and spawn_enemy
Thibaut Girka <thib@sitedethib.com>
parents: 134
diff changeset
512 lambda x: 2. * x - x ** 2)
62
1f591adcea04 Fix animation determination (ins_98 stuff) and some interpolation functions
Thibaut Girka <thib@sitedethib.com>
parents: 59
diff changeset
513
1f591adcea04 Fix animation determination (ins_98 stuff) and some interpolation functions
Thibaut Girka <thib@sitedethib.com>
parents: 59
diff changeset
514
1f591adcea04 Fix animation determination (ins_98 stuff) and some interpolation functions
Thibaut Girka <thib@sitedethib.com>
parents: 59
diff changeset
515 @instruction(59)
76
f305c0e406d6 Handle all move_to_* ECL instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 75
diff changeset
516 def move_to_accel(self, duration, x, y, z):
140
a9d46c4b5764 Fix move_to (handle variables) and spawn_enemy
Thibaut Girka <thib@sitedethib.com>
parents: 134
diff changeset
517 self._enemy.move_to(duration,
a9d46c4b5764 Fix move_to (handle variables) and spawn_enemy
Thibaut Girka <thib@sitedethib.com>
parents: 134
diff changeset
518 self._getval(x), self._getval(y), self._getval(z),
a9d46c4b5764 Fix move_to (handle variables) and spawn_enemy
Thibaut Girka <thib@sitedethib.com>
parents: 134
diff changeset
519 lambda x: x ** 2)
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
520
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
521
57
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 55
diff changeset
522 @instruction(61)
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 55
diff changeset
523 def stop_in(self, duration):
489
59bd29568753 Remove identity lambda for interpolators, improves performances slightly.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 471
diff changeset
524 self._enemy.stop_in(duration, None)
75
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
525
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
526
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
527 @instruction(63)
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
528 def stop_in_accel(self, duration):
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
529 self._enemy.stop_in(duration, lambda x: 1. - x)
57
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 55
diff changeset
530
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 55
diff changeset
531
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
532 @instruction(65)
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
533 def set_screen_box(self, xmin, ymin, xmax, ymax):
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
534 self._enemy.screen_box = xmin, ymin, xmax, ymax
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
535
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
536
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
537 @instruction(66)
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
538 def clear_screen_box(self):
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
539 self._enemy.screen_box = None
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
540
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
541
57
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 55
diff changeset
542 @instruction(67)
82
de48213a02bf Fix a few things
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
543 def set_bullet_attributes1(self, anim, sprite_idx_offset, bullets_per_shot,
79
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
544 number_of_shots, speed, speed2, launch_angle,
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
545 angle, flags):
82
de48213a02bf Fix a few things
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
546 self._enemy.set_bullet_attributes(67, anim,
de48213a02bf Fix a few things
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
547 self._getval(sprite_idx_offset),
79
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
548 self._getval(bullets_per_shot),
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
549 self._getval(number_of_shots),
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
550 self._getval(speed),
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
551 self._getval(speed2),
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
552 self._getval(launch_angle),
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
553 self._getval(angle),
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
554 flags)
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
555
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
556
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
557 @instruction(68)
82
de48213a02bf Fix a few things
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
558 def set_bullet_attributes2(self, anim, sprite_idx_offset, bullets_per_shot,
79
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
559 number_of_shots, speed, speed2, launch_angle,
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
560 angle, flags):
82
de48213a02bf Fix a few things
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
561 self._enemy.set_bullet_attributes(68, anim,
de48213a02bf Fix a few things
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
562 self._getval(sprite_idx_offset),
79
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
563 self._getval(bullets_per_shot),
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
564 self._getval(number_of_shots),
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
565 self._getval(speed),
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
566 self._getval(speed2),
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
567 self._getval(launch_angle),
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
568 self._getval(angle),
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
569 flags)
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
570
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
571
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
572 @instruction(69)
82
de48213a02bf Fix a few things
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
573 def set_bullet_attributes3(self, anim, sprite_idx_offset, bullets_per_shot,
79
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
574 number_of_shots, speed, speed2, launch_angle,
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
575 angle, flags):
82
de48213a02bf Fix a few things
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
576 self._enemy.set_bullet_attributes(69, anim,
de48213a02bf Fix a few things
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
577 self._getval(sprite_idx_offset),
79
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
578 self._getval(bullets_per_shot),
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
579 self._getval(number_of_shots),
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
580 self._getval(speed),
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
581 self._getval(speed2),
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
582 self._getval(launch_angle),
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
583 self._getval(angle),
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
584 flags)
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
585
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
586
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
587 @instruction(70)
82
de48213a02bf Fix a few things
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
588 def set_bullet_attributes4(self, anim, sprite_idx_offset, bullets_per_shot,
79
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
589 number_of_shots, speed, speed2, launch_angle,
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
590 angle, flags):
82
de48213a02bf Fix a few things
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
591 self._enemy.set_bullet_attributes(70, anim,
de48213a02bf Fix a few things
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
592 self._getval(sprite_idx_offset),
79
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
593 self._getval(bullets_per_shot),
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
594 self._getval(number_of_shots),
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
595 self._getval(speed),
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
596 self._getval(speed2),
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
597 self._getval(launch_angle),
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
598 self._getval(angle),
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
599 flags)
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
600
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
601
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
602 @instruction(71)
82
de48213a02bf Fix a few things
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
603 def set_bullet_attributes5(self, anim, sprite_idx_offset, bullets_per_shot,
79
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
604 number_of_shots, speed, speed2, launch_angle,
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
605 angle, flags):
82
de48213a02bf Fix a few things
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
606 self._enemy.set_bullet_attributes(71, anim,
de48213a02bf Fix a few things
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
607 self._getval(sprite_idx_offset),
79
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
608 self._getval(bullets_per_shot),
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
609 self._getval(number_of_shots),
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
610 self._getval(speed),
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
611 self._getval(speed2),
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
612 self._getval(launch_angle),
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
613 self._getval(angle),
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
614 flags)
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
615
57
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 55
diff changeset
616
83
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
617 @instruction(74)
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
618 def set_bullet_attributes6(self, anim, sprite_idx_offset, bullets_per_shot,
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
619 number_of_shots, speed, speed2, launch_angle,
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
620 angle, flags):
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
621 #TODO
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
622 self._enemy.set_bullet_attributes(74, anim,
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
623 self._getval(sprite_idx_offset),
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
624 self._getval(bullets_per_shot),
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
625 self._getval(number_of_shots),
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
626 self._getval(speed),
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
627 self._getval(speed2),
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
628 self._getval(launch_angle),
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
629 self._getval(angle),
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
630 flags)
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
631
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
632
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
633 @instruction(75)
106
c7847bfed427 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 105
diff changeset
634 def set_bullet_attributes7(self, anim, sprite_idx_offset, bullets_per_shot,
83
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
635 number_of_shots, speed, speed2, launch_angle,
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
636 angle, flags):
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
637 #TODO
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
638 self._enemy.set_bullet_attributes(75, anim,
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
639 self._getval(sprite_idx_offset),
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
640 self._getval(bullets_per_shot),
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
641 self._getval(number_of_shots),
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
642 self._getval(speed),
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
643 self._getval(speed2),
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
644 self._getval(launch_angle),
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
645 self._getval(angle),
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
646 flags)
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
647
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
648
78
bcf965ede96c Fix/rename/comment a few things
Thibaut Girka <thib@sitedethib.com>
parents: 77
diff changeset
649 @instruction(76)
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
650 def set_bullet_interval(self, value):
182
20843875ad8f (Hopefully) use difficulty as it should.
Thibaut Girka <thib@sitedethib.com>
parents: 181
diff changeset
651 self._enemy.set_bullet_launch_interval(value)
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
652
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
653
78
bcf965ede96c Fix/rename/comment a few things
Thibaut Girka <thib@sitedethib.com>
parents: 77
diff changeset
654 @instruction(77)
bcf965ede96c Fix/rename/comment a few things
Thibaut Girka <thib@sitedethib.com>
parents: 77
diff changeset
655 def set_bullet_interval_ex(self, value):
329
1bb78c469f64 Fix difficulty influence on bullet launch interval, and fix instruction 77's rand usage
Thibaut Girka <thib@sitedethib.com>
parents: 320
diff changeset
656 self._enemy.set_bullet_launch_interval(value, self._game.prng.rand_uint32())
78
bcf965ede96c Fix/rename/comment a few things
Thibaut Girka <thib@sitedethib.com>
parents: 77
diff changeset
657
bcf965ede96c Fix/rename/comment a few things
Thibaut Girka <thib@sitedethib.com>
parents: 77
diff changeset
658
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
659 @instruction(78)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
660 def set_delay_attack(self):
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
661 self._enemy.delay_attack = True
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
662
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
663
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
664 @instruction(79)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
665 def set_no_delay_attack(self):
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
666 self._enemy.delay_attack = False
23
444ac7bca7bc Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
667
444ac7bca7bc Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
668
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
669 @instruction(81)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
670 def set_bullet_launch_offset(self, x, y, z):
134
e9ac3640280b Add support for enemy spawnling enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 128
diff changeset
671 self._enemy.bullet_launch_offset = (self._getval(x), self._getval(y))
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
672
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
673
79
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
674 @instruction(82)
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
675 def set_extended_bullet_attributes(self, *attributes):
102
ad9297e0fbf2 Handle variables in ECL instruction 82
Thibaut Girka <thib@sitedethib.com>
parents: 100
diff changeset
676 self._enemy.extended_bullet_attributes = tuple(self._getval(attr) for attr in attributes)
79
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
677
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
678
150
4f46717390aa Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents: 147
diff changeset
679 @instruction(83)
4f46717390aa Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents: 147
diff changeset
680 def change_bullets_into_star_items(self):
151
5cf927cbd9c5 Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents: 150
diff changeset
681 self._game.change_bullets_into_star_items()
150
4f46717390aa Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents: 147
diff changeset
682
4f46717390aa Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents: 147
diff changeset
683
274
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
684 @instruction(85)
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
685 def new_laser(self, laser_type, sprite_idx_offset, angle, speed,
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
686 start_offset, end_offset, max_length, width,
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
687 start_duration, duration, end_duration,
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
688 grazing_delay, grazing_extra_duration, unknown):
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
689 self._enemy.new_laser(85, laser_type, sprite_idx_offset, self._getval(angle), speed,
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
690 start_offset, end_offset, max_length, width,
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
691 start_duration, duration, end_duration,
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
692 grazing_delay, grazing_extra_duration, unknown)
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
693
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
694
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
695 @instruction(86)
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
696 def new_laser_towards_player(self, laser_type, sprite_idx_offset, angle, speed,
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
697 start_offset, end_offset, max_length, width,
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
698 start_duration, duration, end_duration,
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
699 grazing_delay, grazing_extra_duration, unknown):
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
700 self._enemy.new_laser(86, laser_type, sprite_idx_offset, self._getval(angle), speed,
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
701 start_offset, end_offset, max_length, width,
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
702 start_duration, duration, end_duration,
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
703 grazing_delay, grazing_extra_duration, unknown)
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
704
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
705
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
706 @instruction(87)
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
707 def set_upcoming_laser_id(self, laser_id):
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
708 self._enemy.current_laser_id = laser_id
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
709
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
710
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
711 @instruction(88)
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
712 def alter_laser_angle(self, laser_id, delta):
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
713 try:
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
714 laser = self._enemy.laser_by_id[laser_id]
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
715 except KeyError:
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
716 pass #TODO
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
717 else:
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
718 laser.angle += self._getval(delta)
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
719
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
720
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
721 @instruction(90)
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
722 def reposition_laser(self, laser_id, ox, oy, oz):
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
723 try:
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
724 laser = self._enemy.laser_by_id[laser_id]
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
725 except KeyError:
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
726 pass #TODO
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
727 else:
471
06f0eeb519bb Make Laser and Orb extension types, and use that where possible.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 457
diff changeset
728 laser.set_base_pos(self._enemy.x + ox, self._enemy.y + oy)
274
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
729
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
730
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
731 @instruction(92)
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
732 def cancel_laser(self, laser_id):
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
733 try:
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
734 laser = self._enemy.laser_by_id[laser_id]
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
735 except KeyError:
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
736 pass #TODO
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
737 else:
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
738 laser.cancel()
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
739
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 273
diff changeset
740
95
e2d8f2a56ea4 Handle ECL opcodes with string.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 93
diff changeset
741 @instruction(93)
276
754ff6452d7e Fix spellcard number 0.
Thibaut Girka <thib@sitedethib.com>
parents: 275
diff changeset
742 def set_spellcard(self, face, number, name):
95
e2d8f2a56ea4 Handle ECL opcodes with string.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 93
diff changeset
743 #TODO: display it on the game.
308
7a464291dd9d Fix difficulty modifiers within spellcards.
Thibaut Girka <thib@sitedethib.com>
parents: 307
diff changeset
744 self._enemy.difficulty_coeffs = (-.5, .5, 0, 0, 0, 0)
160
606468ab4f7b Clean up bullets when starting a spellcard
Thibaut Girka <thib@sitedethib.com>
parents: 159
diff changeset
745 self._game.change_bullets_into_star_items()
457
4ccc47828002 Display the name of a spellcard and the face of its invoker.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 445
diff changeset
746 self._game.spellcard = (number, name, face)
306
52d791bb7c32 Rename a few attributes/methods to make a little more sense.
Thibaut Girka <thib@sitedethib.com>
parents: 304
diff changeset
747 self._game.enable_spellcard_effect()
155
ed86bec43b93 Implement two new instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 154
diff changeset
748
ed86bec43b93 Implement two new instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 154
diff changeset
749
ed86bec43b93 Implement two new instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 154
diff changeset
750 @instruction(94)
ed86bec43b93 Implement two new instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 154
diff changeset
751 def end_spellcard(self):
ed86bec43b93 Implement two new instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 154
diff changeset
752 #TODO: return everything back to normal
ed86bec43b93 Implement two new instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 154
diff changeset
753 #TODO: give the spellcard bonus.
320
1a4ffdda8735 Cancel the bullets when a boss is killed and transfer them to the score.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 318
diff changeset
754 if self._game.spellcard is not None:
180
5a1533677a9a Freeze time during spellcards
Thibaut Girka <thib@sitedethib.com>
parents: 178
diff changeset
755 self._game.change_bullets_into_star_items()
5a1533677a9a Freeze time during spellcards
Thibaut Girka <thib@sitedethib.com>
parents: 178
diff changeset
756 self._game.spellcard = None
306
52d791bb7c32 Rename a few attributes/methods to make a little more sense.
Thibaut Girka <thib@sitedethib.com>
parents: 304
diff changeset
757 self._game.disable_spellcard_effect()
95
e2d8f2a56ea4 Handle ECL opcodes with string.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 93
diff changeset
758
e2d8f2a56ea4 Handle ECL opcodes with string.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 93
diff changeset
759
134
e9ac3640280b Add support for enemy spawnling enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 128
diff changeset
760 @instruction(95)
171
2f3665a77f11 Add support for the last unknown value of the enemy spawning.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 169
diff changeset
761 def pop_enemy(self, sub, x, y, z, life, bonus_dropped, die_score):
372
704bea2e4360 Use a future-proof ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 365
diff changeset
762 self._pop_enemy(sub, 0, self._getval(x),
704bea2e4360 Use a future-proof ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 365
diff changeset
763 self._getval(y),
704bea2e4360 Use a future-proof ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 365
diff changeset
764 self._getval(z),
704bea2e4360 Use a future-proof ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 365
diff changeset
765 life, bonus_dropped, die_score)
134
e9ac3640280b Add support for enemy spawnling enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 128
diff changeset
766
e9ac3640280b Add support for enemy spawnling enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 128
diff changeset
767
154
364935f6e313 Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 152
diff changeset
768 @instruction(96)
364935f6e313 Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 152
diff changeset
769 def kill_enemies(self):
359
130d258217f3 Fix crash in ECL's kill_enemies
Thibaut Girka <thib@sitedethib.com>
parents: 358
diff changeset
770 self._game.kill_enemies()
154
364935f6e313 Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 152
diff changeset
771
364935f6e313 Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 152
diff changeset
772
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
773 @instruction(97)
242
1d3c8c7473a2 Implement auxiliary animations of enemies like magic circles, and interruptions from ecl.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 224
diff changeset
774 def set_anim(self, script):
1d3c8c7473a2 Implement auxiliary animations of enemies like magic circles, and interruptions from ecl.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 224
diff changeset
775 self._enemy.set_anim(script)
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
776
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
777
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
778 @instruction(98)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
779 def set_multiple_anims(self, default, end_left, end_right, left, right):
295
2a60642e8892 Fix Remilia’s bat form.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 291
diff changeset
780 if left == -1:
2a60642e8892 Fix Remilia’s bat form.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 291
diff changeset
781 self._enemy.movement_dependant_sprites = None
2a60642e8892 Fix Remilia’s bat form.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 291
diff changeset
782 else:
2a60642e8892 Fix Remilia’s bat form.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 291
diff changeset
783 self._enemy.movement_dependant_sprites = end_left, end_right, left, right
2a60642e8892 Fix Remilia’s bat form.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 291
diff changeset
784 self._enemy.set_anim(default)
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
785
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
786
242
1d3c8c7473a2 Implement auxiliary animations of enemies like magic circles, and interruptions from ecl.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 224
diff changeset
787 @instruction(99)
1d3c8c7473a2 Implement auxiliary animations of enemies like magic circles, and interruptions from ecl.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 224
diff changeset
788 def set_aux_anm(self, number, script):
1d3c8c7473a2 Implement auxiliary animations of enemies like magic circles, and interruptions from ecl.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 224
diff changeset
789 self._enemy.set_aux_anm(number, script)
1d3c8c7473a2 Implement auxiliary animations of enemies like magic circles, and interruptions from ecl.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 224
diff changeset
790
1d3c8c7473a2 Implement auxiliary animations of enemies like magic circles, and interruptions from ecl.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 224
diff changeset
791
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
792 @instruction(100)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
793 def set_death_anim(self, sprite_index):
181
184196480f59 Don’t use the useless eff00.anm and implement particles (grazing, death, and more).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 180
diff changeset
794 self._enemy.death_anim = sprite_index
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
795
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
796
57
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 55
diff changeset
797 @instruction(101)
177
6e8653ff2b23 Fix boss mode and don’t suicide the boss when she just want to kill the other enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 171
diff changeset
798 def set_boss_mode(self, value):
6e8653ff2b23 Fix boss mode and don’t suicide the boss when she just want to kill the other enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 171
diff changeset
799 #TODO: if there are multiple boss, spawned by a 95,
6e8653ff2b23 Fix boss mode and don’t suicide the boss when she just want to kill the other enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 171
diff changeset
800 # only the last one has her life displayed,
6e8653ff2b23 Fix boss mode and don’t suicide the boss when she just want to kill the other enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 171
diff changeset
801 # but standard enemies are blocked only until any of them is killed.
6e8653ff2b23 Fix boss mode and don’t suicide the boss when she just want to kill the other enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 171
diff changeset
802 if value == 0:
545
bcff39c920ab Set boss mode directly from the enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 497
diff changeset
803 self._enemy.set_boss(True)
177
6e8653ff2b23 Fix boss mode and don’t suicide the boss when she just want to kill the other enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 171
diff changeset
804 elif value == -1:
545
bcff39c920ab Set boss mode directly from the enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 497
diff changeset
805 self._enemy.set_boss(False)
177
6e8653ff2b23 Fix boss mode and don’t suicide the boss when she just want to kill the other enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 171
diff changeset
806 else:
6e8653ff2b23 Fix boss mode and don’t suicide the boss when she just want to kill the other enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 171
diff changeset
807 raise Exception #TODO
57
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 55
diff changeset
808
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 55
diff changeset
809
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
810 @instruction(103)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
811 def set_hitbox(self, width, height, depth):
441
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 430
diff changeset
812 self._enemy.set_hitbox(width, height)
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
813
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
814
79
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
815 @instruction(104)
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
816 def set_collidable(self, collidable):
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
817 """Defines whether the enemy is “collidable”.
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
818 A collision between a collidable enemy and the player will kill the player.
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
819 """
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
820 self._enemy.collidable = bool(collidable & 1)
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
821
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
822
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
823 @instruction(105)
75
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
824 def set_damageable(self, damageable):
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
825 self._enemy.damageable = bool(damageable & 1)
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
826
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
827
343
94fdb6c782c1 Implement sfx for player and enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 329
diff changeset
828 @instruction(106)
94fdb6c782c1 Implement sfx for player and enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 329
diff changeset
829 def play_sound(self, index):
94fdb6c782c1 Implement sfx for player and enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 329
diff changeset
830 self._enemy.play_sound(index)
94fdb6c782c1 Implement sfx for player and enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 329
diff changeset
831
94fdb6c782c1 Implement sfx for player and enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 329
diff changeset
832
75
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
833 @instruction(107)
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
834 def set_death_flags(self, death_flags):
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
835 self._enemy.death_flags = death_flags
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
836
23
444ac7bca7bc Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
837
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
838 @instruction(108)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
839 def set_death_callback(self, sub):
497
3da7395f39e3 Make enemy callbacks programmables.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
840 self._enemy.death_callback.enable(self.switch_to_sub, (sub,))
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
841
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
842
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
843 @instruction(109)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
844 def memory_write(self, value, index):
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
845 if index == 0:
497
3da7395f39e3 Make enemy callbacks programmables.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
846 self._enemy.boss_callback.enable(self.switch_to_sub, (value,))
103
789994275968 Fix boss callback, handle a few more callbacks
Thibaut Girka <thib@sitedethib.com>
parents: 102
diff changeset
847 else:
789994275968 Fix boss callback, handle a few more callbacks
Thibaut Girka <thib@sitedethib.com>
parents: 102
diff changeset
848 raise Exception #TODO
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
849
23
444ac7bca7bc Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
850
51
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
851 @instruction(111)
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
852 def set_life(self, value):
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
853 self._enemy.life = value
346
862011266f2c Add a gauge and use it for the enemy life bar.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 343
diff changeset
854 self._game.interface.set_boss_life()
51
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
855
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
856
67
e2cb9d434dc2 Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents: 65
diff changeset
857 @instruction(112)
e2cb9d434dc2 Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents: 65
diff changeset
858 def set_ellapsed_time(self, value):
e2cb9d434dc2 Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents: 65
diff changeset
859 """Sets the enemy's frame counter.
e2cb9d434dc2 Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents: 65
diff changeset
860 This is used for timeouts, where the framecounter is compared to the
e2cb9d434dc2 Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents: 65
diff changeset
861 timeout value (what's displayed is (enemy.timeout - enemy.frame) // 60).
e2cb9d434dc2 Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents: 65
diff changeset
862 """
e2cb9d434dc2 Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents: 65
diff changeset
863 self._enemy.frame = value
e2cb9d434dc2 Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents: 65
diff changeset
864
e2cb9d434dc2 Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents: 65
diff changeset
865
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
866 @instruction(113)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
867 def set_low_life_trigger(self, value):
291
f6b8483a990d Refactor a bit and fix Rumia's disparition.
Thibaut Girka <thib@sitedethib.com>
parents: 287
diff changeset
868 #TODO: the enemy's life bar fills in 100 frames.
f6b8483a990d Refactor a bit and fix Rumia's disparition.
Thibaut Girka <thib@sitedethib.com>
parents: 287
diff changeset
869 # During those frames, the ECL doesn't seem to be executed.
f6b8483a990d Refactor a bit and fix Rumia's disparition.
Thibaut Girka <thib@sitedethib.com>
parents: 287
diff changeset
870 # However, the ECL isn't directly paused by this instruction itself.
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
871 self._enemy.low_life_trigger = value
347
b150ed7188a2 Show the size of the spellcard life.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 346
diff changeset
872 self._game.interface.set_spell_life()
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
873
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
874
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
875 @instruction(114)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
876 def set_low_life_callback(self, sub):
497
3da7395f39e3 Make enemy callbacks programmables.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
877 self._enemy.low_life_callback.enable(self.switch_to_sub, (sub,))
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
878
23
444ac7bca7bc Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
879
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
880 @instruction(115)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
881 def set_timeout(self, timeout):
286
4838e9bab0f9 Implement dialogs (MSG files).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 284
diff changeset
882 self._enemy.frame = 0
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
883 self._enemy.timeout = timeout
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
884
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
885
67
e2cb9d434dc2 Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents: 65
diff changeset
886 @instruction(116)
e2cb9d434dc2 Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents: 65
diff changeset
887 def set_timeout_callback(self, sub):
497
3da7395f39e3 Make enemy callbacks programmables.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
888 self._enemy.timeout_callback.enable(self.switch_to_sub, (sub,))
67
e2cb9d434dc2 Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents: 65
diff changeset
889
e2cb9d434dc2 Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents: 65
diff changeset
890
e2cb9d434dc2 Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents: 65
diff changeset
891 @instruction(117)
e2cb9d434dc2 Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents: 65
diff changeset
892 def set_touchable(self, value):
e2cb9d434dc2 Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents: 65
diff changeset
893 """Defines whether the enemy is “touchable”.
e2cb9d434dc2 Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents: 65
diff changeset
894 Bullets only collide with an enemy if it is “touchable”.
e2cb9d434dc2 Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents: 65
diff changeset
895 Likewise, ReimuA's homing attacks only target “touchable” enemies.
e2cb9d434dc2 Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents: 65
diff changeset
896 """
e2cb9d434dc2 Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents: 65
diff changeset
897 self._enemy.touchable = bool(value)
e2cb9d434dc2 Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents: 65
diff changeset
898
e2cb9d434dc2 Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents: 65
diff changeset
899
389
eef492100f4c Add "explosion", instruction 118.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
900 @instruction(118)
eef492100f4c Add "explosion", instruction 118.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
901 def drop_particles(self, anim, number, a, b, c, d):
eef492100f4c Add "explosion", instruction 118.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
902 #TODO: find the utility of the other values.
eef492100f4c Add "explosion", instruction 118.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
903
eef492100f4c Add "explosion", instruction 118.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
904 if number == 0 or number > 640: #TODO: remove that hardcoded 640, and verify it.
eef492100f4c Add "explosion", instruction 118.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
905 number = 640
eef492100f4c Add "explosion", instruction 118.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
906
eef492100f4c Add "explosion", instruction 118.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
907 if anim == -1:
eef492100f4c Add "explosion", instruction 118.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
908 return
eef492100f4c Add "explosion", instruction 118.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
909 if 0 <= anim <= 2:
eef492100f4c Add "explosion", instruction 118.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
910 self._game.new_effect((self._enemy.x, self._enemy.y), anim + 3, number=number)
eef492100f4c Add "explosion", instruction 118.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
911 elif anim == 3:
eef492100f4c Add "explosion", instruction 118.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
912 self._game.new_particle((self._enemy.x, self._enemy.y), 6, 256, number=number) #TODO: make it go back a bit at the end.
eef492100f4c Add "explosion", instruction 118.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
913 elif 4 <= anim <= 15:
eef492100f4c Add "explosion", instruction 118.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
914 self._game.new_particle((self._enemy.x, self._enemy.y), anim + 5, 192, number=number)
eef492100f4c Add "explosion", instruction 118.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
915 elif anim == 16:
430
c9433188ffdb Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 389
diff changeset
916 self._game.new_effect((self._enemy.x, self._enemy.y), 0, self._game.spellcard_effect_anm, number=number)
389
eef492100f4c Add "explosion", instruction 118.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
917 elif anim == 17:
eef492100f4c Add "explosion", instruction 118.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
918 self._game.new_particle((self._enemy.x, self._enemy.y), anim - 10, 640, number=number, reverse=True, duration=60)
eef492100f4c Add "explosion", instruction 118.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
919 elif anim == 18:
eef492100f4c Add "explosion", instruction 118.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
920 self._game.new_particle((self._enemy.x, self._enemy.y), anim - 10, 640, number=number, reverse=True, duration=240)
eef492100f4c Add "explosion", instruction 118.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
921 elif anim == 19:
eef492100f4c Add "explosion", instruction 118.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
922 self._game.new_effect((self._enemy.x, self._enemy.y), anim - 10, number=number)
eef492100f4c Add "explosion", instruction 118.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
923 else:
eef492100f4c Add "explosion", instruction 118.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
924 raise Exception #TODO
eef492100f4c Add "explosion", instruction 118.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
925
eef492100f4c Add "explosion", instruction 118.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
926
154
364935f6e313 Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 152
diff changeset
927 @instruction(119)
364935f6e313 Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 152
diff changeset
928 def drop_some_bonus(self, number):
494
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 489
diff changeset
929 if self._enemy.select_player().power < 128:
244
2b7f69ad9ccd Drop the correct amount of power with 119.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 242
diff changeset
930 if number > 0:
2b7f69ad9ccd Drop the correct amount of power with 119.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 242
diff changeset
931 #TODO: find the real formula in the binary.
302
34ea45d95489 Fix ECL instruction 119.
Thibaut Girka <thib@sitedethib.com>
parents: 299
diff changeset
932 self._game.drop_bonus(self._enemy.x - 64 + self._game.prng.rand_double() * 128,
34ea45d95489 Fix ECL instruction 119.
Thibaut Girka <thib@sitedethib.com>
parents: 299
diff changeset
933 self._enemy.y - 64 + self._game.prng.rand_double() * 128,
244
2b7f69ad9ccd Drop the correct amount of power with 119.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 242
diff changeset
934 2)
590
e15672733c93 Switch to Python 3.x instead of 2.7.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 575
diff changeset
935 for i in range(number - 1):
302
34ea45d95489 Fix ECL instruction 119.
Thibaut Girka <thib@sitedethib.com>
parents: 299
diff changeset
936 self._game.drop_bonus(self._enemy.x - 64 + self._game.prng.rand_double() * 128,
34ea45d95489 Fix ECL instruction 119.
Thibaut Girka <thib@sitedethib.com>
parents: 299
diff changeset
937 self._enemy.y - 64 + self._game.prng.rand_double() * 128,
244
2b7f69ad9ccd Drop the correct amount of power with 119.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 242
diff changeset
938 0)
2b7f69ad9ccd Drop the correct amount of power with 119.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 242
diff changeset
939 else:
590
e15672733c93 Switch to Python 3.x instead of 2.7.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 575
diff changeset
940 for i in range(number):
302
34ea45d95489 Fix ECL instruction 119.
Thibaut Girka <thib@sitedethib.com>
parents: 299
diff changeset
941 self._game.drop_bonus(self._enemy.x - 64 + self._game.prng.rand_double() * 128,
34ea45d95489 Fix ECL instruction 119.
Thibaut Girka <thib@sitedethib.com>
parents: 299
diff changeset
942 self._enemy.y - 64 + self._game.prng.rand_double() * 128,
244
2b7f69ad9ccd Drop the correct amount of power with 119.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 242
diff changeset
943 1)
154
364935f6e313 Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 152
diff changeset
944
364935f6e313 Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 152
diff changeset
945
75
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
946 @instruction(120)
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
947 def set_automatic_orientation(self, flags):
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
948 #TODO: does it change anything else than the sprite's rotation?
82
de48213a02bf Fix a few things
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
949 self._enemy.automatic_orientation = bool(flags & 1)
75
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
950
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
951
107
5d9052b9a4e8 (almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents: 106
diff changeset
952 @instruction(121)
5d9052b9a4e8 (almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents: 106
diff changeset
953 def call_special_function(self, function, arg):
5d9052b9a4e8 (almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents: 106
diff changeset
954 if function == 0: # Cirno
5d9052b9a4e8 (almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents: 106
diff changeset
955 if arg == 0:
249
2ef8f4e181e3 Change ECL special function 0 in order to match the game more closely.
Thibaut Girka <thib@sitedethib.com>
parents: 244
diff changeset
956 self._game.new_effect((self._enemy.x, self._enemy.y), 17)
151
5cf927cbd9c5 Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents: 150
diff changeset
957 for bullet in self._game.bullets:
107
5d9052b9a4e8 (almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents: 106
diff changeset
958 bullet.speed = bullet.angle = 0.
256
507dfd6efe0c Refactor pytouhou.game.bullet.
Thibaut Girka <thib@sitedethib.com>
parents: 251
diff changeset
959 bullet.dx, bullet.dy = 0., 0.
128
8ba018617829 Fix Cirno's freezing bullets
Thibaut Girka <thib@sitedethib.com>
parents: 107
diff changeset
960 bullet.set_anim(sprite_idx_offset=15) #TODO: check
107
5d9052b9a4e8 (almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents: 106
diff changeset
961 else:
249
2ef8f4e181e3 Change ECL special function 0 in order to match the game more closely.
Thibaut Girka <thib@sitedethib.com>
parents: 244
diff changeset
962 self._game.new_effect((self._enemy.x, self._enemy.y), 17)
151
5cf927cbd9c5 Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents: 150
diff changeset
963 for bullet in self._game.bullets:
256
507dfd6efe0c Refactor pytouhou.game.bullet.
Thibaut Girka <thib@sitedethib.com>
parents: 251
diff changeset
964 bullet.flags = 16 #TODO: check
250
cd4800154c9b Change ECL special function 0 in order to match the game more closely (again)
Thibaut Girka <thib@sitedethib.com>
parents: 249
diff changeset
965 angle = pi + self._game.prng.rand_double() * 2. * pi
256
507dfd6efe0c Refactor pytouhou.game.bullet.
Thibaut Girka <thib@sitedethib.com>
parents: 251
diff changeset
966 bullet.attributes[4:6] = [0.01, angle] #TODO: check
507dfd6efe0c Refactor pytouhou.game.bullet.
Thibaut Girka <thib@sitedethib.com>
parents: 251
diff changeset
967 bullet.attributes[0] = -1 #TODO: check
250
cd4800154c9b Change ECL special function 0 in order to match the game more closely (again)
Thibaut Girka <thib@sitedethib.com>
parents: 249
diff changeset
968 bullet.set_anim(sprite_idx_offset=15) #TODO: check
168
b96d835c0807 Implement Cirno’s 雪符「ダイアモンドブリザード」 spellcard.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 166
diff changeset
969 elif function == 1: # Cirno
207
709f42eaa55e Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 195
diff changeset
970 offset = (self._game.prng.rand_uint16() % arg - arg / 2,
709f42eaa55e Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 195
diff changeset
971 self._game.prng.rand_uint16() % arg - arg / 2)
709f42eaa55e Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 195
diff changeset
972 self._enemy.fire(offset=offset)
266
3a86c4e070dc Implement ECL’s 3rd hardcoded function.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 256
diff changeset
973 elif function == 3: # Patchouli’s dual sign spellcards
3a86c4e070dc Implement ECL’s 3rd hardcoded function.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 256
diff changeset
974 values = [[0, 3, 1],
3a86c4e070dc Implement ECL’s 3rd hardcoded function.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 256
diff changeset
975 [2, 3, 4],
3a86c4e070dc Implement ECL’s 3rd hardcoded function.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 256
diff changeset
976 [1, 4, 0],
3a86c4e070dc Implement ECL’s 3rd hardcoded function.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 256
diff changeset
977 [4, 2, 3]]
494
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 489
diff changeset
978 character = self._enemy.select_player().character
266
3a86c4e070dc Implement ECL’s 3rd hardcoded function.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 256
diff changeset
979 self.variables[1:4] = values[character]
299
e04e402e6380 Implemented Sakuya's time stop.
Elias Boutaleb <kagekyio@gmail.com>
parents: 296
diff changeset
980 elif function == 4:
e04e402e6380 Implemented Sakuya's time stop.
Elias Boutaleb <kagekyio@gmail.com>
parents: 296
diff changeset
981 if arg == 1:
e04e402e6380 Implemented Sakuya's time stop.
Elias Boutaleb <kagekyio@gmail.com>
parents: 296
diff changeset
982 self._game.time_stop = True
e04e402e6380 Implemented Sakuya's time stop.
Elias Boutaleb <kagekyio@gmail.com>
parents: 296
diff changeset
983 else:
e04e402e6380 Implemented Sakuya's time stop.
Elias Boutaleb <kagekyio@gmail.com>
parents: 296
diff changeset
984 self._game.time_stop = False
309
14c9aca8e274 Implement Remilia's laser webs.
Thibaut Girka <thib@sitedethib.com>
parents: 308
diff changeset
985 elif function == 7: # Remilia’s laser webs
14c9aca8e274 Implement Remilia's laser webs.
Thibaut Girka <thib@sitedethib.com>
parents: 308
diff changeset
986 base_angle = self._game.prng.rand_double() * 2 * pi
590
e15672733c93 Switch to Python 3.x instead of 2.7.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 575
diff changeset
987 for i in range(16):
309
14c9aca8e274 Implement Remilia's laser webs.
Thibaut Girka <thib@sitedethib.com>
parents: 308
diff changeset
988 delta = [+pi / 4., -pi / 4.][i % 2]
14c9aca8e274 Implement Remilia's laser webs.
Thibaut Girka <thib@sitedethib.com>
parents: 308
diff changeset
989 ox, oy = self._enemy.bullet_launch_offset
14c9aca8e274 Implement Remilia's laser webs.
Thibaut Girka <thib@sitedethib.com>
parents: 308
diff changeset
990 length = 32. #TODO: check
14c9aca8e274 Implement Remilia's laser webs.
Thibaut Girka <thib@sitedethib.com>
parents: 308
diff changeset
991
14c9aca8e274 Implement Remilia's laser webs.
Thibaut Girka <thib@sitedethib.com>
parents: 308
diff changeset
992 # Inner circle
14c9aca8e274 Implement Remilia's laser webs.
Thibaut Girka <thib@sitedethib.com>
parents: 308
diff changeset
993 angle = base_angle + i * pi / 8.
14c9aca8e274 Implement Remilia's laser webs.
Thibaut Girka <thib@sitedethib.com>
parents: 308
diff changeset
994 ox, oy = ox + cos(angle) * length, oy + sin(angle) * length
14c9aca8e274 Implement Remilia's laser webs.
Thibaut Girka <thib@sitedethib.com>
parents: 308
diff changeset
995 length = 112. #TODO: check
14c9aca8e274 Implement Remilia's laser webs.
Thibaut Girka <thib@sitedethib.com>
parents: 308
diff changeset
996 if arg == 0:
14c9aca8e274 Implement Remilia's laser webs.
Thibaut Girka <thib@sitedethib.com>
parents: 308
diff changeset
997 self._enemy.new_laser(85, 1, 1, angle, 0., 0., length, length, 30.,
14c9aca8e274 Implement Remilia's laser webs.
Thibaut Girka <thib@sitedethib.com>
parents: 308
diff changeset
998 100, 80, 15, #TODO: check
14c9aca8e274 Implement Remilia's laser webs.
Thibaut Girka <thib@sitedethib.com>
parents: 308
diff changeset
999 0, 0, 0, offset=(ox, oy))
14c9aca8e274 Implement Remilia's laser webs.
Thibaut Girka <thib@sitedethib.com>
parents: 308
diff changeset
1000 else:
14c9aca8e274 Implement Remilia's laser webs.
Thibaut Girka <thib@sitedethib.com>
parents: 308
diff changeset
1001 self._enemy.fire(offset=(ox, oy))
14c9aca8e274 Implement Remilia's laser webs.
Thibaut Girka <thib@sitedethib.com>
parents: 308
diff changeset
1002
14c9aca8e274 Implement Remilia's laser webs.
Thibaut Girka <thib@sitedethib.com>
parents: 308
diff changeset
1003 # Middle circle
14c9aca8e274 Implement Remilia's laser webs.
Thibaut Girka <thib@sitedethib.com>
parents: 308
diff changeset
1004 ox, oy = ox + cos(angle) * length, oy + sin(angle) * length
14c9aca8e274 Implement Remilia's laser webs.
Thibaut Girka <thib@sitedethib.com>
parents: 308
diff changeset
1005 angle += delta
14c9aca8e274 Implement Remilia's laser webs.
Thibaut Girka <thib@sitedethib.com>
parents: 308
diff changeset
1006
14c9aca8e274 Implement Remilia's laser webs.
Thibaut Girka <thib@sitedethib.com>
parents: 308
diff changeset
1007 if arg == 0:
14c9aca8e274 Implement Remilia's laser webs.
Thibaut Girka <thib@sitedethib.com>
parents: 308
diff changeset
1008 self._enemy.new_laser(85, 1, 1, angle, 0., 0., length, length, 30.,
14c9aca8e274 Implement Remilia's laser webs.
Thibaut Girka <thib@sitedethib.com>
parents: 308
diff changeset
1009 100, 80, 15, #TODO: check
14c9aca8e274 Implement Remilia's laser webs.
Thibaut Girka <thib@sitedethib.com>
parents: 308
diff changeset
1010 0, 0, 0, offset=(ox, oy))
14c9aca8e274 Implement Remilia's laser webs.
Thibaut Girka <thib@sitedethib.com>
parents: 308
diff changeset
1011 else:
14c9aca8e274 Implement Remilia's laser webs.
Thibaut Girka <thib@sitedethib.com>
parents: 308
diff changeset
1012 self._enemy.fire(offset=(ox, oy))
14c9aca8e274 Implement Remilia's laser webs.
Thibaut Girka <thib@sitedethib.com>
parents: 308
diff changeset
1013
14c9aca8e274 Implement Remilia's laser webs.
Thibaut Girka <thib@sitedethib.com>
parents: 308
diff changeset
1014 # Outer circle
14c9aca8e274 Implement Remilia's laser webs.
Thibaut Girka <thib@sitedethib.com>
parents: 308
diff changeset
1015 ox, oy = ox + cos(angle) * length, oy + sin(angle) * length
14c9aca8e274 Implement Remilia's laser webs.
Thibaut Girka <thib@sitedethib.com>
parents: 308
diff changeset
1016 angle += delta
14c9aca8e274 Implement Remilia's laser webs.
Thibaut Girka <thib@sitedethib.com>
parents: 308
diff changeset
1017 length = 400. #TODO: check
14c9aca8e274 Implement Remilia's laser webs.
Thibaut Girka <thib@sitedethib.com>
parents: 308
diff changeset
1018
14c9aca8e274 Implement Remilia's laser webs.
Thibaut Girka <thib@sitedethib.com>
parents: 308
diff changeset
1019 if arg == 0:
14c9aca8e274 Implement Remilia's laser webs.
Thibaut Girka <thib@sitedethib.com>
parents: 308
diff changeset
1020 self._enemy.new_laser(85, 1, 1, angle, 0., 0., length, length, 30.,
14c9aca8e274 Implement Remilia's laser webs.
Thibaut Girka <thib@sitedethib.com>
parents: 308
diff changeset
1021 100, 80, 15, #TODO: check
14c9aca8e274 Implement Remilia's laser webs.
Thibaut Girka <thib@sitedethib.com>
parents: 308
diff changeset
1022 0, 0, 0, offset=(ox, oy))
14c9aca8e274 Implement Remilia's laser webs.
Thibaut Girka <thib@sitedethib.com>
parents: 308
diff changeset
1023 else:
14c9aca8e274 Implement Remilia's laser webs.
Thibaut Girka <thib@sitedethib.com>
parents: 308
diff changeset
1024 self._enemy.fire(offset=(ox, oy))
296
c074783d0847 Implement hardcoded function 8 for Remilia.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 295
diff changeset
1025 elif function == 8: # Remilia’s magic
c074783d0847 Implement hardcoded function 8 for Remilia.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 295
diff changeset
1026 bullet_attributes = [70, 1, 1, 1, 1, 0., 0., 0., 0.7, 0]
c074783d0847 Implement hardcoded function 8 for Remilia.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 295
diff changeset
1027 n = 0
c074783d0847 Implement hardcoded function 8 for Remilia.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 295
diff changeset
1028 for bullet in self._game.bullets:
312
8d1768fa4cbb Fix Remilia's “Red Magic”.
Thibaut Girka <thib@sitedethib.com>
parents: 310
diff changeset
1029 if bullet._bullet_type.type_id < 5:
296
c074783d0847 Implement hardcoded function 8 for Remilia.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 295
diff changeset
1030 continue
c074783d0847 Implement hardcoded function 8 for Remilia.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 295
diff changeset
1031 n += 1
c074783d0847 Implement hardcoded function 8 for Remilia.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 295
diff changeset
1032 bullet_attributes[8] = bullet.angle
c074783d0847 Implement hardcoded function 8 for Remilia.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 295
diff changeset
1033 self._enemy.fire(launch_pos=(bullet.x, bullet.y),
c074783d0847 Implement hardcoded function 8 for Remilia.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 295
diff changeset
1034 bullet_attributes=bullet_attributes)
c074783d0847 Implement hardcoded function 8 for Remilia.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 295
diff changeset
1035 self._setval(-10004, n)
313
2ba2462afc70 Implement hardcoded function 9.
Thibaut Girka <thib@sitedethib.com>
parents: 312
diff changeset
1036 elif function == 9:
2ba2462afc70 Implement hardcoded function 9.
Thibaut Girka <thib@sitedethib.com>
parents: 312
diff changeset
1037 self._game.new_effect((self._enemy.x, self._enemy.y), 17)
2ba2462afc70 Implement hardcoded function 9.
Thibaut Girka <thib@sitedethib.com>
parents: 312
diff changeset
1038 base_angle = pi + 2. * self._game.prng.rand_double() * pi
2ba2462afc70 Implement hardcoded function 9.
Thibaut Girka <thib@sitedethib.com>
parents: 312
diff changeset
1039 for bullet in self._game.bullets:
2ba2462afc70 Implement hardcoded function 9.
Thibaut Girka <thib@sitedethib.com>
parents: 312
diff changeset
1040 if bullet._bullet_type.type_id < 5 and bullet.speed == 0.:
2ba2462afc70 Implement hardcoded function 9.
Thibaut Girka <thib@sitedethib.com>
parents: 312
diff changeset
1041 bullet.flags = 16 #TODO: check
2ba2462afc70 Implement hardcoded function 9.
Thibaut Girka <thib@sitedethib.com>
parents: 312
diff changeset
1042 distance = hypot(bullet.x - self._enemy.x, bullet.y - self._enemy.y)
2ba2462afc70 Implement hardcoded function 9.
Thibaut Girka <thib@sitedethib.com>
parents: 312
diff changeset
1043 angle = base_angle
2ba2462afc70 Implement hardcoded function 9.
Thibaut Girka <thib@sitedethib.com>
parents: 312
diff changeset
1044 angle += distance /80. #TODO: This is most probably wrong
2ba2462afc70 Implement hardcoded function 9.
Thibaut Girka <thib@sitedethib.com>
parents: 312
diff changeset
1045 bullet.attributes[4:6] = [0.01, angle] #TODO: check
2ba2462afc70 Implement hardcoded function 9.
Thibaut Girka <thib@sitedethib.com>
parents: 312
diff changeset
1046 bullet.attributes[0] = -1 #TODO: check
2ba2462afc70 Implement hardcoded function 9.
Thibaut Girka <thib@sitedethib.com>
parents: 312
diff changeset
1047 bullet.set_anim(sprite_idx_offset=1) #TODO: check
310
81c5b0b51093 Implement hardcoded function 11.
Thibaut Girka <thib@sitedethib.com>
parents: 309
diff changeset
1048 elif function == 11:
81c5b0b51093 Implement hardcoded function 11.
Thibaut Girka <thib@sitedethib.com>
parents: 309
diff changeset
1049 self._game.new_effect((self._enemy.x, self._enemy.y), 17)
81c5b0b51093 Implement hardcoded function 11.
Thibaut Girka <thib@sitedethib.com>
parents: 309
diff changeset
1050 self._game.prng.rand_double() #TODO: what is it for?
81c5b0b51093 Implement hardcoded function 11.
Thibaut Girka <thib@sitedethib.com>
parents: 309
diff changeset
1051 for bullet in self._game.bullets: #TODO Bullet order is WRONG
312
8d1768fa4cbb Fix Remilia's “Red Magic”.
Thibaut Girka <thib@sitedethib.com>
parents: 310
diff changeset
1052 if bullet._bullet_type.type_id < 5 and bullet.speed == 0.:
310
81c5b0b51093 Implement hardcoded function 11.
Thibaut Girka <thib@sitedethib.com>
parents: 309
diff changeset
1053 bullet.flags = 16 #TODO: check
81c5b0b51093 Implement hardcoded function 11.
Thibaut Girka <thib@sitedethib.com>
parents: 309
diff changeset
1054 angle = pi + self._game.prng.rand_double() * 2. * pi
81c5b0b51093 Implement hardcoded function 11.
Thibaut Girka <thib@sitedethib.com>
parents: 309
diff changeset
1055 bullet.attributes[4:6] = [0.01, angle] #TODO: check
81c5b0b51093 Implement hardcoded function 11.
Thibaut Girka <thib@sitedethib.com>
parents: 309
diff changeset
1056 bullet.attributes[0] = -1 #TODO: check
81c5b0b51093 Implement hardcoded function 11.
Thibaut Girka <thib@sitedethib.com>
parents: 309
diff changeset
1057 bullet.set_anim(sprite_idx_offset=1) #TODO: check
169
c4b4f7c068f2 Fix Cirno’s last spellcard and implement something for Patchy in extra stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 168
diff changeset
1058 elif function == 13:
c4b4f7c068f2 Fix Cirno’s last spellcard and implement something for Patchy in extra stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 168
diff changeset
1059 if self._enemy.bullet_attributes is None:
c4b4f7c068f2 Fix Cirno’s last spellcard and implement something for Patchy in extra stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 168
diff changeset
1060 return
c4b4f7c068f2 Fix Cirno’s last spellcard and implement something for Patchy in extra stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 168
diff changeset
1061
287
981d1893d564 Fix Patchouly's Royal Flare.
Thibaut Girka <thib@sitedethib.com>
parents: 286
diff changeset
1062 frame = self._getval(-10004)
981d1893d564 Fix Patchouly's Royal Flare.
Thibaut Girka <thib@sitedethib.com>
parents: 286
diff changeset
1063 self._setval(-10004, frame + 1)
981d1893d564 Fix Patchouly's Royal Flare.
Thibaut Girka <thib@sitedethib.com>
parents: 286
diff changeset
1064
981d1893d564 Fix Patchouly's Royal Flare.
Thibaut Girka <thib@sitedethib.com>
parents: 286
diff changeset
1065 if frame % 6 != 0:
178
0bd5e5f19a73 Fix Patchouli’s 日符「ロイヤルフレア」 spellcard.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 177
diff changeset
1066 return
0bd5e5f19a73 Fix Patchouli’s 日符「ロイヤルフレア」 spellcard.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 177
diff changeset
1067
207
709f42eaa55e Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 195
diff changeset
1068 (type_, anim, sprite_idx_offset, bullets_per_shot, number_of_shots,
709f42eaa55e Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 195
diff changeset
1069 speed, speed2, launch_angle, angle, flags) = self._enemy.bullet_attributes
178
0bd5e5f19a73 Fix Patchouli’s 日符「ロイヤルフレア」 spellcard.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 177
diff changeset
1070 for i in range(arg):
287
981d1893d564 Fix Patchouly's Royal Flare.
Thibaut Girka <thib@sitedethib.com>
parents: 286
diff changeset
1071 _angle = i*2*pi/arg + self._getval(-10007)
178
0bd5e5f19a73 Fix Patchouli’s 日符「ロイヤルフレア」 spellcard.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 177
diff changeset
1072 _distance = self._getval(-10008)
287
981d1893d564 Fix Patchouly's Royal Flare.
Thibaut Girka <thib@sitedethib.com>
parents: 286
diff changeset
1073 launch_pos = (192 + cos(_angle) * _distance,
981d1893d564 Fix Patchouly's Royal Flare.
Thibaut Girka <thib@sitedethib.com>
parents: 286
diff changeset
1074 224 + sin(_angle) * _distance)
207
709f42eaa55e Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 195
diff changeset
1075 bullet_attributes = (type_, anim, sprite_idx_offset,
709f42eaa55e Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 195
diff changeset
1076 bullets_per_shot, number_of_shots,
709f42eaa55e Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 195
diff changeset
1077 speed, speed2,
709f42eaa55e Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 195
diff changeset
1078 self._getval(-10006) + _angle, angle, flags)
709f42eaa55e Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 195
diff changeset
1079 self._enemy.fire(launch_pos=launch_pos,
709f42eaa55e Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 195
diff changeset
1080 bullet_attributes=bullet_attributes)
275
4b0570bf5847 Implement hardcoded function 14 used by spellcard “Lævateinn”.
Thibaut Girka <thib@sitedethib.com>
parents: 274
diff changeset
1081 elif function == 14: # Laevateinn
4b0570bf5847 Implement hardcoded function 14 used by spellcard “Lævateinn”.
Thibaut Girka <thib@sitedethib.com>
parents: 274
diff changeset
1082 if arg == 0:
4b0570bf5847 Implement hardcoded function 14 used by spellcard “Lævateinn”.
Thibaut Girka <thib@sitedethib.com>
parents: 274
diff changeset
1083 self.variables[4] = 0
4b0570bf5847 Implement hardcoded function 14 used by spellcard “Lævateinn”.
Thibaut Girka <thib@sitedethib.com>
parents: 274
diff changeset
1084 for laser in self._enemy.laser_by_id.values():
4b0570bf5847 Implement hardcoded function 14 used by spellcard “Lævateinn”.
Thibaut Girka <thib@sitedethib.com>
parents: 274
diff changeset
1085 self.variables[4] += 1
4b0570bf5847 Implement hardcoded function 14 used by spellcard “Lævateinn”.
Thibaut Girka <thib@sitedethib.com>
parents: 274
diff changeset
1086 for pos in laser.get_bullets_pos():
4b0570bf5847 Implement hardcoded function 14 used by spellcard “Lævateinn”.
Thibaut Girka <thib@sitedethib.com>
parents: 274
diff changeset
1087 self._enemy.fire(launch_pos=pos)
4b0570bf5847 Implement hardcoded function 14 used by spellcard “Lævateinn”.
Thibaut Girka <thib@sitedethib.com>
parents: 274
diff changeset
1088 else:
4b0570bf5847 Implement hardcoded function 14 used by spellcard “Lævateinn”.
Thibaut Girka <thib@sitedethib.com>
parents: 274
diff changeset
1089 pass #TODO: check
273
595b227886b1 Partially implement hardcoded function 16, used for QED: ripples of 495 years
Thibaut Girka <thib@sitedethib.com>
parents: 272
diff changeset
1090 elif function == 16: # QED: Ripples of 495 years
595b227886b1 Partially implement hardcoded function 16, used for QED: ripples of 495 years
Thibaut Girka <thib@sitedethib.com>
parents: 272
diff changeset
1091 if arg == 0:
360
d55a1843b2a7 Fix Flandre's QED: Ripples of 495 years
Thibaut Girka <thib@sitedethib.com>
parents: 359
diff changeset
1092 self.variables[9] = 40 + self._enemy.life // 25
d55a1843b2a7 Fix Flandre's QED: Ripples of 495 years
Thibaut Girka <thib@sitedethib.com>
parents: 359
diff changeset
1093 self.variables[7] = 2. - self._enemy.life / 6000.
273
595b227886b1 Partially implement hardcoded function 16, used for QED: ripples of 495 years
Thibaut Girka <thib@sitedethib.com>
parents: 272
diff changeset
1094 else:
360
d55a1843b2a7 Fix Flandre's QED: Ripples of 495 years
Thibaut Girka <thib@sitedethib.com>
parents: 359
diff changeset
1095 #TODO: I'm really not sure about that...
273
595b227886b1 Partially implement hardcoded function 16, used for QED: ripples of 495 years
Thibaut Girka <thib@sitedethib.com>
parents: 272
diff changeset
1096 self.variables[6] = self._game.prng.rand_double() * (self._game.width - 64.) + 32.
595b227886b1 Partially implement hardcoded function 16, used for QED: ripples of 495 years
Thibaut Girka <thib@sitedethib.com>
parents: 272
diff changeset
1097 self.variables[7] = self._game.prng.rand_double() * (self._game.width / 2. - 64.) + 32.
107
5d9052b9a4e8 (almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents: 106
diff changeset
1098 else:
5d9052b9a4e8 (almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents: 106
diff changeset
1099 logger.warn("Unimplemented special function %d!", function)
5d9052b9a4e8 (almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents: 106
diff changeset
1100
5d9052b9a4e8 (almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents: 106
diff changeset
1101
75
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
1102 @instruction(123)
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
1103 def skip_frames(self, frames):
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
1104 #TODO: is that all?
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
1105 self.frame += self._getval(frames)
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
1106
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
1107
154
364935f6e313 Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 152
diff changeset
1108 @instruction(124)
364935f6e313 Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 152
diff changeset
1109 def drop_specific_bonus(self, _type):
165
c8c60291c56f Implement item dropping by enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 160
diff changeset
1110 #TODO: if _type < 0, “drop” an bullet animation instead of a bonus (never used).
154
364935f6e313 Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 152
diff changeset
1111 self._game.drop_bonus(self._enemy.x, self._enemy.y, _type)
364935f6e313 Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 152
diff changeset
1112
364935f6e313 Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 152
diff changeset
1113
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
1114 @instruction(126)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
1115 def set_remaining_lives(self, lives):
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
1116 self._enemy.remaining_lives = lives
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
1117
182
20843875ad8f (Hopefully) use difficulty as it should.
Thibaut Girka <thib@sitedethib.com>
parents: 181
diff changeset
1118
242
1d3c8c7473a2 Implement auxiliary animations of enemies like magic circles, and interruptions from ecl.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 224
diff changeset
1119 @instruction(128)
1d3c8c7473a2 Implement auxiliary animations of enemies like magic circles, and interruptions from ecl.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 224
diff changeset
1120 def interrupt(self, event):
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 302
diff changeset
1121 self._enemy.anmrunner.interrupt(event)
242
1d3c8c7473a2 Implement auxiliary animations of enemies like magic circles, and interruptions from ecl.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 224
diff changeset
1122
1d3c8c7473a2 Implement auxiliary animations of enemies like magic circles, and interruptions from ecl.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 224
diff changeset
1123
1d3c8c7473a2 Implement auxiliary animations of enemies like magic circles, and interruptions from ecl.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 224
diff changeset
1124 @instruction(129)
1d3c8c7473a2 Implement auxiliary animations of enemies like magic circles, and interruptions from ecl.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 224
diff changeset
1125 def interrupt_aux(self, number, event):
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 302
diff changeset
1126 self._enemy.aux_anm[number].anmrunner.interrupt(event)
242
1d3c8c7473a2 Implement auxiliary animations of enemies like magic circles, and interruptions from ecl.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 224
diff changeset
1127
1d3c8c7473a2 Implement auxiliary animations of enemies like magic circles, and interruptions from ecl.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 224
diff changeset
1128
182
20843875ad8f (Hopefully) use difficulty as it should.
Thibaut Girka <thib@sitedethib.com>
parents: 181
diff changeset
1129 @instruction(131)
20843875ad8f (Hopefully) use difficulty as it should.
Thibaut Girka <thib@sitedethib.com>
parents: 181
diff changeset
1130 def set_difficulty_coeffs(self, speed_a, speed_b, nb_a, nb_b, shots_a, shots_b):
20843875ad8f (Hopefully) use difficulty as it should.
Thibaut Girka <thib@sitedethib.com>
parents: 181
diff changeset
1131 self._enemy.difficulty_coeffs = (speed_a, speed_b, nb_a, nb_b, shots_a, shots_b)
20843875ad8f (Hopefully) use difficulty as it should.
Thibaut Girka <thib@sitedethib.com>
parents: 181
diff changeset
1132
361
b55939b4b40d Rename set_visible to set_invisible, since it's what it does...
Thibaut Girka <thib@sitedethib.com>
parents: 360
diff changeset
1133
b55939b4b40d Rename set_visible to set_invisible, since it's what it does...
Thibaut Girka <thib@sitedethib.com>
parents: 360
diff changeset
1134 @instruction(132)
b55939b4b40d Rename set_visible to set_invisible, since it's what it does...
Thibaut Girka <thib@sitedethib.com>
parents: 360
diff changeset
1135 def set_invisible(self, value):
b55939b4b40d Rename set_visible to set_invisible, since it's what it does...
Thibaut Girka <thib@sitedethib.com>
parents: 360
diff changeset
1136 self._enemy.visible = not bool(value)
b55939b4b40d Rename set_visible to set_invisible, since it's what it does...
Thibaut Girka <thib@sitedethib.com>
parents: 360
diff changeset
1137
362
3be4c1078095 (partially?) implement ECL's instruction 133
Thibaut Girka <thib@sitedethib.com>
parents: 361
diff changeset
1138
3be4c1078095 (partially?) implement ECL's instruction 133
Thibaut Girka <thib@sitedethib.com>
parents: 361
diff changeset
1139 @instruction(133)
3be4c1078095 (partially?) implement ECL's instruction 133
Thibaut Girka <thib@sitedethib.com>
parents: 361
diff changeset
1140 def copy_callbacks(self):
497
3da7395f39e3 Make enemy callbacks programmables.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
1141 self._enemy.timeout_callback.enable(self.switch_to_sub, (self._enemy.death_callback.args[0],))
362
3be4c1078095 (partially?) implement ECL's instruction 133
Thibaut Girka <thib@sitedethib.com>
parents: 361
diff changeset
1142