Commit 45ee79d1 authored by talljosh's avatar talljosh

Added a server arena option which when set only starts a game when all players...

Added a server arena option which when set only starts a game when all players are ready, not 70% of players. (This is useful for tournament play.)
parent 4683afeaed44
......@@ -104,6 +104,7 @@ class ArenaModelForm(forms.ModelForm):
'name',
'enabled',
'autoStartCountDown',
'require_everyone_ready',
'balance_bot_difficulty',
'machines_difficulty',
'force_half_width',
......
# Generated by Django 2.2.12 on 2021-01-26 11:30
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('trosnoth', '0029_auto_20200821_0142'),
]
operations = [
migrations.AddField(
model_name='trosnotharena',
name='require_everyone_ready',
field=models.BooleanField(default=False, help_text='If enabled, a new game will only start when the countdown runs out, or every player selects ready. If disabled, only 70% of players need to select ready.'),
),
]
......@@ -89,6 +89,13 @@ class TrosnothArena(models.Model):
'to disable)',
default=90,
)
require_everyone_ready = models.BooleanField(
default=False,
help_text='If enabled, a new game will only start when the '
'countdown runs out, or every player selects ready. '
'If disabled, only 70% of players need to select '
'ready.',
)
balance_bot_difficulty = models.IntegerField(
null=True, blank=True, verbose_name='Difficulty for BalanceBot',
default=BOT_DIFFICULTY_EASY)
......
......@@ -575,6 +575,9 @@ class LobbySettings(object):
def get_forced_duration(self):
raise NotImplementedError('{}.get_forced_duration'.format(type(self).__name__))
def get_require_everyone_ready(self):
raise NotImplementedError(f'{type(self).__name__}.get_require_everyone_ready')
class ServerLobbySettings(LobbySettings):
def __init__(self, arenaManager):
......@@ -588,6 +591,10 @@ class ServerLobbySettings(LobbySettings):
return None
return result
def get_require_everyone_ready(self):
record = self.arenaManager.getArenaRecord()
return record.require_everyone_ready
def get_forced_duration(self):
record = self.arenaManager.getArenaRecord()
return record.force_duration
......@@ -611,6 +618,9 @@ class LocalLobbySettings(LobbySettings):
def get_forced_size(self):
return None
def get_require_everyone_ready(self):
return False
class LobbyLevel(Level):
recordGame = False
......@@ -623,6 +633,7 @@ class LobbyLevel(Level):
if lobbySettings is None:
lobbySettings = LocalLobbySettings()
self.lobbySettings = lobbySettings
self.require_everyone_ready = False
def pre_sync_setup(self):
# Keep the existing map, but make all players neutral
......@@ -644,6 +655,7 @@ class LobbyLevel(Level):
AddBotsForLobbyTrigger(self).activate()
StartGameWhenReadyTrigger(self).activate()
autoStartTime = self.lobbySettings.getAutoStartCountDown()
self.require_everyone_ready = self.lobbySettings.get_require_everyone_ready()
title = 'Lobby'
userInfo = (
......@@ -656,6 +668,7 @@ class LobbyLevel(Level):
'Use the menu in the bottom left to leave game',
)
autoStartTime = None
self.require_everyone_ready = False
self.setUserInfo(title, userInfo, BOT_GOAL_NONE)
self.world.abilities.set(zoneCaps=False, renaming=True)
......@@ -676,7 +689,8 @@ class LobbyLevel(Level):
if not players:
return
ready_players = [p for p in players if p.readyToStart]
if len(ready_players) < 0.7 * len(players):
ratio = 1 if self.require_everyone_ready else 0.7
if len(ready_players) < ratio * len(players):
return
# Remove players who are not ready
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment