annotate pytouhou/vm/eclrunner.py @ 99:68aa8bf00c88

Change a debug string to avoid confusion
author Thibaut Girka <thib@sitedethib.com>
date Sun, 04 Sep 2011 23:55:35 +0200
parents ac2e5e1c2c3c
children 5c40cc1b8019
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
51
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
16 from math import atan2, cos, sin
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
97
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
26 class ECLMainRunner(object):
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
27 __metaclass__ = MetaRegistry
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
28 __slots__ = ('_ecl', '_new_enemy_func', '_game_state', 'processes',
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
29 'instruction_pointer')
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
30
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
31 def __init__(self, ecl, new_enemy_func, game_state):
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
32 self._ecl = ecl
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
33 self._new_enemy_func = new_enemy_func
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
34 self._game_state = game_state
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
35
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
36 self.processes = []
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):
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
42 while True:
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
43 try:
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
44 frame, sub, instr_type, args = self._ecl.main[self.instruction_pointer]
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
45 except IndexError:
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
46 break
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
47
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
48 if frame > self._game_state.frame:
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 else:
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
51 self.instruction_pointer += 1
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
52
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
53 if frame == self._game_state.frame:
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
54 try:
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
55 callback = self._handlers[instr_type]
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
56 except KeyError:
99
68aa8bf00c88 Change a debug string to avoid confusion
Thibaut Girka <thib@sitedethib.com>
parents: 97
diff changeset
57 logger.warn('unhandled main opcode %d (args: %r)', instr_type, args)
97
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
58 else:
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
59 callback(self, sub, instr_type, *args)
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
60
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
61 self.processes[:] = (process for process in self.processes
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
62 if process.run_iteration())
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
63
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
64
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
65 @instruction(0)
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
66 @instruction(2)
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
67 @instruction(4)
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
68 @instruction(6)
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
69 def pop_enemy(self, sub, instr_type, x, y, z, life, unknown1, unknown2, unknown3):
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
70 if self._game_state.boss:
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
71 return
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
72 if instr_type & 4:
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
73 if x < -990: #102h.exe@0x411820
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
74 x = self._game_state.prng.rand_double() * 368
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
75 if y < -990: #102h.exe@0x41184b
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
76 y = self._game_state.prng.rand_double() * 416
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
77 if z < -990: #102h.exe@0x411881
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
78 y = self._game_state.prng.rand_double() * 800
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
79 enemy = self._new_enemy_func((x, y), life, instr_type)
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
80 self.processes.append(ECLRunner(self._ecl, sub, enemy, self._game_state))
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
81
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
82
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
83
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 96
diff changeset
84
23
444ac7bca7bc Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
85 class ECLRunner(object):
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
86 __metaclass__ = MetaRegistry
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
87 __slots__ = ('_ecl', '_enemy', '_game_state', 'variables', 'sub', 'frame',
51
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
88 'instruction_pointer', 'comparison_reg', 'stack')
23
444ac7bca7bc Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
89
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
90 def __init__(self, ecl, sub, enemy, game_state):
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
91 # Things not supposed to change
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
92 self._ecl = ecl
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
93 self._enemy = enemy
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
94 self._game_state = game_state
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
95
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
96 # 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
97 self.variables = [0, 0, 0, 0,
1f1793e7ec8e Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
98 0., 0., 0., 0.,
1f1793e7ec8e Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
99 0, 0, 0, 0]
51
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
100 self.comparison_reg = 0
23
444ac7bca7bc Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
101 self.sub = sub
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
102 self.frame = 0
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
103 self.instruction_pointer = 0
23
444ac7bca7bc Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
104
47
1f1793e7ec8e Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
105 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
106
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
107
93
d167280a82fc Handle timeout callbacks, and clean up unneeded things
Thibaut Girka <thib@sitedethib.com>
parents: 91
diff changeset
108 def handle_callbacks(self):
d167280a82fc Handle timeout callbacks, and clean up unneeded things
Thibaut Girka <thib@sitedethib.com>
parents: 91
diff changeset
109 #TODO
d167280a82fc Handle timeout callbacks, and clean up unneeded things
Thibaut Girka <thib@sitedethib.com>
parents: 91
diff changeset
110 enm = self._enemy
d167280a82fc Handle timeout callbacks, and clean up unneeded things
Thibaut Girka <thib@sitedethib.com>
parents: 91
diff changeset
111 if enm.timeout and enm.frame == enm.timeout:
d167280a82fc Handle timeout callbacks, and clean up unneeded things
Thibaut Girka <thib@sitedethib.com>
parents: 91
diff changeset
112 enm.frame = 0
d167280a82fc Handle timeout callbacks, and clean up unneeded things
Thibaut Girka <thib@sitedethib.com>
parents: 91
diff changeset
113 if enm.timeout_callback:
d167280a82fc Handle timeout callbacks, and clean up unneeded things
Thibaut Girka <thib@sitedethib.com>
parents: 91
diff changeset
114 self.frame = 0
d167280a82fc Handle timeout callbacks, and clean up unneeded things
Thibaut Girka <thib@sitedethib.com>
parents: 91
diff changeset
115 self.sub = enm.timeout_callback
d167280a82fc Handle timeout callbacks, and clean up unneeded things
Thibaut Girka <thib@sitedethib.com>
parents: 91
diff changeset
116 self.instruction_pointer = 0
d167280a82fc Handle timeout callbacks, and clean up unneeded things
Thibaut Girka <thib@sitedethib.com>
parents: 91
diff changeset
117 else:
d167280a82fc Handle timeout callbacks, and clean up unneeded things
Thibaut Girka <thib@sitedethib.com>
parents: 91
diff changeset
118 pass #TODO
d167280a82fc Handle timeout callbacks, and clean up unneeded things
Thibaut Girka <thib@sitedethib.com>
parents: 91
diff changeset
119 #TODO: other callbacks (low life, etc.)
d167280a82fc Handle timeout callbacks, and clean up unneeded things
Thibaut Girka <thib@sitedethib.com>
parents: 91
diff changeset
120
d167280a82fc Handle timeout callbacks, and clean up unneeded things
Thibaut Girka <thib@sitedethib.com>
parents: 91
diff changeset
121
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
122 def run_iteration(self):
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
123 # First, if enemy is dead, return
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
124 if self._enemy._removed:
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
125 return False
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
126
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
127 # Then, check for callbacks
93
d167280a82fc Handle timeout callbacks, and clean up unneeded things
Thibaut Girka <thib@sitedethib.com>
parents: 91
diff changeset
128 self.handle_callbacks()
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
129
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
130 # Now, process script
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
131 while True:
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
132 try:
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
133 frame, instr_type, rank_mask, param_mask, args = self._ecl.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
134 except IndexError:
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
135 return False
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
136
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
137 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
138 break
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
139 else:
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
140 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
141
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 55
diff changeset
142
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 55
diff changeset
143 #TODO: skip bad ranks
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 55
diff changeset
144 if not rank_mask & (0x100 << self._game_state.rank):
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 55
diff changeset
145 continue
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 55
diff changeset
146
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 55
diff changeset
147
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
148 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
149 try:
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
150 callback = self._handlers[instr_type]
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
151 except KeyError:
58
3da4de9decd0 Use logging module
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
152 logger.warn('unhandled opcode %d (args: %r)', 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
153 else:
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
154 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
155
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
156 self.frame += 1
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
157 return True
47
1f1793e7ec8e Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
158
1f1793e7ec8e Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
159
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
160 def _getval(self, value):
48
8353c33d53d4 Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents: 47
diff changeset
161 if -10012 <= value <= -10001:
8353c33d53d4 Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents: 47
diff changeset
162 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
163 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
164 if value == -10013:
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
165 return self._game_state.rank
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
166 elif value == -10014:
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
167 return self._game_state.difficulty
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
168 elif value == -10015:
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
169 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
170 elif value == -10016:
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
171 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
172 elif value == -10017:
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
173 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
174 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
175 player = self._enemy.select_player()
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
176 return player.x
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
177 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
178 player = self._enemy.select_player()
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
179 return player.y
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
180 elif value == -10021:
79
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
181 return self._enemy.get_player_angle()
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
182 elif value == -10022:
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
183 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
184 elif value == -10024:
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
185 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
186 elif value == -10025:
79
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
187 return self._enemy.select_player().character
57
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 55
diff changeset
188 raise NotImplementedError(value) #TODO
48
8353c33d53d4 Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents: 47
diff changeset
189 else:
8353c33d53d4 Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents: 47
diff changeset
190 return value
8353c33d53d4 Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents: 47
diff changeset
191
8353c33d53d4 Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents: 47
diff changeset
192
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
193 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
194 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
195 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
196 elif -10025 <= variable_id <= -10013:
55
de358a7684c8 Fix a few bugs
Thibaut Girka <thib@sitedethib.com>
parents: 53
diff changeset
197 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
198 self._enemy.x = value
55
de358a7684c8 Fix a few bugs
Thibaut Girka <thib@sitedethib.com>
parents: 53
diff changeset
199 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
200 self._enemy.y = value
55
de358a7684c8 Fix a few bugs
Thibaut Girka <thib@sitedethib.com>
parents: 53
diff changeset
201 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
202 self._enemy.z = value
55
de358a7684c8 Fix a few bugs
Thibaut Girka <thib@sitedethib.com>
parents: 53
diff changeset
203 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
204 self._enemy.frame = value
55
de358a7684c8 Fix a few bugs
Thibaut Girka <thib@sitedethib.com>
parents: 53
diff changeset
205 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
206 self._enemy.life = value
55
de358a7684c8 Fix a few bugs
Thibaut Girka <thib@sitedethib.com>
parents: 53
diff changeset
207 else:
de358a7684c8 Fix a few bugs
Thibaut Girka <thib@sitedethib.com>
parents: 53
diff changeset
208 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
209 else:
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
210 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
211
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
212
51
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
213 @instruction(0)
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
214 def noop(self):
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
215 pass #TODO: Really?
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
216
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
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 @instruction(1)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
219 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
220 #TODO: arg?
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
221 self._enemy._removed = True
48
8353c33d53d4 Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents: 47
diff changeset
222
8353c33d53d4 Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents: 47
diff changeset
223
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
224 @instruction(2)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
225 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
226 """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
227
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 51
diff changeset
228 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
229 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
230 """
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
231 self.frame, self.instruction_pointer = frame, instruction_pointer
48
8353c33d53d4 Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents: 47
diff changeset
232
8353c33d53d4 Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents: 47
diff changeset
233
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
234 @instruction(3)
53
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
235 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
236 """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
237 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
238
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 51
diff changeset
239 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
240 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
241 """
91
f7525fa66bb0 Fix ECL instruction 3
Thibaut Girka <thib@sitedethib.com>
parents: 87
diff changeset
242 counter_value = self._getval(variable_id) - 1
f7525fa66bb0 Fix ECL instruction 3
Thibaut Girka <thib@sitedethib.com>
parents: 87
diff changeset
243 if counter_value > 0:
f7525fa66bb0 Fix ECL instruction 3
Thibaut Girka <thib@sitedethib.com>
parents: 87
diff changeset
244 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
245 self.frame, self.instruction_pointer = frame, instruction_pointer
47
1f1793e7ec8e Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
246
1f1793e7ec8e Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
247
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
248 @instruction(4)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
249 @instruction(5)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
250 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
251 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
252
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
253
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
254 @instruction(6)
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
255 def set_random_int(self, variable_id, maxval):
63
8527fe640844 Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 62
diff changeset
256 """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
257 """
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
258 self._setval(variable_id, int(self._getval(maxval) * self._game_state.prng.rand_double()))
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
259
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
260
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
261 @instruction(8)
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
262 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
263 """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
264 """
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
265 self._setval(variable_id, self._getval(maxval) * self._game_state.prng.rand_double())
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
266
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
267
59
4fe37a620b22 Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents: 58
diff changeset
268 @instruction(9)
4fe37a620b22 Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents: 58
diff changeset
269 def set_random_float2(self, variable_id, minval, amp):
4fe37a620b22 Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents: 58
diff changeset
270 self._setval(variable_id, self._getval(minval) + self._getval(amp) * self._game_state.prng.rand_double())
4fe37a620b22 Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents: 58
diff changeset
271
4fe37a620b22 Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents: 58
diff changeset
272
75
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
273 @instruction(10)
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
274 def store_x(self, variable_id):
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
275 self._setval(variable_id, self._enemy.x)
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
276
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
277
63
8527fe640844 Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 62
diff changeset
278 @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
279 @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
280 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
281 #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
282 # 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
283 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
284
8527fe640844 Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 62
diff changeset
285
87
fda176f07d6d Fix add_int
Thibaut Girka <thib@sitedethib.com>
parents: 83
diff changeset
286 @instruction(13)
fda176f07d6d Fix add_int
Thibaut Girka <thib@sitedethib.com>
parents: 83
diff changeset
287 @instruction(20)
fda176f07d6d Fix add_int
Thibaut Girka <thib@sitedethib.com>
parents: 83
diff changeset
288 def add(self, variable_id, a, b):
fda176f07d6d Fix add_int
Thibaut Girka <thib@sitedethib.com>
parents: 83
diff changeset
289 #TODO: 13 takes only ints and 20 only floats.
fda176f07d6d Fix add_int
Thibaut Girka <thib@sitedethib.com>
parents: 83
diff changeset
290 # 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
291 self._setval(variable_id, self._getval(a) + self._getval(b))
fda176f07d6d Fix add_int
Thibaut Girka <thib@sitedethib.com>
parents: 83
diff changeset
292
fda176f07d6d Fix add_int
Thibaut Girka <thib@sitedethib.com>
parents: 83
diff changeset
293
63
8527fe640844 Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 62
diff changeset
294 @instruction(15)
8527fe640844 Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 62
diff changeset
295 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
296 #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
297 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
298
8527fe640844 Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 62
diff changeset
299
8527fe640844 Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 62
diff changeset
300 @instruction(16)
8527fe640844 Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 62
diff changeset
301 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
302 #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
303 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
304
8527fe640844 Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 62
diff changeset
305
8527fe640844 Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 62
diff changeset
306 @instruction(17)
8527fe640844 Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 62
diff changeset
307 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
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
96
54929d495654 Handle ECL instruction 18
Thibaut Girka <thib@sitedethib.com>
parents: 95
diff changeset
311 @instruction(18)
54929d495654 Handle ECL instruction 18
Thibaut Girka <thib@sitedethib.com>
parents: 95
diff changeset
312 def increment(self, variable_id):
54929d495654 Handle ECL instruction 18
Thibaut Girka <thib@sitedethib.com>
parents: 95
diff changeset
313 self._setval(variable_id, self._getval(variable_id) + 1)
54929d495654 Handle ECL instruction 18
Thibaut Girka <thib@sitedethib.com>
parents: 95
diff changeset
314
54929d495654 Handle ECL instruction 18
Thibaut Girka <thib@sitedethib.com>
parents: 95
diff changeset
315
63
8527fe640844 Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 62
diff changeset
316 @instruction(23)
8527fe640844 Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 62
diff changeset
317 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
318 #TODO: takes only floats.
63
8527fe640844 Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 62
diff changeset
319 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
320
8527fe640844 Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 62
diff changeset
321
77
6fa6d74a049a Handle a new ECL instruction, and add some names.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 76
diff changeset
322 @instruction(25)
6fa6d74a049a Handle a new ECL instruction, and add some names.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 76
diff changeset
323 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
324 #TODO: takes only floats.
6fa6d74a049a Handle a new ECL instruction, and add some names.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 76
diff changeset
325 self._setval(variable_id, math.atan2(self._getval(y2) - self._getval(y1), self._getval(x2) - self._getval(x1)))
6fa6d74a049a Handle a new ECL instruction, and add some names.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 76
diff changeset
326
6fa6d74a049a Handle a new ECL instruction, and add some names.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 76
diff changeset
327
51
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
328 @instruction(27)
63
8527fe640844 Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 62
diff changeset
329 @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
330 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
331 #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
332 a, b = self._getval(a), self._getval(b)
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
333 if a < b:
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
334 self.comparison_reg = -1
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
335 elif a == b:
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
336 self.comparison_reg = 0
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
337 else:
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
338 self.comparison_reg = 1
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
339
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
340
64
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
341 @instruction(29)
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
342 def relative_jump_if_lower_than(self, frame, instruction_pointer):
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
343 if self.comparison_reg == -1:
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
344 self.relative_jump(frame, instruction_pointer)
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
345
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
346
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
347 @instruction(30)
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
348 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
349 if self.comparison_reg != 1:
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
350 self.relative_jump(frame, instruction_pointer)
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
351
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
352
51
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
353 @instruction(31)
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
354 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
355 if self.comparison_reg == 0:
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
356 self.relative_jump(frame, instruction_pointer)
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
357
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
358
64
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
359 @instruction(32)
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
360 def relative_jump_if_greater_than(self, frame, instruction_pointer):
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
361 if self.comparison_reg == 1:
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
362 self.relative_jump(frame, instruction_pointer)
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
363
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
364
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
365 @instruction(33)
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
366 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
367 if self.comparison_reg != -1:
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
368 self.relative_jump(frame, instruction_pointer)
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
369
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
370
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
371 @instruction(34)
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
372 def relative_jump_if_not_equal(self, frame, instruction_pointer):
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
373 if self.comparison_reg != 0:
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
374 self.relative_jump(frame, instruction_pointer)
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
375
d469012368b3 Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 63
diff changeset
376
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
377 @instruction(35)
47
1f1793e7ec8e Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
378 def call(self, sub, param1, param2):
1f1793e7ec8e Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
379 self.stack.append((self.sub, self.frame, self.instruction_pointer,
51
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
380 self.variables, self.comparison_reg))
47
1f1793e7ec8e Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
381 self.sub = sub
1f1793e7ec8e Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
382 self.frame = 0
1f1793e7ec8e Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
383 self.instruction_pointer = 0
1f1793e7ec8e Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
384 self.variables = [param1, 0, 0, 0,
1f1793e7ec8e Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
385 param2, 0., 0., 0.,
1f1793e7ec8e Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
386 0, 0, 0, 0]
1f1793e7ec8e Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
387
1f1793e7ec8e Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
388
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
389 @instruction(36)
47
1f1793e7ec8e Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
390 def ret(self):
51
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
391 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
392
1f1793e7ec8e Handle a few more opcodes
Thibaut Girka <thib@sitedethib.com>
parents: 43
diff changeset
393
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
394 @instruction(39)
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
395 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
396 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
397 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
398
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
399
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
400 @instruction(43)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
401 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
402 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
403
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
404
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
405 @instruction(45)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
406 def set_angle_speed(self, angle, speed):
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
407 self._enemy.angle, self._enemy.speed = angle, speed
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
408
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
409
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
410 @instruction(46)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
411 def set_rotation_speed(self, speed):
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
412 self._enemy.rotation_speed = speed
23
444ac7bca7bc Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
413
444ac7bca7bc Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
414
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
415 @instruction(47)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
416 def set_speed(self, speed):
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
417 self._enemy.speed = speed
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
418
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
419
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
420 @instruction(48)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
421 def set_acceleration(self, acceleration):
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
422 self._enemy.acceleration = acceleration
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
423
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
424
70
7c1f20407b3e Add set_random_angle support
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
425 @instruction(49)
7c1f20407b3e Add set_random_angle support
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
426 def set_random_angle(self, min_angle, max_angle):
7c1f20407b3e Add set_random_angle support
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
427 angle = self._game_state.prng.rand_double() * (max_angle - min_angle) + min_angle
7c1f20407b3e Add set_random_angle support
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
428 self._enemy.angle = angle
7c1f20407b3e Add set_random_angle support
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
429
7c1f20407b3e Add set_random_angle support
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
430
51
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
431 @instruction(50)
70
7c1f20407b3e Add set_random_angle support
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
432 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
433 if self._enemy.screen_box:
4fe37a620b22 Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents: 58
diff changeset
434 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
435 else:
4fe37a620b22 Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents: 58
diff changeset
436 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
437
51
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
438 angle = self._game_state.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
439 sa, ca = sin(angle), cos(angle)
4fe37a620b22 Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents: 58
diff changeset
440
4fe37a620b22 Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents: 58
diff changeset
441 distx = min(96.0, (maxx - minx) / 2.)
4fe37a620b22 Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents: 58
diff changeset
442 disty = min(96.0, (maxy - miny) / 2.)
4fe37a620b22 Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents: 58
diff changeset
443
4fe37a620b22 Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents: 58
diff changeset
444 if self._enemy.x > maxx - 96.0:
4fe37a620b22 Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents: 58
diff changeset
445 ca = -abs(ca)
4fe37a620b22 Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents: 58
diff changeset
446 elif self._enemy.x < minx + 96.0:
4fe37a620b22 Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents: 58
diff changeset
447 ca = abs(ca)
4fe37a620b22 Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents: 58
diff changeset
448
4fe37a620b22 Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents: 58
diff changeset
449 if self._enemy.y > maxy - 48.0:
4fe37a620b22 Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents: 58
diff changeset
450 sa = -abs(sa)
4fe37a620b22 Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents: 58
diff changeset
451 elif self._enemy.y < miny + 48.0:
4fe37a620b22 Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents: 58
diff changeset
452 sa = abs(sa)
4fe37a620b22 Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents: 58
diff changeset
453 self._enemy.angle = atan2(sa, ca)
51
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
454
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
455
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
456 @instruction(51)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
457 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
458 #TODO: unknown
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
459 self._enemy.speed = speed
79
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
460 self._enemy.angle = self._enemy.get_player_angle()
43
7195aaf95f6e Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents: 42
diff changeset
461
7195aaf95f6e Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents: 42
diff changeset
462
76
f305c0e406d6 Handle all move_to_* ECL instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 75
diff changeset
463 @instruction(56)
f305c0e406d6 Handle all move_to_* ECL instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 75
diff changeset
464 def move_to_linear(self, duration, x, y, z):
f305c0e406d6 Handle all move_to_* ECL instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 75
diff changeset
465 self._enemy.move_to(duration, x, y, z, lambda x: x)
f305c0e406d6 Handle all move_to_* ECL instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 75
diff changeset
466
f305c0e406d6 Handle all move_to_* ECL instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 75
diff changeset
467
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
468 @instruction(57)
76
f305c0e406d6 Handle all move_to_* ECL instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 75
diff changeset
469 def move_to_decel(self, duration, x, y, z):
62
1f591adcea04 Fix animation determination (ins_98 stuff) and some interpolation functions
Thibaut Girka <thib@sitedethib.com>
parents: 59
diff changeset
470 self._enemy.move_to(duration, x, y, z, lambda x: 2. * x - x ** 2)
1f591adcea04 Fix animation determination (ins_98 stuff) and some interpolation functions
Thibaut Girka <thib@sitedethib.com>
parents: 59
diff changeset
471
1f591adcea04 Fix animation determination (ins_98 stuff) and some interpolation functions
Thibaut Girka <thib@sitedethib.com>
parents: 59
diff changeset
472
1f591adcea04 Fix animation determination (ins_98 stuff) and some interpolation functions
Thibaut Girka <thib@sitedethib.com>
parents: 59
diff changeset
473 @instruction(59)
76
f305c0e406d6 Handle all move_to_* ECL instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 75
diff changeset
474 def move_to_accel(self, duration, x, y, z):
75
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
475 self._enemy.move_to(duration, x, y, z, 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
476
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
477
57
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 55
diff changeset
478 @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
479 def stop_in(self, duration):
75
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
480 self._enemy.stop_in(duration, lambda x: x)
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
481
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
482
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
483 @instruction(63)
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
484 def stop_in_accel(self, duration):
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
485 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
486
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 55
diff changeset
487
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
488 @instruction(65)
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
489 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
490 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
491
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
492
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
493 @instruction(66)
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
494 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
495 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
496
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
497
57
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 55
diff changeset
498 @instruction(67)
82
de48213a02bf Fix a few things
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
499 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
500 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
501 angle, flags):
82
de48213a02bf Fix a few things
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
502 self._enemy.set_bullet_attributes(67, anim,
de48213a02bf Fix a few things
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
503 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
504 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
505 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
506 self._getval(speed),
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
507 self._getval(speed2),
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
508 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
509 self._getval(angle),
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
510 flags)
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
511
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
512
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
513 @instruction(68)
82
de48213a02bf Fix a few things
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
514 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
515 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
516 angle, flags):
82
de48213a02bf Fix a few things
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
517 self._enemy.set_bullet_attributes(68, anim,
de48213a02bf Fix a few things
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
518 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
519 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
520 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
521 self._getval(speed),
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
522 self._getval(speed2),
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
523 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
524 self._getval(angle),
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
525 flags)
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
526
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
527
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
528 @instruction(69)
82
de48213a02bf Fix a few things
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
529 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
530 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
531 angle, flags):
82
de48213a02bf Fix a few things
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
532 self._enemy.set_bullet_attributes(69, anim,
de48213a02bf Fix a few things
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
533 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
534 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
535 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
536 self._getval(speed),
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
537 self._getval(speed2),
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
538 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
539 self._getval(angle),
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
540 flags)
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
541
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
542
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
543 @instruction(70)
82
de48213a02bf Fix a few things
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
544 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
545 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
546 angle, flags):
82
de48213a02bf Fix a few things
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
547 self._enemy.set_bullet_attributes(70, anim,
de48213a02bf Fix a few things
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
548 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
549 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
550 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
551 self._getval(speed),
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
552 self._getval(speed2),
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
553 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
554 self._getval(angle),
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
555 flags)
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
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
558 @instruction(71)
82
de48213a02bf Fix a few things
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
559 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
560 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
561 angle, flags):
82
de48213a02bf Fix a few things
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
562 self._enemy.set_bullet_attributes(71, anim,
de48213a02bf Fix a few things
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
563 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
564 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
565 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
566 self._getval(speed),
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
567 self._getval(speed2),
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
568 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
569 self._getval(angle),
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
570 flags)
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
571
57
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 55
diff changeset
572
83
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
573 @instruction(74)
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
574 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
575 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
576 angle, flags):
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
577 #TODO
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
578 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
579 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
580 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
581 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
582 self._getval(speed),
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
583 self._getval(speed2),
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
584 self._getval(launch_angle),
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
585 self._getval(angle),
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
586 flags)
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
587
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
588
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
589 @instruction(75)
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
590 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
591 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
592 angle, flags):
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
593 #TODO
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
594 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
595 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
596 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
597 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
598 self._getval(speed),
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
599 self._getval(speed2),
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
600 self._getval(launch_angle),
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
601 self._getval(angle),
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
602 flags)
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
603
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 82
diff changeset
604
78
bcf965ede96c Fix/rename/comment a few things
Thibaut Girka <thib@sitedethib.com>
parents: 77
diff changeset
605 @instruction(76)
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
606 def set_bullet_interval(self, value):
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
607 self._enemy.bullet_launch_interval = value
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
608
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
609
78
bcf965ede96c Fix/rename/comment a few things
Thibaut Girka <thib@sitedethib.com>
parents: 77
diff changeset
610 @instruction(77)
bcf965ede96c Fix/rename/comment a few things
Thibaut Girka <thib@sitedethib.com>
parents: 77
diff changeset
611 def set_bullet_interval_ex(self, value):
82
de48213a02bf Fix a few things
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
612 self._enemy.bullet_launch_interval = value
de48213a02bf Fix a few things
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
613 self._enemy.bullet_launch_timer = int(self._game_state.prng.rand_double() * value) #TODO: check
78
bcf965ede96c Fix/rename/comment a few things
Thibaut Girka <thib@sitedethib.com>
parents: 77
diff changeset
614
bcf965ede96c Fix/rename/comment a few things
Thibaut Girka <thib@sitedethib.com>
parents: 77
diff changeset
615
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
616 @instruction(78)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
617 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
618 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
619
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
620
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
621 @instruction(79)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
622 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
623 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
624
444ac7bca7bc Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
625
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
626 @instruction(81)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
627 def set_bullet_launch_offset(self, x, y, z):
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
628 self._enemy.bullet_launch_offset = (x, y)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
629
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
630
79
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
631 @instruction(82)
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
632 def set_extended_bullet_attributes(self, *attributes):
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
633 self._enemy.extended_bullet_attributes = attributes
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
634
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
635
95
e2d8f2a56ea4 Handle ECL opcodes with string.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 93
diff changeset
636 @instruction(93)
e2d8f2a56ea4 Handle ECL opcodes with string.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 93
diff changeset
637 def set_spellcard(self, unknown, number, name):
e2d8f2a56ea4 Handle ECL opcodes with string.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 93
diff changeset
638 #TODO: display it on the game.
e2d8f2a56ea4 Handle ECL opcodes with string.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 93
diff changeset
639 print("%d - %s" % (number, name))
e2d8f2a56ea4 Handle ECL opcodes with string.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 93
diff changeset
640
e2d8f2a56ea4 Handle ECL opcodes with string.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 93
diff changeset
641
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
642 @instruction(97)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
643 def set_anim(self, sprite_index):
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
644 self._enemy.set_anim(sprite_index)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
645
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
646
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
647 @instruction(98)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
648 def set_multiple_anims(self, default, end_left, end_right, left, right):
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
649 self._enemy.movement_dependant_sprites = end_left, end_right, left, right
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
650 self._enemy.set_anim(default)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
651
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 @instruction(100)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
654 def set_death_anim(self, sprite_index):
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
655 self._enemy.death_anim = sprite_index % 256 #TODO
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
656
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
657
57
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 55
diff changeset
658 @instruction(101)
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 55
diff changeset
659 def set_boss_mode(self, unknown):
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 55
diff changeset
660 #TODO: unknown
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 55
diff changeset
661 self._game_state.boss = self._enemy
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 55
diff changeset
662
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 55
diff changeset
663
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
664 @instruction(103)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
665 def set_hitbox(self, width, height, depth):
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
666 self._enemy.hitbox = (width, height)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
667
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
668
79
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
669 @instruction(104)
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
670 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
671 """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
672 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
673 """
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
674 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
675
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 78
diff changeset
676
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
677 @instruction(105)
75
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
678 def set_damageable(self, damageable):
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
679 self._enemy.damageable = bool(damageable & 1)
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
680
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
681
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
682 @instruction(107)
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
683 def set_death_flags(self, death_flags):
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
684 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
685
23
444ac7bca7bc Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
686
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
687 @instruction(108)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
688 def set_death_callback(self, sub):
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
689 self._enemy.death_callback = sub
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
690
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
691
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
692 @instruction(109)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
693 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
694 #TODO
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
695 #XXX: this is a hack to display bosses although we don't handle MSG :)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
696 if index == 0:
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
697 self.sub = value
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
698 self.frame = 0
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
699 self.instruction_pointer = 0
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
700
23
444ac7bca7bc Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
701
51
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
702 @instruction(111)
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
703 def set_life(self, value):
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
704 self._enemy.life = value
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
705
0707ff53e7b5 Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
706
67
e2cb9d434dc2 Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents: 65
diff changeset
707 @instruction(112)
e2cb9d434dc2 Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents: 65
diff changeset
708 def set_ellapsed_time(self, value):
e2cb9d434dc2 Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents: 65
diff changeset
709 """Sets the enemy's frame counter.
e2cb9d434dc2 Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents: 65
diff changeset
710 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
711 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
712 """
e2cb9d434dc2 Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents: 65
diff changeset
713 self._enemy.frame = value
e2cb9d434dc2 Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents: 65
diff changeset
714
e2cb9d434dc2 Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents: 65
diff changeset
715
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
716 @instruction(113)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
717 def set_low_life_trigger(self, value):
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
718 self._enemy.low_life_trigger = value
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
719
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
720
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
721 @instruction(114)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
722 def set_low_life_callback(self, sub):
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
723 self._enemy.low_life_callback = sub
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
724
23
444ac7bca7bc Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
725
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
726 @instruction(115)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
727 def set_timeout(self, timeout):
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
728 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
729
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
730
67
e2cb9d434dc2 Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents: 65
diff changeset
731 @instruction(116)
e2cb9d434dc2 Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents: 65
diff changeset
732 def set_timeout_callback(self, sub):
e2cb9d434dc2 Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents: 65
diff changeset
733 self._enemy.timeout_callback = sub
e2cb9d434dc2 Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents: 65
diff changeset
734
e2cb9d434dc2 Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents: 65
diff changeset
735
e2cb9d434dc2 Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents: 65
diff changeset
736 @instruction(117)
e2cb9d434dc2 Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents: 65
diff changeset
737 def set_touchable(self, value):
e2cb9d434dc2 Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents: 65
diff changeset
738 """Defines whether the enemy is “touchable”.
e2cb9d434dc2 Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents: 65
diff changeset
739 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
740 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
741 """
e2cb9d434dc2 Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents: 65
diff changeset
742 self._enemy.touchable = bool(value)
e2cb9d434dc2 Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents: 65
diff changeset
743
e2cb9d434dc2 Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents: 65
diff changeset
744
75
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
745 @instruction(120)
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
746 def set_automatic_orientation(self, flags):
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
747 #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
748 self._enemy.automatic_orientation = bool(flags & 1)
75
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
749
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
750
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
751 @instruction(123)
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
752 def skip_frames(self, frames):
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
753 #TODO: is that all?
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
754 self.frame += self._getval(frames)
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
755
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 74
diff changeset
756
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
757 @instruction(126)
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
758 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
759 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
760