Skip to content

Commit

Permalink
Merge pull request #298 from t1a2l/master
Browse files Browse the repository at this point in the history
Support for Campus Industries Housing Mod
  • Loading branch information
algernon-A authored Sep 17, 2022
2 parents 978d639 + 5e22f1b commit baac4f2
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/RealTime/CustomAI/RealTimeBuildingAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,10 @@ private bool ShouldSwitchBuildingLightsOff(ushort buildingId, ItemClass.Service
{
return false;
}
else if (buildingManager.IsAreaResidentalBuilding(buildingId))
{
return false;
}
else
{
goto default;
Expand Down
30 changes: 28 additions & 2 deletions src/RealTime/GameConnection/BuildingManagerConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace RealTime.GameConnection
{
using ColossalFramework;
using System.Collections.Generic;
using System.Linq;
using ColossalFramework;
using UnityEngine;

/// <summary>
Expand Down Expand Up @@ -453,6 +453,32 @@ public bool IsAreaMainBuilding(ushort buildingId)
return buildinAI is MainCampusBuildingAI || buildinAI is MainIndustryBuildingAI;
}

/// <summary>
/// Determines whether the building with specified ID is a residental building of an Industrial or a Campus area.
/// </summary>
/// <param name="buildingId">The building ID to check.</param>
/// <returns>
/// <c>true</c> if the building with the specified ID is a residental building of an Industrial or a Campus area;
/// otherwise, <c>false</c>.
/// </returns>
public bool IsAreaResidentalBuilding(ushort buildingId)
{
if (buildingId == 0)
{
return false;
}

// Here we need to check if the mod is active
var buildingInfo = BuildingManager.instance.m_buildings.m_buffer[buildingId].Info;
var buildinAI = buildingInfo?.m_buildingAI;
if (buildinAI is AuxiliaryBuildingAI && buildinAI.GetType().Name.Equals("BarracksAI") || buildinAI is CampusBuildingAI && buildinAI.GetType().Name.Equals("DormsAI"))
{
return true;
}

return false;
}

/// <summary>
/// Determines whether the AI class of the building with specified ID is of the specified type <typeparamref name="T"/>.
/// </summary>
Expand Down Expand Up @@ -503,7 +529,7 @@ public bool IsBuildingServiceLevel(ushort buildingId, ItemClass.Service building
private static bool BuildingCanBeVisited(ushort buildingId)
{
var citizenUnitBuffer = Singleton<CitizenManager>.instance.m_units.m_buffer;
uint currentUnitId = BuildingManager.instance.m_buildings.m_buffer[buildingId].m_citizenUnits;
uint currentUnitId = BuildingManager.instance.m_buildings.m_buffer[buildingId].m_citizenUnits;
int unitBufferSize = citizenUnitBuffer.Length;

uint counter = 0;
Expand Down
10 changes: 10 additions & 0 deletions src/RealTime/GameConnection/IBuildingManagerConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,16 @@ ushort FindActiveBuilding(
/// </returns>
bool IsAreaMainBuilding(ushort buildingId);

/// <summary>
/// Determines whether the building with specified ID is a residental building of an Industrial or a Campus area.
/// </summary>
/// <param name="buildingId">The building ID to check.</param>
/// <returns>
/// <c>true</c> if the building with the specified ID is a residental building of an Industrial or a Campus area;
/// otherwise, <c>false</c>.
/// </returns>
bool IsAreaResidentalBuilding(ushort buildingId);

/// <summary>
/// Determines whether the AI class of the building with specified ID is of the specified type <typeparamref name="T"/>.
/// </summary>
Expand Down

0 comments on commit baac4f2

Please sign in to comment.