Skip to content

Commit

Permalink
Add a WAIT phase
Browse files Browse the repository at this point in the history
- Work on #52
- Italy environment
  • Loading branch information
layagyasz committed Jun 8, 2018
1 parent 647e65c commit dd56954
Show file tree
Hide file tree
Showing 29 changed files with 221 additions and 37 deletions.
9 changes: 7 additions & 2 deletions Controller/Match/HumanMatchPlayerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ public Unit SelectedUnit
{ TurnComponent.VEHICLE_COMBAT_MOVEMENT, new OverrunController(this) },
{ TurnComponent.VEHICLE_MOVEMENT, new MovementController(this, true) },
{ TurnComponent.CLOSE_ASSAULT, new CloseAssaultController(this) },
{ TurnComponent.NON_VEHICLE_MOVEMENT, new MovementController(this, false) }
{ TurnComponent.NON_VEHICLE_MOVEMENT, new MovementController(this, false) },
{ TurnComponent.RESET, new NoOpController(this) },
{ TurnComponent.WAIT, new NoOpController(this) },
{ TurnComponent.SPECTATE, new NoOpController(this) },
};

foreach (TileView t in MatchScreen.MapView.TilesEnumerable)
Expand Down Expand Up @@ -249,7 +252,9 @@ void HighlightEnemyFieldOfSight(byte Team)
.Where(i => i.Configuration.Team != Team)
.SelectMany(i => i.Units)
.SelectMany(i =>
i.GetFieldOfSight(AttackMethod.DIRECT_FIRE).Select(
i.GetFieldOfSight(
AttackMethod.DIRECT_FIRE,
_CurrentTurn.Army.SightFinder.GetUnitVisibility(i).LastSeen).Select(
j => new Tuple<Tile, int>(j.Final, PosterizeLineOfSight(j, i))))
.GroupBy(i => i.Item1)
.Select(i => new Tuple<Tile, Color>(i.Key, HIGHLIGHT_COLORS[i.Min(j => j.Item2)])));
Expand Down
1 change: 1 addition & 0 deletions Controller/Match/MatchRecordReplayPlayerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ int WaitMillis(TurnComponent TurnComponent)
{
switch (TurnComponent)
{
case TurnComponent.WAIT: return 0;
case TurnComponent.RESET: return 0;
case TurnComponent.MINEFIELD_ATTACK: return 0;
case TurnComponent.ATTACK: return 1000;
Expand Down
75 changes: 75 additions & 0 deletions Controller/Match/Subcontroller/NoOpController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using SFML.Window;

namespace PanzerBlitz
{
public class NoOpController : BaseController
{
public NoOpController(HumanMatchPlayerController Controller)
: base(Controller) { }

public override bool CanLoad()
{
return false;
}

public override bool CanUnload()
{
return false;
}

public override bool CanDismount()
{
return false;
}

public override bool CanMount()
{
return false;
}

public override bool CanEvacuate()
{
return false;
}

public override bool CanRecon()
{
return false;
}

public override bool CanClearMinefield()
{
return false;
}

public override bool CanEmplace()
{
return false;
}

public override void HandleTileLeftClick(Tile Tile)
{
return;
}

public override void HandleTileRightClick(Tile Tile)
{
return;
}

public override void HandleUnitLeftClick(Unit Unit)
{
return;
}

public override void HandleUnitRightClick(Unit Unit)
{
return;
}

public override void HandleKeyPress(Keyboard.Key Key)
{
return;
}
}
}
7 changes: 5 additions & 2 deletions FileUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,15 @@ public static MarkovGenerator<char> LoadLanguage(string Path)
public static MarkovGenerator<char> GenerateLanguage(string ExamplePath)
{
var g = new MarkovGenerator<char>(3);
var regex = new Regex("\\(.*\\)");
var parentheticals = new Regex("\\(.*\\)");
var capitals = new Regex("[A-Z- ]*");
foreach (var line in File.ReadAllLines(ExamplePath, Encoding.UTF8))
{
var name = line.ToLower();
if (name.Length == 0) continue;
name = regex.Replace(name, "").Trim();
name = parentheticals.Replace(name, "");
name = capitals.Replace(name, "");
name = name.Trim();
g.AddSequence(name);
}
return g;
Expand Down
1 change: 1 addition & 0 deletions Model/Match.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ static IEnumerable<TurnInfo> StandardTurnOrder(IEnumerable<Army> Armies)

static IEnumerable<TurnComponent> TurnComponents()
{
yield return TurnComponent.WAIT;
yield return TurnComponent.MINEFIELD_ATTACK;
yield return TurnComponent.AIRCRAFT;
yield return TurnComponent.ATTACK;
Expand Down
4 changes: 3 additions & 1 deletion Model/MatchRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ public MatchRecord(Match Match, OrderSerializer OrderSerializer)

public MatchRecord(SerializationInputStream Stream)
{
Match = new Match(new Scenario(Stream), null);
var scenario = new Scenario(Stream);
scenario.FogOfWar = false;
Match = new Match(scenario, null);
OrderSerializer = new OrderSerializer(Match);
Orders = Stream.ReadEnumerable(() => OrderSerializer.Deserialize(Stream)).ToList();
}
Expand Down
10 changes: 7 additions & 3 deletions Model/Orders/Attack/AttackOrderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ protected virtual void Recalculate()
_Attackers,
defenders,
AttackMethod,
TargetTile));
TargetTile,
CombatResultsTable.OddsClamp));
}
else if (Target == AttackTarget.WEAKEST)
{
Expand All @@ -155,15 +156,18 @@ protected virtual void Recalculate()
_Attackers,
new Unit[] { i },
AttackMethod,
TargetTile))
TargetTile,
CombatResultsTable.OddsClamp))
.ArgMax(i => i.TotalAttack));
}
else
{
_OddsCalculations.AddRange(
_Attackers
.GroupBy(i => i.Defender)
.Select(i => new OddsCalculation(i, new Unit[] { i.Key }, AttackMethod, TargetTile)));
.Select(
i => new OddsCalculation(
i, new Unit[] { i.Key }, AttackMethod, TargetTile, CombatResultsTable.OddsClamp)));
_OddsCalculations.Sort((x, y) => x.CompareTo(y));
}
// Sync TreatStackAsArmored
Expand Down
18 changes: 18 additions & 0 deletions Model/Orders/Attack/CombatResultsTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ public abstract class CombatResultsTable

