-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMain.cs
More file actions
100 lines (94 loc) · 3.51 KB
/
Main.cs
File metadata and controls
100 lines (94 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using System;
using System.Diagnostics;
using System.IO;
using HarmonyLib;
using TaleWorlds.Core;
using TaleWorlds.MountAndBlade;
namespace FixSiegeAI
{
// Main class
public class Main : MBSubModuleBase
{
// This runs at game main menu
protected override void OnBeforeInitialModuleScreenSetAsRoot()
{
try { File.Delete(@"C:\Users\Shadow\Desktop\FixSiegeAI_Log.txt"); } catch { };
try
{
Main.Log("FixSiegeAI v2.0.2 loaded.",true);
var harmony = new Harmony("fixsiegeai");
harmony.PatchAll();
Main.Log("Harmony patches loaded.");
}
catch (Exception e) { Main.Log(e.Message); };
}
// This runs when module is loaded.
protected override void OnSubModuleLoad()
{
// todo hotkeys
}
// Stops ai from reticking if the original first order is not followed through, DOES NOT prevent first AI order
public override void OnMissionBehaviourInitialize(Mission mission)
{
Main.Log(Environment.NewLine + "Mission loaded. ");
foreach (SiegeWeapon sw in Mission.Current.ActiveMissionObjects.FindAllWithType<SiegeWeapon>())
{
if (sw != null && sw.Side == Mission.Current.PlayerTeam.Side && Mission.Current.PlayerTeam.IsPlayerGeneral)
{
sw.ForcedUse = false;
Main.Log(sw.Side.ToString() + " " + sw.GetSiegeEngineType().ToString() + " forced use haulted.");
// TODO: attempt to fix siege angle restrictions
//if (sw is RangedSiegeWeapon)
//{
// Main.Log(sw.Side.ToString() + " " + sw.GetSiegeEngineType().ToString() + " release angles: " + (sw as RangedSiegeWeapon).TopReleaseAngleRestriction.ToString());
// Main.Log(sw.Side.ToString() + " " + sw.GetSiegeEngineType().ToString() + " release angles: " + (sw as RangedSiegeWeapon).BottomReleaseAngleRestriction.ToString());
// if (sw is Trebuchet)
// {
// (sw as RangedSiegeWeapon).BottomReleaseAngleRestriction = 0.1f;
// }
// Main.Log(sw.Side.ToString() + " " + sw.GetSiegeEngineType().ToString() + " release angles widened.");
//}
}
}
}
// Utilities
public static void Log(string s, bool ingame = false)
{
bool debugging = true; // change this to true for helpful debugging info in-game and to log below
if (ingame || debugging)
{
InformationManager.DisplayMessage(new InformationMessage(s));
}
if (debugging)
{
string log_path = @"C:\Users\Shadow\Desktop\FixSiegeAI_Log.txt"; // change where you want the log to save
try
{
using (System.IO.StreamWriter file = new System.IO.StreamWriter(log_path, true))
{ file.WriteLine(s); };
}
catch { };
}
}
public static void St()
{
StackTrace stackTrace = new StackTrace(true);
foreach (StackFrame frame in stackTrace.GetFrames())
{
Main.Log(" Method Name: " + frame.GetMethod().Name + " File Name:" + frame.GetMethod().Module.Name + " Line No: " + frame.GetFileLineNumber());
}
}
public static bool IsPIC(Formation formation, bool debug = false)
{
bool isPG = formation.Team.IsPlayerGeneral;
if (debug) { Main.Log(Environment.NewLine + "Is player general of formation?: " + isPG.ToString()); }
bool isPS = formation.Team.IsPlayerSergeant;
if (debug) { Main.Log("Is player sergeant of formation?: " + isPS.ToString()); }
bool isPA = Mission.Current.MainAgent != null && Mission.Current.MainAgent.IsActive();
if (debug) { Main.Log("Is player alive?: " + isPA.ToString()); }
bool isPIC = isPA && (isPG | isPS);
if (debug) { Main.Log("Is player in charge of formation?: " + isPIC.ToString()); }
if (isPIC) { return true; } else { return false; }
}
}
}