fixed line-endings on *.cs

This commit is contained in:
Bob
2010-03-22 19:28:37 +12:00
parent 15813b04a8
commit dca15cadb9
20 changed files with 944 additions and 944 deletions

View File

@@ -55,16 +55,16 @@ namespace OpenRA.FileFormats
public static class AudLoader public static class AudLoader
{ {
static int[] IndexAdjust = { -1, -1, -1, -1, 2, 4, 6, 8 }; static int[] IndexAdjust = { -1, -1, -1, -1, 2, 4, 6, 8 };
static int[] StepTable = { static int[] StepTable = {
7, 8, 9, 10, 11, 12, 13, 14, 16, 7, 8, 9, 10, 11, 12, 13, 14, 16,
17, 19, 21, 23, 25, 28, 31, 34, 37, 17, 19, 21, 23, 25, 28, 31, 34, 37,
41, 45, 50, 55, 60, 66, 73, 80, 88, 41, 45, 50, 55, 60, 66, 73, 80, 88,
97, 107, 118, 130, 143, 157, 173, 190, 209, 97, 107, 118, 130, 143, 157, 173, 190, 209,
230, 253, 279, 307, 337, 371, 408, 449, 494, 230, 253, 279, 307, 337, 371, 408, 449, 494,
544, 598, 658, 724, 796, 876, 963, 1060, 1166, 544, 598, 658, 724, 796, 876, 963, 1060, 1166,
1282, 1411, 1552, 1707, 1878, 2066, 2272, 2499, 2749, 1282, 1411, 1552, 1707, 1878, 2066, 2272, 2499, 2749,
3024, 3327, 3660, 4026, 4428, 4871, 5358, 5894, 6484, 3024, 3327, 3660, 4026, 4428, 4871, 5358, 5894, 6484,
7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899, 15289, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899, 15289,
16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767 }; 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767 };
static short DecodeSample(byte b, ref int index, ref int current) static short DecodeSample(byte b, ref int index, ref int current)

View File

@@ -1,69 +1,69 @@
#region Copyright & License Information #region Copyright & License Information
/* /*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford. * Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA. * This file is part of OpenRA.
* *
* OpenRA is free software: you can redistribute it and/or modify * OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* OpenRA is distributed in the hope that it will be useful, * OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>. * along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/ */
#endregion #endregion
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Drawing; using System.Drawing;
using System; using System;
namespace OpenRA.FileFormats namespace OpenRA.FileFormats
{ {
public class TerrainColorSet public class TerrainColorSet
{ {
public readonly Dictionary<TerrainType, Color> colors = new Dictionary<TerrainType, Color>(); public readonly Dictionary<TerrainType, Color> colors = new Dictionary<TerrainType, Color>();
string NextLine( StreamReader reader ) string NextLine( StreamReader reader )
{ {
string ret; string ret;
do do
{ {
ret = reader.ReadLine(); ret = reader.ReadLine();
if( ret == null ) if( ret == null )
return null; return null;
ret = ret.Trim(); ret = ret.Trim();
} }
while( ret.Length == 0 || ret[ 0 ] == ';' ); while( ret.Length == 0 || ret[ 0 ] == ';' );
return ret; return ret;
} }
public TerrainColorSet( string colorFile ) public TerrainColorSet( string colorFile )
{ {
StreamReader file = new StreamReader( FileSystem.Open(colorFile) ); StreamReader file = new StreamReader( FileSystem.Open(colorFile) );
while( true ) while( true )
{ {
string line = NextLine( file ); string line = NextLine( file );
if( line == null ) if( line == null )
break; break;
string[] kv = line.Split('='); string[] kv = line.Split('=');
TerrainType key = (TerrainType)Enum.Parse(typeof(TerrainType),kv[0]); TerrainType key = (TerrainType)Enum.Parse(typeof(TerrainType),kv[0]);
string[] entries = kv[1].Split(','); string[] entries = kv[1].Split(',');
Color val = Color.FromArgb(int.Parse(entries[0]),int.Parse(entries[1]),int.Parse(entries[2])); Color val = Color.FromArgb(int.Parse(entries[0]),int.Parse(entries[1]),int.Parse(entries[2]));
colors.Add(key,val); colors.Add(key,val);
} }
file.Close(); file.Close();
} }
public Color ColorForTerrainType(TerrainType type) public Color ColorForTerrainType(TerrainType type)
{ {
return colors[type]; return colors[type];
} }
} }
} }

View File

@@ -23,21 +23,21 @@ using OpenRA.Graphics;
using System.Drawing; using System.Drawing;
using System; using System;
namespace OpenRA.Widgets namespace OpenRA.Widgets
{ {
class BackgroundWidget : Widget class BackgroundWidget : Widget
{ {
public override void Draw() public override void Draw()
{ {
if (!Visible) if (!Visible)
{ {
base.Draw(); base.Draw();
return; return;
} }
WidgetUtils.DrawPanel("dialog", Bounds, null); WidgetUtils.DrawPanel("dialog", Bounds, null);
base.Draw(); base.Draw();
} }
} }
static class WidgetUtils static class WidgetUtils
@@ -79,5 +79,5 @@ namespace OpenRA.Widgets
r.Device.DisableScissor(); r.Device.DisableScissor();
} }
} }
} }

View File

