changeset 737:0977d479e37d

ecl_vm: Uncomment instruction 121 function 8.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 28 Dec 2019 22:56:32 +0100
parents ff9651cfe1b0
children 817c453b7223
files src/th06/ecl_vm.rs src/th06/enemy.rs
diffstat 2 files changed, 38 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/src/th06/ecl_vm.rs	Sat Dec 28 22:18:23 2019 +0100
+++ b/src/th06/ecl_vm.rs	Sat Dec 28 22:56:32 2019 +0100
@@ -1,7 +1,7 @@
 //! ECL runner.
 
 use crate::th06::ecl::{Ecl, SubInstruction};
-use crate::th06::enemy::{Enemy, Offset};
+use crate::th06::enemy::{Enemy, Offset, BulletAttributes};
 use crate::util::prng::Prng;
 use std::cell::RefCell;
 use std::rc::Rc;
@@ -1107,30 +1107,43 @@
                         }
                     }
                     8 => { // Vampire Fantasy
-                        /*
-                        let mut n = 0:
-                        for bullet in game.bullets{
-                            if bullet._bullet_type.state != 0 && bullet._bullet_type.state != 5 && (30. <= (bullet.sprites[0].additional_infos)->height) {
-                                          local_5c.pos[0] = local_bullet_vec->pos[0];
-                                          local_5c.pos[1] = local_bullet_vec->pos[1];
-                                          local_5c.pos[2] = local_bullet_vec->pos[2];
-                                          local_5c.anim = 3;
-                                          local_5c.sprite_index_offset = 1;
-                                          fVar3 = prng_double(&PRNG_STATE);
-                                          local_5c.launch_angle = (self.get_prng().borrow_mut().get_f64() * (2. * std::f64::consts::PI) - std::f64::consts::PI) as f32;
-                                          local_5c.speed = 0.00000000;
-                                          local_5c.bullets_per_shot = 1;
-                                          local_5c.nb_of_shots = 1;
-                                          local_5c.flags = 8;
-                                          local_5c.bullet_type = 1;
-                                          bullet_fire(&local_5c,&ETAMA_ARRAY);
+                        let n = {
+                            let enemy = self.enemy.borrow();
+                            let game = enemy.game.upgrade().unwrap();
+                            let mut game = game.borrow_mut();
+                            let mut n = 0;
+                            for bullet in game.bullets.iter() {
+                                let mut bullet = bullet.borrow();
+                                // TODO: uncomment that one.
+                                if bullet.state != 0 && bullet.state != 5 /* && (30. <= (bullet.sprites[0].additional_infos).height) */ {
+                                    let prng = enemy.prng.upgrade().unwrap();
+                                    let random = prng.borrow_mut().get_f64();
+                                    let launch_angle = (random * (2. * std::f64::consts::PI) - std::f64::consts::PI) as f32;
+                                    let mut attribs = BulletAttributes {
+                                        // TODO: check if the z value of this pos is really used.
+                                        pos: bullet.pos,
+                                        anim: 3,
+                                        sprite_index_offset: 1,
+                                        launch_angle,
+                                        speed: 0.,
+                                        angle: 0.,
+                                        speed2: 0.,
+                                        bullets_per_shot: 1,
+                                        number_of_shots: 1,
+                                        flags: 8,
+                                        bullet_type: 1,
+                                        extended_attributes: Default::default(),
+                                        sound: None,
+                                    };
+                                    attribs.fire();
+                                    n += 1
                                 }
-                            n += 1
-                        }
+                            }
+                            n
+                        };
                         //TODO: this variable might not always be correct! it uses the argument in
                         //th06: *(int *)(param_1 + 0x9b0) = local_60;
-                        self._setval(-10004, n)
-                        */
+                        self.set_i32(-10004, n);
                     }
 
                     9 => {
--- a/src/th06/enemy.rs	Sat Dec 28 22:18:23 2019 +0100
+++ b/src/th06/enemy.rs	Sat Dec 28 22:56:32 2019 +0100
@@ -93,6 +93,9 @@
 
     /// Current attributes of the bullet.
     pub attributes: [f32; 2],
+
+    /// TODO: what are the values?
+    pub state: i8,
 }
 
 /// God struct of our game.