Skip to content

Commit

Permalink
Merge pull request #30 from bloodypenguin/Code_Cleanup
Browse files Browse the repository at this point in the history
Code cleanup
  • Loading branch information
andreharv authored May 28, 2020
2 parents 799bd9a + 4ab04e1 commit cb16e29
Show file tree
Hide file tree
Showing 14 changed files with 477 additions and 776 deletions.
74 changes: 37 additions & 37 deletions AssetsUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -688,43 +688,43 @@ private static void UpdateNoColPillars()
}
private static void UpdateMetroTrainEffects()
{
var vanillaMetro = PrefabCollection<VehicleInfo>.FindLoaded("Metro");
var arriveEffect = ((MetroTrainAI)vanillaMetro.m_vehicleAI).m_arriveEffect;
for (uint i = 0; i < PrefabCollection<VehicleInfo>.LoadedCount(); i++)
{
try
{
var info = PrefabCollection<VehicleInfo>.GetLoaded(i);
var metroTrainAI = info?.m_vehicleAI as MetroTrainAI;
if (metroTrainAI == null)
{
continue;
}
if (info.m_effects == null || info.m_effects.Length == 0)
{
info.m_effects = vanillaMetro.m_effects;
}
else
{
for (var j = 0; j < info.m_effects.Length; j++)
{
if (info.m_effects[j].m_effect?.name == "Train Movement")
{
info.m_effects[j] = vanillaMetro.m_effects[0];
}
}
}
var arriveEffectName = metroTrainAI.m_arriveEffect?.name;
if (arriveEffectName == null || arriveEffectName == "Transport Arrive")
{
metroTrainAI.m_arriveEffect = arriveEffect;
}
}
catch
{
//swallow
}
}
//var vanillaMetro = PrefabCollection<VehicleInfo>.FindLoaded("Metro");
//var arriveEffect = ((MetroTrainAI)vanillaMetro.m_vehicleAI).m_arriveEffect;
//for (uint i = 0; i < PrefabCollection<VehicleInfo>.LoadedCount(); i++)
//{
// try
// {
// var info = PrefabCollection<VehicleInfo>.GetLoaded(i);
// var metroTrainAI = info?.m_vehicleAI as MetroTrainAI;
// if (metroTrainAI == null)
// {
// continue;
// }
// if (info.m_effects == null || info.m_effects.Length == 0)
// {
// info.m_effects = vanillaMetro.m_effects;
// }
// else
// {
// for (var j = 0; j < info.m_effects.Length; j++)
// {
// if (info.m_effects[j].m_effect?.name == "Train Movement")
// {
// info.m_effects[j] = vanillaMetro.m_effects[0];
// }
// }
// }
// var arriveEffectName = metroTrainAI.m_arriveEffect?.name;
// if (arriveEffectName == null || arriveEffectName == "Transport Arrive")
// {
// metroTrainAI.m_arriveEffect = arriveEffect;
// }
// }
// catch
// {
// //swallow
// }
//}
}
}
}
109 changes: 0 additions & 109 deletions Detours/DepotAIDetour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,114 +65,5 @@ public class DepotAIDetour : DepotAI
}
}
}
[RedirectMethod]
public override string GetLocalizedStats(ushort buildingID, ref Building data)
{
string text = string.Empty;
if ((UnityEngine.Object)this.m_transportInfo != (UnityEngine.Object)null && this.m_maxVehicleCount != 0)
{
switch (this.m_transportInfo.m_transportType)
{
case TransportInfo.TransportType.Bus:
case TransportInfo.TransportType.TouristBus:
{
int vehicleCount = this.GetVehicleCount(buildingID, ref data);
int budget = Singleton<EconomyManager>.instance.GetBudget(this.m_info.m_class);
int productionRate = PlayerBuildingAI.GetProductionRate(100, budget);
int num = (productionRate * this.m_maxVehicleCount + 99) / 100;
text += LocaleFormatter.FormatGeneric("AIINFO_BUSDEPOT_BUSCOUNT", new object[]
{
vehicleCount,
num
});
break;
}
case TransportInfo.TransportType.Ship:
if (this.m_transportInfo.m_vehicleType == VehicleInfo.VehicleType.Ferry)
{
int vehicleCount2 = this.GetVehicleCount(buildingID, ref data);
int budget2 = Singleton<EconomyManager>.instance.GetBudget(this.m_info.m_class);
int productionRate2 = PlayerBuildingAI.GetProductionRate(100, budget2);
int num2 = (productionRate2 * this.m_maxVehicleCount + 99) / 100;
text += LocaleFormatter.FormatGeneric("AIINFO_FERRYDEPOT_FERRYCOUNT", new object[]
{
vehicleCount2,
num2
});
}
break;
case TransportInfo.TransportType.Airplane:
if (this.m_transportInfo.m_vehicleType == VehicleInfo.VehicleType.Blimp)
{
int vehicleCount3 = this.GetVehicleCount(buildingID, ref data);
int budget3 = Singleton<EconomyManager>.instance.GetBudget(this.m_info.m_class);
int productionRate3 = PlayerBuildingAI.GetProductionRate(100, budget3);
int num3 = (productionRate3 * this.m_maxVehicleCount + 99) / 100;
text += LocaleFormatter.FormatGeneric("AIINFO_BLIMPDEPOT_BLIMPCOUNT", new object[]
{
vehicleCount3,
num3
});
}
break;
case TransportInfo.TransportType.Taxi:
{
int vehicleCount4 = this.GetVehicleCount(buildingID, ref data);
int budget4 = Singleton<EconomyManager>.instance.GetBudget(this.m_info.m_class);
int productionRate4 = PlayerBuildingAI.GetProductionRate(100, budget4);
int num4 = (productionRate4 * this.m_maxVehicleCount + 99) / 100;
text += LocaleFormatter.FormatGeneric("AIINFO_TAXIDEPOT_VEHICLES", new object[]
{
vehicleCount4,
num4
});
break;
}
case TransportInfo.TransportType.Tram:
{
int vehicleCount5 = this.GetVehicleCount(buildingID, ref data);
int budget5 = Singleton<EconomyManager>.instance.GetBudget(this.m_info.m_class);
int productionRate5 = PlayerBuildingAI.GetProductionRate(100, budget5);
int num5 = (productionRate5 * this.m_maxVehicleCount + 99) / 100;
text += LocaleFormatter.FormatGeneric("AIINFO_TRAMDEPOT_TRAMCOUNT", new object[]
{
vehicleCount5,
num5
});
break;
}
//begin mod
case TransportInfo.TransportType.Metro:
{
int vehicleCount6 = this.GetVehicleCount(buildingID, ref data);
int budget6 = Singleton<EconomyManager>.instance.GetBudget(this.m_info.m_class);
int productionRate6 = PlayerBuildingAI.GetProductionRate(100, budget6);
int num6 = (productionRate6 * this.m_maxVehicleCount + 99) / 100;
text += LocaleFormatter.FormatGeneric("AIINFO_TRAMDEPOT_TRAMCOUNT", new object[]
{
vehicleCount6,
num6
}).Replace("Tram", "Metro");
break;
}

case TransportInfo.TransportType.Train:
{
int vehicleCount7 = this.GetVehicleCount(buildingID, ref data);
int budget7 = Singleton<EconomyManager>.instance.GetBudget(this.m_info.m_class);
int productionRate7 = PlayerBuildingAI.GetProductionRate(100, budget7);
int num7 = (productionRate7 * this.m_maxVehicleCount + 99) / 100;
text += LocaleFormatter.FormatGeneric("AIINFO_TRAMDEPOT_TRAMCOUNT", new object[]
{
vehicleCount7,
num7
}).Replace("Tram", "Train");
break;
//end mod
}
}
}
return text;
}
}
}
78 changes: 39 additions & 39 deletions Detours/MetroTrainAIDetour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,45 +22,45 @@ public static void ChangeDeployState(bool state)
}
}

