2009-04-19 18:07:22 +00:00
#region = = = = = = = = = = = = = = = = = = Copyright ( c ) 2007 Pascal vd Heiden
/ *
* Copyright ( c ) 2007 Pascal vd Heiden , www . codeimp . com
* This program is released under GNU General Public License
*
* This program 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 .
*
* /
#endregion
#region = = = = = = = = = = = = = = = = = = Namespaces
using System ;
using System.Collections ;
using System.Collections.Generic ;
using System.Globalization ;
using CodeImp.DoomBuilder.IO ;
using CodeImp.DoomBuilder.Map ;
using CodeImp.DoomBuilder.Editing ;
2012-06-01 10:17:47 +00:00
using CodeImp.DoomBuilder.GZBuilder.Data ;
2009-04-19 18:07:22 +00:00
#endregion
namespace CodeImp.DoomBuilder.Config
{
public class GameConfiguration
{
#region = = = = = = = = = = = = = = = = = = Constants
#endregion
#region = = = = = = = = = = = = = = = = = = Variables
// Original configuration
private Configuration cfg ;
// General settings
private string configname ;
private string enginename ;
private float defaulttexturescale ;
private float defaultflatscale ;
2010-01-02 20:54:35 +00:00
private bool scaledtextureoffsets ;
2009-04-19 18:07:22 +00:00
private string defaultsavecompiler ;
private string defaulttestcompiler ;
private string formatinterface ;
2013-06-06 10:22:58 +00:00
private string defaultLinedefActivation ; //mxd
2009-04-19 18:07:22 +00:00
private string singlesidedflag ;
private string doublesidedflag ;
private string impassableflag ;
private string upperunpeggedflag ;
private string lowerunpeggedflag ;
private bool mixtexturesflats ;
private bool generalizedactions ;
private bool generalizedeffects ;
private int start3dmodethingtype ;
private int linedefactivationsfilter ;
private string testparameters ;
private bool testshortpaths ;
private string makedoortrack ;
private int makedooraction ;
2012-04-14 12:22:19 +00:00
private int makedooractivate ;
2009-04-19 18:07:22 +00:00
private int [ ] makedoorargs ;
2012-04-14 12:22:19 +00:00
private Dictionary < string , bool > makedoorflags ;
2009-04-19 18:07:22 +00:00
private bool linetagindicatesectors ;
private string decorategames ;
2013-09-11 09:47:53 +00:00
private string skyflatname ;
2009-06-08 18:52:56 +00:00
private int maxtexturenamelength ;
2010-08-13 18:32:21 +00:00
private int leftboundary ;
private int rightboundary ;
private int topboundary ;
private int bottomboundary ;
2009-07-12 09:58:05 +00:00
private bool doomlightlevels ;
2009-04-19 18:07:22 +00:00
// Skills
private List < SkillInfo > skills ;
// Map lumps
private IDictionary maplumpnames ; // This is old, we should use maplumps instead
private Dictionary < string , MapLumpInfo > maplumps ;
// Texture/flat sources
private IDictionary textureranges ;
private IDictionary flatranges ;
private IDictionary patchranges ;
private IDictionary spriteranges ;
2009-05-12 09:50:08 +00:00
private IDictionary colormapranges ;
2009-04-19 18:07:22 +00:00
// Things
private List < string > defaultthingflags ;
private Dictionary < string , string > thingflags ;
private List < ThingCategory > thingcategories ;
private Dictionary < int , ThingTypeInfo > things ;
private List < FlagTranslation > thingflagstranslation ;
2012-08-27 11:39:14 +00:00
private List < ThingFlagsCompare > thingflagscompare ;
2009-04-19 18:07:22 +00:00
// Linedefs
private Dictionary < string , string > linedefflags ;
2009-07-31 11:00:11 +00:00
private List < string > sortedlinedefflags ;
2009-04-19 18:07:22 +00:00
private Dictionary < int , LinedefActionInfo > linedefactions ;
private List < LinedefActionInfo > sortedlinedefactions ;
private List < LinedefActionCategory > actioncategories ;
private List < LinedefActivateInfo > linedefactivates ;
private List < GeneralizedCategory > genactioncategories ;
private List < FlagTranslation > linedefflagstranslation ;
2013-07-19 15:30:58 +00:00
//mxd. Sidedefs
private Dictionary < string , string > sidedefflags ; //mxd
2009-04-19 18:07:22 +00:00
// Sectors
2013-07-10 08:59:17 +00:00
private Dictionary < string , string > sectorflags ; //mxd
2009-04-19 18:07:22 +00:00
private Dictionary < int , SectorEffectInfo > sectoreffects ;
private List < SectorEffectInfo > sortedsectoreffects ;
private List < GeneralizedOption > geneffectoptions ;
2009-07-10 19:15:22 +00:00
private StepsList brightnesslevels ;
2009-04-19 18:07:22 +00:00
// Universal fields
private List < UniversalFieldInfo > linedeffields ;
private List < UniversalFieldInfo > sectorfields ;
private List < UniversalFieldInfo > sidedeffields ;
private List < UniversalFieldInfo > thingfields ;
private List < UniversalFieldInfo > vertexfields ;
// Enums
private Dictionary < string , EnumList > enums ;
// Defaults
private List < DefinedTextureSet > texturesets ;
private List < ThingsFilter > thingfilters ;
2012-06-01 10:17:47 +00:00
2013-09-11 09:47:53 +00:00
//mxd. Holds base game type (doom, heretic, hexen or strife)
private GameType gameType ;
2009-04-19 18:07:22 +00:00
#endregion
#region = = = = = = = = = = = = = = = = = = Properties
// General settings
public string Name { get { return configname ; } }
public string EngineName { get { return enginename ; } }
public string DefaultSaveCompiler { get { return defaultsavecompiler ; } }
public string DefaultTestCompiler { get { return defaulttestcompiler ; } }
public float DefaultTextureScale { get { return defaulttexturescale ; } }
public float DefaultFlatScale { get { return defaultflatscale ; } }
2010-01-02 20:54:35 +00:00
public bool ScaledTextureOffsets { get { return scaledtextureoffsets ; } }
2009-04-19 18:07:22 +00:00
public string FormatInterface { get { return formatinterface ; } }
2013-06-06 10:22:58 +00:00
public string DefaultLinedefActivationFlag { get { return defaultLinedefActivation ; } } //mxd
2009-04-19 18:07:22 +00:00
public string SingleSidedFlag { get { return singlesidedflag ; } }
public string DoubleSidedFlag { get { return doublesidedflag ; } }
public string ImpassableFlag { get { return impassableflag ; } }
public string UpperUnpeggedFlag { get { return upperunpeggedflag ; } }
public string LowerUnpeggedFlag { get { return lowerunpeggedflag ; } }
public bool MixTexturesFlats { get { return mixtexturesflats ; } }
public bool GeneralizedActions { get { return generalizedactions ; } }
public bool GeneralizedEffects { get { return generalizedeffects ; } }
public int Start3DModeThingType { get { return start3dmodethingtype ; } }
public int LinedefActivationsFilter { get { return linedefactivationsfilter ; } }
public string TestParameters { get { return testparameters ; } }
public bool TestShortPaths { get { return testshortpaths ; } }
public string MakeDoorTrack { get { return makedoortrack ; } }
public int MakeDoorAction { get { return makedooraction ; } }
2012-04-14 12:22:19 +00:00
public int MakeDoorActivate { get { return makedooractivate ; } }
public Dictionary < string , bool > MakeDoorFlags { get { return makedoorflags ; } }
2009-04-19 18:07:22 +00:00
public int [ ] MakeDoorArgs { get { return makedoorargs ; } }
public bool LineTagIndicatesSectors { get { return linetagindicatesectors ; } }
public string DecorateGames { get { return decorategames ; } }
2013-09-11 09:47:53 +00:00
public string SkyFlatName { get { return skyflatname ; } }
2009-06-08 18:52:56 +00:00
public int MaxTextureNamelength { get { return maxtexturenamelength ; } }
2010-08-13 18:32:21 +00:00
public int LeftBoundary { get { return leftboundary ; } }
public int RightBoundary { get { return rightboundary ; } }
public int TopBoundary { get { return topboundary ; } }
public int BottomBoundary { get { return bottomboundary ; } }
2009-07-12 09:58:05 +00:00
public bool DoomLightLevels { get { return doomlightlevels ; } }
2009-04-19 18:07:22 +00:00
// Skills
public List < SkillInfo > Skills { get { return skills ; } }
// Map lumps
public IDictionary MapLumpNames { get { return maplumpnames ; } }
public Dictionary < string , MapLumpInfo > MapLumps { get { return maplumps ; } }
// Texture/flat sources
public IDictionary TextureRanges { get { return textureranges ; } }
public IDictionary FlatRanges { get { return flatranges ; } }
public IDictionary PatchRanges { get { return patchranges ; } }
public IDictionary SpriteRanges { get { return spriteranges ; } }
2009-05-12 09:50:08 +00:00
public IDictionary ColormapRanges { get { return colormapranges ; } }
2009-04-19 18:07:22 +00:00
// Things
public ICollection < string > DefaultThingFlags { get { return defaultthingflags ; } }
public IDictionary < string , string > ThingFlags { get { return thingflags ; } }
public List < FlagTranslation > ThingFlagsTranslation { get { return thingflagstranslation ; } }
2012-08-27 11:39:14 +00:00
public List < ThingFlagsCompare > ThingFlagsCompare { get { return thingflagscompare ; } }
2009-04-19 18:07:22 +00:00
// Linedefs
public IDictionary < string , string > LinedefFlags { get { return linedefflags ; } }
2009-07-31 11:00:11 +00:00
public List < string > SortedLinedefFlags { get { return sortedlinedefflags ; } }
2009-04-19 18:07:22 +00:00
public IDictionary < int , LinedefActionInfo > LinedefActions { get { return linedefactions ; } }
public List < LinedefActionInfo > SortedLinedefActions { get { return sortedlinedefactions ; } }
public List < LinedefActionCategory > ActionCategories { get { return actioncategories ; } }
public List < LinedefActivateInfo > LinedefActivates { get { return linedefactivates ; } }
public List < GeneralizedCategory > GenActionCategories { get { return genactioncategories ; } }
public List < FlagTranslation > LinedefFlagsTranslation { get { return linedefflagstranslation ; } }
2013-07-19 15:30:58 +00:00
//mxd. Sidedefs
public IDictionary < string , string > SidedefFlags { get { return sidedefflags ; } }
2009-04-19 18:07:22 +00:00
// Sectors
2013-07-19 15:30:58 +00:00
public IDictionary < string , string > SectorFlags { get { return sectorflags ; } } //mxd
2009-04-19 18:07:22 +00:00
public IDictionary < int , SectorEffectInfo > SectorEffects { get { return sectoreffects ; } }
public List < SectorEffectInfo > SortedSectorEffects { get { return sortedsectoreffects ; } }
public List < GeneralizedOption > GenEffectOptions { get { return geneffectoptions ; } }
2009-07-10 19:15:22 +00:00
public StepsList BrightnessLevels { get { return brightnesslevels ; } }
2009-04-19 18:07:22 +00:00
// Universal fields
public List < UniversalFieldInfo > LinedefFields { get { return linedeffields ; } }
public List < UniversalFieldInfo > SectorFields { get { return sectorfields ; } }
public List < UniversalFieldInfo > SidedefFields { get { return sidedeffields ; } }
public List < UniversalFieldInfo > ThingFields { get { return thingfields ; } }
public List < UniversalFieldInfo > VertexFields { get { return vertexfields ; } }
// Enums
public IDictionary < string , EnumList > Enums { get { return enums ; } }
// Defaults
internal List < DefinedTextureSet > TextureSets { get { return texturesets ; } }
2009-07-05 10:26:57 +00:00
public List < ThingsFilter > ThingsFilters { get { return thingfilters ; } }
2012-06-01 10:17:47 +00:00
2013-09-11 09:47:53 +00:00
//mxd
public GameType GameType { get { return gameType ; } }
2009-04-19 18:07:22 +00:00
#endregion
#region = = = = = = = = = = = = = = = = = = Constructor / Disposer
// Constructor
internal GameConfiguration ( Configuration cfg )
{
object obj ;
// Initialize
this . cfg = cfg ;
this . thingflags = new Dictionary < string , string > ( ) ;
this . defaultthingflags = new List < string > ( ) ;
this . thingcategories = new List < ThingCategory > ( ) ;
this . things = new Dictionary < int , ThingTypeInfo > ( ) ;
this . linedefflags = new Dictionary < string , string > ( ) ;
2009-07-31 11:00:11 +00:00
this . sortedlinedefflags = new List < string > ( ) ;
2009-04-19 18:07:22 +00:00
this . linedefactions = new Dictionary < int , LinedefActionInfo > ( ) ;
this . actioncategories = new List < LinedefActionCategory > ( ) ;
this . sortedlinedefactions = new List < LinedefActionInfo > ( ) ;
this . linedefactivates = new List < LinedefActivateInfo > ( ) ;
2013-07-19 15:30:58 +00:00
this . sidedefflags = new Dictionary < string , string > ( ) ; //mxd
2009-04-19 18:07:22 +00:00
this . genactioncategories = new List < GeneralizedCategory > ( ) ;
2013-07-10 08:59:17 +00:00
this . sectorflags = new Dictionary < string , string > ( ) ; //mxd
2009-04-19 18:07:22 +00:00
this . sectoreffects = new Dictionary < int , SectorEffectInfo > ( ) ;
this . sortedsectoreffects = new List < SectorEffectInfo > ( ) ;
this . geneffectoptions = new List < GeneralizedOption > ( ) ;
this . enums = new Dictionary < string , EnumList > ( ) ;
this . skills = new List < SkillInfo > ( ) ;
this . texturesets = new List < DefinedTextureSet > ( ) ;
this . makedoorargs = new int [ Linedef . NUM_ARGS ] ;
this . maplumps = new Dictionary < string , MapLumpInfo > ( ) ;
this . thingflagstranslation = new List < FlagTranslation > ( ) ;
this . linedefflagstranslation = new List < FlagTranslation > ( ) ;
this . thingfilters = new List < ThingsFilter > ( ) ;
2012-08-27 11:39:14 +00:00
this . thingflagscompare = new List < ThingFlagsCompare > ( ) ;
2009-07-10 19:15:22 +00:00
this . brightnesslevels = new StepsList ( ) ;
2012-04-14 12:22:19 +00:00
this . makedoorflags = new Dictionary < string , bool > ( ) ;
2009-04-19 18:07:22 +00:00
// Read general settings
configname = cfg . ReadSetting ( "game" , "<unnamed game>" ) ;
2012-06-01 10:17:47 +00:00
2013-09-11 09:47:53 +00:00
//mxd
int gt = ( cfg . ReadSetting ( "basegame" , ( int ) GameType . UNKNOWN ) ) ;
gameType = ( ( gt > - 1 & & gt < Gldefs . GLDEFS_LUMPS_PER_GAME . Length ) ? ( GameType ) gt : GameType . UNKNOWN ) ;
2012-06-01 10:17:47 +00:00
2009-04-19 18:07:22 +00:00
enginename = cfg . ReadSetting ( "engine" , "" ) ;
defaultsavecompiler = cfg . ReadSetting ( "defaultsavecompiler" , "" ) ;
defaulttestcompiler = cfg . ReadSetting ( "defaulttestcompiler" , "" ) ;
defaulttexturescale = cfg . ReadSetting ( "defaulttexturescale" , 1f ) ;
defaultflatscale = cfg . ReadSetting ( "defaultflatscale" , 1f ) ;
2010-01-02 20:54:35 +00:00
scaledtextureoffsets = cfg . ReadSetting ( "scaledtextureoffsets" , true ) ;
2009-04-19 18:07:22 +00:00
formatinterface = cfg . ReadSetting ( "formatinterface" , "" ) ;
mixtexturesflats = cfg . ReadSetting ( "mixtexturesflats" , false ) ;
generalizedactions = cfg . ReadSetting ( "generalizedlinedefs" , false ) ;
generalizedeffects = cfg . ReadSetting ( "generalizedsectors" , false ) ;
start3dmodethingtype = cfg . ReadSetting ( "start3dmode" , 0 ) ;
linedefactivationsfilter = cfg . ReadSetting ( "linedefactivationsfilter" , 0 ) ;
testparameters = cfg . ReadSetting ( "testparameters" , "" ) ;
testshortpaths = cfg . ReadSetting ( "testshortpaths" , false ) ;
makedoortrack = cfg . ReadSetting ( "makedoortrack" , "-" ) ;
makedooraction = cfg . ReadSetting ( "makedooraction" , 0 ) ;
2012-04-14 12:22:19 +00:00
makedooractivate = cfg . ReadSetting ( "makedooractivate" , 0 ) ;
2009-04-19 18:07:22 +00:00
linetagindicatesectors = cfg . ReadSetting ( "linetagindicatesectors" , false ) ;
decorategames = cfg . ReadSetting ( "decorategames" , "" ) ;
2013-09-11 09:47:53 +00:00
skyflatname = cfg . ReadSetting ( "skyflatname" , "F_SKY1" ) ;
2009-06-08 18:52:56 +00:00
maxtexturenamelength = cfg . ReadSetting ( "maxtexturenamelength" , 8 ) ;
2010-08-13 18:32:21 +00:00
leftboundary = cfg . ReadSetting ( "leftboundary" , - 32768 ) ;
rightboundary = cfg . ReadSetting ( "rightboundary" , 32767 ) ;
topboundary = cfg . ReadSetting ( "topboundary" , 32767 ) ;
bottomboundary = cfg . ReadSetting ( "bottomboundary" , - 32768 ) ;
2009-07-12 09:58:05 +00:00
doomlightlevels = cfg . ReadSetting ( "doomlightlevels" , true ) ;
2013-06-06 10:22:58 +00:00
defaultLinedefActivation = cfg . ReadSetting ( "defaultlinedefactivation" , "" ) ; //mxd
2009-04-19 18:07:22 +00:00
for ( int i = 0 ; i < Linedef . NUM_ARGS ; i + + ) makedoorargs [ i ] = cfg . ReadSetting ( "makedoorarg" + i . ToString ( CultureInfo . InvariantCulture ) , 0 ) ;
2012-04-14 12:22:19 +00:00
2009-04-19 18:07:22 +00:00
// Flags have special (invariant culture) conversion
// because they are allowed to be written as integers in the configs
obj = cfg . ReadSettingObject ( "singlesidedflag" , 0 ) ;
if ( obj is int ) singlesidedflag = ( ( int ) obj ) . ToString ( CultureInfo . InvariantCulture ) ; else singlesidedflag = obj . ToString ( ) ;
obj = cfg . ReadSettingObject ( "doublesidedflag" , 0 ) ;
if ( obj is int ) doublesidedflag = ( ( int ) obj ) . ToString ( CultureInfo . InvariantCulture ) ; else doublesidedflag = obj . ToString ( ) ;
obj = cfg . ReadSettingObject ( "impassableflag" , 0 ) ;
if ( obj is int ) impassableflag = ( ( int ) obj ) . ToString ( CultureInfo . InvariantCulture ) ; else impassableflag = obj . ToString ( ) ;
obj = cfg . ReadSettingObject ( "upperunpeggedflag" , 0 ) ;
if ( obj is int ) upperunpeggedflag = ( ( int ) obj ) . ToString ( CultureInfo . InvariantCulture ) ; else upperunpeggedflag = obj . ToString ( ) ;
obj = cfg . ReadSettingObject ( "lowerunpeggedflag" , 0 ) ;
if ( obj is int ) lowerunpeggedflag = ( ( int ) obj ) . ToString ( CultureInfo . InvariantCulture ) ; else lowerunpeggedflag = obj . ToString ( ) ;
// Get map lumps
maplumpnames = cfg . ReadSetting ( "maplumpnames" , new Hashtable ( ) ) ;
// Get texture and flat sources
textureranges = cfg . ReadSetting ( "textures" , new Hashtable ( ) ) ;
flatranges = cfg . ReadSetting ( "flats" , new Hashtable ( ) ) ;
patchranges = cfg . ReadSetting ( "patches" , new Hashtable ( ) ) ;
spriteranges = cfg . ReadSetting ( "sprites" , new Hashtable ( ) ) ;
2009-05-12 09:50:08 +00:00
colormapranges = cfg . ReadSetting ( "colormaps" , new Hashtable ( ) ) ;
2009-04-19 18:07:22 +00:00
// Map lumps
LoadMapLumps ( ) ;
// Skills
LoadSkills ( ) ;
// Enums
LoadEnums ( ) ;
// Things
LoadThingFlags ( ) ;
LoadDefaultThingFlags ( ) ;
LoadThingCategories ( ) ;
// Linedefs
LoadLinedefFlags ( ) ;
LoadLinedefActions ( ) ;
LoadLinedefActivations ( ) ;
LoadLinedefGeneralizedActions ( ) ;
2013-07-19 15:30:58 +00:00
//mxd. Sidedefs
LoadSidedefFlags ( ) ;
2009-04-19 18:07:22 +00:00
// Sectors
2013-07-10 08:59:17 +00:00
LoadSectorFlags ( ) ; //mxd
2009-04-19 18:07:22 +00:00
LoadBrightnessLevels ( ) ;
LoadSectorEffects ( ) ;
LoadSectorGeneralizedEffects ( ) ;
// Universal fields
linedeffields = LoadUniversalFields ( "linedef" ) ;
sectorfields = LoadUniversalFields ( "sector" ) ;
sidedeffields = LoadUniversalFields ( "sidedef" ) ;
thingfields = LoadUniversalFields ( "thing" ) ;
vertexfields = LoadUniversalFields ( "vertex" ) ;
// Defaults
LoadTextureSets ( ) ;
LoadThingFilters ( ) ;
2012-04-14 12:22:19 +00:00
// Make door flags
LoadMakeDoorFlags ( ) ;
2009-04-19 18:07:22 +00:00
}
// Destructor
~ GameConfiguration ( )
{
foreach ( ThingCategory tc in thingcategories ) tc . Dispose ( ) ;
foreach ( LinedefActionCategory ac in actioncategories ) ac . Dispose ( ) ;
2012-08-27 11:39:14 +00:00
foreach ( ThingFlagsCompare tfc in thingflagscompare ) tfc . Dispose ( ) ;
2009-04-19 18:07:22 +00:00
}
#endregion
#region = = = = = = = = = = = = = = = = = = Loading
// This loads the map lumps
private void LoadMapLumps ( )
{
IDictionary dic ;
// Get map lumps list
dic = cfg . ReadSetting ( "maplumpnames" , new Hashtable ( ) ) ;
foreach ( DictionaryEntry de in dic )
{
// Make map lumps
MapLumpInfo lumpinfo = new MapLumpInfo ( de . Key . ToString ( ) , cfg ) ;
maplumps . Add ( de . Key . ToString ( ) , lumpinfo ) ;
}
}
// This loads the enumerations
private void LoadEnums ( )
{
IDictionary dic ;
// Get enums list
dic = cfg . ReadSetting ( "enums" , new Hashtable ( ) ) ;
foreach ( DictionaryEntry de in dic )
{
// Make new enum
EnumList list = new EnumList ( de . Key . ToString ( ) , cfg ) ;
enums . Add ( de . Key . ToString ( ) , list ) ;
}
}
// This loads a universal fields list
private List < UniversalFieldInfo > LoadUniversalFields ( string elementname )
{
List < UniversalFieldInfo > list = new List < UniversalFieldInfo > ( ) ;
UniversalFieldInfo uf ;
IDictionary dic ;
// Get fields
dic = cfg . ReadSetting ( "universalfields." + elementname , new Hashtable ( ) ) ;
foreach ( DictionaryEntry de in dic )
{
try
{
// Read the field info and add to list
uf = new UniversalFieldInfo ( elementname , de . Key . ToString ( ) , cfg , enums ) ;
list . Add ( uf ) ;
}
catch ( Exception )
{
2009-05-10 16:02:08 +00:00
General . ErrorLogger . Add ( ErrorType . Warning , "Unable to read universal field definition 'universalfields." + elementname + "." + de . Key + "' from game configuration '" + this . Name + "'" ) ;
2009-04-19 18:07:22 +00:00
}
}
// Return result
return list ;
}
// Things and thing categories
private void LoadThingCategories ( )
{
IDictionary dic ;
ThingCategory thingcat ;
// Get thing categories
dic = cfg . ReadSetting ( "thingtypes" , new Hashtable ( ) ) ;
foreach ( DictionaryEntry de in dic )
{
2009-08-01 07:45:12 +00:00
if ( de . Value is IDictionary )
2009-04-19 18:07:22 +00:00
{
2009-08-01 07:45:12 +00:00
// Make a category
thingcat = new ThingCategory ( cfg , de . Key . ToString ( ) , enums ) ;
// Add all things in category to the big list
foreach ( ThingTypeInfo t in thingcat . Things )
2009-04-19 18:07:22 +00:00
{
2009-08-01 07:45:12 +00:00
if ( ! things . ContainsKey ( t . Index ) )
{
things . Add ( t . Index , t ) ;
}
else
{
General . ErrorLogger . Add ( ErrorType . Warning , "Thing number " + t . Index + " is defined more than once (as '" + things [ t . Index ] . Title + "' and '" + t . Title + "') in game configuration '" + this . Name + "'" ) ;
}
2009-04-19 18:07:22 +00:00
}
2009-08-01 07:45:12 +00:00
// Add category to list
thingcategories . Add ( thingcat ) ;
}
2009-04-19 18:07:22 +00:00
}
}
// Linedef flags
private void LoadLinedefFlags ( )
{
IDictionary dic ;
// Get linedef flags
dic = cfg . ReadSetting ( "linedefflags" , new Hashtable ( ) ) ;
foreach ( DictionaryEntry de in dic )
linedefflags . Add ( de . Key . ToString ( ) , de . Value . ToString ( ) ) ;
2009-07-31 11:00:11 +00:00
2009-04-19 18:07:22 +00:00
// Get translations
dic = cfg . ReadSetting ( "linedefflagstranslation" , new Hashtable ( ) ) ;
foreach ( DictionaryEntry de in dic )
linedefflagstranslation . Add ( new FlagTranslation ( de ) ) ;
2009-07-31 11:00:11 +00:00
// Sort flags?
MapSetIO io = MapSetIO . Create ( formatinterface ) ;
if ( io . HasNumericLinedefFlags )
{
// Make list for integers that we can sort
List < int > sortlist = new List < int > ( linedefflags . Count ) ;
foreach ( KeyValuePair < string , string > f in linedefflags )
{
int num ;
if ( int . TryParse ( f . Key , NumberStyles . Integer , CultureInfo . InvariantCulture , out num ) ) sortlist . Add ( num ) ;
}
// Sort
sortlist . Sort ( ) ;
// Make list of strings
foreach ( int i in sortlist )
sortedlinedefflags . Add ( i . ToString ( CultureInfo . InvariantCulture ) ) ;
}
// Sort the flags, because they must be compared highest first!
2009-04-19 18:07:22 +00:00
linedefflagstranslation . Sort ( ) ;
}
// Linedef actions and action categories
private void LoadLinedefActions ( )
{
Dictionary < string , LinedefActionCategory > cats = new Dictionary < string , LinedefActionCategory > ( ) ;
IDictionary dic ;
LinedefActionInfo ai ;
LinedefActionCategory ac ;
int actionnumber ;
// Get linedef categories
dic = cfg . ReadSetting ( "linedeftypes" , new Hashtable ( ) ) ;
foreach ( DictionaryEntry cde in dic )
{
2009-08-01 07:45:12 +00:00
if ( cde . Value is IDictionary )
2009-04-19 18:07:22 +00:00
{
2009-08-01 07:45:12 +00:00
// Read category title
string cattitle = cfg . ReadSetting ( "linedeftypes." + cde . Key + ".title" , "" ) ;
// Make or get category
if ( cats . ContainsKey ( cde . Key . ToString ( ) ) )
ac = cats [ cde . Key . ToString ( ) ] ;
else
2009-04-19 18:07:22 +00:00
{
2009-08-01 07:45:12 +00:00
ac = new LinedefActionCategory ( cde . Key . ToString ( ) , cattitle ) ;
cats . Add ( cde . Key . ToString ( ) , ac ) ;
}
2009-04-19 18:07:22 +00:00
2009-08-01 07:45:12 +00:00
// Go for all line types in category
IDictionary catdic = cfg . ReadSetting ( "linedeftypes." + cde . Key , new Hashtable ( ) ) ;
foreach ( DictionaryEntry de in catdic )
{
// Check if the item key is numeric
if ( int . TryParse ( de . Key . ToString ( ) ,
NumberStyles . AllowLeadingWhite | NumberStyles . AllowTrailingWhite ,
CultureInfo . InvariantCulture , out actionnumber ) )
2009-04-19 18:07:22 +00:00
{
2009-08-01 07:45:12 +00:00
// Check if the item value is a structure
if ( de . Value is IDictionary )
{
// Make the line type
ai = new LinedefActionInfo ( actionnumber , cfg , cde . Key . ToString ( ) , enums ) ;
// Add action to category and sorted list
sortedlinedefactions . Add ( ai ) ;
linedefactions . Add ( actionnumber , ai ) ;
ac . Add ( ai ) ;
}
else
{
// Failure
if ( de . Value ! = null )
General . ErrorLogger . Add ( ErrorType . Warning , "Structure 'linedeftypes' contains invalid types in game configuration '" + this . Name + "'. All types must be expanded structures." ) ;
}
2009-04-19 18:07:22 +00:00
}
}
}
}
// Sort the actions list
sortedlinedefactions . Sort ( ) ;
// Copy categories to final list
actioncategories . Clear ( ) ;
actioncategories . AddRange ( cats . Values ) ;
// Sort the categories list
actioncategories . Sort ( ) ;
}
// Linedef activates
private void LoadLinedefActivations ( )
{
IDictionary dic ;
// Get linedef activations
dic = cfg . ReadSetting ( "linedefactivations" , new Hashtable ( ) ) ;
foreach ( DictionaryEntry de in dic )
{
// Add to the list
linedefactivates . Add ( new LinedefActivateInfo ( de . Key . ToString ( ) , de . Value . ToString ( ) ) ) ;
}
// Sort the list
linedefactivates . Sort ( ) ;
}
// Linedef generalized actions
private void LoadLinedefGeneralizedActions ( )
{
IDictionary dic ;
// Get linedef activations
dic = cfg . ReadSetting ( "gen_linedeftypes" , new Hashtable ( ) ) ;
foreach ( DictionaryEntry de in dic )
{
// Check for valid structure
if ( de . Value is IDictionary )
{
// Add category
genactioncategories . Add ( new GeneralizedCategory ( "gen_linedeftypes" , de . Key . ToString ( ) , cfg ) ) ;
}
else
{
2009-05-10 16:02:08 +00:00
General . ErrorLogger . Add ( ErrorType . Warning , "Structure 'gen_linedeftypes' contains invalid entries in game configuration '" + this . Name + "'" ) ;
2009-04-19 18:07:22 +00:00
}
}
}
2013-07-19 15:30:58 +00:00
//mxd. SIdedef flags
private void LoadSidedefFlags ( ) {
// Get linedef flags
IDictionary dic = cfg . ReadSetting ( "sidedefflags" , new Hashtable ( ) ) ;
foreach ( DictionaryEntry de in dic )
sidedefflags . Add ( de . Key . ToString ( ) , de . Value . ToString ( ) ) ;
}
2013-07-10 08:59:17 +00:00
//mxd. Sector flags
private void LoadSectorFlags ( ) {
// Get linedef flags
IDictionary dic = cfg . ReadSetting ( "sectorflags" , new Hashtable ( ) ) ;
foreach ( DictionaryEntry de in dic )
sectorflags . Add ( de . Key . ToString ( ) , de . Value . ToString ( ) ) ;
}
2009-04-19 18:07:22 +00:00
// Sector effects
private void LoadSectorEffects ( )
{
IDictionary dic ;
SectorEffectInfo si ;
int actionnumber ;
// Get sector effects
dic = cfg . ReadSetting ( "sectortypes" , new Hashtable ( ) ) ;
foreach ( DictionaryEntry de in dic )
{
// Try paring the action number
if ( int . TryParse ( de . Key . ToString ( ) ,
NumberStyles . AllowLeadingWhite | NumberStyles . AllowTrailingWhite ,
CultureInfo . InvariantCulture , out actionnumber ) )
{
// Make effects
si = new SectorEffectInfo ( actionnumber , de . Value . ToString ( ) , true , false ) ;
// Add action to category and sorted list
sortedsectoreffects . Add ( si ) ;
sectoreffects . Add ( actionnumber , si ) ;
}
else
{
2009-05-10 16:02:08 +00:00
General . ErrorLogger . Add ( ErrorType . Warning , "Structure 'sectortypes' contains invalid keys in game configuration '" + this . Name + "'" ) ;
2009-04-19 18:07:22 +00:00
}
}
// Sort the actions list
sortedsectoreffects . Sort ( ) ;
}
// Brightness levels
private void LoadBrightnessLevels ( )
{
IDictionary dic ;
int level ;
// Get brightness levels structure
dic = cfg . ReadSetting ( "sectorbrightness" , new Hashtable ( ) ) ;
foreach ( DictionaryEntry de in dic )
{
// Try paring the level
if ( int . TryParse ( de . Key . ToString ( ) ,
NumberStyles . AllowLeadingWhite | NumberStyles . AllowTrailingWhite ,
CultureInfo . InvariantCulture , out level ) )
{
brightnesslevels . Add ( level ) ;
}
else
{
2009-05-10 16:02:08 +00:00
General . ErrorLogger . Add ( ErrorType . Warning , "Structure 'sectorbrightness' contains invalid keys in game configuration '" + this . Name + "'" ) ;
2009-04-19 18:07:22 +00:00
}
}
// Sort the list
brightnesslevels . Sort ( ) ;
}
// Sector generalized effects
private void LoadSectorGeneralizedEffects ( )
{
IDictionary dic ;
// Get sector effects
dic = cfg . ReadSetting ( "gen_sectortypes" , new Hashtable ( ) ) ;
foreach ( DictionaryEntry de in dic )
{
// Check for valid structure
if ( de . Value is IDictionary )
{
// Add option
geneffectoptions . Add ( new GeneralizedOption ( "gen_sectortypes" , "" , de . Key . ToString ( ) , de . Value as IDictionary ) ) ;
}
else
{
2009-05-10 16:02:08 +00:00
General . ErrorLogger . Add ( ErrorType . Warning , "Structure 'gen_sectortypes' contains invalid entries in game configuration '" + this . Name + "'" ) ;
2009-04-19 18:07:22 +00:00
}
}
}
// Thing flags
private void LoadThingFlags ( )
{
IDictionary dic ;
// Get linedef flags
dic = cfg . ReadSetting ( "thingflags" , new Hashtable ( ) ) ;
foreach ( DictionaryEntry de in dic )
thingflags . Add ( de . Key . ToString ( ) , de . Value . ToString ( ) ) ;
// Get translations
dic = cfg . ReadSetting ( "thingflagstranslation" , new Hashtable ( ) ) ;
foreach ( DictionaryEntry de in dic )
thingflagstranslation . Add ( new FlagTranslation ( de ) ) ;
2012-08-27 11:39:14 +00:00
// Get thing compare flag info (for the stuck thing error checker
2013-06-03 11:32:29 +00:00
dic = cfg . ReadSetting ( "thingflagscompare" , new Hashtable ( ) ) ;
foreach ( DictionaryEntry de in dic ) {
IDictionary gdic = cfg . ReadSetting ( "thingflagscompare." + de . Key , new Hashtable ( ) ) ;
foreach ( DictionaryEntry gde in gdic ) {
thingflagscompare . Add ( new ThingFlagsCompare ( cfg , de . Key . ToString ( ) , gde . Key . ToString ( ) ) ) ;
}
}
2009-04-19 18:07:22 +00:00
// Sort the translation flags, because they must be compared highest first!
thingflagstranslation . Sort ( ) ;
}
// Default thing flags
private void LoadDefaultThingFlags ( )
{
IDictionary dic ;
// Get linedef flags
dic = cfg . ReadSetting ( "defaultthingflags" , new Hashtable ( ) ) ;
foreach ( DictionaryEntry de in dic )
{
// Check if flag exists
if ( thingflags . ContainsKey ( de . Key . ToString ( ) ) )
{
defaultthingflags . Add ( de . Key . ToString ( ) ) ;
}
else
{
2009-05-10 16:02:08 +00:00
General . ErrorLogger . Add ( ErrorType . Warning , "Structure 'defaultthingflags' contains unknown thing flags in game configuration '" + this . Name + "'" ) ;
2009-04-19 18:07:22 +00:00
}
}
}
// Skills
private void LoadSkills ( )
{
IDictionary dic ;
// Get skills
dic = cfg . ReadSetting ( "skills" , new Hashtable ( ) ) ;
foreach ( DictionaryEntry de in dic )
{
int num = 0 ;
if ( int . TryParse ( de . Key . ToString ( ) , out num ) )
{
skills . Add ( new SkillInfo ( num , de . Value . ToString ( ) ) ) ;
}
else
{
2009-05-10 16:02:08 +00:00
General . ErrorLogger . Add ( ErrorType . Warning , "Structure 'skills' contains invalid skill numbers in game configuration '" + this . Name + "'" ) ;
2009-04-19 18:07:22 +00:00
}
}
}
// Texture Sets
private void LoadTextureSets ( )
{
IDictionary dic ;
// Get sets
dic = cfg . ReadSetting ( "texturesets" , new Hashtable ( ) ) ;
foreach ( DictionaryEntry de in dic )
{
DefinedTextureSet s = new DefinedTextureSet ( cfg , "texturesets." + de . Key . ToString ( ) ) ;
texturesets . Add ( s ) ;
}
}
// Thing Filters
private void LoadThingFilters ( )
{
IDictionary dic ;
// Get sets
dic = cfg . ReadSetting ( "thingsfilters" , new Hashtable ( ) ) ;
foreach ( DictionaryEntry de in dic )
{
ThingsFilter f = new ThingsFilter ( cfg , "thingsfilters." + de . Key . ToString ( ) ) ;
thingfilters . Add ( f ) ;
}
}
2012-04-14 12:22:19 +00:00
// Make door flags
private void LoadMakeDoorFlags ( )
{
IDictionary dic ;
dic = cfg . ReadSetting ( "makedoorflags" , new Hashtable ( ) ) ;
foreach ( DictionaryEntry de in dic )
{
// Using minus will unset the flag
if ( de . Key . ToString ( ) [ 0 ] = = '-' )
{
makedoorflags [ de . Key . ToString ( ) . TrimStart ( '-' ) ] = false ;
}
else
{
makedoorflags [ de . Key . ToString ( ) ] = true ;
}
}
}
2009-04-19 18:07:22 +00:00
#endregion
#region = = = = = = = = = = = = = = = = = = Methods
// ReadSetting
public string ReadSetting ( string setting , string defaultsetting ) { return cfg . ReadSetting ( setting , defaultsetting ) ; }
public int ReadSetting ( string setting , int defaultsetting ) { return cfg . ReadSetting ( setting , defaultsetting ) ; }
public float ReadSetting ( string setting , float defaultsetting ) { return cfg . ReadSetting ( setting , defaultsetting ) ; }
public short ReadSetting ( string setting , short defaultsetting ) { return cfg . ReadSetting ( setting , defaultsetting ) ; }
public long ReadSetting ( string setting , long defaultsetting ) { return cfg . ReadSetting ( setting , defaultsetting ) ; }
public bool ReadSetting ( string setting , bool defaultsetting ) { return cfg . ReadSetting ( setting , defaultsetting ) ; }
public byte ReadSetting ( string setting , byte defaultsetting ) { return cfg . ReadSetting ( setting , defaultsetting ) ; }
public IDictionary ReadSetting ( string setting , IDictionary defaultsetting ) { return cfg . ReadSetting ( setting , defaultsetting ) ; }
// This gets a list of things categories
internal List < ThingCategory > GetThingCategories ( )
{
return new List < ThingCategory > ( thingcategories ) ;
}
// This gets a list of things
internal Dictionary < int , ThingTypeInfo > GetThingTypes ( )
{
return new Dictionary < int , ThingTypeInfo > ( things ) ;
}
// This checks if an action is generalized or predefined
public static bool IsGeneralized ( int action , List < GeneralizedCategory > categories )
{
// Only actions above 0
if ( action > 0 )
{
// Go for all categories
foreach ( GeneralizedCategory ac in categories )
{
// Check if the action is within range of this category
if ( ( action > = ac . Offset ) & & ( action < ( ac . Offset + ac . Length ) ) ) return true ;
}
}
// Not generalized
return false ;
}
// This gets the generalized action category from action number
public GeneralizedCategory GetGeneralizedActionCategory ( int action )
{
// Only actions above 0
if ( action > 0 )
{
// Go for all categories
foreach ( GeneralizedCategory ac in genactioncategories )
{
// Check if the action is within range of this category
if ( ( action > = ac . Offset ) & & ( action < ( ac . Offset + ac . Length ) ) ) return ac ;
}
}
// Not generalized
return null ;
}
// This checks if a specific edit mode class is listed
public bool IsEditModeSpecified ( string classname )
{
return cfg . SettingExists ( "editingmodes." + classname . ToString ( CultureInfo . InvariantCulture ) ) ;
}
// This returns information on a linedef type
public LinedefActionInfo GetLinedefActionInfo ( int action )
{
// Known type?
if ( linedefactions . ContainsKey ( action ) )
{
return linedefactions [ action ] ;
}
else if ( action = = 0 )
{
return new LinedefActionInfo ( 0 , "None" , true , false ) ;
}
else if ( IsGeneralized ( action , genactioncategories ) )
{
return new LinedefActionInfo ( action , "Generalized (" + GetGeneralizedActionCategory ( action ) + ")" , true , true ) ;
}
else
{
return new LinedefActionInfo ( action , "Unknown" , false , false ) ;
}
}
// This returns information on a sector effect
public SectorEffectInfo GetSectorEffectInfo ( int effect )
{
// Known type?
if ( sectoreffects . ContainsKey ( effect ) )
{
return sectoreffects [ effect ] ;
}
else if ( effect = = 0 )
{
return new SectorEffectInfo ( 0 , "None" , true , false ) ;
}
else
{
return new SectorEffectInfo ( effect , "Unknown" , false , false ) ;
}
}
#endregion
}
}