@@ -21,45 +21,45 @@
using System.Drawing; using System.Drawing;
using OpenRA.Graphics; using OpenRA.Graphics;
namespace OpenRA.Widgets namespace OpenRA.Widgets
{ {
class ButtonWidget : Widget class ButtonWidget : Widget
{ {
public string Text = ""; public string Text = "";
public bool Depressed = false; public bool Depressed = false;
public int VisualHeight = 1; public int VisualHeight = 1;
public override bool HandleInput(MouseInput mi) public override bool HandleInput(MouseInput mi)
{ {
if (Game.chrome.selectedWidget == this) if (Game.chrome.selectedWidget == this)
Depressed = (GetEventBounds().Contains(mi.Location.X,mi.Location.Y)) ? true : false; Depressed = (GetEventBounds().Contains(mi.Location.X,mi.Location.Y)) ? true : false;
// Relinquish focus // Relinquish focus
if (Game.chrome.selectedWidget == this && mi.Event == MouseInputEvent.Up) if (Game.chrome.selectedWidget == this && mi.Event == MouseInputEvent.Up)
{ {
Game.chrome.selectedWidget = null; Game.chrome.selectedWidget = null;
Depressed = false; Depressed = false;
} }
// Are we able to handle this event? // Are we able to handle this event?
if (!Visible || !GetEventBounds().Contains(mi.Location.X,mi.Location.Y)) if (!Visible || !GetEventBounds().Contains(mi.Location.X,mi.Location.Y))
return base.HandleInput(mi); return base.HandleInput(mi);
if (base.HandleInput(mi)) if (base.HandleInput(mi))
return true; return true;
// Give button focus only while the mouse is down // Give button focus only while the mouse is down
// This is a bit of a hack: it will become cleaner soonish // This is a bit of a hack: it will become cleaner soonish
// It will also steal events from any potential children // It will also steal events from any potential children
// We also want to play a click sound // We also want to play a click sound
if (mi.Event == MouseInputEvent.Down) if (mi.Event == MouseInputEvent.Down)
{ {
Game.chrome.selectedWidget = this; Game.chrome.selectedWidget = this;
Depressed = true; Depressed = true;
return true; return true;
} }
return false; return false;
} }
public override void Draw() public override void Draw()
@@ -78,6 +78,6 @@ namespace OpenRA.Widgets
Game.chrome.renderer.BoldFont.Measure(Text).Y / 2) + stateOffset, Color.White)); Game.chrome.renderer.BoldFont.Measure(Text).Y / 2) + stateOffset, Color.White));
base.Draw(); base.Draw();
} }
} }
} }

View File

@@ -16,22 +16,22 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>. * along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/ */
#endregion #endregion
using OpenRA.Graphics; using OpenRA.Graphics;
using System.Drawing; using System.Drawing;
namespace OpenRA.Widgets namespace OpenRA.Widgets
{ {
class CheckboxWidget : Widget class CheckboxWidget : Widget
{ {
public override void Draw() public override void Draw()
{ {
if (!Visible) if (!Visible)
{ {
base.Draw(); base.Draw();
return; return;
} }
var selected = InputHandler.Value != null ? InputHandler.Value.GetState(this) : false; var selected = InputHandler.Value != null ? InputHandler.Value.GetState(this) : false;
@@ -47,9 +47,9 @@ namespace OpenRA.Widgets
Bounds.Height - 9), Bounds.Height - 9),
Color.White); Color.White);
Game.chrome.lineRenderer.Flush(); Game.chrome.lineRenderer.Flush();
} }
base.Draw(); base.Draw();
} }
} }
} }

View File

