@@ -207,13 +207,12 @@ private void ProcessLeaders(string[] values)
207
207
Rules . Leaders = values . Select ( ( value , id ) =>
208
208
{
209
209
var line = value . Split ( ',' , StringSplitOptions . TrimEntries ) ;
210
- var titles = new List < LeaderTitle > (
211
- ) ;
210
+ var titles = new List < LeaderTitle > ( ) ;
212
211
for ( var i = 12 ; i < line . Length ; i += 3 )
213
212
{
214
213
titles . Add ( new LeaderTitle
215
214
{
216
- Gov = int . Parse ( line [ i - 2 ] ) ,
215
+ Gov = int . TryParse ( line [ i - 2 ] , out int val0 ) ? val0 : 0 ,
217
216
TitleMale = line [ i - 1 ] ,
218
217
TitleFemale = line [ i ] ,
219
218
} ) ;
@@ -224,13 +223,13 @@ private void ProcessLeaders(string[] values)
224
223
NameMale = line [ 0 ] ,
225
224
NameFemale = line [ 1 ] ,
226
225
Female = int . Parse ( line [ 2 ] ) == 1 ,
227
- Color = int . Parse ( line [ 3 ] ) ,
228
- CityStyle = int . Parse ( line [ 4 ] ) ,
226
+ Color = int . TryParse ( line [ 3 ] , out int val ) ? val : 0 ,
227
+ CityStyle = int . TryParse ( line [ 4 ] , out val ) ? val : 0 ,
229
228
Plural = line [ 5 ] ,
230
229
Adjective = line [ 6 ] ,
231
- Attack = int . Parse ( line [ 7 ] ) ,
232
- Expand = int . Parse ( line [ 8 ] ) ,
233
- Civilize = int . Parse ( line [ 9 ] ) ,
230
+ Attack = int . TryParse ( line [ 7 ] , out val ) ? val : 0 ,
231
+ Expand = int . TryParse ( line [ 8 ] , out val ) ? val : 0 ,
232
+ Civilize = int . TryParse ( line [ 9 ] , out val ) ? val : 0 ,
234
233
Titles = titles . ToArray ( )
235
234
} ;
236
235
} ) . ToArray ( ) ;
@@ -293,7 +292,7 @@ private void ProcessTerrain(IEnumerable<string>? values)
293
292
if ( row < 11 )
294
293
{
295
294
if ( ! mappings . ContainsKey ( parts [ 1 ] ) )
296
- mappings . Add ( parts [ 1 ] . Substring ( 0 , 3 ) , terrains . Count ) ;
295
+ mappings . Add ( parts [ 1 ] . Length > 3 ? parts [ 1 ] [ .. 3 ] : parts [ 1 ] , terrains . Count ) ;
297
296
terrains . Add ( parts [ 0 ] ) ;
298
297
}
299
298
else
@@ -326,19 +325,19 @@ private void ProcessTerrain(IEnumerable<string>? values)
326
325
{
327
326
Type = ( TerrainType ) type ,
328
327
Name = line [ 0 ] ,
329
- MoveCost = int . Parse ( line [ 1 ] ) ,
330
- Defense = int . Parse ( line [ 2 ] ) ,
331
- Food = int . Parse ( line [ 3 ] ) ,
332
- Shields = int . Parse ( line [ 4 ] ) ,
333
- Trade = int . Parse ( line [ 5 ] ) ,
328
+ MoveCost = int . TryParse ( line [ 1 ] , out int val ) ? val : 1 ,
329
+ Defense = int . TryParse ( line [ 2 ] , out val ) ? val : 1 ,
330
+ Food = int . TryParse ( line [ 3 ] , out val ) ? val : 0 ,
331
+ Shields = int . TryParse ( line [ 4 ] , out val ) ? val : 0 ,
332
+ Trade = int . TryParse ( line [ 5 ] , out val ) ? val : 0 ,
334
333
CanIrrigate = mappings [ line [ 6 ] ] ,
335
- IrrigationBonus = int . Parse ( line [ 7 ] ) ,
336
- TurnsToIrrigate = int . Parse ( line [ 8 ] ) ,
337
- MinGovrnLevelAItoPerformIrrigation = int . Parse ( line [ 9 ] ) ,
334
+ IrrigationBonus = int . TryParse ( line [ 7 ] , out val ) ? val : 0 ,
335
+ TurnsToIrrigate = int . TryParse ( line [ 8 ] , out val ) ? val : 0 ,
336
+ MinGovrnLevelAItoPerformIrrigation = int . TryParse ( line [ 9 ] , out val ) ? val : 0 ,
338
337
CanMine = mappings [ line [ 10 ] ] ,
339
- MiningBonus = int . Parse ( line [ 11 ] ) ,
340
- TurnsToMine = int . Parse ( line [ 12 ] ) ,
341
- MinGovrnLevelAItoPerformMining = int . Parse ( line [ 13 ] ) ,
338
+ MiningBonus = int . TryParse ( line [ 11 ] , out val ) ? val : 0 ,
339
+ TurnsToMine = int . TryParse ( line [ 12 ] , out val ) ? val : 0 ,
340
+ MinGovrnLevelAItoPerformMining = int . TryParse ( line [ 13 ] , out val ) ? val : 0 ,
342
341
Transform = mappings [ line [ 14 ] ] ,
343
342
Impassable = line [ 15 ] == "yes" ,
344
343
RoadBonus = type <= ( int ) TerrainType . Grassland ? 1 : 0 ,
@@ -370,17 +369,17 @@ private void ProcessUnits(string[] values)
370
369
{
371
370
Type = type ,
372
371
Name = text [ 0 ] ,
373
- Until = Rules . AdvanceMappings . ContainsKey ( text [ 1 ] ) ? Rules . AdvanceMappings [ text [ 1 ] ] : - 1 , // temp
374
- Domain = ( UnitGas ) int . Parse ( text [ 2 ] ) ,
375
- Move = Rules . Cosmic . MovementMultiplier * int . Parse ( text [ 3 ] . Replace ( "." , string . Empty ) ) ,
376
- Range = int . Parse ( text [ 4 ] ) ,
377
- Attack = int . Parse ( text [ 5 ] . Replace ( "a" , string . Empty ) ) ,
378
- Defense = int . Parse ( text [ 6 ] . Replace ( "d" , string . Empty ) ) ,
379
- Hitp = 10 * int . Parse ( text [ 7 ] . Replace ( "h" , string . Empty ) ) ,
380
- Firepwr = int . Parse ( text [ 8 ] . Replace ( "f" , string . Empty ) ) ,
381
- Cost = int . Parse ( text [ 9 ] ) ,
382
- Hold = int . Parse ( text [ 10 ] ) ,
383
- AIrole = ( AIroleType ) int . Parse ( text [ 11 ] ) ,
372
+ Until = Rules . AdvanceMappings . TryGetValue ( text [ 1 ] , out int value ) ? value : - 1 ,
373
+ Domain = ( UnitGas ) ( int . TryParse ( text [ 2 ] , out value ) ? value : 0 ) ,
374
+ Move = Rules . Cosmic . MovementMultiplier * ( int . TryParse ( text [ 3 ] . Replace ( "." , string . Empty ) , out value ) ? value : 0 ) ,
375
+ Range = int . TryParse ( text [ 4 ] , out value ) ? value : 0 ,
376
+ Attack = int . TryParse ( text [ 5 ] . Replace ( "a" , string . Empty ) , out value ) ? value : 0 ,
377
+ Defense = int . TryParse ( text [ 6 ] . Replace ( "d" , string . Empty ) , out value ) ? value : 0 ,
378
+ Hitp = 10 * ( int . TryParse ( text [ 7 ] . Replace ( "h" , string . Empty ) , out value ) ? value : 0 ) ,
379
+ Firepwr = int . TryParse ( text [ 8 ] . Replace ( "f" , string . Empty ) , out value ) ? value : 0 ,
380
+ Cost = int . TryParse ( text [ 9 ] , out value ) ? value : 0 ,
381
+ Hold = int . TryParse ( text [ 10 ] , out value ) ? value : 0 ,
382
+ AIrole = ( AIroleType ) ( int . TryParse ( text [ 11 ] , out value ) ? value : 0 ) ,
384
383
Prereq = Rules . AdvanceMappings . ContainsKey ( text [ 12 ] ) ? Rules . AdvanceMappings [ text [ 12 ] ] : - 1 , // temp
385
384
Flags = text [ 13 ] ,
386
385
AttackSound = defaultAttackSounds . FirstOrDefault ( s=> s . Item1 == type ) ? . Item2
@@ -405,15 +404,14 @@ private void ProcessUnits(string[] values)
405
404
406
405
private void ProcessAdvancedUnitFlags ( string [ ] values )
407
406
{
408
-
409
407
var limit = values . Length < Rules . UnitTypes . Length ? values . Length : Rules . UnitTypes . Length ;
410
408
for ( int i = 0 ; i < limit ; i ++ )
411
409
{
412
410
var line = values [ i ] . Split ( new [ ] { ',' , ';' } , StringSplitOptions . TrimEntries ) ;
413
411
var unit = Rules . UnitTypes [ i ] ;
414
412
unit . CivCanBuild = ReadBitsReversed ( line [ 0 ] ) ;
415
413
unit . CanBeOnMap = ReadBitsReversed ( line [ 1 ] ) ;
416
- unit . MinBribe = int . Parse ( line [ 2 ] ) ;
414
+ unit . MinBribe = int . TryParse ( line [ 2 ] , out int val ) ? val : 0 ;
417
415
var extraFlags = ReadBitsReversed ( line [ 6 ] ) ;
418
416
unit . Invisible = extraFlags [ 0 ] ;
419
417
unit . NonDispandable = extraFlags [ 1 ] ;
@@ -456,9 +454,9 @@ private void ProcessImprovements(string[] values)
456
454
{
457
455
Type = type ,
458
456
Name = parts [ 0 ] ,
459
- Cost = int . Parse ( parts [ 1 ] ) ,
460
- Upkeep = int . Parse ( parts [ 2 ] ) ,
461
- Prerequisite = Rules . AdvanceMappings . ContainsKey ( parts [ 3 ] ) ? Rules . AdvanceMappings [ parts [ 3 ] ] : - 1 // temp
457
+ Cost = int . TryParse ( parts [ 1 ] , out int val ) ? val : 1 ,
458
+ Upkeep = int . TryParse ( parts [ 2 ] , out val ) ? val : 0 ,
459
+ Prerequisite = Rules . AdvanceMappings . TryGetValue ( parts [ 3 ] , out val ) ? val : - 1
462
460
} ;
463
461
} ) . ToArray ( ) ;
464
462
}
@@ -542,12 +540,12 @@ private void ProcessTech(IReadOnlyList<string> values)
542
540
{
543
541
Index = index ,
544
542
Name = text [ 0 ] ,
545
- AIvalue = int . Parse ( text [ 1 ] ) ,
546
- Modifier = int . Parse ( text [ 2 ] ) ,
547
- Prereq1 = Rules . AdvanceMappings . ContainsKey ( text [ 3 ] ) ? Rules . AdvanceMappings [ text [ 3 ] ] : - 1 , // temp
548
- Prereq2 = Rules . AdvanceMappings . ContainsKey ( text [ 4 ] ) ? Rules . AdvanceMappings [ text [ 4 ] ] : - 1 , // temp
549
- Epoch = int . Parse ( text [ 5 ] ) ,
550
- KnowledgeCategory = int . Parse ( text [ 6 ] )
543
+ AIvalue = int . TryParse ( text [ 1 ] , out int val ) ? val : 1 ,
544
+ Modifier = int . TryParse ( text [ 2 ] , out val ) ? val : 0 ,
545
+ Prereq1 = Rules . AdvanceMappings . TryGetValue ( text [ 3 ] , out val ) ? val : - 1 ,
546
+ Prereq2 = Rules . AdvanceMappings . TryGetValue ( text [ 4 ] , out val ) ? val : - 1 ,
547
+ Epoch = int . TryParse ( text [ 5 ] , out val ) ? val : 0 ,
548
+ KnowledgeCategory = int . TryParse ( text [ 6 ] , out val ) ? val : 0
551
549
} ;
552
550
} ) . ToArray ( ) ;
553
551
}
@@ -571,11 +569,11 @@ private Special MakeSpecial(string source)
571
569
return new Special
572
570
{
573
571
Name = line [ 0 ] ,
574
- MoveCost = int . Parse ( line [ 1 ] ) ,
575
- Defense = int . Parse ( line [ 2 ] ) ,
576
- Food = int . Parse ( line [ 3 ] ) ,
577
- Shields = int . Parse ( line [ 4 ] ) ,
578
- Trade = int . Parse ( line [ 5 ] ) ,
572
+ MoveCost = int . TryParse ( line [ 1 ] , out int val ) ? val : 1 ,
573
+ Defense = int . TryParse ( line [ 2 ] , out val ) ? val : 1 ,
574
+ Food = int . TryParse ( line [ 3 ] , out val ) ? val : 0 ,
575
+ Shields = int . TryParse ( line [ 4 ] , out val ) ? val : 0 ,
576
+ Trade = int . TryParse ( line [ 5 ] , out val ) ? val : 0 ,
579
577
} ;
580
578
}
581
579
}
0 commit comments