fix units being visible under fog

This commit is contained in:
Chris Forbes
2010-04-02 17:09:20 +13:00
parent ca0d993c1a
commit 37fd8f7c28
6 changed files with 44 additions and 16 deletions

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5"> <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -77,6 +77,7 @@
<Compile Include="Chrome.cs" /> <Compile Include="Chrome.cs" />
<Compile Include="GameRules\WeaponInfo.cs" /> <Compile Include="GameRules\WeaponInfo.cs" />
<Compile Include="Traits\AI\ReturnOnIdle.cs" /> <Compile Include="Traits\AI\ReturnOnIdle.cs" />
<Compile Include="Traits\Render\HiddenUnderFog.cs" />
<Compile Include="Traits\World\Shroud.cs" /> <Compile Include="Traits\World\Shroud.cs" />
<Compile Include="Widgets\Delegates\ConnectionDialogsDelegate.cs" /> <Compile Include="Widgets\Delegates\ConnectionDialogsDelegate.cs" />
<Compile Include="Widgets\Delegates\CreateServerMenuDelegate.cs" /> <Compile Include="Widgets\Delegates\CreateServerMenuDelegate.cs" />

View File

@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OpenRA.Traits.Render
{
class HiddenUnderFogInfo : ITraitInfo
{
public object Create(Actor self) { return new HiddenUnderFog(self); }
}
class HiddenUnderFog : IRenderModifier
{
Shroud shroud;
public HiddenUnderFog(Actor self)
{
shroud = self.World.WorldActor.traits.Get<Shroud>();
}
public IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r)
{
if (self.Owner == self.World.LocalPlayer || shroud.visibleCells[self.Location.X, self.Location.Y] > 0)
return r;
return new Renderable[] { };
}
}
}

View File

@@ -30,17 +30,13 @@ namespace OpenRA.Traits
public override object Create(Actor self) { return new RenderUnit(self); } public override object Create(Actor self) { return new RenderUnit(self); }
} }
class RenderUnit : RenderSimple, INotifyDamage, IRenderModifier class RenderUnit : RenderSimple, INotifyDamage
{ {
Shroud shroud;
public RenderUnit(Actor self) public RenderUnit(Actor self)
: base(self, () => self.traits.Get<Unit>().Facing) : base(self, () => self.traits.Get<Unit>().Facing)
{ {
anim.Play("idle"); anim.Play("idle");
anims.Add( "smoke", new AnimationWithOffset( new Animation( "smoke_m" ), null, () => !isSmoking ) ); anims.Add( "smoke", new AnimationWithOffset( new Animation( "smoke_m" ), null, () => !isSmoking ) );
shroud = self.World.WorldActor.traits.Get<Shroud>();
} }
public void PlayCustomAnimation(Actor self, string newAnim, Action after) public void PlayCustomAnimation(Actor self, string newAnim, Action after)
@@ -62,14 +58,5 @@ namespace OpenRA.Traits
() => smoke.PlayBackwardsThen( "end", () => smoke.PlayBackwardsThen( "end",
() => isSmoking = false ) ) ); () => isSmoking = false ) ) );
} }
public IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r)
{
if (self.Owner == self.World.LocalPlayer ||
shroud.visibleCells[self.Location.X, self.Location.Y] > 0)
return r;
return new Renderable[] { };
}
} }
} }

View File

@@ -36,7 +36,7 @@ namespace OpenRA.Traits
[Sync] [Sync]
public int Altitude; public int Altitude;
public Unit( Actor self ) { } public Unit(Actor self) { }
public void Damaged(Actor self, AttackInfo e) public void Damaged(Actor self, AttackInfo e)
{ {

View File

@@ -10,6 +10,7 @@
Chronoshiftable: Chronoshiftable:
Passenger: Passenger:
IronCurtainable: IronCurtainable:
HiddenUnderFog:
^Infantry: ^Infantry:
Category: Infantry Category: Infantry
@@ -23,6 +24,7 @@
SquishByTank: SquishByTank:
AutoTarget: AutoTarget:
Passenger: Passenger:
HiddenUnderFog:
^Ship: ^Ship:
Category: Ship Category: Ship
@@ -30,11 +32,13 @@
Mobile: Mobile:
MovementType: Float MovementType: Float
Selectable: Selectable:
HiddenUnderFog:
^Plane: ^Plane:
Category: Plane Category: Plane
Unit: Unit:
Selectable: Selectable:
HiddenUnderFog:
^Building: ^Building:
Category: Building Category: Building
@@ -48,6 +52,7 @@
DamagedSound: xplos.aud DamagedSound: xplos.aud
DestroyedSound: xplobig4.aud DestroyedSound: xplobig4.aud
RenderBuilding: RenderBuilding:
^Tree: ^Tree:
Category: Building Category: Building
RenderBuilding: RenderBuilding:
@@ -55,6 +60,7 @@
Building: Building:
Footprint: __ x_ Footprint: __ x_
Dimensions: 2,2 Dimensions: 2,2
^Wall: ^Wall:
Category: Building Category: Building
Building: Building:

View File

@@ -10,6 +10,7 @@
Chronoshiftable: Chronoshiftable:
Passenger: Passenger:
IronCurtainable: IronCurtainable:
HiddenUnderFog:
^Infantry: ^Infantry:
Category: Infantry Category: Infantry
@@ -23,6 +24,7 @@
SquishByTank: SquishByTank:
AutoTarget: AutoTarget:
Passenger: Passenger:
HiddenUnderFog:
^Ship: ^Ship:
Category: Ship Category: Ship
@@ -30,12 +32,14 @@
Mobile: Mobile:
MovementType: Float MovementType: Float
Selectable: Selectable:
HiddenUnderFog:
^Plane: ^Plane:
Category: Plane Category: Plane
Unit: Unit:
TargetType: Air TargetType: Air
Selectable: Selectable:
HiddenUnderFog:
^Building: ^Building:
Category: Building Category: Building