[RedirectMethod]
public override void CreateVehicle(ushort vehicleID, ref Vehicle data)
{
base.CreateVehicle(vehicleID, ref data);
//begin mod
if (vehicleID > 0)
{
var position = VehicleManager.instance.m_vehicles.m_buffer[vehicleID].m_frame0.m_position;
if (position.y < TerrainManager.instance.SampleDetailHeightSmooth(position.x, position.z))
//how about sunken stations?
{
data.m_flags |= Vehicle.Flags.Underground;
}
else
{
data.m_flags &= ~Vehicle.Flags.Underground;
}
}
//end mod
}
//[RedirectMethod]
//public override void CreateVehicle(ushort vehicleID, ref Vehicle data)
//{
// base.CreateVehicle(vehicleID, ref data);
// //begin mod
// if (vehicleID > 0)
// {
// var position = VehicleManager.instance.m_vehicles.m_buffer[vehicleID].m_frame0.m_position;
// if (position.y < TerrainManager.instance.SampleDetailHeightSmooth(position.x, position.z))
// //how about sunken stations?
// {
// data.m_flags |= Vehicle.Flags.Underground;
// }
// else
// {
// data.m_flags &= ~Vehicle.Flags.Underground;
// }
// }
// //end mod
//}

[RedirectMethod]
public override void LoadVehicle(ushort vehicleID, ref Vehicle data)
{
base.LoadVehicle(vehicleID, ref data);
//begin mod
if (vehicleID > 0)
{
var position = VehicleManager.instance.m_vehicles.m_buffer[vehicleID].m_frame0.m_position;
if (position.y < TerrainManager.instance.SampleDetailHeightSmooth(position.x, position.z)) //how about sunken stations?
{
data.m_flags |= Vehicle.Flags.Underground;
}
else
{
data.m_flags &= ~Vehicle.Flags.Underground;
}
}
//end mod
}
//[RedirectMethod]
//public override void LoadVehicle(ushort vehicleID, ref Vehicle data)
//{
// base.LoadVehicle(vehicleID, ref data);
// //begin mod
// if (vehicleID > 0)
// {
// var position = VehicleManager.instance.m_vehicles.m_buffer[vehicleID].m_frame0.m_position;
// if (position.y < TerrainManager.instance.SampleDetailHeightSmooth(position.x, position.z)) //how about sunken stations?
// {
// data.m_flags |= Vehicle.Flags.Underground;
// }
// else
// {
// data.m_flags &= ~Vehicle.Flags.Underground;
// }
// }
// //end mod
//}
}
}
38 changes: 1 addition & 37 deletions Detours/PassengerTrainAIDetour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,43 +37,7 @@ public static void ChangeDeployState(bool state)
Redirector<PassengerTrainAIDetour>.Revert();
}
}
[RedirectMethod]
protected override void ArrivingToDestination(ushort vehicleID, ref Vehicle vehicleData)
{
base.ArrivingToDestination(vehicleID, ref vehicleData);
if (this.m_arriveEffect == null)
return;
if ((vehicleData.m_flags & Vehicle.Flags.GoingBack) != ~(Vehicle.Flags.Created | Vehicle.Flags.Deleted | Vehicle.Flags.Spawned | Vehicle.Flags.Inverted | Vehicle.Flags.TransferToTarget | Vehicle.Flags.TransferToSource | Vehicle.Flags.Emergency1 | Vehicle.Flags.Emergency2 | Vehicle.Flags.WaitingPath | Vehicle.Flags.Stopped | Vehicle.Flags.Leaving | Vehicle.Flags.Arriving | Vehicle.Flags.Reversed | Vehicle.Flags.TakingOff | Vehicle.Flags.Flying | Vehicle.Flags.Landing | Vehicle.Flags.WaitingSpace | Vehicle.Flags.WaitingCargo | Vehicle.Flags.GoingBack | Vehicle.Flags.WaitingTarget | Vehicle.Flags.Importing | Vehicle.Flags.Exporting | Vehicle.Flags.Parking | Vehicle.Flags.CustomName | Vehicle.Flags.OnGravel | Vehicle.Flags.WaitingLoading | Vehicle.Flags.Congestion | Vehicle.Flags.DummyTraffic | Vehicle.Flags.Underground | Vehicle.Flags.Transition | Vehicle.Flags.InsideBuilding | Vehicle.Flags.LeftHandDrive))
{
if ((int)vehicleData.m_sourceBuilding == 0)
return;
Vector3 position = Singleton<BuildingManager>.instance.m_buildings.m_buffer[(int)vehicleData.m_sourceBuilding].m_position;
InstanceID instance = new InstanceID();
instance.Building = vehicleData.m_sourceBuilding;
EffectInfo.SpawnArea spawnArea = new EffectInfo.SpawnArea(position, Vector3.up, 0.0f);
Singleton<EffectManager>.instance.DispatchEffect(this.m_arriveEffect, instance, spawnArea, Vector3.zero, 0.0f, 1f, Singleton<BuildingManager>.instance.m_audioGroup);
}
else if ((vehicleData.m_flags & Vehicle.Flags.DummyTraffic) != ~(Vehicle.Flags.Created | Vehicle.Flags.Deleted | Vehicle.Flags.Spawned | Vehicle.Flags.Inverted | Vehicle.Flags.TransferToTarget | Vehicle.Flags.TransferToSource | Vehicle.Flags.Emergency1 | Vehicle.Flags.Emergency2 | Vehicle.Flags.WaitingPath | Vehicle.Flags.Stopped | Vehicle.Flags.Leaving | Vehicle.Flags.Arriving | Vehicle.Flags.Reversed | Vehicle.Flags.TakingOff | Vehicle.Flags.Flying | Vehicle.Flags.Landing | Vehicle.Flags.WaitingSpace | Vehicle.Flags.WaitingCargo | Vehicle.Flags.GoingBack | Vehicle.Flags.WaitingTarget | Vehicle.Flags.Importing | Vehicle.Flags.Exporting | Vehicle.Flags.Parking | Vehicle.Flags.CustomName | Vehicle.Flags.OnGravel | Vehicle.Flags.WaitingLoading | Vehicle.Flags.Congestion | Vehicle.Flags.DummyTraffic | Vehicle.Flags.Underground | Vehicle.Flags.Transition | Vehicle.Flags.InsideBuilding | Vehicle.Flags.LeftHandDrive))
{
if ((int)vehicleData.m_targetBuilding == 0)
return;
Vector3 position = Singleton<BuildingManager>.instance.m_buildings.m_buffer[(int)vehicleData.m_targetBuilding].m_position;
InstanceID instance = new InstanceID();
instance.Building = vehicleData.m_targetBuilding;
EffectInfo.SpawnArea spawnArea = new EffectInfo.SpawnArea(position, Vector3.up, 0.0f);
Singleton<EffectManager>.instance.DispatchEffect(this.m_arriveEffect, instance, spawnArea, Vector3.zero, 0.0f, 1f, Singleton<BuildingManager>.instance.m_audioGroup);
}
else
{
if ((int)vehicleData.m_targetBuilding == 0)
return;
Vector3 position = Singleton<NetManager>.instance.m_nodes.m_buffer[(int)vehicleData.m_targetBuilding].m_position;
InstanceID instance = new InstanceID();
instance.NetNode = vehicleData.m_targetBuilding;
EffectInfo.SpawnArea spawnArea = new EffectInfo.SpawnArea(position, Vector3.up, 0.0f);
Singleton<EffectManager>.instance.DispatchEffect(this.m_arriveEffect, instance, spawnArea, Vector3.zero, 0.0f, 1f, Singleton<BuildingManager>.instance.m_audioGroup);
}
}