@@ -22,184 +22,184 @@ using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using OpenRA.Server; using OpenRA.Server;
namespace OpenRA.Widgets.Delegates namespace OpenRA.Widgets.Delegates
{ {
public class WidgetDelegate public class WidgetDelegate
{ {
// For checkboxes // For checkboxes
public virtual bool GetState(Widget w) { return false; } public virtual bool GetState(Widget w) { return false; }
// For any widget // For any widget
public virtual bool OnMouseDown(Widget w, MouseInput mi) { return false; } public virtual bool OnMouseDown(Widget w, MouseInput mi) { return false; }
public virtual bool OnMouseUp(Widget w, MouseInput mi) { return false; } public virtual bool OnMouseUp(Widget w, MouseInput mi) { return false; }
public virtual bool OnMouseMove(Widget w, MouseInput mi) { return false; } public virtual bool OnMouseMove(Widget w, MouseInput mi) { return false; }
} }
public class MainMenuButtonsDelegate : WidgetDelegate public class MainMenuButtonsDelegate : WidgetDelegate
{ {
public override bool OnMouseUp(Widget w, MouseInput mi) public override bool OnMouseUp(Widget w, MouseInput mi)
{ {
// Main Menu root // Main Menu root
if (w.Id == "MAINMENU_BUTTON_QUIT") if (w.Id == "MAINMENU_BUTTON_QUIT")
{ {
Game.Exit(); Game.Exit();
return true; return true;
} }
return false; return false;
} }
} }
public class CreateServerMenuDelegate : WidgetDelegate public class CreateServerMenuDelegate : WidgetDelegate
{ {
static bool AdvertiseServerOnline = Game.Settings.InternetServer; static bool AdvertiseServerOnline = Game.Settings.InternetServer;
public override bool GetState(Widget w) public override bool GetState(Widget w)
{ {
if (w.Id == "CREATESERVER_CHECKBOX_ONLINE") if (w.Id == "CREATESERVER_CHECKBOX_ONLINE")
return AdvertiseServerOnline; return AdvertiseServerOnline;
return false; return false;
} }
public override bool OnMouseDown(Widget w, MouseInput mi) public override bool OnMouseDown(Widget w, MouseInput mi)
{ {
if (w.Id == "CREATESERVER_CHECKBOX_ONLINE") if (w.Id == "CREATESERVER_CHECKBOX_ONLINE")
{ {
AdvertiseServerOnline = !AdvertiseServerOnline; AdvertiseServerOnline = !AdvertiseServerOnline;
return true; return true;
} }
return false; return false;
} }
public override bool OnMouseUp(Widget w, MouseInput mi) public override bool OnMouseUp(Widget w, MouseInput mi)
{ {
if (w.Id == "MAINMENU_BUTTON_CREATE") if (w.Id == "MAINMENU_BUTTON_CREATE")
{
Game.chrome.rootWidget.GetWidget("MAINMENU_BG").Visible = false;
Game.chrome.rootWidget.GetWidget("CREATESERVER_BG").Visible = true;
return true;
}
if (w.Id == "CREATESERVER_BUTTON_CANCEL")
{
Game.chrome.rootWidget.GetWidget("MAINMENU_BG").Visible = true;
Game.chrome.rootWidget.GetWidget("CREATESERVER_BG").Visible = false;
return true;
}
if (w.Id == "CREATESERVER_BUTTON_START")
{
Game.chrome.rootWidget.GetWidget("CREATESERVER_BG").Visible = false;
Log.Write("Creating server");
Server.Server.ServerMain(AdvertiseServerOnline, Game.Settings.MasterServer,
Game.Settings.GameName, Game.Settings.ListenPort,
Game.Settings.ExternalPort, Game.Settings.InitialMods);
Log.Write("Joining server");
Game.JoinServer(IPAddress.Loopback.ToString(), Game.Settings.ListenPort);
return true;
}
return false;
}
}
public class ServerBrowserDelegate : WidgetDelegate
{
static GameServer[] GameList;
static List<Widget> GameButtons = new List<Widget>();
public override bool OnMouseUp(Widget w, MouseInput mi)
{
// Main Menu root
if (w.Id == "MAINMENU_BUTTON_JOIN")
{ {
Game.chrome.rootWidget.GetWidget("MAINMENU_BG").Visible = false; Game.chrome.rootWidget.GetWidget("MAINMENU_BG").Visible = false;
Widget bg = Game.chrome.rootWidget.GetWidget("JOINSERVER_BG"); Game.chrome.rootWidget.GetWidget("CREATESERVER_BG").Visible = true;
bg.Visible = true; return true;
}
int height = 50;
int width = 300; if (w.Id == "CREATESERVER_BUTTON_CANCEL")
int i = 0; {
Game.chrome.rootWidget.GetWidget("MAINMENU_BG").Visible = true;
Game.chrome.rootWidget.GetWidget("CREATESERVER_BG").Visible = false;
return true;
}
if (w.Id == "CREATESERVER_BUTTON_START")
{
Game.chrome.rootWidget.GetWidget("CREATESERVER_BG").Visible = false;
Log.Write("Creating server");
Server.Server.ServerMain(AdvertiseServerOnline, Game.Settings.MasterServer,
Game.Settings.GameName, Game.Settings.ListenPort,
Game.Settings.ExternalPort, Game.Settings.InitialMods);
Log.Write("Joining server");
Game.JoinServer(IPAddress.Loopback.ToString(), Game.Settings.ListenPort);
return true;
}
return false;
}
}
public class ServerBrowserDelegate : WidgetDelegate
{
static GameServer[] GameList;
static List<Widget> GameButtons = new List<Widget>();
public override bool OnMouseUp(Widget w, MouseInput mi)
{
// Main Menu root
if (w.Id == "MAINMENU_BUTTON_JOIN")
{
Game.chrome.rootWidget.GetWidget("MAINMENU_BG").Visible = false;
Widget bg = Game.chrome.rootWidget.GetWidget("JOINSERVER_BG");
bg.Visible = true;
int height = 50;
int width = 300;
int i = 0;
GameList = MasterServerQuery.GetGameList(Game.Settings.MasterServer).ToArray(); GameList = MasterServerQuery.GetGameList(Game.Settings.MasterServer).ToArray();
bg.Children.RemoveAll(a => GameButtons.Contains(a)); bg.Children.RemoveAll(a => GameButtons.Contains(a));
GameButtons.Clear(); GameButtons.Clear();
foreach (var game in GameList) foreach (var game in GameList)
{ {
ButtonWidget b = new ButtonWidget(); ButtonWidget b = new ButtonWidget();
b.Bounds = new Rectangle(bg.Bounds.X + 20, bg.Bounds.Y + height, width, 25); b.Bounds = new Rectangle(bg.Bounds.X + 20, bg.Bounds.Y + height, width, 25);
b.GetType().GetField("Id").SetValue( b, "JOIN_GAME_{0}".F(i)); b.GetType().GetField("Id").SetValue( b, "JOIN_GAME_{0}".F(i));
b.GetType().GetField("Text").SetValue( b, "{0} ({1})".F(game.Name, game.Address)); b.GetType().GetField("Text").SetValue( b, "{0} ({1})".F(game.Name, game.Address));
b.GetType().GetField("Delegate").SetValue( b, "ServerBrowserDelegate"); b.GetType().GetField("Delegate").SetValue( b, "ServerBrowserDelegate");
bg.AddChild(b); bg.AddChild(b);
GameButtons.Add(b); GameButtons.Add(b);
height += 35; height += 35;
} }
return true; return true;
} }
if (w.Id == "JOINSERVER_BUTTON_DIRECTCONNECT") if (w.Id == "JOINSERVER_BUTTON_DIRECTCONNECT")
{
Game.chrome.rootWidget.GetWidget("JOINSERVER_BG").Visible = false;
Game.JoinServer(Game.Settings.NetworkHost, Game.Settings.NetworkPort);
return true;
}
if (w.Id.Substring(0,10) == "JOIN_GAME_")
{
Game.chrome.rootWidget.GetWidget("JOINSERVER_BG").Visible = false;
int index = int.Parse(w.Id.Substring(10));
var game = GameList[index];
Game.JoinServer(game.Address.Split(':')[0], int.Parse(game.Address.Split(':')[1]));
return true;
}
if (w.Id == "JOINSERVER_BUTTON_CANCEL")
{ {
Game.chrome.rootWidget.GetWidget("JOINSERVER_BG").Visible = false; Game.chrome.rootWidget.GetWidget("JOINSERVER_BG").Visible = false;
Game.chrome.rootWidget.GetWidget("MAINMENU_BG").Visible = true; Game.JoinServer(Game.Settings.NetworkHost, Game.Settings.NetworkPort);
return true; return true;
} }
return false; if (w.Id.Substring(0,10) == "JOIN_GAME_")
} {
} Game.chrome.rootWidget.GetWidget("JOINSERVER_BG").Visible = false;
int index = int.Parse(w.Id.Substring(10));
public class ConnectionDialogsDelegate : WidgetDelegate var game = GameList[index];
{ Game.JoinServer(game.Address.Split(':')[0], int.Parse(game.Address.Split(':')[1]));
public override bool OnMouseUp(Widget w, MouseInput mi) return true;
{ }
// Main Menu root
if (w.Id == "CONNECTION_BUTTON_ABORT") if (w.Id == "JOINSERVER_BUTTON_CANCEL")
{ {
Game.chrome.rootWidget.GetWidget("MAINMENU_BG").Visible = true; Game.chrome.rootWidget.GetWidget("JOINSERVER_BG").Visible = false;
Game.chrome.rootWidget.GetWidget("CONNECTING_BG").Visible = false; Game.chrome.rootWidget.GetWidget("MAINMENU_BG").Visible = true;
return true; return true;
} }
if (w.Id == "CONNECTION_BUTTON_CANCEL") return false;
{ }
Game.chrome.rootWidget.GetWidget("MAINMENU_BG").Visible = true; }
Game.chrome.rootWidget.GetWidget("CONNECTION_FAILED_BG").Visible = false;
return true; public class ConnectionDialogsDelegate : WidgetDelegate
} {
public override bool OnMouseUp(Widget w, MouseInput mi)
if (w.Id == "CONNECTION_BUTTON_RETRY") {
{ // Main Menu root
Game.JoinServer(Game.CurrentHost,Game.CurrentPort); if (w.Id == "CONNECTION_BUTTON_ABORT")
return true; {
} Game.chrome.rootWidget.GetWidget("MAINMENU_BG").Visible = true;
return false; Game.chrome.rootWidget.GetWidget("CONNECTING_BG").Visible = false;
} return true;
} }
if (w.Id == "CONNECTION_BUTTON_CANCEL")
{
Game.chrome.rootWidget.GetWidget("MAINMENU_BG").Visible = true;
Game.chrome.rootWidget.GetWidget("CONNECTION_FAILED_BG").Visible = false;
return true;
}
if (w.Id == "CONNECTION_BUTTON_RETRY")
{
Game.JoinServer(Game.CurrentHost,Game.CurrentPort);
return true;
}
return false;
}
}
} }

