Skip to content

Commit

Permalink
Merge branch 'bleed' into rv-engine
Browse files Browse the repository at this point in the history
  • Loading branch information
MustaphaTR committed Feb 12, 2024
2 parents 1b6b69d + 12e1d32 commit 75890ed
Show file tree
Hide file tree
Showing 102 changed files with 1,054 additions and 1,186 deletions.
8 changes: 6 additions & 2 deletions OpenRA.Game/Actor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ public Activity CurrentActivity
public IOccupySpace OccupiesSpace { get; }
public ITargetable[] Targetables { get; }
public IEnumerable<ITargetablePositions> EnabledTargetablePositions { get; }
public ICrushable[] Crushables { get; }
readonly ICrushable[] crushables;
public ICrushable[] Crushables
{
get => crushables ?? throw new InvalidOperationException($"Crushables for {Info.Name} are not initialized.");
}

public bool IsIdle => CurrentActivity == null;
public bool IsDead => Disposed || (health != null && health.IsDead);
Expand Down Expand Up @@ -198,7 +202,7 @@ internal Actor(World world, string name, TypeDictionary initDict)
EnabledTargetablePositions = targetablePositions.Where(Exts.IsTraitEnabled);
enabledTargetableWorldPositions = EnabledTargetablePositions.SelectMany(tp => tp.TargetablePositions(this));
SyncHashes = syncHashesList.ToArray();
Crushables = crushablesList.ToArray();
crushables = crushablesList.ToArray();
}
}

Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Game/Renderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ public void SaveScreenshot(string path)