class StandardCombatResultsTable : CombatResultsTable
{
public override int OddsClamp
{
get
{
return 4;
}
}

public override CombatResult GetCombatResult(OddsCalculation Odds, int Roll)
{
return STANDARD_CRT_RESULTS[GetOddsIndex(Odds), Roll + Odds.DieModifier + 2];
Expand Down Expand Up @@ -165,6 +173,14 @@ int GetOddsIndex(OddsCalculation Odds)

class AntiAirCombatResultsTable : CombatResultsTable
{
public override int OddsClamp
{
get
{
return 40;
}
}

public override CombatResult GetCombatResult(OddsCalculation Odds, int Roll)
{
return AA_CRT_RESULTS[GetOddsIndex(Odds), Roll];
Expand All @@ -183,6 +199,8 @@ int GetOddsIndex(OddsCalculation Odds)
}
}

public abstract int OddsClamp { get; }

public abstract CombatResult GetCombatResult(OddsCalculation Odds, int Roll);

public double[] GetCombatResultProbabilities(OddsCalculation Odds)
Expand Down
3 changes: 2 additions & 1 deletion Model/Orders/Attack/IndirectFireAttackOrder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ void Recalculate(Tile Tile)
foreach (var defender in defenders)
{
_OddsCalculations.Add(
new OddsCalculation(_Attackers, new Unit[] { defender }, AttackMethod, Tile));
new OddsCalculation(
_Attackers, new Unit[] { defender }, AttackMethod, Tile, CombatResultsTable.OddsClamp));
}
// Sync TreatStackAsArmored
foreach (OddsCalculation odds in _OddsCalculations)
Expand Down
6 changes: 3 additions & 3 deletions Model/Orders/Attack/OddsCalculation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public int DieModifier
IEnumerable<SingleAttackOrder> AttackOrders,
IEnumerable<Unit> Defenders,
AttackMethod AttackMethod,
Tile Tile)
Tile Tile,
int OddsClamp)
{
OddsCalculationFactors = new List<OddsCalculationFactor>();

Expand Down Expand Up @@ -128,7 +129,7 @@ public int DieModifier
if (_DieModifier > 1) _DieModifier = 1;

// Clamp the odds.
if (_Odds > 4) _Odds = 4;
if (_Odds > OddsClamp) _Odds = OddsClamp;
}