View File

@@ -20,34 +20,34 @@
using System.Drawing; using System.Drawing;
namespace OpenRA.Widgets namespace OpenRA.Widgets
{ {
class LabelWidget : Widget class LabelWidget : Widget
{ {
public string Text = ""; public string Text = "";
public string Align = "Left"; public string Align = "Left";
public override void Draw() public override void Draw()
{ {
if (!Visible) if (!Visible)
{ {
base.Draw(); base.Draw();
return; return;
} }
Rectangle r = Bounds; Rectangle r = Bounds;
Game.chrome.renderer.Device.EnableScissor(r.Left, r.Top, r.Width, r.Height); Game.chrome.renderer.Device.EnableScissor(r.Left, r.Top, r.Width, r.Height);
int2 bounds = Game.chrome.renderer.BoldFont.Measure(Text); int2 bounds = Game.chrome.renderer.BoldFont.Measure(Text);
int2 position = new int2(Bounds.X,Bounds.Y); int2 position = new int2(Bounds.X,Bounds.Y);
if (Align == "Center") if (Align == "Center")
position = new int2(Bounds.X+Bounds.Width/2, Bounds.Y+Bounds.Height/2) - new int2(bounds.X / 2, bounds.Y/2); position = new int2(Bounds.X+Bounds.Width/2, Bounds.Y+Bounds.Height/2) - new int2(bounds.X / 2, bounds.Y/2);
Game.chrome.renderer.BoldFont.DrawText(Game.chrome.rgbaRenderer, Text, position, Color.White); Game.chrome.renderer.BoldFont.DrawText(Game.chrome.rgbaRenderer, Text, position, Color.White);
Game.chrome.renderer.Device.DisableScissor(); Game.chrome.renderer.Device.DisableScissor();
base.Draw(); base.Draw();
} }
} }
} }

View File

