Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert.Unload #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using DynamicPatcher;
using Extension.Utilities;
using PatcherYRpp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Extension.Ext
{
public partial class TechnoExt
{
private bool needConvertWhenLanding = false;
private bool landed = false;
private string FloatingType;
private string LandingType;


public unsafe void UnitClass_Init_Convert_Unload()
{
if (string.IsNullOrEmpty(Type.ConvertUnloadTo)) return;
needConvertWhenLanding = true;
FloatingType = OwnerObject.Ref.Type.Ref.Base.Base.ID;
LandingType = Type.ConvertUnloadTo;

OnUpdateAction += UnitClass_Update_Convert_Unload;
}

public unsafe void UnitClass_Update_Convert_Unload()
{
if (!needConvertWhenLanding) return;
var mission = OwnerObject.Convert<MissionClass>();

if (landed == false)
{
if (mission.Ref.CurrentMission == Mission.Unload)
{
OwnerObject.Convert<UnitClass>().Ref.Type = TechnoTypeClass.ABSTRACTTYPE_ARRAY.Find(LandingType).Convert<UnitTypeClass>();
landed = true;
}
}
else
{
if (mission.Ref.CurrentMission == Mission.Move)
{
OwnerObject.Convert<UnitClass>().Ref.Type = TechnoTypeClass.ABSTRACTTYPE_ARRAY.Find(FloatingType).Convert<UnitTypeClass>();
landed = false;
}
}
}

}

public partial class TechnoTypeExt
{
public string ConvertUnloadTo;

/// <summary>
///
/// </summary>
/// <param name="reader"></param>
/// <param name="section"></param>
private void ReadConvertUnloadData(INIReader reader, string section)
{
if (string.IsNullOrEmpty(ConvertUnloadTo))
{
reader.ReadNormal(section, "Convert.Unload", ref ConvertUnloadTo);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public void OnInit()
case AbstractType.Unit:
UnitClass_Init_JumpjetFacingToTarget();
UnitClass_Init_UnitDeployFireOnce();
UnitClass_Init_Convert_Unload();
break;
case AbstractType.Aircraft:
AircraftClass_Init_AircraftDive();
Expand Down