Skip to content

Commit

Permalink
详见描述
Browse files Browse the repository at this point in the history
- 提升版本号
- 修复在跟随模式下跟随市民时,如果其进入车辆,信息面板将不会显示有关该市民的信息;如果其在小路上时,摄像头可能会进入地下的问题
- 修复自由模式下的自动移动功能问题
- 修复潜在的UI切换问题
- 优化检查模组的方式
- 修复漫游模式下无法跟随市民的问题
- 更新翻译
  • Loading branch information
will258012 committed Sep 15, 2024
1 parent 7267f35 commit 04870a1
Show file tree
Hide file tree
Showing 15 changed files with 203 additions and 185 deletions.
133 changes: 93 additions & 40 deletions FPSCamera/Code/Cam/CitizenCam.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using AlgernonCommons.Translation;
using ColossalFramework;
using ColossalFramework.Math;
using System.Collections.Generic;
using System.Linq;
using static FPSCamera.Utils.MathUtils;

namespace FPSCamera.Cam
Expand All @@ -20,7 +22,7 @@ public CitizenCam(InstanceID id)
}
else if (id.Type == InstanceType.CitizenInstance)
{
var citizenId = GetCitizenInstance().m_citizen;
var citizenId = CitizenManager.instance.m_instances.m_buffer[id.CitizenInstance].m_citizen;
FollowInstance = new InstanceID() { Citizen = citizenId };
FollowID = citizenId;
IsActivated = true;
Expand All @@ -29,9 +31,8 @@ public CitizenCam(InstanceID id)
public uint FollowID { get; private set; }
public bool IsActivated { get; private set; }
public InstanceID FollowInstance { get; private set; }
internal bool CheckAnotherCam()
private void CheckAnotherCam()
{
if (!IsActivated) return false;
var flags = GetCitizenInstance().m_flags;
if (IsinVehicle)
{
Expand All @@ -40,9 +41,7 @@ internal bool CheckAnotherCam()
IsinVehicle = false;
AnotherCam.StopCam();
AnotherCam = null;
return false;
}
return true;
}

if (flags.IsFlagSet(CitizenInstance.Flags.EnteringVehicle))
Expand All @@ -52,56 +51,34 @@ internal bool CheckAnotherCam()
ushort vehicleId = GetCitizen().m_vehicle;
IsinVehicle = true;
AnotherCam = new VehicleCam(new InstanceID() { Vehicle = vehicleId });
return true;
}
}
return false;
}
public Dictionary<string, string> GetInfos()
{
var details = new Dictionary<string, string>();
string occupation;
var flags = GetCitizen().m_flags;
details[Translations.Translate("INFO_HUMAN_HOME")] =
GetCitizen().m_homeBuilding != default ? BuildingManager.instance.GetBuildingName(GetCitizen().m_homeBuilding, new InstanceID() { Building = GetCitizen().m_homeBuilding }) :
Translations.Translate("INFO_HUMAN_HOMELESS");

if ((flags & Citizen.Flags.Tourist) != 0)
occupation = Translations.Translate("INFO_HUMAN_TOURIST");
else
{
if (GetCitizen().m_workBuilding != default)
{
if (((flags & Citizen.Flags.Student) != 0))
{
occupation = string.Format(
Translations.Translate("INFO_HUMAN_STUDENTAT"),
BuildingManager.instance.GetBuildingName(GetCitizen().m_workBuilding, new InstanceID() { Building = GetCitizen().m_workBuilding }));
}
else
{
occupation = string.Format(
Translations.Translate("INFO_HUMAN_WORKAT"),
BuildingManager.instance.GetBuildingName(GetCitizen().m_workBuilding, new InstanceID() { Building = GetCitizen().m_workBuilding }));
}
}
else
{
occupation = Translations.Translate("INFO_HUMAN_UNENPLOYED");
}

details[Translations.Translate("INFO_HUMAN_HOME")] =
GetCitizen().m_homeBuilding != default ? BuildingManager.instance.GetBuildingName(GetCitizen().m_homeBuilding, new InstanceID() { Building = GetCitizen().m_homeBuilding }) :
Translations.Translate("INFO_HUMAN_HOMELESS");

}
details[Translations.Translate("INFO_HUMAN_OCCUPATION")] = occupation;
details[Translations.Translate("INFO_HUMAN_OCCUPATION")] = GetOccupation();

if (GetCitizen().m_hotelBuilding != default)
details[Translations.Translate("INFO_HUMAN_HOTEL")] =
BuildingManager.instance.GetBuildingName(GetCitizen().m_hotelBuilding, new InstanceID() { Building = GetCitizen().m_hotelBuilding });

var anotherDetails = AnotherCam?.GetInfos();
if (anotherDetails != null)
details = details.Concat(anotherDetails).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
return details;
}



public Positioning GetPositioning()
{
if (AnotherCam != null)
return AnotherCam.GetPositioning();
GetCitizenInstance().GetSmoothPosition(GetCitizen().m_instance, out var pos, out var rotation);
return new Positioning(pos, rotation);
}
Expand All @@ -121,10 +98,14 @@ public string GetStatus()
break;
}
return status;

}
public string GetAnotherCamStatus() => AnotherCam?.GetStatus();
public float GetSpeed() => GetCitizenInstance().GetLastFrameData().m_velocity.magnitude;