@@ -23,54 +23,54 @@ using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using OpenRA.FileFormats; using OpenRA.FileFormats;
using OpenRA.Widgets.Delegates; using OpenRA.Widgets.Delegates;
namespace OpenRA.Widgets namespace OpenRA.Widgets
{ {
public class Widget public class Widget
{ {
// Info defined in YAML // Info defined in YAML
public readonly string Id = null; public readonly string Id = null;
public readonly string X = "0"; public readonly string X = "0";
public readonly string Y = "0"; public readonly string Y = "0";
public readonly string Width = "0"; public readonly string Width = "0";
public readonly string Height = "0"; public readonly string Height = "0";
public readonly string Delegate = null; public readonly string Delegate = null;
public Lazy<WidgetDelegate> InputHandler; public Lazy<WidgetDelegate> InputHandler;
public bool Visible = true; public bool Visible = true;
public readonly List<Widget> Children = new List<Widget>(); public readonly List<Widget> Children = new List<Widget>();
// Calculated internally // Calculated internally
public Rectangle Bounds; public Rectangle Bounds;
public Widget Parent = null; public Widget Parent = null;
public Widget() { InputHandler = Lazy.New(() => BindHandler(Delegate)); } public Widget() { InputHandler = Lazy.New(() => BindHandler(Delegate)); }
public virtual void Initialize() public virtual void Initialize()
{ {
// Parse the YAML equations to find the widget bounds // Parse the YAML equations to find the widget bounds
Rectangle parentBounds = (Parent == null) ? new Rectangle(0,0,Game.viewport.Width,Game.viewport.Height) : Parent.Bounds; Rectangle parentBounds = (Parent == null) ? new Rectangle(0,0,Game.viewport.Width,Game.viewport.Height) : Parent.Bounds;
Dictionary<string, int> substitutions = new Dictionary<string, int>(); Dictionary<string, int> substitutions = new Dictionary<string, int>();
substitutions.Add("WINDOW_RIGHT", Game.viewport.Width); substitutions.Add("WINDOW_RIGHT", Game.viewport.Width);
substitutions.Add("WINDOW_BOTTOM", Game.viewport.Height); substitutions.Add("WINDOW_BOTTOM", Game.viewport.Height);
substitutions.Add("PARENT_RIGHT", parentBounds.Width); substitutions.Add("PARENT_RIGHT", parentBounds.Width);
substitutions.Add("PARENT_BOTTOM", parentBounds.Height); substitutions.Add("PARENT_BOTTOM", parentBounds.Height);
int width = Evaluator.Evaluate(Width, substitutions); int width = Evaluator.Evaluate(Width, substitutions);
int height = Evaluator.Evaluate(Height, substitutions); int height = Evaluator.Evaluate(Height, substitutions);
substitutions.Add("WIDTH", width); substitutions.Add("WIDTH", width);
substitutions.Add("HEIGHT", height); substitutions.Add("HEIGHT", height);
Bounds = new Rectangle(parentBounds.X + Evaluator.Evaluate(X, substitutions), Bounds = new Rectangle(parentBounds.X + Evaluator.Evaluate(X, substitutions),
parentBounds.Y + Evaluator.Evaluate(Y, substitutions), parentBounds.Y + Evaluator.Evaluate(Y, substitutions),
width, width,
height); height);
foreach (var child in Children) foreach (var child in Children)
child.Initialize(); child.Initialize();
} }
public Rectangle GetEventBounds() public Rectangle GetEventBounds()
@@ -92,59 +92,59 @@ namespace OpenRA.Widgets
} }
throw new InvalidOperationException("Cannot locate widget delegate: {0}".F(name)); throw new InvalidOperationException("Cannot locate widget delegate: {0}".F(name));
} }
public virtual bool HandleInput(MouseInput mi) public virtual bool HandleInput(MouseInput mi)
{ {
// Are we able to handle this event? // Are we able to handle this event?
if (!Visible || !GetEventBounds().Contains(mi.Location.X,mi.Location.Y)) if (!Visible || !GetEventBounds().Contains(mi.Location.X,mi.Location.Y))
return false; return false;
// Can any of our children handle this? // Can any of our children handle this?
foreach (var child in Children) foreach (var child in Children)
if (child.HandleInput(mi)) if (child.HandleInput(mi))
return true; return true;
// Mousedown // Mousedown
if (InputHandler.Value != null && mi.Event == MouseInputEvent.Down) if (InputHandler.Value != null && mi.Event == MouseInputEvent.Down)
return InputHandler.Value.OnMouseDown(this, mi); return InputHandler.Value.OnMouseDown(this, mi);
// Mouseup // Mouseup
if (InputHandler.Value != null && mi.Event == MouseInputEvent.Up) if (InputHandler.Value != null && mi.Event == MouseInputEvent.Up)
return InputHandler.Value.OnMouseUp(this, mi); return InputHandler.Value.OnMouseUp(this, mi);
// Mousemove // Mousemove
if (InputHandler.Value != null && mi.Event == MouseInputEvent.Move) if (InputHandler.Value != null && mi.Event == MouseInputEvent.Move)
return InputHandler.Value.OnMouseMove(this, mi); return InputHandler.Value.OnMouseMove(this, mi);
return false; return false;
} }
public virtual void Draw() public virtual void Draw()
{ {
if (Visible) if (Visible)
foreach (var child in Children) foreach (var child in Children)
child.Draw(); child.Draw();
} }
public void AddChild(Widget child) public void AddChild(Widget child)
{ {
child.Parent = this; child.Parent = this;
Children.Add( child ); Children.Add( child );
} }
public Widget GetWidget(string id) public Widget GetWidget(string id)
{ {
if (this.Id == id) if (this.Id == id)
return this; return this;
foreach (var child in Children) foreach (var child in Children)
if (child.GetWidget(id) != null) if (child.GetWidget(id) != null)
return child; return child;
return null; return null;
} }
} }
class ContainerWidget : Widget { } class ContainerWidget : Widget { }
} }

View File

@@ -56,7 +56,7 @@ namespace OpenRA.Traits.Activities
.FirstOrDefault(a => a.traits.Contains<RenderBuilding>()); .FirstOrDefault(a => a.traits.Contains<RenderBuilding>());
if (hostBuilding != null) if (hostBuilding != null)
hostBuilding.traits.Get<RenderBuilding>() hostBuilding.traits.Get<RenderBuilding>()
.PlayCustomAnim(hostBuilding, "active"); .PlayCustomAnim(hostBuilding, "active");
remainingTicks = (int)(Rules.General.RepairRate * 60 * 25); remainingTicks = (int)(Rules.General.RepairRate * 60 * 25);

View File

@@ -1,32 +1,32 @@
using System; using System;
namespace OpenRA.Traits.Activities namespace OpenRA.Traits.Activities
{ {
public class Wait: IActivity public class Wait: IActivity
{ {
int remainingTicks; int remainingTicks;
public Wait (int period) public Wait (int period)
{ {
remainingTicks = period; remainingTicks = period;
} }
public IActivity Tick (Actor self) public IActivity Tick (Actor self)
{ {
if (remainingTicks-- == 0) return NextActivity; if (remainingTicks-- == 0) return NextActivity;
return this; return this;
} }
public void Cancel (Actor self) public void Cancel (Actor self)
{ {
remainingTicks = 0; NextActivity = null; remainingTicks = 0; NextActivity = null;
} }
public IActivity NextActivity { get; set; } public IActivity NextActivity { get; set; }
} }
} }

View File

@@ -1,60 +1,60 @@
#region Copyright & License Information #region Copyright & License Information
/* /*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford. * Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA. * This file is part of OpenRA.
* *
* OpenRA is free software: you can redistribute it and/or modify * OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* OpenRA is distributed in the hope that it will be useful, * OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>. * along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/ */
#endregion #endregion
using OpenRA.Effects; using OpenRA.Effects;
namespace OpenRA.Traits namespace OpenRA.Traits
{ {
public class CrateActionInfo : ITraitInfo public class CrateActionInfo : ITraitInfo
{ {
public int SelectionShares = 10; public int SelectionShares = 10;
public string Effect = null; public string Effect = null;
public string Notification = null; public string Notification = null;
public virtual object Create(Actor self) { return new CrateAction(self, this); } public virtual object Create(Actor self) { return new CrateAction(self, this); }
} }
public class CrateAction public class CrateAction
{ {
public Actor self; public Actor self;
public CrateActionInfo info; public CrateActionInfo info;
public CrateAction(Actor self, CrateActionInfo info) public CrateAction(Actor self, CrateActionInfo info)
{ {
this.self = self; this.self = self;
this.info = info; this.info = info;
} }
public virtual int GetSelectionShares(Actor collector) public virtual int GetSelectionShares(Actor collector)
{ {
return info.SelectionShares; return info.SelectionShares;
} }
public virtual void Activate(Actor collector) public virtual void Activate(Actor collector)
{ {
Sound.PlayToPlayer(collector.Owner, info.Notification); Sound.PlayToPlayer(collector.Owner, info.Notification);
collector.World.AddFrameEndTask(w => collector.World.AddFrameEndTask(w =>
{ {
if (info.Effect != null) if (info.Effect != null)
w.Add(new CrateEffect(collector, info.Effect)); w.Add(new CrateEffect(collector, info.Effect));
}); });
} }
} }
} }