[RedirectMethod]
protected override bool StartPathFind(ushort vehicleID, ref Vehicle vehicleData)
{
Expand Down
16 changes: 2 additions & 14 deletions Extensions/BuildingInfoExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -630,19 +630,6 @@ public static List<int> LinkedPaths(this BuildingInfo info, int inx, List<int> i
return retval;
}

public static List<BuildingInfo.PathInfo> LowestHighPaths(this BuildingInfo info)
{
var retval = new List<BuildingInfo.PathInfo>();
retval = info.m_paths.Where(p => p.IsPedestrianPath() && p.m_nodes.Any(n => n.y > -4) && p.m_nodes.Any(nd => nd.y <= -4)).ToList();
if (retval.Count == 0)
{
retval.Add(info.m_paths.Where(p => IsPedestrianPath(p))
.OrderByDescending(p => p.m_nodes[0].y)
.FirstOrDefault());
}
return retval;
}

public static Vector3 FindAverageNode(this BuildingInfo info, bool isDeep)
{
var center = Vector3.zero;
Expand All @@ -667,7 +654,7 @@ public static Vector3 FindAverageNode(this BuildingInfo info, bool isDeep)
{
for (int k = 0; k < path.m_nodes.Length; k++)
{
nodeList.Add(SetStationCustomizations.AdjustNodeForParent(path.m_nodes[k], parentMetaData));
nodeList.Add(SetStationCustomizations.AdjustNodeFromParentToChild(path.m_nodes[k], parentMetaData));
}
}
}
Expand All @@ -683,6 +670,7 @@ public static Vector3 FindAverageNode(this BuildingInfo info, bool isDeep)
center /= nodeList.Count();
return center;
}

public static void StoreBuildingDefault(this BuildingInfo info)
{
if (StationBuildingCustomization.StoredStationPaths == null)
Expand Down
2 changes: 1 addition & 1 deletion Extensions/NetInfoExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ public static bool IsTrainSingleTrack(this NetInfo netInfo)
}
public static bool IsPedestrianNetwork(this NetInfo info)
{
return info != null && (info.name == "Pedestrian Connection Surface" || info.name == "Pedestrian Connection Inside" || info.name == "Pedestrian Connection Underground");
return info != null && info.name.StartsWith("Pedestrian Connection");
}
public static bool IsTrainTrackAI(this NetInfo info)
{
Expand Down
Loading

0 comments on commit cb16e29

Please sign in to comment.