Skip to content

Commit 94b27fe

Browse files
authored
C# Source Modernization initiative (#430)
* Reformat CSUtil.Commons/* * Partial formatting; Debug switches now accessed via Enum * Modernize CustomCarAI * Modernize CargoTruckAI * DebugSettings now can be accessed via static properties = shorter code * Modernize CustomHumanAI * Modernize CustomPassengerCarAI * Modernize Custom{PoliceCar, PostVan, Resident, RoadBase, Ship, Taxi, Tourist}AI * Modernize CustomTrainAI * Modernize CustomTramBaseAI * Modernize CustomVehicleAI * Restore base. in calls, apparently it is important * Modernize CustomPathFind (v1) * Modernize CustomPathManager, StockPathFind * In Release logLogic variable still had its old name: debug * Revert and untabify StockPathFind * Modernize AdvancedParkingManager & new shorter log invocations * Log simplification * Restore performance in Debug * Refactor/rename pathfinding module; Dump other settings into editorconfig * Minor editorconfig changes * Change var to types in affected files: CSUtil.Common, TLM/Custom * Review notes on #430; Removed DEBUGGEO now DEBUG * Removed old PF, renamed PF2 define to PF_DIJKSTRA * Simplify SegmentEndId Equals * Rider/Resharper style settings: Use var when type is evident, otherwise use type
1 parent d6438b0 commit 94b27fe

File tree

69 files changed

+12870
-11273
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+12870
-11273
lines changed

TLM/.editorconfig

Lines changed: 101 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,103 @@
1-
root = true
2-
3-
[*.{cs,vb}]
4-
indent_style = space
5-
indent_size = 4
6-
trim_trailing_whitespace = true
1+
root=true
72

83
[*.cs]
9-
# csharp_new_line_before_open_brace = methods
4+
max_line_length=100
5+
tab_width=8
6+
insert_final_newline=true
7+
trim_trailing_whitespace=true
8+
indent_style=space
9+
indent_size=4
10+
11+
[*]
12+
charset=utf-8
13+
end_of_line=crlf
14+
indent_style=space
15+
indent_size=4
16+
17+
# Microsoft .NET properties
18+
csharp_new_line_before_else=false
19+
csharp_new_line_before_members_in_object_initializers=false
20+
csharp_new_line_before_open_brace=none
21+
csharp_preferred_modifier_order=public, private, protected, internal, new, abstract, virtual, sealed, override, static, readonly, extern, unsafe, volatile, async:suggestion
22+
csharp_space_after_cast=false
23+
csharp_style_var_elsewhere=false:hint
24+
csharp_style_var_for_built_in_types=false:hint
25+
csharp_style_var_when_type_is_apparent=true:hint
26+
dotnet_style_predefined_type_for_locals_parameters_members=true:hint
27+
dotnet_style_predefined_type_for_member_access=true:hint
28+
dotnet_style_qualification_for_event=false:warning
29+
dotnet_style_qualification_for_field=false:warning
30+
dotnet_style_qualification_for_method=false:warning
31+
dotnet_style_qualification_for_property=false:warning
32+
dotnet_style_require_accessibility_modifiers=for_non_interface_members:hint
33+
34+
# ReSharper properties
35+
resharper_add_imports_to_deepest_scope=true
36+
resharper_align_linq_query=true
37+
resharper_align_multiline_argument=true
38+
resharper_align_multiline_calls_chain=true
39+
resharper_align_multiline_expression=true
40+
resharper_align_multiline_extends_list=true
41+
resharper_align_multiline_for_stmt=true
42+
resharper_align_multiline_parameter=true
43+
resharper_align_multiple_declaration=true
44+
resharper_align_multline_type_parameter_constrains=true
45+
resharper_align_multline_type_parameter_list=true
46+
resharper_autodetect_indent_settings=true
47+
resharper_braces_for_for=required
48+
resharper_braces_for_foreach=required
49+
resharper_braces_for_ifelse=required
50+
resharper_braces_for_while=required
51+
resharper_csharp_max_line_length=100
52+
resharper_csharp_tab_width=8
53+
resharper_csharp_wrap_arguments_style=chop_if_long
54+
resharper_csharp_wrap_parameters_style=chop_if_long
55+
resharper_empty_block_style=together
56+
resharper_for_built_in_types=use_var_when_evident
57+
resharper_indent_invocation_pars=outside_and_inside
58+
resharper_indent_method_decl_pars=outside_and_inside
59+
resharper_indent_statement_pars=outside_and_inside
60+
resharper_keep_existing_invocation_parens_arrangement=false
61+
resharper_max_attribute_length_for_same_line=1
62+
resharper_place_attribute_on_same_line=False
63+
resharper_use_indent_from_vs=false
64+
resharper_wrap_after_invocation_lpar=true
65+
resharper_wrap_before_extends_colon=true
66+
resharper_wrap_before_first_type_parameter_constraint=true
67+
68+
# ReSharper inspection severities
69+
resharper_sa1012_highlighting=none
70+
resharper_sa1101_highlighting=none
71+
resharper_sa1116_highlighting=hint
72+
resharper_sa1118_highlighting=hint
73+
resharper_sa1305_highlighting=none
74+
resharper_sa1309_highlighting=hint
75+
resharper_sa1310_highlighting=none
76+
resharper_sa1500_highlighting=none
77+
resharper_sx1309_highlighting=none
78+
resharper_web_config_module_not_resolved_highlighting=warning
79+
resharper_web_config_type_not_resolved_highlighting=warning
80+
resharper_web_config_wrong_module_highlighting=warning
81+
trim_trailing_whitespace=true
82+
insert_final_newline=false
83+
84+
[*.config]
85+
indent_style=space
86+
indent_size=4
87+
88+
[{*.csproj,*.ccproj,*.androidproj}]
89+
indent_style=space
90+
indent_size=4
91+
92+
[*.ruleset]
93+
indent_style=space
94+
indent_size=4
95+
96+
[.editorconfig]
97+
indent_style=space
98+
indent_size=4
99+
100+
[*.{appxmanifest,asax,ascx,aspx,build,config,cshtml,csproj,dbml,discomap,dtd,htm,html,jsproj,lsproj,master,njsproj,nuspec,proj,props,razor,resw,resx,skin,StyleCop,targets,tasks,vb,vbproj,xaml,xamlx,xml,xoml,xsd}]
101+
indent_style=space
102+
indent_size=4
103+
tab_width=4
Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
4-
5-
namespace CSUtil.Commons {
6-
public enum ArrowDirection {
7-
None = 0,
8-
Left = 1,
9-
Forward = 2,
10-
Right = 3,
11-
Turn = 4
12-
}
13-
}
1+
namespace CSUtil.Commons {
2+
public enum ArrowDirection {
3+
None = 0,
4+
Left = 1,
5+
Forward = 2,
6+
Right = 3,
7+
Turn = 4
8+
}
9+
}
Lines changed: 14 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,14 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
6-
namespace CSUtil.Commons {
7-
public class ArrowDirectionUtil {
8-
public static ArrowDirection InvertLeftRight(ArrowDirection dir) {
9-
if (dir == ArrowDirection.Left)
10-
dir = ArrowDirection.Right;
11-
else if (dir == ArrowDirection.Right)
12-
dir = ArrowDirection.Left;
13-
return dir;
14-
}
15-
16-
/// <summary>
17-
/// Calculates the direction of <paramref name="toRelDir"/> in relation to ArrowDirection.TURN.
18-
/// </summary>
19-
/// <param name="fromDir">source direction</param>
20-
/// <param name="toRelDir">target direction, relative to <paramref name="fromDir"/></param>
21-
/// <returns></returns>
22-
public static ArrowDirection MakeAbsolute(ArrowDirection fromDir, ArrowDirection toRelDir) {
23-
if (fromDir == ArrowDirection.None) {
24-
// invalid direction
25-
return ArrowDirection.None;
26-
}
27-
28-
if (toRelDir == ArrowDirection.None) {
29-
// invalid direction
30-
return ArrowDirection.None;
31-
}
32-
33-
if (fromDir == ArrowDirection.Turn) {
34-
// toRelDir is already relative to TURN
35-
return toRelDir;
36-
}
37-
38-
if (toRelDir == ArrowDirection.Turn) {
39-
// toRelDir is fromDir
40-
return fromDir;
41-
}
42-
43-
int fromDirBase0 = (int)fromDir - 1;
44-
int toRelDirBase1 = (int)toRelDir;
45-
/*
46-
* Direction | Base 0 | Base 1
47-
* ==========+========+=======
48-
* Left | 0 | 1
49-
* Forward | 1 | 2
50-
* Right | 2 | 3
51-
*
52-
*
53-
* Direction 1 | Direction 2 | Dir. 1 B0 | Dir. 2 B1 | Sum | (Sum + 1) % 4 | Desired dir.
54-
* ============+=============+===========+===========+=====|===============+=============
55-
* Left | Left | 0 | 1 | 1 | 2 | (Forward, 2)
56-
* Left | Forward | 0 | 2 | 2 | 3 | (Right, 3)
57-
* Left | Right | 0 | 3 | 3 | 0 | (Turn, 4)
58-
* Forward | Left | 1 | 1 | 2 | 3 | (Right, 3)
59-
* Forward | Forward | 1 | 2 | 3 | 0 | (Turn, 4)
60-
* Forward | Right | 1 | 3 | 4 | 1 | (Left, 1)
61-
* Right | Left | 2 | 1 | 3 | 0 | (Turn, 4)
62-
* Right | Forward | 2 | 2 | 4 | 1 | (Left, 1)
63-
* Right | Right | 2 | 3 | 5 | 2 | (Forward, 2)
64-
*/
65-
66-
int ret = (fromDirBase0 + toRelDirBase1 + 1) % 4;
67-
if (ret == 0) {
68-
ret = 4;
69-
}
70-
return (ArrowDirection)ret;
71-
}
72-
}
73-
}
1+
namespace CSUtil.Commons {
2+
public static class ArrowDirectionUtil {
3+
public static ArrowDirection InvertLeftRight(ArrowDirection dir) {
4+
switch (dir) {
5+
case ArrowDirection.Left:
6+
return ArrowDirection.Right;
7+
case ArrowDirection.Right:
8+
return ArrowDirection.Left;
9+
}
10+
11+
return dir;
12+
}
13+
}
14+
}

TLM/CSUtil.Commons/EnumUtil.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
1+
namespace CSUtil.Commons {
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
55

6-
namespace CSUtil.Commons {
7-
public static class EnumUtil {
8-
public static IEnumerable<T> GetValues<T>() {
9-
return Enum.GetValues(typeof(T)).Cast<T>();
10-
}
11-
}
12-
}
6+
public static class EnumUtil {
7+
public static IEnumerable<T> GetValues<T>() {
8+
return Enum.GetValues(typeof(T)).Cast<T>();
9+
}
10+
}
11+
}

0 commit comments

Comments
 (0)