View File

@@ -1,49 +1,49 @@
using System; using System;
namespace OpenRA.Traits namespace OpenRA.Traits
{ {
class HasUnitOnBuildInfo : ITraitInfo class HasUnitOnBuildInfo : ITraitInfo
{ {
public readonly string Unit = null; public readonly string Unit = null;
public readonly string InitialActivity = null; public readonly string InitialActivity = null;
public readonly int2 SpawnOffset = int2.Zero; public readonly int2 SpawnOffset = int2.Zero;
public readonly int Facing = 0; public readonly int Facing = 0;
public object Create( Actor self ) { return new HasUnitOnBuild(self); } public object Create( Actor self ) { return new HasUnitOnBuild(self); }
} }
public class HasUnitOnBuild public class HasUnitOnBuild
{ {
public HasUnitOnBuild(Actor self) public HasUnitOnBuild(Actor self)
{ {
var info = self.Info.Traits.Get<HasUnitOnBuildInfo>(); var info = self.Info.Traits.Get<HasUnitOnBuildInfo>();
self.World.AddFrameEndTask( self.World.AddFrameEndTask(
w => w =>
{ {
var unit = w.CreateActor(info.Unit, self.Location var unit = w.CreateActor(info.Unit, self.Location
+ info.SpawnOffset, self.Owner); + info.SpawnOffset, self.Owner);
var unitTrait = unit.traits.Get<Unit>(); var unitTrait = unit.traits.Get<Unit>();
unitTrait.Facing = info.Facing; unitTrait.Facing = info.Facing;
if (info.InitialActivity != null) if (info.InitialActivity != null)
{ {
foreach (var mod in Game.ModAssemblies) foreach (var mod in Game.ModAssemblies)
{ {
var fullTypeName = mod.Second + "." + info.InitialActivity; var fullTypeName = mod.Second + "." + info.InitialActivity;
var activity = (IActivity)mod.First.CreateInstance(fullTypeName); var activity = (IActivity)mod.First.CreateInstance(fullTypeName);
if (activity == null) continue; if (activity == null) continue;
unit.QueueActivity( activity ); unit.QueueActivity( activity );
return; return;
} }
throw new InvalidOperationException("Cannot locate Activity: `{0}`".F(info.InitialActivity)); throw new InvalidOperationException("Cannot locate Activity: `{0}`".F(info.InitialActivity));
} }
}); });
} }
} }
} }

View File

@@ -1,35 +1,35 @@
#region Copyright & License Information #region Copyright & License Information
/* /*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford. * Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA. * This file is part of OpenRA.
* *
* OpenRA is free software: you can redistribute it and/or modify * OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* OpenRA is distributed in the hope that it will be useful, * OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>. * along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/ */
#endregion #endregion
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using OpenRA.Effects; using OpenRA.Effects;
using OpenRA.GameRules; using OpenRA.GameRules;
using OpenRA.Traits.Activities; using OpenRA.Traits.Activities;
namespace OpenRA.Traits namespace OpenRA.Traits
{ {
public class LineBuildInfo : StatelessTraitInfo<LineBuild> public class LineBuildInfo : StatelessTraitInfo<LineBuild>
{ {
public readonly int Range = 5; public readonly int Range = 5;
} }
public class LineBuild {} public class LineBuild {}
} }

View File

@@ -1,63 +1,63 @@
#region Copyright & License Information #region Copyright & License Information
/* /*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford. * Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA. * This file is part of OpenRA.
* *
* OpenRA is free software: you can redistribute it and/or modify * OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* OpenRA is distributed in the hope that it will be useful, * OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>. * along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/ */
#endregion #endregion
namespace OpenRA.Traits namespace OpenRA.Traits
{ {
class EvaAlertsInfo : StatelessTraitInfo<EvaAlerts> class EvaAlertsInfo : StatelessTraitInfo<EvaAlerts>
{ {
// Sound effects // Sound effects
public readonly string TabClick = "ramenu1.aud"; public readonly string TabClick = "ramenu1.aud";
public readonly string ChatBeep = "rabeep1.aud"; public readonly string ChatBeep = "rabeep1.aud";
public readonly string RadarUp = "radaron2.aud"; public readonly string RadarUp = "radaron2.aud";
public readonly string RadarDown = "radardn1.aud"; public readonly string RadarDown = "radardn1.aud";
public readonly string CashTickUp = "cashup1.aud"; public readonly string CashTickUp = "cashup1.aud";
public readonly string CashTickDown = "cashdn1.aud"; public readonly string CashTickDown = "cashdn1.aud";
// Build Palette // Build Palette
public readonly string BuildPaletteOpen = "bleep13.aud"; public readonly string BuildPaletteOpen = "bleep13.aud";
public readonly string BuildPaletteClose = "bleep13.aud"; public readonly string BuildPaletteClose = "bleep13.aud";
public readonly string BuildingSelectAudio = "abldgin1.aud"; public readonly string BuildingSelectAudio = "abldgin1.aud";
public readonly string BuildingReadyAudio = "conscmp1.aud"; public readonly string BuildingReadyAudio = "conscmp1.aud";
public readonly string BuildingCannotPlaceAudio = "nodeply1.aud"; public readonly string BuildingCannotPlaceAudio = "nodeply1.aud";
public readonly string UnitSelectAudio = "train1.aud"; public readonly string UnitSelectAudio = "train1.aud";
public readonly string UnitReadyAudio = "unitrdy1.aud"; public readonly string UnitReadyAudio = "unitrdy1.aud";
public readonly string OnHoldAudio = "onhold1.aud"; public readonly string OnHoldAudio = "onhold1.aud";
public readonly string CancelledAudio = "cancld1.aud"; public readonly string CancelledAudio = "cancld1.aud";
public readonly string ClickAudio = "ramenu1.aud"; public readonly string ClickAudio = "ramenu1.aud";
// For manual powerup/down in ra-ng // For manual powerup/down in ra-ng
public readonly string DisablePower = "bleep11.aud"; public readonly string DisablePower = "bleep11.aud";
public readonly string EnablePower = "bleep12.aud"; public readonly string EnablePower = "bleep12.aud";
// Eva speech // Eva speech
public readonly string LowPower = "lopower1.aud"; public readonly string LowPower = "lopower1.aud";
public readonly string SilosNeeded = "silond1.aud"; public readonly string SilosNeeded = "silond1.aud";
public readonly string UnitLost = "unitlst1.aud"; public readonly string UnitLost = "unitlst1.aud";
public readonly string NavalUnitLost = "navylst1.aud"; public readonly string NavalUnitLost = "navylst1.aud";
public readonly string PrimaryBuildingSelected = "pribldg1.aud"; public readonly string PrimaryBuildingSelected = "pribldg1.aud";
public readonly string CreditsStolen = "credit1.aud"; public readonly string CreditsStolen = "credit1.aud";
} }
class EvaAlerts {} class EvaAlerts {}
} }

