pub fn major_event(&mut self, state: &WorldState) -> Option<GameEvent> {
        match self.rng.gen_range(1..=1_000) {
            0..=35 => {
                if state.bugs == 0 {
                    return None;
                }

                let task = GameTaskBuilder::new(
                    "",
                    TaskKind::Bug,
                    self.rng.gen_range(0..2),
                    self.rng.gen_range(2..12),
                );

                Some(GameEvent::BugReported(task))
            }
            36..=89 => {
                // someone quits due to project complexity
                let human_count = state.humans.iter().filter(|h| !h.quit).count();
                let complexity = state.complexity;
                let pressure = complexity as u32 + human_count as u32 * 5;
                if human_count > 1 && pressure >= 116 {
                    // pick a random human to quit
                    let index = self.rng.gen_range(1..=human_count - 1);
                    let human = state.humans.iter().filter(|h| !h.quit).nth(index).unwrap();

                    Some(GameEvent::HumanQuit(human.id))
                } else {
                    None
                }
            }
            950..=1_000 => {
                let n_new_tasks = self.rng.gen_range(1..=3);

                let tasks = (0..n_new_tasks)
                    .map(|_| {
                        GameTaskBuilder::new_with_deadline(
                            "Extraordinary task",
                            TaskKind::Normal,
                            // generally higher score than usual
                            self.rng.gen_range(4..=16),
                            // generally harder too
                            self.rng.gen_range(3..15),
                        )
                    })
                    .collect();

                Some(GameEvent::MajorFeatureRequested { message: 0, tasks })
            }
            750..=899 => Some(GameEvent::RandomReport(self.rng.gen_range(0..=8))),
            _ => {
                // do nothing
                None
            }
        }
    }
/// Roll for whether to have a major event
Roll for whether to have a major event
Roll for whether to have a major event
pub fn major_event(&mut self, state: &WorldState) -> Option<GameEvent> {
        match self.rng.gen_range(1..=1_000) {
            0..=35 => {
                if state.bugs == 0 {
                    return None;
                }
                let task = GameTaskBuilder::new(
                    "",
                    TaskKind::Bug,
                    self.rng.gen_range(0..2),
                    self.rng.gen_range(2..12),
                );
                Some(GameEvent::BugReported(task))
            }
            36..=89 => {
                // someone quits due to project complexity
                let human_count = state.humans.iter().filter(|h| !h.quit).count();
                let complexity = state.complexity;
                let pressure = complexity as u32 + human_count as u32 * 5;
                if human_count > 1 && pressure >= 116 {
                    // pick a random human to quit
                    let index = self.rng.gen_range(1..=human_count - 1);
                    let human = state.humans.iter().filter(|h| !h.quit).nth(index).unwrap();
                    Some(GameEvent::HumanQuit(human.id))
                } else {
                    None
                }
            }
            950..=1_000 => {
                let n_new_tasks = self.rng.gen_range(1..=3);
                let tasks = (0..n_new_tasks)
                    .map(|_| {
                        GameTaskBuilder::new_with_deadline(
                            "Extraordinary task",
                            TaskKind::Normal,
                            // generally higher score than usual
                            self.rng.gen_range(4..=16),
                            // generally harder too
                            self.rng.gen_range(3..15),
                        )
                    })
                    .collect();
                Some(GameEvent::MajorFeatureRequested { message: 0, tasks })
            }
            750..=899 => Some(GameEvent::RandomReport(self.rng.gen_range(0..=8))),
            _ => {
                // do nothing
                None
            }
        }
    }
pub fn major_event ( & mut self , state : & WorldState ) -> Option < GameEvent > { match self . rng . gen_range ( 1 ..= 1_000 ) { 0 ..= 35 => { if state . bugs == 0 { return None ; } let task = GameTaskBuilder :: new ( " " , TaskKind :: Bug , self . rng . gen_range ( 0 .. 2 ) , self . rng . gen_range ( 2 .. 12 ) , ) ; Some ( GameEvent :: BugReported ( task ) ) } 36 ..= 89 => { // someone quits due to project complexity let human_count = state . humans . iter ( ) . filter ( | h | ! h . quit ) . count ( ) ; let complexity = state . complexity ; let pressure = complexity as u32 + human_count as u32 * 5 ; if human_count > 1 && pressure >= 116 { // pick a random human to quit let index = self . rng . gen_range ( 1 ..= human_count - 1 ) ; let human = state . humans . iter ( ) . filter ( | h | ! h . quit ) . nth ( index ) . unwrap ( ) ; Some ( GameEvent :: HumanQuit ( human . id ) ) } else { None } } 950 ..= 1_000 => { let n_new_tasks = self . rng . gen_range ( 1 ..= 3 ) ; let tasks = ( 0 .. n_new_tasks ) . map ( | _ | { GameTaskBuilder :: new_with_deadline ( " " , TaskKind :: Normal , // generally higher score than usual self . rng . gen_range ( 4 ..= 16 ) , // generally harder too self . rng . gen_range ( 3 .. 15 ) , ) } ) . collect ( ) ; Some ( GameEvent :: MajorFeatureRequested { message : 0 , tasks } ) } 750 ..= 899 => Some ( GameEvent :: RandomReport ( self . rng . gen_range ( 0 ..= 8 ) ) ) , _ => { // do nothing None } } }
Roll for whether to have a major event
Roll for whether to have a major event
&mut self
state
&WorldState
&mut self
state
&WorldState