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

View File

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

View File

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

View File

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

View File

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

View File

@@ -22,184 +22,184 @@ using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Net;
using OpenRA.Server;
namespace OpenRA.Widgets.Delegates
{
public class WidgetDelegate
{
// For checkboxes
public virtual bool GetState(Widget w) { return false; }
// For any widget
public virtual bool OnMouseDown(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 class MainMenuButtonsDelegate : WidgetDelegate
{
public override bool OnMouseUp(Widget w, MouseInput mi)
{
// Main Menu root
if (w.Id == "MAINMENU_BUTTON_QUIT")
{
Game.Exit();
return true;
}
return false;
}
}
public class CreateServerMenuDelegate : WidgetDelegate
{
static bool AdvertiseServerOnline = Game.Settings.InternetServer;
public override bool GetState(Widget w)
{
if (w.Id == "CREATESERVER_CHECKBOX_ONLINE")
return AdvertiseServerOnline;
return false;
}
public override bool OnMouseDown(Widget w, MouseInput mi)
{
if (w.Id == "CREATESERVER_CHECKBOX_ONLINE")
{
AdvertiseServerOnline = !AdvertiseServerOnline;
return true;
}
return false;
}
public override bool OnMouseUp(Widget w, MouseInput mi)
{
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")
using OpenRA.Server;
namespace OpenRA.Widgets.Delegates
{
public class WidgetDelegate
{
// For checkboxes
public virtual bool GetState(Widget w) { return false; }
// For any widget
public virtual bool OnMouseDown(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 class MainMenuButtonsDelegate : WidgetDelegate
{
public override bool OnMouseUp(Widget w, MouseInput mi)
{
// Main Menu root
if (w.Id == "MAINMENU_BUTTON_QUIT")
{
Game.Exit();
return true;
}
return false;
}
}
public class CreateServerMenuDelegate : WidgetDelegate
{
static bool AdvertiseServerOnline = Game.Settings.InternetServer;
public override bool GetState(Widget w)
{
if (w.Id == "CREATESERVER_CHECKBOX_ONLINE")
return AdvertiseServerOnline;
return false;
}
public override bool OnMouseDown(Widget w, MouseInput mi)
{
if (w.Id == "CREATESERVER_CHECKBOX_ONLINE")
{
AdvertiseServerOnline = !AdvertiseServerOnline;
return true;
}
return false;
}
public override bool OnMouseUp(Widget w, MouseInput mi)
{
if (w.Id == "MAINMENU_BUTTON_CREATE")
{
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;
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;
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();
bg.Children.RemoveAll(a => GameButtons.Contains(a));
GameButtons.Clear();
foreach (var game in GameList)
{
ButtonWidget b = new ButtonWidget();
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("Text").SetValue( b, "{0} ({1})".F(game.Name, game.Address));
b.GetType().GetField("Delegate").SetValue( b, "ServerBrowserDelegate");
GameButtons.Clear();
foreach (var game in GameList)
{
ButtonWidget b = new ButtonWidget();
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("Text").SetValue( b, "{0} ({1})".F(game.Name, game.Address));
b.GetType().GetField("Delegate").SetValue( b, "ServerBrowserDelegate");
bg.AddChild(b);
GameButtons.Add(b);
height += 35;
}
return true;
}
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")
GameButtons.Add(b);
height += 35;
}
return true;
}
if (w.Id == "JOINSERVER_BUTTON_DIRECTCONNECT")
{
Game.chrome.rootWidget.GetWidget("JOINSERVER_BG").Visible = false;
Game.chrome.rootWidget.GetWidget("MAINMENU_BG").Visible = true;
return true;
}
return false;
}
}
public class ConnectionDialogsDelegate : WidgetDelegate
{
public override bool OnMouseUp(Widget w, MouseInput mi)
{
// Main Menu root
if (w.Id == "CONNECTION_BUTTON_ABORT")
{
Game.chrome.rootWidget.GetWidget("MAINMENU_BG").Visible = true;
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;
}
}
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("MAINMENU_BG").Visible = true;
return true;
}
return false;
}
}
public class ConnectionDialogsDelegate : WidgetDelegate
{
public override bool OnMouseUp(Widget w, MouseInput mi)
{
// Main Menu root
if (w.Id == "CONNECTION_BUTTON_ABORT")
{
Game.chrome.rootWidget.GetWidget("MAINMENU_BG").Visible = true;
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;
namespace OpenRA.Widgets
{
class LabelWidget : Widget
{
public string Text = "";
public string Align = "Left";
public override void Draw()
{
if (!Visible)
{
base.Draw();
return;
}
Rectangle r = Bounds;
Game.chrome.renderer.Device.EnableScissor(r.Left, r.Top, r.Width, r.Height);
int2 bounds = Game.chrome.renderer.BoldFont.Measure(Text);
int2 position = new int2(Bounds.X,Bounds.Y);
if (Align == "Center")
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.Device.DisableScissor();
base.Draw();
}
}
namespace OpenRA.Widgets
{
class LabelWidget : Widget
{
public string Text = "";
public string Align = "Left";
public override void Draw()
{
if (!Visible)
{
base.Draw();
return;
}
Rectangle r = Bounds;
Game.chrome.renderer.Device.EnableScissor(r.Left, r.Top, r.Width, r.Height);
int2 bounds = Game.chrome.renderer.BoldFont.Measure(Text);
int2 position = new int2(Bounds.X,Bounds.Y);
if (Align == "Center")
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.Device.DisableScissor();
base.Draw();
}
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -52,7 +52,7 @@ namespace OpenRA.Traits
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())
{
isOpen = false;

View File

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

View File

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

View File

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

View File

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