View File

@@ -1,103 +1,103 @@
#region Copyright & License Information #region Copyright & License Information
/* /*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford. * Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA. * This file is part of OpenRA.
* *
* OpenRA is free software: you can redistribute it and/or modify * OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* OpenRA is distributed in the hope that it will be useful, * OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>. * along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/ */
#endregion #endregion
using System.Linq; using System.Linq;
namespace OpenRA.Traits namespace OpenRA.Traits
{ {
class RenderBuildingWallInfo : RenderBuildingInfo class RenderBuildingWallInfo : RenderBuildingInfo
{ {
public readonly int DamageStates = 2; public readonly int DamageStates = 2;
public override object Create(Actor self) { return new RenderBuildingWall(self); } public override object Create(Actor self) { return new RenderBuildingWall(self); }
} }
class RenderBuildingWall : RenderBuilding class RenderBuildingWall : RenderBuilding
{ {
string seqName; string seqName;
int damageStates; int damageStates;
Actor self; Actor self;
public RenderBuildingWall(Actor self) public RenderBuildingWall(Actor self)
: base(self) : base(self)
{ {
seqName = "idle"; seqName = "idle";
this.self = self; this.self = self;
this.damageStates = self.Info.Traits.Get<RenderBuildingWallInfo>().DamageStates; this.damageStates = self.Info.Traits.Get<RenderBuildingWallInfo>().DamageStates;
} }
public override void Damaged(Actor self, AttackInfo e) public override void Damaged(Actor self, AttackInfo e)
{ {
if (!e.DamageStateChanged) return; if (!e.DamageStateChanged) return;
switch (e.DamageState) switch (e.DamageState)
{ {
case DamageState.Normal: case DamageState.Normal:
seqName = "idle"; seqName = "idle";
break; break;
case DamageState.ThreeQuarter: case DamageState.ThreeQuarter:
if (damageStates >= 4) if (damageStates >= 4)
seqName = "minor-damaged-idle"; seqName = "minor-damaged-idle";
break; break;
case DamageState.Half: case DamageState.Half:
seqName = "damaged-idle"; seqName = "damaged-idle";
Sound.Play(self.Info.Traits.Get<BuildingInfo>().DamagedSound); Sound.Play(self.Info.Traits.Get<BuildingInfo>().DamagedSound);
break; break;
case DamageState.Quarter: case DamageState.Quarter:
if (damageStates >= 3) if (damageStates >= 3)
{ {
seqName = "critical-idle"; seqName = "critical-idle";
Sound.Play(self.Info.Traits.Get<BuildingInfo>().DamagedSound); Sound.Play(self.Info.Traits.Get<BuildingInfo>().DamagedSound);
} }
break; break;
} }
} }
public override void Tick(Actor self) public override void Tick(Actor self)
{ {
base.Tick(self); base.Tick(self);
// TODO: This only needs updating when a wall is built or destroyed // TODO: This only needs updating when a wall is built or destroyed
int index = NearbyWalls( self.Location ); int index = NearbyWalls( self.Location );
anim.PlayFetchIndex(seqName, () => index); anim.PlayFetchIndex(seqName, () => index);
} }
bool IsWall( int x, int y) bool IsWall( int x, int y)
{ {
return self.World.Queries.WithTrait<Wall>().Any(a => (a.Actor.Info.Name == self.Info.Name && a.Actor.Location.X == x && a.Actor.Location.Y == y)); return self.World.Queries.WithTrait<Wall>().Any(a => (a.Actor.Info.Name == self.Info.Name && a.Actor.Location.X == x && a.Actor.Location.Y == y));
} }
int NearbyWalls( int2 xy ) int NearbyWalls( int2 xy )
{ {
int ret = 0; int ret = 0;
if( IsWall( xy.X, xy.Y - 1 ) ) if( IsWall( xy.X, xy.Y - 1 ) )
ret |= 1; ret |= 1;
if( IsWall( xy.X + 1, xy.Y ) ) if( IsWall( xy.X + 1, xy.Y ) )
ret |= 2; ret |= 2;
if( IsWall( xy.X, xy.Y + 1 ) ) if( IsWall( xy.X, xy.Y + 1 ) )
ret |= 4; ret |= 4;
if( IsWall( xy.X - 1, xy.Y ) ) if( IsWall( xy.X - 1, xy.Y ) )
ret |= 8; ret |= 8;
return ret; return ret;
} }
} }
} }

