2021-11-04 23:43:36 +03:00
/ * *
* The only implementation for ` BaseGameMode ` suitable for standard
* killing floor game types .
* Copyright 2021 Anton Tarasenko
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
* This file is part of Acedia .
*
* Acedia is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , version 3 of the License , or
* ( at your option ) any later version .
*
* Acedia is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with Acedia . If not , see < https : //www.gnu.org/licenses/>.
* /
class GameMode extends BaseGameMode
perobjectconfig
config ( AcediaGameModes ) ;
struct GameOption
{
var public string key ;
var public string value ;
} ;
// Allow to specify additional server options for this game mode
var protected config array < GameOption > option ;
// Specify `GameInfo`'s class to use, default is "KFMod.KFGameType"
// (plain string)
var protected config string gameTypeClass ;
// Short version of the name of the game mode players will see in
// voting handler messages sometimes (plain string)
var protected config string acronym ;
// Map prefix - only maps that start with specified prefix will be voteable for
// this game mode (plain string)
var protected config string mapPrefix ;
var private LoggerAPI . Definition warnBadOption ;
protected function DefaultIt ( )
{
title = "Acedia game mode" ;
difficulty = "Hell On Earth" ;
gameTypeClass = "KFMod.KFGameType" ;
acronym = "" ;
mapPrefix = "KF" ;
includeFeature . length = 0 ;
excludeFeature . length = 0 ;
includeMutator . length = 0 ;
option . length = 0 ;
}
2022-07-04 21:47:52 +03:00
protected function HashTable ToData ( )
2021-11-04 23:43:36 +03:00
{
2022-07-04 21:47:52 +03:00
local int i ;
local ArrayList nextArray ;
local HashTable result , nextPair ;
2021-11-04 23:43:36 +03:00
result = super . ToData ( ) ;
if ( result == none ) {
return none ;
}
2022-07-04 21:47:52 +03:00
result . SetString ( P ( "gameTypeClass" ) , gameTypeClass ) ;
result . SetString ( P ( "acronym" ) , acronym ) ;
result . SetString ( P ( "mapPrefix" ) , mapPrefix ) ;
nextArray = _ . collections . EmptyArrayList ( ) ;
2021-11-04 23:43:36 +03:00
for ( i = 0 ; i < option . length ; i += 1 )
{
2022-07-04 21:47:52 +03:00
nextPair = _ . collections . EmptyHashTable ( ) ;
nextPair . SetString ( P ( "key" ) , option [ i ] . key ) ;
nextPair . SetString ( P ( "value" ) , option [ i ] . value ) ;
2021-11-04 23:43:36 +03:00
nextArray . AddItem ( nextPair ) ;
2022-07-04 21:47:52 +03:00
_ . memory . Free ( nextPair ) ;
2021-11-04 23:43:36 +03:00
}
result . SetItem ( P ( "option" ) , nextArray ) ;
2022-07-04 21:47:52 +03:00
_ . memory . Free ( nextArray ) ;
2021-11-04 23:43:36 +03:00
return result ;
}
2022-07-04 21:47:52 +03:00
protected function FromData ( HashTable source )
2021-11-04 23:43:36 +03:00
{
local int i ;
2022-07-04 21:47:52 +03:00
local GameOption nextGameOption ;
local ArrayList nextArray ;
local HashTable nextPair ;
2021-11-04 23:43:36 +03:00
super . FromData ( source ) ;
if ( source == none ) {
return ;
}
2022-07-04 21:47:52 +03:00
gameTypeClass = source . GetString ( P ( "gameTypeClass" ) ) ;
acronym = source . GetString ( P ( "acronym" ) ) ;
mapPrefix = source . GetString ( P ( "mapPrefix" ) ) ;
nextArray = source . GetArrayList ( P ( "option" ) ) ;
2021-11-04 23:43:36 +03:00
if ( nextArray == none ) {
return ;
}
option . length = 0 ;
for ( i = 0 ; i < nextArray . GetLength ( ) ; i += 1 )
{
2022-07-04 21:47:52 +03:00
nextPair = HashTable ( nextArray . GetItem ( i ) ) ;
if ( nextPair == none ) {
continue ;
2021-11-04 23:43:36 +03:00
}
2022-07-04 21:47:52 +03:00
nextGameOption . key = nextPair . GetString ( P ( "key" ) ) ;
nextGameOption . value = nextPair . GetString ( P ( "value" ) ) ;
option [ option . length ] = nextGameOption ;
_ . memory . Free ( nextPair ) ;
2021-11-04 23:43:36 +03:00
}
2022-07-04 21:47:52 +03:00
_ . memory . Free ( nextArray ) ;
2021-11-04 23:43:36 +03:00
}
public function Text GetGameTypeClass ( )
{
if ( gameTypeClass == "" ) {
return P ( "KFMod.KFGameType" ) . Copy ( ) ;
}
else {
return _ . text . FromString ( gameTypeClass ) ;
}
}
public function Text GetAcronym ( )
{
if ( acronym == "" ) {
return _ . text . FromString ( string ( name ) ) ;
}
else {
return _ . text . FromString ( acronym ) ;
}
}
public function Text GetMapPrefix ( )
{
if ( acronym == "" ) {
return _ . text . FromString ( "KF-" ) ;
}
else {
return _ . text . FromString ( mapPrefix ) ;
}
}
/ * *
* Checks option - related settings ( ` option ` ) for correctness and reports
* any issues .
* Currently correctness check performs a simple validity check for mutator ,
* to make sure it would not define a new option in server ' s URL .
*
* See ` ValidateServerURLName() ` in ` BaseGameMode ` for more information .
* /
public function ReportBadOptions ( )
{
local int i ;
for ( i = 0 ; i < option . length ; i += 1 )
{
if ( ! ValidateServerURLName ( option [ i ] . key )
|| ! ValidateServerURLName ( option [ i ] . value ) )
{
_ . logger . Auto ( warnBadOption )
. Arg ( _ . text . FromString ( option [ i ] . key ) )
. Arg ( _ . text . FromString ( option [ i ] . value ) )
. Arg ( _ . text . FromString ( string ( name ) ) ) ;
}
}
}
/ * *
2022-07-15 16:37:04 +03:00
* @ return Server options as key - value pairs in an ` HashTable ` .
2021-11-04 23:43:36 +03:00
* /
2022-07-15 16:37:04 +03:00
public function HashTable GetOptions ( )
2021-11-04 23:43:36 +03:00
{
2022-07-15 16:37:04 +03:00
local int i ;
local HashTable result ;
result = _ . collections . EmptyHashTable ( ) ;
2021-11-04 23:43:36 +03:00
for ( i = 0 ; i < option . length ; i += 1 )
{
if ( ! ValidateServerURLName ( option [ i ] . key ) ) continue ;
if ( ! ValidateServerURLName ( option [ i ] . value ) ) continue ;
result . SetItem ( _ . text . FromString ( option [ i ] . key ) ,
_ . text . FromString ( option [ i ] . value ) ) ;
}
return result ;
}
defaultproperties
{
configName = "AcediaGameModes"
warnBadOption = ( l = LOG _Warning , m = "Option with key \"%1\" and value \"%2\" specified for game mode \"%3\" contains invalid characters and will be ignored. This is a configuration error, you should fix it." )
}