Skip to content

Commit

Permalink
Merge pull request #1 from LeaderEnemyBoss/ELCP215
Browse files Browse the repository at this point in the history
Elcp 2.1.5
  • Loading branch information
LeaderEnemyBoss authored Aug 24, 2018
2 parents f1d2122 + 3e726a4 commit b7faa7e
Show file tree
Hide file tree
Showing 165 changed files with 14,403 additions and 6,886 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,18 @@ internal float Process(SimulationPropertyRefreshContext propertyRefreshContext,
num3 = 0f;
break;
case SimulationModifierDescriptor.ModifierOperation.Addition:
num = propertyRefreshContext.InternalCurrentValue + num2;
propertyRefreshContext.InternalPercentBaseValue = num;
propertyRefreshContext.InternalCurrentValue = num;
if (this.MultiplicativeStacking)
{
num = propertyRefreshContext.InternalCurrentValue + (1f - propertyRefreshContext.InternalCurrentValue) * num2;
propertyRefreshContext.InternalPercentBaseValue = num;
propertyRefreshContext.InternalCurrentValue = num;
}
else
{
num = propertyRefreshContext.InternalCurrentValue + num2;
propertyRefreshContext.InternalPercentBaseValue = num;
propertyRefreshContext.InternalCurrentValue = num;
}
break;
case SimulationModifierDescriptor.ModifierOperation.Subtraction:
num = propertyRefreshContext.InternalCurrentValue - num2;
Expand Down Expand Up @@ -221,6 +230,19 @@ protected float GetValue(object value, SimulationObject context, SimulationObjec
return context.Unsafe_GetPropertyValue(value as StaticString);
}

[XmlAttribute]
public bool MultiplicativeStacking
{
get
{
return this.multiplicativeStacking;
}
private set
{
this.multiplicativeStacking = value;
}
}

protected bool isBindOnSource;

private static int nextId;
Expand All @@ -231,6 +253,8 @@ protected float GetValue(object value, SimulationObject context, SimulationObjec

private SimulationPath path;

private bool multiplicativeStacking;

public enum ModifierOperation
{
Force,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Serialization;
using Amplitude;
using Amplitude.Unity.AI.BehaviourTree;
Expand All @@ -12,48 +13,54 @@ public class AIBehaviorTreeNode_Action_Colonize : AIBehaviorTreeNode_Action

protected override State Execute(AIBehaviorTree aiBehaviorTree, params object[] parameters)
{
State result;
Army army;
if (this.orderPosted)
{
if (this.orderExecuted)
{
this.orderExecuted = false;
this.orderPosted = false;
return State.Success;
result = State.Success;
}
return State.Running;
else
{
result = State.Running;
}
}
else if (base.GetArmyUnlessLocked(aiBehaviorTree, "$Army", out army) > AIArmyMission.AIArmyMissionErrorCode.None)
{
result = State.Failure;
}
else
{
Army army;
AIArmyMission.AIArmyMissionErrorCode armyUnlessLocked = base.GetArmyUnlessLocked(aiBehaviorTree, "$Army", out army);
if (armyUnlessLocked != AIArmyMission.AIArmyMissionErrorCode.None)
{
return State.Failure;
}
ArmyAction armyAction = null;
IDatabase<ArmyAction> database = Databases.GetDatabase<ArmyAction>(false);
List<ArmyAction> list = new List<ArmyAction>(database.GetValues());
List<ArmyAction> list2 = new List<ArmyAction>(list.FindAll((ArmyAction match) => match is ArmyAction_Colonization));
List<StaticString> list3 = new List<StaticString>();
for (int i = 0; i < list2.Count; i++)
List<ArmyAction> list = new List<ArmyAction>(new List<ArmyAction>(Databases.GetDatabase<ArmyAction>(false).GetValues()).FindAll((ArmyAction match) => match is ArmyAction_Colonization));
List<StaticString> list2 = new List<StaticString>();
for (int i = 0; i < list.Count; i++)
{
ArmyAction armyAction2 = list2[i];
if (armyAction2.CanExecute(army, ref list3, new object[0]))
if (list[i].CanExecute(army, ref list2, new object[0]))
{
armyAction = list2[i];
armyAction = list[i];
}
}
if (armyAction != null)
{
this.orderExecuted = false;
this.orderPosted = true;
this.CityLocation = army.WorldPosition;
this.Empire = army.Empire;
Ticket ticket;
armyAction.Execute(army, aiBehaviorTree.AICommander.Empire.PlayerControllers.AI, out ticket, new EventHandler<TicketRaisedEventArgs>(this.ArmyAction_TicketRaised), new object[0]);
return State.Running;
result = State.Running;
}
else
{
aiBehaviorTree.ErrorCode = 22;
result = State.Failure;
}
aiBehaviorTree.ErrorCode = 22;
return State.Failure;
}
return result;
}

protected override bool Initialize(AIBehaviorTree aiBehaviorTree)
Expand All @@ -63,10 +70,82 @@ protected override bool Initialize(AIBehaviorTree aiBehaviorTree)

private void ArmyAction_TicketRaised(object sender, TicketRaisedEventArgs e)
{
this.OrderCityBuilding();
this.CityLocation = WorldPosition.Invalid;
this.Empire = null;
this.orderExecuted = true;
}

private void OrderCityBuilding()
{
DepartmentOfTheInterior agency = this.Empire.GetAgency<DepartmentOfTheInterior>();
DepartmentOfIndustry agency2 = this.Empire.GetAgency<DepartmentOfIndustry>();
if (this.CityLocation.IsValid && agency != null)
{
City closestCityFromWorldPosition = agency.GetClosestCityFromWorldPosition(this.CityLocation, true);
if ((closestCityFromWorldPosition != null || closestCityFromWorldPosition.Empire == this.Empire) && agency2.GetConstructionQueue(closestCityFromWorldPosition).PendingConstructions.Count <= 0)
{
List<string> list = new List<string>
{
"CityImprovementIndustry0",
"CityImprovementDust0",
"CityImprovementFood0",
"CityImprovementApproval1",
"CityImprovementScience0"
};
List<DepartmentOfIndustry.ConstructibleElement> list2 = new List<DepartmentOfIndustry.ConstructibleElement>();
DepartmentOfIndustry.ConstructibleElement constructibleElement = null;
foreach (DepartmentOfIndustry.ConstructibleElement constructibleElement2 in agency2.ConstructibleElementDatabase.GetAvailableConstructibleElements(new StaticString[]
{
CityImprovementDefinition.ReadOnlyCategory
}))
{
if (DepartmentOfTheTreasury.CheckConstructiblePrerequisites(closestCityFromWorldPosition, constructibleElement2, new string[]
{
ConstructionFlags.Prerequisite
}))
{
if (agency.Cities.Count == 1 && constructibleElement2.ToString().Contains("CityImprovementFIDS"))
{
constructibleElement = constructibleElement2;
break;
}
if (list.Contains(constructibleElement2.ToString()))
{
list2.Add(constructibleElement2);
}
}
}
if (constructibleElement == null && list2.Count > 0)
{
using (List<string>.Enumerator enumerator = list.GetEnumerator())
{
while (enumerator.MoveNext())
{
string important = enumerator.Current;
if (list2.Any((DepartmentOfIndustry.ConstructibleElement item) => item.Name == important))
{
constructibleElement = list2.First((DepartmentOfIndustry.ConstructibleElement item) => item.Name == important);
break;
}
}
}
}
if (constructibleElement != null)
{
OrderQueueConstruction order = new OrderQueueConstruction(this.Empire.Index, closestCityFromWorldPosition.GUID, constructibleElement, string.Empty);
Ticket ticket;
this.Empire.PlayerControllers.AI.PostOrder(order, out ticket, null);
}
}
}
}

private bool orderExecuted;

private bool orderPosted;

private WorldPosition CityLocation;

private Empire Empire;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,83 +27,109 @@ public override void Release()
protected override State Execute(AIBehaviorTree aiBehaviorTree, params object[] parameters)
{
this.aiBehaviorTree = aiBehaviorTree;
State result;
if (this.ticket != null)
{
return State.Running;
result = State.Running;
}
Army army;
AIArmyMission.AIArmyMissionErrorCode armyUnlessLocked = base.GetArmyUnlessLocked(aiBehaviorTree, "$Army", out army);
if (armyUnlessLocked != AIArmyMission.AIArmyMissionErrorCode.None)
else
{
return State.Failure;
}
if (!aiBehaviorTree.Variables.ContainsKey(this.TargetVarName))
{
aiBehaviorTree.LogError("${0} not set", new object[]
Army army;
if (base.GetArmyUnlessLocked(aiBehaviorTree, "$Army", out army) > AIArmyMission.AIArmyMissionErrorCode.None)
{
this.TargetVarName
});
return State.Failure;
}
IGameEntity target = aiBehaviorTree.Variables[this.TargetVarName] as IGameEntity;
if (!(target is IWorldPositionable))
{
return State.Failure;
}
IGameService service = Services.GetService<IGameService>();
Diagnostics.Assert(service != null);
IGameEntityRepositoryService service2 = service.Game.Services.GetService<IGameEntityRepositoryService>();
if (!service2.Contains(target.GUID))
{
return State.Success;
}
AICommanderWithObjective commanderObjective = aiBehaviorTree.AICommander as AICommanderWithObjective;
if (commanderObjective == null)
{
return State.Failure;
}
EvaluableMessage_VillageAction evaluableMessage_VillageAction = aiBehaviorTree.AICommander.AIPlayer.Blackboard.FindFirst<EvaluableMessage_VillageAction>(BlackboardLayerID.Empire, (EvaluableMessage_VillageAction match) => match.RegionIndex == commanderObjective.RegionIndex && match.VillageGUID == target.GUID && match.AccountTag == AILayer_AccountManager.ConversionAccountName);
if (evaluableMessage_VillageAction == null || evaluableMessage_VillageAction.EvaluationState == EvaluableMessage.EvaluableMessageState.Cancel)
{
this.aiBehaviorTree.ErrorCode = 32;
return State.Failure;
}
if (evaluableMessage_VillageAction.EvaluationState == EvaluableMessage.EvaluableMessageState.Obtained)
{
return State.Success;
}
if (evaluableMessage_VillageAction.ChosenBuyEvaluation == null || evaluableMessage_VillageAction.ChosenBuyEvaluation.State != BuyEvaluation.EvaluationState.Purchased || evaluableMessage_VillageAction.EvaluationState != EvaluableMessage.EvaluableMessageState.Validate)
{
return State.Failure;
}
IEncounterRepositoryService service3 = service.Game.Services.GetService<IEncounterRepositoryService>();
if (service3 != null)
{
IEnumerable<Encounter> enumerable = service3;
if (enumerable != null)
result = State.Failure;
}
else if (!aiBehaviorTree.Variables.ContainsKey(this.TargetVarName))
{
bool flag = enumerable.Any((Encounter encounter) => encounter.IsGarrisonInEncounter(army.GUID, false) || encounter.IsGarrisonInEncounter(target.GUID, false));
if (flag)
aiBehaviorTree.LogError("${0} not set", new object[]
{
return State.Running;
this.TargetVarName
});
result = State.Failure;
}
else
{
IGameEntity target = aiBehaviorTree.Variables[this.TargetVarName] as IGameEntity;
if (!(target is IWorldPositionable))
{
result = State.Failure;
}
else
{
IGameService service = Services.GetService<IGameService>();
Diagnostics.Assert(service != null);
if (!service.Game.Services.GetService<IGameEntityRepositoryService>().Contains(target.GUID))
{
result = State.Success;
}
else
{
AICommanderWithObjective commanderObjective = aiBehaviorTree.AICommander as AICommanderWithObjective;
if (commanderObjective == null)
{
result = State.Failure;
}
else if (!(target is Village))
{
aiBehaviorTree.ErrorCode = 2;
result = State.Failure;
}
else
{
EvaluableMessage_VillageAction evaluableMessage_VillageAction = aiBehaviorTree.AICommander.AIPlayer.Blackboard.FindFirst<EvaluableMessage_VillageAction>(BlackboardLayerID.Empire, (EvaluableMessage_VillageAction match) => match.RegionIndex == commanderObjective.RegionIndex && match.VillageGUID == target.GUID && match.AccountTag == AILayer_AccountManager.ConversionAccountName);
if (evaluableMessage_VillageAction == null)
{
float num;
army.Empire.GetAgency<DepartmentOfTheTreasury>().TryGetResourceStockValue(army.Empire.SimulationObject, DepartmentOfTheTreasury.Resources.EmpirePoint, out num, false);
if (AILayer_Village.GetVillageConversionCost(army.Empire as MajorEmpire, target as Village) > num || ((target as Village).HasBeenConverted && (target as Village).Converter == aiBehaviorTree.AICommander.Empire as MajorEmpire))
{
this.aiBehaviorTree.ErrorCode = 32;
return State.Failure;
}
}
else
{
if (evaluableMessage_VillageAction.EvaluationState == EvaluableMessage.EvaluableMessageState.Cancel)
{
this.aiBehaviorTree.ErrorCode = 32;
return State.Failure;
}
if (evaluableMessage_VillageAction.EvaluationState == EvaluableMessage.EvaluableMessageState.Obtained)
{
return State.Success;
}
if (evaluableMessage_VillageAction.ChosenBuyEvaluation == null || evaluableMessage_VillageAction.ChosenBuyEvaluation.State != BuyEvaluation.EvaluationState.Purchased || evaluableMessage_VillageAction.EvaluationState != EvaluableMessage.EvaluableMessageState.Validate)
{
return State.Failure;
}
}
IEncounterRepositoryService service2 = service.Game.Services.GetService<IEncounterRepositoryService>();
if (service2 != null)
{
IEnumerable<Encounter> enumerable = service2;
if (enumerable != null && enumerable.Any((Encounter encounter) => encounter.IsGarrisonInEncounter(army.GUID, false) || encounter.IsGarrisonInEncounter(target.GUID, false)))
{
return State.Running;
}
}
Diagnostics.Assert(AIScheduler.Services != null);
if (service.Game.Services.GetService<IWorldPositionningService>().GetDistance(army.WorldPosition, (target as IWorldPositionable).WorldPosition) != 1)
{
aiBehaviorTree.ErrorCode = 12;
result = State.Failure;
}
else
{
OrderConvertVillage order = new OrderConvertVillage(army.Empire.Index, army.GUID, (target as IWorldPositionable).WorldPosition);
aiBehaviorTree.AICommander.Empire.PlayerControllers.AI.PostOrder(order, out this.ticket, new EventHandler<TicketRaisedEventArgs>(this.OrderConvertVillage_TicketRaised));
result = State.Running;
}
}
}
}
}
}
if (!(target is Village))
{
aiBehaviorTree.ErrorCode = 2;
return State.Failure;
}
Diagnostics.Assert(AIScheduler.Services != null);
IWorldPositionningService service4 = service.Game.Services.GetService<IWorldPositionningService>();
if (service4.GetDistance(army.WorldPosition, (target as IWorldPositionable).WorldPosition) != 1)
{
aiBehaviorTree.ErrorCode = 12;
return State.Failure;
}
OrderConvertVillage order = new OrderConvertVillage(army.Empire.Index, army.GUID, (target as IWorldPositionable).WorldPosition);
aiBehaviorTree.AICommander.Empire.PlayerControllers.AI.PostOrder(order, out this.ticket, new EventHandler<TicketRaisedEventArgs>(this.OrderConvertVillage_TicketRaised));
return State.Running;
return result;
}

private void OrderConvertVillage_TicketRaised(object sender, TicketRaisedEventArgs e)
Expand Down
Loading

0 comments on commit b7faa7e

Please sign in to comment.