void IncreaseOdds()
Expand All @@ -140,7 +141,6 @@ void IncreaseOdds()
_OddsAgainst = false;
_Odds = 1;
}
if (_Odds > 4) _Odds = 4;
}

public static bool TreatStackAsArmored(
Expand Down
5 changes: 4 additions & 1 deletion Model/Orders/FullOrderAutomater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public bool AutomateTurn(Match Match, TurnInfo TurnInfo)
return true;

case TurnComponent.AIRCRAFT:
return TurnInfo.Army.Units.All(i => !i.Configuration.IsAircraft());
return TurnInfo.Army.Units.All(
i => !i.Configuration.IsAircraft() || i.Status == UnitStatus.DESTROYED);
case TurnComponent.ATTACK:
return !TurnInfo.Army.Units.Any(
i => i.CanAttack(AttackMethod.DIRECT_FIRE) == OrderInvalidReason.NONE);
Expand All @@ -54,6 +55,8 @@ public bool AutomateTurn(Match Match, TurnInfo TurnInfo)
TurnInfo.Army.Deployments.ForEach(i => i.AutomateMovement(false));
return !TurnInfo.Army.Units.Any(i => i.CanMove(false, false) == OrderInvalidReason.NONE);

case TurnComponent.WAIT:
return false;
case TurnComponent.RESET:
return true;
}
Expand Down
2 changes: 2 additions & 0 deletions Model/Orders/Movement/MovementOrder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ public OrderInvalidReason Validate()
if (!Unit.Moved && Path.Count <= 2) return OrderInvalidReason.NONE;
return OrderInvalidReason.UNIT_NO_MOVE;
}
if (Unit.Configuration.HasUnlimitedMovement() && Unit.RemainingMovement < float.Epsilon)
return OrderInvalidReason.UNIT_NO_MOVE;
if (Combat && Unit.Configuration.CanCloseAssault && Path.Count > 2) return OrderInvalidReason.UNIT_NO_MOVE;
return OrderInvalidReason.NONE;
}
Expand Down
7 changes: 6 additions & 1 deletion Model/Scenario.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ enum Attribute
public readonly List<ArmyConfiguration> DeploymentOrder;
public readonly List<ArmyConfiguration> TurnOrder;
public readonly byte Turns;
public readonly bool FogOfWar;
public bool FogOfWar { get; set; }
public readonly Environment Environment;
public readonly MapConfiguration MapConfiguration;

Expand Down Expand Up @@ -90,5 +90,10 @@ public void Serialize(SerializationOutputStream Stream)
Stream.Write(Environment.UniqueKey);
MapConfigurationSerializer.Instance.Serialize(MapConfiguration, Stream);
}

public void SetFogOfWar(bool FogOfWar)
{
this.FogOfWar = FogOfWar;
}
}
}
Loading

0 comments on commit dd56954

Please sign in to comment.