#region Copyright & License Information /* * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) * 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. For more information, * see COPYING. */ #endregion using System.Collections.Generic; using System.Linq; using OpenRA.Mods.RA; using OpenRA.Graphics; using OpenRA.Traits; namespace OpenRA.Mods.Cnc { public class RenderCargoInfo : ITraitInfo, Requires { /* altitude of the cargo, relative to us. -ve is underneath us */ public readonly int RelativeAltitude = 0; public readonly string[] PassengerTypes; public object Create(ActorInitializer init) { return new RenderCargo(init.self, this); } } public class RenderCargo : IRenderModifier { Cargo cargo; IFacing facing; IMove move; RenderCargoInfo Info; public RenderCargo(Actor self, RenderCargoInfo info) { cargo = self.Trait(); facing = self.TraitOrDefault(); move = self.Trait(); Info = info; } public IEnumerable ModifyRender(Actor self, WorldRenderer wr, IEnumerable r) { foreach (var c in cargo.Passengers) { c.Trait().SetPxPosition( c, move.PxPosition ); var cargoFacing = c.TraitOrDefault(); if (facing != null && cargoFacing != null) cargoFacing.Facing = facing.Facing; } var visiblePassengers = (Info.PassengerTypes != null && Info.PassengerTypes.Length > 0) ? cargo.Passengers.Where(p => Info.PassengerTypes.Contains(p.Trait().info.CargoType)) : cargo.Passengers; return r.Concat(visiblePassengers.SelectMany(a => a.Render(wr)) .Select(a => a.WithPos(a.Pos - new float2(0, Info.RelativeAltitude)) .WithZOffset(a.ZOffset + Info.RelativeAltitude))); } } }