public bool IsVaild()
{
CheckAnotherCam();
var flags = GetCitizenInstance().m_flags;
return IsActivated && ((flags & (CitizenInstance.Flags.Created | CitizenInstance.Flags.Deleted)) == CitizenInstance.Flags.Created);
}
Expand All @@ -137,15 +118,87 @@ public void StopCam()
{
AnotherCam.StopCam();
}
AnotherCam = null;
}



internal IFollowCam AnotherCam = null;
private VehicleCam AnotherCam = null;
private bool IsinVehicle = false;

private Citizen GetCitizen() => CitizenManager.instance.m_citizens.m_buffer[FollowID];
private CitizenInstance GetCitizenInstance() => CitizenManager.instance.m_instances.m_buffer[GetCitizen().m_instance];
private string GetOccupation()
{
var currentSchoolLevel = GetCitizen().GetCurrentSchoolLevel(FollowID);
if (GetCitizen().m_flags.IsFlagSet(Citizen.Flags.Tourist))
{
if (SteamHelper.IsDLCOwned(SteamHelper.DLC.CampusDLC))
{
float num = Singleton<ImmaterialResourceManager>.instance.CheckExchangeStudentAttractivenessBonus() * 100f;
var m_randomizer = new Randomizer(FollowID);
int num2 = m_randomizer.Int32(0, 100);
if (num2 < num)
{
return ColossalFramework.Globalization.Locale.Get("CITIZEN_OCCUPATION_EXCHANGESTUDENT");
}
}

switch (GetCitizen().m_touristType)
{
case Citizen.TouristType.Sightseeing:
return ColossalFramework.Globalization.Locale.Get("CITIZEN_OCCUPATION_TOURIST_SIGHTSEEING");
case Citizen.TouristType.Shopping:
return ColossalFramework.Globalization.Locale.Get("CITIZEN_OCCUPATION_TOURIST_SHOPPING");
case Citizen.TouristType.Business:
return ColossalFramework.Globalization.Locale.Get("CITIZEN_OCCUPATION_TOURIST_BUSINESS");
case Citizen.TouristType.Nature:
return ColossalFramework.Globalization.Locale.Get("CITIZEN_OCCUPATION_TOURIST_NATURE");
default:
return ColossalFramework.Globalization.Locale.Get("CITIZEN_OCCUPATION_TOURIST");
}
}

if (currentSchoolLevel != ItemClass.Level.None)
{
return ColossalFramework.Globalization.Locale.Get("CITIZEN_SCHOOL_LEVEL", currentSchoolLevel.ToString());
}

return (GetCitizen().m_workBuilding == default) ? ColossalFramework.Globalization.Locale.Get("CITIZEN_OCCUPATION_UNEMPLOYED") : GetJobTitle();
}

private string GetJobTitle()
{
ushort workBuilding = GetCitizen().m_workBuilding;
var educationLevel = GetCitizen().EducationLevel;
var gender = GetCitizenInstance().Info.m_gender;
string text = string.Empty;
if (Singleton<BuildingManager>.instance.m_buildings.m_buffer[workBuilding].Info.m_buildingAI is CommonBuildingAI commonBuildingAI)
{
text = commonBuildingAI.GetTitle(gender, educationLevel, workBuilding, FollowID);
}

if (text == string.Empty)
{
int num = new Randomizer(workBuilding + FollowID).Int32(1, 5);
switch (educationLevel)
{
case Citizen.Education.Uneducated:
text = ColossalFramework.Globalization.Locale.Get((gender != Citizen.Gender.Female) ? "CITIZEN_OCCUPATION_PROFESSION_UNEDUCATED" : "CITIZEN_OCCUPATION_PROFESSION_UNEDUCATED_FEMALE", num.ToString());
break;
case Citizen.Education.OneSchool:
text = ColossalFramework.Globalization.Locale.Get((gender != Citizen.Gender.Female) ? "CITIZEN_OCCUPATION_PROFESSION_EDUCATED" : "CITIZEN_OCCUPATION_PROFESSION_EDUCATED_FEMALE", num.ToString());
break;
case Citizen.Education.TwoSchools:
text = ColossalFramework.Globalization.Locale.Get((gender != Citizen.Gender.Female) ? "CITIZEN_OCCUPATION_PROFESSION_WELLEDUCATED" : "CITIZEN_OCCUPATION_PROFESSION_WELLEDUCATED_FEMALE", num.ToString());
break;
case Citizen.Education.ThreeSchools:
text = ColossalFramework.Globalization.Locale.Get((gender != Citizen.Gender.Female) ? "CITIZEN_OCCUPATION_PROFESSION_HIGHLYEDUCATED" : "CITIZEN_OCCUPATION_PROFESSION_HIGHLYEDUCATED_FEMALE", num.ToString());
break;
}
}
return text + " " + ColossalFramework.Globalization.Locale.Get("CITIZEN_OCCUPATION_LOCATIONPREPOSITION") + " " + Singleton<BuildingManager>.instance.GetBuildingName(workBuilding, FollowInstance);
}
}
}

Expand Down
Loading

0 comments on commit 04870a1

Please sign in to comment.