From 075335d187f45de7d002e3f44f6ec93b30abed78 Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Sun, 5 Nov 2023 11:08:16 +0100 Subject: rounds --- src/rounds.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/rounds.c (limited to 'src/rounds.c') diff --git a/src/rounds.c b/src/rounds.c new file mode 100644 index 0000000..8db9ae8 --- /dev/null +++ b/src/rounds.c @@ -0,0 +1,35 @@ + +bool current_round_is_done() +{ + return _current_round.zombies == 0 && number_of_zombies_active() == 0; +} + +void start_next_round() +{ + _current_round.round_nr++; + _current_round.zombies = 6; + _current_round.state = ROUND_SWITCHING; + _current_round.round_timer = 0.0f; + + log_infox("Next round: %d", _current_round.round_nr); +} + +int zombies_left_in_current_round() +{ + if (_current_round.state != ROUND_SPAWNING) return 0; + return _current_round.zombies; +} + +void update_round_server() +{ + _current_round.round_timer += SERVER_TICK_RATE; + if (_current_round.state == ROUND_SWITCHING) { + if (_current_round.round_timer >= ROUND_SWITCH_TIME) { + _current_round.state = ROUND_SPAWNING; + } + } + + if (current_round_is_done()) { + start_next_round(); + } +} \ No newline at end of file -- cgit v1.2.3-70-g09d2