hacked victory conditions

This commit is contained in:
Chris Forbes
2010-04-13 20:35:03 +12:00
parent 3974f82a9e
commit 9e11932ade
7 changed files with 110 additions and 4 deletions

View File

@@ -47,7 +47,7 @@ namespace OpenRA.Graphics
public ITexture PaletteTexture;
public readonly SpriteFont RegularFont, BoldFont;
public readonly SpriteFont RegularFont, BoldFont, TitleFont;
public Size Resolution { get { return device.WindowSize; } }
@@ -64,11 +64,9 @@ namespace OpenRA.Graphics
RgbaSpriteRenderer = new SpriteRenderer( this, RgbaSpriteShader );
WorldSpriteRenderer = new SpriteRenderer( this, WorldSpriteShader );
// RegularFont = device.CreateFont( "FreeSans.ttf" );
// BoldFont = device.CreateFont( "FreeSansBold.ttf" );
RegularFont = new SpriteFont(this, "FreeSans.ttf", 14);
BoldFont = new SpriteFont(this, "FreeSansBold.ttf", 14);
TitleFont = new SpriteFont(this, "titles.ttf", 48);
}
IGraphicsDevice CreateDevice( Assembly rendererDll, int width, int height, bool windowed, bool vsync )

View File

@@ -82,6 +82,7 @@
<Compile Include="Orders\GenericSelectTarget.cs" />
<Compile Include="Traits\AI\EmitInfantryOnSell.cs" />
<Compile Include="Traits\AI\ReturnOnIdle.cs" />
<Compile Include="Traits\Player\VictoryConditions.cs" />
<Compile Include="Traits\Render\HiddenUnderFog.cs" />
<Compile Include="Traits\Render\RenderFlare.cs" />
<Compile Include="Traits\World\Shroud.cs" />
@@ -90,6 +91,7 @@
<Compile Include="Widgets\Delegates\MainMenuButtonsDelegate.cs" />
<Compile Include="Widgets\Delegates\ServerBrowserDelegate.cs" />
<Compile Include="Widgets\Delegates\SettingsMenuDelegate.cs" />
<Compile Include="Widgets\PostGameWidget.cs" />
<Compile Include="Widgets\WidgetUtils.cs" />
<Compile Include="Combat.cs" />
<Compile Include="Effects\Corpse.cs" />

View File

@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OpenRA.Traits
{
class VictoryConditionsInfo : ITraitInfo
{
public readonly string[] ShortGameUnits = { "mcv" };
public object Create(Actor self) { return new VictoryConditions( self ); }
}
interface IVictoryConditions { bool HasLost { get; } bool HasWon { get; } }
class VictoryConditions : ITick, IVictoryConditions
{
public bool HasLost { get; private set; }
public bool HasWon { get; private set; }
public VictoryConditions(Actor self)
{
}
public void Tick(Actor self)
{
var info = self.Info.Traits.Get<VictoryConditionsInfo>();
var hasAnyBuildings = self.World.Queries.OwnedBy[self.Owner]
.WithTrait<Building>().Any();
var hasAnyShortGameUnits = self.World.Queries.OwnedBy[self.Owner]
.Any(a => info.ShortGameUnits.Contains(a.Info.Name));
var hasLost = !(hasAnyBuildings || hasAnyShortGameUnits);
if (hasLost && !HasLost)
Game.Debug("{0} is defeated.".F(self.Owner.PlayerName));
HasLost = hasLost;
}
}
}

View File

@@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenRA.Traits;
using System.Drawing;
namespace OpenRA.Widgets
{
class PostGameWidget : Widget
{
string text;
public override void Draw(World world)
{
base.Draw(world);
if (world.LocalPlayer == null) text = null;
else if (world.players.Count > 2) /* more than just us + neutral */
{
var conds = world.Queries.WithTrait<IVictoryConditions>()
.Where(c => c.Actor.Owner != world.NeutralPlayer);
if (conds.Any(c => c.Actor.Owner == world.LocalPlayer && c.Trait.HasLost))
text = "YOU ARE DEFEATED";
else if (conds.All(c => c.Actor.Owner == world.LocalPlayer || c.Trait.HasLost))
text = "YOU ARE VICTORIOUS";
else
text = null;
}
else
text = null;
if (text != null)
DrawText(text);
}
void DrawText(string s)
{
var size = Game.chrome.renderer.TitleFont.Measure(s);
WidgetUtils.DrawPanel("dialog4", new Rectangle(
(Game.viewport.Width - size.X - 40) / 2,
(Game.viewport.Height - size.Y - 10) / 2,
size.X + 40,
size.Y + 13), null);
Game.chrome.renderer.TitleFont.DrawText(s,
new float2((Game.viewport.Width - size.X) / 2,
(Game.viewport.Height - size.Y) / 2 - .2f * size.Y), Color.White);
Game.chrome.renderer.RgbaSpriteRenderer.Flush();
}
}
}

View File

@@ -1,6 +1,14 @@
Container:
ClickThrough:true
Children:
PostGame@POSTGAME_TEXT:
Id:POSTGAME_TEXT
X:0
Y:0
Width: WINDOW_RIGHT
Height: WINDOW_BOTTOM
ClickThrough: true
Visible: true
Background@MAINMENU_BG:
Id:MAINMENU_BG
X:(WINDOW_RIGHT - WIDTH)/2

View File

@@ -76,6 +76,8 @@ Player:
OneShot: yes
UnitType: badr.bomber
SelectTargetSound: slcttgt1.aud
VictoryConditions:
ShortGameUnits: mcv
World:

BIN
titles.ttf Normal file

Binary file not shown.