View File

@@ -52,7 +52,7 @@ namespace OpenRA.Traits
public void Tick(Actor self) public void Tick(Actor self)
{ {
if (isOpen && !self.World.WorldActor.traits.Get<UnitInfluence>() if (isOpen && !self.World.WorldActor.traits.Get<UnitInfluence>()
.GetUnitsAt(((1f/Game.CellSize) * self.CenterLocation).ToInt2()).Any()) .GetUnitsAt(((1f/Game.CellSize) * self.CenterLocation).ToInt2()).Any())
{ {
isOpen = false; isOpen = false;

View File

@@ -1,32 +1,32 @@
#region Copyright & License Information #region Copyright & License Information
/* /*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford. * Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA. * This file is part of OpenRA.
* *
* OpenRA is free software: you can redistribute it and/or modify * OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* OpenRA is distributed in the hope that it will be useful, * OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>. * along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/ */
#endregion #endregion
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using OpenRA.Effects; using OpenRA.Effects;
using OpenRA.GameRules; using OpenRA.GameRules;
using OpenRA.Traits.Activities; using OpenRA.Traits.Activities;
namespace OpenRA.Traits namespace OpenRA.Traits
{ {
public class WallInfo : StatelessTraitInfo<Wall> {} public class WallInfo : StatelessTraitInfo<Wall> {}
public class Wall {} public class Wall {}
} }

View File

@@ -21,52 +21,52 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using OpenRA.FileFormats; using OpenRA.FileFormats;
namespace OpenRA.Traits namespace OpenRA.Traits
{ {
class ScreenShakerInfo : ITraitInfo class ScreenShakerInfo : ITraitInfo
{ {
public object Create( Actor self ) { return new ScreenShaker(); } public object Create( Actor self ) { return new ScreenShaker(); }
} }
public class ScreenShaker : ITick public class ScreenShaker : ITick
{ {
int ticks = 0; int ticks = 0;
List<Tuple<int, float2, int>> shakeEffects = new List<Tuple<int, float2, int>>(); List<Tuple<int, float2, int>> shakeEffects = new List<Tuple<int, float2, int>>();
public void Tick (Actor self) public void Tick (Actor self)
{ {
Game.viewport.Scroll(getScrollOffset()); Game.viewport.Scroll(getScrollOffset());
shakeEffects.RemoveAll(t => t.a == ticks); shakeEffects.RemoveAll(t => t.a == ticks);
ticks++; ticks++;
} }
public void AddEffect(int time, float2 position, int intensity) public void AddEffect(int time, float2 position, int intensity)
{ {
shakeEffects.Add(Tuple.New(ticks + time, position, intensity)); shakeEffects.Add(Tuple.New(ticks + time, position, intensity));
} }
public float2 getScrollOffset() public float2 getScrollOffset()
{ {
int xFreq = 4; int xFreq = 4;
int yFreq = 5; int yFreq = 5;
return GetIntensity() * new float2( return GetIntensity() * new float2(
(float) Math.Sin((ticks*2*Math.PI)/xFreq) , (float) Math.Sin((ticks*2*Math.PI)/xFreq) ,
(float) Math.Cos((ticks*2*Math.PI)/yFreq)); (float) Math.Cos((ticks*2*Math.PI)/yFreq));
} }
public float GetIntensity() public float GetIntensity()
{ {
var cp = Game.viewport.Location var cp = Game.viewport.Location
+ .5f * new float2(Game.viewport.Width, Game.viewport.Height); + .5f * new float2(Game.viewport.Width, Game.viewport.Height);
var intensity = 24 * 24 * 100 * shakeEffects.Sum( var intensity = 24 * 24 * 100 * shakeEffects.Sum(
e => e.c / (e.b - cp).LengthSquared); e => e.c / (e.b - cp).LengthSquared);
return Math.Min(intensity, 10); return Math.Min(intensity, 10);
} }
} }
} }

View File

@@ -1,33 +1,33 @@
#region Copyright & License Information #region Copyright & License Information
/* /*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford. * Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA. * This file is part of OpenRA.
* *
* OpenRA is free software: you can redistribute it and/or modify * OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* OpenRA is distributed in the hope that it will be useful, * OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>. * along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/ */
#endregion #endregion
namespace OpenRA.Traits namespace OpenRA.Traits
{ {
class TheaterInfo : StatelessTraitInfo<Theater> class TheaterInfo : StatelessTraitInfo<Theater>
{ {
public readonly string Name = null; public readonly string Name = null;
public readonly string Theater = null; public readonly string Theater = null;
public readonly string Suffix = null; public readonly string Suffix = null;
public readonly string Tileset = null; public readonly string Tileset = null;
public readonly string Templates = null; public readonly string Templates = null;
public readonly string MapColors = null; public readonly string MapColors = null;
} }
class Theater {} class Theater {}
} }

View File

@@ -1,41 +1,41 @@
#region Copyright & License Information #region Copyright & License Information
/* /*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford. * Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA. * This file is part of OpenRA.
* *
* OpenRA is free software: you can redistribute it and/or modify * OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* OpenRA is distributed in the hope that it will be useful, * OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>. * along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/ */
#endregion #endregion
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
{ {
class HideMapCrateActionInfo : CrateActionInfo class HideMapCrateActionInfo : CrateActionInfo
{ {
public override object Create(Actor self) { return new HideMapCrateAction(self, this); } public override object Create(Actor self) { return new HideMapCrateAction(self, this); }
} }
class HideMapCrateAction : CrateAction class HideMapCrateAction : CrateAction
{ {
public HideMapCrateAction(Actor self, HideMapCrateActionInfo info) public HideMapCrateAction(Actor self, HideMapCrateActionInfo info)
: base(self, info) {} : base(self, info) {}
public override void Activate(Actor collector) public override void Activate(Actor collector)
{ {
collector.Owner.Shroud.ResetExplored(); collector.Owner.Shroud.ResetExplored();
base.Activate(collector); base.Activate(collector);
} }
} }
} }