public void Dispose()
{
worldBuffer.Dispose();
worldBuffer?.Dispose();
screenBuffer.Dispose();
worldBufferSnapshot.Dispose();
tempVertexBuffer.Dispose();
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Activities/Attack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ protected virtual void DoAttack(Actor self, AttackFrontal attack, IEnumerable<Ar
{
if (!attack.IsTraitPaused)
foreach (var a in armaments)
a.CheckFire(self, facing, target, false);
a.CheckFire(self, facing, target);
}

void IActivityNotifyStanceChanged.StanceChanged(Actor self, AutoTarget autoTarget, UnitStance oldStance, UnitStance newStance)
Expand Down
25 changes: 16 additions & 9 deletions OpenRA.Mods.Common/DiscordService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public sealed class DiscordService : IGlobalModData, IDisposable
{
public readonly string ApplicationId = null;
public readonly string Tooltip = "Open Source real-time strategy game engine for early Westwood titles.";
DiscordRpcClient client;
readonly DiscordRpcClient client;
DiscordState currentState;

static DiscordService instance;
Expand Down Expand Up @@ -105,7 +105,7 @@ void SetStatus(DiscordState state, string details = null, string secret = null,
if (currentState == state)
return;

if (instance == null)
if (client == null)
return;

string stateText;
Expand Down Expand Up @@ -192,6 +192,9 @@ void SetStatus(DiscordState state, string details = null, string secret = null,

void UpdateParty(int players, int slots)
{
if (client == null)
return;

if (client.CurrentPresence.Party != null)
{
client.UpdatePartySize(players, slots);
Expand All @@ -206,14 +209,18 @@ void UpdateParty(int players, int slots)
});
}

void SetDetails(string details)
{
if (client == null)
return;

client.UpdateDetails(details);
}

public void Dispose()
{
if (client != null)
{
client.Dispose();
client = null;
instance = null;
}
client?.Dispose();
instance = null;
}

public static void UpdateStatus(DiscordState state, string details = null, string secret = null, int? players = null, int? slots = null)
Expand All @@ -228,7 +235,7 @@ public static void UpdatePlayers(int players, int slots)

public static void UpdateDetails(string details)
{
Service?.client.UpdateDetails(details);
Service?.SetDetails(details);
}
}
}
17 changes: 14 additions & 3 deletions OpenRA.Mods.Common/EditorBrushes/EditorClipboard.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
using System.Collections.Generic;
#region Copyright & License Information
/*
* Copyright (c) The OpenRA Developers and Contributors
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion

using System.Collections.Generic;
using OpenRA.Mods.Common.Traits;

namespace OpenRA.Mods.Common.EditorBrushes
Expand All @@ -7,10 +18,10 @@ public readonly struct ClipboardTile
{
public readonly TerrainTile TerrainTile;
public readonly ResourceTile ResourceTile;
public readonly ResourceLayerContents ResourceLayerContents;
public readonly ResourceLayerContents? ResourceLayerContents;
public readonly byte Height;

public ClipboardTile(TerrainTile terrainTile, ResourceTile resourceTile, ResourceLayerContents resourceLayerContents, byte height)
public ClipboardTile(TerrainTile terrainTile, ResourceTile resourceTile, ResourceLayerContents? resourceLayerContents, byte height)
{
TerrainTile = terrainTile;
ResourceTile = resourceTile;
Expand Down
73 changes: 41 additions & 32 deletions OpenRA.Mods.Common/EditorBrushes/EditorCopyPasteBrush.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ EditorClipboard CopySelectionContents()
if (!mapTiles.Contains(cell))
continue;

var resourceLayerContents = resourceLayer.GetResource(cell);
var resourceLayerContents = resourceLayer?.GetResource(cell);
tiles.Add(cell, new ClipboardTile(mapTiles[cell], mapResources[cell], resourceLayerContents, mapHeight[cell]));

if (copyFilters.HasFlag(MapCopyFilters.Actors))
Expand Down Expand Up @@ -189,7 +189,7 @@ public void Do()
continue;

// Clear any existing resources.
if (copyFilters.HasFlag(MapCopyFilters.Resources))
if (resourceLayer != null && copyFilters.HasFlag(MapCopyFilters.Resources))
resourceLayer.ClearResources(position);

var tile = tileKeyValuePair.Value;
Expand All @@ -201,33 +201,38 @@ public void Do()
map.Height[position] = tile.Height;
}

if (copyFilters.HasFlag(MapCopyFilters.Resources) && !string.IsNullOrWhiteSpace(resourceLayerContents.Type))
resourceLayer.AddResource(resourceLayerContents.Type, position, resourceLayerContents.Density);
if (copyFilters.HasFlag(MapCopyFilters.Resources) &&
resourceLayerContents.HasValue &&
!string.IsNullOrWhiteSpace(resourceLayerContents.Value.Type))
resourceLayer.AddResource(resourceLayerContents.Value.Type, position, resourceLayerContents.Value.Density);
}

// Clear any existing actors in the paste cells.
var selectionSize = clipboard.CellRegion.BottomRight - clipboard.CellRegion.TopLeft;
var pasteRegion = new CellRegion(map.Grid.Type, pastePosition, pastePosition + selectionSize);
foreach (var regionActor in pasteRegion.SelectMany(editorActorLayer.PreviewsAt).ToHashSet())
editorActorLayer.Remove(regionActor);

// Now place actors.
foreach (var actorKeyValuePair in clipboard.Actors)
if (copyFilters.HasFlag(MapCopyFilters.Actors))
{
var selection = clipboard.CellRegion;
var copy = actorKeyValuePair.Value.Export();
var locationInit = copy.GetOrDefault<LocationInit>();
if (locationInit != null)
// Clear any existing actors in the paste cells.
var selectionSize = clipboard.CellRegion.BottomRight - clipboard.CellRegion.TopLeft;
var pasteRegion = new CellRegion(map.Grid.Type, pastePosition, pastePosition + selectionSize);
foreach (var regionActor in pasteRegion.SelectMany(editorActorLayer.PreviewsAt).ToHashSet())
editorActorLayer.Remove(regionActor);

// Now place actors.
foreach (var actorKeyValuePair in clipboard.Actors)
{
var actorPosition = locationInit.Value + new CVec(pastePosition.X - selection.TopLeft.X, pastePosition.Y - selection.TopLeft.Y);
if (!map.Contains(actorPosition))
continue;

copy.RemoveAll<LocationInit>();
copy.Add(new LocationInit(actorPosition));
var selection = clipboard.CellRegion;
var copy = actorKeyValuePair.Value.Export();
var locationInit = copy.GetOrDefault<LocationInit>();
if (locationInit != null)
{
var actorPosition = locationInit.Value + new CVec(pastePosition.X - selection.TopLeft.X, pastePosition.Y - selection.TopLeft.Y);
if (!map.Contains(actorPosition))
continue;

copy.RemoveAll<LocationInit>();
copy.Add(new LocationInit(actorPosition));
}

editorActorLayer.Add(copy);
}

editorActorLayer.Add(copy);
}
}

Expand All @@ -240,7 +245,7 @@ public void Undo()
var resourceLayerContents = tile.ResourceLayerContents;

// Clear any existing resources.
if (copyFilters.HasFlag(MapCopyFilters.Resources))
if (resourceLayer != null && copyFilters.HasFlag(MapCopyFilters.Resources))
resourceLayer.ClearResources(position);

if (copyFilters.HasFlag(MapCopyFilters.Terrain))
Expand All @@ -249,18 +254,22 @@ public void Undo()
map.Height[position] = tile.Height;
}

if (copyFilters.HasFlag(MapCopyFilters.Resources) && !string.IsNullOrWhiteSpace(resourceLayerContents.Type))
resourceLayer.AddResource(resourceLayerContents.Type, position, resourceLayerContents.Density);
if (copyFilters.HasFlag(MapCopyFilters.Resources) &&
resourceLayerContents.HasValue &&
!string.IsNullOrWhiteSpace(resourceLayerContents.Value.Type))
resourceLayer.AddResource(resourceLayerContents.Value.Type, position, resourceLayerContents.Value.Density);
}

// Clear existing actors.
foreach (var regionActor in undoClipboard.CellRegion.SelectMany(editorActorLayer.PreviewsAt).Distinct().ToList())
editorActorLayer.Remove(regionActor);

// Place actors back again.
if (copyFilters.HasFlag(MapCopyFilters.Actors))
{
// Clear existing actors.
foreach (var regionActor in undoClipboard.CellRegion.SelectMany(editorActorLayer.PreviewsAt).Distinct().ToList())
editorActorLayer.Remove(regionActor);

// Place actors back again.
foreach (var actor in undoClipboard.Actors.Values)
editorActorLayer.Add(actor);
}
}
}
}
Loading

0 comments on commit 75890ed

Please sign in to comment.